diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-06-12 14:59:50 -0400 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-06-12 14:59:50 -0400 |
commit | 8ce97a84ea5adb16f4cf5e01bd931438a22caaf7 (patch) | |
tree | fd71bef5740257fb7c479743bedaa9828ea88176 /src | |
parent | be5efed9f4c0a1532509f0f8d6051f583905662f (diff) | |
download | exuberant-hacks-8ce97a84ea5adb16f4cf5e01bd931438a22caaf7.tar.gz exuberant-hacks-8ce97a84ea5adb16f4cf5e01bd931438a22caaf7.zip |
add function for xscreensaver arg backwards compatability
Diffstat (limited to 'src')
-rw-r--r-- | src/util.rs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/util.rs b/src/util.rs index f35c157..4d87bb5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,6 @@ +use std::str::FromStr; + pub fn view_matrix(position: &[f32; 3], direction: &[f32; 3], up: &[f32; 3]) -> [[f32; 4]; 4] { @@ -34,3 +36,43 @@ pub fn view_matrix(position: &[f32; 3], [p[0], p[1], p[2], 1.0], ] } + +/// This little hacky function converts X-style args like "-root" to standard +/// UNIX long-style args ("--root") that can be parsed by getopts. +/// +/// These variant long-form args should probably be hidden from the user, eg +/// not show up in usage or manpage output. +pub fn convert_xscreensaver_args(raw: Vec<&str>) -> Vec<String> { + + let known_args = vec!["-root", + "-window", + "-mono", + "-install", + "-noinstall", + "-visual", + "-window-id", + "-fps", + "-no-fps", + "-pair", + "-record-animation"]; + + let ret: Vec<String> = raw.into_iter().map(|arg| { + if known_args.contains(&arg) { + let mut longer = String::from_str("-").unwrap(); + longer.push_str(arg); + longer + } else { + String::from_str(arg).unwrap() + } + }).collect(); + ret +} + +#[test] +fn test_xargconv() { + assert_eq!(vec!["--root"], convert_xscreensaver_args(vec!["-root"])); + assert_eq!(vec!["--root"], convert_xscreensaver_args(vec!["--root"])); + assert_eq!(vec!["root"], convert_xscreensaver_args(vec!["root"])); + assert_eq!(vec!["-asdf"], convert_xscreensaver_args(vec!["-asdf"])); + assert_eq!(vec!["-h"], convert_xscreensaver_args(vec!["-h"])); +} |