summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2017-09-13 15:57:58 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2017-09-13 15:57:58 +0000
commit8c36b0434ca4a5ba6df2724542048eb219af7a34 (patch)
treeb6315213d0c73ac7d01023a1a82d568559b68b19 /parse.c
parent70f1d4d70d0c78aa69c52d977130f4046851c4a3 (diff)
Notes
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c118
1 files changed, 59 insertions, 59 deletions
diff --git a/parse.c b/parse.c
index ee58296c25f2..fdd0d847a79d 100644
--- a/parse.c
+++ b/parse.c
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.35 2016/02/17 19:47:49 christos Exp $ */
+/* $NetBSD: parse.c,v 1.40 2016/05/09 21:46:56 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.35 2016/02/17 19:47:49 christos Exp $");
+__RCSID("$NetBSD: parse.c,v 1.40 2016/05/09 21:46:56 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -60,35 +60,35 @@ __RCSID("$NetBSD: parse.c,v 1.35 2016/02/17 19:47:49 christos Exp $");
#include "el.h"
#include "parse.h"
-private const struct {
- const Char *name;
- int (*func)(EditLine *, int, const Char **);
+static const struct {
+ const wchar_t *name;
+ int (*func)(EditLine *, int, const wchar_t **);
} 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 }
};
/* parse_line():
* Parse a line and dispatch it
*/
-protected int
-parse_line(EditLine *el, const Char *line)
+libedit_private int
+parse_line(EditLine *el, const wchar_t *line)
{
- const Char **argv;
+ const wchar_t **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;
}
@@ -96,17 +96,17 @@ parse_line(EditLine *el, const Char *line)
/* el_parse():
* Command dispatcher
*/
-public int
-FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
+int
+el_wparse(EditLine *el, int argc, const wchar_t *argv[])
{
- const Char *ptr;
+ const wchar_t *ptr;
int i;
if (argc < 1)
return -1;
- ptr = Strchr(argv[0], ':');
+ ptr = wcschr(argv[0], L':');
if (ptr != NULL) {
- Char *tprog;
+ wchar_t *tprog;
size_t l;
if (ptr == argv[0])
@@ -115,7 +115,7 @@ FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
tprog = el_malloc((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 = (size_t)el_match(el->el_prog, tprog);
@@ -126,7 +126,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;
}
@@ -138,10 +138,10 @@ FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
* Parse a string of the form ^<char> \<odigit> \<char> \U+xxxx and return
* the appropriate character or -1 if the escape is not valid
*/
-protected int
-parse__escape(const Char **ptr)
+libedit_private int
+parse__escape(const wchar_t **ptr)
{
- const Char *p;
+ const wchar_t *p;
wint_t c;
p = *ptr;
@@ -176,28 +176,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 wchar_t hex[] = L"0123456789ABCDEF";
+ const wchar_t *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':
@@ -238,10 +238,10 @@ parse__escape(const Char **ptr)
/* parse__string():
* Parse the escapes from in and put the raw string out
*/
-protected Char *
-parse__string(Char *out, const Char *in)
+libedit_private wchar_t *
+parse__string(wchar_t *out, const wchar_t *in)
{
- Char *rv = out;
+ wchar_t *rv = out;
int n;
for (;;)
@@ -254,7 +254,7 @@ parse__string(Char *out, const Char *in)
case '^':
if ((n = parse__escape(&in)) == -1)
return NULL;
- *out++ = (Char)n;
+ *out++ = (wchar_t)n;
break;
case 'M':
@@ -276,14 +276,14 @@ parse__string(Char *out, const Char *in)
* Return the command number for the command string given
* or -1 if one is not found
*/
-protected int
-parse_cmd(EditLine *el, const Char *cmd)
+libedit_private int
+parse_cmd(EditLine *el, const wchar_t *cmd)
{
el_bindings_t *b = el->el_map.help;
size_t i;
for (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;
}