FreeCalypso > hg > freecalypso-tools
comparison rvinterf/asyncshell/usercmd.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sat, 11 Jun 2016 00:13:35 +0000 |
| parents | |
| children | 5b4e345095c4 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:e7502631a0f9 |
|---|---|
| 1 /* | |
| 2 * This module implements interactive fc-shell command dispatch. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <ctype.h> | |
| 7 #include <stdio.h> | |
| 8 #include <string.h> | |
| 9 #include <strings.h> | |
| 10 #include <stdlib.h> | |
| 11 | |
| 12 extern char usercmd[]; | |
| 13 | |
| 14 extern void cmd_disable(); | |
| 15 extern void cmd_enable(); | |
| 16 extern void cmd_poweroff(); | |
| 17 extern void cmd_sendat(); | |
| 18 extern void cmd_send_interactive(); | |
| 19 extern void cmd_sp_interactive(); | |
| 20 extern void cmd_tch_dispatch(); | |
| 21 extern void cmd_tchdl_interactive(); | |
| 22 extern void cmd_tgtreset(); | |
| 23 | |
| 24 void | |
| 25 cmd_exit() | |
| 26 { | |
| 27 tty_cleanup(); | |
| 28 exit(0); | |
| 29 } | |
| 30 | |
| 31 static struct cmdtab { | |
| 32 char *cmd; | |
| 33 void (*func)(); | |
| 34 } cmdtab[] = { | |
| 35 {"disable", cmd_disable}, | |
| 36 {"enable", cmd_enable}, | |
| 37 {"exit", cmd_exit}, | |
| 38 {"poweroff", cmd_poweroff}, | |
| 39 {"quit", cmd_exit}, | |
| 40 {"send", cmd_send_interactive}, | |
| 41 {"sp", cmd_sp_interactive}, | |
| 42 {"str", cmd_sendat}, | |
| 43 {"tch", cmd_tch_dispatch}, | |
| 44 {"tch-dl", cmd_tchdl_interactive}, | |
| 45 {"tgtreset", cmd_tgtreset}, | |
| 46 {0, 0} | |
| 47 }; | |
| 48 | |
| 49 void | |
| 50 dispatch_user_cmd() | |
| 51 { | |
| 52 char *cp, *np; | |
| 53 struct cmdtab *tp; | |
| 54 | |
| 55 for (cp = usercmd; isspace(*cp); cp++) | |
| 56 ; | |
| 57 if (!*cp || *cp == '#') | |
| 58 return; | |
| 59 if (!strncmp(cp, "AT", 2) || !strncmp(cp, "at", 2)) { | |
| 60 cmd_sendat(cp); | |
| 61 return; | |
| 62 } | |
| 63 for (np = cp; *cp && !isspace(*cp); cp++) | |
| 64 ; | |
| 65 if (*cp) | |
| 66 *cp++ = '\0'; | |
| 67 for (tp = cmdtab; tp->cmd; tp++) | |
| 68 if (!strcmp(tp->cmd, np)) | |
| 69 break; | |
| 70 if (tp->func) | |
| 71 tp->func(cp); | |
| 72 else | |
| 73 printf("error: no such command\n"); | |
| 74 } |
