55 |
|
#define freqstr(s) efree(s) |
56 |
|
|
57 |
|
static int getinputrec(FILE *fp); |
58 |
< |
static void scaninp(void), advinp(void), skipinp(void); |
58 |
> |
static void scaninp(void), advinp(void), passinp(void), skipinp(void); |
59 |
|
static void putrec(void), putout(void), nbsynch(void); |
60 |
|
static int getrec(void); |
61 |
|
static void execute(char *file); |
69 |
|
static struct strvar* getsvar(char *svname); |
70 |
|
static double l_in(char *); |
71 |
|
|
72 |
< |
struct field *inpfmt = NULL; /* input record format */ |
73 |
< |
struct field *outfmt = NULL; /* output record structure */ |
74 |
< |
struct strvar *svhead = NULL; /* string variables */ |
72 |
> |
struct field *inpfmt = NULL; /* input record format */ |
73 |
> |
struct field *outfmt = NULL; /* output record structure */ |
74 |
> |
struct strvar *svhead = NULL; /* string variables */ |
75 |
|
|
76 |
< |
long incnt = 0; /* limit number of input records? */ |
76 |
> |
long incnt = 0; /* limit number of input records? */ |
77 |
|
long outcnt = 0; /* limit number of output records? */ |
78 |
|
|
79 |
< |
int blnkeq = 1; /* blanks compare equal? */ |
80 |
< |
int igneol = 0; /* ignore end of line? */ |
79 |
> |
int blnkeq = 1; /* blanks compare equal? */ |
80 |
> |
int igneol = 0; /* ignore end of line? */ |
81 |
|
int passive = 0; /* passive mode (transmit unmatched input) */ |
82 |
< |
char sepchar = '\t'; /* input/output separator */ |
83 |
< |
int noinput = 0; /* no input records? */ |
82 |
> |
char sepchar = '\t'; /* input/output separator */ |
83 |
> |
int noinput = 0; /* no input records? */ |
84 |
|
int itype = 'a'; /* input type (a/f/F/d/D) */ |
85 |
|
int nbicols = 0; /* number of binary input columns */ |
86 |
|
int otype = 'a'; /* output format (a/f/F/d/D) */ |
87 |
< |
char inpbuf[INBSIZ]; /* input buffer */ |
88 |
< |
double colval[MAXCOL]; /* input column values */ |
89 |
< |
unsigned long colflg = 0; /* column retrieved flags */ |
90 |
< |
int colpos; /* output column position */ |
87 |
> |
char inpbuf[INBSIZ]; /* input buffer */ |
88 |
> |
double colval[MAXCOL]; /* input column values */ |
89 |
> |
unsigned long colflg = 0; /* column retrieved flags */ |
90 |
> |
int colpos; /* output column position */ |
91 |
|
|
92 |
< |
int nowarn = 0; /* non-fatal diagnostic output */ |
93 |
< |
int unbuff = 0; /* unbuffered output (flush each record) */ |
92 |
> |
int nowarn = 0; /* non-fatal diagnostic output */ |
93 |
> |
int unbuff = 0; /* unbuffered output (flush each record) */ |
94 |
|
|
95 |
|
struct { |
96 |
|
FILE *fin; /* input file */ |
128 |
|
igneol = !igneol; |
129 |
|
break; |
130 |
|
case 'p': |
131 |
< |
passive = !passive; |
131 |
> |
passive = 1; |
132 |
|
break; |
133 |
+ |
case 'P': |
134 |
+ |
passive = -1; |
135 |
+ |
break; |
136 |
|
case 't': |
137 |
|
sepchar = argv[i][2]; |
138 |
|
break; |
232 |
|
userr: |
233 |
|
eputs("Usage: "); |
234 |
|
eputs(argv[0]); |
235 |
< |
eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n"); |
235 |
> |
eputs(" [-b][-l][-n][-p|-P][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n"); |
236 |
|
quit(1); |
237 |
|
} |
238 |
|
if (otype != 'a') |
250 |
|
putout(); |
251 |
|
quit(0); |
252 |
|
} |
253 |
+ |
if (passive && (inpfmt == NULL) | (outfmt == NULL)) { |
254 |
+ |
eputs(argv[0]); |
255 |
+ |
eputs(": options -p and -P require -i and -o formats\n"); |
256 |
+ |
quit(1); |
257 |
+ |
} |
258 |
|
if (blnkeq) /* for efficiency */ |
259 |
|
nbsynch(); |
260 |
|
|
286 |
|
FILE *fp |
287 |
|
) |
288 |
|
{ |
281 |
– |
if (inpfmt != NULL) |
282 |
– |
return(getrec()); |
289 |
|
if ((itype == 'd') | (itype == 'D')) { |
290 |
|
if (getbinary(inpbuf, sizeof(double), nbicols, fp) != nbicols) |
291 |
|
return(0); |
331 |
|
if (inpfmt != NULL) |
332 |
|
initinp(fp); |
333 |
|
|
334 |
< |
while (getinputrec(fp)) { |
334 |
> |
while (inpfmt != NULL ? getrec() : getinputrec(fp)) { |
335 |
|
++nrecs; |
336 |
|
if (set_recno) |
337 |
|
varset("recno", '=', (double)nrecs); |
342 |
|
if (!conditional || varvalue("cond") > 0.0) { |
343 |
|
putout(); |
344 |
|
++nout; |
345 |
+ |
advinp(); |
346 |
+ |
} else if (inpfmt != NULL) { |
347 |
+ |
if (passive < 0) |
348 |
+ |
passinp(); |
349 |
+ |
else |
350 |
+ |
advinp(); |
351 |
|
} |
352 |
|
if (incnt && nrecs >= incnt) |
353 |
|
break; |
700 |
|
|
701 |
|
|
702 |
|
static int |
703 |
< |
getrec(void) /* get next record from file */ |
703 |
> |
getrec(void) /* get next record from file */ |
704 |
|
{ |
705 |
|
int eatline; |
706 |
|
struct field *f; |
717 |
|
for (f = inpfmt; f != NULL; f = f->next) |
718 |
|
if (!getfield(f)) |
719 |
|
break; |
720 |
< |
if (f == NULL) { |
709 |
< |
advinp(); /* got one! */ |
720 |
> |
if (f == NULL) /* got one? */ |
721 |
|
return(1); |
722 |
< |
} |
723 |
< |
skipinp(); /* eat false start */ |
713 |
< |
if (eatline) { /* eat rest of line */ |
722 |
> |
skipinp(); /* else eat false start */ |
723 |
> |
if (eatline) { /* eat rest of line */ |
724 |
|
while (ipb.chr != '\n') { |
725 |
|
if (ipb.chr == EOF) |
726 |
|
return(0); |
929 |
|
|
930 |
|
|
931 |
|
static void |
932 |
< |
skipinp(void) /* rewind position and advance 1 */ |
932 |
> |
passinp(void) /* pass beginning to current position */ |
933 |
|
{ |
934 |
< |
if (ipb.beg == NULL) /* full */ |
934 |
> |
if (!passive | (ipb.beg == NULL)) { |
935 |
> |
advinp(); |
936 |
> |
return; |
937 |
> |
} |
938 |
> |
while (ipb.beg != ipb.pos) { /* transfer buffer unaltered */ |
939 |
> |
putchar(*ipb.beg); |
940 |
> |
if (++ipb.beg >= &inpbuf[INBSIZ]) |
941 |
> |
ipb.beg = inpbuf; |
942 |
> |
} |
943 |
> |
} |
944 |
> |
|
945 |
> |
|
946 |
> |
static void |
947 |
> |
skipinp(void) /* rewind position and advance 1 */ |
948 |
> |
{ |
949 |
> |
if (ipb.beg == NULL) /* full */ |
950 |
|
ipb.beg = ipb.end; |
951 |
|
ipb.pos = ipb.beg; |
952 |
|
ipb.chr = *ipb.pos; |