Module Name:    src
Committed By:   christos
Date:           Tue Apr 12 00:16:06 UTC 2016

Modified Files:
        src/lib/libedit: keymacro.c keymacro.h map.c read.c

Log Message:
>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.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libedit/keymacro.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libedit/keymacro.h
cvs rdiff -u -r1.47 -r1.48 src/lib/libedit/map.c
cvs rdiff -u -r1.91 -r1.92 src/lib/libedit/read.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libedit/keymacro.c
diff -u src/lib/libedit/keymacro.c:1.19 src/lib/libedit/keymacro.c:1.20
--- src/lib/libedit/keymacro.c:1.19	Mon Apr 11 14:56:31 2016
+++ src/lib/libedit/keymacro.c	Mon Apr 11 20:16:06 2016
@@ -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 @@ __RCSID("$NetBSD: keymacro.c,v 1.19 2016
  *	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 @@ keymacro_reset(EditLine *el)
  *	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 @@ node__try(EditLine *el, keymacro_node_t 
 		case XK_NOD:
 			break;
 		case XK_STR:
-		case XK_EXE:
 			if (ptr->val.str)
 				el_free(ptr->val.str);
 			break;
@@ -356,7 +355,6 @@ node__try(EditLine *el, keymacro_node_t 
 			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 @@ node__put(EditLine *el, keymacro_node_t 
 	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 @@ keymacro_kprint(EditLine *el, const wcha
 	if (val != NULL)
 		switch (ntype) {
 		case XK_STR:
-		case XK_EXE:
 			(void) keymacro__decode_str(val->str, unparsbuf,
 			    sizeof(unparsbuf),
 			    ntype == XK_STR ? "\"\"" : "[]");

Index: src/lib/libedit/keymacro.h
diff -u src/lib/libedit/keymacro.h:1.4 src/lib/libedit/keymacro.h:1.5
--- src/lib/libedit/keymacro.h:1.4	Sun Apr 10 20:50:13 2016
+++ src/lib/libedit/keymacro.h	Mon Apr 11 20:16:06 2016
@@ -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 @@ typedef struct el_keymacro_t {
 #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 *);

Index: src/lib/libedit/map.c
diff -u src/lib/libedit/map.c:1.47 src/lib/libedit/map.c:1.48
--- src/lib/libedit/map.c:1.47	Mon Apr 11 14:56:31 2016
+++ src/lib/libedit/map.c	Mon Apr 11 20:16:06 2016
@@ -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 @@ map_bind(EditLine *el, int argc, const w
 			case 's':
 				ntype = XK_STR;
 				break;
-#ifdef notyet
-			case 'c':
-				ntype = XK_EXE;
-				break;
-#endif
 			case 'k':
 				key = 1;
 				break;
@@ -1352,7 +1347,6 @@ map_bind(EditLine *el, int argc, const w
 
 	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]);

Index: src/lib/libedit/read.c
diff -u src/lib/libedit/read.c:1.91 src/lib/libedit/read.c:1.92
--- src/lib/libedit/read.c:1.91	Mon Apr 11 14:56:31 2016
+++ src/lib/libedit/read.c	Mon Apr 11 20:16:06 2016
@@ -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 @@ __RCSID("$NetBSD: read.c,v 1.91 2016/04/
 
 #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 @@ el_read_getfn(EditLine *el)
 }
 
 
-#ifndef MIN
-#define MIN(A,B) ((A) < (B) ? (A) : (B))
-#endif
-
 #ifdef DEBUG_EDIT
 static void
 read_debug(EditLine *el)
@@ -203,7 +197,8 @@ el_wpush(EditLine *el, const wchar_t *st
 
 
 /* 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 @@ read_getcmd(EditLine *el, el_action_t *c
 	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 @@ read_getcmd(EditLine *el, el_action_t *c
 			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 @@ read_getcmd(EditLine *el, el_action_t *c
 			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 @@ el_wgets(EditLine *el, int *nread)
 	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 @@ el_wgets(EditLine *el, int *nread)
 
 
 #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 @@ el_wgets(EditLine *el, int *nread)
 		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;
 		}

Reply via email to