view utils/gen-hex-c.c @ 55:f27bc1e17311

fr-sid/goodsp-frame41.gsmx: starting point This 33-byte binary file contains frame #41 from good_sp.cod from GSM 06.32 test sequence set, converted from ETSI *.cod format into our gsmx format. This frame is an example of a real FRv1 SID.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 22 Aug 2024 05:00:08 +0000
parents 871e83f0cb76
children
line wrap: on
line source

/*
 * This program reads an arbitrary binary file and converts it into
 * ASCII hex output of the form '0xXX,0xXX,...' intended for inclusion
 * into C sources as a const char array.
 */

#include <stdio.h>
#include <stdlib.h>

main(argc, argv)
	char **argv;
{
	FILE *inf, *outf;
	int c, lcnt;

	if (argc != 3) {
		fprintf(stderr, "usage: %s input.bin output.c\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);
	}
	lcnt = 0;
	for (;;) {
		c = getc(inf);
		if (c < 0)
			break;
		fprintf(outf, "0x%02X,", c);
		lcnt++;
		if (lcnt >= 16) {
			putc('\n', outf);
			lcnt = 0;
		}
	}
	if (lcnt)
		putc('\n', outf);
	exit(0);
}