1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
1.3 |
static const char RCSid[] = "$Id: misc.c,v 1.2 2003/07/03 22:41:44 schorsch 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 |
|
|
int |
19 |
|
|
comndx(c) /* return index for command */ |
20 |
|
|
|
21 |
|
|
register int c; |
22 |
|
|
|
23 |
|
|
{ |
24 |
|
|
register char *cp; |
25 |
|
|
|
26 |
|
|
if (!isalpha(c)) |
27 |
|
|
return(-1); |
28 |
|
|
|
29 |
|
|
for (cp = coms; *cp; cp++) |
30 |
|
|
if(*cp == c) |
31 |
|
|
return(cp-coms); |
32 |
|
|
|
33 |
|
|
return(-1); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
PRIMITIVE * |
42 |
|
|
pop(pl) /* pop top off plist */ |
43 |
|
|
|
44 |
|
|
register PLIST *pl; |
45 |
|
|
|
46 |
|
|
{ |
47 |
|
|
register PRIMITIVE *p; |
48 |
|
|
|
49 |
|
|
if ((p = pl->ptop) != NULL) { |
50 |
|
|
if ((pl->ptop = p->pnext) == NULL) |
51 |
|
|
pl->pbot = NULL; |
52 |
|
|
p->pnext = NULL; |
53 |
|
|
} |
54 |
|
|
|
55 |
|
|
return(p); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
push(p, pl) /* push primitive onto plist */ |
62 |
|
|
|
63 |
|
|
register PRIMITIVE *p; |
64 |
|
|
register PLIST *pl; |
65 |
|
|
|
66 |
|
|
{ |
67 |
|
|
|
68 |
|
|
if ((p->pnext = pl->ptop) == NULL) |
69 |
|
|
pl->pbot = p; |
70 |
|
|
pl->ptop = p; |
71 |
|
|
|
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
add(p, pl) /* add primitive to plist */ |
78 |
|
|
|
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 |
|
|
|
96 |
|
|
append(pl1, pl2) /* append pl1 to the end of pl2 */ |
97 |
|
|
|
98 |
|
|
register PLIST *pl1, *pl2; |
99 |
|
|
|
100 |
|
|
{ |
101 |
|
|
|
102 |
|
|
if (pl1->ptop != NULL) { |
103 |
|
|
if (pl2->ptop != NULL) |
104 |
|
|
pl2->pbot->pnext = pl1->ptop; |
105 |
|
|
else |
106 |
|
|
pl2->ptop = pl1->ptop; |
107 |
|
|
pl2->pbot = pl1->pbot; |
108 |
|
|
} |
109 |
|
|
|
110 |
|
|
} |
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
fargs(p) /* free any arguments p has */ |
116 |
|
|
|
117 |
|
|
register PRIMITIVE *p; |
118 |
|
|
|
119 |
|
|
{ |
120 |
|
|
|
121 |
|
|
if (p->args != NULL) { |
122 |
|
|
freestr(p->args); |
123 |
|
|
p->args = NULL; |
124 |
|
|
} |
125 |
|
|
|
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
char * |
131 |
|
|
nextscan(start, format, result) /* scan and advance through string */ |
132 |
|
|
|
133 |
|
|
register char *start; |
134 |
|
|
char *format; |
135 |
|
|
char *result; |
136 |
|
|
|
137 |
|
|
{ |
138 |
|
|
|
139 |
|
|
if (start == NULL) return(NULL); |
140 |
|
|
|
141 |
|
|
while (isspace(*start)) start++; |
142 |
|
|
|
143 |
|
|
if (sscanf(start, format, result) != 1) return(NULL); |
144 |
|
|
|
145 |
|
|
while (*start && !isspace(*start)) start++; |
146 |
|
|
|
147 |
|
|
return(start); |
148 |
|
|
} |
149 |
|
|
|
150 |
|
|
|
151 |
|
|
|
152 |
|
|
mcopy(p1, p2, n) /* copy p2 into p1 size n */ |
153 |
|
|
|
154 |
|
|
register char *p1, *p2; |
155 |
|
|
register int n; |
156 |
|
|
|
157 |
|
|
{ |
158 |
|
|
|
159 |
|
|
while (n--) |
160 |
|
|
*p1++ = *p2++; |
161 |
|
|
|
162 |
|
|
} |
163 |
|
|
|