From 9e78ccb4e7505a6cdc4232a3875b4373bb922537 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 27 Jan 2017 16:06:01 -0700 Subject: [PATCH] Correct argument parsing logic --- host/hackrf-tools/src/hackrf_spiflash.c | 24 ++++++++++++------------ host/hackrf-tools/src/hackrf_transfer.c | 4 ++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_spiflash.c b/host/hackrf-tools/src/hackrf_spiflash.c index bb5c53bb..3304b5b3 100644 --- a/host/hackrf-tools/src/hackrf_spiflash.c +++ b/host/hackrf-tools/src/hackrf_spiflash.c @@ -148,8 +148,12 @@ int main(int argc, char** argv) reset = true; break; + case '?': + usage(); + return EXIT_FAILURE; + default: - fprintf(stderr, "opt error: %d\n", opt); + fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); usage(); return EXIT_FAILURE; } @@ -162,28 +166,24 @@ int main(int argc, char** argv) } } - if((write == read) && (write == reset)) { - if(write && read) { - fprintf(stderr, "Read and write options are mutually exclusive.\n"); - } else { - fprintf(stderr, "Specify either read, write, or reset option.\n"); - } + if(write && read) { + fprintf(stderr, "Read and write options are mutually exclusive.\n"); usage(); return EXIT_FAILURE; } - - if((read || write) && (path == NULL)) { - fprintf(stderr, "Specify a path to a file.\n"); + + if(!(write || read || reset)) { + fprintf(stderr, "Specify either read, write, or reset option.\n"); usage(); return EXIT_FAILURE; - } + } if( write ) { fd = fopen(path, "rb"); if(fd == NULL) { - printf("Error to open file %s\n", path); + printf("Error opening file %s\n", path); return EXIT_FAILURE; } /* Get size of the file */ diff --git a/host/hackrf-tools/src/hackrf_transfer.c b/host/hackrf-tools/src/hackrf_transfer.c index 8ee5142a..a36166c6 100644 --- a/host/hackrf-tools/src/hackrf_transfer.c +++ b/host/hackrf-tools/src/hackrf_transfer.c @@ -673,6 +673,10 @@ int main(int argc, char** argv) { result = parse_u32(optarg, &crystal_correct_ppm); break; + case '?': + usage(); + return EXIT_FAILURE; + default: fprintf(stderr, "unknown argument '-%c %s'\n", opt, optarg); usage();