From e7a6632b41d93d361750fd6242d7b0826068cfc4 Mon Sep 17 00:00:00 2001 From: emma Date: Sun, 14 Jul 2024 18:56:23 -0600 Subject: [PATCH] mm(1): improves comments --- src/mm.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mm.rs b/src/mm.rs index 301ed55..41b7857 100644 --- a/src/mm.rs +++ b/src/mm.rs @@ -47,7 +47,7 @@ fn main() -> ExitCode { let mut u = false; /* unbuffer i/o */ let mut ins = Vec::new(); /* initial input file path vector */ let mut outs = Vec::new(); /* initial output file path vector */ - let mut mode: Option = None; /* mode for positional arguments */ + let mut mode: Option = None; /* mode set by last-used option */ let mut optind = 0; while let Some(opt) = argv.getopt("aei:o:tu") { @@ -59,30 +59,36 @@ fn main() -> ExitCode { Ok("i") => { /* add inputs */ let input = opt.arg().unwrap(); ins.push(input); - mode = Some(In); + mode = Some(In); /* latest argument == -i */ }, Ok("o") => { /* add output */ let output = opt.arg().unwrap(); outs.push(output); - mode = Some(Out); + mode = Some(Out); /* latest argument == -o */ }, Err(_) | Ok(_) => { eprintln!("{}", usage); return ExitCode::from(EX_USAGE as u8); }, }; + optind = opt.ind(); } let remaining = argv.iter().skip(optind); + /* check the last flag specified */ if let Some(m) = mode { for arg in remaining { + /* move the subsequent arguments to the list of inputs or outputs */ match m { In => ins.push(arg.to_string()), Out => outs.push(arg.to_string()), }; } + } else { + eprintln!("{}", usage); + return ExitCode::from(EX_USAGE as u8); } /* use stdin if no inputs are specified */