diff options
Diffstat (limited to 'lib')
45 files changed, 725 insertions, 685 deletions
diff --git a/lib/libc/db/db/db.c b/lib/libc/db/db/db.c index 3cfd0a9..b01ae08 100644 --- a/lib/libc/db/db/db.c +++ b/lib/libc/db/db/db.c @@ -44,6 +44,10 @@ __FBSDID("$FreeBSD$"); static int __dberr(void); +#ifndef O_CLOEXEC +#define O_CLOEXEC 0 +#endif + DB * dbopen(const char *fname, int flags, int mode, DBTYPE type, const void *openinfo) { @@ -51,7 +55,7 @@ dbopen(const char *fname, int flags, int mode, DBTYPE type, const void *openinfo #define DB_FLAGS (DB_LOCK | DB_SHMEM | DB_TXN) #define USE_OPEN_FLAGS \ (O_CREAT | O_EXCL | O_EXLOCK | O_NOFOLLOW | O_NONBLOCK | \ - O_RDONLY | O_RDWR | O_SHLOCK | O_SYNC | O_TRUNC) + O_RDONLY | O_RDWR | O_SHLOCK | O_SYNC | O_TRUNC | O_CLOEXEC) if ((flags & ~(USE_OPEN_FLAGS | DB_FLAGS)) == 0) switch (type) { diff --git a/lib/libc/tests/string/Makefile b/lib/libc/tests/string/Makefile index b769529..a8db9c3 100644 --- a/lib/libc/tests/string/Makefile +++ b/lib/libc/tests/string/Makefile @@ -4,6 +4,7 @@ PACKAGE= tests FILESGROUPS= TESTS TESTSPACKAGE= ${PACKAGE} +ATF_TESTS_C+= memcmp_test ATF_TESTS_C+= stpncpy_test ATF_TESTS_C+= strerror2_test ATF_TESTS_C+= wcscasecmp_test diff --git a/lib/libc/tests/string/memcmp_test.c b/lib/libc/tests/string/memcmp_test.c new file mode 100644 index 0000000..d7fbd8c --- /dev/null +++ b/lib/libc/tests/string/memcmp_test.c @@ -0,0 +1,124 @@ +/*- + * Copyright (c) 2016 Jilles Tjoelker <jilles@FreeBSD.org> + * All rights reserved. + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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> +__FBSDID("$FreeBSD$"); + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <atf-c.h> + +ATF_TC_WITHOUT_HEAD(zero); +ATF_TC_BODY(zero, tc) +{ + + assert(memcmp("a", "b", 0) == 0); + assert(memcmp("", "", 0) == 0); +} + +ATF_TC_WITHOUT_HEAD(eq); +ATF_TC_BODY(eq, tc) +{ + unsigned char data1[256], data2[256]; + int i; + + for (i = 0; i < 256; i++) + data1[i] = data2[i] = i ^ 0x55; + for (i = 1; i < 256; i++) + assert(memcmp(data1, data2, i) == 0); + for (i = 1; i < 256; i++) + assert(memcmp(data1 + i, data2 + i, 256 - i) == 0); +} + +ATF_TC_WITHOUT_HEAD(neq); +ATF_TC_BODY(neq, tc) +{ + unsigned char data1[256], data2[256]; + int i; + + for (i = 0; i < 256; i++) { + data1[i] = i; + data2[i] = i ^ 0x55; + } + for (i = 1; i < 256; i++) + assert(memcmp(data1, data2, i) != 0); + for (i = 1; i < 256; i++) + assert(memcmp(data1 + i, data2 + i, 256 - i) != 0); +} + +ATF_TC_WITHOUT_HEAD(diff); +ATF_TC_BODY(diff, tc) +{ + unsigned char data1[256], data2[256]; + int i; + + memset(data1, 'a', sizeof(data1)); + memset(data2, 'a', sizeof(data2)); + data1[128] = 255; + data2[128] = 0; + for (i = 1; i < 66; i++) { + assert(memcmp(data1 + 128, data2 + 128, i) == 255); + assert(memcmp(data2 + 128, data1 + 128, i) == -255); + assert(memcmp(data1 + 129 - i, data2 + 129 - i, i) == 255); + assert(memcmp(data2 + 129 - i, data1 + 129 - i, i) == -255); + assert(memcmp(data1 + 129 - i, data2 + 129 - i, i * 2) == 255); + assert(memcmp(data2 + 129 - i, data1 + 129 - i, i * 2) == -255); + } + data1[128] = 'c'; + data2[128] = 'e'; + for (i = 1; i < 66; i++) { + assert(memcmp(data1 + 128, data2 + 128, i) == -2); + assert(memcmp(data2 + 128, data1 + 128, i) == 2); + assert(memcmp(data1 + 129 - i, data2 + 129 - i, i) == -2); + assert(memcmp(data2 + 129 - i, data1 + 129 - i, i) == 2); + assert(memcmp(data1 + 129 - i, data2 + 129 - i, i * 2) == -2); + assert(memcmp(data2 + 129 - i, data1 + 129 - i, i * 2) == 2); + } + memset(data1 + 129, 'A', sizeof(data1) - 129); + memset(data2 + 129, 'Z', sizeof(data2) - 129); + for (i = 1; i < 66; i++) { + assert(memcmp(data1 + 128, data2 + 128, i) == -2); + assert(memcmp(data2 + 128, data1 + 128, i) == 2); + assert(memcmp(data1 + 129 - i, data2 + 129 - i, i) == -2); + assert(memcmp(data2 + 129 - i, data1 + 129 - i, i) == 2); + assert(memcmp(data1 + 129 - i, data2 + 129 - i, i * 2) == -2); + assert(memcmp(data2 + 129 - i, data1 + 129 - i, i * 2) == 2); + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, zero); + ATF_TP_ADD_TC(tp, eq); + ATF_TP_ADD_TC(tp, neq); + ATF_TP_ADD_TC(tp, diff); + + return (atf_no_error()); +} diff --git a/lib/libedit/Makefile b/lib/libedit/Makefile index 47a333b..14c9cbb 100644 --- a/lib/libedit/Makefile +++ b/lib/libedit/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.55 2016/02/24 14:25:38 christos Exp $ +# $NetBSD: Makefile,v 1.37 2009/01/18 12:17:49 lukem Exp $ # @(#)Makefile 8.1 (Berkeley) 6/4/93 # $FreeBSD$ @@ -7,7 +7,7 @@ LIB= edit SHLIB_MAJOR= 7 SHLIBDIR?= /lib -OSRCS= chared.c common.c el.c eln.c emacs.c fcns.c filecomplete.c help.c \ +OSRCS= chared.c common.c el.c emacs.c fcns.c filecomplete.c help.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 @@ -35,6 +35,7 @@ CLEANFILES+= common.h editline.c emacs.h fcns.c fcns.h help.c help.h vi.h INCS= histedit.h +OSRCS+= eln.c SRCS+= tokenizern.c historyn.c CLEANFILES+= tokenizern.c historyn.c CFLAGS+= -I. -I${.CURDIR} -I${.CURDIR}/edit -DWIDECHAR diff --git a/lib/libedit/TEST/tc1.c b/lib/libedit/TEST/tc1.c index 1dca813..1969973 100644 --- a/lib/libedit/TEST/tc1.c +++ b/lib/libedit/TEST/tc1.c @@ -1,4 +1,4 @@ -/* $NetBSD: tc1.c,v 1.7 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: tc1.c,v 1.6 2014/06/18 20:12:15 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -42,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\ #if 0 static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tc1.c,v 1.7 2016/02/17 19:47:49 christos Exp $"); +__RCSID("$NetBSD: tc1.c,v 1.6 2014/06/18 20:12:15 christos Exp $"); #endif #endif /* not lint && not SCCSID */ __FBSDID("$FreeBSD$"); @@ -50,15 +50,15 @@ __FBSDID("$FreeBSD$"); /* * test.c: A little test program */ +#include <stdio.h> +#include <string.h> +#include <signal.h> #include <sys/wait.h> #include <ctype.h> -#include <dirent.h> -#include <locale.h> -#include <signal.h> -#include <stdio.h> #include <stdlib.h> -#include <string.h> #include <unistd.h> +#include <dirent.h> +#include <locale.h> #include "histedit.h" @@ -158,7 +158,7 @@ main(int argc, char *argv[]) /* Add a user-defined function */ el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete); - /* Bind tab to it */ + /* Bind tab to it */ el_set(el, EL_BIND, "^I", "ed-complete", NULL); /* diff --git a/lib/libedit/TEST/wtc1.c b/lib/libedit/TEST/wtc1.c index c4a2376..ec5574b 100644 --- a/lib/libedit/TEST/wtc1.c +++ b/lib/libedit/TEST/wtc1.c @@ -5,16 +5,13 @@ __FBSDID("$FreeBSD$"); #include <string.h> #include <signal.h> #include <sys/wait.h> +#include <err.h> #include <ctype.h> +#include <stdlib.h> +#include <unistd.h> #include <dirent.h> -#include <err.h> #include <limits.h> #include <locale.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> #include "../histedit.h" diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c index 9ec618e..2b57051 100644 --- a/lib/libedit/chared.c +++ b/lib/libedit/chared.c @@ -1,4 +1,4 @@ -/* $NetBSD: chared.c,v 1.49 2016/02/24 14:29:21 christos Exp $ */ +/* $NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 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.49 2016/02/24 14:29:21 christos Exp $"); +__RCSID("$NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -46,12 +46,8 @@ __FBSDID("$FreeBSD$"); /* * chared.c: Character editor utilities */ -#include <ctype.h> #include <stdlib.h> -#include <string.h> - #include "el.h" -#include "common.h" private void ch__clearmacro (EditLine *); @@ -205,7 +201,7 @@ c_delbefore1(EditLine *el) * Return if p is part of a word according to emacs */ protected int -ce__isword(wint_t p) +ce__isword(Int p) { return Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL; } @@ -215,7 +211,7 @@ ce__isword(wint_t p) * Return if p is part of a word according to vi */ protected int -cv__isword(wint_t p) +cv__isword(Int p) { if (Isalnum(p) || p == '_') return 1; @@ -229,7 +225,7 @@ cv__isword(wint_t p) * Return if p is part of a big word according to vi */ protected int -cv__isWord(wint_t p) +cv__isWord(Int p) { return !Isspace(p); } @@ -239,7 +235,7 @@ cv__isWord(wint_t p) * Find the previous word */ protected Char * -c__prev_word(Char *p, Char *low, int n, int (*wtest)(wint_t)) +c__prev_word(Char *p, Char *low, int n, int (*wtest)(Int)) { p--; @@ -263,7 +259,7 @@ c__prev_word(Char *p, Char *low, int n, int (*wtest)(wint_t)) * Find the next word */ protected Char * -c__next_word(Char *p, Char *high, int n, int (*wtest)(wint_t)) +c__next_word(Char *p, Char *high, int n, int (*wtest)(Int)) { while (n--) { while ((p < high) && !(*wtest)(*p)) @@ -281,7 +277,7 @@ c__next_word(Char *p, Char *high, int n, int (*wtest)(wint_t)) * Find the next word vi style */ protected Char * -cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(wint_t)) +cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int)) { int test; @@ -310,7 +306,7 @@ cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(wint_t)) * Find the previous word vi style */ protected Char * -cv_prev_word(Char *p, Char *low, int n, int (*wtest)(wint_t)) +cv_prev_word(Char *p, Char *low, int n, int (*wtest)(Int)) { int test; @@ -374,7 +370,7 @@ cv_delfini(EditLine *el) * Go to the end of this word according to vi */ protected Char * -cv__endword(Char *p, Char *high, int n, int (*wtest)(wint_t)) +cv__endword(Char *p, Char *high, int n, int (*wtest)(Int)) { int test; @@ -528,7 +524,7 @@ ch_enlargebufs(EditLine *el, size_t addlen) /* zero the newly added memory, leave old data in */ (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer)); - + oldbuf = el->el_line.buffer; el->el_line.buffer = newbuffer; @@ -577,7 +573,7 @@ ch_enlargebufs(EditLine *el, size_t addlen) el->el_chared.c_redo.lim = newbuffer + (el->el_chared.c_redo.lim - el->el_chared.c_redo.buf); el->el_chared.c_redo.buf = newbuffer; - + if (!hist_enlargebuf(el, sz, newsz)) return 0; @@ -677,9 +673,9 @@ out: protected int c_gets(EditLine *el, Char *buf, const Char *prompt) { - wchar_t wch; + Char ch; ssize_t len; - Char *cp = el->el_line.buffer, ch; + Char *cp = el->el_line.buffer; if (prompt) { len = (ssize_t)Strlen(prompt); @@ -694,28 +690,26 @@ c_gets(EditLine *el, Char *buf, const Char *prompt) el->el_line.lastchar = cp + 1; re_refresh(el); - if (el_wgetc(el, &wch) != 1) { + if (FUN(el,getc)(el, &ch) != 1) { ed_end_of_file(el, 0); len = -1; break; } - ch = (Char)wch; switch (ch) { - case L'\b': /* Delete and backspace */ + case 0010: /* Delete and backspace */ case 0177: if (len == 0) { len = -1; break; } - len--; cp--; continue; case 0033: /* ESC */ - case L'\r': /* Newline */ - case L'\n': + case '\r': /* Newline */ + case '\n': buf[len] = ch; break; diff --git a/lib/libedit/chared.h b/lib/libedit/chared.h index 458e671..909adac 100644 --- a/lib/libedit/chared.h +++ b/lib/libedit/chared.h @@ -1,4 +1,4 @@ -/* $NetBSD: chared.h,v 1.27 2016/02/16 22:53:14 christos Exp $ */ +/* $NetBSD: chared.h,v 1.22 2014/06/18 18:12:28 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,6 +41,11 @@ #ifndef _h_el_chared #define _h_el_chared +#include <ctype.h> +#include <string.h> + +#include "histedit.h" + #define EL_MAXMACRO 10 /* @@ -135,18 +140,24 @@ typedef struct el_chared_t { #define MODE_REPLACE 1 #define MODE_REPLACE_1 2 +#include "common.h" +#include "vi.h" +#include "emacs.h" +#include "search.h" +#include "fcns.h" + -protected int cv__isword(wint_t); -protected int cv__isWord(wint_t); +protected int cv__isword(Int); +protected int cv__isWord(Int); protected void cv_delfini(EditLine *); -protected Char *cv__endword(Char *, Char *, int, int (*)(wint_t)); -protected int ce__isword(wint_t); +protected Char *cv__endword(Char *, Char *, int, int (*)(Int)); +protected int ce__isword(Int); protected void cv_undo(EditLine *); protected void cv_yank(EditLine *, const Char *, int); -protected Char *cv_next_word(EditLine*, Char *, Char *, int, int (*)(wint_t)); -protected Char *cv_prev_word(Char *, Char *, int, int (*)(wint_t)); -protected Char *c__next_word(Char *, Char *, int, int (*)(wint_t)); -protected Char *c__prev_word(Char *, Char *, int, int (*)(wint_t)); +protected Char *cv_next_word(EditLine*, Char *, Char *, int, int (*)(Int)); +protected Char *cv_prev_word(Char *, Char *, int, int (*)(Int)); +protected Char *c__next_word(Char *, Char *, int, int (*)(Int)); +protected Char *c__prev_word(Char *, Char *, int, int (*)(Int)); protected void c_insert(EditLine *, int); protected void c_delbefore(EditLine *, int); protected void c_delbefore1(EditLine *); diff --git a/lib/libedit/chartype.c b/lib/libedit/chartype.c index 9cb54ac..c240c8c 100644 --- a/lib/libedit/chartype.c +++ b/lib/libedit/chartype.c @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.c,v 1.23 2016/02/28 23:02:24 christos Exp $ */ +/* $NetBSD: chartype.c,v 1.12 2015/02/22 02:16:19 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -31,16 +31,13 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: chartype.c,v 1.23 2016/02/28 23:02:24 christos Exp $"); +__RCSID("$NetBSD: chartype.c,v 1.12 2015/02/22 02:16:19 christos Exp $"); #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <ctype.h> -#include <stdlib.h> -#include <string.h> - #include "el.h" +#include <stdlib.h> #define CT_BUFSIZ ((size_t)1024) @@ -71,7 +68,7 @@ ct_conv_wbuff_resize(ct_buffer_t *conv, size_t wsize) { void *p; - if (wsize <= conv->wsize) + if (wsize <= conv->wsize) return 0; conv->wsize = wsize; @@ -209,28 +206,6 @@ ct_encode_char(char *dst, size_t len, Char c) } return l; } - -size_t -ct_mbrtowc(wchar_t *wc, const char *s, size_t n) -{ - mbstate_t mbs; - /* This only works because UTF-8 is stateless */ - memset(&mbs, 0, sizeof(mbs)); - return mbrtowc(wc, s, n, &mbs); -} - -#else - -size_t -ct_mbrtowc(wchar_t *wc, const char *s, size_t n) - if (s == NULL) - return 0; - if (n == 0) - return (size_t)-2; - if (wc != NULL) - *wc = *s; - return *s != '\0'; -} #endif protected const Char * @@ -354,7 +329,7 @@ ct_visual_char(Char *dst, size_t len, Char c) return c > 0xffff ? 8 : 7; #else *dst++ = '\\'; -#define tooctaldigit(v) (Char)((v) + '0') +#define tooctaldigit(v) ((v) + '0') *dst++ = tooctaldigit(((unsigned int) c >> 6) & 0x7); *dst++ = tooctaldigit(((unsigned int) c >> 3) & 0x7); *dst++ = tooctaldigit(((unsigned int) c ) & 0x7); diff --git a/lib/libedit/chartype.h b/lib/libedit/chartype.h index 44ef33a..17ca5f3 100644 --- a/lib/libedit/chartype.h +++ b/lib/libedit/chartype.h @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.h,v 1.23 2016/02/24 17:20:01 christos Exp $ */ +/* $NetBSD: chartype.h,v 1.15 2015/05/17 13:14:41 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -32,6 +32,7 @@ #define _h_chartype_f + #ifdef WIDECHAR /* Ideally we should also test the value of the define to see if it @@ -54,18 +55,21 @@ #warning Build environment does not support non-BMP characters #endif -#define ct_wctob wctob +#define ct_mbtowc mbtowc +#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 #define ct_mbstowcs mbstowcs #define Char wchar_t +#define Int wint_t #define FUN(prefix,rest) prefix ## _w ## rest #define FUNW(type) type ## _w #define TYPE(type) type ## W +#define FCHAR "%lc" #define FSTR "%ls" -#define STR(x) L ## x +#define STR(x) L ## x #define UC(c) c #define Isalpha(x) iswalpha(x) #define Isalnum(x) iswalnum(x) @@ -106,18 +110,21 @@ Width(wchar_t c) #else /* NARROW */ -#define ct_wctob(w) ((int)(w)) +#define ct_mbtowc error +#define ct_mbtowc_reset #define ct_wctomb error -#define ct_wctomb_reset +#define ct_wctomb_reset #define ct_wcstombs(a, b, c) (strncpy(a, b, c), strlen(a)) #define ct_mbstowcs(a, b, c) (strncpy(a, b, c), strlen(a)) #define Char char +#define Int int #define FUN(prefix,rest) prefix ## _ ## rest #define FUNW(type) type #define TYPE(type) type +#define FCHAR "%c" #define FSTR "%s" -#define STR(x) x +#define STR(x) x #define UC(c) (unsigned char)(c) #define Isalpha(x) isalpha((unsigned char)x) @@ -206,7 +213,7 @@ protected size_t ct_enc_width(Char); #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 + * where a wide character takes up more than one column, the adjacent * occupied column entries will contain this faux character. */ #define MB_FILL_CHAR ((Char)-1) @@ -238,7 +245,5 @@ protected const Char *ct_visual_string(const Char *); protected int ct_chr_class(Char c); #endif -size_t ct_mbrtowc(wchar_t *, const char *, size_t); - #endif /* _chartype_f */ diff --git a/lib/libedit/common.c b/lib/libedit/common.c index 26e4289..fc09a9b 100644 --- a/lib/libedit/common.c +++ b/lib/libedit/common.c @@ -1,4 +1,4 @@ -/* $NetBSD: common.c,v 1.39 2016/02/24 14:25:38 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.39 2016/02/24 14:25:38 christos Exp $"); +__RCSID("$NetBSD: common.c,v 1.29 2012/03/24 20:08:43 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -46,13 +46,7 @@ __FBSDID("$FreeBSD$"); /* * common.c: Common Editor functions */ -#include <ctype.h> -#include <string.h> - #include "el.h" -#include "common.h" -#include "parse.h" -#include "vi.h" /* ed_end_of_file(): * Indicate end of file @@ -60,7 +54,7 @@ __FBSDID("$FreeBSD$"); */ protected el_action_t /*ARGSUSED*/ -ed_end_of_file(EditLine *el, wint_t c __attribute__((__unused__))) +ed_end_of_file(EditLine *el, Int c __attribute__((__unused__))) { re_goto_bottom(el); @@ -74,7 +68,7 @@ ed_end_of_file(EditLine *el, wint_t c __attribute__((__unused__))) * Insert a character [bound to all insert keys] */ protected el_action_t -ed_insert(EditLine *el, wint_t c) +ed_insert(EditLine *el, Int c) { int count = el->el_state.argument; @@ -93,14 +87,14 @@ ed_insert(EditLine *el, wint_t c) || el->el_line.cursor >= el->el_line.lastchar) c_insert(el, 1); - *el->el_line.cursor++ = (Char)c; + *el->el_line.cursor++ = c; re_fastaddc(el); /* fast refresh for one char. */ } else { if (el->el_state.inputmode != MODE_REPLACE_1) c_insert(el, el->el_state.argument); while (count-- && el->el_line.cursor < el->el_line.lastchar) - *el->el_line.cursor++ = (Char)c; + *el->el_line.cursor++ = c; re_refresh(el); } @@ -117,7 +111,7 @@ ed_insert(EditLine *el, wint_t c) */ protected el_action_t /*ARGSUSED*/ -ed_delete_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) +ed_delete_prev_word(EditLine *el, Int c __attribute__((__unused__))) { Char *cp, *p, *kp; @@ -145,7 +139,7 @@ ed_delete_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_delete_next_char(EditLine *el, wint_t c __attribute__((__unused__))) +ed_delete_next_char(EditLine *el, Int c __attribute__((__unused__))) { #ifdef DEBUG_EDIT #define EL el->el_line @@ -192,7 +186,7 @@ ed_delete_next_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_kill_line(EditLine *el, wint_t c __attribute__((__unused__))) +ed_kill_line(EditLine *el, Int c __attribute__((__unused__))) { Char *kp, *cp; @@ -213,7 +207,7 @@ ed_kill_line(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_move_to_end(EditLine *el, wint_t c __attribute__((__unused__))) +ed_move_to_end(EditLine *el, Int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.lastchar; @@ -236,7 +230,7 @@ ed_move_to_end(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_move_to_beg(EditLine *el, wint_t c __attribute__((__unused__))) +ed_move_to_beg(EditLine *el, Int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -259,7 +253,7 @@ ed_move_to_beg(EditLine *el, wint_t c __attribute__((__unused__))) * [^T] [^T] */ protected el_action_t -ed_transpose_chars(EditLine *el, wint_t c) +ed_transpose_chars(EditLine *el, Int c) { if (el->el_line.cursor < el->el_line.lastchar) { @@ -272,7 +266,7 @@ ed_transpose_chars(EditLine *el, wint_t c) /* must have at least two chars entered */ c = el->el_line.cursor[-2]; el->el_line.cursor[-2] = el->el_line.cursor[-1]; - el->el_line.cursor[-1] = (Char)c; + el->el_line.cursor[-1] = c; return CC_REFRESH; } else return CC_ERROR; @@ -285,7 +279,7 @@ ed_transpose_chars(EditLine *el, wint_t c) */ protected el_action_t /*ARGSUSED*/ -ed_next_char(EditLine *el, wint_t c __attribute__((__unused__))) +ed_next_char(EditLine *el, Int c __attribute__((__unused__))) { Char *lim = el->el_line.lastchar; @@ -314,7 +308,7 @@ ed_next_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) +ed_prev_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -340,7 +334,7 @@ ed_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) +ed_prev_char(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor > el->el_line.buffer) { @@ -364,12 +358,14 @@ ed_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) * [^V] [^V] */ protected el_action_t -ed_quoted_insert(EditLine *el, wint_t c) +ed_quoted_insert(EditLine *el, Int c) { int num; + Char tc; tty_quotemode(el); - num = el_wgetc(el, &c); + num = FUN(el,getc)(el, &tc); + c = tc; tty_noquotemode(el); if (num == 1) return ed_insert(el, c); @@ -382,7 +378,7 @@ ed_quoted_insert(EditLine *el, wint_t c) * Adds to argument or enters a digit */ protected el_action_t -ed_digit(EditLine *el, wint_t c) +ed_digit(EditLine *el, Int c) { if (!Isdigit(c)) @@ -410,7 +406,7 @@ ed_digit(EditLine *el, wint_t c) * For ESC-n */ protected el_action_t -ed_argument_digit(EditLine *el, wint_t c) +ed_argument_digit(EditLine *el, Int c) { if (!Isdigit(c)) @@ -436,7 +432,7 @@ ed_argument_digit(EditLine *el, wint_t c) protected el_action_t /*ARGSUSED*/ ed_unassigned(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) + Int c __attribute__((__unused__))) { return CC_ERROR; @@ -453,8 +449,8 @@ ed_unassigned(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigint(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) +ed_tty_sigint(EditLine *el __attribute__((__unused__)), + Int c __attribute__((__unused__))) { return CC_NORM; @@ -467,8 +463,8 @@ ed_tty_sigint(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_dsusp(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) +ed_tty_dsusp(EditLine *el __attribute__((__unused__)), + Int c __attribute__((__unused__))) { return CC_NORM; @@ -481,8 +477,8 @@ ed_tty_dsusp(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_flush_output(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) +ed_tty_flush_output(EditLine *el __attribute__((__unused__)), + Int c __attribute__((__unused__))) { return CC_NORM; @@ -495,8 +491,8 @@ ed_tty_flush_output(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigquit(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) +ed_tty_sigquit(EditLine *el __attribute__((__unused__)), + Int c __attribute__((__unused__))) { return CC_NORM; @@ -509,8 +505,8 @@ ed_tty_sigquit(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigtstp(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) +ed_tty_sigtstp(EditLine *el __attribute__((__unused__)), + Int c __attribute__((__unused__))) { return CC_NORM; @@ -523,8 +519,8 @@ ed_tty_sigtstp(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_stop_output(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) +ed_tty_stop_output(EditLine *el __attribute__((__unused__)), + Int c __attribute__((__unused__))) { return CC_NORM; @@ -537,8 +533,8 @@ ed_tty_stop_output(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_start_output(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) +ed_tty_start_output(EditLine *el __attribute__((__unused__)), + Int c __attribute__((__unused__))) { return CC_NORM; @@ -551,7 +547,7 @@ ed_tty_start_output(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_newline(EditLine *el, wint_t c __attribute__((__unused__))) +ed_newline(EditLine *el, Int c __attribute__((__unused__))) { re_goto_bottom(el); @@ -567,7 +563,7 @@ ed_newline(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) +ed_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) @@ -587,7 +583,7 @@ ed_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_clear_screen(EditLine *el, wint_t c __attribute__((__unused__))) +ed_clear_screen(EditLine *el, Int c __attribute__((__unused__))) { terminal_clear_screen(el); /* clear the whole real screen */ @@ -602,8 +598,8 @@ ed_clear_screen(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_redisplay(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) +ed_redisplay(EditLine *el __attribute__((__unused__)), + Int c __attribute__((__unused__))) { return CC_REDISPLAY; @@ -616,7 +612,7 @@ ed_redisplay(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_start_over(EditLine *el, wint_t c __attribute__((__unused__))) +ed_start_over(EditLine *el, Int c __attribute__((__unused__))) { ch_reset(el, 0); @@ -630,8 +626,8 @@ ed_start_over(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), - wint_t c __attribute__((__unused__))) +ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), + Int c __attribute__((__unused__))) { return CC_NORM; @@ -644,7 +640,7 @@ ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), */ protected el_action_t /*ARGSUSED*/ -ed_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) +ed_prev_history(EditLine *el, Int c __attribute__((__unused__))) { char beep = 0; int sv_event = el->el_history.eventno; @@ -664,6 +660,7 @@ ed_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) if (hist_get(el) == CC_ERROR) { if (el->el_map.type == MAP_VI) { el->el_history.eventno = sv_event; + } beep = 1; /* el->el_history.eventno was fixed by first call */ @@ -681,7 +678,7 @@ ed_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_next_history(EditLine *el, wint_t c __attribute__((__unused__))) +ed_next_history(EditLine *el, Int c __attribute__((__unused__))) { el_action_t beep = CC_REFRESH, rval; @@ -708,11 +705,11 @@ ed_next_history(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) +ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__))) { const Char *hp; int h; - int found = 0; + bool_t found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.len = -1; @@ -751,7 +748,7 @@ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) (el->el_line.lastchar - el->el_line.buffer)) || hp[el->el_line.lastchar - el->el_line.buffer]) && c_hmatch(el, hp)) { - found = 1; + found++; break; } h++; @@ -776,11 +773,11 @@ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__))) +ed_search_next_history(EditLine *el, Int c __attribute__((__unused__))) { const Char *hp; int h; - int found = 0; + bool_t found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.len = -1; @@ -830,7 +827,7 @@ ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_prev_line(EditLine *el, wint_t c __attribute__((__unused__))) +ed_prev_line(EditLine *el, Int c __attribute__((__unused__))) { Char *ptr; int nchars = c_hpos(el); @@ -873,7 +870,7 @@ ed_prev_line(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_next_line(EditLine *el, wint_t c __attribute__((__unused__))) +ed_next_line(EditLine *el, Int c __attribute__((__unused__))) { Char *ptr; int nchars = c_hpos(el); @@ -907,7 +904,7 @@ ed_next_line(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -ed_command(EditLine *el, wint_t c __attribute__((__unused__))) +ed_command(EditLine *el, Int c __attribute__((__unused__))) { Char tmpbuf[EL_BUFSIZ]; int tmplen; diff --git a/lib/libedit/config.h b/lib/libedit/config.h index ccc2855..526869f 100644 --- a/lib/libedit/config.h +++ b/lib/libedit/config.h @@ -21,8 +21,8 @@ /* Define to 1 if you have the <fcntl.h> header file. */ #define HAVE_FCNTL_H 1 -/* Define to 1 if you have the `getline' function. */ -#define HAVE_GETLINE 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 @@ -188,6 +188,9 @@ /* 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 @@ -254,9 +257,6 @@ /* Version number of package */ #define VERSION "3.0" -/* Define to 1 if the system provides the SIZE_MAX constant */ -#define HAVE_SIZE_MAX 1 - /* Define to 1 if you want wide-character code */ /* #undef WIDECHAR */ diff --git a/lib/libedit/edit/readline/readline.h b/lib/libedit/edit/readline/readline.h index 34ded0f..e25781b 100644 --- a/lib/libedit/edit/readline/readline.h +++ b/lib/libedit/edit/readline/readline.h @@ -1,4 +1,4 @@ -/* $NetBSD: readline.h,v 1.39 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: readline.h,v 1.37 2015/06/02 15:36:45 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -55,7 +55,7 @@ typedef void *histdata_t; typedef struct _hist_entry { const char *line; - histdata_t data; + histdata_t data; } HIST_ENTRY; typedef struct _keymap_entry { @@ -89,7 +89,7 @@ typedef KEYMAP_ENTRY *Keymap; #define RUBOUT 0x7f #define ABORT_CHAR CTRL('G') -#define RL_READLINE_VERSION 0x0402 +#define RL_READLINE_VERSION 0x0402 #define RL_PROMPT_START_IGNORE '\1' #define RL_PROMPT_END_IGNORE '\2' @@ -98,7 +98,7 @@ typedef KEYMAP_ENTRY *Keymap; extern "C" { #endif extern const char *rl_library_version; -extern int rl_readline_version; +extern int rl_readline_version; extern char *rl_readline_name; extern FILE *rl_instream; extern FILE *rl_outstream; @@ -199,10 +199,10 @@ int rl_add_defun(const char *, rl_command_func_t *, int); HISTORY_STATE *history_get_history_state(void); void rl_get_screen_size(int *, int *); void rl_set_screen_size(int, int); -char *rl_filename_completion_function (const char *, int); +char *rl_filename_completion_function (const char *, int); int _rl_abort_internal(void); int _rl_qsort_string_compare(char **, char **); -char **rl_completion_matches(const char *, rl_compentry_func_t *); +char **rl_completion_matches(const char *, rl_compentry_func_t *); void rl_forced_update_display(void); int rl_set_prompt(const char *); int rl_on_new_line(void); @@ -218,8 +218,6 @@ int rl_generic_bind(int, const char *, const char *, Keymap); int rl_bind_key_in_map(int, rl_command_func_t *, Keymap); void rl_cleanup_after_signal(void); void rl_free_line_state(void); -int rl_set_keyboard_input_timeout(int); - #ifdef __cplusplus } #endif diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3 index 0234b0d..05ee76e 100644 --- a/lib/libedit/editline.3 +++ b/lib/libedit/editline.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: editline.3,v 1.88 2016/02/25 14:59:22 wiz Exp $ +.\" $NetBSD: editline.3,v 1.85 2015/11/03 21:36:59 christos Exp $ .\" .\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd February 24, 2016 +.Dd November 3, 2015 .Dt EDITLINE 3 .Os .Sh NAME @@ -72,7 +72,7 @@ .Nm tok_wreset , .Nm tok_line , .Nm tok_wline , -.Nm tok_str , +.Nm tok_str .Nm tok_wstr .Nd line editor, history and tokenization functions .Sh LIBRARY @@ -130,9 +130,9 @@ .Ft void .Fn el_wdeletestr "EditLine *e" "int count" .Ft History * -.Fn history_init void +.Fn history_init .Ft HistoryW * -.Fn history_winit void +.Fn history_winit .Ft void .Fn history_end "History *h" .Ft void @@ -175,16 +175,6 @@ library (which needs the library). Programs should be linked with .Fl ledit ltermcap . -.Pp -The -.Nm -library respects the -.Ev LC_CTYPE -locale set by the application program and never uses -.Xr setlocale 3 -to change the locale. -The only locales supported are UTF-8 and the default C or POSIX locale. -If any other locale is set, behaviour is undefined. .Sh LINE EDITING FUNCTIONS The line editing functions use a common data structure, .Fa EditLine , @@ -250,42 +240,14 @@ contains the error code that caused it. The return value may not remain valid across calls to .Fn el_gets and must be copied if the data is to be retained. -.It Fn el_wgetc -Read a wide character from the tty, respecting the current locale, -or from the input stream written by -.Fn el_wpush -and -.Fn el_push -if that is not empty, and store it in -.Fa ch . -If an invalid or incomplete character is found, it is discarded, -.Va errno -is set to -.Er EILSEQ , -and the next character is read and stored in -.Fa ch . -Returns 1 if a valid character was read, 0 on end of file, or \-1 on -.Xr read 2 -failure. -In the latter case, -.Va errno -is set to indicate the error. .It Fn el_getc -Read a wide character as described for -.Fn el_wgetc -and return 0 on end of file or \-1 on failure. -If the wide character can be represented as a single-byte character, -convert it with -.Xr wctob 3 , -store the result in -.Fa ch , -and return 1; otherwise, set -.Va errno -to -.Er ERANGE -and return \-1. -In the C or POSIX locale, this simply reads a byte, but for any other -locale, including UTF-8, this is rarely useful. +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, +in which case +.Dv errno +can be inspected for the cause. .It Fn el_push Pushes .Fa str @@ -784,7 +746,7 @@ to the last new element of the history. .It Dv H_ENTER , Fa "const char *str" Add .Fa str -as a new element to the history and, if necessary, +as a new element to the history, and, if necessary, removing the oldest entry to keep the list to the created size. If .Dv H_SETUNIQUE diff --git a/lib/libedit/el.c b/lib/libedit/el.c index 81020b1..65bd86b 100644 --- a/lib/libedit/el.c +++ b/lib/libedit/el.c @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.83 2016/02/24 17:13:22 christos Exp $ */ +/* $NetBSD: el.c,v 1.74 2015/12/08 12:56:55 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.83 2016/02/24 17:13:22 christos Exp $"); +__RCSID("$NetBSD: el.c,v 1.74 2015/12/08 12:56:55 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -48,17 +48,13 @@ __FBSDID("$FreeBSD$"); */ #include <sys/types.h> #include <sys/param.h> -#include <ctype.h> -#include <stdarg.h> -#include <stdlib.h> #include <string.h> -#ifdef WIDECHAR +#include <stdlib.h> +#include <stdarg.h> +#include <ctype.h> #include <locale.h> #include <langinfo.h> -#endif - #include "el.h" -#include "parse.h" /* el_init(): * Initialize editline and set default parameters. @@ -99,10 +95,12 @@ el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr, * Initialize all the modules. Order is important!!! */ el->el_flags = 0; +#ifdef WIDECHAR if (setlocale(LC_CTYPE, NULL) != NULL){ if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0) el->el_flags |= CHARSET_IS_UTF8; } +#endif if (terminal_init(el) == -1) { el_free(el->el_prog); @@ -211,7 +209,7 @@ FUN(el,set)(EditLine *el, int op, ...) el_pfunc_t p = va_arg(ap, el_pfunc_t); int c = va_arg(ap, int); - rv = prompt_set(el, p, (Char)c, op, 1); + rv = prompt_set(el, p, c, op, 1); break; } @@ -310,6 +308,7 @@ FUN(el,set)(EditLine *el, int op, ...) { el_rfunc_t rc = va_arg(ap, el_rfunc_t); rv = el_read_setfn(el, rc); + el->el_flags &= ~NARROW_READ; break; } @@ -438,7 +437,7 @@ FUN(el,get)(EditLine *el, int op, ...) char *argv[20]; int i; - for (i = 1; i < (int)__arraycount(argv); i++) + for (i = 1; i < (int)__arraycount(argv); i++) if ((argv[i] = va_arg(ap, char *)) == NULL) break; @@ -515,7 +514,6 @@ el_source(EditLine *el, const char *fname) { FILE *fp; size_t len; - ssize_t slen; char *ptr; char *path = NULL; const Char *dptr; @@ -552,17 +550,15 @@ el_source(EditLine *el, const char *fname) return -1; } - ptr = NULL; - len = 0; - while ((slen = getline(&ptr, &len, fp)) != -1) { + while ((ptr = fgetln(fp, &len)) != NULL) { if (*ptr == '\n') continue; /* Empty line. */ - if (slen > 0 && ptr[--slen] == '\n') - ptr[slen] = '\0'; - dptr = ct_decode_string(ptr, &el->el_scratch); if (!dptr) continue; + if (len > 0 && dptr[len - 1] == '\n') + --len; + /* loop until first non-space char or EOL */ while (*dptr != '\0' && Isspace(*dptr)) dptr++; @@ -571,7 +567,6 @@ el_source(EditLine *el, const char *fname) if ((error = parse_line(el, dptr)) == -1) break; } - free(ptr); el_free(path); (void) fclose(fp); diff --git a/lib/libedit/el.h b/lib/libedit/el.h index d6b69fc..ed3d2ef 100644 --- a/lib/libedit/el.h +++ b/lib/libedit/el.h @@ -1,4 +1,4 @@ -/* $NetBSD: el.h,v 1.34 2016/02/24 17:13:22 christos Exp $ */ +/* $NetBSD: el.h,v 1.25 2011/07/29 23:44:44 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -49,6 +49,8 @@ #include "histedit.h" #include "chartype.h" +#include <stdio.h> +#include <sys/types.h> #define EL_BUFSIZ ((size_t)1024) /* Maximum line size */ @@ -57,7 +59,11 @@ #define EDIT_DISABLED 0x04 #define UNBUFFERED 0x08 #define CHARSET_IS_UTF8 0x10 +#define IGNORE_EXTCHARS 0x20 /* Ignore characters read > 0xff */ #define NARROW_HISTORY 0x40 +#define NARROW_READ 0x80 + +typedef int bool_t; /* True or not */ typedef unsigned char el_action_t; /* Index to command array */ @@ -67,7 +73,7 @@ typedef struct coord_t { /* Position on the screen */ } coord_t; typedef struct el_line_t { - Char *buffer; /* Input line */ + Char *buffer; /* Input line */ Char *cursor; /* Cursor position */ Char *lastchar; /* Last character */ const Char *limit; /* Max position */ @@ -82,7 +88,7 @@ typedef struct el_state_t { int argument; /* Numeric argument */ int metanext; /* Is the next char a meta char */ el_action_t lastcmd; /* Previous command */ - el_action_t thiscmd; /* this command */ + el_action_t thiscmd; /* this command */ Char thisch; /* char that generated it */ } el_state_t; @@ -99,11 +105,13 @@ typedef struct el_state_t { #include "terminal.h" #include "refresh.h" #include "chared.h" +#include "common.h" #include "search.h" #include "hist.h" -#include "fcns.h" /* el_func_t is needed for map.h */ #include "map.h" +#include "parse.h" #include "sig.h" +#include "help.h" #include "read.h" struct editline { diff --git a/lib/libedit/eln.c b/lib/libedit/eln.c index d35e742..013aa3e 100644 --- a/lib/libedit/eln.c +++ b/lib/libedit/eln.c @@ -1,4 +1,4 @@ -/* $NetBSD: eln.c,v 1.28 2016/02/28 23:02:24 christos Exp $ */ +/* $NetBSD: eln.c,v 1.19 2015/05/18 15:07:04 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -12,6 +12,13 @@ * 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 @@ -27,40 +34,36 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: eln.c,v 1.28 2016/02/28 23:02:24 christos Exp $"); +__RCSID("$NetBSD: eln.c,v 1.19 2015/05/18 15:07:04 christos Exp $"); #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); -#include <errno.h> +#include "histedit.h" +#include "el.h" +#include "read.h" #include <stdarg.h> #include <stdio.h> #include <stdlib.h> -#include "el.h" - public int el_getc(EditLine *el, char *cp) { int num_read; wchar_t wc = 0; - num_read = el_wgetc(el, &wc); - *cp = '\0'; - if (num_read <= 0) - return num_read; - num_read = ct_wctob(wc); - if (num_read == EOF) { - errno = ERANGE; - return -1; - } else { - *cp = (char)num_read; - return 1; - } + if (!(el->el_flags & CHARSET_IS_UTF8)) + el->el_flags |= IGNORE_EXTCHARS; + num_read = el_wgetc (el, &wc); + if (!(el->el_flags & CHARSET_IS_UTF8)) + el->el_flags &= ~IGNORE_EXTCHARS; + + if (num_read > 0) + *cp = (char)wc; + return num_read; } -#ifdef WIDECHAR public void el_push(EditLine *el, const char *str) { @@ -75,15 +78,17 @@ el_gets(EditLine *el, int *nread) { const wchar_t *tmp; + if (!(el->el_flags & CHARSET_IS_UTF8)) + el->el_flags |= IGNORE_EXTCHARS; tmp = el_wgets(el, nread); if (tmp != NULL) { - int i; size_t nwread = 0; - - for (i = 0; i < *nread; i++) + for (int i = 0; i < *nread; i++) nwread += ct_enc_width(tmp[i]); *nread = (int)nwread; } + if (!(el->el_flags & CHARSET_IS_UTF8)) + el->el_flags &= ~IGNORE_EXTCHARS; return ct_encode_string(tmp, &el->el_lgcyconv); } @@ -228,7 +233,7 @@ el_set(EditLine *el, int op, ...) ret = -1; goto out; } - /* XXX: The two strdup's leak */ + // XXX: The two strdup's leak ret = map_addfunc(el, Strdup(wargv[0]), Strdup(wargv[1]), func); ct_free_argv(wargv); @@ -242,8 +247,10 @@ el_set(EditLine *el, int op, ...) break; } + /* XXX: do we need to change el_rfunc_t? */ case EL_GETCFN: /* el_rfunc_t */ ret = el_wset(el, op, va_arg(ap, el_rfunc_t)); + el->el_flags |= NARROW_READ; break; case EL_CLIENTDATA: /* void * */ @@ -337,6 +344,7 @@ el_get(EditLine *el, int op, ...) break; } + /* XXX: do we need to change el_rfunc_t? */ case EL_GETCFN: /* el_rfunc_t */ ret = el_wget(el, op, va_arg(ap, el_rfunc_t *)); break; @@ -391,4 +399,3 @@ el_insertstr(EditLine *el, const char *str) { return el_winsertstr(el, ct_decode_string(str, &el->el_lgcyconv)); } -#endif /* WIDECHAR */ diff --git a/lib/libedit/emacs.c b/lib/libedit/emacs.c index 6c86b9e..c1c30d6 100644 --- a/lib/libedit/emacs.c +++ b/lib/libedit/emacs.c @@ -1,4 +1,4 @@ -/* $NetBSD: emacs.c,v 1.32 2016/02/16 22:53:14 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.32 2016/02/16 22:53:14 christos Exp $"); +__RCSID("$NetBSD: emacs.c,v 1.25 2011/07/29 15:16:33 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -46,10 +46,7 @@ __FBSDID("$FreeBSD$"); /* * emacs.c: Emacs functions */ -#include <ctype.h> - #include "el.h" -#include "emacs.h" /* em_delete_or_list(): * Delete character under cursor or list completions if at end of line @@ -57,7 +54,7 @@ __FBSDID("$FreeBSD$"); */ protected el_action_t /*ARGSUSED*/ -em_delete_or_list(EditLine *el, wint_t c) +em_delete_or_list(EditLine *el, Int c) { if (el->el_line.cursor == el->el_line.lastchar) { @@ -93,7 +90,7 @@ em_delete_or_list(EditLine *el, wint_t c) */ protected el_action_t /*ARGSUSED*/ -em_delete_next_word(EditLine *el, wint_t c __attribute__((__unused__))) +em_delete_next_word(EditLine *el, Int c __attribute__((__unused__))) { Char *cp, *p, *kp; @@ -122,7 +119,7 @@ em_delete_next_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_yank(EditLine *el, wint_t c __attribute__((__unused__))) +em_yank(EditLine *el, Int c __attribute__((__unused__))) { Char *kp, *cp; @@ -158,7 +155,7 @@ em_yank(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_kill_line(EditLine *el, wint_t c __attribute__((__unused__))) +em_kill_line(EditLine *el, Int c __attribute__((__unused__))) { Char *kp, *cp; @@ -180,7 +177,7 @@ em_kill_line(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_kill_region(EditLine *el, wint_t c __attribute__((__unused__))) +em_kill_region(EditLine *el, Int c __attribute__((__unused__))) { Char *kp, *cp; @@ -213,7 +210,7 @@ em_kill_region(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_copy_region(EditLine *el, wint_t c __attribute__((__unused__))) +em_copy_region(EditLine *el, Int c __attribute__((__unused__))) { Char *kp, *cp; @@ -242,14 +239,14 @@ em_copy_region(EditLine *el, wint_t c __attribute__((__unused__))) * Gosling emacs transpose chars [^T] */ protected el_action_t -em_gosmacs_transpose(EditLine *el, wint_t c) +em_gosmacs_transpose(EditLine *el, Int c) { if (el->el_line.cursor > &el->el_line.buffer[1]) { /* must have at least two chars entered */ c = el->el_line.cursor[-2]; el->el_line.cursor[-2] = el->el_line.cursor[-1]; - el->el_line.cursor[-1] = (Char)c; + el->el_line.cursor[-1] = c; return CC_REFRESH; } else return CC_ERROR; @@ -262,7 +259,7 @@ em_gosmacs_transpose(EditLine *el, wint_t c) */ protected el_action_t /*ARGSUSED*/ -em_next_word(EditLine *el, wint_t c __attribute__((__unused__))) +em_next_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) return CC_ERROR; @@ -287,7 +284,7 @@ em_next_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_upper_case(EditLine *el, wint_t c __attribute__((__unused__))) +em_upper_case(EditLine *el, Int c __attribute__((__unused__))) { Char *cp, *ep; @@ -311,7 +308,7 @@ em_upper_case(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_capitol_case(EditLine *el, wint_t c __attribute__((__unused__))) +em_capitol_case(EditLine *el, Int c __attribute__((__unused__))) { Char *cp, *ep; @@ -343,7 +340,7 @@ em_capitol_case(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_lower_case(EditLine *el, wint_t c __attribute__((__unused__))) +em_lower_case(EditLine *el, Int c __attribute__((__unused__))) { Char *cp, *ep; @@ -367,7 +364,7 @@ em_lower_case(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_set_mark(EditLine *el, wint_t c __attribute__((__unused__))) +em_set_mark(EditLine *el, Int c __attribute__((__unused__))) { el->el_chared.c_kill.mark = el->el_line.cursor; @@ -381,7 +378,7 @@ em_set_mark(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_exchange_mark(EditLine *el, wint_t c __attribute__((__unused__))) +em_exchange_mark(EditLine *el, Int c __attribute__((__unused__))) { Char *cp; @@ -398,7 +395,7 @@ em_exchange_mark(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_universal_argument(EditLine *el, wint_t c __attribute__((__unused__))) +em_universal_argument(EditLine *el, Int c __attribute__((__unused__))) { /* multiply current argument by 4 */ if (el->el_state.argument > 1000000) @@ -415,7 +412,7 @@ em_universal_argument(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_meta_next(EditLine *el, wint_t c __attribute__((__unused__))) +em_meta_next(EditLine *el, Int c __attribute__((__unused__))) { el->el_state.metanext = 1; @@ -428,7 +425,7 @@ em_meta_next(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_toggle_overwrite(EditLine *el, wint_t c __attribute__((__unused__))) +em_toggle_overwrite(EditLine *el, Int c __attribute__((__unused__))) { el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ? @@ -442,7 +439,7 @@ em_toggle_overwrite(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_copy_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) +em_copy_prev_word(EditLine *el, Int c __attribute__((__unused__))) { Char *cp, *oldc, *dp; @@ -469,7 +466,7 @@ em_copy_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_inc_search_next(EditLine *el, wint_t c __attribute__((__unused__))) +em_inc_search_next(EditLine *el, Int c __attribute__((__unused__))) { el->el_search.patlen = 0; @@ -482,7 +479,7 @@ em_inc_search_next(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_inc_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) +em_inc_search_prev(EditLine *el, Int c __attribute__((__unused__))) { el->el_search.patlen = 0; @@ -496,7 +493,7 @@ em_inc_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -em_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) +em_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) diff --git a/lib/libedit/filecomplete.c b/lib/libedit/filecomplete.c index 007ca73..10d44e4 100644 --- a/lib/libedit/filecomplete.c +++ b/lib/libedit/filecomplete.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecomplete.c,v 1.40 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: filecomplete.c,v 1.34 2014/10/18 15:07:02 riz Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,24 +31,27 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: filecomplete.c,v 1.40 2016/02/17 19:47:49 christos Exp $"); +__RCSID("$NetBSD: filecomplete.c,v 1.34 2014/10/18 15:07:02 riz Exp $"); #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/stat.h> +#include <stdio.h> #include <dirent.h> -#include <errno.h> -#include <fcntl.h> -#include <limits.h> +#include <string.h> #include <pwd.h> -#include <stdio.h> +#include <ctype.h> #include <stdlib.h> -#include <string.h> #include <unistd.h> +#include <limits.h> +#include <errno.h> +#include <fcntl.h> #include "el.h" +#include "fcns.h" /* for EL_NUM_FCNS */ +#include "histedit.h" #include "filecomplete.h" static const Char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', @@ -97,9 +100,9 @@ fn_tilde_expand(const char *txt) } if (temp[0] == 0) { #ifdef HAVE_GETPW_R_POSIX - if (getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf), + if (getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf), &pass) != 0) - pass = NULL; + pass = NULL; #elif HAVE_GETPW_R_DRAFT pass = getpwuid_r(getuid(), &pwres, pwbuf, sizeof(pwbuf)); #else @@ -481,7 +484,7 @@ fn_complete(EditLine *el, cur_off - (int)len, cur_off); } else matches = 0; - if (!attempted_completion_function || + if (!attempted_completion_function || (over != NULL && !*over && !matches)) matches = completion_matches( ct_encode_string(dequoted_temp ? dequoted_temp : temp, @@ -540,7 +543,7 @@ fn_complete(EditLine *el, } /* 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"); diff --git a/lib/libedit/hist.c b/lib/libedit/hist.c index bcabe68..66cfd312 100644 --- a/lib/libedit/hist.c +++ b/lib/libedit/hist.c @@ -1,4 +1,4 @@ -/* $NetBSD: hist.c,v 1.24 2016/02/16 22:53:14 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.24 2016/02/16 22:53:14 christos Exp $"); +__RCSID("$NetBSD: hist.c,v 1.20 2011/07/29 15:16:33 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -47,8 +47,6 @@ __FBSDID("$FreeBSD$"); * hist.c: History access functions */ #include <stdlib.h> -#include <string.h> - #include "el.h" /* hist_init(): diff --git a/lib/libedit/hist.h b/lib/libedit/hist.h index 23b1e03..6ca6877 100644 --- a/lib/libedit/hist.h +++ b/lib/libedit/hist.h @@ -1,4 +1,4 @@ -/* $NetBSD: hist.h,v 1.18 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: hist.h,v 1.15 2016/01/30 15:05:27 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,6 +41,8 @@ #ifndef _h_el_hist #define _h_el_hist +#include "histedit.h" + typedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...); typedef struct el_history_t { @@ -81,7 +83,7 @@ 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, void *); +protected wchar_t *hist_convert(EditLine *, int, void *); #endif #endif /* _h_el_hist */ diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h index e5449ed..bed186e 100644 --- a/lib/libedit/histedit.h +++ b/lib/libedit/histedit.h @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.h,v 1.55 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: histedit.h,v 1.53 2014/06/18 18:12:28 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -130,7 +130,7 @@ unsigned char _el_fn_sh_complete(EditLine *, int); * For operations that support set or set/get, the argument types listed are for * the "set" operation. For "get", each listed type must be a pointer. * E.g. EL_EDITMODE takes an int when set, but an int* when get. - * + * * Operations that only support "get" have the correct argument types listed. */ #define EL_PROMPT 0 /* , prompt_func); set/get */ @@ -143,7 +143,7 @@ unsigned char _el_fn_sh_complete(EditLine *, int); #define EL_ECHOTC 7 /* , const Char *, ..., NULL); set */ #define EL_SETTY 8 /* , const Char *, ..., NULL); set */ #define EL_ADDFN 9 /* , const Char *, const Char, set */ - /* el_func_t); */ + /* el_func_t); */ #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 */ @@ -251,10 +251,21 @@ int tok_str(Tokenizer *, const char *, /* * Begin Wide Character Support */ +#ifdef __linux__ +/* Apparently we need _GNU_SOURCE defined to get access to wcsdup on Linux */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#endif + #include <wchar.h> #include <wctype.h> /* + * Wide character versions + */ + +/* * ==== Editing ==== */ typedef struct lineinfow { diff --git a/lib/libedit/history.c b/lib/libedit/history.c index d97a797..6e225e9 100644 --- a/lib/libedit/history.c +++ b/lib/libedit/history.c @@ -1,4 +1,4 @@ -/* $NetBSD: history.c,v 1.52 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: history.c,v 1.47 2014/05/11 01:05:17 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.52 2016/02/17 19:47:49 christos Exp $"); +__RCSID("$NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -46,11 +46,11 @@ __FBSDID("$FreeBSD$"); /* * hist.c: TYPE(History) access functions */ -#include <sys/stat.h> -#include <stdarg.h> -#include <stdlib.h> #include <string.h> +#include <stdlib.h> +#include <stdarg.h> #include <vis.h> +#include <sys/stat.h> static const char hist_cookie[] = "_HiStOrY_V2_\n"; @@ -439,7 +439,7 @@ history_def_del(void *p, TYPE(HistEvent) *ev __attribute__((__unused__)), */ /* ARGSUSED */ private void -history_def_delete(history_t *h, +history_def_delete(history_t *h, TYPE(HistEvent) *ev __attribute__((__unused__)), hentry_t *hp) { HistEventPrivate *evp = (void *)&hp->ev; @@ -734,9 +734,7 @@ history_load(TYPE(History) *h, const char *fname) { FILE *fp; char *line; - size_t llen; - ssize_t sz; - size_t max_size; + size_t sz, max_size; char *ptr; int i = -1; TYPE(HistEvent) ev; @@ -747,23 +745,26 @@ history_load(TYPE(History) *h, const char *fname) if ((fp = fopen(fname, "r")) == NULL) return i; - line = NULL; - llen = 0; - if ((sz = getline(&line, &llen, fp)) == -1) + if ((line = fgetln(fp, &sz)) == NULL) goto done; - if (strncmp(line, hist_cookie, (size_t)sz) != 0) + if (strncmp(line, hist_cookie, sz) != 0) goto done; ptr = h_malloc((max_size = 1024) * sizeof(*ptr)); if (ptr == NULL) goto done; - for (i = 0; (sz = getline(&line, &llen, fp)) != -1; i++) { - if (sz > 0 && line[sz - 1] == '\n') + for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) { + char c = line[sz]; + + if (sz != 0 && line[sz - 1] == '\n') line[--sz] = '\0'; - if (max_size < (size_t)sz) { + else + line[sz] = '\0'; + + if (max_size < sz) { char *nptr; - max_size = ((size_t)sz + 1024) & (size_t)~1023; + max_size = (sz + 1024) & (size_t)~1023; nptr = h_realloc(ptr, max_size * sizeof(*ptr)); if (nptr == NULL) { i = -1; @@ -772,6 +773,7 @@ history_load(TYPE(History) *h, const char *fname) ptr = nptr; } (void) strunvis(ptr, line); + line[sz] = c; if (HENTER(h, &ev, ct_decode_string(ptr, &conv)) == -1) { i = -1; goto oomem; @@ -780,7 +782,6 @@ history_load(TYPE(History) *h, const char *fname) oomem: h_free(ptr); done: - free(line); (void) fclose(fp); return i; } @@ -812,8 +813,8 @@ history_save_fp(TYPE(History) *h, FILE *fp) retval != -1; retval = HPREV(h, &ev), i++) { str = ct_encode_string(ev.str, &conv); - len = strlen(str) * 4 + 1; - if (len > max_size) { + len = strlen(str) * 4; + if (len >= max_size) { char *nptr; max_size = (len + 1024) & (size_t)~1023; nptr = h_realloc(ptr, max_size * sizeof(*ptr)); diff --git a/lib/libedit/keymacro.c b/lib/libedit/keymacro.c index e10ed7f..1a1bdd5 100644 --- a/lib/libedit/keymacro.c +++ b/lib/libedit/keymacro.c @@ -1,4 +1,4 @@ -/* $NetBSD: keymacro.c,v 1.14 2016/02/24 14:25:38 christos Exp $ */ +/* $NetBSD: keymacro.c,v 1.7 2011/08/16 16:25:15 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: keymacro.c,v 1.14 2016/02/24 14:25:38 christos Exp $"); +__RCSID("$NetBSD: keymacro.c,v 1.7 2011/08/16 16:25:15 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -65,8 +65,8 @@ __FBSDID("$FreeBSD$"); * 1) It is not possible to have one key that is a * substr of another. */ -#include <stdlib.h> #include <string.h> +#include <stdlib.h> #include "el.h" @@ -75,10 +75,10 @@ __FBSDID("$FreeBSD$"); * linked list of these node elements */ struct keymacro_node_t { - Char ch; /* single character of key */ + 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 */ + /* if this is a leaf */ struct keymacro_node_t *next; /* ptr to next char of this key */ struct keymacro_node_t *sibling;/* ptr to another key with same prefix*/ }; @@ -87,7 +87,7 @@ 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(wint_t); +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 **, @@ -277,23 +277,21 @@ keymacro_print(EditLine *el, const Char *key) /* node_trav(): * recursively traverses node in tree until match or mismatch is - * found. May read in more characters. + * found. May read in more characters. */ private int node_trav(EditLine *el, keymacro_node_t *ptr, Char *ch, keymacro_value_t *val) { - wchar_t wc; if (ptr->ch == *ch) { /* match found */ if (ptr->next) { /* key not complete so get next char */ - if (el_wgetc(el, &wc) != 1) {/* if EOF or error */ + if (FUN(el,getc)(el, ch) != 1) {/* if EOF or error */ val->cmd = ED_END_OF_FILE; return XK_CMD; /* PWP: Pretend we just read an end-of-file */ } - *ch = (Char)wc; return node_trav(el, ptr->next, ch, val); } else { *val = ptr->val; @@ -316,7 +314,7 @@ node_trav(EditLine *el, keymacro_node_t *ptr, Char *ch, keymacro_value_t *val) /* node__try(): - * Find a node that matches *str or allocate a new one + * Find a node that matches *str or allocate a new one */ private int node__try(EditLine *el, keymacro_node_t *ptr, const Char *str, @@ -462,14 +460,14 @@ node__put(EditLine *el, keymacro_node_t *ptr) * Returns pointer to a keymacro_node_t for ch. */ private keymacro_node_t * -node__get(wint_t ch) +node__get(Int ch) { keymacro_node_t *ptr; ptr = el_malloc(sizeof(*ptr)); if (ptr == NULL) return NULL; - ptr->ch = (Char)ch; + ptr->ch = ch; ptr->type = XK_NOD; ptr->val.str = NULL; ptr->next = NULL; @@ -598,7 +596,7 @@ keymacro_kprint(EditLine *el, const Char *key, keymacro_value_t *val, int ntype) case XK_STR: case XK_EXE: (void) keymacro__decode_str(val->str, unparsbuf, - sizeof(unparsbuf), + sizeof(unparsbuf), ntype == XK_STR ? "\"\"" : "[]"); (void) fprintf(el->el_outfile, fmt, ct_encode_string(key, &el->el_scratch), unparsbuf); diff --git a/lib/libedit/makelist b/lib/libedit/makelist index 4cb65bc..ec3292f 100644 --- a/lib/libedit/makelist +++ b/lib/libedit/makelist @@ -62,7 +62,7 @@ case $FLAG in #include "${FILES}" _EOF ;; - + -h) set - `echo $FILES | sed -e 's/\\./_/g'` hdr="_h_`basename $1`" @@ -79,8 +79,7 @@ _EOF # XXX: need a space between name and prototype so that -fc and -fh # parsing is much easier # - printf("protected el_action_t\t%s (EditLine *, wint_t);\n", - name); + printf("protected el_action_t\t%s (EditLine *, Int);\n", name); } } END { @@ -95,7 +94,7 @@ _EOF BEGIN { printf("/* Automatically generated file, do not edit */\n"); printf("#include \"config.h\"\n#include \"el.h\"\n"); - printf("#include \"help.h\"\n"); + printf("#include \"chartype.h\"\n"); printf("private const struct el_bindings_t el_func_help[] = {\n"); low = "abcdefghijklmnopqrstuvwxyz_"; high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; @@ -164,7 +163,7 @@ _EOF END { printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); - printf("typedef el_action_t (*el_func_t)(EditLine *, wint_t);"); + printf("typedef el_action_t (*el_func_t)(EditLine *, Int);"); printf("\nprotected const el_func_t* func__get(void);\n"); printf("#endif /* _h_fcns_c */\n"); }' @@ -177,9 +176,6 @@ _EOF BEGIN { printf("/* Automatically generated file, do not edit */\n"); printf("#include \"config.h\"\n#include \"el.h\"\n"); - printf("#include \"common.h\"\n"); - printf("#include \"emacs.h\"\n"); - printf("#include \"vi.h\"\n"); printf("private const el_func_t el_func[] = {"); maxlen = 80; needn = 1; diff --git a/lib/libedit/map.c b/lib/libedit/map.c index 2d4475c..03bb3d8 100644 --- a/lib/libedit/map.c +++ b/lib/libedit/map.c @@ -1,4 +1,4 @@ -/* $NetBSD: map.c,v 1.43 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: map.c,v 1.35 2015/05/14 10:44:15 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.43 2016/02/17 19:47:49 christos Exp $"); +__RCSID("$NetBSD: map.c,v 1.35 2015/05/14 10:44:15 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -46,16 +46,11 @@ __FBSDID("$FreeBSD$"); /* * map.c: Editor function definitions */ -#include <ctype.h> #include <stdlib.h> -#include <string.h> - #include "el.h" -#include "help.h" -#include "parse.h" private void map_print_key(EditLine *, el_action_t *, const Char *); -private void map_print_some_keys(EditLine *, el_action_t *, wint_t, wint_t); +private void map_print_some_keys(EditLine *, el_action_t *, Int, Int); private void map_print_all_keys(EditLine *); private void map_init_nls(EditLine *); private void map_init_meta(EditLine *); @@ -1149,19 +1144,19 @@ map_print_key(EditLine *el, el_action_t *map, const Char *in) * Print keys from first to last */ private void -map_print_some_keys(EditLine *el, el_action_t *map, wint_t first, wint_t last) +map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last) { el_bindings_t *bp, *ep; Char firstbuf[2], lastbuf[2]; char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ]; - firstbuf[0] = (Char)first; + firstbuf[0] = first; firstbuf[1] = 0; - lastbuf[0] = (Char)last; + lastbuf[0] = last; lastbuf[1] = 0; if (map[first] == ED_UNASSIGNED) { if (first == last) { - (void) keymacro__decode_str(firstbuf, unparsbuf, + (void) keymacro__decode_str(firstbuf, unparsbuf, sizeof(unparsbuf), STRQQ); (void) fprintf(el->el_outfile, "%-15s-> is undefined\n", unparsbuf); @@ -1172,14 +1167,14 @@ map_print_some_keys(EditLine *el, el_action_t *map, wint_t first, wint_t last) for (bp = el->el_map.help; bp < ep; bp++) { if (bp->func == map[first]) { if (first == last) { - (void) keymacro__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) keymacro__decode_str(firstbuf, unparsbuf, + (void) keymacro__decode_str(firstbuf, unparsbuf, sizeof(unparsbuf), STRQQ); - (void) keymacro__decode_str(lastbuf, extrabuf, + (void) keymacro__decode_str(lastbuf, extrabuf, sizeof(extrabuf), STRQQ); (void) fprintf(el->el_outfile, "%-4s to %-7s-> " FSTR "\n", @@ -1190,14 +1185,14 @@ map_print_some_keys(EditLine *el, el_action_t *map, wint_t first, wint_t last) } #ifdef MAP_DEBUG if (map == el->el_map.key) { - (void) keymacro__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) keymacro__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); @@ -1307,8 +1302,8 @@ map_bind(EditLine *el, int argc, const Char **argv) return 0; default: (void) fprintf(el->el_errfile, - "" FSTR ": Invalid switch `%lc'.\n", - argv[0], (wint_t)p[1]); + "" FSTR ": Invalid switch `" FCHAR "'.\n", + argv[0], (Int)p[1]); } else break; diff --git a/lib/libedit/parse.c b/lib/libedit/parse.c index 1b7bdb4..1c19cc7 100644 --- a/lib/libedit/parse.c +++ b/lib/libedit/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.35 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: parse.c,v 1.27 2014/07/06 18:15:34 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.35 2016/02/17 19:47:49 christos Exp $"); +__RCSID("$NetBSD: parse.c,v 1.27 2014/07/06 18:15:34 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -56,19 +56,16 @@ __FBSDID("$FreeBSD$"); * settc * setty */ -#include <stdlib.h> -#include <string.h> - #include "el.h" -#include "parse.h" +#include <stdlib.h> private const struct { const Char *name; int (*func)(EditLine *, int, const Char **); } cmds[] = { - { STR("bind"), map_bind }, + { STR("bind"), map_bind }, { STR("echotc"), terminal_echotc }, - { STR("edit"), el_editmode }, + { STR("edit"), el_editmode }, { STR("history"), hist_command }, { STR("telltc"), terminal_telltc }, { STR("settc"), terminal_settc }, @@ -144,7 +141,7 @@ protected int parse__escape(const Char **ptr) { const Char *p; - wint_t c; + Int c; p = *ptr; @@ -256,7 +253,7 @@ parse__string(Char *out, const Char *in) case '^': if ((n = parse__escape(&in)) == -1) return NULL; - *out++ = (Char)n; + *out++ = n; break; case 'M': diff --git a/lib/libedit/prompt.c b/lib/libedit/prompt.c index afd75bd..3696d0c 100644 --- a/lib/libedit/prompt.c +++ b/lib/libedit/prompt.c @@ -1,4 +1,4 @@ -/* $NetBSD: prompt.c,v 1.23 2016/02/16 15:53:48 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.23 2016/02/16 15:53:48 christos Exp $"); +__RCSID("$NetBSD: prompt.c,v 1.20 2011/07/29 15:16:33 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> diff --git a/lib/libedit/prompt.h b/lib/libedit/prompt.h index 5e14b76..260c818 100644 --- a/lib/libedit/prompt.h +++ b/lib/libedit/prompt.h @@ -1,4 +1,4 @@ -/* $NetBSD: prompt.h,v 1.13 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: prompt.h,v 1.10 2009/12/30 22:37:40 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,13 +41,15 @@ #ifndef _h_el_prompt #define _h_el_prompt +#include "histedit.h" + typedef Char *(*el_pfunc_t)(EditLine *); typedef struct el_prompt_t { el_pfunc_t p_func; /* Function to return the prompt */ coord_t p_pos; /* position in the line after prompt */ Char p_ignore; /* character to start/end literal */ - int p_wide; + int p_wide; } el_prompt_t; protected void prompt_print(EditLine *, int); diff --git a/lib/libedit/read.c b/lib/libedit/read.c index ba2c07a..9740599 100644 --- a/lib/libedit/read.c +++ b/lib/libedit/read.c @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.85 2016/02/24 17:20:01 christos Exp $ */ +/* $NetBSD: read.c,v 1.71 2014/07/06 18:15:34 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: read.c,v 1.85 2016/02/24 17:20:01 christos Exp $"); +__RCSID("$NetBSD: read.c,v 1.71 2014/07/06 18:15:34 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -47,21 +47,18 @@ __FBSDID("$FreeBSD$"); * read.c: Clean this junk up! This is horrible code. * Terminal read functions */ -#include <ctype.h> #include <errno.h> #include <fcntl.h> -#include <limits.h> -#include <stdlib.h> -#include <string.h> #include <unistd.h> - +#include <stdlib.h> +#include <limits.h> #include "el.h" #define OKCMD -1 /* must be -1! */ private int read__fixio(int, int); private int read_preread(EditLine *); -private int read_char(EditLine *, wchar_t *); +private int read_char(EditLine *, Char *); private int read_getcmd(EditLine *, el_action_t *, Char *); private void read_pop(c_macro_t *); @@ -244,21 +241,18 @@ FUN(el,push)(EditLine *el, const Char *str) private int read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch) { - static const Char meta = (Char)0x80; el_action_t cmd; - wchar_t wc; int num; el->el_errno = 0; do { - if ((num = el_wgetc(el, &wc)) != 1) {/* if EOF or error */ + if ((num = FUN(el,getc)(el, ch)) != 1) {/* if EOF or error */ el->el_errno = num == 0 ? 0 : errno; return 0; /* not OKCMD */ } - *ch = (Char)wc; #ifdef KANJI - if ((*ch & meta)) { + if ((*ch & 0200)) { el->el_state.metanext = 0; cmd = CcViMap[' ']; break; @@ -267,7 +261,7 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch) if (el->el_state.metanext) { el->el_state.metanext = 0; - *ch |= meta; + *ch |= 0200; } #ifdef WIDECHAR if (*ch >= N_KEYS) @@ -302,17 +296,29 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch) return OKCMD; } +#ifdef WIDECHAR +/* utf8_islead(): + * Test whether a byte is a leading byte of a UTF-8 sequence. + */ +private int +utf8_islead(int c) +{ + return c < 0x80 || /* single byte char */ + (c >= 0xc2 && c <= 0xf4); /* start of multibyte sequence */ +} +#endif + /* read_char(): * Read a character from the tty. */ private int -read_char(EditLine *el, wchar_t *cp) +read_char(EditLine *el, Char *cp) { ssize_t num_read; int tried = 0; char cbuf[MB_LEN_MAX]; size_t cbp = 0; - int save_errno = errno; + int bytes = 0; again: el->el_signal->sig_no = 0; @@ -328,59 +334,50 @@ read_char(EditLine *el, wchar_t *cp) default: break; } - if (!tried && read__fixio(el->el_infd, e) == 0) { - errno = save_errno; + if (!tried && read__fixio(el->el_infd, e) == 0) tried = 1; - } else { + else { errno = e; - *cp = L'\0'; + *cp = '\0'; return -1; } } /* Test for EOF */ if (num_read == 0) { - *cp = L'\0'; + errno = 0; + *cp = '\0'; return 0; } - for (;;) { - +#ifdef WIDECHAR + if (el->el_flags & CHARSET_IS_UTF8) { + if (!utf8_islead((unsigned char)cbuf[0])) + goto again; /* discard the byte we read and try again */ ++cbp; - switch (ct_mbrtowc(cp, cbuf, cbp)) { - case (size_t)-1: - if (cbp > 1) { - /* - * Invalid sequence, discard all bytes - * except the last one. - */ - cbuf[0] = cbuf[cbp - 1]; - cbp = 0; - break; - } else { - /* Invalid byte, discard it. */ - cbp = 0; - goto again; - } - case (size_t)-2: - /* - * We don't support other multibyte charsets. - * The second condition shouldn't happen - * and is here merely for additional safety. - */ - if ((el->el_flags & CHARSET_IS_UTF8) == 0 || - cbp >= MB_LEN_MAX) { + if ((bytes = ct_mbtowc(cp, cbuf, cbp)) == -1) { + ct_mbtowc_reset; + if (cbp >= MB_LEN_MAX) { /* "shouldn't happen" */ errno = EILSEQ; - *cp = L'\0'; + *cp = '\0'; return -1; } - /* Incomplete sequence, read another byte. */ goto again; - default: - /* Valid character, process it. */ - return 1; } + } 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]; + + if ((el->el_flags & IGNORE_EXTCHARS) && bytes > 1) { + cbp = 0; /* skip this character */ + goto again; } + + return (int)num_read; } /* read_pop(): @@ -398,11 +395,11 @@ read_pop(c_macro_t *ma) ma->offset = 0; } -/* el_wgetc(): - * Read a wide character +/* el_getc(): + * Read a character */ public int -el_wgetc(EditLine *el, wchar_t *cp) +FUN(el,getc)(EditLine *el, Char *cp) { int num_read; c_macro_t *ma = &el->el_chared.c_macro; @@ -444,8 +441,12 @@ el_wgetc(EditLine *el, wchar_t *cp) 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; +#endif #ifdef DEBUG_READ - (void) fprintf(el->el_errfile, "Got it %lc\n", *cp); + (void) fprintf(el->el_errfile, "Got it %c\n", *cp); #endif /* DEBUG_READ */ return num_read; } @@ -486,7 +487,6 @@ FUN(el,gets)(EditLine *el, int *nread) int retval; el_action_t cmdnum = 0; int num; /* how many chars we have read at NL */ - wchar_t wc; Char ch, *cp; int crlf = 0; int nrb; @@ -502,8 +502,7 @@ FUN(el,gets)(EditLine *el, int *nread) size_t idx; cp = el->el_line.buffer; - while ((num = (*el->el_read.read_char)(el, &wc)) == 1) { - *cp = (Char)wc; + 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 = (size_t)(cp - el->el_line.buffer); @@ -555,8 +554,7 @@ FUN(el,gets)(EditLine *el, int *nread) terminal__flush(el); - while ((num = (*el->el_read.read_char)(el, &wc)) == 1) { - *cp = (Char)wc; + 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 = (size_t)(cp - el->el_line.buffer); diff --git a/lib/libedit/read.h b/lib/libedit/read.h index bf43053..fa2a611 100644 --- a/lib/libedit/read.h +++ b/lib/libedit/read.h @@ -1,4 +1,4 @@ -/* $NetBSD: read.h,v 1.9 2016/02/24 17:13:22 christos Exp $ */ +/* $NetBSD: read.h,v 1.7 2009/12/30 22:37:40 christos Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -37,12 +37,12 @@ #ifndef _h_el_read #define _h_el_read -typedef int (*el_rfunc_t)(EditLine *, wchar_t *); +typedef int (*el_rfunc_t)(EditLine *, Char *); typedef struct el_read_t { el_rfunc_t read_char; /* Function to read a character */ } el_read_t; - + protected int read_init(EditLine *); protected void read_prepare(EditLine *); protected void read_finish(EditLine *); diff --git a/lib/libedit/readline.c b/lib/libedit/readline.c index 00ea369..caddb9f 100644 --- a/lib/libedit/readline.c +++ b/lib/libedit/readline.c @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.126 2016/02/24 17:13:22 christos Exp $ */ +/* $NetBSD: readline.c,v 1.117 2015/06/02 15:35:31 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,29 +31,30 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: readline.c,v 1.126 2016/02/24 17:13:22 christos Exp $"); +__RCSID("$NetBSD: readline.c,v 1.117 2015/06/02 15:35:31 christos Exp $"); #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/stat.h> -#include <ctype.h> +#include <stdio.h> #include <dirent.h> -#include <errno.h> -#include <fcntl.h> -#include <limits.h> +#include <string.h> #include <pwd.h> -#include <setjmp.h> -#include <stdint.h> -#include <stdio.h> +#include <ctype.h> #include <stdlib.h> -#include <string.h> #include <unistd.h> +#include <limits.h> +#include <errno.h> +#include <fcntl.h> +#include <setjmp.h> #include <vis.h> #include "readline/readline.h" #include "el.h" +#include "fcns.h" /* for EL_NUM_FCNS */ +#include "histedit.h" #include "filecomplete.h" void rl_prep_terminal(int); @@ -168,13 +169,13 @@ static jmp_buf topbuf; static unsigned char _el_rl_complete(EditLine *, int); static unsigned char _el_rl_tstp(EditLine *, int); static char *_get_prompt(EditLine *); -static int _getc_function(EditLine *, wchar_t *); +static int _getc_function(EditLine *, char *); static HIST_ENTRY *_move_history(int); static int _history_expand_command(const char *, size_t, size_t, char **); static char *_rl_compat_sub(const char *, const char *, const char *, int); -static int _rl_event_read_char(EditLine *, wchar_t *); +static int _rl_event_read_char(EditLine *, char *); static void _rl_update_pos(void); @@ -211,14 +212,14 @@ _move_history(int op) */ static int /*ARGSUSED*/ -_getc_function(EditLine *el __attribute__((__unused__)), wchar_t *c) +_getc_function(EditLine *el __attribute__((__unused__)), char *c) { int i; i = (*rl_getc_function)(NULL); if (i == -1) return 0; - *c = (wchar_t)i; + *c = (char)i; return 1; } @@ -268,7 +269,7 @@ rl_set_prompt(const char *prompt) if (!prompt) prompt = ""; - if (rl_prompt != NULL && strcmp(rl_prompt, prompt) == 0) + if (rl_prompt != NULL && strcmp(rl_prompt, prompt) == 0) return 0; if (rl_prompt) el_free(rl_prompt); @@ -362,7 +363,7 @@ rl_initialize(void) "ReadLine compatible suspend function", _el_rl_tstp); el_set(e, EL_BIND, "^Z", "rl_tstp", NULL); - + /* * Set some readline compatible key-bindings. */ @@ -2009,7 +2010,7 @@ rl_callback_read_char(void) } } -void +void rl_callback_handler_install(const char *prompt, rl_vcpfunc_t *linefunc) { if (e == NULL) { @@ -2018,9 +2019,9 @@ rl_callback_handler_install(const char *prompt, rl_vcpfunc_t *linefunc) (void)rl_set_prompt(prompt); rl_linefunc = linefunc; el_set(e, EL_UNBUFFERED, 1); -} +} -void +void rl_callback_handler_remove(void) { el_set(e, EL_UNBUFFERED, 0); @@ -2101,14 +2102,12 @@ rl_stuff_char(int c) } static int -_rl_event_read_char(EditLine *el, wchar_t *wc) +_rl_event_read_char(EditLine *el, char *cp) { - char ch; int n; ssize_t num_read = 0; - ch = '\0'; - *wc = L'\0'; + *cp = '\0'; while (rl_event_hook) { (*rl_event_hook)(); @@ -2117,7 +2116,7 @@ _rl_event_read_char(EditLine *el, wchar_t *wc) if (ioctl(el->el_infd, FIONREAD, &n) < 0) return -1; if (n) - num_read = read(el->el_infd, &ch, (size_t)1); + num_read = read(el->el_infd, cp, (size_t)1); else num_read = 0; #elif defined(F_SETFL) && defined(O_NDELAY) @@ -2125,12 +2124,12 @@ _rl_event_read_char(EditLine *el, wchar_t *wc) return -1; if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) < 0) return -1; - num_read = read(el->el_infd, &ch, 1); + num_read = read(el->el_infd, cp, 1); if (fcntl(el->el_infd, F_SETFL, n)) return -1; #else /* not non-blocking, but what you gonna do? */ - num_read = read(el->el_infd, &ch, 1); + num_read = read(el->el_infd, cp, 1); return -1; #endif @@ -2142,7 +2141,6 @@ _rl_event_read_char(EditLine *el, wchar_t *wc) } if (!rl_event_hook) el_set(el, EL_GETCFN, EL_BUILTIN_GETCFN); - *wc = (wchar_t)ch; return (int)num_read; } @@ -2205,7 +2203,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun) } qsort(&list[1], len - 1, sizeof(*list), (int (*)(const void *, const void *)) strcmp); - min = SIZE_MAX; + min = SIZE_T_MAX; for (i = 1, a = list[i]; i < len - 1; i++, a = b) { b = list[i + 1]; for (j = 0; a[j] && a[j] == b[j]; j++) @@ -2223,7 +2221,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun) list[0][min] = '\0'; } return list; - + out: el_free(list); return NULL; @@ -2327,10 +2325,3 @@ void rl_free_line_state(void) { } - -int -/*ARGSUSED*/ -rl_set_keyboard_input_timeout(int u __attribute__((__unused__))) -{ - return 0; -} diff --git a/lib/libedit/refresh.c b/lib/libedit/refresh.c index e6f629a..c85e845 100644 --- a/lib/libedit/refresh.c +++ b/lib/libedit/refresh.c @@ -1,4 +1,4 @@ -/* $NetBSD: refresh.c,v 1.44 2016/02/17 19:47:49 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.44 2016/02/17 19:47:49 christos Exp $"); +__RCSID("$NetBSD: refresh.c,v 1.37 2011/07/29 23:44:45 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -47,17 +47,18 @@ __FBSDID("$FreeBSD$"); * refresh.c: Lower level screen refreshing functions */ #include <stdio.h> -#include <string.h> +#include <ctype.h> #include <unistd.h> +#include <string.h> #include "el.h" private void re_nextline(EditLine *); -private void re_addc(EditLine *, wint_t); +private void re_addc(EditLine *, Int); private void re_update_line(EditLine *, Char *, Char *, int); private void re_insert (EditLine *, Char *, int, int, Char *, int); private void re_delete(EditLine *, Char *, int, int, int); -private void re_fastputc(EditLine *, wint_t); +private void re_fastputc(EditLine *, Int); private void re_clear_eol(EditLine *, int, int, int); private void re__strncopy(Char *, Char *, size_t); private void re__copy_and_pad(Char *, const Char *, size_t); @@ -65,7 +66,7 @@ private void re__copy_and_pad(Char *, const Char *, size_t); #ifdef DEBUG_REFRESH private void re_printstr(EditLine *, const char *, char *, char *); #define __F el->el_errfile -#define ELRE_ASSERT(a, b, c) do \ +#define ELRE_ASSERT(a, b, c) do \ if (/*CONSTCOND*/ a) { \ (void) fprintf b; \ c; \ @@ -111,7 +112,7 @@ re_nextline(EditLine *el) for(i = 1; i < lins; i++) el->el_vdisplay[i - 1] = el->el_vdisplay[i]; - firstline[0] = '\0'; /* empty the string */ + firstline[0] = '\0'; /* empty the string */ el->el_vdisplay[i - 1] = firstline; } else el->el_refresh.r_cursor.v++; @@ -126,7 +127,7 @@ re_nextline(EditLine *el) * Draw c, expanding tabs, control chars etc. */ private void -re_addc(EditLine *el, wint_t c) +re_addc(EditLine *el, Int c) { switch (ct_chr_class((Char)c)) { case CHTYPE_TAB: /* expand the tab */ @@ -162,16 +163,16 @@ re_addc(EditLine *el, wint_t c) * Draw the character given */ protected void -re_putc(EditLine *el, wint_t c, int shift) +re_putc(EditLine *el, Int c, int shift) { int i, w = Width(c); - ELRE_DEBUG(1, (__F, "printing %5x '%lc'\r\n", c, c)); + ELRE_DEBUG(1, (__F, "printing %5x '%c'\r\n", c, c)); 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] - [el->el_refresh.r_cursor.h] = (Char)c; + [el->el_refresh.r_cursor.h] = c; /* assumes !shift is only used for single-column chars */ i = w; while (--i > 0) @@ -193,7 +194,7 @@ re_putc(EditLine *el, wint_t c, int shift) /* re_refresh(): * draws the new virtual screen image from the current input - * line, then goes line-by-line changing the real image to the new + * line, then goes line-by-line changing the real image to the new * virtual image. The routine to re-draw a line can be replaced * easily in hopes of a smarter one being placed there. */ @@ -452,7 +453,7 @@ re__strncopy(Char *a, Char *b, size_t n) * in order to make sure that we have cleared the previous contents of * the line. fx and sx is the number of characters inserted or deleted * in the first or second diff, diff is the difference between the - * number of characters between the new and old line. + * number of characters between the new and old line. */ private void re_clear_eol(EditLine *el, int fx, int sx, int diff) @@ -1053,14 +1054,14 @@ re_refresh_cursor(EditLine *el) * Add a character fast. */ private void -re_fastputc(EditLine *el, wint_t c) +re_fastputc(EditLine *el, Int c) { int w = Width((Char)c); while (w > 1 && el->el_cursor.h + w > el->el_terminal.t_size.h) re_fastputc(el, ' '); terminal__putc(el, c); - el->el_display[el->el_cursor.v][el->el_cursor.h++] = (Char)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; @@ -1078,7 +1079,7 @@ re_fastputc(EditLine *el, wint_t c) 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]; diff --git a/lib/libedit/refresh.h b/lib/libedit/refresh.h index b9c4b30..71a1587 100644 --- a/lib/libedit/refresh.h +++ b/lib/libedit/refresh.h @@ -1,4 +1,4 @@ -/* $NetBSD: refresh.h,v 1.9 2016/02/16 15:53:48 christos Exp $ */ +/* $NetBSD: refresh.h,v 1.6 2009/12/30 22:37:40 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,13 +41,15 @@ #ifndef _h_el_refresh #define _h_el_refresh +#include "histedit.h" + typedef struct { coord_t r_cursor; /* Refresh cursor position */ int r_oldcv; /* Vertical locations */ int r_newcv; } el_refresh_t; -protected void re_putc(EditLine *, wint_t, int); +protected void re_putc(EditLine *, Int, int); protected void re_clear_lines(EditLine *); protected void re_clear_display(EditLine *); protected void re_refresh(EditLine *); diff --git a/lib/libedit/search.c b/lib/libedit/search.c index 53ad6ef..df9999c 100644 --- a/lib/libedit/search.c +++ b/lib/libedit/search.c @@ -1,4 +1,4 @@ -/* $NetBSD: search.c,v 1.39 2016/02/24 14:25:38 christos Exp $ */ +/* $NetBSD: search.c,v 1.31 2016/01/30 04:02:51 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.39 2016/02/24 14:25:38 christos Exp $"); +__RCSID("$NetBSD: search.c,v 1.31 2016/01/30 04:02:51 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -47,15 +47,12 @@ __FBSDID("$FreeBSD$"); * search.c: History and character search functions */ #include <stdlib.h> -#include <string.h> #if defined(REGEX) #include <regex.h> #elif defined(REGEXP) #include <regexp.h> #endif - #include "el.h" -#include "common.h" /* * Adjust cursor in vi mode to include the character under it @@ -214,9 +211,8 @@ ce_inc_search(EditLine *el, int dir) STRbck[] = {'b', 'c', 'k', '\0'}; static Char pchar = ':';/* ':' = normal, '?' = failed */ static Char endcmd[2] = {'\0', '\0'}; - Char *ocursor = el->el_line.cursor, oldpchar = pchar, ch; + Char ch, *ocursor = el->el_line.cursor, oldpchar = pchar; const Char *cp; - wchar_t wch; el_action_t ret = CC_NORM; @@ -255,11 +251,9 @@ ce_inc_search(EditLine *el, int dir) *el->el_line.lastchar = '\0'; re_refresh(el); - if (el_wgetc(el, &wch) != 1) + if (FUN(el,getc)(el, &ch) != 1) return ed_end_of_file(el, 0); - ch = (Char)wch; - switch (el->el_map.current[(unsigned char) ch]) { case ED_INSERT: case ED_DIGIT: @@ -353,14 +347,14 @@ ce_inc_search(EditLine *el, int dir) /* Can't search if unmatched '[' */ for (cp = &el->el_search.patbuf[el->el_search.patlen-1], - ch = L']'; + ch = ']'; cp >= &el->el_search.patbuf[LEN]; cp--) if (*cp == '[' || *cp == ']') { ch = *cp; break; } - if (el->el_search.patlen > LEN && ch != L'[') { + if (el->el_search.patlen > LEN && ch != '[') { if (redo && newdir == dir) { if (pchar == '?') { /* wrap around */ el->el_history.eventno = @@ -575,7 +569,7 @@ ce_search_line(EditLine *el, int dir) * Vi repeat search */ protected el_action_t -cv_repeat_srch(EditLine *el, wint_t c) +cv_repeat_srch(EditLine *el, Int c) { #ifdef SDEBUG @@ -601,33 +595,35 @@ cv_repeat_srch(EditLine *el, wint_t c) * Vi character search */ protected el_action_t -cv_csearch(EditLine *el, int direction, wint_t ch, int count, int tflag) +cv_csearch(EditLine *el, int direction, Int ch, int count, int tflag) { Char *cp; if (ch == 0) return CC_ERROR; - if (ch == (wint_t)-1) { - if (el_wgetc(el, &ch) != 1) + if (ch == (Int)-1) { + Char c; + if (FUN(el,getc)(el, &c) != 1) return ed_end_of_file(el, 0); + ch = c; } /* Save for ';' and ',' commands */ - el->el_search.chacha = (Char)ch; + el->el_search.chacha = ch; el->el_search.chadir = direction; el->el_search.chatflg = (char)tflag; cp = el->el_line.cursor; while (count--) { - if ((wint_t)*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 ((wint_t)*cp == ch) + if ((Int)*cp == ch) break; } } diff --git a/lib/libedit/search.h b/lib/libedit/search.h index 1e745bd..02c8f5d 100644 --- a/lib/libedit/search.h +++ b/lib/libedit/search.h @@ -1,4 +1,4 @@ -/* $NetBSD: search.h,v 1.12 2016/02/16 15:53:48 christos Exp $ */ +/* $NetBSD: search.h,v 1.9 2009/12/30 22:37:40 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,6 +41,8 @@ #ifndef _h_el_search #define _h_el_search +#include "histedit.h" + typedef struct el_search_t { Char *patbuf; /* The pattern buffer */ size_t patlen; /* Length of the pattern buffer */ @@ -59,7 +61,7 @@ protected void c_setpat(EditLine *); protected el_action_t ce_inc_search(EditLine *, int); protected el_action_t cv_search(EditLine *, int); protected el_action_t ce_search_line(EditLine *, int); -protected el_action_t cv_repeat_srch(EditLine *, wint_t); -protected el_action_t cv_csearch(EditLine *, int, wint_t, int, int); +protected el_action_t cv_repeat_srch(EditLine *, Int); +protected el_action_t cv_csearch(EditLine *, int, Int, int, int); #endif /* _h_el_search */ diff --git a/lib/libedit/sig.c b/lib/libedit/sig.c index f37a12e..babec69 100644 --- a/lib/libedit/sig.c +++ b/lib/libedit/sig.c @@ -1,4 +1,4 @@ -/* $NetBSD: sig.c,v 1.24 2016/02/16 19:08:41 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.24 2016/02/16 19:08:41 christos Exp $"); +__RCSID("$NetBSD: sig.c,v 1.17 2011/07/28 20:50:55 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -48,11 +48,8 @@ __FBSDID("$FreeBSD$"); * our policy is to trap all signals, set a good state * and pass the ball to our caller. */ -#include <errno.h> -#include <stdlib.h> - #include "el.h" -#include "common.h" +#include <stdlib.h> private EditLine *sel = NULL; @@ -73,10 +70,9 @@ private void sig_handler(int); private void sig_handler(int signo) { - int i, save_errno; + int i; sigset_t nset, oset; - save_errno = errno; (void) sigemptyset(&nset); (void) sigaddset(&nset, signo); (void) sigprocmask(SIG_BLOCK, &nset, &oset); @@ -110,7 +106,6 @@ sig_handler(int signo) sigemptyset(&sel->el_signal->sig_action[i].sa_mask); (void) sigprocmask(SIG_SETMASK, &oset, NULL); (void) kill(0, signo); - errno = save_errno; } diff --git a/lib/libedit/sig.h b/lib/libedit/sig.h index 34ec1da..a096681 100644 --- a/lib/libedit/sig.h +++ b/lib/libedit/sig.h @@ -1,4 +1,4 @@ -/* $NetBSD: sig.h,v 1.10 2016/02/16 15:53:48 christos Exp $ */ +/* $NetBSD: sig.h,v 1.8 2009/02/19 15:20:22 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -43,6 +43,8 @@ #include <signal.h> +#include "histedit.h" + /* * Define here all the signals we are going to handle * The _DO macro is used to iterate in the source code diff --git a/lib/libedit/sys.h b/lib/libedit/sys.h index 3807c95..d005ffd 100644 --- a/lib/libedit/sys.h +++ b/lib/libedit/sys.h @@ -1,4 +1,4 @@ -/* $NetBSD: sys.h,v 1.23 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: sys.h,v 1.17 2011/09/28 14:08:04 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -58,7 +58,7 @@ # define __END_DECLS # endif #endif - + #ifndef public # define public /* Externally visible functions/variables */ #endif @@ -88,9 +88,14 @@ size_t strlcat(char *dst, const char *src, size_t size); size_t strlcpy(char *dst, const char *src, size_t size); #endif -#ifndef HAVE_GETLINE -#define getline libedit_getline -ssize_t getline(char **line, size_t *len, FILE *fp); +#ifndef HAVE_FGETLN +#define fgetln libedit_fgetln +char *fgetln(FILE *fp, size_t *len); +#endif + +#ifndef HAVE_WCSDUP +#include <wchar.h> +wchar_t *wcsdup(const wchar_t *); #endif #ifndef _DIAGASSERT @@ -105,18 +110,13 @@ ssize_t getline(char **line, size_t *len, FILE *fp); typedef unsigned int u_int32_t; #endif -#ifndef HAVE_SIZE_MAX -#define SIZE_MAX ((size_t)-1) +#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 */ -#ifndef WIDECHAR -#define setlocale(c, l) /*LINTED*/NULL -#define nl_langinfo(i) "" -#endif - #if defined(__sun) extern int tgetent(char *, const char *); extern int tgetflag(char *); diff --git a/lib/libedit/terminal.c b/lib/libedit/terminal.c index be76960..0709d53 100644 --- a/lib/libedit/terminal.c +++ b/lib/libedit/terminal.c @@ -1,4 +1,4 @@ -/* $NetBSD: terminal.c,v 1.22 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95"; #else -__RCSID("$NetBSD: terminal.c,v 1.22 2016/02/17 19:47:49 christos Exp $"); +__RCSID("$NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -48,14 +48,12 @@ __FBSDID("$FreeBSD$"); * We have to declare a static variable here, since the * termcap putchar routine does not take an argument! */ -#include <sys/types.h> -#include <sys/ioctl.h> -#include <limits.h> -#include <signal.h> #include <stdio.h> -#include <stdlib.h> +#include <signal.h> #include <string.h> +#include <stdlib.h> #include <unistd.h> +#include <limits.h> #ifdef HAVE_TERMCAP_H #include <termcap.h> #endif @@ -69,6 +67,9 @@ __FBSDID("$FreeBSD$"); #if defined(HAVE_TERM_H) && !defined(__sun) && !defined(HAVE_TERMCAP_H) #include <term.h> #endif + +#include <sys/types.h> +#include <sys/ioctl.h> #ifdef _REENTRANT #include <pthread.h> @@ -273,45 +274,31 @@ terminal_init(EditLine *el) el->el_terminal.t_buf = el_malloc(TC_BUFSIZE * sizeof(*el->el_terminal.t_buf)); if (el->el_terminal.t_buf == NULL) - goto fail1; + return -1; el->el_terminal.t_cap = el_malloc(TC_BUFSIZE * sizeof(*el->el_terminal.t_cap)); if (el->el_terminal.t_cap == NULL) - goto fail2; + return -1; el->el_terminal.t_fkey = el_malloc(A_K_NKEYS * sizeof(*el->el_terminal.t_fkey)); if (el->el_terminal.t_fkey == NULL) - goto fail3; + return -1; el->el_terminal.t_loc = 0; el->el_terminal.t_str = el_malloc(T_str * sizeof(*el->el_terminal.t_str)); if (el->el_terminal.t_str == NULL) - goto fail4; + return -1; (void) memset(el->el_terminal.t_str, 0, T_str * sizeof(*el->el_terminal.t_str)); el->el_terminal.t_val = el_malloc(T_val * sizeof(*el->el_terminal.t_val)); if (el->el_terminal.t_val == NULL) - goto fail5; + return -1; (void) memset(el->el_terminal.t_val, 0, T_val * sizeof(*el->el_terminal.t_val)); (void) terminal_set(el, NULL); terminal_init_arrow(el); return 0; -fail5: - free(el->el_terminal.t_str); - el->el_terminal.t_str = NULL; -fail4: - free(el->el_terminal.t_fkey); - el->el_terminal.t_fkey = NULL; -fail3: - free(el->el_terminal.t_cap); - el->el_terminal.t_cap = NULL; -fail2: - free(el->el_terminal.t_buf); - el->el_terminal.t_buf = NULL; -fail1: - return -1; } /* terminal_end(): @@ -433,14 +420,14 @@ terminal_alloc_display(EditLine *el) b = el_malloc(sizeof(*b) * (size_t)(c->v + 1)); if (b == NULL) - goto done; + return -1; for (i = 0; i < c->v; i++) { b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1)); if (b[i] == NULL) { while (--i >= 0) el_free(b[i]); el_free(b); - goto done; + return -1; } } b[c->v] = NULL; @@ -448,22 +435,19 @@ terminal_alloc_display(EditLine *el) b = el_malloc(sizeof(*b) * (size_t)(c->v + 1)); if (b == NULL) - goto done; + return -1; for (i = 0; i < c->v; i++) { b[i] = el_malloc(sizeof(**b) * (size_t)(c->h + 1)); if (b[i] == NULL) { while (--i >= 0) el_free(b[i]); el_free(b); - goto done; + return -1; } } b[c->v] = NULL; el->el_vdisplay = b; return 0; -done: - terminal_free_display(el); - return -1; } @@ -495,7 +479,7 @@ terminal_free_display(EditLine *el) /* terminal_move_to_line(): * move to line <where> (first line == 0) - * as efficiently as possible + * as efficiently as possible */ protected void terminal_move_to_line(EditLine *el, int where) @@ -508,7 +492,8 @@ terminal_move_to_line(EditLine *el, int where) if (where > el->el_terminal.t_size.v) { #ifdef DEBUG_SCREEN (void) fprintf(el->el_errfile, - "%s: where is ridiculous: %d\r\n", __func__, where); + "terminal_move_to_line: where is ridiculous: %d\r\n", + where); #endif /* DEBUG_SCREEN */ return; } @@ -574,7 +559,8 @@ mc_again: if (where > el->el_terminal.t_size.h) { #ifdef DEBUG_SCREEN (void) fprintf(el->el_errfile, - "%s: where is ridiculous: %d\r\n", __func__, where); + "terminal_move_to_char: where is riduculous: %d\r\n", + where); #endif /* DEBUG_SCREEN */ return; } @@ -610,7 +596,7 @@ mc_again: i < (where & ~0x7); i += 8) terminal__putc(el, - '\t'); + '\t'); /* then tab over */ el->el_cursor.h = where & ~0x7; } @@ -668,7 +654,7 @@ terminal_overwrite(EditLine *el, const Char *cp, size_t n) if (n > (size_t)el->el_terminal.t_size.h) { #ifdef DEBUG_SCREEN (void) fprintf(el->el_errfile, - "%s: n is ridiculous: %d\r\n", __func__, n); + "terminal_overwrite: n is riduculous: %d\r\n", n); #endif /* DEBUG_SCREEN */ return; } @@ -724,7 +710,7 @@ terminal_deletechars(EditLine *el, int num) if (num > el->el_terminal.t_size.h) { #ifdef DEBUG_SCREEN (void) fprintf(el->el_errfile, - "%s: num is ridiculous: %d\r\n", __func__, num); + "terminal_deletechars: num is riduculous: %d\r\n", num); #endif /* DEBUG_SCREEN */ return; } @@ -765,7 +751,7 @@ terminal_insertwrite(EditLine *el, Char *cp, int num) if (num > el->el_terminal.t_size.h) { #ifdef DEBUG_SCREEN (void) fprintf(el->el_errfile, - "%s: num is ridiculous: %d\r\n", __func__, num); + "StartInsert: num is riduculous: %d\r\n", num); #endif /* DEBUG_SCREEN */ return; } @@ -1255,13 +1241,13 @@ terminal_tputs(EditLine *el, const char *cap, int affcnt) * Add a character */ protected int -terminal__putc(EditLine *el, wint_t c) +terminal__putc(EditLine *el, Int c) { char buf[MB_LEN_MAX +1]; ssize_t i; - if (c == (wint_t)MB_FILL_CHAR) + if (c == (Int)MB_FILL_CHAR) return 0; - i = ct_encode_char(buf, (size_t)MB_LEN_MAX, (Char)c); + i = ct_encode_char(buf, (size_t)MB_LEN_MAX, c); if (i <= 0) return (int)i; buf[i] = '\0'; @@ -1282,10 +1268,10 @@ terminal__flush(EditLine *el) * Write the given character out, in a human readable form */ protected void -terminal_writec(EditLine *el, wint_t c) +terminal_writec(EditLine *el, Int c) { Char visbuf[VISUAL_WIDTH_MAX +1]; - ssize_t vcnt = ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c); + ssize_t vcnt = ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c); if (vcnt < 0) vcnt = 0; visbuf[vcnt] = '\0'; @@ -1299,7 +1285,7 @@ terminal_writec(EditLine *el, wint_t c) */ protected int /*ARGSUSED*/ -terminal_telltc(EditLine *el, int argc __attribute__((__unused__)), +terminal_telltc(EditLine *el, int argc __attribute__((__unused__)), const Char **argv __attribute__((__unused__))) { const struct termcapstr *t; diff --git a/lib/libedit/terminal.h b/lib/libedit/terminal.h index 9c66c19..f26f5e1 100644 --- a/lib/libedit/terminal.h +++ b/lib/libedit/terminal.h @@ -1,4 +1,4 @@ -/* $NetBSD: terminal.h,v 1.7 2016/02/16 15:53:48 christos Exp $ */ +/* $NetBSD: terminal.h,v 1.4 2012/03/24 20:09:30 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,6 +41,8 @@ #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 */ @@ -103,8 +105,8 @@ 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 *, wint_t); -protected int terminal__putc(EditLine *, wint_t); +protected void terminal_writec(EditLine *, Int); +protected int terminal__putc(EditLine *, Int); protected void terminal__flush(EditLine *); /* diff --git a/lib/libedit/tokenizer.c b/lib/libedit/tokenizer.c index 23f940f..f5171c4 100644 --- a/lib/libedit/tokenizer.c +++ b/lib/libedit/tokenizer.c @@ -1,4 +1,4 @@ -/* $NetBSD: tokenizer.c,v 1.24 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: tokenizer.c,v 1.22 2016/01/30 04:02:51 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.24 2016/02/17 19:47:49 christos Exp $"); +__RCSID("$NetBSD: tokenizer.c,v 1.22 2016/01/30 04:02:51 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -47,9 +47,8 @@ __FBSDID("$FreeBSD$"); /* * tokenize.c: Bourne shell like tokenizer */ -#include <stdlib.h> #include <string.h> - +#include <stdlib.h> #include "histedit.h" #include "chartype.h" @@ -416,10 +415,8 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line, Char **p; tok->amax += AINCR; p = tok_realloc(tok->argv, tok->amax * sizeof(*p)); - if (p == NULL) { - tok->amax -= AINCR; + if (p == NULL) return -1; - } tok->argv = p; } } diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c index 7cfa6d1..a508e43 100644 --- a/lib/libedit/tty.c +++ b/lib/libedit/tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.58 2016/02/27 18:13:21 christos Exp $ */ +/* $NetBSD: tty.c,v 1.49 2015/12/08 16:53:27 gson Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tty.c,v 1.58 2016/02/27 18:13:21 christos Exp $"); +__RCSID("$NetBSD: tty.c,v 1.49 2015/12/08 16:53:27 gson Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -48,13 +48,11 @@ __FBSDID("$FreeBSD$"); */ #include <assert.h> #include <errno.h> -#include <stdlib.h> /* for abort */ -#include <string.h> -#include <strings.h> /* for ffs */ #include <unistd.h> /* for isatty */ - +#include <strings.h> /* for ffs */ +#include <stdlib.h> /* for abort */ #include "el.h" -#include "parse.h" +#include "tty.h" typedef struct ttymodes_t { const char *m_name; @@ -63,7 +61,7 @@ typedef struct ttymodes_t { } ttymodes_t; typedef struct ttymap_t { - wint_t nch, och; /* Internal and termio rep of chars */ + Int nch, och; /* Internal and termio rep of chars */ el_action_t bind[3]; /* emacs, vi, and vi-cmd */ } ttymap_t; @@ -159,7 +157,7 @@ private const ttymap_t tty_map[] = { {C_LNEXT, VLNEXT, {ED_QUOTED_INSERT, ED_QUOTED_INSERT, ED_UNASSIGNED}}, #endif /* VLNEXT */ - {(wint_t)-1, (wint_t)-1, + {(Int)-1, (Int)-1, {ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED}} }; @@ -500,7 +498,6 @@ tty_setup(EditLine *el) { int rst = 1; - el->el_tty.t_initialized = 0; if (el->el_flags & EDIT_DISABLED) return 0; @@ -563,7 +560,6 @@ tty_setup(EditLine *el) tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]); tty_bind_char(el, 1); - el->el_tty.t_initialized = 1; return 0; } @@ -589,9 +585,6 @@ tty_end(EditLine *el) if (el->el_flags & EDIT_DISABLED) return; - if (el->el_tty.t_initialized) - return; - if (tty_setty(el, TCSAFLUSH, &el->el_tty.t_or) == -1) { #ifdef DEBUG_TTY (void) fprintf(el->el_errfile, @@ -911,9 +904,9 @@ tty_bind_char(EditLine *el, int force) dalt = NULL; } - for (tp = tty_map; tp->nch != (wint_t)-1; tp++) { - new[0] = (Char)t_n[tp->nch]; - old[0] = (Char)t_o[tp->och]; + 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 */ @@ -985,7 +978,7 @@ tty_update_char(EditLine *el, int mode, int c) { /* tty_rawmode(): - * Set terminal into 1 character at a time mode. + * Set terminal into 1 character at a time mode. */ protected int tty_rawmode(EditLine *el) @@ -1183,8 +1176,8 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv) break; default: (void) fprintf(el->el_errfile, - "%s: Unknown switch `%lc'.\n", - name, (wint_t)argv[0][1]); + "%s: Unknown switch `" FCHAR "'.\n", + name, (Int)argv[0][1]); return -1; } diff --git a/lib/libedit/tty.h b/lib/libedit/tty.h index 9694393..b1fc76e 100644 --- a/lib/libedit/tty.h +++ b/lib/libedit/tty.h @@ -1,4 +1,4 @@ -/* $NetBSD: tty.h,v 1.19 2016/02/27 18:13:21 christos Exp $ */ +/* $NetBSD: tty.h,v 1.15 2014/05/19 19:54:12 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,6 +41,8 @@ #ifndef _h_el_tty #define _h_el_tty +#include "sys.h" +#include "histedit.h" #include <termios.h> #include <unistd.h> @@ -473,9 +475,8 @@ typedef struct { int t_tabs; int t_eight; speed_t t_speed; - unsigned char t_mode; + int t_mode; unsigned char t_vdisable; - unsigned char t_initialized; } el_tty_t; diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c index be35a8e..0a426fd 100644 --- a/lib/libedit/vi.c +++ b/lib/libedit/vi.c @@ -1,4 +1,4 @@ -/* $NetBSD: vi.c,v 1.54 2016/02/17 19:47:49 christos Exp $ */ +/* $NetBSD: vi.c,v 1.47 2015/10/21 21:45:30 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -33,11 +33,16 @@ */ #include "config.h" +#include <stdlib.h> +#include <unistd.h> +#include <limits.h> +#include <sys/wait.h> + #if !defined(lint) && !defined(SCCSID) #if 0 static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vi.c,v 1.54 2016/02/17 19:47:49 christos Exp $"); +__RCSID("$NetBSD: vi.c,v 1.47 2015/10/21 21:45:30 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -46,31 +51,21 @@ __FBSDID("$FreeBSD$"); /* * vi.c: Vi mode commands. */ -#include <sys/wait.h> -#include <ctype.h> -#include <limits.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - #include "el.h" -#include "common.h" -#include "emacs.h" -#include "vi.h" -private el_action_t cv_action(EditLine *, wint_t); -private el_action_t cv_paste(EditLine *, wint_t); +private el_action_t cv_action(EditLine *, Int); +private el_action_t cv_paste(EditLine *, Int); /* cv_action(): * Handle vi actions. */ private el_action_t -cv_action(EditLine *el, wint_t c) +cv_action(EditLine *el, Int c) { if (el->el_chared.c_vcmd.action != NOP) { /* 'cc', 'dd' and (possibly) friends */ - if (c != (wint_t)el->el_chared.c_vcmd.action) + if (c != (Int)el->el_chared.c_vcmd.action) return CC_ERROR; if (!(c & YANK)) @@ -97,7 +92,7 @@ cv_action(EditLine *el, wint_t c) * Paste previous deletion before or after the cursor */ private el_action_t -cv_paste(EditLine *el, wint_t c) +cv_paste(EditLine *el, Int c) { c_kill_t *k = &el->el_chared.c_kill; size_t len = (size_t)(k->last - k->buf); @@ -129,7 +124,7 @@ cv_paste(EditLine *el, wint_t c) */ protected el_action_t /*ARGSUSED*/ -vi_paste_next(EditLine *el, wint_t c __attribute__((__unused__))) +vi_paste_next(EditLine *el, Int c __attribute__((__unused__))) { return cv_paste(el, 0); @@ -142,7 +137,7 @@ vi_paste_next(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_paste_prev(EditLine *el, wint_t c __attribute__((__unused__))) +vi_paste_prev(EditLine *el, Int c __attribute__((__unused__))) { return cv_paste(el, 1); @@ -155,7 +150,7 @@ vi_paste_prev(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_prev_big_word(EditLine *el, wint_t c __attribute__((__unused__))) +vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -180,7 +175,7 @@ vi_prev_big_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) +vi_prev_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -205,7 +200,7 @@ vi_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_next_big_word(EditLine *el, wint_t c __attribute__((__unused__))) +vi_next_big_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar - 1) @@ -229,7 +224,7 @@ vi_next_big_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_next_word(EditLine *el, wint_t c __attribute__((__unused__))) +vi_next_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar - 1) @@ -252,7 +247,7 @@ vi_next_word(EditLine *el, wint_t c __attribute__((__unused__))) * [~] */ protected el_action_t -vi_change_case(EditLine *el, wint_t c) +vi_change_case(EditLine *el, Int c) { int i; @@ -284,7 +279,7 @@ vi_change_case(EditLine *el, wint_t c) */ protected el_action_t /*ARGSUSED*/ -vi_change_meta(EditLine *el, wint_t c __attribute__((__unused__))) +vi_change_meta(EditLine *el, Int c __attribute__((__unused__))) { /* @@ -301,7 +296,7 @@ vi_change_meta(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_insert_at_bol(EditLine *el, wint_t c __attribute__((__unused__))) +vi_insert_at_bol(EditLine *el, Int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -317,7 +312,7 @@ vi_insert_at_bol(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_replace_char(EditLine *el, wint_t c __attribute__((__unused__))) +vi_replace_char(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar) @@ -336,7 +331,7 @@ vi_replace_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_replace_mode(EditLine *el, wint_t c __attribute__((__unused__))) +vi_replace_mode(EditLine *el, Int c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -352,7 +347,7 @@ vi_replace_mode(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_substitute_char(EditLine *el, wint_t c __attribute__((__unused__))) +vi_substitute_char(EditLine *el, Int c __attribute__((__unused__))) { c_delafter(el, el->el_state.argument); @@ -367,7 +362,7 @@ vi_substitute_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_substitute_line(EditLine *el, wint_t c __attribute__((__unused__))) +vi_substitute_line(EditLine *el, Int c __attribute__((__unused__))) { cv_undo(el); @@ -385,7 +380,7 @@ vi_substitute_line(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_change_to_eol(EditLine *el, wint_t c __attribute__((__unused__))) +vi_change_to_eol(EditLine *el, Int c __attribute__((__unused__))) { cv_undo(el); @@ -403,7 +398,7 @@ vi_change_to_eol(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_insert(EditLine *el, wint_t c __attribute__((__unused__))) +vi_insert(EditLine *el, Int c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -418,7 +413,7 @@ vi_insert(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_add(EditLine *el, wint_t c __attribute__((__unused__))) +vi_add(EditLine *el, Int c __attribute__((__unused__))) { int ret; @@ -443,7 +438,7 @@ vi_add(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_add_at_eol(EditLine *el, wint_t c __attribute__((__unused__))) +vi_add_at_eol(EditLine *el, Int c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -459,7 +454,7 @@ vi_add_at_eol(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_delete_meta(EditLine *el, wint_t c __attribute__((__unused__))) +vi_delete_meta(EditLine *el, Int c __attribute__((__unused__))) { return cv_action(el, DELETE); @@ -472,7 +467,7 @@ vi_delete_meta(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_end_big_word(EditLine *el, wint_t c __attribute__((__unused__))) +vi_end_big_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) @@ -496,7 +491,7 @@ vi_end_big_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_end_word(EditLine *el, wint_t c __attribute__((__unused__))) +vi_end_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) @@ -520,7 +515,7 @@ vi_end_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_undo(EditLine *el, wint_t c __attribute__((__unused__))) +vi_undo(EditLine *el, Int c __attribute__((__unused__))) { c_undo_t un = el->el_chared.c_undo; @@ -547,7 +542,7 @@ vi_undo(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_command_mode(EditLine *el, wint_t c __attribute__((__unused__))) +vi_command_mode(EditLine *el, Int c __attribute__((__unused__))) { /* [Esc] cancels pending action */ @@ -571,7 +566,7 @@ vi_command_mode(EditLine *el, wint_t c __attribute__((__unused__))) * [0] */ protected el_action_t -vi_zero(EditLine *el, wint_t c) +vi_zero(EditLine *el, Int c) { if (el->el_state.doingarg) @@ -587,12 +582,12 @@ vi_zero(EditLine *el, wint_t c) /* vi_delete_prev_char(): - * Vi move to previous character (backspace) + * Vi move to previous character (backspace) * [^H] in insert mode only */ protected el_action_t /*ARGSUSED*/ -vi_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) +vi_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) @@ -610,7 +605,7 @@ vi_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_list_or_eof(EditLine *el, wint_t c) +vi_list_or_eof(EditLine *el, Int c) { if (el->el_line.cursor == el->el_line.lastchar) { @@ -647,7 +642,7 @@ vi_list_or_eof(EditLine *el, wint_t c) */ protected el_action_t /*ARGSUSED*/ -vi_kill_line_prev(EditLine *el, wint_t c __attribute__((__unused__))) +vi_kill_line_prev(EditLine *el, Int c __attribute__((__unused__))) { Char *kp, *cp; @@ -668,7 +663,7 @@ vi_kill_line_prev(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) +vi_search_prev(EditLine *el, Int c __attribute__((__unused__))) { return cv_search(el, ED_SEARCH_PREV_HISTORY); @@ -681,7 +676,7 @@ vi_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_search_next(EditLine *el, wint_t c __attribute__((__unused__))) +vi_search_next(EditLine *el, Int c __attribute__((__unused__))) { return cv_search(el, ED_SEARCH_NEXT_HISTORY); @@ -694,7 +689,7 @@ vi_search_next(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_repeat_search_next(EditLine *el, wint_t c __attribute__((__unused__))) +vi_repeat_search_next(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_search.patlen == 0) @@ -710,7 +705,7 @@ vi_repeat_search_next(EditLine *el, wint_t c __attribute__((__unused__))) */ /*ARGSUSED*/ protected el_action_t -vi_repeat_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) +vi_repeat_search_prev(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_search.patlen == 0) @@ -728,7 +723,7 @@ vi_repeat_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_next_char(EditLine *el, wint_t c __attribute__((__unused__))) +vi_next_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0); } @@ -740,7 +735,7 @@ vi_next_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) +vi_prev_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0); } @@ -752,7 +747,7 @@ vi_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_to_next_char(EditLine *el, wint_t c __attribute__((__unused__))) +vi_to_next_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1); } @@ -764,7 +759,7 @@ vi_to_next_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_to_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) +vi_to_prev_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1); } @@ -776,7 +771,7 @@ vi_to_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_repeat_next_char(EditLine *el, wint_t c __attribute__((__unused__))) +vi_repeat_next_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, el->el_search.chadir, el->el_search.chacha, @@ -790,7 +785,7 @@ vi_repeat_next_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_repeat_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) +vi_repeat_prev_char(EditLine *el, Int c __attribute__((__unused__))) { el_action_t r; int dir = el->el_search.chadir; @@ -808,7 +803,7 @@ vi_repeat_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_match(EditLine *el, wint_t c __attribute__((__unused__))) +vi_match(EditLine *el, Int c __attribute__((__unused__))) { const Char match_chars[] = STR("()[]{}"); Char *cp; @@ -855,7 +850,7 @@ vi_match(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_undo_line(EditLine *el, wint_t c __attribute__((__unused__))) +vi_undo_line(EditLine *el, Int c __attribute__((__unused__))) { cv_undo(el); @@ -869,7 +864,7 @@ vi_undo_line(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_to_column(EditLine *el, wint_t c __attribute__((__unused__))) +vi_to_column(EditLine *el, Int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -883,7 +878,7 @@ vi_to_column(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_yank_end(EditLine *el, wint_t c __attribute__((__unused__))) +vi_yank_end(EditLine *el, Int c __attribute__((__unused__))) { cv_yank(el, el->el_line.cursor, @@ -897,7 +892,7 @@ vi_yank_end(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_yank(EditLine *el, wint_t c __attribute__((__unused__))) +vi_yank(EditLine *el, Int c __attribute__((__unused__))) { return cv_action(el, YANK); @@ -909,7 +904,7 @@ vi_yank(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_comment_out(EditLine *el, wint_t c __attribute__((__unused__))) +vi_comment_out(EditLine *el, Int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -927,7 +922,7 @@ vi_comment_out(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_alias(EditLine *el, wint_t c __attribute__((__unused__))) +vi_alias(EditLine *el, Int c __attribute__((__unused__))) { char alias_name[3]; const char *alias_text; @@ -953,7 +948,7 @@ vi_alias(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__))) +vi_to_history_line(EditLine *el, Int c __attribute__((__unused__))) { int sv_event_no = el->el_history.eventno; el_action_t rval; @@ -979,7 +974,7 @@ vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__))) el->el_history.eventno = 1; if (hist_get(el) == CC_ERROR) return CC_ERROR; - el->el_history.eventno = 1 + el->el_history.ev.num + el->el_history.eventno = 1 + el->el_history.ev.num - el->el_state.argument; if (el->el_history.eventno < 0) { el->el_history.eventno = sv_event_no; @@ -998,7 +993,7 @@ vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_histedit(EditLine *el, wint_t c __attribute__((__unused__))) +vi_histedit(EditLine *el, Int c __attribute__((__unused__))) { int fd; pid_t pid; @@ -1082,7 +1077,7 @@ error: */ protected el_action_t /*ARGSUSED*/ -vi_history_word(EditLine *el, wint_t c __attribute__((__unused__))) +vi_history_word(EditLine *el, Int c __attribute__((__unused__))) { const Char *wp = HIST_FIRST(el); const Char *wep, *wsp; @@ -1132,7 +1127,7 @@ vi_history_word(EditLine *el, wint_t c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_redo(EditLine *el, wint_t c __attribute__((__unused__))) +vi_redo(EditLine *el, Int c __attribute__((__unused__))) { c_redo_t *r = &el->el_chared.c_redo; |