View | Details | Raw Unified | Return to bug 128645
Collapse All | Expand All

(-)gnu/usr.bin/grep/savedir.c (-1 / +22 lines)
Lines 100-112 Link Here
100
   Return NULL if DIR cannot be opened or if out of memory. */
100
   Return NULL if DIR cannot be opened or if out of memory. */
101
char *
101
char *
102
savedir (const char *dir, off_t name_size, struct exclude *included_patterns,
102
savedir (const char *dir, off_t name_size, struct exclude *included_patterns,
103
	 struct exclude *excluded_patterns)
103
    struct exclude *excluded_patterns, struct exclude *excluded_dirs_patterns)
104
{
104
{
105
  DIR *dirp;
105
  DIR *dirp;
106
  struct dirent *dp;
106
  struct dirent *dp;
107
  char *name_space;
107
  char *name_space;
108
  char *namep;
108
  char *namep;
109
109
110
  if (excluded_dirs_patterns && isdir (dir))
111
    {
112
      const char *d;
113
114
      d = strrchr(dir, '/');
115
      if (d != NULL)
116
        d++;
117
      else
118
        d = dir;
119
      if (excluded_filename (excluded_dirs_patterns, d, 0))
120
        {
121
          if (name_size < 2)
122
            name_size = 2;
123
          name_space = (char *) malloc (name_size);
124
          if (name_space == NULL)
125
            return NULL;
126
          memset (name_space, '\0', name_size);
127
          return name_space;
128
        }
129
    }
130
110
  dirp = opendir (dir);
131
  dirp = opendir (dir);
111
  if (dirp == NULL)
132
  if (dirp == NULL)
112
    return NULL;
133
    return NULL;
(-)gnu/usr.bin/grep/savedir.h (-1 / +1 lines)
Lines 13-18 Link Here
13
13
14
extern char *
14
extern char *
15
savedir PARAMS ((const char *dir, off_t name_size,
15
savedir PARAMS ((const char *dir, off_t name_size,
16
		 struct exclude *, struct exclude *));
16
    struct exclude *, struct exclude *, struct exclude *));
17
17
18
#endif
18
#endif
(-)gnu/usr.bin/grep/grep.c (-2 / +24 lines)
Lines 89-94 Link Here
89
static const char *grep_color = "01;31";
89
static const char *grep_color = "01;31";
90
90
91
static struct exclude *excluded_patterns;
91
static struct exclude *excluded_patterns;
92
static struct exclude *excluded_dirs_patterns;
92
static struct exclude *included_patterns;
93
static struct exclude *included_patterns;
93
/* Short options.  */
94
/* Short options.  */
94
static char const short_options[] =
95
static char const short_options[] =
Lines 103-109 Link Here
103
  EXCLUDE_OPTION,
104
  EXCLUDE_OPTION,
104
  EXCLUDE_FROM_OPTION,
105
  EXCLUDE_FROM_OPTION,
105
  LINE_BUFFERED_OPTION,
106
  LINE_BUFFERED_OPTION,
106
  LABEL_OPTION
107
  LABEL_OPTION,
108
  EXCLUDE_DIR_OPTION
107
};
109
};
108
110
109
/* Long options equivalences. */
111
/* Long options equivalences. */
Lines 122-127 Link Here
122
  {"directories", required_argument, NULL, 'd'},
124
  {"directories", required_argument, NULL, 'd'},
123
  {"extended-regexp", no_argument, NULL, 'E'},
125
  {"extended-regexp", no_argument, NULL, 'E'},
124
  {"exclude", required_argument, NULL, EXCLUDE_OPTION},
126
  {"exclude", required_argument, NULL, EXCLUDE_OPTION},
127
  {"exclude-dir", required_argument, NULL, EXCLUDE_DIR_OPTION},
125
  {"exclude-from", required_argument, NULL, EXCLUDE_FROM_OPTION},
128
  {"exclude-from", required_argument, NULL, EXCLUDE_FROM_OPTION},
126
  {"file", required_argument, NULL, 'f'},
129
  {"file", required_argument, NULL, 'f'},
127
  {"files-with-matches", no_argument, NULL, 'l'},
130
  {"files-with-matches", no_argument, NULL, 'l'},
Lines 1065-1071 Link Here
1065
	}
1068
	}
1066
1069
1067
  name_space = savedir (dir, stats->stat.st_size, included_patterns,
1070
  name_space = savedir (dir, stats->stat.st_size, included_patterns,
1068
			excluded_patterns);
1071
			excluded_patterns, excluded_dirs_patterns);
1069
1072
1070
  if (! name_space)
1073
  if (! name_space)
1071
    {
1074
    {
Lines 1166-1171 Link Here
1166
  -R, -r, --recursive       equivalent to --directories=recurse\n\
1169
  -R, -r, --recursive       equivalent to --directories=recurse\n\
1167
      --include=PATTERN     files that match PATTERN will be examined\n\
1170
      --include=PATTERN     files that match PATTERN will be examined\n\
1168
      --exclude=PATTERN     files that match PATTERN will be skipped.\n\
1171
      --exclude=PATTERN     files that match PATTERN will be skipped.\n\
1172
      --exclude-dir=PATTERN directories that match PATTERN will be skipped.\n\
1169
      --exclude-from=FILE   files that match PATTERN in FILE will be skipped.\n\
1173
      --exclude-from=FILE   files that match PATTERN in FILE will be skipped.\n\
1170
  -L, --files-without-match only print FILE names containing no match\n\
1174
  -L, --files-without-match only print FILE names containing no match\n\
1171
  -l, --files-with-matches  only print FILE names containing matches\n\
1175
  -l, --files-with-matches  only print FILE names containing matches\n\
Lines 1685-1690 Link Here
1685
	add_exclude (excluded_patterns, optarg);
1689
	add_exclude (excluded_patterns, optarg);
1686
	break;
1690
	break;
1687
1691
1692
      case EXCLUDE_DIR_OPTION:
1693
	if (!excluded_dirs_patterns)
1694
	  excluded_dirs_patterns = new_exclude ();
1695
	add_exclude (excluded_dirs_patterns, optarg);
1696
	break;
1697
1688
      case EXCLUDE_FROM_OPTION:
1698
      case EXCLUDE_FROM_OPTION:
1689
	if (!excluded_patterns)
1699
	if (!excluded_patterns)
1690
	  excluded_patterns = new_exclude ();
1700
	  excluded_patterns = new_exclude ();
Lines 1837-1842 Link Here
1837
	do
1847
	do
1838
	{
1848
	{
1839
	  char *file = argv[optind];
1849
	  char *file = argv[optind];
1850
	  if (excluded_dirs_patterns && isdir (file))
1851
            {
1852
              char *d;
1853
1854
              d = strrchr(file, '/');
1855
              if (d != NULL)
1856
                d++;
1857
              else
1858
                d = file;
1859
	      if (excluded_filename (excluded_dirs_patterns, d, 0))
1860
		continue;
1861
            } 
1840
	  if ((included_patterns || excluded_patterns)
1862
	  if ((included_patterns || excluded_patterns)
1841
	      && !isdir (file))
1863
	      && !isdir (file))
1842
	    {
1864
	    {

Return to bug 128645