From 8ce97a84ea5adb16f4cf5e01bd931438a22caaf7 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Sun, 12 Jun 2016 14:59:50 -0400 Subject: add function for xscreensaver arg backwards compatability --- src/util.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src') 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 { + + let known_args = vec!["-root", + "-window", + "-mono", + "-install", + "-noinstall", + "-visual", + "-window-id", + "-fps", + "-no-fps", + "-pair", + "-record-animation"]; + + let ret: Vec = 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"])); +} -- cgit v1.2.3