FreeCalypso > hg > fc-pcsc-tools
annotate uicc/dispatch.c @ 226:0f96b5136541
sws-email2db program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 10 Mar 2021 20:34:03 +0000 |
parents | 2ef31306be22 |
children |
rev | line source |
---|---|
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the command dispatch for fc-uicc-tool |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <ctype.h> |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h> |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
121
8e70ee7c194f
fc-simtool & fc-uicc-tool: raw apdu command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
120
diff
changeset
|
11 extern int cmd_apdu(); |
153
2ef31306be22
fc-uicc-tool bfsearch-{adf,mf} implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
12 extern int cmd_bfsearch_adf(); |
2ef31306be22
fc-uicc-tool bfsearch-{adf,mf} implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
13 extern int cmd_bfsearch_mf(); |
133
ede661d78730
fc-uicc-tool: command shell features match fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
121
diff
changeset
|
14 extern int cmd_cd(); |
119
0ac0aee0df11
fc-uicc-tool: remaining PIN commands from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
118
diff
changeset
|
15 extern int cmd_change_pin(); |
139
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
138
diff
changeset
|
16 extern int cmd_create_file(); |
140
13ab44761ea6
fc-uicc-tool delete-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
139
diff
changeset
|
17 extern int cmd_delete_file(); |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern int cmd_dir(); |
119
0ac0aee0df11
fc-uicc-tool: remaining PIN commands from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
118
diff
changeset
|
19 extern int cmd_disable_pin(); |
0ac0aee0df11
fc-uicc-tool: remaining PIN commands from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
118
diff
changeset
|
20 extern int cmd_enable_pin(); |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 extern int cmd_exec(); |
151
d9dd52bc403b
fc-uicc-tool factored-out GET RESPONSE implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
22 extern int cmd_get_response(); |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 extern int cmd_iccid(); |
120
a98992e9fe82
fc-uicc-tool: {pin,puk}-attempt-cnt commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
119
diff
changeset
|
24 extern int cmd_pin_attempt_cnt(); |
a98992e9fe82
fc-uicc-tool: {pin,puk}-attempt-cnt commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
119
diff
changeset
|
25 extern int cmd_puk_attempt_cnt(); |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 extern int cmd_readbin(); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 extern int cmd_readef(); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 extern int cmd_readrec(); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 extern int cmd_select(); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 extern int cmd_select_aid(); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 extern int cmd_select_isim(); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 extern int cmd_select_usim(); |
107
f1836c8d36cb
hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
106
diff
changeset
|
33 extern int cmd_sim_resp(); |
119
0ac0aee0df11
fc-uicc-tool: remaining PIN commands from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
118
diff
changeset
|
34 extern int cmd_unblock_pin(); |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 extern int cmd_update_bin(); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 extern int cmd_update_bin_imm(); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 extern int cmd_update_rec(); |
118
5d45cde6e4b2
fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
38 extern int cmd_verify_hex(); |
5d45cde6e4b2
fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
39 extern int cmd_verify_pin(); |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 extern int good_exit(); |
29
d368051576d0
fc-simtool & fc-uicc-tool: add explicit atr command
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
42 extern int retrieve_atr(); |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 static struct cmdtab { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 char *cmd; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 int minargs; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 int maxargs; |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
48 int allow_redir; |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 int (*func)(); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } cmdtab[] = { |
121
8e70ee7c194f
fc-simtool & fc-uicc-tool: raw apdu command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
120
diff
changeset
|
51 {"apdu", 1, 1, 0, cmd_apdu}, |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
52 {"atr", 0, 0, 0, retrieve_atr}, |
153
2ef31306be22
fc-uicc-tool bfsearch-{adf,mf} implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
53 {"bfsearch-adf", 0, 0, 1, cmd_bfsearch_adf}, |
2ef31306be22
fc-uicc-tool bfsearch-{adf,mf} implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
54 {"bfsearch-mf", 0, 0, 1, cmd_bfsearch_mf}, |
133
ede661d78730
fc-uicc-tool: command shell features match fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
121
diff
changeset
|
55 {"cd", 1, 1, 0, cmd_cd}, |
119
0ac0aee0df11
fc-uicc-tool: remaining PIN commands from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
118
diff
changeset
|
56 {"change-pin", 3, 3, 0, cmd_change_pin}, |
139
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
138
diff
changeset
|
57 {"create-file", 1, 1, 0, cmd_create_file}, |
140
13ab44761ea6
fc-uicc-tool delete-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
139
diff
changeset
|
58 {"delete-file", 1, 1, 0, cmd_delete_file}, |
106
dcfec53643c5
EF_DIR dump commands support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
105
diff
changeset
|
59 {"dir", 0, 0, 1, cmd_dir}, |
119
0ac0aee0df11
fc-uicc-tool: remaining PIN commands from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
118
diff
changeset
|
60 {"disable-pin", 2, 2, 0, cmd_disable_pin}, |
0ac0aee0df11
fc-uicc-tool: remaining PIN commands from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
118
diff
changeset
|
61 {"enable-pin", 2, 2, 0, cmd_enable_pin}, |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
62 {"exec", 1, 1, 0, cmd_exec}, |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
63 {"exit", 0, 0, 0, good_exit}, |
151
d9dd52bc403b
fc-uicc-tool factored-out GET RESPONSE implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
140
diff
changeset
|
64 {"get-response", 1, 1, 1, cmd_get_response}, |
133
ede661d78730
fc-uicc-tool: command shell features match fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
121
diff
changeset
|
65 {"iccid", 0, 0, 1, cmd_iccid}, |
120
a98992e9fe82
fc-uicc-tool: {pin,puk}-attempt-cnt commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
119
diff
changeset
|
66 {"pin-attempt-cnt", 1, 1, 0, cmd_pin_attempt_cnt}, |
a98992e9fe82
fc-uicc-tool: {pin,puk}-attempt-cnt commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
119
diff
changeset
|
67 {"puk-attempt-cnt", 1, 1, 0, cmd_puk_attempt_cnt}, |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
68 {"quit", 0, 0, 0, good_exit}, |
107
f1836c8d36cb
hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
106
diff
changeset
|
69 {"readbin", 2, 2, 1, cmd_readbin}, |
f1836c8d36cb
hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
106
diff
changeset
|
70 {"readef", 1, 1, 1, cmd_readef}, |
f1836c8d36cb
hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
106
diff
changeset
|
71 {"readrec", 1, 2, 1, cmd_readrec}, |
138
58406ead2497
fc-uicc-tool: support output redirection for select commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
72 {"select", 1, 1, 1, cmd_select}, |
58406ead2497
fc-uicc-tool: support output redirection for select commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
73 {"select-aid", 1, 1, 1, cmd_select_aid}, |
58406ead2497
fc-uicc-tool: support output redirection for select commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
74 {"select-isim", 0, 0, 1, cmd_select_isim}, |
58406ead2497
fc-uicc-tool: support output redirection for select commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
133
diff
changeset
|
75 {"select-usim", 0, 0, 1, cmd_select_usim}, |
107
f1836c8d36cb
hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
106
diff
changeset
|
76 {"sim-resp", 0, 0, 1, cmd_sim_resp}, |
119
0ac0aee0df11
fc-uicc-tool: remaining PIN commands from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
118
diff
changeset
|
77 {"unblock-pin", 3, 3, 0, cmd_unblock_pin}, |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
78 {"update-bin", 2, 2, 0, cmd_update_bin}, |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
79 {"update-bin-imm", 2, 2, 0, cmd_update_bin_imm}, |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
80 {"update-rec", 2, 2, 0, cmd_update_rec}, |
118
5d45cde6e4b2
fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
81 {"verify-ext", 2, 2, 0, cmd_verify_pin}, |
5d45cde6e4b2
fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
82 {"verify-hex", 2, 2, 0, cmd_verify_hex}, |
5d45cde6e4b2
fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
107
diff
changeset
|
83 {"verify-pin", 2, 2, 0, cmd_verify_pin}, |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
84 {0, 0, 0, 0, 0} |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 }; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
87 static FILE * |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
88 handle_output_redir(str) |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
89 char *str; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
90 { |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
91 char *cp, *fn; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
92 FILE *outf; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
93 |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
94 for (cp = str; isspace(*cp); cp++) |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
95 ; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
96 if (!*cp || *cp == '#') { |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
97 fprintf(stderr, "error: no filename after '>'\n"); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
98 return(0); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
99 } |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
100 for (fn = cp; *cp && !isspace(*cp); cp++) |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
101 ; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
102 if (*cp) |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
103 *cp++ = '\0'; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
104 while (isspace(*cp)) |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
105 cp++; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
106 if (*cp && *cp != '#') { |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
107 fprintf(stderr, "error: invalid syntax after '>'\n"); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
108 return(0); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
109 } |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
110 outf = fopen(fn, "w"); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
111 if (!outf) |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
112 perror(fn); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
113 return outf; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
114 } |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
115 |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 simtool_dispatch_cmd(cmd, is_script) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 char *cmd; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 char *argv[10]; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 char *cp, **ap; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 struct cmdtab *tp; |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
122 FILE *outf; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
123 int rc; |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 for (cp = cmd; isspace(*cp); cp++) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 ; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 if (!*cp || *cp == '#') |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 return(0); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 if (is_script) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 printf("Script command: %s\n", cp); |
133
ede661d78730
fc-uicc-tool: command shell features match fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
121
diff
changeset
|
131 if (*cp == '!') |
ede661d78730
fc-uicc-tool: command shell features match fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
121
diff
changeset
|
132 return system(cp + 1); |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 argv[0] = cp; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 while (*cp && !isspace(*cp)) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 cp++; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (*cp) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 *cp++ = '\0'; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 for (tp = cmdtab; tp->cmd; tp++) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 if (!strcmp(tp->cmd, argv[0])) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 break; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 if (!tp->func) { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 fprintf(stderr, "error: no such command\n"); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 return(-1); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 for (ap = argv + 1; ; ) { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 while (isspace(*cp)) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 cp++; |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
148 if (!*cp || *cp == '#' || *cp == '>') |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 break; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 if (ap - argv - 1 >= tp->maxargs) { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 fprintf(stderr, "error: too many arguments\n"); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 return(-1); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 if (*cp == '"') { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 *ap++ = ++cp; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 for (;;) { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 if (!*cp) { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 unterm_qstring: fprintf(stderr, |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 "error: unterminated quoted string\n"); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 return(-1); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 if (*cp == '"') |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 break; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 if (*cp++ == '\\') { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 if (!*cp) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 goto unterm_qstring; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 cp++; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 *cp++ = '\0'; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 } else { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 *ap++ = cp; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 while (*cp && !isspace(*cp)) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 cp++; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 if (*cp) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 *cp++ = '\0'; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 if (ap - argv - 1 < tp->minargs) { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 fprintf(stderr, "error: too few arguments\n"); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 return(-1); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 *ap = 0; |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
184 if (*cp == '>') { |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
185 if (!tp->allow_redir) { |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
186 fprintf(stderr, |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
187 "error: command does not support output redirection\n"); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
188 return(-1); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
189 } |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
190 outf = handle_output_redir(cp + 1); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
191 if (!outf) |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
192 return(-1); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
193 } else |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
194 outf = stdout; |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
195 rc = tp->func(ap - argv, argv, outf); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
196 if (outf != stdout) |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
197 fclose(outf); |
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
198 return rc; |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 dispatch_ready_argv(argc, argv) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 char **argv; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 struct cmdtab *tp; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 for (tp = cmdtab; tp->cmd; tp++) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 if (!strcmp(tp->cmd, argv[0])) |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 break; |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 if (!tp->func) { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 fprintf(stderr, "error: no such command\n"); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 return(-1); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 if (argc - 1 > tp->maxargs) { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 fprintf(stderr, "error: too many arguments\n"); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 return(-1); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 } |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 if (argc - 1 < tp->minargs) { |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 fprintf(stderr, "error: too few arguments\n"); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 return(-1); |
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 } |
105
16481db543e8
fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
221 return tp->func(argc, argv, stdout); |
22
1b1468869ccf
new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 } |