related to LP#1025843 fix tab completion for tilde

this code is insane, who wrote globbing and expansion for mksh’s
predecessor must have been on very interesting drugs
This commit is contained in:
tg 2012-08-24 21:15:42 +00:00
parent 42ac0dc08e
commit e2d1f3bf99
3 changed files with 16 additions and 24 deletions

30
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING #ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.249 2012/08/24 20:57:44 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.250 2012/08/24 21:15:40 tg Exp $");
/* /*
* in later versions we might use libtermcap for this, but since external * in later versions we might use libtermcap for this, but since external
@ -379,7 +379,7 @@ x_file_glob(int *flagsp, char *toglob, char ***wordsp)
/* probably a $FOO expansion */ /* probably a $FOO expansion */
*flagsp |= XCF_IS_NOSPACE; *flagsp |= XCF_IS_NOSPACE;
/* this always results in at most one match */ /* this always results in at most one match */
nwords = DOKEEPQCHAR; nwords = 0;
} }
expand(yylval.cp, &w, nwords); expand(yylval.cp, &w, nwords);
XPput(w, NULL); XPput(w, NULL);
@ -812,24 +812,20 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *lpath)
static int static int
x_escape(const char *s, size_t len, int (*putbuf_func)(const char *, size_t)) x_escape(const char *s, size_t len, int (*putbuf_func)(const char *, size_t))
{ {
char ch;
size_t add = 0, wlen = len; size_t add = 0, wlen = len;
const char *ifs = str_val(local("IFS", 0)); const char *ifs = str_val(local("IFS", 0));
int rval = 0; int rval = 0;
while (wlen - add > 0) { while (wlen - add > 0)
ch = s[add]; if (vstrchr("\"#$&'()*:;<=>?[\\`{|}", s[add]) ||
if (vstrchr("\"#$&'()*:;<=>?[\\`{|}", ch) || vstrchr(ifs, s[add])) {
ch == QCHAR || vstrchr(ifs, ch)) {
if (putbuf_func(s, add) != 0) { if (putbuf_func(s, add) != 0) {
rval = -1; rval = -1;
break; break;
} }
putbuf_func(ch == '\n' ? "'" : "\\", 1); putbuf_func(s[add] == '\n' ? "'" : "\\", 1);
if (ch == QCHAR)
++add;
putbuf_func(&s[add], 1); putbuf_func(&s[add], 1);
if (ch == '\n') if (s[add] == '\n')
putbuf_func("'", 1); putbuf_func("'", 1);
add++; add++;
@ -838,7 +834,6 @@ x_escape(const char *s, size_t len, int (*putbuf_func)(const char *, size_t))
add = 0; add = 0;
} else } else
++add; ++add;
}
if (wlen > 0 && rval == 0) if (wlen > 0 && rval == 0)
rval = putbuf_func(s, wlen); rval = putbuf_func(s, wlen);
@ -2774,15 +2769,16 @@ do_complete(
/* /*
* do some tilde expansion; we know at this * do some tilde expansion; we know at this
* point (by means of having nwords > 1) that * point (by means of having nwords > 1) that
* the string looke like "~foo/bar" * the string looks like "~foo/bar" and that
* the tilde resolves
*/ */
char *cp, *dp; char *cp;
cp = ucstrchr(unescaped + 1, '/'); cp = ucstrchr(unescaped + 1, '/');
*cp++ = 0; *cp++ = 0;
if ((dp = tilde(unescaped + 1))) { cp = shf_smprintf("%s/%s", tilde(unescaped + 1), cp);
/* got a match */ afree(unescaped, ATEMP);
} unescaped = cp;
} }
/* ... convert it from backslash-escaped via QCHAR-escaped... */ /* ... convert it from backslash-escaped via QCHAR-escaped... */

7
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.127 2012/08/24 20:57:45 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/eval.c,v 1.128 2012/08/24 21:15:42 tg Exp $");
/* /*
* string expansion * string expansion
@ -1008,12 +1008,9 @@ expand(const char *cp, /* input word */
} }
break; break;
} }
else { else
/* undo temporary */ /* undo temporary */
quote &= ~2; quote &= ~2;
if (f & DOKEEPQCHAR)
*dp++ = QCHAR;
}
if (make_magic) { if (make_magic) {
make_magic = false; make_magic = false;

3
sh.h
View File

@ -157,7 +157,7 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.582 2012/08/24 20:57:46 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.583 2012/08/24 21:15:42 tg Exp $");
#endif #endif
#define MKSH_VERSION "R40 2012/08/17" #define MKSH_VERSION "R40 2012/08/17"
@ -1343,7 +1343,6 @@ struct ioword {
#define DOTEMP BIT(8) /* dito: in word part of ${..[%#=?]..} */ #define DOTEMP BIT(8) /* dito: in word part of ${..[%#=?]..} */
#define DOVACHECK BIT(9) /* var assign check (for typeset, set, etc) */ #define DOVACHECK BIT(9) /* var assign check (for typeset, set, etc) */
#define DOMARKDIRS BIT(10) /* force markdirs behaviour */ #define DOMARKDIRS BIT(10) /* force markdirs behaviour */
#define DOKEEPQCHAR BIT(11) /* internal use by globbing code */
/* /*
* The arguments of [[ .. ]] expressions are kept in t->args[] and flags * The arguments of [[ .. ]] expressions are kept in t->args[] and flags