Compare commits

...

7 Commits

Author SHA1 Message Date
Greg Shuflin
4b3bf5dc4b Simplify C 2023-07-23 22:21:13 -07:00
Greg Shuflin
d1b289ff8e Remove unused code 2023-07-23 21:01:43 -07:00
Greg Shuflin
9feeb6782b Remove C args 2023-07-23 20:59:42 -07:00
Greg Shuflin
b02247fbe6 Autodecrypt in rust 2023-07-23 20:18:44 -07:00
Greg Shuflin
30b77617e2 Doc comment 2023-07-23 20:16:58 -07:00
Greg Shuflin
1e87c76689 Handle maskblank in rust 2023-07-23 20:13:44 -07:00
Greg Shuflin
2841625b15 handle invalid argument 2023-07-23 20:05:26 -07:00
7 changed files with 36 additions and 145 deletions

View File

@ -12,7 +12,15 @@ pub(crate) struct Args {
///revealed. Valid arguments are "white", "yellow", "magenta", "blue",
///"green", "red", and "cyan".
pub(crate) foreground: Option<OsString>,
/// Set the autoDecrypt flag according to the true/false value of the
/// 'setting' argument. When set to true, nmseffect_exec() will not
/// require a key press to start the decryption effect.
pub(crate) autodecrypt: bool,
/// Set the maskBlank flag according to the true/false value of the
/// 'setting' argument. When set to true, blank spaces characters
/// will be masked as well.
pub(crate) mask_blanks: bool,
}

View File

@ -81,86 +81,3 @@ int input_get(unsigned char** dest, char *prompt)
return input_len;
}
int input_get_str(char** dest, char *prompt)
{
int r, i, input_len;
unsigned char *input;
r = input_get(&input, prompt);
if (r < 0)
{
error_log("Could not get input.");
return -1;
}
if (r > 0)
{
if (input[r - 1] == '\n')
{
--r;
if (r > 0 && input[r - 1] == '\r')
{
--r;
}
}
}
if (r == 0)
{
error_log("No input provided.");
return -1;
}
input_len = r;
*dest = malloc(input_len + 1);
if (*dest == NULL)
{
error_log("Memory allocation error.");
return -1;
}
memset(*dest, 0, input_len + 1);
for (i = 0; i < input_len; ++i)
{
if (isascii(input[i]))
{
(*dest)[i] = input[i];
}
else
{
error_log("Input contains non-ascii characters.");
return -1;
}
}
free(input);
return input_len;
}
int input_get_from_pipe(unsigned char** dest)
{
int r;
if (isatty(STDIN_FILENO))
{
error_log("Input data from a piped or redirected source is required.");
return -1;
}
r = input_get(dest, NULL);
if (r < 0)
{
error_log("Could not get input.");
return -1;
}
if (r == 0)
{
error_log("No input provided.");
return -1;
}
return r;
}

View File

@ -9,7 +9,5 @@
#define INPUT_H 1
int input_get(unsigned char** dest, char *prompt);
int input_get_str(char** dest, char *prompt);
int input_get_from_pipe(unsigned char** dest);
#endif
#endif

View File

@ -3,25 +3,33 @@ 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_autodecrypt(_: c_int) -> c_void;
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 = args::parse_arguments().unwrap();
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}");
std::process::exit(0);
process::exit(0);
}
if let Some(color) = args.foreground {
@ -31,6 +39,13 @@ pub extern "C" fn rust_main() {
foregroundColor = n;
}
}
unsafe {
if args.mask_blanks {
maskBlank = 1;
} else {
maskBlank = 0;
}
}
if args.clear_screen {
unsafe {
@ -38,9 +53,11 @@ pub extern "C" fn rust_main() {
}
}
if args.autodecrypt {
unsafe {
nmseffect_set_autodecrypt(1);
unsafe {
if args.autodecrypt {
autoDecrypt = 1;
} else {
autoDecrypt = 0;
}
}
}

View File

@ -20,33 +20,9 @@ extern void rust_main();
int main(int argc, char *argv[])
{
rust_main();
int r, o;
unsigned char *input;
unsigned char *input = NULL;
input = NULL;
while ((o = getopt(argc, argv, "f:ascv")) != -1)
{
switch (o)
{
case 's':
nmseffect_set_maskblank(1);
break;
case '?':
if (isprint(optopt))
{
error_log("Unknown option '-%c'.", optopt);
}
else
{
error_log("Unknown option character '\\x%x'.", optopt);
}
error_print();
return EXIT_FAILURE;
}
}
r = input_get(&input, "Enter input: ");
int r = input_get(&input, "Enter input: ");
if (r < 0)
{
error_log("Could not get input.");

View File

@ -32,8 +32,8 @@
#define REVEAL_LOOP_SPEED 50 // miliseconds between each reveal loop
// Behavior settings
static int autoDecrypt = 0; // Auto-decrypt flag
static int maskBlank = 0; // Mask blank spaces
int autoDecrypt = 0; // Auto-decrypt flag
int maskBlank = 0; // Mask blank spaces
static int colorOn = 1; // Terminal color flag
// Character attribute structure, linked list. Keeps track of every
@ -290,29 +290,6 @@ char nmseffect_exec(unsigned char *string, int string_len) {
return ret;
}
/*
* Set the autoDecrypt flag according to the true/false value of the
* 'setting' argument. When set to true, nmseffect_exec() will not
* require a key press to start the decryption effect.
*/
void nmseffect_set_autodecrypt(int setting) {
if (setting)
autoDecrypt = 1;
else
autoDecrypt = 0;
}
/*
* Set the maskBlank flag according to the true/false value of the
* 'setting' argument. When set to true, blank spaces characters
* will be masked as well.
*/
void nmseffect_set_maskblank(int setting) {
if (setting)
maskBlank = 1;
else
maskBlank = 0;
}
/*
* Pass the 'setting' argument to the nmstermio module where it will set

View File

@ -11,8 +11,6 @@
// Function prototypes
char nmseffect_exec(unsigned char *, int string_len);
void nmseffect_set_returnopts(char *);
void nmseffect_set_autodecrypt(int);
void nmseffect_set_maskblank(int);
void nmseffect_set_clearscr(int);
void nmseffect_use_color(int);
void nmseffect_set_input_position(int, int);