mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-09-14 19:16:17 +00:00
od: do not panic on invalid user input
use macros from uucore where possible
This commit is contained in:
parent
167d7d3ca9
commit
e905c2ec71
2 changed files with 13 additions and 7 deletions
|
@ -53,8 +53,9 @@ impl<'b> MultifileReader<'b> {
|
|||
// print an error at the time that the file is needed,
|
||||
// then move on the the next file.
|
||||
// This matches the behavior of the original `od`
|
||||
let _ =
|
||||
writeln!(&mut std::io::stderr(), "od: '{}': {}", fname, e);
|
||||
eprintln!("{}: '{}': {}",
|
||||
executable!().split("::").next().unwrap(), // remove module
|
||||
fname, e);
|
||||
self.any_err = true
|
||||
}
|
||||
}
|
||||
|
|
15
src/od/od.rs
15
src/od/od.rs
|
@ -39,7 +39,6 @@ macro_rules! hashmap {
|
|||
}}
|
||||
}
|
||||
|
||||
static NAME: &'static str = "od";
|
||||
static VERSION: &'static str = env!("CARGO_PKG_VERSION");
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -86,7 +85,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
|
||||
let matches = match opts.parse(&args[1..]) {
|
||||
Ok(m) => m,
|
||||
Err(f) => panic!("Invalid options\n{}", f)
|
||||
Err(f) => {
|
||||
disp_err!("{}", f);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
if matches.opt_present("h") {
|
||||
|
@ -94,18 +96,21 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
Usage:
|
||||
{0} [OPTION]... [FILENAME]...
|
||||
|
||||
Displays data in various human-readable formats.", NAME));
|
||||
Displays data in various human-readable formats.", executable!()));
|
||||
println!("{}", opts.usage(&msg));
|
||||
return 0;
|
||||
}
|
||||
if matches.opt_present("version") {
|
||||
println!("{} {}", NAME, VERSION);
|
||||
println!("{} {}", executable!(), VERSION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
let input_offset_base = match parse_radix(matches.opt_str("A")) {
|
||||
Ok(r) => r,
|
||||
Err(f) => { panic!("Invalid -A/--address-radix\n{}", f) }
|
||||
Err(f) => {
|
||||
disp_err!("Invalid -A/--address-radix\n{}", f);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
// Gather up file names - args which don't start with '-'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue