ieee1275: split up grub_machine_get_bootlocation
[grub.git] / util / bin2h.c
1 /*
2  *  Copyright (C) 2008,2010  Free Software Foundation, Inc.
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
18 #include <stdio.h>
19 #include <stdlib.h>
20
21 int
22 main (int argc, char *argv[])
23 {
24   int b, i;
25   char *sym;
26
27   if (2 != argc)
28     return 1;
29
30   sym = argv[1];
31
32   b = getchar ();
33   if (b == EOF)
34     goto abort;
35
36   printf ("/* THIS CHUNK OF BYTES IS AUTOMATICALLY GENERATED */\n"
37           "unsigned char %s[] =\n{\n", sym);
38
39   while (1)
40     {
41       printf ("0x%02x", b);
42
43       b = getchar ();
44       if (b == EOF)
45         goto end;
46
47       for (i = 0; i < 16 - 1; i++)
48         {
49           printf (", 0x%02x", b);
50
51           b = getchar ();
52           if (b == EOF)
53             goto end;
54         }
55
56       printf (",\n");
57     }
58
59 end:
60   printf ("\n};\n");
61
62 abort:
63   exit (0);
64 }