FreeCalypso > hg > freecalypso-hwlab
diff 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 |
line wrap: on
line diff
--- a/simtool/hexread.c Tue Jan 26 00:51:59 2021 +0000 +++ b/simtool/hexread.c Tue Jan 26 01:27:58 2021 +0000 @@ -65,3 +65,33 @@ } return(count); } + +decode_hex_data_from_string(arg, databuf) + char *arg; + u_char *databuf; +{ + unsigned count; + + for (count = 0; ; count++) { + while (isspace(*arg)) + arg++; + if (!*arg) + break; + if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { + fprintf(stderr, "error: invalid hex string input\n"); + return(-1); + } + if (count >= 255) { + fprintf(stderr, "error: hex input data is too long\n"); + return(-1); + } + databuf[count] = (decode_hex_digit(arg[0]) << 4) | + decode_hex_digit(arg[1]); + arg += 2; + } + if (!count) { + fprintf(stderr, "error: empty hex string argument\n"); + return(-1); + } + return(count); +}