FreeCalypso > hg > freecalypso-hwlab
annotate uicc/dispatch.c @ 171:88b8257d353b
eeproms: rm all configs that went to fc-usbser-tools
These configs need to be actively maintained, hence having more than one
official home location for them is a bad idea.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 11 Sep 2023 05:21:56 +0000 |
parents | 19b96c52348f |
children |
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(); |
159
a5e2b6e3bdf7
fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
13 extern int cmd_fix_sysmo_msisdn(); |
134
69628bcfec17
fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
14 extern int cmd_iccid(); |
136
a21d348e01db
fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
15 extern int cmd_pb_dump(); |
a21d348e01db
fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
16 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
|
17 extern int cmd_pb_erase(); |
43463dc91431
fc-uicc-tool: pb-erase commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
18 extern int cmd_pb_erase_one(); |
43463dc91431
fc-uicc-tool: pb-erase commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
19 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
|
20 extern int cmd_pb_update(); |
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(); |
ce2a880ab704
fc-uicc-tool: pb-update commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
22 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
|
23 extern int cmd_readbin(); |
160
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
159
diff
changeset
|
24 extern int cmd_readef(); |
133
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
130
diff
changeset
|
25 extern int cmd_readrec(); |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 extern int cmd_select(); |
138
baf5bd698764
fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
27 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
|
28 extern int cmd_select_isim(); |
6c6e8705dc70
fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
138
diff
changeset
|
29 extern int cmd_select_usim(); |
135
51d6aaa43a7b
fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
134
diff
changeset
|
30 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
|
31 extern int cmd_update_bin(); |
14dee03e9675
fc-uicc-tool: low-level write commands ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
144
diff
changeset
|
32 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
|
33 extern int cmd_update_rec(); |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 extern int display_sim_resp_in_hex(); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 extern int good_exit(); |
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 static struct cmdtab { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 char *cmd; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 int minargs; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 int maxargs; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int (*func)(); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } cmdtab[] = { |
137
c331560c15a4
fc-uicc-tool: dir command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
136
diff
changeset
|
44 {"dir", 0, 0, cmd_dir}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 {"exec", 1, 1, cmd_exec}, |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 {"exit", 0, 0, good_exit}, |
159
a5e2b6e3bdf7
fc-uicc-tool: fix-sysmo-msisdn command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
147
diff
changeset
|
47 {"fix-sysmo-msisdn", 0, 0, cmd_fix_sysmo_msisdn}, |
134
69628bcfec17
fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
48 {"iccid", 0, 0, cmd_iccid}, |
136
a21d348e01db
fc-uicc-tool: pb-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
135
diff
changeset
|
49 {"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
|
50 {"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
|
51 {"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
|
52 {"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
|
53 {"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
|
54 {"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
|
55 {"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
|
56 {"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
|
57 {"quit", 0, 0, good_exit}, |
133
f3bdefbeae38
fc-uicc-tool: readbin and readrec commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
130
diff
changeset
|
58 {"readbin", 2, 2, cmd_readbin}, |
160
19b96c52348f
fc-uicc-tool: readef command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
159
diff
changeset
|
59 {"readef", 1, 1, cmd_readef}, |
144
429a8f80426e
fc-uicc-tool: catch record length from manual select
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
60 {"readrec", 1, 2, cmd_readrec}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 {"select", 1, 1, cmd_select}, |
138
baf5bd698764
fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
137
diff
changeset
|
62 {"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
|
63 {"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
|
64 {"select-usim", 0, 0, cmd_select_usim}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 {"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
|
66 {"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
|
67 {"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
|
68 {"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
|
69 {"update-rec", 2, 2, cmd_update_rec}, |
130
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 {0, 0, 0, 0} |
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 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 simtool_dispatch_cmd(cmd, is_script) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 char *cmd; |
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 char *argv[10]; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 char *cp, **ap; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 struct cmdtab *tp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 for (cp = cmd; isspace(*cp); cp++) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 ; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (!*cp || *cp == '#') |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 return(0); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if (is_script) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 printf("Script command: %s\n", cp); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 argv[0] = cp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 while (*cp && !isspace(*cp)) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 if (*cp) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 *cp++ = '\0'; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 for (tp = cmdtab; tp->cmd; tp++) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (!strcmp(tp->cmd, argv[0])) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 if (!tp->func) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 fprintf(stderr, "error: no such command\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 return(-1); |
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 for (ap = argv + 1; ; ) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 while (isspace(*cp)) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 if (!*cp || *cp == '#') |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 if (ap - argv - 1 >= tp->maxargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 fprintf(stderr, "error: too many arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 if (*cp == '"') { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 *ap++ = ++cp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 for (;;) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 if (!*cp) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 unterm_qstring: fprintf(stderr, |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 "error: unterminated quoted string\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 if (*cp == '"') |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (*cp++ == '\\') { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 if (!*cp) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 goto unterm_qstring; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 cp++; |
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 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 *cp++ = '\0'; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } else { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 *ap++ = cp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 while (*cp && !isspace(*cp)) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 cp++; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 if (*cp) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 *cp++ = '\0'; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 } |
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 if (ap - argv - 1 < tp->minargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 fprintf(stderr, "error: too few arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 return(-1); |
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 *ap = 0; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 return tp->func(ap - argv, 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 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 dispatch_ready_argv(argc, argv) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 char **argv; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 struct cmdtab *tp; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 for (tp = cmdtab; tp->cmd; tp++) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 if (!strcmp(tp->cmd, argv[0])) |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 break; |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 if (!tp->func) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 fprintf(stderr, "error: no such command\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->maxargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 fprintf(stderr, "error: too many 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 if (argc - 1 < tp->minargs) { |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 fprintf(stderr, "error: too few arguments\n"); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 return(-1); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 } |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 return tp->func(argc, argv); |
f691a19f191d
fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |