comparison simtool/hexread.c @ 109:4aaf722ab933

fc-simtool: update-bin-imm command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 26 Jan 2021 01:27:58 +0000
parents 454ff8bd0b83
children 54e33e9238b6
comparison
equal deleted inserted replaced
108:6f80cfdc7e05 109:4aaf722ab933
63 fprintf(stderr, "%s: no hex data input found\n", filename); 63 fprintf(stderr, "%s: no hex data input found\n", filename);
64 return(-1); 64 return(-1);
65 } 65 }
66 return(count); 66 return(count);
67 } 67 }
68
69 decode_hex_data_from_string(arg, databuf)
70 char *arg;
71 u_char *databuf;
72 {
73 unsigned count;
74
75 for (count = 0; ; count++) {
76 while (isspace(*arg))
77 arg++;
78 if (!*arg)
79 break;
80 if (!isxdigit(arg[0]) || !isxdigit(arg[1])) {
81 fprintf(stderr, "error: invalid hex string input\n");
82 return(-1);
83 }
84 if (count >= 255) {
85 fprintf(stderr, "error: hex input data is too long\n");
86 return(-1);
87 }
88 databuf[count] = (decode_hex_digit(arg[0]) << 4) |
89 decode_hex_digit(arg[1]);
90 arg += 2;
91 }
92 if (!count) {
93 fprintf(stderr, "error: empty hex string argument\n");
94 return(-1);
95 }
96 return(count);
97 }