Commit 12b99ca6 authored by Sandrine Bailleux's avatar Sandrine Bailleux Committed by Dan Handley
Browse files

FIP tool: Small optimisation for option parsing

This patch makes use of different values for '--dump' and other
command-line options. This makes the code simpler and also
optimises it a bit (because it avoids a string comparison).

Change-Id: I1c8345f210074fc5f962ea0282fd3625775dec69
parent 82a0aca0
...@@ -38,6 +38,10 @@ ...@@ -38,6 +38,10 @@
#include "fip_create.h" #include "fip_create.h"
#include "firmware_image_package.h" #include "firmware_image_package.h"
/* Values returned by getopt() as part of the command line parsing */
#define OPT_TOC_ENTRY 0
#define OPT_DUMP 1
file_info files[MAX_FILES]; file_info files[MAX_FILES];
unsigned file_info_count = 0; unsigned file_info_count = 0;
uuid_t uuid_null = {0}; uuid_t uuid_null = {0};
...@@ -532,13 +536,7 @@ static int parse_cmdline(int argc, char **argv, struct option *options, ...@@ -532,13 +536,7 @@ static int parse_cmdline(int argc, char **argv, struct option *options,
break; break;
switch (c) { switch (c) {
case 0: case OPT_TOC_ENTRY:
/* if this is --dump, set action and continue */
if (strcmp(options[option_index].name, "dump") == 0) {
do_dump = 1;
continue;
}
if (optarg) { if (optarg) {
/* Does the option expect a filename. */ /* Does the option expect a filename. */
lookup_entry = &toc_entry_lookup_list[option_index]; lookup_entry = &toc_entry_lookup_list[option_index];
...@@ -555,6 +553,11 @@ static int parse_cmdline(int argc, char **argv, struct option *options, ...@@ -555,6 +553,11 @@ static int parse_cmdline(int argc, char **argv, struct option *options,
} }
} }
break; break;
case OPT_DUMP:
do_dump = 1;
continue;
default: default:
/* Unrecognised options are caught in get_filename() */ /* Unrecognised options are caught in get_filename() */
break; break;
...@@ -596,14 +599,14 @@ int main(int argc, char **argv) ...@@ -596,14 +599,14 @@ int main(int argc, char **argv)
/* The only flag defined at the moment is for a FILENAME */ /* The only flag defined at the moment is for a FILENAME */
long_options[i].has_arg = toc_entry_lookup_list[i].flags ? 1 : 0; long_options[i].has_arg = toc_entry_lookup_list[i].flags ? 1 : 0;
long_options[i].flag = 0; long_options[i].flag = 0;
long_options[i].val = 0; long_options[i].val = OPT_TOC_ENTRY;
} }
/* Add '--dump' option */ /* Add '--dump' option */
long_options[i].name = "dump"; long_options[i].name = "dump";
long_options[i].has_arg = 0; long_options[i].has_arg = 0;
long_options[i].flag = 0; long_options[i].flag = 0;
long_options[i].val = 0; long_options[i].val = OPT_DUMP;
/* Zero the last entry (required) */ /* Zero the last entry (required) */
long_options[++i].name = 0; long_options[++i].name = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment