mm(1): improves comments
This commit is contained in:
parent
48dbea0228
commit
e7a6632b41
12
src/mm.rs
12
src/mm.rs
@ -47,7 +47,7 @@ fn main() -> ExitCode {
|
|||||||
let mut u = false; /* unbuffer i/o */
|
let mut u = false; /* unbuffer i/o */
|
||||||
let mut ins = Vec::new(); /* initial input file path vector */
|
let mut ins = Vec::new(); /* initial input file path vector */
|
||||||
let mut outs = Vec::new(); /* initial output file path vector */
|
let mut outs = Vec::new(); /* initial output file path vector */
|
||||||
let mut mode: Option<ArgMode> = None; /* mode for positional arguments */
|
let mut mode: Option<ArgMode> = None; /* mode set by last-used option */
|
||||||
let mut optind = 0;
|
let mut optind = 0;
|
||||||
|
|
||||||
while let Some(opt) = argv.getopt("aei:o:tu") {
|
while let Some(opt) = argv.getopt("aei:o:tu") {
|
||||||
@ -59,30 +59,36 @@ fn main() -> ExitCode {
|
|||||||
Ok("i") => { /* add inputs */
|
Ok("i") => { /* add inputs */
|
||||||
let input = opt.arg().unwrap();
|
let input = opt.arg().unwrap();
|
||||||
ins.push(input);
|
ins.push(input);
|
||||||
mode = Some(In);
|
mode = Some(In); /* latest argument == -i */
|
||||||
},
|
},
|
||||||
Ok("o") => { /* add output */
|
Ok("o") => { /* add output */
|
||||||
let output = opt.arg().unwrap();
|
let output = opt.arg().unwrap();
|
||||||
outs.push(output);
|
outs.push(output);
|
||||||
mode = Some(Out);
|
mode = Some(Out); /* latest argument == -o */
|
||||||
},
|
},
|
||||||
Err(_) | Ok(_) => {
|
Err(_) | Ok(_) => {
|
||||||
eprintln!("{}", usage);
|
eprintln!("{}", usage);
|
||||||
return ExitCode::from(EX_USAGE as u8);
|
return ExitCode::from(EX_USAGE as u8);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
optind = opt.ind();
|
optind = opt.ind();
|
||||||
}
|
}
|
||||||
|
|
||||||
let remaining = argv.iter().skip(optind);
|
let remaining = argv.iter().skip(optind);
|
||||||
|
|
||||||
|
/* check the last flag specified */
|
||||||
if let Some(m) = mode {
|
if let Some(m) = mode {
|
||||||
for arg in remaining {
|
for arg in remaining {
|
||||||
|
/* move the subsequent arguments to the list of inputs or outputs */
|
||||||
match m {
|
match m {
|
||||||
In => ins.push(arg.to_string()),
|
In => ins.push(arg.to_string()),
|
||||||
Out => outs.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 */
|
/* use stdin if no inputs are specified */
|
||||||
|
Loading…
Reference in New Issue
Block a user