From: zrj Date: Tue, 30 Apr 2019 17:59:56 +0000 (+0300) Subject: Merge remote-tracking branch 'origin/vendor/LIBEDIT' X-Git-Tag: v5.7.0~162 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/30baa437bb9bd1152f19689c2d0442f652174e87?hp=02aa41ec2539e6bd53a7ebc8fdd9b77e10c21097 Merge remote-tracking branch 'origin/vendor/LIBEDIT' Conflicts: contrib/libedit/src/chartype.h contrib/libedit/src/eln.c contrib/libedit/src/filecomplete.c contrib/libedit/src/sys.h --- diff --git a/contrib/libedit/src/chared.c b/contrib/libedit/src/chared.c index 3934a684f7..9d46ba68fe 100644 --- a/contrib/libedit/src/chared.c +++ b/contrib/libedit/src/chared.c @@ -1,4 +1,4 @@ -/* $NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $ */ +/* $NetBSD: chared.c,v 1.56 2016/05/22 19:44:26 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,17 +37,20 @@ #if 0 static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $"); +__RCSID("$NetBSD: chared.c,v 1.56 2016/05/22 19:44:26 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * chared.c: Character editor utilities */ +#include #include -#include "el.h" +#include -private void ch__clearmacro (EditLine *); +#include "el.h" +#include "common.h" +#include "fcns.h" /* value to leave unused in line buffer */ #define EL_LEAVE 2 @@ -55,7 +58,7 @@ private void ch__clearmacro (EditLine *); /* cv_undo(): * Handle state for the vi undo command */ -protected void +libedit_private void cv_undo(EditLine *el) { c_undo_t *vu = &el->el_chared.c_undo; @@ -79,8 +82,8 @@ cv_undo(EditLine *el) /* cv_yank(): * Save yank/delete data for paste */ -protected void -cv_yank(EditLine *el, const Char *ptr, int size) +libedit_private void +cv_yank(EditLine *el, const wchar_t *ptr, int size) { c_kill_t *k = &el->el_chared.c_kill; @@ -92,10 +95,10 @@ cv_yank(EditLine *el, const Char *ptr, int size) /* c_insert(): * Insert num characters */ -protected void +libedit_private void c_insert(EditLine *el, int num) { - Char *cp; + wchar_t *cp; if (el->el_line.lastchar + num >= el->el_line.limit) { if (!ch_enlargebufs(el, (size_t)num)) @@ -114,7 +117,7 @@ c_insert(EditLine *el, int num) /* c_delafter(): * Delete num characters after the cursor */ -protected void +libedit_private void c_delafter(EditLine *el, int num) { @@ -127,7 +130,7 @@ c_delafter(EditLine *el, int num) } if (num > 0) { - Char *cp; + wchar_t *cp; for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++) *cp = cp[num]; @@ -140,10 +143,10 @@ c_delafter(EditLine *el, int num) /* c_delafter1(): * Delete the character after the cursor, do not yank */ -protected void +libedit_private void c_delafter1(EditLine *el) { - Char *cp; + wchar_t *cp; for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++) *cp = cp[1]; @@ -155,7 +158,7 @@ c_delafter1(EditLine *el) /* c_delbefore(): * Delete num characters before the cursor */ -protected void +libedit_private void c_delbefore(EditLine *el, int num) { @@ -168,7 +171,7 @@ c_delbefore(EditLine *el, int num) } if (num > 0) { - Char *cp; + wchar_t *cp; for (cp = el->el_line.cursor - num; cp <= el->el_line.lastchar; @@ -183,10 +186,10 @@ c_delbefore(EditLine *el, int num) /* c_delbefore1(): * Delete the character before the cursor, do not yank */ -protected void +libedit_private void c_delbefore1(EditLine *el) { - Char *cp; + wchar_t *cp; for (cp = el->el_line.cursor - 1; cp <= el->el_line.lastchar; cp++) *cp = cp[1]; @@ -198,22 +201,22 @@ c_delbefore1(EditLine *el) /* ce__isword(): * Return if p is part of a word according to emacs */ -protected int -ce__isword(Int p) +libedit_private int +ce__isword(wint_t p) { - return Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL; + return iswalnum(p) || wcschr(L"*?_-.[]~=", p) != NULL; } /* cv__isword(): * Return if p is part of a word according to vi */ -protected int -cv__isword(Int p) +libedit_private int +cv__isword(wint_t p) { - if (Isalnum(p) || p == '_') + if (iswalnum(p) || p == L'_') return 1; - if (Isgraph(p)) + if (iswgraph(p)) return 2; return 0; } @@ -222,18 +225,18 @@ cv__isword(Int p) /* cv__isWord(): * Return if p is part of a big word according to vi */ -protected int -cv__isWord(Int p) +libedit_private int +cv__isWord(wint_t p) { - return !Isspace(p); + return !iswspace(p); } /* c__prev_word(): * Find the previous word */ -protected Char * -c__prev_word(Char *p, Char *low, int n, int (*wtest)(Int)) +libedit_private wchar_t * +c__prev_word(wchar_t *p, wchar_t *low, int n, int (*wtest)(wint_t)) { p--; @@ -256,8 +259,8 @@ c__prev_word(Char *p, Char *low, int n, int (*wtest)(Int)) /* c__next_word(): * Find the next word */ -protected Char * -c__next_word(Char *p, Char *high, int n, int (*wtest)(Int)) +libedit_private wchar_t * +c__next_word(wchar_t *p, wchar_t *high, int n, int (*wtest)(wint_t)) { while (n--) { while ((p < high) && !(*wtest)(*p)) @@ -274,8 +277,9 @@ c__next_word(Char *p, Char *high, int n, int (*wtest)(Int)) /* cv_next_word(): * Find the next word vi style */ -protected Char * -cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int)) +libedit_private wchar_t * +cv_next_word(EditLine *el, wchar_t *p, wchar_t *high, int n, + int (*wtest)(wint_t)) { int test; @@ -288,7 +292,7 @@ cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int)) * trailing whitespace! This is not what 'w' does.. */ if (n || el->el_chared.c_vcmd.action != (DELETE|INSERT)) - while ((p < high) && Isspace(*p)) + while ((p < high) && iswspace(*p)) p++; } @@ -303,14 +307,14 @@ cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int)) /* cv_prev_word(): * Find the previous word vi style */ -protected Char * -cv_prev_word(Char *p, Char *low, int n, int (*wtest)(Int)) +libedit_private wchar_t * +cv_prev_word(wchar_t *p, wchar_t *low, int n, int (*wtest)(wint_t)) { int test; p--; while (n--) { - while ((p > low) && Isspace(*p)) + while ((p > low) && iswspace(*p)) p--; test = (*wtest)(*p); while ((p >= low) && (*wtest)(*p) == test) @@ -329,7 +333,7 @@ cv_prev_word(Char *p, Char *low, int n, int (*wtest)(Int)) /* cv_delfini(): * Finish vi delete action */ -protected void +libedit_private void cv_delfini(EditLine *el) { int size; @@ -367,15 +371,15 @@ cv_delfini(EditLine *el) /* cv__endword(): * Go to the end of this word according to vi */ -protected Char * -cv__endword(Char *p, Char *high, int n, int (*wtest)(Int)) +libedit_private wchar_t * +cv__endword(wchar_t *p, wchar_t *high, int n, int (*wtest)(wint_t)) { int test; p++; while (n--) { - while ((p < high) && Isspace(*p)) + while ((p < high) && iswspace(*p)) p++; test = (*wtest)(*p); @@ -389,11 +393,9 @@ cv__endword(Char *p, Char *high, int n, int (*wtest)(Int)) /* ch_init(): * Initialize the character editor */ -protected int +libedit_private int ch_init(EditLine *el) { - c_macro_t *ma = &el->el_chared.c_macro; - el->el_line.buffer = el_malloc(EL_BUFSIZ * sizeof(*el->el_line.buffer)); if (el->el_line.buffer == NULL) @@ -445,19 +447,14 @@ ch_init(EditLine *el) el->el_state.argument = 1; el->el_state.lastcmd = ED_UNASSIGNED; - ma->level = -1; - ma->offset = 0; - ma->macro = el_malloc(EL_MAXMACRO * sizeof(*ma->macro)); - if (ma->macro == NULL) - return -1; return 0; } /* ch_reset(): * Reset the character editor */ -protected void -ch_reset(EditLine *el, int mclear) +libedit_private void +ch_reset(EditLine *el) { el->el_line.cursor = el->el_line.buffer; el->el_line.lastchar = el->el_line.buffer; @@ -479,28 +476,17 @@ ch_reset(EditLine *el, int mclear) el->el_state.lastcmd = ED_UNASSIGNED; el->el_history.eventno = 0; - - if (mclear) - ch__clearmacro(el); -} - -private void -ch__clearmacro(EditLine *el) -{ - c_macro_t *ma = &el->el_chared.c_macro; - while (ma->level >= 0) - el_free(ma->macro[ma->level--]); } /* ch_enlargebufs(): * Enlarge line buffer to be able to hold twice as much characters. * Returns 1 if successful, 0 if not. */ -protected int +libedit_private int ch_enlargebufs(EditLine *el, size_t addlen) { size_t sz, newsz; - Char *newbuffer, *oldbuf, *oldkbuf; + wchar_t *newbuffer, *oldbuf, *oldkbuf; sz = (size_t)(el->el_line.limit - el->el_line.buffer + EL_LEAVE); newsz = sz * 2; @@ -522,7 +508,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; @@ -571,7 +557,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; @@ -585,7 +571,7 @@ ch_enlargebufs(EditLine *el, size_t addlen) /* ch_end(): * Free the data structures used by the editor */ -protected void +libedit_private void ch_end(EditLine *el) { el_free(el->el_line.buffer); @@ -600,21 +586,19 @@ ch_end(EditLine *el) el->el_chared.c_redo.cmd = ED_UNASSIGNED; el_free(el->el_chared.c_kill.buf); el->el_chared.c_kill.buf = NULL; - ch_reset(el, 1); - el_free(el->el_chared.c_macro.macro); - el->el_chared.c_macro.macro = NULL; + ch_reset(el); } /* el_insertstr(): * Insert string at cursorI */ -public int -FUN(el,insertstr)(EditLine *el, const Char *s) +int +el_winsertstr(EditLine *el, const wchar_t *s) { size_t len; - if (s == NULL || (len = Strlen(s)) == 0) + if (s == NULL || (len = wcslen(s)) == 0) return -1; if (el->el_line.lastchar + len >= el->el_line.limit) { if (!ch_enlargebufs(el, len)) @@ -631,7 +615,7 @@ FUN(el,insertstr)(EditLine *el, const Char *s) /* el_deletestr(): * Delete num characters before the cursor */ -public void +void el_deletestr(EditLine *el, int n) { if (n <= 0) @@ -649,7 +633,7 @@ el_deletestr(EditLine *el, int n) /* el_cursor(): * Move the cursor to the left or the right of the current position */ -public int +int el_cursor(EditLine *el, int n) { if (n == 0) @@ -668,15 +652,14 @@ out: /* c_gets(): * Get a string */ -protected int -c_gets(EditLine *el, Char *buf, const Char *prompt) +libedit_private int +c_gets(EditLine *el, wchar_t *buf, const wchar_t *prompt) { - Char ch; ssize_t len; - Char *cp = el->el_line.buffer; + wchar_t *cp = el->el_line.buffer, ch; if (prompt) { - len = (ssize_t)Strlen(prompt); + len = (ssize_t)wcslen(prompt); (void)memcpy(cp, prompt, (size_t)len * sizeof(*cp)); cp += len; } @@ -688,7 +671,7 @@ c_gets(EditLine *el, Char *buf, const Char *prompt) el->el_line.lastchar = cp + 1; re_refresh(el); - if (FUN(el,getc)(el, &ch) != 1) { + if (el_wgetc(el, &ch) != 1) { ed_end_of_file(el, 0); len = -1; break; @@ -696,18 +679,19 @@ c_gets(EditLine *el, Char *buf, const Char *prompt) switch (ch) { - case 0010: /* Delete and backspace */ + case L'\b': /* Delete and backspace */ case 0177: if (len == 0) { len = -1; break; } + len--; cp--; continue; case 0033: /* ESC */ - case '\r': /* Newline */ - case '\n': + case L'\r': /* Newline */ + case L'\n': buf[len] = ch; break; @@ -733,10 +717,10 @@ c_gets(EditLine *el, Char *buf, const Char *prompt) /* c_hpos(): * Return the current horizontal position of the cursor */ -protected int +libedit_private int c_hpos(EditLine *el) { - Char *ptr; + wchar_t *ptr; /* * Find how many characters till the beginning of this line. @@ -752,7 +736,7 @@ c_hpos(EditLine *el) } } -protected int +libedit_private int ch_resizefun(EditLine *el, el_zfunc_t f, void *a) { el->el_chared.c_resizefun = f; @@ -760,7 +744,7 @@ ch_resizefun(EditLine *el, el_zfunc_t f, void *a) return 0; } -protected int +libedit_private int ch_aliasfun(EditLine *el, el_afunc_t f, void *a) { el->el_chared.c_aliasfun = f; diff --git a/contrib/libedit/src/chared.h b/contrib/libedit/src/chared.h index 6d6ef2341f..39f7d5173a 100644 --- a/contrib/libedit/src/chared.h +++ b/contrib/libedit/src/chared.h @@ -1,4 +1,4 @@ -/* $NetBSD: chared.h,v 1.22 2014/06/18 18:12:28 christos Exp $ */ +/* $NetBSD: chared.h,v 1.30 2016/05/22 19:44:26 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,13 +40,6 @@ #ifndef _h_el_chared #define _h_el_chared -#include -#include - -#include "histedit.h" - -#define EL_MAXMACRO 10 - /* * This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works * like real vi: i.e. the transition from command<->insert modes moves @@ -59,29 +52,22 @@ */ #define VI_MOVE - -typedef struct c_macro_t { - int level; - int offset; - Char **macro; -} c_macro_t; - /* * Undo information for vi - no undo in emacs (yet) */ typedef struct c_undo_t { ssize_t len; /* length of saved line */ int cursor; /* position of saved cursor */ - Char *buf; /* full saved text */ + wchar_t *buf; /* full saved text */ } c_undo_t; /* redo for vi */ typedef struct c_redo_t { - Char *buf; /* redo insert key sequence */ - Char *pos; - Char *lim; + wchar_t *buf; /* redo insert key sequence */ + wchar_t *pos; + wchar_t *lim; el_action_t cmd; /* command to redo */ - Char ch; /* char that invoked it */ + wchar_t ch; /* char that invoked it */ int count; int action; /* from cv_action() */ } c_redo_t; @@ -91,16 +77,16 @@ typedef struct c_redo_t { */ typedef struct c_vcmd_t { int action; - Char *pos; + wchar_t *pos; } c_vcmd_t; /* * Kill buffer for emacs */ typedef struct c_kill_t { - Char *buf; - Char *last; - Char *mark; + wchar_t *buf; + wchar_t *last; + wchar_t *mark; } c_kill_t; typedef void (*el_zfunc_t)(EditLine *, void *); @@ -115,7 +101,6 @@ typedef struct el_chared_t { c_kill_t c_kill; c_redo_t c_redo; c_vcmd_t c_vcmd; - c_macro_t c_macro; el_zfunc_t c_resizefun; el_afunc_t c_aliasfun; void * c_resizearg; @@ -139,37 +124,32 @@ 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(Int); -protected int cv__isWord(Int); -protected void cv_delfini(EditLine *); -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 (*)(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 *); -protected void c_delafter(EditLine *, int); -protected void c_delafter1(EditLine *); -protected int c_gets(EditLine *, Char *, const Char *); -protected int c_hpos(EditLine *); - -protected int ch_init(EditLine *); -protected void ch_reset(EditLine *, int); -protected int ch_resizefun(EditLine *, el_zfunc_t, void *); -protected int ch_aliasfun(EditLine *, el_afunc_t, void *); -protected int ch_enlargebufs(EditLine *, size_t); -protected void ch_end(EditLine *); + +libedit_private int cv__isword(wint_t); +libedit_private int cv__isWord(wint_t); +libedit_private void cv_delfini(EditLine *); +libedit_private wchar_t *cv__endword(wchar_t *, wchar_t *, int, int (*)(wint_t)); +libedit_private int ce__isword(wint_t); +libedit_private void cv_undo(EditLine *); +libedit_private void cv_yank(EditLine *, const wchar_t *, int); +libedit_private wchar_t *cv_next_word(EditLine*, wchar_t *, wchar_t *, int, + int (*)(wint_t)); +libedit_private wchar_t *cv_prev_word(wchar_t *, wchar_t *, int, int (*)(wint_t)); +libedit_private wchar_t *c__next_word(wchar_t *, wchar_t *, int, int (*)(wint_t)); +libedit_private wchar_t *c__prev_word(wchar_t *, wchar_t *, int, int (*)(wint_t)); +libedit_private void c_insert(EditLine *, int); +libedit_private void c_delbefore(EditLine *, int); +libedit_private void c_delbefore1(EditLine *); +libedit_private void c_delafter(EditLine *, int); +libedit_private void c_delafter1(EditLine *); +libedit_private int c_gets(EditLine *, wchar_t *, const wchar_t *); +libedit_private int c_hpos(EditLine *); + +libedit_private int ch_init(EditLine *); +libedit_private void ch_reset(EditLine *); +libedit_private int ch_resizefun(EditLine *, el_zfunc_t, void *); +libedit_private int ch_aliasfun(EditLine *, el_afunc_t, void *); +libedit_private int ch_enlargebufs(EditLine *, size_t); +libedit_private void ch_end(EditLine *); #endif /* _h_el_chared */ diff --git a/contrib/libedit/src/chartype.c b/contrib/libedit/src/chartype.c index b780bb1c3c..9288e6b7db 100644 --- a/contrib/libedit/src/chartype.c +++ b/contrib/libedit/src/chartype.c @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.c,v 1.12 2015/02/22 02:16:19 christos Exp $ */ +/* $NetBSD: chartype.c,v 1.31 2017/01/09 02:54:18 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -12,13 +12,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -38,15 +31,21 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: chartype.c,v 1.12 2015/02/22 02:16:19 christos Exp $"); +__RCSID("$NetBSD: chartype.c,v 1.31 2017/01/09 02:54:18 christos Exp $"); #endif /* not lint && not SCCSID */ -#include "el.h" + +#include #include +#include + +#include "el.h" #define CT_BUFSIZ ((size_t)1024) -#ifdef WIDECHAR -protected int +static int ct_conv_cbuff_resize(ct_buffer_t *, size_t); +static int ct_conv_wbuff_resize(ct_buffer_t *, size_t); + +static int ct_conv_cbuff_resize(ct_buffer_t *conv, size_t csize) { void *p; @@ -67,12 +66,12 @@ ct_conv_cbuff_resize(ct_buffer_t *conv, size_t csize) return 0; } -protected int +static int 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; @@ -89,8 +88,8 @@ ct_conv_wbuff_resize(ct_buffer_t *conv, size_t wsize) } -public char * -ct_encode_string(const Char *s, ct_buffer_t *conv) +char * +ct_encode_string(const wchar_t *s, ct_buffer_t *conv) { char *dst; ssize_t used; @@ -119,7 +118,7 @@ ct_encode_string(const Char *s, ct_buffer_t *conv) return conv->cbuff; } -public Char * +wchar_t * ct_decode_string(const char *s, ct_buffer_t *conv) { size_t len; @@ -127,7 +126,7 @@ ct_decode_string(const char *s, ct_buffer_t *conv) if (!s) return NULL; - len = ct_mbstowcs(NULL, s, (size_t)0); + len = mbstowcs(NULL, s, (size_t)0); if (len == (size_t)-1) return NULL; @@ -135,18 +134,18 @@ ct_decode_string(const char *s, ct_buffer_t *conv) if (ct_conv_wbuff_resize(conv, len + CT_BUFSIZ) == -1) return NULL; - ct_mbstowcs(conv->wbuff, s, conv->wsize); + mbstowcs(conv->wbuff, s, conv->wsize); return conv->wbuff; } -protected Char ** +libedit_private wchar_t ** ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) { size_t bufspace; int i; - Char *p; - Char **wargv; + wchar_t *p; + wchar_t **wargv; ssize_t bytes; /* Make sure we have enough space in the conversion buffer to store all @@ -157,7 +156,7 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) if (ct_conv_wbuff_resize(conv, bufspace + CT_BUFSIZ) == -1) return NULL; - wargv = el_malloc((size_t)argc * sizeof(*wargv)); + wargv = el_malloc((size_t)(argc + 1) * sizeof(*wargv)); for (i = 0, p = conv->wbuff; i < argc; ++i) { if (!argv[i]) { /* don't pass null pointers to mbstowcs */ @@ -175,13 +174,14 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) bufspace -= (size_t)bytes; p += bytes; } + wargv[i] = NULL; return wargv; } -protected size_t -ct_enc_width(Char c) +libedit_private size_t +ct_enc_width(wchar_t c) { /* UTF-8 encoding specific values */ if (c < 0x80) @@ -196,74 +196,66 @@ ct_enc_width(Char c) return 0; /* not a valid codepoint */ } -protected ssize_t -ct_encode_char(char *dst, size_t len, Char c) +libedit_private ssize_t +ct_encode_char(char *dst, size_t len, wchar_t c) { ssize_t l = 0; if (len < ct_enc_width(c)) return -1; - l = ct_wctomb(dst, c); + l = wctomb(dst, c); if (l < 0) { - ct_wctomb_reset; + wctomb(NULL, L'\0'); l = 0; } return l; } -#endif -protected const Char * -ct_visual_string(const Char *s) +libedit_private const wchar_t * +ct_visual_string(const wchar_t *s, ct_buffer_t *conv) { - static Char *buff = NULL; - static size_t buffsize = 0; - void *p; - Char *dst; - ssize_t used = 0; + wchar_t *dst; + ssize_t used; if (!s) return NULL; - if (!buff) { - buffsize = CT_BUFSIZ; - buff = el_malloc(buffsize * sizeof(*buff)); - } - dst = buff; + + if (ct_conv_wbuff_resize(conv, CT_BUFSIZ) == -1) + return NULL; + + used = 0; + dst = conv->wbuff; while (*s) { - used = ct_visual_char(dst, buffsize - (size_t)(dst - buff), *s); - if (used == -1) { /* failed to encode, need more buffer space */ - used = dst - buff; - buffsize += CT_BUFSIZ; - p = el_realloc(buff, buffsize * sizeof(*buff)); - if (p == NULL) - goto out; - buff = p; - dst = buff + used; - /* don't increment s here - we want to retry it! */ + used = ct_visual_char(dst, + conv->wsize - (size_t)(dst - conv->wbuff), *s); + if (used != -1) { + ++s; + dst += used; + continue; } - else - ++s; - dst += used; + + /* failed to encode, need more buffer space */ + used = dst - conv->wbuff; + if (ct_conv_wbuff_resize(conv, conv->wsize + CT_BUFSIZ) == -1) + return NULL; + dst = conv->wbuff + used; } - if (dst >= (buff + buffsize)) { /* sigh */ - buffsize += 1; - p = el_realloc(buff, buffsize * sizeof(*buff)); - if (p == NULL) - goto out; - buff = p; - dst = buff + buffsize - 1; + + if (dst >= (conv->wbuff + conv->wsize)) { /* sigh */ + used = dst - conv->wbuff; + if (ct_conv_wbuff_resize(conv, conv->wsize + CT_BUFSIZ) == -1) + return NULL; + dst = conv->wbuff + used; } - *dst = 0; - return buff; -out: - el_free(buff); - buffsize = 0; - return NULL; + + *dst = L'\0'; + return conv->wbuff; } -protected int -ct_visual_width(Char c) +libedit_private int +ct_visual_width(wchar_t c) { int t = ct_chr_class(c); switch (t) { @@ -273,7 +265,6 @@ ct_visual_width(Char c) return 1; /* Hmm, this really need to be handled outside! */ case CHTYPE_NL: return 0; /* Should this be 1 instead? */ -#ifdef WIDECHAR case CHTYPE_PRINT: return wcwidth(c); case CHTYPE_NONPRINT: @@ -281,20 +272,14 @@ ct_visual_width(Char c) return 8; /* \U+12345 */ else return 7; /* \U+1234 */ -#else - case CHTYPE_PRINT: - return 1; - case CHTYPE_NONPRINT: - return 4; /* \123 */ -#endif default: return 0; /* should not happen */ } } -protected ssize_t -ct_visual_char(Char *dst, size_t len, Char c) +libedit_private ssize_t +ct_visual_char(wchar_t *dst, size_t len, wchar_t c) { int t = ct_chr_class(c); switch (t) { @@ -319,7 +304,6 @@ ct_visual_char(Char *dst, size_t len, Char c) * so this is right */ if ((ssize_t)len < ct_visual_width(c)) return -1; /* insufficient space */ -#ifdef WIDECHAR *dst++ = '\\'; *dst++ = 'U'; *dst++ = '+'; @@ -331,13 +315,6 @@ ct_visual_char(Char *dst, size_t len, Char c) *dst++ = tohexdigit(((unsigned int) c >> 4) & 0xf); *dst = tohexdigit(((unsigned int) c ) & 0xf); return c > 0xffff ? 8 : 7; -#else - *dst++ = '\\'; -#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); -#endif /*FALLTHROUGH*/ /* these two should be handled outside this function */ default: /* we should never hit the default */ @@ -348,16 +325,16 @@ ct_visual_char(Char *dst, size_t len, Char c) -protected int -ct_chr_class(Char c) +libedit_private int +ct_chr_class(wchar_t c) { if (c == '\t') return CHTYPE_TAB; else if (c == '\n') return CHTYPE_NL; - else if (IsASCII(c) && Iscntrl(c)) + else if (c < 0x100 && iswcntrl(c)) return CHTYPE_ASCIICTL; - else if (Isprint(c)) + else if (iswprint(c)) return CHTYPE_PRINT; else return CHTYPE_NONPRINT; diff --git a/contrib/libedit/src/chartype.h b/contrib/libedit/src/chartype.h index 7a1c041d24..a06858126d 100644 --- a/contrib/libedit/src/chartype.h +++ b/contrib/libedit/src/chartype.h @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.h,v 1.13 2015/02/22 02:16:19 christos Exp $ */ +/* $NetBSD: chartype.h,v 1.34 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -12,13 +12,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -36,17 +29,13 @@ #ifndef _h_chartype_f #define _h_chartype_f - - -#ifdef WIDECHAR - /* Ideally we should also test the value of the define to see if it * supports non-BMP code points without requiring UTF-16, but nothing * seems to actually advertise this properly, despite Unicode 3.1 having * been around since 2001... */ #if 0 /* DragonFly wchar supports ISO 10646 */ -#if !defined(__NetBSD__) && !defined(__sun) && !(defined(__APPLE__) && defined(__MACH__)) && !defined(__OpenBSD__) +#if !defined(__NetBSD__) && !defined(__sun) && !(defined(__APPLE__) && defined(__MACH__)) && !defined(__OpenBSD__) && !defined(__FreeBSD__) #ifndef __STDC_ISO_10646__ /* In many places it is assumed that the first 127 code points are ASCII * compatible, so ensure wchar_t indeed does ISO 10646 and not some other @@ -63,182 +52,53 @@ #warning Build environment does not support non-BMP characters #endif -#ifndef HAVE_WCSDUP -wchar_t *wcsdup(const wchar_t *s); -#endif - -#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 FSTR "%ls" -#define STR(x) L ## x -#define UC(c) c -#define Isalpha(x) iswalpha(x) -#define Isalnum(x) iswalnum(x) -#define Isgraph(x) iswgraph(x) -#define Isspace(x) iswspace(x) -#define Isdigit(x) iswdigit(x) -#define Iscntrl(x) iswcntrl(x) -#define Isprint(x) iswprint(x) - -#define Isupper(x) iswupper(x) -#define Islower(x) iswlower(x) -#define Toupper(x) towupper(x) -#define Tolower(x) towlower(x) - -#define IsASCII(x) (x < 0x100) - -#define Strlen(x) wcslen(x) -#define Strchr(s,c) wcschr(s,c) -#define Strrchr(s,c) wcsrchr(s,c) -#define Strstr(s,v) wcsstr(s,v) -#define Strdup(x) wcsdup(x) -#define Strcpy(d,s) wcscpy(d,s) -#define Strncpy(d,s,n) wcsncpy(d,s,n) -#define Strncat(d,s,n) wcsncat(d,s,n) - -#define Strcmp(s,v) wcscmp(s,v) -#define Strncmp(s,v,n) wcsncmp(s,v,n) -#define Strcspn(s,r) wcscspn(s,r) - -#define Strtol(p,e,b) wcstol(p,e,b) - -static inline int -Width(wchar_t c) -{ - int w = wcwidth(c); - return w < 0 ? 0 : w; -} - -#else /* NARROW */ - -#define ct_mbtowc error -#define ct_mbtowc_reset -#define ct_wctomb error -#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 FSTR "%s" -#define STR(x) x -#define UC(c) (unsigned char)(c) - -#define Isalpha(x) isalpha((unsigned char)x) -#define Isalnum(x) isalnum((unsigned char)x) -#define Isgraph(x) isgraph((unsigned char)x) -#define Isspace(x) isspace((unsigned char)x) -#define Isdigit(x) isdigit((unsigned char)x) -#define Iscntrl(x) iscntrl((unsigned char)x) -#define Isprint(x) isprint((unsigned char)x) - -#define Isupper(x) isupper((unsigned char)x) -#define Islower(x) islower((unsigned char)x) -#define Toupper(x) toupper((unsigned char)x) -#define Tolower(x) tolower((unsigned char)x) - -#define IsASCII(x) isascii((unsigned char)x) - -#define Strlen(x) strlen(x) -#define Strchr(s,c) strchr(s,c) -#define Strrchr(s,c) strrchr(s,c) -#define Strstr(s,v) strstr(s,v) -#define Strdup(x) strdup(x) -#define Strcpy(d,s) strcpy(d,s) -#define Strncpy(d,s,n) strncpy(d,s,n) -#define Strncat(d,s,n) strncat(d,s,n) - -#define Strcmp(s,v) strcmp(s,v) -#define Strncmp(s,v,n) strncmp(s,v,n) -#define Strcspn(s,r) strcspn(s,r) - -#define Strtol(p,e,b) strtol(p,e,b) - -#define Width(c) 1 - -#endif - - -#ifdef WIDECHAR /* * Conversion buffer */ typedef struct ct_buffer_t { char *cbuff; size_t csize; - Char *wbuff; + wchar_t *wbuff; size_t wsize; } ct_buffer_t; -#define ct_encode_string __ct_encode_string /* Encode a wide-character string and return the UTF-8 encoded result. */ -public char *ct_encode_string(const Char *, ct_buffer_t *); +char *ct_encode_string(const wchar_t *, ct_buffer_t *); -#define ct_decode_string __ct_decode_string /* Decode a (multi)?byte string and return the wide-character string result. */ -public Char *ct_decode_string(const char *, ct_buffer_t *); +wchar_t *ct_decode_string(const char *, ct_buffer_t *); /* Decode a (multi)?byte argv string array. * The pointer returned must be free()d when done. */ -protected Char **ct_decode_argv(int, const char *[], ct_buffer_t *); - -/* Resizes the conversion buffer(s) if needed. */ -protected int ct_conv_cbuff_resize(ct_buffer_t *, size_t); -protected int ct_conv_wbuff_resize(ct_buffer_t *, size_t); -protected ssize_t ct_encode_char(char *, size_t, Char); -protected size_t ct_enc_width(Char); - -#define ct_free_argv(s) el_free(s) +libedit_private wchar_t **ct_decode_argv(int, const char *[], ct_buffer_t *); -#else -#define ct_encode_string(s, b) (s) -#define ct_decode_string(s, b) (s) -#define ct_decode_argv(l, s, b) (s) -#define ct_conv_cbuff_resize(b, s) ((s) == (0)) -#define ct_conv_wbuff_resize(b, s) ((s) == (0)) -#define ct_encode_char(d, l, s) (*d = s, 1) -#define ct_free_argv(s) -#endif - -#ifndef NARROWCHAR -/* Encode a characted into the destination buffer, provided there is sufficent +/* Encode a character into the destination buffer, provided there is sufficient * buffer space available. Returns the number of bytes used up (zero if the * character cannot be encoded, -1 if there was not enough space available). */ +libedit_private ssize_t ct_encode_char(char *, size_t, wchar_t); +libedit_private size_t ct_enc_width(wchar_t); -/* The maximum buffer size to hold the most unwieldly visual representation, +/* The maximum buffer size to hold the most unwieldy visual representation, * in this case \U+nnnnn. */ #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) +#define MB_FILL_CHAR ((wchar_t)-1) /* Visual width of character c, taking into account ^? , \0177 and \U+nnnnn * style visual expansions. */ -protected int ct_visual_width(Char); +libedit_private int ct_visual_width(wchar_t); /* Turn the given character into the appropriate visual format, matching * the width given by ct_visual_width(). Returns the number of characters used - * up, or -1 if insufficient space. Buffer length is in count of Char's. */ -protected ssize_t ct_visual_char(Char *, size_t, Char); + * up, or -1 if insufficient space. Buffer length is in count of wchar_t's. */ +libedit_private ssize_t ct_visual_char(wchar_t *, size_t, wchar_t); /* Convert the given string into visual format, using the ct_visual_char() * function. Uses a static buffer, so not threadsafe. */ -protected const Char *ct_visual_string(const Char *); +libedit_private const wchar_t *ct_visual_string(const wchar_t *, ct_buffer_t *); /* printable character, use ct_visual_width() to find out display width */ @@ -252,8 +112,6 @@ protected const Char *ct_visual_string(const Char *); /* non-printable character */ #define CHTYPE_NONPRINT (-4) /* classification of character c, as one of the above defines */ -protected int ct_chr_class(Char c); -#endif - +libedit_private int ct_chr_class(wchar_t c); #endif /* _chartype_f */ diff --git a/contrib/libedit/src/common.c b/contrib/libedit/src/common.c index 1726b0f812..270860510b 100644 --- a/contrib/libedit/src/common.c +++ b/contrib/libedit/src/common.c @@ -1,4 +1,4 @@ -/* $NetBSD: common.c,v 1.29 2012/03/24 20:08:43 christos Exp $ */ +/* $NetBSD: common.c,v 1.47 2016/05/22 19:44:26 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,22 +37,29 @@ #if 0 static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: common.c,v 1.29 2012/03/24 20:08:43 christos Exp $"); +__RCSID("$NetBSD: common.c,v 1.47 2016/05/22 19:44:26 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * common.c: Common Editor functions */ +#include +#include + #include "el.h" +#include "common.h" +#include "fcns.h" +#include "parse.h" +#include "vi.h" /* ed_end_of_file(): * Indicate end of file * [^D] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_end_of_file(EditLine *el, Int c __attribute__((__unused__))) +ed_end_of_file(EditLine *el, wint_t c __attribute__((__unused__))) { re_goto_bottom(el); @@ -65,8 +72,8 @@ ed_end_of_file(EditLine *el, Int c __attribute__((__unused__))) * Add character to the line * Insert a character [bound to all insert keys] */ -protected el_action_t -ed_insert(EditLine *el, Int c) +libedit_private el_action_t +ed_insert(EditLine *el, wint_t c) { int count = el->el_state.argument; @@ -107,11 +114,11 @@ ed_insert(EditLine *el, Int c) * Delete from beginning of current word to cursor * [M-^?] [^W] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_delete_prev_word(EditLine *el, Int c __attribute__((__unused__))) +ed_delete_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *cp, *p, *kp; + wchar_t *cp, *p, *kp; if (el->el_line.cursor == el->el_line.buffer) return CC_ERROR; @@ -135,14 +142,14 @@ ed_delete_prev_word(EditLine *el, Int c __attribute__((__unused__))) * Delete character under cursor * [^D] [x] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_delete_next_char(EditLine *el, Int c __attribute__((__unused__))) +ed_delete_next_char(EditLine *el, wint_t c __attribute__((__unused__))) { #ifdef DEBUG_EDIT #define EL el->el_line - (void) fprintf(el->el_errlfile, - "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n", + (void) fprintf(el->el_errfile, + "\nD(b: %p(%ls) c: %p(%ls) last: %p(%ls) limit: %p(%ls)\n", EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar, EL.lastchar, EL.limit, EL.limit); #endif @@ -182,11 +189,11 @@ ed_delete_next_char(EditLine *el, Int c __attribute__((__unused__))) * Cut to the end of line * [^K] [^K] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_kill_line(EditLine *el, Int c __attribute__((__unused__))) +ed_kill_line(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *kp, *cp; + wchar_t *kp, *cp; cp = el->el_line.cursor; kp = el->el_chared.c_kill.buf; @@ -203,9 +210,9 @@ ed_kill_line(EditLine *el, Int c __attribute__((__unused__))) * Move cursor to the end of line * [^E] [^E] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_move_to_end(EditLine *el, Int c __attribute__((__unused__))) +ed_move_to_end(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.lastchar; @@ -226,16 +233,16 @@ ed_move_to_end(EditLine *el, Int c __attribute__((__unused__))) * Move cursor to the beginning of line * [^A] [^A] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_move_to_beg(EditLine *el, Int c __attribute__((__unused__))) +ed_move_to_beg(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; if (el->el_map.type == MAP_VI) { /* We want FIRST non space character */ - while (Isspace(*el->el_line.cursor)) + while (iswspace(*el->el_line.cursor)) el->el_line.cursor++; if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); @@ -250,8 +257,8 @@ ed_move_to_beg(EditLine *el, Int c __attribute__((__unused__))) * Exchange the character to the left of the cursor with the one under it * [^T] [^T] */ -protected el_action_t -ed_transpose_chars(EditLine *el, Int c) +libedit_private el_action_t +ed_transpose_chars(EditLine *el, wint_t c) { if (el->el_line.cursor < el->el_line.lastchar) { @@ -275,11 +282,11 @@ ed_transpose_chars(EditLine *el, Int c) * Move to the right one character * [^F] [^F] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_next_char(EditLine *el, Int c __attribute__((__unused__))) +ed_next_char(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *lim = el->el_line.lastchar; + wchar_t *lim = el->el_line.lastchar; if (el->el_line.cursor >= lim || (el->el_line.cursor == lim - 1 && @@ -304,9 +311,9 @@ ed_next_char(EditLine *el, Int c __attribute__((__unused__))) * Move to the beginning of the current word * [M-b] [b] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_prev_word(EditLine *el, Int c __attribute__((__unused__))) +ed_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -330,9 +337,9 @@ ed_prev_word(EditLine *el, Int c __attribute__((__unused__))) * Move to the left one character * [^B] [^B] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_prev_char(EditLine *el, Int c __attribute__((__unused__))) +ed_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor > el->el_line.buffer) { @@ -355,15 +362,13 @@ ed_prev_char(EditLine *el, Int c __attribute__((__unused__))) * Add the next character typed verbatim * [^V] [^V] */ -protected el_action_t -ed_quoted_insert(EditLine *el, Int c) +libedit_private el_action_t +ed_quoted_insert(EditLine *el, wint_t c) { int num; - Char tc; tty_quotemode(el); - num = FUN(el,getc)(el, &tc); - c = tc; + num = el_wgetc(el, &c); tty_noquotemode(el); if (num == 1) return ed_insert(el, c); @@ -375,11 +380,11 @@ ed_quoted_insert(EditLine *el, Int c) /* ed_digit(): * Adds to argument or enters a digit */ -protected el_action_t -ed_digit(EditLine *el, Int c) +libedit_private el_action_t +ed_digit(EditLine *el, wint_t c) { - if (!Isdigit(c)) + if (!iswdigit(c)) return CC_ERROR; if (el->el_state.doingarg) { @@ -403,11 +408,11 @@ ed_digit(EditLine *el, Int c) * Digit that starts argument * For ESC-n */ -protected el_action_t -ed_argument_digit(EditLine *el, Int c) +libedit_private el_action_t +ed_argument_digit(EditLine *el, wint_t c) { - if (!Isdigit(c)) + if (!iswdigit(c)) return CC_ERROR; if (el->el_state.doingarg) { @@ -427,112 +432,24 @@ ed_argument_digit(EditLine *el, Int c) * Indicates unbound character * Bound to keys that are not assigned */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ ed_unassigned(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) + wint_t c __attribute__((__unused__))) { return CC_ERROR; } -/** - ** TTY key handling. - **/ - -/* ed_tty_sigint(): - * Tty interrupt character - * [^C] - */ -protected el_action_t -/*ARGSUSED*/ -ed_tty_sigint(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) -{ - - return CC_NORM; -} - - -/* ed_tty_dsusp(): - * Tty delayed suspend character - * [^Y] - */ -protected el_action_t -/*ARGSUSED*/ -ed_tty_dsusp(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) -{ - - return CC_NORM; -} - - -/* ed_tty_flush_output(): - * Tty flush output characters - * [^O] - */ -protected el_action_t -/*ARGSUSED*/ -ed_tty_flush_output(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) -{ - - return CC_NORM; -} - - -/* ed_tty_sigquit(): - * Tty quit character - * [^\] - */ -protected el_action_t -/*ARGSUSED*/ -ed_tty_sigquit(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) -{ - - return CC_NORM; -} - - -/* ed_tty_sigtstp(): - * Tty suspend character - * [^Z] - */ -protected el_action_t -/*ARGSUSED*/ -ed_tty_sigtstp(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) -{ - - return CC_NORM; -} - - -/* ed_tty_stop_output(): - * Tty disallow output characters - * [^S] - */ -protected el_action_t -/*ARGSUSED*/ -ed_tty_stop_output(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) -{ - - return CC_NORM; -} - - -/* ed_tty_start_output(): - * Tty allow output characters - * [^Q] +/* ed_ignore(): + * Input characters that have no effect + * [^C ^O ^Q ^S ^Z ^\ ^]] [^C ^O ^Q ^S ^\] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_tty_start_output(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) +ed_ignore(EditLine *el __attribute__((__unused__)), + wint_t c __attribute__((__unused__))) { return CC_NORM; @@ -543,9 +460,9 @@ ed_tty_start_output(EditLine *el __attribute__((__unused__)), * Execute command * [^J] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_newline(EditLine *el, Int c __attribute__((__unused__))) +ed_newline(EditLine *el, wint_t c __attribute__((__unused__))) { re_goto_bottom(el); @@ -559,9 +476,9 @@ ed_newline(EditLine *el, Int c __attribute__((__unused__))) * Delete the character to the left of the cursor * [^?] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) +ed_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) @@ -579,9 +496,9 @@ ed_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) * Clear screen leaving current line at the top * [^L] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_clear_screen(EditLine *el, Int c __attribute__((__unused__))) +ed_clear_screen(EditLine *el, wint_t c __attribute__((__unused__))) { terminal_clear_screen(el); /* clear the whole real screen */ @@ -594,10 +511,10 @@ ed_clear_screen(EditLine *el, Int c __attribute__((__unused__))) * Redisplay everything * ^R */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_redisplay(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) +ed_redisplay(EditLine *el __attribute__((__unused__)), + wint_t c __attribute__((__unused__))) { return CC_REDISPLAY; @@ -608,12 +525,12 @@ ed_redisplay(EditLine *el __attribute__((__unused__)), * Erase current line and start from scratch * [^G] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_start_over(EditLine *el, Int c __attribute__((__unused__))) +ed_start_over(EditLine *el, wint_t c __attribute__((__unused__))) { - ch_reset(el, 0); + ch_reset(el); return CC_REFRESH; } @@ -622,10 +539,10 @@ ed_start_over(EditLine *el, Int c __attribute__((__unused__))) * First character in a bound sequence * Placeholder for external keys */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), - Int c __attribute__((__unused__))) +ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), + wint_t c __attribute__((__unused__))) { return CC_NORM; @@ -636,9 +553,9 @@ ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), * Move to the previous history line * [^P] [k] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_prev_history(EditLine *el, Int c __attribute__((__unused__))) +ed_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) { char beep = 0; int sv_event = el->el_history.eventno; @@ -648,7 +565,7 @@ ed_prev_history(EditLine *el, Int c __attribute__((__unused__))) if (el->el_history.eventno == 0) { /* save the current buffer * away */ - (void) Strncpy(el->el_history.buf, el->el_line.buffer, + (void) wcsncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ); el->el_history.last = el->el_history.buf + (el->el_line.lastchar - el->el_line.buffer); @@ -658,7 +575,6 @@ ed_prev_history(EditLine *el, Int 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 */ @@ -674,9 +590,9 @@ ed_prev_history(EditLine *el, Int c __attribute__((__unused__))) * Move to the next history line * [^N] [j] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_next_history(EditLine *el, Int c __attribute__((__unused__))) +ed_next_history(EditLine *el, wint_t c __attribute__((__unused__))) { el_action_t beep = CC_REFRESH, rval; @@ -701,13 +617,13 @@ ed_next_history(EditLine *el, Int c __attribute__((__unused__))) * Search previous in history for a line matching the current * next search history [M-P] [K] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__))) +ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__))) { - const Char *hp; + const wchar_t *hp; int h; - bool_t found = 0; + int found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.len = -1; @@ -721,7 +637,7 @@ ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__))) return CC_ERROR; } if (el->el_history.eventno == 0) { - (void) Strncpy(el->el_history.buf, el->el_line.buffer, + (void) wcsncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ); el->el_history.last = el->el_history.buf + (el->el_line.lastchar - el->el_line.buffer); @@ -742,11 +658,11 @@ ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__))) #ifdef SDEBUG (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); #endif - if ((Strncmp(hp, el->el_line.buffer, (size_t) + if ((wcsncmp(hp, el->el_line.buffer, (size_t) (el->el_line.lastchar - el->el_line.buffer)) || hp[el->el_line.lastchar - el->el_line.buffer]) && c_hmatch(el, hp)) { - found++; + found = 1; break; } h++; @@ -769,13 +685,13 @@ ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__))) * Search next in history for a line matching the current * [M-N] [J] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_search_next_history(EditLine *el, Int c __attribute__((__unused__))) +ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__))) { - const Char *hp; + const wchar_t *hp; int h; - bool_t found = 0; + int found = 0; el->el_chared.c_vcmd.action = NOP; el->el_chared.c_undo.len = -1; @@ -797,7 +713,7 @@ ed_search_next_history(EditLine *el, Int c __attribute__((__unused__))) #ifdef SDEBUG (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); #endif - if ((Strncmp(hp, el->el_line.buffer, (size_t) + if ((wcsncmp(hp, el->el_line.buffer, (size_t) (el->el_line.lastchar - el->el_line.buffer)) || hp[el->el_line.lastchar - el->el_line.buffer]) && c_hmatch(el, hp)) @@ -823,11 +739,11 @@ ed_search_next_history(EditLine *el, Int c __attribute__((__unused__))) * Move up one line * Could be [k] [^p] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_prev_line(EditLine *el, Int c __attribute__((__unused__))) +ed_prev_line(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *ptr; + wchar_t *ptr; int nchars = c_hpos(el); /* @@ -866,11 +782,11 @@ ed_prev_line(EditLine *el, Int c __attribute__((__unused__))) * Move down one line * Could be [j] [^n] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_next_line(EditLine *el, Int c __attribute__((__unused__))) +ed_next_line(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *ptr; + wchar_t *ptr; int nchars = c_hpos(el); /* @@ -900,14 +816,14 @@ ed_next_line(EditLine *el, Int c __attribute__((__unused__))) * Editline extended command * [M-X] [:] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -ed_command(EditLine *el, Int c __attribute__((__unused__))) +ed_command(EditLine *el, wint_t c __attribute__((__unused__))) { - Char tmpbuf[EL_BUFSIZ]; + wchar_t tmpbuf[EL_BUFSIZ]; int tmplen; - tmplen = c_gets(el, tmpbuf, STR("\n: ")); + tmplen = c_gets(el, tmpbuf, L"\n: "); terminal__putc(el, '\n'); if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1) diff --git a/contrib/libedit/src/editline/readline.h b/contrib/libedit/src/editline/readline.h index 932febb9de..777a4c6f47 100644 --- a/contrib/libedit/src/editline/readline.h +++ b/contrib/libedit/src/editline/readline.h @@ -1,4 +1,4 @@ -/* $NetBSD: readline.h,v 1.34 2013/05/28 00:10:34 christos Exp $ */ +/* $NetBSD: readline.h,v 1.41 2016/10/28 18:32:35 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -39,9 +39,8 @@ /* typedefs */ typedef int Function(const char *, int); typedef void VFunction(void); -typedef void VCPFunction(char *); -typedef char *CPFunction(const char *, int); -typedef char **CPPFunction(const char *, int, int); +typedef void rl_vcpfunc_t(char *); +typedef char **rl_completion_func_t(const char *, int, int); typedef char *rl_compentry_func_t(const char *, int); typedef int rl_command_func_t(int, int); @@ -54,7 +53,7 @@ typedef void *histdata_t; typedef struct _hist_entry { const char *line; - histdata_t data; + histdata_t data; } HIST_ENTRY; typedef struct _keymap_entry { @@ -88,7 +87,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' @@ -97,7 +96,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; @@ -108,9 +107,9 @@ extern int max_input_history; extern char *rl_basic_word_break_characters; extern char *rl_completer_word_break_characters; extern char *rl_completer_quote_characters; -extern Function *rl_completion_entry_function; +extern rl_compentry_func_t *rl_completion_entry_function; extern char *(*rl_completion_word_break_hook)(void); -extern CPPFunction *rl_attempted_completion_function; +extern rl_completion_func_t *rl_attempted_completion_function; extern int rl_attempted_completion_over; extern int rl_completion_type; extern int rl_completion_query_items; @@ -122,6 +121,7 @@ extern Function *rl_startup_hook; extern char *rl_terminal_name; extern int rl_already_prompted; extern char *rl_prompt; +extern int rl_done; /* * The following is not implemented */ @@ -159,6 +159,7 @@ int history_total_bytes(void); int history_set_pos(int); HIST_ENTRY *previous_history(void); HIST_ENTRY *next_history(void); +HIST_ENTRY **history_list(void); int history_search(const char *, int); int history_search_prefix(const char *, int); int history_search_pos(const char *, int, int); @@ -175,7 +176,7 @@ char *filename_completion_function(const char *, int); char *username_completion_function(const char *, int); int rl_complete(int, int); int rl_read_key(void); -char **completion_matches(const char *, CPFunction *); +char **completion_matches(const char *, rl_compentry_func_t *); void rl_display_match_list(char **, int, int); int rl_insert(int, int); @@ -184,7 +185,7 @@ void rl_reset_terminal(const char *); int rl_bind_key(int, rl_command_func_t *); int rl_newline(int, int); void rl_callback_read_char(void); -void rl_callback_handler_install(const char *, VCPFunction *); +void rl_callback_handler_install(const char *, rl_vcpfunc_t *); void rl_callback_handler_remove(void); void rl_redisplay(void); int rl_get_previous_history(int, int); @@ -194,14 +195,14 @@ int rl_read_init_file(const char *); int rl_parse_and_bind(const char *); int rl_variable_bind(const char *, const char *); void rl_stuff_char(int); -int rl_add_defun(const char *, Function *, int); +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); @@ -217,6 +218,8 @@ 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/contrib/libedit/src/el.c b/contrib/libedit/src/el.c index 9342861eb7..87946f7dae 100644 --- a/contrib/libedit/src/el.c +++ b/contrib/libedit/src/el.c @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.73 2014/06/18 18:12:28 christos Exp $ */ +/* $NetBSD: el.c,v 1.92 2016/05/22 19:44:26 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.73 2014/06/18 18:12:28 christos Exp $"); +__RCSID("$NetBSD: el.c,v 1.92 2016/05/22 19:44:26 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -46,13 +46,16 @@ __RCSID("$NetBSD: el.c,v 1.73 2014/06/18 18:12:28 christos Exp $"); */ #include #include -#include -#include -#include #include -#include #include +#include +#include +#include +#include + #include "el.h" +#include "parse.h" +#include "read.h" #ifndef HAVE_SECURE_GETENV # ifdef HAVE___SECURE_GETENV @@ -80,14 +83,14 @@ char *secure_getenv(char const *name) /* el_init(): * Initialize editline and set default parameters. */ -public EditLine * +EditLine * el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr) { return el_init_fd(prog, fin, fout, ferr, fileno(fin), fileno(fout), fileno(ferr)); } -public EditLine * +EditLine * el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr, int fdin, int fdout, int fderr) { @@ -106,7 +109,7 @@ el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr, el->el_outfd = fdout; el->el_errfd = fderr; - el->el_prog = Strdup(ct_decode_string(prog, &el->el_scratch)); + el->el_prog = wcsdup(ct_decode_string(prog, &el->el_scratch)); if (el->el_prog == NULL) { el_free(el); return NULL; @@ -116,12 +119,10 @@ 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); @@ -137,8 +138,10 @@ el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr, (void) hist_init(el); (void) prompt_init(el); (void) sig_init(el); - (void) read_init(el); - + if (read_init(el) == -1) { + el_end(el); + return NULL; + } return el; } @@ -146,7 +149,7 @@ el_init_fd(const char *prog, FILE *fin, FILE *fout, FILE *ferr, /* el_end(): * Clean up. */ -public void +void el_end(EditLine *el) { @@ -158,20 +161,22 @@ el_end(EditLine *el) terminal_end(el); keymacro_end(el); map_end(el); - tty_end(el); + if (!(el->el_flags & NO_TTY)) + tty_end(el); ch_end(el); + read_end(el->el_read); search_end(el); hist_end(el); prompt_end(el); sig_end(el); el_free(el->el_prog); -#ifdef WIDECHAR + el_free(el->el_visual.cbuff); + el_free(el->el_visual.wbuff); el_free(el->el_scratch.cbuff); el_free(el->el_scratch.wbuff); el_free(el->el_lgcyconv.cbuff); el_free(el->el_lgcyconv.wbuff); -#endif el_free(el); } @@ -179,20 +184,20 @@ el_end(EditLine *el) /* el_reset(): * Reset the tty and the parser */ -public void +void el_reset(EditLine *el) { tty_cookedmode(el); - ch_reset(el, 0); /* XXX: Do we want that? */ + ch_reset(el); /* XXX: Do we want that? */ } /* el_set(): * set the editline parameters */ -public int -FUN(el,set)(EditLine *el, int op, ...) +int +el_wset(EditLine *el, int op, ...) { va_list ap; int rv = 0; @@ -229,7 +234,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, c, op, 1); + rv = prompt_set(el, p, (wchar_t)c, op, 1); break; } @@ -238,7 +243,7 @@ FUN(el,set)(EditLine *el, int op, ...) break; case EL_EDITOR: - rv = map_set_editor(el, va_arg(ap, Char *)); + rv = map_set_editor(el, va_arg(ap, wchar_t *)); break; case EL_SIGNAL: @@ -254,36 +259,36 @@ FUN(el,set)(EditLine *el, int op, ...) case EL_ECHOTC: case EL_SETTY: { - const Char *argv[20]; + const wchar_t *argv[20]; int i; for (i = 1; i < (int)__arraycount(argv); i++) - if ((argv[i] = va_arg(ap, Char *)) == NULL) + if ((argv[i] = va_arg(ap, wchar_t *)) == NULL) break; switch (op) { case EL_BIND: - argv[0] = STR("bind"); + argv[0] = L"bind"; rv = map_bind(el, i, argv); break; case EL_TELLTC: - argv[0] = STR("telltc"); + argv[0] = L"telltc"; rv = terminal_telltc(el, i, argv); break; case EL_SETTC: - argv[0] = STR("settc"); + argv[0] = L"settc"; rv = terminal_settc(el, i, argv); break; case EL_ECHOTC: - argv[0] = STR("echotc"); + argv[0] = L"echotc"; rv = terminal_echotc(el, i, argv); break; case EL_SETTY: - argv[0] = STR("setty"); + argv[0] = L"setty"; rv = tty_stty(el, i, argv); break; @@ -297,8 +302,8 @@ FUN(el,set)(EditLine *el, int op, ...) case EL_ADDFN: { - Char *name = va_arg(ap, Char *); - Char *help = va_arg(ap, Char *); + wchar_t *name = va_arg(ap, wchar_t *); + wchar_t *help = va_arg(ap, wchar_t *); el_func_t func = va_arg(ap, el_func_t); rv = map_addfunc(el, name, help, func); @@ -327,8 +332,7 @@ FUN(el,set)(EditLine *el, int op, ...) case EL_GETCFN: { el_rfunc_t rc = va_arg(ap, el_rfunc_t); - rv = el_read_setfn(el, rc); - el->el_flags &= ~NARROW_READ; + rv = el_read_setfn(el->el_read, rc); break; } @@ -405,8 +409,8 @@ FUN(el,set)(EditLine *el, int op, ...) /* el_get(): * retrieve the editline parameters */ -public int -FUN(el,get)(EditLine *el, int op, ...) +int +el_wget(EditLine *el, int op, ...) { va_list ap; int rv; @@ -426,14 +430,14 @@ FUN(el,get)(EditLine *el, int op, ...) case EL_PROMPT_ESC: case EL_RPROMPT_ESC: { el_pfunc_t *p = va_arg(ap, el_pfunc_t *); - Char *c = va_arg(ap, Char *); + wchar_t *c = va_arg(ap, wchar_t *); rv = prompt_get(el, p, c, op); break; } case EL_EDITOR: - rv = map_get_editor(el, va_arg(ap, const Char **)); + rv = map_get_editor(el, va_arg(ap, const wchar_t **)); break; case EL_SIGNAL: @@ -457,7 +461,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; @@ -467,7 +471,7 @@ FUN(el,get)(EditLine *el, int op, ...) } case EL_GETCFN: - *va_arg(ap, el_rfunc_t *) = el_read_getfn(el); + *va_arg(ap, el_rfunc_t *) = el_read_getfn(el->el_read); rv = 0; break; @@ -518,25 +522,26 @@ FUN(el,get)(EditLine *el, int op, ...) /* el_line(): * Return editing info */ -public const TYPE(LineInfo) * -FUN(el,line)(EditLine *el) +const LineInfoW * +el_wline(EditLine *el) { - return (const TYPE(LineInfo) *)(void *)&el->el_line; + return (const LineInfoW *)(void *)&el->el_line; } /* el_source(): * Source a file */ -public int +int el_source(EditLine *el, const char *fname) { FILE *fp; size_t len; + ssize_t slen; char *ptr; char *path = NULL; - const Char *dptr; + const wchar_t *dptr; int error = 0; fp = NULL; @@ -559,23 +564,26 @@ el_source(EditLine *el, const char *fname) return -1; } - while ((ptr = fgetln(fp, &len)) != NULL) { + ptr = NULL; + len = 0; + while ((slen = getline(&ptr, &len, fp)) != -1) { 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)) + while (*dptr != '\0' && iswspace(*dptr)) dptr++; if (*dptr == '#') continue; /* ignore, this is a comment line */ if ((error = parse_line(el, dptr)) == -1) break; } + free(ptr); el_free(path); (void) fclose(fp); @@ -586,7 +594,7 @@ el_source(EditLine *el, const char *fname) /* el_resize(): * Called from program when terminal is resized */ -public void +void el_resize(EditLine *el) { int lins, cols; @@ -607,7 +615,7 @@ el_resize(EditLine *el) /* el_beep(): * Called from the program to beep */ -public void +void el_beep(EditLine *el) { @@ -618,25 +626,25 @@ el_beep(EditLine *el) /* el_editmode() * Set the state of EDIT_DISABLED from the `edit' command. */ -protected int +libedit_private int /*ARGSUSED*/ -el_editmode(EditLine *el, int argc, const Char **argv) +el_editmode(EditLine *el, int argc, const wchar_t **argv) { - const Char *how; + const wchar_t *how; if (argv == NULL || argc != 2 || argv[1] == NULL) return -1; how = argv[1]; - if (Strcmp(how, STR("on")) == 0) { + if (wcscmp(how, L"on") == 0) { el->el_flags &= ~EDIT_DISABLED; tty_rawmode(el); - } else if (Strcmp(how, STR("off")) == 0) { + } else if (wcscmp(how, L"off") == 0) { tty_cookedmode(el); el->el_flags |= EDIT_DISABLED; } else { - (void) fprintf(el->el_errfile, "edit: Bad value `" FSTR "'.\n", + (void) fprintf(el->el_errfile, "edit: Bad value `%ls'.\n", how); return -1; } diff --git a/contrib/libedit/src/el.h b/contrib/libedit/src/el.h index 70c67b8b92..c281bc01b4 100644 --- a/contrib/libedit/src/el.h +++ b/contrib/libedit/src/el.h @@ -1,4 +1,4 @@ -/* $NetBSD: el.h,v 1.25 2011/07/29 23:44:44 christos Exp $ */ +/* $NetBSD: el.h,v 1.41 2016/05/24 15:00:45 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -48,8 +48,6 @@ #include "histedit.h" #include "chartype.h" -#include -#include #define EL_BUFSIZ ((size_t)1024) /* Maximum line size */ @@ -58,11 +56,7 @@ #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 */ @@ -72,10 +66,10 @@ typedef struct coord_t { /* Position on the screen */ } coord_t; typedef struct el_line_t { - Char *buffer; /* Input line */ - Char *cursor; /* Cursor position */ - Char *lastchar; /* Last character */ - const Char *limit; /* Max position */ + wchar_t *buffer; /* Input line */ + wchar_t *cursor; /* Cursor position */ + wchar_t *lastchar; /* Last character */ + const wchar_t *limit; /* Max position */ } el_line_t; /* @@ -87,8 +81,8 @@ 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 */ - Char thisch; /* char that generated it */ + el_action_t thiscmd; /* this command */ + wchar_t thisch; /* char that generated it */ } el_state_t; /* @@ -104,17 +98,15 @@ typedef struct el_state_t { #include "terminal.h" #include "refresh.h" #include "chared.h" -#include "common.h" #include "search.h" #include "hist.h" #include "map.h" -#include "parse.h" #include "sig.h" -#include "help.h" -#include "read.h" + +struct el_read_t; struct editline { - Char *el_prog; /* the program name */ + wchar_t *el_prog; /* the program name */ FILE *el_infile; /* Stdio stuff */ FILE *el_outfile; /* Stdio stuff */ FILE *el_errfile; /* Stdio stuff */ @@ -122,10 +114,9 @@ struct editline { int el_outfd; /* Output file descriptor */ int el_errfd; /* Error file descriptor */ int el_flags; /* Various flags. */ - int el_errno; /* Local copy of errno */ coord_t el_cursor; /* Cursor location */ - Char **el_display; /* Real screen image = what is there */ - Char **el_vdisplay; /* Virtual screen image = what we see */ + wchar_t **el_display; /* Real screen image = what is there */ + wchar_t **el_vdisplay; /* Virtual screen image = what we see */ void *el_data; /* Client data */ el_line_t el_line; /* The current line information */ el_state_t el_state; /* Current editor state */ @@ -140,15 +131,14 @@ struct editline { el_history_t el_history; /* History stuff */ el_search_t el_search; /* Search stuff */ el_signal_t el_signal; /* Signal handling stuff */ - el_read_t el_read; /* Character reading stuff */ -#ifdef WIDECHAR + struct el_read_t *el_read; /* Character reading stuff */ + ct_buffer_t el_visual; /* Buffer for displayable str */ ct_buffer_t el_scratch; /* Scratch conversion buffer */ ct_buffer_t el_lgcyconv; /* Buffer for legacy wrappers */ LineInfo el_lgcylinfo; /* Legacy LineInfo buffer */ -#endif }; -protected int el_editmode(EditLine *, int, const Char **); +libedit_private int el_editmode(EditLine *, int, const wchar_t **); #ifdef DEBUG #define EL_ABORT(a) do { \ diff --git a/contrib/libedit/src/eln.c b/contrib/libedit/src/eln.c index f829d1c164..aa0a5b565d 100644 --- a/contrib/libedit/src/eln.c +++ b/contrib/libedit/src/eln.c @@ -1,4 +1,4 @@ -/* $NetBSD: eln.c,v 1.18 2015/03/24 21:26:50 christos Exp $ */ +/* $NetBSD: eln.c,v 1.34 2016/05/09 21:37:34 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -12,13 +12,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the NetBSD - * Foundation, Inc. and its contributors. - * 4. Neither the name of The NetBSD Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED @@ -34,35 +27,38 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: eln.c,v 1.18 2015/03/24 21:26:50 christos Exp $"); +__RCSID("$NetBSD: eln.c,v 1.34 2016/05/09 21:37:34 christos Exp $"); #endif /* not lint && not SCCSID */ -#include "histedit.h" -#include "el.h" -#include "read.h" +#include #include #include #include -public int +#include "el.h" + +int el_getc(EditLine *el, char *cp) { int num_read; wchar_t wc = 0; - 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; + num_read = el_wgetc(el, &wc); + *cp = '\0'; + if (num_read <= 0) + return num_read; + num_read = wctob(wc); + if (num_read == EOF) { + errno = ERANGE; + return -1; + } else { + *cp = (char)num_read; + return 1; + } } -public void +void el_push(EditLine *el, const char *str) { /* Using multibyte->wide string decoding works fine under single-byte @@ -71,43 +67,41 @@ el_push(EditLine *el, const char *str) } -public const char * +const char * el_gets(EditLine *el, int *nread) { const wchar_t *tmp; - int nwread; - *nread = 0; + tmp = el_wgets(el, nread); + if (tmp != NULL) { + int i; + size_t nwread = 0; - if (!(el->el_flags & CHARSET_IS_UTF8)) - el->el_flags |= IGNORE_EXTCHARS; - tmp = el_wgets(el, &nwread); - if (!(el->el_flags & CHARSET_IS_UTF8)) - el->el_flags &= ~IGNORE_EXTCHARS; - for (int i = 0; i < nwread; i++) - *nread += ct_enc_width(tmp[i]); + for (i = 0; i < *nread; i++) + nwread += ct_enc_width(tmp[i]); + *nread = (int)nwread; + } return ct_encode_string(tmp, &el->el_lgcyconv); } -public int +int el_parse(EditLine *el, int argc, const char *argv[]) { int ret; const wchar_t **wargv; - wargv = (const wchar_t **) - ct_decode_argv(argc, argv, &el->el_lgcyconv); + wargv = (void *)ct_decode_argv(argc, argv, &el->el_lgcyconv); if (!wargv) return -1; ret = el_wparse(el, argc, wargv); - ct_free_argv(wargv); + el_free(wargv); return ret; } -public int +int el_set(EditLine *el, int op, ...) { va_list ap; @@ -176,8 +170,7 @@ el_set(EditLine *el, int op, ...) if ((argv[i] = va_arg(ap, const char *)) == NULL) break; argv[0] = argv[i] = NULL; - wargv = (const wchar_t **) - ct_decode_argv(i + 1, argv, &el->el_lgcyconv); + wargv = (void *)ct_decode_argv(i + 1, argv, &el->el_lgcyconv); if (!wargv) { ret = -1; goto out; @@ -189,29 +182,29 @@ el_set(EditLine *el, int op, ...) */ switch (op) { case EL_BIND: - wargv[0] = STR("bind"); + wargv[0] = L"bind"; ret = map_bind(el, i, wargv); break; case EL_TELLTC: - wargv[0] = STR("telltc"); + wargv[0] = L"telltc"; ret = terminal_telltc(el, i, wargv); break; case EL_SETTC: - wargv[0] = STR("settc"); + wargv[0] = L"settc"; ret = terminal_settc(el, i, wargv); break; case EL_ECHOTC: - wargv[0] = STR("echotc"); + wargv[0] = L"echotc"; ret = terminal_echotc(el, i, wargv); break; case EL_SETTY: - wargv[0] = STR("setty"); + wargv[0] = L"setty"; ret = tty_stty(el, i, wargv); break; default: ret = -1; } - ct_free_argv(wargv); + el_free(wargv); break; } @@ -230,10 +223,10 @@ el_set(EditLine *el, int op, ...) ret = -1; goto out; } - // XXX: The two strdup's leak - ret = map_addfunc(el, Strdup(wargv[0]), Strdup(wargv[1]), + /* XXX: The two strdup's leak */ + ret = map_addfunc(el, wcsdup(wargv[0]), wcsdup(wargv[1]), func); - ct_free_argv(wargv); + el_free(wargv); break; } case EL_HIST: { /* hist_fun_t, const char * */ @@ -244,10 +237,8 @@ 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 * */ @@ -279,7 +270,7 @@ out: } -public int +int el_get(EditLine *el, int op, ...) { va_list ap; @@ -341,7 +332,6 @@ 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; @@ -373,7 +363,7 @@ el_line(EditLine *el) const LineInfoW *winfo = el_wline(el); LineInfo *info = &el->el_lgcylinfo; size_t offset; - const Char *p; + const wchar_t *p; info->buffer = ct_encode_string(winfo->buffer, &el->el_lgcyconv); diff --git a/contrib/libedit/src/emacs.c b/contrib/libedit/src/emacs.c index ab1e2dfe19..0636c28b26 100644 --- a/contrib/libedit/src/emacs.c +++ b/contrib/libedit/src/emacs.c @@ -1,4 +1,4 @@ -/* $NetBSD: emacs.c,v 1.25 2011/07/29 15:16:33 christos Exp $ */ +/* $NetBSD: emacs.c,v 1.36 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,22 +37,26 @@ #if 0 static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: emacs.c,v 1.25 2011/07/29 15:16:33 christos Exp $"); +__RCSID("$NetBSD: emacs.c,v 1.36 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * emacs.c: Emacs functions */ +#include + #include "el.h" +#include "emacs.h" +#include "fcns.h" /* em_delete_or_list(): * Delete character under cursor or list completions if at end of line * [^D] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_delete_or_list(EditLine *el, Int c) +em_delete_or_list(EditLine *el, wint_t c) { if (el->el_line.cursor == el->el_line.lastchar) { @@ -86,11 +90,11 @@ em_delete_or_list(EditLine *el, Int c) * Cut from cursor to end of current word * [M-d] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_delete_next_word(EditLine *el, Int c __attribute__((__unused__))) +em_delete_next_word(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *cp, *p, *kp; + wchar_t *cp, *p, *kp; if (el->el_line.cursor == el->el_line.lastchar) return CC_ERROR; @@ -115,11 +119,11 @@ em_delete_next_word(EditLine *el, Int c __attribute__((__unused__))) * Paste cut buffer at cursor position * [^Y] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_yank(EditLine *el, Int c __attribute__((__unused__))) +em_yank(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *kp, *cp; + wchar_t *kp, *cp; if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) return CC_NORM; @@ -151,11 +155,11 @@ em_yank(EditLine *el, Int c __attribute__((__unused__))) * Cut the entire line and save in cut buffer * [^U] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_kill_line(EditLine *el, Int c __attribute__((__unused__))) +em_kill_line(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *kp, *cp; + wchar_t *kp, *cp; cp = el->el_line.buffer; kp = el->el_chared.c_kill.buf; @@ -173,11 +177,11 @@ em_kill_line(EditLine *el, Int c __attribute__((__unused__))) * Cut area between mark and cursor and save in cut buffer * [^W] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_kill_region(EditLine *el, Int c __attribute__((__unused__))) +em_kill_region(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *kp, *cp; + wchar_t *kp, *cp; if (!el->el_chared.c_kill.mark) return CC_ERROR; @@ -206,11 +210,11 @@ em_kill_region(EditLine *el, Int c __attribute__((__unused__))) * Copy area between mark and cursor to cut buffer * [M-W] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_copy_region(EditLine *el, Int c __attribute__((__unused__))) +em_copy_region(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *kp, *cp; + wchar_t *kp, *cp; if (!el->el_chared.c_kill.mark) return CC_ERROR; @@ -236,8 +240,8 @@ em_copy_region(EditLine *el, Int c __attribute__((__unused__))) * Exchange the two characters before the cursor * Gosling emacs transpose chars [^T] */ -protected el_action_t -em_gosmacs_transpose(EditLine *el, Int c) +libedit_private el_action_t +em_gosmacs_transpose(EditLine *el, wint_t c) { if (el->el_line.cursor > &el->el_line.buffer[1]) { @@ -255,9 +259,9 @@ em_gosmacs_transpose(EditLine *el, Int c) * Move next to end of current word * [M-f] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_next_word(EditLine *el, Int c __attribute__((__unused__))) +em_next_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) return CC_ERROR; @@ -280,18 +284,18 @@ em_next_word(EditLine *el, Int c __attribute__((__unused__))) * Uppercase the characters from cursor to end of current word * [M-u] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_upper_case(EditLine *el, Int c __attribute__((__unused__))) +em_upper_case(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *cp, *ep; + wchar_t *cp, *ep; ep = c__next_word(el->el_line.cursor, el->el_line.lastchar, el->el_state.argument, ce__isword); for (cp = el->el_line.cursor; cp < ep; cp++) - if (Islower(*cp)) - *cp = Toupper(*cp); + if (iswlower(*cp)) + *cp = towupper(*cp); el->el_line.cursor = ep; if (el->el_line.cursor > el->el_line.lastchar) @@ -304,26 +308,26 @@ em_upper_case(EditLine *el, Int c __attribute__((__unused__))) * Capitalize the characters from cursor to end of current word * [M-c] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_capitol_case(EditLine *el, Int c __attribute__((__unused__))) +em_capitol_case(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *cp, *ep; + wchar_t *cp, *ep; ep = c__next_word(el->el_line.cursor, el->el_line.lastchar, el->el_state.argument, ce__isword); for (cp = el->el_line.cursor; cp < ep; cp++) { - if (Isalpha(*cp)) { - if (Islower(*cp)) - *cp = Toupper(*cp); + if (iswalpha(*cp)) { + if (iswlower(*cp)) + *cp = towupper(*cp); cp++; break; } } for (; cp < ep; cp++) - if (Isupper(*cp)) - *cp = Tolower(*cp); + if (iswupper(*cp)) + *cp = towlower(*cp); el->el_line.cursor = ep; if (el->el_line.cursor > el->el_line.lastchar) @@ -336,18 +340,18 @@ em_capitol_case(EditLine *el, Int c __attribute__((__unused__))) * Lowercase the characters from cursor to end of current word * [M-l] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_lower_case(EditLine *el, Int c __attribute__((__unused__))) +em_lower_case(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *cp, *ep; + wchar_t *cp, *ep; ep = c__next_word(el->el_line.cursor, el->el_line.lastchar, el->el_state.argument, ce__isword); for (cp = el->el_line.cursor; cp < ep; cp++) - if (Isupper(*cp)) - *cp = Tolower(*cp); + if (iswupper(*cp)) + *cp = towlower(*cp); el->el_line.cursor = ep; if (el->el_line.cursor > el->el_line.lastchar) @@ -360,9 +364,9 @@ em_lower_case(EditLine *el, Int c __attribute__((__unused__))) * Set the mark at cursor * [^@] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_set_mark(EditLine *el, Int c __attribute__((__unused__))) +em_set_mark(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_chared.c_kill.mark = el->el_line.cursor; @@ -374,11 +378,11 @@ em_set_mark(EditLine *el, Int c __attribute__((__unused__))) * Exchange the cursor and mark * [^X^X] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_exchange_mark(EditLine *el, Int c __attribute__((__unused__))) +em_exchange_mark(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *cp; + wchar_t *cp; cp = el->el_line.cursor; el->el_line.cursor = el->el_chared.c_kill.mark; @@ -391,9 +395,9 @@ em_exchange_mark(EditLine *el, Int c __attribute__((__unused__))) * Universal argument (argument times 4) * [^U] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_universal_argument(EditLine *el, Int c __attribute__((__unused__))) +em_universal_argument(EditLine *el, wint_t c __attribute__((__unused__))) { /* multiply current argument by 4 */ if (el->el_state.argument > 1000000) @@ -408,9 +412,9 @@ em_universal_argument(EditLine *el, Int c __attribute__((__unused__))) * Add 8th bit to next character typed * [] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_meta_next(EditLine *el, Int c __attribute__((__unused__))) +em_meta_next(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_state.metanext = 1; @@ -421,9 +425,9 @@ em_meta_next(EditLine *el, Int c __attribute__((__unused__))) /* em_toggle_overwrite(): * Switch from insert to overwrite mode or vice versa */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_toggle_overwrite(EditLine *el, Int c __attribute__((__unused__))) +em_toggle_overwrite(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ? @@ -435,11 +439,11 @@ em_toggle_overwrite(EditLine *el, Int c __attribute__((__unused__))) /* em_copy_prev_word(): * Copy current word to cursor */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_copy_prev_word(EditLine *el, Int c __attribute__((__unused__))) +em_copy_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *cp, *oldc, *dp; + wchar_t *cp, *oldc, *dp; if (el->el_line.cursor == el->el_line.buffer) return CC_ERROR; @@ -462,9 +466,9 @@ em_copy_prev_word(EditLine *el, Int c __attribute__((__unused__))) /* em_inc_search_next(): * Emacs incremental next search */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_inc_search_next(EditLine *el, Int c __attribute__((__unused__))) +em_inc_search_next(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_search.patlen = 0; @@ -475,9 +479,9 @@ em_inc_search_next(EditLine *el, Int c __attribute__((__unused__))) /* em_inc_search_prev(): * Emacs incremental reverse search */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_inc_search_prev(EditLine *el, Int c __attribute__((__unused__))) +em_inc_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_search.patlen = 0; @@ -489,9 +493,9 @@ em_inc_search_prev(EditLine *el, Int c __attribute__((__unused__))) * Delete the character to the left of the cursor * [^?] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -em_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) +em_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) diff --git a/contrib/libedit/src/fgetln.c b/contrib/libedit/src/fgetln.c deleted file mode 100644 index 6c4f320c12..0000000000 --- a/contrib/libedit/src/fgetln.c +++ /dev/null @@ -1,107 +0,0 @@ -/* $NetBSD: fgetln.c,v 1.9 2008/04/29 06:53:03 martin Exp $ */ - -/*- - * Copyright (c) 1998 The NetBSD Foundation, Inc. - * All rights reserved. - * - * This code is derived from software contributed to The NetBSD Foundation - * by Christos Zoulas. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_NBTOOL_CONFIG_H -#include "nbtool_config.h" -#endif - -#if !HAVE_FGETLN -#include "config.h" -#include -#ifndef HAVE_NBTOOL_CONFIG_H -/* These headers are required, but included from nbtool_config.h */ -#include -#include -#include -#include -#endif - -char * -fgetln(FILE *fp, size_t *len) -{ - static char *buf = NULL; - static size_t bufsiz = 0; - char *ptr; - - - if (buf == NULL) { - bufsiz = BUFSIZ; - if ((buf = malloc(bufsiz)) == NULL) - return NULL; - } - - if (fgets(buf, bufsiz, fp) == NULL) - return NULL; - - *len = 0; - while ((ptr = strchr(&buf[*len], '\n')) == NULL) { - size_t nbufsiz = bufsiz + BUFSIZ; - char *nbuf = realloc(buf, nbufsiz); - - if (nbuf == NULL) { - int oerrno = errno; - free(buf); - errno = oerrno; - buf = NULL; - return NULL; - } else - buf = nbuf; - - if (fgets(&buf[bufsiz], BUFSIZ, fp) == NULL) { - buf[bufsiz] = '\0'; - *len = strlen(buf); - return buf; - } - - *len = bufsiz; - bufsiz = nbufsiz; - } - - *len = (ptr - buf) + 1; - return buf; -} - -#endif - -#ifdef TEST -int -main(int argc, char *argv[]) -{ - char *p; - size_t len; - - while ((p = fgetln(stdin, &len)) != NULL) { - (void)printf("%zu %s", len, p); - free(p); - } - return 0; -} -#endif diff --git a/contrib/libedit/src/filecomplete.c b/contrib/libedit/src/filecomplete.c index 09082f75c0..a1155251db 100644 --- a/contrib/libedit/src/filecomplete.c +++ b/contrib/libedit/src/filecomplete.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecomplete.c,v 1.34 2014/10/18 15:07:02 riz Exp $ */ +/* $NetBSD: filecomplete.c,v 1.44 2016/10/31 17:46:32 abhinav Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -32,31 +32,25 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: filecomplete.c,v 1.34 2014/10/18 15:07:02 riz Exp $"); +__RCSID("$NetBSD: filecomplete.c,v 1.44 2016/10/31 17:46:32 abhinav Exp $"); #endif /* not lint && not SCCSID */ #include #include -#include #include -#include +#include +#include +#include #include -#include +#include #include +#include #include -#include -#include -#include -#include #include "el.h" -#include "fcns.h" /* for EL_NUM_FCNS */ -#include "histedit.h" #include "filecomplete.h" -static const Char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', - '$', '>', '<', '=', ';', '|', '&', '{', '(', '\0' }; - +static const wchar_t break_chars[] = L" \t\n\"\\'`@$><=;|&{("; /********************************/ /* completion functions */ @@ -98,9 +92,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 @@ -409,14 +403,14 @@ int fn_complete(EditLine *el, char *(*complet_func)(const char *, int), char **(*attempted_completion_function)(const char *, int, int), - const Char *word_break, const Char *special_prefixes, + const wchar_t *word_break, const wchar_t *special_prefixes, const char *(*app_func)(const char *), size_t query_items, int *completion_type, int *over, int *point, int *end) { - const TYPE(LineInfo) *li; - Char *temp; + const LineInfoW *li; + wchar_t *temp; char **matches; - const Char *ctemp; + const wchar_t *ctemp; size_t len; int what_to_do = '\t'; int retval = CC_NORM; @@ -434,16 +428,16 @@ fn_complete(EditLine *el, app_func = append_char_function; /* We now look backwards for the start of a filename/variable word */ - li = FUN(el,line)(el); + li = el_wline(el); ctemp = li->cursor; while (ctemp > li->buffer - && !Strchr(word_break, ctemp[-1]) - && (!special_prefixes || !Strchr(special_prefixes, ctemp[-1]) ) ) + && !wcschr(word_break, ctemp[-1]) + && (!special_prefixes || !wcschr(special_prefixes, ctemp[-1]) ) ) ctemp--; len = (size_t)(li->cursor - ctemp); temp = el_malloc((len + 1) * sizeof(*temp)); - (void)Strncpy(temp, ctemp, len); + (void)wcsncpy(temp, ctemp, len); temp[len] = '\0'; /* these can be used by function called in completion_matches() */ @@ -460,7 +454,7 @@ fn_complete(EditLine *el, cur_off - (int)len, cur_off); } else matches = NULL; - if (!attempted_completion_function || + if (!attempted_completion_function || (over != NULL && !*over && !matches)) matches = completion_matches( ct_encode_string(temp, &el->el_scratch), complet_func); @@ -479,12 +473,10 @@ fn_complete(EditLine *el, */ if (matches[0][0] != '\0') { el_deletestr(el, (int) len); - FUN(el,insertstr)(el, + el_winsertstr(el, ct_decode_string(matches[0], &el->el_scratch)); } - if (what_to_do == '?') - goto display_matches; if (matches[2] == NULL && (matches[1] == NULL || strcmp(matches[0], matches[1]) == 0)) { @@ -493,11 +485,10 @@ fn_complete(EditLine *el, * it, unless we do filename completion and the * object is a directory. */ - FUN(el,insertstr)(el, + el_winsertstr(el, ct_decode_string((*app_func)(matches[0]), &el->el_scratch)); - } else if (what_to_do == '!') { - display_matches: + } else if (what_to_do == '!' || what_to_do == '?') { /* * More than one match and requested to list possible * matches. @@ -510,7 +501,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/contrib/libedit/src/filecomplete.h b/contrib/libedit/src/filecomplete.h index 971e6e0593..7e93b9e365 100644 --- a/contrib/libedit/src/filecomplete.h +++ b/contrib/libedit/src/filecomplete.h @@ -1,4 +1,4 @@ -/* $NetBSD: filecomplete.h,v 1.9 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: filecomplete.h,v 1.10 2016/04/11 00:50:13 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ int fn_complete(EditLine *, char *(*)(const char *, int), char **(*)(const char *, int, int), - const Char *, const Char *, const char *(*)(const char *), size_t, + const wchar_t *, const wchar_t *, const char *(*)(const char *), size_t, int *, int *, int *, int *); void fn_display_match_list(EditLine *, char **, size_t, size_t); diff --git a/contrib/libedit/src/hist.c b/contrib/libedit/src/hist.c index 77dbaabc46..3c9db7dcbe 100644 --- a/contrib/libedit/src/hist.c +++ b/contrib/libedit/src/hist.c @@ -1,4 +1,4 @@ -/* $NetBSD: hist.c,v 1.20 2011/07/29 15:16:33 christos Exp $ */ +/* $NetBSD: hist.c,v 1.32 2017/03/05 19:23:58 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.20 2011/07/29 15:16:33 christos Exp $"); +__RCSID("$NetBSD: hist.c,v 1.32 2017/03/05 19:23:58 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -45,12 +45,15 @@ __RCSID("$NetBSD: hist.c,v 1.20 2011/07/29 15:16:33 christos Exp $"); * hist.c: History access functions */ #include +#include +#include + #include "el.h" /* hist_init(): * Initialization function. */ -protected int +libedit_private int hist_init(EditLine *el) { @@ -68,7 +71,7 @@ hist_init(EditLine *el) /* hist_end(): * clean up history; */ -protected void +libedit_private void hist_end(EditLine *el) { @@ -80,7 +83,7 @@ hist_end(EditLine *el) /* hist_set(): * Set new history interface */ -protected int +libedit_private int hist_set(EditLine *el, hist_fun_t fun, void *ptr) { @@ -94,14 +97,15 @@ hist_set(EditLine *el, hist_fun_t fun, void *ptr) * Get a history line and update it in the buffer. * eventno tells us the event to get. */ -protected el_action_t +libedit_private el_action_t hist_get(EditLine *el) { - const Char *hp; + const wchar_t *hp; int h; + size_t blen, hlen; if (el->el_history.eventno == 0) { /* if really the current line */ - (void) Strncpy(el->el_line.buffer, el->el_history.buf, + (void) wcsncpy(el->el_line.buffer, el->el_history.buf, el->el_history.sz); el->el_line.lastchar = el->el_line.buffer + (el->el_history.last - el->el_history.buf); @@ -124,14 +128,16 @@ hist_get(EditLine *el) return CC_ERROR; for (h = 1; h < el->el_history.eventno; h++) - if ((hp = HIST_NEXT(el)) == NULL) { - el->el_history.eventno = h; - return CC_ERROR; - } - (void) Strncpy(el->el_line.buffer, hp, - (size_t)(el->el_line.limit - el->el_line.buffer)); - el->el_line.buffer[el->el_line.limit - el->el_line.buffer - 1] = '\0'; - el->el_line.lastchar = el->el_line.buffer + Strlen(el->el_line.buffer); + if ((hp = HIST_NEXT(el)) == NULL) + goto out; + + hlen = wcslen(hp) + 1; + blen = (size_t)(el->el_line.limit - el->el_line.buffer); + if (hlen > blen && !ch_enlargebufs(el, hlen)) + goto out; + + memcpy(el->el_line.buffer, hp, hlen * sizeof(*hp)); + el->el_line.lastchar = el->el_line.buffer + hlen - 1; if (el->el_line.lastchar > el->el_line.buffer && el->el_line.lastchar[-1] == '\n') @@ -147,41 +153,66 @@ hist_get(EditLine *el) el->el_line.cursor = el->el_line.lastchar; return CC_REFRESH; +out: + el->el_history.eventno = h; + return CC_ERROR; + } /* hist_command() * process a history command */ -protected int -hist_command(EditLine *el, int argc, const Char **argv) +libedit_private int +hist_command(EditLine *el, int argc, const wchar_t **argv) { - const Char *str; + const wchar_t *str; int num; - TYPE(HistEvent) ev; + HistEventW ev; if (el->el_history.ref == NULL) return -1; - if (argc == 1 || Strcmp(argv[1], STR("list")) == 0) { + if (argc == 1 || wcscmp(argv[1], L"list") == 0) { + size_t maxlen = 0; + char *buf = NULL; + int hno = 1; /* List history entries */ - for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el)) - (void) fprintf(el->el_outfile, "%d %s", - el->el_history.ev.num, ct_encode_string(str, &el->el_scratch)); + for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el)) { + char *ptr = + ct_encode_string(str, &el->el_scratch); + size_t len = strlen(ptr); + if (len > 0 && ptr[len - 1] == '\n') + ptr[--len] = '\0'; + len = len * 4 + 1; + if (len >= maxlen) { + maxlen = len + 1024; + char *nbuf = el_realloc(buf, maxlen); + if (nbuf == NULL) { + el_free(buf); + return -1; + } + buf = nbuf; + } + strvis(buf, ptr, VIS_NL); + (void) fprintf(el->el_outfile, "%d\t%s\n", + hno++, buf); + } + el_free(buf); return 0; } if (argc != 3) return -1; - num = (int)Strtol(argv[2], NULL, 0); + num = (int)wcstol(argv[2], NULL, 0); - if (Strcmp(argv[1], STR("size")) == 0) - return FUNW(history)(el->el_history.ref, &ev, H_SETSIZE, num); + if (wcscmp(argv[1], L"size") == 0) + return history_w(el->el_history.ref, &ev, H_SETSIZE, num); - if (Strcmp(argv[1], STR("unique")) == 0) - return FUNW(history)(el->el_history.ref, &ev, H_SETUNIQUE, num); + if (wcscmp(argv[1], L"unique") == 0) + return history_w(el->el_history.ref, &ev, H_SETUNIQUE, num); return -1; } @@ -190,11 +221,11 @@ hist_command(EditLine *el, int argc, const Char **argv) * Enlarge history buffer to specified value. Called from el_enlargebufs(). * Return 0 for failure, 1 for success. */ -protected int +libedit_private int /*ARGSUSED*/ hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz) { - Char *newbuf; + wchar_t *newbuf; newbuf = el_realloc(el->el_history.buf, newsz * sizeof(*newbuf)); if (!newbuf) @@ -210,8 +241,7 @@ hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz) return 1; } -#ifdef WIDECHAR -protected wchar_t * +libedit_private wchar_t * hist_convert(EditLine *el, int fn, void *arg) { HistEventW ev; @@ -220,4 +250,3 @@ hist_convert(EditLine *el, int fn, void *arg) return ct_decode_string((const char *)(const void *)ev.str, &el->el_scratch); } -#endif diff --git a/contrib/libedit/src/hist.h b/contrib/libedit/src/hist.h index 58e5876c91..c58c5bfed8 100644 --- a/contrib/libedit/src/hist.h +++ b/contrib/libedit/src/hist.h @@ -1,4 +1,4 @@ -/* $NetBSD: hist.h,v 1.14 2014/05/11 01:05:17 christos Exp $ */ +/* $NetBSD: hist.h,v 1.22 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,31 +40,24 @@ #ifndef _h_el_hist #define _h_el_hist -#include "histedit.h" - -typedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...); +typedef int (*hist_fun_t)(void *, HistEventW *, int, ...); typedef struct el_history_t { - Char *buf; /* The history buffer */ - size_t sz; /* Size of history buffer */ - Char *last; /* The last character */ + wchar_t *buf; /* The history buffer */ + size_t sz; /* Size of history buffer */ + wchar_t *last; /* The last character */ int eventno; /* Event we are looking for */ - void * ref; /* Argument for history fcns */ + void *ref; /* Argument for history fcns */ hist_fun_t fun; /* Event access */ - TYPE(HistEvent) ev; /* Event cookie */ + HistEventW ev; /* Event cookie */ } el_history_t; #define HIST_FUN_INTERNAL(el, fn, arg) \ ((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \ fn, arg)) == -1) ? NULL : (el)->el_history.ev.str) -#ifdef WIDECHAR #define HIST_FUN(el, fn, arg) \ (((el)->el_flags & NARROW_HISTORY) ? hist_convert(el, fn, arg) : \ HIST_FUN_INTERNAL(el, fn, arg)) -#else -#define HIST_FUN(el, fn, arg) HIST_FUN_INTERNAL(el, fn, arg) -#endif - #define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL) #define HIST_FIRST(el) HIST_FUN(el, H_FIRST, NULL) @@ -75,14 +68,12 @@ typedef struct el_history_t { #define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname) #define HIST_SAVE_FP(el, fp) HIST_FUN(el, H_SAVE_FP fp) -protected int hist_init(EditLine *); -protected void hist_end(EditLine *); -protected el_action_t hist_get(EditLine *); -protected int hist_set(EditLine *, hist_fun_t, 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 *); -#endif +libedit_private int hist_init(EditLine *); +libedit_private void hist_end(EditLine *); +libedit_private el_action_t hist_get(EditLine *); +libedit_private int hist_set(EditLine *, hist_fun_t, void *); +libedit_private int hist_command(EditLine *, int, const wchar_t **); +libedit_private int hist_enlargebuf(EditLine *, size_t, size_t); +libedit_private wchar_t *hist_convert(EditLine *, int, void *); #endif /* _h_el_hist */ diff --git a/contrib/libedit/src/histedit.h b/contrib/libedit/src/histedit.h index 94f33ed2a1..9ea71899d8 100644 --- a/contrib/libedit/src/histedit.h +++ b/contrib/libedit/src/histedit.h @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.h,v 1.53 2014/06/18 18:12:28 christos Exp $ */ +/* $NetBSD: histedit.h,v 1.56 2016/04/19 19:50:53 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -128,7 +128,7 @@ unsigned char _el_fn_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 */ @@ -141,7 +141,7 @@ unsigned char _el_fn_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 */ @@ -249,20 +249,9 @@ 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 #include -/* - * Wide character versions - */ - /* * ==== Editing ==== */ @@ -272,6 +261,8 @@ typedef struct lineinfow { const wchar_t *lastchar; } LineInfoW; +typedef int (*el_rfunc_t)(EditLine *, wchar_t *); + const wchar_t *el_wgets(EditLine *, int *); int el_wgetc(EditLine *, wchar_t *); void el_wpush(EditLine *, const wchar_t *); diff --git a/contrib/libedit/src/history.c b/contrib/libedit/src/history.c index a4875275d4..5cf7e7b6fc 100644 --- a/contrib/libedit/src/history.c +++ b/contrib/libedit/src/history.c @@ -1,4 +1,4 @@ -/* $NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $ */ +/* $NetBSD: history.c,v 1.57 2016/04/11 18:56:31 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,24 +40,60 @@ #if 0 static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $"); +__RCSID("$NetBSD: history.c,v 1.57 2016/04/11 18:56:31 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * hist.c: TYPE(History) access functions */ -#include -#include +#include #include +#include +#include #include -#include static const char hist_cookie[] = "_HiStOrY_V2_\n"; #include "histedit.h" + + +#ifdef NARROWCHAR + +#define Char char +#define FUN(prefix, rest) prefix ## _ ## rest +#define FUNW(type) type +#define TYPE(type) type +#define STR(x) x + +#define Strlen(s) strlen(s) +#define Strdup(s) strdup(s) +#define Strcmp(d, s) strcmp(d, s) +#define Strncmp(d, s, n) strncmp(d, s, n) +#define Strncpy(d, s, n) strncpy(d, s, n) +#define Strncat(d, s, n) strncat(d, s, n) +#define ct_decode_string(s, b) (s) +#define ct_encode_string(s, b) (s) + +#else #include "chartype.h" +#define Char wchar_t +#define FUN(prefix, rest) prefix ## _w ## rest +#define FUNW(type) type ## _w +#define TYPE(type) type ## W +#define STR(x) L ## x + +#define Strlen(s) wcslen(s) +#define Strdup(s) wcsdup(s) +#define Strcmp(d, s) wcscmp(d, s) +#define Strncmp(d, s, n) wcsncmp(d, s, n) +#define Strncpy(d, s, n) wcsncpy(d, s, n) +#define Strncat(d, s, n) wcsncat(d, s, n) + +#endif + + typedef int (*history_gfun_t)(void *, TYPE(HistEvent) *); typedef int (*history_efun_t)(void *, TYPE(HistEvent) *, const Char *); typedef void (*history_vfun_t)(void *, TYPE(HistEvent) *); @@ -100,19 +136,20 @@ typedef struct { } HistEventPrivate; - -private int history_setsize(TYPE(History) *, TYPE(HistEvent) *, int); -private int history_getsize(TYPE(History) *, TYPE(HistEvent) *); -private int history_setunique(TYPE(History) *, TYPE(HistEvent) *, int); -private int history_getunique(TYPE(History) *, TYPE(HistEvent) *); -private int history_set_fun(TYPE(History) *, TYPE(History) *); -private int history_load(TYPE(History) *, const char *); -private int history_save(TYPE(History) *, const char *); -private int history_save_fp(TYPE(History) *, FILE *); -private int history_prev_event(TYPE(History) *, TYPE(HistEvent) *, int); -private int history_next_event(TYPE(History) *, TYPE(HistEvent) *, int); -private int history_next_string(TYPE(History) *, TYPE(HistEvent) *, const Char *); -private int history_prev_string(TYPE(History) *, TYPE(HistEvent) *, const Char *); +static int history_setsize(TYPE(History) *, TYPE(HistEvent) *, int); +static int history_getsize(TYPE(History) *, TYPE(HistEvent) *); +static int history_setunique(TYPE(History) *, TYPE(HistEvent) *, int); +static int history_getunique(TYPE(History) *, TYPE(HistEvent) *); +static int history_set_fun(TYPE(History) *, TYPE(History) *); +static int history_load(TYPE(History) *, const char *); +static int history_save(TYPE(History) *, const char *); +static int history_save_fp(TYPE(History) *, FILE *); +static int history_prev_event(TYPE(History) *, TYPE(HistEvent) *, int); +static int history_next_event(TYPE(History) *, TYPE(HistEvent) *, int); +static int history_next_string(TYPE(History) *, TYPE(HistEvent) *, + const Char *); +static int history_prev_string(TYPE(History) *, TYPE(HistEvent) *, + const Char *); /***********************************************************************/ @@ -137,23 +174,23 @@ typedef struct history_t { #define H_UNIQUE 1 /* Store only unique elements */ } history_t; -private int history_def_next(void *, TYPE(HistEvent) *); -private int history_def_first(void *, TYPE(HistEvent) *); -private int history_def_prev(void *, TYPE(HistEvent) *); -private int history_def_last(void *, TYPE(HistEvent) *); -private int history_def_curr(void *, TYPE(HistEvent) *); -private int history_def_set(void *, TYPE(HistEvent) *, const int); -private void history_def_clear(void *, TYPE(HistEvent) *); -private int history_def_enter(void *, TYPE(HistEvent) *, const Char *); -private int history_def_add(void *, TYPE(HistEvent) *, const Char *); -private int history_def_del(void *, TYPE(HistEvent) *, const int); +static int history_def_next(void *, TYPE(HistEvent) *); +static int history_def_first(void *, TYPE(HistEvent) *); +static int history_def_prev(void *, TYPE(HistEvent) *); +static int history_def_last(void *, TYPE(HistEvent) *); +static int history_def_curr(void *, TYPE(HistEvent) *); +static int history_def_set(void *, TYPE(HistEvent) *, const int); +static void history_def_clear(void *, TYPE(HistEvent) *); +static int history_def_enter(void *, TYPE(HistEvent) *, const Char *); +static int history_def_add(void *, TYPE(HistEvent) *, const Char *); +static int history_def_del(void *, TYPE(HistEvent) *, const int); -private int history_def_init(void **, TYPE(HistEvent) *, int); -private int history_def_insert(history_t *, TYPE(HistEvent) *, const Char *); -private void history_def_delete(history_t *, TYPE(HistEvent) *, hentry_t *); +static int history_def_init(void **, TYPE(HistEvent) *, int); +static int history_def_insert(history_t *, TYPE(HistEvent) *, const Char *); +static void history_def_delete(history_t *, TYPE(HistEvent) *, hentry_t *); -private int history_deldata_nth(history_t *, TYPE(HistEvent) *, int, void **); -private int history_set_nth(void *, TYPE(HistEvent) *, int); +static int history_deldata_nth(history_t *, TYPE(HistEvent) *, int, void **); +static int history_set_nth(void *, TYPE(HistEvent) *, int); #define history_def_setsize(p, num)(void) (((history_t *)p)->max = (num)) #define history_def_getsize(p) (((history_t *)p)->cur) @@ -210,7 +247,7 @@ static const Char *const he_errlist[] = { /* history_def_first(): * Default function to return the first event in the history. */ -private int +static int history_def_first(void *p, TYPE(HistEvent) *ev) { history_t *h = (history_t *) p; @@ -230,7 +267,7 @@ history_def_first(void *p, TYPE(HistEvent) *ev) /* history_def_last(): * Default function to return the last event in the history. */ -private int +static int history_def_last(void *p, TYPE(HistEvent) *ev) { history_t *h = (history_t *) p; @@ -250,7 +287,7 @@ history_def_last(void *p, TYPE(HistEvent) *ev) /* history_def_next(): * Default function to return the next event in the history. */ -private int +static int history_def_next(void *p, TYPE(HistEvent) *ev) { history_t *h = (history_t *) p; @@ -275,7 +312,7 @@ history_def_next(void *p, TYPE(HistEvent) *ev) /* history_def_prev(): * Default function to return the previous event in the history. */ -private int +static int history_def_prev(void *p, TYPE(HistEvent) *ev) { history_t *h = (history_t *) p; @@ -301,7 +338,7 @@ history_def_prev(void *p, TYPE(HistEvent) *ev) /* history_def_curr(): * Default function to return the current event in the history. */ -private int +static int history_def_curr(void *p, TYPE(HistEvent) *ev) { history_t *h = (history_t *) p; @@ -322,7 +359,7 @@ history_def_curr(void *p, TYPE(HistEvent) *ev) * Default function to set the current event in the history to the * given one. */ -private int +static int history_def_set(void *p, TYPE(HistEvent) *ev, const int n) { history_t *h = (history_t *) p; @@ -349,7 +386,7 @@ history_def_set(void *p, TYPE(HistEvent) *ev, const int n) * Default function to set the current event in the history to the * n-th one. */ -private int +static int history_set_nth(void *p, TYPE(HistEvent) *ev, int n) { history_t *h = (history_t *) p; @@ -373,7 +410,7 @@ history_set_nth(void *p, TYPE(HistEvent) *ev, int n) /* history_def_add(): * Append string to element */ -private int +static int history_def_add(void *p, TYPE(HistEvent) *ev, const Char *str) { history_t *h = (history_t *) p; @@ -399,7 +436,7 @@ history_def_add(void *p, TYPE(HistEvent) *ev, const Char *str) } -private int +static int history_deldata_nth(history_t *h, TYPE(HistEvent) *ev, int num, void **data) { @@ -421,7 +458,7 @@ history_deldata_nth(history_t *h, TYPE(HistEvent) *ev, * Delete element hp of the h list */ /* ARGSUSED */ -private int +static int history_def_del(void *p, TYPE(HistEvent) *ev __attribute__((__unused__)), const int num) { @@ -439,8 +476,8 @@ history_def_del(void *p, TYPE(HistEvent) *ev __attribute__((__unused__)), * Delete element hp of the h list */ /* ARGSUSED */ -private void -history_def_delete(history_t *h, +static void +history_def_delete(history_t *h, TYPE(HistEvent) *ev __attribute__((__unused__)), hentry_t *hp) { HistEventPrivate *evp = (void *)&hp->ev; @@ -462,7 +499,7 @@ history_def_delete(history_t *h, /* history_def_insert(): * Insert element with string str in the h list */ -private int +static int history_def_insert(history_t *h, TYPE(HistEvent) *ev, const Char *str) { hentry_t *c; @@ -494,7 +531,7 @@ oomem: /* history_def_enter(): * Default function to enter an item in the history */ -private int +static int history_def_enter(void *p, TYPE(HistEvent) *ev, const Char *str) { history_t *h = (history_t *) p; @@ -521,7 +558,7 @@ history_def_enter(void *p, TYPE(HistEvent) *ev, const Char *str) * Default history initialization function */ /* ARGSUSED */ -private int +static int history_def_init(void **p, TYPE(HistEvent) *ev __attribute__((__unused__)), int n) { history_t *h = (history_t *) h_malloc(sizeof(*h)); @@ -546,7 +583,7 @@ history_def_init(void **p, TYPE(HistEvent) *ev __attribute__((__unused__)), int /* history_def_clear(): * Default history cleanup function */ -private void +static void history_def_clear(void *p, TYPE(HistEvent) *ev) { history_t *h = (history_t *) p; @@ -566,7 +603,7 @@ history_def_clear(void *p, TYPE(HistEvent) *ev) /* history_init(): * Initialization function. */ -public TYPE(History) * +TYPE(History) * FUN(history,init)(void) { TYPE(HistEvent) ev; @@ -597,7 +634,7 @@ FUN(history,init)(void) /* history_end(): * clean up history; */ -public void +void FUN(history,end)(TYPE(History) *h) { TYPE(HistEvent) ev; @@ -613,7 +650,7 @@ FUN(history,end)(TYPE(History) *h) /* history_setsize(): * Set history number of events */ -private int +static int history_setsize(TYPE(History) *h, TYPE(HistEvent) *ev, int num) { @@ -633,7 +670,7 @@ history_setsize(TYPE(History) *h, TYPE(HistEvent) *ev, int num) /* history_getsize(): * Get number of events currently in history */ -private int +static int history_getsize(TYPE(History) *h, TYPE(HistEvent) *ev) { if (h->h_next != history_def_next) { @@ -652,7 +689,7 @@ history_getsize(TYPE(History) *h, TYPE(HistEvent) *ev) /* history_setunique(): * Set if adjacent equal events should not be entered in history. */ -private int +static int history_setunique(TYPE(History) *h, TYPE(HistEvent) *ev, int uni) { @@ -668,7 +705,7 @@ history_setunique(TYPE(History) *h, TYPE(HistEvent) *ev, int uni) /* history_getunique(): * Get if adjacent equal events should not be entered in history. */ -private int +static int history_getunique(TYPE(History) *h, TYPE(HistEvent) *ev) { if (h->h_next != history_def_next) { @@ -683,7 +720,7 @@ history_getunique(TYPE(History) *h, TYPE(HistEvent) *ev) /* history_set_fun(): * Set history functions */ -private int +static int history_set_fun(TYPE(History) *h, TYPE(History) *nh) { TYPE(HistEvent) ev; @@ -730,42 +767,41 @@ history_set_fun(TYPE(History) *h, TYPE(History) *nh) /* history_load(): * TYPE(History) load function */ -private int +static int history_load(TYPE(History) *h, const char *fname) { FILE *fp; char *line; - size_t sz, max_size; + size_t llen; + ssize_t sz; + size_t max_size; char *ptr; int i = -1; TYPE(HistEvent) ev; -#ifdef WIDECHAR +#ifndef NARROWCHAR static ct_buffer_t conv; #endif if ((fp = fopen(fname, "r")) == NULL) return i; - if ((line = fgetln(fp, &sz)) == NULL) + line = NULL; + llen = 0; + if ((sz = getline(&line, &llen, fp)) == -1) goto done; - if (strncmp(line, hist_cookie, sz) != 0) + if (strncmp(line, hist_cookie, (size_t)sz) != 0) goto done; ptr = h_malloc((max_size = 1024) * sizeof(*ptr)); if (ptr == NULL) goto done; - for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) { - char c = line[sz]; - - if (sz != 0 && line[sz - 1] == '\n') + for (i = 0; (sz = getline(&line, &llen, fp)) != -1; i++) { + if (sz > 0 && line[sz - 1] == '\n') line[--sz] = '\0'; - else - line[sz] = '\0'; - - if (max_size < sz) { + if (max_size < (size_t)sz) { char *nptr; - max_size = (sz + 1024) & (size_t)~1023; + max_size = ((size_t)sz + 1024) & (size_t)~1023; nptr = h_realloc(ptr, max_size * sizeof(*ptr)); if (nptr == NULL) { i = -1; @@ -774,7 +810,6 @@ 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; @@ -783,6 +818,7 @@ history_load(TYPE(History) *h, const char *fname) oomem: h_free(ptr); done: + free(line); (void) fclose(fp); return i; } @@ -791,7 +827,7 @@ done: /* history_save_fp(): * TYPE(History) save function */ -private int +static int history_save_fp(TYPE(History) *h, FILE *fp) { TYPE(HistEvent) ev; @@ -799,7 +835,7 @@ history_save_fp(TYPE(History) *h, FILE *fp) size_t len, max_size; char *ptr; const char *str; -#ifdef WIDECHAR +#ifndef NARROWCHAR static ct_buffer_t conv; #endif @@ -814,8 +850,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; - if (len >= max_size) { + len = strlen(str) * 4 + 1; + if (len > max_size) { char *nptr; max_size = (len + 1024) & (size_t)~1023; nptr = h_realloc(ptr, max_size * sizeof(*ptr)); @@ -838,7 +874,7 @@ done: /* history_save(): * History save function */ -private int +static int history_save(TYPE(History) *h, const char *fname) { FILE *fp; @@ -857,7 +893,7 @@ history_save(TYPE(History) *h, const char *fname) /* history_prev_event(): * Find the previous event, with number given */ -private int +static int history_prev_event(TYPE(History) *h, TYPE(HistEvent) *ev, int num) { int retval; @@ -871,7 +907,7 @@ history_prev_event(TYPE(History) *h, TYPE(HistEvent) *ev, int num) } -private int +static int history_next_evdata(TYPE(History) *h, TYPE(HistEvent) *ev, int num, void **d) { int retval; @@ -891,7 +927,7 @@ history_next_evdata(TYPE(History) *h, TYPE(HistEvent) *ev, int num, void **d) /* history_next_event(): * Find the next event, with number given */ -private int +static int history_next_event(TYPE(History) *h, TYPE(HistEvent) *ev, int num) { int retval; @@ -908,7 +944,7 @@ history_next_event(TYPE(History) *h, TYPE(HistEvent) *ev, int num) /* history_prev_string(): * Find the previous event beginning with string */ -private int +static int history_prev_string(TYPE(History) *h, TYPE(HistEvent) *ev, const Char *str) { size_t len = Strlen(str); @@ -926,7 +962,7 @@ history_prev_string(TYPE(History) *h, TYPE(HistEvent) *ev, const Char *str) /* history_next_string(): * Find the next event beginning with string */ -private int +static int history_next_string(TYPE(History) *h, TYPE(HistEvent) *ev, const Char *str) { size_t len = Strlen(str); diff --git a/contrib/libedit/src/historyn.c b/contrib/libedit/src/historyn.c new file mode 100644 index 0000000000..59130dea34 --- /dev/null +++ b/contrib/libedit/src/historyn.c @@ -0,0 +1,3 @@ +#include "config.h" +#define NARROWCHAR +#include "history.c" diff --git a/contrib/libedit/src/keymacro.c b/contrib/libedit/src/keymacro.c index 1cab508fa0..13d208930e 100644 --- a/contrib/libedit/src/keymacro.c +++ b/contrib/libedit/src/keymacro.c @@ -1,4 +1,4 @@ -/* $NetBSD: keymacro.c,v 1.7 2011/08/16 16:25:15 christos Exp $ */ +/* $NetBSD: keymacro.c,v 1.23 2016/05/24 15:00:45 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.7 2011/08/16 16:25:15 christos Exp $"); +__RCSID("$NetBSD: keymacro.c,v 1.23 2016/05/24 15:00:45 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -50,7 +50,7 @@ __RCSID("$NetBSD: keymacro.c,v 1.7 2011/08/16 16:25:15 christos Exp $"); * number of characters. This module maintains a map (the * el->el_keymacro.map) * to convert these extended-key sequences into input strs - * (XK_STR), editor functions (XK_CMD), or unix commands (XK_EXE). + * (XK_STR) or editor functions (XK_CMD). * * Warning: * If key is a substr of some other keys, then the longer @@ -63,36 +63,37 @@ __RCSID("$NetBSD: keymacro.c,v 1.7 2011/08/16 16:25:15 christos Exp $"); * 1) It is not possible to have one key that is a * substr of another. */ -#include #include +#include #include "el.h" +#include "fcns.h" /* * The Nodes of the el->el_keymacro.map. The el->el_keymacro.map is a * linked list of these node elements */ struct keymacro_node_t { - Char ch; /* single character of key */ + wchar_t 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*/ }; -private int node_trav(EditLine *, keymacro_node_t *, Char *, +static int node_trav(EditLine *, keymacro_node_t *, wchar_t *, keymacro_value_t *); -private int node__try(EditLine *, keymacro_node_t *, const Char *, - keymacro_value_t *, int); -private keymacro_node_t *node__get(Int); -private void node__free(keymacro_node_t *); -private void node__put(EditLine *, keymacro_node_t *); -private int node__delete(EditLine *, keymacro_node_t **, - const Char *); -private int node_lookup(EditLine *, const Char *, +static int node__try(EditLine *, keymacro_node_t *, + const wchar_t *, keymacro_value_t *, int); +static keymacro_node_t *node__get(wint_t); +static void node__free(keymacro_node_t *); +static void node__put(EditLine *, keymacro_node_t *); +static int node__delete(EditLine *, keymacro_node_t **, + const wchar_t *); +static int node_lookup(EditLine *, const wchar_t *, keymacro_node_t *, size_t); -private int node_enum(EditLine *, keymacro_node_t *, size_t); +static int node_enum(EditLine *, keymacro_node_t *, size_t); #define KEY_BUFSIZ EL_BUFSIZ @@ -100,7 +101,7 @@ private int node_enum(EditLine *, keymacro_node_t *, size_t); /* keymacro_init(): * Initialize the key maps */ -protected int +libedit_private int keymacro_init(EditLine *el) { @@ -116,7 +117,7 @@ keymacro_init(EditLine *el) /* keymacro_end(): * Free the key maps */ -protected void +libedit_private void keymacro_end(EditLine *el) { @@ -129,7 +130,7 @@ keymacro_end(EditLine *el) /* keymacro_map_cmd(): * Associate cmd with a key value */ -protected keymacro_value_t * +libedit_private keymacro_value_t * keymacro_map_cmd(EditLine *el, int cmd) { @@ -141,8 +142,8 @@ keymacro_map_cmd(EditLine *el, int cmd) /* keymacro_map_str(): * Associate str with a key value */ -protected keymacro_value_t * -keymacro_map_str(EditLine *el, Char *str) +libedit_private keymacro_value_t * +keymacro_map_str(EditLine *el, wchar_t *str) { el->el_keymacro.val.str = str; @@ -155,7 +156,7 @@ keymacro_map_str(EditLine *el, Char *str) * Then initializes el->el_keymacro.map with arrow keys * [Always bind the ansi arrow keys?] */ -protected void +libedit_private void keymacro_reset(EditLine *el) { @@ -169,12 +170,13 @@ keymacro_reset(EditLine *el) * Calls the recursive function with entry point el->el_keymacro.map * Looks up *ch in map and then reads characters until a * complete match is found or a mismatch occurs. Returns the - * type of the match found (XK_STR, XK_CMD, or XK_EXE). + * type of the match found (XK_STR or XK_CMD). * Returns NULL in val.str and XK_STR for no match. + * Returns XK_NOD for end of file or read error. * The last character read is returned in *ch. */ -protected int -keymacro_get(EditLine *el, Char *ch, keymacro_value_t *val) +libedit_private int +keymacro_get(EditLine *el, wchar_t *ch, keymacro_value_t *val) { return node_trav(el, el->el_keymacro.map, ch, val); @@ -187,8 +189,9 @@ keymacro_get(EditLine *el, Char *ch, keymacro_value_t *val) * code is applied to the existing key. Ntype specifies if code is a * command, an out str or a unix command. */ -protected void -keymacro_add(EditLine *el, const Char *key, keymacro_value_t *val, int ntype) +libedit_private void +keymacro_add(EditLine *el, const wchar_t *key, keymacro_value_t *val, + int ntype) { if (key[0] == '\0') { @@ -215,13 +218,11 @@ keymacro_add(EditLine *el, const Char *key, keymacro_value_t *val, int ntype) /* keymacro_clear(): * */ -protected void -keymacro_clear(EditLine *el, el_action_t *map, const Char *in) +libedit_private void +keymacro_clear(EditLine *el, el_action_t *map, const wchar_t *in) { -#ifdef WIDECHAR if (*in > N_KEYS) /* can't be in the map */ return; -#endif if ((map[(unsigned char)*in] == ED_SEQUENCE_LEAD_IN) && ((map == el->el_map.key && el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) || @@ -235,8 +236,8 @@ keymacro_clear(EditLine *el, el_action_t *map, const Char *in) * Delete the key and all longer keys staring with key, if * they exists. */ -protected int -keymacro_delete(EditLine *el, const Char *key) +libedit_private int +keymacro_delete(EditLine *el, const wchar_t *key) { if (key[0] == '\0') { @@ -256,8 +257,8 @@ keymacro_delete(EditLine *el, const Char *key) * Print the binding associated with key key. * Print entire el->el_keymacro.map if null */ -protected void -keymacro_print(EditLine *el, const Char *key) +libedit_private void +keymacro_print(EditLine *el, const wchar_t *key) { /* do nothing if el->el_keymacro.map is empty and null key specified */ @@ -267,7 +268,7 @@ keymacro_print(EditLine *el, const Char *key) el->el_keymacro.buf[0] = '"'; if (node_lookup(el, key, el->el_keymacro.map, (size_t)1) <= -1) /* key is not bound */ - (void) fprintf(el->el_errfile, "Unbound extended key \"" FSTR + (void) fprintf(el->el_errfile, "Unbound extended key \"%ls" "\"\n", key); return; } @@ -275,21 +276,19 @@ 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) +static int +node_trav(EditLine *el, keymacro_node_t *ptr, wchar_t *ch, + keymacro_value_t *val) { if (ptr->ch == *ch) { /* match found */ if (ptr->next) { /* key not complete so get next char */ - if (FUN(el,getc)(el, ch) != 1) {/* if EOF or error */ - val->cmd = ED_END_OF_FILE; - return XK_CMD; - /* PWP: Pretend we just read an end-of-file */ - } + if (el_wgetc(el, ch) != 1) + return XK_NOD; return node_trav(el, ptr->next, ch, val); } else { *val = ptr->val; @@ -312,10 +311,10 @@ 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, +static int +node__try(EditLine *el, keymacro_node_t *ptr, const wchar_t *str, keymacro_value_t *val, int ntype) { @@ -341,7 +340,6 @@ node__try(EditLine *el, keymacro_node_t *ptr, const Char *str, case XK_NOD: break; case XK_STR: - case XK_EXE: if (ptr->val.str) el_free(ptr->val.str); break; @@ -356,8 +354,7 @@ node__try(EditLine *el, keymacro_node_t *ptr, const Char *str, ptr->val = *val; break; case XK_STR: - case XK_EXE: - if ((ptr->val.str = Strdup(val->str)) == NULL) + if ((ptr->val.str = wcsdup(val->str)) == NULL) return -1; break; default: @@ -377,8 +374,8 @@ node__try(EditLine *el, keymacro_node_t *ptr, const Char *str, /* node__delete(): * Delete node that matches str */ -private int -node__delete(EditLine *el, keymacro_node_t **inptr, const Char *str) +static int +node__delete(EditLine *el, keymacro_node_t **inptr, const wchar_t *str) { keymacro_node_t *ptr; keymacro_node_t *prev_ptr = NULL; @@ -425,7 +422,7 @@ node__delete(EditLine *el, keymacro_node_t **inptr, const Char *str) /* node__put(): * Puts a tree of nodes onto free list using free(3). */ -private void +static void node__put(EditLine *el, keymacro_node_t *ptr) { if (ptr == NULL) @@ -441,7 +438,6 @@ node__put(EditLine *el, keymacro_node_t *ptr) case XK_CMD: case XK_NOD: break; - case XK_EXE: case XK_STR: if (ptr->val.str != NULL) el_free(ptr->val.str); @@ -457,8 +453,8 @@ node__put(EditLine *el, keymacro_node_t *ptr) /* node__get(): * Returns pointer to a keymacro_node_t for ch. */ -private keymacro_node_t * -node__get(Int ch) +static keymacro_node_t * +node__get(wint_t ch) { keymacro_node_t *ptr; @@ -473,7 +469,7 @@ node__get(Int ch) return ptr; } -private void +static void node__free(keymacro_node_t *k) { if (k == NULL) @@ -487,8 +483,9 @@ node__free(keymacro_node_t *k) * look for the str starting at node ptr. * Print if last node */ -private int -node_lookup(EditLine *el, const Char *str, keymacro_node_t *ptr, size_t cnt) +static int +node_lookup(EditLine *el, const wchar_t *str, keymacro_node_t *ptr, + size_t cnt) { ssize_t used; @@ -539,7 +536,7 @@ node_lookup(EditLine *el, const Char *str, keymacro_node_t *ptr, size_t cnt) /* node_enum(): * Traverse the node printing the characters it is bound in buffer */ -private int +static int node_enum(EditLine *el, keymacro_node_t *ptr, size_t cnt) { ssize_t used; @@ -549,7 +546,7 @@ node_enum(EditLine *el, keymacro_node_t *ptr, size_t cnt) el->el_keymacro.buf[++cnt] = '\0'; (void) fprintf(el->el_errfile, "Some extended keys too long for internal print buffer"); - (void) fprintf(el->el_errfile, " \"" FSTR "...\"\n", + (void) fprintf(el->el_errfile, " \"%ls...\"\n", el->el_keymacro.buf); return 0; } @@ -582,8 +579,9 @@ node_enum(EditLine *el, keymacro_node_t *ptr, size_t cnt) * Print the specified key and its associated * function specified by val */ -protected void -keymacro_kprint(EditLine *el, const Char *key, keymacro_value_t *val, int ntype) +libedit_private void +keymacro_kprint(EditLine *el, const wchar_t *key, keymacro_value_t *val, + int ntype) { el_bindings_t *fp; char unparsbuf[EL_BUFSIZ]; @@ -592,9 +590,8 @@ keymacro_kprint(EditLine *el, const Char *key, keymacro_value_t *val, int ntype) if (val != NULL) switch (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); @@ -602,7 +599,7 @@ keymacro_kprint(EditLine *el, const Char *key, keymacro_value_t *val, int ntype) case XK_CMD: for (fp = el->el_map.help; fp->name; fp++) if (val->cmd == fp->func) { - ct_wcstombs(unparsbuf, fp->name, sizeof(unparsbuf)); + wcstombs(unparsbuf, fp->name, sizeof(unparsbuf)); unparsbuf[sizeof(unparsbuf) -1] = '\0'; (void) fprintf(el->el_outfile, fmt, ct_encode_string(key, &el->el_scratch), unparsbuf); @@ -633,11 +630,12 @@ keymacro_kprint(EditLine *el, const Char *key, keymacro_value_t *val, int ntype) /* keymacro__decode_str(): * Make a printable version of the ey */ -protected size_t -keymacro__decode_str(const Char *str, char *buf, size_t len, const char *sep) +libedit_private size_t +keymacro__decode_str(const wchar_t *str, char *buf, size_t len, + const char *sep) { char *b = buf, *eb = b + len; - const Char *p; + const wchar_t *p; b = buf; if (sep[0] != '\0') { @@ -649,8 +647,8 @@ keymacro__decode_str(const Char *str, char *buf, size_t len, const char *sep) goto add_endsep; } for (p = str; *p != 0; p++) { - Char dbuf[VISUAL_WIDTH_MAX]; - Char *p2 = dbuf; + wchar_t dbuf[VISUAL_WIDTH_MAX]; + wchar_t *p2 = dbuf; ssize_t l = ct_visual_char(dbuf, VISUAL_WIDTH_MAX, *p); while (l-- > 0) { ssize_t n = ct_encode_char(b, (size_t)(eb - b), *p2++); diff --git a/contrib/libedit/src/keymacro.h b/contrib/libedit/src/keymacro.h index 2445de5a5b..0653bbe3f2 100644 --- a/contrib/libedit/src/keymacro.h +++ b/contrib/libedit/src/keymacro.h @@ -1,4 +1,4 @@ -/* $NetBSD: keymacro.h,v 1.2 2011/07/28 03:44:36 christos Exp $ */ +/* $NetBSD: keymacro.h,v 1.6 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -42,13 +42,13 @@ typedef union keymacro_value_t { el_action_t cmd; /* If it is a command the # */ - Char *str; /* If it is a string... */ + wchar_t *str; /* If it is a string... */ } keymacro_value_t; typedef struct keymacro_node_t keymacro_node_t; -typedef struct el_keymacromacro_t { - Char *buf; /* Key print buffer */ +typedef struct el_keymacro_t { + wchar_t *buf; /* Key print buffer */ keymacro_node_t *map; /* Key map */ keymacro_value_t val; /* Local conversion buffer */ } el_keymacro_t; @@ -56,21 +56,21 @@ typedef struct el_keymacromacro_t { #define XK_CMD 0 #define XK_STR 1 #define XK_NOD 2 -#define XK_EXE 3 -protected int keymacro_init(EditLine *); -protected void keymacro_end(EditLine *); -protected keymacro_value_t *keymacro_map_cmd(EditLine *, int); -protected keymacro_value_t *keymacro_map_str(EditLine *, Char *); -protected void keymacro_reset(EditLine *); -protected int keymacro_get(EditLine *, Char *, keymacro_value_t *); -protected void keymacro_add(EditLine *, const Char *, keymacro_value_t *, int); -protected void keymacro_clear(EditLine *, el_action_t *, const Char *); -protected int keymacro_delete(EditLine *, const Char *); -protected void keymacro_print(EditLine *, const Char *); -protected void keymacro_kprint(EditLine *, const Char *, keymacro_value_t *, - int); -protected size_t keymacro__decode_str(const Char *, char *, size_t, +libedit_private int keymacro_init(EditLine *); +libedit_private void keymacro_end(EditLine *); +libedit_private keymacro_value_t *keymacro_map_cmd(EditLine *, int); +libedit_private keymacro_value_t *keymacro_map_str(EditLine *, wchar_t *); +libedit_private void keymacro_reset(EditLine *); +libedit_private int keymacro_get(EditLine *, wchar_t *, keymacro_value_t *); +libedit_private void keymacro_add(EditLine *, const wchar_t *, + keymacro_value_t *, int); +libedit_private void keymacro_clear(EditLine *, el_action_t *, const wchar_t *); +libedit_private int keymacro_delete(EditLine *, const wchar_t *); +libedit_private void keymacro_print(EditLine *, const wchar_t *); +libedit_private void keymacro_kprint(EditLine *, const wchar_t *, + keymacro_value_t *, int); +libedit_private size_t keymacro__decode_str(const wchar_t *, char *, size_t, const char *); #endif /* _h_el_keymacro */ diff --git a/contrib/libedit/src/makelist b/contrib/libedit/src/makelist index 1e95bae651..598cc7619b 100644 --- a/contrib/libedit/src/makelist +++ b/contrib/libedit/src/makelist @@ -1,5 +1,5 @@ #!/bin/sh - -# $NetBSD: makelist,v 1.18 2012/03/21 05:34:54 matt Exp $ +# $NetBSD: makelist,v 1.29 2016/05/09 21:46:56 christos Exp $ # # Copyright (c) 1992, 1993 # The Regents of the University of California. All rights reserved. @@ -35,7 +35,8 @@ # makelist.sh: Automatically generate header files... -USAGE="Usage: $0 -n|-h|-e|-fc|-fh|-bc|-bh|-m " +AWK=awk +USAGE="Usage: $0 -h|-fc|-fh|-bh " if [ "x$1" = "x" ] then @@ -50,17 +51,6 @@ FILES="$@" case $FLAG in -# generate foo.h file from foo.c -# --n) - cat << _EOF -#include "config.h" -#undef WIDECHAR -#define NARROWCHAR -#include "${FILES}" -_EOF - ;; - -h) set - `echo $FILES | sed -e 's/\\./_/g'` hdr="_h_`basename $1`" @@ -77,7 +67,8 @@ _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 *, Int);\n", name); + printf("libedit_private el_action_t\t%s (EditLine *, wint_t);\n", + name); } } END { @@ -85,15 +76,13 @@ _EOF }' ;; -# generate help.c from various .c files +# generate help.h from various .c files # --bc) +-bh) cat $FILES | $AWK ' BEGIN { printf("/* Automatically generated file, do not edit */\n"); - printf("#include \"config.h\"\n#include \"el.h\"\n"); - printf("#include \"chartype.h\"\n"); - printf("private const struct el_bindings_t el_func_help[] = {\n"); + printf("static const struct el_bindings_t el_func_help[] = {\n"); low = "abcdefghijklmnopqrstuvwxyz_"; high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; for (i = 1; i <= length(low); i++) @@ -113,38 +102,24 @@ _EOF fname = fname s; } - printf(" { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ","); + printf(" { %-30.30s %-30.30s\n","L\"" fname "\",", uname ","); ok = 1; } } /^ \*/ { if (ok) { - printf(" STR(\""); + printf(" L\""); for (i = 2; i < NF; i++) printf("%s ", $i); - printf("%s\") },\n", $i); + printf("%s\" },\n", $i); ok = 0; } } END { printf("};\n"); - printf("\nprotected const el_bindings_t* help__get(void)"); - printf("{ return el_func_help; }\n"); }' ;; -# generate help.h from various .c files -# --bh) - $AWK ' - BEGIN { - printf("/* Automatically generated file, do not edit */\n"); - printf("#ifndef _h_help_c\n#define _h_help_c\n"); - printf("protected const el_bindings_t *help__get(void);\n"); - printf("#endif /* _h_help_c */\n"); - }' /dev/null - ;; - # generate fcns.h from various .h files # -fh) @@ -152,7 +127,6 @@ _EOF sort | tr '[a-z]' '[A-Z]' | $AWK ' BEGIN { printf("/* Automatically generated file, do not edit */\n"); - printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n"); count = 0; } { @@ -160,21 +134,16 @@ _EOF } END { printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); - - 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"); }' ;; -# generate fcns.c from various .h files +# generate func.h from various .h files # -fc) cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' BEGIN { printf("/* Automatically generated file, do not edit */\n"); - printf("#include \"config.h\"\n#include \"el.h\"\n"); - printf("private const el_func_t el_func[] = {"); + printf("static const el_func_t el_func[] = {"); maxlen = 80; needn = 1; len = 0; @@ -194,59 +163,6 @@ _EOF } END { printf("\n};\n"); - printf("\nprotected const el_func_t* func__get(void) { return el_func; }\n"); - }' - ;; - -# generate editline.c from various .c files -# --e) - echo "$FILES" | tr ' ' '\012' | $AWK ' - BEGIN { - printf("/* Automatically generated file, do not edit */\n"); - printf("#define protected static\n"); - printf("#define SCCSID\n"); - } - { - printf("#include \"%s\"\n", $1); - }' - ;; - -# generate man page fragment from various .c files -# --m) - cat $FILES | $AWK ' - BEGIN { - printf(".\\\" Section automatically generated with makelist\n"); - printf(".Bl -tag -width 4n\n"); - } - /\(\):/ { - pr = substr($2, 1, 2); - if (pr == "vi" || pr == "em" || pr == "ed") { - name = substr($2, 1, length($2) - 3); - fname = ""; - for (i = 1; i <= length(name); i++) { - s = substr(name, i, 1); - if (s == "_") - s = "-"; - fname = fname s; - } - - printf(".It Ic %s\n", fname); - ok = 1; - } - } - /^ \*/ { - if (ok) { - for (i = 2; i < NF; i++) - printf("%s ", $i); - printf("%s.\n", $i); - ok = 0; - } - } - END { - printf(".El\n"); - printf(".\\\" End of section automatically generated with makelist\n"); }' ;; diff --git a/contrib/libedit/src/map.c b/contrib/libedit/src/map.c index 79f793cb66..f72d2724a8 100644 --- a/contrib/libedit/src/map.c +++ b/contrib/libedit/src/map.c @@ -1,4 +1,4 @@ -/* $NetBSD: map.c,v 1.34 2014/07/06 18:15:34 christos Exp $ */ +/* $NetBSD: map.c,v 1.51 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,30 +37,40 @@ #if 0 static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: map.c,v 1.34 2014/07/06 18:15:34 christos Exp $"); +__RCSID("$NetBSD: map.c,v 1.51 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * map.c: Editor function definitions */ +#include #include -#include "el.h" +#include -private void map_print_key(EditLine *, el_action_t *, const Char *); -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 *); +#include "el.h" +#include "common.h" +#include "emacs.h" +#include "vi.h" +#include "fcns.h" +#include "func.h" +#include "help.h" +#include "parse.h" + +static void map_print_key(EditLine *, el_action_t *, const wchar_t *); +static void map_print_some_keys(EditLine *, el_action_t *, wint_t, wint_t); +static void map_print_all_keys(EditLine *); +static void map_init_nls(EditLine *); +static void map_init_meta(EditLine *); /* keymap tables ; should be N_KEYS*sizeof(KEYCMD) bytes long */ -private const el_action_t el_map_emacs[] = { +static const el_action_t el_map_emacs[] = { /* 0 */ EM_SET_MARK, /* ^@ */ /* 1 */ ED_MOVE_TO_BEG, /* ^A */ /* 2 */ ED_PREV_CHAR, /* ^B */ - /* 3 */ ED_TTY_SIGINT, /* ^C */ + /* 3 */ ED_IGNORE, /* ^C */ /* 4 */ EM_DELETE_OR_LIST, /* ^D */ /* 5 */ ED_MOVE_TO_END, /* ^E */ /* 6 */ ED_NEXT_CHAR, /* ^F */ @@ -72,21 +82,21 @@ private const el_action_t el_map_emacs[] = { /* 12 */ ED_CLEAR_SCREEN, /* ^L */ /* 13 */ ED_NEWLINE, /* ^M */ /* 14 */ ED_NEXT_HISTORY, /* ^N */ - /* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */ + /* 15 */ ED_IGNORE, /* ^O */ /* 16 */ ED_PREV_HISTORY, /* ^P */ - /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */ + /* 17 */ ED_IGNORE, /* ^Q */ /* 18 */ ED_REDISPLAY, /* ^R */ - /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */ + /* 19 */ ED_IGNORE, /* ^S */ /* 20 */ ED_TRANSPOSE_CHARS, /* ^T */ /* 21 */ EM_KILL_LINE, /* ^U */ /* 22 */ ED_QUOTED_INSERT, /* ^V */ /* 23 */ EM_KILL_REGION, /* ^W */ /* 24 */ ED_SEQUENCE_LEAD_IN, /* ^X */ /* 25 */ EM_YANK, /* ^Y */ - /* 26 */ ED_TTY_SIGTSTP, /* ^Z */ + /* 26 */ ED_IGNORE, /* ^Z */ /* 27 */ EM_META_NEXT, /* ^[ */ - /* 28 */ ED_TTY_SIGQUIT, /* ^\ */ - /* 29 */ ED_TTY_DSUSP, /* ^] */ + /* 28 */ ED_IGNORE, /* ^\ */ + /* 29 */ ED_IGNORE, /* ^] */ /* 30 */ ED_UNASSIGNED, /* ^^ */ /* 31 */ ED_UNASSIGNED, /* ^_ */ /* 32 */ ED_INSERT, /* SPACE */ @@ -323,7 +333,7 @@ private const el_action_t el_map_emacs[] = { * insert mode characters are in the normal keymap, and command mode * in the extended keymap. */ -private const el_action_t el_map_vi_insert[] = { +static const el_action_t el_map_vi_insert[] = { #ifdef KSHVI /* 0 */ ED_UNASSIGNED, /* ^@ */ /* 1 */ ED_INSERT, /* ^A */ @@ -342,9 +352,9 @@ private const el_action_t el_map_vi_insert[] = { /* 14 */ ED_INSERT, /* ^N */ /* 15 */ ED_INSERT, /* ^O */ /* 16 */ ED_INSERT, /* ^P */ - /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */ + /* 17 */ ED_IGNORE, /* ^Q */ /* 18 */ ED_INSERT, /* ^R */ - /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */ + /* 19 */ ED_IGNORE, /* ^S */ /* 20 */ ED_INSERT, /* ^T */ /* 21 */ VI_KILL_LINE_PREV, /* ^U */ /* 22 */ ED_QUOTED_INSERT, /* ^V */ @@ -354,7 +364,7 @@ private const el_action_t el_map_vi_insert[] = { /* 25 */ ED_INSERT, /* ^Y */ /* 26 */ ED_INSERT, /* ^Z */ /* 27 */ VI_COMMAND_MODE, /* ^[ */ /* [ Esc ] key */ - /* 28 */ ED_TTY_SIGQUIT, /* ^\ */ + /* 28 */ ED_IGNORE, /* ^\ */ /* 29 */ ED_INSERT, /* ^] */ /* 30 */ ED_INSERT, /* ^^ */ /* 31 */ ED_INSERT, /* ^_ */ @@ -368,7 +378,7 @@ private const el_action_t el_map_vi_insert[] = { /* 0 */ ED_UNASSIGNED, /* ^@ */ /* 1 */ ED_MOVE_TO_BEG, /* ^A */ /* 2 */ ED_PREV_CHAR, /* ^B */ - /* 3 */ ED_TTY_SIGINT, /* ^C */ + /* 3 */ ED_IGNORE, /* ^C */ /* 4 */ VI_LIST_OR_EOF, /* ^D */ /* 5 */ ED_MOVE_TO_END, /* ^E */ /* 6 */ ED_NEXT_CHAR, /* ^F */ @@ -380,20 +390,20 @@ private const el_action_t el_map_vi_insert[] = { /* 12 */ ED_CLEAR_SCREEN, /* ^L */ /* 13 */ ED_NEWLINE, /* ^M */ /* 14 */ ED_NEXT_HISTORY, /* ^N */ - /* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */ + /* 15 */ ED_IGNORE, /* ^O */ /* 16 */ ED_PREV_HISTORY, /* ^P */ - /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */ + /* 17 */ ED_IGNORE, /* ^Q */ /* 18 */ ED_REDISPLAY, /* ^R */ - /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */ + /* 19 */ ED_IGNORE, /* ^S */ /* 20 */ ED_TRANSPOSE_CHARS, /* ^T */ /* 21 */ VI_KILL_LINE_PREV, /* ^U */ /* 22 */ ED_QUOTED_INSERT, /* ^V */ /* 23 */ ED_DELETE_PREV_WORD, /* ^W */ /* 24 */ ED_UNASSIGNED, /* ^X */ - /* 25 */ ED_TTY_DSUSP, /* ^Y */ - /* 26 */ ED_TTY_SIGTSTP, /* ^Z */ + /* 25 */ ED_IGNORE, /* ^Y */ + /* 26 */ ED_IGNORE, /* ^Z */ /* 27 */ VI_COMMAND_MODE, /* ^[ */ - /* 28 */ ED_TTY_SIGQUIT, /* ^\ */ + /* 28 */ ED_IGNORE, /* ^\ */ /* 29 */ ED_UNASSIGNED, /* ^] */ /* 30 */ ED_UNASSIGNED, /* ^^ */ /* 31 */ ED_UNASSIGNED, /* ^_ */ @@ -624,11 +634,11 @@ private const el_action_t el_map_vi_insert[] = { /* 255 */ ED_INSERT /* M-^? */ }; -private const el_action_t el_map_vi_command[] = { +static const el_action_t el_map_vi_command[] = { /* 0 */ ED_UNASSIGNED, /* ^@ */ /* 1 */ ED_MOVE_TO_BEG, /* ^A */ /* 2 */ ED_UNASSIGNED, /* ^B */ - /* 3 */ ED_TTY_SIGINT, /* ^C */ + /* 3 */ ED_IGNORE, /* ^C */ /* 4 */ ED_UNASSIGNED, /* ^D */ /* 5 */ ED_MOVE_TO_END, /* ^E */ /* 6 */ ED_UNASSIGNED, /* ^F */ @@ -640,11 +650,11 @@ private const el_action_t el_map_vi_command[] = { /* 12 */ ED_CLEAR_SCREEN, /* ^L */ /* 13 */ ED_NEWLINE, /* ^M */ /* 14 */ ED_NEXT_HISTORY, /* ^N */ - /* 15 */ ED_TTY_FLUSH_OUTPUT, /* ^O */ + /* 15 */ ED_IGNORE, /* ^O */ /* 16 */ ED_PREV_HISTORY, /* ^P */ - /* 17 */ ED_TTY_START_OUTPUT, /* ^Q */ + /* 17 */ ED_IGNORE, /* ^Q */ /* 18 */ ED_REDISPLAY, /* ^R */ - /* 19 */ ED_TTY_STOP_OUTPUT, /* ^S */ + /* 19 */ ED_IGNORE, /* ^S */ /* 20 */ ED_UNASSIGNED, /* ^T */ /* 21 */ VI_KILL_LINE_PREV, /* ^U */ /* 22 */ ED_UNASSIGNED, /* ^V */ @@ -653,7 +663,7 @@ private const el_action_t el_map_vi_command[] = { /* 25 */ ED_UNASSIGNED, /* ^Y */ /* 26 */ ED_UNASSIGNED, /* ^Z */ /* 27 */ EM_META_NEXT, /* ^[ */ - /* 28 */ ED_TTY_SIGQUIT, /* ^\ */ + /* 28 */ ED_IGNORE, /* ^\ */ /* 29 */ ED_UNASSIGNED, /* ^] */ /* 30 */ ED_UNASSIGNED, /* ^^ */ /* 31 */ ED_UNASSIGNED, /* ^_ */ @@ -887,7 +897,7 @@ private const el_action_t el_map_vi_command[] = { /* map_init(): * Initialize and allocate the maps */ -protected int +libedit_private int map_init(EditLine *el) { @@ -915,12 +925,12 @@ map_init(EditLine *el) el->el_map.help = el_malloc(sizeof(*el->el_map.help) * EL_NUM_FCNS); if (el->el_map.help == NULL) return -1; - (void) memcpy(el->el_map.help, help__get(), + (void) memcpy(el->el_map.help, el_func_help, sizeof(*el->el_map.help) * EL_NUM_FCNS); el->el_map.func = el_malloc(sizeof(*el->el_map.func) * EL_NUM_FCNS); if (el->el_map.func == NULL) return -1; - memcpy(el->el_map.func, func__get(), sizeof(*el->el_map.func) + memcpy(el->el_map.func, el_func, sizeof(*el->el_map.func) * EL_NUM_FCNS); el->el_map.nfunc = EL_NUM_FCNS; @@ -936,7 +946,7 @@ map_init(EditLine *el) /* map_end(): * Free the space taken by the editor maps */ -protected void +libedit_private void map_end(EditLine *el) { @@ -957,7 +967,7 @@ map_end(EditLine *el) /* map_init_nls(): * Find all the printable keys and bind them to self insert */ -private void +static void map_init_nls(EditLine *el) { int i; @@ -965,7 +975,7 @@ map_init_nls(EditLine *el) el_action_t *map = el->el_map.key; for (i = 0200; i <= 0377; i++) - if (Isprint(i)) + if (iswprint(i)) map[i] = ED_INSERT; } @@ -973,10 +983,10 @@ map_init_nls(EditLine *el) /* map_init_meta(): * Bind all the meta keys to the appropriate ESC- sequence */ -private void +static void map_init_meta(EditLine *el) { - Char buf[3]; + wchar_t buf[3]; int i; el_action_t *map = el->el_map.key; el_action_t *alt = el->el_map.alt; @@ -994,7 +1004,7 @@ map_init_meta(EditLine *el) } else map = alt; } - buf[0] = (Char) i; + buf[0] = (wchar_t)i; buf[2] = 0; for (i = 0200; i <= 0377; i++) switch (map[i]) { @@ -1014,7 +1024,7 @@ map_init_meta(EditLine *el) /* map_init_vi(): * Initialize the vi bindings */ -protected void +libedit_private void map_init_vi(EditLine *el) { int i; @@ -1044,11 +1054,11 @@ map_init_vi(EditLine *el) /* map_init_emacs(): * Initialize the emacs bindings */ -protected void +libedit_private void map_init_emacs(EditLine *el) { int i; - Char buf[3]; + wchar_t buf[3]; el_action_t *key = el->el_map.key; el_action_t *alt = el->el_map.alt; const el_action_t *emacs = el->el_map.emacs; @@ -1078,15 +1088,15 @@ map_init_emacs(EditLine *el) /* map_set_editor(): * Set the editor */ -protected int -map_set_editor(EditLine *el, Char *editor) +libedit_private int +map_set_editor(EditLine *el, wchar_t *editor) { - if (Strcmp(editor, STR("emacs")) == 0) { + if (wcscmp(editor, L"emacs") == 0) { map_init_emacs(el); return 0; } - if (Strcmp(editor, STR("vi")) == 0) { + if (wcscmp(editor, L"vi") == 0) { map_init_vi(el); return 0; } @@ -1097,18 +1107,18 @@ map_set_editor(EditLine *el, Char *editor) /* map_get_editor(): * Retrieve the editor */ -protected int -map_get_editor(EditLine *el, const Char **editor) +libedit_private int +map_get_editor(EditLine *el, const wchar_t **editor) { if (editor == NULL) return -1; switch (el->el_map.type) { case MAP_EMACS: - *editor = STR("emacs"); + *editor = L"emacs"; return 0; case MAP_VI: - *editor = STR("vi"); + *editor = L"vi"; return 0; } return -1; @@ -1118,8 +1128,8 @@ map_get_editor(EditLine *el, const Char **editor) /* map_print_key(): * Print the function description for 1 key */ -private void -map_print_key(EditLine *el, el_action_t *map, const Char *in) +static void +map_print_key(EditLine *el, el_action_t *map, const wchar_t *in) { char outbuf[EL_BUFSIZ]; el_bindings_t *bp, *ep; @@ -1130,7 +1140,7 @@ map_print_key(EditLine *el, el_action_t *map, const Char *in) for (bp = el->el_map.help; bp < ep; bp++) if (bp->func == map[(unsigned char) *in]) { (void) fprintf(el->el_outfile, - "%s\t->\t" FSTR "\n", outbuf, bp->name); + "%s\t->\t%ls\n", outbuf, bp->name); return; } } else @@ -1141,11 +1151,11 @@ map_print_key(EditLine *el, el_action_t *map, const Char *in) /* map_print_some_keys(): * Print keys from first to last */ -private void -map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last) +static void +map_print_some_keys(EditLine *el, el_action_t *map, wint_t first, wint_t last) { el_bindings_t *bp, *ep; - Char firstbuf[2], lastbuf[2]; + wchar_t firstbuf[2], lastbuf[2]; char unparsbuf[EL_BUFSIZ], extrabuf[EL_BUFSIZ]; firstbuf[0] = first; @@ -1154,7 +1164,7 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last) lastbuf[1] = 0; if (map[first] == ED_UNASSIGNED) { if (first == last) { - (void) keymacro__decode_str(firstbuf, unparsbuf, + (void) keymacro__decode_str(firstbuf, unparsbuf, sizeof(unparsbuf), STRQQ); (void) fprintf(el->el_outfile, "%-15s-> is undefined\n", unparsbuf); @@ -1165,17 +1175,17 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last) for (bp = el->el_map.help; bp < ep; bp++) { if (bp->func == map[first]) { if (first == last) { - (void) keymacro__decode_str(firstbuf, unparsbuf, + (void) keymacro__decode_str(firstbuf, unparsbuf, sizeof(unparsbuf), STRQQ); - (void) fprintf(el->el_outfile, "%-15s-> " FSTR "\n", + (void) fprintf(el->el_outfile, "%-15s-> %ls\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", + "%-4s to %-7s-> %ls\n", unparsbuf, extrabuf, bp->name); } return; @@ -1183,14 +1193,14 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last) } #ifdef MAP_DEBUG if (map == el->el_map.key) { - (void) 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); @@ -1205,7 +1215,7 @@ map_print_some_keys(EditLine *el, el_action_t *map, Int first, Int last) /* map_print_all_keys(): * Print the function description for all keys. */ -private void +static void map_print_all_keys(EditLine *el) { int prev, i; @@ -1231,25 +1241,25 @@ map_print_all_keys(EditLine *el) map_print_some_keys(el, el->el_map.alt, prev, i - 1); (void) fprintf(el->el_outfile, "Multi-character bindings\n"); - keymacro_print(el, STR("")); + keymacro_print(el, L""); (void) fprintf(el->el_outfile, "Arrow key bindings\n"); - terminal_print_arrow(el, STR("")); + terminal_print_arrow(el, L""); } /* map_bind(): * Add/remove/change bindings */ -protected int -map_bind(EditLine *el, int argc, const Char **argv) +libedit_private int +map_bind(EditLine *el, int argc, const wchar_t **argv) { el_action_t *map; int ntype, rem; - const Char *p; - Char inbuf[EL_BUFSIZ]; - Char outbuf[EL_BUFSIZ]; - const Char *in = NULL; - Char *out; + const wchar_t *p; + wchar_t inbuf[EL_BUFSIZ]; + wchar_t outbuf[EL_BUFSIZ]; + const wchar_t *in = NULL; + wchar_t *out; el_bindings_t *bp, *ep; int cmd; int key; @@ -1270,11 +1280,6 @@ map_bind(EditLine *el, int argc, const Char **argv) case 's': ntype = XK_STR; break; -#ifdef notyet - case 'c': - ntype = XK_EXE; - break; -#endif case 'k': key = 1; break; @@ -1295,13 +1300,13 @@ map_bind(EditLine *el, int argc, const Char **argv) ep = &el->el_map.help[el->el_map.nfunc]; for (bp = el->el_map.help; bp < ep; bp++) (void) fprintf(el->el_outfile, - "" FSTR "\n\t" FSTR "\n", + "%ls\n\t%ls\n", bp->name, bp->description); return 0; default: (void) fprintf(el->el_errfile, - "" FSTR ": Invalid switch `%c'.\n", - argv[0], p[1]); + "%ls: Invalid switch `%lc'.\n", + argv[0], (wint_t)p[1]); } else break; @@ -1314,7 +1319,7 @@ map_bind(EditLine *el, int argc, const Char **argv) in = argv[argc++]; else if ((in = parse__string(inbuf, argv[argc++])) == NULL) { (void) fprintf(el->el_errfile, - "" FSTR ": Invalid \\ or ^ in instring.\n", + "%ls: Invalid \\ or ^ in instring.\n", argv[0]); return -1; } @@ -1347,10 +1352,9 @@ map_bind(EditLine *el, int argc, const Char **argv) switch (ntype) { case XK_STR: - case XK_EXE: if ((out = parse__string(outbuf, argv[argc])) == NULL) { (void) fprintf(el->el_errfile, - "" FSTR ": Invalid \\ or ^ in outstring.\n", argv[0]); + "%ls: Invalid \\ or ^ in outstring.\n", argv[0]); return -1; } if (key) @@ -1363,7 +1367,7 @@ map_bind(EditLine *el, int argc, const Char **argv) case XK_CMD: if ((cmd = parse_cmd(el, argv[argc])) == -1) { (void) fprintf(el->el_errfile, - "" FSTR ": Invalid command `" FSTR "'.\n", + "%ls: Invalid command `%ls'.\n", argv[0], argv[argc]); return -1; } @@ -1392,8 +1396,9 @@ map_bind(EditLine *el, int argc, const Char **argv) /* map_addfunc(): * add a user defined function */ -protected int -map_addfunc(EditLine *el, const Char *name, const Char *help, el_func_t func) +libedit_private int +map_addfunc(EditLine *el, const wchar_t *name, const wchar_t *help, + el_func_t func) { void *p; size_t nf = el->el_map.nfunc + 1; diff --git a/contrib/libedit/src/map.h b/contrib/libedit/src/map.h index f01b58b818..b4e4e2899a 100644 --- a/contrib/libedit/src/map.h +++ b/contrib/libedit/src/map.h @@ -1,4 +1,4 @@ -/* $NetBSD: map.h,v 1.10 2014/07/06 18:15:34 christos Exp $ */ +/* $NetBSD: map.h,v 1.13 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,13 +40,14 @@ #ifndef _h_el_map #define _h_el_map +typedef el_action_t (*el_func_t)(EditLine *, wint_t); + typedef struct el_bindings_t { /* for the "bind" shell command */ - const Char *name; /* function name for bind command */ + const wchar_t *name; /* function name for bind command */ int func; /* function numeric value */ - const Char *description; /* description of function */ + const wchar_t *description; /* description of function */ } el_bindings_t; - typedef struct el_map_t { el_action_t *alt; /* The current alternate key map */ el_action_t *key; /* The current normal key map */ @@ -65,13 +66,14 @@ typedef struct el_map_t { #define N_KEYS 256 -protected int map_bind(EditLine *, int, const Char **); -protected int map_init(EditLine *); -protected void map_end(EditLine *); -protected void map_init_vi(EditLine *); -protected void map_init_emacs(EditLine *); -protected int map_set_editor(EditLine *, Char *); -protected int map_get_editor(EditLine *, const Char **); -protected int map_addfunc(EditLine *, const Char *, const Char *, el_func_t); +libedit_private int map_bind(EditLine *, int, const wchar_t **); +libedit_private int map_init(EditLine *); +libedit_private void map_end(EditLine *); +libedit_private void map_init_vi(EditLine *); +libedit_private void map_init_emacs(EditLine *); +libedit_private int map_set_editor(EditLine *, wchar_t *); +libedit_private int map_get_editor(EditLine *, const wchar_t **); +libedit_private int map_addfunc(EditLine *, const wchar_t *, const wchar_t *, + el_func_t); #endif /* _h_el_map */ diff --git a/contrib/libedit/src/parse.c b/contrib/libedit/src/parse.c index 47d6f7d9b9..fdd0d847a7 100644 --- a/contrib/libedit/src/parse.c +++ b/contrib/libedit/src/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.27 2014/07/06 18:15:34 christos Exp $ */ +/* $NetBSD: parse.c,v 1.40 2016/05/09 21:46:56 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.27 2014/07/06 18:15:34 christos Exp $"); +__RCSID("$NetBSD: parse.c,v 1.40 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -54,38 +54,41 @@ __RCSID("$NetBSD: parse.c,v 1.27 2014/07/06 18:15:34 christos Exp $"); * settc * setty */ -#include "el.h" #include +#include + +#include "el.h" +#include "parse.h" -private const struct { - const Char *name; - int (*func)(EditLine *, int, const Char **); +static const struct { + const wchar_t *name; + int (*func)(EditLine *, int, const wchar_t **); } cmds[] = { - { STR("bind"), map_bind }, - { STR("echotc"), terminal_echotc }, - { STR("edit"), el_editmode }, - { STR("history"), hist_command }, - { STR("telltc"), terminal_telltc }, - { STR("settc"), terminal_settc }, - { STR("setty"), tty_stty }, - { NULL, NULL } + { L"bind", map_bind }, + { L"echotc", terminal_echotc }, + { L"edit", el_editmode }, + { L"history", hist_command }, + { L"telltc", terminal_telltc }, + { L"settc", terminal_settc }, + { L"setty", tty_stty }, + { NULL, NULL } }; /* parse_line(): * Parse a line and dispatch it */ -protected int -parse_line(EditLine *el, const Char *line) +libedit_private int +parse_line(EditLine *el, const wchar_t *line) { - const Char **argv; + const wchar_t **argv; int argc; - TYPE(Tokenizer) *tok; + TokenizerW *tok; - tok = FUN(tok,init)(NULL); - FUN(tok,str)(tok, line, &argc, &argv); - argc = FUN(el,parse)(el, argc, argv); - FUN(tok,end)(tok); + tok = tok_winit(NULL); + tok_wstr(tok, line, &argc, &argv); + argc = el_wparse(el, argc, argv); + tok_wend(tok); return argc; } @@ -93,17 +96,17 @@ parse_line(EditLine *el, const Char *line) /* el_parse(): * Command dispatcher */ -public int -FUN(el,parse)(EditLine *el, int argc, const Char *argv[]) +int +el_wparse(EditLine *el, int argc, const wchar_t *argv[]) { - const Char *ptr; + const wchar_t *ptr; int i; if (argc < 1) return -1; - ptr = Strchr(argv[0], ':'); + ptr = wcschr(argv[0], L':'); if (ptr != NULL) { - Char *tprog; + wchar_t *tprog; size_t l; if (ptr == argv[0]) @@ -112,7 +115,7 @@ FUN(el,parse)(EditLine *el, int argc, const Char *argv[]) tprog = el_malloc((l + 1) * sizeof(*tprog)); if (tprog == NULL) return 0; - (void) Strncpy(tprog, argv[0], l); + (void) wcsncpy(tprog, argv[0], l); tprog[l] = '\0'; ptr++; l = (size_t)el_match(el->el_prog, tprog); @@ -123,7 +126,7 @@ FUN(el,parse)(EditLine *el, int argc, const Char *argv[]) ptr = argv[0]; for (i = 0; cmds[i].name != NULL; i++) - if (Strcmp(cmds[i].name, ptr) == 0) { + if (wcscmp(cmds[i].name, ptr) == 0) { i = (*cmds[i].func) (el, argc, argv); return -i; } @@ -135,11 +138,11 @@ FUN(el,parse)(EditLine *el, int argc, const Char *argv[]) * Parse a string of the form ^ \ \ \U+xxxx and return * the appropriate character or -1 if the escape is not valid */ -protected int -parse__escape(const Char **ptr) +libedit_private int +parse__escape(const wchar_t **ptr) { - const Char *p; - Int c; + const wchar_t *p; + wint_t c; p = *ptr; @@ -173,28 +176,28 @@ parse__escape(const Char **ptr) case 'e': c = '\033'; /* Escape */ break; - case 'U': /* Unicode \U+xxxx or \U+xxxxx format */ - { - int i; - const Char hex[] = STR("0123456789ABCDEF"); - const Char *h; - ++p; - if (*p++ != '+') - return -1; + case 'U': /* Unicode \U+xxxx or \U+xxxxx format */ + { + int i; + const wchar_t hex[] = L"0123456789ABCDEF"; + const wchar_t *h; + ++p; + if (*p++ != '+') + return -1; c = 0; - for (i = 0; i < 5; ++i) { - h = Strchr(hex, *p++); - if (!h && i < 4) - return -1; - else if (h) - c = (c << 4) | ((int)(h - hex)); - else - --p; - } - if (c > 0x10FFFF) /* outside valid character range */ - return -1; - break; - } + for (i = 0; i < 5; ++i) { + h = wcschr(hex, *p++); + if (!h && i < 4) + return -1; + else if (h) + c = (c << 4) | ((int)(h - hex)); + else + --p; + } + if (c > 0x10FFFF) /* outside valid character range */ + return -1; + break; + } case '0': case '1': case '2': @@ -235,10 +238,10 @@ parse__escape(const Char **ptr) /* parse__string(): * Parse the escapes from in and put the raw string out */ -protected Char * -parse__string(Char *out, const Char *in) +libedit_private wchar_t * +parse__string(wchar_t *out, const wchar_t *in) { - Char *rv = out; + wchar_t *rv = out; int n; for (;;) @@ -251,7 +254,7 @@ parse__string(Char *out, const Char *in) case '^': if ((n = parse__escape(&in)) == -1) return NULL; - *out++ = n; + *out++ = (wchar_t)n; break; case 'M': @@ -273,14 +276,14 @@ parse__string(Char *out, const Char *in) * Return the command number for the command string given * or -1 if one is not found */ -protected int -parse_cmd(EditLine *el, const Char *cmd) +libedit_private int +parse_cmd(EditLine *el, const wchar_t *cmd) { el_bindings_t *b = el->el_map.help; size_t i; for (i = 0; i < el->el_map.nfunc; i++) - if (Strcmp(b[i].name, cmd) == 0) + if (wcscmp(b[i].name, cmd) == 0) return b[i].func; return -1; } diff --git a/contrib/libedit/src/parse.h b/contrib/libedit/src/parse.h index ec04051bc2..fe8eb47335 100644 --- a/contrib/libedit/src/parse.h +++ b/contrib/libedit/src/parse.h @@ -1,4 +1,4 @@ -/* $NetBSD: parse.h,v 1.7 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: parse.h,v 1.9 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,9 +40,9 @@ #ifndef _h_el_parse #define _h_el_parse -protected int parse_line(EditLine *, const Char *); -protected int parse__escape(const Char **); -protected Char *parse__string(Char *, const Char *); -protected int parse_cmd(EditLine *, const Char *); +libedit_private int parse_line(EditLine *, const wchar_t *); +libedit_private int parse__escape(const wchar_t **); +libedit_private wchar_t *parse__string(wchar_t *, const wchar_t *); +libedit_private int parse_cmd(EditLine *, const wchar_t *); #endif /* _h_el_parse */ diff --git a/contrib/libedit/src/prompt.c b/contrib/libedit/src/prompt.c index 48b2d27f87..a3d9915ec0 100644 --- a/contrib/libedit/src/prompt.c +++ b/contrib/libedit/src/prompt.c @@ -1,4 +1,4 @@ -/* $NetBSD: prompt.c,v 1.20 2011/07/29 15:16:33 christos Exp $ */ +/* $NetBSD: prompt.c,v 1.26 2016/05/09 21:46:56 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.20 2011/07/29 15:16:33 christos Exp $"); +__RCSID("$NetBSD: prompt.c,v 1.26 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -47,17 +47,17 @@ __RCSID("$NetBSD: prompt.c,v 1.20 2011/07/29 15:16:33 christos Exp $"); #include #include "el.h" -private Char *prompt_default(EditLine *); -private Char *prompt_default_r(EditLine *); +static wchar_t *prompt_default(EditLine *); +static wchar_t *prompt_default_r(EditLine *); /* prompt_default(): * Just a default prompt, in case the user did not provide one */ -private Char * +static wchar_t * /*ARGSUSED*/ prompt_default(EditLine *el __attribute__((__unused__))) { - static Char a[3] = {'?', ' ', '\0'}; + static wchar_t a[3] = L"? "; return a; } @@ -66,11 +66,11 @@ prompt_default(EditLine *el __attribute__((__unused__))) /* prompt_default_r(): * Just a default rprompt, in case the user did not provide one */ -private Char * +static wchar_t * /*ARGSUSED*/ prompt_default_r(EditLine *el __attribute__((__unused__))) { - static Char a[1] = {'\0'}; + static wchar_t a[1] = L""; return a; } @@ -79,11 +79,11 @@ prompt_default_r(EditLine *el __attribute__((__unused__))) /* prompt_print(): * Print the prompt and update the prompt position. */ -protected void +libedit_private void prompt_print(EditLine *el, int op) { el_prompt_t *elp; - Char *p; + wchar_t *p; int ignore = 0; if (op == EL_PROMPT) @@ -116,7 +116,7 @@ prompt_print(EditLine *el, int op) /* prompt_init(): * Initialize the prompt stuff */ -protected int +libedit_private int prompt_init(EditLine *el) { @@ -135,7 +135,7 @@ prompt_init(EditLine *el) /* prompt_end(): * Clean up the prompt stuff */ -protected void +libedit_private void /*ARGSUSED*/ prompt_end(EditLine *el __attribute__((__unused__))) { @@ -145,8 +145,8 @@ prompt_end(EditLine *el __attribute__((__unused__))) /* prompt_set(): * Install a prompt printing function */ -protected int -prompt_set(EditLine *el, el_pfunc_t prf, Char c, int op, int wide) +libedit_private int +prompt_set(EditLine *el, el_pfunc_t prf, wchar_t c, int op, int wide) { el_prompt_t *p; @@ -177,8 +177,8 @@ prompt_set(EditLine *el, el_pfunc_t prf, Char c, int op, int wide) /* prompt_get(): * Retrieve the prompt printing function */ -protected int -prompt_get(EditLine *el, el_pfunc_t *prf, Char *c, int op) +libedit_private int +prompt_get(EditLine *el, el_pfunc_t *prf, wchar_t *c, int op) { el_prompt_t *p; diff --git a/contrib/libedit/src/prompt.h b/contrib/libedit/src/prompt.h index af63b82b68..2931428dbb 100644 --- a/contrib/libedit/src/prompt.h +++ b/contrib/libedit/src/prompt.h @@ -1,4 +1,4 @@ -/* $NetBSD: prompt.h,v 1.10 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: prompt.h,v 1.15 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,21 +40,19 @@ #ifndef _h_el_prompt #define _h_el_prompt -#include "histedit.h" - -typedef Char *(*el_pfunc_t)(EditLine *); +typedef wchar_t *(*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; + wchar_t p_ignore; /* character to start/end literal */ + int p_wide; } el_prompt_t; -protected void prompt_print(EditLine *, int); -protected int prompt_set(EditLine *, el_pfunc_t, Char, int, int); -protected int prompt_get(EditLine *, el_pfunc_t *, Char *, int); -protected int prompt_init(EditLine *); -protected void prompt_end(EditLine *); +libedit_private void prompt_print(EditLine *, int); +libedit_private int prompt_set(EditLine *, el_pfunc_t, wchar_t, int, int); +libedit_private int prompt_get(EditLine *, el_pfunc_t *, wchar_t *, int); +libedit_private int prompt_init(EditLine *); +libedit_private void prompt_end(EditLine *); #endif /* _h_el_prompt */ diff --git a/contrib/libedit/src/read.c b/contrib/libedit/src/read.c index b81cff609f..ec10be789f 100644 --- a/contrib/libedit/src/read.c +++ b/contrib/libedit/src/read.c @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.71 2014/07/06 18:15:34 christos Exp $ */ +/* $NetBSD: read.c,v 1.102 2016/12/11 15:47:06 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,49 +37,91 @@ #if 0 static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: read.c,v 1.71 2014/07/06 18:15:34 christos Exp $"); +__RCSID("$NetBSD: read.c,v 1.102 2016/12/11 15:47:06 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* - * read.c: Clean this junk up! This is horrible code. - * Terminal read functions + * read.c: Terminal read functions */ +#include #include #include -#include -#include #include -#include "el.h" - -#define OKCMD -1 /* must be -1! */ +#include +#include +#include -private int read__fixio(int, int); -private int read_preread(EditLine *); -private int read_char(EditLine *, Char *); -private int read_getcmd(EditLine *, el_action_t *, Char *); -private void read_pop(c_macro_t *); +#include "el.h" +#include "fcns.h" +#include "read.h" + +#define EL_MAXMACRO 10 + +struct macros { + wchar_t **macro; + int level; + int offset; +}; + +struct el_read_t { + struct macros macros; + el_rfunc_t read_char; /* Function to read a character. */ + int read_errno; +}; + +static int read__fixio(int, int); +static int read_char(EditLine *, wchar_t *); +static int read_getcmd(EditLine *, el_action_t *, wchar_t *); +static void read_clearmacros(struct macros *); +static void read_pop(struct macros *); +static const wchar_t *noedit_wgets(EditLine *, int *); /* read_init(): * Initialize the read stuff */ -protected int +libedit_private int read_init(EditLine *el) { + struct macros *ma; + + if ((el->el_read = el_malloc(sizeof(*el->el_read))) == NULL) + return -1; + + ma = &el->el_read->macros; + if ((ma->macro = el_malloc(EL_MAXMACRO * + sizeof(*ma->macro))) == NULL) { + free(el->el_read); + return -1; + } + ma->level = -1; + ma->offset = 0; + /* builtin read_char */ - el->el_read.read_char = read_char; + el->el_read->read_char = read_char; return 0; } +/* el_read_end(): + * Free the data structures used by the read stuff. + */ +libedit_private void +read_end(struct el_read_t *el_read) +{ + read_clearmacros(&el_read->macros); + el_free(el_read->macros.macro); + el_read->macros.macro = NULL; + el_free(el_read); +} /* el_read_setfn(): * Set the read char function to the one provided. * If it is set to EL_BUILTIN_GETCFN, then reset to the builtin one. */ -protected int -el_read_setfn(EditLine *el, el_rfunc_t rc) +libedit_private int +el_read_setfn(struct el_read_t *el_read, el_rfunc_t rc) { - el->el_read.read_char = (rc == EL_BUILTIN_GETCFN) ? read_char : rc; + el_read->read_char = (rc == EL_BUILTIN_GETCFN) ? read_char : rc; return 0; } @@ -88,42 +130,19 @@ el_read_setfn(EditLine *el, el_rfunc_t rc) * return the current read char function, or EL_BUILTIN_GETCFN * if it is the default one */ -protected el_rfunc_t -el_read_getfn(EditLine *el) +libedit_private el_rfunc_t +el_read_getfn(struct el_read_t *el_read) { - return el->el_read.read_char == read_char ? - EL_BUILTIN_GETCFN : el->el_read.read_char; + return el_read->read_char == read_char ? + EL_BUILTIN_GETCFN : el_read->read_char; } -#ifndef MIN -#define MIN(A,B) ((A) < (B) ? (A) : (B)) -#endif - -#ifdef DEBUG_EDIT -private void -read_debug(EditLine *el) -{ - - if (el->el_line.cursor > el->el_line.lastchar) - (void) fprintf(el->el_errfile, "cursor > lastchar\r\n"); - if (el->el_line.cursor < el->el_line.buffer) - (void) fprintf(el->el_errfile, "cursor < buffer\r\n"); - if (el->el_line.cursor > el->el_line.limit) - (void) fprintf(el->el_errfile, "cursor > limit\r\n"); - if (el->el_line.lastchar > el->el_line.limit) - (void) fprintf(el->el_errfile, "lastchar > limit\r\n"); - if (el->el_line.limit != &el->el_line.buffer[EL_BUFSIZ - 2]) - (void) fprintf(el->el_errfile, "limit != &buffer[EL_BUFSIZ-2]\r\n"); -} -#endif /* DEBUG_EDIT */ - - /* read__fixio(): * Try to recover from a read error */ /* ARGSUSED */ -private int +static int read__fixio(int fd __attribute__((__unused__)), int e) { @@ -181,49 +200,17 @@ read__fixio(int fd __attribute__((__unused__)), int e) } -/* read_preread(): - * Try to read the stuff in the input queue; - */ -private int -read_preread(EditLine *el) -{ - int chrs = 0; - - if (el->el_tty.t_mode == ED_IO) - return 0; - -#ifndef WIDECHAR -/* FIONREAD attempts to buffer up multiple bytes, and to make that work - * properly with partial wide/UTF-8 characters would need some careful work. */ -#ifdef FIONREAD - (void) ioctl(el->el_infd, FIONREAD, &chrs); - if (chrs > 0) { - char buf[EL_BUFSIZ]; - - chrs = read(el->el_infd, buf, - (size_t) MIN(chrs, EL_BUFSIZ - 1)); - if (chrs > 0) { - buf[chrs] = '\0'; - el_push(el, buf); - } - } -#endif /* FIONREAD */ -#endif - return chrs > 0; -} - - /* el_push(): * Push a macro */ -public void -FUN(el,push)(EditLine *el, const Char *str) +void +el_wpush(EditLine *el, const wchar_t *str) { - c_macro_t *ma = &el->el_chared.c_macro; + struct macros *ma = &el->el_read->macros; if (str != NULL && ma->level + 1 < EL_MAXMACRO) { ma->level++; - if ((ma->macro[ma->level] = Strdup(str)) != NULL) + if ((ma->macro[ma->level] = wcsdup(str)) != NULL) return; ma->level--; } @@ -233,24 +220,23 @@ FUN(el,push)(EditLine *el, const Char *str) /* read_getcmd(): - * Get next command from the input stream, return OKCMD on success. + * Get next command from the input stream, + * return 0 on success or -1 on EOF or error. * Character values > 255 are not looked up in the map, but inserted. */ -private int -read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch) +static int +read_getcmd(EditLine *el, el_action_t *cmdnum, wchar_t *ch) { + static const wchar_t meta = (wchar_t)0x80; el_action_t cmd; int num; - el->el_errno = 0; do { - if ((num = FUN(el,getc)(el, ch)) != 1) {/* if EOF or error */ - el->el_errno = num == 0 ? 0 : errno; - return 0; /* not OKCMD */ - } + if ((num = el_wgetc(el, ch)) != 1) + return -1; #ifdef KANJI - if ((*ch & 0200)) { + if ((*ch & meta)) { el->el_state.metanext = 0; cmd = CcViMap[' ']; break; @@ -259,13 +245,11 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch) if (el->el_state.metanext) { el->el_state.metanext = 0; - *ch |= 0200; + *ch |= meta; } -#ifdef WIDECHAR if (*ch >= N_KEYS) cmd = ED_INSERT; else -#endif cmd = el->el_map.current[(unsigned char) *ch]; if (cmd == ED_SEQUENCE_LEAD_IN) { keymacro_value_t val; @@ -274,49 +258,31 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch) cmd = val.cmd; break; case XK_STR: - FUN(el,push)(el, val.str); + el_wpush(el, val.str); break; -#ifdef notyet - case XK_EXE: - /* XXX: In the future to run a user function */ - RunCommand(val.str); - break; -#endif + case XK_NOD: + return -1; default: EL_ABORT((el->el_errfile, "Bad XK_ type \n")); break; } } - if (el->el_map.alt == NULL) - el->el_map.current = el->el_map.key; } while (cmd == ED_SEQUENCE_LEAD_IN); *cmdnum = cmd; - 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 */ + return 0; } -#endif /* read_char(): * Read a character from the tty. */ -private int -read_char(EditLine *el, Char *cp) +static int +read_char(EditLine *el, wchar_t *cp) { ssize_t num_read; int tried = 0; char cbuf[MB_LEN_MAX]; size_t cbp = 0; - int bytes = 0; + int save_errno = errno; again: el->el_signal->sig_no = 0; @@ -324,7 +290,7 @@ read_char(EditLine *el, Char *cp) int e = errno; switch (el->el_signal->sig_no) { case SIGCONT: - FUN(el,set)(el, EL_REFRESH); + el_wset(el, EL_REFRESH); /*FALLTHROUGH*/ case SIGWINCH: sig_set(el); @@ -332,57 +298,69 @@ read_char(EditLine *el, Char *cp) default: break; } - if (!tried && read__fixio(el->el_infd, e) == 0) + if (!tried && read__fixio(el->el_infd, e) == 0) { + errno = save_errno; tried = 1; - else { + } else { errno = e; - *cp = '\0'; + *cp = L'\0'; return -1; } } /* Test for EOF */ if (num_read == 0) { - errno = 0; - *cp = '\0'; + *cp = L'\0'; return 0; } -#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 */ + for (;;) { + mbstate_t mbs; + ++cbp; - if ((bytes = ct_mbtowc(cp, cbuf, cbp)) == -1) { - ct_mbtowc_reset; - if (cbp >= MB_LEN_MAX) { /* "shouldn't happen" */ + /* This only works because UTF8 is stateless. */ + memset(&mbs, 0, sizeof(mbs)); + switch (mbrtowc(cp, cbuf, cbp, &mbs)) { + 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) { errno = EILSEQ; - *cp = '\0'; + *cp = L'\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(): * Pop a macro from the stack */ -private void -read_pop(c_macro_t *ma) +static void +read_pop(struct macros *ma) { int i; @@ -393,22 +371,25 @@ read_pop(c_macro_t *ma) ma->offset = 0; } -/* el_getc(): - * Read a character +static void +read_clearmacros(struct macros *ma) +{ + while (ma->level >= 0) + el_free(ma->macro[ma->level--]); + ma->offset = 0; +} + +/* el_wgetc(): + * Read a wide character */ -public int -FUN(el,getc)(EditLine *el, Char *cp) +int +el_wgetc(EditLine *el, wchar_t *cp) { + struct macros *ma = &el->el_read->macros; int num_read; - c_macro_t *ma = &el->el_chared.c_macro; terminal__flush(el); for (;;) { - if (ma->level < 0) { - if (!read_preread(el)) - break; - } - if (ma->level < 0) break; @@ -427,29 +408,23 @@ FUN(el,getc)(EditLine *el, Char *cp) return 1; } -#ifdef DEBUG_READ - (void) fprintf(el->el_errfile, "Turning raw mode on\n"); -#endif /* DEBUG_READ */ if (tty_rawmode(el) < 0)/* make sure the tty is set up correctly */ return 0; -#ifdef DEBUG_READ - (void) fprintf(el->el_errfile, "Reading a character\n"); -#endif /* DEBUG_READ */ - num_read = (*el->el_read.read_char)(el, cp); + num_read = (*el->el_read->read_char)(el, cp); + + /* + * Remember the original reason of a read failure + * such that el_wgets() can restore it after doing + * various cleanup operation that might change errno. + */ 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 %c\n", *cp); -#endif /* DEBUG_READ */ + el->el_read->read_errno = errno; + return num_read; } -protected void +libedit_private void read_prepare(EditLine *el) { if (el->el_flags & HANDLE_SIGNALS) @@ -463,14 +438,14 @@ read_prepare(EditLine *el) we have the wrong size. */ el_resize(el); re_clear_display(el); /* reset the display stuff */ - ch_reset(el, 0); + ch_reset(el); re_refresh(el); /* print the prompt */ if (el->el_flags & UNBUFFERED) terminal__flush(el); } -protected void +libedit_private void read_finish(EditLine *el) { if ((el->el_flags & UNBUFFERED) == 0) @@ -479,54 +454,52 @@ read_finish(EditLine *el) sig_clr(el); } -public const Char * -FUN(el,gets)(EditLine *el, int *nread) +static const wchar_t * +noedit_wgets(EditLine *el, int *nread) +{ + el_line_t *lp = &el->el_line; + int num; + + while ((num = (*el->el_read->read_char)(el, lp->lastchar)) == 1) { + if (lp->lastchar + 1 >= lp->limit && + !ch_enlargebufs(el, (size_t)2)) + break; + lp->lastchar++; + if (el->el_flags & UNBUFFERED || + lp->lastchar[-1] == '\r' || + lp->lastchar[-1] == '\n') + break; + } + if (num == -1 && errno == EINTR) + lp->lastchar = lp->buffer; + lp->cursor = lp->lastchar; + *lp->lastchar = '\0'; + *nread = (int)(lp->lastchar - lp->buffer); + return *nread ? lp->buffer : NULL; +} + +const wchar_t * +el_wgets(EditLine *el, int *nread) { int retval; el_action_t cmdnum = 0; int num; /* how many chars we have read at NL */ - Char ch, *cp; - int crlf = 0; + wchar_t ch; int nrb; -#ifdef FIONREAD - c_macro_t *ma = &el->el_chared.c_macro; -#endif /* FIONREAD */ if (nread == NULL) nread = &nrb; *nread = 0; + el->el_read->read_errno = 0; if (el->el_flags & NO_TTY) { - size_t idx; - - cp = el->el_line.buffer; - while ((num = (*el->el_read.read_char)(el, cp)) == 1) { - /* make sure there is space for next character */ - if (cp + 1 >= el->el_line.limit) { - idx = (size_t)(cp - el->el_line.buffer); - if (!ch_enlargebufs(el, (size_t)2)) - break; - cp = &el->el_line.buffer[idx]; - } - cp++; - if (el->el_flags & UNBUFFERED) - break; - if (cp[-1] == '\r' || cp[-1] == '\n') - break; - } - if (num == -1) { - if (errno == EINTR) - cp = el->el_line.buffer; - el->el_errno = errno; - } - - goto noedit; + el->el_line.lastchar = el->el_line.buffer; + return noedit_wgets(el, nread); } - #ifdef FIONREAD - if (el->el_tty.t_mode == EX_IO && ma->level < 0) { - long chrs = 0; + if (el->el_tty.t_mode == EX_IO && el->el_read->macros.level < 0) { + int chrs = 0; (void) ioctl(el->el_infd, FIONREAD, &chrs); if (chrs == 0) { @@ -543,82 +516,19 @@ FUN(el,gets)(EditLine *el, int *nread) read_prepare(el); if (el->el_flags & EDIT_DISABLED) { - size_t idx; - if ((el->el_flags & UNBUFFERED) == 0) - cp = el->el_line.buffer; - else - cp = el->el_line.lastchar; - + el->el_line.lastchar = el->el_line.buffer; terminal__flush(el); - - while ((num = (*el->el_read.read_char)(el, cp)) == 1) { - /* make sure there is space next character */ - if (cp + 1 >= el->el_line.limit) { - idx = (size_t)(cp - el->el_line.buffer); - if (!ch_enlargebufs(el, (size_t)2)) - break; - cp = &el->el_line.buffer[idx]; - } - cp++; - crlf = cp[-1] == '\r' || cp[-1] == '\n'; - if (el->el_flags & UNBUFFERED) - break; - if (crlf) - break; - } - - if (num == -1) { - if (errno == EINTR) - cp = el->el_line.buffer; - el->el_errno = errno; - } - - goto noedit; + return noedit_wgets(el, nread); } - for (num = OKCMD; num == OKCMD;) { /* while still editing this - * line */ -#ifdef DEBUG_EDIT - read_debug(el); -#endif /* DEBUG_EDIT */ + for (num = -1; num == -1;) { /* while still editing this line */ /* if EOF or error */ - if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) { - num = -1; -#ifdef DEBUG_READ - (void) fprintf(el->el_errfile, - "Returning from el_gets %d\n", num); -#endif /* DEBUG_READ */ + if (read_getcmd(el, &cmdnum, &ch) == -1) break; - } - if (el->el_errno == EINTR) { - el->el_line.buffer[0] = '\0'; - el->el_line.lastchar = - el->el_line.cursor = el->el_line.buffer; - break; - } - if ((size_t)cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */ -#ifdef DEBUG_EDIT - (void) fprintf(el->el_errfile, - "ERROR: illegal command from key 0%o\r\n", ch); -#endif /* DEBUG_EDIT */ + if ((size_t)cmdnum >= el->el_map.nfunc) /* BUG CHECK command */ continue; /* try again */ - } /* now do the real command */ -#ifdef DEBUG_READ - { - el_bindings_t *b; - for (b = el->el_map.help; b->name; b++) - if (b->func == cmdnum) - break; - if (b->name) - (void) fprintf(el->el_errfile, - "Executing %s\n", b->name); - else - (void) fprintf(el->el_errfile, - "Error command = %d\n", cmdnum); - } -#endif /* DEBUG_READ */ /* vi redo needs these way down the levels... */ el->el_state.thiscmd = cmdnum; el->el_state.thisch = ch; @@ -627,16 +537,12 @@ FUN(el,gets)(EditLine *el, int *nread) el->el_chared.c_redo.pos < el->el_chared.c_redo.lim) { if (cmdnum == VI_DELETE_PREV_CHAR && el->el_chared.c_redo.pos != el->el_chared.c_redo.buf - && Isprint(el->el_chared.c_redo.pos[-1])) + && iswprint(el->el_chared.c_redo.pos[-1])) el->el_chared.c_redo.pos--; else *el->el_chared.c_redo.pos++ = ch; } retval = (*el->el_map.func[cmdnum]) (el, ch); -#ifdef DEBUG_READ - (void) fprintf(el->el_errfile, - "Returned state %d\n", retval ); -#endif /* DEBUG_READ */ /* save the last command here */ el->el_state.lastcmd = cmdnum; @@ -683,22 +589,15 @@ FUN(el,gets)(EditLine *el, int *nread) break; case CC_FATAL: /* fatal error, reset to known state */ -#ifdef DEBUG_READ - (void) fprintf(el->el_errfile, - "*** editor fatal ERROR ***\r\n\n"); -#endif /* DEBUG_READ */ /* put (real) cursor in a known place */ re_clear_display(el); /* reset the display stuff */ - ch_reset(el, 1); /* reset the input pointers */ + ch_reset(el); /* reset the input pointers */ + read_clearmacros(&el->el_read->macros); re_refresh(el); /* print the prompt again */ break; case CC_ERROR: default: /* functions we don't know about */ -#ifdef DEBUG_READ - (void) fprintf(el->el_errfile, - "*** editor ERROR ***\r\n\n"); -#endif /* DEBUG_READ */ terminal_beep(el); terminal__flush(el); break; @@ -715,19 +614,14 @@ FUN(el,gets)(EditLine *el, int *nread) if ((el->el_flags & UNBUFFERED) == 0) { read_finish(el); *nread = num != -1 ? num : 0; - } else { + } else *nread = (int)(el->el_line.lastchar - el->el_line.buffer); - } - goto done; -noedit: - el->el_line.cursor = el->el_line.lastchar = cp; - *cp = '\0'; - *nread = (int)(el->el_line.cursor - el->el_line.buffer); -done: + if (*nread == 0) { if (num == -1) { *nread = -1; - errno = el->el_errno; + if (el->el_read->read_errno) + errno = el->el_read->read_errno; } return NULL; } else diff --git a/contrib/libedit/src/read.h b/contrib/libedit/src/read.h index 852606a9c1..1acf5d6763 100644 --- a/contrib/libedit/src/read.h +++ b/contrib/libedit/src/read.h @@ -1,4 +1,4 @@ -/* $NetBSD: read.h,v 1.7 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: read.h,v 1.12 2016/05/22 19:44:26 christos Exp $ */ /*- * Copyright (c) 2001 The NetBSD Foundation, Inc. @@ -35,16 +35,11 @@ #ifndef _h_el_read #define _h_el_read -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 *); -protected int el_read_setfn(EditLine *, el_rfunc_t); -protected el_rfunc_t el_read_getfn(EditLine *); +libedit_private int read_init(EditLine *); +libedit_private void read_end(struct el_read_t *); +libedit_private void read_prepare(EditLine *); +libedit_private void read_finish(EditLine *); +libedit_private int el_read_setfn(struct el_read_t *, el_rfunc_t); +libedit_private el_rfunc_t el_read_getfn(struct el_read_t *); #endif /* _h_el_read */ diff --git a/contrib/libedit/src/readline.c b/contrib/libedit/src/readline.c index e744448e4d..2e0e2c4eaf 100644 --- a/contrib/libedit/src/readline.c +++ b/contrib/libedit/src/readline.c @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.114 2015/03/24 21:29:52 christos Exp $ */ +/* $NetBSD: readline.c,v 1.140 2017/01/09 03:09:05 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,28 +31,28 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: readline.c,v 1.114 2015/03/24 21:29:52 christos Exp $"); +__RCSID("$NetBSD: readline.c,v 1.140 2017/01/09 03:09:05 christos Exp $"); #endif /* not lint && not SCCSID */ #include #include -#include -#include -#include -#include #include -#include -#include -#include +#include #include #include +#include +#include #include +#include +#include +#include +#include +#include #include #include "editline/readline.h" #include "el.h" -#include "fcns.h" /* for EL_NUM_FCNS */ -#include "histedit.h" +#include "fcns.h" #include "filecomplete.h" #if !defined(SIZE_T_MAX) @@ -82,7 +82,7 @@ FILE *rl_outstream = NULL; int rl_point = 0; int rl_end = 0; char *rl_line_buffer = NULL; -VCPFunction *rl_linefunc = NULL; +rl_vcpfunc_t *rl_linefunc = NULL; int rl_done = 0; VFunction *rl_event_hook = NULL; KEYMAP_ENTRY_ARRAY emacs_standard_keymap, @@ -99,6 +99,7 @@ int rl_catch_sigwinch = 1; int history_base = 1; /* probably never subject to change */ int history_length = 0; +int history_offset = 0; int max_input_history = 0; char history_expansion_char = '!'; char history_subst_char = '^'; @@ -111,9 +112,9 @@ int rl_attempted_completion_over = 0; char *rl_basic_word_break_characters = break_chars; char *rl_completer_word_break_characters = NULL; char *rl_completer_quote_characters = NULL; -Function *rl_completion_entry_function = NULL; +rl_compentry_func_t *rl_completion_entry_function = NULL; char *(*rl_completion_word_break_hook)(void) = NULL; -CPPFunction *rl_attempted_completion_function = NULL; +rl_completion_func_t *rl_attempted_completion_function = NULL; Function *rl_pre_input_hook = NULL; Function *rl_startup1_hook = NULL; int (*rl_getc_function)(FILE *) = NULL; @@ -164,22 +165,22 @@ int rl_completion_append_character = ' '; static History *h = NULL; static EditLine *e = NULL; -static Function *map[256]; +static rl_command_func_t *map[256]; static jmp_buf topbuf; /* internal functions */ 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 *, char *); -static HIST_ENTRY *_move_history(int); +static int _getc_function(EditLine *, wchar_t *); 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 *, char *); +static int _rl_event_read_char(EditLine *, wchar_t *); static void _rl_update_pos(void); +static HIST_ENTRY rl_he; /* ARGSUSED */ static char * @@ -190,38 +191,19 @@ _get_prompt(EditLine *el __attribute__((__unused__))) } -/* - * generic function for moving around history - */ -static HIST_ENTRY * -_move_history(int op) -{ - HistEvent ev; - static HIST_ENTRY rl_he; - - if (history(h, &ev, op) != 0) - return NULL; - - rl_he.line = ev.str; - rl_he.data = NULL; - - return &rl_he; -} - - /* * read one key from user defined input function */ static int /*ARGSUSED*/ -_getc_function(EditLine *el __attribute__((__unused__)), char *c) +_getc_function(EditLine *el __attribute__((__unused__)), wchar_t *c) { int i; - i = (*rl_getc_function)(NULL); + i = (*rl_getc_function)(rl_instream); if (i == -1) return 0; - *c = (char)i; + *c = (wchar_t)i; return 1; } @@ -271,7 +253,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); @@ -365,7 +347,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. */ @@ -488,6 +470,7 @@ using_history(void) { if (h == NULL || e == NULL) rl_initialize(); + history_offset = history_length; } @@ -569,7 +552,7 @@ get_history_event(const char *cmd, int *cindex, int qchar) } if ('0' <= cmd[idx] && cmd[idx] <= '9') { - HIST_ENTRY *rl_he; + HIST_ENTRY *he; num = 0; while (cmd[idx] && '0' <= cmd[idx] && cmd[idx] <= '9') { @@ -577,13 +560,13 @@ get_history_event(const char *cmd, int *cindex, int qchar) idx++; } if (sign) - num = history_length - num + 1; + num = history_length - num + history_base; - if (!(rl_he = history_get(num))) + if (!(he = history_get(num))) return NULL; *cindex = idx; - return rl_he->line; + return he->line; } sub = 0; if (cmd[idx] == '?') { @@ -983,7 +966,8 @@ loop: for (; str[j]; j++) { if (str[j] == '\\' && str[j + 1] == history_expansion_char) { - (void)strcpy(&str[j], &str[j + 1]); + len = strlen(&str[j + 1]) + 1; + memmove(&str[j], &str[j + 1], len); continue; } if (!loop_again) { @@ -1171,12 +1155,22 @@ void stifle_history(int max) { HistEvent ev; + HIST_ENTRY *he; if (h == NULL || e == NULL) rl_initialize(); - if (history(h, &ev, H_SETSIZE, max) == 0) + if (history(h, &ev, H_SETSIZE, max) == 0) { max_input_history = max; + if (history_length > max) + history_base = history_length - max; + while (history_length > max) { + he = remove_history(0); + el_free(he->data); + el_free((void *)(unsigned long)he->line); + el_free(he); + } + } } @@ -1391,25 +1385,37 @@ history_get(int num) if (h == NULL || e == NULL) rl_initialize(); + if (num < history_base) + return NULL; + /* save current position */ if (history(h, &ev, H_CURR) != 0) return NULL; curr_num = ev.num; - /* start from the oldest */ - if (history(h, &ev, H_LAST) != 0) - return NULL; /* error */ - - /* look forwards for event matching specified offset */ - if (history(h, &ev, H_NEXT_EVDATA, num, &she.data)) - return NULL; + /* + * use H_DELDATA to set to nth history (without delete) by passing + * (void **)-1 -- as in history_set_pos + */ + if (history(h, &ev, H_DELDATA, num - history_base, (void **)-1) != 0) + goto out; + /* get current entry */ + if (history(h, &ev, H_CURR) != 0) + goto out; + if (history(h, &ev, H_NEXT_EVDATA, ev.num, &she.data) != 0) + goto out; she.line = ev.str; /* restore pointer to where it was */ (void)history(h, &ev, H_SET, curr_num); return &she; + +out: + /* restore pointer to where it was */ + (void)history(h, &ev, H_SET, curr_num); + return NULL; } @@ -1421,17 +1427,18 @@ add_history(const char *line) { HistEvent ev; - if (line == NULL) - return 0; - if (h == NULL || e == NULL) rl_initialize(); - (void)history(h, &ev, H_ENTER, line); - if (history(h, &ev, H_GETSIZE) == 0) - history_length = ev.num; + if (history(h, &ev, H_ENTER, line) == -1) + return 0; - return !(history_length > 0); /* return 0 if all is okay */ + (void)history(h, &ev, H_GETSIZE); + if (ev.num == history_length) + history_base++; + else + history_length = ev.num; + return 0; } @@ -1521,7 +1528,7 @@ clear_history(void) rl_initialize(); (void)history(h, &ev, H_CLEAR); - history_length = 0; + history_offset = history_length = 0; } @@ -1530,22 +1537,43 @@ clear_history(void) */ int where_history(void) +{ + return history_offset; +} + +static HIST_ENTRY **_history_listp; +static HIST_ENTRY *_history_list; + +HIST_ENTRY ** +history_list(void) { HistEvent ev; - int curr_num, off; + HIST_ENTRY **nlp, *nl; + int i; - if (history(h, &ev, H_CURR) != 0) - return 0; - curr_num = ev.num; + if (history(h, &ev, H_LAST) != 0) + return NULL; - (void)history(h, &ev, H_FIRST); - off = 1; - while (ev.num != curr_num && history(h, &ev, H_NEXT) == 0) - off++; + if ((nlp = el_realloc(_history_listp, + (size_t)history_length * sizeof(*nlp))) == NULL) + return NULL; + _history_listp = nlp; - return off; -} + if ((nl = el_realloc(_history_list, + (size_t)history_length * sizeof(*nl))) == NULL) + return NULL; + _history_list = nl; + i = 0; + do { + _history_listp[i] = &_history_list[i]; + _history_list[i].line = ev.str; + _history_list[i].data = NULL; + if (i++ == history_length) + abort(); + } while (history(h, &ev, H_PREV) == 0); + return _history_listp; +} /* * returns current history event or NULL if there is no such event @@ -1553,8 +1581,14 @@ where_history(void) HIST_ENTRY * current_history(void) { + HistEvent ev; + + if (history(h, &ev, H_PREV_EVENT, history_offset + 1) != 0) + return NULL; - return _move_history(H_CURR); + rl_he.line = ev.str; + rl_he.data = NULL; + return &rl_he; } @@ -1591,35 +1625,31 @@ history_total_bytes(void) int history_set_pos(int pos) { - HistEvent ev; - int curr_num; - if (pos >= history_length || pos < 0) - return -1; - - (void)history(h, &ev, H_CURR); - curr_num = ev.num; + return 0; - /* - * use H_DELDATA to set to nth history (without delete) by passing - * (void **)-1 - */ - if (history(h, &ev, H_DELDATA, pos, (void **)-1)) { - (void)history(h, &ev, H_SET, curr_num); - return -1; - } - return 0; + history_offset = pos; + return 1; } /* * returns previous event in history and shifts pointer accordingly + * Note that readline and editline define directions in opposite ways. */ HIST_ENTRY * previous_history(void) { + HistEvent ev; + + if (history_offset == 0) + return NULL; - return _move_history(H_PREV); + if (history(h, &ev, H_LAST) != 0) + return NULL; + + history_offset--; + return current_history(); } @@ -1629,8 +1659,16 @@ previous_history(void) HIST_ENTRY * next_history(void) { + HistEvent ev; + + if (history_offset >= history_length) + return NULL; + + if (history(h, &ev, H_LAST) != 0) + return NULL; - return _move_history(H_NEXT); + history_offset++; + return current_history(); } @@ -1691,7 +1729,7 @@ history_search_pos(const char *str, return -1; curr_num = ev.num; - if (history_set_pos(off) != 0 || history(h, &ev, H_CURR) != 0) + if (!history_set_pos(off) || history(h, &ev, H_CURR) != 0) return -1; for (;;) { @@ -1801,9 +1839,7 @@ _rl_completion_append_character_function(const char *dummy int rl_complete(int ignore __attribute__((__unused__)), int invoking_key) { -#ifdef WIDECHAR static ct_buffer_t wbreak_conv, sprefix_conv; -#endif char *breakchars; if (h == NULL || e == NULL) @@ -1822,9 +1858,11 @@ rl_complete(int ignore __attribute__((__unused__)), int invoking_key) else breakchars = rl_basic_word_break_characters; + _rl_update_pos(); + /* Just look at how many global variables modify this operation! */ return fn_complete(e, - (CPFunction *)rl_completion_entry_function, + (rl_compentry_func_t *)rl_completion_entry_function, rl_attempted_completion_function, ct_decode_string(rl_basic_word_break_characters, &wbreak_conv), ct_decode_string(breakchars, &sprefix_conv), @@ -1953,7 +1991,7 @@ rl_bind_wrapper(EditLine *el __attribute__((__unused__)), unsigned char c) _rl_update_pos(); - (*map[c])(NULL, c); + (*map[c])(1, c); /* If rl_done was set by the above call, deal with it here */ if (rl_done) @@ -1963,7 +2001,7 @@ rl_bind_wrapper(EditLine *el __attribute__((__unused__)), unsigned char c) } int -rl_add_defun(const char *name, Function *fun, int c) +rl_add_defun(const char *name, rl_command_func_t *fun, int c) { char dest[8]; if ((size_t)c >= sizeof(map) / sizeof(map[0]) || c < 0) @@ -2001,8 +2039,8 @@ rl_callback_read_char(void) } } -void -rl_callback_handler_install(const char *prompt, VCPFunction *linefunc) +void +rl_callback_handler_install(const char *prompt, rl_vcpfunc_t *linefunc) { if (e == NULL) { rl_initialize(); @@ -2010,9 +2048,9 @@ rl_callback_handler_install(const char *prompt, VCPFunction *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); @@ -2093,12 +2131,14 @@ rl_stuff_char(int c) } static int -_rl_event_read_char(EditLine *el, char *cp) +_rl_event_read_char(EditLine *el, wchar_t *wc) { + char ch; int n; ssize_t num_read = 0; - *cp = '\0'; + ch = '\0'; + *wc = L'\0'; while (rl_event_hook) { (*rl_event_hook)(); @@ -2107,7 +2147,7 @@ _rl_event_read_char(EditLine *el, char *cp) if (ioctl(el->el_infd, FIONREAD, &n) < 0) return -1; if (n) - num_read = read(el->el_infd, cp, (size_t)1); + num_read = read(el->el_infd, &ch, (size_t)1); else num_read = 0; #elif defined(F_SETFL) && defined(O_NDELAY) @@ -2115,12 +2155,12 @@ _rl_event_read_char(EditLine *el, char *cp) return -1; if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) < 0) return -1; - num_read = read(el->el_infd, cp, 1); + num_read = read(el->el_infd, &ch, 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, cp, 1); + num_read = read(el->el_infd, &ch, 1); return -1; #endif @@ -2132,6 +2172,7 @@ _rl_event_read_char(EditLine *el, char *cp) } if (!rl_event_hook) el_set(el, EL_GETCFN, EL_BUILTIN_GETCFN); + *wc = (wchar_t)ch; return (int)num_read; } @@ -2194,7 +2235,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_T_MAX; + min = SIZE_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++) @@ -2212,7 +2253,7 @@ rl_completion_matches(const char *str, rl_compentry_func_t *fun) list[0][min] = '\0'; } return list; - + out: el_free(list); return NULL; @@ -2316,3 +2357,10 @@ void rl_free_line_state(void) { } + +int +/*ARGSUSED*/ +rl_set_keyboard_input_timeout(int u __attribute__((__unused__))) +{ + return 0; +} diff --git a/contrib/libedit/src/refresh.c b/contrib/libedit/src/refresh.c index 3e1176eced..e7775b0e4d 100644 --- a/contrib/libedit/src/refresh.c +++ b/contrib/libedit/src/refresh.c @@ -1,4 +1,4 @@ -/* $NetBSD: refresh.c,v 1.37 2011/07/29 23:44:45 christos Exp $ */ +/* $NetBSD: refresh.c,v 1.51 2016/05/09 21:46:56 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.37 2011/07/29 23:44:45 christos Exp $"); +__RCSID("$NetBSD: refresh.c,v 1.51 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -45,26 +45,25 @@ __RCSID("$NetBSD: refresh.c,v 1.37 2011/07/29 23:44:45 christos Exp $"); * refresh.c: Lower level screen refreshing functions */ #include -#include -#include #include +#include #include "el.h" -private void re_nextline(EditLine *); -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 *, 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); +static void re_nextline(EditLine *); +static void re_addc(EditLine *, wint_t); +static void re_update_line(EditLine *, wchar_t *, wchar_t *, int); +static void re_insert (EditLine *, wchar_t *, int, int, wchar_t *, int); +static void re_delete(EditLine *, wchar_t *, int, int, int); +static void re_fastputc(EditLine *, wint_t); +static void re_clear_eol(EditLine *, int, int, int); +static void re__strncopy(wchar_t *, wchar_t *, size_t); +static void re__copy_and_pad(wchar_t *, const wchar_t *, size_t); #ifdef DEBUG_REFRESH -private void re_printstr(EditLine *, const char *, char *, char *); +static void re_printstr(EditLine *, const char *, wchar_t *, wchar_t *); #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; \ @@ -75,8 +74,8 @@ private void re_printstr(EditLine *, const char *, char *, char *); /* re_printstr(): * Print a string on the debugging pty */ -private void -re_printstr(EditLine *el, const char *str, char *f, char *t) +static void +re_printstr(EditLine *el, const char *str, wchar_t *f, wchar_t *t) { ELRE_DEBUG(1, (__F, "%s:\"", str)); @@ -92,7 +91,7 @@ re_printstr(EditLine *el, const char *str, char *f, char *t) /* re_nextline(): * Move to the next line or scroll */ -private void +static void re_nextline(EditLine *el) { el->el_refresh.r_cursor.h = 0; /* reset it. */ @@ -105,12 +104,12 @@ re_nextline(EditLine *el) */ if (el->el_refresh.r_cursor.v + 1 >= el->el_terminal.t_size.v) { int i, lins = el->el_terminal.t_size.v; - Char *firstline = el->el_vdisplay[0]; + wchar_t *firstline = el->el_vdisplay[0]; 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++; @@ -124,10 +123,10 @@ re_nextline(EditLine *el) /* re_addc(): * Draw c, expanding tabs, control chars etc. */ -private void -re_addc(EditLine *el, Int c) +static void +re_addc(EditLine *el, wint_t c) { - switch (ct_chr_class((Char)c)) { + switch (ct_chr_class(c)) { case CHTYPE_TAB: /* expand the tab */ for (;;) { re_putc(el, ' ', 1); @@ -146,9 +145,9 @@ re_addc(EditLine *el, Int c) re_putc(el, c, 1); break; default: { - Char visbuf[VISUAL_WIDTH_MAX]; + wchar_t visbuf[VISUAL_WIDTH_MAX]; ssize_t i, n = - ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c); + ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c); for (i = 0; n-- > 0; ++i) re_putc(el, visbuf[i], 1); break; @@ -160,11 +159,13 @@ re_addc(EditLine *el, Int c) /* re_putc(): * Draw the character given */ -protected void -re_putc(EditLine *el, Int c, int shift) +libedit_private void +re_putc(EditLine *el, wint_t c, int shift) { - int i, w = Width(c); - ELRE_DEBUG(1, (__F, "printing %5x '%c'\r\n", c, c)); + int i, w = wcwidth(c); + ELRE_DEBUG(1, (__F, "printing %5x '%lc'\r\n", c, c)); + if (w == -1) + w = 0; while (shift && (el->el_refresh.r_cursor.h + w > el->el_terminal.t_size.h)) re_putc(el, ' ', 1); @@ -192,21 +193,21 @@ re_putc(EditLine *el, Int 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. */ -protected void +libedit_private void re_refresh(EditLine *el) { int i, rhdiff; - Char *cp, *st; + wchar_t *cp, *st; coord_t cur; #ifdef notyet size_t termsz; #endif - ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%s:\r\n", + ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%ls:\r\n", el->el_line.buffer)); /* reset the Drawing cursor */ @@ -252,7 +253,7 @@ re_refresh(EditLine *el) for (cp = st; cp < el->el_line.lastchar; cp++) { if (cp == el->el_line.cursor) { - int w = Width(*cp); + int w = wcwidth(*cp); /* save for later */ cur.h = el->el_refresh.r_cursor.h; cur.v = el->el_refresh.r_cursor.v; @@ -294,7 +295,8 @@ re_refresh(EditLine *el) ELRE_DEBUG(1, (__F, "term.h=%d vcur.h=%d vcur.v=%d vdisplay[0]=\r\n:%80.80s:\r\n", el->el_terminal.t_size.h, el->el_refresh.r_cursor.h, - el->el_refresh.r_cursor.v, ct_encode_string(el->el_vdisplay[0]))); + el->el_refresh.r_cursor.v, ct_encode_string(el->el_vdisplay[0], + &el->el_scratch))); ELRE_DEBUG(1, (__F, "updating %d lines.\r\n", el->el_refresh.r_newcv)); for (i = 0; i <= el->el_refresh.r_newcv; i++) { @@ -319,10 +321,10 @@ re_refresh(EditLine *el) for (; i <= el->el_refresh.r_oldcv; i++) { terminal_move_to_line(el, i); terminal_move_to_char(el, 0); - /* This Strlen should be safe even with MB_FILL_CHARs */ - terminal_clear_EOL(el, (int) Strlen(el->el_display[i])); + /* This wcslen should be safe even with MB_FILL_CHARs */ + terminal_clear_EOL(el, (int) wcslen(el->el_display[i])); #ifdef DEBUG_REFRESH - terminal_overwrite(el, "C\b", (size_t)2); + terminal_overwrite(el, L"C\b", 2); #endif /* DEBUG_REFRESH */ el->el_display[i][0] = '\0'; } @@ -340,7 +342,7 @@ re_refresh(EditLine *el) /* re_goto_bottom(): * used to go to last used screen line */ -protected void +libedit_private void re_goto_bottom(EditLine *el) { @@ -355,12 +357,12 @@ re_goto_bottom(EditLine *el) * insert num characters of s into d (in front of the character) * at dat, maximum length of d is dlen */ -private void +static void /*ARGSUSED*/ re_insert(EditLine *el __attribute__((__unused__)), - Char *d, int dat, int dlen, Char *s, int num) + wchar_t *d, int dat, int dlen, wchar_t *s, int num) { - Char *a, *b; + wchar_t *a, *b; if (num <= 0) return; @@ -369,8 +371,9 @@ re_insert(EditLine *el __attribute__((__unused__)), ELRE_DEBUG(1, (__F, "re_insert() starting: %d at %d max %d, d == \"%s\"\n", - num, dat, dlen, ct_encode_string(d))); - ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s))); + num, dat, dlen, ct_encode_string(d, &el->el_scratch))); + ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s, + &el->el_scratch))); /* open up the space for num chars */ if (num > 0) { @@ -383,8 +386,9 @@ re_insert(EditLine *el __attribute__((__unused__)), ELRE_DEBUG(1, (__F, "re_insert() after insert: %d at %d max %d, d == \"%s\"\n", - num, dat, dlen, ct_encode_string(d))); - ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s))); + num, dat, dlen, ct_encode_string(d, &el->el_scratch))); + ELRE_DEBUG(1, (__F, "s == \"%s\"\n", ct_encode_string(s, + &el->el_scratch))); /* copy the characters */ for (a = d + dat; (a < d + dlen) && (num > 0); num--) @@ -404,12 +408,12 @@ re_insert(EditLine *el __attribute__((__unused__)), /* re_delete(): * delete num characters d at dat, maximum length of d is dlen */ -private void +static void /*ARGSUSED*/ re_delete(EditLine *el __attribute__((__unused__)), - Char *d, int dat, int dlen, int num) + wchar_t *d, int dat, int dlen, int num) { - Char *a, *b; + wchar_t *a, *b; if (num <= 0) return; @@ -419,7 +423,7 @@ re_delete(EditLine *el __attribute__((__unused__)), } ELRE_DEBUG(1, (__F, "re_delete() starting: %d at %d max %d, d == \"%s\"\n", - num, dat, dlen, ct_encode_string(d))); + num, dat, dlen, ct_encode_string(d, &el->el_scratch))); /* open up the space for num chars */ if (num > 0) { @@ -431,15 +435,15 @@ re_delete(EditLine *el __attribute__((__unused__)), } ELRE_DEBUG(1, (__F, "re_delete() after delete: %d at %d max %d, d == \"%s\"\n", - num, dat, dlen, ct_encode_string(d))); + num, dat, dlen, ct_encode_string(d, &el->el_scratch))); } /* re__strncopy(): * Like strncpy without padding. */ -private void -re__strncopy(Char *a, Char *b, size_t n) +static void +re__strncopy(wchar_t *a, wchar_t *b, size_t n) { while (n-- && *b) @@ -451,9 +455,9 @@ 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 +static void re_clear_eol(EditLine *el, int fx, int sx, int diff) { @@ -497,12 +501,12 @@ new: eddie> Oh, my little buggy says to me, as lurgid as */ #define MIN_END_KEEP 4 -private void -re_update_line(EditLine *el, Char *old, Char *new, int i) +static void +re_update_line(EditLine *el, wchar_t *old, wchar_t *new, int i) { - Char *o, *n, *p, c; - Char *ofd, *ols, *oe, *nfd, *nls, *ne; - Char *osb, *ose, *nsb, *nse; + wchar_t *o, *n, *p, c; + wchar_t *ofd, *ols, *oe, *nfd, *nls, *ne; + wchar_t *osb, *ose, *nsb, *nse; int fx, sx; size_t len; @@ -559,7 +563,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i) nls = ++n; /* - * find same begining and same end + * find same beginning and same end */ osb = ols; nsb = nls; @@ -689,9 +693,9 @@ re_update_line(EditLine *el, Char *old, Char *new, int i) sx = (int)((nls - nse) - (ols - ose)); ELRE_DEBUG(1, (__F, "fx %d, sx %d\n", fx, sx)); - ELRE_DEBUG(1, (__F, "ofd %d, osb %d, ose %d, ols %d, oe %d\n", + ELRE_DEBUG(1, (__F, "ofd %td, osb %td, ose %td, ols %td, oe %td\n", ofd - old, osb - old, ose - old, ols - old, oe - old)); - ELRE_DEBUG(1, (__F, "nfd %d, nsb %d, nse %d, nls %d, ne %d\n", + ELRE_DEBUG(1, (__F, "nfd %td, nsb %td, nse %td, nls %td, ne %td\n", nfd - new, nsb - new, nse - new, nls - new, ne - new)); ELRE_DEBUG(1, (__F, "xxx-xxx:\"00000000001111111111222222222233333333334\"\r\n")); @@ -765,7 +769,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i) if ((nsb != nfd) && fx > 0 && ((p - old) + fx <= el->el_terminal.t_size.h)) { ELRE_DEBUG(1, - (__F, "first diff insert at %d...\r\n", nfd - new)); + (__F, "first diff insert at %td...\r\n", nfd - new)); /* * Move to the first char to insert, where the first diff is. */ @@ -804,7 +808,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i) } } else if (fx < 0) { ELRE_DEBUG(1, - (__F, "first diff delete at %d...\r\n", ofd - old)); + (__F, "first diff delete at %td...\r\n", ofd - old)); /* * move to the first char to delete where the first diff is */ @@ -851,7 +855,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i) if (sx < 0 && (ose - old) + fx < el->el_terminal.t_size.h) { ELRE_DEBUG(1, (__F, - "second diff delete at %d...\r\n", (ose - old) + fx)); + "second diff delete at %td...\r\n", (ose - old) + fx)); /* * Check if we have stuff to delete */ @@ -889,7 +893,7 @@ re_update_line(EditLine *el, Char *old, Char *new, int i) * if we have a first insert AND WE HAVEN'T ALREADY DONE IT... */ if ((nsb != nfd) && (osb - ofd) <= (nsb - nfd) && (fx == 0)) { - ELRE_DEBUG(1, (__F, "late first diff insert at %d...\r\n", + ELRE_DEBUG(1, (__F, "late first diff insert at %td...\r\n", nfd - new)); terminal_move_to_char(el, (int)(nfd - new)); @@ -967,8 +971,8 @@ re_update_line(EditLine *el, Char *old, Char *new, int i) /* re__copy_and_pad(): * Copy string and pad with spaces */ -private void -re__copy_and_pad(Char *dst, const Char *src, size_t width) +static void +re__copy_and_pad(wchar_t *dst, const wchar_t *src, size_t width) { size_t i; @@ -988,10 +992,10 @@ re__copy_and_pad(Char *dst, const Char *src, size_t width) /* re_refresh_cursor(): * Move to the new cursor position */ -protected void +libedit_private void re_refresh_cursor(EditLine *el) { - Char *cp; + wchar_t *cp; int h, v, th, w; if (el->el_line.cursor >= el->el_line.lastchar) { @@ -1019,7 +1023,7 @@ re_refresh_cursor(EditLine *el) continue; break; default: - w = Width(*cp); + w = wcwidth(*cp); if (w > 1 && h + w > th) { /* won't fit on line */ h = 0; v++; @@ -1035,7 +1039,7 @@ re_refresh_cursor(EditLine *el) } /* if we have a next character, and it's a doublewidth one, we need to * check whether we need to linebreak for it to fit */ - if (cp < el->el_line.lastchar && (w = Width(*cp)) > 1) + if (cp < el->el_line.lastchar && (w = wcwidth(*cp)) > 1) if (h + w > th) { h = 0; v++; @@ -1051,10 +1055,10 @@ re_refresh_cursor(EditLine *el) /* re_fastputc(): * Add a character fast. */ -private void -re_fastputc(EditLine *el, Int c) +static void +re_fastputc(EditLine *el, wint_t c) { - int w = Width((Char)c); + int w = wcwidth(c); while (w > 1 && el->el_cursor.h + w > el->el_terminal.t_size.h) re_fastputc(el, ' '); @@ -1076,12 +1080,12 @@ re_fastputc(EditLine *el, Int 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]; - + wchar_t *firstline = el->el_display[0]; + for(i = 1; i < lins; i++) el->el_display[i - 1] = el->el_display[i]; - re__copy_and_pad(firstline, STR(""), (size_t)0); + re__copy_and_pad(firstline, L"", (size_t)0); el->el_display[i - 1] = firstline; } else { el->el_cursor.v++; @@ -1104,10 +1108,10 @@ re_fastputc(EditLine *el, Int c) * we added just one char, handle it fast. * Assumes that screen cursor == real cursor */ -protected void +libedit_private void re_fastaddc(EditLine *el) { - Char c; + wchar_t c; int rhdiff; c = el->el_line.cursor[-1]; @@ -1131,9 +1135,9 @@ re_fastaddc(EditLine *el) break; case CHTYPE_ASCIICTL: case CHTYPE_NONPRINT: { - Char visbuf[VISUAL_WIDTH_MAX]; + wchar_t visbuf[VISUAL_WIDTH_MAX]; ssize_t i, n = - ct_visual_char(visbuf, VISUAL_WIDTH_MAX, (Char)c); + ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c); for (i = 0; n-- > 0; ++i) re_fastputc(el, visbuf[i]); break; @@ -1146,7 +1150,7 @@ re_fastaddc(EditLine *el) /* re_clear_display(): * clear the screen buffers so that new new prompt starts fresh. */ -protected void +libedit_private void re_clear_display(EditLine *el) { int i; @@ -1162,7 +1166,7 @@ re_clear_display(EditLine *el) /* re_clear_lines(): * Make sure all lines are *really* blank */ -protected void +libedit_private void re_clear_lines(EditLine *el) { diff --git a/contrib/libedit/src/refresh.h b/contrib/libedit/src/refresh.h index f80be46354..621c5691ec 100644 --- a/contrib/libedit/src/refresh.h +++ b/contrib/libedit/src/refresh.h @@ -1,4 +1,4 @@ -/* $NetBSD: refresh.h,v 1.6 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: refresh.h,v 1.10 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,20 +40,18 @@ #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 *, Int, int); -protected void re_clear_lines(EditLine *); -protected void re_clear_display(EditLine *); -protected void re_refresh(EditLine *); -protected void re_refresh_cursor(EditLine *); -protected void re_fastaddc(EditLine *); -protected void re_goto_bottom(EditLine *); +libedit_private void re_putc(EditLine *, wint_t, int); +libedit_private void re_clear_lines(EditLine *); +libedit_private void re_clear_display(EditLine *); +libedit_private void re_refresh(EditLine *); +libedit_private void re_refresh_cursor(EditLine *); +libedit_private void re_fastaddc(EditLine *); +libedit_private void re_goto_bottom(EditLine *); #endif /* _h_el_refresh */ diff --git a/contrib/libedit/src/search.c b/contrib/libedit/src/search.c index 9ed7760b7e..3141629fb4 100644 --- a/contrib/libedit/src/search.c +++ b/contrib/libedit/src/search.c @@ -1,4 +1,4 @@ -/* $NetBSD: search.c,v 1.30 2011/10/04 15:27:04 christos Exp $ */ +/* $NetBSD: search.c,v 1.47 2016/05/09 21:46:56 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.30 2011/10/04 15:27:04 christos Exp $"); +__RCSID("$NetBSD: search.c,v 1.47 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -46,12 +46,16 @@ __RCSID("$NetBSD: search.c,v 1.30 2011/10/04 15:27:04 christos Exp $"); */ #include #include +#include #if defined(REGEX) #include #elif defined(REGEXP) #include #endif + #include "el.h" +#include "common.h" +#include "fcns.h" /* * Adjust cursor in vi mode to include the character under it @@ -63,7 +67,7 @@ __RCSID("$NetBSD: search.c,v 1.30 2011/10/04 15:27:04 christos Exp $"); /* search_init(): * Initialize the search stuff */ -protected int +libedit_private int search_init(EditLine *el) { @@ -71,9 +75,10 @@ search_init(EditLine *el) sizeof(*el->el_search.patbuf)); if (el->el_search.patbuf == NULL) return -1; + el->el_search.patbuf[0] = L'\0'; el->el_search.patlen = 0; el->el_search.patdir = -1; - el->el_search.chacha = '\0'; + el->el_search.chacha = L'\0'; el->el_search.chadir = CHAR_FWD; el->el_search.chatflg = 0; return 0; @@ -83,7 +88,7 @@ search_init(EditLine *el) /* search_end(): * Initialize the search stuff */ -protected void +libedit_private void search_end(EditLine *el) { @@ -96,7 +101,7 @@ search_end(EditLine *el) /* regerror(): * Handle regular expression errors */ -public void +void /*ARGSUSED*/ regerror(const char *msg) { @@ -107,12 +112,10 @@ regerror(const char *msg) /* el_match(): * Return if string matches pattern */ -protected int -el_match(const Char *str, const Char *pat) +libedit_private int +el_match(const wchar_t *str, const wchar_t *pat) { -#ifdef WIDECHAR static ct_buffer_t conv; -#endif #if defined (REGEX) regex_t re; int rv; @@ -124,7 +127,7 @@ el_match(const Char *str, const Char *pat) extern int re_exec(const char *); #endif - if (Strstr(str, pat) != 0) + if (wcsstr(str, pat) != 0) return 1; #if defined(REGEX) @@ -148,7 +151,7 @@ el_match(const Char *str, const Char *pat) if (re_comp(ct_encode_string(pat, &conv)) != NULL) return 0; else - return re_exec(ct_encode_string(str, &conv) == 1); + return re_exec(ct_encode_string(str, &conv)) == 1; #endif } @@ -156,8 +159,8 @@ el_match(const Char *str, const Char *pat) /* c_hmatch(): * return True if the pattern matches the prefix */ -protected int -c_hmatch(EditLine *el, const Char *str) +libedit_private int +c_hmatch(EditLine *el, const wchar_t *str) { #ifdef SDEBUG (void) fprintf(el->el_errfile, "match `%s' with `%s'\n", @@ -171,7 +174,7 @@ c_hmatch(EditLine *el, const Char *str) /* c_setpat(): * Set the history seatch pattern */ -protected void +libedit_private void c_setpat(EditLine *el) { if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY && @@ -181,11 +184,11 @@ c_setpat(EditLine *el) if (el->el_search.patlen >= EL_BUFSIZ) el->el_search.patlen = EL_BUFSIZ - 1; if (el->el_search.patlen != 0) { - (void) Strncpy(el->el_search.patbuf, el->el_line.buffer, + (void) wcsncpy(el->el_search.patbuf, el->el_line.buffer, el->el_search.patlen); el->el_search.patbuf[el->el_search.patlen] = '\0'; } else - el->el_search.patlen = Strlen(el->el_search.patbuf); + el->el_search.patlen = wcslen(el->el_search.patbuf); } #ifdef SDEBUG (void) fprintf(el->el_errfile, "\neventno = %d\n", @@ -203,15 +206,14 @@ c_setpat(EditLine *el) /* ce_inc_search(): * Emacs incremental search */ -protected el_action_t +libedit_private el_action_t ce_inc_search(EditLine *el, int dir) { - static const Char STRfwd[] = {'f', 'w', 'd', '\0'}, - STRbck[] = {'b', 'c', 'k', '\0'}; - static Char pchar = ':';/* ':' = normal, '?' = failed */ - static Char endcmd[2] = {'\0', '\0'}; - Char ch, *ocursor = el->el_line.cursor, oldpchar = pchar; - const Char *cp; + static const wchar_t STRfwd[] = L"fwd", STRbck[] = L"bck"; + static wchar_t pchar = L':'; /* ':' = normal, '?' = failed */ + static wchar_t endcmd[2] = {'\0', '\0'}; + wchar_t *ocursor = el->el_line.cursor, oldpchar = pchar, ch; + const wchar_t *cp; el_action_t ret = CC_NORM; @@ -250,7 +252,7 @@ ce_inc_search(EditLine *el, int dir) *el->el_line.lastchar = '\0'; re_refresh(el); - if (FUN(el,getc)(el, &ch) != 1) + if (el_wgetc(el, &ch) != 1) return ed_end_of_file(el, 0); switch (el->el_map.current[(unsigned char) ch]) { @@ -326,7 +328,7 @@ ce_inc_search(EditLine *el, int dir) default: /* Terminate and execute cmd */ endcmd[0] = ch; - FUN(el,push)(el, endcmd); + el_wpush(el, endcmd); /* FALLTHROUGH */ case 0033: /* ESC: Terminate */ @@ -346,14 +348,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 = ']'; + ch = L']'; cp >= &el->el_search.patbuf[LEN]; cp--) if (*cp == '[' || *cp == ']') { ch = *cp; break; } - if (el->el_search.patlen > LEN && ch != '[') { + if (el->el_search.patlen > LEN && ch != L'[') { if (redo && newdir == dir) { if (pchar == '?') { /* wrap around */ el->el_history.eventno = @@ -451,11 +453,11 @@ ce_inc_search(EditLine *el, int dir) /* cv_search(): * Vi search. */ -protected el_action_t +libedit_private el_action_t cv_search(EditLine *el, int dir) { - Char ch; - Char tmpbuf[EL_BUFSIZ]; + wchar_t ch; + wchar_t tmpbuf[EL_BUFSIZ]; ssize_t tmplen; #ifdef ANCHOR @@ -467,7 +469,7 @@ cv_search(EditLine *el, int dir) el->el_search.patdir = dir; tmplen = c_gets(el, &tmpbuf[LEN], - dir == ED_SEARCH_PREV_HISTORY ? STR("\n/") : STR("\n?") ); + dir == ED_SEARCH_PREV_HISTORY ? L"\n/" : L"\n?" ); if (tmplen == -1) return CC_REFRESH; @@ -486,11 +488,11 @@ cv_search(EditLine *el, int dir) #ifdef ANCHOR if (el->el_search.patbuf[0] != '.' && el->el_search.patbuf[0] != '*') { - (void) Strncpy(tmpbuf, el->el_search.patbuf, + (void) wcsncpy(tmpbuf, el->el_search.patbuf, sizeof(tmpbuf) / sizeof(*tmpbuf) - 1); el->el_search.patbuf[0] = '.'; el->el_search.patbuf[1] = '*'; - (void) Strncpy(&el->el_search.patbuf[2], tmpbuf, + (void) wcsncpy(&el->el_search.patbuf[2], tmpbuf, EL_BUFSIZ - 3); el->el_search.patlen++; el->el_search.patbuf[el->el_search.patlen++] = '.'; @@ -504,7 +506,7 @@ cv_search(EditLine *el, int dir) tmpbuf[tmplen++] = '*'; #endif tmpbuf[tmplen] = '\0'; - (void) Strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1); + (void) wcsncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1); el->el_search.patlen = (size_t)tmplen; } el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */ @@ -525,12 +527,12 @@ cv_search(EditLine *el, int dir) /* ce_search_line(): * Look for a pattern inside a line */ -protected el_action_t +libedit_private el_action_t ce_search_line(EditLine *el, int dir) { - Char *cp = el->el_line.cursor; - Char *pattern = el->el_search.patbuf; - Char oc, *ocp; + wchar_t *cp = el->el_line.cursor; + wchar_t *pattern = el->el_search.patbuf; + wchar_t oc, *ocp; #ifdef ANCHOR ocp = &pattern[1]; oc = *ocp; @@ -567,8 +569,8 @@ ce_search_line(EditLine *el, int dir) /* cv_repeat_srch(): * Vi repeat search */ -protected el_action_t -cv_repeat_srch(EditLine *el, Int c) +libedit_private el_action_t +cv_repeat_srch(EditLine *el, wint_t c) { #ifdef SDEBUG @@ -593,19 +595,17 @@ cv_repeat_srch(EditLine *el, Int c) /* cv_csearch(): * Vi character search */ -protected el_action_t -cv_csearch(EditLine *el, int direction, Int ch, int count, int tflag) +libedit_private el_action_t +cv_csearch(EditLine *el, int direction, wint_t ch, int count, int tflag) { - Char *cp; + wchar_t *cp; if (ch == 0) return CC_ERROR; - if (ch == (Int)-1) { - Char c; - if (FUN(el,getc)(el, &c) != 1) + if (ch == (wint_t)-1) { + if (el_wgetc(el, &ch) != 1) return ed_end_of_file(el, 0); - ch = c; } /* Save for ';' and ',' commands */ @@ -615,14 +615,14 @@ cv_csearch(EditLine *el, int direction, Int ch, int count, int tflag) cp = el->el_line.cursor; while (count--) { - if ((Int)*cp == ch) + if ((wint_t)*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 ((Int)*cp == ch) + if ((wint_t)*cp == ch) break; } } diff --git a/contrib/libedit/src/search.h b/contrib/libedit/src/search.h index d9f27e5618..4ca39c4c00 100644 --- a/contrib/libedit/src/search.h +++ b/contrib/libedit/src/search.h @@ -1,4 +1,4 @@ -/* $NetBSD: search.h,v 1.9 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: search.h,v 1.14 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,27 +40,25 @@ #ifndef _h_el_search #define _h_el_search -#include "histedit.h" - typedef struct el_search_t { - Char *patbuf; /* The pattern buffer */ + wchar_t *patbuf; /* The pattern buffer */ size_t patlen; /* Length of the pattern buffer */ int patdir; /* Direction of the last search */ int chadir; /* Character search direction */ - Char chacha; /* Character we are looking for */ + wchar_t chacha; /* Character we are looking for */ char chatflg; /* 0 if f, 1 if t */ } el_search_t; -protected int el_match(const Char *, const Char *); -protected int search_init(EditLine *); -protected void search_end(EditLine *); -protected int c_hmatch(EditLine *, const Char *); -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 *, Int); -protected el_action_t cv_csearch(EditLine *, int, Int, int, int); +libedit_private int el_match(const wchar_t *, const wchar_t *); +libedit_private int search_init(EditLine *); +libedit_private void search_end(EditLine *); +libedit_private int c_hmatch(EditLine *, const wchar_t *); +libedit_private void c_setpat(EditLine *); +libedit_private el_action_t ce_inc_search(EditLine *, int); +libedit_private el_action_t cv_search(EditLine *, int); +libedit_private el_action_t ce_search_line(EditLine *, int); +libedit_private el_action_t cv_repeat_srch(EditLine *, wint_t); +libedit_private el_action_t cv_csearch(EditLine *, int, wint_t, int, int); #endif /* _h_el_search */ diff --git a/contrib/libedit/src/sig.c b/contrib/libedit/src/sig.c index a5a8a895ea..83742a3d65 100644 --- a/contrib/libedit/src/sig.c +++ b/contrib/libedit/src/sig.c @@ -1,4 +1,4 @@ -/* $NetBSD: sig.c,v 1.17 2011/07/28 20:50:55 christos Exp $ */ +/* $NetBSD: sig.c,v 1.26 2016/05/09 21:46:56 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.17 2011/07/28 20:50:55 christos Exp $"); +__RCSID("$NetBSD: sig.c,v 1.26 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -46,31 +46,35 @@ __RCSID("$NetBSD: sig.c,v 1.17 2011/07/28 20:50:55 christos Exp $"); * our policy is to trap all signals, set a good state * and pass the ball to our caller. */ -#include "el.h" +#include #include -private EditLine *sel = NULL; +#include "el.h" +#include "common.h" + +static EditLine *sel = NULL; -private const int sighdl[] = { +static const int sighdl[] = { #define _DO(a) (a), ALLSIGS #undef _DO - 1 }; -private void sig_handler(int); +static void sig_handler(int); /* sig_handler(): * This is the handler called for all signals * XXX: we cannot pass any data so we just store the old editline * state in a private variable */ -private void +static void sig_handler(int signo) { - int i; + int i, save_errno; sigset_t nset, oset; + save_errno = errno; (void) sigemptyset(&nset); (void) sigaddset(&nset, signo); (void) sigprocmask(SIG_BLOCK, &nset, &oset); @@ -104,13 +108,14 @@ 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; } /* sig_init(): * Initialize all signal stuff */ -protected int +libedit_private int sig_init(EditLine *el) { size_t i; @@ -142,7 +147,7 @@ sig_init(EditLine *el) /* sig_end(): * Clear all signal stuff */ -protected void +libedit_private void sig_end(EditLine *el) { @@ -154,7 +159,7 @@ sig_end(EditLine *el) /* sig_set(): * set all the signal handlers */ -protected void +libedit_private void sig_set(EditLine *el) { size_t i; @@ -181,7 +186,7 @@ sig_set(EditLine *el) /* sig_clr(): * clear all the signal handlers */ -protected void +libedit_private void sig_clr(EditLine *el) { size_t i; diff --git a/contrib/libedit/src/sig.h b/contrib/libedit/src/sig.h index c957cfdf5a..5ee453fb61 100644 --- a/contrib/libedit/src/sig.h +++ b/contrib/libedit/src/sig.h @@ -1,4 +1,4 @@ -/* $NetBSD: sig.h,v 1.8 2009/02/19 15:20:22 christos Exp $ */ +/* $NetBSD: sig.h,v 1.11 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -42,8 +42,6 @@ #include -#include "histedit.h" - /* * Define here all the signals we are going to handle * The _DO macro is used to iterate in the source code @@ -64,9 +62,9 @@ typedef struct { volatile sig_atomic_t sig_no; } *el_signal_t; -protected void sig_end(EditLine*); -protected int sig_init(EditLine*); -protected void sig_set(EditLine*); -protected void sig_clr(EditLine*); +libedit_private void sig_end(EditLine*); +libedit_private int sig_init(EditLine*); +libedit_private void sig_set(EditLine*); +libedit_private void sig_clr(EditLine*); #endif /* _h_el_sig */ diff --git a/contrib/libedit/src/strlcat.c b/contrib/libedit/src/strlcat.c deleted file mode 100644 index c1ef3a2189..0000000000 --- a/contrib/libedit/src/strlcat.c +++ /dev/null @@ -1,90 +0,0 @@ -/* $NetBSD: strlcat.c,v 1.4 2013/01/23 07:57:27 matt Exp $ */ -/* $OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE - * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "config.h" - -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: strlcat.c,v 1.4 2013/01/23 07:57:27 matt Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include - -#ifdef _LIBC -# ifdef __weak_alias -__weak_alias(strlcat, _strlcat) -# endif -#endif - -#if !HAVE_STRLCAT -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. - */ -size_t -strlcat(char *dst, const char *src, size_t siz) -{ -#if 1 - char *d = dst; - const char *s = src; - size_t n = siz; - size_t dlen; - - _DIAGASSERT(dst != NULL); - _DIAGASSERT(src != NULL); - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -#else - _DIAGASSERT(dst != NULL); - _DIAGASSERT(src != NULL); - - /* - * Find length of string in dst (maxing out at siz). - */ - size_t dlen = strnlen(dst, siz); - - /* - * Copy src into any remaining space in dst (truncating if needed). - * Note strlcpy(dst, src, 0) returns strlen(src). - */ - return dlen + strlcpy(dst + dlen, src, siz - dlen); -#endif -} -#endif diff --git a/contrib/libedit/src/strlcpy.c b/contrib/libedit/src/strlcpy.c deleted file mode 100644 index 8b3dfad211..0000000000 --- a/contrib/libedit/src/strlcpy.c +++ /dev/null @@ -1,70 +0,0 @@ -/* $NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */ -/* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE - * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#include "config.h" - -#if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $"); -#endif /* LIBC_SCCS and not lint */ - -#include -#include -#include - -#ifdef _LIBC -# ifdef __weak_alias -__weak_alias(strlcpy, _strlcpy) -# endif -#endif - -#if !HAVE_STRLCPY -/* - * Copy src to string dst of size siz. At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. - */ -size_t -strlcpy(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - - _DIAGASSERT(dst != NULL); - _DIAGASSERT(src != NULL); - - /* Copy as many bytes as will fit */ - if (n != 0 && --n != 0) { - do { - if ((*d++ = *s++) == 0) - break; - } while (--n != 0); - } - - /* Not enough room in dst, add NUL and traverse rest of src */ - if (n == 0) { - if (siz != 0) - *d = '\0'; /* NUL-terminate dst */ - while (*s++) - ; - } - - return(s - src - 1); /* count does not include NUL */ -} -#endif diff --git a/contrib/libedit/src/sys.h b/contrib/libedit/src/sys.h index 9e122c09c4..70361dfac1 100644 --- a/contrib/libedit/src/sys.h +++ b/contrib/libedit/src/sys.h @@ -1,4 +1,4 @@ -/* $NetBSD: sys.h,v 1.17 2011/09/28 14:08:04 christos Exp $ */ +/* $NetBSD: sys.h,v 1.27 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -61,19 +61,9 @@ # define __END_DECLS # endif #endif - -#ifndef public -# define public /* Externally visible functions/variables */ -#endif - -#ifndef private -# define private static /* Always hidden internals */ -#endif -#ifndef protected -# define protected /* Redefined from elsewhere to "static" */ - /* When we want to hide everything */ -#endif +/* If your compiler does not support this, define it to be empty. */ +#define libedit_private __attribute__((__visibility__("hidden"))) #ifndef __arraycount # define __arraycount(a) (sizeof(a) / sizeof(*(a))) @@ -101,14 +91,9 @@ 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_FGETLN -#define fgetln libedit_fgetln -char *fgetln(FILE *fp, size_t *len); -#endif - -#ifndef HAVE_WCSDUP -#include -wchar_t *wcsdup(const wchar_t *); +#ifndef HAVE_GETLINE +#define getline libedit_getline +ssize_t getline(char **line, size_t *len, FILE *fp); #endif #ifndef _DIAGASSERT diff --git a/contrib/libedit/src/terminal.c b/contrib/libedit/src/terminal.c index da86404a09..26838e813d 100644 --- a/contrib/libedit/src/terminal.c +++ b/contrib/libedit/src/terminal.c @@ -1,4 +1,4 @@ -/* $NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $ */ +/* $NetBSD: terminal.c,v 1.32 2016/05/09 21:46:56 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.14 2012/05/30 18:21:14 christos Exp $"); +__RCSID("$NetBSD: terminal.c,v 1.32 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -46,12 +46,14 @@ __RCSID("$NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $"); * We have to declare a static variable here, since the * termcap putchar routine does not take an argument! */ -#include +#include +#include +#include #include -#include +#include #include +#include #include -#include #ifdef HAVE_TERMCAP_H #include #endif @@ -65,15 +67,13 @@ __RCSID("$NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $"); #if defined(HAVE_TERM_H) && !defined(__sun) && !defined(HAVE_TERMCAP_H) #include #endif - -#include -#include #ifdef _REENTRANT #include #endif #include "el.h" +#include "fcns.h" /* * IMPORTANT NOTE: these routines are allowed to look at the current screen @@ -89,7 +89,7 @@ __RCSID("$NetBSD: terminal.c,v 1.14 2012/05/30 18:21:14 christos Exp $"); #define Str(a) el->el_terminal.t_str[a] #define Val(a) el->el_terminal.t_val[a] -private const struct termcapstr { +static const struct termcapstr { const char *name; const char *long_name; } tstr[] = { @@ -175,7 +175,7 @@ private const struct termcapstr { { NULL, NULL } }; -private const struct termcapval { +static const struct termcapval { const char *name; const char *long_name; } tval[] = { @@ -200,27 +200,27 @@ private const struct termcapval { }; /* do two or more of the attributes use me */ -private void terminal_setflags(EditLine *); -private int terminal_rebuffer_display(EditLine *); -private void terminal_free_display(EditLine *); -private int terminal_alloc_display(EditLine *); -private void terminal_alloc(EditLine *, const struct termcapstr *, +static void terminal_setflags(EditLine *); +static int terminal_rebuffer_display(EditLine *); +static void terminal_free_display(EditLine *); +static int terminal_alloc_display(EditLine *); +static void terminal_alloc(EditLine *, const struct termcapstr *, const char *); -private void terminal_init_arrow(EditLine *); -private void terminal_reset_arrow(EditLine *); -private int terminal_putc(int); -private void terminal_tputs(EditLine *, const char *, int); +static void terminal_init_arrow(EditLine *); +static void terminal_reset_arrow(EditLine *); +static int terminal_putc(int); +static void terminal_tputs(EditLine *, const char *, int); #ifdef _REENTRANT -private pthread_mutex_t terminal_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t terminal_mutex = PTHREAD_MUTEX_INITIALIZER; #endif -private FILE *terminal_outfile = NULL; +static FILE *terminal_outfile = NULL; /* terminal_setflags(): * Set the terminal capability flags */ -private void +static void terminal_setflags(EditLine *el) { EL_FLAGS = 0; @@ -265,44 +265,58 @@ terminal_setflags(EditLine *el) /* terminal_init(): * Initialize the terminal stuff */ -protected int +libedit_private int 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) - return -1; + goto fail1; el->el_terminal.t_cap = el_malloc(TC_BUFSIZE * sizeof(*el->el_terminal.t_cap)); if (el->el_terminal.t_cap == NULL) - return -1; + goto fail2; el->el_terminal.t_fkey = el_malloc(A_K_NKEYS * sizeof(*el->el_terminal.t_fkey)); if (el->el_terminal.t_fkey == NULL) - return -1; + goto fail3; el->el_terminal.t_loc = 0; el->el_terminal.t_str = el_malloc(T_str * sizeof(*el->el_terminal.t_str)); if (el->el_terminal.t_str == NULL) - return -1; + goto fail4; (void) memset(el->el_terminal.t_str, 0, T_str * sizeof(*el->el_terminal.t_str)); el->el_terminal.t_val = el_malloc(T_val * sizeof(*el->el_terminal.t_val)); if (el->el_terminal.t_val == NULL) - return -1; + goto fail5; (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(): * Clean up the terminal stuff */ -protected void +libedit_private void terminal_end(EditLine *el) { @@ -324,7 +338,7 @@ terminal_end(EditLine *el) /* terminal_alloc(): * Maintain a string pool for termcap strings */ -private void +static void terminal_alloc(EditLine *el, const struct termcapstr *t, const char *cap) { char termbuf[TC_BUFSIZE]; @@ -390,7 +404,7 @@ terminal_alloc(EditLine *el, const struct termcapstr *t, const char *cap) /* terminal_rebuffer_display(): * Rebuffer the display after the screen changed size */ -private int +static int terminal_rebuffer_display(EditLine *el) { coord_t *c = &el->el_terminal.t_size; @@ -409,23 +423,23 @@ terminal_rebuffer_display(EditLine *el) /* terminal_alloc_display(): * Allocate a new display. */ -private int +static int terminal_alloc_display(EditLine *el) { int i; - Char **b; + wchar_t **b; coord_t *c = &el->el_terminal.t_size; b = el_malloc(sizeof(*b) * (size_t)(c->v + 1)); if (b == NULL) - return -1; + goto done; 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); - return -1; + goto done; } } b[c->v] = NULL; @@ -433,30 +447,33 @@ terminal_alloc_display(EditLine *el) b = el_malloc(sizeof(*b) * (size_t)(c->v + 1)); if (b == NULL) - return -1; + goto done; 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); - return -1; + goto done; } } b[c->v] = NULL; el->el_vdisplay = b; return 0; +done: + terminal_free_display(el); + return -1; } /* terminal_free_display(): * Free the display buffers */ -private void +static void terminal_free_display(EditLine *el) { - Char **b; - Char **bufp; + wchar_t **b; + wchar_t **bufp; b = el->el_display; el->el_display = NULL; @@ -477,9 +494,9 @@ terminal_free_display(EditLine *el) /* terminal_move_to_line(): * move to line (first line == 0) - * as efficiently as possible + * as efficiently as possible */ -protected void +libedit_private void terminal_move_to_line(EditLine *el, int where) { int del; @@ -490,8 +507,7 @@ terminal_move_to_line(EditLine *el, int where) if (where > el->el_terminal.t_size.v) { #ifdef DEBUG_SCREEN (void) fprintf(el->el_errfile, - "terminal_move_to_line: where is ridiculous: %d\r\n", - where); + "%s: where is ridiculous: %d\r\n", __func__, where); #endif /* DEBUG_SCREEN */ return; } @@ -501,13 +517,11 @@ terminal_move_to_line(EditLine *el, int where) el->el_display[el->el_cursor.v][0] != '\0') { size_t h = (size_t) (el->el_terminal.t_size.h - 1); -#ifdef WIDECHAR for (; h > 0 && el->el_display[el->el_cursor.v][h] == MB_FILL_CHAR; h--) continue; -#endif /* move without newline */ terminal_move_to_char(el, (int)h); terminal_overwrite(el, &el->el_display @@ -545,7 +559,7 @@ terminal_move_to_line(EditLine *el, int where) /* terminal_move_to_char(): * Move to the character position specified */ -protected void +libedit_private void terminal_move_to_char(EditLine *el, int where) { int del, i; @@ -557,8 +571,7 @@ mc_again: if (where > el->el_terminal.t_size.h) { #ifdef DEBUG_SCREEN (void) fprintf(el->el_errfile, - "terminal_move_to_char: where is riduculous: %d\r\n", - where); + "%s: where is ridiculous: %d\r\n", __func__, where); #endif /* DEBUG_SCREEN */ return; } @@ -582,11 +595,9 @@ mc_again: if (EL_CAN_TAB) { if ((el->el_cursor.h & 0370) != (where & ~0x7) -#ifdef WIDECHAR && (el->el_display[ el->el_cursor.v][where & 0370] != MB_FILL_CHAR) -#endif ) { /* if not within tab stop */ for (i = @@ -594,7 +605,7 @@ mc_again: i < (where & ~0x7); i += 8) terminal__putc(el, - '\t'); + '\t'); /* then tab over */ el->el_cursor.h = where & ~0x7; } @@ -643,8 +654,8 @@ mc_again: * Overstrike num characters * Assumes MB_FILL_CHARs are present to keep the column count correct */ -protected void -terminal_overwrite(EditLine *el, const Char *cp, size_t n) +libedit_private void +terminal_overwrite(EditLine *el, const wchar_t *cp, size_t n) { if (n == 0) return; @@ -652,7 +663,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, - "terminal_overwrite: n is riduculous: %d\r\n", n); + "%s: n is ridiculous: %zu\r\n", __func__, n); #endif /* DEBUG_SCREEN */ return; } @@ -670,15 +681,13 @@ terminal_overwrite(EditLine *el, const Char *cp, size_t n) if (EL_HAS_MAGIC_MARGINS) { /* force the wrap to avoid the "magic" * situation */ - Char c; + wchar_t c; if ((c = el->el_display[el->el_cursor.v] [el->el_cursor.h]) != '\0') { terminal_overwrite(el, &c, (size_t)1); -#ifdef WIDECHAR while (el->el_display[el->el_cursor.v] [el->el_cursor.h] == MB_FILL_CHAR) el->el_cursor.h++; -#endif } else { terminal__putc(el, ' '); el->el_cursor.h = 1; @@ -693,7 +702,7 @@ terminal_overwrite(EditLine *el, const Char *cp, size_t n) /* terminal_deletechars(): * Delete num characters */ -protected void +libedit_private void terminal_deletechars(EditLine *el, int num) { if (num <= 0) @@ -708,7 +717,7 @@ terminal_deletechars(EditLine *el, int num) if (num > el->el_terminal.t_size.h) { #ifdef DEBUG_SCREEN (void) fprintf(el->el_errfile, - "terminal_deletechars: num is riduculous: %d\r\n", num); + "%s: num is ridiculous: %d\r\n", __func__, num); #endif /* DEBUG_SCREEN */ return; } @@ -735,8 +744,8 @@ terminal_deletechars(EditLine *el, int num) * characters in the line * Assumes MB_FILL_CHARs are present to keep column count correct */ -protected void -terminal_insertwrite(EditLine *el, Char *cp, int num) +libedit_private void +terminal_insertwrite(EditLine *el, wchar_t *cp, int num) { if (num <= 0) return; @@ -749,7 +758,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, - "StartInsert: num is riduculous: %d\r\n", num); + "%s: num is ridiculous: %d\r\n", __func__, num); #endif /* DEBUG_SCREEN */ return; } @@ -794,7 +803,7 @@ terminal_insertwrite(EditLine *el, Char *cp, int num) /* terminal_clear_EOL(): * clear to end of line. There are num characters to clear */ -protected void +libedit_private void terminal_clear_EOL(EditLine *el, int num) { int i; @@ -812,7 +821,7 @@ terminal_clear_EOL(EditLine *el, int num) /* terminal_clear_screen(): * Clear the screen */ -protected void +libedit_private void terminal_clear_screen(EditLine *el) { /* clear the whole screen and home */ @@ -833,7 +842,7 @@ terminal_clear_screen(EditLine *el) /* terminal_beep(): * Beep the way the terminal wants us */ -protected void +libedit_private void terminal_beep(EditLine *el) { if (GoodStr(T_bl)) @@ -844,7 +853,7 @@ terminal_beep(EditLine *el) } -protected void +libedit_private void terminal_get(EditLine *el, const char **term) { *term = el->el_terminal.t_name; @@ -854,7 +863,7 @@ terminal_get(EditLine *el, const char **term) /* terminal_set(): * Read in the terminal capabilities from the requested terminal */ -protected int +libedit_private int terminal_set(EditLine *el, const char *term) { int i; @@ -943,7 +952,7 @@ terminal_set(EditLine *el, const char *term) * Return the new window size in lines and cols, and * true if the size was changed. */ -protected int +libedit_private int terminal_get_size(EditLine *el, int *lins, int *cols) { @@ -979,7 +988,7 @@ terminal_get_size(EditLine *el, int *lins, int *cols) /* terminal_change_size(): * Change the size of the terminal */ -protected int +libedit_private int terminal_change_size(EditLine *el, int lins, int cols) { /* @@ -999,42 +1008,42 @@ terminal_change_size(EditLine *el, int lins, int cols) /* terminal_init_arrow(): * Initialize the arrow key bindings from termcap */ -private void +static void terminal_init_arrow(EditLine *el) { funckey_t *arrow = el->el_terminal.t_fkey; - arrow[A_K_DN].name = STR("down"); + arrow[A_K_DN].name = L"down"; arrow[A_K_DN].key = T_kd; arrow[A_K_DN].fun.cmd = ED_NEXT_HISTORY; arrow[A_K_DN].type = XK_CMD; - arrow[A_K_UP].name = STR("up"); + arrow[A_K_UP].name = L"up"; arrow[A_K_UP].key = T_ku; arrow[A_K_UP].fun.cmd = ED_PREV_HISTORY; arrow[A_K_UP].type = XK_CMD; - arrow[A_K_LT].name = STR("left"); + arrow[A_K_LT].name = L"left"; arrow[A_K_LT].key = T_kl; arrow[A_K_LT].fun.cmd = ED_PREV_CHAR; arrow[A_K_LT].type = XK_CMD; - arrow[A_K_RT].name = STR("right"); + arrow[A_K_RT].name = L"right"; arrow[A_K_RT].key = T_kr; arrow[A_K_RT].fun.cmd = ED_NEXT_CHAR; arrow[A_K_RT].type = XK_CMD; - arrow[A_K_HO].name = STR("home"); + arrow[A_K_HO].name = L"home"; arrow[A_K_HO].key = T_kh; arrow[A_K_HO].fun.cmd = ED_MOVE_TO_BEG; arrow[A_K_HO].type = XK_CMD; - arrow[A_K_EN].name = STR("end"); + arrow[A_K_EN].name = L"end"; arrow[A_K_EN].key = T_at7; arrow[A_K_EN].fun.cmd = ED_MOVE_TO_END; arrow[A_K_EN].type = XK_CMD; - arrow[A_K_DE].name = STR("delete"); + arrow[A_K_DE].name = L"delete"; arrow[A_K_DE].key = T_kD; arrow[A_K_DE].fun.cmd = ED_DELETE_NEXT_CHAR; arrow[A_K_DE].type = XK_CMD; @@ -1044,22 +1053,22 @@ terminal_init_arrow(EditLine *el) /* terminal_reset_arrow(): * Reset arrow key bindings */ -private void +static void terminal_reset_arrow(EditLine *el) { funckey_t *arrow = el->el_terminal.t_fkey; - static const Char strA[] = {033, '[', 'A', '\0'}; - static const Char strB[] = {033, '[', 'B', '\0'}; - static const Char strC[] = {033, '[', 'C', '\0'}; - static const Char strD[] = {033, '[', 'D', '\0'}; - static const Char strH[] = {033, '[', 'H', '\0'}; - static const Char strF[] = {033, '[', 'F', '\0'}; - static const Char stOA[] = {033, 'O', 'A', '\0'}; - static const Char stOB[] = {033, 'O', 'B', '\0'}; - static const Char stOC[] = {033, 'O', 'C', '\0'}; - static const Char stOD[] = {033, 'O', 'D', '\0'}; - static const Char stOH[] = {033, 'O', 'H', '\0'}; - static const Char stOF[] = {033, 'O', 'F', '\0'}; + static const wchar_t strA[] = L"\033[A"; + static const wchar_t strB[] = L"\033[B"; + static const wchar_t strC[] = L"\033[C"; + static const wchar_t strD[] = L"\033[D"; + static const wchar_t strH[] = L"\033[H"; + static const wchar_t strF[] = L"\033[F"; + static const wchar_t stOA[] = L"\033OA"; + static const wchar_t stOB[] = L"\033OB"; + static const wchar_t stOC[] = L"\033OC"; + static const wchar_t stOD[] = L"\033OD"; + static const wchar_t stOH[] = L"\033OH"; + static const wchar_t stOF[] = L"\033OF"; keymacro_add(el, strA, &arrow[A_K_UP].fun, arrow[A_K_UP].type); keymacro_add(el, strB, &arrow[A_K_DN].fun, arrow[A_K_DN].type); @@ -1094,15 +1103,15 @@ terminal_reset_arrow(EditLine *el) /* terminal_set_arrow(): * Set an arrow key binding */ -protected int -terminal_set_arrow(EditLine *el, const Char *name, keymacro_value_t *fun, +libedit_private int +terminal_set_arrow(EditLine *el, const wchar_t *name, keymacro_value_t *fun, int type) { funckey_t *arrow = el->el_terminal.t_fkey; int i; for (i = 0; i < A_K_NKEYS; i++) - if (Strcmp(name, arrow[i].name) == 0) { + if (wcscmp(name, arrow[i].name) == 0) { arrow[i].fun = *fun; arrow[i].type = type; return 0; @@ -1114,14 +1123,14 @@ terminal_set_arrow(EditLine *el, const Char *name, keymacro_value_t *fun, /* terminal_clear_arrow(): * Clear an arrow key binding */ -protected int -terminal_clear_arrow(EditLine *el, const Char *name) +libedit_private int +terminal_clear_arrow(EditLine *el, const wchar_t *name) { funckey_t *arrow = el->el_terminal.t_fkey; int i; for (i = 0; i < A_K_NKEYS; i++) - if (Strcmp(name, arrow[i].name) == 0) { + if (wcscmp(name, arrow[i].name) == 0) { arrow[i].type = XK_NOD; return 0; } @@ -1132,14 +1141,14 @@ terminal_clear_arrow(EditLine *el, const Char *name) /* terminal_print_arrow(): * Print the arrow key bindings */ -protected void -terminal_print_arrow(EditLine *el, const Char *name) +libedit_private void +terminal_print_arrow(EditLine *el, const wchar_t *name) { int i; funckey_t *arrow = el->el_terminal.t_fkey; for (i = 0; i < A_K_NKEYS; i++) - if (*name == '\0' || Strcmp(name, arrow[i].name) == 0) + if (*name == '\0' || wcscmp(name, arrow[i].name) == 0) if (arrow[i].type != XK_NOD) keymacro_kprint(el, arrow[i].name, &arrow[i].fun, arrow[i].type); @@ -1149,7 +1158,7 @@ terminal_print_arrow(EditLine *el, const Char *name) /* terminal_bind_arrow(): * Bind the arrow keys */ -protected void +libedit_private void terminal_bind_arrow(EditLine *el) { el_action_t *map; @@ -1168,8 +1177,8 @@ terminal_bind_arrow(EditLine *el) terminal_reset_arrow(el); for (i = 0; i < A_K_NKEYS; i++) { - Char wt_str[VISUAL_WIDTH_MAX]; - Char *px; + wchar_t wt_str[VISUAL_WIDTH_MAX]; + wchar_t *px; size_t n; p = el->el_terminal.t_str[arrow[i].key]; @@ -1214,7 +1223,7 @@ terminal_bind_arrow(EditLine *el) /* terminal_putc(): * Add a character */ -private int +static int terminal_putc(int c) { if (terminal_outfile == NULL) @@ -1222,7 +1231,7 @@ terminal_putc(int c) return fputc(c, terminal_outfile); } -private void +static void terminal_tputs(EditLine *el, const char *cap, int affcnt) { #ifdef _REENTRANT @@ -1238,12 +1247,12 @@ terminal_tputs(EditLine *el, const char *cap, int affcnt) /* terminal__putc(): * Add a character */ -protected int -terminal__putc(EditLine *el, Int c) +libedit_private int +terminal__putc(EditLine *el, wint_t c) { char buf[MB_LEN_MAX +1]; ssize_t i; - if (c == (Int)MB_FILL_CHAR) + if (c == (wint_t)MB_FILL_CHAR) return 0; i = ct_encode_char(buf, (size_t)MB_LEN_MAX, c); if (i <= 0) @@ -1255,7 +1264,7 @@ terminal__putc(EditLine *el, Int c) /* terminal__flush(): * Flush output */ -protected void +libedit_private void terminal__flush(EditLine *el) { @@ -1265,10 +1274,10 @@ terminal__flush(EditLine *el) /* terminal_writec(): * Write the given character out, in a human readable form */ -protected void -terminal_writec(EditLine *el, Int c) +libedit_private void +terminal_writec(EditLine *el, wint_t c) { - Char visbuf[VISUAL_WIDTH_MAX +1]; + wchar_t visbuf[VISUAL_WIDTH_MAX +1]; ssize_t vcnt = ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c); if (vcnt < 0) vcnt = 0; @@ -1281,10 +1290,10 @@ terminal_writec(EditLine *el, Int c) /* terminal_telltc(): * Print the current termcap characteristics */ -protected int +libedit_private int /*ARGSUSED*/ -terminal_telltc(EditLine *el, int argc __attribute__((__unused__)), - const Char **argv __attribute__((__unused__))) +terminal_telltc(EditLine *el, int argc __attribute__((__unused__)), + const wchar_t **argv __attribute__((__unused__))) { const struct termcapstr *t; char **ts; @@ -1307,8 +1316,8 @@ terminal_telltc(EditLine *el, int argc __attribute__((__unused__)), const char *ub; if (*ts && **ts) { ub = ct_encode_string(ct_visual_string( - ct_decode_string(*ts, &el->el_scratch)), - &el->el_scratch); + ct_decode_string(*ts, &el->el_scratch), + &el->el_visual), &el->el_scratch); } else { ub = "(empty)"; } @@ -1323,10 +1332,10 @@ terminal_telltc(EditLine *el, int argc __attribute__((__unused__)), /* terminal_settc(): * Change the current terminal characteristics */ -protected int +libedit_private int /*ARGSUSED*/ terminal_settc(EditLine *el, int argc __attribute__((__unused__)), - const Char **argv) + const wchar_t **argv) { const struct termcapstr *ts; const struct termcapval *tv; @@ -1370,7 +1379,7 @@ terminal_settc(EditLine *el, int argc __attribute__((__unused__)), el->el_terminal.t_val[tv - tval] = 0; else { (void) fprintf(el->el_errfile, - "" FSTR ": Bad value `%s'.\n", argv[0], how); + "%ls: Bad value `%s'.\n", argv[0], how); return -1; } terminal_setflags(el); @@ -1384,7 +1393,7 @@ terminal_settc(EditLine *el, int argc __attribute__((__unused__)), i = strtol(how, &ep, 10); if (*ep != '\0') { (void) fprintf(el->el_errfile, - "" FSTR ": Bad value `%s'.\n", argv[0], how); + "%ls: Bad value `%s'.\n", argv[0], how); return -1; } el->el_terminal.t_val[tv - tval] = (int) i; @@ -1402,7 +1411,7 @@ terminal_settc(EditLine *el, int argc __attribute__((__unused__)), /* terminal_gettc(): * Get the current terminal characteristics */ -protected int +libedit_private int /*ARGSUSED*/ terminal_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv) { @@ -1456,13 +1465,13 @@ terminal_gettc(EditLine *el, int argc __attribute__((__unused__)), char **argv) /* terminal_echotc(): * Print the termcap string out with variable substitution */ -protected int +libedit_private int /*ARGSUSED*/ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)), - const Char **argv) + const wchar_t **argv) { char *cap, *scap; - Char *ep; + wchar_t *ep; int arg_need, arg_cols, arg_rows; int verbose = 0, silent = 0; char *area; @@ -1493,28 +1502,28 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)), } if (!*argv || *argv[0] == '\0') return 0; - if (Strcmp(*argv, STR("tabs")) == 0) { + if (wcscmp(*argv, L"tabs") == 0) { (void) fprintf(el->el_outfile, fmts, EL_CAN_TAB ? "yes" : "no"); return 0; - } else if (Strcmp(*argv, STR("meta")) == 0) { + } else if (wcscmp(*argv, L"meta") == 0) { (void) fprintf(el->el_outfile, fmts, Val(T_km) ? "yes" : "no"); return 0; - } else if (Strcmp(*argv, STR("xn")) == 0) { + } else if (wcscmp(*argv, L"xn") == 0) { (void) fprintf(el->el_outfile, fmts, EL_HAS_MAGIC_MARGINS ? "yes" : "no"); return 0; - } else if (Strcmp(*argv, STR("am")) == 0) { + } else if (wcscmp(*argv, L"am") == 0) { (void) fprintf(el->el_outfile, fmts, EL_HAS_AUTO_MARGINS ? "yes" : "no"); return 0; - } else if (Strcmp(*argv, STR("baud")) == 0) { + } else if (wcscmp(*argv, L"baud") == 0) { (void) fprintf(el->el_outfile, fmtd, (int)el->el_tty.t_speed); return 0; - } else if (Strcmp(*argv, STR("rows")) == 0 || - Strcmp(*argv, STR("lines")) == 0) { + } else if (wcscmp(*argv, L"rows") == 0 || + wcscmp(*argv, L"lines") == 0) { (void) fprintf(el->el_outfile, fmtd, Val(T_li)); return 0; - } else if (Strcmp(*argv, STR("cols")) == 0) { + } else if (wcscmp(*argv, L"cols") == 0) { (void) fprintf(el->el_outfile, fmtd, Val(T_co)); return 0; } @@ -1530,12 +1539,12 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)), } if (t->name == NULL) { /* XXX: some systems' tgetstr needs non const */ - scap = tgetstr(ct_encode_string((Char*)*argv, &el->el_scratch), &area); + scap = tgetstr(ct_encode_string(*argv, &el->el_scratch), &area); } if (!scap || scap[0] == '\0') { if (!silent) (void) fprintf(el->el_errfile, - "echotc: Termcap parameter `" FSTR "' not found.\n", + "echotc: Termcap parameter `%ls' not found.\n", *argv); return -1; } @@ -1578,7 +1587,7 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)), if (*argv && *argv[0]) { if (!silent) (void) fprintf(el->el_errfile, - "echotc: Warning: Extra argument `" FSTR "'.\n", + "echotc: Warning: Extra argument `%ls'.\n", *argv); return -1; } @@ -1593,11 +1602,11 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)), return -1; } arg_cols = 0; - i = Strtol(*argv, &ep, 10); + i = wcstol(*argv, &ep, 10); if (*ep != '\0' || i < 0) { if (!silent) (void) fprintf(el->el_errfile, - "echotc: Bad value `" FSTR "' for rows.\n", + "echotc: Bad value `%ls' for rows.\n", *argv); return -1; } @@ -1606,7 +1615,7 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)), if (*argv && *argv[0]) { if (!silent) (void) fprintf(el->el_errfile, - "echotc: Warning: Extra argument `" FSTR + "echotc: Warning: Extra argument `%ls" "'.\n", *argv); return -1; } @@ -1627,11 +1636,11 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)), "echotc: Warning: Missing argument.\n"); return -1; } - i = Strtol(*argv, &ep, 10); + i = wcstol(*argv, &ep, 10); if (*ep != '\0' || i < 0) { if (!silent) (void) fprintf(el->el_errfile, - "echotc: Bad value `" FSTR "' for cols.\n", + "echotc: Bad value `%ls' for cols.\n", *argv); return -1; } @@ -1643,11 +1652,11 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)), "echotc: Warning: Missing argument.\n"); return -1; } - i = Strtol(*argv, &ep, 10); + i = wcstol(*argv, &ep, 10); if (*ep != '\0' || i < 0) { if (!silent) (void) fprintf(el->el_errfile, - "echotc: Bad value `" FSTR "' for rows.\n", + "echotc: Bad value `%ls' for rows.\n", *argv); return -1; } @@ -1655,14 +1664,14 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)), if (*ep != '\0') { if (!silent) (void) fprintf(el->el_errfile, - "echotc: Bad value `" FSTR "'.\n", *argv); + "echotc: Bad value `%ls'.\n", *argv); return -1; } argv++; if (*argv && *argv[0]) { if (!silent) (void) fprintf(el->el_errfile, - "echotc: Warning: Extra argument `" FSTR + "echotc: Warning: Extra argument `%ls" "'.\n", *argv); return -1; } diff --git a/contrib/libedit/src/terminal.h b/contrib/libedit/src/terminal.h index 42122a79c2..e458369548 100644 --- a/contrib/libedit/src/terminal.h +++ b/contrib/libedit/src/terminal.h @@ -1,4 +1,4 @@ -/* $NetBSD: terminal.h,v 1.4 2012/03/24 20:09:30 christos Exp $ */ +/* $NetBSD: terminal.h,v 1.9 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,10 +40,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 */ + const wchar_t *name; /* name of the key */ int key; /* Index in termcap table */ keymacro_value_t fun; /* Function bound to it */ int type; /* Type of function */ @@ -91,31 +89,32 @@ extern char* tgoto(const char*, int, int); extern char* tgetstr(char*, char**); #endif -protected void terminal_move_to_line(EditLine *, int); -protected void terminal_move_to_char(EditLine *, int); -protected void terminal_clear_EOL(EditLine *, int); -protected void terminal_overwrite(EditLine *, const Char *, size_t); -protected void terminal_insertwrite(EditLine *, Char *, int); -protected void terminal_deletechars(EditLine *, int); -protected void terminal_clear_screen(EditLine *); -protected void terminal_beep(EditLine *); -protected int terminal_change_size(EditLine *, int, int); -protected int terminal_get_size(EditLine *, int *, int *); -protected int terminal_init(EditLine *); -protected void terminal_bind_arrow(EditLine *); -protected void terminal_print_arrow(EditLine *, const Char *); -protected int terminal_clear_arrow(EditLine *, const Char *); -protected int terminal_set_arrow(EditLine *, const Char *, keymacro_value_t *, int); -protected void terminal_end(EditLine *); -protected void terminal_get(EditLine *, const char **); -protected int terminal_set(EditLine *, const char *); -protected int terminal_settc(EditLine *, int, const Char **); -protected int terminal_gettc(EditLine *, int, char **); -protected int terminal_telltc(EditLine *, int, const Char **); -protected int terminal_echotc(EditLine *, int, const Char **); -protected void terminal_writec(EditLine *, Int); -protected int terminal__putc(EditLine *, Int); -protected void terminal__flush(EditLine *); +libedit_private void terminal_move_to_line(EditLine *, int); +libedit_private void terminal_move_to_char(EditLine *, int); +libedit_private void terminal_clear_EOL(EditLine *, int); +libedit_private void terminal_overwrite(EditLine *, const wchar_t *, size_t); +libedit_private void terminal_insertwrite(EditLine *, wchar_t *, int); +libedit_private void terminal_deletechars(EditLine *, int); +libedit_private void terminal_clear_screen(EditLine *); +libedit_private void terminal_beep(EditLine *); +libedit_private int terminal_change_size(EditLine *, int, int); +libedit_private int terminal_get_size(EditLine *, int *, int *); +libedit_private int terminal_init(EditLine *); +libedit_private void terminal_bind_arrow(EditLine *); +libedit_private void terminal_print_arrow(EditLine *, const wchar_t *); +libedit_private int terminal_clear_arrow(EditLine *, const wchar_t *); +libedit_private int terminal_set_arrow(EditLine *, const wchar_t *, + keymacro_value_t *, int); +libedit_private void terminal_end(EditLine *); +libedit_private void terminal_get(EditLine *, const char **); +libedit_private int terminal_set(EditLine *, const char *); +libedit_private int terminal_settc(EditLine *, int, const wchar_t **); +libedit_private int terminal_gettc(EditLine *, int, char **); +libedit_private int terminal_telltc(EditLine *, int, const wchar_t **); +libedit_private int terminal_echotc(EditLine *, int, const wchar_t **); +libedit_private void terminal_writec(EditLine *, wint_t); +libedit_private int terminal__putc(EditLine *, wint_t); +libedit_private void terminal__flush(EditLine *); /* * Easy access macros diff --git a/contrib/libedit/src/tokenizer.c b/contrib/libedit/src/tokenizer.c index 5cb960dfe8..5efb43275e 100644 --- a/contrib/libedit/src/tokenizer.c +++ b/contrib/libedit/src/tokenizer.c @@ -1,4 +1,4 @@ -/* $NetBSD: tokenizer.c,v 1.21 2011/08/16 16:25:15 christos Exp $ */ +/* $NetBSD: tokenizer.c,v 1.28 2016/04/11 18:56:31 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tokenizer.c,v 1.21 2011/08/16 16:25:15 christos Exp $"); +__RCSID("$NetBSD: tokenizer.c,v 1.28 2016/04/11 18:56:31 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -48,10 +48,10 @@ __RCSID("$NetBSD: tokenizer.c,v 1.21 2011/08/16 16:25:15 christos Exp $"); /* * tokenize.c: Bourne shell like tokenizer */ -#include #include +#include + #include "histedit.h" -#include "chartype.h" typedef enum { Q_none, Q_single, Q_double, Q_one, Q_doubleone @@ -68,8 +68,22 @@ typedef enum { #define tok_malloc(a) malloc(a) #define tok_free(a) free(a) #define tok_realloc(a, b) realloc(a, b) -#define tok_strdup(a) Strdup(a) +#ifdef NARROWCHAR +#define Char char +#define FUN(prefix, rest) prefix ## _ ## rest +#define TYPE(type) type +#define STR(x) x +#define Strchr(s, c) strchr(s, c) +#define tok_strdup(s) strdup(s) +#else +#define Char wchar_t +#define FUN(prefix, rest) prefix ## _w ## rest +#define TYPE(type) type ## W +#define STR(x) L ## x +#define Strchr(s, c) wcschr(s, c) +#define tok_strdup(s) wcsdup(s) +#endif struct TYPE(tokenizer) { Char *ifs; /* In field separator */ @@ -83,13 +97,13 @@ struct TYPE(tokenizer) { }; -private void FUN(tok,finish)(TYPE(Tokenizer) *); +static void FUN(tok,finish)(TYPE(Tokenizer) *); /* FUN(tok,finish)(): * Finish a word in the tokenizer. */ -private void +static void FUN(tok,finish)(TYPE(Tokenizer) *tok) { @@ -106,7 +120,7 @@ FUN(tok,finish)(TYPE(Tokenizer) *tok) /* FUN(tok,init)(): * Initialize the tokenizer */ -public TYPE(Tokenizer) * +TYPE(Tokenizer) * FUN(tok,init)(const Char *ifs) { TYPE(Tokenizer) *tok = tok_malloc(sizeof(*tok)); @@ -147,7 +161,7 @@ FUN(tok,init)(const Char *ifs) /* FUN(tok,reset)(): * Reset the tokenizer */ -public void +void FUN(tok,reset)(TYPE(Tokenizer) *tok) { @@ -162,7 +176,7 @@ FUN(tok,reset)(TYPE(Tokenizer) *tok) /* FUN(tok,end)(): * Clean up */ -public void +void FUN(tok,end)(TYPE(Tokenizer) *tok) { @@ -191,7 +205,7 @@ FUN(tok,end)(TYPE(Tokenizer) *tok) * cursorc if !NULL, argv element containing cursor * cursorv if !NULL, offset in argv[cursorc] of cursor */ -public int +int FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line, int *argc, const Char ***argv, int *cursorc, int *cursoro) { @@ -416,8 +430,10 @@ 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) + if (p == NULL) { + tok->amax -= AINCR; return -1; + } tok->argv = p; } } @@ -440,7 +456,7 @@ FUN(tok,line)(TYPE(Tokenizer) *tok, const TYPE(LineInfo) *line, * Simpler version of tok_line, taking a NUL terminated line * and splitting into words, ignoring cursor state. */ -public int +int FUN(tok,str)(TYPE(Tokenizer) *tok, const Char *line, int *argc, const Char ***argv) { @@ -449,5 +465,5 @@ FUN(tok,str)(TYPE(Tokenizer) *tok, const Char *line, int *argc, memset(&li, 0, sizeof(li)); li.buffer = line; li.cursor = li.lastchar = Strchr(line, '\0'); - return FUN(tok,line(tok, &li, argc, argv, NULL, NULL)); + return FUN(tok,line)(tok, &li, argc, argv, NULL, NULL); } diff --git a/contrib/libedit/src/tokenizern.c b/contrib/libedit/src/tokenizern.c new file mode 100644 index 0000000000..5846b60643 --- /dev/null +++ b/contrib/libedit/src/tokenizern.c @@ -0,0 +1,3 @@ +#include "config.h" +#define NARROWCHAR +#include "tokenizer.c" diff --git a/contrib/libedit/src/tty.c b/contrib/libedit/src/tty.c index ce7d86c07d..f524da4734 100644 --- a/contrib/libedit/src/tty.c +++ b/contrib/libedit/src/tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.46 2014/06/18 18:52:49 christos Exp $ */ +/* $NetBSD: tty.c,v 1.65 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)tty.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: tty.c,v 1.46 2014/06/18 18:52:49 christos Exp $"); +__RCSID("$NetBSD: tty.c,v 1.65 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -46,11 +46,14 @@ __RCSID("$NetBSD: tty.c,v 1.46 2014/06/18 18:52:49 christos Exp $"); */ #include #include -#include /* for isatty */ -#include /* for ffs */ #include /* for abort */ +#include +#include /* for ffs */ +#include /* for isatty */ + #include "el.h" -#include "tty.h" +#include "fcns.h" +#include "parse.h" typedef struct ttymodes_t { const char *m_name; @@ -59,12 +62,12 @@ typedef struct ttymodes_t { } ttymodes_t; typedef struct ttymap_t { - Int nch, och; /* Internal and termio rep of chars */ + wint_t nch, och; /* Internal and termio rep of chars */ el_action_t bind[3]; /* emacs, vi, and vi-cmd */ } ttymap_t; -private const ttyperm_t ttyperm = { +static const ttyperm_t ttyperm = { { {"iflag:", ICRNL, (INLCR | IGNCR)}, {"oflag:", (OPOST | ONLCR), ONLRET}, @@ -92,7 +95,7 @@ private const ttyperm_t ttyperm = { } }; -private const ttychar_t ttychar = { +static const ttychar_t ttychar = { { CINTR, CQUIT, CERASE, CKILL, CEOF, CEOL, CEOL2, CSWTCH, @@ -122,7 +125,7 @@ private const ttychar_t ttychar = { } }; -private const ttymap_t tty_map[] = { +static const ttymap_t tty_map[] = { #ifdef VERASE {C_ERASE, VERASE, {EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}}, @@ -155,11 +158,11 @@ private const ttymap_t tty_map[] = { {C_LNEXT, VLNEXT, {ED_QUOTED_INSERT, ED_QUOTED_INSERT, ED_UNASSIGNED}}, #endif /* VLNEXT */ - {(Int)-1, (Int)-1, + {(wint_t)-1, (wint_t)-1, {ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED}} }; -private const ttymodes_t ttymodes[] = { +static const ttymodes_t ttymodes[] = { #ifdef IGNBRK {"ignbrk", IGNBRK, MD_INP}, #endif /* IGNBRK */ @@ -453,21 +456,21 @@ private const ttymodes_t ttymodes[] = { #define tty__geteightbit(td) (((td)->c_cflag & CSIZE) == CS8) #define tty__cooked_mode(td) ((td)->c_lflag & ICANON) -private int tty_getty(EditLine *, struct termios *); -private int tty_setty(EditLine *, int, const struct termios *); -private int tty__getcharindex(int); -private void tty__getchar(struct termios *, unsigned char *); -private void tty__setchar(struct termios *, unsigned char *); -private speed_t tty__getspeed(struct termios *); -private int tty_setup(EditLine *); -private void tty_setup_flags(EditLine *, struct termios *, int); +static int tty_getty(EditLine *, struct termios *); +static int tty_setty(EditLine *, int, const struct termios *); +static int tty__getcharindex(int); +static void tty__getchar(struct termios *, unsigned char *); +static void tty__setchar(struct termios *, unsigned char *); +static speed_t tty__getspeed(struct termios *); +static int tty_setup(EditLine *); +static void tty_setup_flags(EditLine *, struct termios *, int); #define t_qu t_ts /* tty_getty(): * Wrapper for tcgetattr to handle EINTR */ -private int +static int tty_getty(EditLine *el, struct termios *t) { int rv; @@ -479,7 +482,7 @@ tty_getty(EditLine *el, struct termios *t) /* tty_setty(): * Wrapper for tcsetattr to handle EINTR */ -private int +static int tty_setty(EditLine *el, int action, const struct termios *t) { int rv; @@ -491,7 +494,7 @@ tty_setty(EditLine *el, int action, const struct termios *t) /* tty_setup(): * Get the tty parameters and initialize the editing state */ -private int +static int tty_setup(EditLine *el) { int rst = 1; @@ -499,6 +502,9 @@ tty_setup(EditLine *el) if (el->el_flags & EDIT_DISABLED) return 0; + if (el->el_tty.t_initialized) + return -1; + if (!isatty(el->el_outfd)) { #ifdef DEBUG_TTY (void) fprintf(el->el_errfile, "%s: isatty: %s\n", __func__, @@ -558,15 +564,17 @@ 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; } -protected int +libedit_private int tty_init(EditLine *el) { el->el_tty.t_mode = EX_IO; el->el_tty.t_vdisable = _POSIX_VDISABLE; + el->el_tty.t_initialized = 0; (void) memcpy(el->el_tty.t_t, ttyperm, sizeof(ttyperm_t)); (void) memcpy(el->el_tty.t_c, ttychar, sizeof(ttychar_t)); return tty_setup(el); @@ -576,10 +584,16 @@ tty_init(EditLine *el) /* tty_end(): * Restore the tty to its original settings */ -protected void +libedit_private void /*ARGSUSED*/ 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, @@ -592,7 +606,7 @@ tty_end(EditLine *el) /* tty__getspeed(): * Get the tty speed */ -private speed_t +static speed_t tty__getspeed(struct termios *td) { speed_t spd; @@ -605,7 +619,7 @@ tty__getspeed(struct termios *td) /* tty__getspeed(): * Return the index of the asked char in the c_cc array */ -private int +static int tty__getcharindex(int i) { switch (i) { @@ -713,7 +727,7 @@ tty__getcharindex(int i) /* tty__getchar(): * Get the tty characters */ -private void +static void tty__getchar(struct termios *td, unsigned char *s) { @@ -795,7 +809,7 @@ tty__getchar(struct termios *td, unsigned char *s) /* tty__setchar(): * Set the tty characters */ -private void +static void tty__setchar(struct termios *td, unsigned char *s) { @@ -877,13 +891,13 @@ tty__setchar(struct termios *td, unsigned char *s) /* tty_bind_char(): * Rebind the editline functions */ -protected void +libedit_private void tty_bind_char(EditLine *el, int force) { unsigned char *t_n = el->el_tty.t_c[ED_IO]; unsigned char *t_o = el->el_tty.t_ed.c_cc; - Char new[2], old[2]; + wchar_t new[2], old[2]; const ttymap_t *tp; el_action_t *map, *alt; const el_action_t *dmap, *dalt; @@ -899,28 +913,30 @@ tty_bind_char(EditLine *el, int force) dalt = NULL; } - for (tp = tty_map; tp->nch != (Int)-1; tp++) { - new[0] = t_n[tp->nch]; - old[0] = t_o[tp->och]; + for (tp = tty_map; tp->nch != (wint_t)-1; tp++) { + new[0] = (wchar_t)t_n[tp->nch]; + old[0] = (wchar_t)t_o[tp->och]; if (new[0] == old[0] && !force) continue; /* Put the old default binding back, and set the new binding */ keymacro_clear(el, map, old); - map[UC(old[0])] = dmap[UC(old[0])]; + map[(unsigned char)old[0]] = dmap[(unsigned char)old[0]]; keymacro_clear(el, map, new); /* MAP_VI == 1, MAP_EMACS == 0... */ - map[UC(new[0])] = tp->bind[el->el_map.type]; + map[(unsigned char)new[0]] = tp->bind[el->el_map.type]; if (dalt) { keymacro_clear(el, alt, old); - alt[UC(old[0])] = dalt[UC(old[0])]; + alt[(unsigned char)old[0]] = + dalt[(unsigned char)old[0]]; keymacro_clear(el, alt, new); - alt[UC(new[0])] = tp->bind[el->el_map.type + 1]; + alt[(unsigned char)new[0]] = + tp->bind[el->el_map.type + 1]; } } } -private tcflag_t * +static tcflag_t * tty__get_flag(struct termios *t, int kind) { switch (kind) { case MD_INP: @@ -938,7 +954,7 @@ tty__get_flag(struct termios *t, int kind) { } -private tcflag_t +static tcflag_t tty_update_flag(EditLine *el, tcflag_t f, int mode, int kind) { f &= ~el->el_tty.t_t[mode][kind].t_clrmask; @@ -947,7 +963,7 @@ tty_update_flag(EditLine *el, tcflag_t f, int mode, int kind) } -private void +static void tty_update_flags(EditLine *el, int kind) { tcflag_t *tt, *ed, *ex; @@ -962,7 +978,7 @@ tty_update_flags(EditLine *el, int kind) } -private void +static void tty_update_char(EditLine *el, int mode, int c) { if (!((el->el_tty.t_t[mode][MD_CHAR].t_setmask & C_SH(c))) && (el->el_tty.t_c[TS_IO][c] != el->el_tty.t_c[EX_IO][c])) @@ -973,9 +989,9 @@ 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 +libedit_private int tty_rawmode(EditLine *el) { @@ -1030,7 +1046,7 @@ tty_rawmode(EditLine *el) if (i != C_NCC) { /* - * Propagate changes only to the unprotected + * Propagate changes only to the unlibedit_private * chars that have been modified just now. */ for (i = 0; i < C_NCC; i++) @@ -1060,7 +1076,7 @@ tty_rawmode(EditLine *el) /* tty_cookedmode(): * Set the tty back to normal mode */ -protected int +libedit_private int tty_cookedmode(EditLine *el) { /* set tty in normal setup */ @@ -1085,7 +1101,7 @@ tty_cookedmode(EditLine *el) /* tty_quotemode(): * Turn on quote mode */ -protected int +libedit_private int tty_quotemode(EditLine *el) { if (el->el_tty.t_mode == QU_IO) @@ -1110,7 +1126,7 @@ tty_quotemode(EditLine *el) /* tty_noquotemode(): * Turn off quote mode */ -protected int +libedit_private int tty_noquotemode(EditLine *el) { @@ -1131,14 +1147,15 @@ tty_noquotemode(EditLine *el) /* tty_stty(): * Stty builtin */ -protected int +libedit_private int /*ARGSUSED*/ -tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv) +tty_stty(EditLine *el, int argc __attribute__((__unused__)), + const wchar_t **argv) { const ttymodes_t *m; char x; int aflag = 0; - const Char *s, *d; + const wchar_t *s, *d; char name[EL_BUFSIZ]; struct termios *tios = &el->el_tty.t_ex; int z = EX_IO; @@ -1171,8 +1188,8 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv) break; default: (void) fprintf(el->el_errfile, - "%s: Unknown switch `%c'.\n", - name, argv[0][1]); + "%s: Unknown switch `%lc'.\n", + name, (wint_t)argv[0][1]); return -1; } @@ -1222,7 +1239,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv) return 0; } while (argv && (s = *argv++)) { - const Char *p; + const wchar_t *p; switch (*s) { case '+': case '-': @@ -1233,7 +1250,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv) break; } d = s; - p = Strchr(s, '='); + p = wcschr(s, L'='); for (m = ttymodes; m->m_name; m++) if ((p ? strncmp(m->m_name, ct_encode_string(d, &el->el_scratch), (size_t)(p - d)) : @@ -1244,7 +1261,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv) if (!m->m_name) { (void) fprintf(el->el_errfile, - "%s: Invalid argument `" FSTR "'.\n", name, d); + "%s: Invalid argument `%ls'.\n", name, d); return -1; } if (p) { @@ -1293,7 +1310,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv) /* tty_printchar(): * DEbugging routine to print the tty characters */ -private void +static void tty_printchar(EditLine *el, unsigned char *s) { ttyperm_t *m; @@ -1314,7 +1331,7 @@ tty_printchar(EditLine *el, unsigned char *s) #endif /* notyet */ -private void +static void tty_setup_flags(EditLine *el, struct termios *tios, int mode) { int kind; diff --git a/contrib/libedit/src/tty.h b/contrib/libedit/src/tty.h index 0bf4b64ce4..2603e1ad2d 100644 --- a/contrib/libedit/src/tty.h +++ b/contrib/libedit/src/tty.h @@ -1,4 +1,4 @@ -/* $NetBSD: tty.h,v 1.15 2014/05/19 19:54:12 christos Exp $ */ +/* $NetBSD: tty.h,v 1.21 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,8 +40,6 @@ #ifndef _h_el_tty #define _h_el_tty -#include "sys.h" -#include "histedit.h" #include #include @@ -458,14 +456,14 @@ typedef struct { typedef unsigned char ttychar_t[NN_IO][C_NCC]; -protected int tty_init(EditLine *); -protected void tty_end(EditLine *); -protected int tty_stty(EditLine *, int, const Char **); -protected int tty_rawmode(EditLine *); -protected int tty_cookedmode(EditLine *); -protected int tty_quotemode(EditLine *); -protected int tty_noquotemode(EditLine *); -protected void tty_bind_char(EditLine *, int); +libedit_private int tty_init(EditLine *); +libedit_private void tty_end(EditLine *); +libedit_private int tty_stty(EditLine *, int, const wchar_t **); +libedit_private int tty_rawmode(EditLine *); +libedit_private int tty_cookedmode(EditLine *); +libedit_private int tty_quotemode(EditLine *); +libedit_private int tty_noquotemode(EditLine *); +libedit_private void tty_bind_char(EditLine *, int); typedef struct { ttyperm_t t_t; @@ -474,8 +472,9 @@ typedef struct { int t_tabs; int t_eight; speed_t t_speed; - int t_mode; + unsigned char t_mode; unsigned char t_vdisable; + unsigned char t_initialized; } el_tty_t; diff --git a/contrib/libedit/src/unvis.c b/contrib/libedit/src/unvis.c deleted file mode 100644 index d2c65aa3d5..0000000000 --- a/contrib/libedit/src/unvis.c +++ /dev/null @@ -1,560 +0,0 @@ -/* $NetBSD: unvis.c,v 1.44 2014/09/26 15:43:36 roy Exp $ */ - -/*- - * Copyright (c) 1989, 1993 - * The Regents of the University of California. 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. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include "config.h" -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93"; -#else -__RCSID("$NetBSD: unvis.c,v 1.44 2014/09/26 15:43:36 roy Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include - -#include -#include -#ifdef HAVE_STDINT_H -#include -#endif -#include -#include -#include - -#ifdef __weak_alias -__weak_alias(strnunvisx,_strnunvisx) -#endif - -#if !HAVE_VIS -/* - * decode driven by state machine - */ -#define S_GROUND 0 /* haven't seen escape char */ -#define S_START 1 /* start decoding special sequence */ -#define S_META 2 /* metachar started (M) */ -#define S_META1 3 /* metachar more, regular char (-) */ -#define S_CTRL 4 /* control char started (^) */ -#define S_OCTAL2 5 /* octal digit 2 */ -#define S_OCTAL3 6 /* octal digit 3 */ -#define S_HEX 7 /* mandatory hex digit */ -#define S_HEX1 8 /* http hex digit */ -#define S_HEX2 9 /* http hex digit 2 */ -#define S_MIME1 10 /* mime hex digit 1 */ -#define S_MIME2 11 /* mime hex digit 2 */ -#define S_EATCRNL 12 /* mime eating CRNL */ -#define S_AMP 13 /* seen & */ -#define S_NUMBER 14 /* collecting number */ -#define S_STRING 15 /* collecting string */ - -#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') -#define xtod(c) (isdigit(c) ? (c - '0') : ((tolower(c) - 'a') + 10)) -#define XTOD(c) (isdigit(c) ? (c - '0') : ((c - 'A') + 10)) - -/* - * RFC 1866 - */ -static const struct nv { - char name[7]; - uint8_t value; -} nv[] = { - { "AElig", 198 }, /* capital AE diphthong (ligature) */ - { "Aacute", 193 }, /* capital A, acute accent */ - { "Acirc", 194 }, /* capital A, circumflex accent */ - { "Agrave", 192 }, /* capital A, grave accent */ - { "Aring", 197 }, /* capital A, ring */ - { "Atilde", 195 }, /* capital A, tilde */ - { "Auml", 196 }, /* capital A, dieresis or umlaut mark */ - { "Ccedil", 199 }, /* capital C, cedilla */ - { "ETH", 208 }, /* capital Eth, Icelandic */ - { "Eacute", 201 }, /* capital E, acute accent */ - { "Ecirc", 202 }, /* capital E, circumflex accent */ - { "Egrave", 200 }, /* capital E, grave accent */ - { "Euml", 203 }, /* capital E, dieresis or umlaut mark */ - { "Iacute", 205 }, /* capital I, acute accent */ - { "Icirc", 206 }, /* capital I, circumflex accent */ - { "Igrave", 204 }, /* capital I, grave accent */ - { "Iuml", 207 }, /* capital I, dieresis or umlaut mark */ - { "Ntilde", 209 }, /* capital N, tilde */ - { "Oacute", 211 }, /* capital O, acute accent */ - { "Ocirc", 212 }, /* capital O, circumflex accent */ - { "Ograve", 210 }, /* capital O, grave accent */ - { "Oslash", 216 }, /* capital O, slash */ - { "Otilde", 213 }, /* capital O, tilde */ - { "Ouml", 214 }, /* capital O, dieresis or umlaut mark */ - { "THORN", 222 }, /* capital THORN, Icelandic */ - { "Uacute", 218 }, /* capital U, acute accent */ - { "Ucirc", 219 }, /* capital U, circumflex accent */ - { "Ugrave", 217 }, /* capital U, grave accent */ - { "Uuml", 220 }, /* capital U, dieresis or umlaut mark */ - { "Yacute", 221 }, /* capital Y, acute accent */ - { "aacute", 225 }, /* small a, acute accent */ - { "acirc", 226 }, /* small a, circumflex accent */ - { "acute", 180 }, /* acute accent */ - { "aelig", 230 }, /* small ae diphthong (ligature) */ - { "agrave", 224 }, /* small a, grave accent */ - { "amp", 38 }, /* ampersand */ - { "aring", 229 }, /* small a, ring */ - { "atilde", 227 }, /* small a, tilde */ - { "auml", 228 }, /* small a, dieresis or umlaut mark */ - { "brvbar", 166 }, /* broken (vertical) bar */ - { "ccedil", 231 }, /* small c, cedilla */ - { "cedil", 184 }, /* cedilla */ - { "cent", 162 }, /* cent sign */ - { "copy", 169 }, /* copyright sign */ - { "curren", 164 }, /* general currency sign */ - { "deg", 176 }, /* degree sign */ - { "divide", 247 }, /* divide sign */ - { "eacute", 233 }, /* small e, acute accent */ - { "ecirc", 234 }, /* small e, circumflex accent */ - { "egrave", 232 }, /* small e, grave accent */ - { "eth", 240 }, /* small eth, Icelandic */ - { "euml", 235 }, /* small e, dieresis or umlaut mark */ - { "frac12", 189 }, /* fraction one-half */ - { "frac14", 188 }, /* fraction one-quarter */ - { "frac34", 190 }, /* fraction three-quarters */ - { "gt", 62 }, /* greater than */ - { "iacute", 237 }, /* small i, acute accent */ - { "icirc", 238 }, /* small i, circumflex accent */ - { "iexcl", 161 }, /* inverted exclamation mark */ - { "igrave", 236 }, /* small i, grave accent */ - { "iquest", 191 }, /* inverted question mark */ - { "iuml", 239 }, /* small i, dieresis or umlaut mark */ - { "laquo", 171 }, /* angle quotation mark, left */ - { "lt", 60 }, /* less than */ - { "macr", 175 }, /* macron */ - { "micro", 181 }, /* micro sign */ - { "middot", 183 }, /* middle dot */ - { "nbsp", 160 }, /* no-break space */ - { "not", 172 }, /* not sign */ - { "ntilde", 241 }, /* small n, tilde */ - { "oacute", 243 }, /* small o, acute accent */ - { "ocirc", 244 }, /* small o, circumflex accent */ - { "ograve", 242 }, /* small o, grave accent */ - { "ordf", 170 }, /* ordinal indicator, feminine */ - { "ordm", 186 }, /* ordinal indicator, masculine */ - { "oslash", 248 }, /* small o, slash */ - { "otilde", 245 }, /* small o, tilde */ - { "ouml", 246 }, /* small o, dieresis or umlaut mark */ - { "para", 182 }, /* pilcrow (paragraph sign) */ - { "plusmn", 177 }, /* plus-or-minus sign */ - { "pound", 163 }, /* pound sterling sign */ - { "quot", 34 }, /* double quote */ - { "raquo", 187 }, /* angle quotation mark, right */ - { "reg", 174 }, /* registered sign */ - { "sect", 167 }, /* section sign */ - { "shy", 173 }, /* soft hyphen */ - { "sup1", 185 }, /* superscript one */ - { "sup2", 178 }, /* superscript two */ - { "sup3", 179 }, /* superscript three */ - { "szlig", 223 }, /* small sharp s, German (sz ligature) */ - { "thorn", 254 }, /* small thorn, Icelandic */ - { "times", 215 }, /* multiply sign */ - { "uacute", 250 }, /* small u, acute accent */ - { "ucirc", 251 }, /* small u, circumflex accent */ - { "ugrave", 249 }, /* small u, grave accent */ - { "uml", 168 }, /* umlaut (dieresis) */ - { "uuml", 252 }, /* small u, dieresis or umlaut mark */ - { "yacute", 253 }, /* small y, acute accent */ - { "yen", 165 }, /* yen sign */ - { "yuml", 255 }, /* small y, dieresis or umlaut mark */ -}; - -/* - * unvis - decode characters previously encoded by vis - */ -int -unvis(char *cp, int c, int *astate, int flag) -{ - unsigned char uc = (unsigned char)c; - unsigned char st, ia, is, lc; - -/* - * Bottom 8 bits of astate hold the state machine state. - * Top 8 bits hold the current character in the http 1866 nv string decoding - */ -#define GS(a) ((a) & 0xff) -#define SS(a, b) (((uint32_t)(a) << 24) | (b)) -#define GI(a) ((uint32_t)(a) >> 24) - - _DIAGASSERT(cp != NULL); - _DIAGASSERT(astate != NULL); - st = GS(*astate); - - if (flag & UNVIS_END) { - switch (st) { - case S_OCTAL2: - case S_OCTAL3: - case S_HEX2: - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case S_GROUND: - return UNVIS_NOCHAR; - default: - return UNVIS_SYNBAD; - } - } - - switch (st) { - - case S_GROUND: - *cp = 0; - if ((flag & VIS_NOESCAPE) == 0 && c == '\\') { - *astate = SS(0, S_START); - return UNVIS_NOCHAR; - } - if ((flag & VIS_HTTP1808) && c == '%') { - *astate = SS(0, S_HEX1); - return UNVIS_NOCHAR; - } - if ((flag & VIS_HTTP1866) && c == '&') { - *astate = SS(0, S_AMP); - return UNVIS_NOCHAR; - } - if ((flag & VIS_MIMESTYLE) && c == '=') { - *astate = SS(0, S_MIME1); - return UNVIS_NOCHAR; - } - *cp = c; - return UNVIS_VALID; - - case S_START: - switch(c) { - case '\\': - *cp = c; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case '0': case '1': case '2': case '3': - case '4': case '5': case '6': case '7': - *cp = (c - '0'); - *astate = SS(0, S_OCTAL2); - return UNVIS_NOCHAR; - case 'M': - *cp = (char)0200; - *astate = SS(0, S_META); - return UNVIS_NOCHAR; - case '^': - *astate = SS(0, S_CTRL); - return UNVIS_NOCHAR; - case 'n': - *cp = '\n'; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case 'r': - *cp = '\r'; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case 'b': - *cp = '\b'; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case 'a': - *cp = '\007'; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case 'v': - *cp = '\v'; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case 't': - *cp = '\t'; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case 'f': - *cp = '\f'; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case 's': - *cp = ' '; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case 'E': - *cp = '\033'; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - case 'x': - *astate = SS(0, S_HEX); - return UNVIS_NOCHAR; - case '\n': - /* - * hidden newline - */ - *astate = SS(0, S_GROUND); - return UNVIS_NOCHAR; - case '$': - /* - * hidden marker - */ - *astate = SS(0, S_GROUND); - return UNVIS_NOCHAR; - default: - if (isgraph(c)) { - *cp = c; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - } - } - goto bad; - - case S_META: - if (c == '-') - *astate = SS(0, S_META1); - else if (c == '^') - *astate = SS(0, S_CTRL); - else - goto bad; - return UNVIS_NOCHAR; - - case S_META1: - *astate = SS(0, S_GROUND); - *cp |= c; - return UNVIS_VALID; - - case S_CTRL: - if (c == '?') - *cp |= 0177; - else - *cp |= c & 037; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - - case S_OCTAL2: /* second possible octal digit */ - if (isoctal(uc)) { - /* - * yes - and maybe a third - */ - *cp = (*cp << 3) + (c - '0'); - *astate = SS(0, S_OCTAL3); - return UNVIS_NOCHAR; - } - /* - * no - done with current sequence, push back passed char - */ - *astate = SS(0, S_GROUND); - return UNVIS_VALIDPUSH; - - case S_OCTAL3: /* third possible octal digit */ - *astate = SS(0, S_GROUND); - if (isoctal(uc)) { - *cp = (*cp << 3) + (c - '0'); - return UNVIS_VALID; - } - /* - * we were done, push back passed char - */ - return UNVIS_VALIDPUSH; - - case S_HEX: - if (!isxdigit(uc)) - goto bad; - /*FALLTHROUGH*/ - case S_HEX1: - if (isxdigit(uc)) { - *cp = xtod(uc); - *astate = SS(0, S_HEX2); - return UNVIS_NOCHAR; - } - /* - * no - done with current sequence, push back passed char - */ - *astate = SS(0, S_GROUND); - return UNVIS_VALIDPUSH; - - case S_HEX2: - *astate = S_GROUND; - if (isxdigit(uc)) { - *cp = xtod(uc) | (*cp << 4); - return UNVIS_VALID; - } - return UNVIS_VALIDPUSH; - - case S_MIME1: - if (uc == '\n' || uc == '\r') { - *astate = SS(0, S_EATCRNL); - return UNVIS_NOCHAR; - } - if (isxdigit(uc) && (isdigit(uc) || isupper(uc))) { - *cp = XTOD(uc); - *astate = SS(0, S_MIME2); - return UNVIS_NOCHAR; - } - goto bad; - - case S_MIME2: - if (isxdigit(uc) && (isdigit(uc) || isupper(uc))) { - *astate = SS(0, S_GROUND); - *cp = XTOD(uc) | (*cp << 4); - return UNVIS_VALID; - } - goto bad; - - case S_EATCRNL: - switch (uc) { - case '\r': - case '\n': - return UNVIS_NOCHAR; - case '=': - *astate = SS(0, S_MIME1); - return UNVIS_NOCHAR; - default: - *cp = uc; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - } - - case S_AMP: - *cp = 0; - if (uc == '#') { - *astate = SS(0, S_NUMBER); - return UNVIS_NOCHAR; - } - *astate = SS(0, S_STRING); - /*FALLTHROUGH*/ - - case S_STRING: - ia = *cp; /* index in the array */ - is = GI(*astate); /* index in the string */ - lc = is == 0 ? 0 : nv[ia].name[is - 1]; /* last character */ - - if (uc == ';') - uc = '\0'; - - for (; ia < __arraycount(nv); ia++) { - if (is != 0 && nv[ia].name[is - 1] != lc) - goto bad; - if (nv[ia].name[is] == uc) - break; - } - - if (ia == __arraycount(nv)) - goto bad; - - if (uc != 0) { - *cp = ia; - *astate = SS(is + 1, S_STRING); - return UNVIS_NOCHAR; - } - - *cp = nv[ia].value; - *astate = SS(0, S_GROUND); - return UNVIS_VALID; - - case S_NUMBER: - if (uc == ';') - return UNVIS_VALID; - if (!isdigit(uc)) - goto bad; - *cp += (*cp * 10) + uc - '0'; - return UNVIS_NOCHAR; - - default: - bad: - /* - * decoder in unknown state - (probably uninitialized) - */ - *astate = SS(0, S_GROUND); - return UNVIS_SYNBAD; - } -} - -/* - * strnunvisx - decode src into dst - * - * Number of chars decoded into dst is returned, -1 on error. - * Dst is null terminated. - */ - -int -strnunvisx(char *dst, size_t dlen, const char *src, int flag) -{ - char c; - char t = '\0', *start = dst; - int state = 0; - - _DIAGASSERT(src != NULL); - _DIAGASSERT(dst != NULL); -#define CHECKSPACE() \ - do { \ - if (dlen-- == 0) { \ - errno = ENOSPC; \ - return -1; \ - } \ - } while (/*CONSTCOND*/0) - - while ((c = *src++) != '\0') { - again: - switch (unvis(&t, c, &state, flag)) { - case UNVIS_VALID: - CHECKSPACE(); - *dst++ = t; - break; - case UNVIS_VALIDPUSH: - CHECKSPACE(); - *dst++ = t; - goto again; - case 0: - case UNVIS_NOCHAR: - break; - case UNVIS_SYNBAD: - errno = EINVAL; - return -1; - default: - _DIAGASSERT(/*CONSTCOND*/0); - errno = EINVAL; - return -1; - } - } - if (unvis(&t, c, &state, UNVIS_END) == UNVIS_VALID) { - CHECKSPACE(); - *dst++ = t; - } - CHECKSPACE(); - *dst = '\0'; - return (int)(dst - start); -} - -int -strunvisx(char *dst, const char *src, int flag) -{ - return strnunvisx(dst, (size_t)~0, src, flag); -} - -int -strunvis(char *dst, const char *src) -{ - return strnunvisx(dst, (size_t)~0, src, 0); -} - -int -strnunvis(char *dst, size_t dlen, const char *src) -{ - return strnunvisx(dst, dlen, src, 0); -} -#endif diff --git a/contrib/libedit/src/vi.c b/contrib/libedit/src/vi.c index 483066e927..0c37bfb9b2 100644 --- a/contrib/libedit/src/vi.c +++ b/contrib/libedit/src/vi.c @@ -1,4 +1,4 @@ -/* $NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $ */ +/* $NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -33,37 +33,43 @@ */ #include "config.h" -#include -#include -#include -#include - #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.45 2014/06/18 18:12:28 christos Exp $"); +__RCSID("$NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $"); #endif #endif /* not lint && not SCCSID */ /* * vi.c: Vi mode commands. */ +#include +#include +#include +#include +#include +#include + #include "el.h" +#include "common.h" +#include "emacs.h" +#include "fcns.h" +#include "vi.h" -private el_action_t cv_action(EditLine *, Int); -private el_action_t cv_paste(EditLine *, Int); +static el_action_t cv_action(EditLine *, wint_t); +static el_action_t cv_paste(EditLine *, wint_t); /* cv_action(): * Handle vi actions. */ -private el_action_t -cv_action(EditLine *el, Int c) +static el_action_t +cv_action(EditLine *el, wint_t c) { if (el->el_chared.c_vcmd.action != NOP) { /* 'cc', 'dd' and (possibly) friends */ - if (c != (Int)el->el_chared.c_vcmd.action) + if (c != (wint_t)el->el_chared.c_vcmd.action) return CC_ERROR; if (!(c & YANK)) @@ -89,8 +95,8 @@ cv_action(EditLine *el, Int c) /* cv_paste(): * Paste previous deletion before or after the cursor */ -private el_action_t -cv_paste(EditLine *el, Int c) +static el_action_t +cv_paste(EditLine *el, wint_t c) { c_kill_t *k = &el->el_chared.c_kill; size_t len = (size_t)(k->last - k->buf); @@ -98,7 +104,8 @@ cv_paste(EditLine *el, Int c) if (k->buf == NULL || len == 0) return CC_ERROR; #ifdef DEBUG_PASTE - (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", (int)len, k->buf); + (void) fprintf(el->el_errfile, "Paste: \"%.*ls\"\n", (int)len, + k->buf); #endif cv_undo(el); @@ -120,9 +127,9 @@ cv_paste(EditLine *el, Int c) * Vi paste previous deletion to the right of the cursor * [p] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_paste_next(EditLine *el, Int c __attribute__((__unused__))) +vi_paste_next(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_paste(el, 0); @@ -133,9 +140,9 @@ vi_paste_next(EditLine *el, Int c __attribute__((__unused__))) * Vi paste previous deletion to the left of the cursor * [P] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_paste_prev(EditLine *el, Int c __attribute__((__unused__))) +vi_paste_prev(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_paste(el, 1); @@ -146,9 +153,9 @@ vi_paste_prev(EditLine *el, Int c __attribute__((__unused__))) * Vi move to the previous space delimited word * [B] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__))) +vi_prev_big_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -171,9 +178,9 @@ vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__))) * Vi move to the previous word * [b] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_prev_word(EditLine *el, Int c __attribute__((__unused__))) +vi_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -196,9 +203,9 @@ vi_prev_word(EditLine *el, Int c __attribute__((__unused__))) * Vi move to the next space delimited word * [W] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_next_big_word(EditLine *el, Int c __attribute__((__unused__))) +vi_next_big_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar - 1) @@ -220,9 +227,9 @@ vi_next_big_word(EditLine *el, Int c __attribute__((__unused__))) * Vi move to the next word * [w] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_next_word(EditLine *el, Int c __attribute__((__unused__))) +vi_next_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar - 1) @@ -244,8 +251,8 @@ vi_next_word(EditLine *el, Int c __attribute__((__unused__))) * Vi change case of character under the cursor and advance one character * [~] */ -protected el_action_t -vi_change_case(EditLine *el, Int c) +libedit_private el_action_t +vi_change_case(EditLine *el, wint_t c) { int i; @@ -255,10 +262,10 @@ vi_change_case(EditLine *el, Int c) for (i = 0; i < el->el_state.argument; i++) { c = *el->el_line.cursor; - if (Isupper(c)) - *el->el_line.cursor = Tolower(c); - else if (Islower(c)) - *el->el_line.cursor = Toupper(c); + if (iswupper(c)) + *el->el_line.cursor = towlower(c); + else if (iswlower(c)) + *el->el_line.cursor = towupper(c); if (++el->el_line.cursor >= el->el_line.lastchar) { el->el_line.cursor--; @@ -275,9 +282,9 @@ vi_change_case(EditLine *el, Int c) * Vi change prefix command * [c] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_change_meta(EditLine *el, Int c __attribute__((__unused__))) +vi_change_meta(EditLine *el, wint_t c __attribute__((__unused__))) { /* @@ -292,9 +299,9 @@ vi_change_meta(EditLine *el, Int c __attribute__((__unused__))) * Vi enter insert mode at the beginning of line * [I] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_insert_at_bol(EditLine *el, Int c __attribute__((__unused__))) +vi_insert_at_bol(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -308,9 +315,9 @@ vi_insert_at_bol(EditLine *el, Int c __attribute__((__unused__))) * Vi replace character under the cursor with the next character typed * [r] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_replace_char(EditLine *el, Int c __attribute__((__unused__))) +vi_replace_char(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar) @@ -327,9 +334,9 @@ vi_replace_char(EditLine *el, Int c __attribute__((__unused__))) * Vi enter replace mode * [R] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_replace_mode(EditLine *el, Int c __attribute__((__unused__))) +vi_replace_mode(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -343,9 +350,9 @@ vi_replace_mode(EditLine *el, Int c __attribute__((__unused__))) * Vi replace character under the cursor and enter insert mode * [s] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_substitute_char(EditLine *el, Int c __attribute__((__unused__))) +vi_substitute_char(EditLine *el, wint_t c __attribute__((__unused__))) { c_delafter(el, el->el_state.argument); @@ -358,9 +365,9 @@ vi_substitute_char(EditLine *el, Int c __attribute__((__unused__))) * Vi substitute entire line * [S] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_substitute_line(EditLine *el, Int c __attribute__((__unused__))) +vi_substitute_line(EditLine *el, wint_t c __attribute__((__unused__))) { cv_undo(el); @@ -376,9 +383,9 @@ vi_substitute_line(EditLine *el, Int c __attribute__((__unused__))) * Vi change to end of line * [C] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_change_to_eol(EditLine *el, Int c __attribute__((__unused__))) +vi_change_to_eol(EditLine *el, wint_t c __attribute__((__unused__))) { cv_undo(el); @@ -394,9 +401,9 @@ vi_change_to_eol(EditLine *el, Int c __attribute__((__unused__))) * Vi enter insert mode * [i] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_insert(EditLine *el, Int c __attribute__((__unused__))) +vi_insert(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -409,9 +416,9 @@ vi_insert(EditLine *el, Int c __attribute__((__unused__))) * Vi enter insert mode after the cursor * [a] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_add(EditLine *el, Int c __attribute__((__unused__))) +vi_add(EditLine *el, wint_t c __attribute__((__unused__))) { int ret; @@ -434,9 +441,9 @@ vi_add(EditLine *el, Int c __attribute__((__unused__))) * Vi enter insert mode at end of line * [A] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_add_at_eol(EditLine *el, Int c __attribute__((__unused__))) +vi_add_at_eol(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -450,9 +457,9 @@ vi_add_at_eol(EditLine *el, Int c __attribute__((__unused__))) * Vi delete prefix command * [d] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_delete_meta(EditLine *el, Int c __attribute__((__unused__))) +vi_delete_meta(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_action(el, DELETE); @@ -463,9 +470,9 @@ vi_delete_meta(EditLine *el, Int c __attribute__((__unused__))) * Vi move to the end of the current space delimited word * [E] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_end_big_word(EditLine *el, Int c __attribute__((__unused__))) +vi_end_big_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) @@ -487,9 +494,9 @@ vi_end_big_word(EditLine *el, Int c __attribute__((__unused__))) * Vi move to the end of the current word * [e] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_end_word(EditLine *el, Int c __attribute__((__unused__))) +vi_end_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) @@ -511,9 +518,9 @@ vi_end_word(EditLine *el, Int c __attribute__((__unused__))) * Vi undo last change * [u] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_undo(EditLine *el, Int c __attribute__((__unused__))) +vi_undo(EditLine *el, wint_t c __attribute__((__unused__))) { c_undo_t un = el->el_chared.c_undo; @@ -538,9 +545,9 @@ vi_undo(EditLine *el, Int c __attribute__((__unused__))) * Vi enter command mode (use alternative key bindings) * [] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_command_mode(EditLine *el, Int c __attribute__((__unused__))) +vi_command_mode(EditLine *el, wint_t c __attribute__((__unused__))) { /* [Esc] cancels pending action */ @@ -563,8 +570,8 @@ vi_command_mode(EditLine *el, Int c __attribute__((__unused__))) * Vi move to the beginning of line * [0] */ -protected el_action_t -vi_zero(EditLine *el, Int c) +libedit_private el_action_t +vi_zero(EditLine *el, wint_t c) { if (el->el_state.doingarg) @@ -580,12 +587,12 @@ vi_zero(EditLine *el, Int 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 +libedit_private el_action_t /*ARGSUSED*/ -vi_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) +vi_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) @@ -601,9 +608,9 @@ vi_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) * Vi list choices for completion or indicate end of file if empty line * [^D] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_list_or_eof(EditLine *el, Int c) +vi_list_or_eof(EditLine *el, wint_t c) { if (el->el_line.cursor == el->el_line.lastchar) { @@ -638,11 +645,11 @@ vi_list_or_eof(EditLine *el, Int c) * Vi cut from beginning of line to cursor * [^U] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_kill_line_prev(EditLine *el, Int c __attribute__((__unused__))) +vi_kill_line_prev(EditLine *el, wint_t c __attribute__((__unused__))) { - Char *kp, *cp; + wchar_t *kp, *cp; cp = el->el_line.buffer; kp = el->el_chared.c_kill.buf; @@ -659,9 +666,9 @@ vi_kill_line_prev(EditLine *el, Int c __attribute__((__unused__))) * Vi search history previous * [?] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_search_prev(EditLine *el, Int c __attribute__((__unused__))) +vi_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_search(el, ED_SEARCH_PREV_HISTORY); @@ -672,9 +679,9 @@ vi_search_prev(EditLine *el, Int c __attribute__((__unused__))) * Vi search history next * [/] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_search_next(EditLine *el, Int c __attribute__((__unused__))) +vi_search_next(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_search(el, ED_SEARCH_NEXT_HISTORY); @@ -685,9 +692,9 @@ vi_search_next(EditLine *el, Int c __attribute__((__unused__))) * Vi repeat current search in the same search direction * [n] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_repeat_search_next(EditLine *el, Int c __attribute__((__unused__))) +vi_repeat_search_next(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_search.patlen == 0) @@ -702,8 +709,8 @@ vi_repeat_search_next(EditLine *el, Int c __attribute__((__unused__))) * [N] */ /*ARGSUSED*/ -protected el_action_t -vi_repeat_search_prev(EditLine *el, Int c __attribute__((__unused__))) +libedit_private el_action_t +vi_repeat_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_search.patlen == 0) @@ -719,9 +726,9 @@ vi_repeat_search_prev(EditLine *el, Int c __attribute__((__unused__))) * Vi move to the character specified next * [f] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_next_char(EditLine *el, Int c __attribute__((__unused__))) +vi_next_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0); } @@ -731,9 +738,9 @@ vi_next_char(EditLine *el, Int c __attribute__((__unused__))) * Vi move to the character specified previous * [F] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_prev_char(EditLine *el, Int c __attribute__((__unused__))) +vi_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0); } @@ -743,9 +750,9 @@ vi_prev_char(EditLine *el, Int c __attribute__((__unused__))) * Vi move up to the character specified next * [t] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_to_next_char(EditLine *el, Int c __attribute__((__unused__))) +vi_to_next_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1); } @@ -755,9 +762,9 @@ vi_to_next_char(EditLine *el, Int c __attribute__((__unused__))) * Vi move up to the character specified previous * [T] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_to_prev_char(EditLine *el, Int c __attribute__((__unused__))) +vi_to_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1); } @@ -767,9 +774,9 @@ vi_to_prev_char(EditLine *el, Int c __attribute__((__unused__))) * Vi repeat current character search in the same search direction * [;] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_repeat_next_char(EditLine *el, Int c __attribute__((__unused__))) +vi_repeat_next_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, el->el_search.chadir, el->el_search.chacha, @@ -781,9 +788,9 @@ vi_repeat_next_char(EditLine *el, Int c __attribute__((__unused__))) * Vi repeat current character search in the opposite search direction * [,] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_repeat_prev_char(EditLine *el, Int c __attribute__((__unused__))) +vi_repeat_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { el_action_t r; int dir = el->el_search.chadir; @@ -799,22 +806,22 @@ vi_repeat_prev_char(EditLine *el, Int c __attribute__((__unused__))) * Vi go to matching () {} or [] * [%] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_match(EditLine *el, Int c __attribute__((__unused__))) +vi_match(EditLine *el, wint_t c __attribute__((__unused__))) { - const Char match_chars[] = STR("()[]{}"); - Char *cp; + const wchar_t match_chars[] = L"()[]{}"; + wchar_t *cp; size_t delta, i, count; - Char o_ch, c_ch; + wchar_t o_ch, c_ch; *el->el_line.lastchar = '\0'; /* just in case */ - i = Strcspn(el->el_line.cursor, match_chars); + i = wcscspn(el->el_line.cursor, match_chars); o_ch = el->el_line.cursor[i]; if (o_ch == 0) return CC_ERROR; - delta = (size_t)(Strchr(match_chars, o_ch) - match_chars); + delta = (size_t)(wcschr(match_chars, o_ch) - match_chars); c_ch = match_chars[delta ^ 1]; count = 1; delta = 1 - (delta & 1) * 2; @@ -846,9 +853,9 @@ vi_match(EditLine *el, Int c __attribute__((__unused__))) * Vi undo all changes to line * [U] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_undo_line(EditLine *el, Int c __attribute__((__unused__))) +vi_undo_line(EditLine *el, wint_t c __attribute__((__unused__))) { cv_undo(el); @@ -860,9 +867,9 @@ vi_undo_line(EditLine *el, Int c __attribute__((__unused__))) * [|] * NB netbsd vi goes to screen column 'n', posix says nth character */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_to_column(EditLine *el, Int c __attribute__((__unused__))) +vi_to_column(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -874,9 +881,9 @@ vi_to_column(EditLine *el, Int c __attribute__((__unused__))) * Vi yank to end of line * [Y] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_yank_end(EditLine *el, Int c __attribute__((__unused__))) +vi_yank_end(EditLine *el, wint_t c __attribute__((__unused__))) { cv_yank(el, el->el_line.cursor, @@ -888,9 +895,9 @@ vi_yank_end(EditLine *el, Int c __attribute__((__unused__))) * Vi yank * [y] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_yank(EditLine *el, Int c __attribute__((__unused__))) +vi_yank(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_action(el, YANK); @@ -900,9 +907,9 @@ vi_yank(EditLine *el, Int c __attribute__((__unused__))) * Vi comment out current command * [#] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_comment_out(EditLine *el, Int c __attribute__((__unused__))) +vi_comment_out(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -918,9 +925,9 @@ vi_comment_out(EditLine *el, Int c __attribute__((__unused__))) * NB: posix implies that we should enter insert mode, however * this is against historical precedent... */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_alias(EditLine *el __attribute__((__unused__)), Int c __attribute__((__unused__))) +vi_alias(EditLine *el, wint_t c __attribute__((__unused__))) { char alias_name[3]; const char *alias_text; @@ -936,7 +943,7 @@ vi_alias(EditLine *el __attribute__((__unused__)), Int c __attribute__((__unused alias_text = (*el->el_chared.c_aliasfun)(el->el_chared.c_aliasarg, alias_name); if (alias_text != NULL) - FUN(el,push)(el, ct_decode_string(alias_text, &el->el_scratch)); + el_wpush(el, ct_decode_string(alias_text, &el->el_scratch)); return CC_NORM; } @@ -944,16 +951,16 @@ vi_alias(EditLine *el __attribute__((__unused__)), Int c __attribute__((__unused * Vi go to specified history file line. * [G] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_to_history_line(EditLine *el, Int c __attribute__((__unused__))) +vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__))) { int sv_event_no = el->el_history.eventno; el_action_t rval; if (el->el_history.eventno == 0) { - (void) Strncpy(el->el_history.buf, el->el_line.buffer, + (void) wcsncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ); el->el_history.last = el->el_history.buf + (el->el_line.lastchar - el->el_line.buffer); @@ -972,7 +979,7 @@ vi_to_history_line(EditLine *el, Int 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; @@ -989,9 +996,9 @@ vi_to_history_line(EditLine *el, Int c __attribute__((__unused__))) * Vi edit history line with vi * [v] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_histedit(EditLine *el, Int c __attribute__((__unused__))) +vi_histedit(EditLine *el, wint_t c __attribute__((__unused__))) { int fd; pid_t pid; @@ -1000,7 +1007,7 @@ vi_histedit(EditLine *el, Int c __attribute__((__unused__))) char tempfile[] = "/tmp/histedit.XXXXXXXXXX"; char *cp = NULL; size_t len; - Char *line = NULL; + wchar_t *line = NULL; if (el->el_state.doingarg) { if (vi_to_history_line(el, 0) == CC_ERROR) @@ -1018,9 +1025,9 @@ vi_histedit(EditLine *el, Int c __attribute__((__unused__))) line = el_malloc(len * sizeof(*line) + 1); if (line == NULL) goto error; - Strncpy(line, el->el_line.buffer, len); + wcsncpy(line, el->el_line.buffer, len); line[len] = '\0'; - ct_wcstombs(cp, line, TMP_BUFSIZ - 1); + wcstombs(cp, line, TMP_BUFSIZ - 1); cp[TMP_BUFSIZ - 1] = '\0'; len = strlen(cp); write(fd, cp, len); @@ -1038,12 +1045,12 @@ vi_histedit(EditLine *el, Int c __attribute__((__unused__))) while (waitpid(pid, &status, 0) != pid) continue; lseek(fd, (off_t)0, SEEK_SET); - st = read(fd, cp, TMP_BUFSIZ); + st = read(fd, cp, TMP_BUFSIZ - 1); if (st > 0) { - len = (size_t)(el->el_line.lastchar - - el->el_line.buffer); - len = ct_mbstowcs(el->el_line.buffer, cp, len); - if (len > 0 && el->el_line.buffer[len -1] == '\n') + cp[st] = '\0'; + len = (size_t)(el->el_line.limit - el->el_line.buffer); + len = mbstowcs(el->el_line.buffer, cp, len); + if (len > 0 && el->el_line.buffer[len - 1] == '\n') --len; } else @@ -1073,33 +1080,33 @@ error: * Who knows where this one came from! * '_' in vi means 'entire current line', so 'cc' is a synonym for 'c_' */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_history_word(EditLine *el, Int c __attribute__((__unused__))) +vi_history_word(EditLine *el, wint_t c __attribute__((__unused__))) { - const Char *wp = HIST_FIRST(el); - const Char *wep, *wsp; + const wchar_t *wp = HIST_FIRST(el); + const wchar_t *wep, *wsp; int len; - Char *cp; - const Char *lim; + wchar_t *cp; + const wchar_t *lim; if (wp == NULL) return CC_ERROR; - wep = wsp = 0; + wep = wsp = NULL; do { - while (Isspace(*wp)) + while (iswspace(*wp)) wp++; if (*wp == 0) break; wsp = wp; - while (*wp && !Isspace(*wp)) + while (*wp && !iswspace(*wp)) wp++; wep = wp; } while ((!el->el_state.doingarg || --el->el_state.argument > 0) && *wp != 0); - if (wsp == 0 || (el->el_state.doingarg && el->el_state.argument != 0)) + if (wsp == NULL || (el->el_state.doingarg && el->el_state.argument != 0)) return CC_ERROR; cv_undo(el); @@ -1123,9 +1130,9 @@ vi_history_word(EditLine *el, Int c __attribute__((__unused__))) * Vi redo last non-motion command * [.] */ -protected el_action_t +libedit_private el_action_t /*ARGSUSED*/ -vi_redo(EditLine *el, Int c __attribute__((__unused__))) +vi_redo(EditLine *el, wint_t c __attribute__((__unused__))) { c_redo_t *r = &el->el_chared.c_redo; @@ -1141,7 +1148,7 @@ vi_redo(EditLine *el, Int c __attribute__((__unused__))) /* sanity */ r->pos = r->lim - 1; r->pos[0] = 0; - FUN(el,push)(el, r->buf); + el_wpush(el, r->buf); } el->el_state.thiscmd = r->cmd; diff --git a/contrib/libedit/src/vis.c b/contrib/libedit/src/vis.c index d67f55108b..914e7b102e 100644 --- a/contrib/libedit/src/vis.c +++ b/contrib/libedit/src/vis.c @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.66 2014/09/26 15:58:59 roy Exp $ */ +/* $NetBSD: vis.c,v 1.72 2017/02/12 22:37:49 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -58,7 +58,7 @@ #include "config.h" #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: vis.c,v 1.66 2014/09/26 15:58:59 roy Exp $"); +__RCSID("$NetBSD: vis.c,v 1.72 2017/02/12 22:37:49 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #ifdef __FBSDID __FBSDID("$FreeBSD$"); @@ -97,6 +97,30 @@ static wchar_t *do_svis(wchar_t *, wint_t, int, wint_t, const wchar_t *); #undef BELL #define BELL L'\a' + +#if defined(LC_C_LOCALE) +#define iscgraph(c) isgraph_l(c, LC_C_LOCALE) +#else +/* Keep it simple for now, no locale stuff */ +#define iscgraph(c) isgraph(c) +#ifdef notyet +#include +static int +iscgraph(int c) { + int rv; + char *ol; + + ol = setlocale(LC_CTYPE, "C"); + rv = isgraph(c); + if (ol) + setlocale(LC_CTYPE, ol); + return rv; +} +#endif +#endif + +#define ISGRAPH(flags, c) \ + (((flags) & VIS_NOLOCALE) ? iscgraph(c) : iswgraph(c)) #define iswoctal(c) (((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7') #define iswwhite(c) (c == L' ' || c == L'\t' || c == L'\n') @@ -234,7 +258,7 @@ do_mbyte(wchar_t *dst, wint_t c, int flags, wint_t nextc, int iswextra) case L'$': /* vis(1) -l */ break; default: - if (iswgraph(c) && !iswoctal(c)) { + if (ISGRAPH(flags, c) && !iswoctal(c)) { *dst++ = L'\\'; *dst++ = c; return dst; @@ -286,7 +310,7 @@ do_svis(wchar_t *dst, wint_t c, int flags, wint_t nextc, const wchar_t *extra) uint64_t bmsk, wmsk; iswextra = wcschr(extra, c) != NULL; - if (!iswextra && (iswgraph(c) || iswwhite(c) || + if (!iswextra && (ISGRAPH(flags, c) || iswwhite(c) || ((flags & VIS_SAFE) && iswsafe(c)))) { *dst++ = c; return dst; @@ -336,7 +360,7 @@ makeextralist(int flags, const char *src) if ((dst = calloc(len + MAXEXTRAS, sizeof(*dst))) == NULL) return NULL; - if (mbstowcs(dst, src, len) == (size_t)-1) { + if ((flags & VIS_NOLOCALE) || mbstowcs(dst, src, len) == (size_t)-1) { size_t i; for (i = 0; i < len; i++) dst[i] = (wchar_t)(u_char)src[i]; @@ -367,7 +391,7 @@ makeextralist(int flags, const char *src) * All user-visible functions call this one. */ static int -istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, +istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength, int flags, const char *mbextra, int *cerr_ptr) { wchar_t *dst, *src, *pdst, *psrc, *start, *extra; @@ -375,13 +399,22 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, uint64_t bmsk, wmsk; wint_t c; visfun_t f; - int clen = 0, cerr = 0, error = -1, i, shft; + int clen = 0, cerr, error = -1, i, shft; + char *mbdst, *mdst; ssize_t mbslength, maxolen; - _DIAGASSERT(mbdst != NULL); + _DIAGASSERT(mbdstp != NULL); _DIAGASSERT(mbsrc != NULL || mblength == 0); _DIAGASSERT(mbextra != NULL); + mbslength = (ssize_t)mblength; + /* + * When inputing a single character, must also read in the + * next character for nextc, the look-ahead character. + */ + if (mbslength == 1) + mbslength++; + /* * Input (mbsrc) is a char string considered to be multibyte * characters. The input loop will read this string pulling @@ -397,16 +430,28 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, /* Allocate space for the wide char strings */ psrc = pdst = extra = NULL; - if ((psrc = calloc(mblength + 1, sizeof(*psrc))) == NULL) + mdst = NULL; + if ((psrc = calloc(mbslength + 1, sizeof(*psrc))) == NULL) return -1; - if ((pdst = calloc((4 * mblength) + 1, sizeof(*pdst))) == NULL) + if ((pdst = calloc((4 * mbslength) + 1, sizeof(*pdst))) == NULL) goto out; + if (*mbdstp == NULL) { + if ((mdst = calloc((4 * mbslength) + 1, sizeof(*mdst))) == NULL) + goto out; + *mbdstp = mdst; + } + + mbdst = *mbdstp; dst = pdst; src = psrc; - /* Use caller's multibyte conversion error flag. */ - if (cerr_ptr) - cerr = *cerr_ptr; + if (flags & VIS_NOLOCALE) { + /* Do one byte at a time conversion */ + cerr = 1; + } else { + /* Use caller's multibyte conversion error flag. */ + cerr = cerr_ptr ? *cerr_ptr : 0; + } /* * Input loop. @@ -414,13 +459,6 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, * stop at NULs because we may be processing a block of data * that includes NULs. */ - mbslength = (ssize_t)mblength; - /* - * When inputing a single character, must also read in the - * next character for nextc, the look-ahead character. - */ - if (mbslength == 1) - mbslength++; while (mbslength > 0) { /* Convert one multibyte character to wchar_t. */ if (!cerr) @@ -446,6 +484,7 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, } len = src - psrc; src = psrc; + /* * In the single character input case, we will have actually * processed two characters, c and nextc. Reset len back to @@ -461,7 +500,7 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, errno = ENOSPC; goto out; } - *mbdst = '\0'; /* can't create extra, return "" */ + *mbdst = '\0'; /* can't create extra, return "" */ error = 0; goto out; } @@ -533,9 +572,11 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, /* Terminate the output string. */ *mbdst = '\0'; - /* Pass conversion error flag out. */ - if (cerr_ptr) - *cerr_ptr = cerr; + if (flags & VIS_NOLOCALE) { + /* Pass conversion error flag out. */ + if (cerr_ptr) + *cerr_ptr = cerr; + } free(extra); free(pdst); @@ -546,14 +587,15 @@ out: free(extra); free(pdst); free(psrc); + free(mdst); return error; } static int -istrsenvisxl(char *mbdst, size_t *dlen, const char *mbsrc, +istrsenvisxl(char **mbdstp, size_t *dlen, const char *mbsrc, int flags, const char *mbextra, int *cerr_ptr) { - return istrsenvisx(mbdst, dlen, mbsrc, + return istrsenvisx(mbdstp, dlen, mbsrc, mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr); } @@ -576,7 +618,7 @@ svis(char *mbdst, int c, int flags, int nextc, const char *mbextra) cc[0] = c; cc[1] = nextc; - ret = istrsenvisx(mbdst, NULL, cc, 1, flags, mbextra, NULL); + ret = istrsenvisx(&mbdst, NULL, cc, 1, flags, mbextra, NULL); if (ret < 0) return NULL; return mbdst + ret; @@ -591,7 +633,7 @@ snvis(char *mbdst, size_t dlen, int c, int flags, int nextc, const char *mbextra cc[0] = c; cc[1] = nextc; - ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, mbextra, NULL); + ret = istrsenvisx(&mbdst, &dlen, cc, 1, flags, mbextra, NULL); if (ret < 0) return NULL; return mbdst + ret; @@ -600,33 +642,33 @@ snvis(char *mbdst, size_t dlen, int c, int flags, int nextc, const char *mbextra int strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra) { - return istrsenvisxl(mbdst, NULL, mbsrc, flags, mbextra, NULL); + return istrsenvisxl(&mbdst, NULL, mbsrc, flags, mbextra, NULL); } int strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra) { - return istrsenvisxl(mbdst, &dlen, mbsrc, flags, mbextra, NULL); + return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, mbextra, NULL); } int strsvisx(char *mbdst, const char *mbsrc, size_t len, int flags, const char *mbextra) { - return istrsenvisx(mbdst, NULL, mbsrc, len, flags, mbextra, NULL); + return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, mbextra, NULL); } int strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags, const char *mbextra) { - return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, mbextra, NULL); + return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, NULL); } int strsenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags, const char *mbextra, int *cerr_ptr) { - return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr); + return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr); } #endif @@ -643,7 +685,7 @@ vis(char *mbdst, int c, int flags, int nextc) cc[0] = c; cc[1] = nextc; - ret = istrsenvisx(mbdst, NULL, cc, 1, flags, "", NULL); + ret = istrsenvisx(&mbdst, NULL, cc, 1, flags, "", NULL); if (ret < 0) return NULL; return mbdst + ret; @@ -658,7 +700,7 @@ nvis(char *mbdst, size_t dlen, int c, int flags, int nextc) cc[0] = c; cc[1] = nextc; - ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, "", NULL); + ret = istrsenvisx(&mbdst, &dlen, cc, 1, flags, "", NULL); if (ret < 0) return NULL; return mbdst + ret; @@ -675,13 +717,20 @@ nvis(char *mbdst, size_t dlen, int c, int flags, int nextc) int strvis(char *mbdst, const char *mbsrc, int flags) { - return istrsenvisxl(mbdst, NULL, mbsrc, flags, "", NULL); + return istrsenvisxl(&mbdst, NULL, mbsrc, flags, "", NULL); } int strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags) { - return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL); + return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL); +} + +int +stravis(char **mbdstp, const char *mbsrc, int flags) +{ + *mbdstp = NULL; + return istrsenvisxl(mbdstp, NULL, mbsrc, flags, "", NULL); } /* @@ -698,19 +747,19 @@ strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags) int strvisx(char *mbdst, const char *mbsrc, size_t len, int flags) { - return istrsenvisx(mbdst, NULL, mbsrc, len, flags, "", NULL); + return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, "", NULL); } int strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags) { - return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, "", NULL); + return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", NULL); } int strenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags, int *cerr_ptr) { - return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr); + return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr); } #endif diff --git a/contrib/libedit/src/vis.h b/contrib/libedit/src/vis.h index cdcb814c5d..3042d4f989 100644 --- a/contrib/libedit/src/vis.h +++ b/contrib/libedit/src/vis.h @@ -1,4 +1,4 @@ -/* $NetBSD: vis.h,v 1.22 2014/09/26 01:21:07 christos Exp $ */ +/* $NetBSD: vis.h,v 1.24 2016/01/14 20:42:14 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -63,6 +63,7 @@ #define VIS_GLOB 0x1000 /* encode glob(3) magic characters */ #define VIS_SHELL 0x2000 /* encode shell special characters [not glob] */ #define VIS_META (VIS_WHITE | VIS_GLOB | VIS_SHELL) +#define VIS_NOLOCALE 0x4000 /* encode using the C locale */ /* * unvis return codes @@ -86,6 +87,7 @@ char *svis(char *, int, int, int, const char *); char *snvis(char *, size_t, int, int, int, const char *); int strvis(char *, const char *, int); +int stravis(char **, const char *, int); int strnvis(char *, size_t, const char *, int); int strsvis(char *, const char *, int, const char *);