diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2022-02-08 18:39:23 +0100 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2022-03-28 20:50:40 +0200 |
commit | 106f844167942b303913edd4fe69d8ed3f708fd7 (patch) | |
tree | 4250f7583bdecb11a98d9e49e1410bc31111ff15 /tools | |
parent | f13b77fa3578abfac9f15e204a8237c3d27794bf (diff) | |
download | hardware_replicant_libsamsung-ipc-106f844167942b303913edd4fe69d8ed3f708fd7.tar.gz hardware_replicant_libsamsung-ipc-106f844167942b303913edd4fe69d8ed3f708fd7.tar.bz2 hardware_replicant_libsamsung-ipc-106f844167942b303913edd4fe69d8ed3f708fd7.zip |
tools: ipc-modem: getopt_long: shorten nested ifs
This makes the code more readable. It should contain no functional
changes.
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/ipc-modem.c | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/tools/ipc-modem.c b/tools/ipc-modem.c index 7acd6eb..1fbc778 100644 --- a/tools/ipc-modem.c +++ b/tools/ipc-modem.c @@ -626,50 +626,43 @@ int main(int argc, char *argv[]) exit(1); } - while (c >= 0) { + while (true) { c = getopt_long(argc, argv, "", opt_l, &opt_i); - if (c < 0) + if (c != 0) break; - switch (c) { - case 0: - 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) { - cmdline_opts.debug = true; - } else if (strcmp(opt_l[opt_i].name, "dry-run") == 0) { - cmdline_opts.dry_run = true; - } 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) { + if (strcmp(opt_l[opt_i].name, "call") == 0) { + if (optarg) { + if (strlen(optarg) < 14) { assert(strlen(optarg) < - sizeof(sim_pin)); - - printf("[I] Got SIM PIN!\n"); - strcpy(sim_pin, optarg); + sizeof(call_number)); + printf("[I] Got call number!\n"); + strcpy(call_number, optarg); } else { - printf("[E] SIM PIN is too long!\n"); + printf("[E] " + "Call number is too long!\n"); return 1; } } - - break; + } else if (strcmp(opt_l[opt_i].name, "debug") == 0) { + cmdline_opts.debug = true; + } else if (strcmp(opt_l[opt_i].name, "dry-run") == 0) { + cmdline_opts.dry_run = true; + } 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) { + assert(strlen(optarg) < + sizeof(sim_pin)); + + printf("[I] Got SIM PIN!\n"); + strcpy(sim_pin, optarg); + } else { + printf("[E] SIM PIN is too long!\n"); + return 1; + } } } |