FreeCalypso > hg > fc-pcsc-tools
comparison libcommon/hexdump.c @ 107:f1836c8d36cb
hexdump output commands reworked to support redirection
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 19 Feb 2021 06:43:01 +0000 |
| parents | f7145c77b7fb |
| children |
comparison
equal
deleted
inserted
replaced
| 106:dcfec53643c5 | 107:f1836c8d36cb |
|---|---|
| 1 #include <sys/types.h> | 1 #include <sys/types.h> |
| 2 #include <stdio.h> | 2 #include <stdio.h> |
| 3 #include "simresp.h" | 3 #include "simresp.h" |
| 4 | 4 |
| 5 display_sim_resp_in_hex() | 5 display_sim_resp_in_hex(outf) |
| 6 FILE *outf; | |
| 6 { | 7 { |
| 7 unsigned off, cc, n, c; | 8 unsigned off, cc, n, c; |
| 8 | 9 |
| 9 for (off = 0; off < sim_resp_data_len; off += cc) { | 10 for (off = 0; off < sim_resp_data_len; off += cc) { |
| 10 printf("%02X:", off); | 11 fprintf(outf, "%02X:", off); |
| 11 cc = 16; | 12 cc = 16; |
| 12 if (sim_resp_data_len - off < cc) | 13 if (sim_resp_data_len - off < cc) |
| 13 cc = sim_resp_data_len - off; | 14 cc = sim_resp_data_len - off; |
| 14 for (n = 0; n < 16; n++) { | 15 for (n = 0; n < 16; n++) { |
| 15 if (n == 0 || n == 8) | 16 if (n == 0 || n == 8) |
| 16 putchar(' '); | 17 putc(' ', outf); |
| 17 putchar(' '); | 18 putc(' ', outf); |
| 18 if (n < cc) | 19 if (n < cc) |
| 19 printf("%02X", sim_resp_data[off + n]); | 20 fprintf(outf, "%02X", sim_resp_data[off + n]); |
| 20 else { | 21 else { |
| 21 putchar(' '); | 22 putc(' ', outf); |
| 22 putchar(' '); | 23 putc(' ', outf); |
| 23 } | 24 } |
| 24 } | 25 } |
| 25 putchar(' '); | 26 putc(' ', outf); |
| 26 putchar(' '); | 27 putc(' ', outf); |
| 27 for (n = 0; n < cc; n++) { | 28 for (n = 0; n < cc; n++) { |
| 28 c = sim_resp_data[off + n]; | 29 c = sim_resp_data[off + n]; |
| 29 if (c < 0x20 || c > 0x7E) | 30 if (c < 0x20 || c > 0x7E) |
| 30 c = '.'; | 31 c = '.'; |
| 31 putchar(c); | 32 putc(c, outf); |
| 32 } | 33 } |
| 33 putchar('\n'); | 34 putc('\n', outf); |
| 34 } | 35 } |
| 35 return(0); | 36 return(0); |
| 36 } | 37 } |
| 38 | |
| 39 cmd_sim_resp(argc, argv, outf) | |
| 40 char **argv; | |
| 41 FILE *outf; | |
| 42 { | |
| 43 return display_sim_resp_in_hex(outf); | |
| 44 } |
