svn commit: r239589 - stable/9/lib/libedit

Pedro F. Giffuni pfg at FreeBSD.org
Wed Aug 22 20:07:00 UTC 2012


Author: pfg
Date: Wed Aug 22 20:06:59 2012
New Revision: 239589
URL: http://svn.freebsd.org/changeset/base/239589

Log:
  MFC	r238178, 238624, 238810:
  
  Re-merge a couple of changes from NetBSD libedit.
  
  bin/sh has been taught about el_gets setting the count to -1
  on error, so now we can partially revert r238173 to reduce
  differences with NetBSD's implementation.
  
  Also fix some warnings to be more in sync with NetBSD.
  
  Obtained from:	NetBSD

Modified:
  stable/9/lib/libedit/chared.c
  stable/9/lib/libedit/chared.h
  stable/9/lib/libedit/editline.3
  stable/9/lib/libedit/el.h
  stable/9/lib/libedit/makelist
  stable/9/lib/libedit/read.c
  stable/9/lib/libedit/sig.c
  stable/9/lib/libedit/sig.h
  stable/9/lib/libedit/tokenizer.c
Directory Properties:
  stable/9/lib/libedit/   (props changed)

Modified: stable/9/lib/libedit/chared.c
==============================================================================
--- stable/9/lib/libedit/chared.c	Wed Aug 22 20:05:34 2012	(r239588)
+++ stable/9/lib/libedit/chared.c	Wed Aug 22 20:06:59 2012	(r239589)
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$NetBSD: chared.c,v 1.25 2005/08/08 01:41:30 christos Exp $
+ *	$NetBSD: chared.c,v 1.27 2009/02/15 21:55:23 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
@@ -59,12 +59,12 @@ cv_undo(EditLine *el)
 {
 	c_undo_t *vu = &el->el_chared.c_undo;
 	c_redo_t *r = &el->el_chared.c_redo;
-	unsigned int size;
+	size_t size;
 
 	/* Save entire line for undo */
 	size = el->el_line.lastchar - el->el_line.buffer;
 	vu->len = size;
-	vu->cursor = el->el_line.cursor - el->el_line.buffer;
+	vu->cursor = (int)(el->el_line.cursor - el->el_line.buffer);
 	memcpy(vu->buf, el->el_line.buffer, size);
 
 	/* save command info for redo */
@@ -83,7 +83,7 @@ cv_yank(EditLine *el, const char *ptr, i
 {
 	c_kill_t *k = &el->el_chared.c_kill;
 
-	memcpy(k->buf, ptr, size +0u);
+	memcpy(k->buf, ptr, (size_t)size);
 	k->last = k->buf + size;
 }
 
@@ -97,7 +97,7 @@ c_insert(EditLine *el, int num)
 	char *cp;
 
 	if (el->el_line.lastchar + num >= el->el_line.limit) {
-		if (!ch_enlargebufs(el, num +0u))
+		if (!ch_enlargebufs(el, (size_t)num))
 			return;		/* can't go past end of buffer */
 	}
 
@@ -118,7 +118,7 @@ c_delafter(EditLine *el, int num)
 {
 
 	if (el->el_line.cursor + num > el->el_line.lastchar)
-		num = el->el_line.lastchar - el->el_line.cursor;
+		num = (int)(el->el_line.lastchar - el->el_line.cursor);
 
 	if (el->el_map.current != el->el_map.emacs) {
 		cv_undo(el);
@@ -159,7 +159,7 @@ c_delbefore(EditLine *el, int num)
 {
 
 	if (el->el_line.cursor - num < el->el_line.buffer)
-		num = el->el_line.cursor - el->el_line.buffer;
+		num = (int)(el->el_line.cursor - el->el_line.buffer);
 
 	if (el->el_map.current != el->el_map.emacs) {
 		cv_undo(el);
@@ -375,7 +375,7 @@ cv_delfini(EditLine *el)
 		/* sanity */
 		return;
 
-	size = el->el_line.cursor - el->el_chared.c_vcmd.pos;
+	size = (int)(el->el_line.cursor - el->el_chared.c_vcmd.pos);
 	if (size == 0)
 		size = 1;
 	el->el_line.cursor = el->el_chared.c_vcmd.pos;
@@ -529,8 +529,7 @@ ch_reset(EditLine *el, int mclear)
 }
 
 private void
-ch__clearmacro(el)
-	EditLine *el;
+ch__clearmacro(EditLine *el)
 {
 	c_macro_t *ma = &el->el_chared.c_macro;
 	while (ma->level >= 0)
@@ -542,9 +541,7 @@ ch__clearmacro(el)
  *	Returns 1 if successful, 0 if not.
  */
 protected int
-ch_enlargebufs(el, addlen)
-	EditLine *el;
-	size_t addlen;
+ch_enlargebufs(EditLine *el, size_t addlen)
 {
 	size_t sz, newsz;
 	char *newbuffer, *oldbuf, *oldkbuf;
@@ -695,12 +692,12 @@ protected int
 c_gets(EditLine *el, char *buf, const char *prompt)
 {
 	char ch;
-	int len;
+	ssize_t len;
 	char *cp = el->el_line.buffer;
 
 	if (prompt) {
 		len = strlen(prompt);
-		memcpy(cp, prompt, len + 0u);
+		memcpy(cp, prompt, (size_t)len);
 		cp += len;
 	}
 	len = 0;
@@ -721,7 +718,7 @@ c_gets(EditLine *el, char *buf, const ch
 
 		case '\010':	/* Delete and backspace */
 		case '\177':
-			if (len <= 0) {
+			if (len == 0) {
 				len = -1;
 				break;
 			}
@@ -749,7 +746,7 @@ c_gets(EditLine *el, char *buf, const ch
 	el->el_line.buffer[0] = '\0';
 	el->el_line.lastchar = el->el_line.buffer;
 	el->el_line.cursor = el->el_line.buffer;
-	return len;
+	return (int)len;
 }
 
 
@@ -771,6 +768,6 @@ c_hpos(EditLine *el)
 		     ptr >= el->el_line.buffer && *ptr != '\n';
 		     ptr--)
 			continue;
-		return (el->el_line.cursor - ptr - 1);
+		return (int)(el->el_line.cursor - ptr - 1);
 	}
 }

Modified: stable/9/lib/libedit/chared.h
==============================================================================
--- stable/9/lib/libedit/chared.h	Wed Aug 22 20:05:34 2012	(r239588)
+++ stable/9/lib/libedit/chared.h	Wed Aug 22 20:06:59 2012	(r239589)
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)chared.h	8.1 (Berkeley) 6/4/93
- *	$NetBSD: chared.h,v 1.17 2006/03/06 21:11:56 christos Exp $
+ *	$NetBSD: chared.h,v 1.18 2009/02/15 21:55:23 christos Exp $
  * $FreeBSD$
  */
 
@@ -70,7 +70,7 @@ typedef struct c_macro_t {
  * Undo information for vi - no undo in emacs (yet)
  */
 typedef struct c_undo_t {
-	int	 len;			/* length of saved line */
+	ssize_t	 len;			/* length of saved line */
 	int	 cursor;		/* position of saved cursor */
 	char	*buf;			/* full saved text */
 } c_undo_t;

Modified: stable/9/lib/libedit/editline.3
==============================================================================
--- stable/9/lib/libedit/editline.3	Wed Aug 22 20:05:34 2012	(r239588)
+++ stable/9/lib/libedit/editline.3	Wed Aug 22 20:06:59 2012	(r239589)
@@ -162,6 +162,11 @@ is modified to contain the number of cha
 Returns the line read if successful, or
 .Dv NULL
 if no characters were read or if an error occurred.
+If an error occurred,
+.Fa count
+is set to \-1 and
+.Dv errno
+contains the error code that caused it.
 The return value may not remain valid across calls to
 .Fn el_gets
 and must be copied if the data is to be retained.

Modified: stable/9/lib/libedit/el.h
==============================================================================
--- stable/9/lib/libedit/el.h	Wed Aug 22 20:05:34 2012	(r239588)
+++ stable/9/lib/libedit/el.h	Wed Aug 22 20:06:59 2012	(r239589)
@@ -115,6 +115,7 @@ struct editline {
 	FILE		 *el_errfile;	/* Stdio stuff			*/
 	int		  el_infd;	/* Input file descriptor	*/
 	int		  el_flags;	/* Various flags.		*/
+	int		  el_errno;	/* Local copy of errno		*/
 	coord_t		  el_cursor;	/* Cursor location		*/
 	char		**el_display;	/* Real screen image = what is there */
 	char		**el_vdisplay;	/* Virtual screen image = what we see */

Modified: stable/9/lib/libedit/makelist
==============================================================================
--- stable/9/lib/libedit/makelist	Wed Aug 22 20:05:34 2012	(r239588)
+++ stable/9/lib/libedit/makelist	Wed Aug 22 20:06:59 2012	(r239589)
@@ -1,5 +1,5 @@
 #!/bin/sh -
-#	$NetBSD: makelist,v 1.10 2005/08/08 14:04:49 christos Exp $
+#	$NetBSD: makelist,v 1.11 2005/10/22 16:45:03 christos Exp $
 # $FreeBSD$
 #
 # Copyright (c) 1992, 1993
@@ -141,7 +141,7 @@ case $FLAG in
 #
 -fh)
     cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
-    sort | LC_ALL=C tr 'a-z' 'A-Z' | $AWK '
+    sort | LC_ALL=C tr '[:lower:]' '[:upper:]' | $AWK '
 	BEGIN {
 	    printf("/* Automatically generated file, do not edit */\n");
 	    printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");

Modified: stable/9/lib/libedit/read.c
==============================================================================
--- stable/9/lib/libedit/read.c	Wed Aug 22 20:05:34 2012	(r239588)
+++ stable/9/lib/libedit/read.c	Wed Aug 22 20:06:59 2012	(r239589)
@@ -235,9 +235,12 @@ read_getcmd(EditLine *el, el_action_t *c
 	el_action_t cmd;
 	int num;
 
+	el->el_errno = 0;
 	do {
-		if ((num = el_getc(el, ch)) != 1)	/* if EOF or error */
+		if ((num = el_getc(el, ch)) != 1) {	/* if EOF or error */
+			el->el_errno = num == 0 ? 0 : errno;
 			return (num);
+		}
 
 #ifdef	KANJI
 		if ((*ch & 0200)) {
@@ -289,14 +292,21 @@ read_char(EditLine *el, char *cp)
 	ssize_t num_read;
 	int tried = 0;
 
-	while ((num_read = read(el->el_infd, cp, 1)) == -1)
+ again:
+	el->el_signal->sig_no = 0;
+	while ((num_read = read(el->el_infd, cp, 1)) == -1) {
+		if (el->el_signal->sig_no == SIGCONT) {
+			sig_set(el);
+			el_set(el, EL_REFRESH);
+			goto again;
+		}
 		if (!tried && read__fixio(el->el_infd, errno) == 0)
 			tried = 1;
 		else {
 			*cp = '\0';
 			return (-1);
 		}
-
+	}
 	return (int)num_read;
 }
 
@@ -403,10 +413,13 @@ el_gets(EditLine *el, int *nread)
 	int num;		/* how many chars we have read at NL */
 	char ch;
 	int crlf = 0;
+	int nrb;
 #ifdef FIONREAD
 	c_macro_t *ma = &el->el_chared.c_macro;
 #endif /* FIONREAD */
 
+	if (nread == NULL)
+		nread = &nrb;
 	*nread = 0;
 
 	if (el->el_flags & NO_TTY) {
@@ -427,12 +440,13 @@ el_gets(EditLine *el, int *nread)
 			if (cp[-1] == '\r' || cp[-1] == '\n')
 				break;
 		}
+		if (num == -1)
+			el->el_errno = errno;
 
 		el->el_line.cursor = el->el_line.lastchar = cp;
 		*cp = '\0';
-		if (nread)
-			*nread = (int)(el->el_line.cursor - el->el_line.buffer);
-		return (*nread ? el->el_line.buffer : NULL);
+		*nread = (int)(el->el_line.cursor - el->el_line.buffer);
+		goto done;
 	}
 
 
@@ -443,8 +457,8 @@ el_gets(EditLine *el, int *nread)
 		(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
 		if (chrs == 0) {
 			if (tty_rawmode(el) < 0) {
-				if (nread)
-					*nread = 0;
+				errno = 0;
+				*nread = 0;
 				return (NULL);
 			}
 		}
@@ -457,6 +471,7 @@ el_gets(EditLine *el, int *nread)
 	if (el->el_flags & EDIT_DISABLED) {
 		char *cp;
 		size_t idx;
+
 		if ((el->el_flags & UNBUFFERED) == 0)
 			cp = el->el_line.buffer;
 		else
@@ -480,11 +495,13 @@ el_gets(EditLine *el, int *nread)
 				break;
 		}
 
+		if (num == -1) {
+			el->el_errno = errno;
+		}
+
 		el->el_line.cursor = el->el_line.lastchar = cp;
 		*cp = '\0';
-		if (nread)
-			*nread = (int)(el->el_line.cursor - el->el_line.buffer);
-		return (*nread ? el->el_line.buffer : NULL);
+		goto done;
 	}
 
 	for (num = OKCMD; num == OKCMD;) {	/* while still editing this
@@ -617,12 +634,17 @@ el_gets(EditLine *el, int *nread)
 	/* make sure the tty is set up correctly */
 	if ((el->el_flags & UNBUFFERED) == 0) {
 		read_finish(el);
-		if (nread)
-			*nread = num;
+		*nread = num != -1 ? num : 0;
 	} else {
-		if (nread)
-			*nread =
-			    (int)(el->el_line.lastchar - el->el_line.buffer);
+		*nread = (int)(el->el_line.lastchar - el->el_line.buffer);
 	}
-	return (num ? el->el_line.buffer : NULL);
+done:
+	if (*nread == 0) {
+		if (num == -1) {
+			*nread = -1;
+			errno = el->el_errno;
+		}
+		return NULL;
+	} else
+		return el->el_line.buffer;
 }

Modified: stable/9/lib/libedit/sig.c
==============================================================================
--- stable/9/lib/libedit/sig.c	Wed Aug 22 20:05:34 2012	(r239588)
+++ stable/9/lib/libedit/sig.c	Wed Aug 22 20:06:59 2012	(r239589)
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$NetBSD: sig.c,v 1.14 2009/02/18 15:04:40 christos Exp $
+ *	$NetBSD: sig.c,v 1.15 2009/02/19 15:20:22 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
@@ -73,6 +73,8 @@ sig_handler(int signo)
 	(void) sigaddset(&nset, signo);
 	(void) sigprocmask(SIG_BLOCK, &nset, &oset);
 
+	sel->el_signal->sig_no = signo;
+
 	switch (signo) {
 	case SIGCONT:
 		tty_rawmode(sel);
@@ -158,12 +160,12 @@ sig_set(EditLine *el)
 	struct sigaction osa, nsa;
 
 	nsa.sa_handler = sig_handler;
+	nsa.sa_flags = 0;
 	sigemptyset(&nsa.sa_mask);
 
 	(void) sigprocmask(SIG_BLOCK, &el->el_signal->sig_set, &oset);
 
 	for (i = 0; sighdl[i] != -1; i++) {
-		nsa.sa_flags = SIGINT ? 0 : SA_RESTART;
 		/* This could happen if we get interrupted */
 		if (sigaction(sighdl[i], &nsa, &osa) != -1 &&
 		    osa.sa_handler != sig_handler)

Modified: stable/9/lib/libedit/sig.h
==============================================================================
--- stable/9/lib/libedit/sig.h	Wed Aug 22 20:05:34 2012	(r239588)
+++ stable/9/lib/libedit/sig.h	Wed Aug 22 20:06:59 2012	(r239589)
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)sig.h	8.1 (Berkeley) 6/4/93
- *	$NetBSD: sig.h,v 1.7 2009/02/15 21:25:01 christos Exp $
+ *	$NetBSD: sig.h,v 1.8 2009/02/19 15:20:22 christos Exp $
  * $FreeBSD$
  */
 
@@ -61,6 +61,7 @@
 typedef struct {
 	struct sigaction sig_action[ALLSIGSNO];
 	sigset_t sig_set;
+	volatile sig_atomic_t sig_no;
 } *el_signal_t;
 
 protected void	sig_end(EditLine*);

Modified: stable/9/lib/libedit/tokenizer.c
==============================================================================
--- stable/9/lib/libedit/tokenizer.c	Wed Aug 22 20:05:34 2012	(r239588)
+++ stable/9/lib/libedit/tokenizer.c	Wed Aug 22 20:06:59 2012	(r239589)
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$NetBSD: tokenizer.c,v 1.14 2003/12/05 13:37:48 lukem Exp $
+ *	$NetBSD: tokenizer.c,v 1.15 2009/02/15 21:55:23 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
@@ -198,7 +198,7 @@ tok_line(Tokenizer *tok, const LineInfo 
 			ptr = "";
 		if (ptr == line->cursor) {
 			cc = tok->argc;
-			co = tok->wptr - tok->wstart;
+			co = (int)(tok->wptr - tok->wstart);
 		}
 		switch (*ptr) {
 		case '\'':
@@ -417,7 +417,7 @@ tok_line(Tokenizer *tok, const LineInfo 
  tok_line_outok:
 	if (cc == -1 && co == -1) {
 		cc = tok->argc;
-		co = tok->wptr - tok->wstart;
+		co = (int)(tok->wptr - tok->wstart);
 	}
 	if (cursorc != NULL)
 		*cursorc = cc;


More information about the svn-src-stable mailing list