FreeCalypso > hg > freecalypso-tools
view rvinterf/tmsh/usercmd.c @ 33:cefdc6623322
fc-e1gen utility written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 25 Oct 2016 06:49:27 +0000 |
parents | ea061975c883 |
children | ee89ff178ba5 |
line wrap: on
line source
/* * This module implements fc-tmsh user command dispatch. */ #include <sys/types.h> #include <ctype.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> extern char usercmd[]; extern void cmd_abbr(); extern void cmd_abbw(); extern void cmd_audio(); extern void cmd_check_ffs1(); extern void cmd_dieid(); extern void cmd_etmpkt(); extern void cmd_ffs2(); extern void cmd_omr(); extern void cmd_ping(); extern void cmd_r8(); extern void cmd_r16(); extern void cmd_r32(); extern void cmd_set_imeisv(); extern void cmd_set_pcm_string(); extern void cmd_set_rfcap(); extern void cmd_tgtreset(); extern void cmd_version(); extern void cmd_w8(); extern void cmd_w16(); extern void cmd_w32(); void cmd_exit() { tty_cleanup(); exit(0); } static struct cmdtab { char *cmd; int minargs; int maxargs; void (*func)(); } cmdtab[] = { {"abbr", 2, 2, cmd_abbr}, {"abbw", 3, 3, cmd_abbw}, {"audio", 2, 2, cmd_audio}, {"check-ffs1", 0, 0, cmd_check_ffs1}, {"dieid", 0, 0, cmd_dieid}, {"etmpkt", 1, 253, cmd_etmpkt}, {"exit", 0, 0, cmd_exit}, {"ffs2", 1, 3, cmd_ffs2}, {"omr", 2, 2, cmd_omr}, {"ping", 0, 2, cmd_ping}, {"quit", 0, 0, cmd_exit}, {"r8", 1, 2, cmd_r8}, {"r16", 1, 2, cmd_r16}, {"r32", 1, 2, cmd_r32}, {"set-imeisv", 2, 2, cmd_set_imeisv}, {"set-pcm-string", 2, 2, cmd_set_pcm_string}, {"set-rfcap", 16, 16, cmd_set_rfcap}, {"tgtreset", 0, 0, cmd_tgtreset}, {"version", 1, 1, cmd_version}, {"w8", 2, 246, cmd_w8}, {"w16", 2, 123, cmd_w16}, {"w32", 2, 62, cmd_w32}, {0, 0, 0, 0} }; void dispatch_user_cmd() { char *argv[257]; char *cp, **ap; struct cmdtab *tp; for (cp = usercmd; isspace(*cp); cp++) ; if (!*cp || *cp == '#') return; argv[0] = cp; while (*cp && !isspace(*cp)) cp++; if (*cp) *cp++ = '\0'; for (tp = cmdtab; tp->cmd; tp++) if (!strcmp(tp->cmd, argv[0])) break; if (!tp->func) { printf("error: no such command\n"); return; } for (ap = argv + 1; ; ) { while (isspace(*cp)) cp++; if (!*cp || *cp == '#') break; if (ap - argv - 1 >= tp->maxargs) { printf("error: too many arguments\n"); return; } if (*cp == '"') { *ap++ = ++cp; while (*cp && *cp != '"') cp++; if (*cp != '"') { printf("error: unterminated quoted string\n"); return; } *cp++ = '\0'; } else { *ap++ = cp; while (*cp && !isspace(*cp)) cp++; if (*cp) *cp++ = '\0'; } } if (ap - argv - 1 < tp->minargs) { printf("error: too few arguments\n"); return; } *ap = 0; tp->func(ap - argv, argv); }