diff --git a/README.md b/README.md
index 3d64150..e7c226a 100644
--- a/README.md
+++ b/README.md
@@ -133,16 +133,18 @@ read -p "Entrer un nombre : " n
bcv $n
```
-#### Auteur
-Umar Ba
-jUmarB@protonmail.com
-đ github.com/Jukoo
+### Auteur & Mainteneur
+Umar Ba [jUmarB@protonmail.com](jUmarB@protonmail.com)
+_KerHack-Libre_ : â**comprendre**, **construire**, **transmettre**.â
+
#### âïž Licence
Copyright (c) 2025
KerHack-Libre â Logiciel libre et distribuĂ© sans AUCUNE GARANTIE.
+_Lâensemble des projets de KĂ«rHack-Libre sont distribuĂ©s sous GPLv3,
+en accord avec les **4 libertés fondamentales du logiciel libre**_
#### Contribuer
@@ -153,12 +155,5 @@ Si tu veux participer :
* Soumets une pull request
* Ou simplement partage bcv avec dâautres passionnĂ©s du shell !
-##### Ă propos de KerHack-Libre
-
-KerHack-Libre est une initiative qui vise à promouvoir des outils systÚmes libres, légers et éducatifs,
-inspirés de la philosophie Unix et du pragmatisme du libre.
-
-« Faire simple, efficace et libre. »
-
-
+
diff --git a/assets/logo/bcvlogo.png b/assets/logo/bcvlogo.png
index 2f86300..fb62e07 100644
Binary files a/assets/logo/bcvlogo.png and b/assets/logo/bcvlogo.png differ
diff --git a/assets/logo/made_in_senegal.png b/assets/logo/made_in_senegal.png
new file mode 100644
index 0000000..6b96e17
Binary files /dev/null and b/assets/logo/made_in_senegal.png differ
diff --git a/main.c b/main.c
index 8f6febb..665894c 100644
--- a/main.c
+++ b/main.c
@@ -16,16 +16,8 @@
#include "baseconv.h"
#include "bcvrepl.h"
-#define UMAX_LONG ~((0ULL)>>1)
-
-#define bcv_out(__expression ,__annotation) \
- fprintf(stdout , "%s: %s\012", #__annotation , __expression)
-
-
-
void bcv_usage(unsigned char const) ; /* [[noreturn]] */
void bcv_guess_base(const char * __restrict__) ; /* [[noreturn]] */
-void bcv_print(uf64_t value) ;
int main(int ac , char **av)
{
@@ -37,6 +29,7 @@ int main(int ac , char **av)
if (!(ac &~(1)))
{
//! launch interactive shell
+ (void) setlinebuf(stdin) ;
bcrepl_shell(__nptr);
goto _bcv_end;
}
@@ -52,10 +45,13 @@ int main(int ac , char **av)
bcv_usage(*(short_flags+1) & 0xff);
if(!(0x30 ^ (*(short_flags) & 0xff)))
+ {
bcv_guess_base(short_flags) ;
+ return EXIT_SUCCESS ;
+ }
uf64_t value = strtol(short_flags , (void *)00 , 10) ;
- if (!value)
+ if (!value)
value = (unsigned char)(*(short_flags)&0xff);
bcv_print(value);
@@ -112,7 +108,7 @@ void bcv_print(uf64_t value)
bcv_out(bc_oct(value) , OCT);
if(__allbase_enable__ & BIN)
- bcv_out(bc_bin(value) , BIN);
+ bcv_out(bc_bin(value), BIN);
if(__allbase_enable__ & CHR)
bcv_out(bc_chr(value), CHR) ;
@@ -133,49 +129,3 @@ void bcv_usage(unsigned char const char_flag)
exit(EXIT_SUCCESS) ;
}
-
-void bcv_guess_base(const char * restrict num)
-{
-
- uf64_t options = __allbase_enable__,
- resolve_option=__allbase_enable__,
- value = 0 ;
- char indicator = tolower(*(num+1) & 0xff ) ;
-
- switch(indicator)
- {
- case 'x' :
- options&=~HEX;
- value = strtol((num+2), (void *)0 , 0x10) ;
- break;
- case 'o' :
- options&=~OCT ;
- value = strtol((num+2), (void *)0 , 010);
- break;
- case 'b' :
- options&=~BIN ;
- value = strtol((num+2), (void *)0 , 2) ;
- break;
- case 'c':
- options &=~CHR;
- value = strtol((num+2), (void*)0 , 10) ;
- break;
- default :
- //! it's highly a decimal
- options&=~429496729600 ;
- value = strtol(num, (void*)0 , 10) ;
- goto _end;
- }
-
-
- uf64_t exclude= (__allbase_enable__ ^ options) ;
- __allbase_enable__^=exclude;
- bcv_print(value) ;
-
- __allbase_enable__ = resolve_option ;
-
-_end:
- exit(EXIT_SUCCESS) ;
-}
-
-
diff --git a/src/baseconv.c b/src/baseconv.c
index e59c3bc..abbf705 100644
--- a/src/baseconv.c
+++ b/src/baseconv.c
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
#include "baseconv.h"
char bc_global_buffer[0xff]={0} ;
@@ -49,7 +50,7 @@ char * bc_chr( uf64_t value)
unsigned char i = ~7 ,
offset_idx = 0;
bzero(bc_global_buffer , 0xff);
- while ( (i < byte_size) , i+=-~7) ;
+ while ( (i < byte_size) , i+=-~7) ;
{
sprintf((bc_global_buffer+offset_idx), "%c" , (value>>i) & 0xff) ;
offset_idx=-~offset_idx;
@@ -69,6 +70,72 @@ void bc_binv2( uf64_t value , int show_notation)
section_bin+=~(section_bin^section_bin) ;
}
- puts("") ;
+ putchar(012);
}
+
+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_guess_base(const char * restrict num)
+{
+
+ uf64_t options = __allbase_enable__,
+ resolve_option=__allbase_enable__,
+ value = 0 ;
+ char indicator = tolower(*(num+1) & 0xff ) ;
+
+ switch(indicator)
+ {
+ case 'x' :
+ options&=~HEX;
+ value = strtol((num+2), (void *)0 , 0x10) ;
+ break;
+ case 'o' :
+ options&=~OCT ;
+ value = strtol((num+2), (void *)0 , 010);
+ break;
+ case 'b' :
+ options&=~BIN ;
+ value = strtol((num+2), (void *)0 , 2) ;
+ break;
+ case 'c':
+ options &=~CHR;
+ value = strtol((num+2), (void*)0 , 10) ;
+ break;
+ default :
+ //! decimal
+ options&=~429496729600 ;
+ value = strtol(num, (void*)0 , 10) ;
+ goto _end;
+ }
+
+
+ uf64_t exclude= (__allbase_enable__ ^ options) ;
+ __allbase_enable__^=exclude;
+ bcv_print(value) ;
+
+ __allbase_enable__ = resolve_option ;
+
+_end:
+ return ;
+}
+
+
diff --git a/src/baseconv.h b/src/baseconv.h
index efd905f..8a136bc 100644
--- a/src/baseconv.h
+++ b/src/baseconv.h
@@ -56,6 +56,7 @@
}\
}
+
#define SHOWHEX(__expr, __it ,__out) \
SHOWBASE_EXPR(__expr ,__it, "0x","%c", __out)
@@ -65,6 +66,13 @@
#define SHOWBIN(__expr , __it,__out)\
SHOWBASE_EXPR(__expr ,__it, "0b","%i", __out)
+
+#define UMAX_LONG ~((0ULL)>>1)
+#define bcv_out(__expression ,__annotation) \
+ fprintf(stdout , "%s: %s\012", #__annotation , __expression)
+
+
+
#define USAGE "\
Usage : bcv [OPTION] ... \n\
Convert Number to specific base\n\
@@ -171,6 +179,9 @@ __BCX(char *) bc_oct(uf64_t value) ;
__BCX(char *) bc_hex(uf64_t value) ;
__BCX(char *) bc_dec(uf64_t value) ;
__BCX(char *) bc_chr(uf64_t value) ;
+__BCX(void) bcv_print(uf64_t value) ;
+
+__BCX(void) bcv_guess_base(const char * rawinput) ;
#endif //!__BASECONV
diff --git a/src/bcvrepl.c b/src/bcvrepl.c
index cc9d539..7e435f8 100644
--- a/src/bcvrepl.c
+++ b/src/bcvrepl.c
@@ -7,7 +7,7 @@
#include
#include
#include
-#include
+#include
#include "bcvrepl.h"
#include "baseconv.h"
@@ -44,69 +44,80 @@ void bcrepl_shell(const char * prompt)
void bcrepl_customize(user_prompt_custom_shell custom_prompt , const char * prompt)
{
if(!custom_prompt)
- bcrepl_shell( prompt ) ;
- else
- custom_prompt(prompt) ;
+ {
+ bcrepl_shell( prompt ) ;
+ return ;
+ }
+
+ custom_prompt(prompt) ;
+}
+
+char * bcrepl_token_search(const char * bcrpl_inline_buffer)
+{
+ const char token_list[]= BCVRPL_SEPS ;
+ char *token_found = 00 ;
+ unsigned int i = 0 ;
+
+ while(!(token_found = strchr(bcrpl_inline_buffer , *(token_list+i)))) i=-~i ;
+
+ return token_found ;
}
+
void bcrepl_compute(const char * buffer)
{
- bcrepl_listen_special_cmd(buffer) ;
- struct bcv_parse_t {
- char _sym_instruction:8;
- int _value ;
- } bcv_scaner = { 0,0 };
+ char *should_be_tokinezed = 00,
+ *buffer_clone = (char*) buffer ,
+ toksymb = 0 ;
- char *buffer_clone = (char *) buffer,
- *token = __nptr ;
- int scan_limite= 2 ;
- while( __nptr != (token = strtok(buffer_clone , (const char []) { 0x2f , 00 } )))
- {
- if(scan_limite & 0x2)
- {
- bcv_scaner._sym_instruction= (char) *token & 0xff ;
- buffer_clone = __nptr;
- }
- if(scan_limite & 0x1)
+ uf64_t vtok =0 , value =0 ;
+
+ bcrepl_listen_special_cmd(buffer) ;
+ should_be_tokinezed = bcrepl_token_search(buffer_clone) ;
+ if(0 < strlen(should_be_tokinezed))
+ vtok = bcrepl_process(buffer_clone , *(should_be_tokinezed) & 0xff);
+ else
+ {
+ value = strtol(buffer_clone , 00 , 10) ;
+ value ? bcv_print(value) : bcv_guess_base(buffer_clone) ;
+
+ switch(*buffer_clone & 0xff)
{
- bcv_scaner._value = strtol(token , __nptr , 0xa) ;
- if(!bcv_scaner._value)
- bcv_scaner._value = (unsigned char ) (*(token) & 0xff) ;
-
- if(errno!= 0)
- {
- fprintf(stderr , "%s \012", strerror(*__errno_location())) ;
- bcv_scaner._value = 0;
- }
+ case '?':
+ case 'h': fprintf(stdout , "%s%s\12" , USAGE , BCV_VERSION_STR); break;
+ case '!':
+ case 'v': fprintf(stdout , "%s\012", BCV_STARTUP_MESG) ; break ;
}
+
- if(scan_limite ==0) break ;
- scan_limite+=~(scan_limite^scan_limite) ;
- }
- if(!token)
- bcv_scaner._sym_instruction='a';
+ return ;
+ }
+
+ toksymb = (vtok >> 0x20) & 0xff ;
+ value = (vtok & 0xffffffff);
+
+ if(!toksymb)
+ {
+ bcv_print(value) ;
+ return ;
+ }
+ //bcrepl_inline_out_convertion(toksymb) ;
char *out = (void *)0 ;
- switch(bcv_scaner._sym_instruction & 0xff )
+ switch( toksymb )
{
case 'x' :
- out = bc_hex(bcv_scaner._value); break ;
+ out = bc_hex(value); break ;
case 'b':
- out = bc_bin(bcv_scaner._value); break ;
+ out = bc_bin(value); break ;
case 'o':
- out = bc_oct(bcv_scaner._value); break ;
+ out = bc_oct(value); break ;
case 'd':
- out = bc_dec(bcv_scaner._value);break ;
+ out = bc_dec(value); break ;
case 'c':
- out = bc_chr(bcv_scaner._value); break ;
- //bcv_print(value , DEC | HEX | OCT | BIN); break ;
- case '?':
- case 'h': fprintf(stdout , "%s%s\12" , USAGE , BCV_VERSION_STR); break;
-
- case '!':
- case 'v': fprintf(stdout , "%s\012", BCV_STARTUP_MESG) ; break ;
+ out = bc_chr(value); break ;
default :
//BCV_WARN("|-> W: Unknow operation type 'h' or '?' to print the usage\n")
@@ -153,3 +164,28 @@ void __trimlower(char* bcv_cmd)
bzero(bcv_cmd, (len >>8)) ;
memcpy(bcv_cmd , auto_format_cmd , j) ;
}
+
+
+uf64_t bcrepl_process(const char * buffer , const char ftokn)
+{
+ char *token = 00, *buffer_clone = (char *) buffer ,
+ scan_limite=3;
+ uf64_t vtok=0;
+
+
+ while( --scan_limite && __nptr != (token = strtok(buffer_clone, (const char []) { ftokn , 00 } )))
+ {
+ if(buffer_clone) buffer_clone=00;
+
+ if(2 == scan_limite)
+ {
+ char *s = 0 ;
+ asprintf(&s , "%i" , (*token & 0xff)) ;
+ vtok= (uf64_t) strtol(s, 00 , 0xa) << 0x20;
+ free(s) , s=0 ;
+ }
+ else
+ vtok|=(uf64_t)(strtol(token , __nptr , 0xa)) ;
+ }
+ return vtok ;
+}
diff --git a/src/bcvrepl.h b/src/bcvrepl.h
index b5f5942..c83306f 100644
--- a/src/bcvrepl.h
+++ b/src/bcvrepl.h
@@ -11,6 +11,7 @@
#endif
#include "bcv_conf.h"
+#include "baseconv.h"
#if defined(__linux__)
#include
@@ -54,10 +55,14 @@ static inline __attribute__((constructor)) void init_tty(void)
BCV_VERSION_STR\
BCV_DISCLAIMER
-
#define __nptr (void *) 0
-#define _Nullable
-#define _NonNullable [static 0x1]
+
+#define BCVRPL_SEPS {\
+ 0x2f,0x20,\
+ 0x28,0x23,\
+ 0x24,0x25,\
+ 0x0}
+
#define bcrepl_symbole_prompt 0x3e
#define bcrepl_buffer_limit 0x50
#define __bcrepl_prompt_format "[%i] %s %c "
@@ -71,6 +76,8 @@ extern char * program_invocation_short_name ;
# define pname "bcv"
#endif
+
+
typedef typeof(void(const char * __restrict__)) * user_prompt_custom_shell ;
/* @fn bcrepl_shell(const char * _Nullable)
@@ -78,7 +85,7 @@ typedef typeof(void(const char * __restrict__)) * user_prompt_custom_shell ;
* @param const char * - if Null the default shell prompt is used
* */
bcvrepl_export void
-bcrepl_shell(const char * _Nullable __prompt) ;
+bcrepl_shell(const char * __prompt) ;
bcvrepl_export void
@@ -89,22 +96,24 @@ bcrepl_customize(user_prompt_custom_shell, const char * __restrict__ __promp
* @param const char * _NonNullable - buffer
*/
bcvrepl_export void
-bcrepl_compute(const char __buffer _NonNullable) ;
+bcrepl_compute(const char *__buffer) ;
/* @fn bcrepl_listen_cmd(const char * _NonNullable)
* @brief listen basic command instruction like exit quit
* @param const char * _NonNullable - buffer
*/
bcvrepl_export void __attribute__((weak))
-bcrepl_listen_special_cmd(const char __buffer _NonNullable) ;
+bcrepl_listen_special_cmd(const char *__buffer) ;
/* @fn __trimlower(char * _NonNullable)
* @brief trim empty space left and right and make it lower case
* @param char * command
*/
bcvrepl_export void
-__trimlower(char __cmd _NonNullable);
+__trimlower(char *__cmd);
+bcvrepl_export char * bcrepl_token_search(const char * __restrict__) ;
+bcvrepl_export uf64_t bcrepl_process(const char * buffer , char founded_token) ;
#endif //!bcv_repl_h