# HG changeset patch # User Mychaela Falconia # Date 1727290097 0 # Node ID ffbbce856ac7571f26eaf7348b5ef0c3ad9f77b2 # Parent eeb28c9c633a6aa0b5522e4afab319f0b3a61212 utils/gen-hex-lines: import from vband-misc repository diff -r eeb28c9c633a -r ffbbce856ac7 .hgignore --- 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$ diff -r eeb28c9c633a -r ffbbce856ac7 utils/Makefile --- /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} diff -r eeb28c9c633a -r ffbbce856ac7 utils/gen-hex-lines.c --- /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 +#include + +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); +}