Compare commits

..

No commits in common. "4b3bf5dc4ba445bb3e414339af87dc5f9e6e1d68" and "4f74c2f8cd7506286db7d94669a8b126d700ca33" have entirely different histories.

7 changed files with 145 additions and 36 deletions

View File

@ -12,15 +12,7 @@ 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,3 +81,86 @@ 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,5 +9,7 @@
#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

View File

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

View File

@ -20,9 +20,33 @@ extern void rust_main();
int main(int argc, char *argv[])
{
rust_main();
unsigned char *input = NULL;
int r, o;
unsigned char *input;
int r = input_get(&input, "Enter input: ");
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: ");
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
int autoDecrypt = 0; // Auto-decrypt flag
int maskBlank = 0; // Mask blank spaces
static int autoDecrypt = 0; // Auto-decrypt flag
static int maskBlank = 0; // Mask blank spaces
static int colorOn = 1; // Terminal color flag
// Character attribute structure, linked list. Keeps track of every
@ -290,6 +290,29 @@ 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,6 +11,8 @@
// 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);