mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-04 23:17:46 +00:00
Remove pipe_* macros
This commit is contained in:
parent
f0bd170996
commit
5544def54e
3 changed files with 13 additions and 134 deletions
|
@ -1,5 +1,4 @@
|
|||
extern crate getopts;
|
||||
use std::io::Write;
|
||||
|
||||
pub struct HelpText<'a> {
|
||||
pub name : &'a str,
|
||||
|
@ -53,8 +52,8 @@ impl<'a> CoreOptions<'a> {
|
|||
let matches = match self.options.parse(&args[1..]) {
|
||||
Ok(m) => { Some(m) },
|
||||
Err(f) => {
|
||||
pipe_write!(&mut ::std::io::stderr(), "{}: error: ", self.help_text.name);
|
||||
pipe_writeln!(&mut ::std::io::stderr(), "{}", f);
|
||||
eprint!("{}: error: ", self.help_text.name);
|
||||
eprintln!("{}", f);
|
||||
::std::process::exit(1);
|
||||
}
|
||||
}.unwrap();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Arcterus <arcterus@mail.com>
|
||||
* (c) Alex Lyon <arcterus@mail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
|
@ -22,46 +22,36 @@ macro_rules! executable(
|
|||
#[macro_export]
|
||||
macro_rules! show_error(
|
||||
($($args:tt)+) => ({
|
||||
pipe_write!(&mut ::std::io::stderr(), "{}: error: ", executable!());
|
||||
pipe_writeln!(&mut ::std::io::stderr(), $($args)+);
|
||||
eprint!("{}: error: ", executable!());
|
||||
eprintln!($($args)+);
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! show_warning(
|
||||
($($args:tt)+) => ({
|
||||
pipe_write!(&mut ::std::io::stderr(), "{}: warning: ", executable!());
|
||||
pipe_writeln!(&mut ::std::io::stderr(), $($args)+);
|
||||
eprint!("{}: warning: ", executable!());
|
||||
eprintln!($($args)+);
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! show_info(
|
||||
($($args:tt)+) => ({
|
||||
pipe_write!(&mut ::std::io::stderr(), "{}: ", executable!());
|
||||
pipe_writeln!(&mut ::std::io::stderr(), $($args)+);
|
||||
eprint!("{}: ", executable!());
|
||||
eprintln!($($args)+);
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! disp_err(
|
||||
($($args:tt)+) => ({
|
||||
pipe_write!(&mut ::std::io::stderr(), "{}: ", executable!());
|
||||
pipe_writeln!(&mut ::std::io::stderr(), $($args)+);
|
||||
pipe_writeln!(&mut ::std::io::stderr(), "Try '{} --help' for more information.", executable!());
|
||||
eprint!("{}: ", executable!());
|
||||
eprintln!($($args)+);
|
||||
eprintln!("Try '{} --help' for more information.", executable!());
|
||||
})
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! eprint(
|
||||
($($args:tt)+) => (pipe_write!(&mut ::std::io::stderr(), $($args)+))
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! eprintln(
|
||||
($($args:tt)+) => (pipe_writeln!(&mut ::std::io::stderr(), $($args)+))
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! crash(
|
||||
($exitcode:expr, $($args:tt)+) => ({
|
||||
|
@ -87,22 +77,6 @@ macro_rules! crash_if_err(
|
|||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pipe_crash_if_err(
|
||||
($exitcode:expr, $exp:expr) => (
|
||||
match $exp {
|
||||
Ok(_) => (),
|
||||
Err(f) => {
|
||||
if f.kind() == ::std::io::ErrorKind::BrokenPipe {
|
||||
()
|
||||
} else {
|
||||
crash!($exitcode, "{}", f)
|
||||
}
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! return_if_err(
|
||||
($exitcode:expr, $exp:expr) => (
|
||||
|
@ -116,100 +90,6 @@ macro_rules! return_if_err(
|
|||
)
|
||||
);
|
||||
|
||||
// XXX: should the pipe_* macros return an Err just to show the write failed?
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pipe_print(
|
||||
($($args:tt)+) => (
|
||||
match write!(&mut ::std::io::stdout(), $($args)+) {
|
||||
Ok(_) => true,
|
||||
Err(f) => {
|
||||
if f.kind() == ::std::io::ErrorKind::BrokenPipe {
|
||||
false
|
||||
} else {
|
||||
panic!("{}", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pipe_println(
|
||||
($($args:tt)+) => (
|
||||
match writeln!(&mut ::std::io::stdout(), $($args)+) {
|
||||
Ok(_) => true,
|
||||
Err(f) => {
|
||||
if f.kind() == ::std::io::ErrorKind::BrokenPipe {
|
||||
false
|
||||
} else {
|
||||
panic!("{}", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pipe_write(
|
||||
($fd:expr, $($args:tt)+) => (
|
||||
match write!($fd, $($args)+) {
|
||||
Ok(_) => true,
|
||||
Err(f) => {
|
||||
if f.kind() == ::std::io::ErrorKind::BrokenPipe {
|
||||
false
|
||||
} else {
|
||||
panic!("{}", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pipe_writeln(
|
||||
($fd:expr, $($args:tt)+) => (
|
||||
match writeln!($fd, $($args)+) {
|
||||
Ok(_) => true,
|
||||
Err(f) => {
|
||||
if f.kind() == ::std::io::ErrorKind::BrokenPipe {
|
||||
false
|
||||
} else {
|
||||
panic!("{}", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! pipe_flush(
|
||||
() => (
|
||||
match ::std::io::stdout().flush() {
|
||||
Ok(_) => true,
|
||||
Err(f) => {
|
||||
if f.kind() == ::std::io::ErrorKind::BrokenPipe {
|
||||
false
|
||||
} else {
|
||||
panic!("{}", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
($fd:expr) => (
|
||||
match $fd.flush() {
|
||||
Ok(_) => true,
|
||||
Err(f) => {
|
||||
if f.kind() == ::std::io::ErrorKind::BrokenPipe {
|
||||
false
|
||||
} else {
|
||||
panic!("{}", f)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! safe_write(
|
||||
($fd:expr, $($args:tt)+) => (
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
*
|
||||
* (c) Arcterus <arcterus@mail.com>
|
||||
* (c) Alex Lyon <arcterus@mail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue