FreeCalypso > hg > freecalypso-sw
changeset 1013:6eee1e547778
fc-shell: arbitrary send command implemented in interactive mode
author | Mychaela Falconia <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 20 Mar 2016 22:27:07 +0000 |
parents | 93f4fc26b204 |
children | 0511507bf6e7 |
files | rvinterf/asyncshell/Makefile rvinterf/asyncshell/parse.c rvinterf/asyncshell/sendarb.c rvinterf/asyncshell/usercmd.c |
diffstat | 4 files changed, 80 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/rvinterf/asyncshell/Makefile Sun Mar 20 22:06:11 2016 +0000 +++ b/rvinterf/asyncshell/Makefile Sun Mar 20 22:27:07 2016 +0000 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 -I../include PROG= fc-shell -OBJS= at.o init.o main.o oneshot.o pktsort.o poweroff.o rxctl.o sendarb.o \ - sendsp.o usercmd.o +OBJS= at.o init.o main.o oneshot.o parse.o pktsort.o poweroff.o rxctl.o \ + sendarb.o sendsp.o usercmd.o LIBS= ../libasync/libasync.a ../libg23/libg23.a INSTBIN=/usr/local/bin
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/asyncshell/parse.c Sun Mar 20 22:27:07 2016 +0000 @@ -0,0 +1,53 @@ +/* + * This module implements the parser helper function that allows + * the same code to be reused between interactive and one-shot + * versions of the same command. + */ + +#include <stdio.h> +#include <ctype.h> +#include <string.h> +#include <strings.h> +#include <stdlib.h> + +parse_interactive_command_into_argv(argstr, argv, min_arg, max_arg, argcp) + char *argstr, **argv; + int min_arg, max_arg, *argcp; +{ + char *cp, **ap; + + cp = argstr; + for (ap = argv; ; ) { + while (isspace(*cp)) + cp++; + if (!*cp || *cp == '#') + break; + if (ap - argv >= max_arg) { + printf("error: too many arguments\n"); + return(-1); + } + if (*cp == '"') { + *ap++ = ++cp; + while (*cp && *cp != '"') + cp++; + if (*cp != '"') { + printf("error: unterminated quoted string\n"); + return(-1); + } + *cp++ = '\0'; + } else { + *ap++ = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) + *cp++ = '\0'; + } + } + if (ap - argv < min_arg) { + printf("error: too few arguments\n"); + return(-1); + } + *ap = 0; + *argcp = ap - argv; + return(0); +}
--- a/rvinterf/asyncshell/sendarb.c Sun Mar 20 22:06:11 2016 +0000 +++ b/rvinterf/asyncshell/sendarb.c Sun Mar 20 22:27:07 2016 +0000 @@ -10,15 +10,15 @@ #include <stdlib.h> #include "limits.h" -cmd_send_oneshot(argc, argv) +cmd_send_common(argc, argv) char **argv; { u_char sendpkt[MAX_PKT_TO_TARGET]; - unsigned pktlen = argc - 1, i; + unsigned pktlen = argc, i; char *endp; for (i = 0; i < pktlen; i++) { - sendpkt[i] = strtoul(argv[i+1], &endp, 16); + sendpkt[i] = strtoul(argv[i], &endp, 16); if (*endp) { printf( "error: all arguments to send command must be hex bytes\n"); @@ -29,3 +29,23 @@ send_pkt_to_target(sendpkt, pktlen); return(0); } + +void +cmd_send_interactive(argstr) + char *argstr; +{ + char *argv[MAX_PKT_TO_TARGET+1]; + int argc, rc; + + rc = parse_interactive_command_into_argv(argstr, argv, 1, + MAX_PKT_TO_TARGET, &argc); + if (rc < 0) + return; + cmd_send_common(argc, argv); +} + +cmd_send_oneshot(argc, argv) + char **argv; +{ + return cmd_send_common(argc - 1, argv + 1); +}
--- a/rvinterf/asyncshell/usercmd.c Sun Mar 20 22:06:11 2016 +0000 +++ b/rvinterf/asyncshell/usercmd.c Sun Mar 20 22:27:07 2016 +0000 @@ -15,6 +15,7 @@ extern void cmd_enable(); extern void cmd_poweroff(); extern void cmd_sendat(); +extern void cmd_send_interactive(); extern void cmd_sp_interactive(); extern void cmd_tgtreset(); @@ -34,6 +35,7 @@ {"exit", cmd_exit}, {"poweroff", cmd_poweroff}, {"quit", cmd_exit}, + {"send", cmd_send_interactive}, {"sp", cmd_sp_interactive}, {"str", cmd_sendat}, {"tgtreset", cmd_tgtreset},