* Martynas Venckus <marty...@venck.us> [110410 05:17]: > > hi, > > > > (this is a re-post) > > > > make tab completion work for '=', '`', '[', ':', and '$' - pulled from > > mksh by Alexander Polakov (also posted to tech recently). > > > > closes pr 6006 too. > > > > comments/ok? > > The diff is a workaround and even wrong. Ksh lexical analyzer > itself has the ability to deal with escapes properly (see yylex). > > I believe we shouldn't remove backward slashes before passing it > for analysis, this would fix all cases, including: > > $ touch aabbcc aa\*cc > $ echo aa\*cc<tab> > aa*cc aabbcc > $ echo aa\*cc > aa*cc >
Do you mean something like this or I got it all wrong again and we have to wait another 15 years for someone to dig into this? Index: bin/ksh/edit.c =================================================================== RCS file: /cvs/src/bin/ksh/edit.c,v retrieving revision 1.34 diff -u -r1.34 edit.c --- bin/ksh/edit.c 20 May 2010 01:13:07 -0000 1.34 +++ bin/ksh/edit.c 2 May 2011 14:10:47 -0000 @@ -357,20 +357,6 @@ toglob = add_glob(str, slen); - /* remove all escaping backward slashes */ - escaping = 0; - for (i = 0, idx = 0; toglob[i]; i++) { - if (toglob[i] == '\\' && !escaping) { - escaping = 1; - continue; - } - - toglob[idx] = toglob[i]; - idx++; - if (escaping) escaping = 0; - } - toglob[idx] = '\0'; - /* * Convert "foo*" (toglob) to an array of strings (words) */ @@ -393,6 +379,20 @@ ; if (nwords == 1) { struct stat statb; + + /* remove all escaping backward slashes (see below) */ + escaping = 0; + for (i = 0, idx = 0; toglob[i]; i++) { + if (toglob[i] == '\\' && !escaping) { + escaping = 1; + continue; + } + + toglob[idx] = toglob[i]; + idx++; + if (escaping) escaping = 0; + } + toglob[idx] = '\0'; /* Check if globbing failed (returned glob pattern), * but be careful (E.g. toglob == "ab*" when the file Index: bin/ksh/lex.c =================================================================== RCS file: /cvs/src/bin/ksh/lex.c,v retrieving revision 1.45 diff -u -r1.45 lex.c --- bin/ksh/lex.c 9 Mar 2011 09:30:39 -0000 1.45 +++ bin/ksh/lex.c 2 May 2011 14:10:47 -0000 @@ -287,24 +287,15 @@ switch (c) { case '\\': c = getsc(); - switch (c) { - case '\\': - case '$': case '`': + if ((c == '"' && ((cf & HEREDOC) == 0)) || + strchr(" \"#$&'()*;<=>?[\\]`{|}", c)) { *wp++ = QCHAR, *wp++ = c; break; - case '"': - if ((cf & HEREDOC) == 0) { - *wp++ = QCHAR, *wp++ = c; - break; - } - /* FALLTHROUGH */ - default: - Xcheck(ws, wp); - if (c) { /* trailing \ is lost */ - *wp++ = CHAR, *wp++ = '\\'; - *wp++ = CHAR, *wp++ = c; - } - break; + } + Xcheck(ws, wp); + if (c) { /* trailing \ is lost */ + *wp++ = CHAR, *wp++ = '\\'; + *wp++ = CHAR, *wp++ = c; } break; case '$': -- Alexander Polakov | plhk.ru