From 2a91efd07f5f990a5f6a2339e9e5234c14a806dd Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sat, 27 Feb 2021 22:52:27 -0800 Subject: [PATCH] Start adding Rust getopts --- Cargo.toml | 1 + main.c | 2 +- src/lib.rs | 17 ++++++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5cb38e5..d809cba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,3 +11,4 @@ crate-type = ["staticlib"] [dependencies] libc = "0.2" +getopts = "0.2" diff --git a/main.c b/main.c index 1cbd57c..088050a 100644 --- a/main.c +++ b/main.c @@ -59,7 +59,7 @@ int main(int argc, char **argv) case 'c': ++config_flag; continue; case 'u': ++csv_flag; continue; case 'l': ++list_flag; continue; - case 'v': ++verify_flag; continue; + case 'v': ++verify_flag; continue; default: usage(); case EOF: diff --git a/src/lib.rs b/src/lib.rs index 52f3ce9..8bdacad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ pub extern "C" fn print_usage(version_ptr: *const c_char) { let msg = r#" Usage: - dmrconfig -r [-t]\n + dmrconfig -r [-t] Read codeplug from the radio to a file 'device.img'. Save configuration to a text file 'device.conf'. dmrconfig -w [-t] file.img @@ -39,6 +39,21 @@ Options: std::process::exit(-1); } +#[no_mangle] +pub extern "C" fn process_options() { + use getopts::Options; + + let mut opts = Options::new(); + opts.optflag("t", "", "Trace USB protocol."); + opts.optflag("r", "", "Read codeplug from the radio to a file 'device.img'.\nSave configuration to a text file 'device.conf'."); + opts.optflag("w", "", "Write codeplug to the radio."); + opts.optflag("c", "", "Verify configuration script for the radio."); + opts.optflag("u", "", "Update contacts database from CSV file."); + opts.optflag("l", "", "List all supported radios."); + opts.optflag("v", "", "Verify configuration script for the radio."); + +} + #[cfg(test)] mod tests { #[test]