Category : C Source Code
Archive   : FASTGREP.ZIP
Filename : MATCHFOU.C

 
Output of file : MATCHFOU.C contained in archive : FASTGREP.ZIP

#include
#include "bm.h"
#include "extern.h"
MatchFound(Desc, BuffPos, Buffer, BuffEnd)
struct PattDesc *Desc; /* state info about search for one string */
int BuffPos; /* offset of first char of buffer into the file being searched */
char *Buffer, /* pointer to the first character in the buffer */
*BuffEnd; /* pointer to the last character in the buffer */
{
char *MLineBegin, *MLineEnd;
Desc->Success = 0;
if (cFlag)
{
++MatchCount;
return;
} /* if */
/* Start points to first character after a successful match */
MLineBegin = MLineEnd = Desc->Start - 1;
while(MLineBegin >=Buffer && *MLineBegin != '\n')
{
--MLineBegin;
}
++MLineBegin;
while( MLineEnd <= BuffEnd && *MLineEnd != '\n')
{
++MLineEnd;
}
if (MLineEnd > BuffEnd) --MLineEnd;
/* check if exact match */
if (xFlag && !( Desc->PatLen == (*MLineEnd != '\n' ? ((MLineEnd -
MLineBegin) + 1) : (MLineEnd - MLineBegin))))
{
/* fixed 25jun85 pdbain. suppress multiple matches of the same
pattern on one line */
Desc->Start = MLineEnd + 1;
return;
}
PrintLine(BuffPos+(Desc->Start-Buffer),MLineBegin,MLineEnd,Desc->PatLen);
/* fixed 25jun85 pdbain. suppress multiple matches of the same
pattern on one line */
Desc->Start = MLineEnd + 1;
} /* MatchFound */