1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

use crash! macro in echo

This commit is contained in:
Heather 2014-02-05 14:40:22 +04:00
parent f6c46024e8
commit d8896a18d1

View file

@ -1,3 +1,4 @@
#[feature(macro_rules)];
#[crate_id(name="echo", vers="1.0.0", author="Derek Chiang")]; #[crate_id(name="echo", vers="1.0.0", author="Derek Chiang")];
/* /*
@ -12,12 +13,22 @@
extern mod extra; extern mod extra;
use std::os; use std::os;
use std::io::{print, println, stderr}; use std::io::{print, println};
use std::uint; use std::uint;
use extra::getopts::groups; use extra::getopts::groups;
static VERSION: &'static str = "1.0.0"; static VERSION: &'static str = "1.0.0";
#[macro_export]
macro_rules! crash(
($exitcode:expr, $($args:expr),+) => (
{ ::std::os::set_exit_status($exitcode);
let _unused = write!(&mut ::std::io::stderr(), $($args),+);
return;
}
)
)
fn print_char(c: char) { fn print_char(c: char) {
print!("{}", c); print!("{}", c);
} }
@ -77,12 +88,7 @@ fn main() {
let matches = match groups::getopts(args.tail(), opts) { let matches = match groups::getopts(args.tail(), opts) {
Ok(m) => m, Ok(m) => m,
Err(f) => { Err(f) => crash!(1, "Invalid options\n{}", f.to_err_msg())
writeln!(&mut stderr() as &mut Writer,
"Invalid options\n{}", f.to_err_msg());
os::set_exit_status(1);
return
}
}; };
if matches.opt_present("help") { if matches.opt_present("help") {