mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 14:07:46 +00:00
refactor/uucore ~ reorganize macros into sections by 'type'
This commit is contained in:
parent
be8f073217
commit
27c4530f3c
1 changed files with 29 additions and 21 deletions
|
@ -5,19 +5,6 @@
|
||||||
// For the full copyright and license information, please view the LICENSE
|
// For the full copyright and license information, please view the LICENSE
|
||||||
// file that was distributed with this source code.
|
// 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`).
|
/// Get the executable path (as `OsString`).
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! executable_os(
|
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_export]
|
||||||
macro_rules! show(
|
macro_rules! show(
|
||||||
($err:expr) => ({
|
($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.
|
/// Calls `exit()` with the provided exit code.
|
||||||
#[macro_export]
|
#[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
|
/// Unwraps the Result. Instead of panicking, it exists the program with the
|
||||||
/// provided exit code.
|
/// provided exit code.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
@ -131,6 +135,8 @@ macro_rules! crash_if_err(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//====
|
||||||
|
|
||||||
/// Unwraps the Result. Instead of panicking, it shows the error and then
|
/// Unwraps the Result. Instead of panicking, it shows the error and then
|
||||||
/// returns from the function with the provided exit code.
|
/// returns from the function with the provided exit code.
|
||||||
/// Assumes the current function returns an i32 value.
|
/// Assumes the current function returns an i32 value.
|
||||||
|
@ -147,6 +153,8 @@ macro_rules! return_if_err(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//====
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! safe_write(
|
macro_rules! safe_write(
|
||||||
($fd:expr, $($args:tt)+) => (
|
($fd:expr, $($args:tt)+) => (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue