7 |
|
* 9/11/87 |
8 |
|
*/ |
9 |
|
|
10 |
– |
#include <stdio.h> |
11 |
– |
|
10 |
|
#include <stdlib.h> |
11 |
< |
|
11 |
> |
#include <stdio.h> |
12 |
> |
#include <string.h> |
13 |
|
#include <math.h> |
15 |
– |
|
14 |
|
#include <ctype.h> |
15 |
|
|
16 |
+ |
#include "platform.h" |
17 |
|
#include "calcomp.h" |
18 |
+ |
#include "rterror.h" |
19 |
|
|
20 |
– |
#ifdef CPM |
21 |
– |
#define getc agetc /* text files only, right? */ |
22 |
– |
#endif |
23 |
– |
|
20 |
|
#define isnum(c) (isdigit(c) || (c)=='-' || (c)=='.' \ |
21 |
|
|| (c)=='+' || (c)=='e' || (c)=='E') |
22 |
|
|
54 |
|
#define savqstr(s) strcpy(emalloc(strlen(s)+1),s) |
55 |
|
#define freqstr(s) efree(s) |
56 |
|
|
57 |
< |
extern char *strcpy(), *emalloc(), *savestr(); |
58 |
< |
struct strvar *getsvar(); |
57 |
> |
static void scaninp(void), advinp(void), resetinp(void); |
58 |
> |
static void putrec(void), putout(void), nbsynch(void); |
59 |
> |
static int getrec(void); |
60 |
> |
static void execute(char *file); |
61 |
> |
static void initinp(FILE *fp); |
62 |
> |
static void svpreset(char *eqn); |
63 |
> |
static void readfmt(char *spec, int output); |
64 |
> |
static int readfield(char **pp); |
65 |
> |
static int getfield(struct field *f); |
66 |
> |
static void chanset(int n, double v); |
67 |
> |
static void bchanset(int n, double v); |
68 |
> |
static struct strvar* getsvar(char *svname); |
69 |
|
|
70 |
|
struct field *inpfmt = NULL; /* input record format */ |
71 |
|
struct field *outfmt = NULL; /* output record structure */ |
94 |
|
} ipb; /* circular lookahead buffer */ |
95 |
|
|
96 |
|
|
97 |
< |
main(argc, argv) |
98 |
< |
int argc; |
99 |
< |
char *argv[]; |
97 |
> |
int |
98 |
> |
main( |
99 |
> |
int argc, |
100 |
> |
char *argv[] |
101 |
> |
) |
102 |
|
{ |
103 |
|
int i; |
104 |
|
|
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
< |
nbsynch() /* non-blank starting synch character */ |
211 |
> |
static void |
212 |
> |
nbsynch(void) /* non-blank starting synch character */ |
213 |
|
{ |
214 |
|
if (inpfmt == NULL || (inpfmt->type & F_TYP) != T_LIT) |
215 |
|
return; |
221 |
|
|
222 |
|
|
223 |
|
int |
224 |
< |
getinputrec(fp) /* get next input record */ |
225 |
< |
FILE *fp; |
224 |
> |
getinputrec( /* get next input record */ |
225 |
> |
FILE *fp |
226 |
> |
) |
227 |
|
{ |
228 |
|
if (inpfmt != NULL) |
229 |
|
return(getrec()); |
237 |
|
} |
238 |
|
|
239 |
|
|
240 |
< |
execute(file) /* process a file */ |
241 |
< |
char *file; |
240 |
> |
static void |
241 |
> |
execute( /* process a file */ |
242 |
> |
char *file |
243 |
> |
) |
244 |
|
{ |
245 |
|
int conditional = vardefined("cond"); |
246 |
|
long nrecs = 0; |
270 |
|
} |
271 |
|
|
272 |
|
|
273 |
< |
putout() /* produce an output record */ |
273 |
> |
static void |
274 |
> |
putout(void) /* produce an output record */ |
275 |
|
{ |
263 |
– |
extern void chanset(), bchanset(); |
276 |
|
|
277 |
|
colpos = 0; |
278 |
|
if (outfmt != NULL) |
281 |
|
chanout(bchanset); |
282 |
|
else |
283 |
|
chanout(chanset); |
284 |
< |
if (colpos && !bchanset) |
284 |
> |
if (colpos && !bocols) |
285 |
|
putchar('\n'); |
286 |
|
if (unbuff) |
287 |
|
fflush(stdout); |
289 |
|
|
290 |
|
|
291 |
|
double |
292 |
< |
chanvalue(n) /* return value for column n */ |
293 |
< |
int n; |
292 |
> |
chanvalue( /* return value for column n */ |
293 |
> |
int n |
294 |
> |
) |
295 |
|
{ |
296 |
|
int i; |
297 |
|
register char *cp; |
342 |
|
|
343 |
|
|
344 |
|
void |
345 |
< |
chanset(n, v) /* output column n */ |
346 |
< |
int n; |
347 |
< |
double v; |
345 |
> |
chanset( /* output column n */ |
346 |
> |
int n, |
347 |
> |
double v |
348 |
> |
) |
349 |
|
{ |
350 |
|
if (colpos == 0) /* no leading separator */ |
351 |
|
colpos = 1; |
358 |
|
|
359 |
|
|
360 |
|
void |
361 |
< |
bchanset(n, v) /* output binary channel n */ |
362 |
< |
int n; |
363 |
< |
double v; |
361 |
> |
bchanset( /* output binary channel n */ |
362 |
> |
int n, |
363 |
> |
double v |
364 |
> |
) |
365 |
|
{ |
366 |
|
static char zerobuf[sizeof(double)]; |
367 |
|
|
378 |
|
} |
379 |
|
|
380 |
|
|
381 |
< |
readfmt(spec, output) /* read record format */ |
382 |
< |
char *spec; |
383 |
< |
int output; |
381 |
> |
static void |
382 |
> |
readfmt( /* read record format */ |
383 |
> |
char *spec, |
384 |
> |
int output |
385 |
> |
) |
386 |
|
{ |
387 |
|
int fd; |
388 |
|
char *inptr; |
446 |
|
} |
447 |
|
|
448 |
|
|
449 |
< |
int |
450 |
< |
readfield(pp) /* get next field in format */ |
451 |
< |
register char **pp; |
449 |
> |
static int |
450 |
> |
readfield( /* get next field in format */ |
451 |
> |
register char **pp |
452 |
> |
) |
453 |
|
{ |
454 |
|
int type = F_NUL; |
455 |
|
int width = 0; |
514 |
|
|
515 |
|
|
516 |
|
struct strvar * |
517 |
< |
getsvar(svname) /* get string variable */ |
518 |
< |
char *svname; |
517 |
> |
getsvar( /* get string variable */ |
518 |
> |
char *svname |
519 |
> |
) |
520 |
|
{ |
521 |
|
register struct strvar *sv; |
522 |
|
|
532 |
|
} |
533 |
|
|
534 |
|
|
535 |
< |
svpreset(eqn) /* preset a string variable */ |
536 |
< |
char *eqn; |
535 |
> |
static void |
536 |
> |
svpreset( /* preset a string variable */ |
537 |
> |
char *eqn |
538 |
> |
) |
539 |
|
{ |
540 |
|
register struct strvar *sv; |
541 |
|
register char *val; |
554 |
|
} |
555 |
|
|
556 |
|
|
557 |
< |
clearrec() /* clear input record variables */ |
557 |
> |
static void |
558 |
> |
clearrec(void) /* clear input record variables */ |
559 |
|
{ |
560 |
|
register struct field *f; |
561 |
|
|
574 |
|
} |
575 |
|
|
576 |
|
|
577 |
< |
getrec() /* get next record from file */ |
577 |
> |
static int |
578 |
> |
getrec(void) /* get next record from file */ |
579 |
|
{ |
580 |
|
int eatline; |
581 |
|
register struct field *f; |
608 |
|
} |
609 |
|
|
610 |
|
|
611 |
< |
getfield(f) /* get next field */ |
612 |
< |
register struct field *f; |
611 |
> |
static int |
612 |
> |
getfield( /* get next field */ |
613 |
> |
register struct field *f |
614 |
> |
) |
615 |
|
{ |
616 |
< |
static char buf[MAXWORD+1]; /* no recursion! */ |
616 |
> |
static char buf[RMAXWORD+1]; /* no recursion! */ |
617 |
|
int delim, inword; |
618 |
|
double d; |
619 |
|
char *np; |
658 |
|
*cp++ = ipb.chr; |
659 |
|
scaninp(); |
660 |
|
} |
661 |
< |
} while (inword && cp < &buf[MAXWORD]); |
661 |
> |
} while (inword && cp < &buf[RMAXWORD]); |
662 |
|
*cp = '\0'; |
663 |
|
if (f->f.sv->val == NULL) |
664 |
|
f->f.sv->val = savqstr(buf); /* first setting */ |
687 |
|
*cp++ = ipb.chr; |
688 |
|
scaninp(); |
689 |
|
} |
690 |
< |
} while (inword && cp < &buf[MAXWORD]); |
690 |
> |
} while (inword && cp < &buf[RMAXWORD]); |
691 |
|
*cp = '\0'; |
692 |
|
d = np==NULL ? 0. : atof(np); |
693 |
|
if (!vardefined(f->f.nv)) |
697 |
|
return(-1); /* doesn't match! */ |
698 |
|
return(0); |
699 |
|
} |
700 |
+ |
return -1; /* pro forma return */ |
701 |
|
} |
702 |
|
|
703 |
|
|
704 |
< |
putrec() /* output a record */ |
704 |
> |
static void |
705 |
> |
putrec(void) /* output a record */ |
706 |
|
{ |
707 |
|
char fmt[32]; |
708 |
|
register int n; |
752 |
|
} |
753 |
|
|
754 |
|
|
755 |
< |
initinp(fp) /* prepare lookahead buffer */ |
756 |
< |
FILE *fp; |
755 |
> |
static void |
756 |
> |
initinp(FILE *fp) /* prepare lookahead buffer */ |
757 |
> |
|
758 |
|
{ |
759 |
|
ipb.fin = fp; |
760 |
|
ipb.beg = ipb.end = inpbuf; |
764 |
|
} |
765 |
|
|
766 |
|
|
767 |
< |
scaninp() /* scan next character */ |
767 |
> |
static void |
768 |
> |
scaninp(void) /* scan next character */ |
769 |
|
{ |
770 |
|
if (ipb.chr == EOF) |
771 |
|
return; |
784 |
|
} |
785 |
|
|
786 |
|
|
787 |
< |
advinp() /* move home to current position */ |
787 |
> |
static void |
788 |
> |
advinp(void) /* move home to current position */ |
789 |
|
{ |
790 |
|
ipb.beg = ipb.pos; |
791 |
|
} |
792 |
|
|
793 |
|
|
794 |
< |
resetinp() /* rewind position and advance 1 */ |
794 |
> |
static void |
795 |
> |
resetinp(void) /* rewind position and advance 1 */ |
796 |
|
{ |
797 |
|
if (ipb.beg == NULL) /* full */ |
798 |
|
ipb.beg = ipb.end; |
805 |
|
|
806 |
|
|
807 |
|
void |
808 |
< |
eputs(msg) |
778 |
< |
char *msg; |
808 |
> |
eputs(char *msg) |
809 |
|
{ |
810 |
|
fputs(msg, stderr); |
811 |
|
} |
812 |
|
|
813 |
|
|
814 |
|
void |
815 |
< |
wputs(msg) |
786 |
< |
char *msg; |
815 |
> |
wputs(char *msg) |
816 |
|
{ |
817 |
|
if (!nowarn) |
818 |
|
eputs(msg); |
820 |
|
|
821 |
|
|
822 |
|
void |
823 |
< |
quit(code) |
795 |
< |
int code; |
823 |
> |
quit(int code) |
824 |
|
{ |
825 |
|
exit(code); |
826 |
|
} |