From 61cd0783ac6ad5e7ae8fc9317c6aeb3d40910845 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Sat, 10 Apr 2021 14:33:45 +0200 Subject: [PATCH] [v0.97] Make loop option work on ARM too --- src/common/printer.c | 70 +++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/src/common/printer.c b/src/common/printer.c index c619f1b..0b78110 100644 --- a/src/common/printer.c +++ b/src/common/printer.c @@ -369,6 +369,33 @@ uint32_t longest_attribute_length(struct ascii* art) { return max; } +bool run_loop_mode() { +#ifdef _WIN32 + if (!SetConsoleCtrlHandler(loop_mode_handler, TRUE)) { + printErr("SetConsoleCtrlHandler failed"); + return false; + } + #else + struct sigaction act; + memset(&act, 0, sizeof(struct sigaction)); + act.sa_handler = loop_mode_handler; + if(sigaction(SIGINT, &act, NULL) == -1) { + perror("sigaction"); + return false; + } + #endif + + while (loop) { + #ifdef _WIN32 + Sleep(1000); + #else + sleep(1); + #endif + } + + return true; +} + #ifdef ARCH_X86 void print_algorithm_intel(struct ascii* art, int n, bool* flag) { for(int i=0; i < LINE_SIZE; i++) { @@ -432,34 +459,7 @@ void print_ascii_x86(struct ascii* art, uint32_t la, void (*callback_print_algor printf("\n"); } -bool run_loop_mode() { -#ifdef _WIN32 - if (!SetConsoleCtrlHandler(loop_mode_handler, TRUE)) { - printErr("SetConsoleCtrlHandler failed"); - return false; - } - #else - struct sigaction act; - memset(&act, 0, sizeof(struct sigaction)); - act.sa_handler = loop_mode_handler; - if(sigaction(SIGINT, &act, NULL) == -1) { - perror("sigaction"); - return false; - } - #endif - - while (loop) { - #ifdef _WIN32 - Sleep(1000); - #else - sleep(1); - #endif - } - - return true; -} - -bool print_ascii(struct ascii* art) { +void print_ascii(struct ascii* art) { uint32_t longest_attribute = longest_attribute_length(art); if(art->vendor == CPU_VENDOR_INTEL) @@ -469,12 +469,6 @@ bool print_ascii(struct ascii* art) { else { printBug("Invalid CPU vendor: %d\n", art->vendor); } - - if(loop_mode()) { - return run_loop_mode(); - } - - return true; } bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) { @@ -532,6 +526,10 @@ bool print_cpufetch_x86(struct cpuInfo* cpu, STYLE s, struct colors* cs) { print_ascii(art); + if(loop_mode()) { + return run_loop_mode(); + } + free(manufacturing_process); free(max_frequency); free(sockets); @@ -738,6 +736,10 @@ bool print_cpufetch_arm(struct cpuInfo* cpu, STYLE s, struct colors* cs) { print_ascii(art); + if(loop_mode()) { + return run_loop_mode(); + } + free(manufacturing_process); free(pp);