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