FreeCalypso > hg > fc-pcsc-tools
comparison simtool/pbupd_immhex.c @ 13:d4f8c511affe
simtool: pbupdate.c split into separate modules for each command
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 12 Feb 2021 01:28:53 +0000 |
| parents | simtool/pbupdate.c@8a34f5b7c812 |
| children | 52ec2d3eb851 |
comparison
equal
deleted
inserted
replaced
| 12:8a34f5b7c812 | 13:d4f8c511affe |
|---|---|
| 1 /* | |
| 2 * This module implements the pb-update-imm-hex command. | |
| 3 */ | |
| 4 | |
| 5 #include <sys/types.h> | |
| 6 #include <ctype.h> | |
| 7 #include <string.h> | |
| 8 #include <strings.h> | |
| 9 #include <stdio.h> | |
| 10 #include <stdlib.h> | |
| 11 #include "curfile.h" | |
| 12 | |
| 13 static | |
| 14 decode_alphatag_arg_hex(arg, record, maxlen) | |
| 15 char *arg; | |
| 16 u_char *record; | |
| 17 unsigned maxlen; | |
| 18 { | |
| 19 unsigned acclen; | |
| 20 | |
| 21 for (acclen = 0; ; acclen++) { | |
| 22 while (isspace(*arg)) | |
| 23 arg++; | |
| 24 if (!*arg) | |
| 25 break; | |
| 26 if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { | |
| 27 fprintf(stderr, "error: invalid hex string input\n"); | |
| 28 return(-1); | |
| 29 } | |
| 30 if (acclen >= maxlen) { | |
| 31 fprintf(stderr, | |
| 32 "error: alpha tag string is longer than SIM limit\n"); | |
| 33 return(-1); | |
| 34 } | |
| 35 record[acclen] = (decode_hex_digit(arg[0]) << 4) | | |
| 36 decode_hex_digit(arg[1]); | |
| 37 arg += 2; | |
| 38 } | |
| 39 return(0); | |
| 40 } | |
| 41 | |
| 42 cmd_pb_update_imm_hex(argc, argv) | |
| 43 char **argv; | |
| 44 { | |
| 45 int rc; | |
| 46 unsigned recno; | |
| 47 u_char record[255], *fixp; | |
| 48 | |
| 49 rc = phonebook_op_common(argv[1]); | |
| 50 if (rc < 0) | |
| 51 return(rc); | |
| 52 recno = strtoul(argv[2], 0, 0); | |
| 53 if (recno < 1 || recno > curfile_record_count) { | |
| 54 fprintf(stderr, "error: specified record number is invalid\n"); | |
| 55 return(-1); | |
| 56 } | |
| 57 memset(record, 0xFF, curfile_record_len); | |
| 58 fixp = record + curfile_record_len - 14; | |
| 59 rc = encode_phone_number_arg(argv[3], fixp); | |
| 60 if (rc < 0) | |
| 61 return(rc); | |
| 62 rc = decode_alphatag_arg_hex(argv[4], record, curfile_record_len - 14); | |
| 63 if (rc < 0) | |
| 64 return(rc); | |
| 65 return update_rec_op(recno, 0x04, record, curfile_record_len); | |
| 66 } |
