From e7a8130a38fa741bc3aef98053e8f044385e9052 Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Tue, 31 Aug 2021 15:03:18 +0200 Subject: tools: ipc-modem: small code cleanups for the command line interface The help and the code is sorted alphabetically. It should contain no functional changes. Signed-off-by: Denis 'GNUtoo' Carikli --- tools/ipc-modem.c | 60 +++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/tools/ipc-modem.c b/tools/ipc-modem.c index cc53749..db51177 100644 --- a/tools/ipc-modem.c +++ b/tools/ipc-modem.c @@ -469,14 +469,14 @@ void print_help(void) { printf("usage: ipc-modem \n"); printf("commands:\n"); - printf("\tstart boot modem and start read loop\n"); printf("\tboot boot modem only\n"); - printf("\tpower-on power on the modem\n"); - printf("\tpower-off power off the modem\n"); + printf("\tpower-on power on the modem only\n"); + printf("\tpower-off power off the modem only\n"); + printf("\tstart boot modem and start read loop\n"); printf("arguments:\n"); + printf("\t--call=[NUMBER] call NUMBER\n"); printf("\t--debug enable debug messages\n"); printf("\t--pin=[PIN] provide SIM card PIN\n"); - printf("\t--call=[NUMBER] call NUMBER\n"); } int main(int argc, char *argv[]) @@ -488,10 +488,10 @@ int main(int argc, char *argv[]) int debug = 0; struct option opt_l[] = { - {"help", no_argument, 0, 0 }, + {"call", required_argument, 0, 0 }, {"debug", no_argument, 0, 0 }, + {"help", no_argument, 0, 0 }, {"pin", required_argument, 0, 0 }, - {"call", required_argument, 0, 0 }, {0, 0, 0, 0 } }; @@ -507,12 +507,27 @@ int main(int argc, char *argv[]) switch (c) { case 0: - if (strncmp(opt_l[opt_i].name, "help", 4) == 0) { - print_help(); - exit(1); + if (strcmp(opt_l[opt_i].name, "call") == 0) { + if (optarg) { + if (strlen(optarg) < 14) { + assert(strlen(optarg) < + sizeof(call_number)); + printf("[I] " + "Got call number!\n"); + strcpy(call_number, optarg); + } else { + printf("[E] " + "Call number is too long!" + "\n"); + return 1; + } + } } else if (strcmp(opt_l[opt_i].name, "debug") == 0) { debug = 1; printf("[I] Debug enabled\n"); + } else if (strncmp(opt_l[opt_i].name, "help", 4) == 0) { + print_help(); + exit(1); } else if ((strcmp(opt_l[opt_i].name, "pin") == 0) && (optarg)) { if (strlen(optarg) < 8) { @@ -525,21 +540,6 @@ int main(int argc, char *argv[]) printf("[E] SIM PIN is too long!\n"); return 1; } - } else if (strcmp(opt_l[opt_i].name, "call") == 0) { - if (optarg) { - if (strlen(optarg) < 14) { - assert(strlen(optarg) < - sizeof(call_number)); - printf("[I] " - "Got call number!\n"); - strcpy(call_number, optarg); - } else { - printf("[E] " - "Call number is too long!" - "\n"); - return 1; - } - } } break; @@ -562,7 +562,12 @@ int main(int argc, char *argv[]) } while (optind < argc) { - if (strncmp(argv[optind], "power-on", 8) == 0) { + if (strncmp(argv[optind], "boot", 9) == 0) { + rc = ipc_client_boot(client_fmt); + if (rc < 0) + printf("[E] Something went wrong " + "while bootstrapping modem\n"); + } else if (strncmp(argv[optind], "power-on", 8) == 0) { if (ipc_client_power_on(client_fmt) < 0) printf("[E] Something went wrong " "while powering modem on\n"); @@ -572,11 +577,6 @@ int main(int argc, char *argv[]) printf("[E] Something went wrong " "while powering modem off\n"); goto modem_quit; - } else if (strncmp(argv[optind], "boot", 9) == 0) { - rc = ipc_client_boot(client_fmt); - if (rc < 0) - printf("[E] Something went wrong " - "while bootstrapping modem\n"); } else if (strncmp(argv[optind], "start", 5) == 0) { printf("[0] Starting modem on FMT client\n"); rc = modem_start(client_fmt); -- cgit v1.2.3