1
/* $NetBSD: parse.c,v 1.22 2005/05/29 04:58:15 lukem Exp $ */
1
/* $NetBSD: parse.c,v 1.26 2011/08/16 16:25:15 christos Exp $ */
4
4
* Copyright (c) 1992, 1993
57
57
#include <stdlib.h>
59
59
private const struct {
61
int (*func)(EditLine *, int, const char **);
61
int (*func)(EditLine *, int, const Char **);
64
{ "echotc", term_echotc },
65
{ "edit", el_editmode },
66
{ "history", hist_command },
67
{ "telltc", term_telltc },
68
{ "settc", term_settc },
69
{ "setty", tty_stty },
63
{ STR("bind"), map_bind },
64
{ STR("echotc"), terminal_echotc },
65
{ STR("edit"), el_editmode },
66
{ STR("history"), hist_command },
67
{ STR("telltc"), terminal_telltc },
68
{ STR("settc"), terminal_settc },
69
{ STR("setty"), tty_stty },
75
75
* Parse a line and dispatch it
78
parse_line(EditLine *el, const char *line)
78
parse_line(EditLine *el, const Char *line)
85
tok_str(tok, line, &argc, &argv);
86
argc = el_parse(el, argc, argv);
84
tok = FUN(tok,init)(NULL);
85
FUN(tok,str)(tok, line, &argc, &argv);
86
argc = FUN(el,parse)(el, argc, argv);
93
93
* Command dispatcher
96
el_parse(EditLine *el, int argc, const char *argv[])
96
FUN(el,parse)(EditLine *el, int argc, const Char *argv[])
103
ptr = strchr(argv[0], ':');
103
ptr = Strchr(argv[0], ':');
104
104
if (ptr != NULL) {
108
108
if (ptr == argv[0])
110
l = ptr - argv[0] - 1;
111
tprog = (char *) el_malloc(l + 1);
110
l = (size_t)(ptr - argv[0] - 1);
111
tprog = el_malloc((l + 1) * sizeof(*tprog));
112
112
if (tprog == NULL)
114
(void) strncpy(tprog, argv[0], l);
114
(void) Strncpy(tprog, argv[0], l);
117
l = el_match(el->el_prog, tprog);
117
l = (size_t)el_match(el->el_prog, tprog);
124
124
for (i = 0; cmds[i].name != NULL; i++)
125
if (strcmp(cmds[i].name, ptr) == 0) {
125
if (Strcmp(cmds[i].name, ptr) == 0) {
126
126
i = (*cmds[i].func) (el, argc, argv);
133
133
/* parse__escape():
134
* Parse a string of the form ^<char> \<odigit> \<char> and return
134
* Parse a string of the form ^<char> \<odigit> \<char> \U+xxxx and return
135
135
* the appropriate character or -1 if the escape is not valid
138
parse__escape(const char **ptr)
138
parse__escape(const Char **ptr)
148
148
if (*p == '\\') {
173
173
c = '\033'; /* Escape */
175
case 'U': /* Unicode \U+xxxx or \U+xxxxx format */
178
const Char hex[] = STR("0123456789ABCDEF");
184
for (i = 0; i < 5; ++i) {
185
h = Strchr(hex, *p++);
189
c = (c << 4) | ((int)(h - hex));
193
if (c > 0x10FFFF) /* outside valid character range */
212
234
/* parse__string():
213
235
* Parse the escapes from in and put the raw string out
216
parse__string(char *out, const char *in)
238
parse__string(Char *out, const Char *in)
229
251
if ((n = parse__escape(&in)) == -1)
251
273
* or -1 if one is not found
254
parse_cmd(EditLine *el, const char *cmd)
276
parse_cmd(EditLine *el, const Char *cmd)
256
278
el_bindings_t *b;
258
280
for (b = el->el_map.help; b->name != NULL; b++)
259
if (strcmp(b->name, cmd) == 0)
281
if (Strcmp(b->name, cmd) == 0)