Import libedit 2016-03-21

Obtained from:	NetBSD
This commit is contained in:
Pedro F. Giffuni 2017-01-30 22:35:42 +00:00
parent 034904e961
commit 70f1d4d70d
9 changed files with 53 additions and 57 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.55 2016/02/24 14:25:38 christos Exp $
# $NetBSD: Makefile,v 1.56 2016/03/02 19:24:20 christos Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
@ -53,8 +53,8 @@ CLEANFILES+=help.c.tmp help.h.tmp vi.h.tmp tc1.o tc1
CLEANFILES+=tokenizern.c.tmp tokenizern.c tokenizerw.c.tmp tokenizerw.c
CPPFLAGS+=-I. -I${LIBEDITDIR}
CPPFLAGS+=-I. -I${.CURDIR}
CPPFLAGS+=#-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH
CPPFLAGS+=#-DDEBUG_PASTE -DDEBUG_EDIT
#CPPFLAGS+=-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -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

View File

@ -1,4 +1,4 @@
/* $NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $ */
/* $NetBSD: rl1.c,v 1.2 2016/02/29 00:54:19 christos Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@ -15,13 +15,6 @@
* 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 NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@ -38,7 +31,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $");
__RCSID("$NetBSD: rl1.c,v 1.2 2016/02/29 00:54:19 christos Exp $");
#endif /* not lint */
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: chartype.h,v 1.23 2016/02/24 17:20:01 christos Exp $ */
/* $NetBSD: chartype.h,v 1.25 2016/03/07 00:05:20 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -12,13 +12,6 @@
* 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 NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@ -70,6 +63,7 @@
#define FUNW(type) type ## _w
#define TYPE(type) type ## W
#define FSTR "%ls"
#define FSTARSTR "%.*ls"
#define STR(x) L ## x
#define UC(c) c
#define Isalpha(x) iswalpha(x)
@ -122,6 +116,7 @@ Width(wchar_t c)
#define FUNW(type) type
#define TYPE(type) type
#define FSTR "%s"
#define FSTARSTR "%.*s"
#define STR(x) x
#define UC(c) (unsigned char)(c)

View File

@ -1,4 +1,4 @@
/* $NetBSD: common.c,v 1.39 2016/02/24 14:25:38 christos Exp $ */
/* $NetBSD: common.c,v 1.40 2016/03/02 19:24:20 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: common.c,v 1.39 2016/02/24 14:25:38 christos Exp $");
__RCSID("$NetBSD: common.c,v 1.40 2016/03/02 19:24:20 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -147,8 +147,9 @@ ed_delete_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
{
#ifdef DEBUG_EDIT
#define EL el->el_line
(void) fprintf(el->el_errlfile,
"\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n",
(void) fprintf(el->el_errfile,
"\nD(b: %p(" FSTR ") c: %p(" FSTR ") last: %p(" FSTR
") limit: %p(" FSTR ")\n",
EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar,
EL.lastchar, EL.limit, EL.limit);
#endif

6
read.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: read.c,v 1.85 2016/02/24 17:20:01 christos Exp $ */
/* $NetBSD: read.c,v 1.86 2016/03/02 19:24:20 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: read.c,v 1.85 2016/02/24 17:20:01 christos Exp $");
__RCSID("$NetBSD: read.c,v 1.86 2016/03/02 19:24:20 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -615,7 +615,7 @@ FUN(el,gets)(EditLine *el, int *nread)
break;
if (b->name)
(void) fprintf(el->el_errfile,
"Executing %s\n", b->name);
"Executing " FSTR "\n", b->name);
else
(void) fprintf(el->el_errfile,
"Error command = %d\n", cmdnum);

View File

@ -1,4 +1,4 @@
/* $NetBSD: refresh.c,v 1.44 2016/02/17 19:47:49 christos Exp $ */
/* $NetBSD: refresh.c,v 1.45 2016/03/02 19:24:20 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)refresh.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: refresh.c,v 1.44 2016/02/17 19:47:49 christos Exp $");
__RCSID("$NetBSD: refresh.c,v 1.45 2016/03/02 19:24:20 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -61,7 +61,7 @@ private void re__strncopy(Char *, Char *, size_t);
private void re__copy_and_pad(Char *, const Char *, size_t);
#ifdef DEBUG_REFRESH
private void re_printstr(EditLine *, const char *, char *, char *);
private void re_printstr(EditLine *, const char *, Char *, Char *);
#define __F el->el_errfile
#define ELRE_ASSERT(a, b, c) do \
if (/*CONSTCOND*/ a) { \
@ -75,7 +75,7 @@ private void re_printstr(EditLine *, const char *, char *, char *);
* Print a string on the debugging pty
*/
private void
re_printstr(EditLine *el, const char *str, char *f, char *t)
re_printstr(EditLine *el, const char *str, Char *f, Char *t)
{
ELRE_DEBUG(1, (__F, "%s:\"", str));
@ -205,7 +205,7 @@ re_refresh(EditLine *el)
size_t termsz;
#endif
ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%s:\r\n",
ELRE_DEBUG(1, (__F, "el->el_line.buffer = :" FSTR ":\r\n",
el->el_line.buffer));
/* reset the Drawing cursor */
@ -293,7 +293,8 @@ re_refresh(EditLine *el)
ELRE_DEBUG(1, (__F,
"term.h=%d vcur.h=%d vcur.v=%d vdisplay[0]=\r\n:%80.80s:\r\n",
el->el_terminal.t_size.h, el->el_refresh.r_cursor.h,
el->el_refresh.r_cursor.v, ct_encode_string(el->el_vdisplay[0])));
el->el_refresh.r_cursor.v, ct_encode_string(el->el_vdisplay[0],
&el->el_scratch)));
ELRE_DEBUG(1, (__F, "updating %d lines.\r\n", el->el_refresh.r_newcv));
for (i = 0; i <= el->el_refresh.r_newcv; i++) {
@ -321,7 +322,7 @@ re_refresh(EditLine *el)
/* This Strlen should be safe even with MB_FILL_CHARs */
terminal_clear_EOL(el, (int) Strlen(el->el_display[i]));
#ifdef DEBUG_REFRESH
terminal_overwrite(el, "C\b", (size_t)2);
terminal_overwrite(el, STR("C\b"), 2);
#endif /* DEBUG_REFRESH */
el->el_display[i][0] = '\0';
}
@ -368,8 +369,9 @@ re_insert(EditLine *el __attribute__((__unused__)),
ELRE_DEBUG(1,
(__F, "re_insert() starting: %d at %d max %d, d == \"%s\"\n",
num, dat, dlen, ct_encode_string(d)));
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s)));
num, dat, dlen, ct_encode_string(d, &el->el_scratch)));
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s,
&el->el_scratch)));
/* open up the space for num chars */
if (num > 0) {
@ -382,8 +384,9 @@ re_insert(EditLine *el __attribute__((__unused__)),
ELRE_DEBUG(1, (__F,
"re_insert() after insert: %d at %d max %d, d == \"%s\"\n",
num, dat, dlen, ct_encode_string(d)));
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s)));
num, dat, dlen, ct_encode_string(d, &el->el_scratch)));
ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s,
&el->el_scratch)));
/* copy the characters */
for (a = d + dat; (a < d + dlen) && (num > 0); num--)
@ -418,7 +421,7 @@ re_delete(EditLine *el __attribute__((__unused__)),
}
ELRE_DEBUG(1,
(__F, "re_delete() starting: %d at %d max %d, d == \"%s\"\n",
num, dat, dlen, ct_encode_string(d)));
num, dat, dlen, ct_encode_string(d, &el->el_scratch)));
/* open up the space for num chars */
if (num > 0) {
@ -430,7 +433,7 @@ re_delete(EditLine *el __attribute__((__unused__)),
}
ELRE_DEBUG(1,
(__F, "re_delete() after delete: %d at %d max %d, d == \"%s\"\n",
num, dat, dlen, ct_encode_string(d)));
num, dat, dlen, ct_encode_string(d, &el->el_scratch)));
}
@ -688,9 +691,9 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
sx = (int)((nls - nse) - (ols - ose));
ELRE_DEBUG(1, (__F, "fx %d, sx %d\n", fx, sx));
ELRE_DEBUG(1, (__F, "ofd %d, osb %d, ose %d, ols %d, oe %d\n",
ELRE_DEBUG(1, (__F, "ofd %td, osb %td, ose %td, ols %td, oe %td\n",
ofd - old, osb - old, ose - old, ols - old, oe - old));
ELRE_DEBUG(1, (__F, "nfd %d, nsb %d, nse %d, nls %d, ne %d\n",
ELRE_DEBUG(1, (__F, "nfd %td, nsb %td, nse %td, nls %td, ne %td\n",
nfd - new, nsb - new, nse - new, nls - new, ne - new));
ELRE_DEBUG(1, (__F,
"xxx-xxx:\"00000000001111111111222222222233333333334\"\r\n"));
@ -764,7 +767,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
if ((nsb != nfd) && fx > 0 &&
((p - old) + fx <= el->el_terminal.t_size.h)) {
ELRE_DEBUG(1,
(__F, "first diff insert at %d...\r\n", nfd - new));
(__F, "first diff insert at %td...\r\n", nfd - new));
/*
* Move to the first char to insert, where the first diff is.
*/
@ -803,7 +806,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
}
} else if (fx < 0) {
ELRE_DEBUG(1,
(__F, "first diff delete at %d...\r\n", ofd - old));
(__F, "first diff delete at %td...\r\n", ofd - old));
/*
* move to the first char to delete where the first diff is
*/
@ -850,7 +853,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
if (sx < 0 && (ose - old) + fx < el->el_terminal.t_size.h) {
ELRE_DEBUG(1, (__F,
"second diff delete at %d...\r\n", (ose - old) + fx));
"second diff delete at %td...\r\n", (ose - old) + fx));
/*
* Check if we have stuff to delete
*/
@ -888,7 +891,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
* if we have a first insert AND WE HAVEN'T ALREADY DONE IT...
*/
if ((nsb != nfd) && (osb - ofd) <= (nsb - nfd) && (fx == 0)) {
ELRE_DEBUG(1, (__F, "late first diff insert at %d...\r\n",
ELRE_DEBUG(1, (__F, "late first diff insert at %td...\r\n",
nfd - new));
terminal_move_to_char(el, (int)(nfd - new));

View File

@ -1,4 +1,4 @@
/* $NetBSD: terminal.c,v 1.22 2016/02/17 19:47:49 christos Exp $ */
/* $NetBSD: terminal.c,v 1.24 2016/03/22 01:38:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#else
__RCSID("$NetBSD: terminal.c,v 1.22 2016/02/17 19:47:49 christos Exp $");
__RCSID("$NetBSD: terminal.c,v 1.24 2016/03/22 01:38:17 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -378,7 +378,7 @@ terminal_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
*/
tlen = 0;
for (tmp = tlist; tmp < &tlist[T_str]; tmp++)
if (*tmp != NULL && *tmp != '\0' && *tmp != *str) {
if (*tmp != NULL && **tmp != '\0' && *tmp != *str) {
char *ptr;
for (ptr = *tmp; *ptr != '\0'; termbuf[tlen++] = *ptr++)
@ -666,7 +666,7 @@ terminal_overwrite(EditLine *el, const Char *cp, size_t n)
if (n > (size_t)el->el_terminal.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
"%s: n is ridiculous: %d\r\n", __func__, n);
"%s: n is ridiculous: %zu\r\n", __func__, n);
#endif /* DEBUG_SCREEN */
return;
}

11
tty.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: tty.c,v 1.58 2016/02/27 18:13:21 christos Exp $ */
/* $NetBSD: tty.c,v 1.59 2016/03/22 01:34:32 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: tty.c,v 1.58 2016/02/27 18:13:21 christos Exp $");
__RCSID("$NetBSD: tty.c,v 1.59 2016/03/22 01:34:32 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -498,10 +498,12 @@ tty_setup(EditLine *el)
{
int rst = 1;
el->el_tty.t_initialized = 0;
if (el->el_flags & EDIT_DISABLED)
return 0;
if (el->el_tty.t_initialized)
return -1;
if (!isatty(el->el_outfd)) {
#ifdef DEBUG_TTY
(void) fprintf(el->el_errfile, "%s: isatty: %s\n", __func__,
@ -571,6 +573,7 @@ tty_init(EditLine *el)
el->el_tty.t_mode = EX_IO;
el->el_tty.t_vdisable = _POSIX_VDISABLE;
el->el_tty.t_initialized = 0;
(void) memcpy(el->el_tty.t_t, ttyperm, sizeof(ttyperm_t));
(void) memcpy(el->el_tty.t_c, ttychar, sizeof(ttychar_t));
return tty_setup(el);
@ -587,7 +590,7 @@ tty_end(EditLine *el)
if (el->el_flags & EDIT_DISABLED)
return;
if (el->el_tty.t_initialized)
if (!el->el_tty.t_initialized)
return;
if (tty_setty(el, TCSAFLUSH, &el->el_tty.t_or) == -1) {

7
vi.c
View File

@ -1,4 +1,4 @@
/* $NetBSD: vi.c,v 1.54 2016/02/17 19:47:49 christos Exp $ */
/* $NetBSD: vi.c,v 1.55 2016/03/02 19:24:20 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: vi.c,v 1.54 2016/02/17 19:47:49 christos Exp $");
__RCSID("$NetBSD: vi.c,v 1.55 2016/03/02 19:24:20 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -103,7 +103,8 @@ cv_paste(EditLine *el, wint_t c)
if (k->buf == NULL || len == 0)
return CC_ERROR;
#ifdef DEBUG_PASTE
(void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", (int)len, k->buf);
(void) fprintf(el->el_errfile, "Paste: \"" FSTARSTR "\"\n", (int)len,
k->buf);
#endif
cv_undo(el);