diff --git a/src/swab.rs b/src/swab.rs index 7889a59..5b4c173 100644 --- a/src/swab.rs +++ b/src/swab.rs @@ -48,7 +48,8 @@ fn main() -> ExitCode { let mut input = stdin(); let mut output = stdout().lock(); - let mut wordsize: usize = 2; + let mut optind: usize = 1; // argv[0] + let mut wordsize: usize = 2; // Equivalent to dd(1p). while let Some(opt) = argv.getopt(":w:") { match opt.opt() { @@ -59,11 +60,16 @@ fn main() -> ExitCode { _ => { return usage(&argv[0]); }, } } + optind = opt.ind(); }, _ => { return usage(&argv[0]); } } } + if optind < argv.len() { + return usage(&argv[0]); + } + buf.resize(wordsize, 0); loop {