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 "mgvars.h" |
19 |
|
|
20 |
|
typedef struct { |
67 |
|
|
68 |
|
static char curfile[64] = "temp.plt"; /* current file name */ |
69 |
|
|
70 |
< |
char *getfile(), *gets(), *strcpy(); |
70 |
> |
static void mainmenu(void); |
71 |
> |
static void uwait(void); |
72 |
> |
static void gcompute(void); |
73 |
> |
static void setvars(int nvar, VARIABLE vars[]); |
74 |
> |
static void plotout(void); |
75 |
> |
static void settype(void); |
76 |
> |
static char *getfile(void); |
77 |
|
|
78 |
< |
|
78 |
> |
int |
79 |
|
main(argc, argv) |
80 |
|
int argc; |
81 |
|
char *argv[]; |
98 |
|
quit(0); |
99 |
|
} |
100 |
|
|
101 |
< |
|
101 |
> |
extern void |
102 |
|
eputs(msg) /* print error message */ |
103 |
|
char *msg; |
104 |
|
{ |
105 |
|
fputs(msg, stderr); |
106 |
|
} |
107 |
|
|
108 |
< |
|
108 |
> |
extern void |
109 |
|
quit(code) /* recover or quit */ |
110 |
|
int code; |
111 |
|
{ |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
< |
mainmenu() /* the main menu loop */ |
118 |
> |
static void |
119 |
> |
mainmenu(void) /* the main menu loop */ |
120 |
|
{ |
121 |
|
char sbuf[128]; |
122 |
|
|
134 |
|
printf("\t10 Quit\n"); |
135 |
|
|
136 |
|
printf("\nChoice: "); |
137 |
< |
clearerr(stdin); gets(sbuf); |
137 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
138 |
|
if (feof(stdin)) |
139 |
|
return; |
140 |
|
switch (atoi(sbuf)) { |
165 |
|
break; |
166 |
|
case 6: /* set curve variable */ |
167 |
|
printf("\nCurve (A-%c): ", MAXCUR-1+'A'); |
168 |
< |
clearerr(stdin); gets(sbuf); |
168 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
169 |
|
if (islower(sbuf[0])) |
170 |
|
sbuf[0] -= 'a'; |
171 |
|
else if (isupper(sbuf[0])) |
180 |
|
break; |
181 |
|
case 8: /* escape command */ |
182 |
|
printf("\nCommand: "); |
183 |
< |
clearerr(stdin); gets(sbuf); |
183 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
184 |
|
if (sbuf[0]) { |
185 |
|
system(sbuf); |
186 |
|
uwait(); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
< |
char * |
200 |
< |
getfile() /* get file name from user */ |
199 |
> |
static char * |
200 |
> |
getfile(void) /* get file name from user */ |
201 |
|
{ |
202 |
|
char sbuf[128]; |
203 |
|
|
204 |
|
printf("\nFile (%s): ", curfile); |
205 |
< |
clearerr(stdin); gets(sbuf); |
205 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
206 |
|
if (sbuf[0] == '-') |
207 |
|
return(NULL); |
208 |
|
if (sbuf[0]) |
210 |
|
return(curfile); |
211 |
|
} |
212 |
|
|
213 |
< |
|
214 |
< |
settype() /* set plot type */ |
213 |
> |
static void |
214 |
> |
settype(void) /* set plot type */ |
215 |
|
{ |
216 |
|
char sbuf[128]; |
217 |
|
int i; |
222 |
|
printf("\t%d %s\n", i+1, typ[i].descrip); |
223 |
|
|
224 |
|
printf("\nChoice (0): "); |
225 |
< |
clearerr(stdin); gets(sbuf); |
225 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
226 |
|
i = atoi(sbuf) - 1; |
227 |
|
if (i < 0 || i >= NTYP) |
228 |
|
return; |
231 |
|
} |
232 |
|
|
233 |
|
|
234 |
< |
plotout() /* output our graph */ |
234 |
> |
static void |
235 |
> |
plotout(void) /* output our graph */ |
236 |
|
{ |
237 |
|
extern FILE *pout; |
238 |
|
char sbuf[128]; |
247 |
|
printf("\t%d Other\n", NDEV+2); |
248 |
|
|
249 |
|
printf("\nChoice (0): "); |
250 |
< |
clearerr(stdin); gets(sbuf); |
250 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
251 |
|
i = atoi(sbuf) - 1; |
252 |
|
if (i < 0 || i > NDEV+1) |
253 |
|
return; |
263 |
|
return; |
264 |
|
} else if (i == NDEV+1) { |
265 |
|
printf("\nDriver command: "); |
266 |
< |
clearerr(stdin); gets(sbuf); |
266 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
267 |
|
if (!sbuf[0]) |
268 |
|
return; |
269 |
|
command = sbuf; |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
< |
setvars(nvar, vars) /* set variables */ |
288 |
< |
int nvar; |
289 |
< |
VARIABLE vars[]; |
287 |
> |
static void |
288 |
> |
setvars( /* set variables */ |
289 |
> |
int nvar, |
290 |
> |
VARIABLE vars[]) |
291 |
|
{ |
292 |
|
char sbuf[128]; |
293 |
|
int i, j; |
300 |
|
vars[i].name : vars[i].descrip); |
301 |
|
|
302 |
|
printf("\nChoice (0): "); |
303 |
< |
clearerr(stdin); gets(sbuf); |
303 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
304 |
|
i = atoi(sbuf) - 1; |
305 |
|
if (i < 0 || i >= nvar) |
306 |
|
return; |
317 |
|
else |
318 |
|
sprintf(sbuf, "%s=", vars[i].name); |
319 |
|
j = strlen(sbuf); |
320 |
< |
clearerr(stdin); gets(sbuf+j); |
320 |
> |
clearerr(stdin); fgets(sbuf+j, sizeof(sbuf)-j, stdin); |
321 |
|
if (sbuf[j]) { |
322 |
|
if (vars[i].type == DATA && sbuf[j] == '-') |
323 |
|
sbuf[j] = '\0'; |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
< |
gcompute() /* do a computation */ |
336 |
> |
static void |
337 |
> |
gcompute(void) /* do a computation */ |
338 |
|
{ |
339 |
|
char sbuf[64]; |
340 |
|
int i; |
345 |
|
printf("\t%d %s\n", i+1, cal[i].descrip); |
346 |
|
|
347 |
|
printf("\nChoice (0): "); |
348 |
< |
clearerr(stdin); gets(sbuf); |
348 |
> |
clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin); |
349 |
|
i = atoi(sbuf) - 1; |
350 |
|
if (i < 0 || i >= NCAL) |
351 |
|
return; |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
< |
uwait() /* wait for user after command, error */ |
363 |
> |
static void |
364 |
> |
uwait(void) /* wait for user after command, error */ |
365 |
|
{ |
366 |
|
printf("Hit return to continue: "); |
367 |
|
while (getchar() != '\n') |