diff --git a/src/stris.rs b/src/stris.rs index 4336484..95a59b0 100644 --- a/src/stris.rs +++ b/src/stris.rs @@ -23,9 +23,9 @@ use std::{ }; extern crate getopt; -use getopt::{ Opt, Parser }; - extern crate sysexits; + +use getopt::GetOpt; use sysexits::EX_USAGE; struct Reqs { @@ -34,45 +34,39 @@ struct Reqs { } fn usage(s: &str) -> ExitCode { - eprintln!("Usage: {} (-7bcdlu) (-i [inclusions]) [strings...]", s); + eprintln!("Usage: {} [-7bcdlu] [-i inclusions] [strings...]", s); ExitCode::from(EX_USAGE as u8) } fn main() -> ExitCode { let argv = args().collect::>(); - let mut opts = Parser::new(&argv, "7bcdi:lu"); + let mut optind = 1; let mut reqs = Reqs { ascii: false, blank: false, cntrl: false, digit: false, lower: false, upper: false, inuse: false, extra: String::new() }; - loop { - match opts.next() { - None => break, - Some(opt) => { - match opt { - Ok(Opt('7', None)) => reqs.ascii = true, - Ok(Opt('b', None)) => reqs.blank = true, - Ok(Opt('c', None)) => reqs.cntrl = true, - Ok(Opt('d', None)) => reqs.digit = true, - Ok(Opt('i', Some(arg))) => reqs.extra = arg, - Ok(Opt('l', None)) => reqs.lower = true, - Ok(Opt('u', None)) => reqs.upper = true, - _ => { return usage(&argv[0]); } - } - reqs.inuse = true; - } + while let Some(opt) = argv.getopt("7bcdi:lu") { + match opt.opt() { + Ok("7") => reqs.ascii = true, + Ok("b") => reqs.blank = true, + Ok("c") => reqs.cntrl = true, + Ok("d") => reqs.digit = true, + Ok("i") => reqs.extra = opt.arg().unwrap(), + Ok("l") => reqs.lower = true, + Ok("u") => reqs.upper = true, + _ => { return usage(&argv[0]); } } + optind = opt.ind(); + reqs.inuse = true; } - if argv.len() == opts.index() { - return usage(&argv[0]); - } + if argv.len() == optind { return usage(&argv[0]); } drop(argv); if reqs.inuse { - for arg in args().skip(opts.index()) { + for arg in args().skip(optind) { for c in arg.chars() { if (reqs.ascii && c.is_ascii()) || (reqs.blank && c.is_whitespace())