Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!sdcsvax!sdchema!jwp From: jwp@sdchema.UUCP Newsgroups: net.unix-wizards Subject: Re: egrep bug Message-ID: <574@sdchema.UUCP> Date: Sat, 28-May-83 20:25:59 EDT Article-I.D.: sdchema.574 Posted: Sat May 28 20:25:59 1983 Date-Received: Tue, 5-Jul-83 19:11:57 EDT References: floyd.1546 Lines: 27 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