annotate uicc/dispatch.c @ 107:f1836c8d36cb

hexdump output commands reworked to support redirection
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Feb 2021 06:43:01 +0000
parents dcfec53643c5
children 5d45cde6e4b2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 extern int cmd_dir();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern int cmd_exec();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int cmd_iccid();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern int cmd_readbin();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern int cmd_readef();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern int cmd_readrec();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 extern int cmd_select();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern int cmd_select_aid();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern int cmd_select_isim();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern int cmd_select_usim();
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 106
diff changeset
21 extern int cmd_sim_resp();
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 extern int cmd_update_bin();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 extern int cmd_update_bin_imm();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 extern int cmd_update_rec();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 extern int good_exit();
29
d368051576d0 fc-simtool & fc-uicc-tool: add explicit atr command
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
27 extern int retrieve_atr();
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 static struct cmdtab {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 char *cmd;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 int minargs;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 int maxargs;
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
33 int allow_redir;
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 int (*func)();
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 } cmdtab[] = {
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
36 {"atr", 0, 0, 0, retrieve_atr},
106
dcfec53643c5 EF_DIR dump commands support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 105
diff changeset
37 {"dir", 0, 0, 1, cmd_dir},
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
38 {"exec", 1, 1, 0, cmd_exec},
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
39 {"exit", 0, 0, 0, good_exit},
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
40 {"iccid", 0, 0, 0, cmd_iccid},
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
41 {"quit", 0, 0, 0, good_exit},
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 106
diff changeset
42 {"readbin", 2, 2, 1, cmd_readbin},
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 106
diff changeset
43 {"readef", 1, 1, 1, cmd_readef},
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 106
diff changeset
44 {"readrec", 1, 2, 1, cmd_readrec},
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
45 {"select", 1, 1, 0, cmd_select},
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
46 {"select-aid", 1, 1, 0, cmd_select_aid},
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
47 {"select-isim", 0, 0, 0, cmd_select_isim},
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
48 {"select-usim", 0, 0, 0, cmd_select_usim},
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 106
diff changeset
49 {"sim-resp", 0, 0, 1, cmd_sim_resp},
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
50 {"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
51 {"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
52 {"update-rec", 2, 2, 0, cmd_update_rec},
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
53 {0, 0, 0, 0, 0}
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 };
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
56 static FILE *
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
57 handle_output_redir(str)
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
58 char *str;
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
59 {
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
60 char *cp, *fn;
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
61 FILE *outf;
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
62
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
63 for (cp = str; isspace(*cp); cp++)
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
64 ;
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
65 if (!*cp || *cp == '#') {
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
66 fprintf(stderr, "error: no filename after '>'\n");
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
67 return(0);
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
68 }
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
69 for (fn = cp; *cp && !isspace(*cp); cp++)
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
70 ;
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
71 if (*cp)
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
72 *cp++ = '\0';
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
73 while (isspace(*cp))
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
74 cp++;
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
75 if (*cp && *cp != '#') {
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
76 fprintf(stderr, "error: invalid syntax after '>'\n");
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
77 return(0);
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
78 }
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
79 outf = fopen(fn, "w");
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
80 if (!outf)
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
81 perror(fn);
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
82 return outf;
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
83 }
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
84
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 simtool_dispatch_cmd(cmd, is_script)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 char *cmd;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 char *argv[10];
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 char *cp, **ap;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 struct cmdtab *tp;
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
91 FILE *outf;
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
92 int rc;
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 for (cp = cmd; isspace(*cp); cp++)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 ;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 if (!*cp || *cp == '#')
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 return(0);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 if (is_script)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 printf("Script command: %s\n", cp);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 argv[0] = cp;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 while (*cp && !isspace(*cp))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 cp++;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 if (*cp)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 *cp++ = '\0';
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 for (tp = cmdtab; tp->cmd; tp++)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (!strcmp(tp->cmd, argv[0]))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 break;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 if (!tp->func) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 fprintf(stderr, "error: no such command\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 for (ap = argv + 1; ; ) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 while (isspace(*cp))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 cp++;
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
115 if (!*cp || *cp == '#' || *cp == '>')
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 break;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (ap - argv - 1 >= tp->maxargs) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 fprintf(stderr, "error: too many arguments\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 if (*cp == '"') {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 *ap++ = ++cp;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 for (;;) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 if (!*cp) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 unterm_qstring: fprintf(stderr,
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 "error: unterminated quoted string\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 if (*cp == '"')
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 break;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 if (*cp++ == '\\') {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 if (!*cp)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 goto unterm_qstring;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 cp++;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 }
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 } else {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 *ap++ = cp;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 while (*cp && !isspace(*cp))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 cp++;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (*cp)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 *cp++ = '\0';
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 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 if (ap - argv - 1 < tp->minargs) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 fprintf(stderr, "error: too few arguments\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 *ap = 0;
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
151 if (*cp == '>') {
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
152 if (!tp->allow_redir) {
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
153 fprintf(stderr,
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
154 "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
155 return(-1);
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
156 }
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
157 outf = handle_output_redir(cp + 1);
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
158 if (!outf)
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
159 return(-1);
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
160 } else
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
161 outf = stdout;
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
162 rc = tp->func(ap - argv, argv, outf);
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
163 if (outf != stdout)
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
164 fclose(outf);
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
165 return rc;
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 dispatch_ready_argv(argc, argv)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 char **argv;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 struct cmdtab *tp;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 for (tp = cmdtab; tp->cmd; tp++)
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 if (!strcmp(tp->cmd, argv[0]))
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 break;
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 if (!tp->func) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 fprintf(stderr, "error: no such command\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 if (argc - 1 > tp->maxargs) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 fprintf(stderr, "error: too many arguments\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 if (argc - 1 < tp->minargs) {
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 fprintf(stderr, "error: too few arguments\n");
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 return(-1);
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 }
105
16481db543e8 fc-uicc-tool: infrastructure for output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 29
diff changeset
188 return tp->func(argc, argv, stdout);
22
1b1468869ccf new trimmed fc-uicc-tool is here
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 }