1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Add macro to properly find program name.

This commit is contained in:
Joseph Crail 2015-12-07 21:49:18 -05:00
parent b90d253584
commit 58d6add8d1

View file

@ -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)+);
})
);