* .cvsignore file support contributed by David G. Grubbs <dgg@ksr.com>
static char rcsid
[] = "@(#)ignore.c 1.13 92/04/03";
* "!" may be included any time to reset the list (i.e. ignore nothing);
* "*" may be specified to ignore everything. It stays as the first
* element forever, unless a "!" clears it out.
static char **ign_list
; /* List of files to ignore in update
static char **s_ign_list
= NULL
;
static int ign_count
; /* Number of active entries */
static int s_ign_count
= 0;
static int ign_size
; /* This many slots available (plus
static int ign_hold
; /* Index where first "temporary" item
char *ign_default
= ". .. core RCSLOG tags TAGS RCS SCCS .make.state .nse_depinfo #* .#* cvslog.* ,* CVS* .del-* *.a *.o *.so *.Z *~ *.old *.elc *.ln *.bak *.BAK *.orig *.rej";
#define IGN_GROW 16 /* grow the list by 16 elements at a
* To the "ignore list", add the hard-coded default ignored wildcards above,
* the wildcards found in $CVSROOT/CVSROOT/cvsignore, the wildcards found in
* ~/.cvsignore and the wildcards found in the CVSIGNORE environment
/* Start with default list and special case */
tmp
= xstrdup (ign_default
);
/* Then add entries found in repository, if it exists */
(void) sprintf (file
, "%s/%s/%s", CVSroot
, CVSROOTADM
, CVSROOTADM_IGNORE
);
/* Then add entries found in home dir, (if user has one) and file exists */
if ((pw
= (struct passwd
*) getpwuid (getuid ())) && pw
->pw_dir
)
(void) sprintf (file
, "%s/%s", pw
->pw_dir
, CVSDOTIGNORE
);
/* Then add entries found in CVSIGNORE environment variable. */
ign_add (getenv (IGNORE_ENV
), 0);
/* Later, add ignore entries found in -I arguments */
* Open a file and read lines, feeding each line to a line parser. Arrange
* for keeping a temporary list of wildcards at the end, if the "hold"
ign_add_file (file
, hold
)
/* restore the saved list (if any) */
for (i
= 0; i
< s_ign_count
; i
++)
ign_list
[i
] = s_ign_list
[i
];
ign_list
[ign_count
] = NULL
;
/* is this a temporary ignore file? */
/* re-set if we had already done a temporary file */
for (i
= ign_hold
; i
< ign_count
; i
++)
ign_list
[ign_count
] = NULL
;
if (!(fp
= fopen (file
, "r")))
while (fgets (line
, sizeof (line
), fp
))
/* Parse a line of space-separated wildcards and add them to the list. */
/* ignore whitespace before the token */
* if we find a single character !, we must re-set the ignore list
* (saving it if necessary). We also catch * as a special case in a
* global ignore file as an optimization
if (isspace (*(ign
+ 1)) && (*ign
== '!' || *ign
== '*'))
/* permanently reset the ignore list */
for (i
= 0; i
< ign_count
; i
++)
/* if we are doing a '!', continue; otherwise add the '*' */
/* temporarily reset the ignore list */
for (i
= ign_hold
; i
< ign_count
; i
++)
s_ign_list
= (char **) xmalloc (ign_count
* sizeof (char *));
for (i
= 0; i
< ign_count
; i
++)
s_ign_list
[i
] = ign_list
[i
];
/* If we have used up all the space, add some more */
if (ign_count
>= ign_size
)
ign_list
= (char **) xrealloc ((char *) ign_list
,
(ign_size
+ 1) * sizeof (char *));
/* find the end of this token */
for (mark
= ign
; *mark
&& !isspace (*mark
); mark
++)
ign_list
[ign_count
++] = xstrdup (ign
);
ign_list
[ign_count
] = NULL
;
/* Return 1 if the given filename should be ignored by update or import. */
if (fnmatch (*cpp
++, name
, 0) == 0)