summaryrefslogtreecommitdiffstats
path: root/lib/libedit/parse.c
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2016-04-11 19:54:53 +0000
committerschwarze <schwarze@openbsd.org>2016-04-11 19:54:53 +0000
commit5c93237dc61741a77e4aedea71fcbacffe8f97ad (patch)
treebc0e95ee0e85ecbc603cd014b3d6702559a8323f /lib/libedit/parse.c
parent- In isin(), quote $_b to ensure it's treated as string not as pattern. (diff)
downloadwireguard-openbsd-5c93237dc61741a77e4aedea71fcbacffe8f97ad.tar.xz
wireguard-openbsd-5c93237dc61741a77e4aedea71fcbacffe8f97ad.zip
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.
Diffstat (limited to 'lib/libedit/parse.c')
-rw-r--r--lib/libedit/parse.c80
1 files changed, 40 insertions, 40 deletions
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;
}