]>
Commit | Line | Data |
---|---|---|
0b4de514 | 1 | /* |
f40f890a | 2 | * Copyright (C) 2008,2010 Free Software Foundation, Inc. |
0b4de514 RM |
3 | * |
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. | |
8 | * | |
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. | |
13 | * | |
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/>. | |
16 | */ | |
17 | ||
885d1a8d | 18 | #include <config.h> |
0b4de514 RM |
19 | #include <stdio.h> |
20 | #include <stdlib.h> | |
21 | ||
885d1a8d RM |
22 | #define _GNU_SOURCE 1 |
23 | #include <getopt.h> | |
24 | ||
25 | #include "progname.h" | |
26 | ||
27 | static struct option options[] = | |
28 | { | |
29 | {"help", no_argument, 0, 'h' }, | |
30 | {"version", no_argument, 0, 'V' }, | |
31 | {0, 0, 0, 0 } | |
32 | }; | |
33 | ||
34 | static void | |
35 | usage (int status) | |
36 | { | |
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\ | |
94e7e712 | 44 | Convert a binary file to a C header.\n\ |
b510928c | 45 | \n\ |
885d1a8d RM |
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); | |
51 | ||
52 | exit (status); | |
53 | } | |
54 | ||
0b4de514 RM |
55 | int |
56 | main (int argc, char *argv[]) | |
57 | { | |
58 | int b, i; | |
59 | char *sym; | |
0b4de514 | 60 | |
885d1a8d RM |
61 | set_program_name (argv[0]); |
62 | ||
63 | /* Check for options. */ | |
64 | while (1) | |
0b4de514 | 65 | { |
885d1a8d RM |
66 | int c = getopt_long (argc, argv, "snm:r:hVv", options, 0); |
67 | ||
68 | if (c == -1) | |
69 | break; | |
70 | else | |
71 | switch (c) | |
72 | { | |
73 | case 'h': | |
74 | usage (0); | |
75 | break; | |
76 | ||
77 | case 'V': | |
78 | printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION); | |
79 | return 0; | |
80 | ||
81 | default: | |
82 | usage (1); | |
83 | break; | |
84 | } | |
0b4de514 RM |
85 | } |
86 | ||
885d1a8d RM |
87 | if (optind >= argc) |
88 | usage (1); | |
89 | ||
90 | if (optind + 1 != argc) | |
91 | usage (1); | |
92 | ||
93 | sym = argv[optind]; | |
0b4de514 RM |
94 | |
95 | b = getchar (); | |
96 | if (b == EOF) | |
97 | goto abort; | |
98 | ||
a75f4f62 | 99 | printf ("/* THIS CHUNK OF BYTES IS AUTOMATICALLY GENERATED */\n" |
f40f890a | 100 | "unsigned char %s[] =\n{\n", sym); |
0b4de514 RM |
101 | |
102 | while (1) | |
103 | { | |
104 | printf ("0x%02x", b); | |
105 | ||
106 | b = getchar (); | |
107 | if (b == EOF) | |
108 | goto end; | |
109 | ||
110 | for (i = 0; i < 16 - 1; i++) | |
111 | { | |
112 | printf (", 0x%02x", b); | |
113 | ||
114 | b = getchar (); | |
115 | if (b == EOF) | |
116 | goto end; | |
117 | } | |
118 | ||
119 | printf (",\n"); | |
120 | } | |
121 | ||
122 | end: | |
123 | printf ("\n};\n"); | |
124 | ||
125 | abort: | |
126 | exit (0); | |
127 | } |