2009-11-18 Robert Millan <rmh.grub@aybabtu.com>

* util/mkisofs/match.c: Rewrite from scratch, using a linked list
        instead of static allocation.
        * util/mkisofs/match.h: Likewise.
This commit is contained in:
Robert Millan 2009-11-18 22:49:59 +00:00
parent 633877cbb1
commit 1dabbc77cf
3 changed files with 81 additions and 139 deletions

View file

@ -1,3 +1,9 @@
2009-11-18 Robert Millan <rmh.grub@aybabtu.com>
* util/mkisofs/match.c: Rewrite from scratch, using a linked list
instead of static allocation.
* util/mkisofs/match.h: Likewise.
2009-11-18 Robert Millan <rmh.grub@aybabtu.com>
* po/POTFILES-shell: New file. List `util/grub.d/10_kfreebsd.in'

View file

@ -1,147 +1,76 @@
/*
* 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 "fnmatch.h"
#include "match.h"
#define MAXMATCH 1000
static char *mat[MAXMATCH];
void add_match(fn)
char * fn;
struct pattern
{
register int i;
char *str;
struct pattern *next;
};
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;
}
static struct pattern *patlist = NULL;
static struct pattern *i_patlist = NULL; /* ISO9660/RR */
static struct pattern *j_patlist = NULL; /* Joliet */
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);
#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 matches(fn)
char * fn;
{
/* very dumb search method ... */
register int i;
DECL_ADD_MATCH (add_match, patlist)
DECL_ADD_MATCH (i_add_match, i_patlist)
DECL_ADD_MATCH (j_add_match, j_patlist)
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 */
#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; \
}
/* ISO9660/RR hide */
DECL_MATCHES (matches, patlist)
DECL_MATCHES (i_matches, i_patlist)
DECL_MATCHES (j_matches, j_patlist)
static char *i_mat[MAXMATCH];
void i_add_match(fn)
char * fn;
int
i_ishidden()
{
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);
return (i_patlist != NULL);
}
int i_matches(fn)
char * fn;
{
/* 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 */
}
int i_ishidden()
{
return (i_mat[0] != NULL);
}
/* Joliet hide */
static char *j_mat[MAXMATCH];
void j_add_match(fn)
char * fn;
{
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);
}
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);
}

View file

@ -1,22 +1,29 @@
/*
* 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 "config.h"
#include "fnmatch.h"
extern void add_match (char *);
extern void i_add_match (char *);
extern void j_add_match (char *);
void add_match __PR((char *fn));
int matches __PR((char *fn));
extern int matches (char *);
extern int i_matches (char *);
extern int j_matches (char *);
void i_add_match __PR((char *fn));
int i_matches __PR((char *fn));
int i_ishidden __PR((void));
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 ();