]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
Support --help and --version in grub-bin2h.
authorRobert Millan <rmh@aybabtu.com>
Thu, 14 Jan 2010 20:33:10 +0000 (20:33 +0000)
committerRobert Millan <rmh@aybabtu.com>
Thu, 14 Jan 2010 20:33:10 +0000 (20:33 +0000)
ChangeLog.kernel-font
conf/common.rmk
util/bin2h.c

index 69e3dafe8df7f8d7c4f67330cd0890912160f731..3842f9b512daaec3af59a821dcd9a9abfc95d256 100644 (file)
@@ -34,7 +34,7 @@
        used. Call print_glyphs.
        * Makefile.in (pkgdata_DATA): Add `font/ascii.h'.
 
-2010-01-10  Robert Millan  <rmh.grub@aybabtu.com>
+2010-01-14  Robert Millan  <rmh.grub@aybabtu.com>
 
        * conf/common.rmk (bin_UTILITIES): Add `grub-bin2h'.
        (grub_bin2h_SOURCES): New variable.
index 0a67cf0cfca52bd4ce8ddf924945141eb84ffc50..ee503f8b6ccf235f96c799d4cd7c7e9012a0f052 100644 (file)
@@ -89,7 +89,7 @@ bin_UTILITIES += grub-mkrelpath
 grub_mkrelpath_SOURCES = gnulib/progname.c util/grub-mkrelpath.c util/misc.c
 
 bin_UTILITIES += grub-bin2h
-grub_bin2h_SOURCES = util/bin2h.c
+grub_bin2h_SOURCES = gnulib/progname.c util/bin2h.c
 
 # For the parser.
 grub_script.tab.c grub_script.tab.h: script/parser.y
index 4139b52eb180acf5a0b3ea1e0a882eade52e26bc..5ce47f086e37c742e656dace8ed75990bc1342ab 100644 (file)
  *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+#define _GNU_SOURCE    1
+#include <getopt.h>
+
+#include "progname.h"
+
+static struct option options[] =
+  {
+    {"help", no_argument, 0, 'h' },
+    {"version", no_argument, 0, 'V' },
+    {0, 0, 0, 0 }
+  };
+
+static void
+usage (int status)
+{
+  if (status)
+    fprintf (stderr,
+            "Try ``%s --help'' for more information.\n", program_name);
+  else
+    printf ("\
+Usage: %s [OPTIONS] SYMBOL-NAME\n\
+\n\
+  -h, --help                display this message and exit\n\
+  -V, --version             print version information and exit\n\
+\n\
+Report bugs to <%s>.\n\
+", program_name, PACKAGE_BUGREPORT);
+
+  exit (status);
+}
+
 int
 main (int argc, char *argv[])
 {
   int b, i;
   char *sym;
 
-  if (argc != 2)
+  set_program_name (argv[0]);
+
+  /* Check for options.  */
+  while (1)
     {
-      fprintf (stderr, "Usage: %s symbol_name\n", argv[0]);
-      exit (1);
+      int c = getopt_long (argc, argv, "snm:r:hVv", options, 0);
+
+      if (c == -1)
+       break;
+      else
+       switch (c)
+         {
+         case 'h':
+           usage (0);
+           break;
+
+         case 'V':
+           printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
+           return 0;
+
+         default:
+           usage (1);
+           break;
+         }
     }
 
-  sym = argv[1];
+  if (optind >= argc)
+    usage (1);
+  
+  if (optind + 1 != argc)
+    usage (1);
+
+  sym = argv[optind];
 
   b = getchar ();
   if (b == EOF)