FreeCalypso > hg > freecalypso-hwlab
annotate simtool/dispatch.c @ 154:ed34c8b7e2c9
fc-simtool: grcard2-set-pin[12] commands implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Feb 2021 02:29:07 +0000 |
parents | a63e4c64f1f0 |
children | 804a5b0797c6 |
rev | line source |
---|---|
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the command dispatch for fc-simtool |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <ctype.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
127
141489d31667
fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
11 extern int cmd_a38(); |
108
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
12 extern int cmd_change_chv(); |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
13 extern int cmd_disable_chv(); |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
14 extern int cmd_enable_chv(); |
123
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
122
diff
changeset
|
15 extern int cmd_exec(); |
114
34c090f35515
fc-simtool: fix-sysmo-msisdn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
112
diff
changeset
|
16 extern int cmd_fix_sysmo_msisdn(); |
149
451ed3bbfe96
fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
17 extern int cmd_grcard1_set_adm(); |
153
a63e4c64f1f0
fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
149
diff
changeset
|
18 extern int cmd_grcard1_set_ki(); |
148
1232dea1d66a
fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
143
diff
changeset
|
19 extern int cmd_grcard1_set_pin(); |
154
ed34c8b7e2c9
fc-simtool: grcard2-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
153
diff
changeset
|
20 extern int cmd_grcard2_set_pin(); |
96
a5dfab380a90
fc-simtool: iccid high-level read command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
21 extern int cmd_iccid(); |
97
597c4e87a1f4
fc-simtool: imsi high-level read command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
22 extern int cmd_imsi(); |
104
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
103
diff
changeset
|
23 extern int cmd_pb_dump(); |
122
f18704e91393
fc-simtool: pb-dump-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
121
diff
changeset
|
24 extern int cmd_pb_dump_rec(); |
112
87d459d9797a
fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
25 extern int cmd_pb_erase(); |
115
0dcd666292e4
fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
26 extern int cmd_pb_erase_one(); |
121
87b34a244901
fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
120
diff
changeset
|
27 extern int cmd_pb_erase_range(); |
111
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
109
diff
changeset
|
28 extern int cmd_pb_update(); |
117
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
116
diff
changeset
|
29 extern int cmd_pb_update_imm(); |
120
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
119
diff
changeset
|
30 extern int cmd_pb_update_imm_hex(); |
90
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
31 extern int cmd_readbin(); |
95
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
32 extern int cmd_readef(); |
91
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
33 extern int cmd_readrec(); |
100
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
34 extern int cmd_restore_file(); |
99
2e35070d289f
fc-simtool: savebin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
98
diff
changeset
|
35 extern int cmd_savebin(); |
119
c77b0d4cf89f
fc-simtool: save-sms-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
36 extern int cmd_save_sms_bin(); |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 extern int cmd_select(); |
103
90eff13a72fd
fc-simtool: implemented alpha field decoding and spn command
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
38 extern int cmd_spn(); |
98
66c0cb0e9876
fc-simtool: telecom-sum (summary info) command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
39 extern int cmd_telecom_sum(); |
143
431194b772e1
fc-simtool: uicc-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
129
diff
changeset
|
40 extern int cmd_uicc_dir(); |
108
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
41 extern int cmd_unblock_chv(); |
101
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
42 extern int cmd_update_bin(); |
109
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
43 extern int cmd_update_bin_imm(); |
102
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
44 extern int cmd_update_rec(); |
108
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
45 extern int cmd_verify_chv(); |
129
2adb802b2a98
fc-simtool: verify-ext command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
46 extern int cmd_verify_ext(); |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 |
88
91486a77643e
fc-simtool: implement hex display of full SIM responses
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
48 extern int display_sim_resp_in_hex(); |
124
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
49 extern int good_exit(); |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 static struct cmdtab { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 char *cmd; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 int minargs; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 int maxargs; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 int (*func)(); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } cmdtab[] = { |
127
141489d31667
fc-simtool: a38 command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
124
diff
changeset
|
57 {"a38", 1, 1, cmd_a38}, |
108
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
58 {"change-chv1", 2, 2, cmd_change_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
59 {"change-chv2", 2, 2, cmd_change_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
60 {"change-pin1", 2, 2, cmd_change_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
61 {"change-pin2", 2, 2, cmd_change_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
62 {"disable-chv", 1, 1, cmd_disable_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
63 {"disable-pin", 1, 1, cmd_disable_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
64 {"enable-chv", 1, 1, cmd_enable_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
65 {"enable-pin", 1, 1, cmd_enable_chv}, |
123
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
122
diff
changeset
|
66 {"exec", 1, 1, cmd_exec}, |
124
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
67 {"exit", 0, 0, good_exit}, |
114
34c090f35515
fc-simtool: fix-sysmo-msisdn command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
112
diff
changeset
|
68 {"fix-sysmo-msisdn", 0, 0, cmd_fix_sysmo_msisdn}, |
149
451ed3bbfe96
fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
69 {"grcard1-set-adm1", 2, 2, cmd_grcard1_set_adm}, |
451ed3bbfe96
fc-simtool: grcard1-set-adm[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
70 {"grcard1-set-adm2", 2, 2, cmd_grcard1_set_adm}, |
153
a63e4c64f1f0
fc-simtool: grcard1-set-ki command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
149
diff
changeset
|
71 {"grcard1-set-ki", 1, 1, cmd_grcard1_set_ki}, |
148
1232dea1d66a
fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
143
diff
changeset
|
72 {"grcard1-set-pin1", 2, 2, cmd_grcard1_set_pin}, |
1232dea1d66a
fc-simtool: grcard1-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
143
diff
changeset
|
73 {"grcard1-set-pin2", 2, 2, cmd_grcard1_set_pin}, |
154
ed34c8b7e2c9
fc-simtool: grcard2-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
153
diff
changeset
|
74 {"grcard2-set-pin1", 1, 1, cmd_grcard2_set_pin}, |
ed34c8b7e2c9
fc-simtool: grcard2-set-pin[12] commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
153
diff
changeset
|
75 {"grcard2-set-pin2", 1, 1, cmd_grcard2_set_pin}, |
96
a5dfab380a90
fc-simtool: iccid high-level read command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
95
diff
changeset
|
76 {"iccid", 0, 0, cmd_iccid}, |
97
597c4e87a1f4
fc-simtool: imsi high-level read command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
77 {"imsi", 0, 0, cmd_imsi}, |
104
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
103
diff
changeset
|
78 {"pb-dump", 1, 2, cmd_pb_dump}, |
122
f18704e91393
fc-simtool: pb-dump-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
121
diff
changeset
|
79 {"pb-dump-rec", 2, 3, cmd_pb_dump_rec}, |
112
87d459d9797a
fc-simtool: pb-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
111
diff
changeset
|
80 {"pb-erase", 1, 1, cmd_pb_erase}, |
115
0dcd666292e4
fc-simtool: pb-erase-one command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
81 {"pb-erase-one", 2, 2, cmd_pb_erase_one}, |
121
87b34a244901
fc-simtool: pb-erase-range command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
120
diff
changeset
|
82 {"pb-erase-range", 3, 3, cmd_pb_erase_range}, |
111
5bfb5a7262c1
fc-simtool: pb-update command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
109
diff
changeset
|
83 {"pb-update", 2, 2, cmd_pb_update}, |
117
06e2d5c60cbd
fc-simtool: pb-update-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
116
diff
changeset
|
84 {"pb-update-imm", 3, 4, cmd_pb_update_imm}, |
120
70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
119
diff
changeset
|
85 {"pb-update-imm-hex", 4, 4, cmd_pb_update_imm_hex}, |
124
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
86 {"quit", 0, 0, good_exit}, |
90
53e2c00566af
fc-simtool: readbin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
88
diff
changeset
|
87 {"readbin", 2, 2, cmd_readbin}, |
95
5f826e428641
fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
91
diff
changeset
|
88 {"readef", 1, 1, cmd_readef}, |
91
226b231d00f3
fc-simtool: readrec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
90
diff
changeset
|
89 {"readrec", 1, 2, cmd_readrec}, |
100
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
90 {"restore-file", 2, 2, cmd_restore_file}, |
99
2e35070d289f
fc-simtool: savebin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
98
diff
changeset
|
91 {"savebin", 2, 2, cmd_savebin}, |
119
c77b0d4cf89f
fc-simtool: save-sms-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
117
diff
changeset
|
92 {"save-sms-bin", 1, 1, cmd_save_sms_bin}, |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 {"select", 1, 1, cmd_select}, |
88
91486a77643e
fc-simtool: implement hex display of full SIM responses
Mychaela Falconia <falcon@freecalypso.org>
parents:
85
diff
changeset
|
94 {"sim-resp", 0, 0, display_sim_resp_in_hex}, |
103
90eff13a72fd
fc-simtool: implemented alpha field decoding and spn command
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
95 {"spn", 0, 0, cmd_spn}, |
98
66c0cb0e9876
fc-simtool: telecom-sum (summary info) command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
96 {"telecom-sum", 0, 0, cmd_telecom_sum}, |
143
431194b772e1
fc-simtool: uicc-dump command ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
129
diff
changeset
|
97 {"uicc-dir", 0, 0, cmd_uicc_dir}, |
108
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
98 {"unblock-chv1", 2, 2, cmd_unblock_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
99 {"unblock-chv2", 2, 2, cmd_unblock_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
100 {"unblock-pin1", 2, 2, cmd_unblock_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
101 {"unblock-pin2", 2, 2, cmd_unblock_chv}, |
101
454ff8bd0b83
fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
102 {"update-bin", 2, 2, cmd_update_bin}, |
109
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
103 {"update-bin-imm", 2, 2, cmd_update_bin_imm}, |
102
29cc5612797a
fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
104 {"update-rec", 2, 2, cmd_update_rec}, |
108
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
105 {"verify-chv1", 1, 1, cmd_verify_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
106 {"verify-chv2", 1, 1, cmd_verify_chv}, |
129
2adb802b2a98
fc-simtool: verify-ext command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
127
diff
changeset
|
107 {"verify-ext", 2, 2, cmd_verify_ext}, |
108
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
108 {"verify-pin1", 1, 1, cmd_verify_chv}, |
6f80cfdc7e05
fc-simtool: CHV commands implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
109 {"verify-pin2", 1, 1, cmd_verify_chv}, |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 {0, 0, 0, 0} |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 }; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 |
123
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
122
diff
changeset
|
113 simtool_dispatch_cmd(cmd, is_script) |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 char *cmd; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 char *argv[10]; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 char *cp, **ap; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 struct cmdtab *tp; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 for (cp = cmd; isspace(*cp); cp++) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 ; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 if (!*cp || *cp == '#') |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 return(0); |
123
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
122
diff
changeset
|
124 if (is_script) |
b391204d3cd5
fc-simtool: add scripting facility in the form of exec command
Mychaela Falconia <falcon@freecalypso.org>
parents:
122
diff
changeset
|
125 printf("Script command: %s\n", cp); |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 argv[0] = cp; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 while (*cp && !isspace(*cp)) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 cp++; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 if (*cp) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 *cp++ = '\0'; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 for (tp = cmdtab; tp->cmd; tp++) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 if (!strcmp(tp->cmd, argv[0])) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 break; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 if (!tp->func) { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 fprintf(stderr, "error: no such command\n"); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 return(-1); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 } |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 for (ap = argv + 1; ; ) { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 while (isspace(*cp)) |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 cp++; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 if (!*cp || *cp == '#') |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 break; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 if (ap - argv - 1 >= tp->maxargs) { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 fprintf(stderr, "error: too many arguments\n"); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 return(-1); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 } |
109
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
147 if (*cp == '"') { |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
148 *ap++ = ++cp; |
116
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
149 for (;;) { |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
150 if (!*cp) { |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
151 unterm_qstring: fprintf(stderr, |
109
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
152 "error: unterminated quoted string\n"); |
116
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
153 return(-1); |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
154 } |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
155 if (*cp == '"') |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
156 break; |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
157 if (*cp++ == '\\') { |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
158 if (!*cp) |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
159 goto unterm_qstring; |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
160 cp++; |
c8685074c845
fc-simtool command parser: fancier handling of quoted strings
Mychaela Falconia <falcon@freecalypso.org>
parents:
115
diff
changeset
|
161 } |
109
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
162 } |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 *cp++ = '\0'; |
109
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
164 } else { |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
165 *ap++ = cp; |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
166 while (*cp && !isspace(*cp)) |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
167 cp++; |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
168 if (*cp) |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
169 *cp++ = '\0'; |
4aaf722ab933
fc-simtool: update-bin-imm command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
108
diff
changeset
|
170 } |
85
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 } |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 if (ap - argv - 1 < tp->minargs) { |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 fprintf(stderr, "error: too few arguments\n"); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 return(-1); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 } |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 *ap = 0; |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 return tp->func(ap - argv, argv); |
b57cf64ece29
fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 } |
124
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
179 |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
180 dispatch_ready_argv(argc, argv) |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
181 char **argv; |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
182 { |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
183 struct cmdtab *tp; |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
184 |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
185 for (tp = cmdtab; tp->cmd; tp++) |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
186 if (!strcmp(tp->cmd, argv[0])) |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
187 break; |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
188 if (!tp->func) { |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
189 fprintf(stderr, "error: no such command\n"); |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
190 return(-1); |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
191 } |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
192 if (argc - 1 > tp->maxargs) { |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
193 fprintf(stderr, "error: too many arguments\n"); |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
194 return(-1); |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
195 } |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
196 if (argc - 1 < tp->minargs) { |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
197 fprintf(stderr, "error: too few arguments\n"); |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
198 return(-1); |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
199 } |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
200 return tp->func(argc, argv); |
6c4567dd8946
fc-simtool: add non-interactive one-shot command (or script) mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
123
diff
changeset
|
201 } |