🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Roger Collins Fri, 18 Dec 1987 16:42
Another fgrep bug (with fix)
#659
Author: 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.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads