aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorTeddy Wing2018-10-26 00:47:26 +0200
committerTeddy Wing2018-10-26 00:47:26 +0200
commit88d3f71dc79ebd5fc6b21999240935930da84273 (patch)
tree541c2f9e081d64dc7b0227219e4011a49104b3ba /src/lib.rs
parent1f800bc121eb5caa712a94dc018ec9c19c718060 (diff)
downloaddome-key-map-88d3f71dc79ebd5fc6b21999240935930da84273.tar.bz2
Add a `--license` command line argument
Add a new argument that allows users to pass in the path to a license file. Doing so should get picked up by the Objective-C code which will copy and validate the license. In order for the Objective-C code to pick up the path string, we add a `license` field to the `Config.Args` struct. The new `license` field is a `*mut c_char`, which means we can't derive Default any more and need to implement a custom `Default` impl for `Args`. Additionally, 'getopts' gives us a Rust string (of course), which needs to be converted into a raw `CString` before we can stick it in the `license` field in `Args`. I previously wrote `dkeprintln` to be able to print an error here at the conversion point between `CString` and raw C string. Since we used `CString#into_raw()`, we need to call `from_raw()` on the pointer to free it, otherwise we end up with a memory leak. This necessitated adding some additional code to `config_free()` to free the `license` field if non-null. In order to access `config.args.license` from within `config_free()`, I also needed to make the `args` and `license` struct fields public, since the free function is in a different module. Instead of making only those two fields public, I decided to make them all public, as all the fields are technically accessible from C code, and are needed by that C code. Finally, move the module declaration of `prefix_println` to the top of the module list instead of listing it alphabetically, because otherwise any modules declared before it (like `config`) don't get access to its macro. Also add a `#[macro_use]` attribute to the module declaration because we do want to export its macro. (https://stackoverflow.com/questions/26731243/how-do-i-use-a-macro-across-module-files#comment78329437_31749071)
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6a08e4b..1e0daa6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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};