FreeCalypso > hg > fc-sim-tools
comparison simtool/pbdump.c @ 10:ddd767f6e15b
fc-simtool ported over
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 14 Mar 2021 07:11:25 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 9:c9ef9e91dd8e | 10:ddd767f6e15b |
|---|---|
| 1 /* | |
| 2 * This module implements pb-dump and pb-dump-rec commands. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <stdio.h> | |
| 7 #include <stdlib.h> | |
| 8 #include "simresp.h" | |
| 9 #include "curfile.h" | |
| 10 | |
| 11 static | |
| 12 check_blank_area(dp, endp) | |
| 13 u_char *dp, *endp; | |
| 14 { | |
| 15 while (dp < endp) | |
| 16 if (*dp++ != 0xFF) | |
| 17 return(-1); | |
| 18 return(0); | |
| 19 } | |
| 20 | |
| 21 static void | |
| 22 dump_record(recno, outf) | |
| 23 unsigned recno; | |
| 24 FILE *outf; | |
| 25 { | |
| 26 int rc; | |
| 27 unsigned textlen; | |
| 28 u_char *fixp; | |
| 29 char digits[21]; | |
| 30 | |
| 31 fprintf(outf, "#%u: ", recno); | |
| 32 if (sim_resp_data_len > 14) { | |
| 33 rc = validate_alpha_field(sim_resp_data, | |
| 34 sim_resp_data_len - 14, | |
| 35 &textlen); | |
| 36 if (rc < 0) { | |
| 37 malformed: fprintf(outf, "malformed record\n"); | |
| 38 return; | |
| 39 } | |
| 40 } else | |
| 41 textlen = 0; | |
| 42 fixp = sim_resp_data + sim_resp_data_len - 14; | |
| 43 if (fixp[0] < 2 || fixp[0] > 11) | |
| 44 goto malformed; | |
| 45 rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits); | |
| 46 if (rc < 0) | |
| 47 goto malformed; | |
| 48 rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12); | |
| 49 if (rc < 0) | |
| 50 goto malformed; | |
| 51 /* all checks passed */ | |
| 52 fprintf(outf, "%s,0x%02X ", digits, fixp[1]); | |
| 53 if (fixp[12] != 0xFF) | |
| 54 fprintf(outf, "CCP=%u ", fixp[12]); | |
| 55 if (fixp[13] != 0xFF) | |
| 56 fprintf(outf, "EXT=%u ", fixp[13]); | |
| 57 print_alpha_field(sim_resp_data, textlen, outf); | |
| 58 putc('\n', outf); | |
| 59 } | |
| 60 | |
| 61 cmd_pb_dump(argc, argv, outf) | |
| 62 char **argv; | |
| 63 FILE *outf; | |
| 64 { | |
| 65 int rc; | |
| 66 unsigned recno; | |
| 67 | |
| 68 rc = phonebook_op_common(argv[1]); | |
| 69 if (rc < 0) | |
| 70 return(rc); | |
| 71 for (recno = 1; recno <= curfile_record_count; recno++) { | |
| 72 rc = readrec_op(recno, 0x04, curfile_record_len); | |
| 73 if (rc < 0) | |
| 74 return(rc); | |
| 75 if (check_simresp_all_blank()) | |
| 76 continue; | |
| 77 dump_record(recno, outf); | |
| 78 } | |
| 79 return(0); | |
| 80 } | |
| 81 | |
| 82 cmd_pb_dump_rec(argc, argv, outf) | |
| 83 char **argv; | |
| 84 FILE *outf; | |
| 85 { | |
| 86 int rc; | |
| 87 unsigned recno, startrec, endrec; | |
| 88 | |
| 89 rc = phonebook_op_common(argv[1]); | |
| 90 if (rc < 0) | |
| 91 return(rc); | |
| 92 startrec = strtoul(argv[2], 0, 0); | |
| 93 if (startrec < 1 || startrec > curfile_record_count) { | |
| 94 fprintf(stderr, | |
| 95 "error: specified starting record number is invalid\n"); | |
| 96 return(-1); | |
| 97 } | |
| 98 if (argv[3]) { | |
| 99 endrec = strtoul(argv[3], 0, 0); | |
| 100 if (endrec < 1 || endrec > curfile_record_count) { | |
| 101 fprintf(stderr, | |
| 102 "error: specified final record number is invalid\n"); | |
| 103 return(-1); | |
| 104 } | |
| 105 if (startrec > endrec) { | |
| 106 fprintf(stderr, | |
| 107 "error: reverse record range specified\n"); | |
| 108 return(-1); | |
| 109 } | |
| 110 } else | |
| 111 endrec = startrec; | |
| 112 for (recno = startrec; recno <= endrec; recno++) { | |
| 113 rc = readrec_op(recno, 0x04, curfile_record_len); | |
| 114 if (rc < 0) | |
| 115 return(rc); | |
| 116 if (check_simresp_all_blank()) | |
| 117 continue; | |
| 118 dump_record(recno, outf); | |
| 119 } | |
| 120 return(0); | |
| 121 } | |
| 122 | |
| 123 cmd_lnd_dump(argc, argv, outf) | |
| 124 char **argv; | |
| 125 FILE *outf; | |
| 126 { | |
| 127 int rc; | |
| 128 unsigned recno; | |
| 129 | |
| 130 rc = select_ef_lnd(); | |
| 131 if (rc < 0) | |
| 132 return(rc); | |
| 133 for (recno = 1; recno <= curfile_record_count; recno++) { | |
| 134 rc = readrec_op(recno, 0x04, curfile_record_len); | |
| 135 if (rc < 0) | |
| 136 return(rc); | |
| 137 if (check_simresp_all_blank()) | |
| 138 continue; | |
| 139 dump_record(recno, outf); | |
| 140 } | |
| 141 return(0); | |
| 142 } |
