summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2016-04-11 19:54:55 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2016-04-11 19:54:55 +0000
commitabf221675b71c007d7d79df6e96b6c7cdc20da9e (patch)
tree2fd0e414e3915421b30112d11c2897319559c461
parenta3c072d05eac61e126aa13c82d6288e290316dbd (diff)
Move wrapper macros to the two files actually needing them:
FUNW, Strlen, Strdup, Strcmp, Strncmp, Strncpy, Strncat -> history.c Strchr, tok_strdup -> tokenizer.c FUN, TYPE, STR -> both of these files OK martijn@ Also proofread by Christian Heckendorf <mbie at ulmus dot me> who reported some whitespace issues in parse.c.
-rw-r--r--lib/libedit/chared.c10
-rw-r--r--lib/libedit/chartype.h29
-rw-r--r--lib/libedit/common.c12
-rw-r--r--lib/libedit/el.c28
-rw-r--r--lib/libedit/eln.c14
-rw-r--r--lib/libedit/filecomplete.c16
-rw-r--r--lib/libedit/hist.c14
-rw-r--r--lib/libedit/hist.h6
-rw-r--r--lib/libedit/history.c34
-rw-r--r--lib/libedit/keymacro.c4
-rw-r--r--lib/libedit/makelist6
-rw-r--r--lib/libedit/map.c14
-rw-r--r--lib/libedit/parse.c80
-rw-r--r--lib/libedit/read.c10
-rw-r--r--lib/libedit/refresh.c10
-rw-r--r--lib/libedit/search.c16
-rw-r--r--lib/libedit/terminal.c36
-rw-r--r--lib/libedit/tokenizer.c17
-rw-r--r--lib/libedit/tty.c4
-rw-r--r--lib/libedit/vi.c14
20 files changed, 195 insertions, 179 deletions
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c
index 489f48926ff..eb290145f08 100644
--- a/lib/libedit/chared.c
+++ b/lib/libedit/chared.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: chared.c,v 1.22 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: chared.c,v 1.23 2016/04/11 19:54:53 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 iswalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL;
+ return iswalnum(p) || wcschr(L"*?_-.[]~=", p) != NULL;
}
@@ -608,11 +608,11 @@ ch_end(EditLine *el)
* Insert string at cursorI
*/
public int
-FUN(el,insertstr)(EditLine *el, const Char *s)
+el_winsertstr(EditLine *el, const Char *s)
{
size_t len;
- if ((len = Strlen(s)) == 0)
+ if ((len = wcslen(s)) == 0)
return -1;
if (el->el_line.lastchar + len >= el->el_line.limit) {
if (!ch_enlargebufs(el, len))
@@ -655,7 +655,7 @@ c_gets(EditLine *el, Char *buf, const Char *prompt)
Char *cp = el->el_line.buffer, ch;
if (prompt) {
- len = Strlen(prompt);
+ len = wcslen(prompt);
(void)memcpy(cp, prompt, len * sizeof(*cp));
cp += len;
}
diff --git a/lib/libedit/chartype.h b/lib/libedit/chartype.h
index 51d9fd1459e..4a3c999b997 100644
--- a/lib/libedit/chartype.h
+++ b/lib/libedit/chartype.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: chartype.h,v 1.15 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: chartype.h,v 1.16 2016/04/11 19:54:53 schwarze Exp $ */
/* $NetBSD: chartype.h,v 1.5 2010/04/15 00:55:57 christos Exp $ */
/*-
@@ -53,35 +53,8 @@
#endif
#define Char wchar_t
-#define FUN(prefix,rest) prefix ## _w ## rest
-#define FUNW(type) type ## _w
-#define TYPE(type) type ## W
-#define STR(x) L ## x
-
-#define Strlen(x) wcslen(x)
-#define Strchr(s,c) wcschr(s,c)
-#define Strdup(x) wcsdup(x)
-#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)
-
#else /* NARROW */
-
#define Char char
-#define FUN(prefix,rest) prefix ## _ ## rest
-#define FUNW(type) type
-#define TYPE(type) type
-#define STR(x) x
-
-#define Strlen(x) strlen(x)
-#define Strchr(s,c) strchr(s,c)
-#define Strdup(x) strdup(x)
-#define Strncpy(d,s,n) strncpy(d,s,n)
-#define Strncat(d,s,n) strncat(d,s,n)
-
-#define Strcmp(s,v) strcmp(s,v)
-#define Strncmp(s,v,n) strncmp(s,v,n)
#endif
diff --git a/lib/libedit/common.c b/lib/libedit/common.c
index e1bb83bb294..4d101a47201 100644
--- a/lib/libedit/common.c
+++ b/lib/libedit/common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: common.c,v 1.17 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: common.c,v 1.18 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: common.c,v 1.24 2009/12/30 22:37:40 christos Exp $ */
/*-
@@ -648,7 +648,7 @@ ed_prev_history(EditLine *el, wint_t c __attribute__((__unused__)))
if (el->el_history.eventno == 0) { /* save the current buffer
* away */
- (void) Strncpy(el->el_history.buf, el->el_line.buffer,
+ (void) wcsncpy(el->el_history.buf, el->el_line.buffer,
EL_BUFSIZ);
el->el_history.last = el->el_history.buf +
(el->el_line.lastchar - el->el_line.buffer);
@@ -720,7 +720,7 @@ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__)))
return CC_ERROR;
}
if (el->el_history.eventno == 0) {
- (void) Strncpy(el->el_history.buf, el->el_line.buffer,
+ (void) wcsncpy(el->el_history.buf, el->el_line.buffer,
EL_BUFSIZ);
el->el_history.last = el->el_history.buf +
(el->el_line.lastchar - el->el_line.buffer);
@@ -741,7 +741,7 @@ ed_search_prev_history(EditLine *el, wint_t c __attribute__((__unused__)))
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
#endif
- if ((Strncmp(hp, el->el_line.buffer, (size_t)
+ if ((wcsncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) ||
hp[el->el_line.lastchar - el->el_line.buffer]) &&
c_hmatch(el, hp)) {
@@ -796,7 +796,7 @@ ed_search_next_history(EditLine *el, wint_t c __attribute__((__unused__)))
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
#endif
- if ((Strncmp(hp, el->el_line.buffer, (size_t)
+ if ((wcsncmp(hp, el->el_line.buffer, (size_t)
(el->el_line.lastchar - el->el_line.buffer)) ||
hp[el->el_line.lastchar - el->el_line.buffer]) &&
c_hmatch(el, hp))
@@ -906,7 +906,7 @@ ed_command(EditLine *el, wint_t c __attribute__((__unused__)))
Char tmpbuf[EL_BUFSIZ];
int tmplen;
- tmplen = c_gets(el, tmpbuf, STR("\n: "));
+ tmplen = c_gets(el, tmpbuf, L"\n: ");
terminal__putc(el, '\n');
if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index b7b244f7093..b90f2988472 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: el.c,v 1.31 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: el.c,v 1.32 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: el.c,v 1.61 2011/01/27 23:11:40 christos Exp $ */
/*-
@@ -71,7 +71,7 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
el->el_outfd = fileno(fout);
el->el_errfd = fileno(ferr);
- el->el_prog = Strdup(ct_decode_string(prog, &el->el_scratch));
+ el->el_prog = wcsdup(ct_decode_string(prog, &el->el_scratch));
if (el->el_prog == NULL) {
free(el);
return NULL;
@@ -153,7 +153,7 @@ el_reset(EditLine *el)
* set the editline parameters
*/
public int
-FUN(el,set)(EditLine *el, int op, ...)
+el_wset(EditLine *el, int op, ...)
{
va_list ap;
int rv = 0;
@@ -217,27 +217,27 @@ FUN(el,set)(EditLine *el, int op, ...)
switch (op) {
case EL_BIND:
- argv[0] = STR("bind");
+ argv[0] = L"bind";
rv = map_bind(el, i, argv);
break;
case EL_TELLTC:
- argv[0] = STR("telltc");
+ argv[0] = L"telltc";
rv = terminal_telltc(el, i, argv);
break;
case EL_SETTC:
- argv[0] = STR("settc");
+ argv[0] = L"settc";
rv = terminal_settc(el, i, argv);
break;
case EL_ECHOTC:
- argv[0] = STR("echotc");
+ argv[0] = L"echotc";
rv = terminal_echotc(el, i, argv);
break;
case EL_SETTY:
- argv[0] = STR("setty");
+ argv[0] = L"setty";
rv = tty_stty(el, i, argv);
break;
@@ -359,7 +359,7 @@ FUN(el,set)(EditLine *el, int op, ...)
* retrieve the editline parameters
*/
public int
-FUN(el,get)(EditLine *el, int op, ...)
+el_wget(EditLine *el, int op, ...)
{
va_list ap;
int rv;
@@ -480,11 +480,11 @@ FUN(el,get)(EditLine *el, int op, ...)
/* el_line():
* Return editing info
*/
-public const TYPE(LineInfo) *
-FUN(el,line)(EditLine *el)
+public const LineInfoW *
+el_wline(EditLine *el)
{
- return (const TYPE(LineInfo) *)(void *)&el->el_line;
+ return (const LineInfoW *)(void *)&el->el_line;
}
@@ -604,10 +604,10 @@ el_editmode(EditLine *el, int argc, const Char **argv)
return -1;
how = argv[1];
- if (Strcmp(how, STR("on")) == 0) {
+ if (wcscmp(how, L"on") == 0) {
el->el_flags &= ~EDIT_DISABLED;
tty_rawmode(el);
- } else if (Strcmp(how, STR("off")) == 0) {
+ } else if (wcscmp(how, L"off") == 0) {
tty_cookedmode(el);
el->el_flags |= EDIT_DISABLED;
}
diff --git a/lib/libedit/eln.c b/lib/libedit/eln.c
index 0eec7c06872..0679c46aaf6 100644
--- a/lib/libedit/eln.c
+++ b/lib/libedit/eln.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: eln.c,v 1.15 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: eln.c,v 1.16 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: eln.c,v 1.9 2010/11/04 13:53:12 christos Exp $ */
/*-
@@ -175,23 +175,23 @@ el_set(EditLine *el, int op, ...)
*/
switch (op) {
case EL_BIND:
- wargv[0] = STR("bind");
+ wargv[0] = L"bind";
ret = map_bind(el, i, wargv);
break;
case EL_TELLTC:
- wargv[0] = STR("telltc");
+ wargv[0] = L"telltc";
ret = terminal_telltc(el, i, wargv);
break;
case EL_SETTC:
- wargv[0] = STR("settc");
+ wargv[0] = L"settc";
ret = terminal_settc(el, i, wargv);
break;
case EL_ECHOTC:
- wargv[0] = STR("echotc");
+ wargv[0] = L"echotc";
ret = terminal_echotc(el, i, wargv);
break;
case EL_SETTY:
- wargv[0] = STR("setty");
+ wargv[0] = L"setty";
ret = tty_stty(el, i, wargv);
break;
default:
@@ -217,7 +217,7 @@ el_set(EditLine *el, int op, ...)
goto out;
}
/* XXX: The two strdup's leak */
- ret = map_addfunc(el, Strdup(wargv[0]), Strdup(wargv[1]),
+ ret = map_addfunc(el, wcsdup(wargv[0]), wcsdup(wargv[1]),
func);
free(wargv);
break;
diff --git a/lib/libedit/filecomplete.c b/lib/libedit/filecomplete.c
index bf283d8676f..9f56be234cf 100644
--- a/lib/libedit/filecomplete.c
+++ b/lib/libedit/filecomplete.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filecomplete.c,v 1.10 2016/04/09 20:28:27 schwarze Exp $ */
+/* $OpenBSD: filecomplete.c,v 1.11 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: filecomplete.c,v 1.22 2010/12/02 04:42:46 dholland Exp $ */
/*-
@@ -394,7 +394,7 @@ fn_complete(EditLine *el,
const char *(*app_func)(const char *), size_t query_items,
int *completion_type, int *over, int *point, int *end)
{
- const TYPE(LineInfo) *li;
+ const LineInfoW *li;
Char *temp;
char **matches;
const Char *ctemp;
@@ -415,16 +415,16 @@ fn_complete(EditLine *el,
app_func = append_char_function;
/* We now look backwards for the start of a filename/variable word */
- li = FUN(el,line)(el);
+ li = el_wline(el);
ctemp = li->cursor;
while (ctemp > li->buffer
- && !Strchr(word_break, ctemp[-1])
- && (!special_prefixes || !Strchr(special_prefixes, ctemp[-1]) ) )
+ && !wcschr(word_break, ctemp[-1])
+ && (!special_prefixes || !wcschr(special_prefixes, ctemp[-1]) ) )
ctemp--;
len = li->cursor - ctemp;
temp = reallocarray(NULL, len + 1, sizeof(*temp));
- (void)Strncpy(temp, ctemp, len);
+ (void)wcsncpy(temp, ctemp, len);
temp[len] = '\0';
/* these can be used by function called in completion_matches() */
@@ -460,7 +460,7 @@ fn_complete(EditLine *el,
*/
if (matches[0][0] != '\0') {
el_deletestr(el, (int) len);
- FUN(el,insertstr)(el,
+ el_winsertstr(el,
ct_decode_string(matches[0], &el->el_scratch));
}
@@ -473,7 +473,7 @@ fn_complete(EditLine *el,
* it, unless we do filename completion and the
* object is a directory.
*/
- FUN(el,insertstr)(el,
+ el_winsertstr(el,
ct_decode_string((*app_func)(matches[0]),
&el->el_scratch));
} else if (what_to_do == '!') {
diff --git a/lib/libedit/hist.c b/lib/libedit/hist.c
index 130870fe425..20b55f38312 100644
--- a/lib/libedit/hist.c
+++ b/lib/libedit/hist.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hist.c,v 1.15 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: hist.c,v 1.16 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: hist.c,v 1.26 2016/04/09 18:43:17 christos Exp $ */
/*-
@@ -98,7 +98,7 @@ hist_get(EditLine *el)
int h;
if (el->el_history.eventno == 0) { /* if really the current line */
- (void) Strncpy(el->el_line.buffer, el->el_history.buf,
+ (void) wcsncpy(el->el_line.buffer, el->el_history.buf,
el->el_history.sz);
el->el_line.lastchar = el->el_line.buffer +
(el->el_history.last - el->el_history.buf);
@@ -125,10 +125,10 @@ hist_get(EditLine *el)
el->el_history.eventno = h;
return CC_ERROR;
}
- (void) Strncpy(el->el_line.buffer, hp,
+ (void) wcsncpy(el->el_line.buffer, hp,
(size_t)(el->el_line.limit - el->el_line.buffer));
el->el_line.buffer[el->el_line.limit - el->el_line.buffer - 1] = '\0';
- el->el_line.lastchar = el->el_line.buffer + Strlen(el->el_line.buffer);
+ el->el_line.lastchar = el->el_line.buffer + wcslen(el->el_line.buffer);
if (el->el_line.lastchar > el->el_line.buffer
&& el->el_line.lastchar[-1] == '\n')
@@ -160,7 +160,7 @@ hist_command(EditLine *el, int argc, const Char **argv)
if (el->el_history.ref == NULL)
return -1;
- if (argc == 1 || Strcmp(argv[1], STR("list")) == 0) {
+ if (argc == 1 || wcscmp(argv[1], L"list") == 0) {
/* List history entries */
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
@@ -174,10 +174,10 @@ hist_command(EditLine *el, int argc, const Char **argv)
num = (int)wcstol(argv[2], NULL, 0);
- if (Strcmp(argv[1], STR("size")) == 0)
+ if (wcscmp(argv[1], L"size") == 0)
return history(el->el_history.ref, &ev, H_SETSIZE, num);
- if (Strcmp(argv[1], STR("unique")) == 0)
+ if (wcscmp(argv[1], L"unique") == 0)
return history(el->el_history.ref, &ev, H_SETUNIQUE, num);
return -1;
diff --git a/lib/libedit/hist.h b/lib/libedit/hist.h
index cb3a81c309b..1173b7de13a 100644
--- a/lib/libedit/hist.h
+++ b/lib/libedit/hist.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hist.h,v 1.13 2016/04/09 19:31:55 schwarze Exp $ */
+/* $OpenBSD: hist.h,v 1.14 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: hist.h,v 1.19 2016/03/23 22:27:48 christos Exp $ */
/*-
@@ -41,7 +41,7 @@
#ifndef _h_el_hist
#define _h_el_hist
-typedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...);
+typedef int (*hist_fun_t)(void *, HistEventW *, int, ...);
typedef struct el_history_t {
Char *buf; /* The history buffer */
@@ -50,7 +50,7 @@ typedef struct el_history_t {
int eventno; /* Event we are looking for */
void *ref; /* Argument for history fcns */
hist_fun_t fun; /* Event access */
- TYPE(HistEvent) ev; /* Event cookie */
+ HistEventW ev; /* Event cookie */
} el_history_t;
#define HIST_FUN_INTERNAL(el, fn, arg) \
diff --git a/lib/libedit/history.c b/lib/libedit/history.c
index dd5f0c9cc21..110aad9ad0e 100644
--- a/lib/libedit/history.c
+++ b/lib/libedit/history.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: history.c,v 1.24 2016/04/09 19:31:55 schwarze Exp $ */
+/* $OpenBSD: history.c,v 1.25 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: history.c,v 1.37 2010/01/03 18:27:10 christos Exp $ */
/*-
@@ -53,6 +53,38 @@ static const char hist_cookie[] = "_HiStOrY_V2_\n";
#include "histedit.h"
#include "chartype.h"
+
+#ifdef NARROWCHAR
+
+#define FUN(prefix, rest) prefix ## _ ## rest
+#define FUNW(type) type
+#define TYPE(type) type
+#define STR(x) x
+
+#define Strlen(s) strlen(s)
+#define Strdup(s) strdup(s)
+#define Strcmp(d, s) strcmp(d, s)
+#define Strncmp(d, s, n) strncmp(d, s, n)
+#define Strncpy(d, s, n) strncpy(d, s, n)
+#define Strncat(d, s, n) strncat(d, s, n)
+
+#else
+
+#define FUN(prefix, rest) prefix ## _w ## rest
+#define FUNW(type) type ## _w
+#define TYPE(type) type ## W
+#define STR(x) L ## x
+
+#define Strlen(s) wcslen(s)
+#define Strdup(s) wcsdup(s)
+#define Strcmp(d, s) wcscmp(d, s)
+#define Strncmp(d, s, n) wcsncmp(d, s, n)
+#define Strncpy(d, s, n) wcsncpy(d, s, n)
+#define Strncat(d, s, n) wcsncat(d, s, n)
+
+#endif
+
+
typedef int (*history_gfun_t)(void *, TYPE(HistEvent) *);
typedef int (*history_efun_t)(void *, TYPE(HistEvent) *, const Char *);
typedef void (*history_vfun_t)(void *, TYPE(HistEvent) *);
diff --git a/lib/libedit/keymacro.c b/lib/libedit/keymacro.c
index 16a0c63e9b1..ed1dd6acbdb 100644
--- a/lib/libedit/keymacro.c
+++ b/lib/libedit/keymacro.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keymacro.c,v 1.10 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: keymacro.c,v 1.11 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: keymacro.c,v 1.16 2016/04/09 18:43:17 christos Exp $ */
/*-
@@ -351,7 +351,7 @@ node__try(EditLine *el, keymacro_node_t *ptr, const Char *str,
break;
case XK_STR:
case XK_EXE:
- if ((ptr->val.str = Strdup(val->str)) == NULL)
+ if ((ptr->val.str = wcsdup(val->str)) == NULL)
return -1;
break;
default:
diff --git a/lib/libedit/makelist b/lib/libedit/makelist
index df07cc25b12..b6aa9e07abd 100644
--- a/lib/libedit/makelist
+++ b/lib/libedit/makelist
@@ -113,16 +113,16 @@ _EOF
fname = fname s;
}
- printf(" { %-30.30s %-30.30s\n","STR(\"" fname "\"),", uname ",");
+ printf(" { %-30.30s %-30.30s\n","L\"" fname "\",", uname ",");
ok = 1;
}
}
/^ \*/ {
if (ok) {
- printf(" STR(\"");
+ printf(" L\"");
for (i = 2; i < NF; i++)
printf("%s ", $i);
- printf("%s\") },\n", $i);
+ printf("%s\" },\n", $i);
ok = 0;
}
}
diff --git a/lib/libedit/map.c b/lib/libedit/map.c
index 75b5771645b..4eb562abd65 100644
--- a/lib/libedit/map.c
+++ b/lib/libedit/map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: map.c,v 1.20 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: map.c,v 1.21 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: map.c,v 1.25 2009/12/30 22:37:40 christos Exp $ */
/*-
@@ -1082,11 +1082,11 @@ protected int
map_set_editor(EditLine *el, Char *editor)
{
- if (Strcmp(editor, STR("emacs")) == 0) {
+ if (wcscmp(editor, L"emacs") == 0) {
map_init_emacs(el);
return 0;
}
- if (Strcmp(editor, STR("vi")) == 0) {
+ if (wcscmp(editor, L"vi") == 0) {
map_init_vi(el);
return 0;
}
@@ -1105,10 +1105,10 @@ map_get_editor(EditLine *el, const Char **editor)
return -1;
switch (el->el_map.type) {
case MAP_EMACS:
- *editor = STR("emacs");
+ *editor = L"emacs";
return 0;
case MAP_VI:
- *editor = STR("vi");
+ *editor = L"vi";
return 0;
}
return -1;
@@ -1231,9 +1231,9 @@ map_print_all_keys(EditLine *el)
map_print_some_keys(el, el->el_map.alt, prev, i - 1);
(void) fprintf(el->el_outfile, "Multi-character bindings\n");
- keymacro_print(el, STR(""));
+ keymacro_print(el, L"");
(void) fprintf(el->el_outfile, "Arrow key bindings\n");
- terminal_print_arrow(el, STR(""));
+ terminal_print_arrow(el, L"");
}
diff --git a/lib/libedit/parse.c b/lib/libedit/parse.c
index 1cf6524de1f..bc76e7db7a7 100644
--- a/lib/libedit/parse.c
+++ b/lib/libedit/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.17 2016/03/20 23:48:27 schwarze Exp $ */
+/* $OpenBSD: parse.c,v 1.18 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: parse.c,v 1.35 2016/02/17 19:47:49 christos Exp $ */
/*-
@@ -58,14 +58,14 @@ private const struct {
const Char *name;
int (*func)(EditLine *, int, const Char **);
} cmds[] = {
- { STR("bind"), map_bind },
- { STR("echotc"), terminal_echotc },
- { STR("edit"), el_editmode },
- { STR("history"), hist_command },
- { STR("telltc"), terminal_telltc },
- { STR("settc"), terminal_settc },
- { STR("setty"), tty_stty },
- { NULL, NULL }
+ { L"bind", map_bind },
+ { L"echotc", terminal_echotc },
+ { L"edit", el_editmode },
+ { L"history", hist_command },
+ { L"telltc", terminal_telltc },
+ { L"settc", terminal_settc },
+ { L"setty", tty_stty },
+ { NULL, NULL }
};
@@ -77,12 +77,12 @@ parse_line(EditLine *el, const Char *line)
{
const Char **argv;
int argc;
- TYPE(Tokenizer) *tok;
+ TokenizerW *tok;
- tok = FUN(tok,init)(NULL);
- FUN(tok,str)(tok, line, &argc, &argv);
- argc = FUN(el,parse)(el, argc, argv);
- FUN(tok,end)(tok);
+ tok = tok_winit(NULL);
+ tok_wstr(tok, line, &argc, &argv);
+ argc = el_wparse(el, argc, argv);
+ tok_wend(tok);
return argc;
}
@@ -91,14 +91,14 @@ parse_line(EditLine *el, const Char *line)
* Command dispatcher
*/
public int
-FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
+el_wparse(EditLine *el, int argc, const Char *argv[])
{
const Char *ptr;
int i;
if (argc < 1)
return -1;
- ptr = Strchr(argv[0], ':');
+ ptr = wcschr(argv[0], L':');
if (ptr != NULL) {
Char *tprog;
size_t l;
@@ -109,7 +109,7 @@ FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
tprog = reallocarray(NULL, l + 1, sizeof(*tprog));
if (tprog == NULL)
return 0;
- (void) Strncpy(tprog, argv[0], l);
+ (void) wcsncpy(tprog, argv[0], l);
tprog[l] = '\0';
ptr++;
l = el_match(el->el_prog, tprog);
@@ -120,7 +120,7 @@ FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
ptr = argv[0];
for (i = 0; cmds[i].name != NULL; i++)
- if (Strcmp(cmds[i].name, ptr) == 0) {
+ if (wcscmp(cmds[i].name, ptr) == 0) {
i = (*cmds[i].func) (el, argc, argv);
return -i;
}
@@ -170,28 +170,28 @@ parse__escape(const Char **ptr)
case 'e':
c = '\033'; /* Escape */
break;
- case 'U': /* Unicode \U+xxxx or \U+xxxxx format */
- {
- int i;
- const Char hex[] = STR("0123456789ABCDEF");
- const Char *h;
- ++p;
- if (*p++ != '+')
- return -1;
+ case 'U': /* Unicode \U+xxxx or \U+xxxxx format */
+ {
+ int i;
+ const Char hex[] = L"0123456789ABCDEF";
+ const Char *h;
+ ++p;
+ if (*p++ != '+')
+ return -1;
c = 0;
- for (i = 0; i < 5; ++i) {
- h = Strchr(hex, *p++);
- if (!h && i < 4)
- return -1;
- else if (h)
- c = (c << 4) | ((int)(h - hex));
- else
- --p;
- }
- if (c > 0x10FFFF) /* outside valid character range */
- return -1;
- break;
- }
+ for (i = 0; i < 5; ++i) {
+ h = wcschr(hex, *p++);
+ if (!h && i < 4)
+ return -1;
+ else if (h)
+ c = (c << 4) | ((int)(h - hex));
+ else
+ --p;
+ }
+ if (c > 0x10FFFF) /* outside valid character range */
+ return -1;
+ break;
+ }
case '0':
case '1':
case '2':
@@ -277,7 +277,7 @@ parse_cmd(EditLine *el, const Char *cmd)
int i;
for (b = el->el_map.help, i = 0; i < el->el_map.nfunc; i++)
- if (Strcmp(b[i].name, cmd) == 0)
+ if (wcscmp(b[i].name, cmd) == 0)
return b[i].func;
return -1;
}
diff --git a/lib/libedit/read.c b/lib/libedit/read.c
index 7353681b814..68d105f2098 100644
--- a/lib/libedit/read.c
+++ b/lib/libedit/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.32 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.33 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: read.c,v 1.88 2016/04/09 18:43:17 christos Exp $ */
/*-
@@ -181,13 +181,13 @@ read__fixio(int fd __attribute__((__unused__)), int e)
* Push a macro
*/
public void
-FUN(el,push)(EditLine *el, const Char *str)
+el_wpush(EditLine *el, const Char *str)
{
c_macro_t *ma = &el->el_chared.c_macro;
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
ma->level++;
- if ((ma->macro[ma->level] = Strdup(str)) != NULL)
+ if ((ma->macro[ma->level] = wcsdup(str)) != NULL)
return;
ma->level--;
}
@@ -239,7 +239,7 @@ read_getcmd(EditLine *el, el_action_t *cmdnum, Char *ch)
cmd = val.cmd;
break;
case XK_STR:
- FUN(el,push)(el, val.str);
+ el_wpush(el, val.str);
break;
#ifdef notyet
case XK_EXE:
@@ -436,7 +436,7 @@ read_finish(EditLine *el)
}
public const Char *
-FUN(el,gets)(EditLine *el, int *nread)
+el_wgets(EditLine *el, int *nread)
{
int retval;
el_action_t cmdnum = 0;
diff --git a/lib/libedit/refresh.c b/lib/libedit/refresh.c
index 13170a26a05..f7481bb8aeb 100644
--- a/lib/libedit/refresh.c
+++ b/lib/libedit/refresh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: refresh.c,v 1.16 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: refresh.c,v 1.17 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: refresh.c,v 1.46 2016/04/09 18:43:17 christos Exp $ */
/*-
@@ -315,10 +315,10 @@ re_refresh(EditLine *el)
for (; i <= el->el_refresh.r_oldcv; i++) {
terminal_move_to_line(el, i);
terminal_move_to_char(el, 0);
- /* This Strlen should be safe even with MB_FILL_CHARs */
- terminal_clear_EOL(el, (int) Strlen(el->el_display[i]));
+ /* This wcslen should be safe even with MB_FILL_CHARs */
+ terminal_clear_EOL(el, (int) wcslen(el->el_display[i]));
#ifdef DEBUG_REFRESH
- terminal_overwrite(el, STR("C\b"), 2);
+ terminal_overwrite(el, L"C\b", 2);
#endif /* DEBUG_REFRESH */
el->el_display[i][0] = '\0';
}
@@ -1079,7 +1079,7 @@ re_fastputc(EditLine *el, wint_t c)
for(i = 1; i < lins; i++)
el->el_display[i - 1] = el->el_display[i];
- re__copy_and_pad(firstline, STR(""), 0);
+ re__copy_and_pad(firstline, L"", 0);
el->el_display[i - 1] = firstline;
} else {
el->el_cursor.v++;
diff --git a/lib/libedit/search.c b/lib/libedit/search.c
index 4b5948314d6..1b1b6aef2ca 100644
--- a/lib/libedit/search.c
+++ b/lib/libedit/search.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: search.c,v 1.22 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: search.c,v 1.23 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: search.c,v 1.41 2016/04/09 18:43:17 christos Exp $ */
/*-
@@ -173,11 +173,11 @@ c_setpat(EditLine *el)
if (el->el_search.patlen >= EL_BUFSIZ)
el->el_search.patlen = EL_BUFSIZ - 1;
if (el->el_search.patlen != 0) {
- (void) Strncpy(el->el_search.patbuf, el->el_line.buffer,
+ (void) wcsncpy(el->el_search.patbuf, el->el_line.buffer,
el->el_search.patlen);
el->el_search.patbuf[el->el_search.patlen] = '\0';
} else
- el->el_search.patlen = Strlen(el->el_search.patbuf);
+ el->el_search.patlen = wcslen(el->el_search.patbuf);
}
#ifdef SDEBUG
(void) fprintf(el->el_errfile, "\neventno = %d\n",
@@ -321,7 +321,7 @@ ce_inc_search(EditLine *el, int dir)
default: /* Terminate and execute cmd */
endcmd[0] = ch;
- FUN(el,push)(el, endcmd);
+ el_wpush(el, endcmd);
/* FALLTHROUGH */
case 0033: /* ESC: Terminate */
@@ -461,7 +461,7 @@ cv_search(EditLine *el, int dir)
el->el_search.patdir = dir;
tmplen = c_gets(el, &tmpbuf[LEN],
- dir == ED_SEARCH_PREV_HISTORY ? STR("\n/") : STR("\n?") );
+ dir == ED_SEARCH_PREV_HISTORY ? L"\n/" : L"\n?" );
if (tmplen == -1)
return CC_REFRESH;
@@ -480,11 +480,11 @@ cv_search(EditLine *el, int dir)
#ifdef ANCHOR
if (el->el_search.patbuf[0] != '.' &&
el->el_search.patbuf[0] != '*') {
- (void) Strncpy(tmpbuf, el->el_search.patbuf,
+ (void) wcsncpy(tmpbuf, el->el_search.patbuf,
sizeof(tmpbuf) / sizeof(*tmpbuf) - 1);
el->el_search.patbuf[0] = '.';
el->el_search.patbuf[1] = '*';
- (void) Strncpy(&el->el_search.patbuf[2], tmpbuf,
+ (void) wcsncpy(&el->el_search.patbuf[2], tmpbuf,
EL_BUFSIZ - 3);
el->el_search.patlen++;
el->el_search.patbuf[el->el_search.patlen++] = '.';
@@ -498,7 +498,7 @@ cv_search(EditLine *el, int dir)
tmpbuf[tmplen++] = '*';
#endif
tmpbuf[tmplen] = '\0';
- (void) Strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
+ (void) wcsncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
el->el_search.patlen = tmplen;
}
el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
diff --git a/lib/libedit/terminal.c b/lib/libedit/terminal.c
index 1ba9b987475..47d5b777ee8 100644
--- a/lib/libedit/terminal.c
+++ b/lib/libedit/terminal.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: terminal.c,v 1.13 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: terminal.c,v 1.14 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: terminal.c,v 1.17 2016/02/15 15:35:03 christos Exp $ */
/*-
@@ -998,32 +998,32 @@ terminal_init_arrow(EditLine *el)
{
funckey_t *arrow = el->el_terminal.t_fkey;
- arrow[A_K_DN].name = STR("down");
+ arrow[A_K_DN].name = L"down";
arrow[A_K_DN].key = T_kd;
arrow[A_K_DN].fun.cmd = ED_NEXT_HISTORY;
arrow[A_K_DN].type = XK_CMD;
- arrow[A_K_UP].name = STR("up");
+ arrow[A_K_UP].name = L"up";
arrow[A_K_UP].key = T_ku;
arrow[A_K_UP].fun.cmd = ED_PREV_HISTORY;
arrow[A_K_UP].type = XK_CMD;
- arrow[A_K_LT].name = STR("left");
+ arrow[A_K_LT].name = L"left";
arrow[A_K_LT].key = T_kl;
arrow[A_K_LT].fun.cmd = ED_PREV_CHAR;
arrow[A_K_LT].type = XK_CMD;
- arrow[A_K_RT].name = STR("right");
+ arrow[A_K_RT].name = L"right";
arrow[A_K_RT].key = T_kr;
arrow[A_K_RT].fun.cmd = ED_NEXT_CHAR;
arrow[A_K_RT].type = XK_CMD;
- arrow[A_K_HO].name = STR("home");
+ arrow[A_K_HO].name = L"home";
arrow[A_K_HO].key = T_kh;
arrow[A_K_HO].fun.cmd = ED_MOVE_TO_BEG;
arrow[A_K_HO].type = XK_CMD;
- arrow[A_K_EN].name = STR("end");
+ arrow[A_K_EN].name = L"end";
arrow[A_K_EN].key = T_at7;
arrow[A_K_EN].fun.cmd = ED_MOVE_TO_END;
arrow[A_K_EN].type = XK_CMD;
@@ -1091,7 +1091,7 @@ terminal_set_arrow(EditLine *el, const Char *name, keymacro_value_t *fun,
int i;
for (i = 0; i < A_K_NKEYS; i++)
- if (Strcmp(name, arrow[i].name) == 0) {
+ if (wcscmp(name, arrow[i].name) == 0) {
arrow[i].fun = *fun;
arrow[i].type = type;
return 0;
@@ -1110,7 +1110,7 @@ terminal_clear_arrow(EditLine *el, const Char *name)
int i;
for (i = 0; i < A_K_NKEYS; i++)
- if (Strcmp(name, arrow[i].name) == 0) {
+ if (wcscmp(name, arrow[i].name) == 0) {
arrow[i].type = XK_NOD;
return 0;
}
@@ -1128,7 +1128,7 @@ terminal_print_arrow(EditLine *el, const Char *name)
funckey_t *arrow = el->el_terminal.t_fkey;
for (i = 0; i < A_K_NKEYS; i++)
- if (*name == '\0' || Strcmp(name, arrow[i].name) == 0)
+ if (*name == '\0' || wcscmp(name, arrow[i].name) == 0)
if (arrow[i].type != XK_NOD)
keymacro_kprint(el, arrow[i].name,
&arrow[i].fun, arrow[i].type);
@@ -1480,28 +1480,28 @@ terminal_echotc(EditLine *el, int argc __attribute__((__unused__)),
}
if (!*argv || *argv[0] == '\0')
return 0;
- if (Strcmp(*argv, STR("tabs")) == 0) {
+ if (wcscmp(*argv, L"tabs") == 0) {
(void) fprintf(el->el_outfile, fmts, EL_CAN_TAB ? "yes" : "no");
return 0;
- } else if (Strcmp(*argv, STR("meta")) == 0) {
+ } else if (wcscmp(*argv, L"meta") == 0) {
(void) fprintf(el->el_outfile, fmts, Val(T_km) ? "yes" : "no");
return 0;
- } else if (Strcmp(*argv, STR("xn")) == 0) {
+ } else if (wcscmp(*argv, L"xn") == 0) {
(void) fprintf(el->el_outfile, fmts, EL_HAS_MAGIC_MARGINS ?
"yes" : "no");
return 0;
- } else if (Strcmp(*argv, STR("am")) == 0) {
+ } else if (wcscmp(*argv, L"am") == 0) {
(void) fprintf(el->el_outfile, fmts, EL_HAS_AUTO_MARGINS ?
"yes" : "no");
return 0;
- } else if (Strcmp(*argv, STR("baud")) == 0) {
+ } else if (wcscmp(*argv, L"baud") == 0) {
(void) fprintf(el->el_outfile, fmtd, (int)el->el_tty.t_speed);
return 0;
- } else if (Strcmp(*argv, STR("rows")) == 0 ||
- Strcmp(*argv, STR("lines")) == 0) {
+ } else if (wcscmp(*argv, L"rows") == 0 ||
+ wcscmp(*argv, L"lines") == 0) {
(void) fprintf(el->el_outfile, fmtd, Val(T_li));
return 0;
- } else if (Strcmp(*argv, STR("cols")) == 0) {
+ } else if (wcscmp(*argv, L"cols") == 0) {
(void) fprintf(el->el_outfile, fmtd, Val(T_co));
return 0;
}
diff --git a/lib/libedit/tokenizer.c b/lib/libedit/tokenizer.c
index 6a026654eaf..1cdb9019d22 100644
--- a/lib/libedit/tokenizer.c
+++ b/lib/libedit/tokenizer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tokenizer.c,v 1.17 2016/03/20 23:48:27 schwarze Exp $ */
+/* $OpenBSD: tokenizer.c,v 1.18 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: tokenizer.c,v 1.23 2016/02/15 15:37:20 christos Exp $ */
/*-
@@ -57,8 +57,19 @@ typedef enum {
#define IFS STR("\t \n")
-#define tok_strdup(a) Strdup(a)
-
+#ifdef NARROWCHAR
+#define FUN(prefix, rest) prefix ## _ ## rest
+#define TYPE(type) type
+#define STR(x) x
+#define Strchr(s, c) strchr(s, c)
+#define tok_strdup(s) strdup(s)
+#else
+#define FUN(prefix, rest) prefix ## _w ## rest
+#define TYPE(type) type ## W
+#define STR(x) L ## x
+#define Strchr(s, c) wcschr(s, c)
+#define tok_strdup(s) wcsdup(s)
+#endif
struct TYPE(tokenizer) {
Char *ifs; /* In field separator */
diff --git a/lib/libedit/tty.c b/lib/libedit/tty.c
index cc694e86d00..452b0cfb934 100644
--- a/lib/libedit/tty.c
+++ b/lib/libedit/tty.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty.c,v 1.23 2016/04/09 20:15:26 schwarze Exp $ */
+/* $OpenBSD: tty.c,v 1.24 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: tty.c,v 1.34 2011/01/27 23:11:40 christos Exp $ */
/*-
@@ -1243,7 +1243,7 @@ tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
break;
}
d = s;
- p = Strchr(s, '=');
+ p = wcschr(s, L'=');
for (m = ttymodes; m->m_name; m++)
if ((p ? strncmp(m->m_name, ct_encode_string(d, &el->el_scratch), (size_t)(p - d)) :
strcmp(m->m_name, ct_encode_string(d, &el->el_scratch))) == 0 &&
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c
index 5cf96a3de94..d279a1c6616 100644
--- a/lib/libedit/vi.c
+++ b/lib/libedit/vi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vi.c,v 1.21 2016/04/09 20:28:27 schwarze Exp $ */
+/* $OpenBSD: vi.c,v 1.22 2016/04/11 19:54:54 schwarze Exp $ */
/* $NetBSD: vi.c,v 1.33 2011/02/17 16:44:48 joerg Exp $ */
/*-
@@ -803,7 +803,7 @@ protected el_action_t
/*ARGSUSED*/
vi_match(EditLine *el, wint_t c __attribute__((__unused__)))
{
- const Char match_chars[] = STR("()[]{}");
+ const Char match_chars[] = L"()[]{}";
Char *cp;
size_t delta, i, count;
Char o_ch, c_ch;
@@ -814,7 +814,7 @@ vi_match(EditLine *el, wint_t c __attribute__((__unused__)))
o_ch = el->el_line.cursor[i];
if (o_ch == 0)
return CC_ERROR;
- delta = Strchr(match_chars, o_ch) - match_chars;
+ delta = wcschr(match_chars, o_ch) - match_chars;
c_ch = match_chars[delta ^ 1];
count = 1;
delta = 1 - (delta & 1) * 2;
@@ -941,7 +941,7 @@ vi_alias(EditLine *el, wint_t c __attribute__((__unused__)))
alias_text = my_get_alias_text(alias_name);
if (alias_text != NULL)
- FUN(el,push)(el, ct_decode_string(alias_text, &el->el_scratch));
+ el_wpush(el, ct_decode_string(alias_text, &el->el_scratch));
return CC_NORM;
#else
return CC_ERROR;
@@ -961,7 +961,7 @@ vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__)))
if (el->el_history.eventno == 0) {
- (void) Strncpy(el->el_history.buf, el->el_line.buffer,
+ (void) wcsncpy(el->el_history.buf, el->el_line.buffer,
EL_BUFSIZ);
el->el_history.last = el->el_history.buf +
(el->el_line.lastchar - el->el_line.buffer);
@@ -1033,7 +1033,7 @@ vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))
free(cp);
return CC_ERROR;
}
- Strncpy(line, el->el_line.buffer, len);
+ wcsncpy(line, el->el_line.buffer, len);
line[len] = '\0';
wcstombs(cp, line, TMP_BUFSIZ - 1);
cp[TMP_BUFSIZ - 1] = '\0';
@@ -1154,7 +1154,7 @@ vi_redo(EditLine *el, wint_t c __attribute__((__unused__)))
/* sanity */
r->pos = r->lim - 1;
r->pos[0] = 0;
- FUN(el,push)(el, r->buf);
+ el_wpush(el, r->buf);
}
el->el_state.thiscmd = r->cmd;