aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
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"]));
+}