aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-02-11 10:14:56 +0100
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-02-13 13:56:33 +0100
commit89bd4a5d1e07e63f9f0f72c02dab81329454b26e (patch)
tree7fa449f7863e45cebb30127749b7b7a6daef156d
parentde18ddf49a27a98b1b5b999a80946b10ea3e0843 (diff)
downloadhardware_replicant_libsamsung-ipc-89bd4a5d1e07e63f9f0f72c02dab81329454b26e.tar.gz
hardware_replicant_libsamsung-ipc-89bd4a5d1e07e63f9f0f72c02dab81329454b26e.tar.bz2
hardware_replicant_libsamsung-ipc-89bd4a5d1e07e63f9f0f72c02dab81329454b26e.zip
tools: nv_data-imei: handle list-supported in a more generic way
Before that, the command infrastructure wasn't used for list-supported which led to more manual parsing and more code. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--tools/nv_data-imei.c96
1 files changed, 48 insertions, 48 deletions
diff --git a/tools/nv_data-imei.c b/tools/nv_data-imei.c
index 64ce3f5..2c04079 100644
--- a/tools/nv_data-imei.c
+++ b/tools/nv_data-imei.c
@@ -66,6 +66,24 @@ static int print_imei(struct imei *imei)
}
#endif /* DEBUG */
+static int list_supported(void)
+{
+ /* TODO:
+ * - Print the result in a parsable format (json?)
+ * - Print the result in and a human format (a table for instance)
+ * - Add IMEI location (under the battery, unknown, etc)
+ * - Add IMEI known offsets
+ */
+ printf("Supported devices:\n");
+
+ /* Offset: 0xE80, other?
+ * Location: Under the battery
+ */
+ printf("\tNexus S (GT-I902x)\n");
+
+ return 0;
+}
+
static int get_offset(struct command *command, void *arg)
{
struct offset *offset = arg;
@@ -233,7 +251,7 @@ static struct command commands[] = {
"Display supported devices and EFS",
NO_OPTIONS,
NO_OPTIONS,
- NULL,
+ list_supported,
},
{
"read-imei",
@@ -508,24 +526,6 @@ static int command_help(const char *command_name)
return 0;
}
-static int list_supported(void)
-{
- /* TODO:
- * - Print the result in a parsable format (json?)
- * - Print the result in and a human format (a table for instance)
- * - Add IMEI location (under the battery, unknown, etc)
- * - Add IMEI known offsets
- */
- printf("Supported devices:\n");
-
- /* Offset: 0xE80, other?
- * Location: Under the battery
- */
- printf("\tNexus S (GT-I902x)\n");
-
- return 0;
-}
-
static void modem_log_handler(__attribute__((unused)) void *user_data,
const char *msg)
{
@@ -880,14 +880,35 @@ int main(int argc, char * const argv[])
* two.)
*/
- /* nv_data-imei list-supported */
- if (optind == 2 && argc == 2 &&
- strlen("list-supported") ==
- strlen(argv[optind - 1]) &&
- !strncmp("list-supported", argv[optind - 1],
- strlen("list-supported"))) {
- printf("nv_data-imei list-supported\n");
- return list_supported();
+ /* nv_data-imei <argument> */
+ if (optind == 2 && argc == 2) {
+ command = get_command(argv[optind - 1]);
+ /* Example: nv_data-imei list-supported */
+ if (command && command->options == NO_OPTIONS) {
+ rc = command->func();
+ return errno_to_sysexit(rc);
+ } else if (command) {
+ /* The other commands than
+ * list-supported need at least a file
+ * argument so we don't need to handle
+ * all missing options
+ */
+ if (command->options & OPTION_FILE) {
+ printf("Error: the '%s' command "
+ "needs a FILE argument.\n",
+ argv[optind - 1]);
+ printf("See 'nv_data-imei %s -h'"
+ " for more details.\n",
+ argv[optind - 1]);
+ }
+ return EX_USAGE;
+ } else {
+ printf("There is no '%s' command\n",
+ argv[optind - 1]);
+ printf("Try nv_data-imei -h"
+ " to print the help.\n");
+ return EX_USAGE;
+ }
/* nv_data-imei FILE COMMAND [...] */
} else if (optind == 3 && argc >= 3) {
nv_data_path = argv[optind - 2];
@@ -915,27 +936,6 @@ int main(int argc, char * const argv[])
argv[optind - 1]);
return EX_USAGE;
}
- /* nv_data-imei <INVALID_COMMAND> */
- } else if (optind == 2 && argc == 2) {
- command = get_command(argv[optind - 1]);
-
- if (!command) {
- printf("There is no '%s' command\n",
- argv[optind - 1]);
- printf("Try nv_data-imei -h"
- " to print the help.\n");
- } else if (command->options & OPTION_FILE) {
- printf("Error: the '%s' command "
- "needs a FILE argument.\n",
- argv[optind - 1]);
- printf("See 'nv_data-imei %s -h'"
- " for more details.\n",
- argv[optind - 1]);
- } else {
- assert(false);
- }
- return EX_USAGE;
-
}
break;
case 'h':