mirror of https://github.com/ipxe/ipxe.git
[digest] Use generic option-parsing library
Total saving: 68 bytes. Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/1/head
parent
07c6b79102
commit
ee53e69bab
|
@ -19,25 +19,31 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include <ipxe/command.h>
|
#include <ipxe/command.h>
|
||||||
|
#include <ipxe/parseopt.h>
|
||||||
#include <ipxe/image.h>
|
#include <ipxe/image.h>
|
||||||
#include <ipxe/crypto.h>
|
#include <ipxe/crypto.h>
|
||||||
|
|
||||||
#include <ipxe/md5.h>
|
#include <ipxe/md5.h>
|
||||||
#include <ipxe/sha1.h>
|
#include <ipxe/sha1.h>
|
||||||
|
|
||||||
/**
|
/** @file
|
||||||
* "digest" command syntax message
|
*
|
||||||
|
* Digest commands
|
||||||
*
|
*
|
||||||
* @v argv Argument list
|
|
||||||
*/
|
*/
|
||||||
static void digest_syntax ( char **argv ) {
|
|
||||||
printf ( "Usage:\n"
|
/** "digest" options */
|
||||||
" %s <image name>\n"
|
struct digest_options {};
|
||||||
"\n"
|
|
||||||
"Calculate the %s of an image\n",
|
/** "digest" option list */
|
||||||
argv[0], argv[0] );
|
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
|
* The "digest" command
|
||||||
|
@ -45,11 +51,11 @@ static void digest_syntax ( char **argv ) {
|
||||||
* @v argc Argument count
|
* @v argc Argument count
|
||||||
* @v argv Argument list
|
* @v argv Argument list
|
||||||
* @v digest Digest algorithm
|
* @v digest Digest algorithm
|
||||||
* @ret rc Exit code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
static int digest_exec ( int argc, char **argv,
|
static int digest_exec ( int argc, char **argv,
|
||||||
struct digest_algorithm *digest ) {
|
struct digest_algorithm *digest ) {
|
||||||
const char *image_name;
|
struct digest_options opts;
|
||||||
struct image *image;
|
struct image *image;
|
||||||
uint8_t digest_ctx[digest->ctxsize];
|
uint8_t digest_ctx[digest->ctxsize];
|
||||||
uint8_t digest_out[digest->digestsize];
|
uint8_t digest_out[digest->digestsize];
|
||||||
|
@ -59,23 +65,17 @@ static int digest_exec ( int argc, char **argv,
|
||||||
size_t frag_len;
|
size_t frag_len;
|
||||||
int i;
|
int i;
|
||||||
unsigned j;
|
unsigned j;
|
||||||
|
int rc;
|
||||||
|
|
||||||
if ( argc < 2 ||
|
/* Parse options */
|
||||||
!strcmp ( argv[1], "--help" ) ||
|
if ( ( rc = parse_options ( argc, argv, &digest_cmd, &opts ) ) != 0 )
|
||||||
!strcmp ( argv[1], "-h" ) ) {
|
return rc;
|
||||||
digest_syntax ( argv );
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( i = 1 ; i < argc ; i++ ) {
|
for ( i = optind ; i < argc ; i++ ) {
|
||||||
image_name = argv[i];
|
|
||||||
|
|
||||||
/* find image */
|
/* find image */
|
||||||
image = find_image ( image_name );
|
if ( ( rc = parse_image ( argv[i], &image ) ) != 0 )
|
||||||
if ( ! image ) {
|
|
||||||
printf ( "No such image: %s\n", image_name );
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
offset = 0;
|
offset = 0;
|
||||||
len = image->len;
|
len = image->len;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue