source: clfs-sysroot/patches/bash-4.0-branch_update-3.patch@ 4164d66

Last change on this file since 4164d66 was f91445c, checked in by Joe Ciccone <jciccone@…>, 16 years ago

Updated Bash to 4.0.

  • Property mode set to 100644
File size: 15.0 KB
RevLine 
[f91445c]1Submitted By: Jim Gifford (jim at cross-lfs dot org)
2Date: 03-09-2009
3Initial Package Version: 4.0
4Origin: Upstream
5Upstream Status: Applied
6Description: Contains all upstream patches up to 4.0-010
7
8diff -Naur bash-4.0.orig/arrayfunc.c bash-4.0/arrayfunc.c
9--- bash-4.0.orig/arrayfunc.c 2009-01-04 11:32:21.000000000 -0800
10+++ bash-4.0/arrayfunc.c 2009-03-09 15:07:05.270012850 -0700
11@@ -604,64 +604,7 @@
12 }
13 }
14
15-/* This function assumes s[i] == '['; returns with s[ret] == ']' if
16- an array subscript is correctly parsed. */
17-int
18-skipsubscript (s, i)
19- const char *s;
20- int i;
21-{
22- int count, c;
23-#if defined (HANDLE_MULTIBYTE)
24- mbstate_t state, state_bak;
25- size_t slength, mblength;
26-#endif
27-
28-#if defined (HANDLE_MULTIBYTE)
29- memset (&state, '\0', sizeof (mbstate_t));
30- slength = strlen (s + i);
31-#endif
32-
33- count = 1;
34- while (count)
35- {
36- /* Advance one (possibly multibyte) character in S starting at I. */
37-#if defined (HANDLE_MULTIBYTE)
38- if (MB_CUR_MAX > 1)
39- {
40- state_bak = state;
41- mblength = mbrlen (s + i, slength, &state);
42-
43- if (MB_INVALIDCH (mblength))
44- {
45- state = state_bak;
46- i++;
47- slength--;
48- }
49- else if (MB_NULLWCH (mblength))
50- return i;
51- else
52- {
53- i += mblength;
54- slength -= mblength;
55- }
56- }
57- else
58-#endif
59- ++i;
60-
61- c = s[i];
62-
63- if (c == 0)
64- break;
65- else if (c == '[')
66- count++;
67- else if (c == ']')
68- count--;
69- }
70-
71- return i;
72-}
73+/* skipsubscript moved to subst.c to use private functions. 2009/02/24. */
74
75 /* This function is called with SUB pointing to just after the beginning
76 `[' of an array subscript and removes the array element to which SUB
77diff -Naur bash-4.0.orig/builtins/declare.def bash-4.0/builtins/declare.def
78--- bash-4.0.orig/builtins/declare.def 2009-01-04 11:32:22.000000000 -0800
79+++ bash-4.0/builtins/declare.def 2009-03-09 15:07:02.561839362 -0700
80@@ -295,6 +295,13 @@
81 subscript_start = (char *)NULL;
82 if (t = strchr (name, '[')) /* ] */
83 {
84+ /* If offset != 0 we have already validated any array reference */
85+ if (offset == 0 && valid_array_reference (name) == 0)
86+ {
87+ sh_invalidid (name);
88+ assign_error++;
89+ NEXT_VARIABLE ();
90+ }
91 subscript_start = t;
92 *t = '\0';
93 making_array_special = 1;
94@@ -484,7 +491,7 @@
95 }
96 /* declare -a name[[n]] or declare name[n] makes name an indexed
97 array variable. */
98- else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0)
99+ else if ((making_array_special || (flags_on & att_array)) && array_p (var) == 0 && assoc_p (var) == 0)
100 var = convert_var_to_array (var);
101 #endif /* ARRAY_VARS */
102
103diff -Naur bash-4.0.orig/builtins/exit.def bash-4.0/builtins/exit.def
104--- bash-4.0.orig/builtins/exit.def 2009-01-04 11:32:22.000000000 -0800
105+++ bash-4.0/builtins/exit.def 2009-03-09 15:07:01.245754993 -0700
106@@ -113,7 +113,7 @@
107 for (i = stopmsg = 0; i < js.j_jobslots; i++)
108 if (jobs[i] && STOPPED (i))
109 stopmsg = JSTOPPED;
110- else if (check_jobs_at_exit && stopmsg == 0 && RUNNING (i))
111+ else if (check_jobs_at_exit && stopmsg == 0 && jobs[i] && RUNNING (i))
112 stopmsg = JRUNNING;
113
114 if (stopmsg == JSTOPPED)
115diff -Naur bash-4.0.orig/builtins/read.def bash-4.0/builtins/read.def
116--- bash-4.0.orig/builtins/read.def 2009-01-15 20:11:21.000000000 -0800
117+++ bash-4.0/builtins/read.def 2009-03-09 15:07:07.890180751 -0700
118@@ -369,14 +369,14 @@
119 code = setjmp (alrmbuf);
120 if (code)
121 {
122-#if 0
123+ /* Tricky. The top of the unwind-protect stack is the free of
124+ input_string. We want to run all the rest and use input_string,
125+ so we have to remove it from the stack. */
126+ remove_unwind_protect ();
127 run_unwind_frame ("read_builtin");
128- return (EXECUTION_FAILURE);
129-#else
130 input_string[i] = '\0'; /* make sure it's terminated */
131- retval = 128+SIGALRM;;
132+ retval = 128+SIGALRM;
133 goto assign_vars;
134-#endif
135 }
136 old_alrm = set_signal_handler (SIGALRM, sigalrm);
137 add_unwind_protect (reset_alarm, (char *)NULL);
138diff -Naur bash-4.0.orig/parse.y bash-4.0/parse.y
139--- bash-4.0.orig/parse.y 2009-01-08 05:29:12.000000000 -0800
140+++ bash-4.0/parse.y 2009-03-09 15:07:09.194264282 -0700
141@@ -1615,10 +1615,11 @@
142 {
143 int *ret;
144
145- ret = (int *)xmalloc (3 * sizeof (int));
146+ ret = (int *)xmalloc (4 * sizeof (int));
147 ret[0] = last_read_token;
148 ret[1] = token_before_that;
149 ret[2] = two_tokens_ago;
150+ ret[3] = current_token;
151 return ret;
152 }
153
154@@ -1631,6 +1632,7 @@
155 last_read_token = ts[0];
156 token_before_that = ts[1];
157 two_tokens_ago = ts[2];
158+ current_token = ts[3];
159 }
160
161 /*
162@@ -2668,6 +2670,7 @@
163 FREE (word_desc_to_read);
164 word_desc_to_read = (WORD_DESC *)NULL;
165
166+ current_token = '\n'; /* XXX */
167 last_read_token = '\n';
168 token_to_read = '\n';
169 }
170@@ -2915,6 +2918,7 @@
171 #define P_DQUOTE 0x04
172 #define P_COMMAND 0x08 /* parsing a command, so look for comments */
173 #define P_BACKQUOTE 0x10 /* parsing a backquoted command substitution */
174+#define P_ARRAYSUB 0x20 /* parsing a [...] array subscript for assignment */
175
176 /* Lexical state while parsing a grouping construct or $(...). */
177 #define LEX_WASDOL 0x001
178@@ -2927,6 +2931,7 @@
179 #define LEX_INHEREDOC 0x080
180 #define LEX_HEREDELIM 0x100 /* reading here-doc delimiter */
181 #define LEX_STRIPDOC 0x200 /* <<- strip tabs from here doc delim */
182+#define LEX_INWORD 0x400
183
184 #define COMSUB_META(ch) ((ch) == ';' || (ch) == '&' || (ch) == '|')
185
186@@ -3129,6 +3134,8 @@
187 APPEND_NESTRET ();
188 FREE (nestret);
189 }
190+ else if ((flags & P_ARRAYSUB) && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
191+ goto parse_dollar_word;
192 }
193 /* Parse an old-style command substitution within double quotes as a
194 single word. */
195@@ -3145,6 +3152,7 @@
196 else if MBTEST(open != '`' && (tflags & LEX_WASDOL) && (ch == '(' || ch == '{' || ch == '[')) /* ) } ] */
197 /* check for $(), $[], or ${} inside quoted string. */
198 {
199+parse_dollar_word:
200 if (open == ch) /* undo previous increment */
201 count--;
202 if (ch == '(') /* ) */
203@@ -3179,7 +3187,7 @@
204 int open, close;
205 int *lenp, flags;
206 {
207- int count, ch, peekc, tflags, lex_rwlen, lex_firstind;
208+ int count, ch, peekc, tflags, lex_rwlen, lex_wlen, lex_firstind;
209 int nestlen, ttranslen, start_lineno;
210 char *ret, *nestret, *ttrans, *heredelim;
211 int retind, retsize, rflags, hdlen;
212@@ -3200,7 +3208,7 @@
213 retind = 0;
214
215 start_lineno = line_number;
216- lex_rwlen = 0;
217+ lex_rwlen = lex_wlen = 0;
218
219 heredelim = 0;
220 lex_firstind = -1;
221@@ -3267,6 +3275,46 @@
222 continue;
223 }
224
225+ if (tflags & LEX_PASSNEXT) /* last char was backslash */
226+ {
227+/*itrace("parse_comsub:%d: lex_passnext -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
228+ tflags &= ~LEX_PASSNEXT;
229+ if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
230+ {
231+ if (retind > 0)
232+ retind--; /* swallow previously-added backslash */
233+ continue;
234+ }
235+
236+ RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
237+ if MBTEST(ch == CTLESC || ch == CTLNUL)
238+ ret[retind++] = CTLESC;
239+ ret[retind++] = ch;
240+ continue;
241+ }
242+
243+ /* If this is a shell break character, we are not in a word. If not,
244+ we either start or continue a word. */
245+ if MBTEST(shellbreak (ch))
246+ {
247+ tflags &= ~LEX_INWORD;
248+/*itrace("parse_comsub:%d: lex_inword -> 0 ch = `%c' (%d)", line_number, ch, __LINE__);*/
249+ }
250+ else
251+ {
252+ if (tflags & LEX_INWORD)
253+ {
254+ lex_wlen++;
255+/*itrace("parse_comsub:%d: lex_inword == 1 ch = `%c' lex_wlen = %d (%d)", line_number, ch, lex_wlen, __LINE__);*/
256+ }
257+ else
258+ {
259+/*itrace("parse_comsub:%d: lex_inword -> 1 ch = `%c' (%d)", line_number, ch, __LINE__);*/
260+ tflags |= LEX_INWORD;
261+ lex_wlen = 0;
262+ }
263+ }
264+
265 /* Skip whitespace */
266 if MBTEST(shellblank (ch) && lex_rwlen == 0)
267 {
268@@ -3364,9 +3412,21 @@
269 }
270 tflags &= ~LEX_RESWDOK;
271 }
272- else if (shellbreak (ch) == 0)
273+ else if MBTEST((tflags & LEX_CKCOMMENT) && ch == '#' && (lex_rwlen == 0 || ((tflags & LEX_INWORD) && lex_wlen == 0)))
274+ ; /* don't modify LEX_RESWDOK if we're starting a comment */
275+ else if MBTEST((tflags & LEX_INCASE) && ch != '\n')
276+ /* If we can read a reserved word and we're in case, we're at the
277+ point where we can read a new pattern list or an esac. We
278+ handle the esac case above. If we read a newline, we want to
279+ leave LEX_RESWDOK alone. If we read anything else, we want to
280+ turn off LEX_RESWDOK, since we're going to read a pattern list. */
281 {
282- tflags &= ~LEX_RESWDOK;
283+ tflags &= ~LEX_RESWDOK;
284+/*itrace("parse_comsub:%d: lex_incase == 1 found `%c', lex_reswordok -> 0", line_number, ch);*/
285+}
286+ else if MBTEST(shellbreak (ch) == 0)
287+{
288+ tflags &= ~LEX_RESWDOK;
289 /*itrace("parse_comsub:%d: found `%c', lex_reswordok -> 0", line_number, ch);*/
290 }
291 }
292@@ -3394,36 +3454,23 @@
293 }
294 else
295 shell_ungetc (peekc);
296- tflags |= LEX_HEREDELIM;
297- lex_firstind = -1;
298+ if (peekc != '<')
299+ {
300+ tflags |= LEX_HEREDELIM;
301+ lex_firstind = -1;
302+ }
303 continue;
304 }
305 else
306- ch = peekc; /* fall through and continue XXX - this skips comments if peekc == '#' */
307+ ch = peekc; /* fall through and continue XXX */
308 }
309- /* Not exactly right yet, should handle shell metacharacters, too. If
310- any changes are made to this test, make analogous changes to subst.c:
311- extract_delimited_string(). */
312- else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || shellblank (ret[retind - 1])))
313+ else if MBTEST((tflags & LEX_CKCOMMENT) && (tflags & LEX_INCOMMENT) == 0 && ch == '#' && (((tflags & LEX_RESWDOK) && lex_rwlen == 0) || ((tflags & LEX_INWORD) && lex_wlen == 0)))
314+{
315+/*itrace("parse_comsub:%d: lex_incomment -> 1 (%d)", line_number, __LINE__);*/
316 tflags |= LEX_INCOMMENT;
317+}
318
319- if (tflags & LEX_PASSNEXT) /* last char was backslash */
320- {
321- tflags &= ~LEX_PASSNEXT;
322- if (qc != '\'' && ch == '\n') /* double-quoted \<newline> disappears. */
323- {
324- if (retind > 0)
325- retind--; /* swallow previously-added backslash */
326- continue;
327- }
328-
329- RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
330- if MBTEST(ch == CTLESC || ch == CTLNUL)
331- ret[retind++] = CTLESC;
332- ret[retind++] = ch;
333- continue;
334- }
335- else if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
336+ if MBTEST(ch == CTLESC || ch == CTLNUL) /* special shell escapes */
337 {
338 RESIZE_MALLOCED_BUFFER (ret, retind, 2, retsize, 64);
339 ret[retind++] = CTLESC;
340@@ -4248,7 +4295,7 @@
341 ((token_index > 0 && assignment_acceptable (last_read_token) && token_is_ident (token, token_index)) ||
342 (token_index == 0 && (parser_state&PST_COMPASSIGN))))
343 {
344- ttok = parse_matched_pair (cd, '[', ']', &ttoklen, 0);
345+ ttok = parse_matched_pair (cd, '[', ']', &ttoklen, P_ARRAYSUB);
346 if (ttok == &matched_pair_error)
347 return -1; /* Bail immediately. */
348 RESIZE_MALLOCED_BUFFER (token, token_index, ttoklen + 2,
349@@ -4449,6 +4496,7 @@
350 case '}': /* XXX */
351 case AND_AND:
352 case BANG:
353+ case BAR_AND:
354 case DO:
355 case DONE:
356 case ELIF:
357diff -Naur bash-4.0.orig/patchlevel.h bash-4.0/patchlevel.h
358--- bash-4.0.orig/patchlevel.h 2009-01-04 11:32:40.000000000 -0800
359+++ bash-4.0/patchlevel.h 2009-03-09 15:07:09.194264282 -0700
360@@ -25,6 +25,6 @@
361 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
362 looks for to find the patch level (for the sccs version string). */
363
364-#define PATCHLEVEL 0
365+#define PATCHLEVEL 10
366
367 #endif /* _PATCHLEVEL_H_ */
368diff -Naur bash-4.0.orig/pcomplete.c bash-4.0/pcomplete.c
369--- bash-4.0.orig/pcomplete.c 2009-02-01 14:12:31.000000000 -0800
370+++ bash-4.0/pcomplete.c 2009-03-09 15:06:58.589584858 -0700
371@@ -1032,6 +1032,7 @@
372 cmdlist = build_arg_list (funcname, text, lwords, cw);
373
374 pps = &ps;
375+ save_parser_state (pps);
376 begin_unwind_frame ("gen-shell-function-matches");
377 add_unwind_protect (restore_parser_state, (char *)pps);
378 add_unwind_protect (dispose_words, (char *)cmdlist);
379diff -Naur bash-4.0.orig/subst.c bash-4.0/subst.c
380--- bash-4.0.orig/subst.c 2009-01-28 11:34:12.000000000 -0800
381+++ bash-4.0/subst.c 2009-03-09 15:07:05.274015365 -0700
382@@ -222,6 +222,7 @@
383 static int skip_double_quoted __P((char *, size_t, int));
384 static char *extract_delimited_string __P((char *, int *, char *, char *, char *, int));
385 static char *extract_dollar_brace_string __P((char *, int *, int, int));
386+static int skip_matched_pair __P((const char *, int, int, int, int));
387
388 static char *pos_params __P((char *, int, int, int));
389
390@@ -1374,6 +1375,107 @@
391
392 #define CQ_RETURN(x) do { no_longjmp_on_fatal_error = 0; return (x); } while (0)
393
394+/* This function assumes s[i] == open; returns with s[ret] == close; used to
395+ parse array subscripts. FLAGS currently unused. */
396+static int
397+skip_matched_pair (string, start, open, close, flags)
398+ const char *string;
399+ int start, open, close, flags;
400+{
401+ int i, pass_next, backq, si, c, count;
402+ size_t slen;
403+ char *temp, *ss;
404+ DECLARE_MBSTATE;
405+
406+ slen = strlen (string + start) + start;
407+ no_longjmp_on_fatal_error = 1;
408+
409+ i = start + 1; /* skip over leading bracket */
410+ count = 1;
411+ pass_next = backq = 0;
412+ ss = (char *)string;
413+ while (c = string[i])
414+ {
415+ if (pass_next)
416+ {
417+ pass_next = 0;
418+ if (c == 0)
419+ CQ_RETURN(i);
420+ ADVANCE_CHAR (string, slen, i);
421+ continue;
422+ }
423+ else if (c == '\\')
424+ {
425+ pass_next = 1;
426+ i++;
427+ continue;
428+ }
429+ else if (backq)
430+ {
431+ if (c == '`')
432+ backq = 0;
433+ ADVANCE_CHAR (string, slen, i);
434+ continue;
435+ }
436+ else if (c == '`')
437+ {
438+ backq = 1;
439+ i++;
440+ continue;
441+ }
442+ else if (c == open)
443+ {
444+ count++;
445+ i++;
446+ continue;
447+ }
448+ else if (c == close)
449+ {
450+ count--;
451+ if (count == 0)
452+ break;
453+ i++;
454+ continue;
455+ }
456+ else if (c == '\'' || c == '"')
457+ {
458+ i = (c == '\'') ? skip_single_quoted (ss, slen, ++i)
459+ : skip_double_quoted (ss, slen, ++i);
460+ /* no increment, the skip functions increment past the closing quote. */
461+ }
462+ else if (c == '$' && (string[i+1] == LPAREN || string[i+1] == LBRACE))
463+ {
464+ si = i + 2;
465+ if (string[si] == '\0')
466+ CQ_RETURN(si);
467+
468+ if (string[i+1] == LPAREN)
469+ temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */
470+ else
471+ temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC);
472+ i = si;
473+ if (string[i] == '\0') /* don't increment i past EOS in loop */
474+ break;
475+ i++;
476+ continue;
477+ }
478+ else
479+ ADVANCE_CHAR (string, slen, i);
480+ }
481+
482+ CQ_RETURN(i);
483+}
484+
485+#if defined (ARRAY_VARS)
486+int
487+skipsubscript (string, start)
488+ const char *string;
489+ int start;
490+{
491+ return (skip_matched_pair (string, start, '[', ']', 0));
492+}
493+#endif
494+
495 /* Skip characters in STRING until we find a character in DELIMS, and return
496 the index of that character. START is the index into string at which we
497 begin. This is similar in spirit to strpbrk, but it returns an index into
Note: See TracBrowser for help on using the repository browser.