8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdlib.h> |
11 |
+ |
#include <fcntl.h> |
12 |
|
#include <stdio.h> |
13 |
|
#include <string.h> |
14 |
|
#include <math.h> |
15 |
|
#include <ctype.h> |
16 |
|
|
17 |
|
#include "platform.h" |
17 |
– |
#include "calcomp.h" |
18 |
|
#include "rterror.h" |
19 |
+ |
#include "rtmisc.h" |
20 |
+ |
#include "rtio.h" |
21 |
+ |
#include "calcomp.h" |
22 |
|
|
23 |
|
#define isnum(c) (isdigit(c) || (c)=='-' || (c)=='.' \ |
24 |
|
|| (c)=='+' || (c)=='e' || (c)=='E') |
25 |
|
|
26 |
|
#define isblnk(c) (igneol ? isspace(c) : (c)==' '||(c)=='\t') |
27 |
|
|
28 |
< |
#define INBSIZ 4096 /* longest record */ |
28 |
> |
#define INBSIZ 16384 /* longest record */ |
29 |
|
#define MAXCOL 32 /* number of columns recorded */ |
30 |
|
|
31 |
|
/* field type specifications */ |
78 |
|
|
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? */ |
84 |
|
int nbicols = 0; /* number of binary input columns */ |
125 |
|
case 'l': |
126 |
|
igneol = !igneol; |
127 |
|
break; |
128 |
+ |
case 'p': |
129 |
+ |
passive = !passive; |
130 |
+ |
break; |
131 |
|
case 't': |
132 |
|
sepchar = argv[i][2]; |
133 |
|
break; |
205 |
|
userr: |
206 |
|
eputs("Usage: "); |
207 |
|
eputs(argv[0]); |
208 |
< |
eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n"); |
208 |
> |
eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n"); |
209 |
|
quit(1); |
210 |
|
} |
211 |
|
|
212 |
|
if (noinput) { /* produce a single output record */ |
213 |
+ |
if (i < argc) { |
214 |
+ |
eputs(argv[0]); |
215 |
+ |
eputs(": file argument(s) incompatible with -n\n"); |
216 |
+ |
quit(1); |
217 |
+ |
} |
218 |
|
eclock++; |
219 |
|
putout(); |
220 |
|
quit(0); |
230 |
|
execute(argv[i]); |
231 |
|
|
232 |
|
quit(0); |
233 |
+ |
return 0; /* pro forma return */ |
234 |
|
} |
235 |
|
|
236 |
|
|
459 |
|
eputs(": cannot open\n"); |
460 |
|
quit(1); |
461 |
|
} |
462 |
< |
res = read(fd, inpbuf+1, INBSIZ-1); |
462 |
> |
res = read(fd, inpbuf+2, INBSIZ-2); |
463 |
|
if (res <= 0 || res >= INBSIZ-1) { |
464 |
|
eputs(spec); |
465 |
|
if (res < 0) |
471 |
|
quit(1); |
472 |
|
} |
473 |
|
close(fd); |
474 |
< |
(inptr=inpbuf+1)[res] = '\0'; |
474 |
> |
(inptr=inpbuf+2)[res] = '\0'; |
475 |
|
} |
476 |
|
f = &fmt; /* get fields */ |
477 |
|
while ((res = readfield(&inptr)) != F_NUL) { |
633 |
|
|
634 |
|
|
635 |
|
static int |
636 |
< |
getrec(void) /* get next record from file */ |
636 |
> |
getrec(void) /* get next record from file */ |
637 |
|
{ |
638 |
|
int eatline; |
639 |
|
register struct field *f; |
640 |
< |
|
640 |
> |
|
641 |
|
while (ipb.chr != EOF) { |
629 |
– |
eatline = !igneol && ipb.chr != '\n'; |
642 |
|
if (blnkeq) /* beware of nbsynch() */ |
643 |
|
while (isblnk(ipb.chr)) |
644 |
< |
scaninp(); |
644 |
> |
resetinp(); |
645 |
> |
eatline = (!igneol && ipb.chr != '\n'); |
646 |
|
clearrec(); /* start with fresh record */ |
647 |
|
for (f = inpfmt; f != NULL; f = f->next) |
648 |
|
if (getfield(f) == -1) |
649 |
|
break; |
650 |
|
if (f == NULL) { |
651 |
< |
advinp(); |
651 |
> |
advinp(); /* got one! */ |
652 |
|
return(1); |
653 |
|
} |
654 |
< |
resetinp(); |
654 |
> |
resetinp(); /* eat false start */ |
655 |
|
if (eatline) { /* eat rest of line */ |
656 |
|
while (ipb.chr != '\n') { |
657 |
|
if (ipb.chr == EOF) |
658 |
|
return(0); |
659 |
< |
scaninp(); |
659 |
> |
resetinp(); |
660 |
|
} |
661 |
< |
scaninp(); |
649 |
< |
advinp(); |
661 |
> |
resetinp(); |
662 |
|
} |
663 |
|
} |
664 |
|
return(0); |
855 |
|
ipb.beg = ipb.end; |
856 |
|
ipb.pos = ipb.beg; |
857 |
|
ipb.chr = *ipb.pos; |
858 |
+ |
if (passive) /* transmit unmatched character? */ |
859 |
+ |
fputc(ipb.chr, stdout); |
860 |
|
if (++ipb.beg >= &inpbuf[INBSIZ]) |
861 |
|
ipb.beg = inpbuf; |
862 |
|
scaninp(); |