From 8f956d775c4006b688e3a194ecdff3d629c1c8e0 Mon Sep 17 00:00:00 2001 From: emma Date: Fri, 1 Mar 2024 23:10:28 -0700 Subject: [PATCH] fop(1): changed to use strerror(3) --- src/fop.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/fop.rs b/src/fop.rs index c9a767e..0e0b059 100644 --- a/src/fop.rs +++ b/src/fop.rs @@ -22,10 +22,12 @@ use std::{ process::{ Command, exit, Stdio }, }; -extern crate sysexits; extern crate getopt; +extern crate strerror; +extern crate sysexits; use getopt::{ Opt, Parser }; +use strerror::c_error; use sysexits::{ EX_DATAERR, EX_IOERR, EX_UNAVAILABLE, EX_USAGE }; fn main() { @@ -55,7 +57,7 @@ fn main() { }); let index = argv[index_arg].parse::().unwrap_or_else(|e| { - eprintln!("{}: {}: {}.", argv[0], argv[1], e); + eprintln!("{}: {}: {}", argv[0], argv[1], e); exit(EX_DATAERR); }); @@ -75,13 +77,13 @@ fn main() { .stdout(Stdio::piped()) .spawn() .unwrap_or_else( |e| { - eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], c_error(e)); exit(EX_UNAVAILABLE); }); let field = fields.get(index).unwrap_or_else(|| { eprintln!( - "{}: {}: No such index in input.", + "{}: {}: No such index in input", argv[0], index.to_string(), ); @@ -94,7 +96,7 @@ fn main() { } let output = spawned.wait_with_output().unwrap_or_else(|e| { - eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], c_error(e)); exit(EX_IOERR); }); @@ -103,7 +105,7 @@ fn main() { if replace.pop() != Some(b'\n') { replace = output.stdout; } let new_field = String::from_utf8(replace).unwrap_or_else(|e| { - eprintln!("{}: {}: {}.", argv[0], argv[command_arg], e); + eprintln!("{}: {}: {}", argv[0], argv[command_arg], e); exit(EX_IOERR); }); @@ -111,8 +113,8 @@ fn main() { stdout().write_all( fields.join(&d.to_string()).as_bytes() - ).unwrap_or_else(|e|{ - eprintln!("{}: {}.", argv[0], e); + ).unwrap_or_else(|e| { + eprintln!("{}: {}", argv[0], c_error(e)); exit(EX_IOERR); }); }