FreeCalypso > hg > freecalypso-hwlab
comparison simtool/pbupdate.c @ 120:70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Jan 2021 04:46:41 +0000 |
parents | 06e2d5c60cbd |
children | f18b87115cca |
comparison
equal
deleted
inserted
replaced
119:c77b0d4cf89f | 120:70219d92c32e |
---|---|
445 if (rc < 0) | 445 if (rc < 0) |
446 return(rc); | 446 return(rc); |
447 } | 447 } |
448 return update_rec_op(recno, 0x04, record, curfile_record_len); | 448 return update_rec_op(recno, 0x04, record, curfile_record_len); |
449 } | 449 } |
450 | |
451 static | |
452 decode_alphatag_arg_hex(arg, record) | |
453 char *arg; | |
454 u_char *record; | |
455 { | |
456 unsigned maxlen, acclen; | |
457 | |
458 maxlen = curfile_record_len - 14; | |
459 for (acclen = 0; ; acclen++) { | |
460 while (isspace(*arg)) | |
461 arg++; | |
462 if (!*arg) | |
463 break; | |
464 if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { | |
465 fprintf(stderr, "error: invalid hex string input\n"); | |
466 return(-1); | |
467 } | |
468 if (acclen >= maxlen) { | |
469 fprintf(stderr, | |
470 "error: alpha tag string is longer than SIM limit\n"); | |
471 return(-1); | |
472 } | |
473 record[acclen] = (decode_hex_digit(arg[0]) << 4) | | |
474 decode_hex_digit(arg[1]); | |
475 arg += 2; | |
476 } | |
477 return(0); | |
478 } | |
479 | |
480 cmd_pb_update_imm_hex(argc, argv) | |
481 char **argv; | |
482 { | |
483 int rc; | |
484 unsigned recno; | |
485 u_char record[255], *fixp; | |
486 | |
487 rc = phonebook_op_common(argv[1]); | |
488 if (rc < 0) | |
489 return(rc); | |
490 recno = strtoul(argv[2], 0, 0); | |
491 if (recno < 1 || recno > curfile_record_count) { | |
492 fprintf(stderr, "error: specified record number is invalid\n"); | |
493 return(-1); | |
494 } | |
495 memset(record, 0xFF, curfile_record_len); | |
496 fixp = record + curfile_record_len - 14; | |
497 rc = decode_number_arg(argv[3], fixp); | |
498 if (rc < 0) | |
499 return(rc); | |
500 rc = decode_alphatag_arg_hex(argv[4], record); | |
501 if (rc < 0) | |
502 return(rc); | |
503 return update_rec_op(recno, 0x04, record, curfile_record_len); | |
504 } |