FreeCalypso > hg > gsm-net-reveng
changeset 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 | eeb28c9c633a |
children | 6519e5c4b3f3 |
files | .hgignore utils/Makefile utils/gen-hex-lines.c |
diffstat | 3 files changed, 60 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Wed Sep 25 17:55:08 2024 +0000 +++ b/.hgignore Wed Sep 25 18:48:17 2024 +0000 @@ -29,5 +29,7 @@ ^trau-ul-prep/efrdec2tsrc$ ^trau-ul-prep/gsmx2tsrc$ +^utils/gen-hex-lines$ + ^v110/v110-dump16$ ^v110/v110-dump8$
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/Makefile Wed Sep 25 18:48:17 2024 +0000 @@ -0,0 +1,11 @@ +CC= gcc +CFLAGS= -O2 +PROGS= gen-hex-lines + +all: ${PROGS} + +gen-hex-lines: gen-hex-lines.c + ${CC} ${CFLAGS} -o $@ $@.c + +clean: + rm -f *.o ${PROGS}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/utils/gen-hex-lines.c Wed Sep 25 18:48:17 2024 +0000 @@ -0,0 +1,47 @@ +/* + * This program reads an arbitrary binary file and converts it into ASCII hex + * output with a specified number of bytes 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); +}