annotate simtool/readef.c @ 172:e7e0d8c06654

fc-simtool: support output redirection in select command
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 02 Mar 2021 03:18:21 +0000
parents 4d747b86da00
children e70964adcbba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
171
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
1 /*
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
2 * This module implements the readef command for dumping the complete
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
3 * content of SIM files.
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
4 */
4d747b86da00 simtool code: readef command implementation split off
Mychaela Falconia <falcon@freecalypso.org>
parents: 107
diff changeset
5
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
15
5390dce9faa4 simtool/readcmd.c: missed #include <ctype.h>
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
7 #include <ctype.h>
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "simresp.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "curfile.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
13 cmd_readef(argc, argv, outf)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 char **argv;
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
15 FILE *outf;
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 int file_id, rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned readlen;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 file_id = strtoul(argv[1], 0, 16);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 else
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 file_id = find_symbolic_file_name(argv[1]);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (file_id < 0) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 "error: file ID argument is not a hex value or a recognized symbolic name\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 rc = select_op(file_id);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 rc = parse_ef_select_response();
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (curfile_structure != 0x00) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 "error: readef command is only for transparent EFs\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
172
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
41 fprintf(outf, "Transparent EF of %u byte(s)\n", curfile_total_size);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
42 fprintf(outf, "File status: %02X\n", sim_resp_data[11]);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
43 show_access_conditions(outf, "UPDATE", sim_resp_data[8] & 0xF);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
44 show_access_conditions(outf, "READ & SEEK", sim_resp_data[8] >> 4);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
45 show_access_conditions(outf, "INCREASE", sim_resp_data[9] >> 4);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
46 show_access_conditions(outf, "INVALIDATE", sim_resp_data[10] & 0xF);
e7e0d8c06654 fc-simtool: support output redirection in select command
Mychaela Falconia <falcon@freecalypso.org>
parents: 171
diff changeset
47 show_access_conditions(outf, "REHABILITATE", sim_resp_data[10] >> 4);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (!curfile_total_size)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 readlen = curfile_total_size;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (readlen > 256)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 readlen = 256;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 rc = readbin_op(0, readlen);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return(rc);
107
f1836c8d36cb hexdump output commands reworked to support redirection
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
56 display_sim_resp_in_hex(outf);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }