ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/meta/misc.c
Revision: 1.6
Committed: Fri Jun 9 15:25:49 2023 UTC (10 months, 2 weeks ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R4, HEAD
Changes since 1.5: +16 -16 lines
Log Message:
fix: updated a few declarations

File Contents

# User Rev Content
1 greg 1.1 #ifndef lint
2 greg 1.6 static const char RCSid[] = "$Id: misc.c,v 1.5 2005/09/23 19:22:37 greg Exp $";
3 greg 1.1 #endif
4     /*
5     * Miscellaneous functions for meta-files
6     */
7    
8    
9 schorsch 1.4 #include "rtio.h"
10 greg 1.1 #include "meta.h"
11    
12    
13     char coms[] = COML;
14    
15 greg 1.5 /* char errmsg[128]; redundant to error.c in ../commmon */
16 greg 1.1
17    
18    
19     int
20 schorsch 1.4 comndx( /* return index for command */
21 greg 1.6 int c
22 schorsch 1.4 )
23 greg 1.1
24     {
25 greg 1.6 char *cp;
26 greg 1.1
27     if (!isalpha(c))
28     return(-1);
29    
30     for (cp = coms; *cp; cp++)
31     if(*cp == c)
32     return(cp-coms);
33    
34     return(-1);
35     }
36    
37    
38    
39    
40    
41    
42     PRIMITIVE *
43 schorsch 1.4 pop( /* pop top off plist */
44 greg 1.6 PLIST *pl
45 schorsch 1.4 )
46 greg 1.1
47     {
48 greg 1.6 PRIMITIVE *p;
49 greg 1.1
50     if ((p = pl->ptop) != NULL) {
51     if ((pl->ptop = p->pnext) == NULL)
52     pl->pbot = NULL;
53     p->pnext = NULL;
54     }
55    
56     return(p);
57     }
58    
59    
60    
61 schorsch 1.4 void
62     push( /* push primitive onto plist */
63 greg 1.6 PRIMITIVE *p,
64     PLIST *pl
65 schorsch 1.4 )
66 greg 1.1
67     {
68    
69     if ((p->pnext = pl->ptop) == NULL)
70     pl->pbot = p;
71     pl->ptop = p;
72    
73     }
74    
75    
76    
77 schorsch 1.4 void
78     add( /* add primitive to plist */
79 greg 1.6 PRIMITIVE *p,
80     PLIST *pl
81 schorsch 1.4 )
82 greg 1.1 {
83    
84     if (pl->ptop == NULL)
85     pl->ptop = p;
86     else
87     pl->pbot->pnext = p;
88     p->pnext = NULL;
89     pl->pbot = p;
90    
91     }
92    
93    
94    
95 schorsch 1.4 void
96     append( /* append pl1 to the end of pl2 */
97 greg 1.6 PLIST *pl1,
98     PLIST *pl2
99 schorsch 1.4 )
100 greg 1.1
101     {
102    
103     if (pl1->ptop != NULL) {
104     if (pl2->ptop != NULL)
105     pl2->pbot->pnext = pl1->ptop;
106     else
107     pl2->ptop = pl1->ptop;
108     pl2->pbot = pl1->pbot;
109     }
110    
111     }
112    
113    
114    
115 schorsch 1.4 void
116     fargs( /* free any arguments p has */
117 greg 1.6 PRIMITIVE *p
118 schorsch 1.4 )
119 greg 1.1
120     {
121    
122     if (p->args != NULL) {
123     freestr(p->args);
124     p->args = NULL;
125     }
126    
127     }
128    
129    
130    
131     char *
132 schorsch 1.4 nextscan( /* scan and advance through string */
133 greg 1.6 char *start,
134 schorsch 1.4 char *format,
135     char *result
136     )
137 greg 1.1
138     {
139    
140     if (start == NULL) return(NULL);
141    
142     while (isspace(*start)) start++;
143    
144     if (sscanf(start, format, result) != 1) return(NULL);
145    
146     while (*start && !isspace(*start)) start++;
147    
148     return(start);
149     }
150    
151    
152 schorsch 1.4 void
153     mcopy( /* copy p2 into p1 size n */
154 greg 1.6 char *p1,
155     char *p2,
156     int n
157 schorsch 1.4 )
158 greg 1.1
159     {
160    
161     while (n--)
162     *p1++ = *p2++;
163    
164     }
165