2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 a lot of this stuff was derived from GNU tar
28 static char **exclude_list = NULL;
30 static int is_regex(char *str)
32 return strchr(str, '*') || strchr(str, '[') || strchr(str, '?');
36 static int check_one_exclude(char *name,char *pattern)
40 if (!strchr(pattern,'/') && (p=strrchr(name,'/')))
43 if (!name[0]) return 0;
45 if (is_regex(pattern)) {
46 if (fnmatch(pattern, name, 0) == 0)
49 int l1 = strlen(name);
50 int l2 = strlen(pattern);
52 strcmp(name+(l1-l2),pattern) == 0 &&
53 (l1==l2 || name[l1-(l2+1)] == '/'))
61 int check_exclude(char *name,char **local_exclude_list)
66 for (n=0; exclude_list[n]; n++)
67 if (check_one_exclude(name,exclude_list[n]))
71 if (local_exclude_list) {
72 for (n=0; local_exclude_list[n]; n++)
73 if (check_one_exclude(name,local_exclude_list[n]))
81 void add_exclude_list(char *pattern,char ***list)
85 for (; (*list)[len]; len++) ;
87 if (strcmp(pattern,"!") == 0) {
89 fprintf(FERROR,"clearing exclude list\n");
98 *list = (char **)malloc(sizeof(char *)*2);
100 *list = (char **)realloc(*list,sizeof(char *)*(len+2));
103 if (!*list || !((*list)[len] = strdup(pattern)))
104 out_of_memory("add_exclude");
107 fprintf(FERROR,"add_exclude(%s)\n",pattern);
109 (*list)[len+1] = NULL;
112 void add_exclude(char *pattern)
114 add_exclude_list(pattern,&exclude_list);
117 char **make_exclude_list(char *fname,char **list1,int fatal)
120 FILE *f = fopen(fname,"r");
121 char line[MAXPATHLEN];
124 fprintf(FERROR,"%s : %s\n",fname,strerror(errno));
130 while (fgets(line,MAXPATHLEN,f)) {
131 int l = strlen(line);
132 if (l && line[l-1] == '\n') l--;
134 if (line[0]) add_exclude_list(line,&list);
141 void add_exclude_file(char *fname,int fatal)
143 exclude_list = make_exclude_list(fname,exclude_list,fatal);
147 void send_exclude_list(int f)
151 for (i=0;exclude_list[i];i++) {
152 int l = strlen(exclude_list[i]);
153 if (l == 0) continue;
155 write_buf(f,exclude_list[i],l);
161 void recv_exclude_list(int f)
163 char line[MAXPATHLEN];
165 while ((l=read_int(f))) {
173 static char *cvs_ignore_list[] = {
174 "RCS","SCCS","CVS","CVS.adm","RCSLOG","cvslog.*",
175 "tags","TAGS",".make.state",".nse_depinfo",
176 "*~", "#*", ".#*", ",*", "*.old", "*.bak", "*.BAK", "*.orig",
177 "*.rej", ".del-*", "*.a", "*.o", "*.obj", "*.so", "*.Z", "*.elc", "*.ln",
182 void add_cvs_excludes(void)
184 char fname[MAXPATHLEN];
188 for (i=0; cvs_ignore_list[i]; i++)
189 add_exclude(cvs_ignore_list[i]);
191 if ((p=getenv("HOME"))) {
192 sprintf(fname,"%s/.cvsignore",p);
193 add_exclude_file(fname,0);
196 if ((p=getenv("CVSIGNORE"))) {
198 for (tok=strtok(p," "); tok; tok=strtok(NULL," "))