git @ Cat's Eye Technologies Maentwrog / 0b7de78
Tweak Makefile and clean up all warnings (on recent Linux anyway.) Chris Pressey 8 years ago
4 changed file(s) with 37 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
88 -Winline -Wnested-externs -Wredundant-decls
99
1010 ifdef ANSI
11 CFLAGS+= -ansi -pedantic
11 CFLAGS+= -ansi -pedantic -D_BSD_SOURCE
1212 else
13 CFLAGS+= -std=c99 -D_POSIX_C_SOURCE=200112L
13 CFLAGS+= -std=c99 -D_POSIX_C_SOURCE=200809L
1414 endif
1515
1616 CFLAGS+= ${WARNS} ${EXTRA_CFLAGS}
0 #include <stdlib.h>
01 #include <stdio.h>
12 #include <string.h>
23 #include <ctype.h>
2324 int caparse(char *string, int values[]);
2425 int doper(int state, int oper, int modder);
2526
26 main()
27 int main(int argc, char **argv)
2728 {
2829 int values[26] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2930 0, 0, 0, 0, 0, 0, 0, 0, 0 };
3031 char in[255];
3132
33 argc = argc;
34 argv = argv;
3235 while (!feof(stdin))
3336 {
34 gets(in);
37 fgets(in, 255, stdin);
3538 if (isalpha(in[0])&&in[1]=='=')
3639 values[in[0]-'a']=(in[2]-'0');
3740 else
3841 printf("%d\n", caparse(in, values));
3942 }
40
43 return 0;
4144 }
4245
4346 int caparse(char *string, int values[])
9295 case OP_AND : return(state & modder); break;
9396 case OP_XOR : return(state ^ modder); break;
9497 }
98 exit(1);
9599 }
96100
4747 /* prototypes */
4848
4949 /* word-handling */
50 struct word *addword(char *name, char *macro, int fcn);
50 struct word *addword(const char *name, const char *macro, int fcn);
5151 struct word *lookup(char *name);
5252 void initwords(void);
5353 void makeword(void);
7070 /* parsing and interpreting */
7171 void process(char *s);
7272 void procstr(char *s);
73
74 /* entry point */
75 int main(int, char **);
7376
7477 int main(argc, argv)
7578 int argc;
140143 else if (s[0] == '@')
141144 {
142145 if (pop())
143 if (w = lookup(s + 1))
146 if ((w = lookup(s + 1)))
144147 dofunc(w);
145148 }
146149 else if (s[0] == '$')
147150 {
148151 for(i=pop();i;i--)
149 if (w = lookup(s + 1))
152 if ((w = lookup(s + 1)))
150153 dofunc(w);
151154 }
152155 else if (s[0] == '[')
155158 {
156159 if (pop())
157160 {
158 if (w = lookup(s + 1))
161 if ((w = lookup(s + 1)))
159162 dofunc(w);
160163 } else break;
161164 }
162165 }
163 else if (w = lookup(s))
166 else if ((w = lookup(s)))
164167 dofunc(w);
165 else if (v = getvari(s))
168 else if ((v = getvari(s)))
166169 push(v->value);
167170 else
168171 printf("unknown command '%s'\n", s);
201204 /*
202205 * adds a unique word to the list of words.
203206 */
204 struct word *addword(char *name, char *macro, int fcn)
207 struct word *addword(const char *name, const char *macro, int fcn)
205208 {
206209 struct word *new;
207210 for (new = whead; new; new = new->next)
292295 char s[80];
293296 char t[80];
294297 char *y;
295 int size = DEFSIZE;
298 unsigned int size = DEFSIZE;
296299
297300 y = (char *)malloc(size);
298301 scanf("%s", s);
4545 /* prototypes */
4646
4747 /* word-handling */
48 struct word *addword(char *name, char *macro, int fcn);
48 struct word *addword(const char *name, const char *macro, int fcn);
4949 struct word *lookup(char *name);
50 void initwords();
51 void makeword();
50 void initwords(void);
51 void makeword(void);
5252
5353 /* variable-handling */
5454 struct vari *addvari(char *name);
5757
5858 /* stack-handling */
5959 void push(double val);
60 double pop();
60 double pop(void);
6161
6262 /* functions */
6363 void dofunc(struct word * w);
6464 double factorial(double p);
6565 double fibonacci(double p);
66 void words();
67 void vars();
66 void words(void);
67 void vars(void);
6868
6969 /* parsing and interpreting */
7070 void process(char *s);
7171 void procstr(char *s);
7272
73 main(argc, argv)
73 /* entry point */
74 int main(int, char **);
75
76 int main(argc, argv)
7477 int argc;
7578 char **argv;
7679 {
9295 process(s);
9396 i=scanf("%s", s);
9497 }
98 return 0;
9599 }
96100
97101 /*
122126 setvari(s + 1, pop());
123127 else if ((s[0] == '*') && (isalpha(s[1])))
124128 addvari(s + 1);
125 else if (w = lookup(s))
129 else if ((w = lookup(s)))
126130 dofunc(w);
127 else if (v = getvari(s))
131 else if ((v = getvari(s)))
128132 push(v->value);
129133 else
130134 printf("unknown command '%s'\n", s);
135139 */
136140 void procstr(char *s)
137141 {
138 char *h;
142 char *h = (char *)strdup(s);
139143 char *g;
140 h = strdup(s);
141144 g = strtok(h, " ");
142145 while (g)
143146 {
150153 /*
151154 * adds a unique word to the list of words.
152155 */
153 struct word *addword(char *name, char *macro, int fcn)
156 struct word *addword(const char *name, const char *macro, int fcn)
154157 {
155158 struct word *new;
156159 for (new = whead; new; new = new->next)
264267 i=scanf("%s", t);
265268 }
266269 addword(s, y, 0);
270 i=i;
267271 }
268272
269273 /*
315319 strcpy(v->name, name);
316320 v->next = vhead;
317321 vhead = v;
322 return v;
318323 }
319324
320325 /*