1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id: misc.c,v 1.3 2003/07/14 16:05:45 greg Exp $"; |
3 |
#endif |
4 |
/* |
5 |
* Miscellaneous functions for meta-files |
6 |
*/ |
7 |
|
8 |
|
9 |
#include "rtio.h" |
10 |
#include "meta.h" |
11 |
|
12 |
|
13 |
char coms[] = COML; |
14 |
|
15 |
char errmsg[128]; |
16 |
|
17 |
|
18 |
|
19 |
int |
20 |
comndx( /* return index for command */ |
21 |
register int c |
22 |
) |
23 |
|
24 |
{ |
25 |
register char *cp; |
26 |
|
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 |
pop( /* pop top off plist */ |
44 |
register PLIST *pl |
45 |
) |
46 |
|
47 |
{ |
48 |
register PRIMITIVE *p; |
49 |
|
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 |
void |
62 |
push( /* push primitive onto plist */ |
63 |
register PRIMITIVE *p, |
64 |
register PLIST *pl |
65 |
) |
66 |
|
67 |
{ |
68 |
|
69 |
if ((p->pnext = pl->ptop) == NULL) |
70 |
pl->pbot = p; |
71 |
pl->ptop = p; |
72 |
|
73 |
} |
74 |
|
75 |
|
76 |
|
77 |
void |
78 |
add( /* add primitive to plist */ |
79 |
register PRIMITIVE *p, |
80 |
register PLIST *pl |
81 |
) |
82 |
{ |
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 |
void |
96 |
append( /* append pl1 to the end of pl2 */ |
97 |
register PLIST *pl1, |
98 |
register PLIST *pl2 |
99 |
) |
100 |
|
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 |
void |
116 |
fargs( /* free any arguments p has */ |
117 |
register PRIMITIVE *p |
118 |
) |
119 |
|
120 |
{ |
121 |
|
122 |
if (p->args != NULL) { |
123 |
freestr(p->args); |
124 |
p->args = NULL; |
125 |
} |
126 |
|
127 |
} |
128 |
|
129 |
|
130 |
|
131 |
char * |
132 |
nextscan( /* scan and advance through string */ |
133 |
register char *start, |
134 |
char *format, |
135 |
char *result |
136 |
) |
137 |
|
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 |
void |
153 |
mcopy( /* copy p2 into p1 size n */ |
154 |
register char *p1, |
155 |
register char *p2, |
156 |
register int n |
157 |
) |
158 |
|
159 |
{ |
160 |
|
161 |
while (n--) |
162 |
*p1++ = *p2++; |
163 |
|
164 |
} |
165 |
|