diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-10-11 14:49:26 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2010-10-11 15:19:40 -0700 |
commit | 011c1d1c0766c65517ebd495465c99e86edb63ec (patch) | |
tree | 30d8f6a13235af90897c3223554871ef52225462 /pathexp.c | |
parent | 40cfaccf7b178b6239b5cd0013ef80b7ff8e503e (diff) | |
download | vyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.tar.gz vyatta-bash-011c1d1c0766c65517ebd495465c99e86edb63ec.zip |
Update to bash-4.1
Diffstat (limited to 'pathexp.c')
-rw-r--r-- | pathexp.c | 108 |
1 files changed, 78 insertions, 30 deletions
@@ -1,22 +1,22 @@ /* pathexp.c -- The shell interface to the globbing library. */ -/* Copyright (C) 1995-2002 Free Software Foundation, Inc. +/* Copyright (C) 1995-2009 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. - Bash 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 2, or (at your option) any later - version. + Bash 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. - Bash 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. + Bash 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 Bash; see the file COPYING. If not, write to the Free Software - Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */ + You should have received a copy of the GNU General Public License + along with Bash. If not, see <http://www.gnu.org/licenses/>. +*/ #include "config.h" @@ -34,6 +34,7 @@ #include "flags.h" #include "shmbutil.h" +#include "bashintl.h" #include <glob/strmatch.h> @@ -51,7 +52,10 @@ typedef int posix_glob_errfunc_t __P((const char *, int)); int glob_dot_filenames; /* Control whether the extended globbing features are enabled. */ -int extended_glob = 0; +int extended_glob = EXTGLOB_DEFAULT; + +/* Control enabling special handling of `**' */ +int glob_star = 0; /* Return nonzero if STRING has any unquoted special globbing chars in it. */ int @@ -110,6 +114,55 @@ unquoted_glob_pattern_p (string) 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); +} + +int +glob_char_p (s) + const char *s; +{ + switch (*s) + { + case '*': + case '[': + case ']': + case '?': + case '\\': + return 1; + case '+': + case '@': + case '!': + if (s[1] == '(') /*(*/ + return 1; + break; + } + return 0; +} + /* PATHNAME can contain characters prefixed by CTLESC; this indicates that the character is to be quoted. We quote it here in the style that the glob library recognizes. If flags includes QGLOB_CVTNULL, @@ -142,6 +195,15 @@ quote_string_for_globbing (pathname, qflags) { 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 if (pathname[i] == '\\') + { temp[j++] = '\\'; i++; if (pathname[i] == '\0') @@ -168,22 +230,8 @@ quote_globbing_chars (string) temp = (char *)xmalloc (slen * 2 + 1); for (t = temp, s = string; *s; ) { - switch (*s) - { - case '*': - case '[': - case ']': - case '?': - case '\\': - *t++ = '\\'; - break; - case '+': - case '@': - case '!': - if (s[1] == '(') /*(*/ - *t++ = '\\'; - break; - } + if (glob_char_p (s)) + *t++ = '\\'; /* Copy a single (possibly multibyte) character from s to t, incrementing both. */ @@ -251,7 +299,7 @@ shell_glob_filename (pathname) noglob_dot_filenames = glob_dot_filenames == 0; temp = quote_string_for_globbing (pathname, QGLOB_FILENAME); - results = glob_filename (temp, 0); + results = glob_filename (temp, glob_star ? GX_GLOBSTAR : 0); free (temp); if (results && ((GLOB_FAILED (results)) == 0)) |