aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2012-09-25 10:41:30 +0000
committerEd Schouten <ed@FreeBSD.org>2012-09-25 10:41:30 +0000
commit4935023390c7a3c08b4506f8947162bf27915c0c (patch)
treea56e5ec831d235173cea6c673a47c2aa551eec2f
parentc83d78a78592d3fbea7064fc85784b780e912284 (diff)
Vendor import NetBSD's libedit of "2012/09/25 10:41:11 UTC".vendor/NetBSD/libedit/2012-09-25
Obtained from: NetBSD
Notes
Notes: svn path=/vendor/NetBSD/libedit/dist/; revision=240915 svn path=/vendor/NetBSD/libedit/2012-09-25/; revision=240916; tag=vendor/NetBSD/libedit/2012-09-25
-rw-r--r--Makefile22
-rw-r--r--TEST/rl1.c59
-rw-r--r--TEST/wtc1.c15
-rw-r--r--chared.c144
-rw-r--r--chared.h7
-rw-r--r--chartype.c54
-rw-r--r--chartype.h17
-rw-r--r--common.c156
-rw-r--r--config.h291
-rw-r--r--editline.328
-rw-r--r--editrc.57
-rw-r--r--el.c131
-rw-r--r--el.h14
-rw-r--r--eln.c34
-rw-r--r--emacs.c74
-rw-r--r--filecomplete.c204
-rw-r--r--hist.c38
-rw-r--r--hist.h10
-rw-r--r--histedit.h7
-rw-r--r--history.c250
-rw-r--r--keymacro.c (renamed from key.c)308
-rw-r--r--keymacro.h (renamed from key.h)52
-rw-r--r--makelist7
-rw-r--r--map.c155
-rw-r--r--parse.c48
-rw-r--r--prompt.c10
-rw-r--r--read.c141
-rw-r--r--readline.c552
-rw-r--r--readline/readline.h4
-rw-r--r--refresh.c152
-rw-r--r--search.c87
-rw-r--r--sig.c8
-rw-r--r--sys.h69
-rw-r--r--terminal.c (renamed from term.c)786
-rw-r--r--terminal.h (renamed from term.h)73
-rw-r--r--tokenizer.c66
-rw-r--r--tty.c138
-rw-r--r--tty.h6
-rw-r--r--vi.c187
39 files changed, 2366 insertions, 2045 deletions
diff --git a/Makefile b/Makefile
index cd88a787b401..0880363d11ec 100644
--- a/Makefile
+++ b/Makefile
@@ -1,17 +1,22 @@
-# $NetBSD: Makefile,v 1.41 2010/02/03 15:34:43 roy Exp $
+# $NetBSD: Makefile,v 1.51 2012/08/10 12:20:10 joerg Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
USE_SHLIBDIR= yes
WIDECHAR ?= yes
-WARNS= 4
+WARNS?= 5
LIB= edit
LIBDPLIBS+= terminfo ${.CURDIR}/../libterminfo
+.include "bsd.own.mk"
+
+COPTS+= -Wunused-parameter
+CWARNFLAGS.gcc+= -Wconversion
+
OSRCS= chared.c common.c el.c emacs.c fcns.c filecomplete.c help.c \
- hist.c key.c map.c chartype.c \
- parse.c prompt.c read.c refresh.c search.c sig.c term.c tty.c vi.c
+ hist.c keymacro.c map.c chartype.c \
+ parse.c prompt.c read.c refresh.c search.c sig.c terminal.c tty.c vi.c
MAN= editline.3 editrc.5
@@ -113,10 +118,17 @@ historyn.c: makelist Makefile
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) && ${HAVE_GCC} >= 45
+COPTS.editline.c+= -Wno-cast-qual
+COPTS.tokenizer.c+= -Wno-cast-qual
+COPTS.tokenizern.c+= -Wno-cast-qual
+.endif
diff --git a/TEST/rl1.c b/TEST/rl1.c
new file mode 100644
index 000000000000..78ff518e6fe8
--- /dev/null
+++ b/TEST/rl1.c
@@ -0,0 +1,59 @@
+/* $NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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. 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
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION 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>
+#if !defined(lint)
+__RCSID("$NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $");
+#endif /* not lint */
+
+/*
+ * test.c: A little test program
+ */
+#include <stdio.h>
+#include <readline/readline.h>
+
+int
+main(int argc, char *argv[])
+{
+ char *p;
+ while ((p = readline("hi$")) != NULL) {
+ add_history(p);
+ printf("%d %s\n", history_length, p);
+ }
+ return 0;
+}
diff --git a/TEST/wtc1.c b/TEST/wtc1.c
index b1f22a57287f..365bd2e66a72 100644
--- a/TEST/wtc1.c
+++ b/TEST/wtc1.c
@@ -2,6 +2,7 @@
#include <string.h>
#include <signal.h>
#include <sys/wait.h>
+#include <err.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
@@ -14,6 +15,7 @@
static int continuation;
volatile sig_atomic_t gotsig;
+static const char hfile[] = ".whistory";
static wchar_t *
prompt(EditLine *el)
@@ -60,7 +62,8 @@ complete(EditLine *el, int ch)
char *buf, *bptr;
const LineInfoW *lf = el_wline(el);
int len, mblen, i;
- unsigned char res;
+ unsigned char res = 0;
+ wchar_t dir[1024];
/* Find the last word */
for (ptr = lf->cursor -1; !iswspace(*ptr) && ptr > lf->buffer; --ptr)
@@ -70,7 +73,9 @@ complete(EditLine *el, int ch)
/* Convert last word to multibyte encoding, so we can compare to it */
wctomb(NULL, 0); /* Reset shift state */
mblen = MB_LEN_MAX * len + 1;
- buf = bptr =(char *)malloc(mblen);
+ buf = bptr = malloc(mblen);
+ if (buf == NULL)
+ err(1, "malloc");
for (i = 0; i < len; ++i) {
/* Note: really should test for -1 return from wctomb */
bptr += wctomb(bptr, ptr[i]);
@@ -83,7 +88,9 @@ complete(EditLine *el, int ch)
if (mblen > strlen(dp->d_name))
continue;
if (strncmp(dp->d_name, buf, mblen) == 0) {
- if (el_insertstr(el, &dp->d_name[mblen]) == -1)
+ mbstowcs(dir, &dp->d_name[mblen],
+ sizeof(dir) / sizeof(*dir));
+ if (el_winsertstr(el, dir) == -1)
res = CC_ERROR;
else
res = CC_REFRESH;
@@ -119,6 +126,7 @@ main(int argc, char *argv[])
hist = history_winit(); /* Init built-in history */
history_w(hist, &ev, H_SETSIZE, 100); /* Remember 100 events */
+ history_w(hist, &ev, H_LOAD, hfile);
tok = tok_winit(NULL); /* Init the tokenizer */
@@ -260,6 +268,7 @@ main(int argc, char *argv[])
el_end(el);
tok_wend(tok);
+ history_w(hist, &ev, H_SAVE, hfile);
history_wend(hist);
fprintf(stdout, "\n");
diff --git a/chared.c b/chared.c
index a72bb6dc1e34..fb75de8f4a51 100644
--- a/chared.c
+++ b/chared.c
@@ -1,4 +1,4 @@
-/* $NetBSD: chared.c,v 1.28 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: chared.c,v 1.37 2012/07/18 17:12:39 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: chared.c,v 1.28 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.37 2012/07/18 17:12:39 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -63,8 +63,8 @@ cv_undo(EditLine *el)
size_t size;
/* Save entire line for undo */
- size = el->el_line.lastchar - el->el_line.buffer;
- vu->len = size;
+ 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));
@@ -84,7 +84,7 @@ cv_yank(EditLine *el, const Char *ptr, int size)
{
c_kill_t *k = &el->el_chared.c_kill;
- (void)memcpy(k->buf, ptr, size * sizeof(*k->buf));
+ (void)memcpy(k->buf, ptr, (size_t)size * sizeof(*k->buf));
k->last = k->buf + size;
}
@@ -201,7 +201,7 @@ c_delbefore1(EditLine *el)
protected int
ce__isword(Int p)
{
- return (Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL);
+ return Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL;
}
@@ -225,7 +225,7 @@ cv__isword(Int p)
protected int
cv__isWord(Int p)
{
- return (!Isspace(p));
+ return !Isspace(p);
}
@@ -249,7 +249,7 @@ c__prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
if (p < low)
p = low;
/* cp now points where we want it */
- return (p);
+ return p;
}
@@ -268,7 +268,7 @@ c__next_word(Char *p, Char *high, int n, int (*wtest)(Int))
if (p > high)
p = high;
/* p now points where we want it */
- return (p);
+ return p;
}
/* cv_next_word():
@@ -294,9 +294,9 @@ cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int))
/* p now points where we want it */
if (p > high)
- return (high);
+ return high;
else
- return (p);
+ return p;
}
@@ -320,47 +320,12 @@ cv_prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
/* p now points where we want it */
if (p < low)
- return (low);
+ return low;
else
- return (p);
+ return p;
}
-#ifdef notdef
-/* c__number():
- * Ignore character p points to, return number appearing after that.
- * A '$' by itself means a big number; "$-" is for negative; '^' means 1.
- * Return p pointing to last char used.
- */
-protected Char *
-c__number(
- Char *p, /* character position */
- int *num, /* Return value */
- int dval) /* dval is the number to subtract from like $-3 */
-{
- int i;
- int sign = 1;
-
- if (*++p == '^') {
- *num = 1;
- return (p);
- }
- if (*p == '$') {
- if (*++p != '-') {
- *num = 0x7fffffff; /* Handle $ */
- return (--p);
- }
- sign = -1; /* Handle $- */
- ++p;
- }
- /* XXX: this assumes ASCII compatible digits */
- for (i = 0; Isdigit(*p); i = 10 * i + *p++ - '0')
- continue;
- *num = (sign < 0 ? dval - i : i);
- return (--p);
-}
-#endif
-
/* cv_delfini():
* Finish vi delete action
*/
@@ -399,28 +364,6 @@ cv_delfini(EditLine *el)
}
-#ifdef notdef
-/* ce__endword():
- * Go to the end of this word according to emacs
- */
-protected Char *
-ce__endword(Char *p, Char *high, int n)
-{
- p++;
-
- while (n--) {
- while ((p < high) && Isspace(*p))
- p++;
- while ((p < high) && !Isspace(*p))
- p++;
- }
-
- p--;
- return (p);
-}
-#endif
-
-
/* cv__endword():
* Go to the end of this word according to vi
*/
@@ -440,7 +383,7 @@ cv__endword(Char *p, Char *high, int n, int (*wtest)(Int))
p++;
}
p--;
- return (p);
+ return p;
}
/* ch_init():
@@ -454,7 +397,7 @@ 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);
+ return -1;
(void) memset(el->el_line.buffer, 0, EL_BUFSIZ *
sizeof(*el->el_line.buffer));
@@ -465,7 +408,7 @@ ch_init(EditLine *el)
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);
+ 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;
@@ -473,7 +416,7 @@ ch_init(EditLine *el)
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);
+ 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;
@@ -484,11 +427,13 @@ ch_init(EditLine *el)
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);
+ 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_map.current = el->el_map.key;
@@ -502,8 +447,8 @@ ch_init(EditLine *el)
ma->offset = 0;
ma->macro = el_malloc(EL_MAXMACRO * sizeof(*ma->macro));
if (ma->macro == NULL)
- return (-1);
- return (0);
+ return -1;
+ return 0;
}
/* ch_reset():
@@ -542,7 +487,7 @@ ch__clearmacro(EditLine *el)
{
c_macro_t *ma = &el->el_chared.c_macro;
while (ma->level >= 0)
- el_free((ptr_t)ma->macro[ma->level--]);
+ el_free(ma->macro[ma->level--]);
}
/* ch_enlargebufs():
@@ -555,7 +500,7 @@ ch_enlargebufs(EditLine *el, size_t addlen)
size_t sz, newsz;
Char *newbuffer, *oldbuf, *oldkbuf;
- sz = el->el_line.limit - el->el_line.buffer + EL_LEAVE;
+ 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
@@ -587,7 +532,8 @@ ch_enlargebufs(EditLine *el, size_t addlen)
/*
* Reallocate kill buffer.
*/
- newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz * sizeof(*newbuffer));
+ newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz *
+ sizeof(*newbuffer));
if (!newbuffer)
return 0;
@@ -629,6 +575,8 @@ ch_enlargebufs(EditLine *el, size_t addlen)
/* 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;
}
@@ -638,20 +586,20 @@ ch_enlargebufs(EditLine *el, size_t addlen)
protected void
ch_end(EditLine *el)
{
- el_free((ptr_t) el->el_line.buffer);
+ el_free(el->el_line.buffer);
el->el_line.buffer = NULL;
el->el_line.limit = NULL;
- el_free((ptr_t) el->el_chared.c_undo.buf);
+ el_free(el->el_chared.c_undo.buf);
el->el_chared.c_undo.buf = NULL;
- el_free((ptr_t) el->el_chared.c_redo.buf);
+ 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((ptr_t) el->el_chared.c_kill.buf);
+ el_free(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_free(el->el_chared.c_macro.macro);
el->el_chared.c_macro.macro = NULL;
}
@@ -664,17 +612,17 @@ FUN(el,insertstr)(EditLine *el, const Char *s)
{
size_t len;
- if ((len = Strlen(s)) == 0)
- return (-1);
+ if (s == NULL || (len = Strlen(s)) == 0)
+ return -1;
if (el->el_line.lastchar + len >= el->el_line.limit) {
if (!ch_enlargebufs(el, len))
- return (-1);
+ return -1;
}
c_insert(el, (int)len);
while (*s)
*el->el_line.cursor++ = *s++;
- return (0);
+ return 0;
}
@@ -707,8 +655,8 @@ c_gets(EditLine *el, Char *buf, const Char *prompt)
Char *cp = el->el_line.buffer;
if (prompt) {
- len = Strlen(prompt);
- (void)memcpy(cp, prompt, len * sizeof(*cp));
+ len = (ssize_t)Strlen(prompt);
+ (void)memcpy(cp, prompt, (size_t)len * sizeof(*cp));
cp += len;
}
len = 0;
@@ -743,8 +691,8 @@ c_gets(EditLine *el, Char *buf, const Char *prompt)
break;
default:
- if (len >= EL_BUFSIZ - 16)
- term_beep(el);
+ if (len >= (ssize_t)(EL_BUFSIZ - 16))
+ terminal_beep(el);
else {
buf[len++] = ch;
*cp++ = ch;
@@ -773,7 +721,7 @@ c_hpos(EditLine *el)
* Find how many characters till the beginning of this line.
*/
if (el->el_line.cursor == el->el_line.buffer)
- return (0);
+ return 0;
else {
for (ptr = el->el_line.cursor - 1;
ptr >= el->el_line.buffer && *ptr != '\n';
@@ -782,3 +730,11 @@ c_hpos(EditLine *el)
return (int)(el->el_line.cursor - ptr - 1);
}
}
+
+protected 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;
+}
diff --git a/chared.h b/chared.h
index cbe4e5834117..176475ac8f05 100644
--- a/chared.h
+++ b/chared.h
@@ -1,4 +1,4 @@
-/* $NetBSD: chared.h,v 1.20 2010/04/15 00:57:33 christos Exp $ */
+/* $NetBSD: chared.h,v 1.21 2010/08/28 15:44:59 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -103,6 +103,8 @@ typedef struct c_kill_t {
Char *mark;
} c_kill_t;
+typedef void (*el_zfunc_t)(EditLine *, void *);
+
/*
* Note that we use both data structures because the user can bind
* commands from both editors!
@@ -113,6 +115,8 @@ typedef struct el_chared_t {
c_redo_t c_redo;
c_vcmd_t c_vcmd;
c_macro_t c_macro;
+ el_zfunc_t c_resizefun;
+ void * c_resizearg;
} el_chared_t;
@@ -160,6 +164,7 @@ protected int c_hpos(EditLine *);
protected int ch_init(EditLine *);
protected void ch_reset(EditLine *, int);
+protected int ch_resizefun(EditLine *, el_zfunc_t, void *);
protected int ch_enlargebufs(EditLine *, size_t);
protected void ch_end(EditLine *);
diff --git a/chartype.c b/chartype.c
index 3a539d468eb0..8766aacada7c 100644
--- a/chartype.c
+++ b/chartype.c
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.c,v 1.4 2010/04/15 00:55:57 christos Exp $ */
+/* $NetBSD: chartype.c,v 1.10 2011/08/16 16:25:15 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -38,12 +38,12 @@
*/
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: chartype.c,v 1.4 2010/04/15 00:55:57 christos Exp $");
+__RCSID("$NetBSD: chartype.c,v 1.10 2011/08/16 16:25:15 christos Exp $");
#endif /* not lint && not SCCSID */
#include "el.h"
#include <stdlib.h>
-#define CT_BUFSIZ 1024
+#define CT_BUFSIZ ((size_t)1024)
#ifdef WIDECHAR
protected void
@@ -52,7 +52,7 @@ ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize)
void *p;
if (mincsize > conv->csize) {
conv->csize = mincsize;
- p = el_realloc(conv->cbuff, conv->csize);
+ p = el_realloc(conv->cbuff, conv->csize * sizeof(*conv->cbuff));
if (p == NULL) {
conv->csize = 0;
el_free(conv->cbuff);
@@ -63,7 +63,7 @@ ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize)
if (minwsize > conv->wsize) {
conv->wsize = minwsize;
- p = el_realloc(conv->wbuff, conv->wsize);
+ p = el_realloc(conv->wbuff, conv->wsize * sizeof(*conv->wbuff));
if (p == NULL) {
conv->wsize = 0;
el_free(conv->wbuff);
@@ -83,33 +83,27 @@ ct_encode_string(const Char *s, ct_buffer_t *conv)
if (!s)
return NULL;
if (!conv->cbuff)
- ct_conv_buff_resize(conv, CT_BUFSIZ, 0);
+ ct_conv_buff_resize(conv, CT_BUFSIZ, (size_t)0);
if (!conv->cbuff)
return NULL;
dst = conv->cbuff;
while (*s) {
- used = ct_encode_char(dst, (int)(conv->csize -
- (dst - conv->cbuff)), *s);
- if (used == -1) { /* failed to encode, need more buffer space */
+ used = (ssize_t)(conv->csize - (size_t)(dst - conv->cbuff));
+ if (used < 5) {
used = dst - conv->cbuff;
- ct_conv_buff_resize(conv, conv->csize + CT_BUFSIZ, 0);
+ ct_conv_buff_resize(conv, conv->csize + CT_BUFSIZ,
+ (size_t)0);
if (!conv->cbuff)
return NULL;
dst = conv->cbuff + used;
- /* don't increment s here - we want to retry it! */
}
- else
- ++s;
+ used = ct_encode_char(dst, (size_t)5, *s);
+ if (used == -1) /* failed to encode, need more buffer space */
+ abort();
+ ++s;
dst += used;
}
- if (dst >= (conv->cbuff + conv->csize)) {
- used = dst - conv->cbuff;
- ct_conv_buff_resize(conv, conv->csize + 1, 0);
- if (!conv->cbuff)
- return NULL;
- dst = conv->cbuff + used;
- }
*dst = '\0';
return conv->cbuff;
}
@@ -122,13 +116,15 @@ ct_decode_string(const char *s, ct_buffer_t *conv)
if (!s)
return NULL;
if (!conv->wbuff)
- ct_conv_buff_resize(conv, 0, CT_BUFSIZ);
+ ct_conv_buff_resize(conv, (size_t)0, CT_BUFSIZ);
if (!conv->wbuff)
return NULL;
- len = ct_mbstowcs(0, s, 0);
+ len = ct_mbstowcs(NULL, s, (size_t)0);
+ if (len == (size_t)-1)
+ return NULL;
if (len > conv->wsize)
- ct_conv_buff_resize(conv, 0, len + 1);
+ ct_conv_buff_resize(conv, (size_t)0, len + 1);
if (!conv->wbuff)
return NULL;
ct_mbstowcs(conv->wbuff, s, conv->wsize);
@@ -149,11 +145,11 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv)
* the argv strings. */
for (i = 0, bufspace = 0; i < argc; ++i)
bufspace += argv[i] ? strlen(argv[i]) + 1 : 0;
- ct_conv_buff_resize(conv, 0, bufspace);
+ ct_conv_buff_resize(conv, (size_t)0, bufspace);
if (!conv->wsize)
return NULL;
- wargv = el_malloc(argc * sizeof(*wargv));
+ wargv = el_malloc((size_t)argc * sizeof(*wargv));
for (i = 0, p = conv->wbuff; i < argc; ++i) {
if (!argv[i]) { /* don't pass null pointers to mbstowcs */
@@ -161,14 +157,14 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv)
continue;
} else {
wargv[i] = p;
- bytes = mbstowcs(p, argv[i], bufspace);
+ bytes = (ssize_t)mbstowcs(p, argv[i], bufspace);
}
if (bytes == -1) {
el_free(wargv);
return NULL;
} else
bytes++; /* include '\0' in the count */
- bufspace -= bytes;
+ bufspace -= (size_t)bytes;
p += bytes;
}
@@ -225,7 +221,7 @@ ct_visual_string(const Char *s)
}
dst = buff;
while (*s) {
- used = ct_visual_char(dst, buffsize - (dst - buff), *s);
+ used = ct_visual_char(dst, buffsize - (size_t)(dst - buff), *s);
if (used == -1) { /* failed to encode, need more buffer space */
used = dst - buff;
buffsize += CT_BUFSIZ;
@@ -326,7 +322,7 @@ ct_visual_char(Char *dst, size_t len, Char c)
*dst++ = tohexdigit(((unsigned int) c >> 8) & 0xf);
*dst++ = tohexdigit(((unsigned int) c >> 4) & 0xf);
*dst = tohexdigit(((unsigned int) c ) & 0xf);
- return (c > 0xffff) ? 8 : 7;
+ return c > 0xffff ? 8 : 7;
#else
*dst++ = '\\';
#define tooctaldigit(v) ((v) + '0')
diff --git a/chartype.h b/chartype.h
index f5440b4fd8dc..78407f6c4a31 100644
--- a/chartype.h
+++ b/chartype.h
@@ -1,4 +1,4 @@
-/* $NetBSD: chartype.h,v 1.6 2010/04/20 02:01:13 christos Exp $ */
+/* $NetBSD: chartype.h,v 1.10 2011/11/16 01:45:10 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
#endif
#define ct_mbtowc mbtowc
-#define ct_mbtowc_reset mbtowc(0,0,0)
+#define ct_mbtowc_reset mbtowc(0,0,(size_t)0)
#define ct_wctomb wctomb
#define ct_wctomb_reset wctomb(0,0)
#define ct_wcstombs wcstombs
@@ -105,7 +105,12 @@
#define Strtol(p,e,b) wcstol(p,e,b)
-#define Width(c) wcwidth(c)
+static inline int
+Width(wchar_t c)
+{
+ int w = wcwidth(c);
+ return w < 0 ? 0 : w;
+}
#else /* NARROW */
@@ -172,11 +177,11 @@ typedef struct ct_buffer_t {
} ct_buffer_t;
#define ct_encode_string __ct_encode_string
-/* Encode a wide character string and return the UTF-8 encoded result. */
+/* Encode a wide-character string and return the UTF-8 encoded result. */
public char *ct_encode_string(const Char *, ct_buffer_t *);
#define ct_decode_string __ct_decode_string
-/* Decode a (multi)?byte string and return the wide character string result. */
+/* Decode a (multi)?byte string and return the wide-character string result. */
public Char *ct_decode_string(const char *, ct_buffer_t *);
/* Decode a (multi)?byte argv string array.
@@ -206,7 +211,7 @@ protected size_t ct_enc_width(Char);
/* The maximum buffer size to hold the most unwieldly visual representation,
* in this case \U+nnnnn. */
-#define VISUAL_WIDTH_MAX 8
+#define VISUAL_WIDTH_MAX ((size_t)8)
/* The terminal is thought of in terms of X columns by Y lines. In the cases
* where a wide character takes up more than one column, the adjacent
diff --git a/common.c b/common.c
index 6d68e004cda0..1726b0f812fb 100644
--- a/common.c
+++ b/common.c
@@ -1,4 +1,4 @@
-/* $NetBSD: common.c,v 1.24 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: common.c,v 1.29 2012/03/24 20:08:43 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.24 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: common.c,v 1.29 2012/03/24 20:08:43 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -57,7 +57,7 @@ ed_end_of_file(EditLine *el, Int c __attribute__((__unused__)))
re_goto_bottom(el);
*el->el_line.lastchar = '\0';
- return (CC_EOF);
+ return CC_EOF;
}
@@ -71,7 +71,7 @@ ed_insert(EditLine *el, Int c)
int count = el->el_state.argument;
if (c == '\0')
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_line.lastchar + el->el_state.argument >=
el->el_line.limit) {
@@ -99,7 +99,7 @@ ed_insert(EditLine *el, Int c)
if (el->el_state.inputmode == MODE_REPLACE_1)
return vi_command_mode(el, 0);
- return (CC_NORM);
+ return CC_NORM;
}
@@ -114,7 +114,7 @@ ed_delete_prev_word(EditLine *el, Int c __attribute__((__unused__)))
Char *cp, *p, *kp;
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
el->el_state.argument, ce__isword);
@@ -127,7 +127,7 @@ ed_delete_prev_word(EditLine *el, Int c __attribute__((__unused__)))
el->el_line.cursor = cp;
if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer; /* bounds check */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -137,9 +137,9 @@ ed_delete_prev_word(EditLine *el, Int c __attribute__((__unused__)))
*/
protected el_action_t
/*ARGSUSED*/
-ed_delete_next_char(EditLine *el, Int c)
+ed_delete_next_char(EditLine *el, Int c __attribute__((__unused__)))
{
-#ifdef notdef /* XXX */
+#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",
@@ -152,32 +152,29 @@ ed_delete_next_char(EditLine *el, Int c)
if (el->el_line.cursor == el->el_line.buffer) {
/* if I'm also at the beginning */
#ifdef KSHVI
- return (CC_ERROR);
+ return CC_ERROR;
#else
/* then do an EOF */
- term_writec(el, c);
- return (CC_EOF);
+ terminal_writec(el, c);
+ return CC_EOF;
#endif
} else {
#ifdef KSHVI
el->el_line.cursor--;
#else
- return (CC_ERROR);
+ return CC_ERROR;
#endif
}
- } else {
- if (el->el_line.cursor != el->el_line.buffer)
- el->el_line.cursor--;
- else
- return (CC_ERROR);
- }
+ } else
+ return CC_ERROR;
}
c_delafter(el, el->el_state.argument); /* delete after dot */
- if (el->el_line.cursor >= el->el_line.lastchar &&
+ if (el->el_map.type == MAP_VI &&
+ el->el_line.cursor >= el->el_line.lastchar &&
el->el_line.cursor > el->el_line.buffer)
/* bounds check */
el->el_line.cursor = el->el_line.lastchar - 1;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -198,7 +195,7 @@ ed_kill_line(EditLine *el, Int c __attribute__((__unused__)))
el->el_chared.c_kill.last = kp;
/* zap! -- delete to end */
el->el_line.lastchar = el->el_line.cursor;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -215,13 +212,13 @@ ed_move_to_end(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_map.type == MAP_VI) {
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
#ifdef VI_MOVE
el->el_line.cursor--;
#endif
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -242,10 +239,10 @@ ed_move_to_beg(EditLine *el, Int c __attribute__((__unused__)))
el->el_line.cursor++;
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -259,7 +256,7 @@ ed_transpose_chars(EditLine *el, Int c)
if (el->el_line.cursor < el->el_line.lastchar) {
if (el->el_line.lastchar <= &el->el_line.buffer[1])
- return (CC_ERROR);
+ return CC_ERROR;
else
el->el_line.cursor++;
}
@@ -268,9 +265,9 @@ ed_transpose_chars(EditLine *el, Int c)
c = el->el_line.cursor[-2];
el->el_line.cursor[-2] = el->el_line.cursor[-1];
el->el_line.cursor[-1] = c;
- return (CC_REFRESH);
+ return CC_REFRESH;
} else
- return (CC_ERROR);
+ return CC_ERROR;
}
@@ -288,7 +285,7 @@ ed_next_char(EditLine *el, Int c __attribute__((__unused__)))
(el->el_line.cursor == lim - 1 &&
el->el_map.type == MAP_VI &&
el->el_chared.c_vcmd.action == NOP))
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor += el->el_state.argument;
if (el->el_line.cursor > lim)
@@ -297,9 +294,9 @@ ed_next_char(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -313,7 +310,7 @@ ed_prev_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = c__prev_word(el->el_line.cursor,
el->el_line.buffer,
@@ -323,9 +320,9 @@ ed_prev_word(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -346,11 +343,11 @@ ed_prev_char(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
} else
- return (CC_ERROR);
+ return CC_ERROR;
}
@@ -369,9 +366,9 @@ ed_quoted_insert(EditLine *el, Int c)
c = tc;
tty_noquotemode(el);
if (num == 1)
- return (ed_insert(el, c));
+ return ed_insert(el, c);
else
- return (ed_end_of_file(el, 0));
+ return ed_end_of_file(el, 0);
}
@@ -383,7 +380,7 @@ ed_digit(EditLine *el, Int c)
{
if (!Isdigit(c))
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_state.doingarg) {
/* if doing an arg, add this in... */
@@ -391,11 +388,11 @@ ed_digit(EditLine *el, Int c)
el->el_state.argument = c - '0';
else {
if (el->el_state.argument > 1000000)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_state.argument =
(el->el_state.argument * 10) + (c - '0');
}
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
return ed_insert(el, c);
@@ -411,18 +408,18 @@ ed_argument_digit(EditLine *el, Int c)
{
if (!Isdigit(c))
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_state.doingarg) {
if (el->el_state.argument > 1000000)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_state.argument = (el->el_state.argument * 10) +
(c - '0');
} else { /* else starting an argument */
el->el_state.argument = c - '0';
el->el_state.doingarg = 1;
}
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
@@ -432,10 +429,11 @@ ed_argument_digit(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-ed_unassigned(EditLine *el, Int c __attribute__((__unused__)))
+ed_unassigned(EditLine *el __attribute__((__unused__)),
+ Int c __attribute__((__unused__)))
{
- return (CC_ERROR);
+ return CC_ERROR;
}
@@ -453,7 +451,7 @@ ed_tty_sigint(EditLine *el __attribute__((__unused__)),
Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -467,7 +465,7 @@ ed_tty_dsusp(EditLine *el __attribute__((__unused__)),
Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -481,7 +479,7 @@ ed_tty_flush_output(EditLine *el __attribute__((__unused__)),
Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -495,7 +493,7 @@ ed_tty_sigquit(EditLine *el __attribute__((__unused__)),
Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -509,7 +507,7 @@ ed_tty_sigtstp(EditLine *el __attribute__((__unused__)),
Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -523,7 +521,7 @@ ed_tty_stop_output(EditLine *el __attribute__((__unused__)),
Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -537,7 +535,7 @@ ed_tty_start_output(EditLine *el __attribute__((__unused__)),
Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -553,7 +551,7 @@ ed_newline(EditLine *el, Int c __attribute__((__unused__)))
re_goto_bottom(el);
*el->el_line.lastchar++ = '\n';
*el->el_line.lastchar = '\0';
- return (CC_NEWLINE);
+ return CC_NEWLINE;
}
@@ -567,13 +565,13 @@ ed_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor <= el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
c_delbefore(el, el->el_state.argument);
el->el_line.cursor -= el->el_state.argument;
if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -586,9 +584,9 @@ protected el_action_t
ed_clear_screen(EditLine *el, Int c __attribute__((__unused__)))
{
- term_clear_screen(el); /* clear the whole real screen */
+ terminal_clear_screen(el); /* clear the whole real screen */
re_clear_display(el); /* reset everything */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -602,7 +600,7 @@ ed_redisplay(EditLine *el __attribute__((__unused__)),
Int c __attribute__((__unused__)))
{
- return (CC_REDISPLAY);
+ return CC_REDISPLAY;
}
@@ -616,7 +614,7 @@ ed_start_over(EditLine *el, Int c __attribute__((__unused__)))
{
ch_reset(el, 0);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -630,7 +628,7 @@ ed_sequence_lead_in(EditLine *el __attribute__((__unused__)),
Int c __attribute__((__unused__)))
{
- return (CC_NORM);
+ return CC_NORM;
}
@@ -720,7 +718,7 @@ ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__)))
"e_prev_search_hist(): eventno < 0;\n");
#endif
el->el_history.eventno = 0;
- return (CC_ERROR);
+ return CC_ERROR;
}
if (el->el_history.eventno == 0) {
(void) Strncpy(el->el_history.buf, el->el_line.buffer,
@@ -729,11 +727,11 @@ ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__)))
(el->el_line.lastchar - el->el_line.buffer);
}
if (el->el_history.ref == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
hp = HIST_FIRST(el);
if (hp == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
c_setpat(el); /* Set search pattern !! */
@@ -759,11 +757,11 @@ ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__)))
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "not found\n");
#endif
- return (CC_ERROR);
+ return CC_ERROR;
}
el->el_history.eventno = h;
- return (hist_get(el));
+ return hist_get(el);
}
@@ -784,14 +782,14 @@ ed_search_next_history(EditLine *el, Int c __attribute__((__unused__)))
*el->el_line.lastchar = '\0'; /* just in case */
if (el->el_history.eventno == 0)
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_history.ref == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
hp = HIST_FIRST(el);
if (hp == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
c_setpat(el); /* Set search pattern !! */
@@ -812,12 +810,12 @@ ed_search_next_history(EditLine *el, Int c __attribute__((__unused__)))
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "not found\n");
#endif
- return (CC_ERROR);
+ return CC_ERROR;
}
}
el->el_history.eventno = found;
- return (hist_get(el));
+ return hist_get(el);
}
@@ -843,7 +841,7 @@ ed_prev_line(EditLine *el, Int c __attribute__((__unused__)))
break;
if (el->el_state.argument > 0)
- return (CC_ERROR);
+ return CC_ERROR;
/*
* Move to the beginning of the line
@@ -860,7 +858,7 @@ ed_prev_line(EditLine *el, Int c __attribute__((__unused__)))
continue;
el->el_line.cursor = ptr;
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -883,7 +881,7 @@ ed_next_line(EditLine *el, Int c __attribute__((__unused__)))
break;
if (el->el_state.argument > 0)
- return (CC_ERROR);
+ return CC_ERROR;
/*
* Move to the character requested
@@ -894,7 +892,7 @@ ed_next_line(EditLine *el, Int c __attribute__((__unused__)))
continue;
el->el_line.cursor = ptr;
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -910,10 +908,10 @@ ed_command(EditLine *el, Int c __attribute__((__unused__)))
int tmplen;
tmplen = c_gets(el, tmpbuf, STR("\n: "));
- term__putc(el, '\n');
+ terminal__putc(el, '\n');
if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
- term_beep(el);
+ terminal_beep(el);
el->el_map.current = el->el_map.key;
re_clear_display(el);
diff --git a/config.h b/config.h
index f622db133710..d5cb57a6a44d 100644
--- a/config.h
+++ b/config.h
@@ -1,20 +1,289 @@
-/* config.h. Generated automatically by configure. */
-/* #undef SUNOS */
+/* config.h. Generated from config.h.in by configure. */
+/* config.h.in. Generated from configure.ac by autoheader. */
-#define HAVE_SYS_CDEFS_H 1
-#define HAVE_TERMCAP_H 1
-/* #undef HAVE_CURSES_H */
-/* #undef HAVE_NCURSES_H */
-/* #undef HAVE_TERM_H */
-#define HAVE_VIS_H 1
+/* Define to 1 if the `closedir' function returns void instead of `int'. */
+/* #undef CLOSEDIR_VOID */
+
+/* Define to 1 if you have the <curses.h> header file. */
+#define HAVE_CURSES_H 1
+
+/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
+ */
+#define HAVE_DIRENT_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the `endpwent' function. */
+#define HAVE_ENDPWENT 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the `fgetln' function. */
+#define HAVE_FGETLN 1
+
+/* Define to 1 if you have the `fork' function. */
+#define HAVE_FORK 1
+
+/* Define to 1 if you have getpwnam_r and getpwuid_r that are draft POSIX.1
+ versions. */
+/* #undef HAVE_GETPW_R_DRAFT */
+
+/* Define to 1 if you have getpwnam_r and getpwuid_r that are POSIX.1
+ compatible. */
+#define HAVE_GETPW_R_POSIX 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `isascii' function. */
+#define HAVE_ISASCII 1
+
+/* Define to 1 if you have the `issetugid' function. */
#define HAVE_ISSETUGID 1
+/* Define to 1 if you have the `curses' library (-lcurses). */
+/* #undef HAVE_LIBCURSES */
+
+/* Define to 1 if you have the `ncurses' library (-lncurses). */
+/* #undef HAVE_LIBNCURSES */
+
+/* Define to 1 if you have the `termcap' library (-ltermcap). */
+/* #undef HAVE_LIBTERMCAP */
+
+/* Define to 1 if you have the `terminfo' library (-lterminfo). */
+#define HAVE_LIBTERMINFO 1
+
+/* Define to 1 if you have the `termlib' library (-ltermlib). */
+/* #undef HAVE_LIBTERMLIB */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <malloc.h> header file. */
+#define HAVE_MALLOC_H 1
+
+/* Define to 1 if you have the `memchr' function. */
+#define HAVE_MEMCHR 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `memset' function. */
+#define HAVE_MEMSET 1
+
+/* Define to 1 if you have the <ncurses.h> header file. */
+/* #undef HAVE_NCURSES_H */
+
+/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
+/* #undef HAVE_NDIR_H */
+
+/* Define to 1 if you have the `regcomp' function. */
+#define HAVE_REGCOMP 1
+
+/* Define to 1 if you have the `re_comp' function. */
+/* #undef HAVE_RE_COMP */
+
+/* Define to 1 if `stat' has the bug that it succeeds when given the
+ zero-length file name argument. */
+/* #undef HAVE_STAT_EMPTY_STRING_BUG */
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `strcasecmp' function. */
+#define HAVE_STRCASECMP 1
+
+/* Define to 1 if you have the `strchr' function. */
+#define HAVE_STRCHR 1
+
+/* Define to 1 if you have the `strcspn' function. */
+#define HAVE_STRCSPN 1
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strerror' function. */
+#define HAVE_STRERROR 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strlcat' function. */
#define HAVE_STRLCAT 1
+
+/* Define to 1 if you have the `strlcpy' function. */
#define HAVE_STRLCPY 1
-#define HAVE_FGETLN 1
-#define HAVE_STRVIS 1
-#define HAVE_STRUNVIS 1
+/* Define to 1 if you have the `strrchr' function. */
+#define HAVE_STRRCHR 1
+
+/* Define to 1 if you have the `strstr' function. */
+#define HAVE_STRSTR 1
+
+/* Define to 1 if you have the `strtol' function. */
+#define HAVE_STRTOL 1
+
+/* Define to 1 if struct dirent has member d_namlen */
#define HAVE_STRUCT_DIRENT_D_NAMLEN 1
+/* Define to 1 if you have the `strunvis' function. */
+#define HAVE_STRUNVIS 1
+
+/* Define to 1 if you have the `strvis' function. */
+#define HAVE_STRVIS 1
+
+/* Define to 1 if you have the <sys/cdefs.h> header file. */
+#define HAVE_SYS_CDEFS_H 1
+
+/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
+ */
+/* #undef HAVE_SYS_DIR_H */
+
+/* Define to 1 if you have the <sys/ioctl.h> header file. */
+#define HAVE_SYS_IOCTL_H 1
+
+/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
+ */
+/* #undef HAVE_SYS_NDIR_H */
+
+/* Define to 1 if you have the <sys/param.h> header file. */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have <sys/wait.h> that is POSIX.1 compatible. */
+#define HAVE_SYS_WAIT_H 1
+
+/* Define to 1 if you have the <termcap.h> header file. */
+#define HAVE_TERMCAP_H 1
+
+/* Define to 1 if you have the <term.h> header file. */
+#define HAVE_TERM_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if the system has the type `u_int32_t'. */
+#define HAVE_U_INT32_T 1
+
+/* Define to 1 if you have the `vfork' function. */
+#define HAVE_VFORK 1
+
+/* Define to 1 if you have the <vfork.h> header file. */
+/* #undef HAVE_VFORK_H */
+
+/* Define to 1 if you have the `vis' function. */
+#define HAVE_VIS 1
+
+/* Define to 1 if you have the `wcsdup' function. */
+#define HAVE_WCSDUP 1
+
+/* Define to 1 if `fork' works. */
+#define HAVE_WORKING_FORK 1
+
+/* Define to 1 if `vfork' works. */
+#define HAVE_WORKING_VFORK 1
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+ slash. */
+#define LSTAT_FOLLOWS_SLASHED_SYMLINK 1
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+ */
+#define LT_OBJDIR ".libs/"
+
+/* Name of package */
+#define PACKAGE "libedit-20110729"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT ""
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "libedit"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "libedit 3.0"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "libedit-20110729"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL ""
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "3.0"
+
+/* Define as the return type of signal handlers (`int' or `void'). */
+#define RETSIGTYPE void
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+# define _TANDEM_SOURCE 1
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__ 1
+#endif
+
+
+/* Version number of package */
+#define VERSION "3.0"
+
+/* Define to 1 if you want wide-character code */
+/* #undef WIDECHAR */
+
+/* Define to 1 if on MINIX. */
+/* #undef _MINIX */
+
+/* Define to 2 if the system does not provide POSIX.1 features except with
+ this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define to 1 if you need to in order for `stat' and other things to work. */
+/* #undef _POSIX_SOURCE */
+
+/* Define to empty if `const' does not conform to ANSI C. */
+/* #undef const */
+
+/* Define to `int' if <sys/types.h> does not define. */
+/* #undef pid_t */
+
+/* Define to `unsigned int' if <sys/types.h> does not define. */
+/* #undef size_t */
+
+/* Define as `fork' if `vfork' does not work. */
+/* #undef vfork */
+
+
#include "sys.h"
+/* #undef SCCSID */
+/* #undef LIBC_SCCS */
+/* #undef lint */
+
diff --git a/editline.3 b/editline.3
index e2504107c8b8..e869161d7ff1 100644
--- a/editline.3
+++ b/editline.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: editline.3,v 1.73 2010/01/03 19:05:26 wiz Exp $
+.\" $NetBSD: editline.3,v 1.77 2012/09/11 20:29:58 christos Exp $
.\"
.\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -26,7 +26,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd January 3, 2010
+.Dd September 11, 2012
.Dt EDITLINE 3
.Os
.Sh NAME
@@ -173,7 +173,7 @@ which is created by
and freed by
.Fn el_end .
.Pp
-The wide character functions behave the same way as their narrow
+The wide-character functions behave the same way as their narrow
counterparts.
.Pp
The following functions are available:
@@ -221,7 +221,10 @@ and must be copied if the data is to be retained.
Read a character from the tty.
.Fa ch
is modified to contain the character read.
-Returns the number of characters read if successful, \-1 otherwise.
+Returns the number of characters read if successful, \-1 otherwise,
+in which case
+.Dv errno
+can be inspected for the cause.
.It Fn el_push
Pushes
.Fa str
@@ -432,6 +435,14 @@ check this
(using
.Fn el_get )
to determine if editing should be enabled or not.
+.It Dv EL_UNBUFFERED , Fa "int flag"
+If
+.Fa flag
+is zero,
+unbuffered mode is disabled (the default).
+In unbuffered mode,
+.Fn el_gets
+will return immediately after processing a single character.
.It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
Define the character reading function as
.Fa f ,
@@ -501,7 +512,7 @@ If
is not
.Dv NULL ,
return the start/stop literal prompt character in it.
-.It Dv EL_EDITOR , Fa "const char *"
+.It Dv EL_EDITOR , Fa "const char **"
Return the name of the editor, which will be one of
.Dq emacs
or
@@ -534,10 +545,7 @@ previously registered with the corresponding
.Fn el_set
call.
.It Dv EL_UNBUFFERED , Fa "int"
-Sets or clears unbuffered mode.
-In this mode,
-.Fn el_gets
-will return immediately after processing a single character.
+Return non-zero if unbuffered mode is enabled.
.It Dv EL_PREP_TERM , Fa "int"
Sets or clears terminal editing mode.
.It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
@@ -861,7 +869,7 @@ Luke Mewburn wrote this manual and implemented
and
.Dv EL_RPROMPT .
Jaromir Dolecek implemented the readline emulation.
-Johny Mattsson implemented wide character support.
+Johny Mattsson implemented wide-character support.
.Sh BUGS
At this time, it is the responsibility of the caller to
check the result of the
diff --git a/editrc.5 b/editrc.5
index 44ab99d2d5fa..0c01605b086c 100644
--- a/editrc.5
+++ b/editrc.5
@@ -1,4 +1,4 @@
-.\" $NetBSD: editrc.5,v 1.24 2009/04/11 22:17:52 wiz Exp $
+.\" $NetBSD: editrc.5,v 1.26 2012/06/02 14:19:20 njoly Exp $
.\"
.\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -88,7 +88,7 @@ shell.
The following builtin commands are available:
.Bl -tag -width 4n
.It Ic bind Oo Fl a Oc Oo Fl e Oc Oo Fl k Oc Oo Fl l Oc Oo Fl r Oc \
-Oo Fl s Oc Oo Fl v Oc Oo Ar key Op Ar command Oc
+Oo Fl s Oc Oo Fl v Oc Oo Ar key Oo Ar command Oc Oc
Without options, list all bound keys, and the editor command to which
each is bound.
If
@@ -194,7 +194,8 @@ is
.Sq cols ,
.Sq lines ,
.Sq rows ,
-.Sq meta or
+.Sq meta ,
+or
.Sq tabs ,
the value of that capability is printed, with
.Dq yes
diff --git a/el.c b/el.c
index b17e7c546330..d62790c1f16f 100644
--- a/el.c
+++ b/el.c
@@ -1,4 +1,4 @@
-/* $NetBSD: el.c,v 1.59 2010/04/15 00:56:40 christos Exp $ */
+/* $NetBSD: el.c,v 1.71 2012/09/11 11:58:53 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#else
-__RCSID("$NetBSD: el.c,v 1.59 2010/04/15 00:56:40 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.71 2012/09/11 11:58:53 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -60,10 +60,10 @@ __RCSID("$NetBSD: el.c,v 1.59 2010/04/15 00:56:40 christos Exp $");
public EditLine *
el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
{
- EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
+ EditLine *el = el_malloc(sizeof(*el));
if (el == NULL)
- return (NULL);
+ return NULL;
memset(el, 0, sizeof(EditLine));
@@ -72,6 +72,8 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
el->el_errfile = ferr;
el->el_infd = fileno(fin);
+ el->el_outfd = fileno(fout);
+ el->el_errfd = fileno(ferr);
el->el_prog = Strdup(ct_decode_string(prog, &el->el_scratch));
if (el->el_prog == NULL) {
@@ -90,12 +92,12 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
}
#endif
- if (term_init(el) == -1) {
+ if (terminal_init(el) == -1) {
el_free(el->el_prog);
el_free(el);
return NULL;
}
- (void) key_init(el);
+ (void) keymacro_init(el);
(void) map_init(el);
if (tty_init(el) == -1)
el->el_flags |= NO_TTY;
@@ -106,7 +108,7 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
(void) sig_init(el);
(void) read_init(el);
- return (el);
+ return el;
}
@@ -122,8 +124,8 @@ el_end(EditLine *el)
el_reset(el);
- term_end(el);
- key_end(el);
+ terminal_end(el);
+ keymacro_end(el);
map_end(el);
tty_end(el);
ch_end(el);
@@ -132,14 +134,14 @@ el_end(EditLine *el)
prompt_end(el);
sig_end(el);
- el_free((ptr_t) el->el_prog);
- el_free((ptr_t) el);
+ el_free(el->el_prog);
#ifdef WIDECHAR
- el_free((ptr_t) el->el_scratch.cbuff);
- el_free((ptr_t) el->el_scratch.wbuff);
- el_free((ptr_t) el->el_lgcyconv.cbuff);
- el_free((ptr_t) el->el_lgcyconv.wbuff);
+ el_free(el->el_scratch.cbuff);
+ el_free(el->el_scratch.wbuff);
+ el_free(el->el_lgcyconv.cbuff);
+ el_free(el->el_lgcyconv.wbuff);
#endif
+ el_free(el);
}
@@ -165,7 +167,7 @@ FUN(el,set)(EditLine *el, int op, ...)
int rv = 0;
if (el == NULL)
- return (-1);
+ return -1;
va_start(ap, op);
switch (op) {
@@ -177,6 +179,13 @@ FUN(el,set)(EditLine *el, int op, ...)
break;
}
+ case EL_RESIZE: {
+ el_zfunc_t p = va_arg(ap, el_zfunc_t);
+ void *arg = va_arg(ap, void *);
+ rv = ch_resizefun(el, p, arg);
+ break;
+ }
+
case EL_PROMPT_ESC:
case EL_RPROMPT_ESC: {
el_pfunc_t p = va_arg(ap, el_pfunc_t);
@@ -187,7 +196,7 @@ FUN(el,set)(EditLine *el, int op, ...)
}
case EL_TERMINAL:
- rv = term_set(el, va_arg(ap, char *));
+ rv = terminal_set(el, va_arg(ap, char *));
break;
case EL_EDITOR:
@@ -210,7 +219,7 @@ FUN(el,set)(EditLine *el, int op, ...)
const Char *argv[20];
int i;
- for (i = 1; i < 20; i++)
+ for (i = 1; i < (int)__arraycount(argv); i++)
if ((argv[i] = va_arg(ap, Char *)) == NULL)
break;
@@ -222,17 +231,17 @@ FUN(el,set)(EditLine *el, int op, ...)
case EL_TELLTC:
argv[0] = STR("telltc");
- rv = term_telltc(el, i, argv);
+ rv = terminal_telltc(el, i, argv);
break;
case EL_SETTC:
argv[0] = STR("settc");
- rv = term_settc(el, i, argv);
+ rv = terminal_settc(el, i, argv);
break;
case EL_ECHOTC:
argv[0] = STR("echotc");
- rv = term_echotc(el, i, argv);
+ rv = terminal_echotc(el, i, argv);
break;
case EL_SETTY:
@@ -261,7 +270,7 @@ FUN(el,set)(EditLine *el, int op, ...)
case EL_HIST:
{
hist_fun_t func = va_arg(ap, hist_fun_t);
- ptr_t ptr = va_arg(ap, ptr_t);
+ void *ptr = va_arg(ap, void *);
rv = hist_set(el, func, ptr);
if (!(el->el_flags & CHARSET_IS_UTF8))
@@ -326,9 +335,11 @@ FUN(el,set)(EditLine *el, int op, ...)
break;
case 1:
el->el_outfile = fp;
+ el->el_outfd = fileno(fp);
break;
case 2:
el->el_errfile = fp;
+ el->el_errfd = fileno(fp);
break;
default:
rv = -1;
@@ -340,7 +351,7 @@ FUN(el,set)(EditLine *el, int op, ...)
case EL_REFRESH:
re_clear_display(el);
re_refresh(el);
- term__flush(el);
+ terminal__flush(el);
break;
default:
@@ -349,7 +360,7 @@ FUN(el,set)(EditLine *el, int op, ...)
}
va_end(ap);
- return (rv);
+ return rv;
}
@@ -398,7 +409,7 @@ FUN(el,get)(EditLine *el, int op, ...)
break;
case EL_TERMINAL:
- term_get(el, va_arg(ap, const char **));
+ terminal_get(el, va_arg(ap, const char **));
rv = 0;
break;
@@ -408,21 +419,12 @@ FUN(el,get)(EditLine *el, int op, ...)
char *argv[20];
int i;
- for (i = 1; i < (int)(sizeof(argv) / sizeof(argv[0])); i++)
+ for (i = 1; i < (int)__arraycount(argv); i++)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
- switch (op) {
- case EL_GETTC:
- argv[0] = name;
- rv = term_gettc(el, i, argv);
- break;
-
- default:
- rv = -1;
- EL_ABORT((el->el_errfile, "Bad op %d\n", op));
- break;
- }
+ argv[0] = name;
+ rv = terminal_gettc(el, i, argv);
break;
}
@@ -437,7 +439,7 @@ FUN(el,get)(EditLine *el, int op, ...)
break;
case EL_UNBUFFERED:
- *va_arg(ap, int *) = (!(el->el_flags & UNBUFFERED));
+ *va_arg(ap, int *) = (el->el_flags & UNBUFFERED) != 0;
rv = 0;
break;
@@ -471,7 +473,7 @@ FUN(el,get)(EditLine *el, int op, ...)
}
va_end(ap);
- return (rv);
+ return rv;
}
@@ -482,7 +484,7 @@ public const TYPE(LineInfo) *
FUN(el,line)(EditLine *el)
{
- return (const TYPE(LineInfo) *) (void *) &el->el_line;
+ return (const TYPE(LineInfo) *)(void *)&el->el_line;
}
@@ -495,24 +497,24 @@ el_source(EditLine *el, const char *fname)
FILE *fp;
size_t len;
char *ptr;
-#ifdef HAVE_ISSETUGID
- char path[MAXPATHLEN];
-#endif
+ char *path = NULL;
const Char *dptr;
+ int error = 0;
fp = NULL;
if (fname == NULL) {
#ifdef HAVE_ISSETUGID
static const char elpath[] = "/.editrc";
+ size_t plen = sizeof(elpath);
if (issetugid())
- return (-1);
+ return -1;
if ((ptr = getenv("HOME")) == NULL)
- return (-1);
- if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
- return (-1);
- if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
- return (-1);
+ return -1;
+ plen += strlen(ptr);
+ if ((path = el_malloc(plen * sizeof(*path))) == NULL)
+ return -1;
+ (void)snprintf(path, plen, "%s%s", ptr, elpath);
fname = path;
#else
/*
@@ -520,15 +522,19 @@ el_source(EditLine *el, const char *fname)
* to keep from inadvertently opening up the user to a security
* hole.
*/
- return (-1);
+ return -1;
#endif
}
if (fp == NULL)
fp = fopen(fname, "r");
- if (fp == NULL)
- return (-1);
+ if (fp == NULL) {
+ el_free(path);
+ return -1;
+ }
while ((ptr = fgetln(fp, &len)) != NULL) {
+ if (*ptr == '\n')
+ continue; /* Empty line. */
dptr = ct_decode_string(ptr, &el->el_scratch);
if (!dptr)
continue;
@@ -540,14 +546,13 @@ el_source(EditLine *el, const char *fname)
dptr++;
if (*dptr == '#')
continue; /* ignore, this is a comment line */
- if (parse_line(el, dptr) == -1) {
- (void) fclose(fp);
- return (-1);
- }
+ if ((error = parse_line(el, dptr)) == -1)
+ break;
}
+ el_free(path);
(void) fclose(fp);
- return (0);
+ return error;
}
@@ -565,8 +570,8 @@ el_resize(EditLine *el)
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
/* get the correct window size */
- if (term_get_size(el, &lins, &cols))
- term_change_size(el, lins, cols);
+ if (terminal_get_size(el, &lins, &cols))
+ terminal_change_size(el, lins, cols);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}
@@ -579,7 +584,7 @@ public void
el_beep(EditLine *el)
{
- term_beep(el);
+ terminal_beep(el);
}
@@ -593,7 +598,7 @@ el_editmode(EditLine *el, int argc, const Char **argv)
const Char *how;
if (argv == NULL || argc != 2 || argv[1] == NULL)
- return (-1);
+ return -1;
how = argv[1];
if (Strcmp(how, STR("on")) == 0) {
@@ -606,7 +611,7 @@ el_editmode(EditLine *el, int argc, const Char **argv)
else {
(void) fprintf(el->el_errfile, "edit: Bad value `" FSTR "'.\n",
how);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
diff --git a/el.h b/el.h
index df574ce635bb..70c67b8b922f 100644
--- a/el.h
+++ b/el.h
@@ -1,4 +1,4 @@
-/* $NetBSD: el.h,v 1.21 2009/12/31 15:58:26 christos Exp $ */
+/* $NetBSD: el.h,v 1.25 2011/07/29 23:44:44 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -51,7 +51,7 @@
#include <stdio.h>
#include <sys/types.h>
-#define EL_BUFSIZ 1024 /* Maximum line size */
+#define EL_BUFSIZ ((size_t)1024) /* Maximum line size */
#define HANDLE_SIGNALS 0x01
#define NO_TTY 0x02
@@ -100,8 +100,8 @@ typedef struct el_state_t {
#include "tty.h"
#include "prompt.h"
-#include "key.h"
-#include "term.h"
+#include "keymacro.h"
+#include "terminal.h"
#include "refresh.h"
#include "chared.h"
#include "common.h"
@@ -119,6 +119,8 @@ struct editline {
FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */
+ int el_outfd; /* Output file descriptor */
+ int el_errfd; /* Error file descriptor */
int el_flags; /* Various flags. */
int el_errno; /* Local copy of errno */
coord_t el_cursor; /* Cursor location */
@@ -127,14 +129,14 @@ struct editline {
void *el_data; /* Client data */
el_line_t el_line; /* The current line information */
el_state_t el_state; /* Current editor state */
- el_term_t el_term; /* Terminal dependent stuff */
+ el_terminal_t el_terminal; /* Terminal dependent stuff */
el_tty_t el_tty; /* Tty dependent stuff */
el_refresh_t el_refresh; /* Refresh stuff */
el_prompt_t el_prompt; /* Prompt stuff */
el_prompt_t el_rprompt; /* Prompt stuff */
el_chared_t el_chared; /* Characted editor stuff */
el_map_t el_map; /* Key mapping stuff */
- el_key_t el_key; /* Key binding stuff */
+ el_keymacro_t el_keymacro; /* Key binding stuff */
el_history_t el_history; /* History stuff */
el_search_t el_search; /* Search stuff */
el_signal_t el_signal; /* Signal handling stuff */
diff --git a/eln.c b/eln.c
index 072a034b7a7b..1b829c2c6f1b 100644
--- a/eln.c
+++ b/eln.c
@@ -1,4 +1,4 @@
-/* $NetBSD: eln.c,v 1.7 2010/04/15 00:52:48 christos Exp $ */
+/* $NetBSD: eln.c,v 1.14 2012/03/11 21:15:25 christos Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
*/
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: eln.c,v 1.7 2010/04/15 00:52:48 christos Exp $");
+__RCSID("$NetBSD: eln.c,v 1.14 2012/03/11 21:15:25 christos Exp $");
#endif /* not lint && not SCCSID */
#include "histedit.h"
@@ -57,7 +57,7 @@ el_getc(EditLine *el, char *cp)
el->el_flags &= ~IGNORE_EXTCHARS;
if (num_read > 0)
- *cp = (unsigned char)wc;
+ *cp = (char)wc;
return num_read;
}
@@ -118,6 +118,13 @@ el_set(EditLine *el, int op, ...)
break;
}
+ case EL_RESIZE: {
+ el_zfunc_t p = va_arg(ap, el_zfunc_t);
+ void *arg = va_arg(ap, void *);
+ ret = ch_resizefun(el, p, arg);
+ break;
+ }
+
case EL_TERMINAL: /* const char * */
ret = el_wset(el, op, va_arg(ap, char *));
break;
@@ -147,7 +154,7 @@ el_set(EditLine *el, int op, ...)
break;
argv[0] = NULL;
wargv = (const wchar_t **)
- ct_decode_argv(i, argv, &el->el_lgcyconv);
+ ct_decode_argv(i + 1, argv, &el->el_lgcyconv);
if (!wargv) {
ret = -1;
goto out;
@@ -164,15 +171,15 @@ el_set(EditLine *el, int op, ...)
break;
case EL_TELLTC:
wargv[0] = STR("telltc");
- ret = term_telltc(el, i, wargv);
+ ret = terminal_telltc(el, i, wargv);
break;
case EL_SETTC:
wargv[0] = STR("settc");
- ret = term_settc(el, i, wargv);
+ ret = terminal_settc(el, i, wargv);
break;
case EL_ECHOTC:
wargv[0] = STR("echotc");
- ret = term_echotc(el, i, wargv);
+ ret = terminal_echotc(el, i, wargv);
break;
case EL_SETTY:
wargv[0] = STR("setty");
@@ -208,10 +215,9 @@ el_set(EditLine *el, int op, ...)
}
case EL_HIST: { /* hist_fun_t, const char * */
hist_fun_t fun = va_arg(ap, hist_fun_t);
- ptr_t ptr = va_arg(ap, ptr_t);
+ void *ptr = va_arg(ap, void *);
ret = hist_set(el, fun, ptr);
- if (!(el->el_flags & CHARSET_IS_UTF8))
- el->el_flags |= NARROW_HISTORY;
+ el->el_flags |= NARROW_HISTORY;
break;
}
/* XXX: do we need to change el_rfunc_t? */
@@ -231,7 +237,7 @@ el_set(EditLine *el, int op, ...)
case EL_PROMPT_ESC: /* el_pfunc_t, char */
case EL_RPROMPT_ESC: {
el_pfunc_t p = va_arg(ap, el_pfunc_t);
- char c = va_arg(ap, int);
+ char c = (char)va_arg(ap, int);
ret = prompt_set(el, p, c, op, 0);
break;
}
@@ -269,9 +275,9 @@ el_get(EditLine *el, int op, ...)
case EL_RPROMPT_ESC: {
el_pfunc_t *p = va_arg(ap, el_pfunc_t *);
char *c = va_arg(ap, char *);
- wchar_t wc;
+ wchar_t wc = 0;
ret = prompt_get(el, p, &wc, op);
- *c = (unsigned char)wc;
+ *c = (char)wc;
break;
}
@@ -304,7 +310,7 @@ el_get(EditLine *el, int op, ...)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
argv[0] = gettc;
- ret = term_gettc(el, i, argv);
+ ret = terminal_gettc(el, i, argv);
break;
}
diff --git a/emacs.c b/emacs.c
index 8fb6f4b50ae0..ab1e2dfe1912 100644
--- a/emacs.c
+++ b/emacs.c
@@ -1,4 +1,4 @@
-/* $NetBSD: emacs.c,v 1.23 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: emacs.c,v 1.25 2011/07/29 15:16:33 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: emacs.c,v 1.23 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: emacs.c,v 1.25 2011/07/29 15:16:33 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -59,15 +59,15 @@ em_delete_or_list(EditLine *el, Int c)
/* if I'm at the end */
if (el->el_line.cursor == el->el_line.buffer) {
/* and the beginning */
- term_writec(el, c); /* then do an EOF */
- return (CC_EOF);
+ terminal_writec(el, c); /* then do an EOF */
+ return CC_EOF;
} else {
/*
* Here we could list completions, but it is an
* error right now
*/
- term_beep(el);
- return (CC_ERROR);
+ terminal_beep(el);
+ return CC_ERROR;
}
} else {
if (el->el_state.doingarg)
@@ -77,7 +77,7 @@ em_delete_or_list(EditLine *el, Int c)
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
/* bounds check */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
}
@@ -93,7 +93,7 @@ em_delete_next_word(EditLine *el, Int c __attribute__((__unused__)))
Char *cp, *p, *kp;
if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
@@ -107,7 +107,7 @@ em_delete_next_word(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
/* bounds check */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -122,12 +122,12 @@ em_yank(EditLine *el, Int c __attribute__((__unused__)))
Char *kp, *cp;
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf)
- return (CC_NORM);
+ return CC_NORM;
if (el->el_line.lastchar +
(el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
el->el_line.limit)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_chared.c_kill.mark = el->el_line.cursor;
cp = el->el_line.cursor;
@@ -143,7 +143,7 @@ em_yank(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_state.argument == 1)
el->el_line.cursor = cp;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -165,7 +165,7 @@ em_kill_line(EditLine *el, Int c __attribute__((__unused__)))
/* zap! -- delete all of it */
el->el_line.lastchar = el->el_line.buffer;
el->el_line.cursor = el->el_line.buffer;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -180,7 +180,7 @@ em_kill_region(EditLine *el, Int c __attribute__((__unused__)))
Char *kp, *cp;
if (!el->el_chared.c_kill.mark)
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
@@ -198,7 +198,7 @@ em_kill_region(EditLine *el, Int c __attribute__((__unused__)))
c_delbefore(el, (int)(cp - el->el_chared.c_kill.mark));
el->el_line.cursor = el->el_chared.c_kill.mark;
}
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -213,7 +213,7 @@ em_copy_region(EditLine *el, Int c __attribute__((__unused__)))
Char *kp, *cp;
if (!el->el_chared.c_kill.mark)
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
@@ -228,7 +228,7 @@ em_copy_region(EditLine *el, Int c __attribute__((__unused__)))
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
}
- return (CC_NORM);
+ return CC_NORM;
}
@@ -245,9 +245,9 @@ em_gosmacs_transpose(EditLine *el, Int c)
c = el->el_line.cursor[-2];
el->el_line.cursor[-2] = el->el_line.cursor[-1];
el->el_line.cursor[-1] = c;
- return (CC_REFRESH);
+ return CC_REFRESH;
} else
- return (CC_ERROR);
+ return CC_ERROR;
}
@@ -260,7 +260,7 @@ protected el_action_t
em_next_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = c__next_word(el->el_line.cursor,
el->el_line.lastchar,
@@ -270,9 +270,9 @@ em_next_word(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -296,7 +296,7 @@ em_upper_case(EditLine *el, Int c __attribute__((__unused__)))
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -328,7 +328,7 @@ em_capitol_case(EditLine *el, Int c __attribute__((__unused__)))
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -352,7 +352,7 @@ em_lower_case(EditLine *el, Int c __attribute__((__unused__)))
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -366,7 +366,7 @@ em_set_mark(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_chared.c_kill.mark = el->el_line.cursor;
- return (CC_NORM);
+ return CC_NORM;
}
@@ -383,7 +383,7 @@ em_exchange_mark(EditLine *el, Int c __attribute__((__unused__)))
cp = el->el_line.cursor;
el->el_line.cursor = el->el_chared.c_kill.mark;
el->el_chared.c_kill.mark = cp;
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -397,10 +397,10 @@ em_universal_argument(EditLine *el, Int c __attribute__((__unused__)))
{ /* multiply current argument by 4 */
if (el->el_state.argument > 1000000)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_state.doingarg = 1;
el->el_state.argument *= 4;
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
@@ -414,7 +414,7 @@ em_meta_next(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_state.metanext = 1;
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
@@ -428,7 +428,7 @@ em_toggle_overwrite(EditLine *el, Int c __attribute__((__unused__)))
el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
MODE_REPLACE : MODE_INSERT;
- return (CC_NORM);
+ return CC_NORM;
}
@@ -442,7 +442,7 @@ em_copy_prev_word(EditLine *el, Int c __attribute__((__unused__)))
Char *cp, *oldc, *dp;
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
oldc = el->el_line.cursor;
/* does a bounds check */
@@ -455,7 +455,7 @@ em_copy_prev_word(EditLine *el, Int c __attribute__((__unused__)))
el->el_line.cursor = dp;/* put cursor at end */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -468,7 +468,7 @@ em_inc_search_next(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_search.patlen = 0;
- return (ce_inc_search(el, ED_SEARCH_NEXT_HISTORY));
+ return ce_inc_search(el, ED_SEARCH_NEXT_HISTORY);
}
@@ -481,7 +481,7 @@ em_inc_search_prev(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_search.patlen = 0;
- return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
+ return ce_inc_search(el, ED_SEARCH_PREV_HISTORY);
}
@@ -495,7 +495,7 @@ em_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor <= el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
if (el->el_state.doingarg)
c_delbefore(el, el->el_state.argument);
@@ -504,5 +504,5 @@ em_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
el->el_line.cursor -= el->el_state.argument;
if (el->el_line.cursor < el->el_line.buffer)
el->el_line.cursor = el->el_line.buffer;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
diff --git a/filecomplete.c b/filecomplete.c
index c97b9f206c07..5e98cf56442d 100644
--- a/filecomplete.c
+++ b/filecomplete.c
@@ -1,4 +1,4 @@
-/* $NetBSD: filecomplete.c,v 1.19 2010/06/01 18:20:26 christos Exp $ */
+/* $NetBSD: filecomplete.c,v 1.31 2011/09/16 16:13:16 plunky Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: filecomplete.c,v 1.19 2010/06/01 18:20:26 christos Exp $");
+__RCSID("$NetBSD: filecomplete.c,v 1.31 2011/09/16 16:13:16 plunky Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@@ -46,20 +46,13 @@ __RCSID("$NetBSD: filecomplete.c,v 1.19 2010/06/01 18:20:26 christos Exp $");
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
-#ifdef HAVE_VIS_H
-#include <vis.h>
-#else
-#include "np/vis.h"
-#endif
-#ifdef HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
+
#include "el.h"
#include "fcns.h" /* for EL_NUM_FCNS */
#include "histedit.h"
#include "filecomplete.h"
-static Char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@',
+static const Char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@',
'$', '>', '<', '=', ';', '|', '&', '{', '(', '\0' };
@@ -76,13 +69,16 @@ static Char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@',
char *
fn_tilde_expand(const char *txt)
{
- struct passwd pwres, *pass;
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ struct passwd pwres;
+ char pwbuf[1024];
+#endif
+ struct passwd *pass;
char *temp;
size_t len = 0;
- char pwbuf[1024];
if (txt[0] != '~')
- return (strdup(txt));
+ return strdup(txt);
temp = strchr(txt + 1, '/');
if (temp == NULL) {
@@ -90,34 +86,49 @@ fn_tilde_expand(const char *txt)
if (temp == NULL)
return NULL;
} else {
- len = temp - txt + 1; /* text until string after slash */
- temp = malloc(len);
+ /* text until string after slash */
+ len = (size_t)(temp - txt + 1);
+ temp = el_malloc(len * sizeof(*temp));
if (temp == NULL)
return NULL;
(void)strncpy(temp, txt + 1, len - 2);
temp[len - 2] = '\0';
}
if (temp[0] == 0) {
- if (getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf), &pass) != 0)
- pass = NULL;
+#ifdef HAVE_GETPW_R_POSIX
+ if (getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf),
+ &pass) != 0)
+ pass = NULL;
+#elif HAVE_GETPW_R_DRAFT
+ pass = getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf));
+#else
+ pass = getpwuid(getuid());
+#endif
} else {
+#ifdef HAVE_GETPW_R_POSIX
if (getpwnam_r(temp, &pwres, pwbuf, sizeof(pwbuf), &pass) != 0)
pass = NULL;
+#elif HAVE_GETPW_R_DRAFT
+ pass = getpwnam_r(temp, &pwres, pwbuf, sizeof(pwbuf));
+#else
+ pass = getpwnam(temp);
+#endif
}
- free(temp); /* value no more needed */
+ el_free(temp); /* value no more needed */
if (pass == NULL)
- return (strdup(txt));
+ return strdup(txt);
/* update pointer txt to point at string immedially following */
/* first slash */
txt += len;
- temp = malloc(strlen(pass->pw_dir) + 1 + strlen(txt) + 1);
+ len = strlen(pass->pw_dir) + 1 + strlen(txt) + 1;
+ temp = el_malloc(len * sizeof(*temp));
if (temp == NULL)
return NULL;
- (void)sprintf(temp, "%s/%s", pass->pw_dir, txt);
+ (void)snprintf(temp, len, "%s/%s", pass->pw_dir, txt);
- return (temp);
+ return temp;
}
@@ -143,19 +154,21 @@ fn_filename_completion_function(const char *text, int state)
if (temp) {
char *nptr;
temp++;
- nptr = realloc(filename, strlen(temp) + 1);
+ nptr = el_realloc(filename, (strlen(temp) + 1) *
+ sizeof(*nptr));
if (nptr == NULL) {
- free(filename);
+ el_free(filename);
filename = NULL;
return NULL;
}
filename = nptr;
(void)strcpy(filename, temp);
- len = temp - text; /* including last slash */
+ len = (size_t)(temp - text); /* including last slash */
- nptr = realloc(dirname, len + 1);
+ nptr = el_realloc(dirname, (len + 1) *
+ sizeof(*nptr));
if (nptr == NULL) {
- free(dirname);
+ el_free(dirname);
dirname = NULL;
return NULL;
}
@@ -163,7 +176,7 @@ fn_filename_completion_function(const char *text, int state)
(void)strncpy(dirname, text, len);
dirname[len] = '\0';
} else {
- free(filename);
+ el_free(filename);
if (*text == 0)
filename = NULL;
else {
@@ -171,7 +184,7 @@ fn_filename_completion_function(const char *text, int state)
if (filename == NULL)
return NULL;
}
- free(dirname);
+ el_free(dirname);
dirname = NULL;
}
@@ -182,7 +195,7 @@ fn_filename_completion_function(const char *text, int state)
/* support for ``~user'' syntax */
- free(dirpath);
+ el_free(dirpath);
dirpath = NULL;
if (dirname == NULL) {
if ((dirname = strdup("")) == NULL)
@@ -198,7 +211,7 @@ fn_filename_completion_function(const char *text, int state)
dir = opendir(dirpath);
if (!dir)
- return (NULL); /* cannot open the directory */
+ return NULL; /* cannot open the directory */
/* will be used in cycle */
filename_len = filename ? strlen(filename) : 0;
@@ -233,17 +246,18 @@ fn_filename_completion_function(const char *text, int state)
len = strlen(entry->d_name);
#endif
- temp = malloc(strlen(dirname) + len + 1);
+ len = strlen(dirname) + len + 1;
+ temp = el_malloc(len * sizeof(*temp));
if (temp == NULL)
return NULL;
- (void)sprintf(temp, "%s%s", dirname, entry->d_name);
+ (void)snprintf(temp, len, "%s%s", dirname, entry->d_name);
} else {
(void)closedir(dir);
dir = NULL;
temp = NULL;
}
- return (temp);
+ return temp;
}
@@ -260,7 +274,7 @@ append_char_function(const char *name)
rs = "/";
out:
if (expname)
- free(expname);
+ el_free(expname);
return rs;
}
/*
@@ -283,10 +297,10 @@ completion_matches(const char *text, char *(*genfunc)(const char *, int))
char **nmatch_list;
while (matches + 3 >= match_list_len)
match_list_len <<= 1;
- nmatch_list = realloc(match_list,
- match_list_len * sizeof(char *));
+ nmatch_list = el_realloc(match_list,
+ match_list_len * sizeof(*nmatch_list));
if (nmatch_list == NULL) {
- free(match_list);
+ el_free(match_list);
return NULL;
}
match_list = nmatch_list;
@@ -309,9 +323,9 @@ completion_matches(const char *text, char *(*genfunc)(const char *, int))
max_equal = i;
}
- retstr = malloc(max_equal + 1);
+ retstr = el_malloc((max_equal + 1) * sizeof(*retstr));
if (retstr == NULL) {
- free(match_list);
+ el_free(match_list);
return NULL;
}
(void)strncpy(retstr, match_list[1], max_equal);
@@ -319,9 +333,9 @@ completion_matches(const char *text, char *(*genfunc)(const char *, int))
match_list[0] = retstr;
/* add NULL as last pointer to the array */
- match_list[matches + 1] = (char *) NULL;
+ match_list[matches + 1] = NULL;
- return (match_list);
+ return match_list;
}
/*
@@ -338,39 +352,46 @@ _fn_qsort_string_compare(const void *i1, const void *i2)
/*
* Display list of strings in columnar format on readline's output stream.
- * 'matches' is list of strings, 'len' is number of strings in 'matches',
- * 'max' is maximum length of string in 'matches'.
+ * 'matches' is list of strings, 'num' is number of strings in 'matches',
+ * 'width' is maximum length of string in 'matches'.
+ *
+ * matches[0] is not one of the match strings, but it is counted in
+ * num, so the strings are matches[1] *through* matches[num-1].
*/
void
-fn_display_match_list (EditLine *el, char **matches, size_t len, size_t max)
+fn_display_match_list (EditLine *el, char **matches, size_t num, size_t width)
{
- size_t i, idx, limit, count;
- int screenwidth = el->el_term.t_size.h;
+ size_t line, lines, col, cols, thisguy;
+ int screenwidth = el->el_terminal.t_size.h;
+
+ /* Ignore matches[0]. Avoid 1-based array logic below. */
+ matches++;
+ num--;
/*
- * Find out how many entries can be put on one line, count
- * with two spaces between strings.
+ * Find out how many entries can be put on one line; count
+ * with one space between strings the same way it's printed.
*/
- limit = screenwidth / (max + 2);
- if (limit == 0)
- limit = 1;
-
- /* how many lines of output */
- count = len / limit;
- if (count * limit < len)
- count++;
-
- /* Sort the items if they are not already sorted. */
- qsort(&matches[1], (size_t)(len - 1), sizeof(char *),
- _fn_qsort_string_compare);
-
- idx = 1;
- for(; count > 0; count--) {
- int more = limit > 0 && matches[0];
- for(i = 0; more; i++, idx++) {
- more = ++i < limit && matches[idx + 1];
- (void)fprintf(el->el_outfile, "%-*s%s", (int)max,
- matches[idx], more ? " " : "");
+ cols = (size_t)screenwidth / (width + 1);
+ if (cols == 0)
+ cols = 1;
+
+ /* how many lines of output, rounded up */
+ lines = (num + cols - 1) / cols;
+
+ /* Sort the items. */
+ qsort(matches, num, sizeof(char *), _fn_qsort_string_compare);
+
+ /*
+ * On the ith line print elements i, i+lines, i+lines*2, etc.
+ */
+ for (line = 0; line < lines; line++) {
+ for (col = 0; col < cols; col++) {
+ thisguy = line + col * lines;
+ if (thisguy >= num)
+ break;
+ (void)fprintf(el->el_outfile, "%s%-*s",
+ col == 0 ? "" : " ", (int)width, matches[thisguy]);
}
(void)fprintf(el->el_outfile, "\n");
}
@@ -424,12 +445,8 @@ fn_complete(EditLine *el,
&& (!special_prefixes || !Strchr(special_prefixes, ctemp[-1]) ) )
ctemp--;
- len = li->cursor - ctemp;
-#if defined(__SSP__) || defined(__SSP_ALL__)
- temp = malloc(sizeof(*temp) * (len + 1));
-#else
- temp = alloca(sizeof(*temp) * (len + 1));
-#endif
+ len = (size_t)(li->cursor - ctemp);
+ temp = el_malloc((len + 1) * sizeof(*temp));
(void)Strncpy(temp, ctemp, len);
temp[len] = '\0';
@@ -442,13 +459,15 @@ fn_complete(EditLine *el,
if (attempted_completion_function) {
int cur_off = (int)(li->cursor - li->buffer);
- matches = (*attempted_completion_function) (ct_encode_string(temp, &el->el_scratch),
- (int)(cur_off - len), cur_off);
+ matches = (*attempted_completion_function)(
+ ct_encode_string(temp, &el->el_scratch),
+ cur_off - (int)len, cur_off);
} else
matches = 0;
if (!attempted_completion_function ||
(over != NULL && !*over && !matches))
- matches = completion_matches(ct_encode_string(temp, &el->el_scratch), complet_func);
+ matches = completion_matches(
+ ct_encode_string(temp, &el->el_scratch), complet_func);
if (over != NULL)
*over = 0;
@@ -492,7 +511,8 @@ fn_complete(EditLine *el,
if (match_len > maxlen)
maxlen = match_len;
}
- matches_num = i - 1;
+ /* matches[1] through matches[i-1] are available */
+ matches_num = (size_t)(i - 1);
/* newline to get on next line from command line */
(void)fprintf(el->el_outfile, "\n");
@@ -511,9 +531,17 @@ fn_complete(EditLine *el,
(void)fprintf(el->el_outfile, "\n");
}
- if (match_display)
- fn_display_match_list(el, matches, matches_num,
- maxlen);
+ if (match_display) {
+ /*
+ * Interface of this function requires the
+ * strings be matches[1..num-1] for compat.
+ * We have matches_num strings not counting
+ * the prefix in matches[0], so we need to
+ * add 1 to matches_num for the call.
+ */
+ fn_display_match_list(el, matches,
+ matches_num+1, maxlen);
+ }
retval = CC_REDISPLAY;
} else if (matches[0][0]) {
/*
@@ -531,13 +559,11 @@ fn_complete(EditLine *el,
/* free elements of array and the array itself */
for (i = 0; matches[i]; i++)
- free(matches[i]);
- free(matches);
+ el_free(matches[i]);
+ el_free(matches);
matches = NULL;
}
-#if defined(__SSP__) || defined(__SSP_ALL__)
- free(temp);
-#endif
+ el_free(temp);
return retval;
}
@@ -549,6 +575,6 @@ unsigned char
_el_fn_complete(EditLine *el, int ch __attribute__((__unused__)))
{
return (unsigned char)fn_complete(el, NULL, NULL,
- break_chars, NULL, NULL, 100,
+ break_chars, NULL, NULL, (size_t)100,
NULL, NULL, NULL, NULL);
}
diff --git a/hist.c b/hist.c
index e12bfb9b9b4a..77dbaabc467e 100644
--- a/hist.c
+++ b/hist.c
@@ -1,4 +1,4 @@
-/* $NetBSD: hist.c,v 1.17 2009/12/30 23:54:52 christos Exp $ */
+/* $NetBSD: hist.c,v 1.20 2011/07/29 15:16:33 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: hist.c,v 1.17 2009/12/30 23:54:52 christos Exp $");
+__RCSID("$NetBSD: hist.c,v 1.20 2011/07/29 15:16:33 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -59,9 +59,9 @@ hist_init(EditLine *el)
el->el_history.buf = el_malloc(EL_BUFSIZ * sizeof(*el->el_history.buf));
el->el_history.sz = EL_BUFSIZ;
if (el->el_history.buf == NULL)
- return (-1);
+ return -1;
el->el_history.last = el->el_history.buf;
- return (0);
+ return 0;
}
@@ -72,7 +72,7 @@ protected void
hist_end(EditLine *el)
{
- el_free((ptr_t) el->el_history.buf);
+ el_free(el->el_history.buf);
el->el_history.buf = NULL;
}
@@ -81,12 +81,12 @@ hist_end(EditLine *el)
* Set new history interface
*/
protected int
-hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
+hist_set(EditLine *el, hist_fun_t fun, void *ptr)
{
el->el_history.ref = ptr;
el->el_history.fun = fun;
- return (0);
+ return 0;
}
@@ -113,20 +113,20 @@ hist_get(EditLine *el)
#endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
if (el->el_history.ref == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
hp = HIST_FIRST(el);
if (hp == NULL)
- return (CC_ERROR);
+ return CC_ERROR;
for (h = 1; h < el->el_history.eventno; h++)
if ((hp = HIST_NEXT(el)) == NULL) {
el->el_history.eventno = h;
- return (CC_ERROR);
+ return CC_ERROR;
}
(void) Strncpy(el->el_line.buffer, hp,
(size_t)(el->el_line.limit - el->el_line.buffer));
@@ -146,7 +146,7 @@ hist_get(EditLine *el)
#endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -158,10 +158,10 @@ hist_command(EditLine *el, int argc, const Char **argv)
{
const Char *str;
int num;
- HistEvent ev;
+ TYPE(HistEvent) ev;
if (el->el_history.ref == NULL)
- return (-1);
+ return -1;
if (argc == 1 || Strcmp(argv[1], STR("list")) == 0) {
/* List history entries */
@@ -169,19 +169,19 @@ hist_command(EditLine *el, int argc, const Char **argv)
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
(void) fprintf(el->el_outfile, "%d %s",
el->el_history.ev.num, ct_encode_string(str, &el->el_scratch));
- return (0);
+ return 0;
}
if (argc != 3)
- return (-1);
+ return -1;
num = (int)Strtol(argv[2], NULL, 0);
if (Strcmp(argv[1], STR("size")) == 0)
- return history(el->el_history.ref, &ev, H_SETSIZE, num);
+ return FUNW(history)(el->el_history.ref, &ev, H_SETSIZE, num);
if (Strcmp(argv[1], STR("unique")) == 0)
- return history(el->el_history.ref, &ev, H_SETUNIQUE, num);
+ return FUNW(history)(el->el_history.ref, &ev, H_SETUNIQUE, num);
return -1;
}
@@ -212,7 +212,7 @@ hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz)
#ifdef WIDECHAR
protected wchar_t *
-hist_convert(EditLine *el, int fn, ptr_t arg)
+hist_convert(EditLine *el, int fn, void *arg)
{
HistEventW ev;
if ((*(el)->el_history.fun)((el)->el_history.ref, &ev, fn, arg) == -1)
diff --git a/hist.h b/hist.h
index 8c3af40bf868..a63be499dbdb 100644
--- a/hist.h
+++ b/hist.h
@@ -1,4 +1,4 @@
-/* $NetBSD: hist.h,v 1.12 2009/12/30 23:54:52 christos Exp $ */
+/* $NetBSD: hist.h,v 1.13 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -42,14 +42,14 @@
#include "histedit.h"
-typedef int (*hist_fun_t)(ptr_t, TYPE(HistEvent) *, int, ...);
+typedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...);
typedef struct el_history_t {
Char *buf; /* The history buffer */
size_t sz; /* Size of history buffer */
Char *last; /* The last character */
int eventno; /* Event we are looking for */
- ptr_t ref; /* Argument for history fcns */
+ void * ref; /* Argument for history fcns */
hist_fun_t fun; /* Event access */
TYPE(HistEvent) ev; /* Event cookie */
} el_history_t;
@@ -77,11 +77,11 @@ typedef struct el_history_t {
protected int hist_init(EditLine *);
protected void hist_end(EditLine *);
protected el_action_t hist_get(EditLine *);
-protected int hist_set(EditLine *, hist_fun_t, ptr_t);
+protected int hist_set(EditLine *, hist_fun_t, void *);
protected int hist_command(EditLine *, int, const Char **);
protected int hist_enlargebuf(EditLine *, size_t, size_t);
#ifdef WIDECHAR
-protected wchar_t *hist_convert(EditLine *, int, ptr_t);
+protected wchar_t *hist_convert(EditLine *, int, void *);
#endif
#endif /* _h_el_hist */
diff --git a/histedit.h b/histedit.h
index 5a0bb69db242..61f9875873dc 100644
--- a/histedit.h
+++ b/histedit.h
@@ -1,4 +1,4 @@
-/* $NetBSD: histedit.h,v 1.46 2010/04/15 00:50:03 christos Exp $ */
+/* $NetBSD: histedit.h,v 1.49 2012/05/31 13:16:39 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -43,8 +43,6 @@
#define LIBEDIT_MAJOR 2
#define LIBEDIT_MINOR 11
-#include <stdint.h>
-
#include <sys/types.h>
#include <stdio.h>
@@ -142,7 +140,7 @@ unsigned char _el_fn_complete(EditLine *, int);
#define EL_SETTY 8 /* , const Char *, ..., NULL); set */
#define EL_ADDFN 9 /* , const Char *, const Char, set */
/* el_func_t); */
-#define EL_HIST 10 /* , hist_fun_t, const ptr_t); set */
+#define EL_HIST 10 /* , hist_fun_t, const void *); set */
#define EL_EDITMODE 11 /* , int); set/get */
#define EL_RPROMPT 12 /* , prompt_func); set/get */
#define EL_GETCFN 13 /* , el_rfunc_t); set/get */
@@ -155,6 +153,7 @@ unsigned char _el_fn_complete(EditLine *, int);
#define EL_REFRESH 20 /* , void); set */
#define EL_PROMPT_ESC 21 /* , prompt_func, Char); set/get */
#define EL_RPROMPT_ESC 22 /* , prompt_func, Char); set/get */
+#define EL_RESIZE 23 /* , el_zfunc_t, void *); set */
#define EL_BUILTIN_GETCFN (NULL)
diff --git a/history.c b/history.c
index aa593b2db2f6..7e8f5209ca5f 100644
--- a/history.c
+++ b/history.c
@@ -1,4 +1,4 @@
-/* $NetBSD: history.c,v 1.37 2010/01/03 18:27:10 christos Exp $ */
+/* $NetBSD: history.c,v 1.46 2011/11/18 20:39:18 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: history.c,v 1.37 2010/01/03 18:27:10 christos Exp $");
+__RCSID("$NetBSD: history.c,v 1.46 2011/11/18 20:39:18 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -47,11 +47,7 @@ __RCSID("$NetBSD: history.c,v 1.37 2010/01/03 18:27:10 christos Exp $");
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
-#ifdef HAVE_VIS_H
#include <vis.h>
-#else
-#include "np/vis.h"
-#endif
#include <sys/stat.h>
static const char hist_cookie[] = "_HiStOrY_V2_\n";
@@ -59,13 +55,13 @@ static const char hist_cookie[] = "_HiStOrY_V2_\n";
#include "histedit.h"
#include "chartype.h"
-typedef int (*history_gfun_t)(ptr_t, TYPE(HistEvent) *);
-typedef int (*history_efun_t)(ptr_t, TYPE(HistEvent) *, const Char *);
-typedef void (*history_vfun_t)(ptr_t, TYPE(HistEvent) *);
-typedef int (*history_sfun_t)(ptr_t, TYPE(HistEvent) *, const int);
+typedef int (*history_gfun_t)(void *, TYPE(HistEvent) *);
+typedef int (*history_efun_t)(void *, TYPE(HistEvent) *, const Char *);
+typedef void (*history_vfun_t)(void *, TYPE(HistEvent) *);
+typedef int (*history_sfun_t)(void *, TYPE(HistEvent) *, const int);
struct TYPE(history) {
- ptr_t h_ref; /* Argument for history fcns */
+ void *h_ref; /* Argument for history fcns */
int h_ent; /* Last entry point for history */
history_gfun_t h_first; /* Get the first element */
history_gfun_t h_next; /* Get the next element */
@@ -137,23 +133,23 @@ typedef struct history_t {
#define H_UNIQUE 1 /* Store only unique elements */
} history_t;
-private int history_def_next(ptr_t, TYPE(HistEvent) *);
-private int history_def_first(ptr_t, TYPE(HistEvent) *);
-private int history_def_prev(ptr_t, TYPE(HistEvent) *);
-private int history_def_last(ptr_t, TYPE(HistEvent) *);
-private int history_def_curr(ptr_t, TYPE(HistEvent) *);
-private int history_def_set(ptr_t, TYPE(HistEvent) *, const int);
-private void history_def_clear(ptr_t, TYPE(HistEvent) *);
-private int history_def_enter(ptr_t, TYPE(HistEvent) *, const Char *);
-private int history_def_add(ptr_t, TYPE(HistEvent) *, const Char *);
-private int history_def_del(ptr_t, TYPE(HistEvent) *, const int);
-
-private int history_def_init(ptr_t *, TYPE(HistEvent) *, int);
+private int history_def_next(void *, TYPE(HistEvent) *);
+private int history_def_first(void *, TYPE(HistEvent) *);
+private int history_def_prev(void *, TYPE(HistEvent) *);
+private int history_def_last(void *, TYPE(HistEvent) *);
+private int history_def_curr(void *, TYPE(HistEvent) *);
+private int history_def_set(void *, TYPE(HistEvent) *, const int);
+private void history_def_clear(void *, TYPE(HistEvent) *);
+private int history_def_enter(void *, TYPE(HistEvent) *, const Char *);
+private int history_def_add(void *, TYPE(HistEvent) *, const Char *);
+private int history_def_del(void *, TYPE(HistEvent) *, const int);
+
+private int history_def_init(void **, TYPE(HistEvent) *, int);
private int history_def_insert(history_t *, TYPE(HistEvent) *, const Char *);
private void history_def_delete(history_t *, TYPE(HistEvent) *, hentry_t *);
private int history_deldata_nth(history_t *, TYPE(HistEvent) *, int, void **);
-private int history_set_nth(ptr_t, TYPE(HistEvent) *, int);
+private int history_set_nth(void *, TYPE(HistEvent) *, int);
#define history_def_setsize(p, num)(void) (((history_t *)p)->max = (num))
#define history_def_getsize(p) (((history_t *)p)->cur)
@@ -211,7 +207,7 @@ static const Char *const he_errlist[] = {
* Default function to return the first event in the history.
*/
private int
-history_def_first(ptr_t p, TYPE(HistEvent) *ev)
+history_def_first(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -220,10 +216,10 @@ history_def_first(ptr_t p, TYPE(HistEvent) *ev)
*ev = h->cursor->ev;
else {
he_seterrev(ev, _HE_FIRST_NOTFOUND);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -231,7 +227,7 @@ history_def_first(ptr_t p, TYPE(HistEvent) *ev)
* Default function to return the last event in the history.
*/
private int
-history_def_last(ptr_t p, TYPE(HistEvent) *ev)
+history_def_last(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -240,10 +236,10 @@ history_def_last(ptr_t p, TYPE(HistEvent) *ev)
*ev = h->cursor->ev;
else {
he_seterrev(ev, _HE_LAST_NOTFOUND);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -251,24 +247,24 @@ history_def_last(ptr_t p, TYPE(HistEvent) *ev)
* Default function to return the next event in the history.
*/
private int
-history_def_next(ptr_t p, TYPE(HistEvent) *ev)
+history_def_next(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
if (h->cursor == &h->list) {
he_seterrev(ev, _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
if (h->cursor->next == &h->list) {
he_seterrev(ev, _HE_END_REACHED);
- return (-1);
+ return -1;
}
h->cursor = h->cursor->next;
*ev = h->cursor->ev;
- return (0);
+ return 0;
}
@@ -276,25 +272,25 @@ history_def_next(ptr_t p, TYPE(HistEvent) *ev)
* Default function to return the previous event in the history.
*/
private int
-history_def_prev(ptr_t p, TYPE(HistEvent) *ev)
+history_def_prev(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
if (h->cursor == &h->list) {
he_seterrev(ev,
(h->cur > 0) ? _HE_END_REACHED : _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
if (h->cursor->prev == &h->list) {
he_seterrev(ev, _HE_START_REACHED);
- return (-1);
+ return -1;
}
h->cursor = h->cursor->prev;
*ev = h->cursor->ev;
- return (0);
+ return 0;
}
@@ -302,7 +298,7 @@ history_def_prev(ptr_t p, TYPE(HistEvent) *ev)
* Default function to return the current event in the history.
*/
private int
-history_def_curr(ptr_t p, TYPE(HistEvent) *ev)
+history_def_curr(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
@@ -311,10 +307,10 @@ history_def_curr(ptr_t p, TYPE(HistEvent) *ev)
else {
he_seterrev(ev,
(h->cur > 0) ? _HE_CURR_INVALID : _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -323,13 +319,13 @@ history_def_curr(ptr_t p, TYPE(HistEvent) *ev)
* given one.
*/
private int
-history_def_set(ptr_t p, TYPE(HistEvent) *ev, const int n)
+history_def_set(void *p, TYPE(HistEvent) *ev, const int n)
{
history_t *h = (history_t *) p;
if (h->cur == 0) {
he_seterrev(ev, _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
if (h->cursor == &h->list || h->cursor->ev.num != n) {
for (h->cursor = h->list.next; h->cursor != &h->list;
@@ -339,9 +335,9 @@ history_def_set(ptr_t p, TYPE(HistEvent) *ev, const int n)
}
if (h->cursor == &h->list) {
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -350,13 +346,13 @@ history_def_set(ptr_t p, TYPE(HistEvent) *ev, const int n)
* n-th one.
*/
private int
-history_set_nth(ptr_t p, TYPE(HistEvent) *ev, int n)
+history_set_nth(void *p, TYPE(HistEvent) *ev, int n)
{
history_t *h = (history_t *) p;
if (h->cur == 0) {
he_seterrev(ev, _HE_EMPTY_LIST);
- return (-1);
+ return -1;
}
for (h->cursor = h->list.prev; h->cursor != &h->list;
h->cursor = h->cursor->prev)
@@ -364,9 +360,9 @@ history_set_nth(ptr_t p, TYPE(HistEvent) *ev, int n)
break;
if (h->cursor == &h->list) {
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -374,7 +370,7 @@ history_set_nth(ptr_t p, TYPE(HistEvent) *ev, int n)
* Append string to element
*/
private int
-history_def_add(ptr_t p, TYPE(HistEvent) *ev, const Char *str)
+history_def_add(void *p, TYPE(HistEvent) *ev, const Char *str)
{
history_t *h = (history_t *) p;
size_t len;
@@ -382,20 +378,20 @@ history_def_add(ptr_t p, TYPE(HistEvent) *ev, const Char *str)
HistEventPrivate *evp = (void *)&h->cursor->ev;
if (h->cursor == &h->list)
- return (history_def_enter(p, ev, str));
+ return history_def_enter(p, ev, str);
len = Strlen(evp->str) + Strlen(str) + 1;
s = h_malloc(len * sizeof(*s));
if (s == NULL) {
he_seterrev(ev, _HE_MALLOC_FAILED);
- return (-1);
+ return -1;
}
(void) Strncpy(s, h->cursor->ev.str, len);
s[len - 1] = '\0';
(void) Strncat(s, str, len - Strlen(s) - 1);
- h_free((ptr_t)evp->str);
+ h_free(evp->str);
evp->str = s;
*ev = h->cursor->ev;
- return (0);
+ return 0;
}
@@ -404,16 +400,16 @@ history_deldata_nth(history_t *h, TYPE(HistEvent) *ev,
int num, void **data)
{
if (history_set_nth(h, ev, num) != 0)
- return (-1);
+ return -1;
/* magic value to skip delete (just set to n-th history) */
if (data == (void **)-1)
- return (0);
+ return 0;
ev->str = Strdup(h->cursor->ev.str);
ev->num = h->cursor->ev.num;
if (data)
*data = h->cursor->data;
history_def_delete(h, ev, h->cursor);
- return (0);
+ return 0;
}
@@ -422,16 +418,16 @@ history_deldata_nth(history_t *h, TYPE(HistEvent) *ev,
*/
/* ARGSUSED */
private int
-history_def_del(ptr_t p, TYPE(HistEvent) *ev __attribute__((__unused__)),
+history_def_del(void *p, TYPE(HistEvent) *ev __attribute__((__unused__)),
const int num)
{
history_t *h = (history_t *) p;
if (history_def_set(h, ev, num) != 0)
- return (-1);
+ return -1;
ev->str = Strdup(h->cursor->ev.str);
ev->num = h->cursor->ev.num;
history_def_delete(h, ev, h->cursor);
- return (0);
+ return 0;
}
@@ -453,7 +449,7 @@ history_def_delete(history_t *h,
}
hp->prev->next = hp->next;
hp->next->prev = hp->prev;
- h_free((ptr_t) evp->str);
+ h_free(evp->str);
h_free(hp);
h->cur--;
}
@@ -465,27 +461,29 @@ history_def_delete(history_t *h,
private int
history_def_insert(history_t *h, TYPE(HistEvent) *ev, const Char *str)
{
+ hentry_t *c;
- h->cursor = (hentry_t *) h_malloc(sizeof(hentry_t));
- if (h->cursor == NULL)
+ c = h_malloc(sizeof(*c));
+ if (c == NULL)
goto oomem;
- if ((h->cursor->ev.str = h_strdup(str)) == NULL) {
- h_free((ptr_t)h->cursor);
+ if ((c->ev.str = h_strdup(str)) == NULL) {
+ h_free(c);
goto oomem;
}
- h->cursor->data = NULL;
- h->cursor->ev.num = ++h->eventid;
- h->cursor->next = h->list.next;
- h->cursor->prev = &h->list;
- h->list.next->prev = h->cursor;
- h->list.next = h->cursor;
+ c->data = NULL;
+ c->ev.num = ++h->eventid;
+ c->next = h->list.next;
+ c->prev = &h->list;
+ h->list.next->prev = c;
+ h->list.next = c;
h->cur++;
+ h->cursor = c;
- *ev = h->cursor->ev;
- return (0);
+ *ev = c->ev;
+ return 0;
oomem:
he_seterrev(ev, _HE_MALLOC_FAILED);
- return (-1);
+ return -1;
}
@@ -493,16 +491,16 @@ oomem:
* Default function to enter an item in the history
*/
private int
-history_def_enter(ptr_t p, TYPE(HistEvent) *ev, const Char *str)
+history_def_enter(void *p, TYPE(HistEvent) *ev, const Char *str)
{
history_t *h = (history_t *) p;
if ((h->flags & H_UNIQUE) != 0 && h->list.next != &h->list &&
Strcmp(h->list.next->ev.str, str) == 0)
- return (0);
+ return 0;
if (history_def_insert(h, ev, str) == -1)
- return (-1); /* error, keep error message */
+ return -1; /* error, keep error message */
/*
* Always keep at least one entry.
@@ -511,7 +509,7 @@ history_def_enter(ptr_t p, TYPE(HistEvent) *ev, const Char *str)
while (h->cur > h->max && h->cur > 0)
history_def_delete(h, ev, h->list.prev);
- return (1);
+ return 1;
}
@@ -520,9 +518,9 @@ history_def_enter(ptr_t p, TYPE(HistEvent) *ev, const Char *str)
*/
/* ARGSUSED */
private int
-history_def_init(ptr_t *p, TYPE(HistEvent) *ev __attribute__((__unused__)), int n)
+history_def_init(void **p, TYPE(HistEvent) *ev __attribute__((__unused__)), int n)
{
- history_t *h = (history_t *) h_malloc(sizeof(history_t));
+ history_t *h = (history_t *) h_malloc(sizeof(*h));
if (h == NULL)
return -1;
@@ -536,7 +534,7 @@ history_def_init(ptr_t *p, TYPE(HistEvent) *ev __attribute__((__unused__)), int
h->list.ev.num = 0;
h->cursor = &h->list;
h->flags = 0;
- *p = (ptr_t) h;
+ *p = h;
return 0;
}
@@ -545,12 +543,13 @@ history_def_init(ptr_t *p, TYPE(HistEvent) *ev __attribute__((__unused__)), int
* Default history cleanup function
*/
private void
-history_def_clear(ptr_t p, TYPE(HistEvent) *ev)
+history_def_clear(void *p, TYPE(HistEvent) *ev)
{
history_t *h = (history_t *) p;
while (h->list.prev != &h->list)
history_def_delete(h, ev, h->list.prev);
+ h->cursor = &h->list;
h->eventid = 0;
h->cur = 0;
}
@@ -567,12 +566,12 @@ public TYPE(History) *
FUN(history,init)(void)
{
TYPE(HistEvent) ev;
- TYPE(History) *h = (TYPE(History) *) h_malloc(sizeof(TYPE(History)));
+ TYPE(History) *h = (TYPE(History) *) h_malloc(sizeof(*h));
if (h == NULL)
return NULL;
if (history_def_init(&h->h_ref, &ev, 0) == -1) {
- h_free((ptr_t)h);
+ h_free(h);
return NULL;
}
h->h_ent = -1;
@@ -587,7 +586,7 @@ FUN(history,init)(void)
h->h_add = history_def_add;
h->h_del = history_def_del;
- return (h);
+ return h;
}
@@ -616,14 +615,14 @@ history_setsize(TYPE(History) *h, TYPE(HistEvent) *ev, int num)
if (h->h_next != history_def_next) {
he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
+ return -1;
}
if (num < 0) {
he_seterrev(ev, _HE_BAD_PARAM);
- return (-1);
+ return -1;
}
history_def_setsize(h->h_ref, num);
- return (0);
+ return 0;
}
@@ -635,14 +634,14 @@ history_getsize(TYPE(History) *h, TYPE(HistEvent) *ev)
{
if (h->h_next != history_def_next) {
he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
+ return -1;
}
ev->num = history_def_getsize(h->h_ref);
if (ev->num < -1) {
he_seterrev(ev, _HE_SIZE_NEGATIVE);
- return (-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -655,10 +654,10 @@ history_setunique(TYPE(History) *h, TYPE(HistEvent) *ev, int uni)
if (h->h_next != history_def_next) {
he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
+ return -1;
}
history_def_setunique(h->h_ref, uni);
- return (0);
+ return 0;
}
@@ -670,10 +669,10 @@ history_getunique(TYPE(History) *h, TYPE(HistEvent) *ev)
{
if (h->h_next != history_def_next) {
he_seterrev(ev, _HE_NOT_ALLOWED);
- return (-1);
+ return -1;
}
ev->num = history_def_getunique(h->h_ref);
- return (0);
+ return 0;
}
@@ -690,7 +689,8 @@ history_set_fun(TYPE(History) *h, TYPE(History) *nh)
nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL ||
nh->h_del == NULL || nh->h_ref == NULL) {
if (h->h_next != history_def_next) {
- history_def_init(&h->h_ref, &ev, 0);
+ if (history_def_init(&h->h_ref, &ev, 0) == -1)
+ return -1;
h->h_first = history_def_first;
h->h_next = history_def_next;
h->h_last = history_def_last;
@@ -702,7 +702,7 @@ history_set_fun(TYPE(History) *h, TYPE(History) *nh)
h->h_add = history_def_add;
h->h_del = history_def_del;
}
- return (-1);
+ return -1;
}
if (h->h_next == history_def_next)
history_def_clear(h->h_ref, &ev);
@@ -719,7 +719,7 @@ history_set_fun(TYPE(History) *h, TYPE(History) *nh)
h->h_add = nh->h_add;
h->h_del = nh->h_del;
- return (0);
+ return 0;
}
@@ -740,7 +740,7 @@ history_load(TYPE(History) *h, const char *fname)
#endif
if ((fp = fopen(fname, "r")) == NULL)
- return (i);
+ return i;
if ((line = fgetln(fp, &sz)) == NULL)
goto done;
@@ -748,7 +748,7 @@ history_load(TYPE(History) *h, const char *fname)
if (strncmp(line, hist_cookie, sz) != 0)
goto done;
- ptr = h_malloc(max_size = 1024);
+ ptr = h_malloc((max_size = 1024) * sizeof(*ptr));
if (ptr == NULL)
goto done;
for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) {
@@ -761,8 +761,8 @@ history_load(TYPE(History) *h, const char *fname)
if (max_size < sz) {
char *nptr;
- max_size = (sz + 1024) & ~1023;
- nptr = h_realloc(ptr, max_size);
+ max_size = (sz + 1024) & (size_t)~1023;
+ nptr = h_realloc(ptr, max_size * sizeof(*ptr));
if (nptr == NULL) {
i = -1;
goto oomem;
@@ -777,10 +777,10 @@ history_load(TYPE(History) *h, const char *fname)
}
}
oomem:
- h_free((ptr_t)ptr);
+ h_free(ptr);
done:
(void) fclose(fp);
- return (i);
+ return i;
}
@@ -795,42 +795,44 @@ history_save(TYPE(History) *h, const char *fname)
int i = -1, retval;
size_t len, max_size;
char *ptr;
+ const char *str;
#ifdef WIDECHAR
static ct_buffer_t conv;
#endif
if ((fp = fopen(fname, "w")) == NULL)
- return (-1);
+ return -1;
if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
goto done;
if (fputs(hist_cookie, fp) == EOF)
goto done;
- ptr = h_malloc(max_size = 1024);
+ ptr = h_malloc((max_size = 1024) * sizeof(*ptr));
if (ptr == NULL)
goto done;
for (i = 0, retval = HLAST(h, &ev);
retval != -1;
retval = HPREV(h, &ev), i++) {
- len = Strlen(ev.str) * 4;
+ str = ct_encode_string(ev.str, &conv);
+ len = strlen(str) * 4;
if (len >= max_size) {
char *nptr;
- max_size = (len + 1024) & ~1023;
- nptr = h_realloc(ptr, max_size);
+ max_size = (len + 1024) & (size_t)~1023;
+ nptr = h_realloc(ptr, max_size * sizeof(*ptr));
if (nptr == NULL) {
i = -1;
goto oomem;
}
ptr = nptr;
}
- (void) strvis(ptr, ct_encode_string(ev.str, &conv), VIS_WHITE);
+ (void) strvis(ptr, str, VIS_WHITE);
(void) fprintf(fp, "%s\n", ptr);
}
oomem:
- h_free((ptr_t)ptr);
+ h_free(ptr);
done:
(void) fclose(fp);
- return (i);
+ return i;
}
@@ -844,10 +846,10 @@ history_prev_event(TYPE(History) *h, TYPE(HistEvent) *ev, int num)
for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
if (ev->num == num)
- return (0);
+ return 0;
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
@@ -857,14 +859,14 @@ history_next_evdata(TYPE(History) *h, TYPE(HistEvent) *ev, int num, void **d)
int retval;
for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
- if (num-- <= 0) {
+ if (ev->num == num) {
if (d)
*d = ((history_t *)h->h_ref)->cursor->data;
- return (0);
+ return 0;
}
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
@@ -878,10 +880,10 @@ history_next_event(TYPE(History) *h, TYPE(HistEvent) *ev, int num)
for (retval = HCURR(h, ev); retval != -1; retval = HNEXT(h, ev))
if (ev->num == num)
- return (0);
+ return 0;
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
@@ -896,10 +898,10 @@ history_prev_string(TYPE(History) *h, TYPE(HistEvent) *ev, const Char *str)
for (retval = HCURR(h, ev); retval != -1; retval = HNEXT(h, ev))
if (Strncmp(str, ev->str, len) == 0)
- return (0);
+ return 0;
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
@@ -914,10 +916,10 @@ history_next_string(TYPE(History) *h, TYPE(HistEvent) *ev, const Char *str)
for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
if (Strncmp(str, ev->str, len) == 0)
- return (0);
+ return 0;
he_seterrev(ev, _HE_NOT_FOUND);
- return (-1);
+ return -1;
}
@@ -1034,7 +1036,7 @@ FUNW(history)(TYPE(History) *h, TYPE(HistEvent) *ev, int fun, ...)
{
TYPE(History) hf;
- hf.h_ref = va_arg(va, ptr_t);
+ hf.h_ref = va_arg(va, void *);
h->h_ent = -1;
hf.h_first = va_arg(va, history_gfun_t);
hf.h_next = va_arg(va, history_gfun_t);
diff --git a/key.c b/keymacro.c
index 4ff506d9734b..1cab508fa0ca 100644
--- a/key.c
+++ b/keymacro.c
@@ -1,4 +1,4 @@
-/* $NetBSD: key.c,v 1.23 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: keymacro.c,v 1.7 2011/08/16 16:25:15 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,25 +37,26 @@
#if 0
static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: key.c,v 1.23 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: keymacro.c,v 1.7 2011/08/16 16:25:15 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
/*
- * key.c: This module contains the procedures for maintaining
- * the extended-key map.
+ * keymacro.c: This module contains the procedures for maintaining
+ * the extended-key map.
*
* An extended-key (key) is a sequence of keystrokes introduced
* with a sequence introducer and consisting of an arbitrary
- * number of characters. This module maintains a map (the el->el_key.map)
+ * number of characters. This module maintains a map (the
+ * el->el_keymacro.map)
* to convert these extended-key sequences into input strs
* (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE).
*
* Warning:
* If key is a substr of some other keys, then the longer
* keys are lost!! That is, if the keys "abcd" and "abcef"
- * are in el->el_key.map, adding the key "abc" will cause the first two
- * definitions to be lost.
+ * are in el->el_keymacro.map, adding the key "abc" will cause
+ * the first two definitions to be lost.
*
* Restrictions:
* -------------
@@ -68,102 +69,104 @@ __RCSID("$NetBSD: key.c,v 1.23 2009/12/30 22:37:40 christos Exp $");
#include "el.h"
/*
- * The Nodes of the el->el_key.map. The el->el_key.map is a linked list
- * of these node elements
+ * The Nodes of the el->el_keymacro.map. The el->el_keymacro.map is a
+ * linked list of these node elements
*/
-struct key_node_t {
- Char ch; /* single character of key */
- int type; /* node type */
- key_value_t val; /* command code or pointer to str, */
+struct keymacro_node_t {
+ Char ch; /* single character of key */
+ int type; /* node type */
+ keymacro_value_t val; /* command code or pointer to str, */
/* if this is a leaf */
- struct key_node_t *next; /* ptr to next char of this key */
- struct key_node_t *sibling; /* ptr to another key with same prefix*/
+ struct keymacro_node_t *next; /* ptr to next char of this key */
+ struct keymacro_node_t *sibling;/* ptr to another key with same prefix*/
};
-private int node_trav(EditLine *, key_node_t *, Char *,
- key_value_t *);
-private int node__try(EditLine *, key_node_t *, const Char *,
- key_value_t *, int);
-private key_node_t *node__get(Int);
-private void node__free(key_node_t *);
-private void node__put(EditLine *, key_node_t *);
-private int node__delete(EditLine *, key_node_t **, const Char *);
-private int node_lookup(EditLine *, const Char *, key_node_t *,
- size_t);
-private int node_enum(EditLine *, key_node_t *, size_t);
+private int node_trav(EditLine *, keymacro_node_t *, Char *,
+ keymacro_value_t *);
+private int node__try(EditLine *, keymacro_node_t *, const Char *,
+ keymacro_value_t *, int);
+private keymacro_node_t *node__get(Int);
+private void node__free(keymacro_node_t *);
+private void node__put(EditLine *, keymacro_node_t *);
+private int node__delete(EditLine *, keymacro_node_t **,
+ const Char *);
+private int node_lookup(EditLine *, const Char *,
+ keymacro_node_t *, size_t);
+private int node_enum(EditLine *, keymacro_node_t *, size_t);
#define KEY_BUFSIZ EL_BUFSIZ
-/* key_init():
+/* keymacro_init():
* Initialize the key maps
*/
protected int
-key_init(EditLine *el)
+keymacro_init(EditLine *el)
{
- el->el_key.buf = el_malloc(KEY_BUFSIZ * sizeof(*el->el_key.buf));
- if (el->el_key.buf == NULL)
- return (-1);
- el->el_key.map = NULL;
- key_reset(el);
- return (0);
+ el->el_keymacro.buf = el_malloc(KEY_BUFSIZ *
+ sizeof(*el->el_keymacro.buf));
+ if (el->el_keymacro.buf == NULL)
+ return -1;
+ el->el_keymacro.map = NULL;
+ keymacro_reset(el);
+ return 0;
}
-/* key_end():
+/* keymacro_end():
* Free the key maps
*/
protected void
-key_end(EditLine *el)
+keymacro_end(EditLine *el)
{
- el_free((ptr_t) el->el_key.buf);
- el->el_key.buf = NULL;
- node__free(el->el_key.map);
+ el_free(el->el_keymacro.buf);
+ el->el_keymacro.buf = NULL;
+ node__free(el->el_keymacro.map);
}
-/* key_map_cmd():
+/* keymacro_map_cmd():
* Associate cmd with a key value
*/
-protected key_value_t *
-key_map_cmd(EditLine *el, int cmd)
+protected keymacro_value_t *
+keymacro_map_cmd(EditLine *el, int cmd)
{
- el->el_key.val.cmd = (el_action_t) cmd;
- return (&el->el_key.val);
+ el->el_keymacro.val.cmd = (el_action_t) cmd;
+ return &el->el_keymacro.val;
}
-/* key_map_str():
+/* keymacro_map_str():
* Associate str with a key value
*/
-protected key_value_t *
-key_map_str(EditLine *el, Char *str)
+protected keymacro_value_t *
+keymacro_map_str(EditLine *el, Char *str)
{
- el->el_key.val.str = str;
- return (&el->el_key.val);
+ el->el_keymacro.val.str = str;
+ return &el->el_keymacro.val;
}
-/* key_reset():
- * Takes all nodes on el->el_key.map and puts them on free list. Then
- * initializes el->el_key.map with arrow keys
+/* keymacro_reset():
+ * Takes all nodes on el->el_keymacro.map and puts them on free list.
+ * Then initializes el->el_keymacro.map with arrow keys
* [Always bind the ansi arrow keys?]
*/
protected void
-key_reset(EditLine *el)
+keymacro_reset(EditLine *el)
{
- node__put(el, el->el_key.map);
- el->el_key.map = NULL;
+ node__put(el, el->el_keymacro.map);
+ el->el_keymacro.map = NULL;
return;
}
-/* key_get():
- * Calls the recursive function with entry point el->el_key.map
+/* keymacro_get():
+ * Calls the recursive function with entry point el->el_keymacro.map
* Looks up *ch in map and then reads characters until a
* complete match is found or a mismatch occurs. Returns the
* type of the match found (XK_STR, XK_CMD, or XK_EXE).
@@ -171,49 +174,49 @@ key_reset(EditLine *el)
* The last character read is returned in *ch.
*/
protected int
-key_get(EditLine *el, Char *ch, key_value_t *val)
+keymacro_get(EditLine *el, Char *ch, keymacro_value_t *val)
{
- return (node_trav(el, el->el_key.map, ch, val));
+ return node_trav(el, el->el_keymacro.map, ch, val);
}
-/* key_add():
- * Adds key to the el->el_key.map and associates the value in val with it.
- * If key is already is in el->el_key.map, the new code is applied to the
- * existing key. Ntype specifies if code is a command, an
- * out str or a unix command.
+/* keymacro_add():
+ * Adds key to the el->el_keymacro.map and associates the value in
+ * val with it. If key is already is in el->el_keymacro.map, the new
+ * code is applied to the existing key. Ntype specifies if code is a
+ * command, an out str or a unix command.
*/
protected void
-key_add(EditLine *el, const Char *key, key_value_t *val, int ntype)
+keymacro_add(EditLine *el, const Char *key, keymacro_value_t *val, int ntype)
{
if (key[0] == '\0') {
(void) fprintf(el->el_errfile,
- "key_add: Null extended-key not allowed.\n");
+ "keymacro_add: Null extended-key not allowed.\n");
return;
}
if (ntype == XK_CMD && val->cmd == ED_SEQUENCE_LEAD_IN) {
(void) fprintf(el->el_errfile,
- "key_add: sequence-lead-in command not allowed\n");
+ "keymacro_add: sequence-lead-in command not allowed\n");
return;
}
- if (el->el_key.map == NULL)
+ if (el->el_keymacro.map == NULL)
/* tree is initially empty. Set up new node to match key[0] */
- el->el_key.map = node__get(key[0]);
+ el->el_keymacro.map = node__get(key[0]);
/* it is properly initialized */
- /* Now recurse through el->el_key.map */
- (void) node__try(el, el->el_key.map, key, val, ntype);
+ /* Now recurse through el->el_keymacro.map */
+ (void) node__try(el, el->el_keymacro.map, key, val, ntype);
return;
}
-/* key_clear():
+/* keymacro_clear():
*
*/
protected void
-key_clear(EditLine *el, el_action_t *map, const Char *in)
+keymacro_clear(EditLine *el, el_action_t *map, const Char *in)
{
#ifdef WIDECHAR
if (*in > N_KEYS) /* can't be in the map */
@@ -224,48 +227,48 @@ key_clear(EditLine *el, el_action_t *map, const Char *in)
el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) ||
(map == el->el_map.alt &&
el->el_map.key[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN)))
- (void) key_delete(el, in);
+ (void) keymacro_delete(el, in);
}
-/* key_delete():
+/* keymacro_delete():
* Delete the key and all longer keys staring with key, if
* they exists.
*/
protected int
-key_delete(EditLine *el, const Char *key)
+keymacro_delete(EditLine *el, const Char *key)
{
if (key[0] == '\0') {
(void) fprintf(el->el_errfile,
- "key_delete: Null extended-key not allowed.\n");
- return (-1);
+ "keymacro_delete: Null extended-key not allowed.\n");
+ return -1;
}
- if (el->el_key.map == NULL)
- return (0);
+ if (el->el_keymacro.map == NULL)
+ return 0;
- (void) node__delete(el, &el->el_key.map, key);
- return (0);
+ (void) node__delete(el, &el->el_keymacro.map, key);
+ return 0;
}
-/* key_print():
+/* keymacro_print():
* Print the binding associated with key key.
- * Print entire el->el_key.map if null
+ * Print entire el->el_keymacro.map if null
*/
protected void
-key_print(EditLine *el, const Char *key)
+keymacro_print(EditLine *el, const Char *key)
{
- /* do nothing if el->el_key.map is empty and null key specified */
- if (el->el_key.map == NULL && *key == 0)
+ /* do nothing if el->el_keymacro.map is empty and null key specified */
+ if (el->el_keymacro.map == NULL && *key == 0)
return;
- el->el_key.buf[0] = '"';
- if (node_lookup(el, key, el->el_key.map, 1) <= -1)
+ el->el_keymacro.buf[0] = '"';
+ if (node_lookup(el, key, el->el_keymacro.map, (size_t)1) <= -1)
/* key is not bound */
- (void) fprintf(el->el_errfile, "Unbound extended key \"" FSTR "\"\n",
- key);
+ (void) fprintf(el->el_errfile, "Unbound extended key \"" FSTR
+ "\"\n", key);
return;
}
@@ -275,7 +278,7 @@ key_print(EditLine *el, const Char *key)
* found. May read in more characters.
*/
private int
-node_trav(EditLine *el, key_node_t *ptr, Char *ch, key_value_t *val)
+node_trav(EditLine *el, keymacro_node_t *ptr, Char *ch, keymacro_value_t *val)
{
if (ptr->ch == *ch) {
@@ -284,25 +287,25 @@ node_trav(EditLine *el, key_node_t *ptr, Char *ch, key_value_t *val)
/* key not complete so get next char */
if (FUN(el,getc)(el, ch) != 1) {/* if EOF or error */
val->cmd = ED_END_OF_FILE;
- return (XK_CMD);
+ return XK_CMD;
/* PWP: Pretend we just read an end-of-file */
}
- return (node_trav(el, ptr->next, ch, val));
+ return node_trav(el, ptr->next, ch, val);
} else {
*val = ptr->val;
if (ptr->type != XK_CMD)
*ch = '\0';
- return (ptr->type);
+ return ptr->type;
}
} else {
/* no match found here */
if (ptr->sibling) {
/* try next sibling */
- return (node_trav(el, ptr->sibling, ch, val));
+ return node_trav(el, ptr->sibling, ch, val);
} else {
/* no next sibling -- mismatch */
val->str = NULL;
- return (XK_STR);
+ return XK_STR;
}
}
}
@@ -312,11 +315,12 @@ node_trav(EditLine *el, key_node_t *ptr, Char *ch, key_value_t *val)
* Find a node that matches *str or allocate a new one
*/
private int
-node__try(EditLine *el, key_node_t *ptr, const Char *str, key_value_t *val, int ntype)
+node__try(EditLine *el, keymacro_node_t *ptr, const Char *str,
+ keymacro_value_t *val, int ntype)
{
if (ptr->ch != *str) {
- key_node_t *xm;
+ keymacro_node_t *xm;
for (xm = ptr; xm->sibling != NULL; xm = xm->sibling)
if (xm->sibling->ch == *str)
@@ -339,7 +343,7 @@ node__try(EditLine *el, key_node_t *ptr, const Char *str, key_value_t *val, int
case XK_STR:
case XK_EXE:
if (ptr->val.str)
- el_free((ptr_t) ptr->val.str);
+ el_free(ptr->val.str);
break;
default:
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n",
@@ -366,7 +370,7 @@ node__try(EditLine *el, key_node_t *ptr, const Char *str, key_value_t *val, int
ptr->next = node__get(*str); /* setup new node */
(void) node__try(el, ptr->next, str, val, ntype);
}
- return (0);
+ return 0;
}
@@ -374,21 +378,21 @@ node__try(EditLine *el, key_node_t *ptr, const Char *str, key_value_t *val, int
* Delete node that matches str
*/
private int
-node__delete(EditLine *el, key_node_t **inptr, const Char *str)
+node__delete(EditLine *el, keymacro_node_t **inptr, const Char *str)
{
- key_node_t *ptr;
- key_node_t *prev_ptr = NULL;
+ keymacro_node_t *ptr;
+ keymacro_node_t *prev_ptr = NULL;
ptr = *inptr;
if (ptr->ch != *str) {
- key_node_t *xm;
+ keymacro_node_t *xm;
for (xm = ptr; xm->sibling != NULL; xm = xm->sibling)
if (xm->sibling->ch == *str)
break;
if (xm->sibling == NULL)
- return (0);
+ return 0;
prev_ptr = xm;
ptr = xm->sibling;
}
@@ -400,20 +404,20 @@ node__delete(EditLine *el, key_node_t **inptr, const Char *str)
prev_ptr->sibling = ptr->sibling;
ptr->sibling = NULL;
node__put(el, ptr);
- return (1);
+ return 1;
} else if (ptr->next != NULL &&
node__delete(el, &ptr->next, str) == 1) {
if (ptr->next != NULL)
- return (0);
+ return 0;
if (prev_ptr == NULL)
*inptr = ptr->sibling;
else
prev_ptr->sibling = ptr->sibling;
ptr->sibling = NULL;
node__put(el, ptr);
- return (1);
+ return 1;
} else {
- return (0);
+ return 0;
}
}
@@ -422,7 +426,7 @@ node__delete(EditLine *el, key_node_t **inptr, const Char *str)
* Puts a tree of nodes onto free list using free(3).
*/
private void
-node__put(EditLine *el, key_node_t *ptr)
+node__put(EditLine *el, keymacro_node_t *ptr)
{
if (ptr == NULL)
return;
@@ -440,25 +444,25 @@ node__put(EditLine *el, key_node_t *ptr)
case XK_EXE:
case XK_STR:
if (ptr->val.str != NULL)
- el_free((ptr_t) ptr->val.str);
+ el_free(ptr->val.str);
break;
default:
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ptr->type));
break;
}
- el_free((ptr_t) ptr);
+ el_free(ptr);
}
/* node__get():
- * Returns pointer to a key_node_t for ch.
+ * Returns pointer to a keymacro_node_t for ch.
*/
-private key_node_t *
+private keymacro_node_t *
node__get(Int ch)
{
- key_node_t *ptr;
+ keymacro_node_t *ptr;
- ptr = (key_node_t *) el_malloc((size_t) sizeof(key_node_t));
+ ptr = el_malloc(sizeof(*ptr));
if (ptr == NULL)
return NULL;
ptr->ch = ch;
@@ -466,17 +470,17 @@ node__get(Int ch)
ptr->val.str = NULL;
ptr->next = NULL;
ptr->sibling = NULL;
- return (ptr);
+ return ptr;
}
private void
-node__free(key_node_t *k)
+node__free(keymacro_node_t *k)
{
if (k == NULL)
return;
node__free(k->sibling);
node__free(k->next);
- el_free((ptr_t) k);
+ el_free(k);
}
/* node_lookup():
@@ -484,39 +488,40 @@ node__free(key_node_t *k)
* Print if last node
*/
private int
-node_lookup(EditLine *el, const Char *str, key_node_t *ptr, size_t cnt)
+node_lookup(EditLine *el, const Char *str, keymacro_node_t *ptr, size_t cnt)
{
ssize_t used;
if (ptr == NULL)
- return (-1); /* cannot have null ptr */
+ return -1; /* cannot have null ptr */
if (!str || *str == 0) {
/* no more chars in str. node_enum from here. */
(void) node_enum(el, ptr, cnt);
- return (0);
+ return 0;
} else {
- /* If match put this char into el->el_key.buf. Recurse */
+ /* If match put this char into el->el_keymacro.buf. Recurse */
if (ptr->ch == *str) {
/* match found */
- used = ct_visual_char(el->el_key.buf + cnt,
+ used = ct_visual_char(el->el_keymacro.buf + cnt,
KEY_BUFSIZ - cnt, ptr->ch);
if (used == -1)
- return (-1); /* ran out of buffer space */
+ return -1; /* ran out of buffer space */
if (ptr->next != NULL)
/* not yet at leaf */
return (node_lookup(el, str + 1, ptr->next,
- used + cnt));
+ (size_t)used + cnt));
else {
/* next node is null so key should be complete */
if (str[1] == 0) {
- el->el_key.buf[cnt + used ] = '"';
- el->el_key.buf[cnt + used + 1] = '\0';
- key_kprint(el, el->el_key.buf,
+ size_t px = cnt + (size_t)used;
+ el->el_keymacro.buf[px] = '"';
+ el->el_keymacro.buf[px + 1] = '\0';
+ keymacro_kprint(el, el->el_keymacro.buf,
&ptr->val, ptr->type);
- return (0);
+ return 0;
} else
- return (-1);
+ return -1;
/* mismatch -- str still has chars */
}
} else {
@@ -525,7 +530,7 @@ node_lookup(EditLine *el, const Char *str, key_node_t *ptr, size_t cnt)
return (node_lookup(el, str, ptr->sibling,
cnt));
else
- return (-1);
+ return -1;
}
}
}
@@ -535,48 +540,50 @@ node_lookup(EditLine *el, const Char *str, key_node_t *ptr, size_t cnt)
* Traverse the node printing the characters it is bound in buffer
*/
private int
-node_enum(EditLine *el, key_node_t *ptr, size_t cnt)
+node_enum(EditLine *el, keymacro_node_t *ptr, size_t cnt)
{
ssize_t used;
if (cnt >= KEY_BUFSIZ - 5) { /* buffer too small */
- el->el_key.buf[++cnt] = '"';
- el->el_key.buf[++cnt] = '\0';
+ el->el_keymacro.buf[++cnt] = '"';
+ el->el_keymacro.buf[++cnt] = '\0';
(void) fprintf(el->el_errfile,
"Some extended keys too long for internal print buffer");
- (void) fprintf(el->el_errfile, " \"" FSTR "...\"\n", el->el_key.buf);
- return (0);
+ (void) fprintf(el->el_errfile, " \"" FSTR "...\"\n",
+ el->el_keymacro.buf);
+ return 0;
}
if (ptr == NULL) {
#ifdef DEBUG_EDIT
(void) fprintf(el->el_errfile,
"node_enum: BUG!! Null ptr passed\n!");
#endif
- return (-1);
+ return -1;
}
/* put this char at end of str */
- used = ct_visual_char(el->el_key.buf + cnt, KEY_BUFSIZ - cnt, ptr->ch);
+ used = ct_visual_char(el->el_keymacro.buf + cnt, KEY_BUFSIZ - cnt,
+ ptr->ch);
if (ptr->next == NULL) {
/* print this key and function */
- el->el_key.buf[cnt + used ] = '"';
- el->el_key.buf[cnt + used + 1] = '\0';
- key_kprint(el, el->el_key.buf, &ptr->val, ptr->type);
+ el->el_keymacro.buf[cnt + (size_t)used ] = '"';
+ el->el_keymacro.buf[cnt + (size_t)used + 1] = '\0';
+ keymacro_kprint(el, el->el_keymacro.buf, &ptr->val, ptr->type);
} else
- (void) node_enum(el, ptr->next, cnt + used);
+ (void) node_enum(el, ptr->next, cnt + (size_t)used);
/* go to sibling if there is one */
if (ptr->sibling)
(void) node_enum(el, ptr->sibling, cnt);
- return (0);
+ return 0;
}
-/* key_kprint():
+/* keymacro_kprint():
* Print the specified key and its associated
* function specified by val
*/
protected void
-key_kprint(EditLine *el, const Char *key, key_value_t *val, int ntype)
+keymacro_kprint(EditLine *el, const Char *key, keymacro_value_t *val, int ntype)
{
el_bindings_t *fp;
char unparsbuf[EL_BUFSIZ];
@@ -586,7 +593,7 @@ key_kprint(EditLine *el, const Char *key, key_value_t *val, int ntype)
switch (ntype) {
case XK_STR:
case XK_EXE:
- (void) key__decode_str(val->str, unparsbuf,
+ (void) keymacro__decode_str(val->str, unparsbuf,
sizeof(unparsbuf),
ntype == XK_STR ? "\"\"" : "[]");
(void) fprintf(el->el_outfile, fmt,
@@ -623,11 +630,11 @@ key_kprint(EditLine *el, const Char *key, key_value_t *val, int ntype)
*b++ = c; \
else \
b++
-/* key__decode_str():
+/* keymacro__decode_str():
* Make a printable version of the ey
*/
protected size_t
-key__decode_str(const Char *str, char *buf, size_t len, const char *sep)
+keymacro__decode_str(const Char *str, char *buf, size_t len, const char *sep)
{
char *b = buf, *eb = b + len;
const Char *p;
@@ -662,4 +669,3 @@ add_endsep:
buf[len - 1] = '\0';
return (size_t)(b - buf);
}
-
diff --git a/key.h b/keymacro.h
index 8f067a0647c8..2445de5a5bc6 100644
--- a/key.h
+++ b/keymacro.h
@@ -1,4 +1,4 @@
-/* $NetBSD: key.h,v 1.13 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: keymacro.h,v 1.2 2011/07/28 03:44:36 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -35,46 +35,42 @@
*/
/*
- * el.key.h: Key macro header
+ * el.keymacro.h: Key macro header
*/
-#ifndef _h_el_key
-#define _h_el_key
+#ifndef _h_el_keymacro
+#define _h_el_keymacro
-typedef union key_value_t {
+typedef union keymacro_value_t {
el_action_t cmd; /* If it is a command the # */
Char *str; /* If it is a string... */
-} key_value_t;
+} keymacro_value_t;
-typedef struct key_node_t key_node_t;
+typedef struct keymacro_node_t keymacro_node_t;
-typedef struct el_key_t {
+typedef struct el_keymacromacro_t {
Char *buf; /* Key print buffer */
- key_node_t *map; /* Key map */
- key_value_t val; /* Local conversion buffer */
-} el_key_t;
+ keymacro_node_t *map; /* Key map */
+ keymacro_value_t val; /* Local conversion buffer */
+} el_keymacro_t;
#define XK_CMD 0
#define XK_STR 1
#define XK_NOD 2
#define XK_EXE 3
-#undef key_end
-#undef key_clear
-#undef key_print
-
-protected int key_init(EditLine *);
-protected void key_end(EditLine *);
-protected key_value_t *key_map_cmd(EditLine *, int);
-protected key_value_t *key_map_str(EditLine *, Char *);
-protected void key_reset(EditLine *);
-protected int key_get(EditLine *, Char *, key_value_t *);
-protected void key_add(EditLine *, const Char *, key_value_t *, int);
-protected void key_clear(EditLine *, el_action_t *, const Char *);
-protected int key_delete(EditLine *, const Char *);
-protected void key_print(EditLine *, const Char *);
-protected void key_kprint(EditLine *, const Char *, key_value_t *,
+protected int keymacro_init(EditLine *);
+protected void keymacro_end(EditLine *);
+protected keymacro_value_t *keymacro_map_cmd(EditLine *, int);
+protected keymacro_value_t *keymacro_map_str(EditLine *, Char *);
+protected void keymacro_reset(EditLine *);
+protected int keymacro_get(EditLine *, Char *, keymacro_value_t *);
+protected void keymacro_add(EditLine *, const Char *, keymacro_value_t *, int);
+protected void keymacro_clear(EditLine *, el_action_t *, const Char *);
+protected int keymacro_delete(EditLine *, const Char *);
+protected void keymacro_print(EditLine *, const Char *);
+protected void keymacro_kprint(EditLine *, const Char *, keymacro_value_t *,
int);
-protected size_t key__decode_str(const Char *, char *, size_t,
+protected size_t keymacro__decode_str(const Char *, char *, size_t,
const char *);
-#endif /* _h_el_key */
+#endif /* _h_el_keymacro */
diff --git a/makelist b/makelist
index cfb6469a7b6c..588397bc6728 100644
--- a/makelist
+++ b/makelist
@@ -1,5 +1,5 @@
#!/bin/sh -
-# $NetBSD: makelist,v 1.16 2010/04/18 21:17:05 christos Exp $
+# $NetBSD: makelist,v 1.18 2012/03/21 05:34:54 matt Exp $
#
# Copyright (c) 1992, 1993
# The Regents of the University of California. All rights reserved.
@@ -55,6 +55,7 @@ case $FLAG in
#
-n)
cat << _EOF
+#include "config.h"
#undef WIDECHAR
#define NARROWCHAR
#include "${FILES}"
@@ -128,7 +129,7 @@ _EOF
}
END {
printf("};\n");
- printf("\nprotected const el_bindings_t* help__get()");
+ printf("\nprotected const el_bindings_t* help__get(void)");
printf("{ return el_func_help; }\n");
}'
;;
@@ -194,7 +195,7 @@ _EOF
}
END {
printf("\n};\n");
- printf("\nprotected const el_func_t* func__get() { return el_func; }\n");
+ printf("\nprotected const el_func_t* func__get(void) { return el_func; }\n");
}'
;;
diff --git a/map.c b/map.c
index bd46d8ff96f2..802c37174c24 100644
--- a/map.c
+++ b/map.c
@@ -1,4 +1,4 @@
-/* $NetBSD: map.c,v 1.25 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: map.c,v 1.31 2011/11/18 20:39:18 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: map.c,v 1.25 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: map.c,v 1.31 2011/11/18 20:39:18 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -903,26 +903,25 @@ map_init(EditLine *el)
EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
#endif
- el->el_map.alt = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
+ el->el_map.alt = el_malloc(sizeof(*el->el_map.alt) * N_KEYS);
if (el->el_map.alt == NULL)
- return (-1);
- el->el_map.key = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
+ return -1;
+ el->el_map.key = el_malloc(sizeof(*el->el_map.key) * N_KEYS);
if (el->el_map.key == NULL)
- return (-1);
+ return -1;
el->el_map.emacs = el_map_emacs;
el->el_map.vic = el_map_vi_command;
el->el_map.vii = el_map_vi_insert;
- el->el_map.help = (el_bindings_t *) el_malloc(sizeof(el_bindings_t) *
- EL_NUM_FCNS);
+ el->el_map.help = el_malloc(sizeof(*el->el_map.help) * EL_NUM_FCNS);
if (el->el_map.help == NULL)
- return (-1);
+ return -1;
(void) memcpy(el->el_map.help, help__get(),
- sizeof(el_bindings_t) * EL_NUM_FCNS);
- el->el_map.func = (el_func_t *)el_malloc(sizeof(el_func_t) *
- EL_NUM_FCNS);
+ sizeof(*el->el_map.help) * EL_NUM_FCNS);
+ el->el_map.func = el_malloc(sizeof(*el->el_map.func) * EL_NUM_FCNS);
if (el->el_map.func == NULL)
- return (-1);
- memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS);
+ return -1;
+ memcpy(el->el_map.func, func__get(), sizeof(*el->el_map.func)
+ * EL_NUM_FCNS);
el->el_map.nfunc = EL_NUM_FCNS;
#ifdef VIDEFAULT
@@ -930,7 +929,7 @@ map_init(EditLine *el)
#else
map_init_emacs(el);
#endif /* VIDEFAULT */
- return (0);
+ return 0;
}
@@ -941,16 +940,16 @@ protected void
map_end(EditLine *el)
{
- el_free((ptr_t) el->el_map.alt);
+ el_free(el->el_map.alt);
el->el_map.alt = NULL;
- el_free((ptr_t) el->el_map.key);
+ el_free(el->el_map.key);
el->el_map.key = NULL;
el->el_map.emacs = NULL;
el->el_map.vic = NULL;
el->el_map.vii = NULL;
- el_free((ptr_t) el->el_map.help);
+ el_free(el->el_map.help);
el->el_map.help = NULL;
- el_free((ptr_t) el->el_map.func);
+ el_free(el->el_map.func);
el->el_map.func = NULL;
}
@@ -1005,7 +1004,7 @@ map_init_meta(EditLine *el)
break;
default:
buf[1] = i & 0177;
- key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD);
+ keymacro_add(el, buf, keymacro_map_cmd(el, (int) map[i]), XK_CMD);
break;
}
map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
@@ -1027,7 +1026,7 @@ map_init_vi(EditLine *el)
el->el_map.type = MAP_VI;
el->el_map.current = el->el_map.key;
- key_reset(el);
+ keymacro_reset(el);
for (i = 0; i < N_KEYS; i++) {
key[i] = vii[i];
@@ -1038,7 +1037,7 @@ map_init_vi(EditLine *el)
map_init_nls(el);
tty_bind_char(el, 1);
- term_bind_arrow(el);
+ terminal_bind_arrow(el);
}
@@ -1056,7 +1055,7 @@ map_init_emacs(EditLine *el)
el->el_map.type = MAP_EMACS;
el->el_map.current = el->el_map.key;
- key_reset(el);
+ keymacro_reset(el);
for (i = 0; i < N_KEYS; i++) {
key[i] = emacs[i];
@@ -1069,10 +1068,10 @@ map_init_emacs(EditLine *el)
buf[0] = CONTROL('X');
buf[1] = CONTROL('X');
buf[2] = 0;
- key_add(el, buf, key_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
+ keymacro_add(el, buf, keymacro_map_cmd(el, EM_EXCHANGE_MARK), XK_CMD);
tty_bind_char(el, 1);
- term_bind_arrow(el);
+ terminal_bind_arrow(el);
}
@@ -1085,13 +1084,13 @@ map_set_editor(EditLine *el, Char *editor)
if (Strcmp(editor, STR("emacs")) == 0) {
map_init_emacs(el);
- return (0);
+ return 0;
}
if (Strcmp(editor, STR("vi")) == 0) {
map_init_vi(el);
- return (0);
+ return 0;
}
- return (-1);
+ return -1;
}
@@ -1103,16 +1102,16 @@ map_get_editor(EditLine *el, const Char **editor)
{
if (editor == NULL)
- return (-1);
+ return -1;
switch (el->el_map.type) {
case MAP_EMACS:
*editor = STR("emacs");
- return (0);
+ return 0;
case MAP_VI:
*editor = STR("vi");
- return (0);
+ return 0;
}
- return (-1);
+ return -1;
}
@@ -1126,7 +1125,7 @@ map_print_key(EditLine *el, el_action_t *map, const Char *in)
el_bindings_t *bp, *ep;
if (in[0] == '\0' || in[1] == '\0') {
- (void) key__decode_str(in, outbuf, sizeof(outbuf), "");
+ (void) keymacro__decode_str(in, outbuf, sizeof(outbuf), "");
ep = &el->el_map.help[el->el_map.nfunc];
for (bp = el->el_map.help; bp < ep; bp++)
if (bp->func == map[(unsigned char) *in]) {
@@ -1135,7 +1134,7 @@ map_print_key(EditLine *el, el_action_t *map, const Char *in)
return;
}
} else
- key_print(el, in);
+ keymacro_print(el, in);
}
@@ -1155,7 +1154,7 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
lastbuf[1] = 0;
if (map[first] == ED_UNASSIGNED) {
if (first == last) {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile,
"%-15s-> is undefined\n", unparsbuf);
@@ -1166,14 +1165,14 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
for (bp = el->el_map.help; bp < ep; bp++) {
if (bp->func == map[first]) {
if (first == last) {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile, "%-15s-> " FSTR "\n",
unparsbuf, bp->name);
} else {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
- (void) key__decode_str(lastbuf, extrabuf,
+ (void) keymacro__decode_str(lastbuf, extrabuf,
sizeof(extrabuf), STRQQ);
(void) fprintf(el->el_outfile,
"%-4s to %-7s-> " FSTR "\n",
@@ -1184,14 +1183,14 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last)
}
#ifdef MAP_DEBUG
if (map == el->el_map.key) {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile,
"BUG!!! %s isn't bound to anything.\n", unparsbuf);
(void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
first, el->el_map.key[first]);
} else {
- (void) key__decode_str(firstbuf, unparsbuf,
+ (void) keymacro__decode_str(firstbuf, unparsbuf,
sizeof(unparsbuf), STRQQ);
(void) fprintf(el->el_outfile,
"BUG!!! %s isn't bound to anything.\n", unparsbuf);
@@ -1232,9 +1231,9 @@ map_print_all_keys(EditLine *el)
map_print_some_keys(el, el->el_map.alt, prev, i - 1);
(void) fprintf(el->el_outfile, "Multi-character bindings\n");
- key_print(el, STR(""));
+ keymacro_print(el, STR(""));
(void) fprintf(el->el_outfile, "Arrow key bindings\n");
- term_print_arrow(el, STR(""));
+ terminal_print_arrow(el, STR(""));
}
@@ -1256,7 +1255,7 @@ map_bind(EditLine *el, int argc, const Char **argv)
int key;
if (argv == NULL)
- return (-1);
+ return -1;
map = el->el_map.key;
ntype = XK_CMD;
@@ -1286,11 +1285,11 @@ map_bind(EditLine *el, int argc, const Char **argv)
case 'v':
map_init_vi(el);
- return (0);
+ return 0;
case 'e':
map_init_emacs(el);
- return (0);
+ return 0;
case 'l':
ep = &el->el_map.help[el->el_map.nfunc];
@@ -1298,7 +1297,7 @@ map_bind(EditLine *el, int argc, const Char **argv)
(void) fprintf(el->el_outfile,
"" FSTR "\n\t" FSTR "\n",
bp->name, bp->description);
- return (0);
+ return 0;
default:
(void) fprintf(el->el_errfile,
"" FSTR ": Invalid switch `%c'.\n",
@@ -1309,7 +1308,7 @@ map_bind(EditLine *el, int argc, const Char **argv)
if (argv[argc] == NULL) {
map_print_all_keys(el);
- return (0);
+ return 0;
}
if (key)
in = argv[argc++];
@@ -1317,32 +1316,32 @@ map_bind(EditLine *el, int argc, const Char **argv)
(void) fprintf(el->el_errfile,
"" FSTR ": Invalid \\ or ^ in instring.\n",
argv[0]);
- return (-1);
+ return -1;
}
if (rem) {
if (key) {
- (void) term_clear_arrow(el, in);
- return (-1);
+ (void) terminal_clear_arrow(el, in);
+ return -1;
}
if (in[1])
- (void) key_delete(el, in);
+ (void) keymacro_delete(el, in);
else if (map[(unsigned char) *in] == ED_SEQUENCE_LEAD_IN)
- (void) key_delete(el, in);
+ (void) keymacro_delete(el, in);
else
map[(unsigned char) *in] = ED_UNASSIGNED;
- return (0);
+ return 0;
}
if (argv[argc] == NULL) {
if (key)
- term_print_arrow(el, in);
+ terminal_print_arrow(el, in);
else
map_print_key(el, map, in);
- return (0);
+ return 0;
}
#ifdef notyet
if (argv[argc + 1] != NULL) {
- bindkey_usage();
- return (-1);
+ bindkeymacro_usage();
+ return -1;
}
#endif
@@ -1352,12 +1351,12 @@ map_bind(EditLine *el, int argc, const Char **argv)
if ((out = parse__string(outbuf, argv[argc])) == NULL) {
(void) fprintf(el->el_errfile,
"" FSTR ": Invalid \\ or ^ in outstring.\n", argv[0]);
- return (-1);
+ return -1;
}
if (key)
- term_set_arrow(el, in, key_map_str(el, out), ntype);
+ terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
else
- key_add(el, in, key_map_str(el, out), ntype);
+ keymacro_add(el, in, keymacro_map_str(el, out), ntype);
map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
break;
@@ -1366,26 +1365,27 @@ map_bind(EditLine *el, int argc, const Char **argv)
(void) fprintf(el->el_errfile,
"" FSTR ": Invalid command `" FSTR "'.\n",
argv[0], argv[argc]);
- return (-1);
+ return -1;
}
if (key)
- term_set_arrow(el, in, key_map_str(el, out), ntype);
+ terminal_set_arrow(el, in, keymacro_map_str(el, out), ntype);
else {
if (in[1]) {
- key_add(el, in, key_map_cmd(el, cmd), ntype);
+ keymacro_add(el, in, keymacro_map_cmd(el, cmd), ntype);
map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
} else {
- key_clear(el, map, in);
- map[(unsigned char) *in] = cmd;
+ keymacro_clear(el, map, in);
+ map[(unsigned char) *in] = (el_action_t)cmd;
}
}
break;
+ /* coverity[dead_error_begin] */
default:
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
break;
}
- return (0);
+ return 0;
}
@@ -1396,26 +1396,27 @@ protected int
map_addfunc(EditLine *el, const Char *name, const Char *help, el_func_t func)
{
void *p;
- int nf = el->el_map.nfunc + 1;
+ size_t nf = (size_t)el->el_map.nfunc + 1;
if (name == NULL || help == NULL || func == NULL)
- return (-1);
+ return -1;
- if ((p = el_realloc(el->el_map.func, nf * sizeof(el_func_t))) == NULL)
- return (-1);
- el->el_map.func = (el_func_t *) p;
- if ((p = el_realloc(el->el_map.help, nf * sizeof(el_bindings_t)))
+ if ((p = el_realloc(el->el_map.func, nf *
+ sizeof(*el->el_map.func))) == NULL)
+ return -1;
+ el->el_map.func = p;
+ if ((p = el_realloc(el->el_map.help, nf * sizeof(*el->el_map.help)))
== NULL)
- return (-1);
- el->el_map.help = (el_bindings_t *) p;
+ return -1;
+ el->el_map.help = p;
- nf = el->el_map.nfunc;
+ nf = (size_t)el->el_map.nfunc;
el->el_map.func[nf] = func;
el->el_map.help[nf].name = name;
- el->el_map.help[nf].func = nf;
+ el->el_map.help[nf].func = (int)nf;
el->el_map.help[nf].description = help;
el->el_map.nfunc++;
- return (0);
+ return 0;
}
diff --git a/parse.c b/parse.c
index 9983fa750372..f1c4391a2f04 100644
--- a/parse.c
+++ b/parse.c
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.23 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: parse.c,v 1.26 2011/08/16 16:25:15 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: parse.c,v 1.23 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: parse.c,v 1.26 2011/08/16 16:25:15 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -62,11 +62,11 @@ private const struct {
int (*func)(EditLine *, int, const Char **);
} cmds[] = {
{ STR("bind"), map_bind },
- { STR("echotc"), term_echotc },
+ { STR("echotc"), terminal_echotc },
{ STR("edit"), el_editmode },
{ STR("history"), hist_command },
- { STR("telltc"), term_telltc },
- { STR("settc"), term_settc },
+ { STR("telltc"), terminal_telltc },
+ { STR("settc"), terminal_settc },
{ STR("setty"), tty_stty },
{ NULL, NULL }
};
@@ -86,7 +86,7 @@ parse_line(EditLine *el, const Char *line)
FUN(tok,str)(tok, line, &argc, &argv);
argc = FUN(el,parse)(el, argc, argv);
FUN(tok,end)(tok);
- return (argc);
+ return argc;
}
@@ -100,34 +100,34 @@ FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
int i;
if (argc < 1)
- return (-1);
+ return -1;
ptr = Strchr(argv[0], ':');
if (ptr != NULL) {
Char *tprog;
size_t l;
if (ptr == argv[0])
- return (0);
- l = ptr - argv[0] - 1;
+ return 0;
+ l = (size_t)(ptr - argv[0] - 1);
tprog = el_malloc((l + 1) * sizeof(*tprog));
if (tprog == NULL)
- return (0);
+ return 0;
(void) Strncpy(tprog, argv[0], l);
tprog[l] = '\0';
ptr++;
- l = el_match(el->el_prog, tprog);
+ l = (size_t)el_match(el->el_prog, tprog);
el_free(tprog);
if (!l)
- return (0);
+ return 0;
} else
ptr = argv[0];
for (i = 0; cmds[i].name != NULL; i++)
if (Strcmp(cmds[i].name, ptr) == 0) {
i = (*cmds[i].func) (el, argc, argv);
- return (-i);
+ return -i;
}
- return (-1);
+ return -1;
}
@@ -144,7 +144,7 @@ parse__escape(const Char **ptr)
p = *ptr;
if (p[1] == 0)
- return (-1);
+ return -1;
if (*p == '\\') {
p++;
@@ -180,12 +180,12 @@ parse__escape(const Char **ptr)
const Char *h;
++p;
if (*p++ != '+')
- return (-1);
+ return -1;
c = 0;
for (i = 0; i < 5; ++i) {
h = Strchr(hex, *p++);
if (!h && i < 4)
- return (-1);
+ return -1;
else if (h)
c = (c << 4) | ((int)(h - hex));
else
@@ -214,8 +214,8 @@ parse__escape(const Char **ptr)
}
c = (c << 3) | (ch - '0');
}
- if ((c & 0xffffff00) != 0)
- return (-1);
+ if ((c & (wint_t)0xffffff00) != (wint_t)0)
+ return -1;
--p;
break;
}
@@ -229,7 +229,7 @@ parse__escape(const Char **ptr)
} else
c = *p;
*ptr = ++p;
- return (c);
+ return c;
}
/* parse__string():
@@ -245,12 +245,12 @@ parse__string(Char *out, const Char *in)
switch (*in) {
case '\0':
*out = '\0';
- return (rv);
+ return rv;
case '\\':
case '^':
if ((n = parse__escape(&in)) == -1)
- return (NULL);
+ return NULL;
*out++ = n;
break;
@@ -280,6 +280,6 @@ parse_cmd(EditLine *el, const Char *cmd)
for (b = el->el_map.help; b->name != NULL; b++)
if (Strcmp(b->name, cmd) == 0)
- return (b->func);
- return (-1);
+ return b->func;
+ return -1;
}
diff --git a/prompt.c b/prompt.c
index acfb4372e4a1..48b2d27f8720 100644
--- a/prompt.c
+++ b/prompt.c
@@ -1,4 +1,4 @@
-/* $NetBSD: prompt.c,v 1.18 2009/12/31 15:58:26 christos Exp $ */
+/* $NetBSD: prompt.c,v 1.20 2011/07/29 15:16:33 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: prompt.c,v 1.18 2009/12/31 15:58:26 christos Exp $");
+__RCSID("$NetBSD: prompt.c,v 1.20 2011/07/29 15:16:33 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -59,7 +59,7 @@ prompt_default(EditLine *el __attribute__((__unused__)))
{
static Char a[3] = {'?', ' ', '\0'};
- return (a);
+ return a;
}
@@ -72,7 +72,7 @@ prompt_default_r(EditLine *el __attribute__((__unused__)))
{
static Char a[1] = {'\0'};
- return (a);
+ return a;
}
@@ -103,7 +103,7 @@ prompt_print(EditLine *el, int op)
continue;
}
if (ignore)
- term__putc(el, *p);
+ terminal__putc(el, *p);
else
re_putc(el, *p, 1);
}
diff --git a/read.c b/read.c
index 4a51799c1e64..74796b1db2f8 100644
--- a/read.c
+++ b/read.c
@@ -1,4 +1,4 @@
-/* $NetBSD: read.c,v 1.57 2010/07/21 18:18:52 christos Exp $ */
+/* $NetBSD: read.c,v 1.69 2012/09/11 12:31:08 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.57 2010/07/21 18:18:52 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.69 2012/09/11 12:31:08 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -52,7 +52,7 @@ __RCSID("$NetBSD: read.c,v 1.57 2010/07/21 18:18:52 christos Exp $");
#include <limits.h>
#include "el.h"
-#define OKCMD -1 /* must be -1! */
+#define OKCMD -1 /* must be -1! */
private int read__fixio(int, int);
private int read_preread(EditLine *);
@@ -91,7 +91,7 @@ el_read_setfn(EditLine *el, el_rfunc_t rc)
protected el_rfunc_t
el_read_getfn(EditLine *el)
{
- return (el->el_read.read_char == read_char) ?
+ return el->el_read.read_char == read_char ?
EL_BUILTIN_GETCFN : el->el_read.read_char;
}
@@ -133,7 +133,7 @@ read__fixio(int fd __attribute__((__unused__)), int e)
#ifdef EWOULDBLOCK
case EWOULDBLOCK:
#ifndef TRY_AGAIN
-#define TRY_AGAIN
+#define TRY_AGAIN
#endif
#endif /* EWOULDBLOCK */
@@ -141,7 +141,7 @@ read__fixio(int fd __attribute__((__unused__)), int e)
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EAGAIN:
#ifndef TRY_AGAIN
-#define TRY_AGAIN
+#define TRY_AGAIN
#endif
#endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
#endif /* POSIX && EAGAIN */
@@ -150,10 +150,10 @@ read__fixio(int fd __attribute__((__unused__)), int e)
#ifdef TRY_AGAIN
#if defined(F_SETFL) && defined(O_NDELAY)
if ((e = fcntl(fd, F_GETFL, 0)) == -1)
- return (-1);
+ return -1;
if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
- return (-1);
+ return -1;
else
e = 1;
#endif /* F_SETFL && O_NDELAY */
@@ -162,21 +162,21 @@ read__fixio(int fd __attribute__((__unused__)), int e)
{
int zero = 0;
- if (ioctl(fd, FIONBIO, (ioctl_t) & zero) == -1)
- return (-1);
+ if (ioctl(fd, FIONBIO, &zero) == -1)
+ return -1;
else
e = 1;
}
#endif /* FIONBIO */
#endif /* TRY_AGAIN */
- return (e ? 0 : -1);
+ return e ? 0 : -1;
case EINTR:
- return (0);
+ return 0;
default:
- return (-1);
+ return -1;
}
}
@@ -190,13 +190,13 @@ read_preread(EditLine *el)
int chrs = 0;
if (el->el_tty.t_mode == ED_IO)
- return (0);
+ return 0;
#ifndef WIDECHAR
/* FIONREAD attempts to buffer up multiple bytes, and to make that work
* properly with partial wide/UTF-8 characters would need some careful work. */
#ifdef FIONREAD
- (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
+ (void) ioctl(el->el_infd, FIONREAD, &chrs);
if (chrs > 0) {
char buf[EL_BUFSIZ];
@@ -209,7 +209,7 @@ read_preread(EditLine *el)
}
#endif /* FIONREAD */
#endif
- return (chrs > 0);
+ return chrs > 0;
}
@@ -227,13 +227,13 @@ FUN(el,push)(EditLine *el, const Char *str)
return;
ma->level--;
}
- term_beep(el);
- term__flush(el);
+ terminal_beep(el);
+ terminal__flush(el);
}
/* read_getcmd():
- * Return next command from the input stream.
+ * Get next command from the input stream, return OKCMD on success.
* Character values > 255 are not looked up in the map, but inserted.
*/
private int
@@ -246,7 +246,7 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch)
do {
if ((num = FUN(el,getc)(el, ch)) != 1) {/* if EOF or error */
el->el_errno = num == 0 ? 0 : errno;
- return (num);
+ return 0; /* not OKCMD */
}
#ifdef KANJI
@@ -262,14 +262,14 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch)
*ch |= 0200;
}
#ifdef WIDECHAR
- if (*ch >= N_KEYS)
- cmd = ED_INSERT;
+ if (*ch >= N_KEYS)
+ cmd = ED_INSERT;
else
#endif
- cmd = el->el_map.current[(unsigned char) *ch];
+ cmd = el->el_map.current[(unsigned char) *ch];
if (cmd == ED_SEQUENCE_LEAD_IN) {
- key_value_t val;
- switch (key_get(el, ch, &val)) {
+ keymacro_value_t val;
+ switch (keymacro_get(el, ch, &val)) {
case XK_CMD:
cmd = val.cmd;
break;
@@ -291,18 +291,18 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch)
el->el_map.current = el->el_map.key;
} while (cmd == ED_SEQUENCE_LEAD_IN);
*cmdnum = cmd;
- return (OKCMD);
+ return OKCMD;
}
#ifdef WIDECHAR
/* utf8_islead():
- * Test whether a byte is a leading byte of a UTF-8 sequence.
+ * Test whether a byte is a leading byte of a UTF-8 sequence.
*/
private int
-utf8_islead(unsigned char c)
+utf8_islead(int c)
{
- return (c < 0x80) || /* single byte char */
- (c >= 0xc2 && c <= 0xf4); /* start of multibyte sequence */
+ return c < 0x80 || /* single byte char */
+ (c >= 0xc2 && c <= 0xf4); /* start of multibyte sequence */
}
#endif
@@ -314,16 +314,17 @@ read_char(EditLine *el, Char *cp)
{
ssize_t num_read;
int tried = 0;
- char cbuf[MB_LEN_MAX];
- int cbp = 0;
- int bytes = 0;
+ char cbuf[MB_LEN_MAX];
+ size_t cbp = 0;
+ int bytes = 0;
again:
el->el_signal->sig_no = 0;
- while ((num_read = read(el->el_infd, cbuf + cbp, 1)) == -1) {
+ while ((num_read = read(el->el_infd, cbuf + cbp, (size_t)1)) == -1) {
+ int e = errno;
switch (el->el_signal->sig_no) {
case SIGCONT:
- el_set(el, EL_REFRESH);
+ FUN(el,set)(el, EL_REFRESH);
/*FALLTHROUGH*/
case SIGWINCH:
sig_set(el);
@@ -331,11 +332,12 @@ read_char(EditLine *el, Char *cp)
default:
break;
}
- if (!tried && read__fixio(el->el_infd, errno) == 0)
+ if (!tried && read__fixio(el->el_infd, e) == 0)
tried = 1;
else {
+ errno = e;
*cp = '\0';
- return (-1);
+ return -1;
}
}
@@ -347,12 +349,17 @@ read_char(EditLine *el, Char *cp)
if ((bytes = ct_mbtowc(cp, cbuf, cbp)) == -1) {
ct_mbtowc_reset;
if (cbp >= MB_LEN_MAX) { /* "shouldn't happen" */
+ errno = EILSEQ;
*cp = '\0';
- return (-1);
+ return -1;
}
goto again;
}
- } else /* we don't support other multibyte charsets */
+ } else if (isascii((unsigned char)cbuf[0]) ||
+ /* we don't support other multibyte charsets */
+ ++cbp != 1 ||
+ /* Try non-ASCII characters in a 8-bit character set */
+ (bytes = ct_mbtowc(cp, cbuf, cbp)) != 1)
#endif
*cp = (unsigned char)cbuf[0];
@@ -388,7 +395,7 @@ FUN(el,getc)(EditLine *el, Char *cp)
int num_read;
c_macro_t *ma = &el->el_chared.c_macro;
- term__flush(el);
+ terminal__flush(el);
for (;;) {
if (ma->level < 0) {
if (!read_preread(el))
@@ -410,19 +417,21 @@ FUN(el,getc)(EditLine *el, Char *cp)
read_pop(ma);
}
- return (1);
+ return 1;
}
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Turning raw mode on\n");
#endif /* DEBUG_READ */
if (tty_rawmode(el) < 0)/* make sure the tty is set up correctly */
- return (0);
+ return 0;
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Reading a character\n");
#endif /* DEBUG_READ */
num_read = (*el->el_read.read_char)(el, cp);
+ if (num_read < 0)
+ el->el_errno = errno;
#ifdef WIDECHAR
if (el->el_flags & NARROW_READ)
*cp = *(char *)(void *)cp;
@@ -430,7 +439,7 @@ FUN(el,getc)(EditLine *el, Char *cp)
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Got it %c\n", *cp);
#endif /* DEBUG_READ */
- return (num_read);
+ return num_read;
}
protected void
@@ -451,7 +460,7 @@ read_prepare(EditLine *el)
re_refresh(el); /* print the prompt */
if (el->el_flags & UNBUFFERED)
- term__flush(el);
+ terminal__flush(el);
}
protected void
@@ -469,7 +478,7 @@ FUN(el,gets)(EditLine *el, int *nread)
int retval;
el_action_t cmdnum = 0;
int num; /* how many chars we have read at NL */
- Char ch;
+ Char ch, *cp;
int crlf = 0;
int nrb;
#ifdef FIONREAD
@@ -481,14 +490,14 @@ FUN(el,gets)(EditLine *el, int *nread)
*nread = 0;
if (el->el_flags & NO_TTY) {
- Char *cp = el->el_line.buffer;
size_t idx;
+ cp = el->el_line.buffer;
while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
/* make sure there is space for next character */
if (cp + 1 >= el->el_line.limit) {
- idx = (cp - el->el_line.buffer);
- if (!ch_enlargebufs(el, 2))
+ idx = (size_t)(cp - el->el_line.buffer);
+ if (!ch_enlargebufs(el, (size_t)2))
break;
cp = &el->el_line.buffer[idx];
}
@@ -504,10 +513,7 @@ FUN(el,gets)(EditLine *el, int *nread)
el->el_errno = errno;
}
- el->el_line.cursor = el->el_line.lastchar = cp;
- *cp = '\0';
- *nread = (int)(el->el_line.cursor - el->el_line.buffer);
- goto done;
+ goto noedit;
}
@@ -515,12 +521,12 @@ FUN(el,gets)(EditLine *el, int *nread)
if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
long chrs = 0;
- (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
+ (void) ioctl(el->el_infd, FIONREAD, &chrs);
if (chrs == 0) {
if (tty_rawmode(el) < 0) {
errno = 0;
*nread = 0;
- return (NULL);
+ return NULL;
}
}
}
@@ -530,7 +536,6 @@ FUN(el,gets)(EditLine *el, int *nread)
read_prepare(el);
if (el->el_flags & EDIT_DISABLED) {
- Char *cp;
size_t idx;
if ((el->el_flags & UNBUFFERED) == 0)
@@ -538,13 +543,13 @@ FUN(el,gets)(EditLine *el, int *nread)
else
cp = el->el_line.lastchar;
- term__flush(el);
+ terminal__flush(el);
while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
/* make sure there is space next character */
if (cp + 1 >= el->el_line.limit) {
- idx = (cp - el->el_line.buffer);
- if (!ch_enlargebufs(el, 2))
+ idx = (size_t)(cp - el->el_line.buffer);
+ if (!ch_enlargebufs(el, (size_t)2))
break;
cp = &el->el_line.buffer[idx];
}
@@ -562,9 +567,7 @@ FUN(el,gets)(EditLine *el, int *nread)
el->el_errno = errno;
}
- el->el_line.cursor = el->el_line.lastchar = cp;
- *cp = '\0';
- goto done;
+ goto noedit;
}
for (num = OKCMD; num == OKCMD;) { /* while still editing this
@@ -574,6 +577,7 @@ FUN(el,gets)(EditLine *el, int *nread)
#endif /* DEBUG_EDIT */
/* if EOF or error */
if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
+ num = -1;
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile,
"Returning from el_gets %d\n", num);
@@ -647,7 +651,7 @@ FUN(el,gets)(EditLine *el, int *nread)
case CC_REFRESH_BEEP:
re_refresh(el);
- term_beep(el);
+ terminal_beep(el);
break;
case CC_NORM: /* normal char */
@@ -679,7 +683,7 @@ FUN(el,gets)(EditLine *el, int *nread)
/* put (real) cursor in a known place */
re_clear_display(el); /* reset the display stuff */
ch_reset(el, 1); /* reset the input pointers */
- re_refresh(el); /* print the prompt again */
+ re_refresh(el); /* print the prompt again */
break;
case CC_ERROR:
@@ -688,8 +692,8 @@ FUN(el,gets)(EditLine *el, int *nread)
(void) fprintf(el->el_errfile,
"*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
- term_beep(el);
- term__flush(el);
+ terminal_beep(el);
+ terminal__flush(el);
break;
}
el->el_state.argument = 1;
@@ -699,7 +703,7 @@ FUN(el,gets)(EditLine *el, int *nread)
break;
}
- term__flush(el); /* flush any buffered output */
+ terminal__flush(el); /* flush any buffered output */
/* make sure the tty is set up correctly */
if ((el->el_flags & UNBUFFERED) == 0) {
read_finish(el);
@@ -707,6 +711,11 @@ FUN(el,gets)(EditLine *el, int *nread)
} else {
*nread = (int)(el->el_line.lastchar - el->el_line.buffer);
}
+ goto done;
+noedit:
+ el->el_line.cursor = el->el_line.lastchar = cp;
+ *cp = '\0';
+ *nread = (int)(el->el_line.cursor - el->el_line.buffer);
done:
if (*nread == 0) {
if (num == -1) {
diff --git a/readline.c b/readline.c
index 2f8afabec7ee..534acd8af241 100644
--- a/readline.c
+++ b/readline.c
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.c,v 1.90 2010/08/04 20:29:18 christos Exp $ */
+/* $NetBSD: readline.c,v 1.105 2012/07/12 18:46:20 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.90 2010/08/04 20:29:18 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.105 2012/07/12 18:46:20 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@@ -47,11 +47,8 @@ __RCSID("$NetBSD: readline.c,v 1.90 2010/08/04 20:29:18 christos Exp $");
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h>
-#ifdef HAVE_VIS_H
#include <vis.h>
-#else
-#include "np/vis.h"
-#endif
+
#include "readline/readline.h"
#include "el.h"
#include "fcns.h" /* for EL_NUM_FCNS */
@@ -103,6 +100,7 @@ char *rl_basic_word_break_characters = break_chars;
char *rl_completer_word_break_characters = NULL;
char *rl_completer_quote_characters = NULL;
Function *rl_completion_entry_function = NULL;
+char *(*rl_completion_word_break_hook)(void) = NULL;
CPPFunction *rl_attempted_completion_function = NULL;
Function *rl_pre_input_hook = NULL;
Function *rl_startup1_hook = NULL;
@@ -121,10 +119,6 @@ VFunction *rl_prep_term_function = (VFunction *)rl_prep_terminal;
VFunction *rl_deprep_term_function = (VFunction *)rl_deprep_terminal;
KEYMAP_ENTRY_ARRAY emacs_meta_keymap;
-#ifdef WIDECHAR
-static ct_buffer_t conv;
-#endif
-
/*
* The current prompt string.
*/
@@ -157,7 +151,7 @@ int rl_completion_append_character = ' ';
/* stuff below is used internally by libedit for readline emulation */
-static TYPE(History) *h = NULL;
+static History *h = NULL;
static EditLine *e = NULL;
static Function *map[256];
static jmp_buf topbuf;
@@ -181,7 +175,7 @@ static char *
_get_prompt(EditLine *el __attribute__((__unused__)))
{
rl_already_prompted = 1;
- return (rl_prompt);
+ return rl_prompt;
}
@@ -191,16 +185,16 @@ _get_prompt(EditLine *el __attribute__((__unused__)))
static HIST_ENTRY *
_move_history(int op)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
static HIST_ENTRY rl_he;
- if (FUNW(history)(h, &ev, op) != 0)
- return (HIST_ENTRY *) NULL;
+ if (history(h, &ev, op) != 0)
+ return NULL;
- rl_he.line = ct_encode_string(ev.str, &conv);
+ rl_he.line = ev.str;
rl_he.data = NULL;
- return (&rl_he);
+ return &rl_he;
}
@@ -209,18 +203,27 @@ _move_history(int op)
*/
static int
/*ARGSUSED*/
-_getc_function(EditLine *el, char *c)
+_getc_function(EditLine *el __attribute__((__unused__)), char *c)
{
int i;
i = (*rl_getc_function)(NULL);
if (i == -1)
return 0;
- *c = i;
+ *c = (char)i;
return 1;
}
-static const char _dothistory[] = "/.history";
+static void
+_resize_fun(EditLine *el, void *a)
+{
+ const LineInfo *li;
+ char **ap = a;
+
+ li = el_line(el);
+ /* a cheesy way to get rid of const cast. */
+ *ap = memchr(li->buffer, *li->buffer, (size_t)1);
+}
static const char *
_default_history_file(void)
@@ -232,8 +235,7 @@ _default_history_file(void)
return path;
if ((p = getpwuid(getuid())) == NULL)
return NULL;
- strlcpy(path, p->pw_dir, PATH_MAX);
- strlcat(path, _dothistory, PATH_MAX);
+ (void)snprintf(path, sizeof(path), "%s/.history", p->pw_dir);
return path;
}
@@ -254,7 +256,7 @@ rl_set_prompt(const char *prompt)
if (rl_prompt != NULL && strcmp(rl_prompt, prompt) == 0)
return 0;
if (rl_prompt)
- free(rl_prompt);
+ el_free(rl_prompt);
rl_prompt = strdup(prompt);
if (rl_prompt == NULL)
return -1;
@@ -271,15 +273,14 @@ rl_set_prompt(const char *prompt)
int
rl_initialize(void)
{
- TYPE(HistEvent) ev;
- const LineInfo *li;
+ HistEvent ev;
int editmode = 1;
struct termios t;
if (e != NULL)
el_end(e);
if (h != NULL)
- FUN(history,end)(h);
+ history_end(h);
if (!rl_instream)
rl_instream = stdin;
@@ -295,24 +296,27 @@ rl_initialize(void)
e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr);
if (!editmode)
- FUN(el,set)(e, EL_EDITMODE, 0);
+ el_set(e, EL_EDITMODE, 0);
- h = FUN(history,init)();
+ h = history_init();
if (!e || !h)
- return (-1);
+ return -1;
- FUNW(history)(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */
+ history(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */
history_length = 0;
max_input_history = INT_MAX;
el_set(e, EL_HIST, history, h);
+ /* Setup resize function */
+ el_set(e, EL_RESIZE, _resize_fun, &rl_line_buffer);
+
/* setup getc function if valid */
if (rl_getc_function)
el_set(e, EL_GETCFN, _getc_function);
/* for proper prompt printing in readline() */
if (rl_set_prompt("") == -1) {
- FUN(history,end)(h);
+ history_end(h);
el_end(e);
return -1;
}
@@ -351,15 +355,13 @@ rl_initialize(void)
* Unfortunately, some applications really do use rl_point
* and rl_line_buffer directly.
*/
- li = el_line(e);
- /* a cheesy way to get rid of const cast. */
- rl_line_buffer = memchr(li->buffer, *li->buffer, 1);
+ _resize_fun(e, &rl_line_buffer);
_rl_update_pos();
if (rl_startup_hook)
(*rl_startup_hook)(NULL, 0);
- return (0);
+ return 0;
}
@@ -370,7 +372,7 @@ rl_initialize(void)
char *
readline(const char *p)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
const char * volatile prompt = p;
int count;
const char *ret;
@@ -418,7 +420,7 @@ readline(const char *p)
} else
buf = NULL;
- FUNW(history)(h, &ev, H_GETSIZE);
+ history(h, &ev, H_GETSIZE);
history_length = ev.num;
return buf;
@@ -468,7 +470,7 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
} else
s++;
}
- r = result = malloc(len + 1);
+ r = result = el_malloc((len + 1) * sizeof(*r));
if (result == NULL)
return NULL;
s = str;
@@ -479,13 +481,13 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
s += what_len;
if (!globally) {
(void)strcpy(r, s);
- return(result);
+ return result;
}
} else
*r++ = *s++;
}
*r = '\0';
- return(result);
+ return result;
}
static char *last_search_pat; /* last !?pat[?] search pattern */
@@ -498,18 +500,18 @@ get_history_event(const char *cmd, int *cindex, int qchar)
size_t len;
char *pat;
const char *rptr;
- TYPE(HistEvent) ev;
+ HistEvent ev;
idx = *cindex;
if (cmd[idx++] != history_expansion_char)
- return(NULL);
+ return NULL;
/* find out which event to take */
if (cmd[idx] == history_expansion_char || cmd[idx] == '\0') {
- if (FUNW(history)(h, &ev, H_FIRST) != 0)
- return(NULL);
+ if (history(h, &ev, H_FIRST) != 0)
+ return NULL;
*cindex = cmd[idx]? (idx + 1):idx;
- return ct_encode_string(ev.str, &conv);
+ return ev.str;
}
sign = 0;
if (cmd[idx] == '-') {
@@ -529,10 +531,10 @@ get_history_event(const char *cmd, int *cindex, int qchar)
num = history_length - num + 1;
if (!(rl_he = history_get(num)))
- return(NULL);
+ return NULL;
*cindex = idx;
- return(rl_he->line);
+ return rl_he->line;
}
sub = 0;
if (cmd[idx] == '?') {
@@ -550,31 +552,31 @@ get_history_event(const char *cmd, int *cindex, int qchar)
break;
idx++;
}
- len = idx - begin;
+ len = (size_t)idx - (size_t)begin;
if (sub && cmd[idx] == '?')
idx++;
if (sub && len == 0 && last_search_pat && *last_search_pat)
pat = last_search_pat;
else if (len == 0)
- return(NULL);
+ return NULL;
else {
- if ((pat = malloc(len + 1)) == NULL)
+ if ((pat = el_malloc((len + 1) * sizeof(*pat))) == NULL)
return NULL;
(void)strncpy(pat, cmd + begin, len);
pat[len] = '\0';
}
- if (FUNW(history)(h, &ev, H_CURR) != 0) {
+ if (history(h, &ev, H_CURR) != 0) {
if (pat != last_search_pat)
- free(pat);
- return (NULL);
+ el_free(pat);
+ return NULL;
}
num = ev.num;
if (sub) {
if (pat != last_search_pat) {
if (last_search_pat)
- free(last_search_pat);
+ el_free(last_search_pat);
last_search_pat = pat;
}
ret = history_search(pat, -1);
@@ -583,29 +585,29 @@ get_history_event(const char *cmd, int *cindex, int qchar)
if (ret == -1) {
/* restore to end of list on failed search */
- FUNW(history)(h, &ev, H_FIRST);
+ history(h, &ev, H_FIRST);
(void)fprintf(rl_outstream, "%s: Event not found\n", pat);
if (pat != last_search_pat)
- free(pat);
- return(NULL);
+ el_free(pat);
+ return NULL;
}
if (sub && len) {
if (last_search_match && last_search_match != pat)
- free(last_search_match);
+ el_free(last_search_match);
last_search_match = pat;
}
if (pat != last_search_pat)
- free(pat);
+ el_free(pat);
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return(NULL);
+ if (history(h, &ev, H_CURR) != 0)
+ return NULL;
*cindex = idx;
- rptr = ct_encode_string(ev.str, &conv);
+ rptr = ev.str;
/* roll back to original position */
- (void)FUNW(history)(h, &ev, H_SET, num);
+ (void)history(h, &ev, H_SET, num);
return rptr;
}
@@ -652,7 +654,8 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
} else {
if (command[offs + 1] == '#') {
/* use command so far */
- if ((aptr = malloc(offs + 1)) == NULL)
+ if ((aptr = el_malloc((offs + 1) * sizeof(*aptr)))
+ == NULL)
return -1;
(void)strncpy(aptr, command, offs);
aptr[offs] = '\0';
@@ -663,19 +666,19 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
qchar = (offs > 0 && command[offs - 1] == '"')? '"':0;
ptr = get_history_event(command + offs, &idx, qchar);
}
- has_mods = command[offs + idx] == ':';
+ has_mods = command[offs + (size_t)idx] == ':';
}
if (ptr == NULL && aptr == NULL)
- return(-1);
+ return -1;
if (!has_mods) {
*result = strdup(aptr ? aptr : ptr);
if (aptr)
- free(aptr);
+ el_free(aptr);
if (*result == NULL)
return -1;
- return(1);
+ return 1;
}
cmd = command + offs + idx + 1;
@@ -720,18 +723,18 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
(void)fprintf(rl_outstream, "%s: Bad word specifier",
command + offs + idx);
if (aptr)
- free(aptr);
- return(-1);
+ el_free(aptr);
+ return -1;
}
} else
tmp = strdup(aptr? aptr:ptr);
if (aptr)
- free(aptr);
+ el_free(aptr);
if (*cmd == '\0' || ((size_t)(cmd - (command + offs)) >= cmdlen)) {
*result = tmp;
- return(1);
+ return 1;
}
for (; *cmd; cmd++) {
@@ -743,7 +746,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
} else if (*cmd == 't') { /* remove leading path */
if ((aptr = strrchr(tmp, '/')) != NULL) {
aptr = strdup(aptr + 1);
- free(tmp);
+ el_free(tmp);
tmp = aptr;
}
} else if (*cmd == 'r') { /* remove trailing suffix */
@@ -752,7 +755,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
} else if (*cmd == 'e') { /* remove all but suffix */
if ((aptr = strrchr(tmp, '.')) != NULL) {
aptr = strdup(aptr);
- free(tmp);
+ el_free(tmp);
tmp = aptr;
}
} else if (*cmd == 'p') /* print only */
@@ -769,10 +772,10 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
else if (*cmd == 's') {
delim = *(++cmd), cmd++;
size = 16;
- what = realloc(from, size);
+ what = el_realloc(from, size * sizeof(*what));
if (what == NULL) {
- free(from);
- free(tmp);
+ el_free(from);
+ el_free(tmp);
return 0;
}
len = 0;
@@ -781,11 +784,12 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
cmd++;
if (len >= size) {
char *nwhat;
- nwhat = realloc(what,
- (size <<= 1));
+ nwhat = el_realloc(what,
+ (size <<= 1) *
+ sizeof(*nwhat));
if (nwhat == NULL) {
- free(what);
- free(tmp);
+ el_free(what);
+ el_free(tmp);
return 0;
}
what = nwhat;
@@ -795,17 +799,17 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
what[len] = '\0';
from = what;
if (*what == '\0') {
- free(what);
+ el_free(what);
if (search) {
from = strdup(search);
if (from == NULL) {
- free(tmp);
+ el_free(tmp);
return 0;
}
} else {
from = NULL;
- free(tmp);
- return (-1);
+ el_free(tmp);
+ return -1;
}
}
cmd++; /* shift after delim */
@@ -813,10 +817,10 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
continue;
size = 16;
- with = realloc(to, size);
+ with = el_realloc(to, size * sizeof(*with));
if (with == NULL) {
- free(to);
- free(tmp);
+ el_free(to);
+ el_free(tmp);
return -1;
}
len = 0;
@@ -825,10 +829,11 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
if (len + from_len + 1 >= size) {
char *nwith;
size += from_len + 1;
- nwith = realloc(with, size);
+ nwith = el_realloc(with,
+ size * sizeof(*nwith));
if (nwith == NULL) {
- free(with);
- free(tmp);
+ el_free(with);
+ el_free(tmp);
return -1;
}
with = nwith;
@@ -851,14 +856,14 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
aptr = _rl_compat_sub(tmp, from, to, g_on);
if (aptr) {
- free(tmp);
+ el_free(tmp);
tmp = aptr;
}
g_on = 0;
}
}
*result = tmp;
- return (p_on? 2:1);
+ return p_on? 2:1;
}
@@ -877,13 +882,13 @@ history_expand(char *str, char **output)
if (history_expansion_char == 0) {
*output = strdup(str);
- return(0);
+ return 0;
}
*output = NULL;
if (str[0] == history_subst_char) {
/* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */
- *output = malloc(strlen(str) + 4 + 1);
+ *output = el_malloc((strlen(str) + 4 + 1) * sizeof(**output));
if (*output == NULL)
return 0;
(*output)[0] = (*output)[1] = history_expansion_char;
@@ -900,11 +905,12 @@ history_expand(char *str, char **output)
#define ADD_STRING(what, len, fr) \
{ \
if (idx + len + 1 > size) { \
- char *nresult = realloc(result, (size += len + 1));\
+ char *nresult = el_realloc(result, \
+ (size += len + 1) * sizeof(*nresult)); \
if (nresult == NULL) { \
- free(*output); \
+ el_free(*output); \
if (/*CONSTCOND*/fr) \
- free(tmp); \
+ el_free(tmp); \
return 0; \
} \
result = nresult; \
@@ -971,7 +977,7 @@ loop:
ADD_STRING(tmp, len, 1);
}
if (tmp) {
- free(tmp);
+ el_free(tmp);
tmp = NULL;
}
i = j;
@@ -988,10 +994,10 @@ loop:
ret = -1;
#endif
}
- free(*output);
+ el_free(*output);
*output = result;
- return (ret);
+ return ret;
}
/*
@@ -1026,14 +1032,14 @@ history_arg_extract(int start, int end, const char *str)
(size_t)end > max || start > end)
goto out;
- for (i = start, len = 0; i <= (size_t)end; i++)
+ for (i = (size_t)start, len = 0; i <= (size_t)end; i++)
len += strlen(arr[i]) + 1;
len++;
- result = malloc(len);
+ result = el_malloc(len * sizeof(*result));
if (result == NULL)
goto out;
- for (i = start, len = 0; i <= (size_t)end; i++) {
+ for (i = (size_t)start, len = 0; i <= (size_t)end; i++) {
(void)strcpy(result + len, arr[i]);
len += strlen(arr[i]);
if (i < (size_t)end)
@@ -1043,8 +1049,8 @@ history_arg_extract(int start, int end, const char *str)
out:
for (i = 0; arr[i]; i++)
- free(arr[i]);
- free(arr);
+ el_free(arr[i]);
+ el_free(arr);
return result;
}
@@ -1083,19 +1089,19 @@ history_tokenize(const char *str)
if (idx + 2 >= size) {
char **nresult;
size <<= 1;
- nresult = realloc(result, size * sizeof(char *));
+ nresult = el_realloc(result, (size_t)size * sizeof(*nresult));
if (nresult == NULL) {
- free(result);
+ el_free(result);
return NULL;
}
result = nresult;
}
- len = i - start;
- temp = malloc(len + 1);
+ len = (size_t)i - (size_t)start;
+ temp = el_malloc((size_t)(len + 1) * sizeof(*temp));
if (temp == NULL) {
for (i = 0; i < idx; i++)
- free(result[i]);
- free(result);
+ el_free(result[i]);
+ el_free(result);
return NULL;
}
(void)strncpy(temp, &str[start], len);
@@ -1105,7 +1111,7 @@ history_tokenize(const char *str)
if (str[i])
i++;
}
- return (result);
+ return result;
}
@@ -1115,12 +1121,12 @@ history_tokenize(const char *str)
void
stifle_history(int max)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
- if (FUNW(history)(h, &ev, H_SETSIZE, max) == 0)
+ if (history(h, &ev, H_SETSIZE, max) == 0)
max_input_history = max;
}
@@ -1131,13 +1137,13 @@ stifle_history(int max)
int
unstifle_history(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int omax;
- FUNW(history)(h, &ev, H_SETSIZE, INT_MAX);
+ history(h, &ev, H_SETSIZE, INT_MAX);
omax = max_input_history;
max_input_history = INT_MAX;
- return (omax); /* some value _must_ be returned */
+ return omax; /* some value _must_ be returned */
}
@@ -1146,7 +1152,7 @@ history_is_stifled(void)
{
/* cannot return true answer */
- return (max_input_history != INT_MAX);
+ return max_input_history != INT_MAX;
}
static const char _history_tmp_template[] = "/tmp/.historyXXXXXX";
@@ -1181,7 +1187,7 @@ history_truncate_file (const char *filename, int nlines)
}
for(;;) {
- if (fread(buf, sizeof(buf), 1, fp) != 1) {
+ if (fread(buf, sizeof(buf), (size_t)1, fp) != 1) {
if (ferror(fp)) {
ret = errno;
break;
@@ -1191,7 +1197,7 @@ history_truncate_file (const char *filename, int nlines)
ret = errno;
break;
}
- left = fread(buf, 1, sizeof(buf), fp);
+ left = (ssize_t)fread(buf, (size_t)1, sizeof(buf), fp);
if (ferror(fp)) {
ret = errno;
break;
@@ -1199,14 +1205,15 @@ history_truncate_file (const char *filename, int nlines)
if (left == 0) {
count--;
left = sizeof(buf);
- } else if (fwrite(buf, (size_t)left, 1, tp) != 1) {
+ } else if (fwrite(buf, (size_t)left, (size_t)1, tp)
+ != 1) {
ret = errno;
break;
}
fflush(tp);
break;
}
- if (fwrite(buf, sizeof(buf), 1, tp) != 1) {
+ if (fwrite(buf, sizeof(buf), (size_t)1, tp) != 1) {
ret = errno;
break;
}
@@ -1236,7 +1243,7 @@ history_truncate_file (const char *filename, int nlines)
ret = errno;
break;
}
- if (fread(buf, sizeof(buf), 1, tp) != 1) {
+ if (fread(buf, sizeof(buf), (size_t)1, tp) != 1) {
if (ferror(tp)) {
ret = errno;
break;
@@ -1250,7 +1257,7 @@ history_truncate_file (const char *filename, int nlines)
if (ret || nlines > 0)
goto out3;
- if (fseeko(fp, 0, SEEK_SET) == (off_t)-1) {
+ if (fseeko(fp, (off_t)0, SEEK_SET) == (off_t)-1) {
ret = errno;
goto out3;
}
@@ -1262,12 +1269,12 @@ history_truncate_file (const char *filename, int nlines)
}
for(;;) {
- if ((left = fread(buf, 1, sizeof(buf), tp)) == 0) {
+ if ((left = (ssize_t)fread(buf, (size_t)1, sizeof(buf), tp)) == 0) {
if (ferror(fp))
ret = errno;
break;
}
- if (fwrite(buf, (size_t)left, 1, fp) != 1) {
+ if (fwrite(buf, (size_t)left, (size_t)1, fp) != 1) {
ret = errno;
break;
}
@@ -1292,14 +1299,14 @@ out1:
int
read_history(const char *filename)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
if (filename == NULL && (filename = _default_history_file()) == NULL)
return errno;
- return (FUNW(history)(h, &ev, H_LOAD, filename) == -1 ?
- (errno ? errno : EINVAL) : 0);
+ return history(h, &ev, H_LOAD, filename) == -1 ?
+ (errno ? errno : EINVAL) : 0;
}
@@ -1309,14 +1316,14 @@ read_history(const char *filename)
int
write_history(const char *filename)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
if (filename == NULL && (filename = _default_history_file()) == NULL)
return errno;
- return (FUNW(history)(h, &ev, H_SAVE, filename) == -1 ?
- (errno ? errno : EINVAL) : 0);
+ return history(h, &ev, H_SAVE, filename) == -1 ?
+ (errno ? errno : EINVAL) : 0;
}
@@ -1329,31 +1336,31 @@ HIST_ENTRY *
history_get(int num)
{
static HIST_ENTRY she;
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num;
if (h == NULL || e == NULL)
rl_initialize();
/* save current position */
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (NULL);
+ if (history(h, &ev, H_CURR) != 0)
+ return NULL;
curr_num = ev.num;
/* start from the oldest */
- if (FUNW(history)(h, &ev, H_LAST) != 0)
- return (NULL); /* error */
+ if (history(h, &ev, H_LAST) != 0)
+ return NULL; /* error */
/* look forwards for event matching specified offset */
- if (FUNW(history)(h, &ev, H_NEXT_EVDATA, num, &she.data))
- return (NULL);
+ if (history(h, &ev, H_NEXT_EVDATA, num, &she.data))
+ return NULL;
- she.line = ct_encode_string(ev.str, &conv);
+ she.line = ev.str;
/* restore pointer to where it was */
- (void)FUNW(history)(h, &ev, H_SET, curr_num);
+ (void)history(h, &ev, H_SET, curr_num);
- return (&she);
+ return &she;
}
@@ -1363,19 +1370,19 @@ history_get(int num)
int
add_history(const char *line)
{
- TYPE(HistEvent) ev;
- const Char *wline;
+ HistEvent ev;
+
+ if (line == NULL)
+ return 0;
if (h == NULL || e == NULL)
rl_initialize();
- wline = ct_decode_string(line, &conv);
-
- (void)FUNW(history)(h, &ev, H_ENTER, wline);
- if (FUNW(history)(h, &ev, H_GETSIZE) == 0)
+ (void)history(h, &ev, H_ENTER, line);
+ if (history(h, &ev, H_GETSIZE) == 0)
history_length = ev.num;
- return (!(history_length > 0)); /* return 0 if all is okay */
+ return !(history_length > 0); /* return 0 if all is okay */
}
@@ -1386,21 +1393,21 @@ HIST_ENTRY *
remove_history(int num)
{
HIST_ENTRY *he;
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
- if ((he = malloc(sizeof(*he))) == NULL)
+ if ((he = el_malloc(sizeof(*he))) == NULL)
return NULL;
- if (FUNW(history)(h, &ev, H_DELDATA, num, &he->data) != 0) {
- free(he);
+ if (history(h, &ev, H_DELDATA, num, &he->data) != 0) {
+ el_free(he);
return NULL;
}
- he->line = ct_encode_string(ev.str, &conv);
- if (FUNW(history)(h, &ev, H_GETSIZE) == 0)
+ he->line = ev.str;
+ if (history(h, &ev, H_GETSIZE) == 0)
history_length = ev.num;
return he;
@@ -1414,42 +1421,42 @@ HIST_ENTRY *
replace_history_entry(int num, const char *line, histdata_t data)
{
HIST_ENTRY *he;
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num;
if (h == NULL || e == NULL)
rl_initialize();
/* save current position */
- if (FUNW(history)(h, &ev, H_CURR) != 0)
+ if (history(h, &ev, H_CURR) != 0)
return NULL;
curr_num = ev.num;
/* start from the oldest */
- if (FUNW(history)(h, &ev, H_LAST) != 0)
+ if (history(h, &ev, H_LAST) != 0)
return NULL; /* error */
- if ((he = malloc(sizeof(*he))) == NULL)
+ if ((he = el_malloc(sizeof(*he))) == NULL)
return NULL;
/* look forwards for event matching specified offset */
- if (FUNW(history)(h, &ev, H_NEXT_EVDATA, num, &he->data))
+ if (history(h, &ev, H_NEXT_EVDATA, num, &he->data))
goto out;
- he->line = strdup(ct_encode_string(ev.str, &e->el_scratch));
+ he->line = strdup(ev.str);
if (he->line == NULL)
goto out;
- if (FUNW(history)(h, &ev, H_REPLACE, line, data))
+ if (history(h, &ev, H_REPLACE, line, data))
goto out;
/* restore pointer to where it was */
- if (FUNW(history)(h, &ev, H_SET, curr_num))
+ if (history(h, &ev, H_SET, curr_num))
goto out;
return he;
out:
- free(he);
+ el_free(he);
return NULL;
}
@@ -1459,9 +1466,9 @@ out:
void
clear_history(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
- (void)FUNW(history)(h, &ev, H_CLEAR);
+ (void)history(h, &ev, H_CLEAR);
history_length = 0;
}
@@ -1472,19 +1479,19 @@ clear_history(void)
int
where_history(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num, off;
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (0);
+ if (history(h, &ev, H_CURR) != 0)
+ return 0;
curr_num = ev.num;
- (void)FUNW(history)(h, &ev, H_FIRST);
+ (void)history(h, &ev, H_FIRST);
off = 1;
- while (ev.num != curr_num && FUNW(history)(h, &ev, H_NEXT) == 0)
+ while (ev.num != curr_num && history(h, &ev, H_NEXT) == 0)
off++;
- return (off);
+ return off;
}
@@ -1495,7 +1502,7 @@ HIST_ENTRY *
current_history(void)
{
- return (_move_history(H_CURR));
+ return _move_history(H_CURR);
}
@@ -1505,24 +1512,24 @@ current_history(void)
int
history_total_bytes(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num;
size_t size;
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (-1);
+ if (history(h, &ev, H_CURR) != 0)
+ return -1;
curr_num = ev.num;
- (void)FUNW(history)(h, &ev, H_FIRST);
+ (void)history(h, &ev, H_FIRST);
size = 0;
do
- size += Strlen(ev.str) * sizeof(*ev.str);
- while (FUNW(history)(h, &ev, H_NEXT) == 0);
+ size += strlen(ev.str) * sizeof(*ev.str);
+ while (history(h, &ev, H_NEXT) == 0);
/* get to the same position as before */
- FUNW(history)(h, &ev, H_PREV_EVENT, curr_num);
+ history(h, &ev, H_PREV_EVENT, curr_num);
- return (int)(size);
+ return (int)size;
}
@@ -1532,24 +1539,24 @@ history_total_bytes(void)
int
history_set_pos(int pos)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num;
if (pos >= history_length || pos < 0)
- return (-1);
+ return -1;
- (void)FUNW(history)(h, &ev, H_CURR);
+ (void)history(h, &ev, H_CURR);
curr_num = ev.num;
/*
* use H_DELDATA to set to nth history (without delete) by passing
* (void **)-1
*/
- if (FUNW(history)(h, &ev, H_DELDATA, pos, (void **)-1)) {
- (void)FUNW(history)(h, &ev, H_SET, curr_num);
- return(-1);
+ if (history(h, &ev, H_DELDATA, pos, (void **)-1)) {
+ (void)history(h, &ev, H_SET, curr_num);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -1560,7 +1567,7 @@ HIST_ENTRY *
previous_history(void)
{
- return (_move_history(H_PREV));
+ return _move_history(H_PREV);
}
@@ -1571,7 +1578,7 @@ HIST_ENTRY *
next_history(void)
{
- return (_move_history(H_NEXT));
+ return _move_history(H_NEXT);
}
@@ -1581,24 +1588,22 @@ next_history(void)
int
history_search(const char *str, int direction)
{
- TYPE(HistEvent) ev;
- const Char *strp;
- const Char *wstr;
+ HistEvent ev;
+ const char *strp;
int curr_num;
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (-1);
+ if (history(h, &ev, H_CURR) != 0)
+ return -1;
curr_num = ev.num;
- wstr = ct_decode_string(str, &conv);
for (;;) {
- if ((strp = Strstr(ev.str, wstr)) != NULL)
- return (int) (strp - ev.str);
- if (FUNW(history)(h, &ev, direction < 0 ? H_NEXT:H_PREV) != 0)
+ if ((strp = strstr(ev.str, str)) != NULL)
+ return (int)(strp - ev.str);
+ if (history(h, &ev, direction < 0 ? H_NEXT:H_PREV) != 0)
break;
}
- (void)FUNW(history)(h, &ev, H_SET, curr_num);
- return (-1);
+ (void)history(h, &ev, H_SET, curr_num);
+ return -1;
}
@@ -1608,9 +1613,9 @@ history_search(const char *str, int direction)
int
history_search_prefix(const char *str, int direction)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
- return (FUNW(history)(h, &ev, direction < 0 ?
+ return (history(h, &ev, direction < 0 ?
H_PREV_STR : H_NEXT_STR, str));
}
@@ -1624,33 +1629,31 @@ int
history_search_pos(const char *str,
int direction __attribute__((__unused__)), int pos)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int curr_num, off;
- const Char *wstr;
off = (pos > 0) ? pos : -pos;
pos = (pos > 0) ? 1 : -1;
- if (FUNW(history)(h, &ev, H_CURR) != 0)
- return (-1);
+ if (history(h, &ev, H_CURR) != 0)
+ return -1;
curr_num = ev.num;
- if (history_set_pos(off) != 0 || FUNW(history)(h, &ev, H_CURR) != 0)
- return (-1);
+ if (history_set_pos(off) != 0 || history(h, &ev, H_CURR) != 0)
+ return -1;
- wstr = ct_decode_string(str, &conv);
for (;;) {
- if (Strstr(ev.str, wstr))
- return (off);
- if (FUNW(history)(h, &ev, (pos < 0) ? H_PREV : H_NEXT) != 0)
+ if (strstr(ev.str, str))
+ return off;
+ if (history(h, &ev, (pos < 0) ? H_PREV : H_NEXT) != 0)
break;
}
/* set "current" pointer back to previous state */
- (void)FUNW(history)(h, &ev,
+ (void)history(h, &ev,
pos < 0 ? H_NEXT_EVENT : H_PREV_EVENT, curr_num);
- return (-1);
+ return -1;
}
@@ -1673,17 +1676,20 @@ filename_completion_function(const char *name, int state)
* a completion generator for usernames; returns _first_ username
* which starts with supplied text
* text contains a partial username preceded by random character
- * (usually '~'); state is ignored
+ * (usually '~'); state resets search from start (??? should we do that anyway)
* it's callers responsibility to free returned value
*/
char *
username_completion_function(const char *text, int state)
{
- struct passwd *pwd, pwres;
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ struct passwd pwres;
char pwbuf[1024];
+#endif
+ struct passwd *pass = NULL;
if (text[0] == '\0')
- return (NULL);
+ return NULL;
if (*text == '~')
text++;
@@ -1691,15 +1697,21 @@ username_completion_function(const char *text, int state)
if (state == 0)
setpwent();
- while (getpwent_r(&pwres, pwbuf, sizeof(pwbuf), &pwd) == 0
- && pwd != NULL && text[0] == pwd->pw_name[0]
- && strcmp(text, pwd->pw_name) == 0);
+ while (
+#if defined(HAVE_GETPW_R_POSIX) || defined(HAVE_GETPW_R_DRAFT)
+ getpwent_r(&pwres, pwbuf, sizeof(pwbuf), &pass) == 0 && pass != NULL
+#else
+ (pass = getpwent()) != NULL
+#endif
+ && text[0] == pass->pw_name[0]
+ && strcmp(text, pass->pw_name) == 0)
+ continue;
- if (pwd == NULL) {
+ if (pass == NULL) {
endpwent();
return NULL;
}
- return strdup(pwd->pw_name);
+ return strdup(pass->pw_name);
}
@@ -1732,7 +1744,7 @@ _rl_completion_append_character_function(const char *dummy
__attribute__((__unused__)))
{
static char buf[2];
- buf[0] = rl_completion_append_character;
+ buf[0] = (char)rl_completion_append_character;
buf[1] = '\0';
return buf;
}
@@ -1748,6 +1760,7 @@ rl_complete(int ignore __attribute__((__unused__)), int invoking_key)
#ifdef WIDECHAR
static ct_buffer_t wbreak_conv, sprefix_conv;
#endif
+ char *breakchars;
if (h == NULL || e == NULL)
rl_initialize();
@@ -1757,19 +1770,26 @@ rl_complete(int ignore __attribute__((__unused__)), int invoking_key)
arr[0] = (char)invoking_key;
arr[1] = '\0';
el_insertstr(e, arr);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
+ if (rl_completion_word_break_hook != NULL)
+ breakchars = (*rl_completion_word_break_hook)();
+ else
+ breakchars = rl_basic_word_break_characters;
+
/* Just look at how many global variables modify this operation! */
return fn_complete(e,
(CPFunction *)rl_completion_entry_function,
rl_attempted_completion_function,
ct_decode_string(rl_basic_word_break_characters, &wbreak_conv),
- ct_decode_string(rl_special_prefixes, &sprefix_conv),
+ ct_decode_string(breakchars, &sprefix_conv),
_rl_completion_append_character_function,
(size_t)rl_completion_query_items,
&rl_completion_type, &rl_attempted_completion_over,
&rl_point, &rl_end);
+
+
}
@@ -1800,7 +1820,7 @@ rl_bind_key(int c, rl_command_func_t *func)
e->el_map.key[c] = ED_INSERT;
retval = 0;
}
- return (retval);
+ return retval;
}
@@ -1816,7 +1836,7 @@ rl_read_key(void)
if (e == NULL || h == NULL)
rl_initialize();
- return (el_getc(e, fooarr));
+ return el_getc(e, fooarr);
}
@@ -1846,32 +1866,33 @@ rl_insert(int count, int c)
rl_initialize();
/* XXX - int -> char conversion can lose on multichars */
- arr[0] = c;
+ arr[0] = (char)c;
arr[1] = '\0';
for (; count > 0; count--)
el_push(e, arr);
- return (0);
+ return 0;
}
int
rl_insert_text(const char *text)
{
if (!text || *text == 0)
- return (0);
+ return 0;
if (h == NULL || e == NULL)
rl_initialize();
if (el_insertstr(e, text) < 0)
- return (0);
+ return 0;
return (int)strlen(text);
}
/*ARGSUSED*/
int
-rl_newline(int count, int c)
+rl_newline(int count __attribute__((__unused__)),
+ int c __attribute__((__unused__)))
{
/*
* Readline-4.0 appears to ignore the args.
@@ -1881,7 +1902,7 @@ rl_newline(int count, int c)
/*ARGSUSED*/
static unsigned char
-rl_bind_wrapper(EditLine *el, unsigned char c)
+rl_bind_wrapper(EditLine *el __attribute__((__unused__)), unsigned char c)
{
if (map[c] == NULL)
return CC_ERROR;
@@ -1911,7 +1932,7 @@ rl_add_defun(const char *name, Function *fun, int c)
}
void
-rl_callback_read_char()
+rl_callback_read_char(void)
{
int count = 0, done = 0;
const char *buf = el_gets(e, &count);
@@ -1958,7 +1979,7 @@ void
rl_redisplay(void)
{
char a[2];
- a[0] = e->el_tty.t_c[TS_IO][C_REPRINT];
+ a[0] = (char)e->el_tty.t_c[TS_IO][C_REPRINT];
a[1] = '\0';
el_push(e, a);
}
@@ -1967,7 +1988,7 @@ int
rl_get_previous_history(int count, int key)
{
char a[2];
- a[0] = key;
+ a[0] = (char)key;
a[1] = '\0';
while (count--)
el_push(e, a);
@@ -1976,7 +1997,7 @@ rl_get_previous_history(int count, int key)
void
/*ARGSUSED*/
-rl_prep_terminal(int meta_flag)
+rl_prep_terminal(int meta_flag __attribute__((__unused__)))
{
el_set(e, EL_PREP_TERM, 1);
}
@@ -1990,7 +2011,7 @@ rl_deprep_terminal(void)
int
rl_read_init_file(const char *s)
{
- return(el_source(e, s));
+ return el_source(e, s);
}
int
@@ -2004,7 +2025,7 @@ rl_parse_and_bind(const char *line)
tok_str(tok, line, &argc, &argv);
argc = el_parse(e, argc, argv);
tok_end(tok);
- return (argc ? 1 : 0);
+ return argc ? 1 : 0;
}
int
@@ -2014,7 +2035,7 @@ rl_variable_bind(const char *var, const char *value)
* The proper return value is undocument, but this is what the
* readline source seems to do.
*/
- return ((el_set(e, EL_BIND, "", var, value) == -1) ? 1 : 0);
+ return el_set(e, EL_BIND, "", var, value) == -1 ? 1 : 0;
}
void
@@ -2022,7 +2043,7 @@ rl_stuff_char(int c)
{
char buf[2];
- buf[0] = c;
+ buf[0] = (char)c;
buf[1] = '\0';
el_insertstr(e, buf);
}
@@ -2040,23 +2061,23 @@ _rl_event_read_char(EditLine *el, char *cp)
#if defined(FIONREAD)
if (ioctl(el->el_infd, FIONREAD, &n) < 0)
- return(-1);
+ return -1;
if (n)
- num_read = read(el->el_infd, cp, 1);
+ num_read = read(el->el_infd, cp, (size_t)1);
else
num_read = 0;
#elif defined(F_SETFL) && defined(O_NDELAY)
if ((n = fcntl(el->el_infd, F_GETFL, 0)) < 0)
- return(-1);
+ return -1;
if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) < 0)
- return(-1);
+ return -1;
num_read = read(el->el_infd, cp, 1);
if (fcntl(el->el_infd, F_SETFL, n))
- return(-1);
+ return -1;
#else
/* not non-blocking, but what you gonna do? */
num_read = read(el->el_infd, cp, 1);
- return(-1);
+ return -1;
#endif
if (num_read < 0 && errno == EAGAIN)
@@ -2106,7 +2127,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
len = 1;
max = 10;
- if ((list = malloc(max * sizeof(*list))) == NULL)
+ if ((list = el_malloc(max * sizeof(*list))) == NULL)
return NULL;
while ((match = (*fun)(str, (int)(len - 1))) != NULL) {
@@ -2114,7 +2135,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
if (len == max) {
char **nl;
max += 10;
- if ((nl = realloc(list, max * sizeof(*nl))) == NULL)
+ if ((nl = el_realloc(list, max * sizeof(*nl))) == NULL)
goto out;
list = nl;
}
@@ -2141,7 +2162,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
if ((list[0] = strdup(str)) == NULL)
goto out;
} else {
- if ((list[0] = malloc(min + 1)) == NULL)
+ if ((list[0] = el_malloc((min + 1) * sizeof(*list[0]))) == NULL)
goto out;
(void)memcpy(list[0], list[1], min);
list[0][min] = '\0';
@@ -2149,7 +2170,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun)
return list;
out:
- free(list);
+ el_free(list);
return NULL;
}
@@ -2184,15 +2205,16 @@ history_get_history_state(void)
{
HISTORY_STATE *hs;
- if ((hs = malloc(sizeof(HISTORY_STATE))) == NULL)
- return (NULL);
+ if ((hs = el_malloc(sizeof(*hs))) == NULL)
+ return NULL;
hs->length = history_length;
- return (hs);
+ return hs;
}
int
/*ARGSUSED*/
-rl_kill_text(int from, int to)
+rl_kill_text(int from __attribute__((__unused__)),
+ int to __attribute__((__unused__)))
{
return 0;
}
@@ -2211,20 +2233,25 @@ rl_get_keymap(void)
void
/*ARGSUSED*/
-rl_set_keymap(Keymap k)
+rl_set_keymap(Keymap k __attribute__((__unused__)))
{
}
int
/*ARGSUSED*/
-rl_generic_bind(int type, const char * keyseq, const char * data, Keymap k)
+rl_generic_bind(int type __attribute__((__unused__)),
+ const char * keyseq __attribute__((__unused__)),
+ const char * data __attribute__((__unused__)),
+ Keymap k __attribute__((__unused__)))
{
return 0;
}
int
/*ARGSUSED*/
-rl_bind_key_in_map(int key, rl_command_func_t *fun, Keymap k)
+rl_bind_key_in_map(int key __attribute__((__unused__)),
+ rl_command_func_t *fun __attribute__((__unused__)),
+ Keymap k __attribute__((__unused__)))
{
return 0;
}
@@ -2240,3 +2267,8 @@ rl_on_new_line(void)
{
return 0;
}
+
+void
+rl_free_line_state(void)
+{
+}
diff --git a/readline/readline.h b/readline/readline.h
index db16ecc91101..0d1371345af0 100644
--- a/readline/readline.h
+++ b/readline/readline.h
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.h,v 1.31 2010/08/04 20:29:18 christos Exp $ */
+/* $NetBSD: readline.h,v 1.33 2012/05/15 17:30:04 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -109,6 +109,7 @@ extern char *rl_basic_word_break_characters;
extern char *rl_completer_word_break_characters;
extern char *rl_completer_quote_characters;
extern Function *rl_completion_entry_function;
+extern char *(*rl_completion_word_break_hook)(void);
extern CPPFunction *rl_attempted_completion_function;
extern int rl_attempted_completion_over;
extern int rl_completion_type;
@@ -151,7 +152,6 @@ int where_history(void);
HIST_ENTRY *current_history(void);
HIST_ENTRY *history_get(int);
HIST_ENTRY *remove_history(int);
-/*###152 [lint] syntax error 'histdata_t' [249]%%%*/
HIST_ENTRY *replace_history_entry(int, const char *, histdata_t);
int history_total_bytes(void);
int history_set_pos(int);
diff --git a/refresh.c b/refresh.c
index 7c128df0fba8..3e1176eced60 100644
--- a/refresh.c
+++ b/refresh.c
@@ -1,4 +1,4 @@
-/* $NetBSD: refresh.c,v 1.35 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: refresh.c,v 1.37 2011/07/29 23:44:45 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.35 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: refresh.c,v 1.37 2011/07/29 23:44:45 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -103,8 +103,8 @@ re_nextline(EditLine *el)
* We do this via pointer shuffling - it's safe in this case
* and we avoid memcpy().
*/
- if (el->el_refresh.r_cursor.v + 1 >= el->el_term.t_size.v) {
- int i, lins = el->el_term.t_size.v;
+ if (el->el_refresh.r_cursor.v + 1 >= el->el_terminal.t_size.v) {
+ int i, lins = el->el_terminal.t_size.v;
Char *firstline = el->el_vdisplay[0];
for(i = 1; i < lins; i++)
@@ -115,9 +115,9 @@ re_nextline(EditLine *el)
} else
el->el_refresh.r_cursor.v++;
- ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_term.t_size.v,
+ ELRE_ASSERT(el->el_refresh.r_cursor.v >= el->el_terminal.t_size.v,
(__F, "\r\nre_putc: overflow! r_cursor.v == %d > %d\r\n",
- el->el_refresh.r_cursor.v, el->el_term.t_size.v),
+ el->el_refresh.r_cursor.v, el->el_terminal.t_size.v),
abort());
}
@@ -166,7 +166,7 @@ re_putc(EditLine *el, Int c, int shift)
int i, w = Width(c);
ELRE_DEBUG(1, (__F, "printing %5x '%c'\r\n", c, c));
- while (shift && (el->el_refresh.r_cursor.h + w > el->el_term.t_size.h))
+ while (shift && (el->el_refresh.r_cursor.h + w > el->el_terminal.t_size.h))
re_putc(el, ' ', 1);
el->el_vdisplay[el->el_refresh.r_cursor.v]
@@ -181,9 +181,9 @@ re_putc(EditLine *el, Int c, int shift)
return;
el->el_refresh.r_cursor.h += w; /* advance to next place */
- if (el->el_refresh.r_cursor.h >= el->el_term.t_size.h) {
+ if (el->el_refresh.r_cursor.h >= el->el_terminal.t_size.h) {
/* assure end of line */
- el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_term.t_size.h]
+ el->el_vdisplay[el->el_refresh.r_cursor.v][el->el_terminal.t_size.h]
= '\0';
re_nextline(el);
}
@@ -235,7 +235,7 @@ re_refresh(EditLine *el)
/* draw the current input buffer */
#if notyet
- termsz = el->el_term.t_size.h * el->el_term.t_size.v;
+ termsz = el->el_terminal.t_size.h * el->el_terminal.t_size.v;
if (el->el_line.lastchar - el->el_line.buffer > termsz) {
/*
* If line is longer than terminal, process only part
@@ -244,8 +244,8 @@ re_refresh(EditLine *el)
size_t rem = (el->el_line.lastchar-el->el_line.buffer)%termsz;
st = el->el_line.lastchar - rem
- - (termsz - (((rem / el->el_term.t_size.v) - 1)
- * el->el_term.t_size.v));
+ - (termsz - (((rem / el->el_terminal.t_size.v) - 1)
+ * el->el_terminal.t_size.v));
} else
#endif
st = el->el_line.buffer;
@@ -258,7 +258,7 @@ re_refresh(EditLine *el)
cur.v = el->el_refresh.r_cursor.v;
/* handle being at a linebroken doublewidth char */
if (w > 1 && el->el_refresh.r_cursor.h + w >
- el->el_term.t_size.h) {
+ el->el_terminal.t_size.h) {
cur.h = 0;
cur.v++;
}
@@ -270,7 +270,7 @@ re_refresh(EditLine *el)
cur.h = el->el_refresh.r_cursor.h;
cur.v = el->el_refresh.r_cursor.v;
}
- rhdiff = el->el_term.t_size.h - el->el_refresh.r_cursor.h -
+ rhdiff = el->el_terminal.t_size.h - el->el_refresh.r_cursor.h -
el->el_rprompt.p_pos.h;
if (el->el_rprompt.p_pos.h && !el->el_rprompt.p_pos.v &&
!el->el_refresh.r_cursor.v && rhdiff > 1) {
@@ -293,7 +293,7 @@ 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_term.t_size.h, el->el_refresh.r_cursor.h,
+ 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])));
ELRE_DEBUG(1, (__F, "updating %d lines.\r\n", el->el_refresh.r_newcv));
@@ -309,7 +309,7 @@ re_refresh(EditLine *el)
* leftover stuff.
*/
re__copy_and_pad(el->el_display[i], el->el_vdisplay[i],
- (size_t) el->el_term.t_size.h);
+ (size_t) el->el_terminal.t_size.h);
}
ELRE_DEBUG(1, (__F,
"\r\nel->el_refresh.r_cursor.v=%d,el->el_refresh.r_oldcv=%d i=%d\r\n",
@@ -317,12 +317,12 @@ re_refresh(EditLine *el)
if (el->el_refresh.r_oldcv > el->el_refresh.r_newcv)
for (; i <= el->el_refresh.r_oldcv; i++) {
- term_move_to_line(el, i);
- term_move_to_char(el, 0);
+ terminal_move_to_line(el, i);
+ terminal_move_to_char(el, 0);
/* This Strlen should be safe even with MB_FILL_CHARs */
- term_clear_EOL(el, (int) Strlen(el->el_display[i]));
+ terminal_clear_EOL(el, (int) Strlen(el->el_display[i]));
#ifdef DEBUG_REFRESH
- term_overwrite(el, "C\b", (size_t)2);
+ terminal_overwrite(el, "C\b", (size_t)2);
#endif /* DEBUG_REFRESH */
el->el_display[i][0] = '\0';
}
@@ -332,8 +332,8 @@ re_refresh(EditLine *el)
"\r\ncursor.h = %d, cursor.v = %d, cur.h = %d, cur.v = %d\r\n",
el->el_refresh.r_cursor.h, el->el_refresh.r_cursor.v,
cur.h, cur.v));
- term_move_to_line(el, cur.v); /* go to where the cursor is */
- term_move_to_char(el, cur.h);
+ terminal_move_to_line(el, cur.v); /* go to where the cursor is */
+ terminal_move_to_char(el, cur.h);
}
@@ -344,10 +344,10 @@ protected void
re_goto_bottom(EditLine *el)
{
- term_move_to_line(el, el->el_refresh.r_oldcv);
- term__putc(el, '\n');
+ terminal_move_to_line(el, el->el_refresh.r_oldcv);
+ terminal__putc(el, '\n');
re_clear_display(el);
- term__flush(el);
+ terminal__flush(el);
}
@@ -470,7 +470,7 @@ re_clear_eol(EditLine *el, int fx, int sx, int diff)
diff = sx;
ELRE_DEBUG(1, (__F, "re_clear_eol %d\n", diff));
- term_clear_EOL(el, diff);
+ terminal_clear_EOL(el, diff);
}
/*****************************************************************
@@ -717,7 +717,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
* don't have to change the line, we don't move to it. el_cursor.h to
* first diff char
*/
- term_move_to_line(el, i);
+ terminal_move_to_line(el, i);
/*
* at this point we have something like this:
@@ -741,7 +741,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
* if we have a net insert on the first difference, AND inserting the
* net amount ((nsb-nfd) - (osb-ofd)) won't push the last useful
* character (which is ne if nls != ne, otherwise is nse) off the edge
- * of the screen (el->el_term.t_size.h) else we do the deletes first
+ * of the screen (el->el_terminal.t_size.h) else we do the deletes first
* so that we keep everything we need to.
*/
@@ -763,13 +763,13 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
* No insert or delete
*/
if ((nsb != nfd) && fx > 0 &&
- ((p - old) + fx <= el->el_term.t_size.h)) {
+ ((p - old) + fx <= el->el_terminal.t_size.h)) {
ELRE_DEBUG(1,
(__F, "first diff insert at %d...\r\n", nfd - new));
/*
* Move to the first char to insert, where the first diff is.
*/
- term_move_to_char(el, (int)(nfd - new));
+ terminal_move_to_char(el, (int)(nfd - new));
/*
* Check if we have stuff to keep at end
*/
@@ -781,21 +781,21 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
if (fx > 0) {
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in early first diff\n"));
- term_insertwrite(el, nfd, fx);
+ terminal_insertwrite(el, nfd, fx);
re_insert(el, old, (int)(ofd - old),
- el->el_term.t_size.h, nfd, fx);
+ el->el_terminal.t_size.h, nfd, fx);
}
/*
* write (nsb-nfd) - fx chars of new starting at
* (nfd + fx)
*/
len = (size_t) ((nsb - nfd) - fx);
- term_overwrite(el, (nfd + fx), len);
+ terminal_overwrite(el, (nfd + fx), len);
re__strncopy(ofd + fx, nfd + fx, len);
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
len = (size_t)(nsb - nfd);
- term_overwrite(el, nfd, len);
+ terminal_overwrite(el, nfd, len);
re__strncopy(ofd, nfd, len);
/*
* Done
@@ -808,7 +808,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
/*
* move to the first char to delete where the first diff is
*/
- term_move_to_char(el, (int)(ofd - old));
+ terminal_move_to_char(el, (int)(ofd - old));
/*
* Check if we have stuff to save
*/
@@ -821,15 +821,15 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
if (fx < 0) {
ELRE_DEBUG(!EL_CAN_DELETE, (__F,
"ERROR: cannot delete in first diff\n"));
- term_deletechars(el, -fx);
+ terminal_deletechars(el, -fx);
re_delete(el, old, (int)(ofd - old),
- el->el_term.t_size.h, -fx);
+ el->el_terminal.t_size.h, -fx);
}
/*
* write (nsb-nfd) chars of new starting at nfd
*/
len = (size_t) (nsb - nfd);
- term_overwrite(el, nfd, len);
+ terminal_overwrite(el, nfd, len);
re__strncopy(ofd, nfd, len);
} else {
@@ -838,7 +838,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
/*
* write (nsb-nfd) chars of new starting at nfd
*/
- term_overwrite(el, nfd, (size_t)(nsb - nfd));
+ terminal_overwrite(el, nfd, (size_t)(nsb - nfd));
re_clear_eol(el, fx, sx,
(int)((oe - old) - (ne - new)));
/*
@@ -849,7 +849,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
} else
fx = 0;
- if (sx < 0 && (ose - old) + fx < el->el_term.t_size.h) {
+ 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));
/*
@@ -859,7 +859,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
* fx is the number of characters inserted (+) or deleted (-)
*/
- term_move_to_char(el, (int)((ose - old) + fx));
+ terminal_move_to_char(el, (int)((ose - old) + fx));
/*
* Check if we have stuff to save
*/
@@ -871,16 +871,16 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
if (sx < 0) {
ELRE_DEBUG(!EL_CAN_DELETE, (__F,
"ERROR: cannot delete in second diff\n"));
- term_deletechars(el, -sx);
+ terminal_deletechars(el, -sx);
}
/*
* write (nls-nse) chars of new starting at nse
*/
- term_overwrite(el, nse, (size_t)(nls - nse));
+ terminal_overwrite(el, nse, (size_t)(nls - nse));
} else {
ELRE_DEBUG(1, (__F,
"but with nothing left to save\r\n"));
- term_overwrite(el, nse, (size_t)(nls - nse));
+ terminal_overwrite(el, nse, (size_t)(nls - nse));
re_clear_eol(el, fx, sx,
(int)((oe - old) - (ne - new)));
}
@@ -892,7 +892,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
ELRE_DEBUG(1, (__F, "late first diff insert at %d...\r\n",
nfd - new));
- term_move_to_char(el, (int)(nfd - new));
+ terminal_move_to_char(el, (int)(nfd - new));
/*
* Check if we have stuff to keep at the end
*/
@@ -910,21 +910,21 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
*/
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in late first diff\n"));
- term_insertwrite(el, nfd, fx);
+ terminal_insertwrite(el, nfd, fx);
re_insert(el, old, (int)(ofd - old),
- el->el_term.t_size.h, nfd, fx);
+ el->el_terminal.t_size.h, nfd, fx);
}
/*
* write (nsb-nfd) - fx chars of new starting at
* (nfd + fx)
*/
len = (size_t) ((nsb - nfd) - fx);
- term_overwrite(el, (nfd + fx), len);
+ terminal_overwrite(el, (nfd + fx), len);
re__strncopy(ofd + fx, nfd + fx, len);
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
len = (size_t) (nsb - nfd);
- term_overwrite(el, nfd, len);
+ terminal_overwrite(el, nfd, len);
re__strncopy(ofd, nfd, len);
}
}
@@ -934,24 +934,24 @@ re_update_line(EditLine *el, Char *old, Char *new, int i)
if (sx >= 0) {
ELRE_DEBUG(1, (__F,
"second diff insert at %d...\r\n", (int)(nse - new)));
- term_move_to_char(el, (int)(nse - new));
+ terminal_move_to_char(el, (int)(nse - new));
if (ols != oe) {
ELRE_DEBUG(1, (__F, "with stuff to keep at end\r\n"));
if (sx > 0) {
/* insert sx chars of new starting at nse */
ELRE_DEBUG(!EL_CAN_INSERT, (__F,
"ERROR: cannot insert in second diff\n"));
- term_insertwrite(el, nse, sx);
+ terminal_insertwrite(el, nse, sx);
}
/*
* write (nls-nse) - sx chars of new starting at
* (nse + sx)
*/
- term_overwrite(el, (nse + sx),
+ terminal_overwrite(el, (nse + sx),
(size_t)((nls - nse) - sx));
} else {
ELRE_DEBUG(1, (__F, "without anything to save\r\n"));
- term_overwrite(el, nse, (size_t)(nls - nse));
+ terminal_overwrite(el, nse, (size_t)(nls - nse));
/*
* No need to do a clear-to-end here because we were
@@ -1005,7 +1005,7 @@ re_refresh_cursor(EditLine *el)
/* first we must find where the cursor is... */
h = el->el_prompt.p_pos.h;
v = el->el_prompt.p_pos.v;
- th = el->el_term.t_size.h; /* optimize for speed */
+ th = el->el_terminal.t_size.h; /* optimize for speed */
/* do input buffer to el->el_line.cursor */
for (cp = el->el_line.buffer; cp < el->el_line.cursor; cp++) {
@@ -1042,9 +1042,9 @@ re_refresh_cursor(EditLine *el)
}
/* now go there */
- term_move_to_line(el, v);
- term_move_to_char(el, h);
- term__flush(el);
+ terminal_move_to_line(el, v);
+ terminal_move_to_char(el, h);
+ terminal__flush(el);
}
@@ -1055,16 +1055,16 @@ private void
re_fastputc(EditLine *el, Int c)
{
int w = Width((Char)c);
- while (w > 1 && el->el_cursor.h + w > el->el_term.t_size.h)
+ while (w > 1 && el->el_cursor.h + w > el->el_terminal.t_size.h)
re_fastputc(el, ' ');
- term__putc(el, c);
+ terminal__putc(el, c);
el->el_display[el->el_cursor.v][el->el_cursor.h++] = c;
while (--w > 0)
el->el_display[el->el_cursor.v][el->el_cursor.h++]
= MB_FILL_CHAR;
- if (el->el_cursor.h >= el->el_term.t_size.h) {
+ if (el->el_cursor.h >= el->el_terminal.t_size.h) {
/* if we must overflow */
el->el_cursor.h = 0;
@@ -1074,14 +1074,14 @@ re_fastputc(EditLine *el, Int c)
* We do this via pointer shuffling - it's safe in this case
* and we avoid memcpy().
*/
- if (el->el_cursor.v + 1 >= el->el_term.t_size.v) {
- int i, lins = el->el_term.t_size.v;
+ if (el->el_cursor.v + 1 >= el->el_terminal.t_size.v) {
+ int i, lins = el->el_terminal.t_size.v;
Char *firstline = el->el_display[0];
for(i = 1; i < lins; i++)
el->el_display[i - 1] = el->el_display[i];
- re__copy_and_pad(firstline, STR(""), 0);
+ re__copy_and_pad(firstline, STR(""), (size_t)0);
el->el_display[i - 1] = firstline;
} else {
el->el_cursor.v++;
@@ -1089,12 +1089,12 @@ re_fastputc(EditLine *el, Int c)
}
if (EL_HAS_AUTO_MARGINS) {
if (EL_HAS_MAGIC_MARGINS) {
- term__putc(el, ' ');
- term__putc(el, '\b');
+ terminal__putc(el, ' ');
+ terminal__putc(el, '\b');
}
} else {
- term__putc(el, '\r');
- term__putc(el, '\n');
+ terminal__putc(el, '\r');
+ terminal__putc(el, '\n');
}
}
}
@@ -1116,7 +1116,7 @@ re_fastaddc(EditLine *el)
re_refresh(el); /* too hard to handle */
return;
}
- rhdiff = el->el_term.t_size.h - el->el_cursor.h -
+ rhdiff = el->el_terminal.t_size.h - el->el_cursor.h -
el->el_rprompt.p_pos.h;
if (el->el_rprompt.p_pos.h && rhdiff < 3) {
re_refresh(el); /* clear out rprompt if less than 1 char gap */
@@ -1139,7 +1139,7 @@ re_fastaddc(EditLine *el)
break;
}
}
- term__flush(el);
+ terminal__flush(el);
}
@@ -1153,7 +1153,7 @@ re_clear_display(EditLine *el)
el->el_cursor.v = 0;
el->el_cursor.h = 0;
- for (i = 0; i < el->el_term.t_size.v; i++)
+ for (i = 0; i < el->el_terminal.t_size.v; i++)
el->el_display[i][0] = '\0';
el->el_refresh.r_oldcv = 0;
}
@@ -1170,14 +1170,14 @@ re_clear_lines(EditLine *el)
int i;
for (i = el->el_refresh.r_oldcv; i >= 0; i--) {
/* for each line on the screen */
- term_move_to_line(el, i);
- term_move_to_char(el, 0);
- term_clear_EOL(el, el->el_term.t_size.h);
+ terminal_move_to_line(el, i);
+ terminal_move_to_char(el, 0);
+ terminal_clear_EOL(el, el->el_terminal.t_size.h);
}
} else {
- term_move_to_line(el, el->el_refresh.r_oldcv);
+ terminal_move_to_line(el, el->el_refresh.r_oldcv);
/* go to last line */
- term__putc(el, '\r'); /* go to BOL */
- term__putc(el, '\n'); /* go to new line */
+ terminal__putc(el, '\r'); /* go to BOL */
+ terminal__putc(el, '\n'); /* go to new line */
}
}
diff --git a/search.c b/search.c
index 366d3c4342a2..762b40604a05 100644
--- a/search.c
+++ b/search.c
@@ -1,4 +1,4 @@
-/* $NetBSD: search.c,v 1.24 2010/04/15 00:57:33 christos Exp $ */
+/* $NetBSD: search.c,v 1.30 2011/10/04 15:27:04 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: search.c,v 1.24 2010/04/15 00:57:33 christos Exp $");
+__RCSID("$NetBSD: search.c,v 1.30 2011/10/04 15:27:04 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -69,13 +69,13 @@ search_init(EditLine *el)
el->el_search.patbuf = el_malloc(EL_BUFSIZ *
sizeof(*el->el_search.patbuf));
if (el->el_search.patbuf == NULL)
- return (-1);
+ return -1;
el->el_search.patlen = 0;
el->el_search.patdir = -1;
el->el_search.chacha = '\0';
el->el_search.chadir = CHAR_FWD;
el->el_search.chatflg = 0;
- return (0);
+ return 0;
}
@@ -86,7 +86,7 @@ protected void
search_end(EditLine *el)
{
- el_free((ptr_t) el->el_search.patbuf);
+ el_free(el->el_search.patbuf);
el->el_search.patbuf = NULL;
}
@@ -124,29 +124,30 @@ el_match(const Char *str, const Char *pat)
#endif
if (Strstr(str, pat) != 0)
- return (1);
+ return 1;
#if defined(REGEX)
if (regcomp(&re, ct_encode_string(pat, &conv), 0) == 0) {
- rv = regexec(&re, ct_encode_string(str, &conv), 0, NULL, 0) == 0;
+ rv = regexec(&re, ct_encode_string(str, &conv), (size_t)0, NULL,
+ 0) == 0;
regfree(&re);
} else {
rv = 0;
}
- return (rv);
+ return rv;
#elif defined(REGEXP)
if ((re = regcomp(ct_encode_string(pat, &conv))) != NULL) {
rv = regexec(re, ct_encode_string(str, &conv));
- free((ptr_t) re);
+ el_free(re);
} else {
rv = 0;
}
- return (rv);
+ return rv;
#else
if (re_comp(ct_encode_string(pat, &conv)) != NULL)
- return (0);
+ return 0;
else
- return (re_exec(ct_encode_string(str, &conv)) == 1);
+ return re_exec(ct_encode_string(str, &conv) == 1);
#endif
}
@@ -162,7 +163,7 @@ c_hmatch(EditLine *el, const Char *str)
el->el_search.patbuf, str);
#endif /* SDEBUG */
- return (el_match(str, el->el_search.patbuf));
+ return el_match(str, el->el_search.patbuf);
}
@@ -174,7 +175,8 @@ c_setpat(EditLine *el)
{
if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY &&
el->el_state.lastcmd != ED_SEARCH_NEXT_HISTORY) {
- el->el_search.patlen = EL_CURSOR(el) - el->el_line.buffer;
+ el->el_search.patlen =
+ (size_t)(EL_CURSOR(el) - el->el_line.buffer);
if (el->el_search.patlen >= EL_BUFSIZ)
el->el_search.patlen = EL_BUFSIZ - 1;
if (el->el_search.patlen != 0) {
@@ -220,7 +222,7 @@ ce_inc_search(EditLine *el, int dir)
if (el->el_line.lastchar + sizeof(STRfwd) /
sizeof(*el->el_line.lastchar) + 2 +
el->el_search.patlen >= el->el_line.limit)
- return (CC_ERROR);
+ return CC_ERROR;
for (;;) {
@@ -248,13 +250,13 @@ ce_inc_search(EditLine *el, int dir)
re_refresh(el);
if (FUN(el,getc)(el, &ch) != 1)
- return (ed_end_of_file(el, 0));
+ return ed_end_of_file(el, 0);
switch (el->el_map.current[(unsigned char) ch]) {
case ED_INSERT:
case ED_DIGIT:
if (el->el_search.patlen >= EL_BUFSIZ - LEN)
- term_beep(el);
+ terminal_beep(el);
else {
el->el_search.patbuf[el->el_search.patlen++] =
ch;
@@ -279,7 +281,7 @@ ce_inc_search(EditLine *el, int dir)
if (el->el_search.patlen > LEN)
done++;
else
- term_beep(el);
+ terminal_beep(el);
break;
default:
@@ -303,7 +305,7 @@ ce_inc_search(EditLine *el, int dir)
*el->el_line.cursor != '\n') {
if (el->el_search.patlen >=
EL_BUFSIZ - LEN) {
- term_beep(el);
+ terminal_beep(el);
break;
}
el->el_search.patbuf[el->el_search.patlen++] =
@@ -316,7 +318,7 @@ ce_inc_search(EditLine *el, int dir)
re_refresh(el);
break;
} else if (isglob(*cp)) {
- term_beep(el);
+ terminal_beep(el);
break;
}
break;
@@ -385,9 +387,10 @@ ce_inc_search(EditLine *el, int dir)
/* avoid c_setpat */
el->el_state.lastcmd =
(el_action_t) newdir;
- ret = newdir == ED_SEARCH_PREV_HISTORY ?
+ ret = (el_action_t)
+ (newdir == ED_SEARCH_PREV_HISTORY ?
ed_search_prev_history(el, 0) :
- ed_search_next_history(el, 0);
+ ed_search_next_history(el, 0));
if (ret != CC_ERROR) {
el->el_line.cursor = newdir ==
ED_SEARCH_PREV_HISTORY ?
@@ -401,13 +404,13 @@ ce_inc_search(EditLine *el, int dir)
el->el_search.patbuf[el->el_search.patlen] =
'\0';
if (ret == CC_ERROR) {
- term_beep(el);
+ terminal_beep(el);
if (el->el_history.eventno !=
ohisteventno) {
el->el_history.eventno =
ohisteventno;
if (hist_get(el) == CC_ERROR)
- return (CC_ERROR);
+ return CC_ERROR;
}
el->el_line.cursor = ocursor;
pchar = '?';
@@ -432,14 +435,14 @@ ce_inc_search(EditLine *el, int dir)
if (el->el_history.eventno != ohisteventno) {
el->el_history.eventno = ohisteventno;
if (hist_get(el) == CC_ERROR)
- return (CC_ERROR);
+ return CC_ERROR;
}
el->el_line.cursor = ocursor;
if (ret == CC_ERROR)
re_refresh(el);
}
if (done || ret != CC_NORM)
- return (ret);
+ return ret;
}
}
@@ -452,7 +455,7 @@ cv_search(EditLine *el, int dir)
{
Char ch;
Char tmpbuf[EL_BUFSIZ];
- int tmplen;
+ ssize_t tmplen;
#ifdef ANCHOR
tmpbuf[0] = '.';
@@ -477,7 +480,7 @@ cv_search(EditLine *el, int dir)
*/
if (el->el_search.patlen == 0) {
re_refresh(el);
- return (CC_ERROR);
+ return CC_ERROR;
}
#ifdef ANCHOR
if (el->el_search.patbuf[0] != '.' &&
@@ -501,20 +504,20 @@ cv_search(EditLine *el, int dir)
#endif
tmpbuf[tmplen] = '\0';
(void) Strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
- el->el_search.patlen = tmplen;
+ el->el_search.patlen = (size_t)tmplen;
}
el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer;
if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
ed_search_next_history(el, 0)) == CC_ERROR) {
re_refresh(el);
- return (CC_ERROR);
+ return CC_ERROR;
}
if (ch == 0033) {
re_refresh(el);
return ed_newline(el, 0);
}
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -541,21 +544,21 @@ ce_search_line(EditLine *el, int dir)
if (el_match(cp, ocp)) {
*ocp = oc;
el->el_line.cursor = cp;
- return (CC_NORM);
+ return CC_NORM;
}
}
*ocp = oc;
- return (CC_ERROR);
+ return CC_ERROR;
} else {
for (; *cp != '\0' && cp < el->el_line.limit; cp++) {
if (el_match(cp, ocp)) {
*ocp = oc;
el->el_line.cursor = cp;
- return (CC_NORM);
+ return CC_NORM;
}
}
*ocp = oc;
- return (CC_ERROR);
+ return CC_ERROR;
}
}
@@ -577,11 +580,11 @@ cv_repeat_srch(EditLine *el, Int c)
switch (c) {
case ED_SEARCH_NEXT_HISTORY:
- return (ed_search_next_history(el, 0));
+ return ed_search_next_history(el, 0);
case ED_SEARCH_PREV_HISTORY:
- return (ed_search_prev_history(el, 0));
+ return ed_search_prev_history(el, 0);
default:
- return (CC_ERROR);
+ return CC_ERROR;
}
}
@@ -597,7 +600,7 @@ cv_csearch(EditLine *el, int direction, Int ch, int count, int tflag)
if (ch == 0)
return CC_ERROR;
- if (ch == -1) {
+ if (ch == (Int)-1) {
Char c;
if (FUN(el,getc)(el, &c) != 1)
return ed_end_of_file(el, 0);
@@ -607,18 +610,18 @@ cv_csearch(EditLine *el, int direction, Int ch, int count, int tflag)
/* Save for ';' and ',' commands */
el->el_search.chacha = ch;
el->el_search.chadir = direction;
- el->el_search.chatflg = tflag;
+ el->el_search.chatflg = (char)tflag;
cp = el->el_line.cursor;
while (count--) {
- if (*cp == ch)
+ if ((Int)*cp == ch)
cp += direction;
for (;;cp += direction) {
if (cp >= el->el_line.lastchar)
return CC_ERROR;
if (cp < el->el_line.buffer)
return CC_ERROR;
- if (*cp == ch)
+ if ((Int)*cp == ch)
break;
}
}
diff --git a/sig.c b/sig.c
index 1ea319faa063..a5a8a895eaf4 100644
--- a/sig.c
+++ b/sig.c
@@ -1,4 +1,4 @@
-/* $NetBSD: sig.c,v 1.15 2009/02/19 15:20:22 christos Exp $ */
+/* $NetBSD: sig.c,v 1.17 2011/07/28 20:50:55 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: sig.c,v 1.15 2009/02/19 15:20:22 christos Exp $");
+__RCSID("$NetBSD: sig.c,v 1.17 2011/07/28 20:50:55 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -82,7 +82,7 @@ sig_handler(int signo)
tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel);
- term__flush(sel);
+ terminal__flush(sel);
break;
case SIGWINCH:
@@ -146,7 +146,7 @@ protected void
sig_end(EditLine *el)
{
- el_free((ptr_t) el->el_signal);
+ el_free(el->el_signal);
el->el_signal = NULL;
}
diff --git a/sys.h b/sys.h
index 23171d85f9f2..690e1354b116 100644
--- a/sys.h
+++ b/sys.h
@@ -1,4 +1,4 @@
-/* $NetBSD: sys.h,v 1.13 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: sys.h,v 1.17 2011/09/28 14:08:04 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -75,16 +75,6 @@
# define __arraycount(a) (sizeof(a) / sizeof(*(a)))
#endif
-#ifndef _PTR_T
-# define _PTR_T
-typedef void *ptr_t;
-#endif
-
-#ifndef _IOCTL_T
-# define _IOCTL_T
-typedef void *ioctl_t;
-#endif
-
#include <stdio.h>
#ifndef HAVE_STRLCAT
@@ -102,6 +92,27 @@ size_t strlcpy(char *dst, const char *src, size_t size);
char *fgetln(FILE *fp, size_t *len);
#endif
+#ifndef HAVE_WCSDUP
+#include <wchar.h>
+wchar_t *wcsdup(const wchar_t *);
+#endif
+
+#ifndef _DIAGASSERT
+#define _DIAGASSERT(x)
+#endif
+
+#ifndef __RCSID
+#define __RCSID(x)
+#endif
+
+#ifndef HAVE_U_INT32_T
+typedef unsigned int u_int32_t;
+#endif
+
+#ifndef SIZE_T_MAX
+#define SIZE_T_MAX ((size_t)-1)
+#endif
+
#define REGEX /* Use POSIX.2 regular expression functions */
#undef REGEXP /* Use UNIX V8 regular expression functions */
@@ -114,40 +125,4 @@ extern char* tgoto(const char*, int, int);
extern char* tgetstr(char*, char**);
#endif
-#ifdef notdef
-# undef REGEX
-# undef REGEXP
-# include <malloc.h>
-# ifdef __GNUC__
-/*
- * Broken hdrs.
- */
-extern int tgetent(const char *bp, char *name);
-extern int tgetflag(const char *id);
-extern int tgetnum(const char *id);
-extern char *tgetstr(const char *id, char **area);
-extern char *tgoto(const char *cap, int col, int row);
-extern int tputs(const char *str, int affcnt, int (*putc)(int));
-extern char *getenv(const char *);
-extern int fprintf(FILE *, const char *, ...);
-extern int sigsetmask(int);
-extern int sigblock(int);
-extern int fputc(int, FILE *);
-extern int fgetc(FILE *);
-extern int fflush(FILE *);
-extern int tolower(int);
-extern int toupper(int);
-extern int errno, sys_nerr;
-extern char *sys_errlist[];
-extern void perror(const char *);
-# include <string.h>
-# define strerror(e) sys_errlist[e]
-# endif
-# ifdef SABER
-extern ptr_t memcpy(ptr_t, const ptr_t, size_t);
-extern ptr_t memset(ptr_t, int, size_t);
-# endif
-extern char *fgetline(FILE *, int *);
-#endif
-
#endif /* _h_sys */
diff --git a/term.c b/terminal.c
index 39c881a38671..c4a2543e4963 100644
--- a/term.c
+++ b/terminal.c
@@ -1,4 +1,4 @@
-/* $NetBSD: term.c,v 1.57 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,14 +37,14 @@
#if 0
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#else
-__RCSID("$NetBSD: term.c,v 1.57 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
/*
- * term.c: Editor/termcap-curses interface
- * We have to declare a static variable here, since the
- * termcap putchar routine does not take an argument!
+ * terminal.c: Editor/termcap-curses interface
+ * We have to declare a static variable here, since the
+ * termcap putchar routine does not take an argument!
*/
#include <stdio.h>
#include <signal.h>
@@ -60,11 +60,12 @@ __RCSID("$NetBSD: term.c,v 1.57 2009/12/30 22:37:40 christos Exp $");
#elif HAVE_NCURSES_H
#include <ncurses.h>
#endif
-/* Solaris's term.h does horrid things. */
-#if defined(HAVE_TERM_H) && !defined(__sun)
+/* Solaris's term.h does horrid things. */
+#if defined(HAVE_TERM_H) && !defined(__sun) && !defined(HAVE_TERMCAP_H)
#include <term.h>
#endif
+
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -81,84 +82,12 @@ __RCSID("$NetBSD: term.c,v 1.57 2009/12/30 22:37:40 christos Exp $");
* assumption...
*/
-#define TC_BUFSIZE 2048
-
-#define GoodStr(a) (el->el_term.t_str[a] != NULL && \
- el->el_term.t_str[a][0] != '\0')
-#define Str(a) el->el_term.t_str[a]
-#define Val(a) el->el_term.t_val[a]
+#define TC_BUFSIZE ((size_t)2048)
-#ifdef notdef
-private const struct {
- const char *b_name;
- int b_rate;
-} baud_rate[] = {
-#ifdef B0
- { "0", B0 },
-#endif
-#ifdef B50
- { "50", B50 },
-#endif
-#ifdef B75
- { "75", B75 },
-#endif
-#ifdef B110
- { "110", B110 },
-#endif
-#ifdef B134
- { "134", B134 },
-#endif
-#ifdef B150
- { "150", B150 },
-#endif
-#ifdef B200
- { "200", B200 },
-#endif
-#ifdef B300
- { "300", B300 },
-#endif
-#ifdef B600
- { "600", B600 },
-#endif
-#ifdef B900
- { "900", B900 },
-#endif
-#ifdef B1200
- { "1200", B1200 },
-#endif
-#ifdef B1800
- { "1800", B1800 },
-#endif
-#ifdef B2400
- { "2400", B2400 },
-#endif
-#ifdef B3600
- { "3600", B3600 },
-#endif
-#ifdef B4800
- { "4800", B4800 },
-#endif
-#ifdef B7200
- { "7200", B7200 },
-#endif
-#ifdef B9600
- { "9600", B9600 },
-#endif
-#ifdef EXTA
- { "19200", EXTA },
-#endif
-#ifdef B19200
- { "19200", B19200 },
-#endif
-#ifdef EXTB
- { "38400", EXTB },
-#endif
-#ifdef B38400
- { "38400", B38400 },
-#endif
- { NULL, 0 }
-};
-#endif
+#define GoodStr(a) (el->el_terminal.t_str[a] != NULL && \
+ el->el_terminal.t_str[a][0] != '\0')
+#define Str(a) el->el_terminal.t_str[a]
+#define Val(a) el->el_terminal.t_val[a]
private const struct termcapstr {
const char *name;
@@ -240,7 +169,9 @@ private const struct termcapstr {
{ "kh", "send cursor home" },
#define T_at7 37
{ "@7", "send cursor end" },
-#define T_str 38
+#define T_kD 38
+ { "kD", "send cursor delete" },
+#define T_str 39
{ NULL, NULL }
};
@@ -269,27 +200,28 @@ private const struct termcapval {
};
/* do two or more of the attributes use me */
-private void term_setflags(EditLine *);
-private int term_rebuffer_display(EditLine *);
-private void term_free_display(EditLine *);
-private int term_alloc_display(EditLine *);
-private void term_alloc(EditLine *, const struct termcapstr *, const char *);
-private void term_init_arrow(EditLine *);
-private void term_reset_arrow(EditLine *);
-private int term_putc(int);
-private void term_tputs(EditLine *, const char *, int);
+private void terminal_setflags(EditLine *);
+private int terminal_rebuffer_display(EditLine *);
+private void terminal_free_display(EditLine *);
+private int terminal_alloc_display(EditLine *);
+private void terminal_alloc(EditLine *, const struct termcapstr *,
+ const char *);
+private void terminal_init_arrow(EditLine *);
+private void terminal_reset_arrow(EditLine *);
+private int terminal_putc(int);
+private void terminal_tputs(EditLine *, const char *, int);
#ifdef _REENTRANT
-private pthread_mutex_t term_mutex = PTHREAD_MUTEX_INITIALIZER;
+private pthread_mutex_t terminal_mutex = PTHREAD_MUTEX_INITIALIZER;
#endif
-private FILE *term_outfile = NULL;
+private FILE *terminal_outfile = NULL;
-/* term_setflags():
+/* terminal_setflags():
* Set the terminal capability flags
*/
private void
-term_setflags(EditLine *el)
+terminal_setflags(EditLine *el)
{
EL_FLAGS = 0;
if (el->el_tty.t_tabs)
@@ -330,69 +262,77 @@ term_setflags(EditLine *el)
#endif /* DEBUG_SCREEN */
}
-/* term_init():
+/* terminal_init():
* Initialize the terminal stuff
*/
protected int
-term_init(EditLine *el)
+terminal_init(EditLine *el)
{
- el->el_term.t_buf = (char *) el_malloc(TC_BUFSIZE);
- if (el->el_term.t_buf == NULL)
- return (-1);
- el->el_term.t_cap = (char *) el_malloc(TC_BUFSIZE);
- if (el->el_term.t_cap == NULL)
- return (-1);
- el->el_term.t_fkey = (fkey_t *) el_malloc(A_K_NKEYS * sizeof(fkey_t));
- if (el->el_term.t_fkey == NULL)
- return (-1);
- el->el_term.t_loc = 0;
- el->el_term.t_str = (char **) el_malloc(T_str * sizeof(char *));
- if (el->el_term.t_str == NULL)
- return (-1);
- (void) memset(el->el_term.t_str, 0, T_str * sizeof(char *));
- el->el_term.t_val = (int *) el_malloc(T_val * sizeof(int));
- if (el->el_term.t_val == NULL)
- return (-1);
- (void) memset(el->el_term.t_val, 0, T_val * sizeof(int));
- (void) term_set(el, NULL);
- term_init_arrow(el);
- return (0);
+ el->el_terminal.t_buf = el_malloc(TC_BUFSIZE *
+ sizeof(*el->el_terminal.t_buf));
+ if (el->el_terminal.t_buf == NULL)
+ return -1;
+ el->el_terminal.t_cap = el_malloc(TC_BUFSIZE *
+ sizeof(*el->el_terminal.t_cap));
+ if (el->el_terminal.t_cap == NULL)
+ return -1;
+ el->el_terminal.t_fkey = el_malloc(A_K_NKEYS *
+ sizeof(*el->el_terminal.t_fkey));
+ if (el->el_terminal.t_fkey == NULL)
+ return -1;
+ el->el_terminal.t_loc = 0;
+ el->el_terminal.t_str = el_malloc(T_str *
+ sizeof(*el->el_terminal.t_str));
+ if (el->el_terminal.t_str == NULL)
+ return -1;
+ (void) memset(el->el_terminal.t_str, 0, T_str *
+ sizeof(*el->el_terminal.t_str));
+ el->el_terminal.t_val = el_malloc(T_val *
+ sizeof(*el->el_terminal.t_val));
+ if (el->el_terminal.t_val == NULL)
+ return -1;
+ (void) memset(el->el_terminal.t_val, 0, T_val *
+ sizeof(*el->el_terminal.t_val));
+ (void) terminal_set(el, NULL);
+ terminal_init_arrow(el);
+ return 0;
}
-/* term_end():
+/* terminal_end():
* Clean up the terminal stuff
*/
protected void
-term_end(EditLine *el)
+terminal_end(EditLine *el)
{
- el_free((ptr_t) el->el_term.t_buf);
- el->el_term.t_buf = NULL;
- el_free((ptr_t) el->el_term.t_cap);
- el->el_term.t_cap = NULL;
- el->el_term.t_loc = 0;
- el_free((ptr_t) el->el_term.t_str);
- el->el_term.t_str = NULL;
- el_free((ptr_t) el->el_term.t_val);
- el->el_term.t_val = NULL;
- el_free((ptr_t) el->el_term.t_fkey);
- el->el_term.t_fkey = NULL;
- term_free_display(el);
+ el_free(el->el_terminal.t_buf);
+ el->el_terminal.t_buf = NULL;
+ el_free(el->el_terminal.t_cap);
+ el->el_terminal.t_cap = NULL;
+ el->el_terminal.t_loc = 0;
+ el_free(el->el_terminal.t_str);
+ el->el_terminal.t_str = NULL;
+ el_free(el->el_terminal.t_val);
+ el->el_terminal.t_val = NULL;
+ el_free(el->el_terminal.t_fkey);
+ el->el_terminal.t_fkey = NULL;
+ terminal_free_display(el);
}
-/* term_alloc():
+/* terminal_alloc():
* Maintain a string pool for termcap strings
*/
private void
-term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
+terminal_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
{
char termbuf[TC_BUFSIZE];
size_t tlen, clen;
- char **tlist = el->el_term.t_str;
+ char **tlist = el->el_terminal.t_str;
char **tmp, **str = &tlist[t - tstr];
+ (void) memset(termbuf, 0, sizeof(termbuf));
if (cap == NULL || *cap == '\0') {
*str = NULL;
return;
@@ -412,11 +352,11 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
/*
* New string is longer; see if we have enough space to append
*/
- if (el->el_term.t_loc + 3 < TC_BUFSIZE) {
+ if (el->el_terminal.t_loc + 3 < TC_BUFSIZE) {
/* XXX strcpy is safe */
- (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc],
- cap);
- el->el_term.t_loc += (int)clen + 1; /* one for \0 */
+ (void) strcpy(*str = &el->el_terminal.t_buf[
+ el->el_terminal.t_loc], cap);
+ el->el_terminal.t_loc += clen + 1; /* one for \0 */
return;
}
/*
@@ -432,87 +372,88 @@ term_alloc(EditLine *el, const struct termcapstr *t, const char *cap)
continue;
termbuf[tlen++] = '\0';
}
- memcpy(el->el_term.t_buf, termbuf, TC_BUFSIZE);
- el->el_term.t_loc = (int)tlen;
- if (el->el_term.t_loc + 3 >= TC_BUFSIZE) {
+ memcpy(el->el_terminal.t_buf, termbuf, TC_BUFSIZE);
+ el->el_terminal.t_loc = tlen;
+ if (el->el_terminal.t_loc + 3 >= TC_BUFSIZE) {
(void) fprintf(el->el_errfile,
"Out of termcap string space.\n");
return;
}
/* XXX strcpy is safe */
- (void) strcpy(*str = &el->el_term.t_buf[el->el_term.t_loc], cap);
- el->el_term.t_loc += (int)clen + 1; /* one for \0 */
+ (void) strcpy(*str = &el->el_terminal.t_buf[el->el_terminal.t_loc],
+ cap);
+ el->el_terminal.t_loc += (size_t)clen + 1; /* one for \0 */
return;
}
-/* term_rebuffer_display():
+/* terminal_rebuffer_display():
* Rebuffer the display after the screen changed size
*/
private int
-term_rebuffer_display(EditLine *el)
+terminal_rebuffer_display(EditLine *el)
{
- coord_t *c = &el->el_term.t_size;
+ coord_t *c = &el->el_terminal.t_size;
- term_free_display(el);
+ terminal_free_display(el);
c->h = Val(T_co);
c->v = Val(T_li);
- if (term_alloc_display(el) == -1)
- return (-1);
- return (0);
+ if (terminal_alloc_display(el) == -1)
+ return -1;
+ return 0;
}
-/* term_alloc_display():
+/* terminal_alloc_display():
* Allocate a new display.
*/
private int
-term_alloc_display(EditLine *el)
+terminal_alloc_display(EditLine *el)
{
int i;
Char **b;
- coord_t *c = &el->el_term.t_size;
+ coord_t *c = &el->el_terminal.t_size;
- b = el_malloc(sizeof(*b) * (c->v + 1));
+ b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
if (b == NULL)
- return (-1);
+ return -1;
for (i = 0; i < c->v; i++) {
- b[i] = el_malloc(sizeof(**b) * (c->h + 1));
+ b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
if (b[i] == NULL) {
while (--i >= 0)
- el_free((ptr_t) b[i]);
- el_free((ptr_t) b);
- return (-1);
+ el_free(b[i]);
+ el_free(b);
+ return -1;
}
}
b[c->v] = NULL;
el->el_display = b;
- b = el_malloc(sizeof(*b) * (c->v + 1));
+ b = el_malloc(sizeof(*b) * (size_t)(c->v + 1));
if (b == NULL)
- return (-1);
+ return -1;
for (i = 0; i < c->v; i++) {
- b[i] = el_malloc(sizeof(**b) * (c->h + 1));
+ b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1));
if (b[i] == NULL) {
while (--i >= 0)
- el_free((ptr_t) b[i]);
- el_free((ptr_t) b);
- return (-1);
+ el_free(b[i]);
+ el_free(b);
+ return -1;
}
}
b[c->v] = NULL;
el->el_vdisplay = b;
- return (0);
+ return 0;
}
-/* term_free_display():
+/* terminal_free_display():
* Free the display buffers
*/
private void
-term_free_display(EditLine *el)
+terminal_free_display(EditLine *el)
{
Char **b;
Char **bufp;
@@ -521,35 +462,36 @@ term_free_display(EditLine *el)
el->el_display = NULL;
if (b != NULL) {
for (bufp = b; *bufp != NULL; bufp++)
- el_free((ptr_t) *bufp);
- el_free((ptr_t) b);
+ el_free(*bufp);
+ el_free(b);
}
b = el->el_vdisplay;
el->el_vdisplay = NULL;
if (b != NULL) {
for (bufp = b; *bufp != NULL; bufp++)
- el_free((ptr_t) *bufp);
- el_free((ptr_t) b);
+ el_free(*bufp);
+ el_free(b);
}
}
-/* term_move_to_line():
+/* terminal_move_to_line():
* move to line <where> (first line == 0)
* as efficiently as possible
*/
protected void
-term_move_to_line(EditLine *el, int where)
+terminal_move_to_line(EditLine *el, int where)
{
int del;
if (where == el->el_cursor.v)
return;
- if (where > el->el_term.t_size.v) {
+ if (where > el->el_terminal.t_size.v) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
- "term_move_to_line: where is ridiculous: %d\r\n", where);
+ "terminal_move_to_line: where is ridiculous: %d\r\n",
+ where);
#endif /* DEBUG_SCREEN */
return;
}
@@ -557,7 +499,8 @@ term_move_to_line(EditLine *el, int where)
while (del > 0) {
if (EL_HAS_AUTO_MARGINS &&
el->el_display[el->el_cursor.v][0] != '\0') {
- size_t h = el->el_term.t_size.h - 1;
+ size_t h = (size_t)
+ (el->el_terminal.t_size.h - 1);
#ifdef WIDECHAR
for (; h > 0 &&
el->el_display[el->el_cursor.v][h] ==
@@ -566,21 +509,21 @@ term_move_to_line(EditLine *el, int where)
continue;
#endif
/* move without newline */
- term_move_to_char(el, (int)h);
- term_overwrite(el, &el->el_display
+ terminal_move_to_char(el, (int)h);
+ terminal_overwrite(el, &el->el_display
[el->el_cursor.v][el->el_cursor.h],
- (size_t)(el->el_term.t_size.h -
+ (size_t)(el->el_terminal.t_size.h -
el->el_cursor.h));
/* updates Cursor */
del--;
} else {
if ((del > 1) && GoodStr(T_DO)) {
- term_tputs(el, tgoto(Str(T_DO), del,
+ terminal_tputs(el, tgoto(Str(T_DO), del,
del), del);
del = 0;
} else {
for (; del > 0; del--)
- term__putc(el, '\n');
+ terminal__putc(el, '\n');
/* because the \n will become \r\n */
el->el_cursor.h = 0;
}
@@ -588,22 +531,22 @@ term_move_to_line(EditLine *el, int where)
}
} else { /* del < 0 */
if (GoodStr(T_UP) && (-del > 1 || !GoodStr(T_up)))
- term_tputs(el, tgoto(Str(T_UP), -del, -del), -del);
+ terminal_tputs(el, tgoto(Str(T_UP), -del, -del), -del);
else {
if (GoodStr(T_up))
for (; del < 0; del++)
- term_tputs(el, Str(T_up), 1);
+ terminal_tputs(el, Str(T_up), 1);
}
}
el->el_cursor.v = where;/* now where is here */
}
-/* term_move_to_char():
+/* terminal_move_to_char():
* Move to the character position specified
*/
protected void
-term_move_to_char(EditLine *el, int where)
+terminal_move_to_char(EditLine *el, int where)
{
int del, i;
@@ -611,15 +554,16 @@ mc_again:
if (where == el->el_cursor.h)
return;
- if (where > el->el_term.t_size.h) {
+ if (where > el->el_terminal.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
- "term_move_to_char: where is riduculous: %d\r\n", where);
+ "terminal_move_to_char: where is riduculous: %d\r\n",
+ where);
#endif /* DEBUG_SCREEN */
return;
}
if (!where) { /* if where is first column */
- term__putc(el, '\r'); /* do a CR */
+ terminal__putc(el, '\r'); /* do a CR */
el->el_cursor.h = 0;
return;
}
@@ -627,11 +571,12 @@ mc_again:
if ((del < -4 || del > 4) && GoodStr(T_ch))
/* go there directly */
- term_tputs(el, tgoto(Str(T_ch), where, where), where);
+ terminal_tputs(el, tgoto(Str(T_ch), where, where), where);
else {
if (del > 0) { /* moving forward */
if ((del > 4) && GoodStr(T_RI))
- term_tputs(el, tgoto(Str(T_RI), del, del), del);
+ terminal_tputs(el, tgoto(Str(T_RI), del, del),
+ del);
else {
/* if I can do tabs, use them */
if (EL_CAN_TAB) {
@@ -648,7 +593,8 @@ mc_again:
(el->el_cursor.h & 0370);
i < (where & ~0x7);
i += 8)
- term__putc(el, '\t');
+ terminal__putc(el,
+ '\t');
/* then tab over */
el->el_cursor.h = where & ~0x7;
}
@@ -658,17 +604,17 @@ mc_again:
* chars, so we do.
*/
/*
- * NOTE THAT term_overwrite() WILL CHANGE
+ * NOTE THAT terminal_overwrite() WILL CHANGE
* el->el_cursor.h!!!
*/
- term_overwrite(el, &el->el_display[
+ terminal_overwrite(el, &el->el_display[
el->el_cursor.v][el->el_cursor.h],
(size_t)(where - el->el_cursor.h));
}
} else { /* del < 0 := moving backward */
if ((-del > 4) && GoodStr(T_LE))
- term_tputs(el, tgoto(Str(T_LE), -del, -del),
+ terminal_tputs(el, tgoto(Str(T_LE), -del, -del),
-del);
else { /* can't go directly there */
/*
@@ -680,12 +626,12 @@ mc_again:
(((unsigned int) where >> 3) +
(where & 07)))
: (-del > where)) {
- term__putc(el, '\r'); /* do a CR */
+ terminal__putc(el, '\r');/* do a CR */
el->el_cursor.h = 0;
goto mc_again; /* and try again */
}
for (i = 0; i < -del; i++)
- term__putc(el, '\b');
+ terminal__putc(el, '\b');
}
}
}
@@ -693,31 +639,31 @@ mc_again:
}
-/* term_overwrite():
+/* terminal_overwrite():
* Overstrike num characters
* Assumes MB_FILL_CHARs are present to keep the column count correct
*/
protected void
-term_overwrite(EditLine *el, const Char *cp, size_t n)
+terminal_overwrite(EditLine *el, const Char *cp, size_t n)
{
if (n == 0)
return;
- if (n > (size_t)el->el_term.t_size.h) {
+ if (n > (size_t)el->el_terminal.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
- "term_overwrite: n is riduculous: %d\r\n", n);
+ "terminal_overwrite: n is riduculous: %d\r\n", n);
#endif /* DEBUG_SCREEN */
return;
}
do {
- /* term__putc() ignores any MB_FILL_CHARs */
- term__putc(el, *cp++);
+ /* terminal__putc() ignores any MB_FILL_CHARs */
+ terminal__putc(el, *cp++);
el->el_cursor.h++;
} while (--n);
- if (el->el_cursor.h >= el->el_term.t_size.h) { /* wrap? */
+ if (el->el_cursor.h >= el->el_terminal.t_size.h) { /* wrap? */
if (EL_HAS_AUTO_MARGINS) { /* yes */
el->el_cursor.h = 0;
el->el_cursor.v++;
@@ -727,28 +673,28 @@ term_overwrite(EditLine *el, const Char *cp, size_t n)
Char c;
if ((c = el->el_display[el->el_cursor.v]
[el->el_cursor.h]) != '\0') {
- term_overwrite(el, &c, 1);
+ terminal_overwrite(el, &c, (size_t)1);
#ifdef WIDECHAR
while (el->el_display[el->el_cursor.v]
[el->el_cursor.h] == MB_FILL_CHAR)
el->el_cursor.h++;
#endif
} else {
- term__putc(el, ' ');
+ terminal__putc(el, ' ');
el->el_cursor.h = 1;
}
}
} else /* no wrap, but cursor stays on screen */
- el->el_cursor.h = el->el_term.t_size.h - 1;
+ el->el_cursor.h = el->el_terminal.t_size.h - 1;
}
}
-/* term_deletechars():
+/* terminal_deletechars():
* Delete num characters
*/
protected void
-term_deletechars(EditLine *el, int num)
+terminal_deletechars(EditLine *el, int num)
{
if (num <= 0)
return;
@@ -759,38 +705,38 @@ term_deletechars(EditLine *el, int num)
#endif /* DEBUG_EDIT */
return;
}
- if (num > el->el_term.t_size.h) {
+ if (num > el->el_terminal.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
- "term_deletechars: num is riduculous: %d\r\n", num);
+ "terminal_deletechars: num is riduculous: %d\r\n", num);
#endif /* DEBUG_SCREEN */
return;
}
if (GoodStr(T_DC)) /* if I have multiple delete */
if ((num > 1) || !GoodStr(T_dc)) { /* if dc would be more
* expen. */
- term_tputs(el, tgoto(Str(T_DC), num, num), num);
+ terminal_tputs(el, tgoto(Str(T_DC), num, num), num);
return;
}
if (GoodStr(T_dm)) /* if I have delete mode */
- term_tputs(el, Str(T_dm), 1);
+ terminal_tputs(el, Str(T_dm), 1);
if (GoodStr(T_dc)) /* else do one at a time */
while (num--)
- term_tputs(el, Str(T_dc), 1);
+ terminal_tputs(el, Str(T_dc), 1);
if (GoodStr(T_ed)) /* if I have delete mode */
- term_tputs(el, Str(T_ed), 1);
+ terminal_tputs(el, Str(T_ed), 1);
}
-/* term_insertwrite():
+/* terminal_insertwrite():
* Puts terminal in insert character mode or inserts num
* characters in the line
* Assumes MB_FILL_CHARs are present to keep column count correct
*/
protected void
-term_insertwrite(EditLine *el, Char *cp, int num)
+terminal_insertwrite(EditLine *el, Char *cp, int num)
{
if (num <= 0)
return;
@@ -800,7 +746,7 @@ term_insertwrite(EditLine *el, Char *cp, int num)
#endif /* DEBUG_EDIT */
return;
}
- if (num > el->el_term.t_size.h) {
+ if (num > el->el_terminal.t_size.h) {
#ifdef DEBUG_SCREEN
(void) fprintf(el->el_errfile,
"StartInsert: num is riduculous: %d\r\n", num);
@@ -810,120 +756,106 @@ term_insertwrite(EditLine *el, Char *cp, int num)
if (GoodStr(T_IC)) /* if I have multiple insert */
if ((num > 1) || !GoodStr(T_ic)) {
/* if ic would be more expensive */
- term_tputs(el, tgoto(Str(T_IC), num, num), num);
- term_overwrite(el, cp, (size_t)num);
+ terminal_tputs(el, tgoto(Str(T_IC), num, num), num);
+ terminal_overwrite(el, cp, (size_t)num);
/* this updates el_cursor.h */
return;
}
if (GoodStr(T_im) && GoodStr(T_ei)) { /* if I have insert mode */
- term_tputs(el, Str(T_im), 1);
+ terminal_tputs(el, Str(T_im), 1);
el->el_cursor.h += num;
do
- term__putc(el, *cp++);
+ terminal__putc(el, *cp++);
while (--num);
if (GoodStr(T_ip)) /* have to make num chars insert */
- term_tputs(el, Str(T_ip), 1);
+ terminal_tputs(el, Str(T_ip), 1);
- term_tputs(el, Str(T_ei), 1);
+ terminal_tputs(el, Str(T_ei), 1);
return;
}
do {
if (GoodStr(T_ic)) /* have to make num chars insert */
- term_tputs(el, Str(T_ic), 1);
+ terminal_tputs(el, Str(T_ic), 1);
- term__putc(el, *cp++);
+ terminal__putc(el, *cp++);
el->el_cursor.h++;
if (GoodStr(T_ip)) /* have to make num chars insert */
- term_tputs(el, Str(T_ip), 1);
+ terminal_tputs(el, Str(T_ip), 1);
/* pad the inserted char */
} while (--num);
}
-/* term_clear_EOL():
+/* terminal_clear_EOL():
* clear to end of line. There are num characters to clear
*/
protected void
-term_clear_EOL(EditLine *el, int num)
+terminal_clear_EOL(EditLine *el, int num)
{
int i;
if (EL_CAN_CEOL && GoodStr(T_ce))
- term_tputs(el, Str(T_ce), 1);
+ terminal_tputs(el, Str(T_ce), 1);
else {
for (i = 0; i < num; i++)
- term__putc(el, ' ');
+ terminal__putc(el, ' ');
el->el_cursor.h += num; /* have written num spaces */
}
}
-/* term_clear_screen():
+/* terminal_clear_screen():
* Clear the screen
*/
protected void
-term_clear_screen(EditLine *el)
+terminal_clear_screen(EditLine *el)
{ /* clear the whole screen and home */
if (GoodStr(T_cl))
/* send the clear screen code */
- term_tputs(el, Str(T_cl), Val(T_li));
+ terminal_tputs(el, Str(T_cl), Val(T_li));
else if (GoodStr(T_ho) && GoodStr(T_cd)) {
- term_tputs(el, Str(T_ho), Val(T_li)); /* home */
+ terminal_tputs(el, Str(T_ho), Val(T_li)); /* home */
/* clear to bottom of screen */
- term_tputs(el, Str(T_cd), Val(T_li));
+ terminal_tputs(el, Str(T_cd), Val(T_li));
} else {
- term__putc(el, '\r');
- term__putc(el, '\n');
+ terminal__putc(el, '\r');
+ terminal__putc(el, '\n');
}
}
-/* term_beep():
+/* terminal_beep():
* Beep the way the terminal wants us
*/
protected void
-term_beep(EditLine *el)
+terminal_beep(EditLine *el)
{
if (GoodStr(T_bl))
/* what termcap says we should use */
- term_tputs(el, Str(T_bl), 1);
+ terminal_tputs(el, Str(T_bl), 1);
else
- term__putc(el, '\007'); /* an ASCII bell; ^G */
+ terminal__putc(el, '\007'); /* an ASCII bell; ^G */
}
-#ifdef notdef
-/* term_clear_to_bottom():
- * Clear to the bottom of the screen
- */
-protected void
-term_clear_to_bottom(EditLine *el)
-{
- if (GoodStr(T_cd))
- term_tputs(el, Str(T_cd), Val(T_li));
- else if (GoodStr(T_ce))
- term_tputs(el, Str(T_ce), Val(T_li));
-}
-#endif
-
protected void
-term_get(EditLine *el, const char **term)
+terminal_get(EditLine *el, const char **term)
{
- *term = el->el_term.t_name;
+ *term = el->el_terminal.t_name;
}
-/* term_set():
+/* terminal_set():
* Read in the terminal capabilities from the requested terminal
*/
protected int
-term_set(EditLine *el, const char *term)
+terminal_set(EditLine *el, const char *term)
{
int i;
char buf[TC_BUFSIZE];
@@ -948,9 +880,9 @@ term_set(EditLine *el, const char *term)
if (strcmp(term, "emacs") == 0)
el->el_flags |= EDIT_DISABLED;
- memset(el->el_term.t_cap, 0, TC_BUFSIZE);
+ (void) memset(el->el_terminal.t_cap, 0, TC_BUFSIZE);
- i = tgetent(el->el_term.t_cap, term);
+ i = tgetent(el->el_terminal.t_cap, term);
if (i <= 0) {
if (i == -1)
@@ -965,7 +897,7 @@ term_set(EditLine *el, const char *term)
Val(T_pt) = Val(T_km) = Val(T_li) = 0;
Val(T_xt) = Val(T_MT);
for (t = tstr; t->name != NULL; t++)
- term_alloc(el, t, NULL);
+ terminal_alloc(el, t, NULL);
} else {
/* auto/magic margins */
Val(T_am) = tgetflag("am");
@@ -981,7 +913,7 @@ term_set(EditLine *el, const char *term)
Val(T_li) = tgetnum("li");
for (t = tstr; t->name != NULL; t++) {
/* XXX: some systems' tgetstr needs non const */
- term_alloc(el, t, tgetstr(strchr(t->name, *t->name),
+ terminal_alloc(el, t, tgetstr(strchr(t->name, *t->name),
&area));
}
}
@@ -991,28 +923,28 @@ term_set(EditLine *el, const char *term)
if (Val(T_li) < 1)
Val(T_li) = 24;
- el->el_term.t_size.v = Val(T_co);
- el->el_term.t_size.h = Val(T_li);
+ el->el_terminal.t_size.v = Val(T_co);
+ el->el_terminal.t_size.h = Val(T_li);
- term_setflags(el);
+ terminal_setflags(el);
/* get the correct window size */
- (void) term_get_size(el, &lins, &cols);
- if (term_change_size(el, lins, cols) == -1)
- return (-1);
+ (void) terminal_get_size(el, &lins, &cols);
+ if (terminal_change_size(el, lins, cols) == -1)
+ return -1;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
- term_bind_arrow(el);
- el->el_term.t_name = term;
- return (i <= 0 ? -1 : 0);
+ terminal_bind_arrow(el);
+ el->el_terminal.t_name = term;
+ return i <= 0 ? -1 : 0;
}
-/* term_get_size():
+/* terminal_get_size():
* Return the new window size in lines and cols, and
* true if the size was changed.
*/
protected int
-term_get_size(EditLine *el, int *lins, int *cols)
+terminal_get_size(EditLine *el, int *lins, int *cols)
{
*cols = Val(T_co);
@@ -1021,7 +953,7 @@ term_get_size(EditLine *el, int *lins, int *cols)
#ifdef TIOCGWINSZ
{
struct winsize ws;
- if (ioctl(el->el_infd, TIOCGWINSZ, (ioctl_t) & ws) != -1) {
+ if (ioctl(el->el_infd, TIOCGWINSZ, &ws) != -1) {
if (ws.ws_col)
*cols = ws.ws_col;
if (ws.ws_row)
@@ -1032,7 +964,7 @@ term_get_size(EditLine *el, int *lins, int *cols)
#ifdef TIOCGSIZE
{
struct ttysize ts;
- if (ioctl(el->el_infd, TIOCGSIZE, (ioctl_t) & ts) != -1) {
+ if (ioctl(el->el_infd, TIOCGSIZE, &ts) != -1) {
if (ts.ts_cols)
*cols = ts.ts_cols;
if (ts.ts_lines)
@@ -1040,15 +972,15 @@ term_get_size(EditLine *el, int *lins, int *cols)
}
}
#endif
- return (Val(T_co) != *cols || Val(T_li) != *lins);
+ return Val(T_co) != *cols || Val(T_li) != *lins;
}
-/* term_change_size():
+/* terminal_change_size():
* Change the size of the terminal
*/
protected int
-term_change_size(EditLine *el, int lins, int cols)
+terminal_change_size(EditLine *el, int lins, int cols)
{
/*
* Just in case
@@ -1057,20 +989,20 @@ term_change_size(EditLine *el, int lins, int cols)
Val(T_li) = (lins < 1) ? 24 : lins;
/* re-make display buffers */
- if (term_rebuffer_display(el) == -1)
- return (-1);
+ if (terminal_rebuffer_display(el) == -1)
+ return -1;
re_clear_display(el);
- return (0);
+ return 0;
}
-/* term_init_arrow():
+/* terminal_init_arrow():
* Initialize the arrow key bindings from termcap
*/
private void
-term_init_arrow(EditLine *el)
+terminal_init_arrow(EditLine *el)
{
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
arrow[A_K_DN].name = STR("down");
arrow[A_K_DN].key = T_kd;
@@ -1101,16 +1033,21 @@ term_init_arrow(EditLine *el)
arrow[A_K_EN].key = T_at7;
arrow[A_K_EN].fun.cmd = ED_MOVE_TO_END;
arrow[A_K_EN].type = XK_CMD;
+
+ arrow[A_K_DE].name = STR("delete");
+ arrow[A_K_DE].key = T_kD;
+ arrow[A_K_DE].fun.cmd = ED_DELETE_NEXT_CHAR;
+ arrow[A_K_DE].type = XK_CMD;
}
-/* term_reset_arrow():
+/* terminal_reset_arrow():
* Reset arrow key bindings
*/
private void
-term_reset_arrow(EditLine *el)
+terminal_reset_arrow(EditLine *el)
{
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
static const Char strA[] = {033, '[', 'A', '\0'};
static const Char strB[] = {033, '[', 'B', '\0'};
static const Char strC[] = {033, '[', 'C', '\0'};
@@ -1124,117 +1061,118 @@ term_reset_arrow(EditLine *el)
static const Char stOH[] = {033, 'O', 'H', '\0'};
static const Char stOF[] = {033, 'O', 'F', '\0'};
- key_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- key_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
-
- if (el->el_map.type == MAP_VI) {
- key_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- key_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
- key_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
- key_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
- key_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
- key_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
- key_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
- }
+ keymacro_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+ keymacro_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+ keymacro_add(el, strC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+ keymacro_add(el, strD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+ keymacro_add(el, strH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+ keymacro_add(el, strF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+ keymacro_add(el, stOA, &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+ keymacro_add(el, stOB, &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+ keymacro_add(el, stOC, &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+ keymacro_add(el, stOD, &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+ keymacro_add(el, stOH, &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+ keymacro_add(el, stOF, &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+
+ if (el->el_map.type != MAP_VI)
+ return;
+ keymacro_add(el, &strA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+ keymacro_add(el, &strB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+ keymacro_add(el, &strC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+ keymacro_add(el, &strD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+ keymacro_add(el, &strH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+ keymacro_add(el, &strF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
+ keymacro_add(el, &stOA[1], &arrow[A_K_UP].fun, arrow[A_K_UP].type);
+ keymacro_add(el, &stOB[1], &arrow[A_K_DN].fun, arrow[A_K_DN].type);
+ keymacro_add(el, &stOC[1], &arrow[A_K_RT].fun, arrow[A_K_RT].type);
+ keymacro_add(el, &stOD[1], &arrow[A_K_LT].fun, arrow[A_K_LT].type);
+ keymacro_add(el, &stOH[1], &arrow[A_K_HO].fun, arrow[A_K_HO].type);
+ keymacro_add(el, &stOF[1], &arrow[A_K_EN].fun, arrow[A_K_EN].type);
}
-/* term_set_arrow():
+/* terminal_set_arrow():
* Set an arrow key binding
*/
protected int
-term_set_arrow(EditLine *el, const Char *name, key_value_t *fun, int type)
+terminal_set_arrow(EditLine *el, const Char *name, keymacro_value_t *fun,
+ int type)
{
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
int i;
for (i = 0; i < A_K_NKEYS; i++)
if (Strcmp(name, arrow[i].name) == 0) {
arrow[i].fun = *fun;
arrow[i].type = type;
- return (0);
+ return 0;
}
- return (-1);
+ return -1;
}
-/* term_clear_arrow():
+/* terminal_clear_arrow():
* Clear an arrow key binding
*/
protected int
-term_clear_arrow(EditLine *el, const Char *name)
+terminal_clear_arrow(EditLine *el, const Char *name)
{
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
int i;
for (i = 0; i < A_K_NKEYS; i++)
if (Strcmp(name, arrow[i].name) == 0) {
arrow[i].type = XK_NOD;
- return (0);
+ return 0;
}
- return (-1);
+ return -1;
}
-/* term_print_arrow():
+/* terminal_print_arrow():
* Print the arrow key bindings
*/
protected void
-term_print_arrow(EditLine *el, const Char *name)
+terminal_print_arrow(EditLine *el, const Char *name)
{
int i;
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
for (i = 0; i < A_K_NKEYS; i++)
if (*name == '\0' || Strcmp(name, arrow[i].name) == 0)
if (arrow[i].type != XK_NOD)
- key_kprint(el, arrow[i].name, &arrow[i].fun,
- arrow[i].type);
+ keymacro_kprint(el, arrow[i].name,
+ &arrow[i].fun, arrow[i].type);
}
-/* term_bind_arrow():
+/* terminal_bind_arrow():
* Bind the arrow keys
*/
protected void
-term_bind_arrow(EditLine *el)
+terminal_bind_arrow(EditLine *el)
{
el_action_t *map;
const el_action_t *dmap;
int i, j;
char *p;
- fkey_t *arrow = el->el_term.t_fkey;
+ funckey_t *arrow = el->el_terminal.t_fkey;
/* Check if the components needed are initialized */
- if (el->el_term.t_buf == NULL || el->el_map.key == NULL)
+ if (el->el_terminal.t_buf == NULL || el->el_map.key == NULL)
return;
map = el->el_map.type == MAP_VI ? el->el_map.alt : el->el_map.key;
dmap = el->el_map.type == MAP_VI ? el->el_map.vic : el->el_map.emacs;
- term_reset_arrow(el);
+ terminal_reset_arrow(el);
for (i = 0; i < A_K_NKEYS; i++) {
Char wt_str[VISUAL_WIDTH_MAX];
Char *px;
size_t n;
- p = el->el_term.t_str[arrow[i].key];
+ p = el->el_terminal.t_str[arrow[i].key];
if (!p || !*p)
continue;
for (n = 0; n < VISUAL_WIDTH_MAX && p[n]; ++n)
@@ -1254,96 +1192,98 @@ term_bind_arrow(EditLine *el)
* unassigned key.
*/
if (arrow[i].type == XK_NOD)
- key_clear(el, map, px);
+ keymacro_clear(el, map, px);
else {
if (p[1] && (dmap[j] == map[j] ||
map[j] == ED_SEQUENCE_LEAD_IN)) {
- key_add(el, px, &arrow[i].fun,
+ keymacro_add(el, px, &arrow[i].fun,
arrow[i].type);
map[j] = ED_SEQUENCE_LEAD_IN;
} else if (map[j] == ED_UNASSIGNED) {
- key_clear(el, map, px);
+ keymacro_clear(el, map, px);
if (arrow[i].type == XK_CMD)
map[j] = arrow[i].fun.cmd;
else
- key_add(el, px, &arrow[i].fun,
+ keymacro_add(el, px, &arrow[i].fun,
arrow[i].type);
}
}
}
}
-/* term_putc():
+/* terminal_putc():
* Add a character
*/
private int
-term_putc(int c)
+terminal_putc(int c)
{
- if (term_outfile == NULL)
+ if (terminal_outfile == NULL)
return -1;
- return fputc(c, term_outfile);
+ return fputc(c, terminal_outfile);
}
private void
-term_tputs(EditLine *el, const char *cap, int affcnt)
+terminal_tputs(EditLine *el, const char *cap, int affcnt)
{
#ifdef _REENTRANT
- pthread_mutex_lock(&term_mutex);
+ pthread_mutex_lock(&terminal_mutex);
#endif
- term_outfile = el->el_outfile;
- (void)tputs(cap, affcnt, term_putc);
+ terminal_outfile = el->el_outfile;
+ (void)tputs(cap, affcnt, terminal_putc);
#ifdef _REENTRANT
- pthread_mutex_unlock(&term_mutex);
+ pthread_mutex_unlock(&terminal_mutex);
#endif
}
-/* term__putc():
+/* terminal__putc():
* Add a character
*/
protected int
-term__putc(EditLine *el, Int c)
+terminal__putc(EditLine *el, Int c)
{
char buf[MB_LEN_MAX +1];
ssize_t i;
- if (c == MB_FILL_CHAR)
+ if (c == (Int)MB_FILL_CHAR)
return 0;
- i = ct_encode_char(buf, MB_LEN_MAX, c);
+ i = ct_encode_char(buf, (size_t)MB_LEN_MAX, c);
if (i <= 0)
return (int)i;
buf[i] = '\0';
return fputs(buf, el->el_outfile);
}
-/* term__flush():
+/* terminal__flush():
* Flush output
*/
protected void
-term__flush(EditLine *el)
+terminal__flush(EditLine *el)
{
(void) fflush(el->el_outfile);
}
-/* term_writec():
+/* terminal_writec():
* Write the given character out, in a human readable form
*/
protected void
-term_writec(EditLine *el, Int c)
+terminal_writec(EditLine *el, Int c)
{
Char visbuf[VISUAL_WIDTH_MAX +1];
ssize_t vcnt = ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c);
+ if (vcnt < 0)
+ vcnt = 0;
visbuf[vcnt] = '\0';
- term_overwrite(el, visbuf, (size_t)vcnt);
- term__flush(el);
+ terminal_overwrite(el, visbuf, (size_t)vcnt);
+ terminal__flush(el);
}
-/* term_telltc():
+/* terminal_telltc():
* Print the current termcap characteristics
*/
protected int
/*ARGSUSED*/
-term_telltc(EditLine *el, int argc __attribute__((__unused__)),
+terminal_telltc(EditLine *el, int argc __attribute__((__unused__)),
const Char **argv __attribute__((__unused__)))
{
const struct termcapstr *t;
@@ -1363,7 +1303,7 @@ term_telltc(EditLine *el, int argc __attribute__((__unused__)),
(void) fprintf(el->el_outfile, "\tIt %s magic margins\n",
EL_HAS_MAGIC_MARGINS ? "has" : "does not have");
- for (t = tstr, ts = el->el_term.t_str; t->name != NULL; t++, ts++) {
+ for (t = tstr, ts = el->el_terminal.t_str; t->name != NULL; t++, ts++) {
const char *ub;
if (*ts && **ts) {
ub = ct_encode_string(ct_visual_string(
@@ -1376,16 +1316,16 @@ term_telltc(EditLine *el, int argc __attribute__((__unused__)),
t->long_name, t->name, ub);
}
(void) fputc('\n', el->el_outfile);
- return (0);
+ return 0;
}
-/* term_settc():
+/* terminal_settc():
* Change the current terminal characteristics
*/
protected int
/*ARGSUSED*/
-term_settc(EditLine *el, int argc __attribute__((__unused__)),
+terminal_settc(EditLine *el, int argc __attribute__((__unused__)),
const Char **argv)
{
const struct termcapstr *ts;
@@ -1408,8 +1348,8 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)),
break;
if (ts->name != NULL) {
- term_alloc(el, ts, how);
- term_setflags(el);
+ terminal_alloc(el, ts, how);
+ terminal_setflags(el);
return 0;
}
/*
@@ -1425,16 +1365,16 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)),
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
tv == &tval[T_am] || tv == &tval[T_xn]) {
if (strcmp(how, "yes") == 0)
- el->el_term.t_val[tv - tval] = 1;
+ el->el_terminal.t_val[tv - tval] = 1;
else if (strcmp(how, "no") == 0)
- el->el_term.t_val[tv - tval] = 0;
+ el->el_terminal.t_val[tv - tval] = 0;
else {
(void) fprintf(el->el_errfile,
"" FSTR ": Bad value `%s'.\n", argv[0], how);
return -1;
}
- term_setflags(el);
- if (term_change_size(el, Val(T_li), Val(T_co)) == -1)
+ terminal_setflags(el);
+ if (terminal_change_size(el, Val(T_li), Val(T_co)) == -1)
return -1;
return 0;
} else {
@@ -1447,11 +1387,11 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)),
"" FSTR ": Bad value `%s'.\n", argv[0], how);
return -1;
}
- el->el_term.t_val[tv - tval] = (int) i;
- el->el_term.t_size.v = Val(T_co);
- el->el_term.t_size.h = Val(T_li);
+ el->el_terminal.t_val[tv - tval] = (int) i;
+ el->el_terminal.t_size.v = Val(T_co);
+ el->el_terminal.t_size.h = Val(T_li);
if (tv == &tval[T_co] || tv == &tval[T_li])
- if (term_change_size(el, Val(T_li), Val(T_co))
+ if (terminal_change_size(el, Val(T_li), Val(T_co))
== -1)
return -1;
return 0;
@@ -1459,12 +1399,12 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)),
}
-/* term_gettc():
+/* terminal_gettc():
* Get the current terminal characteristics
*/
protected int
/*ARGSUSED*/
-term_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv)
+terminal_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv)
{
const struct termcapstr *ts;
const struct termcapval *tv;
@@ -1472,7 +1412,7 @@ term_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv)
void *how;
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
- return (-1);
+ return -1;
what = argv[1];
how = argv[2];
@@ -1485,7 +1425,7 @@ term_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv)
break;
if (ts->name != NULL) {
- *(char **)how = el->el_term.t_str[ts - tstr];
+ *(char **)how = el->el_terminal.t_str[ts - tstr];
return 0;
}
/*
@@ -1502,23 +1442,23 @@ term_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv)
tv == &tval[T_am] || tv == &tval[T_xn]) {
static char yes[] = "yes";
static char no[] = "no";
- if (el->el_term.t_val[tv - tval])
+ if (el->el_terminal.t_val[tv - tval])
*(char **)how = yes;
else
*(char **)how = no;
return 0;
} else {
- *(int *)how = el->el_term.t_val[tv - tval];
+ *(int *)how = el->el_terminal.t_val[tv - tval];
return 0;
}
}
-/* term_echotc():
+/* terminal_echotc():
* Print the termcap string out with variable substitution
*/
protected int
/*ARGSUSED*/
-term_echotc(EditLine *el, int argc __attribute__((__unused__)),
+terminal_echotc(EditLine *el, int argc __attribute__((__unused__)),
const Char **argv)
{
char *cap, *scap;
@@ -1534,7 +1474,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
area = buf;
if (argv == NULL || argv[1] == NULL)
- return (-1);
+ return -1;
argv++;
if (argv[0][0] == '-') {
@@ -1552,43 +1492,31 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
argv++;
}
if (!*argv || *argv[0] == '\0')
- return (0);
+ return 0;
if (Strcmp(*argv, STR("tabs")) == 0) {
(void) fprintf(el->el_outfile, fmts, EL_CAN_TAB ? "yes" : "no");
- return (0);
+ return 0;
} else if (Strcmp(*argv, STR("meta")) == 0) {
(void) fprintf(el->el_outfile, fmts, Val(T_km) ? "yes" : "no");
- return (0);
+ return 0;
} else if (Strcmp(*argv, STR("xn")) == 0) {
(void) fprintf(el->el_outfile, fmts, EL_HAS_MAGIC_MARGINS ?
"yes" : "no");
- return (0);
+ return 0;
} else if (Strcmp(*argv, STR("am")) == 0) {
(void) fprintf(el->el_outfile, fmts, EL_HAS_AUTO_MARGINS ?
"yes" : "no");
- return (0);
+ return 0;
} else if (Strcmp(*argv, STR("baud")) == 0) {
-#ifdef notdef
- int i;
-
- for (i = 0; baud_rate[i].b_name != NULL; i++)
- if (el->el_tty.t_speed == baud_rate[i].b_rate) {
- (void) fprintf(el->el_outfile, fmts,
- baud_rate[i].b_name);
- return (0);
- }
- (void) fprintf(el->el_outfile, fmtd, 0);
-#else
(void) fprintf(el->el_outfile, fmtd, (int)el->el_tty.t_speed);
-#endif
- return (0);
+ return 0;
} else if (Strcmp(*argv, STR("rows")) == 0 ||
Strcmp(*argv, STR("lines")) == 0) {
(void) fprintf(el->el_outfile, fmtd, Val(T_li));
- return (0);
+ return 0;
} else if (Strcmp(*argv, STR("cols")) == 0) {
(void) fprintf(el->el_outfile, fmtd, Val(T_co));
- return (0);
+ return 0;
}
/*
* Try to use our local definition first
@@ -1597,7 +1525,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
for (t = tstr; t->name != NULL; t++)
if (strcmp(t->name,
ct_encode_string(*argv, &el->el_scratch)) == 0) {
- scap = el->el_term.t_str[t - tstr];
+ scap = el->el_terminal.t_str[t - tstr];
break;
}
if (t->name == NULL) {
@@ -1609,7 +1537,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
(void) fprintf(el->el_errfile,
"echotc: Termcap parameter `" FSTR "' not found.\n",
*argv);
- return (-1);
+ return -1;
}
/*
* Count home many values we need for this capability.
@@ -1652,9 +1580,9 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
(void) fprintf(el->el_errfile,
"echotc: Warning: Extra argument `" FSTR "'.\n",
*argv);
- return (-1);
+ return -1;
}
- term_tputs(el, scap, 1);
+ terminal_tputs(el, scap, 1);
break;
case 1:
argv++;
@@ -1662,7 +1590,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
if (!silent)
(void) fprintf(el->el_errfile,
"echotc: Warning: Missing argument.\n");
- return (-1);
+ return -1;
}
arg_cols = 0;
i = Strtol(*argv, &ep, 10);
@@ -1671,18 +1599,18 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
(void) fprintf(el->el_errfile,
"echotc: Bad value `" FSTR "' for rows.\n",
*argv);
- return (-1);
+ return -1;
}
arg_rows = (int) i;
argv++;
if (*argv && *argv[0]) {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Warning: Extra argument `" FSTR "'.\n",
- *argv);
- return (-1);
+ "echotc: Warning: Extra argument `" FSTR
+ "'.\n", *argv);
+ return -1;
}
- term_tputs(el, tgoto(scap, arg_cols, arg_rows), 1);
+ terminal_tputs(el, tgoto(scap, arg_cols, arg_rows), 1);
break;
default:
/* This is wrong, but I will ignore it... */
@@ -1697,7 +1625,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
if (!silent)
(void) fprintf(el->el_errfile,
"echotc: Warning: Missing argument.\n");
- return (-1);
+ return -1;
}
i = Strtol(*argv, &ep, 10);
if (*ep != '\0' || i < 0) {
@@ -1705,7 +1633,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
(void) fprintf(el->el_errfile,
"echotc: Bad value `" FSTR "' for cols.\n",
*argv);
- return (-1);
+ return -1;
}
arg_cols = (int) i;
argv++;
@@ -1713,7 +1641,7 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
if (!silent)
(void) fprintf(el->el_errfile,
"echotc: Warning: Missing argument.\n");
- return (-1);
+ return -1;
}
i = Strtol(*argv, &ep, 10);
if (*ep != '\0' || i < 0) {
@@ -1721,25 +1649,25 @@ term_echotc(EditLine *el, int argc __attribute__((__unused__)),
(void) fprintf(el->el_errfile,
"echotc: Bad value `" FSTR "' for rows.\n",
*argv);
- return (-1);
+ return -1;
}
arg_rows = (int) i;
if (*ep != '\0') {
if (!silent)
(void) fprintf(el->el_errfile,
"echotc: Bad value `" FSTR "'.\n", *argv);
- return (-1);
+ return -1;
}
argv++;
if (*argv && *argv[0]) {
if (!silent)
(void) fprintf(el->el_errfile,
- "echotc: Warning: Extra argument `" FSTR "'.\n",
- *argv);
- return (-1);
+ "echotc: Warning: Extra argument `" FSTR
+ "'.\n", *argv);
+ return -1;
}
- term_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows);
+ terminal_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows);
break;
}
- return (0);
+ return 0;
}
diff --git a/term.h b/terminal.h
index de9157e8b7b8..c50736305eca 100644
--- a/term.h
+++ b/terminal.h
@@ -1,4 +1,4 @@
-/* $NetBSD: term.h,v 1.21 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: terminal.h,v 1.4 2012/03/24 20:09:30 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,17 +37,17 @@
/*
* el.term.h: Termcap header
*/
-#ifndef _h_el_term
-#define _h_el_term
+#ifndef _h_el_terminal
+#define _h_el_terminal
#include "histedit.h"
typedef struct { /* Symbolic function key bindings */
const Char *name; /* name of the key */
int key; /* Index in termcap table */
- key_value_t fun; /* Function bound to it */
+ keymacro_value_t fun; /* Function bound to it */
int type; /* Type of function */
-} fkey_t;
+} funckey_t;
typedef struct {
const char *t_name; /* the terminal name */
@@ -63,12 +63,12 @@ typedef struct {
#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
char *t_buf; /* Termcap buffer */
- int t_loc; /* location used */
+ size_t t_loc; /* location used */
char **t_str; /* termcap strings */
int *t_val; /* termcap values */
char *t_cap; /* Termcap buffer */
- fkey_t *t_fkey; /* Array of keys */
-} el_term_t;
+ funckey_t *t_fkey; /* Array of keys */
+} el_terminal_t;
/*
* fKey indexes
@@ -79,38 +79,39 @@ typedef struct {
#define A_K_RT 3
#define A_K_HO 4
#define A_K_EN 5
-#define A_K_NKEYS 6
+#define A_K_DE 6
+#define A_K_NKEYS 7
-protected void term_move_to_line(EditLine *, int);
-protected void term_move_to_char(EditLine *, int);
-protected void term_clear_EOL(EditLine *, int);
-protected void term_overwrite(EditLine *, const Char *, size_t);
-protected void term_insertwrite(EditLine *, Char *, int);
-protected void term_deletechars(EditLine *, int);
-protected void term_clear_screen(EditLine *);
-protected void term_beep(EditLine *);
-protected int term_change_size(EditLine *, int, int);
-protected int term_get_size(EditLine *, int *, int *);
-protected int term_init(EditLine *);
-protected void term_bind_arrow(EditLine *);
-protected void term_print_arrow(EditLine *, const Char *);
-protected int term_clear_arrow(EditLine *, const Char *);
-protected int term_set_arrow(EditLine *, const Char *, key_value_t *, int);
-protected void term_end(EditLine *);
-protected void term_get(EditLine *, const char **);
-protected int term_set(EditLine *, const char *);
-protected int term_settc(EditLine *, int, const Char **);
-protected int term_gettc(EditLine *, int, char **);
-protected int term_telltc(EditLine *, int, const Char **);
-protected int term_echotc(EditLine *, int, const Char **);
-protected void term_writec(EditLine *, Int);
-protected int term__putc(EditLine *, Int);
-protected void term__flush(EditLine *);
+protected void terminal_move_to_line(EditLine *, int);
+protected void terminal_move_to_char(EditLine *, int);
+protected void terminal_clear_EOL(EditLine *, int);
+protected void terminal_overwrite(EditLine *, const Char *, size_t);
+protected void terminal_insertwrite(EditLine *, Char *, int);
+protected void terminal_deletechars(EditLine *, int);
+protected void terminal_clear_screen(EditLine *);
+protected void terminal_beep(EditLine *);
+protected int terminal_change_size(EditLine *, int, int);
+protected int terminal_get_size(EditLine *, int *, int *);
+protected int terminal_init(EditLine *);
+protected void terminal_bind_arrow(EditLine *);
+protected void terminal_print_arrow(EditLine *, const Char *);
+protected int terminal_clear_arrow(EditLine *, const Char *);
+protected int terminal_set_arrow(EditLine *, const Char *, keymacro_value_t *, int);
+protected void terminal_end(EditLine *);
+protected void terminal_get(EditLine *, const char **);
+protected int terminal_set(EditLine *, const char *);
+protected int terminal_settc(EditLine *, int, const Char **);
+protected int terminal_gettc(EditLine *, int, char **);
+protected int terminal_telltc(EditLine *, int, const Char **);
+protected int terminal_echotc(EditLine *, int, const Char **);
+protected void terminal_writec(EditLine *, Int);
+protected int terminal__putc(EditLine *, Int);
+protected void terminal__flush(EditLine *);
/*
* Easy access macros
*/
-#define EL_FLAGS (el)->el_term.t_flags
+#define EL_FLAGS (el)->el_terminal.t_flags
#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
@@ -122,4 +123,4 @@ protected void term__flush(EditLine *);
#define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS)
#define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS)
-#endif /* _h_el_term */
+#endif /* _h_el_terminal */
diff --git a/tokenizer.c b/tokenizer.c
index 90af723d0156..7fd842d4864d 100644
--- a/tokenizer.c
+++ b/tokenizer.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tokenizer.c,v 1.18 2010/01/03 18:27:10 christos Exp $ */
+/* $NetBSD: tokenizer.c,v 1.21 2011/08/16 16:25:15 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: tokenizer.c,v 1.18 2010/01/03 18:27:10 christos Exp $");
+__RCSID("$NetBSD: tokenizer.c,v 1.21 2011/08/16 16:25:15 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -70,7 +70,7 @@ typedef enum {
struct TYPE(tokenizer) {
Char *ifs; /* In field separator */
- int argc, amax; /* Current and maximum number of args */
+ size_t argc, amax; /* Current and maximum number of args */
Char **argv; /* Argument list */
Char *wptr, *wmax; /* Space and limit on the word buffer */
Char *wstart; /* Beginning of next word */
@@ -106,29 +106,29 @@ FUN(tok,finish)(TYPE(Tokenizer) *tok)
public TYPE(Tokenizer) *
FUN(tok,init)(const Char *ifs)
{
- TYPE(Tokenizer) *tok = tok_malloc(sizeof(TYPE(Tokenizer)));
+ TYPE(Tokenizer) *tok = tok_malloc(sizeof(*tok));
if (tok == NULL)
return NULL;
tok->ifs = tok_strdup(ifs ? ifs : IFS);
if (tok->ifs == NULL) {
- tok_free((ptr_t)tok);
+ tok_free(tok);
return NULL;
}
tok->argc = 0;
tok->amax = AINCR;
tok->argv = tok_malloc(sizeof(*tok->argv) * tok->amax);
if (tok->argv == NULL) {
- tok_free((ptr_t)tok->ifs);
- tok_free((ptr_t)tok);
+ tok_free(tok->ifs);
+ tok_free(tok);
return NULL;
}
tok->argv[0] = NULL;
tok->wspace = tok_malloc(WINCR * sizeof(*tok->wspace));
if (tok->wspace == NULL) {
- tok_free((ptr_t)tok->argv);
- tok_free((ptr_t)tok->ifs);
- tok_free((ptr_t)tok);
+ tok_free(tok->argv);
+ tok_free(tok->ifs);
+ tok_free(tok);
return NULL;
}
tok->wmax = tok->wspace + WINCR;
@@ -137,7 +137,7 @@ FUN(tok,init)(const Char *ifs)
tok->flags = 0;
tok->quote = Q_none;
- return (tok);
+ return tok;
}
@@ -163,10 +163,10 @@ public void
FUN(tok,end)(TYPE(Tokenizer) *tok)
{
- tok_free((ptr_t) tok->ifs);
- tok_free((ptr_t) tok->wspace);
- tok_free((ptr_t) tok->argv);
- tok_free((ptr_t) tok);
+ tok_free(tok->ifs);
+ tok_free(tok->wspace);
+ tok_free(tok->argv);
+ tok_free(tok);
}
@@ -201,7 +201,7 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
if (ptr >= line->lastchar)
ptr = STR("");
if (ptr == line->cursor) {
- cc = tok->argc;
+ cc = (int)tok->argc;
co = (int)(tok->wptr - tok->wstart);
}
switch (*ptr) {
@@ -233,7 +233,7 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
break;
default:
- return (-1);
+ return -1;
}
break;
@@ -264,7 +264,7 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
break;
default:
- return (-1);
+ return -1;
}
break;
@@ -295,7 +295,7 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
break;
default:
- return (-1);
+ return -1;
}
break;
@@ -321,7 +321,7 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
break;
default:
- return (0);
+ return 0;
}
break;
@@ -331,15 +331,15 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
/* Finish word and return */
if (tok->flags & TOK_EAT) {
tok->flags &= ~TOK_EAT;
- return (3);
+ return 3;
}
goto tok_line_outok;
case Q_single:
- return (1);
+ return 1;
case Q_double:
- return (2);
+ return 2;
case Q_doubleone:
tok->quote = Q_double;
@@ -352,7 +352,7 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
break;
default:
- return (-1);
+ return -1;
}
break;
@@ -384,21 +384,21 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
break;
default:
- return (-1);
+ return -1;
}
break;
}
if (tok->wptr >= tok->wmax - 4) {
- size_t size = tok->wmax - tok->wspace + WINCR;
+ size_t size = (size_t)(tok->wmax - tok->wspace + WINCR);
Char *s = tok_realloc(tok->wspace,
size * sizeof(*s));
if (s == NULL)
- return (-1);
+ return -1;
if (s != tok->wspace) {
- int i;
+ size_t i;
for (i = 0; i < tok->argc; i++) {
tok->argv[i] =
(tok->argv[i] - tok->wspace) + s;
@@ -414,13 +414,13 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
tok->amax += AINCR;
p = tok_realloc(tok->argv, tok->amax * sizeof(*p));
if (p == NULL)
- return (-1);
+ return -1;
tok->argv = p;
}
}
tok_line_outok:
if (cc == -1 && co == -1) {
- cc = tok->argc;
+ cc = (int)tok->argc;
co = (int)(tok->wptr - tok->wstart);
}
if (cursorc != NULL)
@@ -429,8 +429,8 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line,
*cursoro = co;
FUN(tok,finish)(tok);
*argv = (const Char **)tok->argv;
- *argc = tok->argc;
- return (0);
+ *argc = (int)tok->argc;
+ return 0;
}
/* FUN(tok,str)():
@@ -446,5 +446,5 @@ FUN(tok,str)(TYPE(Tokenizer) *tok, const Char *line, int *argc,
memset(&li, 0, sizeof(li));
li.buffer = line;
li.cursor = li.lastchar = Strchr(line, '\0');
- return (FUN(tok,line)(tok, &li, argc, argv, NULL, NULL));
+ return FUN(tok,line(tok, &li, argc, argv, NULL, NULL));
}
diff --git a/tty.c b/tty.c
index d6ed3cab6803..57c8ee8916c8 100644
--- a/tty.c
+++ b/tty.c
@@ -1,4 +1,4 @@
-/* $NetBSD: tty.c,v 1.33 2010/04/18 21:17:22 christos Exp $ */
+/* $NetBSD: tty.c,v 1.42 2012/05/15 15:59:01 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.33 2010/04/18 21:17:22 christos Exp $");
+__RCSID("$NetBSD: tty.c,v 1.42 2012/05/15 15:59:01 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -46,6 +46,7 @@ __RCSID("$NetBSD: tty.c,v 1.33 2010/04/18 21:17:22 christos Exp $");
*/
#include <assert.h>
#include <errno.h>
+#include <unistd.h> /* for isatty */
#include <strings.h> /* for ffs */
#include "el.h"
#include "tty.h"
@@ -153,7 +154,7 @@ private const ttymap_t tty_map[] = {
{C_LNEXT, VLNEXT,
{ED_QUOTED_INSERT, ED_QUOTED_INSERT, ED_UNASSIGNED}},
#endif /* VLNEXT */
- {-1, -1,
+ {(Int)-1, (Int)-1,
{ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED}}
};
@@ -494,16 +495,23 @@ tty_setup(EditLine *el)
int rst = 1;
if (el->el_flags & EDIT_DISABLED)
- return (0);
+ return 0;
- if (tty_getty(el, &el->el_tty.t_ed) == -1) {
+ if (!isatty(el->el_outfd)) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile,
- "tty_setup: tty_getty: %s\n", strerror(errno));
+ (void) fprintf(el->el_errfile, "%s: isatty: %s\n", __func__,
+ strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
- el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed;
+ if (tty_getty(el, &el->el_tty.t_or) == -1) {
+#ifdef DEBUG_TTY
+ (void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
+ strerror(errno));
+#endif /* DEBUG_TTY */
+ return -1;
+ }
+ el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed = el->el_tty.t_or;
el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ex);
el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex);
@@ -547,17 +555,12 @@ tty_setup(EditLine *el)
tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile,
- "tty_setup: tty_setty: %s\n",
- strerror(errno));
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
+ __func__, strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
}
-#ifdef notdef
- else
- tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
-#endif
el->el_tty.t_ed.c_iflag &= ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask;
el->el_tty.t_ed.c_iflag |= el->el_tty.t_t[ED_IO][MD_INP].t_setmask;
@@ -573,7 +576,7 @@ tty_setup(EditLine *el)
tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
tty_bind_char(el, 1);
- return (0);
+ return 0;
}
protected int
@@ -584,7 +587,7 @@ tty_init(EditLine *el)
el->el_tty.t_vdisable = _POSIX_VDISABLE;
(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));
+ return tty_setup(el);
}
@@ -593,10 +596,14 @@ tty_init(EditLine *el)
*/
protected void
/*ARGSUSED*/
-tty_end(EditLine *el __attribute__((__unused__)))
+tty_end(EditLine *el)
{
-
- /* XXX: Maybe reset to an initial state? */
+ if (tty_setty(el, TCSAFLUSH, &el->el_tty.t_or) == -1) {
+#ifdef DEBUG_TTY
+ (void) fprintf(el->el_errfile,
+ "%s: tty_setty: %s\n", __func__, strerror(errno));
+#endif /* DEBUG_TTY */
+ }
}
@@ -610,7 +617,7 @@ tty__getspeed(struct termios *td)
if ((spd = cfgetispeed(td)) == 0)
spd = cfgetospeed(td);
- return (spd);
+ return spd;
}
/* tty__getspeed():
@@ -910,21 +917,21 @@ tty_bind_char(EditLine *el, int force)
dalt = NULL;
}
- for (tp = tty_map; tp->nch != -1; tp++) {
+ for (tp = tty_map; tp->nch != (Int)-1; tp++) {
new[0] = t_n[tp->nch];
old[0] = t_o[tp->och];
if (new[0] == old[0] && !force)
continue;
/* Put the old default binding back, and set the new binding */
- key_clear(el, map, old);
+ keymacro_clear(el, map, old);
map[UC(old[0])] = dmap[UC(old[0])];
- key_clear(el, map, new);
+ keymacro_clear(el, map, new);
/* MAP_VI == 1, MAP_EMACS == 0... */
map[UC(new[0])] = tp->bind[el->el_map.type];
if (dalt) {
- key_clear(el, alt, old);
+ keymacro_clear(el, alt, old);
alt[UC(old[0])] = dalt[UC(old[0])];
- key_clear(el, alt, new);
+ keymacro_clear(el, alt, new);
alt[UC(new[0])] = tp->bind[el->el_map.type + 1];
}
}
@@ -939,17 +946,17 @@ tty_rawmode(EditLine *el)
{
if (el->el_tty.t_mode == ED_IO || el->el_tty.t_mode == QU_IO)
- return (0);
+ return 0;
if (el->el_flags & EDIT_DISABLED)
- return (0);
+ return 0;
if (tty_getty(el, &el->el_tty.t_ts) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "tty_rawmode: tty_getty: %s\n",
+ (void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
/*
* We always keep up with the eight bit setting and the speed of the
@@ -1076,13 +1083,13 @@ tty_rawmode(EditLine *el)
}
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",
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
el->el_tty.t_mode = ED_IO;
- return (0);
+ return 0;
}
@@ -1094,21 +1101,20 @@ tty_cookedmode(EditLine *el)
{ /* set tty in normal setup */
if (el->el_tty.t_mode == EX_IO)
- return (0);
+ return 0;
if (el->el_flags & EDIT_DISABLED)
- return (0);
+ return 0;
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",
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
el->el_tty.t_mode = EX_IO;
- return (0);
+ return 0;
}
@@ -1119,7 +1125,7 @@ protected int
tty_quotemode(EditLine *el)
{
if (el->el_tty.t_mode == QU_IO)
- return (0);
+ return 0;
el->el_tty.t_qu = el->el_tty.t_ed;
@@ -1137,13 +1143,13 @@ tty_quotemode(EditLine *el)
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "QuoteModeOn: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
el->el_tty.t_mode = QU_IO;
- return (0);
+ return 0;
}
@@ -1155,16 +1161,16 @@ tty_noquotemode(EditLine *el)
{
if (el->el_tty.t_mode != QU_IO)
- return (0);
+ return 0;
if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
#ifdef DEBUG_TTY
- (void) fprintf(el->el_errfile, "QuoteModeOff: tty_setty: %s\n",
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
el->el_tty.t_mode = ED_IO;
- return (0);
+ return 0;
}
@@ -1184,7 +1190,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
int z = EX_IO;
if (argv == NULL)
- return (-1);
+ return -1;
strncpy(name, ct_encode_string(*argv++, &el->el_scratch), sizeof(name));
name[sizeof(name) - 1] = '\0';
@@ -1213,7 +1219,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
(void) fprintf(el->el_errfile,
"%s: Unknown switch `%c'.\n",
name, argv[0][1]);
- return (-1);
+ return -1;
}
if (!argv || !*argv) {
@@ -1231,8 +1237,9 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
if (i != -1) {
x = (el->el_tty.t_t[z][i].t_setmask & m->m_value)
? '+' : '\0';
- x = (el->el_tty.t_t[z][i].t_clrmask & m->m_value)
- ? '-' : x;
+
+ if (el->el_tty.t_t[z][i].t_clrmask & m->m_value)
+ x = '-';
} else {
x = '\0';
}
@@ -1241,7 +1248,8 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
cu = strlen(m->m_name) + (x != '\0') + 1;
- if (len + cu >= (size_t)el->el_term.t_size.h) {
+ if (len + cu >=
+ (size_t)el->el_terminal.t_size.h) {
(void) fprintf(el->el_outfile, "\n%*s",
(int)st, "");
len = st + cu;
@@ -1257,14 +1265,14 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
}
}
(void) fprintf(el->el_outfile, "\n");
- return (0);
+ return 0;
}
while (argv && (s = *argv++)) {
const Char *p;
switch (*s) {
case '+':
case '-':
- x = *s++;
+ x = (char)*s++;
break;
default:
x = '\0';
@@ -1273,15 +1281,17 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
d = s;
p = Strchr(s, '=');
for (m = ttymodes; m->m_name; m++)
- if ((p ? strncmp(m->m_name, ct_encode_string(d, &el->el_scratch), (size_t)(p - d)) :
- strcmp(m->m_name, ct_encode_string(d, &el->el_scratch))) == 0 &&
+ if ((p ? strncmp(m->m_name, ct_encode_string(d,
+ &el->el_scratch), (size_t)(p - d)) :
+ strcmp(m->m_name, ct_encode_string(d,
+ &el->el_scratch))) == 0 &&
(p == NULL || m->m_type == MD_CHAR))
break;
if (!m->m_name) {
(void) fprintf(el->el_errfile,
"%s: Invalid argument `" FSTR "'.\n", name, d);
- return (-1);
+ return -1;
}
if (p) {
int c = ffs((int)m->m_value);
@@ -1291,7 +1301,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
c--;
c = tty__getcharindex(c);
assert(c != -1);
- tios->c_cc[c] = v;
+ tios->c_cc[c] = (cc_t)v;
continue;
}
switch (x) {
@@ -1313,14 +1323,14 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
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));
+ (void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
+ __func__, strerror(errno));
#endif /* DEBUG_TTY */
- return (-1);
+ return -1;
}
}
- return (0);
+ return 0;
}
diff --git a/tty.h b/tty.h
index f4b4d42a5eee..7bdb0b2bb991 100644
--- a/tty.h
+++ b/tty.h
@@ -1,4 +1,4 @@
-/* $NetBSD: tty.h,v 1.12 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: tty.h,v 1.14 2012/05/15 15:59:01 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -431,7 +431,7 @@
#define C_MIN 23
#define C_TIME 24
#define C_NCC 25
-#define C_SH(A) (1 << (A))
+#define C_SH(A) ((unsigned int)(1 << (A)))
/*
* Terminal dependend data structures
@@ -469,7 +469,7 @@ protected void tty_bind_char(EditLine *, int);
typedef struct {
ttyperm_t t_t;
ttychar_t t_c;
- struct termios t_ex, t_ed, t_ts;
+ struct termios t_or, t_ex, t_ed, t_ts;
int t_tabs;
int t_eight;
speed_t t_speed;
diff --git a/vi.c b/vi.c
index e52ea4d65748..ec9abbd70c6a 100644
--- a/vi.c
+++ b/vi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: vi.c,v 1.31 2009/12/30 22:37:40 christos Exp $ */
+/* $NetBSD: vi.c,v 1.43 2012/01/16 14:57:45 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: vi.c,v 1.31 2009/12/30 22:37:40 christos Exp $");
+__RCSID("$NetBSD: vi.c,v 1.43 2012/01/16 14:57:45 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -63,7 +63,7 @@ cv_action(EditLine *el, Int c)
if (el->el_chared.c_vcmd.action != NOP) {
/* 'cc', 'dd' and (possibly) friends */
- if (c != el->el_chared.c_vcmd.action)
+ if (c != (Int)el->el_chared.c_vcmd.action)
return CC_ERROR;
if (!(c & YANK))
@@ -79,11 +79,11 @@ cv_action(EditLine *el, Int c)
if (c & INSERT)
el->el_map.current = el->el_map.key;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
el->el_chared.c_vcmd.pos = el->el_line.cursor;
el->el_chared.c_vcmd.action = c;
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
/* cv_paste():
@@ -96,7 +96,7 @@ cv_paste(EditLine *el, Int c)
size_t len = (size_t)(k->last - k->buf);
if (k->buf == NULL || len == 0)
- return (CC_ERROR);
+ return CC_ERROR;
#ifdef DEBUG_PASTE
(void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", (int)len, k->buf);
#endif
@@ -108,11 +108,11 @@ cv_paste(EditLine *el, Int c)
c_insert(el, (int)len);
if (el->el_line.cursor + len > el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
(void) memcpy(el->el_line.cursor, k->buf, len *
sizeof(*el->el_line.cursor));
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -125,7 +125,7 @@ protected el_action_t
vi_paste_next(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_paste(el, 0));
+ return cv_paste(el, 0);
}
@@ -138,7 +138,7 @@ protected el_action_t
vi_paste_prev(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_paste(el, 1));
+ return cv_paste(el, 1);
}
@@ -152,7 +152,7 @@ vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv_prev_word(el->el_line.cursor,
el->el_line.buffer,
@@ -161,9 +161,9 @@ vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -177,7 +177,7 @@ vi_prev_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv_prev_word(el->el_line.cursor,
el->el_line.buffer,
@@ -186,9 +186,9 @@ vi_prev_word(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -202,7 +202,7 @@ vi_next_big_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor >= el->el_line.lastchar - 1)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
el->el_line.lastchar, el->el_state.argument, cv__isWord);
@@ -210,9 +210,9 @@ vi_next_big_word(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -226,7 +226,7 @@ vi_next_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor >= el->el_line.lastchar - 1)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
el->el_line.lastchar, el->el_state.argument, cv__isword);
@@ -234,9 +234,9 @@ vi_next_word(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -250,7 +250,7 @@ vi_change_case(EditLine *el, Int c)
int i;
if (el->el_line.cursor >= el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
cv_undo(el);
for (i = 0; i < el->el_state.argument; i++) {
@@ -284,7 +284,7 @@ vi_change_meta(EditLine *el, Int c __attribute__((__unused__)))
* Delete with insert == change: first we delete and then we leave in
* insert mode.
*/
- return (cv_action(el, DELETE | INSERT));
+ return cv_action(el, DELETE | INSERT);
}
@@ -300,7 +300,7 @@ vi_insert_at_bol(EditLine *el, Int c __attribute__((__unused__)))
el->el_line.cursor = el->el_line.buffer;
cv_undo(el);
el->el_map.current = el->el_map.key;
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -319,7 +319,7 @@ vi_replace_char(EditLine *el, Int c __attribute__((__unused__)))
el->el_map.current = el->el_map.key;
el->el_state.inputmode = MODE_REPLACE_1;
cv_undo(el);
- return (CC_ARGHACK);
+ return CC_ARGHACK;
}
@@ -335,7 +335,7 @@ vi_replace_mode(EditLine *el, Int c __attribute__((__unused__)))
el->el_map.current = el->el_map.key;
el->el_state.inputmode = MODE_REPLACE;
cv_undo(el);
- return (CC_NORM);
+ return CC_NORM;
}
@@ -350,7 +350,7 @@ vi_substitute_char(EditLine *el, Int c __attribute__((__unused__)))
c_delafter(el, el->el_state.argument);
el->el_map.current = el->el_map.key;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -368,7 +368,7 @@ vi_substitute_line(EditLine *el, Int c __attribute__((__unused__)))
(int)(el->el_line.lastchar - el->el_line.buffer));
(void) em_kill_line(el, 0);
el->el_map.current = el->el_map.key;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -386,7 +386,7 @@ vi_change_to_eol(EditLine *el, Int c __attribute__((__unused__)))
(int)(el->el_line.lastchar - el->el_line.cursor));
(void) ed_kill_line(el, 0);
el->el_map.current = el->el_map.key;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -401,7 +401,7 @@ vi_insert(EditLine *el, Int c __attribute__((__unused__)))
el->el_map.current = el->el_map.key;
cv_undo(el);
- return (CC_NORM);
+ return CC_NORM;
}
@@ -426,7 +426,7 @@ vi_add(EditLine *el, Int c __attribute__((__unused__)))
cv_undo(el);
- return (ret);
+ return (el_action_t)ret;
}
@@ -442,7 +442,7 @@ vi_add_at_eol(EditLine *el, Int c __attribute__((__unused__)))
el->el_map.current = el->el_map.key;
el->el_line.cursor = el->el_line.lastchar;
cv_undo(el);
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -455,7 +455,7 @@ protected el_action_t
vi_delete_meta(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_action(el, DELETE));
+ return cv_action(el, DELETE);
}
@@ -465,11 +465,11 @@ vi_delete_meta(EditLine *el, Int c __attribute__((__unused__)))
*/
protected el_action_t
/*ARGSUSED*/
-vi_end_big_word(EditLine *el, Int c)
+vi_end_big_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv__endword(el->el_line.cursor,
el->el_line.lastchar, el->el_state.argument, cv__isWord);
@@ -477,9 +477,9 @@ vi_end_big_word(EditLine *el, Int c)
if (el->el_chared.c_vcmd.action != NOP) {
el->el_line.cursor++;
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -493,7 +493,7 @@ vi_end_word(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor == el->el_line.lastchar)
- return (CC_ERROR);
+ return CC_ERROR;
el->el_line.cursor = cv__endword(el->el_line.cursor,
el->el_line.lastchar, el->el_state.argument, cv__isword);
@@ -501,9 +501,9 @@ vi_end_word(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_chared.c_vcmd.action != NOP) {
el->el_line.cursor++;
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -530,7 +530,7 @@ vi_undo(EditLine *el, Int c __attribute__((__unused__)))
el->el_line.cursor = un.buf + un.cursor;
el->el_line.lastchar = un.buf + un.len;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -555,7 +555,7 @@ vi_command_mode(EditLine *el, Int c __attribute__((__unused__)))
if (el->el_line.cursor > el->el_line.buffer)
el->el_line.cursor--;
#endif
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -573,9 +573,9 @@ vi_zero(EditLine *el, Int c)
el->el_line.cursor = el->el_line.buffer;
if (el->el_chared.c_vcmd.action != NOP) {
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
@@ -589,11 +589,11 @@ vi_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_line.cursor <= el->el_line.buffer)
- return (CC_ERROR);
+ return CC_ERROR;
c_delbefore1(el);
el->el_line.cursor--;
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -608,27 +608,27 @@ vi_list_or_eof(EditLine *el, Int c)
if (el->el_line.cursor == el->el_line.lastchar) {
if (el->el_line.cursor == el->el_line.buffer) {
- term_writec(el, c); /* then do a EOF */
- return (CC_EOF);
+ terminal_writec(el, c); /* then do a EOF */
+ return CC_EOF;
} else {
/*
* Here we could list completions, but it is an
* error right now
*/
- term_beep(el);
- return (CC_ERROR);
+ terminal_beep(el);
+ return CC_ERROR;
}
} else {
#ifdef notyet
re_goto_bottom(el);
*el->el_line.lastchar = '\0'; /* just in case */
- return (CC_LIST_CHOICES);
+ return CC_LIST_CHOICES;
#else
/*
* Just complain for now.
*/
- term_beep(el);
- return (CC_ERROR);
+ terminal_beep(el);
+ return CC_ERROR;
#endif
}
}
@@ -651,7 +651,7 @@ vi_kill_line_prev(EditLine *el, Int c __attribute__((__unused__)))
el->el_chared.c_kill.last = kp;
c_delbefore(el, (int)(el->el_line.cursor - el->el_line.buffer));
el->el_line.cursor = el->el_line.buffer; /* zap! */
- return (CC_REFRESH);
+ return CC_REFRESH;
}
@@ -664,7 +664,7 @@ protected el_action_t
vi_search_prev(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_search(el, ED_SEARCH_PREV_HISTORY));
+ return cv_search(el, ED_SEARCH_PREV_HISTORY);
}
@@ -677,7 +677,7 @@ protected el_action_t
vi_search_next(EditLine *el, Int c __attribute__((__unused__)))
{
- return (cv_search(el, ED_SEARCH_NEXT_HISTORY));
+ return cv_search(el, ED_SEARCH_NEXT_HISTORY);
}
@@ -691,9 +691,9 @@ vi_repeat_search_next(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_search.patlen == 0)
- return (CC_ERROR);
+ return CC_ERROR;
else
- return (cv_repeat_srch(el, el->el_search.patdir));
+ return cv_repeat_srch(el, el->el_search.patdir);
}
@@ -707,7 +707,7 @@ vi_repeat_search_prev(EditLine *el, Int c __attribute__((__unused__)))
{
if (el->el_search.patlen == 0)
- return (CC_ERROR);
+ return CC_ERROR;
else
return (cv_repeat_srch(el,
el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?
@@ -801,7 +801,7 @@ vi_repeat_prev_char(EditLine *el, Int c __attribute__((__unused__)))
*/
protected el_action_t
/*ARGSUSED*/
-vi_match(EditLine *el, Int c)
+vi_match(EditLine *el, Int c __attribute__((__unused__)))
{
const Char match_chars[] = STR("()[]{}");
Char *cp;
@@ -814,7 +814,7 @@ vi_match(EditLine *el, Int c)
o_ch = el->el_line.cursor[i];
if (o_ch == 0)
return CC_ERROR;
- delta = Strchr(match_chars, o_ch) - match_chars;
+ delta = (size_t)(Strchr(match_chars, o_ch) - match_chars);
c_ch = match_chars[delta ^ 1];
count = 1;
delta = 1 - (delta & 1) * 2;
@@ -837,9 +837,9 @@ vi_match(EditLine *el, Int c)
if (delta > 0)
el->el_line.cursor++;
cv_delfini(el);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
- return (CC_CURSOR);
+ return CC_CURSOR;
}
/* vi_undo_line():
@@ -848,7 +848,7 @@ vi_match(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_undo_line(EditLine *el, Int c)
+vi_undo_line(EditLine *el, Int c __attribute__((__unused__)))
{
cv_undo(el);
@@ -862,7 +862,7 @@ vi_undo_line(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_to_column(EditLine *el, Int c)
+vi_to_column(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_line.cursor = el->el_line.buffer;
@@ -876,7 +876,7 @@ vi_to_column(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_yank_end(EditLine *el, Int c)
+vi_yank_end(EditLine *el, Int c __attribute__((__unused__)))
{
cv_yank(el, el->el_line.cursor,
@@ -890,7 +890,7 @@ vi_yank_end(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_yank(EditLine *el, Int c)
+vi_yank(EditLine *el, Int c __attribute__((__unused__)))
{
return cv_action(el, YANK);
@@ -902,7 +902,7 @@ vi_yank(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_comment_out(EditLine *el, Int c)
+vi_comment_out(EditLine *el, Int c __attribute__((__unused__)))
{
el->el_line.cursor = el->el_line.buffer;
@@ -919,17 +919,18 @@ vi_comment_out(EditLine *el, Int c)
* this is against historical precedent...
*/
#ifdef __weak_reference
-extern char *get_alias_text(const char *) __weak_reference(get_alias_text);
+__weakref_visible char *my_get_alias_text(const char *)
+ __weak_reference(get_alias_text);
#endif
protected el_action_t
/*ARGSUSED*/
-vi_alias(EditLine *el, Int c)
+vi_alias(EditLine *el, Int c __attribute__((__unused__)))
{
#ifdef __weak_reference
char alias_name[3];
char *alias_text;
- if (get_alias_text == 0) {
+ if (my_get_alias_text == 0) {
return CC_ERROR;
}
@@ -938,7 +939,7 @@ vi_alias(EditLine *el, Int c)
if (el_getc(el, &alias_name[1]) != 1)
return CC_ERROR;
- alias_text = get_alias_text(alias_name);
+ alias_text = my_get_alias_text(alias_name);
if (alias_text != NULL)
FUN(el,push)(el, ct_decode_string(alias_text, &el->el_scratch));
return CC_NORM;
@@ -953,7 +954,7 @@ vi_alias(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_to_history_line(EditLine *el, Int c)
+vi_to_history_line(EditLine *el, Int c __attribute__((__unused__)))
{
int sv_event_no = el->el_history.eventno;
el_action_t rval;
@@ -998,16 +999,16 @@ vi_to_history_line(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_histedit(EditLine *el, Int c)
+vi_histedit(EditLine *el, Int c __attribute__((__unused__)))
{
int fd;
pid_t pid;
ssize_t st;
int status;
char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
- char *cp;
+ char *cp = NULL;
size_t len;
- Char *line;
+ Char *line = NULL;
if (el->el_state.doingarg) {
if (vi_to_history_line(el, 0) == CC_ERROR)
@@ -1019,29 +1020,23 @@ vi_histedit(EditLine *el, Int c)
return CC_ERROR;
len = (size_t)(el->el_line.lastchar - el->el_line.buffer);
#define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX)
- cp = el_malloc(TMP_BUFSIZ);
+ cp = el_malloc(TMP_BUFSIZ * sizeof(*cp));
if (cp == NULL)
- return CC_ERROR;
- line = el_malloc(len * sizeof(*line));
- if (line == NULL) {
- el_free((ptr_t)cp);
- return CC_ERROR;
- }
+ goto error;
+ line = el_malloc(len * sizeof(*line) + 1);
+ if (line == NULL)
+ goto error;
Strncpy(line, el->el_line.buffer, len);
line[len] = '\0';
ct_wcstombs(cp, line, TMP_BUFSIZ - 1);
cp[TMP_BUFSIZ - 1] = '\0';
len = strlen(cp);
write(fd, cp, len);
- write(fd, "\n", 1);
+ write(fd, "\n", (size_t)1);
pid = fork();
switch (pid) {
case -1:
- close(fd);
- unlink(tempfile);
- el_free(cp);
- el_free(line);
- return CC_ERROR;
+ goto error;
case 0:
close(fd);
execlp("vi", "vi", tempfile, (char *)NULL);
@@ -1072,6 +1067,12 @@ vi_histedit(EditLine *el, Int c)
unlink(tempfile);
/* return CC_REFRESH; */
return ed_newline(el, 0);
+error:
+ el_free(line);
+ el_free(cp);
+ close(fd);
+ unlink(tempfile);
+ return CC_ERROR;
}
/* vi_history_word():
@@ -1082,7 +1083,7 @@ vi_histedit(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_history_word(EditLine *el, Int c)
+vi_history_word(EditLine *el, Int c __attribute__((__unused__)))
{
const Char *wp = HIST_FIRST(el);
const Char *wep, *wsp;
@@ -1132,7 +1133,7 @@ vi_history_word(EditLine *el, Int c)
*/
protected el_action_t
/*ARGSUSED*/
-vi_redo(EditLine *el, Int c)
+vi_redo(EditLine *el, Int c __attribute__((__unused__)))
{
c_redo_t *r = &el->el_chared.c_redo;
@@ -1153,5 +1154,5 @@ vi_redo(EditLine *el, Int c)
el->el_state.thiscmd = r->cmd;
el->el_state.thisch = r->ch;
- return (*el->el_map.func[r->cmd])(el, r->ch);
+ return (*el->el_map.func[r->cmd])(el, r->ch);
}