]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - bracecomp.c
fix for SIGINT in sourced script
[thirdparty/bash.git] / bracecomp.c
index 323b7945e15b201056a23e1213852db4f5914137..4fbca8583d14e11addabe399e5e8b39d413402a1 100644 (file)
@@ -4,25 +4,26 @@
 
 /* Original version by tromey@cns.caltech.edu,  Fri Feb  7 1992. */
 
-/* Copyright (C) 1993 Free Software Foundation, Inc.
+/* Copyright (C) 1993-2009 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
-   Bash is free software; you can redistribute it and/or modify it under
-   the terms of the GNU General Public License as published by the Free
-   Software Foundation; either version 2, or (at your option) any later
-   version.
+   Bash is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-   Bash is distributed in the hope that it will be useful, but WITHOUT ANY
-   WARRANTY; without even the implied warranty of MERCHANTABILITY or
-   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-   for more details.
+   Bash is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   You should have received a copy of the GNU General Public License along
-   with Bash; see the file COPYING.  If not, write to the Free Software
-   Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
+   You should have received a copy of the GNU General Public License
+   along with Bash.  If not, see <http://www.gnu.org/licenses/>.
+*/
 
 #include "config.h"
+
 #if defined (BRACE_EXPANSION) && defined (READLINE)
 
 #include <stdio.h>
 #endif
 
 #include "bashansi.h"
+#include "shmbutil.h"
 
 #include "shell.h"
 #include <readline/readline.h>
 
+static int _strcompare __P((char **, char **));
+
 /* Find greatest common prefix of two strings. */
 static int
 string_gcd (s1, s2)
@@ -71,8 +75,8 @@ really_munge_braces (array, real_start, real_end, gcd_zero)
 
   if (real_start == real_end)
     {
-      x = array[real_start] ? sh_backslash_quote (array[real_start] + gcd_zero)
-                           : sh_backslash_quote (array[0]);
+      x = array[real_start] ? sh_backslash_quote (array[real_start] + gcd_zero, 0, 0)
+                           : sh_backslash_quote (array[0], 0, 0);
       return x;
     }
 
@@ -111,7 +115,7 @@ really_munge_braces (array, real_start, real_end, gcd_zero)
       if (start == end)
        {
          x = savestring (array[start] + gcd_zero);
-         subterm = sh_backslash_quote (x);
+         subterm = sh_backslash_quote (x, 0, 0);
          free (x);
        }
       else
@@ -122,7 +126,7 @@ really_munge_braces (array, real_start, real_end, gcd_zero)
          x = (char *)xmalloc (tlen + 1);
          strncpy (x, array[start] + gcd_zero, tlen);
          x[tlen] = '\0';
-         subterm = sh_backslash_quote (x);
+         subterm = sh_backslash_quote (x, 0, 0);
          free (x);
          result_size += strlen (subterm) + 1;
          result = (char *)xrealloc (result, result_size);
@@ -145,6 +149,19 @@ really_munge_braces (array, real_start, real_end, gcd_zero)
   return (result);
 }
 
+static int
+_strcompare (s1, s2)
+     char **s1, **s2;
+{
+  int result;
+
+  result = **s1 - **s2;
+  if (result == 0)
+    result = strcmp (*s1, *s2);
+
+  return result;
+}
+
 static int
 hack_braces_completion (names)
      char **names;
@@ -152,7 +169,11 @@ hack_braces_completion (names)
   register int i;
   char *temp;
 
-  temp = really_munge_braces (names, 1, array_len (names), 0);
+  i = strvec_len (names);
+  if (MB_CUR_MAX > 1 && i > 2)
+    qsort (names+1, i-1, sizeof (char *), (QSFUNC *)_strcompare);
+      
+  temp = really_munge_braces (names, 1, i, 0);
 
   for (i = 0; names[i]; ++i)
     {