Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 31 Mar 2011 01:13:05 +0000 (UTC)
From:      "David E. O'Brien" <obrien@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-vendor@freebsd.org
Subject:   svn commit: r220178 - in vendor/NetBSD/libedit/dist: . TEST readline
Message-ID:  <201103310113.p2V1D5dh086606@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: obrien
Date: Thu Mar 31 01:13:05 2011
New Revision: 220178
URL: http://svn.freebsd.org/changeset/base/220178

Log:
  Vendor import NetBSD's libedit of "2005/08/02 12:11:14 UTC".
  
  Obtained from:	NetBSD

Added:
  vendor/NetBSD/libedit/dist/TEST/Makefile   (contents, props changed)
  vendor/NetBSD/libedit/dist/config.h   (contents, props changed)
  vendor/NetBSD/libedit/dist/filecomplete.c   (contents, props changed)
  vendor/NetBSD/libedit/dist/filecomplete.h   (contents, props changed)
Deleted:
  vendor/NetBSD/libedit/dist/tokenizer.h
Modified:
  vendor/NetBSD/libedit/dist/Makefile
  vendor/NetBSD/libedit/dist/TEST/test.c
  vendor/NetBSD/libedit/dist/chared.c
  vendor/NetBSD/libedit/dist/chared.h
  vendor/NetBSD/libedit/dist/common.c
  vendor/NetBSD/libedit/dist/editline.3
  vendor/NetBSD/libedit/dist/editrc.5
  vendor/NetBSD/libedit/dist/el.c
  vendor/NetBSD/libedit/dist/el.h
  vendor/NetBSD/libedit/dist/emacs.c
  vendor/NetBSD/libedit/dist/hist.c
  vendor/NetBSD/libedit/dist/hist.h
  vendor/NetBSD/libedit/dist/histedit.h
  vendor/NetBSD/libedit/dist/history.c
  vendor/NetBSD/libedit/dist/key.c
  vendor/NetBSD/libedit/dist/key.h
  vendor/NetBSD/libedit/dist/makelist
  vendor/NetBSD/libedit/dist/map.c
  vendor/NetBSD/libedit/dist/map.h
  vendor/NetBSD/libedit/dist/parse.c
  vendor/NetBSD/libedit/dist/parse.h
  vendor/NetBSD/libedit/dist/prompt.c
  vendor/NetBSD/libedit/dist/prompt.h
  vendor/NetBSD/libedit/dist/read.c
  vendor/NetBSD/libedit/dist/read.h
  vendor/NetBSD/libedit/dist/readline.c
  vendor/NetBSD/libedit/dist/readline/Makefile
  vendor/NetBSD/libedit/dist/readline/readline.h
  vendor/NetBSD/libedit/dist/refresh.c
  vendor/NetBSD/libedit/dist/refresh.h
  vendor/NetBSD/libedit/dist/search.c
  vendor/NetBSD/libedit/dist/search.h
  vendor/NetBSD/libedit/dist/shlib_version
  vendor/NetBSD/libedit/dist/sig.c
  vendor/NetBSD/libedit/dist/sig.h
  vendor/NetBSD/libedit/dist/sys.h
  vendor/NetBSD/libedit/dist/term.c
  vendor/NetBSD/libedit/dist/term.h
  vendor/NetBSD/libedit/dist/tokenizer.c
  vendor/NetBSD/libedit/dist/tty.c
  vendor/NetBSD/libedit/dist/tty.h
  vendor/NetBSD/libedit/dist/vi.c

Modified: vendor/NetBSD/libedit/dist/Makefile
==============================================================================
--- vendor/NetBSD/libedit/dist/Makefile	Thu Mar 31 01:03:24 2011	(r220177)
+++ vendor/NetBSD/libedit/dist/Makefile	Thu Mar 31 01:13:05 2011	(r220178)
@@ -1,9 +1,15 @@
-#	$NetBSD: Makefile,v 1.20 2001/01/05 21:15:49 jdolecek Exp $
+#	$NetBSD: Makefile,v 1.34 2005/05/28 12:02:53 lukem Exp $
 #	@(#)Makefile	8.1 (Berkeley) 6/4/93
 
+USE_SHLIBDIR=	yes
+
+WARNS=	3
 LIB=	edit
 
-OSRCS=	chared.c common.c el.c emacs.c fcns.c help.c hist.c key.c map.c \
+LIBDPLIBS=     termcap ${.CURDIR}/../libterm
+
+OSRCS=	chared.c common.c el.c emacs.c fcns.c filecomplete.c help.c hist.c \
+	key.c map.c \
 	parse.c prompt.c read.c refresh.c search.c sig.c term.c tty.c vi.c
 
 MAN=	editline.3 editrc.5
@@ -13,75 +19,86 @@ MLINKS=	editline.3 el_init.3 editline.3 
 	editline.3 el_parse.3 editline.3 el_set.3 editline.3 el_get.3 \
 	editline.3 el_source.3 editline.3 el_resize.3 editline.3 el_line.3 \
 	editline.3 el_insertstr.3 editline.3 el_deletestr.3 \
-	editline.3 history_init.3 editline.3 history_end.3 editline.3 history.3
+	editline.3 history_init.3 editline.3 history_end.3 \
+	editline.3 history.3 \
+	editline.3 tok_init.3 editline.3 tok_end.3 editline.3 tok_reset.3 \
+	editline.3 tok_line.3 editline.3 tok_str.3
 
 # For speed and debugging
 #SRCS=   ${OSRCS} tokenizer.c history.c readline.c
 # For protection
 SRCS=	editline.c tokenizer.c history.c readline.c
 
-SRCS+=	common.h emacs.h fcns.h help.h vi.h
-
 LIBEDITDIR?=${.CURDIR}
 
 INCS= histedit.h
 INCSDIR=/usr/include
 
-CLEANFILES+=common.h editline.c emacs.h fcns.c fcns.h help.c help.h vi.h
+CLEANFILES+=editline.c
 CLEANFILES+=common.h.tmp editline.c.tmp emacs.h.tmp fcns.c.tmp fcns.h.tmp
 CLEANFILES+=help.c.tmp help.h.tmp vi.h.tmp
+CLEANFILES+=test.o test
 CPPFLAGS+=-I. -I${LIBEDITDIR} 
 CPPFLAGS+=-I. -I${.CURDIR}
 CPPFLAGS+=#-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH
-CPPFLAGS+=#-DDEBUG_PASTE
+CPPFLAGS+=#-DDEBUG_PASTE -DDEBUG_EDIT
 
 AHDR=vi.h emacs.h common.h 
 ASRC=${LIBEDITDIR}/vi.c ${LIBEDITDIR}/emacs.c ${LIBEDITDIR}/common.c
 
+DPSRCS+=	${AHDR} fcns.h help.h fcns.c help.c
+CLEANFILES+=	${AHDR} fcns.h help.h fcns.c help.c
+
 SUBDIR=	readline
 
-vi.h: vi.c makelist
-	sh ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/vi.c > ${.TARGET}.tmp && \
+vi.h: vi.c makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/vi.c \
+	    > ${.TARGET}.tmp && \
 	    mv ${.TARGET}.tmp ${.TARGET}
 
-emacs.h: emacs.c makelist
-	sh ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/emacs.c > ${.TARGET}.tmp && \
+emacs.h: emacs.c makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/emacs.c \
+	    > ${.TARGET}.tmp && \
 	    mv ${.TARGET}.tmp ${.TARGET}
 
-common.h: common.c makelist
-	sh ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/common.c > ${.TARGET}.tmp && \
+common.h: common.c makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/common.c \
+	    > ${.TARGET}.tmp && \
 	    mv ${.TARGET}.tmp ${.TARGET}
 
-fcns.h: ${AHDR} makelist
-	sh ${LIBEDITDIR}/makelist -fh ${AHDR} > ${.TARGET}.tmp && \
+fcns.h: ${AHDR} makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -fh ${AHDR} > ${.TARGET}.tmp && \
 	    mv ${.TARGET}.tmp ${.TARGET}
 
-fcns.c: ${AHDR} fcns.h makelist
-	sh ${LIBEDITDIR}/makelist -fc ${AHDR} > ${.TARGET}.tmp && \
+fcns.c: ${AHDR} fcns.h help.h makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -fc ${AHDR} > ${.TARGET}.tmp && \
 	    mv ${.TARGET}.tmp ${.TARGET}
 
-help.c: ${ASRC} makelist 
-	sh ${LIBEDITDIR}/makelist -bc ${ASRC} > ${.TARGET}.tmp && \
+help.c: ${ASRC} makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -bc ${ASRC} > ${.TARGET}.tmp && \
 	    mv ${.TARGET}.tmp ${.TARGET}
 
-help.h: ${ASRC} makelist
-	sh ${LIBEDITDIR}/makelist -bh ${ASRC} > ${.TARGET}.tmp && \
+help.h: ${ASRC} makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -bh ${ASRC} > ${.TARGET}.tmp && \
 	    mv ${.TARGET}.tmp ${.TARGET}
 
-editline.c: ${OSRCS}
-	sh ${LIBEDITDIR}/makelist -e ${.ALLSRC:T} > ${.TARGET}.tmp && \
+editline.c: ${OSRCS} makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -e ${OSRCS:T} > ${.TARGET}.tmp && \
 	    mv ${.TARGET}.tmp ${.TARGET}
 
 test.o:	${LIBEDITDIR}/TEST/test.c
 	
 test:	libedit.a test.o 
+	${_MKTARGET_LINK}
 	${CC} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD} -ltermcap
 
-# minimal dependency to make "make depend" optional
-editline.o editline.po editline.so editline.ln:	\
-	common.h emacs.h fcns.c fcns.h help.c help.h vi.h
-readline.o readline.po readline.so readline.ln:	\
-	common.h emacs.h fcns.h help.h vi.h
-
 .include <bsd.lib.mk>
 .include <bsd.subdir.mk>

Added: vendor/NetBSD/libedit/dist/TEST/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ vendor/NetBSD/libedit/dist/TEST/Makefile	Thu Mar 31 01:13:05 2011	(r220178)
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.2 2003/12/05 13:37:48 lukem Exp $
+
+NOMAN=1
+PROG=test
+CPPFLAGS=-I${.CURDIR}/..
+LDADD+=-ledit -ltermcap
+DPADD+=${LIBEDIT} ${LIBTERMCAP}
+
+.ifdef DEBUG
+CPPFLAGS+=-DDEBUG
+.endif
+
+.include <bsd.prog.mk>

Modified: vendor/NetBSD/libedit/dist/TEST/test.c
==============================================================================
--- vendor/NetBSD/libedit/dist/TEST/test.c	Thu Mar 31 01:03:24 2011	(r220177)
+++ vendor/NetBSD/libedit/dist/TEST/test.c	Thu Mar 31 01:13:05 2011	(r220178)
@@ -1,4 +1,4 @@
-/*	$NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $	*/
+/*	$NetBSD: test.c,v 1.18 2005/06/01 11:37:52 lukem Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -15,11 +15,7 @@
  * 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. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
  *
@@ -36,7 +32,7 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
+#include "config.h"
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
 	The Regents of the University of California.  All rights reserved.\n");
@@ -46,14 +42,13 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 19
 #if 0
 static char sccsid[] = "@(#)test.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $");
+__RCSID("$NetBSD: test.c,v 1.18 2005/06/01 11:37:52 lukem Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
 /*
  * test.c: A little test program
  */
-#include "sys.h"
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
@@ -64,12 +59,11 @@ __RCSID("$NetBSD: test.c,v 1.9 2000/09/0
 #include <dirent.h>
 
 #include "histedit.h"
-#include "tokenizer.h"
 
 static int continuation = 0;
-static EditLine *el = NULL;
+volatile sig_atomic_t gotsig = 0;
 
-static	u_char	complete(EditLine *, int);
+static	unsigned char	complete(EditLine *, int);
 	int	main(int, char **);
 static	char   *prompt(EditLine *);
 static	void	sig(int);
@@ -77,8 +71,8 @@ static	void	sig(int);
 static char *
 prompt(EditLine *el)
 {
-	static char a[] = "Edit$";
-	static char b[] = "Edit>";
+	static char a[] = "Edit$ ";
+	static char b[] = "Edit> ";
 
 	return (continuation ? b : a);
 }
@@ -86,9 +80,7 @@ prompt(EditLine *el)
 static void
 sig(int i)
 {
-
-	(void) fprintf(stderr, "Got signal %d.\n", i);
-	el_reset(el);
+	gotsig = i;
 }
 
 static unsigned char
@@ -103,7 +95,8 @@ complete(EditLine *el, int ch)
 	/*
 	 * Find the last word
 	 */
-	for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
+	for (ptr = lf->cursor - 1;
+	    !isspace((unsigned char)*ptr) && ptr > lf->buffer; ptr--)
 		continue;
 	len = lf->cursor - ++ptr;
 
@@ -126,10 +119,14 @@ complete(EditLine *el, int ch)
 int
 main(int argc, char *argv[])
 {
+	EditLine *el = NULL;
 	int num;
 	const char *buf;
 	Tokenizer *tok;
-	int lastevent = 0, ncontinuation;
+#if 0
+	int lastevent = 0;
+#endif
+	int ncontinuation;
 	History *hist;
 	HistEvent ev;
 
@@ -173,17 +170,41 @@ main(int argc, char *argv[])
 	el_source(el, NULL);
 
 	while ((buf = el_gets(el, &num)) != NULL && num != 0)  {
-		int ac;
-		char **av;
+		int ac, cc, co;
 #ifdef DEBUG
-		(void) fprintf(stderr, "got %d %s", num, buf);
+		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", gotsig);
+			gotsig = 0;
+			el_reset(el);
+		}
+
 		if (!continuation && num == 1)
 			continue;
 
-		if (tok_line(tok, buf, &ac, &av) > 0)
-			ncontinuation = 1;
-
+		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) {
 			/*
@@ -191,7 +212,7 @@ main(int argc, char *argv[])
 			 * moved around in history.
 			 */
 			if (history(hist, &ev, H_SET, lastevent) == -1)
-				err(1, "%d: %s\n", lastevent, ev.str);
+				err(1, "%d: %s", lastevent, ev.str);
 			history(hist, &ev, H_ADD , buf);
 		} else {
 			history(hist, &ev, H_ENTER, buf);
@@ -204,6 +225,18 @@ main(int argc, char *argv[])
 
 		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;
@@ -239,7 +272,7 @@ main(int argc, char *argv[])
 		} else if (el_parse(el, ac, av) == -1) {
 			switch (fork()) {
 			case 0:
-				execvp(av[0], av);
+				execvp(av[0], (char *const *)__UNCONST(av));
 				perror(av[0]);
 				_exit(1);
 				/*NOTREACHED*/

Modified: vendor/NetBSD/libedit/dist/chared.c
==============================================================================
--- vendor/NetBSD/libedit/dist/chared.c	Thu Mar 31 01:03:24 2011	(r220177)
+++ vendor/NetBSD/libedit/dist/chared.c	Thu Mar 31 01:13:05 2011	(r220178)
@@ -1,4 +1,4 @@
-/*	$NetBSD: chared.c,v 1.14 2001/05/17 01:02:17 christos Exp $	*/
+/*	$NetBSD: chared.c,v 1.24 2005/08/01 23:00:15 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -15,11 +15,7 @@
  * 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. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
  *
@@ -36,23 +32,23 @@
  * SUCH DAMAGE.
  */
 
-#include <sys/cdefs.h>
+#include "config.h"
 #if !defined(lint) && !defined(SCCSID)
 #if 0
 static char sccsid[] = "@(#)chared.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: chared.c,v 1.14 2001/05/17 01:02:17 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.24 2005/08/01 23:00:15 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
 /*
  * chared.c: Character editor utilities
  */
-#include "sys.h"
-
 #include <stdlib.h>
 #include "el.h"
 
+private void ch__clearmacro __P((EditLine *));
+
 /* value to leave unused in line buffer */
 #define	EL_LEAVE	2
 
@@ -60,17 +56,36 @@ __RCSID("$NetBSD: chared.c,v 1.14 2001/0
  *	Handle state for the vi undo command
  */
 protected void
-cv_undo(EditLine *el,int action, size_t size, char *ptr)
+cv_undo(EditLine *el)
 {
 	c_undo_t *vu = &el->el_chared.c_undo;
-	vu->action = action;
-	vu->ptr    = ptr;
-	vu->isize  = size;
-	(void) memcpy(vu->buf, vu->ptr, size);
-#ifdef DEBUG_UNDO
-	(void) fprintf(el->el_errfile, "Undo buffer \"%s\" size = +%d -%d\n",
-	       vu->ptr, vu->isize, vu->dsize);
-#endif
+	c_redo_t *r = &el->el_chared.c_redo;
+	unsigned int 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;
+	memcpy(vu->buf, el->el_line.buffer, size);
+
+	/* save command info for redo */
+	r->count = el->el_state.doingarg ? el->el_state.argument : 0;
+	r->action = el->el_chared.c_vcmd.action;
+	r->pos = r->buf;
+	r->cmd = el->el_state.thiscmd;
+	r->ch = el->el_state.thisch;
+}
+
+/* cv_yank():
+ *	Save yank/delete data for paste
+ */
+protected void
+cv_yank(EditLine *el, const char *ptr, int size)
+{
+	c_kill_t *k = &el->el_chared.c_kill;
+
+	memcpy(k->buf, ptr, size +0u);
+	k->last = k->buf + size;
 }
 
 
@@ -82,8 +97,10 @@ c_insert(EditLine *el, int num)
 {
 	char *cp;
 
-	if (el->el_line.lastchar + num >= el->el_line.limit)
-		return;			/* can't go past end of buffer */
+	if (el->el_line.lastchar + num >= el->el_line.limit) {
+		if (!ch_enlargebufs(el, num +0u))
+			return;		/* can't go past end of buffer */
+	}
 
 	if (el->el_line.cursor < el->el_line.lastchar) {
 		/* if I must move chars */
@@ -104,12 +121,14 @@ 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;
 
+	if (el->el_map.current != el->el_map.emacs) {
+		cv_undo(el);
+		cv_yank(el, el->el_line.cursor, num);
+	}
+
 	if (num > 0) {
 		char *cp;
 
-		if (el->el_map.current != el->el_map.emacs)
-			cv_undo(el, INSERT, (size_t)num, el->el_line.cursor);
-
 		for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
 			*cp = cp[num];
 
@@ -118,6 +137,21 @@ c_delafter(EditLine *el, int num)
 }
 
 
+/* c_delafter1():
+ *	Delete the character after the cursor, do not yank
+ */
+protected void
+c_delafter1(EditLine *el)
+{
+	char *cp;
+
+	for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
+		*cp = cp[1];
+
+	el->el_line.lastchar--;
+}
+
+
 /* c_delbefore():
  *	Delete num characters before the cursor
  */
@@ -128,13 +162,14 @@ 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;
 
+	if (el->el_map.current != el->el_map.emacs) {
+		cv_undo(el);
+		cv_yank(el, el->el_line.cursor - num, num);
+	}
+
 	if (num > 0) {
 		char *cp;
 
-		if (el->el_map.current != el->el_map.emacs)
-			cv_undo(el, INSERT, (size_t)num,
-			    el->el_line.cursor - num);
-
 		for (cp = el->el_line.cursor - num;
 		    cp <= el->el_line.lastchar;
 		    cp++)
@@ -145,13 +180,28 @@ c_delbefore(EditLine *el, int num)
 }
 
 
+/* c_delbefore1():
+ *	Delete the character before the cursor, do not yank
+ */
+protected void
+c_delbefore1(EditLine *el)
+{
+	char *cp;
+
+	for (cp = el->el_line.cursor - 1; cp <= el->el_line.lastchar; cp++)
+		*cp = cp[1];
+
+	el->el_line.lastchar--;
+}
+
+
 /* ce__isword():
  *	Return if p is part of a word according to emacs
  */
 protected int
 ce__isword(int p)
 {
-	return (isalpha(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL);
+	return (isalnum(p) || strchr("*?_-.[]~=", p) != NULL);
 }
 
 
@@ -161,6 +211,20 @@ ce__isword(int p)
 protected int
 cv__isword(int p)
 {
+	if (isalnum(p) || p == '_')
+		return 1;
+	if (isgraph(p))
+		return 2;
+	return 0;
+}
+
+
+/* cv__isWord():
+ *	Return if p is part of a big word according to vi
+ */
+protected int
+cv__isWord(int p)
+{
 	return (!isspace(p));
 }
 
@@ -223,7 +287,7 @@ cv_next_word(EditLine *el, char *p, char
 		 * vi historically deletes with cw only the word preserving the
 		 * trailing whitespace! This is not what 'w' does..
 		 */
-		if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
+		if (n || el->el_chared.c_vcmd.action != (DELETE|INSERT))
 			while ((p < high) && isspace((unsigned char) *p))
 				p++;
 	}
@@ -240,26 +304,19 @@ cv_next_word(EditLine *el, char *p, char
  *	Find the previous word vi style
  */
 protected char *
-cv_prev_word(EditLine *el, char *p, char *low, int n, int (*wtest)(int))
+cv_prev_word(char *p, char *low, int n, int (*wtest)(int))
 {
 	int test;
 
+	p--;
 	while (n--) {
-		p--;
-		/*
-		 * vi historically deletes with cb only the word preserving the
-		 * leading whitespace! This is not what 'b' does..
-		 */
-		if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
-			while ((p > low) && isspace((unsigned char) *p))
-				p--;
+		while ((p > low) && isspace((unsigned char) *p))
+			p--;
 		test = (*wtest)((unsigned char) *p);
 		while ((p >= low) && (*wtest)((unsigned char) *p) == test)
 			p--;
-		p++;
-		while (isspace((unsigned char) *p))
-			p++;
 	}
+	p++;
 
 	/* p now points where we want it */
 	if (p < low)
@@ -310,47 +367,34 @@ protected void
 cv_delfini(EditLine *el)
 {
 	int size;
-	int oaction;
+	int action = el->el_chared.c_vcmd.action;
 
-	if (el->el_chared.c_vcmd.action & INSERT)
+	if (action & INSERT)
 		el->el_map.current = el->el_map.key;
 
-	oaction = el->el_chared.c_vcmd.action;
-	el->el_chared.c_vcmd.action = NOP;
-
 	if (el->el_chared.c_vcmd.pos == 0)
+		/* sanity */
 		return;
 
-
-	if (el->el_line.cursor > el->el_chared.c_vcmd.pos) {
-		size = (int) (el->el_line.cursor - el->el_chared.c_vcmd.pos);
-		c_delbefore(el, size);
-		el->el_line.cursor = el->el_chared.c_vcmd.pos;
-		re_refresh_cursor(el);
-	} else if (el->el_line.cursor < el->el_chared.c_vcmd.pos) {
-		size = (int)(el->el_chared.c_vcmd.pos - el->el_line.cursor);
-		c_delafter(el, size);
-	} else {
+	size = el->el_line.cursor - el->el_chared.c_vcmd.pos;
+	if (size == 0)
 		size = 1;
-		c_delafter(el, size);
-	}
-	switch (oaction) {
-	case DELETE|INSERT:
-		el->el_chared.c_undo.action = DELETE|INSERT;
-		break;
-	case DELETE:
-		el->el_chared.c_undo.action = INSERT;
-		break;
-	case NOP:
-	case INSERT:
-	default:
-		EL_ABORT((el->el_errfile, "Bad oaction %d\n", oaction));
-		break;
+	el->el_line.cursor = el->el_chared.c_vcmd.pos;
+	if (action & YANK) {
+		if (size > 0)
+			cv_yank(el, el->el_line.cursor, size);
+		else
+			cv_yank(el, el->el_line.cursor + size, -size);
+	} else {
+		if (size > 0) {
+			c_delafter(el, size);
+			re_refresh_cursor(el);
+		} else  {
+			c_delbefore(el, -size);
+			el->el_line.cursor += size;
+		}
 	}
-
-
-	el->el_chared.c_undo.ptr = el->el_line.cursor;
-	el->el_chared.c_undo.dsize = size;
+	el->el_chared.c_vcmd.action = NOP;
 }
 
 
@@ -380,21 +424,19 @@ ce__endword(char *p, char *high, int n)
  *	Go to the end of this word according to vi
  */
 protected char *
-cv__endword(char *p, char *high, int n)
+cv__endword(char *p, char *high, int n, int (*wtest)(int))
 {
+	int test;
+
 	p++;
 
 	while (n--) {
 		while ((p < high) && isspace((unsigned char) *p))
 			p++;
 
-		if (isalnum((unsigned char) *p))
-			while ((p < high) && isalnum((unsigned char) *p))
-				p++;
-		else
-			while ((p < high) && !(isspace((unsigned char) *p) ||
-			    isalnum((unsigned char) *p)))
-				p++;
+		test = (*wtest)((unsigned char) *p);
+		while ((p < high) && (*wtest)((unsigned char) *p) == test)
+			p++;
 	}
 	p--;
 	return (p);
@@ -406,6 +448,8 @@ cv__endword(char *p, char *high, int n)
 protected int
 ch_init(EditLine *el)
 {
+	c_macro_t *ma = &el->el_chared.c_macro;
+
 	el->el_line.buffer		= (char *) el_malloc(EL_BUFSIZ);
 	if (el->el_line.buffer == NULL)
 		return (-1);
@@ -413,20 +457,23 @@ ch_init(EditLine *el)
 	(void) memset(el->el_line.buffer, 0, EL_BUFSIZ);
 	el->el_line.cursor		= el->el_line.buffer;
 	el->el_line.lastchar		= el->el_line.buffer;
-	el->el_line.limit		= &el->el_line.buffer[EL_BUFSIZ - 2];
+	el->el_line.limit		= &el->el_line.buffer[EL_BUFSIZ - EL_LEAVE];
 
 	el->el_chared.c_undo.buf	= (char *) el_malloc(EL_BUFSIZ);
 	if (el->el_chared.c_undo.buf == NULL)
 		return (-1);
 	(void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ);
-	el->el_chared.c_undo.action	= NOP;
-	el->el_chared.c_undo.isize	= 0;
-	el->el_chared.c_undo.dsize	= 0;
-	el->el_chared.c_undo.ptr	= el->el_line.buffer;
+	el->el_chared.c_undo.len	= -1;
+	el->el_chared.c_undo.cursor	= 0;
+	el->el_chared.c_redo.buf	= (char *) el_malloc(EL_BUFSIZ);
+	if (el->el_chared.c_redo.buf == NULL)
+		return (-1);
+	el->el_chared.c_redo.pos	= el->el_chared.c_redo.buf;
+	el->el_chared.c_redo.lim	= el->el_chared.c_redo.buf + EL_BUFSIZ;
+	el->el_chared.c_redo.cmd	= ED_UNASSIGNED;
 
 	el->el_chared.c_vcmd.action	= NOP;
 	el->el_chared.c_vcmd.pos	= el->el_line.buffer;
-	el->el_chared.c_vcmd.ins	= el->el_line.buffer;
 
 	el->el_chared.c_kill.buf	= (char *) el_malloc(EL_BUFSIZ);
 	if (el->el_chared.c_kill.buf == NULL)
@@ -443,11 +490,10 @@ ch_init(EditLine *el)
 	el->el_state.argument		= 1;
 	el->el_state.lastcmd		= ED_UNASSIGNED;
 
-	el->el_chared.c_macro.nline	= NULL;
-	el->el_chared.c_macro.level	= -1;
-	el->el_chared.c_macro.macro	= (char **) el_malloc(EL_MAXMACRO *
-	    sizeof(char *));
-	if (el->el_chared.c_macro.macro == NULL)
+	ma->level	= -1;
+	ma->offset	= 0;
+	ma->macro	= (char **) el_malloc(EL_MAXMACRO * sizeof(char *));
+	if (ma->macro == NULL)
 		return (-1);
 	return (0);
 }
@@ -456,19 +502,16 @@ ch_init(EditLine *el)
  *	Reset the character editor
  */
 protected void
-ch_reset(EditLine *el)
+ch_reset(EditLine *el, int mclear)
 {
 	el->el_line.cursor		= el->el_line.buffer;
 	el->el_line.lastchar		= el->el_line.buffer;
 
-	el->el_chared.c_undo.action	= NOP;
-	el->el_chared.c_undo.isize	= 0;
-	el->el_chared.c_undo.dsize	= 0;
-	el->el_chared.c_undo.ptr	= el->el_line.buffer;
+	el->el_chared.c_undo.len	= -1;
+	el->el_chared.c_undo.cursor	= 0;
 
 	el->el_chared.c_vcmd.action	= NOP;
 	el->el_chared.c_vcmd.pos	= el->el_line.buffer;
-	el->el_chared.c_vcmd.ins	= el->el_line.buffer;
 
 	el->el_chared.c_kill.mark	= el->el_line.buffer;
 
@@ -480,9 +523,17 @@ ch_reset(EditLine *el)
 	el->el_state.argument		= 1;
 	el->el_state.lastcmd		= ED_UNASSIGNED;
 
-	el->el_chared.c_macro.level	= -1;
+	if (mclear)
+		ch__clearmacro(el);
+}
 
-	el->el_history.eventno		= 0;
+private void
+ch__clearmacro(el)
+	EditLine *el;
+{
+	c_macro_t *ma = &el->el_chared.c_macro;
+	while (ma->level >= 0)
+		el_free((ptr_t)ma->macro[ma->level--]);
 }
 
 /* ch_enlargebufs():
@@ -523,7 +574,8 @@ ch_enlargebufs(el, addlen)
 	el->el_line.buffer = newbuffer;
 	el->el_line.cursor = newbuffer + (el->el_line.cursor - oldbuf);
 	el->el_line.lastchar = newbuffer + (el->el_line.lastchar - oldbuf);
-	el->el_line.limit  = &newbuffer[newsz - EL_LEAVE];
+	/* don't set new size until all buffers are enlarged */
+	el->el_line.limit  = &newbuffer[sz - EL_LEAVE];
 
 	/*
 	 * Reallocate kill buffer.
@@ -552,14 +604,22 @@ ch_enlargebufs(el, addlen)
 
 	/* zero the newly added memory, leave old data in */
 	(void) memset(&newbuffer[sz], 0, newsz - sz);
-
-	el->el_chared.c_undo.ptr = el->el_line.buffer +
-				    (el->el_chared.c_undo.ptr - oldbuf);
 	el->el_chared.c_undo.buf = newbuffer;
+
+	newbuffer = el_realloc(el->el_chared.c_redo.buf, newsz);
+	if (!newbuffer)
+		return 0;
+	el->el_chared.c_redo.pos = newbuffer +
+			(el->el_chared.c_redo.pos - el->el_chared.c_redo.buf);
+	el->el_chared.c_redo.lim = newbuffer +
+			(el->el_chared.c_redo.lim - el->el_chared.c_redo.buf);
+	el->el_chared.c_redo.buf = newbuffer;
 	
 	if (!hist_enlargebuf(el, sz, newsz))
 		return 0;
 
+	/* Safe to set enlarged buffer size */
+	el->el_line.limit  = &el->el_line.buffer[newsz - EL_LEAVE];
 	return 1;
 }
 
@@ -574,11 +634,16 @@ ch_end(EditLine *el)
 	el->el_line.limit = NULL;
 	el_free((ptr_t) el->el_chared.c_undo.buf);
 	el->el_chared.c_undo.buf = NULL;
+	el_free((ptr_t) el->el_chared.c_redo.buf);
+	el->el_chared.c_redo.buf = NULL;
+	el->el_chared.c_redo.pos = NULL;
+	el->el_chared.c_redo.lim = NULL;
+	el->el_chared.c_redo.cmd = ED_UNASSIGNED;
 	el_free((ptr_t) el->el_chared.c_kill.buf);
 	el->el_chared.c_kill.buf = NULL;
+	ch_reset(el, 1);
 	el_free((ptr_t) el->el_chared.c_macro.macro);
 	el->el_chared.c_macro.macro = NULL;
-	ch_reset(el);
 }
 
 
@@ -626,51 +691,64 @@ el_deletestr(EditLine *el, int n)
  *	Get a string
  */
 protected int
-c_gets(EditLine *el, char *buf)
+c_gets(EditLine *el, char *buf, const char *prompt)
 {
 	char ch;
-	int len = 0;
+	int len;
+	char *cp = el->el_line.buffer;
+
+	if (prompt) {
+		len = strlen(prompt);
+		memcpy(cp, prompt, len + 0u);
+		cp += len;
+	}
+	len = 0;
+
+	for (;;) {
+		el->el_line.cursor = cp;
+		*cp = ' ';
+		el->el_line.lastchar = cp + 1;
+		re_refresh(el);
+
+		if (el_getc(el, &ch) != 1) {
+			ed_end_of_file(el, 0);
+			len = -1;
+			break;
+		}
 
-	for (ch = 0; ch == 0;) {
-		if (el_getc(el, &ch) != 1)
-			return (ed_end_of_file(el, 0));
 		switch (ch) {
+
 		case 0010:	/* Delete and backspace */
 		case 0177:
-			if (len > 1) {
-				*el->el_line.cursor-- = '\0';
-				el->el_line.lastchar = el->el_line.cursor;
-				buf[len--] = '\0';
-			} else {
-				el->el_line.buffer[0] = '\0';
-				el->el_line.lastchar = el->el_line.buffer;
-				el->el_line.cursor = el->el_line.buffer;
-				return (CC_REFRESH);
+			if (len <= 0) {
+				len = -1;
+				break;
 			}
-			re_refresh(el);
-			ch = 0;
-			break;
+			cp--;
+			continue;
 
 		case 0033:	/* ESC */
 		case '\r':	/* Newline */
 		case '\n':
+			buf[len] = ch;
 			break;
 
 		default:
-			if (len >= EL_BUFSIZ)
+			if (len >= EL_BUFSIZ - 16)
 				term_beep(el);
 			else {
 				buf[len++] = ch;
-				*el->el_line.cursor++ = ch;
-				el->el_line.lastchar = el->el_line.cursor;
+				*cp++ = ch;
 			}
-			re_refresh(el);
-			ch = 0;
-			break;
+			continue;
 		}
+		break;
 	}
-	buf[len] = ch;
-	return (len);
+
+	el->el_line.buffer[0] = '\0';
+	el->el_line.lastchar = el->el_line.buffer;
+	el->el_line.cursor = el->el_line.buffer;
+	return len;
 }
 
 

Modified: vendor/NetBSD/libedit/dist/chared.h
==============================================================================
--- vendor/NetBSD/libedit/dist/chared.h	Thu Mar 31 01:03:24 2011	(r220177)
+++ vendor/NetBSD/libedit/dist/chared.h	Thu Mar 31 01:13:05 2011	(r220178)
@@ -1,4 +1,4 @@
-/*	$NetBSD: chared.h,v 1.6 2001/01/10 07:45:41 jdolecek Exp $	*/
+/*	$NetBSD: chared.h,v 1.15 2005/08/01 23:00:15 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -15,11 +15,7 @@
  * 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. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *	This product includes software developed by the University of
- *	California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 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.
  *
@@ -66,28 +62,36 @@
 
 typedef struct c_macro_t {
 	int	  level;
+	int	  offset;
 	char	**macro;
-	char	 *nline;
 } c_macro_t;
 
 /*
- * Undo information for both vi and emacs
+ * Undo information for vi - no undo in emacs (yet)
  */
 typedef struct c_undo_t {
-	int	 action;
-	size_t	 isize;
-	size_t	 dsize;
-	char	*ptr;
-	char	*buf;
+	int	 len;			/* length of saved line */
+	int	 cursor;		/* position of saved cursor */
+	char	*buf;			/* full saved text */
 } c_undo_t;
 
+/* redo for vi */
+typedef struct c_redo_t {
+	char	*buf;			/* redo insert key sequence */
+	char	*pos;
+	char	*lim;
+	el_action_t	cmd;		/* command to redo */
+	char	ch;			/* char that invoked it */
+	int	count;
+	int	action;			/* from cv_action() */
+} c_redo_t;
+
 /*
  * Current action information for vi
  */

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201103310113.p2V1D5dh086606>