--- ray/src/cal/rcalc.c 2004/03/28 20:33:12 1.12 +++ ray/src/cal/rcalc.c 2004/12/10 05:52:14 1.16 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rcalc.c,v 1.12 2004/03/28 20:33:12 schorsch Exp $"; +static const char RCSid[] = "$Id: rcalc.c,v 1.16 2004/12/10 05:52:14 greg Exp $"; #endif /* * rcalc.c - record calculator program. @@ -25,7 +25,7 @@ static const char RCSid[] = "$Id: rcalc.c,v 1.12 2004/ #define isblnk(c) (igneol ? isspace(c) : (c)==' '||(c)=='\t') -#define INBSIZ 4096 /* longest record */ +#define INBSIZ 16384 /* longest record */ #define MAXCOL 32 /* number of columns recorded */ /* field type specifications */ @@ -78,6 +78,7 @@ struct strvar *svhead = NULL; /* string variables */ int blnkeq = 1; /* blanks compare equal? */ int igneol = 0; /* ignore end of line? */ +int passive = 0; /* passive mode (transmit unmatched input) */ char sepchar = '\t'; /* input/output separator */ int noinput = 0; /* no input records? */ int nbicols = 0; /* number of binary input columns */ @@ -124,6 +125,9 @@ char *argv[] case 'l': igneol = !igneol; break; + case 'p': + passive = !passive; + break; case 't': sepchar = argv[i][2]; break; @@ -201,7 +205,7 @@ char *argv[] userr: eputs("Usage: "); eputs(argv[0]); -eputs(" [-b][-l][-n][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n"); +eputs(" [-b][-l][-n][-p][-w][-u][-tS][-s svar=sval][-e expr][-f source][-i infmt][-o outfmt] [file]\n"); quit(1); } @@ -450,7 +454,7 @@ int output eputs(": cannot open\n"); quit(1); } - res = read(fd, inpbuf+1, INBSIZ-1); + res = read(fd, inpbuf+2, INBSIZ-2); if (res <= 0 || res >= INBSIZ-1) { eputs(spec); if (res < 0) @@ -462,7 +466,7 @@ int output quit(1); } close(fd); - (inptr=inpbuf+1)[res] = '\0'; + (inptr=inpbuf+2)[res] = '\0'; } f = &fmt; /* get fields */ while ((res = readfield(&inptr)) != F_NUL) { @@ -624,33 +628,32 @@ clearrec(void) /* clear input record variables */ static int -getrec(void) /* get next record from file */ +getrec(void) /* get next record from file */ { int eatline; register struct field *f; - + while (ipb.chr != EOF) { - eatline = !igneol && ipb.chr != '\n'; if (blnkeq) /* beware of nbsynch() */ while (isblnk(ipb.chr)) - scaninp(); + resetinp(); + eatline = (!igneol && ipb.chr != '\n'); clearrec(); /* start with fresh record */ for (f = inpfmt; f != NULL; f = f->next) if (getfield(f) == -1) break; if (f == NULL) { - advinp(); + advinp(); /* got one! */ return(1); } - resetinp(); + resetinp(); /* eat false start */ if (eatline) { /* eat rest of line */ while (ipb.chr != '\n') { if (ipb.chr == EOF) return(0); - scaninp(); + resetinp(); } - scaninp(); - advinp(); + resetinp(); } } return(0); @@ -847,6 +850,8 @@ resetinp(void) /* rewind position ipb.beg = ipb.end; ipb.pos = ipb.beg; ipb.chr = *ipb.pos; + if (passive) /* transmit unmatched character? */ + fputc(ipb.chr, stdout); if (++ipb.beg >= &inpbuf[INBSIZ]) ipb.beg = inpbuf; scaninp();