diff --git a/extern/editline/ChangeLog b/extern/editline/ChangeLog index 3725120bc9..ed76ec3f28 100644 --- a/extern/editline/ChangeLog +++ b/extern/editline/ChangeLog @@ -1,6 +1,38 @@ * See also NetBSD changelog: http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit +2015-03-25 Jess Thrysoee + + * version-info: 0:53:0 + + * all: sync with upstream source + +2014-10-30 Jess Thrysoee + + * version-info: 0:52:0 + + * all: sync with upstream source + + * configura.ac: Fix posix shell portability issue. Patch by Ryo Onodera. + +2014-06-20 Jess Thrysoee + + * version-info: 0:51:0 + + * all: sync with upstream source + +2014-06-18 Jess Thrysoee + + * version-info: 0:50:0 + + * all: sync with upstream source - add weak alias patches + +2014-06-18 Jess Thrysoee + + * version-info: 0:49:0 + + * all: sync with upstream source. + 2014-02-13 Jess Thrysoee * version-info: 0:48:0 diff --git a/extern/editline/src/chared.c b/extern/editline/src/chared.c index 35ec4b4b59..3934a684f7 100644 --- a/extern/editline/src/chared.c +++ b/extern/editline/src/chared.c @@ -1,4 +1,4 @@ -/* $NetBSD: chared.c,v 1.39 2013/07/12 22:39:50 christos Exp $ */ +/* $NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: chared.c,v 1.39 2013/07/12 22:39:50 christos Exp $"); +__RCSID("$NetBSD: chared.c,v 1.40 2014/06/18 18:12:28 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -434,6 +434,8 @@ ch_init(EditLine *el) el->el_chared.c_kill.last = el->el_chared.c_kill.buf; el->el_chared.c_resizefun = NULL; el->el_chared.c_resizearg = NULL; + el->el_chared.c_aliasfun = NULL; + el->el_chared.c_aliasarg = NULL; el->el_map.current = el->el_map.key; @@ -757,3 +759,11 @@ ch_resizefun(EditLine *el, el_zfunc_t f, void *a) el->el_chared.c_resizearg = a; return 0; } + +protected int +ch_aliasfun(EditLine *el, el_afunc_t f, void *a) +{ + el->el_chared.c_aliasfun = f; + el->el_chared.c_aliasarg = a; + return 0; +} diff --git a/extern/editline/src/chared.h b/extern/editline/src/chared.h index 176475ac8f..6d6ef2341f 100644 --- a/extern/editline/src/chared.h +++ b/extern/editline/src/chared.h @@ -1,4 +1,4 @@ -/* $NetBSD: chared.h,v 1.21 2010/08/28 15:44:59 christos Exp $ */ +/* $NetBSD: chared.h,v 1.22 2014/06/18 18:12:28 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -104,6 +104,7 @@ typedef struct c_kill_t { } c_kill_t; typedef void (*el_zfunc_t)(EditLine *, void *); +typedef const char *(*el_afunc_t)(void *, const char *); /* * Note that we use both data structures because the user can bind @@ -116,7 +117,9 @@ typedef struct el_chared_t { c_vcmd_t c_vcmd; c_macro_t c_macro; el_zfunc_t c_resizefun; + el_afunc_t c_aliasfun; void * c_resizearg; + void * c_aliasarg; } el_chared_t; @@ -165,6 +168,7 @@ protected int c_hpos(EditLine *); protected int ch_init(EditLine *); protected void ch_reset(EditLine *, int); protected int ch_resizefun(EditLine *, el_zfunc_t, void *); +protected int ch_aliasfun(EditLine *, el_afunc_t, void *); protected int ch_enlargebufs(EditLine *, size_t); protected void ch_end(EditLine *); diff --git a/extern/editline/src/chartype.c b/extern/editline/src/chartype.c index 8766aacada..b780bb1c3c 100644 --- a/extern/editline/src/chartype.c +++ b/extern/editline/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 (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; + 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; +} + +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/extern/editline/src/chartype.h b/extern/editline/src/chartype.h index 7623d73a83..0beee17cd2 100644 --- a/extern/editline/src/chartype.h +++ b/extern/editline/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 @@ -65,9 +65,9 @@ wchar_t *wcsdup(const wchar_t *s); #endif #define ct_mbtowc mbtowc -#define ct_mbtowc_reset EL_UNUSED(mbtowc(0,0,(size_t)0)) +#define ct_mbtowc_reset mbtowc(0,0,(size_t)0) #define ct_wctomb wctomb -#define ct_wctomb_reset EL_UNUSED(wctomb(0,0)) +#define ct_wctomb_reset wctomb(0,0) #define ct_wcstombs wcstombs #define ct_mbstowcs mbstowcs @@ -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/extern/editline/src/el.c b/extern/editline/src/el.c index 3726b9b688..e3e3bc7f98 100644 --- a/extern/editline/src/el.c +++ b/extern/editline/src/el.c @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.72 2013/01/22 20:23:21 christos Exp $ */ +/* $NetBSD: el.c,v 1.73 2014/06/18 18:12:28 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.72 2013/01/22 20:23:21 christos Exp $"); +__RCSID("$NetBSD: el.c,v 1.73 2014/06/18 18:12:28 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -221,6 +221,13 @@ FUN(el,set)(EditLine *el, int op, ...) break; } + case EL_ALIAS_TEXT: { + el_afunc_t p = va_arg(ap, el_afunc_t); + void *arg = va_arg(ap, void *); + rv = ch_aliasfun(el, p, arg); + break; + } + case EL_PROMPT_ESC: case EL_RPROMPT_ESC: { el_pfunc_t p = va_arg(ap, el_pfunc_t); diff --git a/extern/editline/src/eln.c b/extern/editline/src/eln.c index b94ecf3bb5..0e74996f52 100644 --- a/extern/editline/src/eln.c +++ b/extern/editline/src/eln.c @@ -1,4 +1,4 @@ -/* $NetBSD: eln.c,v 1.14 2012/03/11 21:15:25 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.14 2012/03/11 21:15:25 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" @@ -75,7 +75,7 @@ public const char * el_gets(EditLine *el, int *nread) { const wchar_t *tmp; -//we don't want to ignore extended chars with UTF8 charsets /FSG 2011 + if (!(el->el_flags & CHARSET_IS_UTF8)) el->el_flags |= IGNORE_EXTCHARS; tmp = el_wgets(el, nread); @@ -127,6 +127,22 @@ el_set(EditLine *el, int op, ...) break; } + case EL_ALIAS_TEXT: { + el_afunc_t p = va_arg(ap, el_afunc_t); + void *arg = va_arg(ap, void *); + ret = ch_aliasfun(el, p, arg); + break; + } + + case EL_PROMPT_ESC: + case EL_RPROMPT_ESC: { + el_pfunc_t p = va_arg(ap, el_pfunc_t); + int c = va_arg(ap, int); + + ret = prompt_set(el, p, c, op, 0); + break; + } + case EL_TERMINAL: /* const char * */ ret = el_wset(el, op, va_arg(ap, char *)); break; @@ -151,10 +167,10 @@ el_set(EditLine *el, int op, ...) const char *argv[20]; int i; const wchar_t **wargv; - for (i = 1; i < (int)__arraycount(argv); ++i) - if ((argv[i] = va_arg(ap, char *)) == NULL) + for (i = 1; i < (int)__arraycount(argv) - 1; ++i) + if ((argv[i] = va_arg(ap, const char *)) == NULL) break; - argv[0] = NULL; + argv[0] = argv[i] = NULL; wargv = (const wchar_t **) ct_decode_argv(i + 1, argv, &el->el_lgcyconv); if (!wargv) { @@ -222,27 +238,31 @@ el_set(EditLine *el, int op, ...) el->el_flags |= NARROW_HISTORY; 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 * */ ret = el_wset(el, op, va_arg(ap, void *)); break; + case EL_SETFP: { /* int, FILE * */ int what = va_arg(ap, int); FILE *fp = va_arg(ap, FILE *); ret = el_wset(el, op, what, fp); break; } - case EL_PROMPT_ESC: /* el_pfunc_t, char */ - case EL_RPROMPT_ESC: { - el_pfunc_t p = va_arg(ap, el_pfunc_t); - char c = (char)va_arg(ap, int); - ret = prompt_set(el, p, c, op, 0); + + case EL_REFRESH: + re_clear_display(el); + re_refresh(el); + terminal__flush(el); + ret = 0; break; - } + default: ret = -1; break; diff --git a/extern/editline/src/filecomplete.c b/extern/editline/src/filecomplete.c index 49f8005c47..438de4ea9a 100644 --- a/extern/editline/src/filecomplete.c +++ b/extern/editline/src/filecomplete.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecomplete.c,v 1.31 2011/09/16 16:13:16 plunky 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.31 2011/09/16 16:13:16 plunky 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) @@ -486,7 +486,8 @@ fn_complete(EditLine *el, if (what_to_do == '?') goto display_matches; - if (matches[2] == NULL && strcmp(matches[0], matches[1]) == 0) { + if (matches[2] == NULL && + (matches[1] == NULL || strcmp(matches[0], matches[1]) == 0)) { /* * We found exact match. Add a space after * it, unless we do filename completion and the diff --git a/extern/editline/src/hist.h b/extern/editline/src/hist.h index a63be499db..58e5876c91 100644 --- a/extern/editline/src/hist.h +++ b/extern/editline/src/hist.h @@ -1,4 +1,4 @@ -/* $NetBSD: hist.h,v 1.13 2011/07/28 20:50:55 christos Exp $ */ +/* $NetBSD: hist.h,v 1.14 2014/05/11 01:05:17 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -73,6 +73,7 @@ typedef struct el_history_t { #define HIST_SET(el, num) HIST_FUN(el, H_SET, num) #define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname) #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 *); diff --git a/extern/editline/src/histedit.h b/extern/editline/src/histedit.h index 73e8375c53..94f33ed2a1 100644 --- a/extern/editline/src/histedit.h +++ b/extern/editline/src/histedit.h @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.h,v 1.51 2013/07/12 17:48:29 christos Exp $ */ +/* $NetBSD: histedit.h,v 1.53 2014/06/18 18:12:28 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -156,6 +156,7 @@ unsigned char _el_fn_complete(EditLine *, int); #define EL_PROMPT_ESC 21 /* , prompt_func, Char); set/get */ #define EL_RPROMPT_ESC 22 /* , prompt_func, Char); set/get */ #define EL_RESIZE 23 /* , el_zfunc_t, void *); set */ +#define EL_ALIAS_TEXT 24 /* , el_afunc_t, void *); set */ #define EL_BUILTIN_GETCFN (NULL) @@ -224,6 +225,7 @@ int history(History *, HistEvent *, int, ...); #define H_NEXT_EVDATA 23 /* , const int, histdata_t *); */ #define H_DELDATA 24 /* , int, histdata_t *);*/ #define H_REPLACE 25 /* , const char *, histdata_t); */ +#define H_SAVE_FP 26 /* , FILE *); */ diff --git a/extern/editline/src/history.c b/extern/editline/src/history.c index c65d4eef87..a4875275d4 100644 --- a/extern/editline/src/history.c +++ b/extern/editline/src/history.c @@ -1,4 +1,4 @@ -/* $NetBSD: history.c,v 1.46 2011/11/18 20:39:18 christos Exp $ */ +/* $NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: history.c,v 1.46 2011/11/18 20:39:18 christos Exp $"); +__RCSID("$NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -108,6 +108,7 @@ 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 *); @@ -787,13 +788,12 @@ done: } -/* history_save(): +/* history_save_fp(): * TYPE(History) save function */ private int -history_save(TYPE(History) *h, const char *fname) +history_save_fp(TYPE(History) *h, FILE *fp) { - FILE *fp; TYPE(HistEvent) ev; int i = -1, retval; size_t len, max_size; @@ -803,9 +803,6 @@ history_save(TYPE(History) *h, const char *fname) static ct_buffer_t conv; #endif - if ((fp = fopen(fname, "w")) == NULL) - return -1; - if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1) goto done; if (fputs(hist_cookie, fp) == EOF) @@ -834,11 +831,29 @@ history_save(TYPE(History) *h, const char *fname) oomem: h_free(ptr); done: - (void) fclose(fp); return i; } +/* history_save(): + * History save function + */ +private int +history_save(TYPE(History) *h, const char *fname) +{ + FILE *fp; + int i; + + if ((fp = fopen(fname, "w")) == NULL) + return -1; + + i = history_save_fp(h, fp); + + (void) fclose(fp); + return i; +} + + /* history_prev_event(): * Find the previous event, with number given */ @@ -1019,6 +1034,12 @@ FUNW(history)(TYPE(History) *h, TYPE(HistEvent) *ev, int fun, ...) he_seterrev(ev, _HE_HIST_WRITE); break; + case H_SAVE_FP: + retval = history_save_fp(h, va_arg(va, FILE *)); + if (retval == -1) + he_seterrev(ev, _HE_HIST_WRITE); + break; + case H_PREV_EVENT: retval = history_prev_event(h, ev, va_arg(va, int)); break; diff --git a/extern/editline/src/map.c b/extern/editline/src/map.c index b3e11ba66b..79f793cb66 100644 --- a/extern/editline/src/map.c +++ b/extern/editline/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/extern/editline/src/map.h b/extern/editline/src/map.h index 8e0c7e4eaa..f01b58b818 100644 --- a/extern/editline/src/map.h +++ b/extern/editline/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/extern/editline/src/parse.c b/extern/editline/src/parse.c index f1c4391a2f..47d6f7d9b9 100644 --- a/extern/editline/src/parse.c +++ b/extern/editline/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/extern/editline/src/read.c b/extern/editline/src/read.c index df6ac20208..b81cff609f 100644 --- a/extern/editline/src/read.c +++ b/extern/editline/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/extern/editline/src/readline.c b/extern/editline/src/readline.c index ff18b32b4f..e744448e4d 100644 --- a/extern/editline/src/readline.c +++ b/extern/editline/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, @@ -1299,9 +1330,7 @@ history_truncate_file (const char *filename, int nlines) } fflush(fp); if((off = ftello(fp)) > 0) - { - EL_UNUSED(ftruncate(fileno(fp), off)); - } + (void)ftruncate(fileno(fp), off); out3: fclose(tp); out2: @@ -1700,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) @@ -1968,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/extern/editline/src/tty.c b/extern/editline/src/tty.c index 57c8ee8916..ce7d86c07d 100644 --- a/extern/editline/src/tty.c +++ b/extern/editline/src/tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.42 2012/05/15 15:59:01 christos Exp $ */ +/* $NetBSD: tty.c,v 1.46 2014/06/18 18:52:49 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.42 2012/05/15 15:59:01 christos Exp $"); +__RCSID("$NetBSD: tty.c,v 1.46 2014/06/18 18:52:49 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -48,6 +48,7 @@ __RCSID("$NetBSD: tty.c,v 1.42 2012/05/15 15:59:01 christos Exp $"); #include #include /* for isatty */ #include /* for ffs */ +#include /* for abort */ #include "el.h" #include "tty.h" @@ -459,6 +460,7 @@ 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); #define t_qu t_ts @@ -517,17 +519,7 @@ tty_setup(EditLine *el) el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex); el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ex); - el->el_tty.t_ex.c_iflag &= ~el->el_tty.t_t[EX_IO][MD_INP].t_clrmask; - el->el_tty.t_ex.c_iflag |= el->el_tty.t_t[EX_IO][MD_INP].t_setmask; - - el->el_tty.t_ex.c_oflag &= ~el->el_tty.t_t[EX_IO][MD_OUT].t_clrmask; - el->el_tty.t_ex.c_oflag |= el->el_tty.t_t[EX_IO][MD_OUT].t_setmask; - - el->el_tty.t_ex.c_cflag &= ~el->el_tty.t_t[EX_IO][MD_CTL].t_clrmask; - el->el_tty.t_ex.c_cflag |= el->el_tty.t_t[EX_IO][MD_CTL].t_setmask; - - el->el_tty.t_ex.c_lflag &= ~el->el_tty.t_t[EX_IO][MD_LIN].t_clrmask; - el->el_tty.t_ex.c_lflag |= el->el_tty.t_t[EX_IO][MD_LIN].t_setmask; + tty_setup_flags(el, &el->el_tty.t_ex, EX_IO); /* * Reset the tty chars to reasonable defaults @@ -562,17 +554,7 @@ tty_setup(EditLine *el) } } - el->el_tty.t_ed.c_iflag &= ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask; - el->el_tty.t_ed.c_iflag |= el->el_tty.t_t[ED_IO][MD_INP].t_setmask; - - el->el_tty.t_ed.c_oflag &= ~el->el_tty.t_t[ED_IO][MD_OUT].t_clrmask; - el->el_tty.t_ed.c_oflag |= el->el_tty.t_t[ED_IO][MD_OUT].t_setmask; - - el->el_tty.t_ed.c_cflag &= ~el->el_tty.t_t[ED_IO][MD_CTL].t_clrmask; - el->el_tty.t_ed.c_cflag |= el->el_tty.t_t[ED_IO][MD_CTL].t_setmask; - - el->el_tty.t_ed.c_lflag &= ~el->el_tty.t_t[ED_IO][MD_LIN].t_clrmask; - el->el_tty.t_ed.c_lflag |= el->el_tty.t_t[ED_IO][MD_LIN].t_setmask; + tty_setup_flags(el, &el->el_tty.t_ed, ED_IO); tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]); tty_bind_char(el, 1); @@ -938,6 +920,58 @@ tty_bind_char(EditLine *el, int force) } +private tcflag_t * +tty__get_flag(struct termios *t, int kind) { + switch (kind) { + case MD_INP: + return &t->c_iflag; + case MD_OUT: + return &t->c_oflag; + case MD_CTL: + return &t->c_cflag; + case MD_LIN: + return &t->c_lflag; + default: + abort(); + /*NOTREACHED*/ + } +} + + +private tcflag_t +tty_update_flag(EditLine *el, tcflag_t f, int mode, int kind) +{ + f &= ~el->el_tty.t_t[mode][kind].t_clrmask; + f |= el->el_tty.t_t[mode][kind].t_setmask; + return f; +} + + +private void +tty_update_flags(EditLine *el, int kind) +{ + tcflag_t *tt, *ed, *ex; + tt = tty__get_flag(&el->el_tty.t_ts, kind); + ed = tty__get_flag(&el->el_tty.t_ed, kind); + ex = tty__get_flag(&el->el_tty.t_ex, kind); + + if (*tt != *ex && (kind != MD_CTL || *tt != *ed)) { + *ed = tty_update_flag(el, *tt, ED_IO, kind); + *ex = tty_update_flag(el, *tt, EX_IO, kind); + } +} + + +private 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])) + el->el_tty.t_c[mode][c] = el->el_tty.t_c[TS_IO][c]; + if (el->el_tty.t_t[mode][MD_CHAR].t_clrmask & C_SH(c)) + el->el_tty.t_c[mode][c] = el->el_tty.t_vdisable; +} + + /* tty_rawmode(): * Set terminal into 1 character at a time mode. */ @@ -973,112 +1007,42 @@ tty_rawmode(EditLine *el) (void) cfsetospeed(&el->el_tty.t_ed, el->el_tty.t_speed); } if (tty__cooked_mode(&el->el_tty.t_ts)) { - if (el->el_tty.t_ts.c_cflag != el->el_tty.t_ex.c_cflag) { - el->el_tty.t_ex.c_cflag = - el->el_tty.t_ts.c_cflag; - el->el_tty.t_ex.c_cflag &= - ~el->el_tty.t_t[EX_IO][MD_CTL].t_clrmask; - el->el_tty.t_ex.c_cflag |= - el->el_tty.t_t[EX_IO][MD_CTL].t_setmask; + int i; - el->el_tty.t_ed.c_cflag = - el->el_tty.t_ts.c_cflag; - el->el_tty.t_ed.c_cflag &= - ~el->el_tty.t_t[ED_IO][MD_CTL].t_clrmask; - el->el_tty.t_ed.c_cflag |= - el->el_tty.t_t[ED_IO][MD_CTL].t_setmask; - } - if ((el->el_tty.t_ts.c_lflag != el->el_tty.t_ex.c_lflag) && - (el->el_tty.t_ts.c_lflag != el->el_tty.t_ed.c_lflag)) { - el->el_tty.t_ex.c_lflag = - el->el_tty.t_ts.c_lflag; - el->el_tty.t_ex.c_lflag &= - ~el->el_tty.t_t[EX_IO][MD_LIN].t_clrmask; - el->el_tty.t_ex.c_lflag |= - el->el_tty.t_t[EX_IO][MD_LIN].t_setmask; + for (i = MD_INP; i <= MD_LIN; i++) + tty_update_flags(el, i); - el->el_tty.t_ed.c_lflag = - el->el_tty.t_ts.c_lflag; - el->el_tty.t_ed.c_lflag &= - ~el->el_tty.t_t[ED_IO][MD_LIN].t_clrmask; - el->el_tty.t_ed.c_lflag |= - el->el_tty.t_t[ED_IO][MD_LIN].t_setmask; - } - if ((el->el_tty.t_ts.c_iflag != el->el_tty.t_ex.c_iflag) && - (el->el_tty.t_ts.c_iflag != el->el_tty.t_ed.c_iflag)) { - el->el_tty.t_ex.c_iflag = - el->el_tty.t_ts.c_iflag; - el->el_tty.t_ex.c_iflag &= - ~el->el_tty.t_t[EX_IO][MD_INP].t_clrmask; - el->el_tty.t_ex.c_iflag |= - el->el_tty.t_t[EX_IO][MD_INP].t_setmask; - - el->el_tty.t_ed.c_iflag = - el->el_tty.t_ts.c_iflag; - el->el_tty.t_ed.c_iflag &= - ~el->el_tty.t_t[ED_IO][MD_INP].t_clrmask; - el->el_tty.t_ed.c_iflag |= - el->el_tty.t_t[ED_IO][MD_INP].t_setmask; - } - if ((el->el_tty.t_ts.c_oflag != el->el_tty.t_ex.c_oflag) && - (el->el_tty.t_ts.c_oflag != el->el_tty.t_ed.c_oflag)) { - el->el_tty.t_ex.c_oflag = - el->el_tty.t_ts.c_oflag; - el->el_tty.t_ex.c_oflag &= - ~el->el_tty.t_t[EX_IO][MD_OUT].t_clrmask; - el->el_tty.t_ex.c_oflag |= - el->el_tty.t_t[EX_IO][MD_OUT].t_setmask; - - el->el_tty.t_ed.c_oflag = - el->el_tty.t_ts.c_oflag; - el->el_tty.t_ed.c_oflag &= - ~el->el_tty.t_t[ED_IO][MD_OUT].t_clrmask; - el->el_tty.t_ed.c_oflag |= - el->el_tty.t_t[ED_IO][MD_OUT].t_setmask; - } if (tty__gettabs(&el->el_tty.t_ex) == 0) el->el_tty.t_tabs = 0; else el->el_tty.t_tabs = EL_CAN_TAB ? 1 : 0; - { - int i; + tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]); + /* + * Check if the user made any changes. + * If he did, then propagate the changes to the + * edit and execute data structures. + */ + for (i = 0; i < C_NCC; i++) + if (el->el_tty.t_c[TS_IO][i] != + el->el_tty.t_c[EX_IO][i]) + break; - tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]); + if (i != C_NCC) { /* - * Check if the user made any changes. - * If he did, then propagate the changes to the - * edit and execute data structures. - */ + * Propagate changes only to the unprotected + * chars that have been modified just now. + */ for (i = 0; i < C_NCC; i++) - if (el->el_tty.t_c[TS_IO][i] != - el->el_tty.t_c[EX_IO][i]) - break; + tty_update_char(el, ED_IO, i); - if (i != C_NCC) { - /* - * Propagate changes only to the unprotected - * chars that have been modified just now. - */ - for (i = 0; i < C_NCC; i++) { - if (!((el->el_tty.t_t[ED_IO][MD_CHAR].t_setmask & C_SH(i))) - && (el->el_tty.t_c[TS_IO][i] != el->el_tty.t_c[EX_IO][i])) - el->el_tty.t_c[ED_IO][i] = el->el_tty.t_c[TS_IO][i]; - if (el->el_tty.t_t[ED_IO][MD_CHAR].t_clrmask & C_SH(i)) - el->el_tty.t_c[ED_IO][i] = el->el_tty.t_vdisable; - } - tty_bind_char(el, 0); - tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]); + tty_bind_char(el, 0); + tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]); - for (i = 0; i < C_NCC; i++) { - if (!((el->el_tty.t_t[EX_IO][MD_CHAR].t_setmask & C_SH(i))) - && (el->el_tty.t_c[TS_IO][i] != el->el_tty.t_c[EX_IO][i])) - el->el_tty.t_c[EX_IO][i] = el->el_tty.t_c[TS_IO][i]; - if (el->el_tty.t_t[EX_IO][MD_CHAR].t_clrmask & C_SH(i)) - el->el_tty.t_c[EX_IO][i] = el->el_tty.t_vdisable; - } - tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]); - } + for (i = 0; i < C_NCC; i++) + tty_update_char(el, EX_IO, i); + + tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]); } } if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) { @@ -1129,17 +1093,7 @@ tty_quotemode(EditLine *el) el->el_tty.t_qu = el->el_tty.t_ed; - el->el_tty.t_qu.c_iflag &= ~el->el_tty.t_t[QU_IO][MD_INP].t_clrmask; - el->el_tty.t_qu.c_iflag |= el->el_tty.t_t[QU_IO][MD_INP].t_setmask; - - el->el_tty.t_qu.c_oflag &= ~el->el_tty.t_t[QU_IO][MD_OUT].t_clrmask; - el->el_tty.t_qu.c_oflag |= el->el_tty.t_t[QU_IO][MD_OUT].t_setmask; - - el->el_tty.t_qu.c_cflag &= ~el->el_tty.t_t[QU_IO][MD_CTL].t_clrmask; - el->el_tty.t_qu.c_cflag |= el->el_tty.t_t[QU_IO][MD_CTL].t_setmask; - - el->el_tty.t_qu.c_lflag &= ~el->el_tty.t_t[QU_IO][MD_LIN].t_clrmask; - el->el_tty.t_qu.c_lflag |= el->el_tty.t_t[QU_IO][MD_LIN].t_setmask; + tty_setup_flags(el, &el->el_tty.t_qu, QU_IO); if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) { #ifdef DEBUG_TTY @@ -1320,6 +1274,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv) } } + tty_setup_flags(el, tios, z); if (el->el_tty.t_mode == z) { if (tty_setty(el, TCSADRAIN, tios) == -1) { #ifdef DEBUG_TTY @@ -1357,3 +1312,14 @@ tty_printchar(EditLine *el, unsigned char *s) (void) fprintf(el->el_errfile, "\n"); } #endif /* notyet */ + + +private void +tty_setup_flags(EditLine *el, struct termios *tios, int mode) +{ + int kind; + for (kind = MD_INP; kind <= MD_LIN; kind++) { + tcflag_t *f = tty__get_flag(tios, kind); + *f = tty_update_flag(el, *f, mode, kind); + } +} diff --git a/extern/editline/src/tty.h b/extern/editline/src/tty.h index 7bdb0b2bb9..0bf4b64ce4 100644 --- a/extern/editline/src/tty.h +++ b/extern/editline/src/tty.h @@ -1,4 +1,4 @@ -/* $NetBSD: tty.h,v 1.14 2012/05/15 15:59:01 christos Exp $ */ +/* $NetBSD: tty.h,v 1.15 2014/05/19 19:54:12 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -442,6 +442,7 @@ #define QU_IO 2 /* used only for quoted chars */ #define NN_IO 3 /* The number of entries */ +/* Don't re-order */ #define MD_INP 0 #define MD_OUT 1 #define MD_CTL 2 diff --git a/extern/editline/src/unvis.c b/extern/editline/src/unvis.c index 4bbc7bcb07..d2c65aa3d5 100644 --- a/extern/editline/src/unvis.c +++ b/extern/editline/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/extern/editline/src/vi.c b/extern/editline/src/vi.c index 0d44b8399f..483066e927 100644 --- a/extern/editline/src/vi.c +++ b/extern/editline/src/vi.c @@ -1,4 +1,4 @@ -/* $NetBSD: vi.c,v 1.43 2012/01/16 14:57:45 christos Exp $ */ +/* $NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: vi.c,v 1.43 2012/01/16 14:57:45 christos Exp $"); +__RCSID("$NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -918,34 +918,26 @@ vi_comment_out(EditLine *el, Int c __attribute__((__unused__))) * NB: posix implies that we should enter insert mode, however * this is against historical precedent... */ -#ifdef __weak_reference -__weakref_visible char *my_get_alias_text(const char *) - __weak_reference(get_alias_text); -#endif protected el_action_t /*ARGSUSED*/ vi_alias(EditLine *el __attribute__((__unused__)), Int c __attribute__((__unused__))) { -#ifdef __weak_reference char alias_name[3]; - char *alias_text; + const char *alias_text; - if (my_get_alias_text == 0) { + if (el->el_chared.c_aliasfun == NULL) return CC_ERROR; - } alias_name[0] = '_'; alias_name[2] = 0; if (el_getc(el, &alias_name[1]) != 1) return CC_ERROR; - alias_text = my_get_alias_text(alias_name); + 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)); return CC_NORM; -#else - return CC_ERROR; -#endif } /* vi_to_history_line(): @@ -1031,8 +1023,8 @@ vi_histedit(EditLine *el, Int c __attribute__((__unused__))) ct_wcstombs(cp, line, TMP_BUFSIZ - 1); cp[TMP_BUFSIZ - 1] = '\0'; len = strlen(cp); - EL_UNUSED(write(fd, cp, len)); - EL_UNUSED(write(fd, "\n", (size_t)1)); + write(fd, cp, len); + write(fd, "\n", (size_t)1); pid = fork(); switch (pid) { case -1: diff --git a/extern/editline/src/vis.c b/extern/editline/src/vis.c index 880eacb105..d67f55108b 100644 --- a/extern/editline/src/vis.c +++ b/extern/editline/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/extern/editline/src/vis.h b/extern/editline/src/vis.h index 93e758e7df..cdcb814c5d 100644 --- a/extern/editline/src/vis.h +++ b/extern/editline/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