Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit Add fn_complete2() that controls the quoting of ...



details:   https://anonhg.NetBSD.org/src/rev/5d65f2e8248c
branches:  trunk
changeset: 954014:5d65f2e8248c
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Mar 27 18:55:02 2021 +0000

description:
Add fn_complete2() that controls the quoting of the returned match.
Before it was based on the heuristic that we were not supplied an
attempted_completion_function, which worked well because programs
that supplied that function were not shells and did not want/understand
shell quoting. Recently though Piotr Stefaniak wanted to enhance command
completion for the Bourne Shell and this could benefit quoting the returned
command. This function adds an extra flags argument that controls that quoting.

diffstat:

 lib/libedit/filecomplete.c |  39 +++++++++++++++++++++++++++------------
 lib/libedit/filecomplete.h |   8 +++++++-
 2 files changed, 34 insertions(+), 13 deletions(-)

diffs (110 lines):

diff -r 46bcdcd06337 -r 5d65f2e8248c lib/libedit/filecomplete.c
--- a/lib/libedit/filecomplete.c        Sat Mar 27 16:37:12 2021 +0000
+++ b/lib/libedit/filecomplete.c        Sat Mar 27 18:55:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: filecomplete.c,v 1.64 2020/01/05 07:12:05 abhinav Exp $        */
+/*     $NetBSD: filecomplete.c,v 1.65 2021/03/27 18:55:02 christos Exp $       */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: filecomplete.c,v 1.64 2020/01/05 07:12:05 abhinav Exp $");
+__RCSID("$NetBSD: filecomplete.c,v 1.65 2021/03/27 18:55:02 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <sys/types.h>
@@ -652,12 +652,13 @@
  *       '!' could never be invoked
  */
 int
-fn_complete(EditLine *el,
-       char *(*complet_func)(const char *, int),
-       char **(*attempted_completion_function)(const char *, int, int),
-       const wchar_t *word_break, const wchar_t *special_prefixes,
-       const char *(*app_func)(const char *), size_t query_items,
-       int *completion_type, int *over, int *point, int *end)
+fn_complete2(EditLine *el,
+    char *(*complete_func)(const char *, int),
+    char **(*attempted_completion_function)(const char *, int, int),
+    const wchar_t *word_break, const wchar_t *special_prefixes,
+    const char *(*app_func)(const char *), size_t query_items,
+    int *completion_type, int *over, int *point, int *end,
+    unsigned int flags)
 {
        const LineInfoW *li;
        wchar_t *temp;
@@ -675,8 +676,8 @@
        if (completion_type != NULL)
                *completion_type = what_to_do;
 
-       if (!complet_func)
-               complet_func = fn_filename_completion_function;
+       if (!complete_func)
+               complete_func = fn_filename_completion_function;
        if (!app_func)
                app_func = append_char_function;
 
@@ -703,7 +704,7 @@
        if (!attempted_completion_function ||
            (over != NULL && !*over && !matches))
                matches = completion_matches(
-                   ct_encode_string(temp, &el->el_scratch), complet_func);
+                   ct_encode_string(temp, &el->el_scratch), complete_func);
 
        if (over != NULL)
                *over = 0;
@@ -720,7 +721,7 @@
 
        if (matches[0][0] != '\0') {
                el_deletestr(el, (int)len);
-               if (!attempted_completion_function)
+               if (flags & FN_QUOTE_MATCH)
                        completion = escape_filename(el, matches[0],
                            single_match, app_func);
                else
@@ -817,6 +818,20 @@
        return retval;
 }
 
+int
+fn_complete(EditLine *el,
+    char *(*complete_func)(const char *, int),
+    char **(*attempted_completion_function)(const char *, int, int),
+    const wchar_t *word_break, const wchar_t *special_prefixes,
+    const char *(*app_func)(const char *), size_t query_items,
+    int *completion_type, int *over, int *point, int *end)
+{
+       return fn_complete2(el, complete_func, attempted_completion_function,
+           word_break, special_prefixes, app_func, query_items,
+           completion_type, over, point, end,
+           attempted_completion_function ? 0 : FN_QUOTE_MATCH);
+}
+
 /*
  * el-compatible wrapper around rl_complete; needed for key binding
  */
diff -r 46bcdcd06337 -r 5d65f2e8248c lib/libedit/filecomplete.h
--- a/lib/libedit/filecomplete.h        Sat Mar 27 16:37:12 2021 +0000
+++ b/lib/libedit/filecomplete.h        Sat Mar 27 18:55:02 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: filecomplete.h,v 1.11 2017/04/21 05:38:03 abhinav Exp $        */
+/*     $NetBSD: filecomplete.h,v 1.12 2021/03/27 18:55:02 christos Exp $       */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -36,6 +36,12 @@
     char **(*)(const char *, int, int),
     const wchar_t *, const wchar_t *, const char *(*)(const char *), size_t,
     int *, int *, int *, int *);
+int fn_complete2(EditLine *,
+    char *(*)(const char *, int),
+    char **(*)(const char *, int, int),
+    const wchar_t *, const wchar_t *, const char *(*)(const char *), size_t,
+    int *, int *, int *, int *, unsigned int);
+#define FN_QUOTE_MATCH 1
 
 void fn_display_match_list(EditLine *, char **, size_t, size_t,
        const char *(*)(const char *));



Home | Main Index | Thread Index | Old Index