no-more-secrets-rust/src/lib.rs

62 lines
1.2 KiB
Rust
Raw Normal View History

2023-07-23 03:04:59 -07:00
mod args;
2023-07-23 19:52:25 -07:00
mod color;
2023-07-23 03:03:23 -07:00
2023-07-23 19:52:25 -07:00
use color::Color;
2023-07-23 20:01:02 -07:00
use libc::{c_int, c_void};
2023-07-23 20:05:26 -07:00
use std::process;
2023-07-23 03:14:38 -07:00
2023-07-23 19:52:25 -07:00
const VERSION: &str = "2.0.0";
2023-07-23 03:19:40 -07:00
2023-07-23 03:14:49 -07:00
extern "C" {
fn nmseffect_set_autodecrypt(_: c_int) -> c_void;
2023-07-23 03:19:40 -07:00
fn nmseffect_set_clearscr(_: c_int) -> c_void;
2023-07-23 19:35:15 -07:00
static mut foregroundColor: c_int;
2023-07-23 20:13:44 -07:00
static mut maskBlank: c_int;
2023-07-23 03:14:38 -07:00
}
2023-07-23 03:03:23 -07:00
#[no_mangle]
pub extern "C" fn rust_main() {
println!("Hello from rust");
2023-07-23 03:14:38 -07:00
2023-07-23 20:05:26 -07:00
let args = match args::parse_arguments() {
Ok(args) => args,
Err(e) => {
println!("{e}");
process::exit(1);
}
};
2023-07-23 19:52:25 -07:00
println!("{:?}", args);
2023-07-23 03:14:38 -07:00
2023-07-23 03:19:40 -07:00
if args.version {
println!("nms version {VERSION}");
2023-07-23 20:05:26 -07:00
process::exit(0);
2023-07-23 03:19:40 -07:00
}
2023-07-23 19:52:25 -07:00
if let Some(color) = args.foreground {
let color = Color::try_from(color).unwrap_or_default();
let n = color as c_int;
2023-07-23 19:35:15 -07:00
unsafe {
2023-07-23 19:52:25 -07:00
foregroundColor = n;
2023-07-23 19:35:15 -07:00
}
}
2023-07-23 20:13:44 -07:00
unsafe {
if args.mask_blanks {
maskBlank = 1;
} else {
maskBlank = 0;
}
}
2023-07-23 19:35:15 -07:00
2023-07-23 03:19:40 -07:00
if args.clear_screen {
unsafe {
nmseffect_set_clearscr(1);
}
}
2023-07-23 03:14:38 -07:00
if args.autodecrypt {
unsafe {
nmseffect_set_autodecrypt(1);
}
}
2023-07-23 03:03:23 -07:00
}