added YacError type, returned from rust_main()
This commit is contained in:
parent
d2af983f4a
commit
87abddd277
|
@ -15,6 +15,5 @@ libc-print = "0.1.21"
|
||||||
bindgen = "0.63.0"
|
bindgen = "0.63.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "entry", "errors"]
|
default = [ "entry" ]
|
||||||
entry = []
|
entry = []
|
||||||
errors = []
|
|
||||||
|
|
|
@ -31,3 +31,10 @@ impl From<YacError> for (String, u32) {
|
||||||
(err.message, err.code)
|
(err.message, err.code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<(String, u32)> for YacError {
|
||||||
|
fn from(err: (String, u32)) -> Self {
|
||||||
|
let (message, code) = err;
|
||||||
|
YacError { message, code }
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
mod args;
|
mod args;
|
||||||
|
mod errors;
|
||||||
pub use args::Args;
|
pub use args::Args;
|
||||||
|
pub use errors::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
exit,
|
exit,
|
||||||
|
@ -34,7 +36,7 @@ pub unsafe fn c_str_to_rust_unchecked(ptr: *const u8) -> &'static str {
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "Rust" {
|
extern "Rust" {
|
||||||
fn rust_main(args: args::Args) -> Result<u32, (alloc::string::String, u32)>;
|
fn rust_main(args: args::Args) -> Result<u32, YacError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
@ -50,11 +52,11 @@ pub unsafe extern fn main(argc: c_int, argv: *const *const u8) -> c_int {
|
||||||
libc_eprintln!("Unable to ascertain argv[0].");
|
libc_eprintln!("Unable to ascertain argv[0].");
|
||||||
exit(71);
|
exit(71);
|
||||||
});
|
});
|
||||||
rust_main(args).unwrap_or_else(|(err, code)| {
|
rust_main(args).unwrap_or_else(|err| {
|
||||||
if code == EX_USAGE {
|
if err.code == EX_USAGE {
|
||||||
libc_eprintln!("Usage: {} {}", argv0, err);
|
libc_eprintln!("Usage: {} {}", argv0, err.message);
|
||||||
} else { libc_eprintln!("{}: {}", argv0, err); }
|
} else { libc_eprintln!("{}: {}", argv0, err.message); }
|
||||||
code
|
err.code
|
||||||
}) as _
|
}) as _
|
||||||
},
|
},
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
|
@ -72,11 +72,9 @@ extern crate core;
|
||||||
|
|
||||||
#[cfg(feature = "entry")]
|
#[cfg(feature = "entry")]
|
||||||
mod entry;
|
mod entry;
|
||||||
#[cfg(feature = "errors")]
|
|
||||||
mod errors;
|
|
||||||
|
|
||||||
pub use entry::Args;
|
#[cfg(feature = "entry")]
|
||||||
pub use errors::*;
|
pub use entry::*;
|
||||||
|
|
||||||
pub fn exit(code: u32) -> ! {
|
pub fn exit(code: u32) -> ! {
|
||||||
unsafe { libc::exit(code as i32 as libc::c_int); }
|
unsafe { libc::exit(code as i32 as libc::c_int); }
|
||||||
|
|
Reference in New Issue