1 /* exclude.c -- exclude file names
2 Copyright 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; see the file COPYING.
16 If not, write to the Free Software Foundation,
17 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 /* Written by Paul Eggert <eggert@twinsun.com> */
32 #include <sys/types.h>
34 void *xmalloc __EXCLUDE_P ((size_t));
35 void *xrealloc __EXCLUDE_P ((void *, size_t));
37 /* Keep track of excluded file name patterns. */
51 struct exclude *ex = (struct exclude *) xmalloc (sizeof (struct exclude));
52 ex->exclude_count = 0;
53 ex->exclude_alloc = 64;
54 ex->exclude = (char const **) xmalloc (ex->exclude_alloc * sizeof (char *));
61 excluded_filename (struct exclude const *ex, char const *f)
63 char const * const *exclude = ex->exclude;
64 int exclude_count = ex->exclude_count;
67 for (i = 0; i < exclude_count; i++)
68 if (fnmatch (exclude[i], f, 0) == 0)
77 add_exclude (struct exclude *ex, char const *pattern)
79 if (ex->exclude_alloc <= ex->exclude_count)
80 ex->exclude = (char const **) xrealloc (ex->exclude,
81 ((ex->exclude_alloc *= 2)
84 ex->exclude[ex->exclude_count++] = pattern;
90 add_exclude_file (struct exclude *ex, char const *filename, char line_end)
92 int use_stdin = filename[0] == '-' && !filename[1];
98 size_t buf_alloc = 1024;
105 else if (! (in = fopen (filename, "r")))
108 buf = xmalloc (buf_alloc);
110 while ((c = getc (in)) != EOF)
112 buf[buf_count++] = c;
113 if (buf_count == buf_alloc)
114 buf = xrealloc (buf, buf_alloc *= 2);
117 buf = xrealloc (buf, buf_count + 1);
122 if (!use_stdin && fclose (in) != 0)
125 for (pattern = p = buf, lim = buf + buf_count; p <= lim; p++)
126 if (p < lim ? *p == line_end : buf < p && p[-1])
129 add_exclude (ex, pattern);