bsdgrep: correct assumptions to prepare for chunking
Correct a couple of minor BSD grep assumptions that are valid for line processing but not future chunk-based processing. Submitted by: Kyle Evans <kevans91@ksu.edu> Reviewed by: bapt, cem Differential Revision: https://reviews.freebsd.org/D10824
This commit is contained in:
parent
b773cce6a6
commit
6b50dcbb8c
@ -78,7 +78,7 @@ const char *errstr[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Flags passed to regcomp() and regexec() */
|
/* Flags passed to regcomp() and regexec() */
|
||||||
int cflags = REG_NOSUB;
|
int cflags = REG_NOSUB | REG_NEWLINE;
|
||||||
int eflags = REG_STARTEND;
|
int eflags = REG_STARTEND;
|
||||||
|
|
||||||
/* XXX TODO: Get rid of this flag.
|
/* XXX TODO: Get rid of this flag.
|
||||||
|
@ -82,7 +82,7 @@ extern const char *errstr[];
|
|||||||
#define EXCL_PAT 0
|
#define EXCL_PAT 0
|
||||||
#define INCL_PAT 1
|
#define INCL_PAT 1
|
||||||
|
|
||||||
#define MAX_LINE_MATCHES 32
|
#define MAX_MATCHES 32
|
||||||
|
|
||||||
struct file {
|
struct file {
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -61,7 +61,7 @@ static bool first_match = true;
|
|||||||
* other useful bits
|
* other useful bits
|
||||||
*/
|
*/
|
||||||
struct parsec {
|
struct parsec {
|
||||||
regmatch_t matches[MAX_LINE_MATCHES]; /* Matches made */
|
regmatch_t matches[MAX_MATCHES]; /* Matches made */
|
||||||
struct str ln; /* Current line */
|
struct str ln; /* Current line */
|
||||||
size_t lnstart; /* Position in line */
|
size_t lnstart; /* Position in line */
|
||||||
size_t matchidx; /* Latest match index */
|
size_t matchidx; /* Latest match index */
|
||||||
@ -295,7 +295,7 @@ procfile(const char *fn)
|
|||||||
/* Print the matching line, but only if not quiet/binary */
|
/* Print the matching line, but only if not quiet/binary */
|
||||||
if (t == 0 && printmatch) {
|
if (t == 0 && printmatch) {
|
||||||
printline(&pc, ':');
|
printline(&pc, ':');
|
||||||
while (pc.matchidx >= MAX_LINE_MATCHES) {
|
while (pc.matchidx >= MAX_MATCHES) {
|
||||||
/* Reset matchidx and try again */
|
/* Reset matchidx and try again */
|
||||||
pc.matchidx = 0;
|
pc.matchidx = 0;
|
||||||
if (procline(&pc) == 0)
|
if (procline(&pc) == 0)
|
||||||
@ -401,7 +401,7 @@ procline(struct parsec *pc)
|
|||||||
lastmatches = 0;
|
lastmatches = 0;
|
||||||
startm = matchidx;
|
startm = matchidx;
|
||||||
retry = 0;
|
retry = 0;
|
||||||
if (st > 0)
|
if (st > 0 && pc->ln.dat[st - 1] != fileeol)
|
||||||
leflags |= REG_NOTBOL;
|
leflags |= REG_NOTBOL;
|
||||||
/* Loop to compare with all the patterns */
|
/* Loop to compare with all the patterns */
|
||||||
for (i = 0; i < patterns; i++) {
|
for (i = 0; i < patterns; i++) {
|
||||||
@ -483,7 +483,7 @@ procline(struct parsec *pc)
|
|||||||
}
|
}
|
||||||
/* avoid excessive matching - skip further patterns */
|
/* avoid excessive matching - skip further patterns */
|
||||||
if ((color == NULL && !oflag) || qflag || lflag ||
|
if ((color == NULL && !oflag) || qflag || lflag ||
|
||||||
matchidx >= MAX_LINE_MATCHES) {
|
matchidx >= MAX_MATCHES) {
|
||||||
pc->lnstart = nst;
|
pc->lnstart = nst;
|
||||||
lastmatches = 0;
|
lastmatches = 0;
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user