comparison utils/gen-hex-lines.c @ 51:914eeb3ab866

efr-sid OS#6538: generate test frames in hex form
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 12 Aug 2024 03:06:17 +0000
parents utils/gen-hex-c.c@871e83f0cb76
children
comparison
equal deleted inserted replaced
50:0db059f4632d 51:914eeb3ab866
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. The intended purpose
4 * is to convert gsmx files (FR or EFR) into hex files with one frame per line.
5 */
6
7 #include <stdio.h>
8 #include <stdlib.h>
9
10 main(argc, argv)
11 char **argv;
12 {
13 FILE *inf, *outf;
14 int c, lcnt, bpl;
15
16 if (argc != 4) {
17 fprintf(stderr,
18 "usage: %s input.bin output.hex bytes-per-line\n",
19 argv[0]);
20 exit(1);
21 }
22 inf = fopen(argv[1], "r");
23 if (!inf) {
24 perror(argv[1]);
25 exit(1);
26 }
27 outf = fopen(argv[2], "w");
28 if (!outf) {
29 perror(argv[2]);
30 exit(1);
31 }
32 bpl = atoi(argv[3]);
33 lcnt = 0;
34 for (;;) {
35 c = getc(inf);
36 if (c < 0)
37 break;
38 fprintf(outf, "%02X", c);
39 lcnt++;
40 if (lcnt >= bpl) {
41 putc('\n', outf);
42 lcnt = 0;
43 }
44 }
45 if (lcnt)
46 putc('\n', outf);
47 exit(0);
48 }