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