From 9ac06af335c5c9b2e2da041c363afa14db50bd71 Mon Sep 17 00:00:00 2001 From: jukoo Date: Sat, 21 Feb 2026 13:35:30 +0000 Subject: [PATCH] a dedicated helper and show only printable char --- main.c | 21 --------------------- src/baseconv.c | 17 ++++++++++++++++- src/baseconv.h | 1 + src/bcvrepl.c | 28 ++++++++++++++++------------ src/bcvrepl.h | 2 ++ 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/main.c b/main.c index 665894c..9178ed9 100644 --- a/main.c +++ b/main.c @@ -17,7 +17,6 @@ #include "bcvrepl.h" void bcv_usage(unsigned char const) ; /* [[noreturn]] */ -void bcv_guess_base(const char * __restrict__) ; /* [[noreturn]] */ int main(int ac , char **av) { @@ -95,26 +94,6 @@ int main(int ac , char **av) return EXIT_SUCCESS ; } - -void bcv_print(uf64_t value) -{ - if((__allbase_enable__ >> 32)& 0x64) - bcv_out(bc_dec(value), DEC); - - if(__allbase_enable__ & HEX) - bcv_out(bc_hex(value), HEX); - - if(__allbase_enable__ & OCT) - bcv_out(bc_oct(value) , OCT); - - if(__allbase_enable__ & BIN) - bcv_out(bc_bin(value), BIN); - - if(__allbase_enable__ & CHR) - bcv_out(bc_chr(value), CHR) ; - -} - void bcv_usage(unsigned char const char_flag) { switch(char_flag) diff --git a/src/baseconv.c b/src/baseconv.c index abbf705..ec978e5 100644 --- a/src/baseconv.c +++ b/src/baseconv.c @@ -89,7 +89,12 @@ void bcv_print(uf64_t value) bcv_out(bc_bin(value), BIN); if(__allbase_enable__ & CHR) - bcv_out(bc_chr(value), CHR) ; + { + const char *s = bc_chr(value) ; + if(is_printable(s)) + bcv_out(s , CHR) ; + } + } @@ -138,4 +143,14 @@ void bcv_guess_base(const char * restrict num) return ; } +//!NOTE : for all the different variations of the ASCII table, +// : Only printable characters, represent letters, digits, punctuation marks, and a few miscellaneous symbols. +// : You will find almost every character on your keyboard. +// +//!WARNING : The extended ASCII code are not yet supported +static int is_printable(const char * ascii_code) +{ + unsigned char code = (*ascii_code& 0xff) ; + return (0x20 < code) ? ( code < 0x7f ) : 0 ; +} diff --git a/src/baseconv.h b/src/baseconv.h index 8a136bc..650e3ac 100644 --- a/src/baseconv.h +++ b/src/baseconv.h @@ -184,4 +184,5 @@ __BCX(void) bcv_print(uf64_t value) ; __BCX(void) bcv_guess_base(const char * rawinput) ; +static int is_printable(const char *code_ascii); #endif //!__BASECONV diff --git a/src/bcvrepl.c b/src/bcvrepl.c index 7e435f8..a8cc58a 100644 --- a/src/bcvrepl.c +++ b/src/bcvrepl.c @@ -22,8 +22,8 @@ void bcrepl_shell(const char * prompt) fprintf(stdout , "%s" , BCV_STARTUP_MESG) ; while (proceed, ++line) { - //!repl_promt + //!BCV_SUCCESS() apply( printf(bpf, line, prmpt , bcrepl_symbole_prompt) , GREEN) ; if(!(fgets(prompt_buffer , bcrepl_buffer_limit, stdin))) @@ -34,9 +34,8 @@ void bcrepl_shell(const char * prompt) if (0==strlen(prompt_buffer)) continue ; bcrepl_compute(prompt_buffer) ; - /* NOTICE :always clean the repl buffer */ + bzero(prompt_buffer , bcrepl_buffer_limit) ; - fflush(stdin) ; } } @@ -81,16 +80,8 @@ void bcrepl_compute(const char * buffer) { value = strtol(buffer_clone , 00 , 10) ; value ? bcv_print(value) : bcv_guess_base(buffer_clone) ; - - switch(*buffer_clone & 0xff) - { - case '?': - case 'h': fprintf(stdout , "%s%s\12" , USAGE , BCV_VERSION_STR); break; - case '!': - case 'v': fprintf(stdout , "%s\012", BCV_STARTUP_MESG) ; break ; - } + bcrepl_show_helper(buffer_clone) ; - return ; } @@ -127,6 +118,7 @@ void bcrepl_compute(const char * buffer) } if (!out) return ; + //BCV_ERR() apply(printf(" |-> %s\012", out) , RED) ; } @@ -189,3 +181,15 @@ uf64_t bcrepl_process(const char * buffer , const char ftokn) } return vtok ; } + +static void bcrepl_show_helper(const char repl_buffer[static 1]) +{ + switch( *repl_buffer & 0xff) + { + case '?': + case 'h': fprintf(stdout , "%s%s\12" , USAGE , BCV_VERSION_STR); break; + case '!': + case 'v': fprintf(stdout , "%s\012", BCV_STARTUP_MESG) ; break ; + } + +} diff --git a/src/bcvrepl.h b/src/bcvrepl.h index c83306f..b08c5f7 100644 --- a/src/bcvrepl.h +++ b/src/bcvrepl.h @@ -116,4 +116,6 @@ bcvrepl_export char * bcrepl_token_search(const char * __restrict__) ; bcvrepl_export uf64_t bcrepl_process(const char * buffer , char founded_token) ; + +static void bcrepl_show_helper(const char buffer [ static 1 ]) ; #endif //!bcv_repl_h