Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1OvRp4-0006JD-Bt for mharc-grub-devel@gnu.org; Tue, 14 Sep 2010 05:29:06 -0400 Received: from [140.186.70.92] (port=51004 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OvRp0-0006IU-Jd for grub-devel@gnu.org; Tue, 14 Sep 2010 05:29:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OvRoy-0003Jc-P9 for grub-devel@gnu.org; Tue, 14 Sep 2010 05:29:02 -0400 Received: from smarthost02.mail.zen.net.uk ([212.23.3.141]:53268) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OvRoy-0003JU-GX for grub-devel@gnu.org; Tue, 14 Sep 2010 05:29:00 -0400 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost02.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1OvRox-0002Xj-6L for grub-devel@gnu.org; Tue, 14 Sep 2010 09:28:59 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) for grub-devel@gnu.org id 1OvRow-0004Ac-00; Tue, 14 Sep 2010 10:28:58 +0100 Date: Tue, 14 Sep 2010 10:28:58 +0100 From: Colin Watson To: The development of GNU GRUB Message-ID: <20100914092858.GH21862@riva.ucam.org> References: <20100913140602.12949.42630.stgit@colinux.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100913140602.12949.42630.stgit@colinux.localdomain> User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost02-IP: [82.69.40.219] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: Re: [PATCH] grub-setup.c: Use argp instead of getopt. X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Sep 2010 09:29:04 -0000 On Mon, Sep 13, 2010 at 04:06:02PM +0200, Yves Blusseau wrote: > util/i386/pc/grub-setup.c | 315 ++++++++++++++++++++++++--------------------- Unless and until they're unified, please keep util/sparc64/ieee1275/grub-setup.c in sync with this as best you can. > -static struct option options[] = > - { > - {"boot-image", required_argument, 0, 'b'}, > - {"core-image", required_argument, 0, 'c'}, > - {"directory", required_argument, 0, 'd'}, > - {"device-map", required_argument, 0, 'm'}, > - {"root-device", required_argument, 0, 'r'}, > - {"force", no_argument, 0, 'f'}, > - {"skip-fs-probe", no_argument, 0, 's'}, > - {"help", no_argument, 0, 'h'}, > - {"version", no_argument, 0, 'V'}, > - {"verbose", no_argument, 0, 'v'}, > - {0, 0, 0, 0} > - }; > - > +/* Print the version information. */ > static void > -usage (int status) > +print_version (FILE *stream, struct argp_state *state) > { > - if (status) > - fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name); > - else > - printf (_("\ > -Usage: %s [OPTION]... DEVICE\n\ > -\n\ > + fprintf (stream, "%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION); > +} > +void (*argp_program_version_hook) (FILE *, struct argp_state *) = print_version; > + > +const char *argp_program_bug_address = "<"PACKAGE_BUGREPORT">"; > + > +static struct argp_option options[] = { > + {"boot-image", 'b', N_("FILE"), 0, > + N_("Use FILE as the boot image [default=")DEFAULT_BOOT_FILE"]", 0}, I don't think this translates well. What if some language wants the translation to be of the form: Use FILE [default=blah] as the boot image The rule of thumb is that you should not split up translatable strings into any units smaller than sentences. Instead, you should write this as N_("Use FILE as the boot image [default=%s]"), write a function that looks a bit like this: static char * help_filter (int key, const char *text, void *input __attribute__ ((unused))) { switch (key) { case 'b': return xasprintf (text, DEFAULT_BOOT_FILE); ... default: return (char *) text; } } ... and add that function as the sixth element in your 'struct argp'. > +struct arguments > +{ > + char *boot_file; /* --boot-file */ > + char *core_file; /* --core-file */ > + char *dir; /* --directory */ > + char *dev_map; /* --device-map */ > + char *root_dev; /* --root-device */ > + int force; /* --force */ > + int fs_probe; /* --skip-fs-probe */ > + char *device; /* DEVICE */ > +}; I think this is perhaps overcommented. :-) > +static struct argp argp = { > + options, argp_parser, "DEVICE", > +"\n\ > Set up images to boot from DEVICE.\n\ > -DEVICE must be a GRUB device (e.g. `(hd0,1)').\n\ > -\n\ > -You should not normally run %s directly. Use grub-install instead.\n\ > -\n\ > - -b, --boot-image=FILE use FILE as the boot image [default=%s]\n\ > - -c, --core-image=FILE use FILE as the core image [default=%s]\n\ > - -d, --directory=DIR use GRUB files in the directory DIR [default=%s]\n\ > - -m, --device-map=FILE use FILE as the device map [default=%s]\n\ > - -r, --root-device=DEV use DEV as the root device [default=guessed]\n\ > - -f, --force install even if problems are detected\n\ > - -s, --skip-fs-probe do not probe for filesystems in DEVICE\n\ > - -h, --help display this message and exit\n\ > - -V, --version print version information and exit\n\ > - -v, --verbose print verbose messages\n\ > \n\ > -Report bugs to <%s>.\n\ > -"), > - program_name, program_name, > - DEFAULT_BOOT_FILE, DEFAULT_CORE_FILE, DEFAULT_DIRECTORY, > - DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT); > +You should not normally run this program directly. Use grub-install instead.\n\ > +\v\ > +DEVICE must be an OS device (e.g. /dev/sda1).", > + NULL, NULL, NULL > +}; The strings here should be enclosed in N_() so that they can be translated. > + /* Parse our arguments */ > + argp_parse (&argp, argc, argv, 0, 0, &arguments); You need to check the return value. exit (1) would probably be appropriate handling. -- Colin Watson [cjwatson@ubuntu.com]