From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IqsEW-00082W-Bk for mharc-grub-devel@gnu.org; Sat, 10 Nov 2007 10:26:52 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IqsEU-0007yT-4l for grub-devel@gnu.org; Sat, 10 Nov 2007 10:26:50 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IqsET-0007wc-3z for grub-devel@gnu.org; Sat, 10 Nov 2007 10:26:49 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IqsES-0007wN-Qy for grub-devel@gnu.org; Sat, 10 Nov 2007 10:26:48 -0500 Received: from mailout09.sul.t-online.de ([194.25.134.84] helo=mailout09.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IqsES-0002LH-B3 for grub-devel@gnu.org; Sat, 10 Nov 2007 10:26:48 -0500 Received: from fwd32.aul.t-online.de by mailout09.sul.t-online.com with smtp id 1IqsEQ-0001ox-05; Sat, 10 Nov 2007 16:26:46 +0100 Received: from [10.3.2.2] (ZSbMZEZXghUxqkxTRePKEU7OQQmF4uZhrfQ7-Q5FxeU9coEUwJYgyOPhfRKqsfmwNp@[217.235.232.217]) by fwd32.aul.t-online.de with esmtp id 1IqsEL-0IVm8e0; Sat, 10 Nov 2007 16:26:41 +0100 Message-ID: <4735CDA9.4060501@t-online.de> Date: Sat, 10 Nov 2007 16:26:33 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 MIME-Version: 1.0 To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="------------090603080601050501050402" X-ID: ZSbMZEZXghUxqkxTRePKEU7OQQmF4uZhrfQ7-Q5FxeU9coEUwJYgyOPhfRKqsfmwNp X-TOI-MSGID: 26e43b82-45e7-4396-ba23-5ee31152f91d X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [PATCH] Use getopt_long() instead of argp_parse() in grub-emu X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 10 Nov 2007 15:26:50 -0000 This is a multi-part message in MIME format. --------------090603080601050501050402 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Unlike the other GRUB2 utils, grub-emu uses the glibc extension argp_parse(). It is unavailable on Cygwin, which might also be the case for other platforms where glibc is not the native runtime. This patch changes this back to the more traditional getopt_long(). It also fixes the syntax of the path prefix. Christian 2007-11-10 Christian Franke * util/grub-emu.c: Replace argp.h by getopt.h. (parse_opt): Remove. (usage): New function. (main): Replace argp_parse() by getopt_long(). Rename argument variables accordingly. Add missing "(...)" for root_dev in prefix. --------------090603080601050501050402 Content-Type: text/x-patch; name="grub2-emu-getopt.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-emu-getopt.patch" --- grub2.orig/util/grub-emu.c 2007-08-02 19:24:06.000000000 +0200 +++ grub2/util/grub-emu.c 2007-11-10 16:05:26.843750000 +0100 @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include #include @@ -90,104 +90,115 @@ grub_machine_fini (void) } -const char *argp_program_version = PACKAGE_STRING; -const char *argp_program_bug_address = PACKAGE_BUGREPORT; -static char doc[] = "GRUB emulator"; - -static struct argp_option options[] = { - {"root-device", 'r', "DEV", 0, "use DEV as the root device [default=guessed]", 0}, - {"device-map", 'm', "FILE", 0, "use FILE as the device map", 0}, - {"directory", 'd', "DIR", 0, "use GRUB files in the directory DIR", 0}, - {"verbose", 'v', 0 , 0, "print verbose messages", 0}, - {"hold", 'H', "SECONDS", OPTION_ARG_OPTIONAL, "wait until a debugger will attach", 0}, - { 0, 0, 0, 0, 0, 0 } -}; - -struct arguments -{ - char *root_dev; - char *dev_map; - char *dir; - int hold; -}; - -static error_t -parse_opt (int key, char *arg, struct argp_state *state) -{ - struct arguments *args = state->input; - - switch (key) - { - case 'r': - args->root_dev = arg; - break; - case 'd': - args->dir = arg; - break; - case 'm': - args->dev_map = arg; - break; - case 'v': - verbosity++; - break; - case 'H': - args->hold = arg ? atoi (arg) : -1; - break; - case ARGP_KEY_END: - break; - default: - return ARGP_ERR_UNKNOWN; - } - return 0; +static struct option options[] = + { + {"root-device", required_argument, 0, 'r'}, + {"device-map", required_argument, 0, 'm'}, + {"directory", required_argument, 0, 'd'}, + {"hold", optional_argument, 0, 'H'}, + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {"verbose", no_argument, 0, 'v'}, + { 0, 0, 0, 0 } + }; + +static int +usage (int status) +{ + if (status) + fprintf (stderr, + "Try ``grub-emu --help'' for more information.\n"); + else + printf ( + "Usage: grub-emu [OPTION]...\n" + "\n" + "GRUB emulator.\n" + "\n" + " -r, --root-device=DEV use DEV as the root device [default=guessed]\n" + " -m, --device-map=FILE use FILE as the device map [default=%s]\n" + " -d, --directory=DIR use GRUB files in the directory DIR [default=%s]\n" + " -v, --verbose print verbose messages\n" + " -H, --hold[=SECONDS] wait until a debugger will attach\n" + " -h, --help display this message and exit\n" + " -V, --version print version information and exit\n" + "\n" + "Report bugs to <%s>.\n", DEFAULT_DEVICE_MAP, DEFAULT_DIRECTORY, PACKAGE_BUGREPORT); + return status; } - -static struct argp argp = {options, parse_opt, 0, doc, 0, 0, 0}; int main (int argc, char *argv[]) { - char *dir; - - struct arguments args = - { - .dir = DEFAULT_DIRECTORY, - .dev_map = DEFAULT_DEVICE_MAP, - .hold = 0 - }; + char *root_dev = 0; + char *dir = DEFAULT_DIRECTORY; + char *dev_map = DEFAULT_DEVICE_MAP; + volatile int hold = 0; + int opt; progname = "grub-emu"; - - argp_parse (&argp, argc, argv, 0, 0, &args); + + while ((opt = getopt_long (argc, argv, "r:d:m:vH:hV", options, 0)) != -1) + switch (opt) + { + case 'r': + root_dev = optarg; + break; + case 'd': + dir = optarg; + break; + case 'm': + dev_map = optarg; + break; + case 'v': + verbosity++; + break; + case 'H': + hold = (optarg ? atoi (optarg) : -1); + break; + case 'h': + return usage (0); + case 'V': + printf ("%s (%s) %s\n", progname, PACKAGE_NAME, PACKAGE_VERSION); + return 0; + default: + return usage (1); + } + + if (optind < argc) + { + fprintf (stderr, "Unknown extra argument `%s'.\n", argv[optind]); + return usage (1); + } /* Wait until the ARGS.HOLD variable is cleared by an attached debugger. */ - if (args.hold && verbosity > 0) + if (hold && verbosity > 0) printf ("Run \"gdb %s %d\", and set ARGS.HOLD to zero.\n", progname, (int) getpid ()); - while (args.hold) + while (hold) { - if (args.hold > 0) - args.hold--; + if (hold > 0) + hold--; sleep (1); } /* XXX: This is a bit unportable. */ - grub_util_biosdisk_init (args.dev_map); + grub_util_biosdisk_init (dev_map); grub_hostfs_init (); grub_init_all (); /* Make sure that there is a root device. */ - if (! args.root_dev) + if (! root_dev) { - char *device_name = grub_guess_root_device (args.dir ? : DEFAULT_DIRECTORY); + char *device_name = grub_guess_root_device (dir); if (! device_name) - grub_util_error ("cannot find a device for %s.\n", args.dir ? : DEFAULT_DIRECTORY); + grub_util_error ("cannot find a device for %s.\n", dir); - args.root_dev = grub_util_get_grub_dev (device_name); - if (! args.root_dev) + root_dev = grub_util_get_grub_dev (device_name); + if (! root_dev) { grub_util_info ("guessing the root device failed, because of `%s'", grub_errmsg); @@ -195,9 +206,9 @@ main (int argc, char *argv[]) } } - dir = grub_get_prefix (args.dir ? : DEFAULT_DIRECTORY); - prefix = xmalloc (strlen (args.root_dev) + strlen (dir) + 1); - sprintf (prefix, "%s%s", args.root_dev, dir); + dir = grub_get_prefix (dir); + prefix = xmalloc (strlen (root_dev) + 2 + strlen (dir) + 1); + sprintf (prefix, "(%s)%s", root_dev, dir); free (dir); /* Start GRUB! */ --------------090603080601050501050402--