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;
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 (*pattern == '/' && *name != '/') pattern++;
47 if (is_regex(pattern)) {
48 if (fnmatch(pattern, name, 0) == 0)
51 int l1 = strlen(name);
52 int l2 = strlen(pattern);
54 strcmp(name+(l1-l2),pattern) == 0 &&
55 (l1==l2 || name[l1-(l2+1)] == '/'))
63 int check_exclude(char *name,char **local_exclude_list)
68 for (n=0; exclude_list[n]; n++)
69 if (check_one_exclude(name,exclude_list[n]))
73 if (local_exclude_list) {
74 for (n=0; local_exclude_list[n]; n++)
75 if (check_one_exclude(name,local_exclude_list[n]))
83 void add_exclude_list(char *pattern,char ***list)
87 for (; (*list)[len]; len++) ;
89 if (strcmp(pattern,"!") == 0) {
91 rprintf(FINFO,"clearing exclude list\n");
100 *list = (char **)malloc(sizeof(char *)*2);
102 *list = (char **)realloc(*list,sizeof(char *)*(len+2));
105 if (!*list || !((*list)[len] = strdup(pattern)))
106 out_of_memory("add_exclude");
109 rprintf(FINFO,"add_exclude(%s)\n",pattern);
111 (*list)[len+1] = NULL;
114 void add_exclude(char *pattern)
116 add_exclude_list(pattern,&exclude_list);
119 char **make_exclude_list(char *fname,char **list1,int fatal)
122 FILE *f = fopen(fname,"r");
123 char line[MAXPATHLEN];
126 rprintf(FERROR,"%s : %s\n",fname,strerror(errno));
132 while (fgets(line,MAXPATHLEN,f)) {
133 int l = strlen(line);
134 if (l && line[l-1] == '\n') l--;
136 if (line[0]) add_exclude_list(line,&list);
143 void add_exclude_file(char *fname,int fatal)
145 exclude_list = make_exclude_list(fname,exclude_list,fatal);
149 void send_exclude_list(int f)
153 for (i=0;exclude_list[i];i++) {
154 int l = strlen(exclude_list[i]);
155 if (l == 0) continue;
157 write_buf(f,exclude_list[i],l);
163 void recv_exclude_list(int f)
165 char line[MAXPATHLEN];
167 while ((l=read_int(f))) {
168 if (l >= MAXPATHLEN) overflow("recv_exclude_list");
175 static char *cvs_ignore_list[] = {
176 "RCS","SCCS","CVS","CVS.adm","RCSLOG","cvslog.*",
177 "tags","TAGS",".make.state",".nse_depinfo",
178 "*~", "#*", ".#*", ",*", "*.old", "*.bak", "*.BAK", "*.orig",
179 "*.rej", ".del-*", "*.a", "*.o", "*.obj", "*.so", "*.Z", "*.elc", "*.ln",
184 void add_cvs_excludes(void)
186 char fname[MAXPATHLEN];
190 for (i=0; cvs_ignore_list[i]; i++)
191 add_exclude(cvs_ignore_list[i]);
193 if ((p=getenv("HOME")) && strlen(p) < (MAXPATHLEN-12)) {
194 sprintf(fname,"%s/.cvsignore",p);
195 add_exclude_file(fname,0);
198 if ((p=getenv("CVSIGNORE"))) {
200 for (tok=strtok(p," "); tok; tok=strtok(NULL," "))