diff options
| author | Teddy Wing | 2018-10-05 19:16:23 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-10-05 19:16:23 +0200 |
| commit | 961b3b0b2d33a2c632fbc093b61e2c2d4dc07f70 (patch) | |
| tree | 8c9cde38a296b6509780b1200472490465df485f /src | |
| parent | 42fa76b3472c2dae8fd6db6649058e54e9f67003 (diff) | |
| download | dome-key-map-961b3b0b2d33a2c632fbc093b61e2c2d4dc07f70.tar.bz2 | |
Add an FFI bridge to the `parse_args()` function
This will allow us to parse command line arguments starting from a C
argv array (hopefully).
Diffstat (limited to 'src')
| -rw-r--r-- | src/cocoa_bridge.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index 1b07ed0..f572c37 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -14,6 +14,7 @@ use stderrlog; use xdg; use {Action, HeadphoneButton, MapAction, MapGroup, MapKind}; +use config::{self, Config}; #[repr(C)] struct renameMeMapGroup { @@ -297,6 +298,36 @@ fn run_action(map_action: &MapAction) { // fn run_command(command: Action) -> Result { // } +#[no_mangle] +pub extern "C" fn parse_args( + args: *const c_char, + length: size_t, +) -> *const Config { + let args = unsafe { + assert!(!args.is_null()); + + let args = slice::from_raw_parts(args, length as usize); + + args + .iter() + .map(|s| + CStr::from_ptr(s) + .to_string_lossy() + .into_owned()) + .collect::<Vec<String>>() + }; + + let config = config::parse_args(&args); + + Box::into_raw(Box::new(config)) as *const Config +} + +#[no_mangle] +pub extern "C" fn config_free(ptr: *mut Config) { + if ptr.is_null() { return } + unsafe { Box::from_raw(ptr); } +} + mod tests { use super::*; |
