2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
18 fprintf(stderr
, "usage: file2c [-n count] [-x] filename [prefix [suffix]]\n");
23 main(int argc
, char *argv
[])
25 int c
, count
, linepos
, maxcount
, radix
;
30 while ((c
= getopt(argc
, argv
, "n:x")) != -1) {
32 case 'n': /* Max. number of bytes per line. */
33 maxcount
= strtol(optarg
, NULL
, 10);
35 case 'x': /* Print hexadecimal numbers. */
48 fp
= fopen(argv
[0], "rb");
53 printf("%s\n", argv
[1]);
55 while((c
= fgetc(fp
)) != EOF
) {
60 if ((maxcount
== 0 && linepos
> 70) ||
61 (maxcount
> 0 && count
>= maxcount
)) {
67 linepos
+= printf("%d", c
);
70 linepos
+= printf("0x%02x", c
);
80 printf("%s\n", argv
[2]);