/* bin2h.c
 *
 * This file is part of vdr-skinneutrino
 * Copyright (C) 2007 Sascha Wessel <sawe@users.sf.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

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

int main(int argc, char **argv) {
	FILE *file;
	int b, i = 0;

	if (argc != 3) {
		fprintf(stderr, "usage: %s <filename> <varname>\n", argv[0]);
		return 1;
	}

	if (!(file = fopen(argv[1], "r"))) {
		fprintf(stderr, "error: fopen failed: %s\n", argv[1]);
		return 1;
	}

	printf("const unsigned char %s[] = {", argv[2]);


	while ((b = fgetc(file)) != EOF) {
		if (!(i++ % 16))
			printf("\n");
		printf("0x%02x, ", b);
	}

	if (!feof(file)) {
		fprintf(stderr, "error: fgetc failed: %s\n", argv[1]);
		fclose(file);
		return 1;
	}

	fclose(file);
	printf("\n};\n");

	return 0;
}

