Source-Changes-HG archive

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

[src/trunk]: src/lib/libedit From Ingo Schwarze:



details:   https://anonhg.NetBSD.org/src/rev/17c1dd6a8366
branches:  trunk
changeset: 344703:17c1dd6a8366
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Apr 12 00:16:06 2016 +0000

description:
>From Ingo Schwarze:

 * Delete the stubs of the XK_EXE mechanism that was never implemented.
   From a security, stability, and simplicity perspective, i would
   consider implementing it a truly terrible idea, so let's better
   get rid of it.

 * Do not use the local variable "num" in el_wgets() alternately for
   two completely different purposes.  Only use it for the number
   of characters read, as stated in the comment (or -1 as long as
   that number is still unknown), not for the (more or less boolean)
   return value of read_getcmd().  Actually, there is no need at
   all to save the latter return value after testing it once.

 * The function read_getcmd() has very unusual return values:
   It returns -1 for success and 0 for EOF/error.  Switch that around
   to 0 for success and -1 for EOF/error to be less confusing, and
   get rid of the OKCMD preprocessor macro.

 * Get rid of one #ifdef section in el_wgets() by using
   el->el_chared.c_macro directly at the only place
   where it is used.

 * Delete the unused MIN() macro.

diffstat:

 lib/libedit/keymacro.c |  12 ++++--------
 lib/libedit/keymacro.h |   3 +--
 lib/libedit/map.c      |  10 ++--------
 lib/libedit/read.c     |  36 ++++++++++--------------------------
 4 files changed, 17 insertions(+), 44 deletions(-)

diffs (242 lines):

diff -r 5c2f4fde2987 -r 17c1dd6a8366 lib/libedit/keymacro.c
--- a/lib/libedit/keymacro.c    Mon Apr 11 23:41:15 2016 +0000
+++ b/lib/libedit/keymacro.c    Tue Apr 12 00:16:06 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: keymacro.c,v 1.19 2016/04/11 18:56:31 christos Exp $   */
+/*     $NetBSD: keymacro.c,v 1.20 2016/04/12 00:16:06 christos Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)key.c      8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: keymacro.c,v 1.19 2016/04/11 18:56:31 christos Exp $");
+__RCSID("$NetBSD: keymacro.c,v 1.20 2016/04/12 00:16:06 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -50,7 +50,7 @@
  *     number of characters.  This module maintains a map (the
  *     el->el_keymacro.map)
  *     to convert these extended-key sequences into input strs
- *     (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
+ *     (XK_STR) or editor functions (XK_CMD).
  *
  *      Warning:
  *       If key is a substr of some other keys, then the longer
@@ -169,7 +169,7 @@
  *     Calls the recursive function with entry point el->el_keymacro.map
  *      Looks up *ch in map and then reads characters until a
  *      complete match is found or a mismatch occurs. Returns the
- *      type of the match found (XK_STR, XK_CMD, or XK_EXE).
+ *      type of the match found (XK_STR or XK_CMD).
  *      Returns NULL in val.str and XK_STR for no match.
  *      The last character read is returned in *ch.
  */
@@ -341,7 +341,6 @@
                case XK_NOD:
                        break;
                case XK_STR:
-               case XK_EXE:
                        if (ptr->val.str)
                                el_free(ptr->val.str);
                        break;
@@ -356,7 +355,6 @@
                        ptr->val = *val;
                        break;
                case XK_STR:
-               case XK_EXE:
                        if ((ptr->val.str = wcsdup(val->str)) == NULL)
                                return -1;
                        break;
@@ -441,7 +439,6 @@
        case XK_CMD:
        case XK_NOD:
                break;
-       case XK_EXE:
        case XK_STR:
                if (ptr->val.str != NULL)
                        el_free(ptr->val.str);
@@ -594,7 +591,6 @@
        if (val != NULL)
                switch (ntype) {
                case XK_STR:
-               case XK_EXE:
                        (void) keymacro__decode_str(val->str, unparsbuf,
                            sizeof(unparsbuf),
                            ntype == XK_STR ? "\"\"" : "[]");
diff -r 5c2f4fde2987 -r 17c1dd6a8366 lib/libedit/keymacro.h
--- a/lib/libedit/keymacro.h    Mon Apr 11 23:41:15 2016 +0000
+++ b/lib/libedit/keymacro.h    Tue Apr 12 00:16:06 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: keymacro.h,v 1.4 2016/04/11 00:50:13 christos Exp $    */
+/*     $NetBSD: keymacro.h,v 1.5 2016/04/12 00:16:06 christos Exp $    */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -56,7 +56,6 @@
 #define        XK_CMD  0
 #define        XK_STR  1
 #define        XK_NOD  2
-#define        XK_EXE  3
 
 protected int keymacro_init(EditLine *);
 protected void keymacro_end(EditLine *);
diff -r 5c2f4fde2987 -r 17c1dd6a8366 lib/libedit/map.c
--- a/lib/libedit/map.c Mon Apr 11 23:41:15 2016 +0000
+++ b/lib/libedit/map.c Tue Apr 12 00:16:06 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: map.c,v 1.47 2016/04/11 18:56:31 christos Exp $        */
+/*     $NetBSD: map.c,v 1.48 2016/04/12 00:16:06 christos Exp $        */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)map.c      8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: map.c,v 1.47 2016/04/11 18:56:31 christos Exp $");
+__RCSID("$NetBSD: map.c,v 1.48 2016/04/12 00:16:06 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -1275,11 +1275,6 @@
                        case 's':
                                ntype = XK_STR;
                                break;
-#ifdef notyet
-                       case 'c':
-                               ntype = XK_EXE;
-                               break;
-#endif
                        case 'k':
                                key = 1;
                                break;
@@ -1352,7 +1347,6 @@
 
        switch (ntype) {
        case XK_STR:
-       case XK_EXE:
                if ((out = parse__string(outbuf, argv[argc])) == NULL) {
                        (void) fprintf(el->el_errfile,
                            "%ls: Invalid \\ or ^ in outstring.\n", argv[0]);
diff -r 5c2f4fde2987 -r 17c1dd6a8366 lib/libedit/read.c
--- a/lib/libedit/read.c        Mon Apr 11 23:41:15 2016 +0000
+++ b/lib/libedit/read.c        Tue Apr 12 00:16:06 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: read.c,v 1.91 2016/04/11 18:56:31 christos Exp $       */
+/*     $NetBSD: read.c,v 1.92 2016/04/12 00:16:06 christos Exp $       */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)read.c     8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: read.c,v 1.91 2016/04/11 18:56:31 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.92 2016/04/12 00:16:06 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -55,8 +55,6 @@
 
 #include "el.h"
 
-#define OKCMD  -1      /* must be -1! */
-
 static int     read__fixio(int, int);
 static int     read_char(EditLine *, wchar_t *);
 static int     read_getcmd(EditLine *, el_action_t *, wchar_t *);
@@ -98,10 +96,6 @@
 }
 
 
-#ifndef MIN
-#define MIN(A,B) ((A) < (B) ? (A) : (B))
-#endif
-
 #ifdef DEBUG_EDIT
 static void
 read_debug(EditLine *el)
@@ -203,7 +197,8 @@
 
 
 /* read_getcmd():
- *     Get next command from the input stream, return OKCMD on success.
+ *     Get next command from the input stream,
+ *     return 0 on success or -1 on EOF or error.
  *     Character values > 255 are not looked up in the map, but inserted.
  */
 static int
@@ -217,7 +212,7 @@
        do {
                if ((num = el_wgetc(el, ch)) != 1) {/* if EOF or error */
                        el->el_errno = num == 0 ? 0 : errno;
-                       return 0;       /* not OKCMD */
+                       return -1;
                }
 
 #ifdef KANJI
@@ -245,12 +240,6 @@
                        case XK_STR:
                                el_wpush(el, val.str);
                                break;
-#ifdef notyet
-                       case XK_EXE:
-                               /* XXX: In the future to run a user function */
-                               RunCommand(val.str);
-                               break;
-#endif
                        default:
                                EL_ABORT((el->el_errfile, "Bad XK_ type \n"));
                                break;
@@ -260,7 +249,7 @@
                        el->el_map.current = el->el_map.key;
        } while (cmd == ED_SEQUENCE_LEAD_IN);
        *cmdnum = cmd;
-       return OKCMD;
+       return 0;
 }
 
 /* read_char():
@@ -449,9 +438,6 @@
        wchar_t ch, *cp;
        int crlf = 0;
        int nrb;
-#ifdef FIONREAD
-       c_macro_t *ma = &el->el_chared.c_macro;
-#endif /* FIONREAD */
 
        if (nread == NULL)
                nread = &nrb;
@@ -487,7 +473,7 @@
 
 
 #ifdef FIONREAD
-       if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
+       if (el->el_tty.t_mode == EX_IO && el->el_chared.c_macro.level < 0) {
                long chrs = 0;
 
                (void) ioctl(el->el_infd, FIONREAD, &chrs);
@@ -540,17 +526,15 @@
                goto noedit;
        }
 
-       for (num = OKCMD; num == OKCMD;) {      /* while still editing this
-                                                * line */
+       for (num = -1; num == -1;) {  /* while still editing this line */
 #ifdef DEBUG_EDIT
                read_debug(el);
 #endif /* DEBUG_EDIT */
                /* if EOF or error */
-               if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
-                       num = -1;
+               if (read_getcmd(el, &cmdnum, &ch) == -1) {
 #ifdef DEBUG_READ
                        (void) fprintf(el->el_errfile,
-                           "Returning from el_gets %d\n", num);
+                           "Returning from el_gets\n");
 #endif /* DEBUG_READ */
                        break;
                }



Home | Main Index | Thread Index | Old Index