🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.bugs.sys5
Article #659

Another fgrep bug (with fix)

#659
From: Roger Collins
Date: Fri, 18 Dec 1987 16:42
57 lines
1486 bytes
This is SysV.2 fgrep with all the changes posted by guy@gorodish.Sun.COM 
(Guy Harris).

Execute the following:

echo asd | fgrep 'asdf
asder
asd'

The output should be "asd", but no output is produced.

The cause is that fgrep expects a newline after the last key-word.

An easy fix is to kludge the getargc() function to add a newline
at the end of a file *if* newline is not already there.

Here is the new getargc():

----------
getargc()
{
	static char lastc = 0;
	register c;
	if (wordf) {
		c = getc(wordf);
		if (c == EOF) {
			if (ferror(wordf)) {
				fprintf(stderr,"fgrep: Read error\n");
				exit(1);
			}
			fclose(wordf);
		}
	}
	else {
		if ((c = *argptr++) == '\0') {
			c = EOF;
			--argptr;
		}
	}
	if (c == EOF && lastc != '\n')
		c = '\n';

	return(lastc=c);
}
----------

This works whether the word list is input on the command line or
with the "-f" option.

Merry Christmas,

--
Roger Collins
NCR - E&M Columbia
rogerc@ncrcae.Columbia.NCR.COM
Disclaimer:  Everything here is opinion and all opinions expressed here are 
	     my own and do not reflect those of my employer or anyone else.
Technical Details
Message-ID: <2893@ncrcae.Columbia.NCR.COM>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!hubcap!ncrcae!rogerc

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!bloom-beacon!gatech!hubcap!ncrcae!rogerc
From: rogerc@ncrcae.Columbia.NCR.COM (Roger Collins)
Newsgroups: comp.bugs.sys5
Subject: Another fgrep bug (with fix)
Message-ID: <2893@ncrcae.Columbia.NCR.COM>
Date: 18 Dec 87 16:42:52 GMT
Organization: NCR - E & M Columbia
Lines: 57