1 /*
2 * 27-Mar-96: Jan-Piet Mens <jpm@mens.de>
3 * added 'match' option (-m) to specify regular expressions NOT to be included
4 * in the CD image.
5 */
6
7 #ifdef APPLE_HYB
8 /*
9 * Added a number of routines to create lists of files to hidden from
10 * the ISO9660 and/or Joliet trees. James Pearson (j.pearson@ge.ucl.ac.uk)
11 * January 1999 (these will probably appear in mkisofs in the future)
12 */
13 #endif /* APPLE_HYB */
14
15 #include "config.h"
16 #include <prototyp.h>
17 #include <stdio.h>
18 #include <fnmatch.h>
19 #ifndef VMS
20 #ifdef HAVE_MALLOC_H
21 #include <malloc.h>
22 #else
23 #include <stdlib.h>
24 #endif
25 #endif
26 #include <inttypes.h>
27 #include <string.h>
28 #include "match.h"
29
30 #define MAXMATCH 1000
31 static char *mat[MAXMATCH];
32
add_match(fn)33 int add_match(fn)
34 char * fn;
35 {
36 register int i;
37
38 for (i=0; mat[i] && i<MAXMATCH; i++);
39 if (i == MAXMATCH) {
40 fprintf(stderr,"Can't exclude RE '%s' - too many entries in table\n",fn);
41 return 1;
42 }
43
44
45 mat[i] = (char *) malloc(strlen(fn)+1);
46 if (! mat[i]) {
47 fprintf(stderr,"Can't allocate memory for excluded filename\n");
48 return 1;
49 }
50
51 strcpy(mat[i],fn);
52
53 return 0;
54 }
55
matches(fn)56 int matches(fn)
57 char * fn;
58 {
59 /* very dumb search method ... */
60 register int i;
61
62 for (i=0; mat[i] && i<MAXMATCH; i++) {
63 if (fnmatch(mat[i], fn, FNM_PATHNAME) != FNM_NOMATCH) {
64 return 1; /* found -> excluded filenmae */
65 }
66 }
67 return 0; /* not found -> not excluded */
68 }
69
70 /* ISO9660/RR hide */
71
72 static char *i_mat[MAXMATCH];
73
i_add_match(fn)74 int i_add_match(fn)
75 char * fn;
76 {
77 register int i;
78
79 for (i=0; i_mat[i] && i<MAXMATCH; i++);
80 if (i == MAXMATCH) {
81 fprintf(stderr,"Can't exclude RE '%s' - too many entries in table\n",fn);
82 return 1;
83 }
84
85
86 i_mat[i] = (char *) malloc(strlen(fn)+1);
87 if (! i_mat[i]) {
88 fprintf(stderr,"Can't allocate memory for excluded filename\n");
89 return 1;
90 }
91
92 strcpy(i_mat[i],fn);
93
94 return 0;
95 }
96
i_matches(fn)97 int i_matches(fn)
98 char * fn;
99 {
100 /* very dumb search method ... */
101 register int i;
102
103 for (i=0; i_mat[i] && i<MAXMATCH; i++) {
104 if (fnmatch(i_mat[i], fn, FNM_PATHNAME) != FNM_NOMATCH) {
105 return 1; /* found -> excluded filenmae */
106 }
107 }
108 return 0; /* not found -> not excluded */
109 }
110
i_ishidden()111 intptr_t i_ishidden()
112 {
113 return((intptr_t)i_mat[0]);
114 }
115
116 /* Joliet hide */
117
118 static char *j_mat[MAXMATCH];
119
j_add_match(fn)120 int j_add_match(fn)
121 char * fn;
122 {
123 register int i;
124
125 for (i=0; j_mat[i] && i<MAXMATCH; i++);
126 if (i == MAXMATCH) {
127 fprintf(stderr,"Can't exclude RE '%s' - too many entries in table\n",fn);
128 return 1;
129 }
130
131
132 j_mat[i] = (char *) malloc(strlen(fn)+1);
133 if (! j_mat[i]) {
134 fprintf(stderr,"Can't allocate memory for excluded filename\n");
135 return 1;
136 }
137
138 strcpy(j_mat[i],fn);
139
140 return 0;
141 }
142
j_matches(fn)143 int j_matches(fn)
144 char * fn;
145 {
146 /* very dumb search method ... */
147 register int i;
148
149 for (i=0; j_mat[i] && i<MAXMATCH; i++) {
150 if (fnmatch(j_mat[i], fn, FNM_PATHNAME) != FNM_NOMATCH) {
151 return 1; /* found -> excluded filenmae */
152 }
153 }
154 return 0; /* not found -> not excluded */
155 }
156
j_ishidden()157 intptr_t j_ishidden()
158 {
159 return((intptr_t)j_mat[0]);
160 }
161
162 #ifdef APPLE_HYB
163
164 /* HFS hide */
165
166 static char *hfs_mat[MAXMATCH];
167
hfs_add_match(fn)168 int hfs_add_match(fn)
169 char * fn;
170 {
171 register int i;
172
173 for (i=0; hfs_mat[i] && i<MAXMATCH; i++);
174 if (i == MAXMATCH) {
175 fprintf(stderr,"Can't exclude RE '%s' - too many entries in table\n",fn);
176 return 1;
177 }
178
179
180 hfs_mat[i] = (char *) malloc(strlen(fn)+1);
181 if (! hfs_mat[i]) {
182 fprintf(stderr,"Can't allocate memory for excluded filename\n");
183 return 1;
184 }
185
186 strcpy(hfs_mat[i],fn);
187
188 return 0;
189 }
190
hfs_add_list(file)191 void hfs_add_list(file)
192 char *file;
193 {
194 FILE *fp;
195 char name[1024];
196
197 if ((fp = fopen(file, "r")) == NULL) {
198 fprintf(stderr,"Can't open hidden file list %s\n", file);
199 exit (1);
200 }
201
202 while (fscanf(fp, "%s", name) != EOF) {
203 if (hfs_add_match(name)) {
204 fclose(fp);
205 return;
206 }
207 }
208
209 fclose(fp);
210 }
211
212
hfs_matches(fn)213 int hfs_matches(fn)
214 char * fn;
215 {
216 /* very dumb search method ... */
217 register int i;
218
219 for (i=0; hfs_mat[i] && i<MAXMATCH; i++) {
220 if (fnmatch(hfs_mat[i], fn, FNM_PATHNAME) != FNM_NOMATCH) {
221 return 1; /* found -> excluded filenmae */
222 }
223 }
224 return 0; /* not found -> not excluded */
225 }
226
hfs_ishidden()227 intptr_t hfs_ishidden()
228 {
229 return((intptr_t)hfs_mat[0]);
230 }
231
232 /* These will probably appear in mkisofs in the future */
233
add_list(file)234 void add_list(file)
235 char *file;
236 {
237 FILE *fp;
238 char name[1024];
239
240 if ((fp = fopen(file, "r")) == NULL) {
241 fprintf(stderr,"Can't open exclude file list %s\n", file);
242 exit (1);
243 }
244
245 while (fscanf(fp, "%s", name) != EOF) {
246 if (add_match(name)) {
247 fclose(fp);
248 return;
249 }
250 }
251
252 fclose(fp);
253 }
254
i_add_list(file)255 void i_add_list(file)
256 char *file;
257 {
258 FILE *fp;
259 char name[1024];
260
261 if ((fp = fopen(file, "r")) == NULL) {
262 fprintf(stderr,"Can't open hidden file list %s\n", file);
263 exit (1);
264 }
265
266 while (fscanf(fp, "%s", name) != EOF) {
267 if (i_add_match(name)) {
268 fclose(fp);
269 return;
270 }
271 }
272
273 fclose(fp);
274 }
275
j_add_list(file)276 void j_add_list(file)
277 char *file;
278 {
279 FILE *fp;
280 char name[1024];
281
282 if ((fp = fopen(file, "r")) == NULL) {
283 fprintf(stderr,"Can't open hidden file list %s\n", file);
284 exit (1);
285 }
286
287 while (fscanf(fp, "%s", name) != EOF) {
288 if (j_add_match(name)) {
289 fclose(fp);
290 return;
291 }
292 }
293
294 fclose(fp);
295 }
296
297 #endif /* APPLE_HYB */
298