From ee53e69bab842a0d6d34d50a85715356008c8581 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Sun, 21 Nov 2010 18:37:54 +0000 Subject: [PATCH] [digest] Use generic option-parsing library Total saving: 68 bytes. Signed-off-by: Michael Brown --- src/hci/commands/digest_cmd.c | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/hci/commands/digest_cmd.c b/src/hci/commands/digest_cmd.c index e28e6c3b..99c196a1 100644 --- a/src/hci/commands/digest_cmd.c +++ b/src/hci/commands/digest_cmd.c @@ -19,25 +19,31 @@ #include #include #include +#include #include +#include #include #include - #include #include -/** - * "digest" command syntax message +/** @file + * + * Digest commands * - * @v argv Argument list */ -static void digest_syntax ( char **argv ) { - printf ( "Usage:\n" - " %s \n" - "\n" - "Calculate the %s of an image\n", - argv[0], argv[0] ); -} + +/** "digest" options */ +struct digest_options {}; + +/** "digest" option list */ +static struct option_descriptor digest_opts[] = {}; + +/** "digest" command descriptor */ +static struct command_descriptor digest_cmd = + COMMAND_DESC ( struct digest_options, digest_opts, 1, MAX_ARGUMENTS, + " [...]", + "Calculate the digest of an image" ); /** * The "digest" command @@ -45,11 +51,11 @@ static void digest_syntax ( char **argv ) { * @v argc Argument count * @v argv Argument list * @v digest Digest algorithm - * @ret rc Exit code + * @ret rc Return status code */ static int digest_exec ( int argc, char **argv, struct digest_algorithm *digest ) { - const char *image_name; + struct digest_options opts; struct image *image; uint8_t digest_ctx[digest->ctxsize]; uint8_t digest_out[digest->digestsize]; @@ -59,23 +65,17 @@ static int digest_exec ( int argc, char **argv, size_t frag_len; int i; unsigned j; + int rc; - if ( argc < 2 || - !strcmp ( argv[1], "--help" ) || - !strcmp ( argv[1], "-h" ) ) { - digest_syntax ( argv ); - return 1; - } + /* Parse options */ + if ( ( rc = parse_options ( argc, argv, &digest_cmd, &opts ) ) != 0 ) + return rc; - for ( i = 1 ; i < argc ; i++ ) { - image_name = argv[i]; + for ( i = optind ; i < argc ; i++ ) { /* find image */ - image = find_image ( image_name ); - if ( ! image ) { - printf ( "No such image: %s\n", image_name ); + if ( ( rc = parse_image ( argv[i], &image ) ) != 0 ) continue; - } offset = 0; len = image->len;