FreeCalypso > hg > gsm-net-reveng
comparison utils/gen-hex-lines.c @ 61:ffbbce856ac7
utils/gen-hex-lines: import from vband-misc repository
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 25 Sep 2024 18:48:17 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
60:eeb28c9c633a | 61:ffbbce856ac7 |
---|---|
1 /* | |
2 * This program reads an arbitrary binary file and converts it into ASCII hex | |
3 * output with a specified number of bytes per line. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 | |
9 main(argc, argv) | |
10 char **argv; | |
11 { | |
12 FILE *inf, *outf; | |
13 int c, lcnt, bpl; | |
14 | |
15 if (argc != 4) { | |
16 fprintf(stderr, | |
17 "usage: %s input.bin output.hex bytes-per-line\n", | |
18 argv[0]); | |
19 exit(1); | |
20 } | |
21 inf = fopen(argv[1], "r"); | |
22 if (!inf) { | |
23 perror(argv[1]); | |
24 exit(1); | |
25 } | |
26 outf = fopen(argv[2], "w"); | |
27 if (!outf) { | |
28 perror(argv[2]); | |
29 exit(1); | |
30 } | |
31 bpl = atoi(argv[3]); | |
32 lcnt = 0; | |
33 for (;;) { | |
34 c = getc(inf); | |
35 if (c < 0) | |
36 break; | |
37 fprintf(outf, "%02X", c); | |
38 lcnt++; | |
39 if (lcnt >= bpl) { | |
40 putc('\n', outf); | |
41 lcnt = 0; | |
42 } | |
43 } | |
44 if (lcnt) | |
45 putc('\n', outf); | |
46 exit(0); | |
47 } |