10 |
|
*/ |
11 |
|
|
12 |
|
#include <stdio.h> |
13 |
– |
|
13 |
|
#include <ctype.h> |
15 |
– |
|
14 |
|
#include <setjmp.h> |
15 |
|
|
16 |
|
#include "rtprocess.h" |
17 |
+ |
#include "rterror.h" |
18 |
+ |
#include "meta.h" |
19 |
+ |
#include "mgraph.h" |
20 |
|
#include "mgvars.h" |
21 |
|
|
22 |
|
typedef struct { |
69 |
|
|
70 |
|
static char curfile[64] = "temp.plt"; /* current file name */ |
71 |
|
|
72 |
< |
char *getfile(), *gets(), *strcpy(); |
72 |
> |
static void mainmenu(void); |
73 |
> |
static void uwait(void); |
74 |
> |
static void gcompute(void); |
75 |
> |
static void setvars(int nvar, VARIABLE vars[]); |
76 |
> |
static void plotout(void); |
77 |
> |
static void settype(void); |
78 |
> |
static char *getfile(void); |
79 |
|
|
80 |
< |
|
80 |
> |
int |
81 |
|
main(argc, argv) |
82 |
|
int argc; |
83 |
|
char *argv[]; |
98 |
|
mainmenu(); |
99 |
|
|
100 |
|
quit(0); |
101 |
+ |
return 0; /* pro forma return */ |
102 |
|
} |
103 |
|
|
104 |
< |
|
105 |
< |
eputs(msg) /* print error message */ |
98 |
< |
char *msg; |
104 |
> |
void |
105 |
> |
eputs(const char *msg) /* print error message */ |
106 |
|
{ |
107 |
|
fputs(msg, stderr); |
108 |
|
} |
109 |
|
|
110 |
< |
|
111 |
< |
quit(code) /* recover or quit */ |
105 |
< |
int code; |
110 |
> |
void |
111 |
> |
quit(int code) /* recover or quit */ |
112 |
|
{ |
113 |
|
if (code && recover--) |
114 |
|
longjmp(env, 1); |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
< |
mainmenu() /* the main menu loop */ |
119 |
> |
static void |
120 |
> |
mainmenu(void) /* the main menu loop */ |
121 |
|
{ |
122 |
|
char sbuf[128]; |
123 |
|
|
135 |
|
printf("\t10 Quit\n"); |
136 |
|
|
137 |
|
printf("\nChoice: "); |
138 |
< |
clearerr(stdin); gets(sbuf); |
138 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
139 |
|
if (feof(stdin)) |
140 |
|
return; |
141 |
|
switch (atoi(sbuf)) { |
166 |
|
break; |
167 |
|
case 6: /* set curve variable */ |
168 |
|
printf("\nCurve (A-%c): ", MAXCUR-1+'A'); |
169 |
< |
clearerr(stdin); gets(sbuf); |
169 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
170 |
|
if (islower(sbuf[0])) |
171 |
|
sbuf[0] -= 'a'; |
172 |
|
else if (isupper(sbuf[0])) |
174 |
|
else |
175 |
|
break; |
176 |
|
if (sbuf[0] < MAXCUR) |
177 |
< |
setvars(NCVARS, cparam[sbuf[0]]); |
177 |
> |
setvars(NCVARS, cparam[(int)sbuf[0]]); |
178 |
|
break; |
179 |
|
case 7: /* output plot */ |
180 |
|
plotout(); |
181 |
|
break; |
182 |
|
case 8: /* escape command */ |
183 |
|
printf("\nCommand: "); |
184 |
< |
clearerr(stdin); gets(sbuf); |
184 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
185 |
|
if (sbuf[0]) { |
186 |
|
system(sbuf); |
187 |
|
uwait(); |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
< |
char * |
201 |
< |
getfile() /* get file name from user */ |
200 |
> |
static char * |
201 |
> |
getfile(void) /* get file name from user */ |
202 |
|
{ |
203 |
|
char sbuf[128]; |
204 |
|
|
205 |
|
printf("\nFile (%s): ", curfile); |
206 |
< |
clearerr(stdin); gets(sbuf); |
206 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
207 |
|
if (sbuf[0] == '-') |
208 |
|
return(NULL); |
209 |
|
if (sbuf[0]) |
211 |
|
return(curfile); |
212 |
|
} |
213 |
|
|
214 |
< |
|
215 |
< |
settype() /* set plot type */ |
214 |
> |
static void |
215 |
> |
settype(void) /* set plot type */ |
216 |
|
{ |
217 |
|
char sbuf[128]; |
218 |
|
int i; |
223 |
|
printf("\t%d %s\n", i+1, typ[i].descrip); |
224 |
|
|
225 |
|
printf("\nChoice (0): "); |
226 |
< |
clearerr(stdin); gets(sbuf); |
226 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
227 |
|
i = atoi(sbuf) - 1; |
228 |
|
if (i < 0 || i >= NTYP) |
229 |
|
return; |
232 |
|
} |
233 |
|
|
234 |
|
|
235 |
< |
plotout() /* output our graph */ |
235 |
> |
static void |
236 |
> |
plotout(void) /* output our graph */ |
237 |
|
{ |
238 |
|
extern FILE *pout; |
239 |
|
char sbuf[128]; |
240 |
< |
char *command; |
240 |
> |
char *command = NULL; |
241 |
|
int i; |
242 |
|
|
243 |
|
printf("\nOUTPUT PLOT\n"); |
248 |
|
printf("\t%d Other\n", NDEV+2); |
249 |
|
|
250 |
|
printf("\nChoice (0): "); |
251 |
< |
clearerr(stdin); gets(sbuf); |
251 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
252 |
|
i = atoi(sbuf) - 1; |
253 |
|
if (i < 0 || i > NDEV+1) |
254 |
|
return; |
264 |
|
return; |
265 |
|
} else if (i == NDEV+1) { |
266 |
|
printf("\nDriver command: "); |
267 |
< |
clearerr(stdin); gets(sbuf); |
267 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
268 |
|
if (!sbuf[0]) |
269 |
|
return; |
270 |
|
command = sbuf; |
285 |
|
} |
286 |
|
|
287 |
|
|
288 |
< |
setvars(nvar, vars) /* set variables */ |
289 |
< |
int nvar; |
290 |
< |
VARIABLE vars[]; |
288 |
> |
static void |
289 |
> |
setvars( /* set variables */ |
290 |
> |
int nvar, |
291 |
> |
VARIABLE vars[]) |
292 |
|
{ |
293 |
|
char sbuf[128]; |
294 |
|
int i, j; |
301 |
|
vars[i].name : vars[i].descrip); |
302 |
|
|
303 |
|
printf("\nChoice (0): "); |
304 |
< |
clearerr(stdin); gets(sbuf); |
304 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
305 |
|
i = atoi(sbuf) - 1; |
306 |
|
if (i < 0 || i >= nvar) |
307 |
|
return; |
318 |
|
else |
319 |
|
sprintf(sbuf, "%s=", vars[i].name); |
320 |
|
j = strlen(sbuf); |
321 |
< |
clearerr(stdin); gets(sbuf+j); |
321 |
> |
clearerr(stdin); fgets(sbuf+j, sizeof(sbuf)-j, stdin); |
322 |
|
if (sbuf[j]) { |
323 |
|
if (vars[i].type == DATA && sbuf[j] == '-') |
324 |
|
sbuf[j] = '\0'; |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
< |
gcompute() /* do a computation */ |
337 |
> |
static void |
338 |
> |
gcompute(void) /* do a computation */ |
339 |
|
{ |
340 |
|
char sbuf[64]; |
341 |
|
int i; |
346 |
|
printf("\t%d %s\n", i+1, cal[i].descrip); |
347 |
|
|
348 |
|
printf("\nChoice (0): "); |
349 |
< |
clearerr(stdin); gets(sbuf); |
349 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
350 |
|
i = atoi(sbuf) - 1; |
351 |
|
if (i < 0 || i >= NCAL) |
352 |
|
return; |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
< |
uwait() /* wait for user after command, error */ |
364 |
> |
static void |
365 |
> |
uwait(void) /* wait for user after command, error */ |
366 |
|
{ |
367 |
|
printf("Hit return to continue: "); |
368 |
|
while (getchar() != '\n') |