FreeCalypso > hg > freecalypso-sw
comparison rvinterf/asyncshell/usercmd.c @ 872:5e46679bdb6a
fc-shell skeleton created
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Sat, 30 May 2015 06:42:32 +0000 |
parents | |
children | 72d64c172d85 |
comparison
equal
deleted
inserted
replaced
871:a5c8f48003cd | 872:5e46679bdb6a |
---|---|
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 void | |
15 cmd_exit() | |
16 { | |
17 tty_cleanup(); | |
18 exit(0); | |
19 } | |
20 | |
21 static struct cmdtab { | |
22 char *cmd; | |
23 void (*func)(); | |
24 } cmdtab[] = { | |
25 {"exit", cmd_exit}, | |
26 {"quit", cmd_exit}, | |
27 {0, 0} | |
28 }; | |
29 | |
30 void | |
31 dispatch_user_cmd() | |
32 { | |
33 char *cp, *np; | |
34 struct cmdtab *tp; | |
35 | |
36 for (cp = usercmd; isspace(*cp); cp++) | |
37 ; | |
38 if (!*cp || *cp == '#') | |
39 return; | |
40 for (np = cp; *cp && !isspace(*cp); cp++) | |
41 ; | |
42 if (*cp) | |
43 *cp++ = '\0'; | |
44 for (tp = cmdtab; tp->cmd; tp++) | |
45 if (!strcmp(tp->cmd, np)) | |
46 break; | |
47 if (tp->func) | |
48 tp->func(cp); | |
49 else | |
50 printf("error: no such command\n"); | |
51 } |