CVS commit: src/usr.bin/grep
Module Name:src Committed By: msaitoh Date: Mon Jan 21 03:24:43 UTC 2013 Modified Files: src/usr.bin/grep: util.c Log Message: Fix memory leak in file_matching(). To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.16 src/usr.bin/grep/util.c:1.17 --- src/usr.bin/grep/util.c:1.16 Sun May 6 22:32:05 2012 +++ src/usr.bin/grep/util.c Mon Jan 21 03:24:43 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.16 2012/05/06 22:32:05 joerg Exp $ */ +/* $NetBSD: util.c,v 1.17 2013/01/21 03:24:43 msaitoh Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: util.c,v 1.16 2012/05/06 22:32:05 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.17 2013/01/21 03:24:43 msaitoh Exp $"); #include #include @@ -74,9 +74,10 @@ file_matching(const char *fname) for (i = 0; i < fpatterns; ++i) { if (fnmatch(fpattern[i].pat, fname, 0) == 0 || fnmatch(fpattern[i].pat, fname_base, 0) == 0) { - if (fpattern[i].mode == EXCL_PAT) + if (fpattern[i].mode == EXCL_PAT) { +free(fname_copy); return (false); - else + } else ret = true; } }
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Wed Aug 17 15:32:20 UTC 2011 Modified Files: src/usr.bin/grep: Makefile Log Message: document non-literal format strings To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.bin/grep/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/Makefile diff -u src/usr.bin/grep/Makefile:1.4 src/usr.bin/grep/Makefile:1.5 --- src/usr.bin/grep/Makefile:1.4 Tue Feb 15 20:31:33 2011 +++ src/usr.bin/grep/Makefile Wed Aug 17 11:32:20 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.4 2011/02/16 01:31:33 joerg Exp $ +# $NetBSD: Makefile,v 1.5 2011/08/17 15:32:20 christos Exp $ # $FreeBSD: head/usr.bin/grep/Makefile 210389 2010-07-22 19:11:57Z gabor $ # $OpenBSD: Makefile,v 1.6 2003/06/25 15:00:04 millert Exp $ @@ -34,4 +34,7 @@ uk_UA.UTF-8.msg \ zh_CN.UTF-8.msg +COPTS.grep.c += -Wno-format-nonliteral +COPTS.util.c += -Wno-format-nonliteral + .include
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Sun May 6 21:56:08 UTC 2012 Modified Files: src/usr.bin/grep: util.c Log Message: Make the matchall case a full short cut. To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.13 src/usr.bin/grep/util.c:1.14 --- src/usr.bin/grep/util.c:1.13 Mon Apr 18 23:22:42 2011 +++ src/usr.bin/grep/util.c Sun May 6 21:56:08 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.13 2011/04/18 23:22:42 joerg Exp $ */ +/* $NetBSD: util.c,v 1.14 2012/05/06 21:56:08 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: util.c,v 1.13 2011/04/18 23:22:42 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.14 2012/05/06 21:56:08 joerg Exp $"); #include #include @@ -295,78 +295,86 @@ procline(struct str *l, int nottext) unsigned int i; int c = 0, m = 0, r = 0; - if (!matchall) { - /* Loop to process the whole line */ - while (st <= l->len) { - pmatch.rm_so = st; - pmatch.rm_eo = l->len; + if (matchall) { + /* Short cut the case of (not) matching wild card pattern */ + if (vflag) + return (0); + if ((binbehave == BINFILE_BIN && nottext) || cflag || qflag || + lflag || Lflag) + return (1); + printline(l, ':', matches, m); + return (1); + } - /* Loop to compare with all the patterns */ - for (i = 0; i < patterns; i++) { + /* Loop to process the whole line */ + while (st <= l->len) { + pmatch.rm_so = st; + pmatch.rm_eo = l->len; + + /* Loop to compare with all the patterns */ + for (i = 0; i < patterns; i++) { /* * XXX: grep_search() is a workaround for speed up and should be * removed in the future. See fastgrep.c. */ -if (fg_pattern[i].pattern) { - r = grep_search(&fg_pattern[i], - (unsigned char *)l->dat, - l->len, &pmatch); - r = (r == 0) ? 0 : REG_NOMATCH; - st = pmatch.rm_eo; -} else { - r = regexec(&r_pattern[i], l->dat, 1, - &pmatch, eflags); - r = (r == 0) ? 0 : REG_NOMATCH; - st = pmatch.rm_eo; -} -if (r == REG_NOMATCH) - continue; -/* Check for full match */ -if (r == 0 && xflag) - if (pmatch.rm_so != 0 || - (size_t)pmatch.rm_eo != l->len) - r = REG_NOMATCH; -/* Check for whole word match */ -if (r == 0 && fg_pattern[i].word && -pmatch.rm_so != 0) { - wint_t wbegin, wend; - - wbegin = wend = L' '; - if (pmatch.rm_so != 0 && - sscanf(&l->dat[pmatch.rm_so - 1], - "%lc", &wbegin) != 1) - r = REG_NOMATCH; - else if ((size_t)pmatch.rm_eo != l->len && - sscanf(&l->dat[pmatch.rm_eo], - "%lc", &wend) != 1) - r = REG_NOMATCH; - else if (iswword(wbegin) || iswword(wend)) - r = REG_NOMATCH; -} -if (r == 0) { - if (m == 0) - c++; - if (m < MAX_LINE_MATCHES) - matches[m++] = pmatch; - /* matches - skip further patterns */ - if ((color != NULL && !oflag) || qflag || lflag) - break; -} + if (fg_pattern[i].pattern) { +r = grep_search(&fg_pattern[i], +(unsigned char *)l->dat, +l->len, &pmatch); +r = (r == 0) ? 0 : REG_NOMATCH; +st = pmatch.rm_eo; + } else { +r = regexec(&r_pattern[i], l->dat, 1, +&pmatch, eflags); +r = (r == 0) ? 0 : REG_NOMATCH; +st = pmatch.rm_eo; } - - if (vflag) { -c = !c; -break; + if (r == REG_NOMATCH) +continue; + /* Check for full match */ + if (r == 0 && xflag) +if (pmatch.rm_so != 0 || +(size_t)pmatch.rm_eo != l->len) + r = REG_NOMATCH; + /* Check for whole word match */ + if (r == 0 && fg_pattern[i].word && + pmatch.rm_so != 0) { +wint_t wbegin, wend; + +wbegin = wend = L' '; +if (pmatch.rm_so != 0 && +sscanf(&l->dat[pmatch.rm_so - 1], +"%lc", &wbegin) != 1) + r = REG_NOMATCH; +else if ((size_t)pmatch.rm_eo != l->len && +sscanf(&l->dat[pmatch.rm_eo], +"%lc", &wend) != 1) + r = REG_NOMATCH; +else if (iswword(wbegin) || iswword(wend)) + r = REG_NOMATCH; } - /* One pass if we are not recording matches */ - if ((color != NULL && !oflag) || qflag || lflag) -break; + if (r == 0) { +if (m == 0) + c++; +if (m < MAX_LINE_MATCHES) + matches[m++] = pmatch; +/* matches - skip further patterns */ +if ((color != NULL && !oflag) || qflag || lflag) + break; + } + } - if (st == (size_t)pmatch.rm_so) -break; /* No matches */ + if (vflag) { + c = !c; + break; } - } else - c = !vflag; + /* One pass if we are not recording matches */ + if ((color != NULL && !oflag) || qflag || lflag) + break; + + if (st
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Sun May 6 22:27:01 UTC 2012 Modified Files: src/usr.bin/grep: grep.c grep.h util.c Log Message: Remove matchall handling for now, it doesn't work correctly and as such, it is a premature optimisation. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.bin/grep/grep.c cvs rdiff -u -r1.7 -r1.8 src/usr.bin/grep/grep.h cvs rdiff -u -r1.14 -r1.15 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/grep.c diff -u src/usr.bin/grep/grep.c:1.10 src/usr.bin/grep/grep.c:1.11 --- src/usr.bin/grep/grep.c:1.10 Fri Sep 16 15:39:26 2011 +++ src/usr.bin/grep/grep.c Sun May 6 22:27:00 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.10 2011/09/16 15:39:26 joerg Exp $ */ +/* $NetBSD: grep.c,v 1.11 2012/05/06 22:27:00 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: grep.c,v 1.10 2011/09/16 15:39:26 joerg Exp $"); +__RCSID("$NetBSD: grep.c,v 1.11 2012/05/06 22:27:00 joerg Exp $"); #include #include @@ -80,9 +80,6 @@ const char *errstr[] = { int cflags = 0; int eflags = REG_STARTEND; -/* Shortcut for matching all cases like empty regex */ -bool matchall; - /* Searching patterns */ unsigned int patterns, pattern_sz; char **pattern; @@ -229,11 +226,8 @@ static void add_pattern(char *pat, size_t len) { - /* Check if we can do a shortcut */ - if (len == 0 || matchall) { - matchall = true; - return; - } + /* TODO: Check for empty patterns and shortcut */ + /* Increase size if necessary */ if (patterns == pattern_sz) { pattern_sz *= 2; Index: src/usr.bin/grep/grep.h diff -u src/usr.bin/grep/grep.h:1.7 src/usr.bin/grep/grep.h:1.8 --- src/usr.bin/grep/grep.h:1.7 Mon Apr 18 22:46:48 2011 +++ src/usr.bin/grep/grep.h Sun May 6 22:27:00 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.h,v 1.7 2011/04/18 22:46:48 joerg Exp $ */ +/* $NetBSD: grep.h,v 1.8 2012/05/06 22:27:00 joerg Exp $ */ /* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $ */ @@ -120,7 +120,7 @@ extern char *label; extern const char *color; extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave; -extern bool matchall, notfound; +extern bool notfound; extern int tail; extern unsigned int dpatterns, fpatterns, patterns; extern char**pattern; Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.14 src/usr.bin/grep/util.c:1.15 --- src/usr.bin/grep/util.c:1.14 Sun May 6 21:56:08 2012 +++ src/usr.bin/grep/util.c Sun May 6 22:27:01 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.14 2012/05/06 21:56:08 joerg Exp $ */ +/* $NetBSD: util.c,v 1.15 2012/05/06 22:27:01 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: util.c,v 1.14 2012/05/06 21:56:08 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.15 2012/05/06 22:27:01 joerg Exp $"); #include #include @@ -227,12 +227,8 @@ procfile(const char *fn) for (first = true, c = 0; c == 0 || !(lflag || qflag); ) { ln.off += ln.len + 1; - if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL || ln.len == 0) { - if (ln.line_no == 0 && matchall) -exit(0); - else -break; - } + if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL || ln.len == 0) + break; if (ln.len > 0 && ln.dat[ln.len - 1] == line_sep) --ln.len; ln.line_no++; @@ -295,17 +291,6 @@ procline(struct str *l, int nottext) unsigned int i; int c = 0, m = 0, r = 0; - if (matchall) { - /* Short cut the case of (not) matching wild card pattern */ - if (vflag) - return (0); - if ((binbehave == BINFILE_BIN && nottext) || cflag || qflag || - lflag || Lflag) - return (1); - printline(l, ':', matches, m); - return (1); - } - /* Loop to process the whole line */ while (st <= l->len) { pmatch.rm_so = st;
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Sun May 6 22:32:05 UTC 2012 Modified Files: src/usr.bin/grep: util.c Log Message: Consistently short cut the pattern loop on mismatches. Don't assign 1 conditionally, if unconditional works as well. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.15 src/usr.bin/grep/util.c:1.16 --- src/usr.bin/grep/util.c:1.15 Sun May 6 22:27:01 2012 +++ src/usr.bin/grep/util.c Sun May 6 22:32:05 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.15 2012/05/06 22:27:01 joerg Exp $ */ +/* $NetBSD: util.c,v 1.16 2012/05/06 22:32:05 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: util.c,v 1.15 2012/05/06 22:27:01 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.16 2012/05/06 22:32:05 joerg Exp $"); #include #include @@ -317,36 +317,32 @@ procline(struct str *l, int nottext) if (r == REG_NOMATCH) continue; /* Check for full match */ - if (r == 0 && xflag) -if (pmatch.rm_so != 0 || -(size_t)pmatch.rm_eo != l->len) - r = REG_NOMATCH; + if (xflag && + (pmatch.rm_so != 0 || + (size_t)pmatch.rm_eo != l->len)) +continue; /* Check for whole word match */ - if (r == 0 && fg_pattern[i].word && - pmatch.rm_so != 0) { + if (fg_pattern[i].word && pmatch.rm_so != 0) { wint_t wbegin, wend; wbegin = wend = L' '; if (pmatch.rm_so != 0 && sscanf(&l->dat[pmatch.rm_so - 1], "%lc", &wbegin) != 1) - r = REG_NOMATCH; -else if ((size_t)pmatch.rm_eo != l->len && + continue; +if ((size_t)pmatch.rm_eo != l->len && sscanf(&l->dat[pmatch.rm_eo], "%lc", &wend) != 1) - r = REG_NOMATCH; -else if (iswword(wbegin) || iswword(wend)) - r = REG_NOMATCH; - } - if (r == 0) { -if (m == 0) - c++; -if (m < MAX_LINE_MATCHES) - matches[m++] = pmatch; -/* matches - skip further patterns */ -if ((color != NULL && !oflag) || qflag || lflag) - break; + continue; +if (iswword(wbegin) || iswword(wend)) + continue; } + c = 1; + if (m < MAX_LINE_MATCHES) +matches[m++] = pmatch; + /* matches - skip further patterns */ + if ((color != NULL && !oflag) || qflag || lflag) +break; } if (vflag) {
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Wed Feb 16 18:35:39 UTC 2011 Modified Files: src/usr.bin/grep: fastgrep.c file.c util.c Log Message: Fix signed / unsigned issues. Refactor basename usage to use a local copy and do it only once, not for each pattern. Remove late inline. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.bin/grep/fastgrep.c cvs rdiff -u -r1.4 -r1.5 src/usr.bin/grep/file.c cvs rdiff -u -r1.7 -r1.8 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/fastgrep.c diff -u src/usr.bin/grep/fastgrep.c:1.1 src/usr.bin/grep/fastgrep.c:1.2 --- src/usr.bin/grep/fastgrep.c:1.1 Wed Feb 16 01:31:33 2011 +++ src/usr.bin/grep/fastgrep.c Wed Feb 16 18:35:39 2011 @@ -36,7 +36,7 @@ */ #include -__RCSID("$NetBSD: fastgrep.c,v 1.1 2011/02/16 01:31:33 joerg Exp $"); +__RCSID("$NetBSD: fastgrep.c,v 1.2 2011/02/16 18:35:39 joerg Exp $"); #include #include @@ -61,8 +61,7 @@ fg->eol = false; fg->reversed = false; - fg->pattern = grep_malloc(strlen(pat) + 1); - strcpy(fg->pattern, pat); + fg->pattern = (unsigned char *)grep_strdup(pat); /* Preprocess pattern. */ for (i = 0; i <= UCHAR_MAX; i++) @@ -120,7 +119,8 @@ * string respectively. */ fg->pattern = grep_malloc(fg->len + 1); - strlcpy(fg->pattern, pat + (bol ? 1 : 0) + wflag, fg->len + 1); + strlcpy((char *)fg->pattern, pat + (bol ? 1 : 0) + wflag, + fg->len + 1); /* Look for ways to cheat...er...avoid the full regex engine. */ for (i = 0; i < fg->len; i++) { Index: src/usr.bin/grep/file.c diff -u src/usr.bin/grep/file.c:1.4 src/usr.bin/grep/file.c:1.5 --- src/usr.bin/grep/file.c:1.4 Wed Feb 16 01:31:33 2011 +++ src/usr.bin/grep/file.c Wed Feb 16 18:35:39 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.4 2011/02/16 01:31:33 joerg Exp $ */ +/* $NetBSD: file.c,v 1.5 2011/02/16 18:35:39 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/file.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $ */ @@ -31,7 +31,7 @@ */ #include -__RCSID("$NetBSD: file.c,v 1.4 2011/02/16 01:31:33 joerg Exp $"); +__RCSID("$NetBSD: file.c,v 1.5 2011/02/16 18:35:39 joerg Exp $"); #include #include @@ -139,13 +139,13 @@ if (bufrem == 0) { /* Return zero length to indicate EOF */ *lenp = 0; - return (bufpos); + return ((char *)bufpos); } /* Look for a newline in the remaining part of the buffer */ if ((p = memchr(bufpos, '\n', bufrem)) != NULL) { ++p; /* advance over newline */ - ret = bufpos; + ret = (char *)bufpos; len = p - bufpos; bufrem -= len; bufpos = p; @@ -179,7 +179,7 @@ break; } *lenp = len; - return (lnbuf); + return ((char *)lnbuf); error: *lenp = 0; Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.7 src/usr.bin/grep/util.c:1.8 --- src/usr.bin/grep/util.c:1.7 Wed Feb 16 01:31:33 2011 +++ src/usr.bin/grep/util.c Wed Feb 16 18:35:39 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.7 2011/02/16 01:31:33 joerg Exp $ */ +/* $NetBSD: util.c,v 1.8 2011/02/16 18:35:39 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: util.c,v 1.7 2011/02/16 01:31:33 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.8 2011/02/16 18:35:39 joerg Exp $"); #include #include @@ -57,20 +57,23 @@ bool file_matching(const char *fname) { + char *fname_base, *fname_copy; bool ret; ret = finclude ? false : true; + fname_copy = grep_strdup(fname); + fname_base = basename(fname_copy); for (unsigned int i = 0; i < fpatterns; ++i) { - if (fnmatch(fpattern[i].pat, - fname, 0) == 0 || fnmatch(fpattern[i].pat, - basename(fname), 0) == 0) { + if (fnmatch(fpattern[i].pat, fname, 0) == 0 || + fnmatch(fpattern[i].pat, fname_base, 0) == 0) { if (fpattern[i].mode == EXCL_PAT) return (false); else ret = true; } } + free(fname_copy); return (ret); } @@ -279,7 +282,7 @@ * matches. The matching lines are passed to printline() to display the * appropriate output. */ -static inline int +static int procline(struct str *l, int nottext) { regmatch_t matches[MAX_LINE_MATCHES];
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Thu Feb 17 22:03:25 UTC 2011 Modified Files: src/usr.bin/grep: fastgrep.c Log Message: Simplify. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.bin/grep/fastgrep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/fastgrep.c diff -u src/usr.bin/grep/fastgrep.c:1.2 src/usr.bin/grep/fastgrep.c:1.3 --- src/usr.bin/grep/fastgrep.c:1.2 Wed Feb 16 18:35:39 2011 +++ src/usr.bin/grep/fastgrep.c Thu Feb 17 22:03:25 2011 @@ -36,7 +36,7 @@ */ #include -__RCSID("$NetBSD: fastgrep.c,v 1.2 2011/02/16 18:35:39 joerg Exp $"); +__RCSID("$NetBSD: fastgrep.c,v 1.3 2011/02/17 22:03:25 joerg Exp $"); #include #include @@ -82,8 +82,6 @@ int hasDot = 0; int lastHalfDot = 0; int shiftPatternLen; - bool bol = false; - bool eol = false; /* Initialize. */ fg->len = strlen(pat); @@ -93,34 +91,34 @@ /* Remove end-of-line character ('$'). */ if (fg->len > 0 && pat[fg->len - 1] == '$') { - eol = true; fg->eol = true; fg->len--; } /* Remove beginning-of-line character ('^'). */ if (pat[0] == '^') { - bol = true; fg->bol = true; fg->len--; + pat++; } if (fg->len >= 14 && - strncmp(pat + (fg->bol ? 1 : 0), "[[:<:]]", 7) == 0 && - strncmp(pat + (fg->bol ? 1 : 0) + fg->len - 7, "[[:>:]]", 7) == 0) { + memcmp(pat, "[[:<:]]", 7) == 0 && + memcmp(pat + fg->len - 7, "[[:>:]]", 7) == 0) { fg->len -= 14; + pat += 7; /* Word boundary is handled separately in util.c */ wflag = true; } /* - * Copy pattern minus '^' and '$' characters as well as word - * match character classes at the beginning and ending of the - * string respectively. + * pat has been adjusted earlier to not include '^', '$' or + * the word match character classes at the beginning and ending + * of the string respectively. */ fg->pattern = grep_malloc(fg->len + 1); - strlcpy((char *)fg->pattern, pat + (bol ? 1 : 0) + wflag, - fg->len + 1); + memcpy(fg->pattern, pat, fg->len); + fg->pattern[fg->len] = '\0'; /* Look for ways to cheat...er...avoid the full regex engine. */ for (i = 0; i < fg->len; i++) { @@ -149,7 +147,7 @@ * Determine if a reverse search would be faster based on the placement * of the dots. */ - if ((!(lflag || cflag)) && ((!(bol || eol)) && + if ((!(lflag || cflag)) && ((!(fg->bol || fg->eol)) && ((lastHalfDot) && ((firstHalfDot < 0) || ((fg->len - (lastHalfDot + 1)) < (size_t)firstHalfDot && !oflag && !color) {
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Sun Feb 27 17:33:37 UTC 2011 Modified Files: src/usr.bin/grep: fastgrep.c grep.h util.c Log Message: If transforming patterns with \<...\> to implicit word bounaries, don't change the global wflag, but use a per pattern flag derived from it. Fixes usage of grep with multiple -w arguments. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.bin/grep/fastgrep.c cvs rdiff -u -r1.4 -r1.5 src/usr.bin/grep/grep.h cvs rdiff -u -r1.8 -r1.9 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/fastgrep.c diff -u src/usr.bin/grep/fastgrep.c:1.3 src/usr.bin/grep/fastgrep.c:1.4 --- src/usr.bin/grep/fastgrep.c:1.3 Thu Feb 17 22:03:25 2011 +++ src/usr.bin/grep/fastgrep.c Sun Feb 27 17:33:37 2011 @@ -36,7 +36,7 @@ */ #include -__RCSID("$NetBSD: fastgrep.c,v 1.3 2011/02/17 22:03:25 joerg Exp $"); +__RCSID("$NetBSD: fastgrep.c,v 1.4 2011/02/27 17:33:37 joerg Exp $"); #include #include @@ -88,6 +88,7 @@ fg->bol = false; fg->eol = false; fg->reversed = false; + fg->word = wflag; /* Remove end-of-line character ('$'). */ if (fg->len > 0 && pat[fg->len - 1] == '$') { @@ -108,7 +109,7 @@ fg->len -= 14; pat += 7; /* Word boundary is handled separately in util.c */ - wflag = true; + fg->word = true; } /* Index: src/usr.bin/grep/grep.h diff -u src/usr.bin/grep/grep.h:1.4 src/usr.bin/grep/grep.h:1.5 --- src/usr.bin/grep/grep.h:1.4 Wed Feb 16 01:31:33 2011 +++ src/usr.bin/grep/grep.h Sun Feb 27 17:33:37 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.h,v 1.4 2011/02/16 01:31:33 joerg Exp $ */ +/* $NetBSD: grep.h,v 1.5 2011/02/27 17:33:37 joerg Exp $ */ /* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $ */ @@ -103,6 +103,7 @@ bool bol; bool eol; bool reversed; + bool word; } fastgrep_t; /* Flags passed to regcomp() and regexec() */ Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.8 src/usr.bin/grep/util.c:1.9 --- src/usr.bin/grep/util.c:1.8 Wed Feb 16 18:35:39 2011 +++ src/usr.bin/grep/util.c Sun Feb 27 17:33:37 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.8 2011/02/16 18:35:39 joerg Exp $ */ +/* $NetBSD: util.c,v 1.9 2011/02/27 17:33:37 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: util.c,v 1.8 2011/02/16 18:35:39 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.9 2011/02/27 17:33:37 joerg Exp $"); #include #include @@ -323,7 +323,8 @@ (size_t)pmatch.rm_eo != l->len) r = REG_NOMATCH; /* Check for whole word match */ -if (r == 0 && wflag && pmatch.rm_so != 0) { +if (r == 0 && fg_pattern[i].word && +pmatch.rm_so != 0) { wint_t wbegin, wend; wbegin = wend = L' ';
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Mon Apr 18 03:27:40 UTC 2011 Modified Files: src/usr.bin/grep: fastgrep.c file.c grep.c queue.c util.c Log Message: Include nbtool_config.h for tool builds. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.bin/grep/fastgrep.c src/usr.bin/grep/grep.c cvs rdiff -u -r1.5 -r1.6 src/usr.bin/grep/file.c cvs rdiff -u -r1.2 -r1.3 src/usr.bin/grep/queue.c cvs rdiff -u -r1.9 -r1.10 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/fastgrep.c diff -u src/usr.bin/grep/fastgrep.c:1.4 src/usr.bin/grep/fastgrep.c:1.5 --- src/usr.bin/grep/fastgrep.c:1.4 Sun Feb 27 17:33:37 2011 +++ src/usr.bin/grep/fastgrep.c Mon Apr 18 03:27:40 2011 @@ -35,8 +35,12 @@ * meantime, we need to use this workaround. */ +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #include -__RCSID("$NetBSD: fastgrep.c,v 1.4 2011/02/27 17:33:37 joerg Exp $"); +__RCSID("$NetBSD: fastgrep.c,v 1.5 2011/04/18 03:27:40 joerg Exp $"); #include #include Index: src/usr.bin/grep/grep.c diff -u src/usr.bin/grep/grep.c:1.4 src/usr.bin/grep/grep.c:1.5 --- src/usr.bin/grep/grep.c:1.4 Wed Feb 16 01:31:33 2011 +++ src/usr.bin/grep/grep.c Mon Apr 18 03:27:40 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.4 2011/02/16 01:31:33 joerg Exp $ */ +/* $NetBSD: grep.c,v 1.5 2011/04/18 03:27:40 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -29,8 +29,12 @@ * SUCH DAMAGE. */ +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #include -__RCSID("$NetBSD: grep.c,v 1.4 2011/02/16 01:31:33 joerg Exp $"); +__RCSID("$NetBSD: grep.c,v 1.5 2011/04/18 03:27:40 joerg Exp $"); #include #include Index: src/usr.bin/grep/file.c diff -u src/usr.bin/grep/file.c:1.5 src/usr.bin/grep/file.c:1.6 --- src/usr.bin/grep/file.c:1.5 Wed Feb 16 18:35:39 2011 +++ src/usr.bin/grep/file.c Mon Apr 18 03:27:40 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.5 2011/02/16 18:35:39 joerg Exp $ */ +/* $NetBSD: file.c,v 1.6 2011/04/18 03:27:40 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/file.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $ */ @@ -30,8 +30,12 @@ * SUCH DAMAGE. */ +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #include -__RCSID("$NetBSD: file.c,v 1.5 2011/02/16 18:35:39 joerg Exp $"); +__RCSID("$NetBSD: file.c,v 1.6 2011/04/18 03:27:40 joerg Exp $"); #include #include Index: src/usr.bin/grep/queue.c diff -u src/usr.bin/grep/queue.c:1.2 src/usr.bin/grep/queue.c:1.3 --- src/usr.bin/grep/queue.c:1.2 Wed Feb 16 01:31:33 2011 +++ src/usr.bin/grep/queue.c Mon Apr 18 03:27:40 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: queue.c,v 1.2 2011/02/16 01:31:33 joerg Exp $ */ +/* $NetBSD: queue.c,v 1.3 2011/04/18 03:27:40 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/queue.c 211496 2010-08-19 09:28:59Z des $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -31,8 +31,12 @@ * Dodge. It is used in place of to get a better performance. */ +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #include -__RCSID("$NetBSD: queue.c,v 1.2 2011/02/16 01:31:33 joerg Exp $"); +__RCSID("$NetBSD: queue.c,v 1.3 2011/04/18 03:27:40 joerg Exp $"); #include #include Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.9 src/usr.bin/grep/util.c:1.10 --- src/usr.bin/grep/util.c:1.9 Sun Feb 27 17:33:37 2011 +++ src/usr.bin/grep/util.c Mon Apr 18 03:27:40 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.9 2011/02/27 17:33:37 joerg Exp $ */ +/* $NetBSD: util.c,v 1.10 2011/04/18 03:27:40 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -29,8 +29,12 @@ * SUCH DAMAGE. */ +#if HAVE_NBTOOL_CONFIG_H +#include "nbtool_config.h" +#endif + #include -__RCSID("$NetBSD: util.c,v 1.9 2011/02/27 17:33:37 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.10 2011/04/18 03:27:40 joerg Exp $"); #include #include
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Mon Apr 18 03:47:40 UTC 2011 Modified Files: src/usr.bin/grep: queue.c Log Message: Fix memory leaks. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.bin/grep/queue.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/queue.c diff -u src/usr.bin/grep/queue.c:1.3 src/usr.bin/grep/queue.c:1.4 --- src/usr.bin/grep/queue.c:1.3 Mon Apr 18 03:27:40 2011 +++ src/usr.bin/grep/queue.c Mon Apr 18 03:47:40 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: queue.c,v 1.3 2011/04/18 03:27:40 joerg Exp $ */ +/* $NetBSD: queue.c,v 1.4 2011/04/18 03:47:40 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/queue.c 211496 2010-08-19 09:28:59Z des $ */ /*- * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav @@ -36,7 +36,7 @@ #endif #include -__RCSID("$NetBSD: queue.c,v 1.3 2011/04/18 03:27:40 joerg Exp $"); +__RCSID("$NetBSD: queue.c,v 1.4 2011/04/18 03:47:40 joerg Exp $"); #include #include @@ -71,8 +71,11 @@ STAILQ_INSERT_TAIL(&queue, item, list); - if (++count > Bflag) - free(dequeue()); + if (++count > Bflag) { + item = dequeue(); + free(item->data.dat); + free(item); + } } static struct qentry * @@ -96,6 +99,7 @@ while ((item = dequeue()) != NULL) { printline(&item->data, '-', (regmatch_t *)NULL, 0); + free(item->data.dat); free(item); } } @@ -105,6 +109,8 @@ { struct qentry *item; - while ((item = dequeue()) != NULL) + while ((item = dequeue()) != NULL) { + free(item->data.dat); free(item); + } }
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Mon Apr 18 03:48:23 UTC 2011 Modified Files: src/usr.bin/grep: grep.c Log Message: Use the more portable getline. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/grep/grep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/grep.c diff -u src/usr.bin/grep/grep.c:1.5 src/usr.bin/grep/grep.c:1.6 --- src/usr.bin/grep/grep.c:1.5 Mon Apr 18 03:27:40 2011 +++ src/usr.bin/grep/grep.c Mon Apr 18 03:48:23 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.5 2011/04/18 03:27:40 joerg Exp $ */ +/* $NetBSD: grep.c,v 1.6 2011/04/18 03:48:23 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: grep.c,v 1.5 2011/04/18 03:27:40 joerg Exp $"); +__RCSID("$NetBSD: grep.c,v 1.6 2011/04/18 03:48:23 joerg Exp $"); #include #include @@ -292,11 +292,15 @@ FILE *f; char *line; size_t len; + ssize_t rlen; if ((f = fopen(fn, "r")) == NULL) err(2, "%s", fn); - while ((line = fgetln(f, &len)) != NULL) - add_pattern(line, *line == '\n' ? 0 : len); + line = NULL; + len = 0; + while ((rlen = getline(&line, &len, f)) != -1) + add_pattern(line, *line == '\n' ? 0 : (size_t)rlen); + free(line); if (ferror(f)) err(2, "%s", fn); fclose(f);
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Mon Apr 18 17:18:04 UTC 2011 Modified Files: src/usr.bin/grep: grep.c grep.h util.c Log Message: Redo context printing so that adjourning contexts don't print the separator, following GNU grep's behavior in this regard. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/grep/grep.c cvs rdiff -u -r1.5 -r1.6 src/usr.bin/grep/grep.h cvs rdiff -u -r1.10 -r1.11 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/grep.c diff -u src/usr.bin/grep/grep.c:1.6 src/usr.bin/grep/grep.c:1.7 --- src/usr.bin/grep/grep.c:1.6 Mon Apr 18 03:48:23 2011 +++ src/usr.bin/grep/grep.c Mon Apr 18 17:18:03 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.6 2011/04/18 03:48:23 joerg Exp $ */ +/* $NetBSD: grep.c,v 1.7 2011/04/18 17:18:03 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: grep.c,v 1.6 2011/04/18 03:48:23 joerg Exp $"); +__RCSID("$NetBSD: grep.c,v 1.7 2011/04/18 17:18:03 joerg Exp $"); #include #include @@ -147,8 +147,6 @@ static inline const char *init_color(const char *); /* Housekeeping */ -bool first = true; /* flag whether we are processing the first match */ -bool prev; /* flag whether or not the previous line matched */ int tail; /* lines left to print */ bool notfound; /* file not found */ Index: src/usr.bin/grep/grep.h diff -u src/usr.bin/grep/grep.h:1.5 src/usr.bin/grep/grep.h:1.6 --- src/usr.bin/grep/grep.h:1.5 Sun Feb 27 17:33:37 2011 +++ src/usr.bin/grep/grep.h Mon Apr 18 17:18:04 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.h,v 1.5 2011/02/27 17:33:37 joerg Exp $ */ +/* $NetBSD: grep.h,v 1.6 2011/04/18 17:18:04 joerg Exp $ */ /* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $ */ @@ -119,7 +119,7 @@ extern const char *color; extern int binbehave, devbehave, dirbehave, filebehave, grepbehave, linkbehave; -extern bool first, matchall, notfound, prev; +extern bool matchall, notfound; extern int tail; extern unsigned int dpatterns, fpatterns, patterns; extern char**pattern; Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.10 src/usr.bin/grep/util.c:1.11 --- src/usr.bin/grep/util.c:1.10 Mon Apr 18 03:27:40 2011 +++ src/usr.bin/grep/util.c Mon Apr 18 17:18:04 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.10 2011/04/18 03:27:40 joerg Exp $ */ +/* $NetBSD: util.c,v 1.11 2011/04/18 17:18:04 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: util.c,v 1.10 2011/04/18 03:27:40 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.11 2011/04/18 17:18:04 joerg Exp $"); #include #include @@ -55,7 +55,9 @@ #include "grep.h" -static int linesqueued; +static bool first, first_global = true; +static unsigned long long since_printed; + static int procline(struct str *l, int); bool @@ -218,11 +220,10 @@ strcpy(ln.file, fn); ln.line_no = 0; ln.len = 0; - linesqueued = 0; tail = 0; ln.off = -1; - for (c = 0; c == 0 || !(lflag || qflag); ) { + for (first = true, c = 0; c == 0 || !(lflag || qflag); ) { ln.off += ln.len + 1; if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL || ln.len == 0) { if (ln.line_no == 0 && matchall) @@ -242,10 +243,7 @@ return (0); } /* Process the file line-by-line */ - if ((t = procline(&ln, f->binary)) == 0 && Bflag > 0) { - enqueue(&ln); - linesqueued++; - } + t = procline(&ln, f->binary); c += t; /* Count the matches if we have a match limit */ @@ -374,28 +372,25 @@ /* Dealing with the context */ if ((tail || c) && !cflag && !qflag && !lflag && !Lflag) { if (c) { - if (!first && !prev && !tail && Aflag) + if ((Aflag || Bflag) && !first_global && + (first || since_printed > Bflag)) printf("--\n"); tail = Aflag; - if (Bflag > 0) { -if (!first && !prev) - printf("--\n"); + if (Bflag > 0) printqueue(); - } - linesqueued = 0; printline(l, ':', matches, m); } else { printline(l, '-', matches, m); tail--; } - } - - if (c) { - prev = true; first = false; - } else - prev = false; - + first_global = false; + since_printed = 0; + } else { + if (Bflag) + enqueue(l); + since_printed++; + } return (c); }
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Mon Apr 18 22:46:49 UTC 2011 Modified Files: src/usr.bin/grep: file.c grep.1 grep.c grep.h util.c src/usr.bin/grep/nls: C.msg es_ES.ISO8859-1.msg gl_ES.ISO8859-1.msg hu_HU.ISO8859-2.msg ja_JP.SJIS.msg ja_JP.UTF-8.msg ja_JP.eucJP.msg pt_BR.ISO8859-1.msg ru_RU.KOI8-R.msg uk_UA.UTF-8.msg zh_CN.UTF-8.msg Log Message: Add support for --null-data. Change -Z to behave like GNU grep's -Z. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/grep/file.c src/usr.bin/grep/grep.h cvs rdiff -u -r1.2 -r1.3 src/usr.bin/grep/grep.1 cvs rdiff -u -r1.7 -r1.8 src/usr.bin/grep/grep.c cvs rdiff -u -r1.11 -r1.12 src/usr.bin/grep/util.c cvs rdiff -u -r1.1 -r1.2 src/usr.bin/grep/nls/C.msg \ src/usr.bin/grep/nls/es_ES.ISO8859-1.msg \ src/usr.bin/grep/nls/gl_ES.ISO8859-1.msg \ src/usr.bin/grep/nls/hu_HU.ISO8859-2.msg \ src/usr.bin/grep/nls/ja_JP.SJIS.msg src/usr.bin/grep/nls/ja_JP.UTF-8.msg \ src/usr.bin/grep/nls/ja_JP.eucJP.msg \ src/usr.bin/grep/nls/pt_BR.ISO8859-1.msg \ src/usr.bin/grep/nls/ru_RU.KOI8-R.msg \ src/usr.bin/grep/nls/uk_UA.UTF-8.msg src/usr.bin/grep/nls/zh_CN.UTF-8.msg Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/file.c diff -u src/usr.bin/grep/file.c:1.6 src/usr.bin/grep/file.c:1.7 --- src/usr.bin/grep/file.c:1.6 Mon Apr 18 03:27:40 2011 +++ src/usr.bin/grep/file.c Mon Apr 18 22:46:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.6 2011/04/18 03:27:40 joerg Exp $ */ +/* $NetBSD: file.c,v 1.7 2011/04/18 22:46:48 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/file.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $ */ @@ -35,7 +35,7 @@ #endif #include -__RCSID("$NetBSD: file.c,v 1.6 2011/04/18 03:27:40 joerg Exp $"); +__RCSID("$NetBSD: file.c,v 1.7 2011/04/18 22:46:48 joerg Exp $"); #include #include @@ -147,7 +147,7 @@ } /* Look for a newline in the remaining part of the buffer */ - if ((p = memchr(bufpos, '\n', bufrem)) != NULL) { + if ((p = memchr(bufpos, line_sep, bufrem)) != NULL) { ++p; /* advance over newline */ ret = (char *)bufpos; len = p - bufpos; @@ -169,7 +169,7 @@ if (bufrem == 0) /* EOF: return partial line */ break; - if ((p = memchr(bufpos, '\n', bufrem)) == NULL) + if ((p = memchr(bufpos, line_sep, bufrem)) == NULL) continue; /* got it: finish up the line (like code above) */ ++p; @@ -207,7 +207,8 @@ goto error; /* Check for binary stuff, if necessary */ - if (binbehave != BINFILE_TEXT && memchr(bufpos, '\0', bufrem) != NULL) + if (!nulldataflag && binbehave != BINFILE_TEXT && + memchr(bufpos, '\0', bufrem) != NULL) f->binary = true; return (f); Index: src/usr.bin/grep/grep.h diff -u src/usr.bin/grep/grep.h:1.6 src/usr.bin/grep/grep.h:1.7 --- src/usr.bin/grep/grep.h:1.6 Mon Apr 18 17:18:04 2011 +++ src/usr.bin/grep/grep.h Mon Apr 18 22:46:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.h,v 1.6 2011/04/18 17:18:04 joerg Exp $ */ +/* $NetBSD: grep.h,v 1.7 2011/04/18 22:46:48 joerg Exp $ */ /* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $ */ @@ -113,7 +113,8 @@ extern bool Eflag, Fflag, Gflag, Hflag, Lflag, bflag, cflag, hflag, iflag, lflag, mflag, nflag, oflag, qflag, sflag, vflag, wflag, xflag; -extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag; +extern bool dexclude, dinclude, fexclude, finclude, lbflag, nullflag, nulldataflag; +extern unsigned char line_sep; extern unsigned long long Aflag, Bflag, mcount; extern char *label; extern const char *color; Index: src/usr.bin/grep/grep.1 diff -u src/usr.bin/grep/grep.1:1.2 src/usr.bin/grep/grep.1:1.3 --- src/usr.bin/grep/grep.1:1.2 Wed Feb 16 01:31:33 2011 +++ src/usr.bin/grep/grep.1 Mon Apr 18 22:46:48 2011 @@ -1,4 +1,4 @@ -.\" $NetBSD: grep.1,v 1.2 2011/02/16 01:31:33 joerg Exp $ +.\" $NetBSD: grep.1,v 1.3 2011/04/18 22:46:48 joerg Exp $ .\" $FreeBSD: head/usr.bin/grep/grep.1 210652 2010-07-30 14:05:20Z joel $ .\" $OpenBSD: grep.1,v 1.38 2010/04/05 06:30:59 jmc Exp $ .\" Copyright (c) 1980, 1990, 1993 @@ -30,7 +30,7 @@ .\" .\" @(#)grep.1 8.3 (Berkeley) 4/18/94 .\" -.Dd July 28, 2010 +.Dd April 19, 2011 .Dt GREP 1 .Os .Sh NAME @@ -40,7 +40,7 @@ .Sh SYNOPSIS .Nm grep .Bk -words -.Op Fl abcdDEFGHhIiJLlmnOopqRSsUVvwxZ +.Op Fl abcdDEFGHhIiJLlmnOopqRSsUVvwxZz .Op Fl A Ar num .Op Fl B Ar num .Op Fl C Ns Op Ar num @@ -50,9 +50,9 @@ .Op Fl Fl color Ns Op = Ns Ar when .Op Fl Fl colour Ns Op = Ns Ar when .Op Fl Fl context Ns Op = Ns Ar num +.Op Fl Fl decompress .Op Fl Fl label .Op Fl Fl line-buffered -.Op Fl Fl null .Op Ar pattern .Op Ar .Ek @@ -318,8 +318,6 @@ .Fl q is specified. -.It Fl Fl null -Prints a zero-byte after the file name. .It F
CVS commit: src/usr.bin/grep
Module Name:src Committed By: joerg Date: Mon Apr 18 23:22:42 UTC 2011 Modified Files: src/usr.bin/grep: grep.c util.c Log Message: Avoid C99 features. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.bin/grep/grep.c cvs rdiff -u -r1.12 -r1.13 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/grep.c diff -u src/usr.bin/grep/grep.c:1.8 src/usr.bin/grep/grep.c:1.9 --- src/usr.bin/grep/grep.c:1.8 Mon Apr 18 22:46:48 2011 +++ src/usr.bin/grep/grep.c Mon Apr 18 23:22:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.8 2011/04/18 22:46:48 joerg Exp $ */ +/* $NetBSD: grep.c,v 1.9 2011/04/18 23:22:42 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: grep.c,v 1.8 2011/04/18 22:46:48 joerg Exp $"); +__RCSID("$NetBSD: grep.c,v 1.9 2011/04/18 23:22:42 joerg Exp $"); #include #include @@ -323,7 +323,7 @@ char **aargv, **eargv, *eopts; char *ep; unsigned long long l; - unsigned int aargc, eargc, i; + unsigned int aargc, eargc, i, j; int c, lastc, needpattern, newarg, prevoptind; setlocale(LC_ALL, ""); @@ -374,7 +374,7 @@ char *str; /* make an estimation of how many extra arguments we have */ - for (unsigned int j = 0; j < strlen(eopts); j++) + for (j = 0; j < strlen(eopts); j++) if (eopts[j] == ' ') eargc++; @@ -391,7 +391,7 @@ aargv[0] = argv[0]; for (i = 0; i < eargc; i++) aargv[i + 1] = eargv[i]; - for (int j = 1; j < argc; j++, i++) + for (j = 1; j < (unsigned int)argc; j++, i++) aargv[i + 1] = argv[j]; aargc = eargc + argc; Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.12 src/usr.bin/grep/util.c:1.13 --- src/usr.bin/grep/util.c:1.12 Mon Apr 18 22:46:48 2011 +++ src/usr.bin/grep/util.c Mon Apr 18 23:22:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.12 2011/04/18 22:46:48 joerg Exp $ */ +/* $NetBSD: util.c,v 1.13 2011/04/18 23:22:42 joerg Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: util.c,v 1.12 2011/04/18 22:46:48 joerg Exp $"); +__RCSID("$NetBSD: util.c,v 1.13 2011/04/18 23:22:42 joerg Exp $"); #include #include @@ -64,13 +64,14 @@ file_matching(const char *fname) { char *fname_base, *fname_copy; + unsigned int i; bool ret; ret = finclude ? false : true; fname_copy = grep_strdup(fname); fname_base = basename(fname_copy); - for (unsigned int i = 0; i < fpatterns; ++i) { + for (i = 0; i < fpatterns; ++i) { if (fnmatch(fpattern[i].pat, fname, 0) == 0 || fnmatch(fpattern[i].pat, fname_base, 0) == 0) { if (fpattern[i].mode == EXCL_PAT) @@ -86,11 +87,12 @@ static inline bool dir_matching(const char *dname) { + unsigned int i; bool ret; ret = dinclude ? false : true; - for (unsigned int i = 0; i < dpatterns; ++i) { + for (i = 0; i < dpatterns; ++i) { if (dname != NULL && fnmatch(dname, dpattern[i].pat, 0) == 0) { if (dpattern[i].mode == EXCL_PAT)
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Fri Jul 11 16:30:45 UTC 2014 Modified Files: src/usr.bin/grep: grep.c Log Message: remove dup usage print (enh at google dot com): arm just sent us (Android) this: https://android-review.googlesource.com/#/c/100970/1 To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.bin/grep/grep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/grep.c diff -u src/usr.bin/grep/grep.c:1.11 src/usr.bin/grep/grep.c:1.12 --- src/usr.bin/grep/grep.c:1.11 Sun May 6 18:27:00 2012 +++ src/usr.bin/grep/grep.c Fri Jul 11 12:30:45 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.11 2012/05/06 22:27:00 joerg Exp $ */ +/* $NetBSD: grep.c,v 1.12 2014/07/11 16:30:45 christos Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: grep.c,v 1.11 2012/05/06 22:27:00 joerg Exp $"); +__RCSID("$NetBSD: grep.c,v 1.12 2014/07/11 16:30:45 christos Exp $"); #include #include @@ -159,7 +159,6 @@ usage(void) { fprintf(stderr, getstr(4), __progname); fprintf(stderr, "%s", getstr(5)); - fprintf(stderr, "%s", getstr(5)); fprintf(stderr, "%s", getstr(6)); fprintf(stderr, "%s", getstr(7)); exit(2);
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Mon Jul 14 21:56:03 UTC 2014 Modified Files: src/usr.bin/grep: util.c Log Message: fix type, from enh at google dot com To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/grep/util.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/util.c diff -u src/usr.bin/grep/util.c:1.17 src/usr.bin/grep/util.c:1.18 --- src/usr.bin/grep/util.c:1.17 Sun Jan 20 22:24:43 2013 +++ src/usr.bin/grep/util.c Mon Jul 14 17:56:03 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: util.c,v 1.17 2013/01/21 03:24:43 msaitoh Exp $ */ +/* $NetBSD: util.c,v 1.18 2014/07/14 21:56:03 christos Exp $ */ /* $FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: util.c,v 1.17 2013/01/21 03:24:43 msaitoh Exp $"); +__RCSID("$NetBSD: util.c,v 1.18 2014/07/14 21:56:03 christos Exp $"); #include #include @@ -324,7 +324,7 @@ procline(struct str *l, int nottext) continue; /* Check for whole word match */ if (fg_pattern[i].word && pmatch.rm_so != 0) { -wint_t wbegin, wend; +wchar_t wbegin, wend; wbegin = wend = L' '; if (pmatch.rm_so != 0 &&
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Sat Aug 11 16:03:37 UTC 2018 Modified Files: src/usr.bin/grep: file.c Log Message: remove dup includes (already in grep.h) To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/grep/file.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/file.c diff -u src/usr.bin/grep/file.c:1.7 src/usr.bin/grep/file.c:1.8 --- src/usr.bin/grep/file.c:1.7 Mon Apr 18 18:46:48 2011 +++ src/usr.bin/grep/file.c Sat Aug 11 12:03:37 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.7 2011/04/18 22:46:48 joerg Exp $ */ +/* $NetBSD: file.c,v 1.8 2018/08/11 16:03:37 christos Exp $ */ /* $FreeBSD: head/usr.bin/grep/file.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $ */ @@ -35,13 +35,12 @@ #endif #include -__RCSID("$NetBSD: file.c,v 1.7 2011/04/18 22:46:48 joerg Exp $"); +__RCSID("$NetBSD: file.c,v 1.8 2018/08/11 16:03:37 christos Exp $"); #include #include #include -#include #include #include #include @@ -51,7 +50,6 @@ __RCSID("$NetBSD: file.c,v 1.7 2011/04/1 #include #include #include -#include #include "grep.h"
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Sat Aug 11 19:43:54 UTC 2018 Modified Files: src/usr.bin/grep: Makefile Log Message: don't build NLS if we don't need to To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.bin/grep/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/Makefile diff -u src/usr.bin/grep/Makefile:1.5 src/usr.bin/grep/Makefile:1.6 --- src/usr.bin/grep/Makefile:1.5 Wed Aug 17 11:32:20 2011 +++ src/usr.bin/grep/Makefile Sat Aug 11 15:43:54 2018 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.5 2011/08/17 15:32:20 christos Exp $ +# $NetBSD: Makefile,v 1.6 2018/08/11 19:43:54 christos Exp $ # $FreeBSD: head/usr.bin/grep/Makefile 210389 2010-07-22 19:11:57Z gabor $ # $OpenBSD: Makefile,v 1.6 2003/06/25 15:00:04 millert Exp $ @@ -20,6 +20,7 @@ MLINKS= grep.1 egrep.1 \ LDADD= -lz -lbz2 DPADD= ${LIBZ} ${LIBBZ2} +.if empty(HOST_CPPFLAGS:M*-DWITHOUT_NLS*) .PATH: ${.CURDIR}/nls NLS= C.msg \ @@ -33,6 +34,7 @@ NLS= C.msg \ ru_RU.KOI8-R.msg \ uk_UA.UTF-8.msg \ zh_CN.UTF-8.msg +.endif COPTS.grep.c += -Wno-format-nonliteral COPTS.util.c += -Wno-format-nonliteral
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Sat Aug 11 19:44:19 UTC 2018 Modified Files: src/usr.bin/grep: grep.c Log Message: use setvbuf if available; it is more portable. To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/usr.bin/grep/grep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/grep.c diff -u src/usr.bin/grep/grep.c:1.12 src/usr.bin/grep/grep.c:1.13 --- src/usr.bin/grep/grep.c:1.12 Fri Jul 11 12:30:45 2014 +++ src/usr.bin/grep/grep.c Sat Aug 11 15:44:19 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.12 2014/07/11 16:30:45 christos Exp $ */ +/* $NetBSD: grep.c,v 1.13 2018/08/11 19:44:19 christos Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: grep.c,v 1.12 2014/07/11 16:30:45 christos Exp $"); +__RCSID("$NetBSD: grep.c,v 1.13 2018/08/11 19:44:19 christos Exp $"); #include #include @@ -679,8 +679,13 @@ main(int argc, char *argv[]) } } - if (lbflag) + if (lbflag) { +#ifdef _IOLBF + setvbuf(stdout, NULL, _IOLBF, 0); +#else setlinebuf(stdout); +#endif + } if ((aargc == 0 || aargc == 1) && !Hflag) hflag = true;
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Sun Aug 12 07:53:19 UTC 2018 Modified Files: src/usr.bin/grep: Makefile file.c grep.c grep.h Log Message: add WITHOUT_BZ2 for tools build. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.bin/grep/Makefile cvs rdiff -u -r1.8 -r1.9 src/usr.bin/grep/file.c src/usr.bin/grep/grep.h cvs rdiff -u -r1.13 -r1.14 src/usr.bin/grep/grep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/Makefile diff -u src/usr.bin/grep/Makefile:1.6 src/usr.bin/grep/Makefile:1.7 --- src/usr.bin/grep/Makefile:1.6 Sat Aug 11 15:43:54 2018 +++ src/usr.bin/grep/Makefile Sun Aug 12 03:53:19 2018 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.6 2018/08/11 19:43:54 christos Exp $ +# $NetBSD: Makefile,v 1.7 2018/08/12 07:53:19 christos Exp $ # $FreeBSD: head/usr.bin/grep/Makefile 210389 2010-07-22 19:11:57Z gabor $ # $OpenBSD: Makefile,v 1.6 2003/06/25 15:00:04 millert Exp $ @@ -17,8 +17,13 @@ MLINKS= grep.1 egrep.1 \ grep.1 zegrep.1 \ grep.1 zfgrep.1 -LDADD= -lz -lbz2 -DPADD= ${LIBZ} ${LIBBZ2} +LDADD+= -lz +DPADD+= ${LIBZ} + +.if empty(HOST_CPPFLAGS:M(*-DWITHOUT_BZ2*) +LDADD+= -lz +DPADD+= ${LIBZ} +.endif .if empty(HOST_CPPFLAGS:M*-DWITHOUT_NLS*) .PATH: ${.CURDIR}/nls Index: src/usr.bin/grep/file.c diff -u src/usr.bin/grep/file.c:1.8 src/usr.bin/grep/file.c:1.9 --- src/usr.bin/grep/file.c:1.8 Sat Aug 11 12:03:37 2018 +++ src/usr.bin/grep/file.c Sun Aug 12 03:53:19 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.8 2018/08/11 16:03:37 christos Exp $ */ +/* $NetBSD: file.c,v 1.9 2018/08/12 07:53:19 christos Exp $ */ /* $FreeBSD: head/usr.bin/grep/file.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $ */ @@ -35,7 +35,7 @@ #endif #include -__RCSID("$NetBSD: file.c,v 1.8 2018/08/11 16:03:37 christos Exp $"); +__RCSID("$NetBSD: file.c,v 1.9 2018/08/12 07:53:19 christos Exp $"); #include #include @@ -57,7 +57,9 @@ __RCSID("$NetBSD: file.c,v 1.8 2018/08/1 #define LNBUFBUMP 80 static gzFile gzbufdesc; +#ifndef WITHOUT_BZ2 static BZFILE* bzbufdesc; +#endif static unsigned char buffer[MAXBUFSIZ]; static unsigned char *bufpos; @@ -75,9 +77,10 @@ grep_refill(struct file *f) bufpos = buffer; bufrem = 0; - if (filebehave == FILE_GZIP) + if (filebehave == FILE_GZIP) { nr = gzread(gzbufdesc, buffer, MAXBUFSIZ); - else if (filebehave == FILE_BZIP && bzbufdesc != NULL) { +#ifndef WITHOUT_BZ2 + } else if (filebehave == FILE_BZIP && bzbufdesc != NULL) { nr = BZ2_bzRead(&bzerr, bzbufdesc, buffer, MAXBUFSIZ); switch (bzerr) { case BZ_OK: @@ -103,6 +106,7 @@ grep_refill(struct file *f) /* Make sure we exit with an error */ nr = -1; } +#endif } else nr = read(f->fd, buffer, MAXBUFSIZ); @@ -196,9 +200,11 @@ grep_file_init(struct file *f) (gzbufdesc = gzdopen(f->fd, "r")) == NULL) goto error; +#ifndef WITHOUT_BZ2 if (filebehave == FILE_BZIP && (bzbufdesc = BZ2_bzdopen(f->fd, "r")) == NULL) goto error; +#endif /* Fill read buffer, also catches errors early */ if (grep_refill(f) != 0) Index: src/usr.bin/grep/grep.h diff -u src/usr.bin/grep/grep.h:1.8 src/usr.bin/grep/grep.h:1.9 --- src/usr.bin/grep/grep.h:1.8 Sun May 6 18:27:00 2012 +++ src/usr.bin/grep/grep.h Sun Aug 12 03:53:19 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.h,v 1.8 2012/05/06 22:27:00 joerg Exp $ */ +/* $NetBSD: grep.h,v 1.9 2018/08/12 07:53:19 christos Exp $ */ /* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $ */ @@ -29,7 +29,9 @@ * SUCH DAMAGE. */ +#ifndef WITHOUT_BZ2 #include +#endif #include #include #include Index: src/usr.bin/grep/grep.c diff -u src/usr.bin/grep/grep.c:1.13 src/usr.bin/grep/grep.c:1.14 --- src/usr.bin/grep/grep.c:1.13 Sat Aug 11 15:44:19 2018 +++ src/usr.bin/grep/grep.c Sun Aug 12 03:53:19 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.13 2018/08/11 19:44:19 christos Exp $ */ +/* $NetBSD: grep.c,v 1.14 2018/08/12 07:53:19 christos Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: grep.c,v 1.13 2018/08/11 19:44:19 christos Exp $"); +__RCSID("$NetBSD: grep.c,v 1.14 2018/08/12 07:53:19 christos Exp $"); #include #include @@ -197,7 +197,9 @@ struct option long_options[] = {"no-filename", no_argument, NULL, 'h'}, {"with-filename", no_argument, NULL, 'H'}, {"ignore-case", no_argument, NULL, 'i'}, +#ifndef WITHOUT_BZ2 {"bz2decompress", no_argument, NULL, 'J'}, +#endif {"files-with-matches", no_argument, NULL, 'l'}, {"files-without-match", no_argument,NULL, 'L'}, {"max-count", required_argument, NULL, 'm'}, @@ -491,9 +493,11 @@ main(int argc, char *argv[]) iflag
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Sun Aug 12 07:59:14 UTC 2018 Modified Files: src/usr.bin/grep: Makefile Log Message: remove stray paren To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.bin/grep/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/Makefile diff -u src/usr.bin/grep/Makefile:1.7 src/usr.bin/grep/Makefile:1.8 --- src/usr.bin/grep/Makefile:1.7 Sun Aug 12 03:53:19 2018 +++ src/usr.bin/grep/Makefile Sun Aug 12 03:59:14 2018 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.7 2018/08/12 07:53:19 christos Exp $ +# $NetBSD: Makefile,v 1.8 2018/08/12 07:59:14 christos Exp $ # $FreeBSD: head/usr.bin/grep/Makefile 210389 2010-07-22 19:11:57Z gabor $ # $OpenBSD: Makefile,v 1.6 2003/06/25 15:00:04 millert Exp $ @@ -20,7 +20,7 @@ MLINKS= grep.1 egrep.1 \ LDADD+= -lz DPADD+= ${LIBZ} -.if empty(HOST_CPPFLAGS:M(*-DWITHOUT_BZ2*) +.if empty(HOST_CPPFLAGS:M*-DWITHOUT_BZ2*) LDADD+= -lz DPADD+= ${LIBZ} .endif
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Sun Aug 12 08:00:32 UTC 2018 Modified Files: src/usr.bin/grep: Makefile Log Message: fix libraries To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.bin/grep/Makefile Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/Makefile diff -u src/usr.bin/grep/Makefile:1.8 src/usr.bin/grep/Makefile:1.9 --- src/usr.bin/grep/Makefile:1.8 Sun Aug 12 03:59:14 2018 +++ src/usr.bin/grep/Makefile Sun Aug 12 04:00:32 2018 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.8 2018/08/12 07:59:14 christos Exp $ +# $NetBSD: Makefile,v 1.9 2018/08/12 08:00:32 christos Exp $ # $FreeBSD: head/usr.bin/grep/Makefile 210389 2010-07-22 19:11:57Z gabor $ # $OpenBSD: Makefile,v 1.6 2003/06/25 15:00:04 millert Exp $ @@ -21,8 +21,8 @@ LDADD+= -lz DPADD+= ${LIBZ} .if empty(HOST_CPPFLAGS:M*-DWITHOUT_BZ2*) -LDADD+= -lz -DPADD+= ${LIBZ} +LDADD+= -lbz2 +DPADD+= ${LIBBZ2} .endif .if empty(HOST_CPPFLAGS:M*-DWITHOUT_NLS*)
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Sun Aug 12 09:03:21 UTC 2018 Modified Files: src/usr.bin/grep: Makefile file.c grep.c grep.h Log Message: add WITHOUT_GZIP for the tools build. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.bin/grep/Makefile src/usr.bin/grep/file.c \ src/usr.bin/grep/grep.h cvs rdiff -u -r1.14 -r1.15 src/usr.bin/grep/grep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/Makefile diff -u src/usr.bin/grep/Makefile:1.9 src/usr.bin/grep/Makefile:1.10 --- src/usr.bin/grep/Makefile:1.9 Sun Aug 12 04:00:32 2018 +++ src/usr.bin/grep/Makefile Sun Aug 12 05:03:21 2018 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.9 2018/08/12 08:00:32 christos Exp $ +# $NetBSD: Makefile,v 1.10 2018/08/12 09:03:21 christos Exp $ # $FreeBSD: head/usr.bin/grep/Makefile 210389 2010-07-22 19:11:57Z gabor $ # $OpenBSD: Makefile,v 1.6 2003/06/25 15:00:04 millert Exp $ @@ -17,8 +17,10 @@ MLINKS= grep.1 egrep.1 \ grep.1 zegrep.1 \ grep.1 zfgrep.1 +.if empty(HOST_CPPFLAGS:M*-DWITHOUT_GZIP*) LDADD+= -lz DPADD+= ${LIBZ} +.endif .if empty(HOST_CPPFLAGS:M*-DWITHOUT_BZ2*) LDADD+= -lbz2 Index: src/usr.bin/grep/file.c diff -u src/usr.bin/grep/file.c:1.9 src/usr.bin/grep/file.c:1.10 --- src/usr.bin/grep/file.c:1.9 Sun Aug 12 03:53:19 2018 +++ src/usr.bin/grep/file.c Sun Aug 12 05:03:21 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.9 2018/08/12 07:53:19 christos Exp $ */ +/* $NetBSD: file.c,v 1.10 2018/08/12 09:03:21 christos Exp $ */ /* $FreeBSD: head/usr.bin/grep/file.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $ */ @@ -35,7 +35,7 @@ #endif #include -__RCSID("$NetBSD: file.c,v 1.9 2018/08/12 07:53:19 christos Exp $"); +__RCSID("$NetBSD: file.c,v 1.10 2018/08/12 09:03:21 christos Exp $"); #include #include @@ -56,7 +56,9 @@ __RCSID("$NetBSD: file.c,v 1.9 2018/08/1 #define MAXBUFSIZ (32 * 1024) #define LNBUFBUMP 80 +#ifndef WITHOUT_GZIP static gzFile gzbufdesc; +#endif #ifndef WITHOUT_BZ2 static BZFILE* bzbufdesc; #endif @@ -71,16 +73,21 @@ static size_t lnbuflen; static inline int grep_refill(struct file *f) { - ssize_t nr; + ssize_t nr = -1; int bzerr; bufpos = buffer; bufrem = 0; +#ifndef WITHOUT_GZIP if (filebehave == FILE_GZIP) { nr = gzread(gzbufdesc, buffer, MAXBUFSIZ); + if (nr == -1) + return -1; + } +#endif #ifndef WITHOUT_BZ2 - } else if (filebehave == FILE_BZIP && bzbufdesc != NULL) { + if (filebehave == FILE_BZIP && bzbufdesc != NULL) { nr = BZ2_bzRead(&bzerr, bzbufdesc, buffer, MAXBUFSIZ); switch (bzerr) { case BZ_OK: @@ -106,9 +113,13 @@ grep_refill(struct file *f) /* Make sure we exit with an error */ nr = -1; } + if (nr == -1) + return -1; + } #endif - } else + if (nr == -1) { nr = read(f->fd, buffer, MAXBUFSIZ); + } if (nr < 0) return (-1); @@ -196,9 +207,11 @@ static inline struct file * grep_file_init(struct file *f) { +#ifndef WITHOUT_GZIP if (filebehave == FILE_GZIP && (gzbufdesc = gzdopen(f->fd, "r")) == NULL) goto error; +#endif #ifndef WITHOUT_BZ2 if (filebehave == FILE_BZIP && Index: src/usr.bin/grep/grep.h diff -u src/usr.bin/grep/grep.h:1.9 src/usr.bin/grep/grep.h:1.10 --- src/usr.bin/grep/grep.h:1.9 Sun Aug 12 03:53:19 2018 +++ src/usr.bin/grep/grep.h Sun Aug 12 05:03:21 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.h,v 1.9 2018/08/12 07:53:19 christos Exp $ */ +/* $NetBSD: grep.h,v 1.10 2018/08/12 09:03:21 christos Exp $ */ /* $OpenBSD: grep.h,v 1.15 2010/04/05 03:03:55 tedu Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.h 211496 2010-08-19 09:28:59Z des $ */ @@ -36,7 +36,9 @@ #include #include #include +#ifndef WITHOUT_GZIP #include +#endif #ifdef WITHOUT_NLS #define getstr(n) errstr[n] Index: src/usr.bin/grep/grep.c diff -u src/usr.bin/grep/grep.c:1.14 src/usr.bin/grep/grep.c:1.15 --- src/usr.bin/grep/grep.c:1.14 Sun Aug 12 03:53:19 2018 +++ src/usr.bin/grep/grep.c Sun Aug 12 05:03:21 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: grep.c,v 1.14 2018/08/12 07:53:19 christos Exp $ */ +/* $NetBSD: grep.c,v 1.15 2018/08/12 09:03:21 christos Exp $ */ /* $FreeBSD: head/usr.bin/grep/grep.c 211519 2010-08-19 22:55:17Z delphij $ */ /* $OpenBSD: grep.c,v 1.42 2010/07/02 22:18:03 tedu Exp $ */ @@ -34,7 +34,7 @@ #endif #include -__RCSID("$NetBSD: grep.c,v 1.14 2018/08/12 07:53:19 christos Exp $"); +__RCSID("$NetBSD: grep.c,v 1.15 2018/08/12 09:03:21 christos Exp $"); #include #include @@ -170,7 +170,9 @@ static const char optstr[] = struct option long_options[] = { {"binary-files", required_argument, NULL, BIN_OPT}, +#ifndef WITHOUT_GZIP {"decompress", no_argument,NULL, DECOMPRESS_OPT}, +#endif {"help", no_argument, NULL, HELP_OPT}, {"mmap", no_argument, NULL, MMAP_OPT}, {"line-buffered", no_argument, NULL, LINEBUF_OPT}, @@ -340,6 +342,7 @
CVS commit: src/usr.bin/grep
Module Name:src Committed By: christos Date: Fri Apr 5 13:34:42 UTC 2019 Modified Files: src/usr.bin/grep: file.c Log Message: Fix asan heap buffer overflow. from enh at google. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.bin/grep/file.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/grep/file.c diff -u src/usr.bin/grep/file.c:1.10 src/usr.bin/grep/file.c:1.11 --- src/usr.bin/grep/file.c:1.10 Sun Aug 12 05:03:21 2018 +++ src/usr.bin/grep/file.c Fri Apr 5 09:34:41 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: file.c,v 1.10 2018/08/12 09:03:21 christos Exp $ */ +/* $NetBSD: file.c,v 1.11 2019/04/05 13:34:41 christos Exp $ */ /* $FreeBSD: head/usr.bin/grep/file.c 211496 2010-08-19 09:28:59Z des $ */ /* $OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $ */ @@ -35,7 +35,7 @@ #endif #include -__RCSID("$NetBSD: file.c,v 1.10 2018/08/12 09:03:21 christos Exp $"); +__RCSID("$NetBSD: file.c,v 1.11 2019/04/05 13:34:41 christos Exp $"); #include #include @@ -63,7 +63,7 @@ static gzFile gzbufdesc; static BZFILE* bzbufdesc; #endif -static unsigned char buffer[MAXBUFSIZ]; +static unsigned char buffer[MAXBUFSIZ + 1]; static unsigned char *bufpos; static size_t bufrem; @@ -128,7 +128,7 @@ grep_refill(struct file *f) return (0); } -static inline int +static inline void grep_lnbufgrow(size_t newlen) { @@ -136,15 +136,19 @@ grep_lnbufgrow(size_t newlen) lnbuf = grep_realloc(lnbuf, newlen); lnbuflen = newlen; } +} - return (0); +static void +grep_copyline(size_t off, size_t len) +{ + memcpy(lnbuf + off, bufpos, len); + lnbuf[off + len] = '\0'; } char * grep_fgetln(struct file *f, size_t *lenp) { unsigned char *p; - char *ret; size_t len; size_t off; ptrdiff_t diff; @@ -162,20 +166,20 @@ grep_fgetln(struct file *f, size_t *lenp /* Look for a newline in the remaining part of the buffer */ if ((p = memchr(bufpos, line_sep, bufrem)) != NULL) { ++p; /* advance over newline */ - ret = (char *)bufpos; len = p - bufpos; + grep_lnbufgrow(len + 1); + grep_copyline(0, len); + *lenp = len; bufrem -= len; bufpos = p; - *lenp = len; - return (ret); + return (char *)lnbuf; } /* We have to copy the current buffered data to the line buffer */ for (len = bufrem, off = 0; ; len += bufrem) { /* Make sure there is room for more data */ - if (grep_lnbufgrow(len + LNBUFBUMP)) - goto error; - memcpy(lnbuf + off, bufpos, len - off); + grep_lnbufgrow(len + LNBUFBUMP); + grep_copyline(off, len - off); off = len; if (grep_refill(f) != 0) goto error; @@ -188,9 +192,8 @@ grep_fgetln(struct file *f, size_t *lenp ++p; diff = p - bufpos; len += diff; - if (grep_lnbufgrow(len)) - goto error; - memcpy(lnbuf + off, bufpos, diff); + grep_lnbufgrow(len + 1); + grep_copyline(off, diff); bufrem -= diff; bufpos = p; break;