47 | 47 |
/* prototypes */
|
48 | 48 |
|
49 | 49 |
/* word-handling */
|
50 | |
struct word *addword(const char *name, const char *macro, int fcn);
|
51 | |
struct word *lookup(char *name);
|
|
50 |
struct word *addword(const char *, const char *, int);
|
|
51 |
struct word *lookup(const char *);
|
52 | 52 |
void initwords(void);
|
53 | 53 |
void makeword(void);
|
54 | 54 |
|
55 | 55 |
/* variable-handling */
|
56 | |
struct vari *addvari(char *name);
|
57 | |
struct vari *getvari(char *name);
|
58 | |
void setvari(char *name, signed long value);
|
|
56 |
struct vari *addvari(char *);
|
|
57 |
struct vari *getvari(char *);
|
|
58 |
void setvari(char *, signed long);
|
59 | 59 |
|
60 | 60 |
/* stack-handling */
|
61 | |
void push(signed long val);
|
|
61 |
void push(signed long);
|
62 | 62 |
signed long pop(void);
|
63 | 63 |
|
64 | 64 |
/* functions */
|
65 | |
void dofunc(struct word * w);
|
|
65 |
void dofunc(struct word *);
|
66 | 66 |
void words(void);
|
67 | 67 |
void vars(void);
|
68 | 68 |
signed long sizestack(void);
|
69 | 69 |
|
70 | 70 |
/* parsing and interpreting */
|
71 | |
void process(char *s);
|
72 | |
void procstr(char *s);
|
|
71 |
char *strdupe(const char *);
|
|
72 |
void process(char *);
|
|
73 |
void procstr(char *);
|
73 | 74 |
|
74 | 75 |
/* entry point */
|
75 | 76 |
int main(int, char **);
|
|
171 | 172 |
printf("unknown command '%s'\n", s);
|
172 | 173 |
}
|
173 | 174 |
|
|
175 |
char *strdupe(const char *s)
|
|
176 |
{
|
|
177 |
char *t = malloc(strlen(s) + 1);
|
|
178 |
strcpy(t, s);
|
|
179 |
return t;
|
|
180 |
}
|
|
181 |
|
174 | 182 |
/*
|
175 | 183 |
* processes each word in the string s.
|
176 | 184 |
* strtok doesn't work with recursion :-(
|
177 | 185 |
*/
|
178 | 186 |
void procstr(char *s)
|
179 | 187 |
{
|
180 | |
char *h=(char *)strdup(s);
|
|
188 |
char *h=strdupe(s);
|
181 | 189 |
char *g, *gg;
|
182 | 190 |
g = h;
|
183 | 191 |
|
|
198 | 206 |
g++;
|
199 | 207 |
}
|
200 | 208 |
|
201 | |
free(h); /* called with strdup(), so we must free */
|
|
209 |
free(h); /* called with strdupe(), so we must free */
|
202 | 210 |
}
|
203 | 211 |
|
204 | 212 |
/*
|
|
215 | 223 |
}
|
216 | 224 |
new = (struct word *) malloc(sizeof(struct word));
|
217 | 225 |
strcpy(new->name, name);
|
218 | |
new->macro = (char *)strdup(macro);
|
|
226 |
new->macro = strdupe(macro);
|
219 | 227 |
new->fcn = fcn;
|
220 | 228 |
|
221 | 229 |
new->next = whead;
|
|
227 | 235 |
* attempts to find the word 'name' in the words list. returns NULL if it
|
228 | 236 |
* could not be found.
|
229 | 237 |
*/
|
230 | |
struct word *lookup(char *name)
|
|
238 |
struct word *lookup(const char *name)
|
231 | 239 |
{
|
232 | 240 |
struct word *l = whead;
|
233 | 241 |
struct word *k = NULL;
|