summaryrefslogtreecommitdiff
path: root/bin2h.c
blob: 65674964250947156ff999dc03993199d88c02f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/* bin2h -- embed a binary file as the C array clectio compiles in.
 * usage: bin2h <file> > text.lz.h
 * Copyright (C) 2026 Ɓukasz Kasprzak.  SPDX-License-Identifier: GPL-3.0-or-later */
#include <stdio.h>

int main(int argc, char **argv) {
	FILE *f;
	int c, n = 0;
	if (argc != 2 || !(f = fopen(argv[1], "rb"))) {
		fprintf(stderr, "usage: bin2h <file> > out.h\n");
		return 1;
	}
	printf("static const unsigned char text_lz[] = {");
	while ((c = fgetc(f)) != EOF) {
		if (n % 20 == 0)
			printf("\n\t");
		printf("%d,", c);
		n++;
	}
	printf("\n};\nstatic const unsigned text_lz_len = %d;\n", n);
	fclose(f);
	return 0;
}