summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools
diff options
context:
space:
mode:
author Fabrice Bellet <fabrice@bellet.info>2018-06-27 08:15:39 +0200
committer Vas Crabb <cuavas@users.noreply.github.com>2018-07-22 21:25:59 +1000
commit0d8ca95a1b5942b0c56744edfed3f74515418750 (patch)
tree111ad1dcf9d95c5c938b2822b9c069241ca39f98 /src/tools
parentc0ab1c5aa4c172aa9e3e0deec5c2cc19d4f278d1 (diff)
imgtool: fix parsing options with enum values
When parsing an enumerated option, we should use the parameter of the enumerated value, as an integer, instead of the raw identifier as a string. The behaviour probably changed around commit b60879e595, but modules still expect the old behaviour.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/imgtool/main.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/tools/imgtool/main.cpp b/src/tools/imgtool/main.cpp
index 50c65845ddb..5c55535932e 100644
--- a/src/tools/imgtool/main.cpp
+++ b/src/tools/imgtool/main.cpp
@@ -106,7 +106,23 @@ static int parse_options(int argc, char *argv[], int minunnamed, int maxunnamed,
if (i < minunnamed)
goto error; /* Too few unnamed */
- resolution->find(name)->set_value(value);
+ util::option_resolution::entry *entry = resolution->find(name);
+ if (entry->option_type() == util::option_guide::entry::option_type::ENUM_BEGIN)
+ {
+ const util::option_guide::entry *enum_value;
+ for (enum_value = entry->enum_value_begin(); enum_value != entry->enum_value_end(); enum_value++)
+ {
+ if (!strcmp (enum_value->identifier(), value))
+ {
+ entry->set_value(enum_value->parameter());
+ break;
+ }
+ }
+ if (enum_value == entry->enum_value_end())
+ goto error;
+ }
+ else
+ entry->set_value(value);
}
}
}