Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / util / bin2h.c
blob106c87a53072802d6a80e7f4aa4e983da3ad5879
1 /*
2 * Copyright (C) 2008,2010 Free Software Foundation, Inc.
4 * GRUB is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * GRUB is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
18 #include <config.h>
19 #include <stdio.h>
20 #include <stdlib.h>
22 #define _GNU_SOURCE 1
23 #include <getopt.h>
25 #include "progname.h"
27 static struct option options[] =
29 {"help", no_argument, 0, 'h' },
30 {"version", no_argument, 0, 'V' },
31 {0, 0, 0, 0 }
34 static void __attribute__ ((noreturn))
35 usage (int status)
37 if (status)
38 fprintf (stderr,
39 "Try ``%s --help'' for more information.\n", program_name);
40 else
41 printf ("\
42 Usage: %s [OPTIONS] SYMBOL-NAME\n\
43 \n\
44 Convert a binary file to a C header.\n\
45 \n\
46 -h, --help display this message and exit\n\
47 -V, --version print version information and exit\n\
48 \n\
49 Report bugs to <%s>.\n\
50 ", program_name, PACKAGE_BUGREPORT);
52 exit (status);
55 int
56 main (int argc, char *argv[])
58 int b, i;
59 char *sym;
61 set_program_name (argv[0]);
63 /* Check for options. */
64 while (1)
66 int c = getopt_long (argc, argv, "snm:r:hVv", options, 0);
68 if (c == -1)
69 break;
70 else
71 switch (c)
73 case 'h':
74 usage (0);
75 break;
77 case 'V':
78 printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
79 return 0;
81 default:
82 usage (1);
83 break;
87 if (optind >= argc)
88 usage (1);
90 if (optind + 1 != argc)
91 usage (1);
93 sym = argv[optind];
95 b = getchar ();
96 if (b == EOF)
97 goto abort;
99 printf ("/* THIS CHUNK OF BYTES IS AUTOMATICALLY GENERATED */\n"
100 "unsigned char %s[] =\n{\n", sym);
102 while (1)
104 printf ("0x%02x", b);
106 b = getchar ();
107 if (b == EOF)
108 goto end;
110 for (i = 0; i < 16 - 1; i++)
112 printf (", 0x%02x", b);
114 b = getchar ();
115 if (b == EOF)
116 goto end;
119 printf (",\n");
122 end:
123 printf ("\n};\n");
125 abort:
126 exit (0);