1 |
#ifndef lint |
2 |
static const char RCSid[] = "$Id$"; |
3 |
#endif |
4 |
/* |
5 |
* Miscellaneous functions for meta-files |
6 |
*/ |
7 |
|
8 |
|
9 |
#include "meta.h" |
10 |
|
11 |
|
12 |
|
13 |
char coms[] = COML; |
14 |
|
15 |
char errmsg[128]; |
16 |
|
17 |
|
18 |
|
19 |
error(errtype, emsg) /* report error */ |
20 |
|
21 |
int errtype; |
22 |
char *emsg; |
23 |
|
24 |
{ |
25 |
|
26 |
switch (errtype) { |
27 |
|
28 |
case WARNING: |
29 |
wputs(progname); |
30 |
wputs(": warning - "); |
31 |
wputs(emsg); |
32 |
wputs("\n"); |
33 |
break; |
34 |
|
35 |
case USER: |
36 |
eputs(progname); |
37 |
eputs(": fatal - "); |
38 |
eputs(emsg); |
39 |
eputs("\n"); |
40 |
exit(1); |
41 |
break; |
42 |
|
43 |
case SYSTEM: |
44 |
eputs(progname); |
45 |
eputs(": system - "); |
46 |
eputs(emsg); |
47 |
eputs("\n"); |
48 |
exit(1); |
49 |
break; |
50 |
} |
51 |
|
52 |
} |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
int |
58 |
comndx(c) /* return index for command */ |
59 |
|
60 |
register int c; |
61 |
|
62 |
{ |
63 |
register char *cp; |
64 |
|
65 |
if (!isalpha(c)) |
66 |
return(-1); |
67 |
|
68 |
for (cp = coms; *cp; cp++) |
69 |
if(*cp == c) |
70 |
return(cp-coms); |
71 |
|
72 |
return(-1); |
73 |
} |
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
PRIMITIVE * |
81 |
pop(pl) /* pop top off plist */ |
82 |
|
83 |
register PLIST *pl; |
84 |
|
85 |
{ |
86 |
register PRIMITIVE *p; |
87 |
|
88 |
if ((p = pl->ptop) != NULL) { |
89 |
if ((pl->ptop = p->pnext) == NULL) |
90 |
pl->pbot = NULL; |
91 |
p->pnext = NULL; |
92 |
} |
93 |
|
94 |
return(p); |
95 |
} |
96 |
|
97 |
|
98 |
|
99 |
|
100 |
push(p, pl) /* push primitive onto plist */ |
101 |
|
102 |
register PRIMITIVE *p; |
103 |
register PLIST *pl; |
104 |
|
105 |
{ |
106 |
|
107 |
if ((p->pnext = pl->ptop) == NULL) |
108 |
pl->pbot = p; |
109 |
pl->ptop = p; |
110 |
|
111 |
} |
112 |
|
113 |
|
114 |
|
115 |
|
116 |
add(p, pl) /* add primitive to plist */ |
117 |
|
118 |
register PRIMITIVE *p; |
119 |
register PLIST *pl; |
120 |
|
121 |
{ |
122 |
|
123 |
if (pl->ptop == NULL) |
124 |
pl->ptop = p; |
125 |
else |
126 |
pl->pbot->pnext = p; |
127 |
p->pnext = NULL; |
128 |
pl->pbot = p; |
129 |
|
130 |
} |
131 |
|
132 |
|
133 |
|
134 |
|
135 |
append(pl1, pl2) /* append pl1 to the end of pl2 */ |
136 |
|
137 |
register PLIST *pl1, *pl2; |
138 |
|
139 |
{ |
140 |
|
141 |
if (pl1->ptop != NULL) { |
142 |
if (pl2->ptop != NULL) |
143 |
pl2->pbot->pnext = pl1->ptop; |
144 |
else |
145 |
pl2->ptop = pl1->ptop; |
146 |
pl2->pbot = pl1->pbot; |
147 |
} |
148 |
|
149 |
} |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
fargs(p) /* free any arguments p has */ |
155 |
|
156 |
register PRIMITIVE *p; |
157 |
|
158 |
{ |
159 |
|
160 |
if (p->args != NULL) { |
161 |
freestr(p->args); |
162 |
p->args = NULL; |
163 |
} |
164 |
|
165 |
} |
166 |
|
167 |
|
168 |
|
169 |
char * |
170 |
nextscan(start, format, result) /* scan and advance through string */ |
171 |
|
172 |
register char *start; |
173 |
char *format; |
174 |
char *result; |
175 |
|
176 |
{ |
177 |
|
178 |
if (start == NULL) return(NULL); |
179 |
|
180 |
while (isspace(*start)) start++; |
181 |
|
182 |
if (sscanf(start, format, result) != 1) return(NULL); |
183 |
|
184 |
while (*start && !isspace(*start)) start++; |
185 |
|
186 |
return(start); |
187 |
} |
188 |
|
189 |
|
190 |
|
191 |
mcopy(p1, p2, n) /* copy p2 into p1 size n */ |
192 |
|
193 |
register char *p1, *p2; |
194 |
register int n; |
195 |
|
196 |
{ |
197 |
|
198 |
while (n--) |
199 |
*p1++ = *p2++; |
200 |
|
201 |
} |
202 |
|