"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libedit/parse.c" between
tnftp-20151004.tar.gz and tnftp-20200705.tar.gz

About: tnftp is an enhanced ftp client (prior name "lukemftp").

parse.c  (tnftp-20151004):parse.c  (tnftp-20200705)
/* $NetBSD: parse.c,v 1.6 2005/06/09 16:48:58 lukem Exp $ */ /* $NetBSD: parse.c,v 1.9 2020/07/04 13:43:21 lukem Exp $ */
/* from NetBSD: parse.c,v 1.22 2005/05/29 04:58:15 lukem Exp */ /* from NetBSD: parse.c,v 1.42 2019/07/23 10:18:52 christos Exp */
/*- /*-
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* This code is derived from software contributed to Berkeley by * This code is derived from software contributed to Berkeley by
* Christos Zoulas of Cornell University. * Christos Zoulas of Cornell University.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
skipping to change at line 36 skipping to change at line 36
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include "tnftp.h" #include "config.h"
#include "sys.h"
#if 0 /* tnftp */
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID(" NetBSD: parse.c,v 1.42 2019/07/23 10:18:52 christos Exp ");
#endif
#endif /* not lint && not SCCSID */
#endif /* tnftp */
/* /*
* parse.c: parse an editline extended command * parse.c: parse an editline extended command
* *
* commands are: * commands are:
* *
* bind * bind
* echotc * echotc
* edit * edit
* gettc * gettc
* history * history
* settc * settc
* setty * setty
*/ */
#include "el.h" #if 0 /* tnftp */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#endif /* tnftp */
#include "el.h"
#include "parse.h"
private const struct { static const struct {
const char *name; const wchar_t *name;
int (*func)(EditLine *, int, const char **); int (*func)(EditLine *, int, const wchar_t **);
} cmds[] = { } cmds[] = {
{ "bind", map_bind }, { L"bind", map_bind },
{ "echotc", term_echotc }, { L"echotc", terminal_echotc },
{ "edit", el_editmode }, { L"edit", el_editmode },
{ "history", hist_command }, { L"history", hist_command },
{ "telltc", term_telltc }, { L"telltc", terminal_telltc },
{ "settc", term_settc }, { L"settc", terminal_settc },
{ "setty", tty_stty }, { L"setty", tty_stty },
{ NULL, NULL } { NULL, NULL }
}; };
/* parse_line(): /* parse_line():
* Parse a line and dispatch it * Parse a line and dispatch it
*/ */
protected int libedit_private int
parse_line(EditLine *el, const char *line) parse_line(EditLine *el, const wchar_t *line)
{ {
const char **argv; const wchar_t **argv;
int argc; int argc;
Tokenizer *tok; TokenizerW *tok;
tok = tok_init(NULL); tok = tok_winit(NULL);
tok_str(tok, line, &argc, &argv); tok_wstr(tok, line, &argc, &argv);
argc = el_parse(el, argc, argv); argc = el_wparse(el, argc, argv);
tok_end(tok); tok_wend(tok);
return (argc); return argc;
} }
/* el_parse(): /* el_parse():
* Command dispatcher * Command dispatcher
*/ */
public int int
el_parse(EditLine *el, int argc, const char *argv[]) el_wparse(EditLine *el, int argc, const wchar_t *argv[])
{ {
const char *ptr; const wchar_t *ptr;
int i; int i;
if (argc < 1) if (argc < 1)
return (-1); return -1;
ptr = strchr(argv[0], ':'); ptr = wcschr(argv[0], L':');
if (ptr != NULL) { if (ptr != NULL) {
char *tprog; wchar_t *tprog;
size_t l; size_t l;
if (ptr == argv[0]) if (ptr == argv[0])
return (0); return 0;
l = ptr - argv[0] - 1; l = (size_t)(ptr - argv[0]);
tprog = (char *) el_malloc(l + 1); tprog = el_calloc(l + 1, sizeof(*tprog));
if (tprog == NULL) if (tprog == NULL)
return (0); return 0;
(void) strncpy(tprog, argv[0], l); (void) wcsncpy(tprog, argv[0], l);
tprog[l] = '\0'; tprog[l] = '\0';
ptr++; ptr++;
l = el_match(el->el_prog, tprog); l = (size_t)el_match(el->el_prog, tprog);
el_free(tprog); el_free(tprog);
if (!l) if (!l)
return (0); return 0;
} else } else
ptr = argv[0]; ptr = argv[0];
for (i = 0; cmds[i].name != NULL; i++) 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); i = (*cmds[i].func) (el, argc, argv);
return (-i); return -i;
} }
return (-1); return -1;
} }
/* parse__escape(): /* 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 * the appropriate character or -1 if the escape is not valid
*/ */
protected int libedit_private int
parse__escape(const char **ptr) parse__escape(const wchar_t **ptr)
{ {
const char *p; const wchar_t *p;
int c; wint_t c;
p = *ptr; p = *ptr;
if (p[1] == 0) if (p[1] == 0)
return (-1); return -1;
if (*p == '\\') { if (*p == '\\') {
p++; p++;
switch (*p) { switch (*p) {
case 'a': case 'a':
c = '\007'; /* Bell */ c = '\007'; /* Bell */
break; break;
case 'b': case 'b':
c = '\010'; /* Backspace */ c = '\010'; /* Backspace */
break; break;
skipping to change at line 168 skipping to change at line 182
break; break;
case 'f': case 'f':
c = '\014'; /* Form Feed */ c = '\014'; /* Form Feed */
break; break;
case 'r': case 'r':
c = '\015'; /* Carriage Return */ c = '\015'; /* Carriage Return */
break; break;
case 'e': case 'e':
c = '\033'; /* Escape */ c = '\033'; /* Escape */
break; break;
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 = 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 '0':
case '1': case '1':
case '2': case '2':
case '3': case '3':
case '4': case '4':
case '5': case '5':
case '6': case '6':
case '7': case '7':
{ {
int cnt, ch; int cnt, ch;
for (cnt = 0, c = 0; cnt < 3; cnt++) { for (cnt = 0, c = 0; cnt < 3; cnt++) {
ch = *p++; ch = *p++;
if (ch < '0' || ch > '7') { if (ch < '0' || ch > '7') {
p--; p--;
break; break;
} }
c = (c << 3) | (ch - '0'); c = (c << 3) | (ch - '0');
} }
if ((c & 0xffffff00) != 0) if ((c & (wint_t)0xffffff00) != (wint_t)0)
return (-1); return -1;
--p; --p;
break; break;
} }
default: default:
c = *p; c = *p;
break; break;
} }
} else if (*p == '^') { } else if (*p == '^') {
p++; p++;
c = (*p == '?') ? '\177' : (*p & 0237); c = (*p == '?') ? '\177' : (*p & 0237);
} else } else
c = *p; c = *p;
*ptr = ++p; *ptr = ++p;
return (c); return c;
} }
/* parse__string(): /* parse__string():
* Parse the escapes from in and put the raw string out * Parse the escapes from in and put the raw string out
*/ */
protected char * libedit_private wchar_t *
parse__string(char *out, const char *in) parse__string(wchar_t *out, const wchar_t *in)
{ {
char *rv = out; wchar_t *rv = out;
int n; int n;
for (;;) for (;;)
switch (*in) { switch (*in) {
case '\0': case '\0':
*out = '\0'; *out = '\0';
return (rv); return rv;
case '\\': case '\\':
case '^': case '^':
if ((n = parse__escape(&in)) == -1) if ((n = parse__escape(&in)) == -1)
return (NULL); return NULL;
*out++ = n; *out++ = (wchar_t)n;
break; break;
case 'M': case 'M':
if (in[1] == '-' && in[2] != '\0') { if (in[1] == '-' && in[2] != '\0') {
*out++ = '\033'; *out++ = '\033';
in += 2; in += 2;
break; break;
} }
/*FALLTHROUGH*/ /*FALLTHROUGH*/
default: default:
*out++ = *in++; *out++ = *in++;
break; break;
} }
} }
/* parse_cmd(): /* parse_cmd():
* Return the command number for the command string given * Return the command number for the command string given
* or -1 if one is not found * or -1 if one is not found
*/ */
protected int libedit_private int
parse_cmd(EditLine *el, const char *cmd) parse_cmd(EditLine *el, const wchar_t *cmd)
{ {
el_bindings_t *b; el_bindings_t *b = el->el_map.help;
size_t i;
for (b = el->el_map.help; b->name != NULL; b++) for (i = 0; i < el->el_map.nfunc; i++)
if (strcmp(b->name, cmd) == 0) if (wcscmp(b[i].name, cmd) == 0)
return (b->func); return b[i].func;
return (-1); return -1;
} }
 End of changes. 35 change blocks. 
63 lines changed or deleted 100 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)