31c31
< __FBSDID("$FreeBSD: head/usr.bin/grep/grep.c 210461 2010-07-25 08:42:18Z gabor $");
---
> __FBSDID("$FreeBSD: head/usr.bin/grep/grep.c 210578 2010-07-29 00:11:14Z gabor $");
88,89c88,90
< unsigned int epatterns, epattern_sz;
< struct epat *epattern;
---
> unsigned int fpatterns, fpattern_sz;
> unsigned int dpatterns, dpattern_sz;
> struct epat *dpattern, *fpattern;
115d115
< bool exclflag; /* --exclude */
124a125,127
> bool dexclude, dinclude; /* --exclude amd --include */
> bool fexclude, finclude; /* --exclude-dir and --include-dir */
>
237,238c240
< memcpy(pattern[patterns], pat, len);
< pattern[patterns][len] = '\0';
---
> strlcpy(pattern[patterns], pat, len + 1);
243c245
< * Adds an include/exclude pattern to the internal array.
---
> * Adds a file include/exclude pattern to the internal array.
246c248
< add_epattern(char *pat, size_t len, int type, int mode)
---
> add_fpattern(const char *pat, int mode)
250,252c252,254
< if (epatterns == epattern_sz) {
< epattern_sz *= 2;
< epattern = grep_realloc(epattern, ++epattern_sz *
---
> if (fpatterns == fpattern_sz) {
> fpattern_sz *= 2;
> fpattern = grep_realloc(fpattern, ++fpattern_sz *
255,262c257,259
< if (len > 0 && pat[len - 1] == '\n')
< --len;
< epattern[epatterns].pat = grep_malloc(len + 1);
< memcpy(epattern[epatterns].pat, pat, len);
< epattern[epatterns].pat[len] = '\0';
< epattern[epatterns].type = type;
< epattern[epatterns].mode = mode;
< ++epatterns;
---
> fpattern[fpatterns].pat = grep_strdup(pat);
> fpattern[fpatterns].mode = mode;
> ++fpatterns;
265a263,280
> * Adds a directory include/exclude pattern to the internal array.
> */
> static void
> add_dpattern(const char *pat, int mode)
> {
>
> /* Increase size if necessary */
> if (dpatterns == dpattern_sz) {
> dpattern_sz *= 2;
> dpattern = grep_realloc(dpattern, ++dpattern_sz *
> sizeof(struct epat));
> }
> dpattern[dpatterns].pat = grep_strdup(pat);
> dpattern[dpatterns].mode = mode;
> ++dpatterns;
> }
>
> /*
594,596c609,610
< exclflag = true;
< add_epattern(basename(optarg), strlen(basename(optarg)),
< FILE_PAT, INCL_PAT);
---
> finclude = true;
> add_fpattern(optarg, INCL_PAT);
599,601c613,614
< exclflag = true;
< add_epattern(basename(optarg), strlen(basename(optarg)),
< FILE_PAT, EXCL_PAT);
---
> fexclude = true;
> add_fpattern(optarg, EXCL_PAT);
604,606c617,618
< exclflag = true;
< add_epattern(basename(optarg), strlen(basename(optarg)),
< DIR_PAT, INCL_PAT);
---
> dexclude = true;
> add_dpattern(optarg, INCL_PAT);
609,611c621,622
< exclflag = true;
< add_epattern(basename(optarg), strlen(basename(optarg)),
< DIR_PAT, EXCL_PAT);
---
> dinclude = true;
> add_dpattern(optarg, EXCL_PAT);
683c694,696
< for (c = 0; aargc--; ++aargv)
---
> for (c = 0; aargc--; ++aargv) {
> if ((finclude || fexclude) && !file_matching(*aargv))
> continue;
684a698
> }
< __FBSDID("$FreeBSD: head/usr.bin/grep/grep.c 210461 2010-07-25 08:42:18Z gabor $");
---
> __FBSDID("$FreeBSD: head/usr.bin/grep/grep.c 210578 2010-07-29 00:11:14Z gabor $");
88,89c88,90
< unsigned int epatterns, epattern_sz;
< struct epat *epattern;
---
> unsigned int fpatterns, fpattern_sz;
> unsigned int dpatterns, dpattern_sz;
> struct epat *dpattern, *fpattern;
115d115
< bool exclflag; /* --exclude */
124a125,127
> bool dexclude, dinclude; /* --exclude amd --include */
> bool fexclude, finclude; /* --exclude-dir and --include-dir */
>
237,238c240
< memcpy(pattern[patterns], pat, len);
< pattern[patterns][len] = '\0';
---
> strlcpy(pattern[patterns], pat, len + 1);
243c245
< * Adds an include/exclude pattern to the internal array.
---
> * Adds a file include/exclude pattern to the internal array.
246c248
< add_epattern(char *pat, size_t len, int type, int mode)
---
> add_fpattern(const char *pat, int mode)
250,252c252,254
< if (epatterns == epattern_sz) {
< epattern_sz *= 2;
< epattern = grep_realloc(epattern, ++epattern_sz *
---
> if (fpatterns == fpattern_sz) {
> fpattern_sz *= 2;
> fpattern = grep_realloc(fpattern, ++fpattern_sz *
255,262c257,259
< if (len > 0 && pat[len - 1] == '\n')
< --len;
< epattern[epatterns].pat = grep_malloc(len + 1);
< memcpy(epattern[epatterns].pat, pat, len);
< epattern[epatterns].pat[len] = '\0';
< epattern[epatterns].type = type;
< epattern[epatterns].mode = mode;
< ++epatterns;
---
> fpattern[fpatterns].pat = grep_strdup(pat);
> fpattern[fpatterns].mode = mode;
> ++fpatterns;
265a263,280
> * Adds a directory include/exclude pattern to the internal array.
> */
> static void
> add_dpattern(const char *pat, int mode)
> {
>
> /* Increase size if necessary */
> if (dpatterns == dpattern_sz) {
> dpattern_sz *= 2;
> dpattern = grep_realloc(dpattern, ++dpattern_sz *
> sizeof(struct epat));
> }
> dpattern[dpatterns].pat = grep_strdup(pat);
> dpattern[dpatterns].mode = mode;
> ++dpatterns;
> }
>
> /*
594,596c609,610
< exclflag = true;
< add_epattern(basename(optarg), strlen(basename(optarg)),
< FILE_PAT, INCL_PAT);
---
> finclude = true;
> add_fpattern(optarg, INCL_PAT);
599,601c613,614
< exclflag = true;
< add_epattern(basename(optarg), strlen(basename(optarg)),
< FILE_PAT, EXCL_PAT);
---
> fexclude = true;
> add_fpattern(optarg, EXCL_PAT);
604,606c617,618
< exclflag = true;
< add_epattern(basename(optarg), strlen(basename(optarg)),
< DIR_PAT, INCL_PAT);
---
> dexclude = true;
> add_dpattern(optarg, INCL_PAT);
609,611c621,622
< exclflag = true;
< add_epattern(basename(optarg), strlen(basename(optarg)),
< DIR_PAT, EXCL_PAT);
---
> dinclude = true;
> add_dpattern(optarg, EXCL_PAT);
683c694,696
< for (c = 0; aargc--; ++aargv)
---
> for (c = 0; aargc--; ++aargv) {
> if ((finclude || fexclude) && !file_matching(*aargv))
> continue;
684a698
> }