bm (update to 1.1)

sources-request at genrad.UUCP sources-request at genrad.UUCP
Fri Jul 26 06:34:38 AEST 1985


Mod.sources:  Volume 2, Issue 19
Submitted by: Peter Bain <ihnp4!watmath!wateng!pdbain>


Jeff Mogul (mogul at Carmel) pointed out a bug and kindly provided
the fix.  The last line in the buffer was getting thrown away or mangled, due
to an error in arguments to MoveResidue. This occurred only in long files.
The correction to Execute.c is:
*** 78,84
  			} /* for */
  		} /* while */
  		if(NRead) {
! 			ResSize = MoveResidue(DescVec,NPats,Buffer,BuffEnd);
  			BuffPos += BuffSize - ResSize;
  		} /* if */
  	} while (NRead);

--- 78,85 -----
  			} /* for */
  		} /* while */
  		if(NRead) {
! 			ResSize = MoveResidue(DescVec,NPats,Buffer,
! 						Buffer + BuffSize - 1);
  			BuffPos += BuffSize - ResSize;
  		} /* if */
  	} while (NRead);

The correct code for Execute.c is
----------------------- go into scissor mode here ------------------
: This is a shar archive.	Extract with sh, not csh.
: The rest of this file will extract:
: Execute.c
echo Extracting Execute.c
sed 's/^X//' > Execute.c << 'e-o-f'
X#include <stdio.h>
X#include "bm.h"
X#include "Extern.h"
XExecute(DescVec, NPats, TextFile, Buffer)
Xstruct PattDesc *DescVec[]; /* pointers to status vectors for the different
X	* patterns, including skip tables, position in buffer, etc. */
Xint NPats; /* number of patterns */
Xchar Buffer[]; /* holds text from file */
Xint TextFile; /* file to search */
X{
X	int NRead, /* number of chars read from file */
X		NWanted, /* number of chars wanted */
X		NAvail, /* number of chars actually read */
X		BuffSize, /* number of chars in buffer */
X		BuffPos, /* offset of first char in Buffer in TextFile */
X		BuffEx, /* flag to indicate that buffer has been searched */
X		ResSize,
X		/* number of characters in the last, incomplete line */
X		Found, /* flag indicates whether pattern found
X		* completely and all matches printed */
X		Valid; /* was the match "valid", i.e. if -x used,
X		* did the whole line match? */
X	char *BuffEnd; /* pointer to last char of last complete line */
X
X	/* misc working variables */
X	int i;
X
X	/* initialize */
X	ResSize = 0;
X	Found = 0;
X	BuffPos = 0;
X	for (i=0; i < NPats; i++) {
X		DescVec[i] -> Success = 0;
X		DescVec[i] -> Start = Buffer;
X	} /* for */
X	/* now do the searching */
X	do {
X		/* first, read a bufferfull and set up the variables */
X		NWanted = MAXBUFF - ResSize; NRead = 0;
X		do {
X			NAvail =
X			   read(TextFile,Buffer + ResSize + NRead, NWanted);
X			if (NAvail == -1) {
X				fprintf(stderr,
X				  "bm: error reading from input file\n");
X				exit(2);
X			} /* if */
X			NRead += NAvail; NWanted -= NAvail;
X		} while (NAvail && NWanted);
X		BuffEx = 0;
X		BuffSize = ResSize + NRead;
X		BuffEnd = Buffer + BuffSize - 1;
X		/* locate the end of the last complete line */
X		while (*BuffEnd != '\n' && BuffEnd >= Buffer)
X			--BuffEnd;
X		if (BuffEnd < Buffer)
X			BuffEnd = Buffer + BuffSize - 1;
X		while (!BuffEx) { /* work through one buffer full */
X			BuffEx = 1; /* set it provisionally, then clear
X			* it if we find the buffer non-empty */
X			for (i=0; i< NPats; i++) {
X				if (!DescVec[i]->Success)
X				/* if the pattern  has not been found */
X					DescVec[i]-> Success =
X					Search(DescVec[i]->Pattern,
X					DescVec[i]->PatLen, Buffer, BuffEnd,
X					DescVec[i]->Skip1, DescVec[i]->Skip2,
X					DescVec[i]);
X				if (DescVec[i]->Success){
X				/* if a match occurred */
X					BuffEx = 0;
X					Valid = MatchFound(DescVec[i],BuffPos,
X					Buffer, BuffEnd);
X					Found |= Valid;
X					if ((sFlag || lFlag) && Found)
X						return(0);
X				} /* if */
X			} /* for */
X		} /* while */
X		if(NRead) {
X			ResSize = MoveResidue(DescVec,NPats,Buffer,
X				Buffer + BuffSize -1);
X			BuffPos += BuffSize - ResSize;
X		} /* if */
X	} while (NRead);
X	return(!Found);
X} /* Execute */
e-o-f
exit 0
 



More information about the Mod.sources mailing list