FreeCalypso > hg > freecalypso-hwlab
annotate uicc/dispatch.c @ 135:51d6aaa43a7b
fc-uicc-tool: telecom-sum command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 04 Feb 2021 02:55:31 +0000 |
parents | 69628bcfec17 |
children | a21d348e01db |
rev | line source |
---|---|
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the command dispatch for fc-uicc-tool |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <ctype.h> |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h> |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 extern int cmd_exec(); |
134
69628bcfec17
fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
12 extern int cmd_iccid(); |
133
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
130
diff
changeset
|
13 extern int cmd_readbin(); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
130
diff
changeset
|
14 extern int cmd_readrec(); |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern int cmd_select(); |
135
51d6aaa43a7b
fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
134
diff
changeset
|
16 extern int cmd_telecom_sum(); |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern int display_sim_resp_in_hex(); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 extern int good_exit(); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 static struct cmdtab { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char *cmd; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int minargs; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 int maxargs; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int (*func)(); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } cmdtab[] = { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 {"exec", 1, 1, cmd_exec}, |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 {"exit", 0, 0, good_exit}, |
134
69628bcfec17
fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
29 {"iccid", 0, 0, cmd_iccid}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 {"quit", 0, 0, good_exit}, |
133
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
130
diff
changeset
|
31 {"readbin", 2, 2, cmd_readbin}, |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
130
diff
changeset
|
32 {"readrec", 2, 2, cmd_readrec}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 {"select", 1, 1, cmd_select}, |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 {"sim-resp", 0, 0, display_sim_resp_in_hex}, |
135
51d6aaa43a7b
fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
134
diff
changeset
|
35 {"telecom-sum", 0, 0, cmd_telecom_sum}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 {0, 0, 0, 0} |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 }; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 simtool_dispatch_cmd(cmd, is_script) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 char *cmd; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 char *argv[10]; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 char *cp, **ap; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 struct cmdtab *tp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 for (cp = cmd; isspace(*cp); cp++) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 ; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (!*cp || *cp == '#') |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return(0); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (is_script) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 printf("Script command: %s\n", cp); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 argv[0] = cp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 while (*cp && !isspace(*cp)) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (*cp) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 *cp++ = '\0'; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 for (tp = cmdtab; tp->cmd; tp++) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (!strcmp(tp->cmd, argv[0])) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (!tp->func) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 fprintf(stderr, "error: no such command\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 for (ap = argv + 1; ; ) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 while (isspace(*cp)) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (!*cp || *cp == '#') |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (ap - argv - 1 >= tp->maxargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 fprintf(stderr, "error: too many arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (*cp == '"') { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 *ap++ = ++cp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 for (;;) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 if (!*cp) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 unterm_qstring: fprintf(stderr, |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 "error: unterminated quoted string\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (*cp == '"') |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 if (*cp++ == '\\') { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (!*cp) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 goto unterm_qstring; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 *cp++ = '\0'; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 } else { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 *ap++ = cp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 while (*cp && !isspace(*cp)) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 if (*cp) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 *cp++ = '\0'; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 if (ap - argv - 1 < tp->minargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 fprintf(stderr, "error: too few arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 *ap = 0; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 return tp->func(ap - argv, argv); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 dispatch_ready_argv(argc, argv) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 char **argv; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 struct cmdtab *tp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 for (tp = cmdtab; tp->cmd; tp++) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 if (!strcmp(tp->cmd, argv[0])) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 if (!tp->func) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 fprintf(stderr, "error: no such command\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 if (argc - 1 > tp->maxargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 fprintf(stderr, "error: too many arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 if (argc - 1 < tp->minargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 fprintf(stderr, "error: too few arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 return tp->func(argc, argv); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |