Tweak Makefile and clean up all warnings (on recent Linux anyway.)
Chris Pressey
8 years ago
8 | 8 |
-Winline -Wnested-externs -Wredundant-decls
|
9 | 9 |
|
10 | 10 |
ifdef ANSI
|
11 | |
CFLAGS+= -ansi -pedantic
|
|
11 |
CFLAGS+= -ansi -pedantic -D_BSD_SOURCE
|
12 | 12 |
else
|
13 | |
CFLAGS+= -std=c99 -D_POSIX_C_SOURCE=200112L
|
|
13 |
CFLAGS+= -std=c99 -D_POSIX_C_SOURCE=200809L
|
14 | 14 |
endif
|
15 | 15 |
|
16 | 16 |
CFLAGS+= ${WARNS} ${EXTRA_CFLAGS}
|
|
0 |
#include <stdlib.h>
|
0 | 1 |
#include <stdio.h>
|
1 | 2 |
#include <string.h>
|
2 | 3 |
#include <ctype.h>
|
|
23 | 24 |
int caparse(char *string, int values[]);
|
24 | 25 |
int doper(int state, int oper, int modder);
|
25 | 26 |
|
26 | |
main()
|
|
27 |
int main(int argc, char **argv)
|
27 | 28 |
{
|
28 | 29 |
int values[26] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
29 | 30 |
0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
30 | 31 |
char in[255];
|
31 | 32 |
|
|
33 |
argc = argc;
|
|
34 |
argv = argv;
|
32 | 35 |
while (!feof(stdin))
|
33 | 36 |
{
|
34 | |
gets(in);
|
|
37 |
fgets(in, 255, stdin);
|
35 | 38 |
if (isalpha(in[0])&&in[1]=='=')
|
36 | 39 |
values[in[0]-'a']=(in[2]-'0');
|
37 | 40 |
else
|
38 | 41 |
printf("%d\n", caparse(in, values));
|
39 | 42 |
}
|
40 | |
|
|
43 |
return 0;
|
41 | 44 |
}
|
42 | 45 |
|
43 | 46 |
int caparse(char *string, int values[])
|
|
92 | 95 |
case OP_AND : return(state & modder); break;
|
93 | 96 |
case OP_XOR : return(state ^ modder); break;
|
94 | 97 |
}
|
|
98 |
exit(1);
|
95 | 99 |
}
|
96 | 100 |
|
47 | 47 |
/* prototypes */
|
48 | 48 |
|
49 | 49 |
/* word-handling */
|
50 | |
struct word *addword(char *name, char *macro, int fcn);
|
|
50 |
struct word *addword(const char *name, const char *macro, int fcn);
|
51 | 51 |
struct word *lookup(char *name);
|
52 | 52 |
void initwords(void);
|
53 | 53 |
void makeword(void);
|
|
70 | 70 |
/* parsing and interpreting */
|
71 | 71 |
void process(char *s);
|
72 | 72 |
void procstr(char *s);
|
|
73 |
|
|
74 |
/* entry point */
|
|
75 |
int main(int, char **);
|
73 | 76 |
|
74 | 77 |
int main(argc, argv)
|
75 | 78 |
int argc;
|
|
140 | 143 |
else if (s[0] == '@')
|
141 | 144 |
{
|
142 | 145 |
if (pop())
|
143 | |
if (w = lookup(s + 1))
|
|
146 |
if ((w = lookup(s + 1)))
|
144 | 147 |
dofunc(w);
|
145 | 148 |
}
|
146 | 149 |
else if (s[0] == '$')
|
147 | 150 |
{
|
148 | 151 |
for(i=pop();i;i--)
|
149 | |
if (w = lookup(s + 1))
|
|
152 |
if ((w = lookup(s + 1)))
|
150 | 153 |
dofunc(w);
|
151 | 154 |
}
|
152 | 155 |
else if (s[0] == '[')
|
|
155 | 158 |
{
|
156 | 159 |
if (pop())
|
157 | 160 |
{
|
158 | |
if (w = lookup(s + 1))
|
|
161 |
if ((w = lookup(s + 1)))
|
159 | 162 |
dofunc(w);
|
160 | 163 |
} else break;
|
161 | 164 |
}
|
162 | 165 |
}
|
163 | |
else if (w = lookup(s))
|
|
166 |
else if ((w = lookup(s)))
|
164 | 167 |
dofunc(w);
|
165 | |
else if (v = getvari(s))
|
|
168 |
else if ((v = getvari(s)))
|
166 | 169 |
push(v->value);
|
167 | 170 |
else
|
168 | 171 |
printf("unknown command '%s'\n", s);
|
|
201 | 204 |
/*
|
202 | 205 |
* adds a unique word to the list of words.
|
203 | 206 |
*/
|
204 | |
struct word *addword(char *name, char *macro, int fcn)
|
|
207 |
struct word *addword(const char *name, const char *macro, int fcn)
|
205 | 208 |
{
|
206 | 209 |
struct word *new;
|
207 | 210 |
for (new = whead; new; new = new->next)
|
|
292 | 295 |
char s[80];
|
293 | 296 |
char t[80];
|
294 | 297 |
char *y;
|
295 | |
int size = DEFSIZE;
|
|
298 |
unsigned int size = DEFSIZE;
|
296 | 299 |
|
297 | 300 |
y = (char *)malloc(size);
|
298 | 301 |
scanf("%s", s);
|
45 | 45 |
/* prototypes */
|
46 | 46 |
|
47 | 47 |
/* word-handling */
|
48 | |
struct word *addword(char *name, char *macro, int fcn);
|
|
48 |
struct word *addword(const char *name, const char *macro, int fcn);
|
49 | 49 |
struct word *lookup(char *name);
|
50 | |
void initwords();
|
51 | |
void makeword();
|
|
50 |
void initwords(void);
|
|
51 |
void makeword(void);
|
52 | 52 |
|
53 | 53 |
/* variable-handling */
|
54 | 54 |
struct vari *addvari(char *name);
|
|
57 | 57 |
|
58 | 58 |
/* stack-handling */
|
59 | 59 |
void push(double val);
|
60 | |
double pop();
|
|
60 |
double pop(void);
|
61 | 61 |
|
62 | 62 |
/* functions */
|
63 | 63 |
void dofunc(struct word * w);
|
64 | 64 |
double factorial(double p);
|
65 | 65 |
double fibonacci(double p);
|
66 | |
void words();
|
67 | |
void vars();
|
|
66 |
void words(void);
|
|
67 |
void vars(void);
|
68 | 68 |
|
69 | 69 |
/* parsing and interpreting */
|
70 | 70 |
void process(char *s);
|
71 | 71 |
void procstr(char *s);
|
72 | 72 |
|
73 | |
main(argc, argv)
|
|
73 |
/* entry point */
|
|
74 |
int main(int, char **);
|
|
75 |
|
|
76 |
int main(argc, argv)
|
74 | 77 |
int argc;
|
75 | 78 |
char **argv;
|
76 | 79 |
{
|
|
92 | 95 |
process(s);
|
93 | 96 |
i=scanf("%s", s);
|
94 | 97 |
}
|
|
98 |
return 0;
|
95 | 99 |
}
|
96 | 100 |
|
97 | 101 |
/*
|
|
122 | 126 |
setvari(s + 1, pop());
|
123 | 127 |
else if ((s[0] == '*') && (isalpha(s[1])))
|
124 | 128 |
addvari(s + 1);
|
125 | |
else if (w = lookup(s))
|
|
129 |
else if ((w = lookup(s)))
|
126 | 130 |
dofunc(w);
|
127 | |
else if (v = getvari(s))
|
|
131 |
else if ((v = getvari(s)))
|
128 | 132 |
push(v->value);
|
129 | 133 |
else
|
130 | 134 |
printf("unknown command '%s'\n", s);
|
|
135 | 139 |
*/
|
136 | 140 |
void procstr(char *s)
|
137 | 141 |
{
|
138 | |
char *h;
|
|
142 |
char *h = (char *)strdup(s);
|
139 | 143 |
char *g;
|
140 | |
h = strdup(s);
|
141 | 144 |
g = strtok(h, " ");
|
142 | 145 |
while (g)
|
143 | 146 |
{
|
|
150 | 153 |
/*
|
151 | 154 |
* adds a unique word to the list of words.
|
152 | 155 |
*/
|
153 | |
struct word *addword(char *name, char *macro, int fcn)
|
|
156 |
struct word *addword(const char *name, const char *macro, int fcn)
|
154 | 157 |
{
|
155 | 158 |
struct word *new;
|
156 | 159 |
for (new = whead; new; new = new->next)
|
|
264 | 267 |
i=scanf("%s", t);
|
265 | 268 |
}
|
266 | 269 |
addword(s, y, 0);
|
|
270 |
i=i;
|
267 | 271 |
}
|
268 | 272 |
|
269 | 273 |
/*
|
|
315 | 319 |
strcpy(v->name, name);
|
316 | 320 |
v->next = vhead;
|
317 | 321 |
vhead = v;
|
|
322 |
return v;
|
318 | 323 |
}
|
319 | 324 |
|
320 | 325 |
/*
|