aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2016-06-12 14:59:50 -0400
committerbnewbold <bnewbold@robocracy.org>2016-06-12 14:59:50 -0400
commit8ce97a84ea5adb16f4cf5e01bd931438a22caaf7 (patch)
treefd71bef5740257fb7c479743bedaa9828ea88176 /src
parentbe5efed9f4c0a1532509f0f8d6051f583905662f (diff)
downloadexuberant-hacks-8ce97a84ea5adb16f4cf5e01bd931438a22caaf7.tar.gz
exuberant-hacks-8ce97a84ea5adb16f4cf5e01bd931438a22caaf7.zip
add function for xscreensaver arg backwards compatability
Diffstat (limited to 'src')
-rw-r--r--src/util.rs42
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"]));
+}