1 diff -Naur bash-3.0.orig/array.c bash-3.0/array.c
2 --- bash-3.0.orig/array.c 2004-05-06 12:24:13.000000000 +0000
3 +++ bash-3.0/array.c 2005-01-08 05:40:02.059798512 +0000
6 array_dispose_element(new);
7 free(element_value(ae));
8 - ae->value = savestring(v);
9 + ae->value = v ? savestring(v) : (char *)NULL;
11 } else if (element_index(ae) > i) {
13 diff -Naur bash-3.0.orig/arrayfunc.c bash-3.0/arrayfunc.c
14 --- bash-3.0.orig/arrayfunc.c 2003-12-19 05:03:09.000000000 +0000
15 +++ bash-3.0/arrayfunc.c 2005-01-08 05:40:01.679856272 +0000
17 var = find_variable (t);
21 + return (var == 0 || invisible_p (var)) ? (SHELL_VAR *)0 : var;
24 /* Return a string containing the elements in the array and subscript
25 diff -Naur bash-3.0.orig/bashline.c bash-3.0/bashline.c
26 --- bash-3.0.orig/bashline.c 2004-07-06 03:22:12.000000000 +0000
27 +++ bash-3.0/bashline.c 2005-01-08 05:40:42.016724136 +0000
31 /* Helper functions for Readline. */
32 +static int bash_directory_expansion __P((char **));
33 static int bash_directory_completion_hook __P((char **));
34 static int filename_completion_ignore __P((char **));
35 static int bash_push_line __P((void));
37 /* See if we have anything to do. */
38 at = strchr (rl_completer_word_break_characters, '@');
39 if ((at == 0 && on_or_off == 0) || (at != 0 && on_or_off != 0))
43 /* We have something to do. Do it. */
44 nval = (char *)xmalloc (strlen (rl_completer_word_break_characters) + 1 + on_or_off);
45 @@ -1406,10 +1407,19 @@
47 if (*hint_text == '~')
53 tl = strlen (hint_text);
55 l = vl - hint_len; /* # of chars added */
57 + rd = savestring (filename_hint);
58 + bash_directory_expansion (&rd);
60 + l = vl - dl; /* # of chars added */
63 temp = (char *)xmalloc (l + 2 + tl);
64 strcpy (temp, hint_text);
65 strcpy (temp + tl, val + vl - l);
66 @@ -2187,6 +2197,27 @@
70 +/* Simulate the expansions that will be performed by
71 + rl_filename_completion_function. This must be called with the address of
72 + a pointer to malloc'd memory. */
74 +bash_directory_expansion (dirname)
79 + d = savestring (*dirname);
81 + if (rl_directory_rewrite_hook)
82 + (*rl_directory_rewrite_hook) (&d);
84 + if (rl_directory_completion_hook && (*rl_directory_completion_hook) (&d))
91 /* Handle symbolic link references and other directory name
92 expansions while hacking completion. */
95 static char **matches = (char **)NULL;
103 @@ -2523,17 +2554,22 @@
107 + ttext = bash_tilde_expand (text, 0);
111 - globorig = savestring (text);
112 - glen = strlen (text);
113 + globorig = savestring (ttext);
114 + glen = strlen (ttext);
115 globtext = (char *)xmalloc (glen + 2);
116 - strcpy (globtext, text);
117 + strcpy (globtext, ttext);
118 globtext[glen] = '*';
119 globtext[glen+1] = '\0';
122 - globtext = globorig = savestring (text);
123 + globtext = globorig = savestring (ttext);
128 matches = shell_glob_filename (globtext);
129 if (GLOB_FAILED (matches))
130 diff -Naur bash-3.0.orig/braces.c bash-3.0/braces.c
131 --- bash-3.0.orig/braces.c 2003-12-04 16:09:52.000000000 +0000
132 +++ bash-3.0/braces.c 2005-01-08 05:40:50.317462232 +0000
135 if (lhs_t == ST_CHAR)
139 + lhs_v = (unsigned char)lhs[0];
140 + rhs_v = (unsigned char)rhs[0];
153 diff -Naur bash-3.0.orig/builtins/trap.def bash-3.0/builtins/trap.def
154 --- bash-3.0.orig/builtins/trap.def 2004-05-28 02:26:19.000000000 +0000
155 +++ bash-3.0/builtins/trap.def 2005-01-08 05:40:04.443436144 +0000
159 $FUNCTION trap_builtin
160 -$SHORT_DOC trap [-lp] [[arg] signal_spec ...]
161 +$SHORT_DOC trap [-lp] [arg signal_spec ...]
162 The command ARG is to be read and executed when the shell receives
163 signal(s) SIGNAL_SPEC. If ARG is absent (and a single SIGNAL_SPEC
164 is supplied) or `-', each specified signal is reset to its original
169 - int list_signal_names, display, result, opt;
170 + int list_signal_names, display, result, opt, first_signal;
172 list_signal_names = display = 0;
173 result = EXECUTION_SUCCESS;
174 @@ -118,14 +118,19 @@
178 - int operation, sig;
179 + int operation, sig, first_signal;
182 first_arg = list->word->word;
183 + first_signal = first_arg && *first_arg && all_digits (first_arg) && signal_object_p (first_arg, opt);
185 + /* Backwards compatibility */
187 + operation = REVERT;
188 /* When in posix mode, the historical behavior of looking for a
189 missing first argument is disabled. To revert to the original
190 signal handling disposition, use `-' as the first argument. */
191 - if (posixly_correct == 0 && first_arg && *first_arg &&
192 + else if (posixly_correct == 0 && first_arg && *first_arg &&
193 (*first_arg != '-' || first_arg[1]) &&
194 signal_object_p (first_arg, opt) && list->next == 0)
196 diff -Naur bash-3.0.orig/doc/bashref.texi bash-3.0/doc/bashref.texi
197 --- bash-3.0.orig/doc/bashref.texi 2004-06-26 18:26:07.000000000 +0000
198 +++ bash-3.0/doc/bashref.texi 2005-01-08 05:40:04.494428392 +0000
199 @@ -5953,7 +5953,8 @@
201 The @code{trap} builtin doesn't check the first argument for a possible
202 signal specification and revert the signal handling to the original
203 -disposition if it is. If users want to reset the handler for a given
204 +disposition if it is, unless that argument consists solely of digits and
205 +is a valid signal number. If users want to reset the handler for a given
206 signal to the original disposition, they should use @samp{-} as the
209 diff -Naur bash-3.0.orig/general.c bash-3.0/general.c
210 --- bash-3.0.orig/general.c 2004-04-15 03:20:13.000000000 +0000
211 +++ bash-3.0/general.c 2005-01-08 05:40:51.913219640 +0000
213 c = string[indx = 0];
215 #if defined (ARRAY_VARS)
216 - if ((legal_variable_starter (c) == 0) && (flags && c != '[')) /* ] */
217 + if ((legal_variable_starter (c) == 0) && (flags == 0 || c != '[')) /* ] */
219 if (legal_variable_starter (c) == 0)
221 diff -Naur bash-3.0.orig/include/shmbutil.h bash-3.0/include/shmbutil.h
222 --- bash-3.0.orig/include/shmbutil.h 2004-04-19 13:59:42.000000000 +0000
223 +++ bash-3.0/include/shmbutil.h 2005-01-08 05:40:05.724241432 +0000
225 extern size_t xmbsrtowcs __P((wchar_t *, const char **, size_t, mbstate_t *));
226 extern size_t xdupmbstowcs __P((wchar_t **, char ***, const char *));
228 +extern size_t mbstrlen __P((const char *));
230 extern char *xstrchr __P((const char *, int));
234 #define MB_NULLWCH(x) ((x) == 0)
237 +#define MBSLEN(s) (((s) && (s)[0]) ? ((s)[1] ? mbstrlen (s) : 1) : 0)
238 +#define MB_STRLEN(s) ((MB_CUR_MAX > 1) ? MBSLEN (s) : STRLEN (s))
240 #else /* !HANDLE_MULTIBYTE */
244 #define MB_NULLWCH(x) (0)
247 +#define MB_STRLEN(s) (STRLEN(s))
249 #endif /* !HANDLE_MULTIBYTE */
251 /* Declare and initialize a multibyte state. Call must be terminated
252 diff -Naur bash-3.0.orig/jobs.c bash-3.0/jobs.c
253 --- bash-3.0.orig/jobs.c 2004-04-23 20:28:25.000000000 +0000
254 +++ bash-3.0/jobs.c 2005-01-08 05:40:40.567944384 +0000
255 @@ -1778,8 +1778,13 @@
259 - for (p = jobs[job]->pipe; p->next != jobs[job]->pipe; p = p->next)
260 - if (p->status != EXECUTION_SUCCESS) fail = p->status;
261 + p = jobs[job]->pipe;
264 + if (p->status != EXECUTION_SUCCESS) fail = p->status;
267 + while (p != jobs[job]->pipe);
271 diff -Naur bash-3.0.orig/lib/readline/display.c bash-3.0/lib/readline/display.c
272 --- bash-3.0.orig/lib/readline/display.c 2004-05-28 02:57:51.000000000 +0000
273 +++ bash-3.0/lib/readline/display.c 2005-01-08 05:40:08.574808080 +0000
275 int *lp, *lip, *niflp, *vlp;
278 - int l, rl, last, ignoring, ninvis, invfl, ind, pind, physchars;
279 + int l, rl, last, ignoring, ninvis, invfl, invflset, ind, pind, physchars;
281 /* Short-circuit if we can. */
282 if ((MB_CUR_MAX <= 1 || rl_byte_oriented) && strchr (pmt, RL_PROMPT_START_IGNORE) == 0)
284 r = ret = (char *)xmalloc (l + 1);
286 invfl = 0; /* invisible chars in first line of prompt */
287 + invflset = 0; /* we only want to set invfl once */
289 for (rl = ignoring = last = ninvis = physchars = 0, p = pmt; p && *p; p++)
298 + physchars += _rl_col_width (pmt, pind, ind);
301 ninvis += ind - pind;
302 p--; /* compensate for later increment */
303 @@ -259,16 +263,19 @@
307 - rl++; /* visible length byte counter */
309 + rl++; /* visible length byte counter */
313 ninvis++; /* invisible chars byte counter */
316 - if (rl >= _rl_screenwidth)
321 + if (invflset == 0 && rl >= _rl_screenwidth)
329 @@ -351,14 +358,14 @@
330 local_prompt = expand_prompt (p, &prompt_visible_length,
331 &prompt_last_invisible,
334 + &prompt_physical_chars);
336 /* The portion of the prompt string up to and including the
337 final newline is now null-terminated. */
338 local_prompt_prefix = expand_prompt (prompt, &prompt_prefix_length,
340 &prompt_invis_chars_first_line,
341 - &prompt_physical_chars);
344 return (prompt_prefix_length);
347 register int in, out, c, linenum, cursor_linenum;
349 int c_pos, inv_botlin, lb_botlin, lb_linenum;
350 - int newlines, lpos, temp, modmark;
351 + int newlines, lpos, temp, modmark, n0, num;
352 char *prompt_this_line;
353 #if defined (HANDLE_MULTIBYTE)
357 #if defined (HANDLE_MULTIBYTE)
358 memset (_rl_wrapped_line, 0, vis_lbsize);
362 /* prompt_invis_chars_first_line is the number of invisible characters in
363 @@ -591,13 +599,32 @@
364 probably too much work for the benefit gained. How many people have
365 prompts that exceed two physical lines?
366 Additional logic fix from Edward Catmur <ed@catmur.co.uk> */
367 +#if defined (HANDLE_MULTIBYTE)
369 + temp = local_prompt ? strlen (local_prompt) : 0;
372 + if (_rl_col_width (local_prompt, n0, num) > _rl_screenwidth)
374 + num = _rl_find_prev_mbchar (local_prompt, num, MB_FIND_ANY);
381 temp = ((newlines + 1) * _rl_screenwidth) +
382 +#endif /* !HANDLE_MULTIBYTE */
383 ((local_prompt_prefix == 0) ? ((newlines == 0) ? prompt_invis_chars_first_line
384 : ((newlines == 1) ? wrap_offset : 0))
385 : ((newlines == 0) ? wrap_offset :0));
387 inv_lbreaks[++newlines] = temp;
388 +#if defined (HANDLE_MULTIBYTE)
389 + lpos -= _rl_col_width (local_prompt, n0, num);
391 lpos -= _rl_screenwidth;
395 prompt_last_screen_line = newlines;
396 diff -Naur bash-3.0.orig/lib/readline/mbutil.c bash-3.0/lib/readline/mbutil.c
397 --- bash-3.0.orig/lib/readline/mbutil.c 2004-01-14 14:44:52.000000000 +0000
398 +++ bash-3.0/lib/readline/mbutil.c 2005-01-08 05:40:39.252144416 +0000
399 @@ -126,11 +126,11 @@
402 tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps);
403 - while (wcwidth (wc) == 0)
404 + while (tmp > 0 && wcwidth (wc) == 0)
407 tmp = mbrtowc (&wc, string + point, strlen (string + point), &ps);
408 - if (tmp == (size_t)(0) || tmp == (size_t)(-1) || tmp == (size_t)(-2))
409 + if (MB_NULLWCH (tmp) || MB_INVALIDCH (tmp))
413 diff -Naur bash-3.0.orig/lib/readline/misc.c bash-3.0/lib/readline/misc.c
414 --- bash-3.0.orig/lib/readline/misc.c 2004-07-07 12:56:32.000000000 +0000
415 +++ bash-3.0/lib/readline/misc.c 2005-01-08 05:40:07.040041400 +0000
417 _rl_saved_line_for_history->line = savestring (rl_line_buffer);
418 _rl_saved_line_for_history->data = (char *)rl_undo_list;
420 - else if (STREQ (rl_line_buffer, _rl_saved_line_for_history->line) == 0)
422 - free (_rl_saved_line_for_history->line);
423 - _rl_saved_line_for_history->line = savestring (rl_line_buffer);
424 - _rl_saved_line_for_history->data = (char *)rl_undo_list; /* XXX possible memleak */
429 diff -Naur bash-3.0.orig/lib/readline/vi_mode.c bash-3.0/lib/readline/vi_mode.c
430 --- bash-3.0.orig/lib/readline/vi_mode.c 2004-07-13 18:08:27.000000000 +0000
431 +++ bash-3.0/lib/readline/vi_mode.c 2005-01-08 05:40:25.349257976 +0000
432 @@ -272,10 +272,12 @@
436 + _rl_free_saved_history_line ();
437 rl_noninc_forward_search (count, key);
441 + _rl_free_saved_history_line ();
442 rl_noninc_reverse_search (count, key);
448 char mb[MB_LEN_MAX+1];
453 memset (&ps, 0, sizeof (mbstate_t));
454 @@ -713,11 +715,14 @@
455 /* Vi is kind of strange here. */
459 mblen = wcrtomb (mb, wc, &ps);
462 rl_begin_undo_group ();
464 + rl_vi_delete (1, 0);
465 + if (rl_point < p) /* Did we retreat at EOL? */
466 + rl_point++; /* XXX - should we advance more than 1 for mbchar? */
468 rl_end_undo_group ();
470 @@ -1310,12 +1315,16 @@
472 #if defined (HANDLE_MULTIBYTE)
473 if (MB_CUR_MAX > 1 && rl_byte_oriented == 0)
474 - while (_rl_insert_char (1, c))
476 - RL_SETSTATE (RL_STATE_MOREINPUT);
477 - c = rl_read_key ();
478 - RL_UNSETSTATE (RL_STATE_MOREINPUT);
481 + if (rl_point < p) /* Did we retreat at EOL? */
483 + while (_rl_insert_char (1, c))
485 + RL_SETSTATE (RL_STATE_MOREINPUT);
486 + c = rl_read_key ();
487 + RL_UNSETSTATE (RL_STATE_MOREINPUT);
493 diff -Naur bash-3.0.orig/patchlevel.h bash-3.0/patchlevel.h
494 --- bash-3.0.orig/patchlevel.h 2001-08-22 12:05:39.000000000 +0000
495 +++ bash-3.0/patchlevel.h 2005-01-08 05:40:53.584965496 +0000
497 regexp `^#define[ ]*PATCHLEVEL', since that's what support/mkversion.sh
498 looks for to find the patch level (for the sccs version string). */
500 -#define PATCHLEVEL 0
501 +#define PATCHLEVEL 16
503 #endif /* _PATCHLEVEL_H_ */
504 diff -Naur bash-3.0.orig/pcomplete.c bash-3.0/pcomplete.c
505 --- bash-3.0.orig/pcomplete.c 2004-01-08 15:36:17.000000000 +0000
506 +++ bash-3.0/pcomplete.c 2005-01-08 05:40:02.049800032 +0000
508 if (array_p (v) == 0)
509 v = convert_var_to_array (v);
510 v = assign_array_var_from_word_list (v, lwords);
512 + VUNSETATTR (v, att_invisible);
515 #endif /* ARRAY_VARS */
516 @@ -1022,6 +1024,8 @@
517 if (array_p (v) == 0)
518 v = convert_var_to_array (v);
520 + VUNSETATTR (v, att_invisible);
523 if (a == 0 || array_empty (a))
524 sl = (STRINGLIST *)NULL;
525 diff -Naur bash-3.0.orig/subst.c bash-3.0/subst.c
526 --- bash-3.0.orig/subst.c 2004-07-04 17:56:13.000000000 +0000
527 +++ bash-3.0/subst.c 2005-01-08 05:40:53.574967016 +0000
528 @@ -4691,6 +4691,26 @@
529 legal_identifier (name + 1)); /* ${#PS1} */
532 +#if defined (HANDLE_MULTIBYTE)
541 + memset (&mbs, 0, sizeof (mbs));
542 + while ((clen = mbrlen(s, MB_CUR_MAX, &mbs)) != 0 && (MB_INVALIDCH(clen) == 0))
552 /* Handle the parameter brace expansion that requires us to return the
553 length of a parameter. */
555 @@ -4746,14 +4766,14 @@
556 if (legal_number (name + 1, &arg_index)) /* ${#1} */
558 t = get_dollar_var_value (arg_index);
559 - number = STRLEN (t);
560 + number = MB_STRLEN (t);
563 #if defined (ARRAY_VARS)
564 - else if ((var = find_variable (name + 1)) && array_p (var))
565 + else if ((var = find_variable (name + 1)) && (invisible_p (var) == 0) && array_p (var))
567 t = array_reference (array_cell (var), 0);
568 - number = STRLEN (t);
569 + number = MB_STRLEN (t);
573 @@ -4766,7 +4786,7 @@
575 dispose_words (list);
577 - number = STRLEN (t);
578 + number = MB_STRLEN (t);
582 @@ -4871,7 +4891,7 @@
586 - len = strlen (value);
587 + len = MB_STRLEN (value);
590 len = number_of_args () + 1;
591 @@ -4879,8 +4899,9 @@
592 #if defined (ARRAY_VARS)
595 - /* For arrays, the first value deals with array indices. */
596 - len = array_max_index (a); /* arrays index from 0 to n - 1 */
597 + /* For arrays, the first value deals with array indices. Negative
598 + offsets count from one past the array's maximum index. */
599 + len = array_max_index (a) + (*e1p < 0); /* arrays index from 0 to n - 1 */
603 @@ -4891,7 +4912,7 @@
604 if (*e1p < 0) /* negative offsets count from end */
607 - if (*e1p >= len || *e1p < 0)
608 + if (*e1p > len || *e1p < 0)
611 #if defined (ARRAY_VARS)
612 @@ -4982,7 +5003,7 @@
616 - else if ((v = find_variable (varname)) && array_p (v))
617 + else if ((v = find_variable (varname)) && (invisible_p (v) == 0) && array_p (v))
619 vtype = VT_ARRAYMEMBER;
621 diff -Naur bash-3.0.orig/tests/array.right bash-3.0/tests/array.right
622 --- bash-3.0.orig/tests/array.right 2003-10-05 03:25:10.000000000 +0000
623 +++ bash-3.0/tests/array.right 2005-01-08 05:40:53.582965800 +0000
626 positive offset - expect five seven
628 -negative offset - expect five seven
630 +negative offset to unset element - expect seven
632 positive offset 2 - expect seven
634 negative offset 2 - expect seven
635 diff -Naur bash-3.0.orig/tests/array.tests bash-3.0/tests/array.tests
636 --- bash-3.0.orig/tests/array.tests 2003-10-05 03:25:00.000000000 +0000
637 +++ bash-3.0/tests/array.tests 2005-01-08 05:40:53.580966104 +0000
640 echo positive offset - expect five seven
642 -echo negative offset - expect five seven
643 +echo negative offset to unset element - expect seven
646 echo positive offset 2 - expect seven
647 diff -Naur bash-3.0.orig/tests/dbg-support.tests bash-3.0/tests/dbg-support.tests
648 --- bash-3.0.orig/tests/dbg-support.tests 2003-03-25 20:33:03.000000000 +0000
649 +++ bash-3.0/tests/dbg-support.tests 2005-01-08 05:40:02.065797600 +0000
651 trap 'print_debug_trap $LINENO' DEBUG
652 trap 'print_return_trap $LINENO' RETURN
654 -# Funcname is now an array. Vanilla Bash 2.05 doesn't have FUNCNAME array.
655 -echo "FUNCNAME" ${FUNCNAME[0]}
656 +# Funcname is now an array, but you still can't see it outside a function
657 +echo "FUNCNAME" ${FUNCNAME[0]:-main}
659 # We should trace into the below.
660 # Start easy with a simple function.
661 diff -Naur bash-3.0.orig/tests/errors.right bash-3.0/tests/errors.right
662 --- bash-3.0.orig/tests/errors.right 2004-05-28 02:26:03.000000000 +0000
663 +++ bash-3.0/tests/errors.right 2005-01-08 05:40:04.502427176 +0000
665 ./errors.tests: line 213: /bin/sh + 0: syntax error: operand expected (error token is "/bin/sh + 0")
666 ./errors.tests: line 216: trap: NOSIG: invalid signal specification
667 ./errors.tests: line 219: trap: -s: invalid option
668 -trap: usage: trap [-lp] [[arg] signal_spec ...]
669 +trap: usage: trap [-lp] [arg signal_spec ...]
670 ./errors.tests: line 225: return: can only `return' from a function or sourced script
671 ./errors.tests: line 229: break: 0: loop count out of range
672 ./errors.tests: line 233: continue: 0: loop count out of range
673 diff -Naur bash-3.0.orig/variables.c bash-3.0/variables.c
674 --- bash-3.0.orig/variables.c 2004-07-04 17:57:26.000000000 +0000
675 +++ bash-3.0/variables.c 2005-01-08 05:40:01.842831496 +0000
676 @@ -1419,11 +1419,11 @@
677 v = init_dynamic_array_var ("GROUPS", get_groupset, null_array_assign, att_noassign);
679 # if defined (DEBUGGER)
680 - v = init_dynamic_array_var ("BASH_ARGC", get_self, null_array_assign, (att_invisible|att_noassign));
681 - v = init_dynamic_array_var ("BASH_ARGV", get_self, null_array_assign, (att_invisible|att_noassign));
682 + v = init_dynamic_array_var ("BASH_ARGC", get_self, null_array_assign, att_noassign);
683 + v = init_dynamic_array_var ("BASH_ARGV", get_self, null_array_assign, att_noassign);
684 # endif /* DEBUGGER */
685 - v = init_dynamic_array_var ("BASH_SOURCE", get_self, null_array_assign, (att_invisible|att_noassign));
686 - v = init_dynamic_array_var ("BASH_LINENO", get_self, null_array_assign, (att_invisible|att_noassign));
687 + v = init_dynamic_array_var ("BASH_SOURCE", get_self, null_array_assign, att_noassign);
688 + v = init_dynamic_array_var ("BASH_LINENO", get_self, null_array_assign, att_noassign);
691 v = init_funcname_var ();
692 @@ -1599,7 +1599,10 @@
693 /* local foo; local foo; is a no-op. */
694 old_var = find_variable (name);
695 if (old_var && local_p (old_var) && old_var->context == variable_context)
698 + VUNSETATTR (old_var, att_invisible);
702 was_tmpvar = old_var && tempvar_p (old_var);