svn commit: r323546 - in vendor/NetBSD/libedit/2017-09-05: . TEST readline

Pedro F. Giffuni pfg at FreeBSD.org
Wed Sep 13 16:05:27 UTC 2017


Author: pfg
Date: Wed Sep 13 16:05:26 2017
New Revision: 323546
URL: https://svnweb.freebsd.org/changeset/base/323546

Log:
  Tag import of libedit 2017-09-05.

Added:
  vendor/NetBSD/libedit/2017-09-05/
     - copied from r323542, vendor/NetBSD/libedit/dist/
  vendor/NetBSD/libedit/2017-09-05/editline.7
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/editline.7
  vendor/NetBSD/libedit/2017-09-05/historyn.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/historyn.c
  vendor/NetBSD/libedit/2017-09-05/literal.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/literal.c
  vendor/NetBSD/libedit/2017-09-05/literal.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/literal.h
  vendor/NetBSD/libedit/2017-09-05/tokenizern.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/tokenizern.c
Replaced:
  vendor/NetBSD/libedit/2017-09-05/Makefile
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/Makefile
  vendor/NetBSD/libedit/2017-09-05/TEST/Makefile
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/TEST/Makefile
  vendor/NetBSD/libedit/2017-09-05/chared.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/chared.c
  vendor/NetBSD/libedit/2017-09-05/chared.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/chared.h
  vendor/NetBSD/libedit/2017-09-05/chartype.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/chartype.c
  vendor/NetBSD/libedit/2017-09-05/chartype.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/chartype.h
  vendor/NetBSD/libedit/2017-09-05/common.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/common.c
  vendor/NetBSD/libedit/2017-09-05/config.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/config.h
  vendor/NetBSD/libedit/2017-09-05/editline.3
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/editline.3
  vendor/NetBSD/libedit/2017-09-05/editrc.5
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/editrc.5
  vendor/NetBSD/libedit/2017-09-05/el.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/el.c
  vendor/NetBSD/libedit/2017-09-05/el.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/el.h
  vendor/NetBSD/libedit/2017-09-05/eln.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/eln.c
  vendor/NetBSD/libedit/2017-09-05/emacs.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/emacs.c
  vendor/NetBSD/libedit/2017-09-05/filecomplete.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/filecomplete.c
  vendor/NetBSD/libedit/2017-09-05/filecomplete.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/filecomplete.h
  vendor/NetBSD/libedit/2017-09-05/hist.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/hist.c
  vendor/NetBSD/libedit/2017-09-05/hist.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/hist.h
  vendor/NetBSD/libedit/2017-09-05/histedit.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/histedit.h
  vendor/NetBSD/libedit/2017-09-05/history.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/history.c
  vendor/NetBSD/libedit/2017-09-05/keymacro.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/keymacro.c
  vendor/NetBSD/libedit/2017-09-05/keymacro.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/keymacro.h
  vendor/NetBSD/libedit/2017-09-05/makelist
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/makelist
  vendor/NetBSD/libedit/2017-09-05/map.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/map.c
  vendor/NetBSD/libedit/2017-09-05/map.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/map.h
  vendor/NetBSD/libedit/2017-09-05/parse.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/parse.c
  vendor/NetBSD/libedit/2017-09-05/parse.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/parse.h
  vendor/NetBSD/libedit/2017-09-05/prompt.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/prompt.c
  vendor/NetBSD/libedit/2017-09-05/prompt.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/prompt.h
  vendor/NetBSD/libedit/2017-09-05/read.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/read.c
  vendor/NetBSD/libedit/2017-09-05/read.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/read.h
  vendor/NetBSD/libedit/2017-09-05/readline.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/readline.c
  vendor/NetBSD/libedit/2017-09-05/readline/readline.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/readline/readline.h
  vendor/NetBSD/libedit/2017-09-05/refresh.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/refresh.c
  vendor/NetBSD/libedit/2017-09-05/refresh.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/refresh.h
  vendor/NetBSD/libedit/2017-09-05/search.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/search.c
  vendor/NetBSD/libedit/2017-09-05/search.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/search.h
  vendor/NetBSD/libedit/2017-09-05/sig.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/sig.c
  vendor/NetBSD/libedit/2017-09-05/sig.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/sig.h
  vendor/NetBSD/libedit/2017-09-05/sys.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/sys.h
  vendor/NetBSD/libedit/2017-09-05/terminal.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/terminal.c
  vendor/NetBSD/libedit/2017-09-05/terminal.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/terminal.h
  vendor/NetBSD/libedit/2017-09-05/tokenizer.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/tokenizer.c
  vendor/NetBSD/libedit/2017-09-05/tty.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/tty.c
  vendor/NetBSD/libedit/2017-09-05/tty.h
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/tty.h
  vendor/NetBSD/libedit/2017-09-05/vi.c
     - copied unchanged from r323545, vendor/NetBSD/libedit/dist/vi.c

Copied: vendor/NetBSD/libedit/2017-09-05/Makefile (from r323545, vendor/NetBSD/libedit/dist/Makefile)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ vendor/NetBSD/libedit/2017-09-05/Makefile	Wed Sep 13 16:05:26 2017	(r323546, copy of r323545, vendor/NetBSD/libedit/dist/Makefile)
@@ -0,0 +1,139 @@
+#	$NetBSD: Makefile,v 1.65 2017/06/30 20:26:52 kre Exp $
+#	@(#)Makefile	8.1 (Berkeley) 6/4/93
+
+USE_SHLIBDIR=	yes
+
+WARNS?=	5
+LIB=	edit
+
+LIBDPLIBS+=     terminfo ${.CURDIR}/../libterminfo
+
+.include "bsd.own.mk"
+
+COPTS+=	-Wunused-parameter
+CWARNFLAGS.gcc+=	-Wconversion
+CWARNFLAGS.clang+=	-Wno-cast-qual
+
+SRCS =	chared.c chartype.c common.c el.c eln.c emacs.c filecomplete.c \
+	hist.c history.c historyn.c keymacro.c literal.c map.c \
+	parse.c prompt.c read.c readline.c refresh.c search.c sig.c \
+	terminal.c tokenizer.c tokenizern.c tty.c vi.c
+
+MAN=	editline.3 editrc.5 editline.7
+
+MLINKS= \
+editline.3 el_deletestr.3 \
+editline.3 el_end.3 \
+editline.3 el_get.3 \
+editline.3 el_getc.3 \
+editline.3 el_gets.3 \
+editline.3 el_init.3 \
+editline.3 el_init_fd.3 \
+editline.3 el_insertstr.3 \
+editline.3 el_line.3 \
+editline.3 el_parse.3 \
+editline.3 el_push.3 \
+editline.3 el_reset.3 \
+editline.3 el_resize.3 \
+editline.3 el_set.3 \
+editline.3 el_source.3 \
+editline.3 history.3 \
+editline.3 history_end.3 \
+editline.3 history_init.3 \
+editline.3 tok_end.3 \
+editline.3 tok_init.3 \
+editline.3 tok_line.3 \
+editline.3 tok_reset.3 \
+editline.3 tok_str.3
+
+MLINKS+= \
+editline.3 el_wdeletestr.3 \
+editline.3 el_wget.3 \
+editline.3 el_wgetc.3 \
+editline.3 el_wgets.3 \
+editline.3 el_winsertstr.3 \
+editline.3 el_wline.3 \
+editline.3 el_wparse.3 \
+editline.3 el_wpush.3 \
+editline.3 el_wset.3 \
+editline.3 history_w.3 \
+editline.3 history_wend.3 \
+editline.3 history_winit.3 \
+editline.3 tok_wend.3 \
+editline.3 tok_winit.3 \
+editline.3 tok_wline.3 \
+editline.3 tok_wreset.3 \
+editline.3 tok_wstr.3
+
+LIBEDITDIR?=${.CURDIR}
+
+INCS= histedit.h
+INCSDIR=/usr/include
+
+CLEANFILES+=common.h.tmp emacs.h.tmp fcns.h.tmp func.h.tmp
+CLEANFILES+=help.h.tmp vi.h.tmp tc1.o tc1 .depend
+
+CPPFLAGS+=-I. -I${LIBEDITDIR}
+CPPFLAGS+=-I. -I${.CURDIR}
+#CPPFLAGS+=-DDEBUG_TTY -DDEBUG_KEY -DDEBUG -DDEBUG_REFRESH
+#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 func.h help.h
+CLEANFILES+=	${AHDR} fcns.h func.h help.h
+
+SUBDIR=	readline
+
+.depend: ${AHDR} fcns.h func.h help.h
+
+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 Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/emacs.c \
+	    > ${.TARGET}.tmp && \
+	    mv ${.TARGET}.tmp ${.TARGET}
+
+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 Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -fh ${AHDR} > ${.TARGET}.tmp && \
+	    mv ${.TARGET}.tmp ${.TARGET}
+
+func.h: ${AHDR} makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -fc ${AHDR} > ${.TARGET}.tmp && \
+	    mv ${.TARGET}.tmp ${.TARGET}
+
+help.h: ${ASRC} makelist Makefile
+	${_MKTARGET_CREATE}
+	${HOST_SH} ${LIBEDITDIR}/makelist -bh ${ASRC} > ${.TARGET}.tmp && \
+	    mv ${.TARGET}.tmp ${.TARGET}
+
+tc1.o:	${LIBEDITDIR}/TEST/tc1.c
+
+tc1:	libedit.a tc1.o
+	${_MKTARGET_LINK}
+	${CC} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD} -ltermlib
+
+.include <bsd.lib.mk>
+.include <bsd.subdir.mk>
+
+# XXX
+.if defined(HAVE_GCC)
+COPTS.editline.c+=	-Wno-cast-qual
+COPTS.literal.c+=	-Wno-sign-conversion
+COPTS.tokenizer.c+=	-Wno-cast-qual
+COPTS.tokenizern.c+=	-Wno-cast-qual
+.endif

Copied: vendor/NetBSD/libedit/2017-09-05/TEST/Makefile (from r323545, vendor/NetBSD/libedit/dist/TEST/Makefile)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ vendor/NetBSD/libedit/2017-09-05/TEST/Makefile	Wed Sep 13 16:05:26 2017	(r323546, copy of r323545, vendor/NetBSD/libedit/dist/TEST/Makefile)
@@ -0,0 +1,13 @@
+# $NetBSD: Makefile,v 1.7 2016/03/23 22:27:48 christos Exp $
+
+NOMAN=1
+PROG=wtc1
+CPPFLAGS=-I${.CURDIR}/..
+LDADD+=-ledit -ltermlib
+DPADD+=${LIBEDIT} ${LIBTERMLIB}
+
+.ifdef DEBUG
+CPPFLAGS+=-DDEBUG
+.endif
+
+.include <bsd.prog.mk>

Copied: vendor/NetBSD/libedit/2017-09-05/chared.c (from r323545, vendor/NetBSD/libedit/dist/chared.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ vendor/NetBSD/libedit/2017-09-05/chared.c	Wed Sep 13 16:05:26 2017	(r323546, copy of r323545, vendor/NetBSD/libedit/dist/chared.c)
@@ -0,0 +1,753 @@
+/*	$NetBSD: chared.c,v 1.56 2016/05/22 19:44:26 christos Exp $	*/
+
+/*-
+ * 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 "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.56 2016/05/22 19:44:26 christos Exp $");
+#endif
+#endif /* not lint && not SCCSID */
+
+/*
+ * chared.c: Character editor utilities
+ */
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "el.h"
+#include "common.h"
+#include "fcns.h"
+
+/* value to leave unused in line buffer */
+#define	EL_LEAVE	2
+
+/* cv_undo():
+ *	Handle state for the vi undo command
+ */
+libedit_private void
+cv_undo(EditLine *el)
+{
+	c_undo_t *vu = &el->el_chared.c_undo;
+	c_redo_t *r = &el->el_chared.c_redo;
+	size_t size;
+
+	/* Save entire line for undo */
+	size = (size_t)(el->el_line.lastchar - el->el_line.buffer);
+	vu->len = (ssize_t)size;
+	vu->cursor = (int)(el->el_line.cursor - el->el_line.buffer);
+	(void)memcpy(vu->buf, el->el_line.buffer, size * sizeof(*vu->buf));
+
+	/* 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
+ */
+libedit_private void
+cv_yank(EditLine *el, const wchar_t *ptr, int size)
+{
+	c_kill_t *k = &el->el_chared.c_kill;
+
+	(void)memcpy(k->buf, ptr, (size_t)size * sizeof(*k->buf));
+	k->last = k->buf + size;
+}
+
+
+/* c_insert():
+ *	Insert num characters
+ */
+libedit_private void
+c_insert(EditLine *el, int num)
+{
+	wchar_t *cp;
+
+	if (el->el_line.lastchar + num >= el->el_line.limit) {
+		if (!ch_enlargebufs(el, (size_t)num))
+			return;		/* can't go past end of buffer */
+	}
+
+	if (el->el_line.cursor < el->el_line.lastchar) {
+		/* if I must move chars */
+		for (cp = el->el_line.lastchar; cp >= el->el_line.cursor; cp--)
+			cp[num] = *cp;
+	}
+	el->el_line.lastchar += num;
+}
+
+
+/* c_delafter():
+ *	Delete num characters after the cursor
+ */
+libedit_private void
+c_delafter(EditLine *el, int num)
+{
+
+	if (el->el_line.cursor + num > el->el_line.lastchar)
+		num = (int)(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) {
+		wchar_t *cp;
+
+		for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
+			*cp = cp[num];
+
+		el->el_line.lastchar -= num;
+	}
+}
+
+
+/* c_delafter1():
+ *	Delete the character after the cursor, do not yank
+ */
+libedit_private void
+c_delafter1(EditLine *el)
+{
+	wchar_t *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
+ */
+libedit_private void
+c_delbefore(EditLine *el, int num)
+{
+
+	if (el->el_line.cursor - num < 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);
+		cv_yank(el, el->el_line.cursor - num, num);
+	}
+
+	if (num > 0) {
+		wchar_t *cp;
+
+		for (cp = el->el_line.cursor - num;
+		    cp <= el->el_line.lastchar;
+		    cp++)
+			*cp = cp[num];
+
+		el->el_line.lastchar -= num;
+	}
+}
+
+
+/* c_delbefore1():
+ *	Delete the character before the cursor, do not yank
+ */
+libedit_private void
+c_delbefore1(EditLine *el)
+{
+	wchar_t *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
+ */
+libedit_private int
+ce__isword(wint_t p)
+{
+	return iswalnum(p) || wcschr(L"*?_-.[]~=", p) != NULL;
+}
+
+
+/* cv__isword():
+ *	Return if p is part of a word according to vi
+ */
+libedit_private int
+cv__isword(wint_t p)
+{
+	if (iswalnum(p) || p == L'_')
+		return 1;
+	if (iswgraph(p))
+		return 2;
+	return 0;
+}
+
+
+/* cv__isWord():
+ *	Return if p is part of a big word according to vi
+ */
+libedit_private int
+cv__isWord(wint_t p)
+{
+	return !iswspace(p);
+}
+
+
+/* c__prev_word():
+ *	Find the previous word
+ */
+libedit_private wchar_t *
+c__prev_word(wchar_t *p, wchar_t *low, int n, int (*wtest)(wint_t))
+{
+	p--;
+
+	while (n--) {
+		while ((p >= low) && !(*wtest)(*p))
+			p--;
+		while ((p >= low) && (*wtest)(*p))
+			p--;
+	}
+
+	/* cp now points to one character before the word */
+	p++;
+	if (p < low)
+		p = low;
+	/* cp now points where we want it */
+	return p;
+}
+
+
+/* c__next_word():
+ *	Find the next word
+ */
+libedit_private wchar_t *
+c__next_word(wchar_t *p, wchar_t *high, int n, int (*wtest)(wint_t))
+{
+	while (n--) {
+		while ((p < high) && !(*wtest)(*p))
+			p++;
+		while ((p < high) && (*wtest)(*p))
+			p++;
+	}
+	if (p > high)
+		p = high;
+	/* p now points where we want it */
+	return p;
+}
+
+/* cv_next_word():
+ *	Find the next word vi style
+ */
+libedit_private wchar_t *
+cv_next_word(EditLine *el, wchar_t *p, wchar_t *high, int n,
+    int (*wtest)(wint_t))
+{
+	int test;
+
+	while (n--) {
+		test = (*wtest)(*p);
+		while ((p < high) && (*wtest)(*p) == test)
+			p++;
+		/*
+		 * vi historically deletes with cw only the word preserving the
+		 * trailing whitespace! This is not what 'w' does..
+		 */
+		if (n || el->el_chared.c_vcmd.action != (DELETE|INSERT))
+			while ((p < high) && iswspace(*p))
+				p++;
+	}
+
+	/* p now points where we want it */
+	if (p > high)
+		return high;
+	else
+		return p;
+}
+
+
+/* cv_prev_word():
+ *	Find the previous word vi style
+ */
+libedit_private wchar_t *
+cv_prev_word(wchar_t *p, wchar_t *low, int n, int (*wtest)(wint_t))
+{
+	int test;
+
+	p--;
+	while (n--) {
+		while ((p > low) && iswspace(*p))
+			p--;
+		test = (*wtest)(*p);
+		while ((p >= low) && (*wtest)(*p) == test)
+			p--;
+	}
+	p++;
+
+	/* p now points where we want it */
+	if (p < low)
+		return low;
+	else
+		return p;
+}
+
+
+/* cv_delfini():
+ *	Finish vi delete action
+ */
+libedit_private void
+cv_delfini(EditLine *el)
+{
+	int size;
+	int action = el->el_chared.c_vcmd.action;
+
+	if (action & INSERT)
+		el->el_map.current = el->el_map.key;
+
+	if (el->el_chared.c_vcmd.pos == 0)
+		/* sanity */
+		return;
+
+	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;
+	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_vcmd.action = NOP;
+}
+
+
+/* cv__endword():
+ *	Go to the end of this word according to vi
+ */
+libedit_private wchar_t *
+cv__endword(wchar_t *p, wchar_t *high, int n, int (*wtest)(wint_t))
+{
+	int test;
+
+	p++;
+
+	while (n--) {
+		while ((p < high) && iswspace(*p))
+			p++;
+
+		test = (*wtest)(*p);
+		while ((p < high) && (*wtest)(*p) == test)
+			p++;
+	}
+	p--;
+	return p;
+}
+
+/* ch_init():
+ *	Initialize the character editor
+ */
+libedit_private int
+ch_init(EditLine *el)
+{
+	el->el_line.buffer		= el_malloc(EL_BUFSIZ *
+	    sizeof(*el->el_line.buffer));
+	if (el->el_line.buffer == NULL)
+		return -1;
+
+	(void) memset(el->el_line.buffer, 0, EL_BUFSIZ *
+	    sizeof(*el->el_line.buffer));
+	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 - EL_LEAVE];
+
+	el->el_chared.c_undo.buf	= el_malloc(EL_BUFSIZ *
+	    sizeof(*el->el_chared.c_undo.buf));
+	if (el->el_chared.c_undo.buf == NULL)
+		return -1;
+	(void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ *
+	    sizeof(*el->el_chared.c_undo.buf));
+	el->el_chared.c_undo.len	= -1;
+	el->el_chared.c_undo.cursor	= 0;
+	el->el_chared.c_redo.buf	= el_malloc(EL_BUFSIZ *
+	    sizeof(*el->el_chared.c_redo.buf));
+	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_kill.buf	= el_malloc(EL_BUFSIZ *
+	    sizeof(*el->el_chared.c_kill.buf));
+	if (el->el_chared.c_kill.buf == NULL)
+		return -1;
+	(void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ *
+	    sizeof(*el->el_chared.c_kill.buf));
+	el->el_chared.c_kill.mark	= el->el_line.buffer;
+	el->el_chared.c_kill.last	= el->el_chared.c_kill.buf;
+	el->el_chared.c_resizefun	= NULL;
+	el->el_chared.c_resizearg	= NULL;
+	el->el_chared.c_aliasfun	= NULL;
+	el->el_chared.c_aliasarg	= NULL;
+
+	el->el_map.current		= el->el_map.key;
+
+	el->el_state.inputmode		= MODE_INSERT; /* XXX: save a default */
+	el->el_state.doingarg		= 0;
+	el->el_state.metanext		= 0;
+	el->el_state.argument		= 1;
+	el->el_state.lastcmd		= ED_UNASSIGNED;
+
+	return 0;
+}
+
+/* ch_reset():
+ *	Reset the character editor
+ */
+libedit_private void
+ch_reset(EditLine *el)
+{
+	el->el_line.cursor		= el->el_line.buffer;
+	el->el_line.lastchar		= 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_kill.mark	= el->el_line.buffer;
+
+	el->el_map.current		= el->el_map.key;
+
+	el->el_state.inputmode		= MODE_INSERT; /* XXX: save a default */
+	el->el_state.doingarg		= 0;
+	el->el_state.metanext		= 0;
+	el->el_state.argument		= 1;
+	el->el_state.lastcmd		= ED_UNASSIGNED;
+
+	el->el_history.eventno		= 0;
+}
+
+/* ch_enlargebufs():
+ *	Enlarge line buffer to be able to hold twice as much characters.
+ *	Returns 1 if successful, 0 if not.
+ */
+libedit_private int
+ch_enlargebufs(EditLine *el, size_t addlen)
+{
+	size_t sz, newsz;
+	wchar_t *newbuffer, *oldbuf, *oldkbuf;
+
+	sz = (size_t)(el->el_line.limit - el->el_line.buffer + EL_LEAVE);
+	newsz = sz * 2;
+	/*
+	 * If newly required length is longer than current buffer, we need
+	 * to make the buffer big enough to hold both old and new stuff.
+	 */
+	if (addlen > sz) {
+		while(newsz - sz < addlen)
+			newsz *= 2;
+	}
+
+	/*
+	 * Reallocate line buffer.
+	 */
+	newbuffer = el_realloc(el->el_line.buffer, newsz * sizeof(*newbuffer));
+	if (!newbuffer)
+		return 0;
+
+	/* zero the newly added memory, leave old data in */
+	(void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
+
+	oldbuf = el->el_line.buffer;
+
+	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);
+	/* don't set new size until all buffers are enlarged */
+	el->el_line.limit  = &newbuffer[sz - EL_LEAVE];
+
+	/*
+	 * Reallocate kill buffer.
+	 */
+	newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz *
+	    sizeof(*newbuffer));
+	if (!newbuffer)
+		return 0;
+
+	/* zero the newly added memory, leave old data in */
+	(void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
+
+	oldkbuf = el->el_chared.c_kill.buf;
+
+	el->el_chared.c_kill.buf = newbuffer;
+	el->el_chared.c_kill.last = newbuffer +
+					(el->el_chared.c_kill.last - oldkbuf);
+	el->el_chared.c_kill.mark = el->el_line.buffer +
+					(el->el_chared.c_kill.mark - oldbuf);
+
+	/*
+	 * Reallocate undo buffer.
+	 */
+	newbuffer = el_realloc(el->el_chared.c_undo.buf,
+	    newsz * sizeof(*newbuffer));
+	if (!newbuffer)
+		return 0;
+
+	/* zero the newly added memory, leave old data in */
+	(void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
+	el->el_chared.c_undo.buf = newbuffer;
+
+	newbuffer = el_realloc(el->el_chared.c_redo.buf,
+	    newsz * sizeof(*newbuffer));
+	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];
+	if (el->el_chared.c_resizefun)
+		(*el->el_chared.c_resizefun)(el, el->el_chared.c_resizearg);
+	return 1;
+}
+
+/* ch_end():
+ *	Free the data structures used by the editor
+ */
+libedit_private void
+ch_end(EditLine *el)
+{
+	el_free(el->el_line.buffer);
+	el->el_line.buffer = NULL;
+	el->el_line.limit = NULL;
+	el_free(el->el_chared.c_undo.buf);
+	el->el_chared.c_undo.buf = NULL;
+	el_free(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(el->el_chared.c_kill.buf);
+	el->el_chared.c_kill.buf = NULL;
+	ch_reset(el);
+}
+
+
+/* el_insertstr():
+ *	Insert string at cursorI
+ */
+int
+el_winsertstr(EditLine *el, const wchar_t *s)
+{
+	size_t len;
+
+	if (s == NULL || (len = wcslen(s)) == 0)
+		return -1;
+	if (el->el_line.lastchar + len >= el->el_line.limit) {
+		if (!ch_enlargebufs(el, len))
+			return -1;
+	}
+
+	c_insert(el, (int)len);
+	while (*s)
+		*el->el_line.cursor++ = *s++;
+	return 0;
+}
+
+
+/* el_deletestr():
+ *	Delete num characters before the cursor
+ */
+void
+el_deletestr(EditLine *el, int n)
+{
+	if (n <= 0)
+		return;
+
+	if (el->el_line.cursor < &el->el_line.buffer[n])
+		return;
+
+	c_delbefore(el, n);		/* delete before dot */
+	el->el_line.cursor -= n;
+	if (el->el_line.cursor < el->el_line.buffer)
+		el->el_line.cursor = el->el_line.buffer;
+}
+
+/* el_cursor():
+ *	Move the cursor to the left or the right of the current position
+ */
+int
+el_cursor(EditLine *el, int n)
+{
+	if (n == 0)
+		goto out;
+
+	el->el_line.cursor += n;
+
+	if (el->el_line.cursor < el->el_line.buffer)
+		el->el_line.cursor = el->el_line.buffer;
+	if (el->el_line.cursor > el->el_line.lastchar)
+		el->el_line.cursor = el->el_line.lastchar;
+out:
+	return (int)(el->el_line.cursor - el->el_line.buffer);
+}
+
+/* c_gets():
+ *	Get a string
+ */
+libedit_private int
+c_gets(EditLine *el, wchar_t *buf, const wchar_t *prompt)
+{
+	ssize_t len;
+	wchar_t *cp = el->el_line.buffer, ch;
+
+	if (prompt) {
+		len = (ssize_t)wcslen(prompt);
+		(void)memcpy(cp, prompt, (size_t)len * sizeof(*cp));
+		cp += len;
+	}
+	len = 0;
+
+	for (;;) {
+		el->el_line.cursor = cp;
+		*cp = ' ';
+		el->el_line.lastchar = cp + 1;
+		re_refresh(el);
+
+		if (el_wgetc(el, &ch) != 1) {
+			ed_end_of_file(el, 0);
+			len = -1;
+			break;
+		}
+
+		switch (ch) {
+
+		case L'\b':	/* Delete and backspace */
+		case 0177:
+			if (len == 0) {
+				len = -1;
+				break;
+			}
+			len--;
+			cp--;
+			continue;
+
+		case 0033:	/* ESC */
+		case L'\r':	/* Newline */
+		case L'\n':
+			buf[len] = ch;
+			break;
+
+		default:
+			if (len >= (ssize_t)(EL_BUFSIZ - 16))
+				terminal_beep(el);
+			else {
+				buf[len++] = ch;
+				*cp++ = ch;
+			}
+			continue;
+		}
+		break;
+	}
+
+	el->el_line.buffer[0] = '\0';
+	el->el_line.lastchar = el->el_line.buffer;
+	el->el_line.cursor = el->el_line.buffer;
+	return (int)len;
+}
+
+
+/* c_hpos():
+ *	Return the current horizontal position of the cursor
+ */
+libedit_private int
+c_hpos(EditLine *el)
+{
+	wchar_t *ptr;
+
+	/*
+	 * Find how many characters till the beginning of this line.
+	 */
+	if (el->el_line.cursor == el->el_line.buffer)
+		return 0;
+	else {
+		for (ptr = el->el_line.cursor - 1;
+		     ptr >= el->el_line.buffer && *ptr != '\n';
+		     ptr--)
+			continue;
+		return (int)(el->el_line.cursor - ptr - 1);
+	}
+}
+
+libedit_private int
+ch_resizefun(EditLine *el, el_zfunc_t f, void *a)
+{
+	el->el_chared.c_resizefun = f;
+	el->el_chared.c_resizearg = a;
+	return 0;
+}
+
+libedit_private int
+ch_aliasfun(EditLine *el, el_afunc_t f, void *a)
+{
+	el->el_chared.c_aliasfun = f;
+	el->el_chared.c_aliasarg = a;
+	return 0;
+}

Copied: vendor/NetBSD/libedit/2017-09-05/chared.h (from r323545, vendor/NetBSD/libedit/dist/chared.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ vendor/NetBSD/libedit/2017-09-05/chared.h	Wed Sep 13 16:05:26 2017	(r323546, copy of r323545, vendor/NetBSD/libedit/dist/chared.h)
@@ -0,0 +1,155 @@
+/*	$NetBSD: chared.h,v 1.30 2016/05/22 19:44:26 christos Exp $	*/
+
+/*-
+ * 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.
+ *
+ *	@(#)chared.h	8.1 (Berkeley) 6/4/93
+ */
+
+/*
+ * el.chared.h: Character editor interface
+ */
+#ifndef _h_el_chared
+#define	_h_el_chared
+
+/*
+ * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
+ * like real vi: i.e. the transition from command<->insert modes moves
+ * the cursor.
+ *
+ * On the other hand we really don't want to move the cursor, because
+ * all the editing commands don't include the character under the cursor.
+ * Probably the best fix is to make all the editing commands aware of
+ * this fact.
+ */
+#define	VI_MOVE
+
+/*
+ * Undo information for vi - no undo in emacs (yet)
+ */
+typedef struct c_undo_t {
+	ssize_t	 len;			/* length of saved line */
+	int	 cursor;		/* position of saved cursor */
+	wchar_t	*buf;			/* full saved text */
+} c_undo_t;
+
+/* redo for vi */
+typedef struct c_redo_t {
+	wchar_t	*buf;			/* redo insert key sequence */
+	wchar_t	*pos;
+	wchar_t	*lim;
+	el_action_t	cmd;		/* command to redo */
+	wchar_t	ch;			/* char that invoked it */
+	int	count;
+	int	action;			/* from cv_action() */
+} c_redo_t;
+
+/*
+ * Current action information for vi
+ */
+typedef struct c_vcmd_t {
+	int	 action;
+	wchar_t	*pos;
+} c_vcmd_t;
+
+/*

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


More information about the svn-src-all mailing list