More options logic

This commit is contained in:
Greg Shuflin 2021-02-27 23:50:31 -08:00
parent 1c81834b62
commit d41d257650
2 changed files with 13 additions and 1 deletions

2
main.c
View File

@ -80,11 +80,11 @@ int old_c_main(int argc, char **argv)
radio_list(); radio_list();
exit(0); exit(0);
} }
*/
if (read_flag + write_flag + config_flag + csv_flag + verify_flag > 1) { 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"); fprintf(stderr, "Only one of -r, -w, -c, -v or -u options is allowed.\n");
usage(); usage();
} }
*/
setvbuf(stdout, 0, _IOLBF, 0); setvbuf(stdout, 0, _IOLBF, 0);
setvbuf(stderr, 0, _IOLBF, 0); setvbuf(stderr, 0, _IOLBF, 0);

View File

@ -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 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 { if list_flag {
radio::list(); radio::list();
exit(0); 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 { unsafe {
old_c_main(argc, argv) old_c_main(argc, argv)
} }