]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
commit bash-20100708 snapshot
authorChet Ramey <chet.ramey@case.edu>
Tue, 13 Dec 2011 03:02:22 +0000 (22:02 -0500)
committerChet Ramey <chet.ramey@case.edu>
Tue, 13 Dec 2011 03:02:22 +0000 (22:02 -0500)
16 files changed:
CWRU/CWRU.chlog
CWRU/CWRU.chlog~
bashline.c
bashline.c~
doc/bash.1
doc/bash.1~
doc/bashref.texi
doc/bashref.texi~
execute_cmd.c
lib/readline/keymaps.h
lib/sh/strftime.c
subst.c
subst.c~
tests/RUN-ONE-TEST
tests/lastpipe.tests
tests/printf3.sub

index 11095486e80b127a304bab78b8254fe15050043f..99bc6e9df6d56d5dcb9fa978af07e77791b04020 100644 (file)
@@ -10200,3 +10200,10 @@ jobs.[ch]
 execute_cmd.c
        - changes to lastpipe code to make `pipefail' option, $PIPESTATUS, and
          $? work correctly.  Uses append_process and job_exit_status
+
+                                  7/10
+                                  ----
+subst.c
+       - when performing pattern substitution word expansions, a `&' in the
+         replacement string is replaced by the text matched by the pattern.
+         The `&' can be quoted with a backslash to inhibit the expansion
index ce9009c151a9af2a9f94ca678407146108ad77fb..11095486e80b127a304bab78b8254fe15050043f 100644 (file)
@@ -10194,6 +10194,8 @@ jobs.[ch]
          takes info, creates a PROCESS from them, and adds it to the end of
          the passed job id's pipeline.  lastpipe code uses it to add a dummy
          process for the last command in the pipeline
+       - freeze_jobs_list: new utility function so rest of shell can freeze
+         the jobs list.  Used by the lastpipe code
 
 execute_cmd.c
        - changes to lastpipe code to make `pipefail' option, $PIPESTATUS, and
index 575a0e2570e3a40a2c661cb74ab61345e5c9352d..7fee50d2979391dc78cef20914fa61dbbcb9e6c3 100644 (file)
@@ -529,11 +529,8 @@ initialize_readline ()
   enable_hostname_completion (perform_hostname_completion);
 
   /* characters that need to be quoted when appearing in filenames. */
-#if 0
-  rl_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!:{";       /*}*/
-#else
   rl_filename_quote_characters = " \t\n\\\"'@<>=;|&()#$`?*[!:{~";      /*}*/
-#endif
+
   rl_filename_quoting_function = bash_quote_filename;
   rl_filename_dequoting_function = bash_dequote_filename;
   rl_char_is_quoted_p = char_is_quoted;
index eb86b3b7125475c27f9da061c212ebe4a47ad3e1..575a0e2570e3a40a2c661cb74ab61345e5c9352d 100644 (file)
@@ -1,6 +1,6 @@
 /* bashline.c -- Bash's interface to the readline library. */
 
-/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2010 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
index e65aec7737af2e99ce107d92fc4a9fec9eb41561..626aed701d00237d12a2b816bdbb3534216d7472 100644 (file)
@@ -10,7 +10,7 @@
 .\" bash_builtins, strip all but Built-Ins section
 .if \n(zZ=1 .ig zZ
 .if \n(zY=1 .ig zY
-.TH BASH 1 "2010 July 2" "GNU Bash-4.1"
+.TH BASH 1 "2010 July 2" "GNU Bash-4.2"
 .\"
 .\" There's some problem with having a `@'
 .\" in a tagged paragraph with the BSD man macros.
index 98faf69436b99fefc0ff95b07b8b740d264adf16..626aed701d00237d12a2b816bdbb3534216d7472 100644 (file)
@@ -10,7 +10,7 @@
 .\" bash_builtins, strip all but Built-Ins section
 .if \n(zZ=1 .ig zZ
 .if \n(zY=1 .ig zY
-.TH BASH 1 "2010 July 2" "GNU Bash-4.1"
+.TH BASH 1 "2010 July 2" "GNU Bash-4.2"
 .\"
 .\" There's some problem with having a `@'
 .\" in a tagged paragraph with the BSD man macros.
@@ -3868,8 +3868,10 @@ in multiple identically-named entries in the environment passed to the
 shell's children.
 Care should be taken in cases where this may cause a problem.
 .PP
-Functions may be recursive.  No limit is imposed on the number
-of recursive calls.
+Functions may be recursive.
+The \fBFUNCNEST\fP variable may be used to limit the depth of the
+function call stack and restrict the number of function invocations.
+By default, no limit is imposed on the number of recursive calls.
 .SH "ARITHMETIC EVALUATION"
 The shell allows arithmetic expressions to be evaluated, under
 certain circumstances (see the \fBlet\fP and \fBdeclare\fP builtin
index 1f3bacbee10a79d5bd8e09c00d8fdeda89eac0c3..f4faf880807ac1874142f77ee5d307ad0fa68f8d 100644 (file)
@@ -820,7 +820,7 @@ until it evaluates to zero.
 Each time @var{expr2} evaluates to a non-zero value, @var{commands} are
 executed and the arithmetic expression @var{expr3} is evaluated.       
 If any expression is omitted, it behaves as if it evaluates to 1.
-The return value is the exit status of the last command in @var{list}
+The return value is the exit status of the last command in @var{commands}
 that is executed, or false if any of the expressions is invalid.
 
 @end table
index d214d20ee8c6986c01d70b0ee0cf64a38b8911fa..1f3bacbee10a79d5bd8e09c00d8fdeda89eac0c3 100644 (file)
@@ -1328,8 +1328,10 @@ in multiple identically-named entries in the environment passed to the
 shell's children.
 Care should be taken in cases where this may cause a problem.
 
-Functions may be recursive.  No limit is placed on the number of
-recursive  calls.
+Functions may be recursive.
+The @code{FUNCNEST} variable may be used to limit the depth of the
+function call stack and restrict the number of function invocations.
+By default, no limit is placed on the number of recursive  calls.
 
 @node Shell Parameters
 @section Shell Parameters
index 8132566b099e4f7ade4be7afc84c54c60a26e14d..af556fa9175415255480230b15ccdbfaad27267f 100644 (file)
@@ -2219,10 +2219,6 @@ execute_pipeline (command, asynchronous, pipe_in, pipe_out, fds_to_close)
   if (prev >= 0)
     add_unwind_protect (close, prev);
 
-  /* XXX - might need to temporarily put shell process in pgrp of the pipeline,
-     so after we give the terminal to that process group in stop_pipeline, the
-     shell can still access it.  Would need to give it to
-     jobs[lastpipe_jid]->pgrp  */
   exec_result = execute_command_internal (cmd, asynchronous, prev, pipe_out, fds_to_close);
 
   if (lstdin > 0)
index 6c4611d3e1664d84769ce1a25633f4f9ebedc2cc..af8d5d997d4b7de21ebc4f3bc13c3ea0169a6f31 100644 (file)
@@ -52,11 +52,6 @@ typedef struct _keymap_entry {
 #define KEYMAP_SIZE 257
 #define ANYOTHERKEY KEYMAP_SIZE-1
 
-/* I wanted to make the above structure contain a union of:
-   union { rl_command_func_t *function; struct _keymap_entry *keymap; } value;
-   but this made it impossible for me to create a static array.
-   Maybe I need C lessons. */
-
 typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE];
 typedef KEYMAP_ENTRY *Keymap;
 
index 572baaee0dd46ec9f7bd740609bcb8ee724c5438..5335ead155632c84288cb72b5daeadba68baa2af 100644 (file)
@@ -114,6 +114,11 @@ extern int timezone, altzone;
 
 #undef min     /* just in case */
 
+/* format for %+ */
+#ifndef NATIONAL_FORMAT
+#define NATIONAL_FORMAT "%a %b %e %H:%M:%S %Z %Y"
+#endif
+
 /* min --- return minimum of two numbers */
 
 static inline int
diff --git a/subst.c b/subst.c
index e6cb89dd4e6260777a1779639732c2109574df00..d20b055e6f5682aeed2fb4e5be501b275dc58a80 100644 (file)
--- a/subst.c
+++ b/subst.c
@@ -288,6 +288,8 @@ static int get_var_and_type __P((char *, char *, int, SHELL_VAR **, char **));
 static char *mb_substring __P((char *, int, int));
 static char *parameter_brace_substring __P((char *, char *, char *, int));
 
+static int shouldexp_replacement __P((char *));
+
 static char *pos_params_pat_subst __P((char *, char *, char *, int));
 
 static char *parameter_brace_patsub __P((char *, char *, char *, int));
@@ -6327,21 +6329,40 @@ parameter_brace_substring (varname, value, substr, quoted)
 /*                                                             */
 /****************************************************************/
 
+static int
+shouldexp_replacement (s)
+     char *s;
+{
+  register char *p;
+
+  for (p = s; p && *p; p++)
+    {
+      if (*p == '\\')
+       p++;
+      else if (*p == '&')
+       return 1;
+    }
+  return 0;
+}
+
 char *
 pat_subst (string, pat, rep, mflags)
      char *string, *pat, *rep;
      int mflags;
 {
-  char *ret, *s, *e, *str;
-  int rsize, rptr, l, replen, mtype;
+  char *ret, *s, *e, *str, *rstr, *mstr;
+  int rsize, rptr, l, replen, mtype, rxpand, rslen, mlen;
 
   mtype = mflags & MATCH_TYPEMASK;
 
+  rxpand = (rep && *rep) ? shouldexp_replacement (rep) : 0;
+
   /* Special cases:
    *   1.  A null pattern with mtype == MATCH_BEG means to prefix STRING
    *       with REP and return the result.
    *   2.  A null pattern with mtype == MATCH_END means to append REP to
    *       STRING and return the result.
+   * These don't understand or process `&' in the replacement string.
    */
   if ((pat == 0 || *pat == 0) && (mtype == MATCH_BEG || mtype == MATCH_END))
     {
@@ -6371,7 +6392,25 @@ pat_subst (string, pat, rep, mflags)
       if (match_pattern (str, pat, mtype, &s, &e) == 0)
        break;
       l = s - str;
-      RESIZE_MALLOCED_BUFFER (ret, rptr, (l + replen), rsize, 64);
+
+      if (rxpand)
+        {
+          int x;
+          mlen = e - s;
+          mstr = xmalloc (mlen + 1);
+         for (x = 0; x < mlen; x++)
+           mstr[x] = s[x];
+          mstr[mlen] = '\0';
+          rstr = strcreplace (rep, '&', mstr, 0);
+          rslen = strlen (rstr);
+        }
+      else
+        {
+          rstr = rep;
+          rslen = replen;
+        }
+        
+      RESIZE_MALLOCED_BUFFER (ret, rptr, (l + rslen), rsize, 64);
 
       /* OK, now copy the leading unmatched portion of the string (from
         str to s) to ret starting at rptr (the current offset).  Then copy
@@ -6384,11 +6423,14 @@ pat_subst (string, pat, rep, mflags)
        }
       if (replen)
        {
-         strncpy (ret + rptr, rep, replen);
-         rptr += replen;
+         strncpy (ret + rptr, rstr, rslen);
+         rptr += rslen;
        }
       str = e;         /* e == end of match */
 
+      if (rstr != rep)
+       free (rstr);
+
       if (((mflags & MATCH_GLOBREP) == 0) || mtype != MATCH_ANY)
        break;
 
index 626ec80f86de4ef06a0caab70b22e768126baa62..b27c0310ea10905be28a84f87f4be4fb5d1d00dc 100644 (file)
--- a/subst.c~
+++ b/subst.c~
@@ -288,6 +288,8 @@ static int get_var_and_type __P((char *, char *, int, SHELL_VAR **, char **));
 static char *mb_substring __P((char *, int, int));
 static char *parameter_brace_substring __P((char *, char *, char *, int));
 
+static int shouldexp_replacement __P((char *));
+
 static char *pos_params_pat_subst __P((char *, char *, char *, int));
 
 static char *parameter_brace_patsub __P((char *, char *, char *, int));
@@ -3942,6 +3944,8 @@ remove_pattern (param, pattern, op)
          return ((xret == param) ? savestring (param) : xret);
        }
       oret = ret = remove_wpattern (wparam, n, wpattern, op);
+      /* Don't bother to convert wparam back to multibyte string if nothing
+        matched; just return copy of original string */
       if (ret == wparam)
         {
           free (wparam);
@@ -6325,16 +6329,34 @@ parameter_brace_substring (varname, value, substr, quoted)
 /*                                                             */
 /****************************************************************/
 
+static int
+shouldexp_replacement (s)
+     char *s;
+{
+  register char *p;
+
+  for (p = s; p && *p; p++)
+    {
+      if (*p == '\\')
+       p++;
+      else if (*p == '&')
+       return 1;
+    }
+  return 0;
+}
+
 char *
 pat_subst (string, pat, rep, mflags)
      char *string, *pat, *rep;
      int mflags;
 {
-  char *ret, *s, *e, *str;
-  int rsize, rptr, l, replen, mtype;
+  char *ret, *s, *e, *str, *rstr, *mstr;
+  int rsize, rptr, l, replen, mtype, rxpand, rslen, mlen;
 
   mtype = mflags & MATCH_TYPEMASK;
 
+  rxpand = (rep && *rep) ? shouldexp_replacement (rep) : 0;
+
   /* Special cases:
    *   1.  A null pattern with mtype == MATCH_BEG means to prefix STRING
    *       with REP and return the result.
@@ -6369,7 +6391,25 @@ pat_subst (string, pat, rep, mflags)
       if (match_pattern (str, pat, mtype, &s, &e) == 0)
        break;
       l = s - str;
-      RESIZE_MALLOCED_BUFFER (ret, rptr, (l + replen), rsize, 64);
+
+      if (rxpand)
+        {
+          int x;
+          mlen = e - s;
+          mstr = xmalloc (mlen + 1);
+         for (x = 0; x < mlen; x++)
+           mstr[x] = s[x];
+          mstr[mlen] = '\0';
+          rstr = strcreplace (rep, '&', mstr, 0);
+          rslen = strlen (rstr);
+        }
+      else
+        {
+          rstr = rep;
+          rslen = replen;
+        }
+        
+      RESIZE_MALLOCED_BUFFER (ret, rptr, (l + rslen), rsize, 64);
 
       /* OK, now copy the leading unmatched portion of the string (from
         str to s) to ret starting at rptr (the current offset).  Then copy
@@ -6382,11 +6422,14 @@ pat_subst (string, pat, rep, mflags)
        }
       if (replen)
        {
-         strncpy (ret + rptr, rep, replen);
-         rptr += replen;
+         strncpy (ret + rptr, rstr, rslen);
+         rptr += rslen;
        }
       str = e;         /* e == end of match */
 
+      if (rstr != rep)
+       free (rstr);
+
       if (((mflags & MATCH_GLOBREP) == 0) || mtype != MATCH_ANY)
        break;
 
index 72ec06a2c1fd8dde92acea5e8ac773e35f1d061b..3efcf32d68e9722024b6ca9d67f9e81b2aa5ac04 100755 (executable)
@@ -1,4 +1,4 @@
-BUILD_DIR=/usr/local/build/bash/bash-current
+BUILD_DIR=/usr/local/build/chet/bash/bash-current
 THIS_SH=$BUILD_DIR/bash
 PATH=$PATH:$BUILD_DIR
 
index 2b0990e3173df5122854d20f8cca967d8c3c3e42..c846316e53a75f4eda71b2c00af5313288bbcd27 100644 (file)
@@ -1,3 +1,18 @@
+if [ -x /usr/bin/true ]; then
+       bintrue=/usr/bin/true
+elif [ -x /bin/true ]; then
+       bintrue=/bin/true
+else
+       bintrue=true
+fi
+if [ -x /usr/bin/false ]; then
+       binfalse=/usr/bin/false
+elif [ -x /bin/false ]; then
+       binfalse=/bin/false
+else
+       binfalse=true
+fi
+
 shopt -s lastpipe
 
 unset foo bar
@@ -20,17 +35,17 @@ echo last = $last
 exit 142 | false
 echo $? -- ${PIPESTATUS[@]}
 
-true | false | /usr/bin/true
+true | false | $bintrue
 echo $? -- ${PIPESTATUS[@]}
 
-true | /usr/bin/true | false
+true | $bintrue | false
 echo $? -- ${PIPESTATUS[@]}
 
 set -o pipefail
-true | /usr/bin/true | false
+true | $bintrue | false
 echo $? -- ${PIPESTATUS[@]}
 
-true | /usr/bin/false | true
+true | $binfalse | true
 echo $? -- ${PIPESTATUS[@]}
 set +o pipefail
 
index 0de273af173fbcba14f51b0552683421f66d6fb8..85a2705c22b08785fe1ba68538412d7ad5a8d7f7 100644 (file)
@@ -44,10 +44,10 @@ printf "current time: %(%F %r)T\n" $SECS
 printf "epoch time: %(%F %r %z)T\n" 0
 printf "random time: %(%F %r %z)T\n"  $SECS
 
-printf "local time: %(%+)T\n" $SECS
+printf "local time: %(%a %b %e %H:%M:%S %Z %Y)T\n" $SECS
 
 # test fieldwidth, justification, precision
-printf "%-40.50(%+)T date-style time\n" $SECS
+printf "%-40.50(%a %b %e %H:%M:%S %Z %Y)T date-style time\n" $SECS
 
 # test fieldwidth, justification, precision, embedded parens
 printf "%-40.50(%x (foo) %X)T date-style time\n" $SECS