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? */ |
58 |
|
#define savqstr(s) strcpy(emalloc(strlen(s)+1),s) |
59 |
|
#define freqstr(s) efree(s) |
60 |
|
|
61 |
< |
extern char *strcpy(), *emalloc(), *savestr(); |
62 |
< |
struct strvar *getsvar(); |
61 |
> |
static void scaninp(void), advinp(void), resetinp(void); |
62 |
> |
static void putrec(void), putout(void), nbsynch(void); |
63 |
> |
static int getrec(void); |
64 |
> |
static void execute(char *file); |
65 |
> |
static void initinp(FILE *fp); |
66 |
> |
static void svpreset(char *eqn); |
67 |
> |
static void readfmt(char *spec, int output); |
68 |
> |
static int readfield(char **pp); |
69 |
> |
static int getfield(struct field *f); |
70 |
> |
static void chanset(int n, double v); |
71 |
> |
static void bchanset(int n, double v); |
72 |
> |
static struct strvar* getsvar(char *svname); |
73 |
|
|
74 |
|
struct field *inpfmt = NULL; /* input record format */ |
75 |
|
struct field *outfmt = NULL; /* output record structure */ |
98 |
|
} ipb; /* circular lookahead buffer */ |
99 |
|
|
100 |
|
|
101 |
< |
main(argc, argv) |
102 |
< |
int argc; |
103 |
< |
char *argv[]; |
101 |
> |
int |
102 |
> |
main( |
103 |
> |
int argc, |
104 |
> |
char *argv[] |
105 |
> |
) |
106 |
|
{ |
107 |
|
int i; |
108 |
|
|
212 |
|
} |
213 |
|
|
214 |
|
|
215 |
< |
nbsynch() /* non-blank starting synch character */ |
215 |
> |
static void |
216 |
> |
nbsynch(void) /* non-blank starting synch character */ |
217 |
|
{ |
218 |
|
if (inpfmt == NULL || (inpfmt->type & F_TYP) != T_LIT) |
219 |
|
return; |
225 |
|
|
226 |
|
|
227 |
|
int |
228 |
< |
getinputrec(fp) /* get next input record */ |
229 |
< |
FILE *fp; |
228 |
> |
getinputrec( /* get next input record */ |
229 |
> |
FILE *fp |
230 |
> |
) |
231 |
|
{ |
232 |
|
if (inpfmt != NULL) |
233 |
|
return(getrec()); |
241 |
|
} |
242 |
|
|
243 |
|
|
244 |
< |
execute(file) /* process a file */ |
245 |
< |
char *file; |
244 |
> |
static void |
245 |
> |
execute( /* process a file */ |
246 |
> |
char *file |
247 |
> |
) |
248 |
|
{ |
249 |
|
int conditional = vardefined("cond"); |
250 |
|
long nrecs = 0; |
274 |
|
} |
275 |
|
|
276 |
|
|
277 |
< |
putout() /* produce an output record */ |
277 |
> |
static void |
278 |
> |
putout(void) /* produce an output record */ |
279 |
|
{ |
263 |
– |
extern void chanset(), bchanset(); |
280 |
|
|
281 |
|
colpos = 0; |
282 |
|
if (outfmt != NULL) |
285 |
|
chanout(bchanset); |
286 |
|
else |
287 |
|
chanout(chanset); |
288 |
< |
if (colpos && !bchanset) |
288 |
> |
if (colpos && !bocols) |
289 |
|
putchar('\n'); |
290 |
|
if (unbuff) |
291 |
|
fflush(stdout); |
293 |
|
|
294 |
|
|
295 |
|
double |
296 |
< |
chanvalue(n) /* return value for column n */ |
297 |
< |
int n; |
296 |
> |
chanvalue( /* return value for column n */ |
297 |
> |
int n |
298 |
> |
) |
299 |
|
{ |
300 |
|
int i; |
301 |
|
register char *cp; |
346 |
|
|
347 |
|
|
348 |
|
void |
349 |
< |
chanset(n, v) /* output column n */ |
350 |
< |
int n; |
351 |
< |
double v; |
349 |
> |
chanset( /* output column n */ |
350 |
> |
int n, |
351 |
> |
double v |
352 |
> |
) |
353 |
|
{ |
354 |
|
if (colpos == 0) /* no leading separator */ |
355 |
|
colpos = 1; |
362 |
|
|
363 |
|
|
364 |
|
void |
365 |
< |
bchanset(n, v) /* output binary channel n */ |
366 |
< |
int n; |
367 |
< |
double v; |
365 |
> |
bchanset( /* output binary channel n */ |
366 |
> |
int n, |
367 |
> |
double v |
368 |
> |
) |
369 |
|
{ |
370 |
|
static char zerobuf[sizeof(double)]; |
371 |
|
|
382 |
|
} |
383 |
|
|
384 |
|
|
385 |
< |
readfmt(spec, output) /* read record format */ |
386 |
< |
char *spec; |
387 |
< |
int output; |
385 |
> |
static void |
386 |
> |
readfmt( /* read record format */ |
387 |
> |
char *spec, |
388 |
> |
int output |
389 |
> |
) |
390 |
|
{ |
391 |
|
int fd; |
392 |
|
char *inptr; |
450 |
|
} |
451 |
|
|
452 |
|
|
453 |
< |
int |
454 |
< |
readfield(pp) /* get next field in format */ |
455 |
< |
register char **pp; |
453 |
> |
static int |
454 |
> |
readfield( /* get next field in format */ |
455 |
> |
register char **pp |
456 |
> |
) |
457 |
|
{ |
458 |
|
int type = F_NUL; |
459 |
|
int width = 0; |
518 |
|
|
519 |
|
|
520 |
|
struct strvar * |
521 |
< |
getsvar(svname) /* get string variable */ |
522 |
< |
char *svname; |
521 |
> |
getsvar( /* get string variable */ |
522 |
> |
char *svname |
523 |
> |
) |
524 |
|
{ |
525 |
|
register struct strvar *sv; |
526 |
|
|
536 |
|
} |
537 |
|
|
538 |
|
|
539 |
< |
svpreset(eqn) /* preset a string variable */ |
540 |
< |
char *eqn; |
539 |
> |
static void |
540 |
> |
svpreset( /* preset a string variable */ |
541 |
> |
char *eqn |
542 |
> |
) |
543 |
|
{ |
544 |
|
register struct strvar *sv; |
545 |
|
register char *val; |
558 |
|
} |
559 |
|
|
560 |
|
|
561 |
< |
clearrec() /* clear input record variables */ |
561 |
> |
static void |
562 |
> |
clearrec(void) /* clear input record variables */ |
563 |
|
{ |
564 |
|
register struct field *f; |
565 |
|
|
578 |
|
} |
579 |
|
|
580 |
|
|
581 |
< |
getrec() /* get next record from file */ |
581 |
> |
static int |
582 |
> |
getrec(void) /* get next record from file */ |
583 |
|
{ |
584 |
|
int eatline; |
585 |
|
register struct field *f; |
612 |
|
} |
613 |
|
|
614 |
|
|
615 |
< |
getfield(f) /* get next field */ |
616 |
< |
register struct field *f; |
615 |
> |
static int |
616 |
> |
getfield( /* get next field */ |
617 |
> |
register struct field *f |
618 |
> |
) |
619 |
|
{ |
620 |
< |
static char buf[MAXWORD+1]; /* no recursion! */ |
620 |
> |
static char buf[RMAXWORD+1]; /* no recursion! */ |
621 |
|
int delim, inword; |
622 |
|
double d; |
623 |
|
char *np; |
662 |
|
*cp++ = ipb.chr; |
663 |
|
scaninp(); |
664 |
|
} |
665 |
< |
} while (inword && cp < &buf[MAXWORD]); |
665 |
> |
} while (inword && cp < &buf[RMAXWORD]); |
666 |
|
*cp = '\0'; |
667 |
|
if (f->f.sv->val == NULL) |
668 |
|
f->f.sv->val = savqstr(buf); /* first setting */ |
691 |
|
*cp++ = ipb.chr; |
692 |
|
scaninp(); |
693 |
|
} |
694 |
< |
} while (inword && cp < &buf[MAXWORD]); |
694 |
> |
} while (inword && cp < &buf[RMAXWORD]); |
695 |
|
*cp = '\0'; |
696 |
|
d = np==NULL ? 0. : atof(np); |
697 |
|
if (!vardefined(f->f.nv)) |
701 |
|
return(-1); /* doesn't match! */ |
702 |
|
return(0); |
703 |
|
} |
704 |
+ |
return -1; /* pro forma return */ |
705 |
|
} |
706 |
|
|
707 |
|
|
708 |
< |
putrec() /* output a record */ |
708 |
> |
static void |
709 |
> |
putrec(void) /* output a record */ |
710 |
|
{ |
711 |
|
char fmt[32]; |
712 |
|
register int n; |
756 |
|
} |
757 |
|
|
758 |
|
|
759 |
< |
initinp(fp) /* prepare lookahead buffer */ |
760 |
< |
FILE *fp; |
759 |
> |
static void |
760 |
> |
initinp(FILE *fp) /* prepare lookahead buffer */ |
761 |
> |
|
762 |
|
{ |
763 |
|
ipb.fin = fp; |
764 |
|
ipb.beg = ipb.end = inpbuf; |
768 |
|
} |
769 |
|
|
770 |
|
|
771 |
< |
scaninp() /* scan next character */ |
771 |
> |
static void |
772 |
> |
scaninp(void) /* scan next character */ |
773 |
|
{ |
774 |
|
if (ipb.chr == EOF) |
775 |
|
return; |
788 |
|
} |
789 |
|
|
790 |
|
|
791 |
< |
advinp() /* move home to current position */ |
791 |
> |
static void |
792 |
> |
advinp(void) /* move home to current position */ |
793 |
|
{ |
794 |
|
ipb.beg = ipb.pos; |
795 |
|
} |
796 |
|
|
797 |
|
|
798 |
< |
resetinp() /* rewind position and advance 1 */ |
798 |
> |
static void |
799 |
> |
resetinp(void) /* rewind position and advance 1 */ |
800 |
|
{ |
801 |
|
if (ipb.beg == NULL) /* full */ |
802 |
|
ipb.beg = ipb.end; |
809 |
|
|
810 |
|
|
811 |
|
void |
812 |
< |
eputs(msg) |
778 |
< |
char *msg; |
812 |
> |
eputs(char *msg) |
813 |
|
{ |
814 |
|
fputs(msg, stderr); |
815 |
|
} |
816 |
|
|
817 |
|
|
818 |
|
void |
819 |
< |
wputs(msg) |
786 |
< |
char *msg; |
819 |
> |
wputs(char *msg) |
820 |
|
{ |
821 |
|
if (!nowarn) |
822 |
|
eputs(msg); |
824 |
|
|
825 |
|
|
826 |
|
void |
827 |
< |
quit(code) |
795 |
< |
int code; |
827 |
> |
quit(int code) |
828 |
|
{ |
829 |
|
exit(code); |
830 |
|
} |