From 5544def54e09357cb93273e05d1ec86da081b951 Mon Sep 17 00:00:00 2001 From: Alex Lyon Date: Sun, 10 Dec 2017 20:57:39 -0800 Subject: [PATCH] Remove pipe_* macros --- src/uucore/coreopts.rs | 5 +- src/uucore/macros.rs | 140 +++------------------------------------ src/uucore/parse_time.rs | 2 +- 3 files changed, 13 insertions(+), 134 deletions(-) diff --git a/src/uucore/coreopts.rs b/src/uucore/coreopts.rs index da2454508..76895b612 100644 --- a/src/uucore/coreopts.rs +++ b/src/uucore/coreopts.rs @@ -1,5 +1,4 @@ extern crate getopts; -use std::io::Write; pub struct HelpText<'a> { pub name : &'a str, @@ -53,8 +52,8 @@ impl<'a> CoreOptions<'a> { let matches = match self.options.parse(&args[1..]) { Ok(m) => { Some(m) }, Err(f) => { - pipe_write!(&mut ::std::io::stderr(), "{}: error: ", self.help_text.name); - pipe_writeln!(&mut ::std::io::stderr(), "{}", f); + eprint!("{}: error: ", self.help_text.name); + eprintln!("{}", f); ::std::process::exit(1); } }.unwrap(); diff --git a/src/uucore/macros.rs b/src/uucore/macros.rs index 5e2f68a66..03decc92e 100644 --- a/src/uucore/macros.rs +++ b/src/uucore/macros.rs @@ -1,7 +1,7 @@ /* * This file is part of the uutils coreutils package. * - * (c) Arcterus + * (c) Alex Lyon * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -22,46 +22,36 @@ macro_rules! executable( #[macro_export] macro_rules! show_error( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: error: ", executable!()); - pipe_writeln!(&mut ::std::io::stderr(), $($args)+); + eprint!("{}: error: ", executable!()); + eprintln!($($args)+); }) ); #[macro_export] macro_rules! show_warning( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: warning: ", executable!()); - pipe_writeln!(&mut ::std::io::stderr(), $($args)+); + eprint!("{}: warning: ", executable!()); + eprintln!($($args)+); }) ); #[macro_export] macro_rules! show_info( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: ", executable!()); - pipe_writeln!(&mut ::std::io::stderr(), $($args)+); + eprint!("{}: ", executable!()); + eprintln!($($args)+); }) ); #[macro_export] macro_rules! disp_err( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: ", executable!()); - pipe_writeln!(&mut ::std::io::stderr(), $($args)+); - pipe_writeln!(&mut ::std::io::stderr(), "Try '{} --help' for more information.", executable!()); + eprint!("{}: ", executable!()); + eprintln!($($args)+); + eprintln!("Try '{} --help' for more information.", executable!()); }) ); -#[macro_export] -macro_rules! eprint( - ($($args:tt)+) => (pipe_write!(&mut ::std::io::stderr(), $($args)+)) -); - -#[macro_export] -macro_rules! eprintln( - ($($args:tt)+) => (pipe_writeln!(&mut ::std::io::stderr(), $($args)+)) -); - #[macro_export] macro_rules! crash( ($exitcode:expr, $($args:tt)+) => ({ @@ -87,22 +77,6 @@ macro_rules! crash_if_err( ) ); -#[macro_export] -macro_rules! pipe_crash_if_err( - ($exitcode:expr, $exp:expr) => ( - match $exp { - Ok(_) => (), - Err(f) => { - if f.kind() == ::std::io::ErrorKind::BrokenPipe { - () - } else { - crash!($exitcode, "{}", f) - } - }, - } - ) -); - #[macro_export] macro_rules! return_if_err( ($exitcode:expr, $exp:expr) => ( @@ -116,100 +90,6 @@ macro_rules! return_if_err( ) ); -// XXX: should the pipe_* macros return an Err just to show the write failed? - -#[macro_export] -macro_rules! pipe_print( - ($($args:tt)+) => ( - match write!(&mut ::std::io::stdout(), $($args)+) { - Ok(_) => true, - Err(f) => { - if f.kind() == ::std::io::ErrorKind::BrokenPipe { - false - } else { - panic!("{}", f) - } - } - } - ) -); - -#[macro_export] -macro_rules! pipe_println( - ($($args:tt)+) => ( - match writeln!(&mut ::std::io::stdout(), $($args)+) { - Ok(_) => true, - Err(f) => { - if f.kind() == ::std::io::ErrorKind::BrokenPipe { - false - } else { - panic!("{}", f) - } - } - } - ) -); - -#[macro_export] -macro_rules! pipe_write( - ($fd:expr, $($args:tt)+) => ( - match write!($fd, $($args)+) { - Ok(_) => true, - Err(f) => { - if f.kind() == ::std::io::ErrorKind::BrokenPipe { - false - } else { - panic!("{}", f) - } - } - } - ) -); - -#[macro_export] -macro_rules! pipe_writeln( - ($fd:expr, $($args:tt)+) => ( - match writeln!($fd, $($args)+) { - Ok(_) => true, - Err(f) => { - if f.kind() == ::std::io::ErrorKind::BrokenPipe { - false - } else { - panic!("{}", f) - } - } - } - ) -); - -#[macro_export] -macro_rules! pipe_flush( - () => ( - match ::std::io::stdout().flush() { - Ok(_) => true, - Err(f) => { - if f.kind() == ::std::io::ErrorKind::BrokenPipe { - false - } else { - panic!("{}", f) - } - } - } - ); - ($fd:expr) => ( - match $fd.flush() { - Ok(_) => true, - Err(f) => { - if f.kind() == ::std::io::ErrorKind::BrokenPipe { - false - } else { - panic!("{}", f) - } - } - } - ) -); - #[macro_export] macro_rules! safe_write( ($fd:expr, $($args:tt)+) => ( diff --git a/src/uucore/parse_time.rs b/src/uucore/parse_time.rs index 6083badd9..05b9f17b1 100644 --- a/src/uucore/parse_time.rs +++ b/src/uucore/parse_time.rs @@ -1,7 +1,7 @@ /* * This file is part of the uutils coreutils package. * - * (c) Arcterus + * (c) Alex Lyon * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code.