1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 03:26:18 +00:00

od: do not panic on invalid user input

use macros from uucore where possible
This commit is contained in:
Wim Hueskes 2016-07-23 23:18:02 +02:00
parent 167d7d3ca9
commit e905c2ec71
2 changed files with 13 additions and 7 deletions

View file

@ -53,8 +53,9 @@ impl<'b> MultifileReader<'b> {
// print an error at the time that the file is needed, // print an error at the time that the file is needed,
// then move on the the next file. // then move on the the next file.
// This matches the behavior of the original `od` // This matches the behavior of the original `od`
let _ = eprintln!("{}: '{}': {}",
writeln!(&mut std::io::stderr(), "od: '{}': {}", fname, e); executable!().split("::").next().unwrap(), // remove module
fname, e);
self.any_err = true self.any_err = true
} }
} }

View file

@ -39,7 +39,6 @@ macro_rules! hashmap {
}} }}
} }
static NAME: &'static str = "od";
static VERSION: &'static str = env!("CARGO_PKG_VERSION"); static VERSION: &'static str = env!("CARGO_PKG_VERSION");
#[derive(Debug)] #[derive(Debug)]
@ -86,7 +85,10 @@ pub fn uumain(args: Vec<String>) -> i32 {
let matches = match opts.parse(&args[1..]) { let matches = match opts.parse(&args[1..]) {
Ok(m) => m, Ok(m) => m,
Err(f) => panic!("Invalid options\n{}", f) Err(f) => {
disp_err!("{}", f);
return 1;
}
}; };
if matches.opt_present("h") { if matches.opt_present("h") {
@ -94,18 +96,21 @@ pub fn uumain(args: Vec<String>) -> i32 {
Usage: Usage:
{0} [OPTION]... [FILENAME]... {0} [OPTION]... [FILENAME]...
Displays data in various human-readable formats.", NAME)); Displays data in various human-readable formats.", executable!()));
println!("{}", opts.usage(&msg)); println!("{}", opts.usage(&msg));
return 0; return 0;
} }
if matches.opt_present("version") { if matches.opt_present("version") {
println!("{} {}", NAME, VERSION); println!("{} {}", executable!(), VERSION);
return 0; return 0;
} }
let input_offset_base = match parse_radix(matches.opt_str("A")) { let input_offset_base = match parse_radix(matches.opt_str("A")) {
Ok(r) => r, 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 '-' // Gather up file names - args which don't start with '-'