On Wed, 3 Mar 2010 18:14:51 -0500
Brad <b...@comstyle.com> wrote:

> On Thursday 04 March 2010 03:00:03 Sviatoslav Chagaev wrote:
> > Greetings and felicitations!
> 
> Ensure the diffs are created as a unified diff (.e.g. cvs diff -upRN) if
> you actually want anyone to look at them ;)
> 
> -- 
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
> 

Ok, sorry:

Index: edit.c
===================================================================
RCS file: /OpenBSD/src/bin/ksh/edit.c,v
retrieving revision 1.33
diff -u -p -r1.33 edit.c
--- edit.c      2 Aug 2007 10:50:25 -0000       1.33
+++ edit.c      3 Mar 2010 23:20:14 -0000
@@ -411,7 +411,7 @@ x_file_glob(int flags, const char *str, 
        }
        source = sold;
        XPinit(w, 32);
-       expand(yylval.cp, &w, DOGLOB|DOTILDE|DOMARKDIRS);
+       expand(yylval.cp, &w, DOCOMPLETION|DOGLOB|DOTILDE|DOMARKDIRS);
        XPput(w, NULL);
        words = (char **) XPclose(w);
 
@@ -484,7 +484,7 @@ x_command_glob(int flags, const char *st
        toglob = add_glob(str, slen);
 
        /* Convert "foo*" (toglob) to a pattern for future use */
-       pat = evalstr(toglob, DOPAT|DOTILDE);
+       pat = evalstr(toglob, DOCOMPLETION|DOPAT|DOTILDE);
        afree(toglob, ATEMP);
 
        XPinit(w, 32);
@@ -647,41 +647,20 @@ x_cf_glob(int flags, const char *buf, in
        return nwords;
 }
 
-/* Given a string, copy it and possibly add a '*' to the end.  The
+/* Given a string, copy it and add a '*' to the end.  The
  * new string is returned.
  */
 static char *
 add_glob(const char *str, int slen)
 {
        char *toglob;
-       char *s;
-       bool saw_slash = false;
 
        if (slen < 0)
                return (char *) 0;
 
-       toglob = str_nsave(str, slen + 1, ATEMP); /* + 1 for "*" */
-       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 '*').
-        */
-       for (s = toglob; *s; s++) {
-               if (*s == '\\' && s[1])
-                       s++;
-               else if (*s == '*' || *s == '[' || *s == '?' || *s == '$'
-                        || (s[1] == '(' /*)*/ && strchr("*...@!", *s)))
-                       break;
-               else if (*s == '/')
-                       saw_slash = true;
-       }
-       if (!*s && (*toglob != '~' || saw_slash)) {
-               toglob[slen] = '*';
-               toglob[slen + 1] = '\0';
-       }
+       toglob = str_nsave(str, slen + 1, ATEMP);
+       toglob[slen] = '*';
+       toglob[slen + 1] = '\0';
 
        return toglob;
 }
Index: eval.c
===================================================================
RCS file: /OpenBSD/src/bin/ksh/eval.c,v
retrieving revision 1.34
diff -u -p -r1.34 eval.c
--- eval.c      29 Jan 2009 23:27:26 -0000      1.34
+++ eval.c      3 Mar 2010 23:20:14 -0000
@@ -554,7 +554,7 @@ expand(char *cp,    /* input word */
                                else
 #endif /* BRACE_EXPAND */
                                if (fdo & DOGLOB)
-                                       glob(p, wp, f & DOMARKDIRS);
+                                       glob(p, wp, f & (DOCOMPLETION | 
DOMARKDIRS));
                                else if ((f & DOPAT) || !(fdo & DOMAGIC_))
                                        XPput(*wp, p);
                                else
@@ -596,15 +596,18 @@ expand(char *cp,  /* input word */
                                         * to have magic !,-,]'s outside of
                                         * [...] expressions.
                                         */
-                                       if (f & (DOPAT | DOGLOB)) {
+                                       if (!(f & DOCOMPLETION) && f & (DOPAT | 
DOGLOB)) {
                                                fdo |= DOMAGIC_;
                                                if (c == '[')
                                                        fdo |= f & DOGLOB;
                                                *dp++ = MAGIC;
                                        }
                                        break;
-                               case '*':
                                case '?':
+                                       if (f & DOCOMPLETION)
+                                               break;
+                                       /* fall through */
+                               case '*':
                                        if (f & (DOPAT | DOGLOB)) {
                                                fdo |= DOMAGIC_ | (f & DOGLOB);
                                                *dp++ = MAGIC;
@@ -614,10 +617,11 @@ expand(char *cp,  /* input word */
                                case OBRACE:
                                case ',':
                                case CBRACE:
-                                       if ((f & DOBRACE_) && (c == OBRACE ||
-                                           (fdo & DOBRACE_))) {
-                                               fdo |= DOBRACE_|DOMAGIC_;
-                                               *dp++ = MAGIC;
+                                       if (!(f & DOCOMPLETION) &&
+                                               (f & DOBRACE_) &&
+                                               (c == OBRACE || (fdo & 
DOBRACE_))) {
+                                                       fdo |= 
DOBRACE_|DOMAGIC_;
+                                                       *dp++ = MAGIC;
                                        }
                                        break;
 #endif /* BRACE_EXPAND */
@@ -933,13 +937,14 @@ trimsub(char *str, char *pat, int how)
 
 /* XXX cp not const 'cause slashes are temporarily replaced with nulls... */
 static void
-glob(char *cp, XPtrV *wp, int markdirs)
+glob(char *cp, XPtrV *wp, int flags)
 {
        int oldsize = XPsize(*wp);
 
-       if (glob_str(cp, wp, markdirs) == 0)
-               XPput(*wp, debunk(cp, cp, strlen(cp) + 1));
-       else
+       if (glob_str(cp, wp, flags & DOMARKDIRS) == 0) {
+               if (!(flags & DOCOMPLETION))
+                       XPput(*wp, debunk(cp, cp, strlen(cp) + 1));
+       } else
                qsortp(XPptrv(*wp) + oldsize, (size_t)(XPsize(*wp) - oldsize),
                        xstrcmp);
 }
@@ -1141,8 +1146,8 @@ debunk(char *dp, const char *sp, size_t 
 
        if ((s = strchr(sp, MAGIC))) {
                if (s - sp >= dlen)
-                       return dp;
-               memcpy(dp, sp, s - sp);
+                       return dp; 
+               memmove(dp, sp, s - sp);
                for (d = dp + (s - sp); *s && (d - dp < dlen); s++)
                        if (!ISMAGIC(*s) || !(*++s & 0x80) ||
                            !strchr("*...@! ", *s & 0x7f))
Index: tree.h
===================================================================
RCS file: /OpenBSD/src/bin/ksh/tree.h,v
retrieving revision 1.10
diff -u -p -r1.10 tree.h
--- tree.h      28 Mar 2005 21:28:22 -0000      1.10
+++ tree.h      3 Mar 2010 23:20:18 -0000
@@ -126,6 +126,7 @@ struct ioword {
 #define DOTEMP_        BIT(8)          /* ditto : in word part of 
${..[%#=?]..} */
 #define DOVACHECK BIT(9)       /* var assign check (for typeset, set, etc) */
 #define DOMARKDIRS BIT(10)     /* force markdirs behaviour */
+#define DOCOMPLETION BIT(11)   /* hint that we are doing an auto-completion */
 
 /*
  * The arguments of [[ .. ]] expressions are kept in t->args[] and flags

Reply via email to