more toolchain + stage 1 updates
[hdw-linux/hdw-linux.git] / packages / base / bash / official_fixes.patch
1 --- bash-3.1.orig/arrayfunc.c   2005-07-04 17:25:58.000000000 -0700
2 +++ bash-3.1/arrayfunc.c        2006-04-19 15:59:29.000000000 -0700
3 @@ -592,11 +592,7 @@
4    exp = (char *)xmalloc (len);
5    strncpy (exp, s, len - 1);
6    exp[len - 1] = '\0';
7 -#if 0
8 -  t = expand_string_to_string (exp, 0);
9 -#else 
10 -  t = expand_string_to_string (exp, Q_DOUBLE_QUOTES);
11 -#endif
12 +  t = expand_arith_string (exp, 0);
13    this_command_name = (char *)NULL;
14    val = evalexp (t, &expok);
15    free (t);
16 --- bash-3.1.orig/doc/bash.1    2005-10-12 08:40:52.000000000 -0700
17 +++ bash-3.1/doc/bash.1 2006-04-19 15:58:34.000000000 -0700
18 @@ -6,12 +6,12 @@
19  .\"    Case Western Reserve University
20  .\"    chet@po.cwru.edu
21  .\"
22 -.\"    Last Change: Sat Aug 27 13:28:44 EDT 2005
23 +.\"    Last Change: Wed Dec 28 19:58:45 EST 2005
24  .\"
25  .\" bash_builtins, strip all but Built-Ins section
26  .if \n(zZ=1 .ig zZ
27  .if \n(zY=1 .ig zY
28 -.TH BASH 1 "2005 Aug 27" "GNU Bash-3.1-beta1"
29 +.TH BASH 1 "2005 Dec 28" "GNU Bash-3.1"
30  .\"
31  .\" There's some problem with having a `@'
32  .\" in a tagged paragraph with the BSD man macros.
33 @@ -677,8 +677,8 @@
34  .B nocasematch
35  is enabled, the match is performed without regard to the case
36  of alphabetic characters.
37 -The return value is 0 if the string matches or does not match
38 -the pattern, respectively, and 1 otherwise.
39 +The return value is 0 if the string matches (\fB==\fP) or does not match
40 +(\fB!=\fP) the pattern, and 1 otherwise.
41  Any part of the pattern may be quoted to force it to be matched as a
42  string.
43  .if t .sp 0.5
44 @@ -807,6 +807,12 @@
45  as for pathname expansion (see
46  .B Pathname Expansion
47  below).
48 +The \fIword\fP is expanded using tilde
49 +expansion, parameter and variable expansion, arithmetic substituion,
50 +command substitution, process substitution and quote removal.
51 +Each \fIpattern\fP examined is expanded using tilde
52 +expansion, parameter and variable expansion, arithmetic substituion,
53 +command substitution, and process substitution.
54  If the shell option
55  .B nocasematch
56  is enabled, the match is performed without regard to the case
57 @@ -8484,7 +8490,7 @@
58  returns true if any of the arguments are found, false if
59  none are found.
60  .TP
61 -\fBulimit\fP [\fB\-SHacdflmnpstuv\fP [\fIlimit\fP]]
62 +\fBulimit\fP [\fB\-SHacdfilmnpqstuvx\fP [\fIlimit\fP]]
63  Provides control over the resources available to the shell and to
64  processes started by it, on systems that allow such control.
65  The \fB\-H\fP and \fB\-S\fP options specify that the hard or soft limit is
66 @@ -8523,6 +8529,9 @@
67  .B \-f
68  The maximum size of files created by the shell
69  .TP
70 +.B \-i
71 +The maximum number of pending signals
72 +.TP
73  .B \-l
74  The maximum size that may be locked into memory
75  .TP
76 @@ -8536,6 +8545,9 @@
77  .B \-p
78  The pipe size in 512-byte blocks (this may not be set)
79  .TP
80 +.B \-q
81 +The maximum number of bytes in POSIX message queues
82 +.TP
83  .B \-s
84  The maximum stack size
85  .TP
86 @@ -8547,6 +8559,9 @@
87  .TP
88  .B \-v
89  The maximum amount of virtual memory available to the shell
90 +.TP
91 +.B \-x
92 +The maximum number of file locks
93  .PD
94  .PP
95  If
96 --- bash-3.1.orig/doc/bashref.texi      2005-10-03 12:07:21.000000000 -0700
97 +++ bash-3.1/doc/bashref.texi   2006-04-19 15:58:34.000000000 -0700
98 @@ -961,8 +961,8 @@
99  (see the description of @code{shopt} in @ref{Bash Builtins})
100  is enabled, the match is performed without regard to the case
101  of alphabetic characters.
102 -The return value is 0 if the string matches or does not match
103 -the pattern, respectively, and 1 otherwise.
104 +The return value is 0 if the string matches (@samp{==}) or does not
105 +match (@samp{!=})the pattern, and 1 otherwise.
106  Any part of the pattern may be quoted to force it to be matched as a
107  string.
108  
109 @@ -2598,7 +2598,7 @@
110  Builtin commands are necessary to implement functionality impossible
111  or inconvenient to obtain with separate utilities.
112  
113 -This section briefly the builtins which Bash inherits from
114 +This section briefly describes the builtins which Bash inherits from
115  the Bourne Shell, as well as the builtin commands which are unique
116  to or have been extended in Bash.
117  
118 @@ -3833,7 +3833,7 @@
119  @item ulimit
120  @btindex ulimit
121  @example
122 -ulimit [-acdflmnpstuvSH] [@var{limit}]
123 +ulimit [-acdfilmnpqstuvxSH] [@var{limit}]
124  @end example
125  @code{ulimit} provides control over the resources available to processes
126  started by the shell, on systems that allow such control.  If an
127 @@ -3857,6 +3857,9 @@
128  @item -f
129  The maximum size of files created by the shell.
130  
131 +@item -i
132 +The maximum number of pending signals.
133 +
134  @item -l
135  The maximum size that may be locked into memory.
136  
137 @@ -3869,6 +3872,9 @@
138  @item -p
139  The pipe buffer size.
140  
141 +@item -q
142 +The maximum number of bytes in POSIX message queues.
143 +
144  @item -s
145  The maximum stack size.
146  
147 @@ -3881,6 +3887,9 @@
148  @item -v
149  The maximum amount of virtual memory available to the process.
150  
151 +@item -x
152 +The maximum number of file locks.
153 +
154  @end table
155  
156  If @var{limit} is given, it is the new value of the specified resource;
157 @@ -4089,8 +4098,8 @@
158  Print shell input lines as they are read.
159  
160  @item -x
161 -Print a trace of simple commands, \fBfor\fP commands, \fBcase\fP
162 -commands, \fBselect\fP commands, and arithmetic \fBfor\fP commands
163 +Print a trace of simple commands, @code{for} commands, @code{case}
164 +commands, @code{select} commands, and arithmetic @code{for} commands
165  and their arguments or associated word lists after they are
166  expanded and before they are executed.  The value of the @env{PS4}
167  variable is expanded and the resultant value is printed before
168 --- bash-3.1.orig/doc/version.texi      2005-09-20 11:52:56.000000000 -0700
169 +++ bash-3.1/doc/version.texi   2006-04-19 15:58:34.000000000 -0700
170 @@ -2,9 +2,9 @@
171  Copyright (C) 1988-2005 Free Software Foundation, Inc.
172  @end ignore
173  
174 -@set LASTCHANGE Mon Sep  5 11:47:04 EDT 2005
175 +@set LASTCHANGE Fri Dec 30 10:50:51 EST 2005
176  
177 -@set EDITION 3.1-beta1
178 -@set VERSION 3.1-beta1
179 -@set UPDATED 5 September 2005
180 -@set UPDATED-MONTH September 2005
181 +@set EDITION 3.1
182 +@set VERSION 3.1
183 +@set UPDATED 30 December 2005
184 +@set UPDATED-MONTH December 2005
185 --- bash-3.1.orig/jobs.c        2005-11-11 20:13:27.000000000 -0800
186 +++ bash-3.1/jobs.c     2006-04-19 15:58:34.000000000 -0700
187 @@ -619,8 +619,11 @@
188            * once in the parent and once in each child.  This is where
189            * the parent gives it away.
190            *
191 +          * Don't give the terminal away if this shell is an asynchronous
192 +          * subshell.
193 +          *
194            */
195 -         if (job_control && newjob->pgrp)
196 +         if (job_control && newjob->pgrp && (subshell_environment&SUBSHELL_ASYNC) == 0)
197             give_terminal_to (newjob->pgrp, 0);
198         }
199      }
200 @@ -844,9 +847,10 @@
201  realloc_jobs_list ()
202  {
203    sigset_t set, oset;
204 -  int nsize, i, j;
205 +  int nsize, i, j, ncur, nprev;
206    JOB **nlist;
207  
208 +  ncur = nprev = NO_JOB;
209    nsize = ((js.j_njobs + JOB_SLOTS - 1) / JOB_SLOTS);
210    nsize *= JOB_SLOTS;
211    i = js.j_njobs % JOB_SLOTS;
212 @@ -854,17 +858,51 @@
213      nsize += JOB_SLOTS;
214  
215    BLOCK_CHILD (set, oset);
216 -  nlist = (JOB **) xmalloc (nsize * sizeof (JOB *));
217 +  nlist = (js.j_jobslots == nsize) ? jobs : (JOB **) xmalloc (nsize * sizeof (JOB *));
218 +
219    for (i = j = 0; i < js.j_jobslots; i++)
220      if (jobs[i])
221 -      nlist[j++] = jobs[i];
222 +      {
223 +       if (i == js.j_current)
224 +         ncur = j;
225 +       if (i == js.j_previous)
226 +         nprev = j;
227 +       nlist[j++] = jobs[i];
228 +      }
229 +
230 +#if defined (DEBUG)
231 +  itrace ("realloc_jobs_list: resize jobs list from %d to %d", js.j_jobslots, nsize);
232 +  itrace ("realloc_jobs_list: j_lastj changed from %d to %d", js.j_lastj, (j > 0) ? j - 1 : 0);
233 +  itrace ("realloc_jobs_list: j_njobs changed from %d to %d", js.j_njobs, (j > 0) ? j - 1 : 0);
234 +#endif
235  
236    js.j_firstj = 0;
237 -  js.j_lastj = (j > 0) ? j - 1: 0;
238 +  js.j_lastj = (j > 0) ? j - 1 : 0;
239 +  js.j_njobs = j;
240    js.j_jobslots = nsize;
241  
242 -  free (jobs);
243 -  jobs = nlist;
244 +  /* Zero out remaining slots in new jobs list */
245 +  for ( ; j < nsize; j++)
246 +    nlist[j] = (JOB *)NULL;
247 +
248 +  if (jobs != nlist)
249 +    {
250 +      free (jobs);
251 +      jobs = nlist;
252 +    }
253 +
254 +  if (ncur != NO_JOB)
255 +    js.j_current = ncur;
256 +  if (nprev != NO_JOB)
257 +    js.j_previous = nprev;
258 +
259 +  /* Need to reset these */
260 +  if (js.j_current == NO_JOB || js.j_previous == NO_JOB || js.j_current > js.j_lastj || js.j_previous > js.j_lastj)
261 +    reset_current ();
262 +
263 +#ifdef DEBUG
264 +  itrace ("realloc_jobs_list: reset js.j_current (%d) and js.j_previous (%d)", js.j_current, js.j_previous);
265 +#endif
266  
267    UNBLOCK_CHILD (oset);
268  }
269 @@ -1655,7 +1693,7 @@
270              In this case, we don't want to give the terminal to the
271              shell's process group (we could be in the middle of a
272              pipeline, for example). */
273 -         if (async_p == 0 && pipeline_pgrp != shell_pgrp)
274 +         if (async_p == 0 && pipeline_pgrp != shell_pgrp && ((subshell_environment&SUBSHELL_ASYNC) == 0))
275             give_terminal_to (pipeline_pgrp, 0);
276  
277  #if defined (PGRP_PIPE)
278 @@ -2198,7 +2236,11 @@
279    /* This is possibly a race condition -- should it go in stop_pipeline? */
280    wait_sigint_received = 0;
281    if (job_control == 0)
282 -    old_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler);
283 +    {
284 +      old_sigint_handler = set_signal_handler (SIGINT, wait_sigint_handler);
285 +      if (old_sigint_handler == SIG_IGN)
286 +       set_signal_handler (SIGINT, old_sigint_handler);
287 +    }
288  
289    termination_state = last_command_exit_value;
290  
291 --- bash-3.1.orig/lib/glob/glob.c       2005-03-24 09:42:27.000000000 -0800
292 +++ bash-3.1/lib/glob/glob.c    2006-04-19 15:58:34.000000000 -0700
293 @@ -360,6 +360,7 @@
294    count = lose = skip = 0;
295  
296    firstmalloc = 0;
297 +  nalloca = 0;
298  
299    /* If PAT is empty, skip the loop, but return one (empty) filename. */
300    if (pat == 0 || *pat == '\0')
301 @@ -546,6 +547,8 @@
302                 firstmalloc = 0;
303               tmplink = lastlink;
304             }
305 +         else
306 +           tmplink = 0;
307           free (lastlink->name);
308           lastlink = lastlink->next;
309           FREE (tmplink);
310 --- bash-3.1.orig/lib/glob/sm_loop.c    2005-10-16 18:21:04.000000000 -0700
311 +++ bash-3.1/lib/glob/sm_loop.c 2006-04-19 15:58:34.000000000 -0700
312 @@ -638,12 +638,13 @@
313    CHAR *psub;                  /* pointer to sub-pattern */
314    CHAR *pnext;                 /* pointer to next sub-pattern */
315    CHAR *srest;                 /* pointer to rest of string */
316 -  int m1, m2;
317 +  int m1, m2, xflags;          /* xflags = flags passed to recursive matches */
318  
319  #if DEBUG_MATCHING
320  fprintf(stderr, "extmatch: xc = %c\n", xc);
321  fprintf(stderr, "extmatch: s = %s; se = %s\n", s, se);
322  fprintf(stderr, "extmatch: p = %s; pe = %s\n", p, pe);
323 +fprintf(stderr, "extmatch: flags = %d\n", flags);
324  #endif
325  
326    prest = PATSCAN (p + (*p == L('(')), pe, 0); /* ) */
327 @@ -677,8 +678,12 @@
328                  string matches the rest of the pattern.  Also handle
329                  multiple matches of the pattern. */
330               if (m1)
331 -               m2 = (GMATCH (srest, se, prest, pe, flags) == 0) ||
332 -                     (s != srest && GMATCH (srest, se, p - 1, pe, flags) == 0);
333 +               {
334 +                 /* if srest > s, we are not at start of string */
335 +                 xflags = (srest > s) ? (flags & ~FNM_PERIOD) : flags;
336 +                 m2 = (GMATCH (srest, se, prest, pe, xflags) == 0) ||
337 +                       (s != srest && GMATCH (srest, se, p - 1, pe, xflags) == 0);
338 +               }
339               if (m1 && m2)
340                 return (0);
341             }
342 @@ -704,8 +709,10 @@
343           srest = (prest == pe) ? se : s;
344           for ( ; srest <= se; srest++)
345             {
346 +             /* if srest > s, we are not at start of string */
347 +             xflags = (srest > s) ? (flags & ~FNM_PERIOD) : flags;
348               if (GMATCH (s, srest, psub, pnext - 1, flags) == 0 &&
349 -                 GMATCH (srest, se, prest, pe, flags) == 0)
350 +                 GMATCH (srest, se, prest, pe, xflags) == 0)
351                 return (0);
352             }
353           if (pnext == prest)
354 @@ -726,7 +733,9 @@
355               if (pnext == prest)
356                 break;
357             }
358 -         if (m1 == 0 && GMATCH (srest, se, prest, pe, flags) == 0)
359 +         /* if srest > s, we are not at start of string */
360 +         xflags = (srest > s) ? (flags & ~FNM_PERIOD) : flags;
361 +         if (m1 == 0 && GMATCH (srest, se, prest, pe, xflags) == 0)
362             return (0);
363         }
364        return (FNM_NOMATCH);
365 --- bash-3.1.orig/lib/readline/display.c        2005-11-30 11:05:02.000000000 -0800
366 +++ bash-3.1/lib/readline/display.c     2006-04-19 15:58:34.000000000 -0700
367 @@ -1983,11 +1983,15 @@
368       int pchar;
369  {
370    int len;
371 -  char *pmt;
372 +  char *pmt, *p;
373  
374    rl_save_prompt ();
375  
376 -  if (saved_local_prompt == 0)
377 +  /* We've saved the prompt, and can do anything with the various prompt
378 +     strings we need before they're restored.  We want the unexpanded
379 +     portion of the prompt string after any final newline. */
380 +  p = rl_prompt ? strrchr (rl_prompt, '\n') : 0;
381 +  if (p == 0)
382      {
383        len = (rl_prompt && *rl_prompt) ? strlen (rl_prompt) : 0;
384        pmt = (char *)xmalloc (len + 2);
385 @@ -1998,19 +2002,17 @@
386      }
387    else
388      {
389 -      len = *saved_local_prompt ? strlen (saved_local_prompt) : 0;
390 +      p++;
391 +      len = strlen (p);
392        pmt = (char *)xmalloc (len + 2);
393        if (len)
394 -       strcpy (pmt, saved_local_prompt);
395 +       strcpy (pmt, p);
396        pmt[len] = pchar;
397        pmt[len+1] = '\0';
398 -      local_prompt = savestring (pmt);
399 -      prompt_last_invisible = saved_last_invisible;
400 -      prompt_visible_length = saved_visible_length + 1;
401 -    }
402 +    }  
403  
404 +  /* will be overwritten by expand_prompt, called from rl_message */
405    prompt_physical_chars = saved_physical_chars + 1;
406 -
407    return pmt;
408  }
409  
410 --- bash-3.1.orig/lib/readline/readline.c       2005-07-04 19:29:35.000000000 -0700
411 +++ bash-3.1/lib/readline/readline.c    2006-04-19 15:58:34.000000000 -0700
412 @@ -282,6 +282,7 @@
413  {
414    FREE (rl_prompt);
415    rl_prompt = prompt ? savestring (prompt) : (char *)NULL;
416 +  rl_display_prompt = rl_prompt ? rl_prompt : "";
417  
418    rl_visible_prompt_length = rl_expand_prompt (rl_prompt);
419    return 0;
420 --- bash-3.1.orig/lib/readline/terminal.c       2005-11-12 17:46:54.000000000 -0800
421 +++ bash-3.1/lib/readline/terminal.c    2006-04-19 15:58:34.000000000 -0700
422 @@ -122,7 +122,7 @@
423  static char *_rl_visible_bell;
424  
425  /* Non-zero means the terminal can auto-wrap lines. */
426 -int _rl_term_autowrap;
427 +int _rl_term_autowrap = -1;
428  
429  /* Non-zero means that this terminal has a meta key. */
430  static int term_has_meta;
431 @@ -274,6 +274,9 @@
432  _rl_set_screen_size (rows, cols)
433       int rows, cols;
434  {
435 +  if (_rl_term_autowrap == -1)
436 +    _rl_init_terminal_io (rl_terminal_name);
437 +
438    if (rows > 0)
439      _rl_screenheight = rows;
440    if (cols > 0)
441 --- bash-3.1.orig/parse.y       2005-11-11 20:14:18.000000000 -0800
442 +++ bash-3.1/parse.y    2006-04-19 15:58:34.000000000 -0700
443 @@ -2716,6 +2716,7 @@
444  #define P_ALLOWESC     0x02
445  #define P_DQUOTE       0x04
446  #define P_COMMAND      0x08    /* parsing a command, so look for comments */
447 +#define P_BACKQUOTE    0x10    /* parsing a backquoted command substitution */
448  
449  static char matched_pair_error;
450  static char *
451 @@ -2725,12 +2726,12 @@
452       int *lenp, flags;
453  {
454    int count, ch, was_dollar, in_comment, check_comment;
455 -  int pass_next_character, nestlen, ttranslen, start_lineno;
456 +  int pass_next_character, backq_backslash, nestlen, ttranslen, start_lineno;
457    char *ret, *nestret, *ttrans;
458    int retind, retsize, rflags;
459  
460    count = 1;
461 -  pass_next_character = was_dollar = in_comment = 0;
462 +  pass_next_character = backq_backslash = was_dollar = in_comment = 0;
463    check_comment = (flags & P_COMMAND) && qc != '\'' && qc != '"' && (flags & P_DQUOTE) == 0;
464  
465    /* RFLAGS is the set of flags we want to pass to recursive calls. */
466 @@ -2742,11 +2743,8 @@
467    start_lineno = line_number;
468    while (count)
469      {
470 -#if 0
471 -      ch = shell_getc ((qc != '\'' || (flags & P_ALLOWESC)) && pass_next_character == 0);
472 -#else
473 -      ch = shell_getc (qc != '\'' && pass_next_character == 0);
474 -#endif
475 +      ch = shell_getc (qc != '\'' && pass_next_character == 0 && backq_backslash == 0);
476 +
477        if (ch == EOF)
478         {
479           free (ret);
480 @@ -2771,9 +2769,16 @@
481           continue;
482         }
483        /* Not exactly right yet */
484 -      else if (check_comment && in_comment == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || whitespace (ret[retind -1])))
485 +      else if MBTEST(check_comment && in_comment == 0 && ch == '#' && (retind == 0 || ret[retind-1] == '\n' || whitespace (ret[retind - 1])))
486         in_comment = 1;
487  
488 +      /* last char was backslash inside backquoted command substitution */
489 +      if (backq_backslash)
490 +       {
491 +         backq_backslash = 0;
492 +         /* Placeholder for adding special characters */
493 +       }
494 +
495        if (pass_next_character)         /* last char was backslash */
496         {
497           pass_next_character = 0;
498 @@ -2814,6 +2819,8 @@
499         {
500           if MBTEST((flags & P_ALLOWESC) && ch == '\\')
501             pass_next_character++;
502 +         else if MBTEST((flags & P_BACKQUOTE) && ch == '\\')
503 +           backq_backslash++;
504           continue;
505         }
506  
507 @@ -2898,7 +2905,11 @@
508         }
509        else if MBTEST(qc == '`' && (ch == '"' || ch == '\'') && in_comment == 0)
510         {
511 -         nestret = parse_matched_pair (0, ch, ch, &nestlen, rflags);
512 +         /* Add P_BACKQUOTE so backslash quotes the next character and
513 +            shell_getc does the right thing with \<newline>.  We do this for
514 +            a measure  of backwards compatibility -- it's not strictly the
515 +            right POSIX thing. */
516 +         nestret = parse_matched_pair (0, ch, ch, &nestlen, rflags|P_BACKQUOTE);
517           goto add_nestret;
518         }
519        else if MBTEST(was_dollar && (ch == '(' || ch == '{' || ch == '['))      /* ) } ] */
520 @@ -2907,7 +2918,7 @@
521           if (open == ch)       /* undo previous increment */
522             count--;
523           if (ch == '(')                /* ) */
524 -           nestret = parse_matched_pair (0, '(', ')', &nestlen, rflags);
525 +           nestret = parse_matched_pair (0, '(', ')', &nestlen, rflags & ~P_DQUOTE);
526           else if (ch == '{')           /* } */
527             nestret = parse_matched_pair (0, '{', '}', &nestlen, P_FIRSTCLOSE|rflags);
528           else if (ch == '[')           /* ] */
529 @@ -3578,7 +3589,7 @@
530               FREE (ttok);
531               all_digit_token = 0;
532               compound_assignment = 1;
533 -#if 0
534 +#if 1
535               goto next_character;
536  #else
537               goto got_token;           /* ksh93 seems to do this */
538 @@ -3695,7 +3706,9 @@
539        struct builtin *b;
540        b = builtin_address_internal (token, 0);
541        if (b && (b->flags & ASSIGNMENT_BUILTIN))
542 -        parser_state |= PST_ASSIGNOK;
543 +       parser_state |= PST_ASSIGNOK;
544 +      else if (STREQ (token, "eval") || STREQ (token, "let"))
545 +       parser_state |= PST_ASSIGNOK;
546      }
547  
548    yylval.word = the_word;
549 @@ -4686,18 +4699,21 @@
550       int *retlenp;
551  {
552    WORD_LIST *wl, *rl;
553 -  int tok, orig_line_number, orig_token_size;
554 +  int tok, orig_line_number, orig_token_size, orig_last_token, assignok;
555    char *saved_token, *ret;
556  
557    saved_token = token;
558    orig_token_size = token_buffer_size;
559    orig_line_number = line_number;
560 +  orig_last_token = last_read_token;
561  
562    last_read_token = WORD;      /* WORD to allow reserved words here */
563  
564    token = (char *)NULL;
565    token_buffer_size = 0;
566  
567 +  assignok = parser_state&PST_ASSIGNOK;                /* XXX */
568 +
569    wl = (WORD_LIST *)NULL;      /* ( */
570    parser_state |= PST_COMPASSIGN;
571  
572 @@ -4740,7 +4756,7 @@
573         jump_to_top_level (DISCARD);
574      }
575  
576 -  last_read_token = WORD;
577 +  last_read_token = orig_last_token;           /* XXX - was WORD? */
578    if (wl)
579      {
580        rl = REVERSE_LIST (wl, WORD_LIST *);
581 @@ -4752,6 +4768,10 @@
582  
583    if (retlenp)
584      *retlenp = (ret && *ret) ? strlen (ret) : 0;
585 +
586 +  if (assignok)
587 +    parser_state |= PST_ASSIGNOK;
588 +
589    return ret;
590  }
591  
592 --- bash-3.1.orig/patchlevel.h  2005-07-20 10:58:20.000000000 -0700
593 +++ bash-3.1/patchlevel.h       2006-04-19 15:59:29.000000000 -0700
594 @@ -25,6 +25,6 @@
595     regexp `^#define[   ]*PATCHLEVEL', since that's what support/mkversion.sh
596     looks for to find the patch level (for the sccs version string). */
597  
598 -#define PATCHLEVEL 0
599 +#define PATCHLEVEL 17
600  
601  #endif /* _PATCHLEVEL_H_ */
602 --- bash-3.1.orig/subst.c       2005-10-24 06:51:13.000000000 -0700
603 +++ bash-3.1/subst.c    2006-04-19 15:59:29.000000000 -0700
604 @@ -2187,7 +2187,7 @@
605    if (mklocal && variable_context)
606      {
607        v = find_variable (name);
608 -      if (v == 0 || array_p (v) == 0)
609 +      if (v == 0 || array_p (v) == 0 || v->context != variable_context)
610          v = make_local_array_variable (name);
611        v = assign_array_var_from_string (v, value, flags);
612      }
613 @@ -2575,6 +2575,13 @@
614    return (expand_string_to_string_internal (string, quoted, expand_string_assignment));
615  }
616  
617 +char *
618 +expand_arith_string (string, quoted)
619 +     char *string;
620 +{
621 +  return (expand_string_if_necessary (string, quoted, expand_string));
622 +}
623 +
624  #if defined (COND_COMMAND)
625  /* Just remove backslashes in STRING.  Returns a new string. */
626  char *
627 @@ -5248,7 +5255,7 @@
628    else
629      t = (char *)0;
630  
631 -  temp1 = expand_string_if_necessary (substr, Q_DOUBLE_QUOTES, expand_string);
632 +  temp1 = expand_arith_string (substr, Q_DOUBLE_QUOTES);
633    *e1p = evalexp (temp1, &expok);
634    free (temp1);
635    if (expok == 0)
636 @@ -5293,7 +5300,7 @@
637      {
638        t++;
639        temp2 = savestring (t);
640 -      temp1 = expand_string_if_necessary (temp2, Q_DOUBLE_QUOTES, expand_string);
641 +      temp1 = expand_arith_string (temp2, Q_DOUBLE_QUOTES);
642        free (temp2);
643        t[-1] = ':';
644        *e2p = evalexp (temp1, &expok);
645 @@ -6435,7 +6442,7 @@
646           temp2[t_index] = '\0';
647  
648           /* Expand variables found inside the expression. */
649 -         temp1 = expand_string_if_necessary (temp2, Q_DOUBLE_QUOTES, expand_string);
650 +         temp1 = expand_arith_string (temp2, Q_DOUBLE_QUOTES);
651           free (temp2);
652  
653  arithsub:
654 @@ -6477,7 +6484,7 @@
655        zindex = t_index;
656  
657         /* Do initial variable expansion. */
658 -      temp1 = expand_string_if_necessary (temp, Q_DOUBLE_QUOTES, expand_string);
659 +      temp1 = expand_arith_string (temp, Q_DOUBLE_QUOTES);
660  
661        goto arithsub;
662  
663 @@ -6795,6 +6802,12 @@
664           if (temp && *temp && t_index > 0)
665             {
666               temp1 = bash_tilde_expand (temp, tflag);
667 +             if  (temp1 && *temp1 == '~' && STREQ (temp, temp1))
668 +               {
669 +                 FREE (temp);
670 +                 FREE (temp1);
671 +                 goto add_character;           /* tilde expansion failed */
672 +               }
673               free (temp);
674               temp = temp1;
675               sindex += t_index;
676 --- bash-3.1.orig/subst.h       2004-11-07 12:12:28.000000000 -0800
677 +++ bash-3.1/subst.h    2006-04-19 15:59:29.000000000 -0700
678 @@ -151,6 +151,9 @@
679  extern char *expand_string_unsplit_to_string __P((char *, int));
680  extern char *expand_assignment_string_to_string __P((char *, int));
681  
682 +/* Expand an arithmetic expression string */
683 +extern char *expand_arith_string __P((char *, int));
684 +
685  /* De-quoted quoted characters in STRING. */
686  extern char *dequote_string __P((char *));
687  
688 --- bash-3.1.orig/variables.c   2005-11-12 18:22:37.000000000 -0800
689 +++ bash-3.1/variables.c        2006-04-19 15:58:34.000000000 -0700
690 @@ -860,9 +860,11 @@
691  {
692    char val[INT_STRLEN_BOUND(int) + 1], *v;
693  
694 +#if defined (READLINE)
695    /* If we are currently assigning to LINES or COLUMNS, don't do anything. */
696    if (winsize_assignment)
697      return;
698 +#endif
699  
700    v = inttostr (lines, val, sizeof (val));
701    bind_variable ("LINES", v, 0);