/*
- * 27-Mar-96: Jan-Piet Mens <jpm@mens.de>
- * added 'match' option (-m) to specify regular expressions NOT to be included
- * in the CD image.
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-static char rcsid[] ="$Id: match.c,v 1.3 1999/03/02 03:41:25 eric Exp $";
-
#include "config.h"
-#include <prototyp.h>
-#include <stdio.h>
-#ifndef VMS
-#ifdef HAVE_MALLOC_H
-#include <malloc.h>
-#else
+
#include <stdlib.h>
-#endif
-#endif
#include <string.h>
-#include "match.h"
-
-#define MAXMATCH 1000
-static char *mat[MAXMATCH];
-
-void add_match(fn)
-char * fn;
-{
- register int i;
-
- for (i=0; mat[i] && i<MAXMATCH; i++);
- if (i == MAXMATCH) {
- fprintf(stderr,"Can't exclude RE '%s' - too many entries in table\n",fn);
- return;
- }
-
-
- mat[i] = (char *) malloc(strlen(fn)+1);
- if (! mat[i]) {
- fprintf(stderr,"Can't allocate memory for excluded filename\n");
- return;
- }
-
- strcpy(mat[i],fn);
-}
-
-int matches(fn)
-char * fn;
-{
- /* very dumb search method ... */
- register int i;
-
- for (i=0; mat[i] && i<MAXMATCH; i++) {
- if (fnmatch(mat[i], fn, FNM_FILE_NAME) != FNM_NOMATCH) {
- return 1; /* found -> excluded filenmae */
- }
- }
- return 0; /* not found -> not excluded */
-}
-
-/* ISO9660/RR hide */
-
-static char *i_mat[MAXMATCH];
+#include "fnmatch.h"
-void i_add_match(fn)
-char * fn;
-{
- register int i;
-
- for (i=0; i_mat[i] && i<MAXMATCH; i++);
- if (i == MAXMATCH) {
- fprintf(stderr,"Can't exclude RE '%s' - too many entries in table\n",fn);
- return;
- }
-
-
- i_mat[i] = (char *) malloc(strlen(fn)+1);
- if (! i_mat[i]) {
- fprintf(stderr,"Can't allocate memory for excluded filename\n");
- return;
- }
-
- strcpy(i_mat[i],fn);
-}
+#include "match.h"
-int i_matches(fn)
-char * fn;
+struct pattern
{
- /* very dumb search method ... */
- register int i;
-
- for (i=0; i_mat[i] && i<MAXMATCH; i++) {
- if (fnmatch(i_mat[i], fn, FNM_FILE_NAME) != FNM_NOMATCH) {
- return 1; /* found -> excluded filenmae */
- }
- }
- return 0; /* not found -> not excluded */
+ char *str;
+ struct pattern *next;
+};
+
+static struct pattern *patlist = NULL;
+static struct pattern *i_patlist = NULL; /* ISO9660/RR */
+static struct pattern *j_patlist = NULL; /* Joliet */
+
+#define DECL_ADD_MATCH(function, list) \
+void \
+function (char *pattern) \
+{ \
+ struct pattern *new; \
+ new = malloc (sizeof (*new)); \
+ new->str = strdup (pattern); \
+ new->next = list; \
+ list = new; \
}
-int i_ishidden()
-{
- return (i_mat[0] != NULL);
+DECL_ADD_MATCH (add_match, patlist)
+DECL_ADD_MATCH (i_add_match, i_patlist)
+DECL_ADD_MATCH (j_add_match, j_patlist)
+
+#define DECL_MATCHES(function, list) \
+int \
+function (char *str) \
+{ \
+ struct pattern *i; \
+ for (i = list; i != NULL; i = i->next) \
+ if (fnmatch (i->str, str, FNM_FILE_NAME) != FNM_NOMATCH) \
+ return 1; \
+ return 0; \
}
-/* Joliet hide */
+DECL_MATCHES (matches, patlist)
+DECL_MATCHES (i_matches, i_patlist)
+DECL_MATCHES (j_matches, j_patlist)
-static char *j_mat[MAXMATCH];
-
-void j_add_match(fn)
-char * fn;
+int
+i_ishidden()
{
- register int i;
-
- for (i=0; j_mat[i] && i<MAXMATCH; i++);
- if (i == MAXMATCH) {
- fprintf(stderr,"Can't exclude RE '%s' - too many entries in table\n",fn);
- return;
- }
-
-
- j_mat[i] = (char *) malloc(strlen(fn)+1);
- if (! j_mat[i]) {
- fprintf(stderr,"Can't allocate memory for excluded filename\n");
- return;
- }
-
- strcpy(j_mat[i],fn);
+ return (i_patlist != NULL);
}
-int j_matches(fn)
-char * fn;
-{
- /* very dumb search method ... */
- register int i;
-
- for (i=0; j_mat[i] && i<MAXMATCH; i++) {
- if (fnmatch(j_mat[i], fn, FNM_FILE_NAME) != FNM_NOMATCH) {
- return 1; /* found -> excluded filenmae */
- }
- }
- return 0; /* not found -> not excluded */
-}
int j_ishidden()
{
- return (j_mat[0] != NULL);
+ return (j_patlist != NULL);
}
-
/*
- * 27th March 1996. Added by Jan-Piet Mens for matching regular expressions
- * in paths.
- *
+ * Copyright (C) 2009 Free Software Foundation, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/*
- * $Id: match.h,v 1.2 1999/03/02 03:41:25 eric Exp $
- */
-
-#include "fnmatch.h"
+#include "config.h"
-void add_match __PR((char *fn));
-int matches __PR((char *fn));
+extern void add_match (char *);
+extern void i_add_match (char *);
+extern void j_add_match (char *);
-void i_add_match __PR((char *fn));
-int i_matches __PR((char *fn));
-int i_ishidden __PR((void));
+extern int matches (char *);
+extern int i_matches (char *);
+extern int j_matches (char *);
-void j_add_match __PR((char *fn));
-int j_matches __PR((char *fn));
-int j_ishidden __PR((void));
+extern int i_ishidden ();
+extern int j_ishidden ();