Re: ksh: tab completion fix (again)

2012-09-26 Thread LEVAI Daniel
On cs, szept 27, 2012 at 01:42:25 +0400, Alexander Polakov wrote:
> I sent this diff in 2011 (?) with a bunch of other diffs.
> It fixes tab completion for filenames containing special
> characters like [], () and so.
> 
> This code affects interactive mode only, and I don't know a way
> to do automated testing of this. Suggestions welcome.
[...]

I've been using this (and the other ones) since then. No problems
neither on OpenBSD or Linux.


Daniel

-- 
LÉVAI Dániel
PGP key ID = 0x83B63A8F
Key fingerprint = DBEC C66B A47A DFA2 792D  650C C69B BE4C 83B6 3A8F



Re: ksh: tab completion fix (again)

2012-09-26 Thread Aaron Bieber
On Thu, Sep 27, 2012 at 01:42:25AM +0400, Alexander Polakov wrote:
> I sent this diff in 2011 (?) with a bunch of other diffs.
> It fixes tab completion for filenames containing special
> characters like [], () and so.
> 
> This code affects interactive mode only, and I don't know a way
> to do automated testing of this. Suggestions welcome.
> 
Seems to be working for me! Tested with the below:

$ touch bad\]file
$ rm ba 
- which expands to-
$ rm bad\]file
$

>  
> 
> -- 
> open source wizard



ksh: tab completion fix (again)

2012-09-26 Thread Alexander Polakov
I sent this diff in 2011 (?) with a bunch of other diffs.
It fixes tab completion for filenames containing special
characters like [], () and so.

This code affects interactive mode only, and I don't know a way
to do automated testing of this. Suggestions welcome.

Index: edit.c
===
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.35
diff -u -r1.35 edit.c
--- edit.c  10 Sep 2012 01:25:30 -  1.35
+++ edit.c  26 Sep 2012 21:32:42 -
@@ -348,7 +348,7 @@
 {
char *toglob;
char **words;
-   int nwords, i, idx, escaping;
+   int nwords;
XPtrV w;
struct source *s, *sold;
 
@@ -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)
 */
@@ -378,7 +364,7 @@
s = pushs(SWSTR, ATEMP);
s->start = s->str = toglob;
source = s;
-   if (yylex(ONEWORD) != LWORD) {
+   if (yylex(ONEWORD|UNESCAPE) != LWORD) {
source = sold;
internal_errorf(0, "fileglob: substitute error");
return 0;
@@ -394,15 +380,12 @@
if (nwords == 1) {
struct stat statb;
 
-   /* Check if globbing failed (returned glob pattern),
-* but be careful (E.g. toglob == "ab*" when the file
-* "ab*" exists is not an error).
-* Also, check for empty result - happens if we tried
-* to glob something which evaluated to an empty
-* string (e.g., "$FOO" when there is no FOO, etc).
+   /* Check if file exists, also, check for empty
+* result - happens if we tried to glob something
+* which evaluated to an empty string (e.g.,
+* "$FOO" when there is no FOO, etc).
 */
-   if ((strcmp(words[0], toglob) == 0 &&
-   stat(words[0], &statb) < 0) ||
+if ((lstat(words[0], &statb) < 0) ||
words[0][0] == '\0') {
x_free_words(nwords, words);
words = NULL;
Index: lex.c
===
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.45
diff -u -r1.45 lex.c
--- lex.c   9 Mar 2011 09:30:39 -   1.45
+++ lex.c   26 Sep 2012 21:32:43 -
@@ -299,6 +299,10 @@
}
/* FALLTHROUGH */
default:
+   if (cf & UNESCAPE) {
+   *wp++ = QCHAR, *wp++ = c;
+   break;
+   }
Xcheck(ws, wp);
if (c) { /* trailing \ is lost */
*wp++ = CHAR, *wp++ = '\\';
Index: lex.h
===
RCS file: /cvs/src/bin/ksh/lex.h,v
retrieving revision 1.11
diff -u -r1.11 lex.h
--- lex.h   29 May 2006 18:22:24 -  1.11
+++ lex.h   26 Sep 2012 21:32:43 -
@@ -113,6 +113,7 @@
 #define CMDWORD BIT(8) /* parsing simple command (alias related) */
 #define HEREDELIM BIT(9)   /* parsing <<,<<- delimiter */
 #define HEREDOC BIT(10)/* parsing heredoc */
+#define UNESCAPE BIT(11)   /* remove backslashes */
 
 #defineHERES   10  /* max << in line */
 

-- 
open source wizard