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 if (!fname || !*fname) return;
147 exclude_list = make_exclude_list(fname,exclude_list,fatal);
151 void send_exclude_list(int f)
155 for (i=0;exclude_list[i];i++) {
156 int l = strlen(exclude_list[i]);
157 if (l == 0) continue;
159 write_buf(f,exclude_list[i],l);
165 void recv_exclude_list(int f)
167 char line[MAXPATHLEN];
169 while ((l=read_int(f))) {
170 if (l >= MAXPATHLEN) overflow("recv_exclude_list");
177 void add_exclude_line(char *p)
180 if (!p || !*p) return;
182 if (!p) out_of_memory("add_exclude_line");
183 for (tok=strtok(p," "); tok; tok=strtok(NULL," "))
189 static char *cvs_ignore_list[] = {
190 "RCS","SCCS","CVS","CVS.adm","RCSLOG","cvslog.*",
191 "tags","TAGS",".make.state",".nse_depinfo",
192 "*~", "#*", ".#*", ",*", "*.old", "*.bak", "*.BAK", "*.orig",
193 "*.rej", ".del-*", "*.a", "*.o", "*.obj", "*.so", "*.Z", "*.elc", "*.ln",
198 void add_cvs_excludes(void)
200 char fname[MAXPATHLEN];
204 for (i=0; cvs_ignore_list[i]; i++)
205 add_exclude(cvs_ignore_list[i]);
207 if ((p=getenv("HOME")) && strlen(p) < (MAXPATHLEN-12)) {
208 slprintf(fname,sizeof(fname)-1, "%s/.cvsignore",p);
209 add_exclude_file(fname,0);
212 add_exclude_line(getenv("CVSIGNORE"));