Compare commits

...

10 Commits

Author SHA1 Message Date
Greg Shuflin c334492ea9 More args in rust 2023-07-23 03:19:40 -07:00
Greg Shuflin 78fb4ecbfc cargo fmt 2023-07-23 03:14:49 -07:00
Greg Shuflin c280dbe716 Call a method from rust 2023-07-23 03:14:38 -07:00
Greg Shuflin d7b402c764 Arg parsing in rust 2023-07-23 03:04:59 -07:00
Greg Shuflin ec74203e70 Start porting to rust 2023-07-23 03:03:23 -07:00
Brian Barto cb4873e2ab Update ToC
modified:   README.md
2023-02-17 12:18:55 -05:00
Brian Barto 9e23931041 Replace tips section with link to sonsors page.
modified:   README.md
2023-02-17 11:37:40 -05:00
Brian Barto 8842fb7e04 Update funding file
modified:   .github/FUNDING.yml
2022-06-30 13:06:40 -04:00
Brian Barto 8a326f8ef4 Update funding file
modified:   .github/FUNDING.yml
2022-06-30 13:04:03 -04:00
Brian Barto d124669e02 Testing the FUNDING file
new file:   .github/FUNDING.yml
2022-06-30 13:00:46 -04:00
9 changed files with 127 additions and 16 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: bartobri

5
.gitignore vendored
View File

@ -1,3 +1,8 @@
bin/*
obj/*
.vs
# Added by cargo
/target

23
Cargo.lock generated Normal file
View File

@ -0,0 +1,23 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "lexopt"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baff4b617f7df3d896f97fe922b64817f6cd9a756bb81d40f8883f2f66dcb401"
[[package]]
name = "libc"
version = "0.2.147"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3"
[[package]]
name = "nmsrust"
version = "0.1.0"
dependencies = [
"lexopt",
"libc",
]

15
Cargo.toml Normal file
View File

@ -0,0 +1,15 @@
[package]
name = "nmsrust"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["staticlib"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
lexopt = "0.3.0"
libc = "0.2.147"

View File

@ -18,7 +18,7 @@ CFLAGS ?= -Wextra -Wall -O2
.PHONY: all install uninstall clean
nms: $(OBJ)/input.o $(OBJ)/error.o $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/nms.o | $(BIN)
$(CC) $(CFLAGS) -o $(BIN)/$@ $^
$(CC) $(CFLAGS) -o $(BIN)/$@ $^ target/release/libnmsrust.a
sneakers: $(OBJ)/nmscharset.o $(OBJ)/nmstermio.o $(OBJ)/nmseffect.o $(OBJ)/sneakers.o | $(BIN)
$(CC) $(CFLAGS) -o $(BIN)/$@ $^

View File

@ -1,5 +1,7 @@
![Version](https://img.shields.io/badge/Version-1.0.1-green.svg)
Like this project? Consider tipping me: [https://github.com/sponsors/bartobri](https://github.com/sponsors/bartobri)
No More Secrets
===============
@ -33,7 +35,6 @@ Table of Contents
2. [Usage](#usage)
3. [The NMS Library](#the-nms-library)
4. [License](#license)
5. [Tips](#tips)
Download and Install
--------------------
@ -143,8 +144,3 @@ License
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License. See [LICENSE](LICENSE) for
more details.
Tips
----
[Tips are always appreciated!](https://github.com/bartobri/tips)

42
src/args.rs Normal file
View File

@ -0,0 +1,42 @@
use std::ffi::OsString;
use lexopt::prelude::*;
#[derive(Debug, Default)]
pub(crate) struct Args {
pub(crate) version: bool,
pub(crate) clear_screen: bool,
pub(crate) foreground: Option<OsString>,
pub(crate) autodecrypt: bool,
pub(crate) mask_blanks: bool,
}
pub(crate) fn parse_arguments() -> Result<Args, lexopt::Error> {
let mut parser = lexopt::Parser::from_env();
let mut args = Args::default();
while let Some(arg) = parser.next()? {
match arg {
Short('a') => {
args.autodecrypt = true;
}
Short('c') => {
args.clear_screen = true;
}
Short('f') => {
let foreground = parser.value()?;
args.foreground = Some(foreground);
}
Short('s') => {
args.mask_blanks = true;
}
Short('v') => {
args.version = true;
}
_ => return Err(arg.unexpected()),
}
}
Ok(args)
}

35
src/lib.rs Normal file
View File

@ -0,0 +1,35 @@
mod args;
use libc::{c_int, c_void};
const VERSION: &str = "2.0.0";
extern "C" {
fn nmseffect_set_autodecrypt(_: c_int) -> c_void;
fn nmseffect_set_clearscr(_: c_int) -> c_void;
}
#[no_mangle]
pub extern "C" fn rust_main() {
println!("Hello from rust");
let args = args::parse_arguments().unwrap();
if args.version {
println!("nms version {VERSION}");
std::process::exit(0);
}
if args.clear_screen {
unsafe {
nmseffect_set_clearscr(1);
}
}
if args.autodecrypt {
unsafe {
nmseffect_set_autodecrypt(1);
}
}
println!("{:?}", args);
}

View File

@ -15,8 +15,11 @@
#define VERSION "1.0.1"
extern void rust_main();
int main(int argc, char *argv[])
{
rust_main();
int r, o;
unsigned char *input;
@ -29,18 +32,9 @@ int main(int argc, char *argv[])
case 'f':
nmseffect_set_foregroundcolor(optarg);
break;
case 'a':
nmseffect_set_autodecrypt(1);
break;
case 's':
nmseffect_set_maskblank(1);
break;
case 'c':
nmseffect_set_clearscr(1);
break;
case 'v':
printf("nms version " VERSION "\n");
return EXIT_SUCCESS;
case '?':
if (isprint(optopt))
{