egrep bug
jwp at sdchema.UUCP
jwp at sdchema.UUCP
Sun May 29 10:25:59 AEST 1983
There's another problem in 4.1BSD egrep that I discovered quite a while
back, but don't remember if I told anyone or not (though if you haven't
discovered it by now you probably don't have any applicatons that care).
It has to do with using the '-f' flag to get the patterns then trying
to read the data from a pipe, e.g:
program | egrep -f patternfile ...
The inner 'if' at the 'out' label in 'main()' reads:
if(freopen(fname = *argv, "r", stdin) == NULL) {
fprintf(stderr, "egrep: can't open %s\n", fname);
exit(2);
}
The inner 'if' in 'nextch()' reads:
if((c = getc(stdin)) == EOF) return(0);
This bit of cleverness causes a slight problem (egrep exits after reading
all of the patterns in since stdin is really pointing at "patternfile"
and nextch() returns EOF). I have a fix for anyone who cares and doesn't
want to work it out themselves (it's relatively straight forward - simply
use another file pointer for the pattern file).
John Pierce, Chemistry, UC San Diego
{ucbvax, philabs}!sdcsvax!sdchema!jwp
More information about the Comp.unix.wizards
mailing list