summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brown2010-11-21 19:37:54 +0100
committerMichael Brown2010-11-22 00:37:56 +0100
commitee53e69bab842a0d6d34d50a85715356008c8581 (patch)
tree2b25b3861ebb68fef3a8739dd108ee668280a541
parent[dhcp] Use generic option-parsing library (diff)
downloadipxe-ee53e69bab842a0d6d34d50a85715356008c8581.tar.gz
ipxe-ee53e69bab842a0d6d34d50a85715356008c8581.tar.xz
ipxe-ee53e69bab842a0d6d34d50a85715356008c8581.zip
[digest] Use generic option-parsing library
Total saving: 68 bytes. Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/hci/commands/digest_cmd.c50
1 files 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 <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <getopt.h>
#include <ipxe/command.h>
+#include <ipxe/parseopt.h>
#include <ipxe/image.h>
#include <ipxe/crypto.h>
-
#include <ipxe/md5.h>
#include <ipxe/sha1.h>
-/**
- * "digest" command syntax message
+/** @file
+ *
+ * Digest commands
*
- * @v argv Argument list
*/
-static void digest_syntax ( char **argv ) {
- printf ( "Usage:\n"
- " %s <image name>\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,
+ "<image> [<image>...]",
+ "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;