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 |
|
|
147 |
|
nbicols = atoi(argv[i]+3); |
148 |
|
else |
149 |
|
nbicols = 1; |
150 |
+ |
if (nbicols*sizeof(double) > INBSIZ) { |
151 |
+ |
eputs(argv[0]); |
152 |
+ |
eputs(": too many input columns\n"); |
153 |
+ |
quit(1); |
154 |
+ |
} |
155 |
|
break; |
156 |
|
case 'f': |
157 |
|
if (isdigit(argv[i][3])) |
158 |
|
nbicols = -atoi(argv[i]+3); |
159 |
|
else |
160 |
|
nbicols = -1; |
161 |
+ |
if (-nbicols*sizeof(float) > INBSIZ) { |
162 |
+ |
eputs(argv[0]); |
163 |
+ |
eputs(": too many input columns\n"); |
164 |
+ |
quit(1); |
165 |
+ |
} |
166 |
|
break; |
167 |
|
default: |
168 |
|
goto userr; |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
< |
nbsynch() /* non-blank starting synch character */ |
221 |
> |
static void |
222 |
> |
nbsynch(void) /* non-blank starting synch character */ |
223 |
|
{ |
224 |
|
if (inpfmt == NULL || (inpfmt->type & F_TYP) != T_LIT) |
225 |
|
return; |
231 |
|
|
232 |
|
|
233 |
|
int |
234 |
< |
getinputrec(fp) /* get next input record */ |
235 |
< |
FILE *fp; |
234 |
> |
getinputrec( /* get next input record */ |
235 |
> |
FILE *fp |
236 |
> |
) |
237 |
|
{ |
238 |
|
if (inpfmt != NULL) |
239 |
|
return(getrec()); |
247 |
|
} |
248 |
|
|
249 |
|
|
250 |
< |
execute(file) /* process a file */ |
251 |
< |
char *file; |
250 |
> |
static void |
251 |
> |
execute( /* process a file */ |
252 |
> |
char *file |
253 |
> |
) |
254 |
|
{ |
255 |
|
int conditional = vardefined("cond"); |
256 |
|
long nrecs = 0; |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
< |
putout() /* produce an output record */ |
283 |
> |
static void |
284 |
> |
putout(void) /* produce an output record */ |
285 |
|
{ |
263 |
– |
extern void chanset(), bchanset(); |
286 |
|
|
287 |
|
colpos = 0; |
288 |
|
if (outfmt != NULL) |
299 |
|
|
300 |
|
|
301 |
|
double |
302 |
< |
chanvalue(n) /* return value for column n */ |
303 |
< |
int n; |
302 |
> |
chanvalue( /* return value for column n */ |
303 |
> |
int n |
304 |
> |
) |
305 |
|
{ |
306 |
|
int i; |
307 |
|
register char *cp; |
352 |
|
|
353 |
|
|
354 |
|
void |
355 |
< |
chanset(n, v) /* output column n */ |
356 |
< |
int n; |
357 |
< |
double v; |
355 |
> |
chanset( /* output column n */ |
356 |
> |
int n, |
357 |
> |
double v |
358 |
> |
) |
359 |
|
{ |
360 |
|
if (colpos == 0) /* no leading separator */ |
361 |
|
colpos = 1; |
368 |
|
|
369 |
|
|
370 |
|
void |
371 |
< |
bchanset(n, v) /* output binary channel n */ |
372 |
< |
int n; |
373 |
< |
double v; |
371 |
> |
bchanset( /* output binary channel n */ |
372 |
> |
int n, |
373 |
> |
double v |
374 |
> |
) |
375 |
|
{ |
376 |
|
static char zerobuf[sizeof(double)]; |
377 |
|
|
388 |
|
} |
389 |
|
|
390 |
|
|
391 |
< |
readfmt(spec, output) /* read record format */ |
392 |
< |
char *spec; |
393 |
< |
int output; |
391 |
> |
static void |
392 |
> |
readfmt( /* read record format */ |
393 |
> |
char *spec, |
394 |
> |
int output |
395 |
> |
) |
396 |
|
{ |
397 |
|
int fd; |
398 |
|
char *inptr; |
456 |
|
} |
457 |
|
|
458 |
|
|
459 |
< |
int |
460 |
< |
readfield(pp) /* get next field in format */ |
461 |
< |
register char **pp; |
459 |
> |
static int |
460 |
> |
readfield( /* get next field in format */ |
461 |
> |
register char **pp |
462 |
> |
) |
463 |
|
{ |
464 |
|
int type = F_NUL; |
465 |
|
int width = 0; |
524 |
|
|
525 |
|
|
526 |
|
struct strvar * |
527 |
< |
getsvar(svname) /* get string variable */ |
528 |
< |
char *svname; |
527 |
> |
getsvar( /* get string variable */ |
528 |
> |
char *svname |
529 |
> |
) |
530 |
|
{ |
531 |
|
register struct strvar *sv; |
532 |
|
|
542 |
|
} |
543 |
|
|
544 |
|
|
545 |
< |
svpreset(eqn) /* preset a string variable */ |
546 |
< |
char *eqn; |
545 |
> |
static void |
546 |
> |
svpreset( /* preset a string variable */ |
547 |
> |
char *eqn |
548 |
> |
) |
549 |
|
{ |
550 |
|
register struct strvar *sv; |
551 |
|
register char *val; |
564 |
|
} |
565 |
|
|
566 |
|
|
567 |
< |
clearrec() /* clear input record variables */ |
567 |
> |
static void |
568 |
> |
clearrec(void) /* clear input record variables */ |
569 |
|
{ |
570 |
|
register struct field *f; |
571 |
|
|
584 |
|
} |
585 |
|
|
586 |
|
|
587 |
< |
getrec() /* get next record from file */ |
587 |
> |
static int |
588 |
> |
getrec(void) /* get next record from file */ |
589 |
|
{ |
590 |
|
int eatline; |
591 |
|
register struct field *f; |
618 |
|
} |
619 |
|
|
620 |
|
|
621 |
< |
getfield(f) /* get next field */ |
622 |
< |
register struct field *f; |
621 |
> |
static int |
622 |
> |
getfield( /* get next field */ |
623 |
> |
register struct field *f |
624 |
> |
) |
625 |
|
{ |
626 |
< |
static char buf[MAXWORD+1]; /* no recursion! */ |
626 |
> |
static char buf[RMAXWORD+1]; /* no recursion! */ |
627 |
|
int delim, inword; |
628 |
|
double d; |
629 |
|
char *np; |
656 |
|
delim = f->next->f.sl[0]; |
657 |
|
cp = buf; |
658 |
|
do { |
659 |
< |
if (ipb.chr == EOF) |
659 |
> |
if (ipb.chr == EOF || ipb.chr == '\n') |
660 |
|
inword = 0; |
661 |
|
else if (blnkeq && delim != EOF) |
662 |
|
inword = isblnk(delim) ? |
668 |
|
*cp++ = ipb.chr; |
669 |
|
scaninp(); |
670 |
|
} |
671 |
< |
} while (inword && cp < &buf[MAXWORD]); |
671 |
> |
} while (inword && cp < &buf[RMAXWORD]); |
672 |
|
*cp = '\0'; |
673 |
|
if (f->f.sv->val == NULL) |
674 |
|
f->f.sv->val = savqstr(buf); /* first setting */ |
697 |
|
*cp++ = ipb.chr; |
698 |
|
scaninp(); |
699 |
|
} |
700 |
< |
} while (inword && cp < &buf[MAXWORD]); |
700 |
> |
} while (inword && cp < &buf[RMAXWORD]); |
701 |
|
*cp = '\0'; |
702 |
|
d = np==NULL ? 0. : atof(np); |
703 |
|
if (!vardefined(f->f.nv)) |
707 |
|
return(-1); /* doesn't match! */ |
708 |
|
return(0); |
709 |
|
} |
710 |
+ |
return -1; /* pro forma return */ |
711 |
|
} |
712 |
|
|
713 |
|
|
714 |
< |
putrec() /* output a record */ |
714 |
> |
static void |
715 |
> |
putrec(void) /* output a record */ |
716 |
|
{ |
717 |
|
char fmt[32]; |
718 |
|
register int n; |
762 |
|
} |
763 |
|
|
764 |
|
|
765 |
< |
initinp(fp) /* prepare lookahead buffer */ |
766 |
< |
FILE *fp; |
765 |
> |
static void |
766 |
> |
initinp(FILE *fp) /* prepare lookahead buffer */ |
767 |
> |
|
768 |
|
{ |
769 |
|
ipb.fin = fp; |
770 |
|
ipb.beg = ipb.end = inpbuf; |
774 |
|
} |
775 |
|
|
776 |
|
|
777 |
< |
scaninp() /* scan next character */ |
777 |
> |
static void |
778 |
> |
scaninp(void) /* scan next character */ |
779 |
|
{ |
780 |
|
if (ipb.chr == EOF) |
781 |
|
return; |
794 |
|
} |
795 |
|
|
796 |
|
|
797 |
< |
advinp() /* move home to current position */ |
797 |
> |
static void |
798 |
> |
advinp(void) /* move home to current position */ |
799 |
|
{ |
800 |
|
ipb.beg = ipb.pos; |
801 |
|
} |
802 |
|
|
803 |
|
|
804 |
< |
resetinp() /* rewind position and advance 1 */ |
804 |
> |
static void |
805 |
> |
resetinp(void) /* rewind position and advance 1 */ |
806 |
|
{ |
807 |
|
if (ipb.beg == NULL) /* full */ |
808 |
|
ipb.beg = ipb.end; |
815 |
|
|
816 |
|
|
817 |
|
void |
818 |
< |
eputs(msg) |
778 |
< |
char *msg; |
818 |
> |
eputs(char *msg) |
819 |
|
{ |
820 |
|
fputs(msg, stderr); |
821 |
|
} |
822 |
|
|
823 |
|
|
824 |
|
void |
825 |
< |
wputs(msg) |
786 |
< |
char *msg; |
825 |
> |
wputs(char *msg) |
826 |
|
{ |
827 |
|
if (!nowarn) |
828 |
|
eputs(msg); |
830 |
|
|
831 |
|
|
832 |
|
void |
833 |
< |
quit(code) |
795 |
< |
int code; |
833 |
> |
quit(int code) |
834 |
|
{ |
835 |
|
exit(code); |
836 |
|
} |