refactor/uucore ~ reorganize macros into sections by 'type'

This commit is contained in:
Roy Ivy III 2021-06-30 22:14:37 -05:00 committed by Michael Debertol
parent be8f073217
commit 27c4530f3c

View file

@ -5,19 +5,6 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
/// Get the utility name.
#[macro_export]
macro_rules! util_name(
() => ({
let crate_name = env!("CARGO_PKG_NAME");
if crate_name.starts_with("uu_") {
&crate_name[3..]
} else {
&crate_name
}
})
);
/// Get the executable path (as `OsString`).
#[macro_export]
macro_rules! executable_os(
@ -48,6 +35,21 @@ macro_rules! executable_name(
})
);
/// Derive the utility name.
#[macro_export]
macro_rules! util_name(
() => ({
let crate_name = env!("CARGO_PKG_NAME");
if crate_name.starts_with("uu_") {
&crate_name[3..]
} else {
&crate_name
}
})
);
//====
#[macro_export]
macro_rules! show(
($err:expr) => ({
@ -102,14 +104,7 @@ macro_rules! show_usage_error(
})
);
/// Display the provided error message, then `exit()` with the provided exit code
#[macro_export]
macro_rules! crash(
($exit_code:expr, $($args:tt)+) => ({
show_error!($($args)+);
::std::process::exit($exit_code)
})
);
//====
/// Calls `exit()` with the provided exit code.
#[macro_export]
@ -119,6 +114,15 @@ macro_rules! exit(
})
);
/// Display the provided error message, then `exit()` with the provided exit code
#[macro_export]
macro_rules! crash(
($exit_code:expr, $($args:tt)+) => ({
show_error!($($args)+);
::std::process::exit($exit_code)
})
);
/// Unwraps the Result. Instead of panicking, it exists the program with the
/// provided exit code.
#[macro_export]
@ -131,6 +135,8 @@ macro_rules! crash_if_err(
)
);
//====
/// Unwraps the Result. Instead of panicking, it shows the error and then
/// returns from the function with the provided exit code.
/// Assumes the current function returns an i32 value.
@ -147,6 +153,8 @@ macro_rules! return_if_err(
)
);
//====
#[macro_export]
macro_rules! safe_write(
($fd:expr, $($args:tt)+) => (