2014-02-07 06:39:07 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the uutils coreutils package.
|
|
|
|
*
|
|
|
|
* (c) Arcterus <arcterus@mail.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2014-03-31 16:40:21 +00:00
|
|
|
#![macro_escape]
|
2014-02-07 06:39:07 +00:00
|
|
|
|
2014-04-26 05:03:08 +00:00
|
|
|
extern crate libc;
|
|
|
|
|
2014-02-07 06:39:07 +00:00
|
|
|
#[macro_export]
|
2014-06-09 01:49:06 +00:00
|
|
|
macro_rules! show_errer(
|
2014-06-08 08:37:02 +00:00
|
|
|
($($args:expr),+) => ({
|
|
|
|
safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME);
|
|
|
|
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2014-03-24 23:48:40 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! show_warning(
|
|
|
|
($($args:expr),+) => ({
|
|
|
|
safe_write!(&mut ::std::io::stderr(), "{}: warning: ", ::NAME);
|
|
|
|
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
|
2014-02-07 06:39:07 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! crash(
|
|
|
|
($exitcode:expr, $($args:expr),+) => ({
|
2014-06-09 01:49:06 +00:00
|
|
|
safe_write!(&mut ::std::io::stderr(), "{}: error: ", ::NAME);
|
|
|
|
safe_writeln!(&mut ::std::io::stderr(), $($args),+);
|
2014-04-26 05:03:08 +00:00
|
|
|
unsafe { self::libc::exit($exitcode as self::libc::c_int); }
|
2014-04-03 13:59:58 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! exit(
|
|
|
|
($exitcode:expr) => ({
|
2014-04-26 05:03:08 +00:00
|
|
|
unsafe { self::libc::exit($exitcode); }
|
2014-02-07 06:39:07 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
|
2014-02-27 18:59:51 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! crash_if_err(
|
|
|
|
($exitcode:expr, $exp:expr) => (
|
|
|
|
match $exp {
|
|
|
|
Ok(m) => m,
|
|
|
|
Err(f) => crash!($exitcode, "{}", f.to_str())
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2014-02-07 06:39:07 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! safe_write(
|
|
|
|
($fd:expr, $($args:expr),+) => (
|
|
|
|
match write!($fd, $($args),+) {
|
|
|
|
Ok(_) => {}
|
|
|
|
Err(f) => { fail!(f.to_str()); }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! safe_writeln(
|
|
|
|
($fd:expr, $($args:expr),+) => (
|
|
|
|
match writeln!($fd, $($args),+) {
|
|
|
|
Ok(_) => {}
|
|
|
|
Err(f) => { fail!(f.to_str()); }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2014-02-19 01:10:32 +00:00
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! safe_unwrap(
|
|
|
|
($exp:expr) => (
|
|
|
|
match $exp {
|
|
|
|
Ok(m) => m,
|
|
|
|
Err(f) => crash!(1, "{}", f.to_str())
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|