RPM Package Manager, CVS Repository http://rpm5.org/cvs/ ____________________________________________________________________________
Server: rpm5.org Name: Jeff Johnson Root: /v/rpm/cvs Email: j...@rpm5.org Module: bash Date: 09-May-2009 18:14:35 Branch: HEAD Handle: 2009050916143400 Modified files: bash arrayfunc.c parse.y patchlevel.h subst.c Log: - jbj: apply bash40-007. Summary: Revision Changes Path 1.2 +1 -58 bash/arrayfunc.c 1.5 +5 -1 bash/parse.y 1.8 +1 -1 bash/patchlevel.h 1.2 +102 -0 bash/subst.c ____________________________________________________________________________ patch -p0 <<'@@ .' Index: bash/arrayfunc.c ============================================================================ $ cvs diff -u -r1.1.1.1 -r1.2 arrayfunc.c --- bash/arrayfunc.c 9 May 2009 14:31:30 -0000 1.1.1.1 +++ bash/arrayfunc.c 9 May 2009 16:14:34 -0000 1.2 @@ -604,64 +604,7 @@ } } -/* This function assumes s[i] == '['; returns with s[ret] == ']' if - an array subscript is correctly parsed. */ -int -skipsubscript (s, i) - const char *s; - int i; -{ - int count, c; -#if defined (HANDLE_MULTIBYTE) - mbstate_t state, state_bak; - size_t slength, mblength; -#endif - -#if defined (HANDLE_MULTIBYTE) - memset (&state, '\0', sizeof (mbstate_t)); - slength = strlen (s + i); -#endif - - count = 1; - while (count) - { - /* Advance one (possibly multibyte) character in S starting at I. */ -#if defined (HANDLE_MULTIBYTE) - if (MB_CUR_MAX > 1) - { - state_bak = state; - mblength = mbrlen (s + i, slength, &state); - - if (MB_INVALIDCH (mblength)) - { - state = state_bak; - i++; - slength--; - } - else if (MB_NULLWCH (mblength)) - return i; - else - { - i += mblength; - slength -= mblength; - } - } - else -#endif - ++i; - - c = s[i]; - - if (c == 0) - break; - else if (c == '[') - count++; - else if (c == ']') - count--; - } - - return i; -} +/* skipsubscript moved to subst.c to use private functions. 2009/02/24. */ /* This function is called with SUB pointing to just after the beginning `[' of an array subscript and removes the array element to which SUB @@ . patch -p0 <<'@@ .' Index: bash/parse.y ============================================================================ $ cvs diff -u -r1.4 -r1.5 parse.y --- bash/parse.y 9 May 2009 16:13:55 -0000 1.4 +++ bash/parse.y 9 May 2009 16:14:34 -0000 1.5 @@ -2918,6 +2918,7 @@ #define P_DQUOTE 0x04 #define P_COMMAND 0x08 /* parsing a command, so look for comments */ #define P_BACKQUOTE 0x10 /* parsing a backquoted command substitution */ +#define P_ARRAYSUB 0x20 /* parsing a [...] array subscript for assignment */ /* Lexical state while parsing a grouping construct or $(...). */ #define LEX_WASDOL 0x001 @@ -3133,6 +3134,8 @@ APPEND_NESTRET (); FREE (nestret); } + else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ + goto parse_dollar_word; } /* Parse an old-style command substitution within double quotes as a single word. */ @@ -3149,6 +3152,7 @@ else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */ /* check for $(), $[], or ${} inside quoted string. */ { +parse_dollar_word: if (open == ch) /* undo previous increment */ count--; if (ch == '(') /* ) */ @@ -4276,7 +4280,7 @@ ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) || (token_index == 0 && (parser_state&PST_COMPASSIGN)))) { - ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0); + ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB); if (ttok == &matched_pair_error) return -1; /* Bail immediately. */ RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2, @@ . patch -p0 <<'@@ .' Index: bash/patchlevel.h ============================================================================ $ cvs diff -u -r1.7 -r1.8 patchlevel.h --- bash/patchlevel.h 9 May 2009 16:13:55 -0000 1.7 +++ bash/patchlevel.h 9 May 2009 16:14:34 -0000 1.8 @@ -25,6 +25,6 @@ regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh looks for to find the patch level (for the sccs version string). */ -#define PATCHLEVEL 6 +#define PATCHLEVEL 7 #endif /* _PATCHLEVEL_H_ */ @@ . patch -p0 <<'@@ .' Index: bash/subst.c ============================================================================ $ cvs diff -u -r1.1.1.1 -r1.2 subst.c --- bash/subst.c 9 May 2009 14:31:48 -0000 1.1.1.1 +++ bash/subst.c 9 May 2009 16:14:34 -0000 1.2 @@ -222,6 +222,7 @@ static int skip_double_quoted __P((char *, size_t, int)); static char *extract_delimited_string __P((char *, int *, char *, char *, char *, int)); static char *extract_dollar_brace_string __P((char *, int *, int, int)); +static int skip_matched_pair __P((const char *, int, int, int, int)); static char *pos_params __P((char *, int, int, int)); @@ -1374,6 +1375,107 @@ #define CQ_RETURN(x) do { no_longjmp_on_fatal_error = 0; return (x); } while (0) +/* This function assumes s[i] == open; returns with s[ret] == close; used to + parse array subscripts. FLAGS currently unused. */ +static int +skip_matched_pair (string, start, open, close, flags) + const char *string; + int start, open, close, flags; +{ + int i, pass_next, backq, si, c, count; + size_t slen; + char *temp, *ss; + DECLARE_MBSTATE; + + slen = strlen (string + start) + start; + no_longjmp_on_fatal_error = 1; + + i = start + 1; /* skip over leading bracket */ + count = 1; + pass_next = backq = 0; + ss = (char *)string; + while (c = string[i]) + { + if (pass_next) + { + pass_next = 0; + if (c == 0) + CQ_RETURN(i); + ADVANCE_CHAR (string, slen, i); + continue; + } + else if (c == '\\') + { + pass_next = 1; + i++; + continue; + } + else if (backq) + { + if (c == '`') + backq = 0; + ADVANCE_CHAR (string, slen, i); + continue; + } + else if (c == '`') + { + backq = 1; + i++; + continue; + } + else if (c == open) + { + count++; + i++; + continue; + } + else if (c == close) + { + count--; + if (count == 0) + break; + i++; + continue; + } + else if (c == '\'' || c == '"') + { + i = (c == '\'') ? skip_single_quoted (ss, slen, ++i) + : skip_double_quoted (ss, slen, ++i); + /* no increment, the skip functions increment past the closing quote. */ + } + else if (c == '$' && (string[i+1] == LPAREN || string[i+1] == LBRACE)) + { + si = i + 2; + if (string[si] == '\0') + CQ_RETURN(si); + + if (string[i+1] == LPAREN) + temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */ + else + temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC); + i = si; + if (string[i] == '\0') /* don't increment i past EOS in loop */ + break; + i++; + continue; + } + else + ADVANCE_CHAR (string, slen, i); + } + + CQ_RETURN(i); +} + +#if defined (ARRAY_VARS) +int +skipsubscript (string, start) + const char *string; + int start; +{ + return (skip_matched_pair (string, start, '[', ']', 0)); +} +#endif + /* Skip characters in STRING until we find a character in DELIMS, and return the index of that character. START is the index into string at which we begin. This is similar in spirit to strpbrk, but it returns an index into @@ . ______________________________________________________________________ RPM Package Manager http://rpm5.org CVS Sources Repository rpm-cvs@rpm5.org