2N/A/*
2N/A * Copyright (C) 2008,2010 Free Software Foundation, Inc.
2N/A *
2N/A * GRUB is free software: you can redistribute it and/or modify
2N/A * it under the terms of the GNU General Public License as published by
2N/A * the Free Software Foundation, either version 3 of the License, or
2N/A * (at your option) any later version.
2N/A *
2N/A * GRUB is distributed in the hope that it will be useful,
2N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2N/A * GNU General Public License for more details.
2N/A *
2N/A * You should have received a copy of the GNU General Public License
2N/A * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
2N/A */
2N/A
2N/A#include <config.h>
2N/A#include <stdio.h>
2N/A#include <stdlib.h>
2N/A
2N/A#define _GNU_SOURCE 1
2N/A#include <getopt.h>
2N/A
2N/A#include "progname.h"
2N/A
2N/Astatic struct option options[] =
2N/A {
2N/A {"help", no_argument, 0, 'h' },
2N/A {"version", no_argument, 0, 'V' },
2N/A {0, 0, 0, 0 }
2N/A };
2N/A
2N/Astatic void
2N/Ausage (int status)
2N/A{
2N/A if (status)
2N/A fprintf (stderr,
2N/A "Try ``%s --help'' for more information.\n", program_name);
2N/A else
2N/A printf ("\
2N/AUsage: %s [OPTIONS] SYMBOL-NAME\n\
2N/A\n\
2N/AConvert a binary file to a C header.\n\
2N/A\n\
2N/A -h, --help display this message and exit\n\
2N/A -V, --version print version information and exit\n\
2N/A\n\
2N/AReport bugs to <%s>.\n\
2N/A", program_name, PACKAGE_BUGREPORT);
2N/A
2N/A exit (status);
2N/A}
2N/A
2N/Aint
2N/Amain (int argc, char *argv[])
2N/A{
2N/A int b, i;
2N/A char *sym;
2N/A
2N/A set_program_name (argv[0]);
2N/A
2N/A /* Check for options. */
2N/A while (1)
2N/A {
2N/A int c = getopt_long (argc, argv, "snm:r:hVv", options, 0);
2N/A
2N/A if (c == -1)
2N/A break;
2N/A else
2N/A switch (c)
2N/A {
2N/A case 'h':
2N/A usage (0);
2N/A break;
2N/A
2N/A case 'V':
2N/A printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
2N/A return 0;
2N/A
2N/A default:
2N/A usage (1);
2N/A break;
2N/A }
2N/A }
2N/A
2N/A if (optind >= argc)
2N/A usage (1);
2N/A
2N/A if (optind + 1 != argc)
2N/A usage (1);
2N/A
2N/A sym = argv[optind];
2N/A
2N/A b = getchar ();
2N/A if (b == EOF)
2N/A goto abort;
2N/A
2N/A printf ("/* THIS CHUNK OF BYTES IS AUTOMATICALLY GENERATED */\n"
2N/A "unsigned char %s[] =\n{\n", sym);
2N/A
2N/A while (1)
2N/A {
2N/A printf ("0x%02x", b);
2N/A
2N/A b = getchar ();
2N/A if (b == EOF)
2N/A goto end;
2N/A
2N/A for (i = 0; i < 16 - 1; i++)
2N/A {
2N/A printf (", 0x%02x", b);
2N/A
2N/A b = getchar ();
2N/A if (b == EOF)
2N/A goto end;
2N/A }
2N/A
2N/A printf (",\n");
2N/A }
2N/A
2N/Aend:
2N/A printf ("\n};\n");
2N/A
2N/Aabort:
2N/A exit (0);
2N/A}