From 58d6add8d11b6376966ccbe88a5661e9c9160a46 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Mon, 7 Dec 2015 21:49:18 -0500 Subject: [PATCH] Add macro to properly find program name. --- src/uucore/macros.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/uucore/macros.rs b/src/uucore/macros.rs index 89fa1c2a6..8789b7e6c 100644 --- a/src/uucore/macros.rs +++ b/src/uucore/macros.rs @@ -7,10 +7,22 @@ * file that was distributed with this source code. */ +#[macro_export] +macro_rules! executable( + () => ({ + let module = module_path!(); + if &module[0..3] == "uu_" { + &module[3..] + } else { + module + } + }) +); + #[macro_export] macro_rules! show_error( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: error: ", module_path!()); + pipe_write!(&mut ::std::io::stderr(), "{}: error: ", executable!()); pipe_writeln!(&mut ::std::io::stderr(), $($args)+); }) ); @@ -18,7 +30,7 @@ macro_rules! show_error( #[macro_export] macro_rules! show_warning( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: warning: ", module_path!()); + pipe_write!(&mut ::std::io::stderr(), "{}: warning: ", executable!()); pipe_writeln!(&mut ::std::io::stderr(), $($args)+); }) ); @@ -26,7 +38,7 @@ macro_rules! show_warning( #[macro_export] macro_rules! show_info( ($($args:tt)+) => ({ - pipe_write!(&mut ::std::io::stderr(), "{}: ", module_path!()); + pipe_write!(&mut ::std::io::stderr(), "{}: ", executable!()); pipe_writeln!(&mut ::std::io::stderr(), $($args)+); }) );