| 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; |
| 189 |
|
break; |
| 190 |
|
case 'd': |
| 191 |
|
bocols = 1; |
| 192 |
+ |
SET_FILE_BINARY(stdout); |
| 193 |
|
break; |
| 194 |
|
case 'f': |
| 195 |
|
bocols = -1; |
| 196 |
+ |
SET_FILE_BINARY(stdout); |
| 197 |
|
break; |
| 198 |
+ |
default: |
| 199 |
+ |
goto userr; |
| 200 |
|
} |
| 201 |
|
break; |
| 202 |
|
case 'w': |
| 209 |
|
userr: |
| 210 |
|
eputs("Usage: "); |
| 211 |
|
eputs(argv[0]); |
| 212 |
< |
eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n"); |
| 212 |
> |
eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n"); |
| 213 |
|
quit(1); |
| 214 |
|
} |
| 215 |
< |
|
| 215 |
> |
if (bocols) |
| 216 |
> |
SET_FILE_BINARY(stdout); |
| 217 |
|
if (noinput) { /* produce a single output record */ |
| 218 |
+ |
if (i < argc) { |
| 219 |
+ |
eputs(argv[0]); |
| 220 |
+ |
eputs(": file argument(s) incompatible with -n\n"); |
| 221 |
+ |
quit(1); |
| 222 |
+ |
} |
| 223 |
|
eclock++; |
| 224 |
|
putout(); |
| 225 |
|
quit(0); |
| 226 |
|
} |
| 227 |
+ |
if (nbicols) |
| 228 |
+ |
SET_FILE_BINARY(stdin); |
| 229 |
|
|
| 230 |
|
if (blnkeq) /* for efficiency */ |
| 231 |
|
nbsynch(); |
| 237 |
|
execute(argv[i]); |
| 238 |
|
|
| 239 |
|
quit(0); |
| 240 |
+ |
return 0; /* pro forma return */ |
| 241 |
|
} |
| 242 |
|
|
| 243 |
|
|
| 466 |
|
eputs(": cannot open\n"); |
| 467 |
|
quit(1); |
| 468 |
|
} |
| 469 |
< |
res = read(fd, inpbuf+1, INBSIZ-1); |
| 469 |
> |
res = read(fd, inpbuf+2, INBSIZ-2); |
| 470 |
|
if (res <= 0 || res >= INBSIZ-1) { |
| 471 |
|
eputs(spec); |
| 472 |
|
if (res < 0) |
| 478 |
|
quit(1); |
| 479 |
|
} |
| 480 |
|
close(fd); |
| 481 |
< |
(inptr=inpbuf+1)[res] = '\0'; |
| 481 |
> |
(inptr=inpbuf+2)[res] = '\0'; |
| 482 |
|
} |
| 483 |
|
f = &fmt; /* get fields */ |
| 484 |
|
while ((res = readfield(&inptr)) != F_NUL) { |
| 640 |
|
|
| 641 |
|
|
| 642 |
|
static int |
| 643 |
< |
getrec(void) /* get next record from file */ |
| 643 |
> |
getrec(void) /* get next record from file */ |
| 644 |
|
{ |
| 645 |
|
int eatline; |
| 646 |
|
register struct field *f; |
| 647 |
< |
|
| 647 |
> |
|
| 648 |
|
while (ipb.chr != EOF) { |
| 649 |
< |
eatline = !igneol && ipb.chr != '\n'; |
| 630 |
< |
if (blnkeq) /* beware of nbsynch() */ |
| 649 |
> |
if (blnkeq) { /* beware of nbsynch() */ |
| 650 |
|
while (isblnk(ipb.chr)) |
| 651 |
< |
scaninp(); |
| 651 |
> |
resetinp(); |
| 652 |
> |
if (ipb.chr == EOF) |
| 653 |
> |
return(0); |
| 654 |
> |
} |
| 655 |
> |
eatline = (!igneol && ipb.chr != '\n'); |
| 656 |
|
clearrec(); /* start with fresh record */ |
| 657 |
|
for (f = inpfmt; f != NULL; f = f->next) |
| 658 |
|
if (getfield(f) == -1) |
| 659 |
|
break; |
| 660 |
|
if (f == NULL) { |
| 661 |
< |
advinp(); |
| 661 |
> |
advinp(); /* got one! */ |
| 662 |
|
return(1); |
| 663 |
|
} |
| 664 |
< |
resetinp(); |
| 664 |
> |
resetinp(); /* eat false start */ |
| 665 |
|
if (eatline) { /* eat rest of line */ |
| 666 |
|
while (ipb.chr != '\n') { |
| 667 |
|
if (ipb.chr == EOF) |
| 668 |
|
return(0); |
| 669 |
< |
scaninp(); |
| 669 |
> |
resetinp(); |
| 670 |
|
} |
| 671 |
< |
scaninp(); |
| 649 |
< |
advinp(); |
| 671 |
> |
resetinp(); |
| 672 |
|
} |
| 673 |
|
} |
| 674 |
|
return(0); |
| 865 |
|
ipb.beg = ipb.end; |
| 866 |
|
ipb.pos = ipb.beg; |
| 867 |
|
ipb.chr = *ipb.pos; |
| 868 |
+ |
if (passive) /* transmit unmatched character? */ |
| 869 |
+ |
fputc(ipb.chr, stdout); |
| 870 |
|
if (++ipb.beg >= &inpbuf[INBSIZ]) |
| 871 |
|
ipb.beg = inpbuf; |
| 872 |
|
scaninp(); |