FreeCalypso > hg > freecalypso-hwlab
annotate uicc/dispatch.c @ 151:d515cfbb3f39
fc-simtool: hex string parsing: add minimum length parameter
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Feb 2021 00:18:30 +0000 |
parents | 43463dc91431 |
children | a5e2b6e3bdf7 |
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 |
137
c331560c15a4
fc-uicc-tool: dir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
136
diff
changeset
|
11 extern int cmd_dir(); |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern int cmd_exec(); |
134
69628bcfec17
fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
13 extern int cmd_iccid(); |
136
a21d348e01db
fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
14 extern int cmd_pb_dump(); |
a21d348e01db
fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
15 extern int cmd_pb_dump_rec(); |
147
43463dc91431
fc-uicc-tool: pb-erase commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
16 extern int cmd_pb_erase(); |
43463dc91431
fc-uicc-tool: pb-erase commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
17 extern int cmd_pb_erase_one(); |
43463dc91431
fc-uicc-tool: pb-erase commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
18 extern int cmd_pb_erase_range(); |
146
ce2a880ab704
fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
19 extern int cmd_pb_update(); |
ce2a880ab704
fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
20 extern int cmd_pb_update_imm(); |
ce2a880ab704
fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
21 extern int cmd_pb_update_imm_hex(); |
133
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
130
diff
changeset
|
22 extern int cmd_readbin(); |
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
130
diff
changeset
|
23 extern int cmd_readrec(); |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 extern int cmd_select(); |
138
baf5bd698764
fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
25 extern int cmd_select_aid(); |
139
6c6e8705dc70
fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
138
diff
changeset
|
26 extern int cmd_select_isim(); |
6c6e8705dc70
fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
138
diff
changeset
|
27 extern int cmd_select_usim(); |
135
51d6aaa43a7b
fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
134
diff
changeset
|
28 extern int cmd_telecom_sum(); |
145
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
29 extern int cmd_update_bin(); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
30 extern int cmd_update_bin_imm(); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
31 extern int cmd_update_rec(); |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 extern int display_sim_resp_in_hex(); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 extern int good_exit(); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 static struct cmdtab { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 char *cmd; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 int minargs; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 int maxargs; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 int (*func)(); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } cmdtab[] = { |
137
c331560c15a4
fc-uicc-tool: dir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
136
diff
changeset
|
42 {"dir", 0, 0, cmd_dir}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 {"exec", 1, 1, cmd_exec}, |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 {"exit", 0, 0, good_exit}, |
134
69628bcfec17
fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
45 {"iccid", 0, 0, cmd_iccid}, |
136
a21d348e01db
fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
46 {"pb-dump", 1, 2, cmd_pb_dump}, |
a21d348e01db
fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
47 {"pb-dump-rec", 2, 3, cmd_pb_dump_rec}, |
147
43463dc91431
fc-uicc-tool: pb-erase commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
48 {"pb-erase", 1, 1, cmd_pb_erase}, |
43463dc91431
fc-uicc-tool: pb-erase commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
49 {"pb-erase-one", 2, 2, cmd_pb_erase_one}, |
43463dc91431
fc-uicc-tool: pb-erase commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
50 {"pb-erase-range", 3, 3, cmd_pb_erase_range}, |
146
ce2a880ab704
fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
51 {"pb-update", 2, 2, cmd_pb_update}, |
ce2a880ab704
fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
52 {"pb-update-imm", 3, 4, cmd_pb_update_imm}, |
ce2a880ab704
fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
53 {"pb-update-imm-hex", 4, 4, cmd_pb_update_imm_hex}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 {"quit", 0, 0, good_exit}, |
133
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
130
diff
changeset
|
55 {"readbin", 2, 2, cmd_readbin}, |
144
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
56 {"readrec", 1, 2, cmd_readrec}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 {"select", 1, 1, cmd_select}, |
138
baf5bd698764
fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
58 {"select-aid", 1, 1, cmd_select_aid}, |
140
062141ce5755
fc-uicc-tool: select-[ui]sim: command dispatch bugfix
Mychaela Falconia <falcon@freecalypso.org>
parents:
139
diff
changeset
|
59 {"select-isim", 0, 0, cmd_select_isim}, |
062141ce5755
fc-uicc-tool: select-[ui]sim: command dispatch bugfix
Mychaela Falconia <falcon@freecalypso.org>
parents:
139
diff
changeset
|
60 {"select-usim", 0, 0, cmd_select_usim}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 {"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
|
62 {"telecom-sum", 0, 0, cmd_telecom_sum}, |
145
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
63 {"update-bin", 2, 2, cmd_update_bin}, |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
64 {"update-bin-imm", 2, 2, cmd_update_bin_imm}, |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
65 {"update-rec", 2, 2, cmd_update_rec}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 {0, 0, 0, 0} |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 }; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 simtool_dispatch_cmd(cmd, is_script) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 char *cmd; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 char *argv[10]; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 char *cp, **ap; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 struct cmdtab *tp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 for (cp = cmd; isspace(*cp); cp++) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 ; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (!*cp || *cp == '#') |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return(0); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (is_script) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 printf("Script command: %s\n", cp); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 argv[0] = cp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 while (*cp && !isspace(*cp)) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (*cp) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 *cp++ = '\0'; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 for (tp = cmdtab; tp->cmd; tp++) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (!strcmp(tp->cmd, argv[0])) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (!tp->func) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 fprintf(stderr, "error: no such command\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 for (ap = argv + 1; ; ) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 while (isspace(*cp)) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 if (!*cp || *cp == '#') |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (ap - argv - 1 >= tp->maxargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 fprintf(stderr, "error: too many arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 if (*cp == '"') { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 *ap++ = ++cp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 for (;;) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 if (!*cp) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 unterm_qstring: fprintf(stderr, |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 "error: unterminated quoted string\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 return(-1); |
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 if (*cp == '"') |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 if (*cp++ == '\\') { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 if (!*cp) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 goto unterm_qstring; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 cp++; |
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 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 *cp++ = '\0'; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } else { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 *ap++ = cp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 while (*cp && !isspace(*cp)) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 if (*cp) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 *cp++ = '\0'; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 if (ap - argv - 1 < tp->minargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 fprintf(stderr, "error: too few arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 *ap = 0; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 return tp->func(ap - argv, argv); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 dispatch_ready_argv(argc, argv) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 char **argv; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 struct cmdtab *tp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 for (tp = cmdtab; tp->cmd; tp++) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 if (!strcmp(tp->cmd, argv[0])) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 if (!tp->func) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 fprintf(stderr, "error: no such command\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 if (argc - 1 > tp->maxargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 fprintf(stderr, "error: too many arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (argc - 1 < tp->minargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 fprintf(stderr, "error: too few arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 return tp->func(argc, argv); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 } |