> Delivered-To: marty...@venck.us
> Received: by 10.231.147.205 with SMTP id m13cs105662ibv;
>         Tue, 15 Mar 2011 01:48:25 -0700 (PDT)
> Received: by 10.43.46.135 with SMTP id uo7mr4936656icb.50.1300178905343;
>         Tue, 15 Mar 2011 01:48:25 -0700 (PDT)
> Return-Path: <owner-tech+m23...@openbsd.org>
> Received: from shear.ucar.edu (lists.openbsd.org [192.43.244.163])
>         by mx.google.com with ESMTP id 
> yd20si10108737icb.5.2011.03.15.01.48.25;
>         Tue, 15 Mar 2011 01:48:25 -0700 (PDT)
> Received-SPF: pass (google.com: manual fallback record for domain of 
> owner-tech+m23...@openbsd.org designates 192.43.244.163 as permitted sender) 
> client-ip=192.43.244.163;
> Authentication-Results: mx.google.com; spf=pass (google.com: manual fallback 
> record for domain of owner-tech+m23...@openbsd.org designates 192.43.244.163 
> as permitted sender) smtp.mail=owner-tech+m23...@openbsd.org
> Received: from openbsd.org (localhost.ucar.edu [127.0.0.1])
>       by shear.ucar.edu (8.14.3/8.14.3) with ESMTP id p2F8lBju030637;
>       Tue, 15 Mar 2011 02:47:11 -0600 (MDT)
> Received: from clam.khaoz.org (clam.khaoz.org [64.90.163.62])
>       by shear.ucar.edu (8.14.3/8.14.3) with ESMTP id p2F8jjJq003536 
> (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=FAIL); Tue, 15 
> Mar 2011 02:45:46 -0600 (MDT)
> Received: from clam.khaoz.org (okan@localhost [IPv6:::1])
>       by clam.khaoz.org (8.14.3/8.14.3) with ESMTP id p2F8jhx2026590 
> (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO); Tue, 15 
> Mar 2011 04:45:44 -0400 (EDT)
> Date: Tue, 15 Mar 2011 04:45:43 -0400
> From: Okan Demirmen <o...@openbsd.org>
> To: tech@openbsd.org
> Cc: r...@openbsd.org
> Subject: ksh completion
> Message-ID: <20110315084543.ga17...@clam.khaoz.org>
> Mail-Followup-To: tech@openbsd.org, r...@openbsd.org
> MIME-Version: 1.0
> Content-Type: text/plain; charset=us-ascii
> List-Help: <mailto:majord...@openbsd.org?body=help>
> List-Owner: <mailto:tech-ow...@openbsd.org>
> List-Post: <mailto:tech@openbsd.org>
> List-Subscribe: <mailto:majord...@openbsd.org?body=sub%20tech>
> List-Unsubscribe: <mailto:majord...@openbsd.org?body=unsub%20tech>
> X-Loop: tech@openbsd.org
> Precedence: list
> Sender: owner-t...@openbsd.org
>
> 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

> Index: edit.c
> ===================================================================
> RCS file: /home/okan/hack/open/cvs/src/bin/ksh/edit.c,v
> retrieving revision 1.34
> diff -u -p -r1.34 edit.c
> --- edit.c    20 May 2010 01:13:07 -0000      1.34
> +++ edit.c    14 Mar 2011 09:59:27 -0000
> @@ -365,6 +365,11 @@ x_file_glob(int flags, const char *str,
>                       continue;
>               }
>
> +             /* specially escape escaped [ or $ or ` for globbing */
> +             if (escaping && (toglob[i] == '[' ||
> +                 toglob[i] == '$' || toglob[i] == '`'))
> +                     toglob[idx++] = QCHAR;
> +
>               toglob[idx] = toglob[i];
>               idx++;
>               if (escaping) escaping = 0;
> @@ -378,7 +383,7 @@ x_file_glob(int flags, const char *str,
>       s = pushs(SWSTR, ATEMP);
>       s->start = s->str = toglob;
>       source = s;
> -     if (yylex(ONEWORD) != LWORD) {
> +     if (yylex(ONEWORD|LQCHAR) != LWORD) {
>               source = sold;
>               internal_errorf(0, "fileglob: substitute error");
>               return 0;
> @@ -821,7 +826,7 @@ x_escape(const char *s, size_t len, int
>       int rval = 0;
>
>       for (add = 0, wlen = len; wlen - add > 0; add++) {
> -             if (strchr("\"#$&'()*;<=>?[\\]`{|}", s[add]) ||
> +             if (strchr("\"#$&'()*:;<=>?[\\]`{|}", s[add]) ||
>                   strchr(ifs, s[add])) {
>                       if (putbuf_func(s, add) != 0) {
>                               rval = -1;
> Index: lex.c
> ===================================================================
> RCS file: /home/okan/hack/open/cvs/src/bin/ksh/lex.c,v
> retrieving revision 1.45
> diff -u -p -r1.45 lex.c
> --- lex.c     9 Mar 2011 09:30:39 -0000       1.45
> +++ lex.c     14 Mar 2011 09:59:27 -0000
> @@ -411,6 +411,13 @@ yylex(int cf)
>                                       }
>                               }
>                               break;
> +                     case QCHAR:
> +                             if (cf & LQCHAR) {
> +                                     *wp++ = QCHAR;
> +                                     *wp++ = getsc();
> +                                     break;
> +                             }
> +                             /* FALLTHROUGH */
>                       default:
>                               *wp++ = CHAR, *wp++ = c;
>                       }
> Index: lex.h
> ===================================================================
> RCS file: /home/okan/hack/open/cvs/src/bin/ksh/lex.h,v
> retrieving revision 1.11
> diff -u -p -r1.11 lex.h
> --- lex.h     29 May 2006 18:22:24 -0000      1.11
> +++ lex.h     14 Mar 2011 09:59:27 -0000
> @@ -113,6 +113,7 @@ typedef union {
>  #define CMDWORD BIT(8)               /* parsing simple command (alias 
> related) */
>  #define HEREDELIM BIT(9)     /* parsing <<,<<- delimiter */
>  #define HEREDOC BIT(10)              /* parsing heredoc */
> +#define LQCHAR BIT(11)               /* source string contains QCHAR */
>
>  #define      HERES   10              /* max << in line */

Reply via email to