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
29 static char **exclude_list;
31 static int is_regex(char *str)
33 return strchr(str, '*') || strchr(str, '[') || strchr(str, '?');
37 static int check_one_exclude(char *name,char *pattern)
41 if (!strchr(pattern,'/') && (p=strrchr(name,'/')))
44 if (!name[0]) return 0;
46 if (is_regex(pattern)) {
47 if (fnmatch(pattern, name, 0) == 0)
50 int l1 = strlen(name);
51 int l2 = strlen(pattern);
53 strcmp(name+(l1-l2),pattern) == 0 &&
54 (l1==l2 || name[l1-(l2+1)] == '/'))
62 int check_exclude(char *name,char **local_exclude_list)
67 for (n=0; exclude_list[n]; n++)
68 if (check_one_exclude(name,exclude_list[n]))
72 if (local_exclude_list) {
73 for (n=0; local_exclude_list[n]; n++)
74 if (check_one_exclude(name,local_exclude_list[n]))
82 void add_exclude_list(char *pattern,char ***list)
86 for (; (*list)[len]; len++) ;
88 if (strcmp(pattern,"!") == 0) {
90 fprintf(FINFO,"clearing exclude list\n");
99 *list = (char **)malloc(sizeof(char *)*2);
101 *list = (char **)realloc(*list,sizeof(char *)*(len+2));
104 if (!*list || !((*list)[len] = strdup(pattern)))
105 out_of_memory("add_exclude");
108 fprintf(FINFO,"add_exclude(%s)\n",pattern);
110 (*list)[len+1] = NULL;
113 void add_exclude(char *pattern)
115 add_exclude_list(pattern,&exclude_list);
118 char **make_exclude_list(char *fname,char **list1,int fatal)
121 FILE *f = fopen(fname,"r");
122 char line[MAXPATHLEN];
125 fprintf(FERROR,"%s : %s\n",fname,strerror(errno));
131 while (fgets(line,MAXPATHLEN,f)) {
132 int l = strlen(line);
133 if (l && line[l-1] == '\n') l--;
135 if (line[0]) add_exclude_list(line,&list);
142 void add_exclude_file(char *fname,int fatal)
144 exclude_list = make_exclude_list(fname,exclude_list,fatal);
148 void send_exclude_list(int f)
152 for (i=0;exclude_list[i];i++) {
153 int l = strlen(exclude_list[i]);
154 if (l == 0) continue;
156 write_buf(f,exclude_list[i],l);
162 void recv_exclude_list(int f)
164 char line[MAXPATHLEN];
166 while ((l=read_int(f))) {
174 static char *cvs_ignore_list[] = {
175 "RCS","SCCS","CVS","CVS.adm","RCSLOG","cvslog.*",
176 "tags","TAGS",".make.state",".nse_depinfo",
177 "*~", "#*", ".#*", ",*", "*.old", "*.bak", "*.BAK", "*.orig",
178 "*.rej", ".del-*", "*.a", "*.o", "*.obj", "*.so", "*.Z", "*.elc", "*.ln",
183 void add_cvs_excludes(void)
185 char fname[MAXPATHLEN];
189 for (i=0; cvs_ignore_list[i]; i++)
190 add_exclude(cvs_ignore_list[i]);
192 if ((p=getenv("HOME")) && strlen(p) < (MAXPATHLEN-12)) {
193 sprintf(fname,"%s/.cvsignore",p);
194 add_exclude_file(fname,0);
197 if ((p=getenv("CVSIGNORE"))) {
199 for (tok=strtok(p," "); tok; tok=strtok(NULL," "))