/* pathexp.c -- The shell interface to the globbing library. */
-/* Copyright (C) 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1995-2007 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
#include "pathexp.h"
#include "flags.h"
-#include <glob/fnmatch.h>
+#include "shmbutil.h"
+#include <glob/strmatch.h>
+
+static int glob_name_is_acceptable __P((const char *));
+static void ignore_globbed_names __P((char **, sh_ignore_func_t *));
+
#if defined (USE_POSIX_GLOB_LIBRARY)
# include <glob.h>
+typedef int posix_glob_errfunc_t __P((const char *, int));
#else
# include <glob/glob.h>
#endif
register char *string;
{
register int c;
+ char *send;
int open;
+ DECLARE_MBSTATE;
+
open = 0;
+ send = string + strlen (string);
+
while (c = *string++)
{
switch (c)
if (*string++ == '\0')
return (0);
}
+
+ /* Advance one fewer byte than an entire multibyte character to
+ account for the auto-increment in the loop above. */
+#ifdef HANDLE_MULTIBYTE
+ string--;
+ ADVANCE_CHAR_P (string, send - string);
+ string++;
+#else
+ ADVANCE_CHAR_P (string, send - string);
+#endif
+ }
+ return (0);
+}
+
+/* Return 1 if C is a character that is `special' in a POSIX ERE and needs to
+ be quoted to match itself. */
+static inline int
+ere_char (c)
+ int c;
+{
+ switch (c)
+ {
+ case '.':
+ case '[':
+ case '\\':
+ case '(':
+ case ')':
+ case '*':
+ case '+':
+ case '?':
+ case '{':
+ case '|':
+ case '^':
+ case '$':
+ return 1;
+ default:
+ return 0;
}
return (0);
}
char *temp;
register int i, j;
- temp = xmalloc (strlen (pathname) + 1);
+ temp = (char *)xmalloc (strlen (pathname) + 1);
if ((qflags & QGLOB_CVTNULL) && QUOTED_NULL (pathname))
{
{
if ((qflags & QGLOB_FILENAME) && pathname[i+1] == '/')
continue;
+ if ((qflags & QGLOB_REGEXP) && ere_char (pathname[i+1]) == 0)
+ continue;
temp[j++] = '\\';
+ i++;
+ if (pathname[i] == '\0')
+ break;
}
- else
- temp[j++] = pathname[i];
+ temp[j++] = pathname[i];
}
temp[j] = '\0';
quote_globbing_chars (string)
char *string;
{
- char *temp, *s, *t;
+ size_t slen;
+ char *temp, *s, *t, *send;
+ DECLARE_MBSTATE;
- temp = xmalloc (strlen (string) * 2 + 1);
+ slen = strlen (string);
+ send = string + slen;
+
+ temp = (char *)xmalloc (slen * 2 + 1);
for (t = temp, s = string; *s; )
{
switch (*s)
*t++ = '\\';
break;
}
- *t++ = *s++;
+
+ /* Copy a single (possibly multibyte) character from s to t,
+ incrementing both. */
+ COPY_CHAR_P (t, s, send);
}
*t = '\0';
return temp;
glob_flags |= (GLOB_ERR | GLOB_DOOFFS);
- i = glob (temp, glob_flags, (Function *)NULL, &filenames);
+ i = glob (temp, glob_flags, (posix_glob_errfunc_t *)NULL, &filenames);
free (temp);
if (should_ignore_glob_matches ())
ignore_glob_matches (results);
if (results && results[0])
- sort_char_array (results);
+ strvec_sort (results);
else
{
FREE (results);
noglob_dot_filenames = glob_dot_filenames == 0;
temp = quote_string_for_globbing (pathname, QGLOB_FILENAME);
-
- results = glob_filename (temp);
+ results = glob_filename (temp, 0);
free (temp);
if (results && ((GLOB_FAILED (results)) == 0))
if (should_ignore_glob_matches ())
ignore_glob_matches (results);
if (results && results[0])
- sort_char_array (results);
+ strvec_sort (results);
else
{
FREE (results);
(struct ign *)0,
0,
(char *)0,
- (Function *)0,
+ (sh_iv_item_func_t *)0,
};
/* Set up to ignore some glob matches because the value of GLOBIGNORE
/* Return 0 if NAME matches a pattern in the globignore.ignores list. */
static int
glob_name_is_acceptable (name)
- char *name;
+ const char *name;
{
struct ign *p;
int flags;
flags = FNM_PATHNAME | FNMATCH_EXTFLAG;
for (p = globignore.ignores; p->val; p++)
{
- if (fnmatch (p->val, name, flags) != FNM_NOMATCH)
+ if (strmatch (p->val, (char *)name, flags) != FNM_NOMATCH)
return (0);
}
return (1);
static void
ignore_globbed_names (names, name_func)
char **names;
- Function *name_func;
+ sh_ignore_func_t *name_func;
{
char **newnames;
int n, i;
for (i = 0; names[i]; i++)
;
- newnames = alloc_array (i + 1);
+ newnames = strvec_create (i + 1);
for (n = i = 0; names[i]; i++)
{