From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Nxpfd-0000re-GW for mharc-grub-devel@gnu.org; Fri, 02 Apr 2010 18:48:57 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nxpfb-0000nj-NP for grub-devel@gnu.org; Fri, 02 Apr 2010 18:48:55 -0400 Received: from [140.186.70.92] (port=50003 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NxpfZ-0000ji-Uj for grub-devel@gnu.org; Fri, 02 Apr 2010 18:48:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NxpfX-0002ek-F0 for grub-devel@gnu.org; Fri, 02 Apr 2010 18:48:53 -0400 Received: from mail-fx0-f227.google.com ([209.85.220.227]:48699) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NxpfX-0002eM-2q for grub-devel@gnu.org; Fri, 02 Apr 2010 18:48:51 -0400 Received: by fxm27 with SMTP id 27so1413927fxm.8 for ; Fri, 02 Apr 2010 15:48:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:x-enigmail-version:content-type; bh=X9470nQKQsG98sXrrFgP0+YbrT4e3LKytkfIpMhDySU=; b=txRBzPrxM0bLWc7tGo37gCPC1W/vOAYdYH5nkm9zip1JMbSlsa7MIWSFPkB+7yTPDV rholhthEqGZqLp9KxzaZpoGb22fHHToao5n4hn6u25HhEk+Hew+Sx+3E66KFAKo6os8I pS5C0/3wF9fRcQoVcxo3ka97p/VZoDw6KbyBE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :x-enigmail-version:content-type; b=fExzUIvttnowvOYj8BmeeO7n4E3qGBEdwWM+gmJJFezlOt9bl6y9X2PLQWH1M4JfhO bpu4L5n6MFl7cYavMVo1BODhdKDWfCPr1zfO1/xWULdnPK5zjhL/vgotNg24QPYu0oLk cWAVhufMAjCeiPD42aC5aMrtvYta/VqHWd/RE= Received: by 10.223.21.23 with SMTP id h23mr2584827fab.21.1270248530134; Fri, 02 Apr 2010 15:48:50 -0700 (PDT) Received: from debian.bg45.phnet (222-14.77-83.cust.bluewin.ch [83.77.14.222]) by mx.google.com with ESMTPS id e17sm20882515fke.27.2010.04.02.15.48.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 02 Apr 2010 15:48:49 -0700 (PDT) Message-ID: <4BB67449.9070809@gmail.com> Date: Sat, 03 Apr 2010 00:48:41 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla-Thunderbird 2.0.0.22 (X11/20091109) MIME-Version: 1.0 To: The development of GRUB 2 X-Enigmail-Version: 0.95.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enig35ADC28928DB33873B1600F0" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: argp module import 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: Fri, 02 Apr 2010 22:48:55 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig35ADC28928DB33873B1600F0 Content-Type: multipart/mixed; boundary="------------080306090603080704030303" This is a multi-part message in MIME format. --------------080306090603080704030303 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, all. I've just imported argp module. I attach the patch to make grub-fstest argp-based. Can someone familiar with argp have a look at it?= --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------080306090603080704030303 Content-Type: text/x-diff; name="fstest_argp.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline; filename="fstest_argp.diff" =3D=3D=3D modified file 'util/grub-fstest.c' --- util/grub-fstest.c 2010-01-27 01:49:11 +0000 +++ util/grub-fstest.c 2010-04-02 22:47:13 +0000 @@ -39,9 +39,9 @@ #include #include #include -#include =20 #include "progname.h" +#include "argp.h" =20 void grub_putchar (int c) @@ -275,8 +275,17 @@ cmd_crc (char *pathname) printf ("%08x\n", crc); } =20 +static char *root =3D NULL; +static int args_count =3D 0; +static int nparm =3D 0; +static int num_disks =3D 1; +static char **images =3D NULL; +static int cmd =3D 0; +static char *debug_str =3D NULL; +static char **args =3D NULL; + static void -fstest (char **images, int num_disks, int cmd, int n, char **args) +fstest (int n, char **args) { char *host_file; char *loop_name; @@ -350,202 +359,166 @@ fstest (char **images, int num_disks, in } } =20 -static struct option options[] =3D { - {"root", required_argument, 0, 'r'}, - {"skip", required_argument, 0, 's'}, - {"length", required_argument, 0, 'n'}, - {"diskcount", required_argument, 0, 'c'}, - {"debug", required_argument, 0, 'd'}, - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {"verbose", no_argument, 0, 'v'}, - {0, 0, 0, 0} +static struct argp_option options[] =3D { + {0, 0, 0 , OPTION_DOC, "Commands:", 1}, + {"ls PATH", 0, 0 , OPTION_DOC, "List files in PATH.", 1}, + {"cp FILE LOCAL", 0, 0, OPTION_DOC, "Copy FILE to local file LOCAL.",= 1}, + {"cmp FILE LOCAL", 0, 0, OPTION_DOC, "Compare FILE with local file LOC= AL.", 1}, + {"hex FILE", 0, 0 , OPTION_DOC, "Hex dump FILE.", 1}, + {"crc FILE", 0, 0 , OPTION_DOC, "Get crc32 checksum of FILE.", 1},= + {"blocklist FILE", 0, 0, OPTION_DOC, "Display blocklist of FILE.", 1},= + + {"root", 'r', "DEVICE_NAME", 0, "Set root device.", = 2}, + {"skip", 's', "N", 0, "Skip N bytes from output file.",= 2}, + {"length", 'n', "N", 0, "Handle N bytes in output file.",= 2}, + {"diskcount", 'c', "N", 0, "N input files.", = 2}, + {"debug", 'd', "S", 0, "Set debug environment variable."= , 2}, + {"verbose", 'v', NULL, OPTION_ARG_OPTIONAL, "Print verbose messages.= ", 2}, + {0, 0, 0, 0, 0, 0} }; =20 -static void -usage (int status) +error_t=20 +argp_parser (int key, char *arg, struct argp_state *state) { - if (status) - fprintf (stderr, "Try `%s --help' for more information.\n", program_= name); - else - printf ("\ -Usage: %s [OPTION]... IMAGE_PATH COMMANDS\n\ -\n\ -Debug tool for filesystem driver.\n\ -\nCommands:\n\ - ls PATH list files in PATH\n\ - cp FILE LOCAL copy FILE to local file LOCAL\n\ - cmp FILE LOCAL compare FILE with local file LOCAL\n\ - hex FILE Hex dump FILE\n\ - crc FILE Get crc32 checksum of FILE\n\ - blocklist FILE display blocklist of FILE\n\ -\nOptions:\n\ - -r, --root=3DDEVICE_NAME set root device\n\ - -s, --skip=3DN skip N bytes from output file\n\ - -n, --length=3DN handle N bytes in output file\n\ - -c, --diskcount=3DN N input files\n\ - -d, --debug=3DS Set debug environment variable\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, PACKAGE_BUGREPORT); - - exit (status); -} + char *p; =20 -int -main (int argc, char *argv[]) -{ - char *debug_str =3D NULL, *root =3D NULL, *default_root, *alloc_root; - int i, cmd, num_opts, image_index, num_disks =3D 1; - - set_program_name (argv[0]); - - grub_util_init_nls (); - - /* Find the first non option entry. */ - for (num_opts =3D 1; num_opts < argc; num_opts++) - if (argv[num_opts][0] =3D=3D '-') - { - if ((argv[num_opts][2] =3D=3D 0) && (num_opts < argc - 1) && - ((argv[num_opts][1] =3D=3D 'r') || - (argv[num_opts][1] =3D=3D 's') || - (argv[num_opts][1] =3D=3D 'n') || - (argv[num_opts][1] =3D=3D 'c') || - (argv[num_opts][1] =3D=3D 'd'))) - num_opts++; - } - else - break; - - /* Check for options. */ - while (1) + switch (key) { - int c =3D getopt_long (num_opts, argv, "r:s:n:c:d:hVv", options, 0= ); - char *p; - - if (c =3D=3D -1) - break; - else - switch (c) - { - case 'r': - root =3D optarg; - break; - - case 's': - skip =3D grub_strtoul (optarg, &p, 0); - if (*p =3D=3D 's') - skip <<=3D GRUB_DISK_SECTOR_BITS; - break; - - case 'n': - leng =3D grub_strtoul (optarg, &p, 0); - if (*p =3D=3D 's') - leng <<=3D GRUB_DISK_SECTOR_BITS; - break; - - case 'c': - num_disks =3D grub_strtoul (optarg, NULL, 0); - if (num_disks < 1) - { - fprintf (stderr, "Invalid disk count.\n"); - usage (1); - } - break; - - case 'd': - debug_str =3D optarg; - break; + case 'r': + root =3D arg; + return 0; + + case 's': + skip =3D grub_strtoul (arg, &p, 0); + if (*p =3D=3D 's') + skip <<=3D GRUB_DISK_SECTOR_BITS; + return 0; + + case 'n': + leng =3D grub_strtoul (arg, &p, 0); + if (*p =3D=3D 's') + leng <<=3D GRUB_DISK_SECTOR_BITS; + return 0; + + case 'c': + num_disks =3D grub_strtoul (arg, NULL, 0); + if (num_disks < 1) + { + fprintf (stderr, "Invalid disk count.\n"); + argp_usage (state); + } + if (args_count !=3D 0) + { + fprintf (stderr, "Disk count must precede disks list.\n"); + argp_usage (state); + } + return 0; =20 - case 'h': - usage (0); - break; + case 'd': + debug_str =3D arg; + return 0; + + case 'v': + verbosity++; + return 0; =20 - case 'V': - printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION= ); - return 0; + case ARGP_KEY_END: + if (args_count < num_disks) + { + fprintf (stderr, "No command is specified.\n"); + argp_usage (state); + } + if (args_count - 1 - num_disks < nparm) + { + fprintf (stderr, "Not enough parameters to command.\n"); + argp_usage (state); + } + return 0; =20 - case 'v': - verbosity++; - break; + case ARGP_KEY_ARG: + break; =20 - default: - usage (1); - break; - } + default: + return ARGP_ERR_UNKNOWN; } =20 - /* Obtain PATH. */ - if (optind + num_disks - 1 >=3D argc) + if (args_count < num_disks) { - fprintf (stderr, "Not enough pathname.\n"); - usage (1); + if (arg[0] !=3D '/') + { + fprintf (stderr, "Must use absolute path.\n"); + argp_usage (state); + } + if (args_count =3D=3D 0) + images =3D xmalloc (num_disks * sizeof (images[0])); + images[args_count] =3D xstrdup (arg); + args_count++; + return 0; } =20 - image_index =3D optind; - for (i =3D 0; i < num_disks; i++, optind++) - if (argv[optind][0] !=3D '/') - { - fprintf (stderr, "Must use absolute path.\n"); - usage (1); - } - - cmd =3D 0; - if (optind < argc) + if (args_count =3D=3D num_disks) { - int nparm =3D 0; - - if (!grub_strcmp (argv[optind], "ls")) + if (!grub_strcmp (arg, "ls")) { cmd =3D CMD_LS; } - else if (!grub_strcmp (argv[optind], "cp")) + else if (!grub_strcmp (arg, "cp")) { cmd =3D CMD_CP; nparm =3D 2; } - else if (!grub_strcmp (argv[optind], "cmp")) + else if (!grub_strcmp (arg, "cmp")) { cmd =3D CMD_CMP; nparm =3D 2; } - else if (!grub_strcmp (argv[optind], "hex")) + else if (!grub_strcmp (arg, "hex")) { cmd =3D CMD_HEX; nparm =3D 1; } - else if (!grub_strcmp (argv[optind], "crc")) + else if (!grub_strcmp (arg, "crc")) { cmd =3D CMD_CRC; nparm =3D 1; } - else if (!grub_strcmp (argv[optind], "blocklist")) + else if (!grub_strcmp (arg, "blocklist")) { cmd =3D CMD_BLOCKLIST; nparm =3D 1; } else { - fprintf (stderr, "Invalid command %s.\n", argv[optind]); - usage (1); + fprintf (stderr, "Invalid command %s.\n", arg); + argp_usage (state); } + args_count++; + return 0; + } =20 - if (optind + 1 + nparm > argc) - { - fprintf (stderr, "Invalid parameter for command %s.\n", - argv[optind]); - usage (1); - } + args[args_count - 1 - num_disks] =3D xstrdup (arg); + args_count++; + return 0; +} =20 - optind++; - } - else - { - fprintf (stderr, "No command is specified.\n"); - usage (1); - } +struct argp argp =3D { + options, argp_parser, "IMAGE_PATH COMMANDS", + "Debug tool for filesystem driver.",=20 + NULL, NULL, NULL +}; + +int +main (int argc, char *argv[]) +{ + char *default_root, *alloc_root; + + set_program_name (argv[0]); + + grub_util_init_nls (); + + args =3D xmalloc (argc * sizeof (args[0])); + + argp_parse (&argp, argc, argv, 0, 0, 0); =20 /* Initialize all modules. */ grub_init_all (); @@ -574,7 +547,7 @@ main (int argc, char *argv[]) free (alloc_root); =20 /* Do it. */ - fstest (argv + image_index, num_disks, cmd, argc - optind, argv + opti= nd); + fstest (args_count - 1 - num_disks, args); =20 /* Free resources. */ grub_fini_all (); --------------080306090603080704030303-- --------------enig35ADC28928DB33873B1600F0 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iF4EAREKAAYFAku2dFAACgkQNak7dOguQgkoTwEArqmP3BrIZlZf8DMAQMyrPX/2 +SL2KTYxruOkZUMwvHgBAKi04ufO92Sa6mw4EqQqxphXt5bWG5H6ac3Zsh0wUC/Y =xuCV -----END PGP SIGNATURE----- --------------enig35ADC28928DB33873B1600F0--