FreeCalypso > hg > vband-misc
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/gen-hex-lines.c Mon Aug 12 03:06:17 2024 +0000 @@ -0,0 +1,48 @@ +/* + * This program reads an arbitrary binary file and converts it into ASCII hex + * output with a specified number of bytes per line. The intended purpose + * is to convert gsmx files (FR or EFR) into hex files with one frame per line. + */ + +#include <stdio.h> +#include <stdlib.h> + +main(argc, argv) + char **argv; +{ + FILE *inf, *outf; + int c, lcnt, bpl; + + if (argc != 4) { + fprintf(stderr, + "usage: %s input.bin output.hex bytes-per-line\n", + argv[0]); + exit(1); + } + inf = fopen(argv[1], "r"); + if (!inf) { + perror(argv[1]); + exit(1); + } + outf = fopen(argv[2], "w"); + if (!outf) { + perror(argv[2]); + exit(1); + } + bpl = atoi(argv[3]); + lcnt = 0; + for (;;) { + c = getc(inf); + if (c < 0) + break; + fprintf(outf, "%02X", c); + lcnt++; + if (lcnt >= bpl) { + putc('\n', outf); + lcnt = 0; + } + } + if (lcnt) + putc('\n', outf); + exit(0); +}