summaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c92
1 files changed, 57 insertions, 35 deletions
diff --git a/parse.c b/parse.c
index 5552308ba6fe0..9983fa7503729 100644
--- a/parse.c
+++ b/parse.c
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.22 2005/05/29 04:58:15 lukem Exp $ */
+/* $NetBSD: parse.c,v 1.23 2009/12/30 22:37:40 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.22 2005/05/29 04:58:15 lukem Exp $");
+__RCSID("$NetBSD: parse.c,v 1.23 2009/12/30 22:37:40 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -58,17 +58,17 @@ __RCSID("$NetBSD: parse.c,v 1.22 2005/05/29 04:58:15 lukem Exp $");
#include <stdlib.h>
private const struct {
- const char *name;
- int (*func)(EditLine *, int, const char **);
+ const Char *name;
+ int (*func)(EditLine *, int, const Char **);
} cmds[] = {
- { "bind", map_bind },
- { "echotc", term_echotc },
- { "edit", el_editmode },
- { "history", hist_command },
- { "telltc", term_telltc },
- { "settc", term_settc },
- { "setty", tty_stty },
- { NULL, NULL }
+ { STR("bind"), map_bind },
+ { STR("echotc"), term_echotc },
+ { STR("edit"), el_editmode },
+ { STR("history"), hist_command },
+ { STR("telltc"), term_telltc },
+ { STR("settc"), term_settc },
+ { STR("setty"), tty_stty },
+ { NULL, NULL }
};
@@ -76,16 +76,16 @@ private const struct {
* Parse a line and dispatch it
*/
protected int
-parse_line(EditLine *el, const char *line)
+parse_line(EditLine *el, const Char *line)
{
- const char **argv;
+ const Char **argv;
int argc;
- Tokenizer *tok;
+ TYPE(Tokenizer) *tok;
- tok = tok_init(NULL);
- tok_str(tok, line, &argc, &argv);
- argc = el_parse(el, argc, argv);
- tok_end(tok);
+ tok = FUN(tok,init)(NULL);
+ FUN(tok,str)(tok, line, &argc, &argv);
+ argc = FUN(el,parse)(el, argc, argv);
+ FUN(tok,end)(tok);
return (argc);
}
@@ -94,25 +94,25 @@ parse_line(EditLine *el, const char *line)
* Command dispatcher
*/
public int
-el_parse(EditLine *el, int argc, const char *argv[])
+FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
{
- const char *ptr;
+ const Char *ptr;
int i;
if (argc < 1)
return (-1);
- ptr = strchr(argv[0], ':');
+ ptr = Strchr(argv[0], ':');
if (ptr != NULL) {
- char *tprog;
+ Char *tprog;
size_t l;
if (ptr == argv[0])
return (0);
l = ptr - argv[0] - 1;
- tprog = (char *) el_malloc(l + 1);
+ tprog = el_malloc((l + 1) * sizeof(*tprog));
if (tprog == NULL)
return (0);
- (void) strncpy(tprog, argv[0], l);
+ (void) Strncpy(tprog, argv[0], l);
tprog[l] = '\0';
ptr++;
l = el_match(el->el_prog, tprog);
@@ -123,7 +123,7 @@ 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 (Strcmp(cmds[i].name, ptr) == 0) {
i = (*cmds[i].func) (el, argc, argv);
return (-i);
}
@@ -132,14 +132,14 @@ el_parse(EditLine *el, int argc, const char *argv[])
/* parse__escape():
- * Parse a string of the form ^<char> \<odigit> \<char> and return
+ * 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)
+parse__escape(const Char **ptr)
{
- const char *p;
- int c;
+ const Char *p;
+ Int c;
p = *ptr;
@@ -173,6 +173,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);
+ 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;
+ }
case '0':
case '1':
case '2':
@@ -213,10 +235,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)
+protected Char *
+parse__string(Char *out, const Char *in)
{
- char *rv = out;
+ Char *rv = out;
int n;
for (;;)
@@ -252,12 +274,12 @@ parse__string(char *out, const char *in)
* or -1 if one is not found
*/
protected int
-parse_cmd(EditLine *el, const char *cmd)
+parse_cmd(EditLine *el, const Char *cmd)
{
el_bindings_t *b;
for (b = el->el_map.help; b->name != NULL; b++)
- if (strcmp(b->name, cmd) == 0)
+ if (Strcmp(b->name, cmd) == 0)
return (b->func);
return (-1);
}