Created
December 17, 2013 12:40
-
-
Save anonymous/8004322 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern mod extra; | |
use std; | |
use std::os; | |
use self::ops_int::{inited,Flag,Opt,Opts}; | |
mod ops_int; | |
// remove getters and setters when macros get more powerful | |
option!(uint _delay = 0, set_delay, delay) | |
option!(bool _countdown = false, set_countdown, countdown) | |
option!(bool _select = false, set_select, select) | |
option!(bool _window = false, set_window, window) | |
option!(uint _quality = 75, set_quality, quality) | |
option!(bool _border = false, set_border, border) | |
option!(bool _multidisp = false, set_multidisp, multidisp) | |
option!(uint _thumb = 0, set_thumb, thumb) | |
option!(uint _thumb_width = 0, set_thumb_width, thumb_width) | |
option!(uint _thumb_height = 0, set_thumb_height, thumb_height) | |
option!(~str _output_file = ~"", set_output_file, output_file) | |
option!(~str _thumb_file = ~"", set_thumb_file, thumb_file) | |
option!(~str _exec = ~"", set_exec, exec) | |
option!(~str _program = ~"", set_program, program) | |
pub fn parse() -> Result<(), ~str> { | |
if inited() { | |
return Err(~"already initialized"); | |
} | |
let args = os::args(); | |
set_program(args[0].to_owned()); | |
set_output_file(~"%Y-%m-%d-%H%M%S_$wx$h_rot.png"); | |
set_thumb_file(~"%Y-%m-%d-%H%M%S_$wx$h_rot-thumb.png"); | |
let ops = ~[ | |
flag!( !! "top"), | |
flag!("a" !! ), | |
flag!("h" !! "help"), | |
flag!("v" !! "version"), | |
flag!("c" !! "count"), | |
flag!("s" !! "select"), | |
flag!("w" !! "window"), | |
flag!("b" !! "border"), | |
flag!("m" !! "multidisp"), | |
opts!("t" !! "thumb"), | |
opts!("d" !! "delay"), | |
opts!("q" !! "quality"), | |
opts!("e" !! "exec"), | |
]; | |
let ms = match ops.get(args.tail()) { | |
Ok(ms) => ms, | |
Err(e) => return Err(e), | |
}; | |
for m in ms.matches.iter() { | |
match m.name { | |
~"a" => (), | |
~"top" => (), | |
~"h" => (), | |
~"v" => (), | |
~"c" => set_countdown(true), | |
~"s" => set_select(true), | |
~"w" => set_window(true), | |
~"b" => set_border(true), | |
~"m" => set_multidisp(true), | |
~"t" => parse_thumb(m.value.clone()), | |
~"d" => on_error!(m.parse(set_delay), return Err(~"top")), | |
~"q" => on_error!(m.parse(set_quality), return Err(~"kek")), | |
~"e" => set_exec(m.value.clone()), | |
_ => (), | |
} | |
}; | |
let mut output_set = false; | |
for s in ms.free.move_iter() { | |
if output_set { | |
return Err(format!("unrecognized option {}", s.clone())); | |
} | |
output_set = true; | |
set_output_file(s.clone()); | |
let path = std::path::posix::Path::new(s.clone()); | |
let stem = match path.filestem_str() { | |
None => ~"", | |
Some(s) => s.to_owned(), | |
}; | |
let ex = match path.extension_str() { | |
None => ~"", | |
Some(s) => "." + s.to_owned(), | |
}; | |
set_output_file(stem + "-thumb" + ex); | |
}; | |
Ok(()) | |
} | |
fn parse_thumb(thumb: &str) { | |
let _ = thumb; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment