svn commit: r268783 - in stable/9/lib/libedit: . TEST

Pedro F. Giffuni pfg at FreeBSD.org
Thu Jul 17 02:22:06 UTC 2014


Author: pfg
Date: Thu Jul 17 02:22:03 2014
New Revision: 268783
URL: http://svnweb.freebsd.org/changeset/base/268783

Log:
  MFC	r268502:
  Sync some (mostly cosmetical) changes from NetBSD
  
  Makefile,v 1.37
  tc1.c v 1.3
  Rename TEST/test.c tc1.c
  
  common.c,v 1.23
  pass lint on _LP64.
  
  emacs.c,v 1.22
  pass lint on _LP64.
  
  filecomplete.h,v 1.8
  mv NetBSD ID back from 1.9 as we don't
  have the widecharacter support.
  
  prompt.c,v 1.14
  prompt.h,v 1.9
  term.h,v 1.20
  read.h,v 1.6
  Update NetBSD version strings
  
  sys.h,v 1.12
  Misc sun stuff.
  
  tty.c 1.31
  handle EINTR in the termios operations
  Allow a single process to control multiple ttys (for pthreads using _REENTRANT)
  using multiple EditLine objects.
  pass lint on _LP64.
  Don't depend on side effects inside an assert
  
  Obtained from:	NetBSD

Added:
  stable/9/lib/libedit/TEST/tc1.c
     - copied unchanged from r268502, head/lib/libedit/TEST/tc1.c
Deleted:
  stable/9/lib/libedit/TEST/test.c
Modified:
  stable/9/lib/libedit/Makefile
  stable/9/lib/libedit/common.c
  stable/9/lib/libedit/emacs.c
  stable/9/lib/libedit/filecomplete.h
  stable/9/lib/libedit/histedit.h
  stable/9/lib/libedit/prompt.c
  stable/9/lib/libedit/prompt.h
  stable/9/lib/libedit/read.h
  stable/9/lib/libedit/sys.h
  stable/9/lib/libedit/term.h
  stable/9/lib/libedit/tty.c
Directory Properties:
  stable/9/lib/libedit/   (props changed)

Modified: stable/9/lib/libedit/Makefile
==============================================================================
--- stable/9/lib/libedit/Makefile	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/Makefile	Thu Jul 17 02:22:03 2014	(r268783)
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.34 2005/05/28 12:02:53 lukem Exp $
+#	$NetBSD: Makefile,v 1.37 2009/01/18 12:17:49 lukem Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 # $FreeBSD$
 
@@ -70,9 +70,9 @@ editline.c: ${OSRCS}
 editline.o editline.po editline.So editline.ln:	\
 	common.h emacs.h fcns.c fcns.h help.c help.h vi.h
 
-test.o: ${.CURDIR}/TEST/test.c
+tc1.o: ${.CURDIR}/TEST/tc1.c
 
-test: test.o libedit.a ${DPADD} ${LIBTERMCAP}
+test: tc1.o libedit.a ${DPADD} ${LIBTERMCAP}
 	${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD}
 
 .include <bsd.lib.mk>

Copied: stable/9/lib/libedit/TEST/tc1.c (from r268502, head/lib/libedit/TEST/tc1.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/lib/libedit/TEST/tc1.c	Thu Jul 17 02:22:03 2014	(r268783, copy of r268502, head/lib/libedit/TEST/tc1.c)
@@ -0,0 +1,298 @@
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Christos Zoulas of Cornell University.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
+	The Regents of the University of California.  All rights reserved.\n");
+#endif /* not lint */
+
+#if !defined(lint) && !defined(SCCSID)
+static char sccsid[] = "@(#)test.c	8.1 (Berkeley) 6/4/93";
+#endif /* not lint && not SCCSID */
+__RCSID("$NetBSD: test.c,v 1.3 2009/07/17 12:25:52 christos Exp $");
+__FBSDID("$FreeBSD$");
+
+/*
+ * test.c: A little test program
+ */
+#include "sys.h"
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dirent.h>
+
+#include "histedit.h"
+
+static int continuation = 0;
+volatile sig_atomic_t gotsig = 0;
+
+static	unsigned char	complete(EditLine *, int);
+	int	main(int, char **);
+static	char   *prompt(EditLine *);
+static	void	sig(int);
+
+static char *
+prompt(EditLine *el)
+{
+	static char a[] = "\1\e[7m\1Edit$\1\e[0m\1 ";
+	static char b[] = "Edit> ";
+
+	return (continuation ? b : a);
+}
+
+static void
+sig(int i)
+{
+	gotsig = i;
+}
+
+static unsigned char
+complete(EditLine *el, int ch)
+{
+	DIR *dd = opendir(".");
+	struct dirent *dp;
+	const char* ptr;
+	const LineInfo *lf = el_line(el);
+	int len;
+
+	/*
+	 * Find the last word
+	 */
+	for (ptr = lf->cursor - 1;
+	    !isspace((unsigned char)*ptr) && ptr > lf->buffer; ptr--)
+		continue;
+	len = lf->cursor - ++ptr;
+
+	for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
+		if (len > strlen(dp->d_name))
+			continue;
+		if (strncmp(dp->d_name, ptr, len) == 0) {
+			closedir(dd);
+			if (el_insertstr(el, &dp->d_name[len]) == -1)
+				return (CC_ERROR);
+			else
+				return (CC_REFRESH);
+		}
+	}
+
+	closedir(dd);
+	return (CC_ERROR);
+}
+
+int
+main(int argc, char *argv[])
+{
+	EditLine *el = NULL;
+	int num;
+	const char *buf;
+	Tokenizer *tok;
+#if 0
+	int lastevent = 0;
+#endif
+	int ncontinuation;
+	History *hist;
+	HistEvent ev;
+
+	(void) signal(SIGINT, sig);
+	(void) signal(SIGQUIT, sig);
+	(void) signal(SIGHUP, sig);
+	(void) signal(SIGTERM, sig);
+
+	hist = history_init();		/* Init the builtin history	*/
+					/* Remember 100 events		*/
+	history(hist, &ev, H_SETSIZE, 100);
+
+	tok  = tok_init(NULL);		/* Initialize the tokenizer	*/
+
+					/* Initialize editline		*/
+	el = el_init(*argv, stdin, stdout, stderr);
+
+	el_set(el, EL_EDITOR, "vi");	/* Default editor is vi		*/
+	el_set(el, EL_SIGNAL, 1);	/* Handle signals gracefully	*/
+	el_set(el, EL_PROMPT_ESC, prompt, '\1');/* Set the prompt function */
+
+			/* Tell editline to use this history interface	*/
+	el_set(el, EL_HIST, history, hist);
+
+					/* Add a user-defined function	*/
+	el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
+
+					/* Bind tab to it 		*/
+	el_set(el, EL_BIND, "^I", "ed-complete", NULL);
+
+	/*
+	 * Bind j, k in vi command mode to previous and next line, instead
+	 * of previous and next history.
+	 */
+	el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
+	el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
+
+	/*
+	 * Source the user's defaults file.
+	 */
+	el_source(el, NULL);
+
+	while ((buf = el_gets(el, &num)) != NULL && num != 0)  {
+		int ac, cc, co;
+#ifdef DEBUG
+		int i;
+#endif
+		const char **av;
+		const LineInfo *li;
+		li = el_line(el);
+#ifdef DEBUG
+		(void) fprintf(stderr, "==> got %d %s", num, buf);
+		(void) fprintf(stderr, "  > li `%.*s_%.*s'\n",
+		    (li->cursor - li->buffer), li->buffer,
+		    (li->lastchar - 1 - li->cursor),
+		    (li->cursor >= li->lastchar) ? "" : li->cursor);
+
+#endif
+		if (gotsig) {
+			(void) fprintf(stderr, "Got signal %d.\n", (int)gotsig);
+			gotsig = 0;
+			el_reset(el);
+		}
+
+		if (!continuation && num == 1)
+			continue;
+
+		ac = cc = co = 0;
+		ncontinuation = tok_line(tok, li, &ac, &av, &cc, &co);
+		if (ncontinuation < 0) {
+			(void) fprintf(stderr, "Internal error\n");
+			continuation = 0;
+			continue;
+		}
+#ifdef DEBUG
+		(void) fprintf(stderr, "  > nc %d ac %d cc %d co %d\n",
+		    ncontinuation, ac, cc, co);
+#endif
+#if 0
+		if (continuation) {
+			/*
+			 * Append to the right event in case the user
+			 * moved around in history.
+			 */
+			if (history(hist, &ev, H_SET, lastevent) == -1)
+				err(1, "%d: %s", lastevent, ev.str);
+			history(hist, &ev, H_ADD , buf);
+		} else {
+			history(hist, &ev, H_ENTER, buf);
+			lastevent = ev.num;
+		}
+#else
+				/* Simpler */
+		history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf);
+#endif
+
+		continuation = ncontinuation;
+		ncontinuation = 0;
+		if (continuation)
+			continue;
+#ifdef DEBUG
+		for (i = 0; i < ac; i++) {
+			(void) fprintf(stderr, "  > arg# %2d ", i);
+			if (i != cc)
+				(void) fprintf(stderr, "`%s'\n", av[i]);
+			else
+				(void) fprintf(stderr, "`%.*s_%s'\n",
+				    co, av[i], av[i] + co);
+		}
+#endif
+
+		if (strcmp(av[0], "history") == 0) {
+			int rv;
+
+			switch (ac) {
+			case 1:
+				for (rv = history(hist, &ev, H_LAST); rv != -1;
+				    rv = history(hist, &ev, H_PREV))
+					(void) fprintf(stdout, "%4d %s",
+					    ev.num, ev.str);
+				break;
+
+			case 2:
+				if (strcmp(av[1], "clear") == 0)
+					 history(hist, &ev, H_CLEAR);
+				else
+					 goto badhist;
+				break;
+
+			case 3:
+				if (strcmp(av[1], "load") == 0)
+					 history(hist, &ev, H_LOAD, av[2]);
+				else if (strcmp(av[1], "save") == 0)
+					 history(hist, &ev, H_SAVE, av[2]);
+				break;
+
+			badhist:
+			default:
+				(void) fprintf(stderr,
+				    "Bad history arguments\n");
+				break;
+			}
+		} else if (el_parse(el, ac, av) == -1) {
+			switch (fork()) {
+			case 0:
+				execvp(av[0], __DECONST(char *const *, av));
+				perror(av[0]);
+				_exit(1);
+				/*NOTREACHED*/
+				break;
+
+			case -1:
+				perror("fork");
+				break;
+
+			default:
+				if (wait(&num) == -1)
+					perror("wait");
+				(void) fprintf(stderr, "Exit %x\n", num);
+				break;
+			}
+		}
+
+		tok_reset(tok);
+	}
+
+	el_end(el);
+	tok_end(tok);
+	history_end(hist);
+
+	return (0);
+}

Modified: stable/9/lib/libedit/common.c
==============================================================================
--- stable/9/lib/libedit/common.c	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/common.c	Thu Jul 17 02:22:03 2014	(r268783)
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$NetBSD: common.c,v 1.19 2006/03/06 21:11:56 christos Exp $
+ *	$NetBSD: common.c,v 1.23 2009/02/27 04:18:45 msaitoh Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
@@ -121,7 +121,7 @@ ed_delete_prev_word(EditLine *el, int c 
 		*kp++ = *p;
 	el->el_chared.c_kill.last = kp;
 
-	c_delbefore(el, el->el_line.cursor - cp);	/* delete before dot */
+	c_delbefore(el, (int)(el->el_line.cursor - cp));/* delete before dot */
 	el->el_line.cursor = cp;
 	if (el->el_line.cursor < el->el_line.buffer)
 		el->el_line.cursor = el->el_line.buffer; /* bounds check */
@@ -208,9 +208,6 @@ ed_move_to_end(EditLine *el, int c __unu
 
 	el->el_line.cursor = el->el_line.lastchar;
 	if (el->el_map.type == MAP_VI) {
-#ifdef VI_MOVE
-		el->el_line.cursor--;
-#endif
 		if (el->el_chared.c_vcmd.action != NOP) {
 			cv_delfini(el);
 			return (CC_REFRESH);

Modified: stable/9/lib/libedit/emacs.c
==============================================================================
--- stable/9/lib/libedit/emacs.c	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/emacs.c	Thu Jul 17 02:22:03 2014	(r268783)
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$NetBSD: emacs.c,v 1.21 2006/03/06 21:11:56 christos Exp $
+ *	$NetBSD: emacs.c,v 1.22 2009/02/15 21:55:23 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
@@ -101,7 +101,7 @@ em_delete_next_word(EditLine *el, int c 
 		*kp++ = *p;
 	el->el_chared.c_kill.last = kp;
 
-	c_delafter(el, cp - el->el_line.cursor);	/* delete after dot */
+	c_delafter(el, (int)(cp - el->el_line.cursor));	/* delete after dot */
 	if (el->el_line.cursor > el->el_line.lastchar)
 		el->el_line.cursor = el->el_line.lastchar;
 				/* bounds check */
@@ -131,7 +131,8 @@ em_yank(EditLine *el, int c __unused)
 	cp = el->el_line.cursor;
 
 	/* open the space, */
-	c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
+	c_insert(el,
+	    (int)(el->el_chared.c_kill.last - el->el_chared.c_kill.buf));
 	/* copy the chars */
 	for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
 		*cp++ = *kp;
@@ -185,14 +186,14 @@ em_kill_region(EditLine *el, int c __unu
 		while (cp < el->el_chared.c_kill.mark)
 			*kp++ = *cp++;	/* copy it */
 		el->el_chared.c_kill.last = kp;
-		c_delafter(el, cp - el->el_line.cursor);
+		c_delafter(el, (int)(cp - el->el_line.cursor));
 	} else {		/* mark is before cursor */
 		cp = el->el_chared.c_kill.mark;
 		kp = el->el_chared.c_kill.buf;
 		while (cp < el->el_line.cursor)
 			*kp++ = *cp++;	/* copy it */
 		el->el_chared.c_kill.last = kp;
-		c_delbefore(el, cp - el->el_chared.c_kill.mark);
+		c_delbefore(el, (int)(cp - el->el_chared.c_kill.mark));
 		el->el_line.cursor = el->el_chared.c_kill.mark;
 	}
 	return (CC_REFRESH);
@@ -446,7 +447,7 @@ em_copy_prev_word(EditLine *el, int c __
 	cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
 	    el->el_state.argument, ce__isword);
 
-	c_insert(el, oldc - cp);
+	c_insert(el, (int)(oldc - cp));
 	for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
 		*dp++ = *cp;
 

Modified: stable/9/lib/libedit/filecomplete.h
==============================================================================
--- stable/9/lib/libedit/filecomplete.h	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/filecomplete.h	Thu Jul 17 02:22:03 2014	(r268783)
@@ -26,7 +26,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- *	$NetBSD: filecomplete.h,v 1.9 2009/12/30 22:37:40 christos Exp $
+ *	$NetBSD: filecomplete.h,v 1.8 2009/02/16 00:15:45 christos Exp $
  * $FreeBSD$
  */
 #ifndef _FILECOMPLETE_H_

Modified: stable/9/lib/libedit/histedit.h
==============================================================================
--- stable/9/lib/libedit/histedit.h	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/histedit.h	Thu Jul 17 02:22:03 2014	(r268783)
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)histedit.h	8.2 (Berkeley) 1/3/94
- *	$NetBSD: histedit.h,v 1.32 2007/06/10 20:20:28 christos Exp $
+ *	$NetBSD: histedit.h,v 1.41 2009/09/07 21:24:33 christos Exp $
  * $FreeBSD$
  */
 

Modified: stable/9/lib/libedit/prompt.c
==============================================================================
--- stable/9/lib/libedit/prompt.c	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/prompt.c	Thu Jul 17 02:22:03 2014	(r268783)
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$NetBSD: prompt.c,v 1.11 2003/08/07 16:44:32 agc Exp $
+ *	$NetBSD: prompt.c,v 1.14 2009/03/31 17:38:27 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)

Modified: stable/9/lib/libedit/prompt.h
==============================================================================
--- stable/9/lib/libedit/prompt.h	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/prompt.h	Thu Jul 17 02:22:03 2014	(r268783)
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)prompt.h	8.1 (Berkeley) 6/4/93
- *	$NetBSD: prompt.h,v 1.6 2003/08/07 16:44:32 agc Exp $
+ *	$NetBSD: prompt.h,v 1.9 2009/03/31 17:38:27 christos Exp $
  * $FreeBSD$
  */
 
@@ -45,8 +45,8 @@
 typedef char * (*el_pfunc_t)(EditLine*);
 
 typedef struct el_prompt_t {
-	el_pfunc_t	p_func;	/* Function to return the prompt	*/
-	coord_t		p_pos;	/* position in the line after prompt	*/
+	el_pfunc_t	p_func;		/* Function to return the prompt */
+	coord_t		p_pos;		/* position in the line after prompt */
 	char		p_ignore;	/* character to start/end literal 
 */
 } el_prompt_t;

Modified: stable/9/lib/libedit/read.h
==============================================================================
--- stable/9/lib/libedit/read.h	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/read.h	Thu Jul 17 02:22:03 2014	(r268783)
@@ -26,7 +26,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  *
- *	$NetBSD: read.h,v 1.5 2006/08/21 12:45:30 christos Exp $
+ *	$NetBSD: read.h,v 1.6 2008/04/29 06:53:01 martin Exp $
  * $FreeBSD$
  */
 

Modified: stable/9/lib/libedit/sys.h
==============================================================================
--- stable/9/lib/libedit/sys.h	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/sys.h	Thu Jul 17 02:22:03 2014	(r268783)
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)sys.h	8.1 (Berkeley) 6/4/93
- *	$NetBSD: sys.h,v 1.9 2004/01/17 17:57:40 christos Exp $
+ *	$NetBSD: sys.h,v 1.12 2009/08/31 00:05:43 christos Exp $
  * $FreeBSD$
  */
 
@@ -70,6 +70,15 @@ typedef void	*ioctl_t;
 #define	REGEX		/* Use POSIX.2 regular expression functions */
 #undef	REGEXP		/* Use UNIX V8 regular expression functions */
 
+#if defined(__sun)
+extern int tgetent(char *, const char *);
+extern int tgetflag(char *);
+extern int tgetnum(char *);
+extern int tputs(const char *, int, int (*)(int));
+extern char* tgoto(const char*, int, int);
+extern char* tgetstr(char*, char**);
+#endif
+
 #ifdef notdef
 # undef REGEX
 # undef REGEXP

Modified: stable/9/lib/libedit/term.h
==============================================================================
--- stable/9/lib/libedit/term.h	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/term.h	Thu Jul 17 02:22:03 2014	(r268783)
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *	@(#)term.h	8.1 (Berkeley) 6/4/93
- *	$NetBSD: term.h,v 1.18 2006/11/24 00:01:17 christos Exp $
+ *	$NetBSD: term.h,v 1.20 2009/03/31 17:38:27 christos Exp $
  * $FreeBSD$
  */
 

Modified: stable/9/lib/libedit/tty.c
==============================================================================
--- stable/9/lib/libedit/tty.c	Thu Jul 17 02:14:25 2014	(r268782)
+++ stable/9/lib/libedit/tty.c	Thu Jul 17 02:22:03 2014	(r268783)
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *	$NetBSD: tty.c,v 1.25 2006/03/18 09:09:41 christos Exp $
+ *	$NetBSD: tty.c,v 1.31 2009/07/22 15:58:09 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
@@ -443,13 +443,12 @@ private const ttymodes_t ttymodes[] = {
 
 
 
-#define	tty_getty(el, td)	tcgetattr((el)->el_infd, (td))
-#define	tty_setty(el, td)	tcsetattr((el)->el_infd, TCSADRAIN, (td))
-
 #define	tty__gettabs(td)	((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1)
 #define	tty__geteightbit(td)	(((td)->c_cflag & CSIZE) == CS8)
 #define	tty__cooked_mode(td)	((td)->c_lflag & ICANON)
 
+private int	tty_getty(EditLine *, struct termios *);
+private int	tty_setty(EditLine *, int, const struct termios *);
 private int	tty__getcharindex(int);
 private void	tty__getchar(struct termios *, unsigned char *);
 private void	tty__setchar(struct termios *, unsigned char *);
@@ -458,6 +457,29 @@ private int	tty_setup(EditLine *);
 
 #define	t_qu	t_ts
 
+/* tty_getty():
+ *	Wrapper for tcgetattr to handle EINTR
+ */
+private int
+tty_getty(EditLine *el, struct termios *t)
+{
+	int rv;
+	while ((rv = tcgetattr(el->el_infd, t)) == -1 && errno == EINTR)
+		continue;
+	return rv;
+}
+
+/* tty_setty():
+ *	Wrapper for tcsetattr to handle EINTR
+ */
+private int
+tty_setty(EditLine *el, int action, const struct termios *t)
+{
+	int rv;
+	while ((rv = tcsetattr(el->el_infd, action, t)) == -1 && errno == EINTR)
+		continue;
+	return rv;
+}
 
 /* tty_setup():
  *	Get the tty parameters and initialize the editing state
@@ -996,7 +1018,7 @@ tty_rawmode(EditLine *el)
 	if (el->el_tty.t_mode == EX_IO)
 		el->el_tty.t_ex = el->el_tty.t_ts;
 
-	if (tty_setty(el, &el->el_tty.t_ed) == -1) {
+	if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
 #ifdef DEBUG_TTY
 		(void) fprintf(el->el_errfile, "tty_rawmode: tty_setty: %s\n",
 		    strerror(errno));
@@ -1021,7 +1043,7 @@ tty_cookedmode(EditLine *el)
 	if (el->el_flags & EDIT_DISABLED)
 		return (0);
 
-	if (tty_setty(el, &el->el_tty.t_ex) == -1) {
+	if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
 #ifdef DEBUG_TTY
 		(void) fprintf(el->el_errfile,
 		    "tty_cookedmode: tty_setty: %s\n",
@@ -1057,7 +1079,7 @@ tty_quotemode(EditLine *el)
 	el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask;
 	el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask;
 
-	if (tty_setty(el, &el->el_tty.t_qu) == -1) {
+	if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) {
 #ifdef DEBUG_TTY
 		(void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
 		    strerror(errno));
@@ -1078,7 +1100,7 @@ tty_noquotemode(EditLine *el)
 
 	if (el->el_tty.t_mode != QU_IO)
 		return (0);
-	if (tty_setty(el, &el->el_tty.t_ed) == -1) {
+	if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
 #ifdef DEBUG_TTY
 		(void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
 		    strerror(errno));
@@ -1139,7 +1161,7 @@ tty_stty(EditLine *el, int argc __unused
 
 	if (!argv || !*argv) {
 		int i = -1;
-		int len = 0, st = 0, cu;
+		size_t len = 0, st = 0, cu;
 		for (m = ttymodes; m->m_name; m++) {
 			if (m->m_type != i) {
 				(void) fprintf(el->el_outfile, "%s%s",
@@ -1162,9 +1184,9 @@ tty_stty(EditLine *el, int argc __unused
 
 				cu = strlen(m->m_name) + (x != '\0') + 1;
 
-				if (len + cu >= el->el_term.t_size.h) {
+				if (len + cu >= (size_t)el->el_term.t_size.h) {
 					(void) fprintf(el->el_outfile, "\n%*s",
-					    st, "");
+					    (int)st, "");
 					len = st + cu;
 				} else
 					len += cu;
@@ -1208,7 +1230,8 @@ tty_stty(EditLine *el, int argc __unused
 			int c = ffs((int)m->m_value);
 			int v = *++p ? parse__escape((const char **) &p) :
 			    el->el_tty.t_vdisable;
-			assert(c-- != 0);
+			assert(c != 0);
+			c--;
 			c = tty__getcharindex(c);
 			assert(c != -1);
 			tios->c_cc[c] = v;
@@ -1229,6 +1252,17 @@ tty_stty(EditLine *el, int argc __unused
 			break;
 		}
 	}
+
+	if (el->el_tty.t_mode == z) {
+		if (tty_setty(el, TCSADRAIN, tios) == -1) {
+#ifdef DEBUG_TTY
+			(void) fprintf(el->el_errfile,
+			    "tty_stty: tty_setty: %s\n", strerror(errno));
+#endif /* DEBUG_TTY */
+			return (-1);
+		}
+	}
+
 	return (0);
 }
 


More information about the svn-src-stable-9 mailing list