comparison libcommon/pbdumpfunc.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 simtool/pbdump.c@4a9bf783491d
children
comparison
equal deleted inserted replaced
8:4a9bf783491d 9:dc565e91069d
1 /*
2 * This module implements the meaty function for pb-dump commands.
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include "simresp.h"
8
9 static
10 check_blank_area(dp, endp)
11 u_char *dp, *endp;
12 {
13 while (dp < endp)
14 if (*dp++ != 0xFF)
15 return(-1);
16 return(0);
17 }
18
19 void
20 dump_phonebook_record(recno, outf)
21 unsigned recno;
22 FILE *outf;
23 {
24 int rc;
25 unsigned textlen;
26 u_char *fixp;
27 char digits[21];
28
29 fprintf(outf, "#%u: ", recno);
30 if (sim_resp_data_len > 14) {
31 rc = validate_alpha_field(sim_resp_data,
32 sim_resp_data_len - 14,
33 &textlen);
34 if (rc < 0) {
35 malformed: fprintf(outf, "malformed record\n");
36 return;
37 }
38 } else
39 textlen = 0;
40 fixp = sim_resp_data + sim_resp_data_len - 14;
41 if (fixp[0] < 2 || fixp[0] > 11)
42 goto malformed;
43 rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits);
44 if (rc < 0)
45 goto malformed;
46 rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12);
47 if (rc < 0)
48 goto malformed;
49 /* all checks passed */
50 fprintf(outf, "%s,0x%02X ", digits, fixp[1]);
51 if (fixp[12] != 0xFF)
52 fprintf(outf, "CCP=%u ", fixp[12]);
53 if (fixp[13] != 0xFF)
54 fprintf(outf, "EXT=%u ", fixp[13]);
55 print_alpha_field(sim_resp_data, textlen, outf);
56 putc('\n', outf);
57 }