mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-05 07:27: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;
|
extern crate getopts;
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
pub struct HelpText<'a> {
|
pub struct HelpText<'a> {
|
||||||
pub name : &'a str,
|
pub name : &'a str,
|
||||||
|
@ -53,8 +52,8 @@ impl<'a> CoreOptions<'a> {
|
||||||
let matches = match self.options.parse(&args[1..]) {
|
let matches = match self.options.parse(&args[1..]) {
|
||||||
Ok(m) => { Some(m) },
|
Ok(m) => { Some(m) },
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
pipe_write!(&mut ::std::io::stderr(), "{}: error: ", self.help_text.name);
|
eprint!("{}: error: ", self.help_text.name);
|
||||||
pipe_writeln!(&mut ::std::io::stderr(), "{}", f);
|
eprintln!("{}", f);
|
||||||
::std::process::exit(1);
|
::std::process::exit(1);
|
||||||
}
|
}
|
||||||
}.unwrap();
|
}.unwrap();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* 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
|
* 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.
|
||||||
|
@ -22,46 +22,36 @@ macro_rules! executable(
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! show_error(
|
macro_rules! show_error(
|
||||||
($($args:tt)+) => ({
|
($($args:tt)+) => ({
|
||||||
pipe_write!(&mut ::std::io::stderr(), "{}: error: ", executable!());
|
eprint!("{}: error: ", executable!());
|
||||||
pipe_writeln!(&mut ::std::io::stderr(), $($args)+);
|
eprintln!($($args)+);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! show_warning(
|
macro_rules! show_warning(
|
||||||
($($args:tt)+) => ({
|
($($args:tt)+) => ({
|
||||||
pipe_write!(&mut ::std::io::stderr(), "{}: warning: ", executable!());
|
eprint!("{}: warning: ", executable!());
|
||||||
pipe_writeln!(&mut ::std::io::stderr(), $($args)+);
|
eprintln!($($args)+);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! show_info(
|
macro_rules! show_info(
|
||||||
($($args:tt)+) => ({
|
($($args:tt)+) => ({
|
||||||
pipe_write!(&mut ::std::io::stderr(), "{}: ", executable!());
|
eprint!("{}: ", executable!());
|
||||||
pipe_writeln!(&mut ::std::io::stderr(), $($args)+);
|
eprintln!($($args)+);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! disp_err(
|
macro_rules! disp_err(
|
||||||
($($args:tt)+) => ({
|
($($args:tt)+) => ({
|
||||||
pipe_write!(&mut ::std::io::stderr(), "{}: ", executable!());
|
eprint!("{}: ", executable!());
|
||||||
pipe_writeln!(&mut ::std::io::stderr(), $($args)+);
|
eprintln!($($args)+);
|
||||||
pipe_writeln!(&mut ::std::io::stderr(), "Try '{} --help' for more information.", executable!());
|
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_export]
|
||||||
macro_rules! crash(
|
macro_rules! crash(
|
||||||
($exitcode:expr, $($args:tt)+) => ({
|
($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_export]
|
||||||
macro_rules! return_if_err(
|
macro_rules! return_if_err(
|
||||||
($exitcode:expr, $exp:expr) => (
|
($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_export]
|
||||||
macro_rules! safe_write(
|
macro_rules! safe_write(
|
||||||
($fd:expr, $($args:tt)+) => (
|
($fd:expr, $($args:tt)+) => (
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* 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
|
* 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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue