Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion src/baseconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) ;
}


}

Expand Down Expand Up @@ -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 ;
}

1 change: 1 addition & 0 deletions src/baseconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 16 additions & 12 deletions src/bcvrepl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand All @@ -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) ;
}
}
Expand Down Expand Up @@ -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 ;
}

Expand Down Expand Up @@ -127,6 +118,7 @@ void bcrepl_compute(const char * buffer)
}
if (!out)
return ;

//BCV_ERR()
apply(printf(" |-> %s\012", out) , RED) ;
}
Expand Down Expand Up @@ -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 ;
}

}
2 changes: 2 additions & 0 deletions src/bcvrepl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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