From a0c9eb18debe82e3cbe370d5e1a639a09cbac2e9 Mon Sep 17 00:00:00 2001 From: John Marino Date: Wed, 4 Nov 2015 00:23:15 +0100 Subject: [PATCH] Update libedit from version 2014-06-20 to 2015-03-25 on vendor branch --- contrib/libedit/src/chartype.c | 100 ++++++++++++++++------------- contrib/libedit/src/chartype.h | 10 +-- contrib/libedit/src/eln.c | 10 +-- contrib/libedit/src/filecomplete.c | 8 +-- contrib/libedit/src/map.c | 6 +- contrib/libedit/src/map.h | 4 +- contrib/libedit/src/parse.c | 13 ++-- contrib/libedit/src/read.c | 6 +- contrib/libedit/src/readline.c | 43 +++++++++++-- contrib/libedit/src/unvis.c | 10 ++- contrib/libedit/src/vis.c | 63 ++++++++++++------ contrib/libedit/src/vis.h | 4 +- 12 files changed, 178 insertions(+), 99 deletions(-) diff --git a/contrib/libedit/src/chartype.c b/contrib/libedit/src/chartype.c index 8766aacada..b780bb1c3c 100644 --- a/contrib/libedit/src/chartype.c +++ b/contrib/libedit/src/chartype.c @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.c,v 1.10 2011/08/16 16:25:15 christos Exp $ */ +/* $NetBSD: chartype.c,v 1.12 2015/02/22 02:16:19 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: chartype.c,v 1.10 2011/08/16 16:25:15 christos Exp $"); +__RCSID("$NetBSD: chartype.c,v 1.12 2015/02/22 02:16:19 christos Exp $"); #endif /* not lint && not SCCSID */ #include "el.h" #include @@ -46,31 +46,46 @@ __RCSID("$NetBSD: chartype.c,v 1.10 2011/08/16 16:25:15 christos Exp $"); #define CT_BUFSIZ ((size_t)1024) #ifdef WIDECHAR -protected void -ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize) +protected int +ct_conv_cbuff_resize(ct_buffer_t *conv, size_t csize) { void *p; - if (mincsize > conv->csize) { - conv->csize = mincsize; - p = el_realloc(conv->cbuff, conv->csize * sizeof(*conv->cbuff)); - if (p == NULL) { - conv->csize = 0; - el_free(conv->cbuff); - conv->cbuff = NULL; - } else - conv->cbuff = p; + + if (csize <= conv->csize) + return 0; + + conv->csize = csize; + + p = el_realloc(conv->cbuff, conv->csize * sizeof(*conv->cbuff)); + if (p == NULL) { + conv->csize = 0; + el_free(conv->cbuff); + conv->cbuff = NULL; + return -1; } + conv->cbuff = p; + return 0; +} - if (minwsize > conv->wsize) { - conv->wsize = minwsize; - p = el_realloc(conv->wbuff, conv->wsize * sizeof(*conv->wbuff)); - if (p == NULL) { - conv->wsize = 0; - el_free(conv->wbuff); - conv->wbuff = NULL; - } else - conv->wbuff = p; +protected int +ct_conv_wbuff_resize(ct_buffer_t *conv, size_t wsize) +{ + void *p; + + if (wsize <= conv->wsize) + return 0; + + conv->wsize = wsize; + + p = el_realloc(conv->wbuff, conv->wsize * sizeof(*conv->wbuff)); + if (p == NULL) { + conv->wsize = 0; + el_free(conv->wbuff); + conv->wbuff = NULL; + return -1; } + conv->wbuff = p; + return 0; } @@ -78,26 +93,22 @@ public char * ct_encode_string(const Char *s, ct_buffer_t *conv) { char *dst; - ssize_t used = 0; + ssize_t used; if (!s) return NULL; - if (!conv->cbuff) - ct_conv_buff_resize(conv, CT_BUFSIZ, (size_t)0); - if (!conv->cbuff) - return NULL; dst = conv->cbuff; - while (*s) { - used = (ssize_t)(conv->csize - (size_t)(dst - conv->cbuff)); - if (used < 5) { - used = dst - conv->cbuff; - ct_conv_buff_resize(conv, conv->csize + CT_BUFSIZ, - (size_t)0); - if (!conv->cbuff) + for (;;) { + used = (ssize_t)(dst - conv->cbuff); + if ((conv->csize - (size_t)used) < 5) { + if (ct_conv_cbuff_resize(conv, + conv->csize + CT_BUFSIZ) == -1) return NULL; dst = conv->cbuff + used; } + if (!*s) + break; used = ct_encode_char(dst, (size_t)5, *s); if (used == -1) /* failed to encode, need more buffer space */ abort(); @@ -111,22 +122,19 @@ ct_encode_string(const Char *s, ct_buffer_t *conv) public Char * ct_decode_string(const char *s, ct_buffer_t *conv) { - size_t len = 0; + size_t len; if (!s) return NULL; - if (!conv->wbuff) - ct_conv_buff_resize(conv, (size_t)0, CT_BUFSIZ); - if (!conv->wbuff) - return NULL; len = ct_mbstowcs(NULL, s, (size_t)0); if (len == (size_t)-1) return NULL; - if (len > conv->wsize) - ct_conv_buff_resize(conv, (size_t)0, len + 1); - if (!conv->wbuff) - return NULL; + + if (conv->wsize < ++len) + if (ct_conv_wbuff_resize(conv, len + CT_BUFSIZ) == -1) + return NULL; + ct_mbstowcs(conv->wbuff, s, conv->wsize); return conv->wbuff; } @@ -145,9 +153,9 @@ ct_decode_argv(int argc, const char *argv[], ct_buffer_t *conv) * the argv strings. */ for (i = 0, bufspace = 0; i < argc; ++i) bufspace += argv[i] ? strlen(argv[i]) + 1 : 0; - ct_conv_buff_resize(conv, (size_t)0, bufspace); - if (!conv->wsize) - return NULL; + if (conv->wsize < ++bufspace) + if (ct_conv_wbuff_resize(conv, bufspace + CT_BUFSIZ) == -1) + return NULL; wargv = el_malloc((size_t)argc * sizeof(*wargv)); diff --git a/contrib/libedit/src/chartype.h b/contrib/libedit/src/chartype.h index 12fa9ac1f7..0beee17cd2 100644 --- a/contrib/libedit/src/chartype.h +++ b/contrib/libedit/src/chartype.h @@ -1,4 +1,4 @@ -/* $NetBSD: chartype.h,v 1.10 2011/11/16 01:45:10 christos Exp $ */ +/* $NetBSD: chartype.h,v 1.13 2015/02/22 02:16:19 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -44,7 +44,7 @@ * 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 !defined(__NetBSD__) && !defined(__sun) && !(defined(__APPLE__) && defined(__MACH__)) +#if !defined(__NetBSD__) && !defined(__sun) && !(defined(__APPLE__) && defined(__MACH__)) && !defined(__OpenBSD__) #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 @@ -193,7 +193,8 @@ public Char *ct_decode_string(const char *, ct_buffer_t *); protected Char **ct_decode_argv(int, const char *[], ct_buffer_t *); /* Resizes the conversion buffer(s) if needed. */ -protected void ct_conv_buff_resize(ct_buffer_t *, size_t, size_t); +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); @@ -203,7 +204,8 @@ protected size_t ct_enc_width(Char); #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_buff_resize(b, os, ns) +#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 diff --git a/contrib/libedit/src/eln.c b/contrib/libedit/src/eln.c index 5bcfb4f2b3..0e74996f52 100644 --- a/contrib/libedit/src/eln.c +++ b/contrib/libedit/src/eln.c @@ -1,4 +1,4 @@ -/* $NetBSD: eln.c,v 1.17 2014/06/18 18:12:28 christos Exp $ */ +/* $NetBSD: eln.c,v 1.18 2015/03/24 21:26:50 christos Exp $ */ /*- * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: eln.c,v 1.17 2014/06/18 18:12:28 christos Exp $"); +__RCSID("$NetBSD: eln.c,v 1.18 2015/03/24 21:26:50 christos Exp $"); #endif /* not lint && not SCCSID */ #include "histedit.h" @@ -76,9 +76,11 @@ el_gets(EditLine *el, int *nread) { const wchar_t *tmp; - el->el_flags |= IGNORE_EXTCHARS; + if (!(el->el_flags & CHARSET_IS_UTF8)) + el->el_flags |= IGNORE_EXTCHARS; tmp = el_wgets(el, nread); - el->el_flags &= ~IGNORE_EXTCHARS; + if (!(el->el_flags & CHARSET_IS_UTF8)) + el->el_flags &= ~IGNORE_EXTCHARS; return ct_encode_string(tmp, &el->el_lgcyconv); } diff --git a/contrib/libedit/src/filecomplete.c b/contrib/libedit/src/filecomplete.c index ab74a4b58c..438de4ea9a 100644 --- a/contrib/libedit/src/filecomplete.c +++ b/contrib/libedit/src/filecomplete.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecomplete.c,v 1.32 2014/06/05 22:07:42 christos Exp $ */ +/* $NetBSD: filecomplete.c,v 1.34 2014/10/18 15:07:02 riz Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: filecomplete.c,v 1.32 2014/06/05 22:07:42 christos Exp $"); +__RCSID("$NetBSD: filecomplete.c,v 1.34 2014/10/18 15:07:02 riz Exp $"); #endif /* not lint && not SCCSID */ #include @@ -66,7 +66,7 @@ static const Char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', * if ``user'' isn't valid user name or ``txt'' doesn't start * w/ '~', returns pointer to strdup()ed copy of ``txt'' * - * it's callers's responsibility to free() returned string + * it's the caller's responsibility to free() the returned string */ char * fn_tilde_expand(const char *txt) @@ -139,7 +139,7 @@ fn_tilde_expand(const char *txt) * such file can be found * value of ``state'' is ignored * - * it's caller's responsibility to free returned string + * it's the caller's responsibility to free the returned string */ char * fn_filename_completion_function(const char *text, int state) diff --git a/contrib/libedit/src/map.c b/contrib/libedit/src/map.c index b3e11ba66b..79f793cb66 100644 --- a/contrib/libedit/src/map.c +++ b/contrib/libedit/src/map.c @@ -1,4 +1,4 @@ -/* $NetBSD: map.c,v 1.33 2013/01/01 15:34:02 christos Exp $ */ +/* $NetBSD: map.c,v 1.34 2014/07/06 18:15:34 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: map.c,v 1.33 2013/01/01 15:34:02 christos Exp $"); +__RCSID("$NetBSD: map.c,v 1.34 2014/07/06 18:15:34 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -1396,7 +1396,7 @@ protected int map_addfunc(EditLine *el, const Char *name, const Char *help, el_func_t func) { void *p; - size_t nf = (size_t)el->el_map.nfunc + 1; + size_t nf = el->el_map.nfunc + 1; if (name == NULL || help == NULL || func == NULL) return -1; diff --git a/contrib/libedit/src/map.h b/contrib/libedit/src/map.h index 8e0c7e4eaa..f01b58b818 100644 --- a/contrib/libedit/src/map.h +++ b/contrib/libedit/src/map.h @@ -1,4 +1,4 @@ -/* $NetBSD: map.h,v 1.9 2009/12/30 22:37:40 christos Exp $ */ +/* $NetBSD: map.h,v 1.10 2014/07/06 18:15:34 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -57,7 +57,7 @@ typedef struct el_map_t { int type; /* Emacs or vi */ el_bindings_t *help; /* The help for the editor functions */ el_func_t *func; /* List of available functions */ - int nfunc; /* The number of functions/help items */ + size_t nfunc; /* The number of functions/help items */ } el_map_t; #define MAP_EMACS 0 diff --git a/contrib/libedit/src/parse.c b/contrib/libedit/src/parse.c index f1c4391a2f..47d6f7d9b9 100644 --- a/contrib/libedit/src/parse.c +++ b/contrib/libedit/src/parse.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.26 2011/08/16 16:25:15 christos Exp $ */ +/* $NetBSD: parse.c,v 1.27 2014/07/06 18:15:34 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: parse.c,v 1.26 2011/08/16 16:25:15 christos Exp $"); +__RCSID("$NetBSD: parse.c,v 1.27 2014/07/06 18:15:34 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -276,10 +276,11 @@ parse__string(Char *out, const Char *in) protected int parse_cmd(EditLine *el, const Char *cmd) { - el_bindings_t *b; + el_bindings_t *b = el->el_map.help; + size_t i; - for (b = el->el_map.help; b->name != NULL; b++) - if (Strcmp(b->name, cmd) == 0) - return b->func; + for (i = 0; i < el->el_map.nfunc; i++) + if (Strcmp(b[i].name, cmd) == 0) + return b[i].func; return -1; } diff --git a/contrib/libedit/src/read.c b/contrib/libedit/src/read.c index df6ac20208..b81cff609f 100644 --- a/contrib/libedit/src/read.c +++ b/contrib/libedit/src/read.c @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.70 2013/05/27 23:55:55 christos Exp $ */ +/* $NetBSD: read.c,v 1.71 2014/07/06 18:15:34 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: read.c,v 1.70 2013/05/27 23:55:55 christos Exp $"); +__RCSID("$NetBSD: read.c,v 1.71 2014/07/06 18:15:34 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -597,7 +597,7 @@ FUN(el,gets)(EditLine *el, int *nread) el->el_line.cursor = el->el_line.buffer; break; } - if ((unsigned int)cmdnum >= (unsigned int)el->el_map.nfunc) { /* BUG CHECK command */ + 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); diff --git a/contrib/libedit/src/readline.c b/contrib/libedit/src/readline.c index f549dfea46..e744448e4d 100644 --- a/contrib/libedit/src/readline.c +++ b/contrib/libedit/src/readline.c @@ -1,4 +1,4 @@ -/* $NetBSD: readline.c,v 1.110 2014/01/21 13:51:44 christos Exp $ */ +/* $NetBSD: readline.c,v 1.114 2015/03/24 21:29:52 christos Exp $ */ /*- * Copyright (c) 1997 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include "config.h" #if !defined(lint) && !defined(SCCSID) -__RCSID("$NetBSD: readline.c,v 1.110 2014/01/21 13:51:44 christos Exp $"); +__RCSID("$NetBSD: readline.c,v 1.114 2015/03/24 21:29:52 christos Exp $"); #endif /* not lint && not SCCSID */ #include @@ -342,7 +342,7 @@ rl_initialize(void) el_set(e, EL_SIGNAL, rl_catch_signals); /* set default mode to "emacs"-style and read setting afterwards */ - /* so this can be overriden */ + /* so this can be overridden */ el_set(e, EL_EDITOR, "emacs"); if (rl_terminal_name != NULL) el_set(e, EL_TERMINAL, rl_terminal_name); @@ -366,6 +366,37 @@ rl_initialize(void) _el_rl_tstp); el_set(e, EL_BIND, "^Z", "rl_tstp", NULL); + /* + * Set some readline compatible key-bindings. + */ + el_set(e, EL_BIND, "^R", "em-inc-search-prev", NULL); + + /* + * Allow the use of Home/End keys. + */ + el_set(e, EL_BIND, "\\e[1~", "ed-move-to-beg", NULL); + el_set(e, EL_BIND, "\\e[4~", "ed-move-to-end", NULL); + el_set(e, EL_BIND, "\\e[7~", "ed-move-to-beg", NULL); + el_set(e, EL_BIND, "\\e[8~", "ed-move-to-end", NULL); + el_set(e, EL_BIND, "\\e[H", "ed-move-to-beg", NULL); + el_set(e, EL_BIND, "\\e[F", "ed-move-to-end", NULL); + + /* + * Allow the use of the Delete/Insert keys. + */ + el_set(e, EL_BIND, "\\e[3~", "ed-delete-next-char", NULL); + el_set(e, EL_BIND, "\\e[2~", "ed-quoted-insert", NULL); + + /* + * Ctrl-left-arrow and Ctrl-right-arrow for word moving. + */ + el_set(e, EL_BIND, "\\e[1;5C", "em-next-word", NULL); + el_set(e, EL_BIND, "\\e[1;5D", "ed-prev-word", NULL); + el_set(e, EL_BIND, "\\e[5C", "em-next-word", NULL); + el_set(e, EL_BIND, "\\e[5D", "ed-prev-word", NULL); + el_set(e, EL_BIND, "\\e\\e[C", "em-next-word", NULL); + el_set(e, EL_BIND, "\\e\\e[D", "ed-prev-word", NULL); + /* read settings from configuration file */ el_source(e, NULL); @@ -638,7 +669,7 @@ get_history_event(const char *cmd, int *cindex, int qchar) * returns 0 if data was not modified, 1 if it was and 2 if the string * should be only printed and not executed; in case of error, * returns -1 and *result points to NULL - * it's callers responsibility to free() string returned in *result + * it's the caller's responsibility to free() the string returned in *result */ static int _history_expand_command(const char *command, size_t offs, size_t cmdlen, @@ -1698,7 +1729,7 @@ filename_completion_function(const char *name, int state) * which starts with supplied text * text contains a partial username preceded by random character * (usually '~'); state resets search from start (??? should we do that anyway) - * it's callers responsibility to free returned value + * it's the caller's responsibility to free the returned value */ char * username_completion_function(const char *text, int state) @@ -1966,7 +1997,7 @@ rl_callback_read_char(void) } else wbuf = NULL; (*(void (*)(const char *))rl_linefunc)(wbuf); - //el_set(e, EL_UNBUFFERED, 1); + el_set(e, EL_UNBUFFERED, 1); } } diff --git a/contrib/libedit/src/unvis.c b/contrib/libedit/src/unvis.c index 4bbc7bcb07..d2c65aa3d5 100644 --- a/contrib/libedit/src/unvis.c +++ b/contrib/libedit/src/unvis.c @@ -1,4 +1,4 @@ -/* $NetBSD: unvis.c,v 1.41 2012/12/15 04:29:53 matt Exp $ */ +/* $NetBSD: unvis.c,v 1.44 2014/09/26 15:43:36 roy Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: unvis.c,v 1.41 2012/12/15 04:29:53 matt Exp $"); +__RCSID("$NetBSD: unvis.c,v 1.44 2014/09/26 15:43:36 roy Exp $"); #endif #endif /* LIBC_SCCS and not lint */ @@ -314,6 +314,12 @@ unvis(char *cp, int c, int *astate, int flag) */ *astate = SS(0, S_GROUND); return UNVIS_NOCHAR; + default: + if (isgraph(c)) { + *cp = c; + *astate = SS(0, S_GROUND); + return UNVIS_VALID; + } } goto bad; diff --git a/contrib/libedit/src/vis.c b/contrib/libedit/src/vis.c index 880eacb105..d67f55108b 100644 --- a/contrib/libedit/src/vis.c +++ b/contrib/libedit/src/vis.c @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.60 2013/02/21 16:21:20 joerg Exp $ */ +/* $NetBSD: vis.c,v 1.66 2014/09/26 15:58:59 roy Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -58,7 +58,7 @@ #include "config.h" #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: vis.c,v 1.60 2013/02/21 16:21:20 joerg Exp $"); +__RCSID("$NetBSD: vis.c,v 1.66 2014/09/26 15:58:59 roy Exp $"); #endif /* LIBC_SCCS and not lint */ #ifdef __FBSDID __FBSDID("$FreeBSD$"); @@ -104,7 +104,10 @@ static wchar_t *do_svis(wchar_t *, wint_t, int, wint_t, const wchar_t *); #define xtoa(c) L"0123456789abcdef"[c] #define XTOA(c) L"0123456789ABCDEF"[c] -#define MAXEXTRAS 10 +#define MAXEXTRAS 30 + +static const wchar_t char_shell[] = L"'`\";&<>()|{}]\\$!^~"; +static const wchar_t char_glob[] = L"*?[#"; #if !HAVE_NBTOOL_CONFIG_H #ifndef __NetBSD__ @@ -215,8 +218,23 @@ do_mbyte(wchar_t *dst, wint_t c, int flags, wint_t nextc, int iswextra) *dst++ = L'0'; } return dst; + /* We cannot encode these characters in VIS_CSTYLE + * because they special meaning */ + case L'n': + case L'r': + case L'b': + case L'a': + case L'v': + case L't': + case L'f': + case L's': + case L'0': + case L'M': + case L'^': + case L'$': /* vis(1) -l */ + break; default: - if (iswgraph(c)) { + if (iswgraph(c) && !iswoctal(c)) { *dst++ = L'\\'; *dst++ = c; return dst; @@ -312,6 +330,7 @@ makeextralist(int flags, const char *src) { wchar_t *dst, *d; size_t len; + const wchar_t *s; len = strlen(src); if ((dst = calloc(len + MAXEXTRAS, sizeof(*dst))) == NULL) @@ -320,17 +339,18 @@ makeextralist(int flags, const char *src) if (mbstowcs(dst, src, len) == (size_t)-1) { size_t i; for (i = 0; i < len; i++) - dst[i] = (wint_t)(u_char)src[i]; + dst[i] = (wchar_t)(u_char)src[i]; d = dst + len; } else d = dst + wcslen(dst); - if (flags & VIS_GLOB) { - *d++ = L'*'; - *d++ = L'?'; - *d++ = L'['; - *d++ = L'#'; - } + if (flags & VIS_GLOB) + for (s = char_glob; *s; *d++ = *s++) + continue; + + if (flags & VIS_SHELL) + for (s = char_shell; *s; *d++ = *s++) + continue; if (flags & VIS_SP) *d++ = L' '; if (flags & VIS_TAB) *d++ = L'\t'; @@ -359,7 +379,7 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, ssize_t mbslength, maxolen; _DIAGASSERT(mbdst != NULL); - _DIAGASSERT(mbsrc != NULL); + _DIAGASSERT(mbsrc != NULL || mblength == 0); _DIAGASSERT(mbextra != NULL); /* @@ -377,8 +397,6 @@ istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, /* Allocate space for the wide char strings */ psrc = pdst = extra = NULL; - if (!mblength) - mblength = strlen(mbsrc); if ((psrc = calloc(mblength + 1, sizeof(*psrc))) == NULL) return -1; if ((pdst = calloc((4 * mblength) + 1, sizeof(*pdst))) == NULL) @@ -530,6 +548,15 @@ out: free(psrc); return error; } + +static int +istrsenvisxl(char *mbdst, size_t *dlen, const char *mbsrc, + int flags, const char *mbextra, int *cerr_ptr) +{ + return istrsenvisx(mbdst, dlen, mbsrc, + mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr); +} + #endif #if !HAVE_SVIS @@ -573,13 +600,13 @@ 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 istrsenvisx(mbdst, NULL, mbsrc, 0, 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 istrsenvisx(mbdst, &dlen, mbsrc, 0, flags, mbextra, NULL); + return istrsenvisxl(mbdst, &dlen, mbsrc, flags, mbextra, NULL); } int @@ -648,13 +675,13 @@ nvis(char *mbdst, size_t dlen, int c, int flags, int nextc) int strvis(char *mbdst, const char *mbsrc, int flags) { - return istrsenvisx(mbdst, NULL, mbsrc, 0, flags, "", NULL); + return istrsenvisxl(mbdst, NULL, mbsrc, flags, "", NULL); } int strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags) { - return istrsenvisx(mbdst, &dlen, mbsrc, 0, flags, "", NULL); + return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL); } /* diff --git a/contrib/libedit/src/vis.h b/contrib/libedit/src/vis.h index 93e758e7df..cdcb814c5d 100644 --- a/contrib/libedit/src/vis.h +++ b/contrib/libedit/src/vis.h @@ -1,4 +1,4 @@ -/* $NetBSD: vis.h,v 1.21 2013/02/20 17:01:15 christos Exp $ */ +/* $NetBSD: vis.h,v 1.22 2014/09/26 01:21:07 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -61,6 +61,8 @@ #define VIS_NOESCAPE 0x0400 /* don't decode `\' */ #define _VIS_END 0x0800 /* for unvis */ #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) /* * unvis return codes -- 2.41.0