From 733693258c5e2d99515fb4f0cbdd5f4e534fba26 Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Wed, 15 Nov 2023 19:52:55 -0800 Subject: [PATCH] Perform in rust --- src/lib.rs | 2 +- src/sneakers.c | 179 ------------------------------------------------ src/sneakers.rs | 9 +-- 3 files changed, 6 insertions(+), 184 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 81fd0d4..474daf1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,7 +84,7 @@ pub extern "C" fn rust_main() { exec_effect(input, args.autodecrypt, args.mask_blanks, args.clear_screen); } -fn exec_effect(input: String, autodecrypt: bool, maskblank: bool, clear_screen: bool) { +pub(crate) fn exec_effect(input: String, autodecrypt: bool, maskblank: bool, clear_screen: bool) { let maskblank_c = if maskblank { 1 } else { 0 }; let autodecrypt_c = if autodecrypt { 1 } else { 0}; diff --git a/src/sneakers.c b/src/sneakers.c index 3e8b21f..c0df3d5 100644 --- a/src/sneakers.c +++ b/src/sneakers.c @@ -17,184 +17,5 @@ int main(void) { rust_sneakers_effect(); - - int termCols, spaces = 0; - unsigned char *display_uc = NULL; - char *display = NULL; - char *head1Left = "DATANET PROC RECORD: 45-3456-W-3452"; - char *head1Right = "Transnet on/xc-3"; - char *head2Center = "FEDERAL RESERVE TRANSFER NODE"; - char *head3Center = "National Headquarters"; - char *head4Center = "************ Remote Systems Network Input Station ************"; - char *head5Center = "================================================================"; - char *menu1 = "[1] Interbank Funds Transfer (Code Prog: 485-GWU)"; - char *menu2 = "[2] International Telelink Access (Code Lim: XRP-262)"; - char *menu3 = "[3] Remote Facsimile Send/Receive (Code Tran: 2LZP-517)"; - char *menu4 = "[4] Regional Bank Interconnect (Security Code: 47-B34)"; - char *menu5 = "[5] Update System Parameters (Entry Auth. Req.)"; - char *menu6 = "[6] Remote Operator Logon/Logoff"; - char *foot1Center = "================================================================"; - char *foot2Center = "[ ] Select Option or ESC to Abort"; - - // Get terminal dimentions (needed for centering) - struct winsize w; - // if not an interactive tty, w is not populated, resulting in UB - if (ioctl(0, TIOCGWINSZ, &w) == -1) { - perror("Input not from an interactive terminal"); - return 1; - } - termCols = w.ws_col; - - // Allocate space for our display string - if ((display = malloc(20 * termCols)) == NULL) - { - fprintf(stderr, "Memory Allocation Error. Quitting!\n"); - return 1; - } - - // Allocate space for our display string - if ((display_uc = malloc(20 * termCols)) == NULL) - { - free(display); - fprintf(stderr, "Memory Allocation Error. Quitting!\n"); - return 1; - } - - memset(display, 0, 20 * termCols); - memset(display_uc, 0, 20 * termCols); - - // Start building the display string - strcpy(display, head1Left); - - spaces = termCols - strlen(head1Left) - strlen(head1Right); - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, head1Right); - - strcat(display, "\n"); - - spaces = (termCols - strlen(head2Center)) / 2; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, head2Center); - - strcat(display, "\n"); - strcat(display, "\n"); - - spaces = (termCols - strlen(head3Center)) / 2; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, head3Center); - - strcat(display, "\n"); - strcat(display, "\n"); - - spaces = (termCols - strlen(head4Center)) / 2; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, head4Center); - - strcat(display, "\n"); - - spaces = (termCols - strlen(head5Center)) / 2; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, head5Center); - - strcat(display, "\n"); - strcat(display, "\n"); - - spaces = ((termCols - strlen(head5Center)) / 2) + 3; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, menu1); - - strcat(display, "\n"); - - spaces = ((termCols - strlen(head5Center)) / 2) + 3; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, menu2); - - strcat(display, "\n"); - - spaces = ((termCols - strlen(head5Center)) / 2) + 3; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, menu3); - - strcat(display, "\n"); - - spaces = ((termCols - strlen(head5Center)) / 2) + 3; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, menu4); - - strcat(display, "\n"); - - spaces = ((termCols - strlen(head5Center)) / 2) + 3; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, menu5); - - strcat(display, "\n"); - - spaces = ((termCols - strlen(head5Center)) / 2) + 3; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, menu6); - - strcat(display, "\n"); - strcat(display, "\n"); - - spaces = (termCols - strlen(foot1Center)) / 2; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, foot1Center); - - strcat(display, "\n"); - strcat(display, "\n"); - - spaces = (termCols - strlen(foot2Center)) / 2; - while (spaces > 0) { - strcat(display, " "); - --spaces; - } - strcat(display, foot2Center); - - nmseffect_set_clearscr(1); - - memcpy(display_uc, display, 20 * termCols); - - // Execute effect - nmseffect_exec(display_uc, strlen(display), 0, 0, 1); - - free(display); - free(display_uc); - return 0; } diff --git a/src/sneakers.rs b/src/sneakers.rs index 09c193e..1b9c553 100644 --- a/src/sneakers.rs +++ b/src/sneakers.rs @@ -17,7 +17,6 @@ const foot2Center: &str = "[ ] Select Option or ESC to Abort"; #[no_mangle] pub extern "C" fn rust_sneakers_effect() { - println!("Rust sneakers effect"); use std::time::Duration; let (term_width, _term_height) = crossterm::terminal::size().expect("Error reading terminal size"); @@ -61,9 +60,11 @@ pub extern "C" fn rust_sneakers_effect() { buf.push('\n'); }; - println!("{}", buf); + // println!("{}", buf); - let dur = Duration::from_millis(2000); - std::thread::sleep(dur); + // let dur = Duration::from_millis(2000); + // std::thread::sleep(dur); + + crate::exec_effect(buf, false, false, true); }