Vendor import NetBSD's libedit of "2012/09/25 10:41:11 UTC".

Obtained from:	NetBSD
This commit is contained in:
Ed Schouten 2012-09-25 10:41:30 +00:00
parent c83d78a785
commit 4935023390
Notes: svn2git 2020-12-20 02:59:44 +00:00
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
39 changed files with 2363 additions and 2042 deletions

View File

@ -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

59
TEST/rl1.c Normal file
View File

@ -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;
}

View File

@ -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");

144
chared.c
View File

@ -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;
}

View File

@ -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 *);

View File

@ -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')

View File

@ -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

156
common.c
View File

@ -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);

295
config.h
View File

@ -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 HAVE_STRLCAT 1
#define HAVE_STRLCPY 1
#define HAVE_FGETLN 1
#define HAVE_STRVIS 1
#define HAVE_STRUNVIS 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 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 */

View File

@ -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

View File

@ -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

131
el.c
View File

@ -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;
}

14
el.h
View File

@ -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 */

34
eln.c
View File

@ -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;
}

74
emacs.c
View File

@ -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;
}

View File

@ -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;
cols = (size_t)screenwidth / (width + 1);
if (cols == 0)
cols = 1;
/* how many lines of output */
count = len / limit;
if (count * limit < len)
count++;
/* how many lines of output, rounded up */
lines = (num + cols - 1) / cols;
/* Sort the items if they are not already sorted. */
qsort(&matches[1], (size_t)(len - 1), sizeof(char *),
_fn_qsort_string_compare);
/* Sort the items. */
qsort(matches, num, 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 ? " " : "");
/*
* 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);
}

38
hist.c
View File

@ -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)

10
hist.h
View File

@ -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 */

View File

@ -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)

248
history.c
View File

@ -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_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(ptr_t *, TYPE(HistEvent) *, 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 @@ history_def_insert(history_t *h, TYPE(HistEvent) *ev, const Char *str)
* 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);

View File

@ -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 @@ key__decode_str(const Char *str, char *buf, size_t len, const char *sep)
buf[len - 1] = '\0';
return (size_t)(b - buf);
}

View File

@ -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 */

View File

@ -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");
}'
;;

155
map.c
View File

@ -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;
}

48
parse.c
View File

@ -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;
}

View File

@ -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);
}

141
read.c
View File

@ -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) {

File diff suppressed because it is too large Load Diff

View File

@ -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);

152
refresh.c
View File

@ -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 */
}
}

View File

@ -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;
}
}

8
sig.c
View File

@ -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;
}

69
sys.h
View File

@ -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 */

File diff suppressed because it is too large Load Diff

View File

@ -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 */

View File

@ -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));
}

138
tty.c
View File

@ -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;
}

6
tty.h
View File

@ -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;

187
vi.c
View File

@ -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);
}