Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-1-5]: src/bin/ksh Pull up revision 1.7 (requested by sjg):



details:   https://anonhg.NetBSD.org/src/rev/b6e860db15f1
branches:  netbsd-1-5
changeset: 492656:b6e860db15f1
user:      he <he%NetBSD.org@localhost>
date:      Wed Feb 06 13:55:57 2002 +0000

description:
Pull up revision 1.7 (requested by sjg):
  Fix some aspects of globbing, particularly in emacs mode.

diffstat:

 bin/ksh/edit.c |  60 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 54 insertions(+), 6 deletions(-)

diffs (89 lines):

diff -r 149a0d399ade -r b6e860db15f1 bin/ksh/edit.c
--- a/bin/ksh/edit.c    Tue Feb 05 12:55:32 2002 +0000
+++ b/bin/ksh/edit.c    Wed Feb 06 13:55:57 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: edit.c,v 1.6 1999/11/02 22:06:45 jdolecek Exp $        */
+/*     $NetBSD: edit.c,v 1.6.6.1 2002/02/06 13:55:57 he Exp $  */
 
 /*
  * Command line editing - common code
@@ -840,6 +840,40 @@
        return nwords;
 }
 
+
+static char *
+find_match(const char *s, int have)
+{
+       int     want = 0;
+       int     nest = 1;
+       int     c;
+       
+       switch (have) {
+       case '(':       want = ')'; break;
+       case '{':       want = '}'; break;
+       case '[':       want = ']'; break;
+       case '\'':      
+       case '"':       want = have; break;
+       }
+       if (want == 0 || s == NULL)
+               return NULL;
+
+       while (nest > 0 && (c = *s)) {
+               if (c == '\\') {
+                       s++;
+                       s++;
+                       continue;
+               }
+               if (c == want)
+                       nest--;
+               else if (c == have)
+                       nest++;
+               if (nest > 0)
+                       s++;
+       }
+       return (nest == 0) ? (char *) s : NULL;
+}
+
 /* Given a string, copy it and possibly add a '*' to the end.  The
  * new string is returned.
  */
@@ -859,19 +893,33 @@
        toglob[slen] = '\0';
 
        /*
-        * If the pathname contains a wildcard (an unquoted '*',
-        * '?', or '[') or parameter expansion ('$'), or a ~username
-        * with no trailing slash, then it is globbed based on that
-        * value (i.e., without the appended '*').
+        * If the pathname contains a wildcard (an unquoted '*', '?',
+        * or '[') or parameter expansion ('$') with nothing following
+        * it, or a ~username with no trailing slash, then it is
+        * globbed based on that value (i.e., without the appended
+        * '*').
         */
        for (s = toglob; *s; s++) {
                if (*s == '\\' && s[1])
                        s++;
-               else if (*s == '*' || *s == '[' || *s == '?' || *s == '$'
+               else if (*s == '*' || *s == '[' || *s == '?'
                         || (s[1] == '(' /*)*/ && strchr("*+?@!", *s)))
                        break;
                else if (ISDIRSEP(*s))
                        saw_slash = TRUE;
+               else if (*s == '$') {
+                       if (*++s == '{') {
+                               char *cp;
+                               
+                               if ((cp = find_match(&s[1], '{')))
+                                       s = ++cp;
+                       }
+                       if (*s)
+                               s += strcspn(s,
+                                       ".,/?-<>[]{}()'\";:\\|=+*&^%$#@!`~");
+                       if (!*s)
+                               return toglob;
+               }
        }
        if (!*s && (*toglob != '~' || saw_slash)) {
                toglob[slen] = '*';



Home | Main Index | Thread Index | Old Index