diff options
| -rw-r--r-- | dome_key_map.h | 1 | ||||
| -rw-r--r-- | src/cocoa_bridge.rs | 5 | ||||
| -rw-r--r-- | src/config.rs | 37 | ||||
| -rw-r--r-- | src/lib.rs | 4 |
4 files changed, 39 insertions, 8 deletions
diff --git a/dome_key_map.h b/dome_key_map.h index 88909f0..af7a102 100644 --- a/dome_key_map.h +++ b/dome_key_map.h @@ -24,6 +24,7 @@ typedef struct State State; typedef struct { bool reload; bool daemon; + char *license; } Args; typedef uint16_t Milliseconds; diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 7b707de..cd1dafa 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -346,7 +346,10 @@ pub extern "C" fn config_get() -> *mut Config { #[no_mangle] pub extern "C" fn config_free(ptr: *mut Config) { if ptr.is_null() { return } - unsafe { Box::from_raw(ptr); } + let config = unsafe { Box::from_raw(ptr) }; + + if config.args.license.is_null() { return } + unsafe { CString::from_raw(config.args.license); } } diff --git a/src/config.rs b/src/config.rs index feaf578..b4cab10 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,18 +1,32 @@ +use std::ffi::CString; use std::fs; +use std::ptr; +use libc::c_char; use getopts::Options; use toml; use xdg; use errors::*; +use prefix_println; type Milliseconds = u16; #[repr(C)] -#[derive(Default)] -struct Args { - reload: bool, - daemon: bool, +pub struct Args { + pub reload: bool, + pub daemon: bool, + pub license: *mut c_char, +} + +impl Default for Args { + fn default() -> Self { + Args { + reload: false, + daemon: false, + license: ptr::null_mut(), + } + } } #[repr(C)] @@ -20,8 +34,8 @@ struct Args { #[serde(default)] pub struct Config { #[serde(skip)] - args: Args, - timeout: Milliseconds, + pub args: Args, + pub timeout: Milliseconds, } impl Default for Config { @@ -43,6 +57,12 @@ pub fn parse_args<'a>(args: &[String], config: &'a mut Config) -> &'a mut Config opts.optflag("d", "daemon", "run the daemon in the current shell"); opts.optflag("r", "reload-mappings", "reload the mappings file"); + opts.optopt( + "", + "license", + "register the software using a license plist file", + "FILE" + ); opts.optflag("h", "help", "print this help menu"); let matches = match opts.parse(&args[1..]) { @@ -59,6 +79,11 @@ pub fn parse_args<'a>(args: &[String], config: &'a mut Config) -> &'a mut Config config.args.reload = true; } else if matches.opt_present("d") { config.args.daemon = true; + } else if let Some(license_path) = matches.opt_str("license") { + match CString::new(license_path) { + Ok(str) => config.args.license = str.into_raw(), + Err(e) => dkeprintln!("{}", e), + } } else { print_usage(opts); } @@ -31,13 +31,15 @@ extern crate stderrlog; extern crate toml; extern crate xdg; +#[macro_use] +mod prefix_println; + mod autopilot_internal; mod cocoa_bridge; mod config; mod errors; mod key_code; mod parser; -mod prefix_println; mod trial; use parser::{Action, HeadphoneButton, MapAction, MapGroup, MapKind}; |
