From d41d257650dc8f4b7745b886851382d775bea1d9 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sat, 27 Feb 2021 23:50:31 -0800 Subject: [PATCH] More options logic --- main.c | 2 +- src/lib.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 4ebc5cf..23ea098 100644 --- a/main.c +++ b/main.c @@ -80,11 +80,11 @@ int old_c_main(int argc, char **argv) radio_list(); exit(0); } - */ if (read_flag + write_flag + config_flag + csv_flag + verify_flag > 1) { fprintf(stderr, "Only one of -r, -w, -c, -v or -u options is allowed.\n"); usage(); } + */ setvbuf(stdout, 0, _IOLBF, 0); setvbuf(stderr, 0, _IOLBF, 0); diff --git a/src/lib.rs b/src/lib.rs index 164830c..b7e7511 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,11 +72,23 @@ pub extern "C" fn rust_main(argc: c_int, argv: *const *const c_char) -> c_int { }; let list_flag = matches.opt_present("l"); + let verify_flag = matches.opt_present("v"); + let read_flag = matches.opt_present("r"); + let write_flag = matches.opt_present("w"); + let config_flag = matches.opt_present("c"); + let csv_flag = matches.opt_present("u"); + if list_flag { radio::list(); exit(0); } + if [read_flag, write_flag, config_flag, csv_flag, verify_flag].iter().filter(|x| **x).count() > 1 { + eprintln!("Only one of -r, -w, -c, -v or -u options is allowed."); + exit(-1); + //print_usage(); + } + unsafe { old_c_main(argc, argv) }