comparison simtool/pbdump.c @ 9:dc565e91069d

pb-dump meaty function factored out into libcommon
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 12 Feb 2021 00:28:06 +0000
parents 4a9bf783491d
children 72a24b8538eb
comparison
equal deleted inserted replaced
8:4a9bf783491d 9:dc565e91069d
1 /* 1 /*
2 * This module implements the pb-dump command. 2 * This module implements pb-dump and pb-dump-rec commands.
3 */ 3 */
4 4
5 #include <sys/types.h> 5 #include <sys/types.h>
6 #include <string.h>
7 #include <strings.h>
8 #include <stdio.h> 6 #include <stdio.h>
9 #include <stdlib.h> 7 #include <stdlib.h>
10 #include "simresp.h"
11 #include "curfile.h" 8 #include "curfile.h"
12
13 static
14 check_blank_area(dp, endp)
15 u_char *dp, *endp;
16 {
17 while (dp < endp)
18 if (*dp++ != 0xFF)
19 return(-1);
20 return(0);
21 }
22
23 static void
24 dump_record(recno, outf)
25 unsigned recno;
26 FILE *outf;
27 {
28 int rc;
29 unsigned textlen;
30 u_char *fixp;
31 char digits[21];
32
33 fprintf(outf, "#%u: ", recno);
34 if (curfile_record_len > 14) {
35 rc = validate_alpha_field(sim_resp_data,
36 curfile_record_len - 14,
37 &textlen);
38 if (rc < 0) {
39 malformed: fprintf(outf, "malformed record\n");
40 return;
41 }
42 } else
43 textlen = 0;
44 fixp = sim_resp_data + sim_resp_data_len - 14;
45 if (fixp[0] < 2 || fixp[0] > 11)
46 goto malformed;
47 rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits);
48 if (rc < 0)
49 goto malformed;
50 rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12);
51 if (rc < 0)
52 goto malformed;
53 /* all checks passed */
54 fprintf(outf, "%s,0x%02X ", digits, fixp[1]);
55 if (fixp[12] != 0xFF)
56 fprintf(outf, "CCP=%u ", fixp[12]);
57 if (fixp[13] != 0xFF)
58 fprintf(outf, "EXT=%u ", fixp[13]);
59 print_alpha_field(sim_resp_data, textlen, outf);
60 putc('\n', outf);
61 }
62 9
63 cmd_pb_dump(argc, argv) 10 cmd_pb_dump(argc, argv)
64 char **argv; 11 char **argv;
65 { 12 {
66 int rc; 13 int rc;
85 fclose(outf); 32 fclose(outf);
86 return(rc); 33 return(rc);
87 } 34 }
88 if (check_simresp_all_blank()) 35 if (check_simresp_all_blank())
89 continue; 36 continue;
90 dump_record(recno, outf); 37 dump_phonebook_record(recno, outf);
91 } 38 }
92 if (argv[2]) 39 if (argv[2])
93 fclose(outf); 40 fclose(outf);
94 return(0); 41 return(0);
95 } 42 }
127 rc = readrec_op(recno, 0x04, curfile_record_len); 74 rc = readrec_op(recno, 0x04, curfile_record_len);
128 if (rc < 0) 75 if (rc < 0)
129 return(rc); 76 return(rc);
130 if (check_simresp_all_blank()) 77 if (check_simresp_all_blank())
131 continue; 78 continue;
132 dump_record(recno, stdout); 79 dump_phonebook_record(recno, stdout);
133 } 80 }
134 return(0); 81 return(0);
135 } 82 }