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
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.”
<img src="assets/logo/made_in_senegal.png" width="200" height="" alt="made_in_senegal" title="made_in_senegal" style="margin-right:20px;border-radius:35px" align="right"/></br>

#### ⚖️ 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

Expand All @@ -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. »

<img src="assets/logo/khl1.png" width="100" height="" alt="khlogo" align="right"/>
<img src="assets/logo/khl1.png" width="100" height="" alt="khlogo" align="left"/>

Binary file modified assets/logo/bcvlogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo/made_in_senegal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 6 additions & 56 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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) ;
Expand All @@ -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) ;
}


71 changes: 69 additions & 2 deletions src/baseconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "baseconv.h"

char bc_global_buffer[0xff]={0} ;
Expand Down Expand Up @@ -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;
Expand All @@ -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 ;
}


11 changes: 11 additions & 0 deletions src/baseconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
}\
}


#define SHOWHEX(__expr, __it ,__out) \
SHOWBASE_EXPR(__expr ,__it, "0x","%c", __out)

Expand All @@ -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] ... <NUMBER>\n\
Convert Number to specific base\n\
Expand Down Expand Up @@ -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
Loading