annotate simtool/pbdump.c @ 47:ae3342497fea

fc-simtool verify-hex command added
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 13 Feb 2021 00:57:57 +0000
parents 72a24b8538eb
children 1861d9fb7751
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
9
dc565e91069d pb-dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
2 * This module implements pb-dump and pb-dump-rec commands.
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
19
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
8 #include "simresp.h"
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "curfile.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
19
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
11 static
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
12 check_blank_area(dp, endp)
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
13 u_char *dp, *endp;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
14 {
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
15 while (dp < endp)
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
16 if (*dp++ != 0xFF)
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
17 return(-1);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
18 return(0);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
19 }
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
20
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
21 static void
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
22 dump_record(recno, outf)
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
23 unsigned recno;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
24 FILE *outf;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
25 {
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
26 int rc;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
27 unsigned textlen;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
28 u_char *fixp;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
29 char digits[21];
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
30
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
31 fprintf(outf, "#%u: ", recno);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
32 if (sim_resp_data_len > 14) {
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
33 rc = validate_alpha_field(sim_resp_data,
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
34 sim_resp_data_len - 14,
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
35 &textlen);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
36 if (rc < 0) {
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
37 malformed: fprintf(outf, "malformed record\n");
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
38 return;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
39 }
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
40 } else
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
41 textlen = 0;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
42 fixp = sim_resp_data + sim_resp_data_len - 14;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
43 if (fixp[0] < 2 || fixp[0] > 11)
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
44 goto malformed;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
45 rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
46 if (rc < 0)
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
47 goto malformed;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
48 rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
49 if (rc < 0)
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
50 goto malformed;
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
51 /* all checks passed */
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
52 fprintf(outf, "%s,0x%02X ", digits, fixp[1]);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
53 if (fixp[12] != 0xFF)
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
54 fprintf(outf, "CCP=%u ", fixp[12]);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
55 if (fixp[13] != 0xFF)
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
56 fprintf(outf, "EXT=%u ", fixp[13]);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
57 print_alpha_field(sim_resp_data, textlen, outf);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
58 putc('\n', outf);
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
59 }
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
60
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 cmd_pb_dump(argc, argv)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 FILE *outf;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 unsigned recno;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 rc = phonebook_op_common(argv[1]);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (argv[2]) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 outf = fopen(argv[2], "w");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 if (!outf) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 perror(argv[2]);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 } else
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 outf = stdout;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 for (recno = 1; recno <= curfile_record_count; recno++) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 rc = readrec_op(recno, 0x04, curfile_record_len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (rc < 0) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (argv[2])
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 fclose(outf);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
5
ce189c97b7b1 check_simresp_all_blank() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
86 if (check_simresp_all_blank())
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 continue;
19
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
88 dump_record(recno, outf);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (argv[2])
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 fclose(outf);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 cmd_pb_dump_rec(argc, argv)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 unsigned recno, startrec, endrec;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 rc = phonebook_op_common(argv[1]);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 startrec = strtoul(argv[2], 0, 0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 if (startrec < 1 || startrec > curfile_record_count) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 "error: specified starting record number is invalid\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 if (argv[3]) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 endrec = strtoul(argv[3], 0, 0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (endrec < 1 || endrec > curfile_record_count) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 "error: specified final record number is invalid\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 if (startrec > endrec) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 "error: reverse record range specified\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 } else
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 endrec = startrec;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 for (recno = startrec; recno <= endrec; recno++) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 rc = readrec_op(recno, 0x04, curfile_record_len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 return(rc);
5
ce189c97b7b1 check_simresp_all_blank() factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
128 if (check_simresp_all_blank())
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 continue;
19
72a24b8538eb meaty function of pb-dump moved back into simtool, out of libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents: 9
diff changeset
130 dump_record(recno, stdout);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 }