summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2016-04-09 20:15:26 +0000
committerschwarze <schwarze@openbsd.org>2016-04-09 20:15:26 +0000
commit565aa7e845bd05480ccceb0abafa956d0083e470 (patch)
tree4df95ff3b16dd3435140c916a69960d6f7d775d7
parentAlways compile with WIDECHAR on and delete that preprocessor switch. (diff)
downloadwireguard-openbsd-565aa7e845bd05480ccceb0abafa956d0083e470.tar.xz
wireguard-openbsd-565aa7e845bd05480ccceb0abafa956d0083e470.zip
Delete 26 wrapper macros and two wrapper functions that are no
longer needed now that we always compile with wide character support, reducing code obfuscation. OK czarkoff@ martijn@. Diff also proofread by Christian Heckendorf <mbie at ulmus dot me>.
-rw-r--r--lib/libedit/chared.c16
-rw-r--r--lib/libedit/chartype.c15
-rw-r--r--lib/libedit/chartype.h41
-rw-r--r--lib/libedit/common.c11
-rw-r--r--lib/libedit/el.c6
-rw-r--r--lib/libedit/eln.c10
-rw-r--r--lib/libedit/emacs.c22
-rw-r--r--lib/libedit/hist.c6
-rw-r--r--lib/libedit/keymacro.c10
-rw-r--r--lib/libedit/map.c20
-rw-r--r--lib/libedit/read.c12
-rw-r--r--lib/libedit/refresh.c18
-rw-r--r--lib/libedit/search.c6
-rw-r--r--lib/libedit/terminal.c32
-rw-r--r--lib/libedit/tty.c14
-rw-r--r--lib/libedit/vi.c22
16 files changed, 113 insertions, 148 deletions
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c
index 1f6d319c03f..489f48926ff 100644
--- a/lib/libedit/chared.c
+++ b/lib/libedit/chared.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: chared.c,v 1.21 2016/03/21 15:25:39 schwarze Exp $ */
+/* $OpenBSD: chared.c,v 1.22 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: chared.c,v 1.28 2009/12/30 22:37:40 christos Exp $ */
/*-
@@ -199,7 +199,7 @@ c_delbefore1(EditLine *el)
protected int
ce__isword(wint_t p)
{
- return Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL;
+ return iswalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL;
}
@@ -209,9 +209,9 @@ ce__isword(wint_t p)
protected 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;
}
@@ -223,7 +223,7 @@ cv__isword(wint_t p)
protected int
cv__isWord(wint_t p)
{
- return !Isspace(p);
+ return !iswspace(p);
}
@@ -286,7 +286,7 @@ cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(wint_t))
* 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++;
}
@@ -308,7 +308,7 @@ cv_prev_word(Char *p, Char *low, int n, int (*wtest)(wint_t))
p--;
while (n--) {
- while ((p > low) && Isspace(*p))
+ while ((p > low) && iswspace(*p))
p--;
test = (*wtest)(*p);
while ((p >= low) && (*wtest)(*p) == test)
@@ -373,7 +373,7 @@ cv__endword(Char *p, Char *high, int n, int (*wtest)(wint_t))
p++;
while (n--) {
- while ((p < high) && Isspace(*p))
+ while ((p < high) && iswspace(*p))
p++;
test = (*wtest)(*p);
diff --git a/lib/libedit/chartype.c b/lib/libedit/chartype.c
index ee8717a6937..60b2e41485e 100644
--- a/lib/libedit/chartype.c
+++ b/lib/libedit/chartype.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: chartype.c,v 1.11 2016/04/09 19:31:55 schwarze Exp $ */
+/* $OpenBSD: chartype.c,v 1.12 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: chartype.c,v 1.6 2011/07/28 00:48:21 christos Exp $ */
/*-
@@ -113,14 +113,15 @@ ct_decode_string(const char *s, ct_buffer_t *conv)
if (!conv->wbuff)
return NULL;
- len = ct_mbstowcs(NULL, s, 0);
+ len = mbstowcs(NULL, s, 0);
if (len == (size_t)-1)
return NULL;
if (len > conv->wsize)
ct_conv_buff_resize(conv, 0, len + 1);
if (!conv->wbuff)
return NULL;
- ct_mbstowcs(conv->wbuff, s, conv->wsize);
+
+ mbstowcs(conv->wbuff, s, conv->wsize);
return conv->wbuff;
}
@@ -188,10 +189,10 @@ ct_encode_char(char *dst, size_t len, Char 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;
@@ -327,9 +328,9 @@ ct_chr_class(Char c)
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/lib/libedit/chartype.h b/lib/libedit/chartype.h
index 24ff1b382f3..51d9fd1459e 100644
--- a/lib/libedit/chartype.h
+++ b/lib/libedit/chartype.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: chartype.h,v 1.14 2016/04/09 19:31:55 schwarze Exp $ */
+/* $OpenBSD: chartype.h,v 1.15 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: chartype.h,v 1.5 2010/04/15 00:55:57 christos Exp $ */
/*-
@@ -30,7 +30,6 @@
#ifndef _h_chartype_f
#define _h_chartype_f
-
#ifndef NARROWCHAR
/* Ideally we should also test the value of the define to see if it
@@ -53,57 +52,22 @@
#warning Build environment does not support non-BMP characters
#endif
-#define ct_mbrtowc mbrtowc
-#define ct_wctob wctob
-#define ct_wctomb wctomb
-#define ct_wctomb_reset wctomb(0,0)
-#define ct_wcstombs wcstombs
-#define ct_mbstowcs mbstowcs
-
#define Char wchar_t
#define FUN(prefix,rest) prefix ## _w ## rest
#define FUNW(type) type ## _w
#define TYPE(type) type ## W
-#define FSTR "%ls"
-#define FSTARSTR "%.*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)
-
-#define Width(c) (wcwidth(c) == -1 ? 0 : wcwidth(c))
#else /* NARROW */
-size_t ct_mbrtowc(wchar_t *, const char *, size_t, void *);
-
#define Char char
#define FUN(prefix,rest) prefix ## _ ## rest
#define FUNW(type) type
@@ -149,8 +113,6 @@ protected void ct_conv_buff_resize(ct_buffer_t *, size_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) free(s)
-
#else
#define ct_encode_string(s, b) (s)
#define ct_decode_string(s, b) (s)
@@ -198,5 +160,4 @@ protected const Char *ct_visual_string(const Char *);
protected int ct_chr_class(Char c);
#endif
-
#endif /* _chartype_f */
diff --git a/lib/libedit/common.c b/lib/libedit/common.c
index f6988df9878..e1bb83bb294 100644
--- a/lib/libedit/common.c
+++ b/lib/libedit/common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: common.c,v 1.16 2016/03/22 11:32:18 schwarze Exp $ */
+/* $OpenBSD: common.c,v 1.17 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: common.c,v 1.24 2009/12/30 22:37:40 christos Exp $ */
/*-
@@ -142,8 +142,7 @@ ed_delete_next_char(EditLine *el, wint_t c)
#ifdef notdef /* XXX */
#define EL el->el_line
(void) fprintf(el->el_errfile,
- "\nD(b: %p(" FSTR ") c: %p(" FSTR ") last: %p(" FSTR
- ") limit: %p(" FSTR ")\n",
+ "\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
@@ -239,7 +238,7 @@ ed_move_to_beg(EditLine *el, wint_t c __attribute__((__unused__)))
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);
@@ -381,7 +380,7 @@ protected el_action_t
ed_digit(EditLine *el, wint_t c)
{
- if (!Isdigit(c))
+ if (!iswdigit(c))
return CC_ERROR;
if (el->el_state.doingarg) {
@@ -409,7 +408,7 @@ protected 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) {
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index aa201e1a0ea..b7b244f7093 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: el.c,v 1.30 2016/04/09 19:31:55 schwarze Exp $ */
+/* $OpenBSD: el.c,v 1.31 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: el.c,v 1.61 2011/01/27 23:11:40 christos Exp $ */
/*-
@@ -543,7 +543,7 @@ el_source(EditLine *el, const char *fname)
if (!dptr)
continue;
/* 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 */
@@ -612,7 +612,7 @@ el_editmode(EditLine *el, int argc, const Char **argv)
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/lib/libedit/eln.c b/lib/libedit/eln.c
index 42334c6bd98..0eec7c06872 100644
--- a/lib/libedit/eln.c
+++ b/lib/libedit/eln.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eln.c,v 1.14 2016/04/09 19:31:55 schwarze Exp $ */
+/* $OpenBSD: eln.c,v 1.15 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: eln.c,v 1.9 2010/11/04 13:53:12 christos Exp $ */
/*-
@@ -45,7 +45,7 @@ el_getc(EditLine *el, char *cp)
*cp = '\0';
if (num_read <= 0)
return num_read;
- num_read = ct_wctob(wc);
+ num_read = wctob(wc);
if (num_read == EOF) {
errno = ERANGE;
return -1;
@@ -103,7 +103,7 @@ el_parse(EditLine *el, int argc, const char *argv[])
if (!wargv)
return -1;
ret = el_wparse(el, argc, wargv);
- ct_free_argv(wargv);
+ free(wargv);
return ret;
}
@@ -197,7 +197,7 @@ el_set(EditLine *el, int op, ...)
default:
ret = -1;
}
- ct_free_argv(wargv);
+ free(wargv);
break;
}
@@ -219,7 +219,7 @@ el_set(EditLine *el, int op, ...)
/* XXX: The two strdup's leak */
ret = map_addfunc(el, Strdup(wargv[0]), Strdup(wargv[1]),
func);
- ct_free_argv(wargv);
+ free(wargv);
break;
}
case EL_HIST: { /* hist_fun_t, const char * */
diff --git a/lib/libedit/emacs.c b/lib/libedit/emacs.c
index 567dcf4b277..693e5e2559c 100644
--- a/lib/libedit/emacs.c
+++ b/lib/libedit/emacs.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: emacs.c,v 1.14 2016/03/20 23:48:27 schwarze Exp $ */
-/* $NetBSD: emacs.c,v 1.32 2016/02/16 22:53:14 christos Exp $ */
+/* $OpenBSD: emacs.c,v 1.15 2016/04/09 20:15:26 schwarze Exp $ */
+/* $NetBSD: emacs.c,v 1.33 2016/04/09 18:43:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -287,8 +287,8 @@ em_upper_case(EditLine *el, wint_t c __attribute__((__unused__)))
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)
@@ -311,16 +311,16 @@ em_capitol_case(EditLine *el, wint_t c __attribute__((__unused__)))
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)
@@ -343,8 +343,8 @@ em_lower_case(EditLine *el, wint_t c __attribute__((__unused__)))
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)
diff --git a/lib/libedit/hist.c b/lib/libedit/hist.c
index 3bf93534926..130870fe425 100644
--- a/lib/libedit/hist.c
+++ b/lib/libedit/hist.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: hist.c,v 1.14 2016/04/09 19:31:55 schwarze Exp $ */
-/* $NetBSD: hist.c,v 1.25 2016/03/23 22:27:48 christos Exp $ */
+/* $OpenBSD: hist.c,v 1.15 2016/04/09 20:15:26 schwarze Exp $ */
+/* $NetBSD: hist.c,v 1.26 2016/04/09 18:43:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -172,7 +172,7 @@ hist_command(EditLine *el, int argc, const Char **argv)
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 history(el->el_history.ref, &ev, H_SETSIZE, num);
diff --git a/lib/libedit/keymacro.c b/lib/libedit/keymacro.c
index a0a7806dc5f..16a0c63e9b1 100644
--- a/lib/libedit/keymacro.c
+++ b/lib/libedit/keymacro.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: keymacro.c,v 1.9 2016/04/09 19:31:55 schwarze Exp $ */
-/* $NetBSD: keymacro.c,v 1.15 2016/03/23 22:27:48 christos Exp $ */
+/* $OpenBSD: keymacro.c,v 1.10 2016/04/09 20:15:26 schwarze Exp $ */
+/* $NetBSD: keymacro.c,v 1.16 2016/04/09 18:43:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -259,7 +259,7 @@ keymacro_print(EditLine *el, const Char *key)
el->el_keymacro.buf[0] = '"';
if (node_lookup(el, key, el->el_keymacro.map, 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;
}
@@ -542,7 +542,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;
}
@@ -595,7 +595,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);
diff --git a/lib/libedit/map.c b/lib/libedit/map.c
index 3c53980059e..75b5771645b 100644
--- a/lib/libedit/map.c
+++ b/lib/libedit/map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map.c,v 1.19 2016/03/20 23:48:27 schwarze Exp $ */
+/* $OpenBSD: map.c,v 1.20 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: map.c,v 1.25 2009/12/30 22:37:40 christos Exp $ */
/*-
@@ -965,7 +965,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;
}
@@ -1130,7 +1130,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
@@ -1167,7 +1167,7 @@ map_print_some_keys(EditLine *el, el_action_t *map, wint_t first, wint_t last)
if (first == last) {
(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,
@@ -1175,7 +1175,7 @@ map_print_some_keys(EditLine *el, el_action_t *map, wint_t first, wint_t last)
(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;
@@ -1295,12 +1295,12 @@ 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 `%lc'.\n",
+ "%ls: Invalid switch `%lc'.\n",
argv[0], (wint_t)p[1]);
}
else
@@ -1314,7 +1314,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;
}
@@ -1350,7 +1350,7 @@ map_bind(EditLine *el, int argc, const Char **argv)
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 +1363,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;
}
diff --git a/lib/libedit/read.c b/lib/libedit/read.c
index 12bdf8189f8..7353681b814 100644
--- a/lib/libedit/read.c
+++ b/lib/libedit/read.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: read.c,v 1.31 2016/04/09 19:31:55 schwarze Exp $ */
-/* $NetBSD: read.c,v 1.81 2016/02/16 22:53:14 christos Exp $ */
+/* $OpenBSD: read.c,v 1.32 2016/04/09 20:15:26 schwarze Exp $ */
+/* $NetBSD: read.c,v 1.88 2016/04/09 18:43:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -305,9 +305,9 @@ read_char(EditLine *el, wchar_t *cp)
mbstate_t mbs;
++cbp;
- /* This only works because UTF8 is stateless */
+ /* This only works because UTF8 is stateless. */
memset(&mbs, 0, sizeof(mbs));
- switch (ct_mbrtowc(cp, cbuf, cbp, &mbs)) {
+ switch (mbrtowc(cp, cbuf, cbp, &mbs)) {
case (size_t)-1:
if (cbp > 1) {
/*
@@ -572,7 +572,7 @@ FUN(el,gets)(EditLine *el, int *nread)
break;
if (b->name)
(void) fprintf(el->el_errfile,
- "Executing " FSTR "\n", b->name);
+ "Executing %ls\n", b->name);
else
(void) fprintf(el->el_errfile,
"Error command = %d\n", cmdnum);
@@ -586,7 +586,7 @@ 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;
diff --git a/lib/libedit/refresh.c b/lib/libedit/refresh.c
index 16088ec346d..13170a26a05 100644
--- a/lib/libedit/refresh.c
+++ b/lib/libedit/refresh.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: refresh.c,v 1.15 2016/03/22 11:32:18 schwarze Exp $ */
-/* $NetBSD: refresh.c,v 1.45 2016/03/02 19:24:20 christos Exp $ */
+/* $OpenBSD: refresh.c,v 1.16 2016/04/09 20:15:26 schwarze Exp $ */
+/* $NetBSD: refresh.c,v 1.46 2016/04/09 18:43:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -156,8 +156,10 @@ re_addc(EditLine *el, wint_t c)
protected void
re_putc(EditLine *el, wint_t c, int shift)
{
- int i, w = Width(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);
@@ -199,7 +201,7 @@ re_refresh(EditLine *el)
size_t termsz;
#endif
- ELRE_DEBUG(1, (__F, "el->el_line.buffer = :" FSTR ":\r\n",
+ ELRE_DEBUG(1, (__F, "el->el_line.buffer = :%ls:\r\n",
el->el_line.buffer));
/* reset the Drawing cursor */
@@ -245,7 +247,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;
@@ -1015,7 +1017,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++;
@@ -1031,7 +1033,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++;
@@ -1050,7 +1052,7 @@ re_refresh_cursor(EditLine *el)
private void
re_fastputc(EditLine *el, wint_t c)
{
- int w = Width((Char)c);
+ int w = wcwidth((Char)c);
while (w > 1 && el->el_cursor.h + w > el->el_terminal.t_size.h)
re_fastputc(el, ' ');
diff --git a/lib/libedit/search.c b/lib/libedit/search.c
index 15ab6acbadd..4b5948314d6 100644
--- a/lib/libedit/search.c
+++ b/lib/libedit/search.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: search.c,v 1.21 2016/04/09 19:31:55 schwarze Exp $ */
-/* $NetBSD: search.c,v 1.40 2016/03/23 22:27:48 christos Exp $ */
+/* $OpenBSD: search.c,v 1.22 2016/04/09 20:15:26 schwarze Exp $ */
+/* $NetBSD: search.c,v 1.41 2016/04/09 18:43:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -118,7 +118,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)
diff --git a/lib/libedit/terminal.c b/lib/libedit/terminal.c
index f65710f9fb0..1ba9b987475 100644
--- a/lib/libedit/terminal.c
+++ b/lib/libedit/terminal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: terminal.c,v 1.12 2016/04/09 19:31:55 schwarze Exp $ */
+/* $OpenBSD: terminal.c,v 1.13 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: terminal.c,v 1.17 2016/02/15 15:35:03 christos Exp $ */
/*-
@@ -1357,7 +1357,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);
@@ -1371,7 +1371,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;
@@ -1522,7 +1522,7 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)),
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;
}
@@ -1565,7 +1565,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;
}
@@ -1580,11 +1580,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;
}
@@ -1593,8 +1593,8 @@ 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",
- *argv);
+ "echotc: Warning: Extra argument `%ls"
+ "'.\n", *argv);
return -1;
}
terminal_tputs(el, tgoto(scap, arg_cols, arg_rows), 1);
@@ -1614,11 +1614,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;
}
@@ -1630,11 +1630,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;
}
@@ -1642,15 +1642,15 @@ 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 "'.\n",
- *argv);
+ "echotc: Warning: Extra argument `%ls"
+ "'.\n", *argv);
return -1;
}
terminal_tputs(el, tgoto(scap, arg_cols, arg_rows), arg_rows);
diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c
index c68f8ecc530..cc694e86d00 100644
--- a/lib/libedit/tty.c
+++ b/lib/libedit/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.22 2016/04/09 18:42:49 schwarze Exp $ */
+/* $OpenBSD: tty.c,v 1.23 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: tty.c,v 1.34 2011/01/27 23:11:40 christos Exp $ */
/*-
@@ -914,15 +914,17 @@ tty_bind_char(EditLine *el, int 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];
}
}
}
@@ -1250,7 +1252,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) {
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c
index fe06c14d09f..c3f60855f34 100644
--- a/lib/libedit/vi.c
+++ b/lib/libedit/vi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vi.c,v 1.19 2016/03/22 11:32:18 schwarze Exp $ */
+/* $OpenBSD: vi.c,v 1.20 2016/04/09 20:15:26 schwarze Exp $ */
/* $NetBSD: vi.c,v 1.33 2011/02/17 16:44:48 joerg Exp $ */
/*-
@@ -97,7 +97,7 @@ cv_paste(EditLine *el, wint_t c)
if (k->buf == NULL || len == 0)
return CC_ERROR;
#ifdef DEBUG_PASTE
- (void) fprintf(el->el_errfile, "Paste: \"" FSTARSTR "\"\n", (int)len,
+ (void) fprintf(el->el_errfile, "Paste: \"%.*ls\"\n", (int)len,
k->buf);
#endif
@@ -255,10 +255,10 @@ vi_change_case(EditLine *el, wint_t 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--;
@@ -810,7 +810,7 @@ vi_match(EditLine *el, wint_t c __attribute__((__unused__)))
*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;
@@ -1035,7 +1035,7 @@ vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))
}
Strncpy(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);
@@ -1061,7 +1061,7 @@ vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))
if (st > 0) {
len = (size_t)(el->el_line.lastchar -
el->el_line.buffer);
- len = ct_mbstowcs(el->el_line.buffer, cp, len);
+ len = mbstowcs(el->el_line.buffer, cp, len);
if (len > 0 && el->el_line.buffer[len -1] == '\n')
--len;
}
@@ -1101,12 +1101,12 @@ vi_history_word(EditLine *el, wint_t c __attribute__((__unused__)))
wep = wsp = 0;
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)