no-more-secrets-rust/src/lib.rs
2023-07-23 20:18:44 -07:00

64 lines
1.2 KiB
Rust

mod args;
mod color;
use color::Color;
use libc::{c_int, c_void};
use std::process;
const VERSION: &str = "2.0.0";
extern "C" {
fn nmseffect_set_clearscr(_: c_int) -> c_void;
static mut foregroundColor: c_int;
static mut maskBlank: c_int;
static mut autoDecrypt: c_int;
}
#[no_mangle]
pub extern "C" fn rust_main() {
println!("Hello from rust");
let args = match args::parse_arguments() {
Ok(args) => args,
Err(e) => {
println!("{e}");
process::exit(1);
}
};
println!("{:?}", args);
if args.version {
println!("nms version {VERSION}");
process::exit(0);
}
if let Some(color) = args.foreground {
let color = Color::try_from(color).unwrap_or_default();
let n = color as c_int;
unsafe {
foregroundColor = n;
}
}
unsafe {
if args.mask_blanks {
maskBlank = 1;
} else {
maskBlank = 0;
}
}
if args.clear_screen {
unsafe {
nmseffect_set_clearscr(1);
}
}
unsafe {
if args.autodecrypt {
autoDecrypt = 1;
} else {
autoDecrypt = 0;
}
}
}