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
18 changes: 7 additions & 11 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include <stdint.h>

#include "baseconv.h"
#include "bcvrepl.h"

#define NO_ARGS !(ac &~(1))

void bcv_usage(unsigned char const) ; /* [[noreturn]] */

Expand All @@ -23,16 +24,11 @@ int main(int ac , char **av)
(void) setvbuf(stdout , (void *)0 , _IONBF ,0) ;

//!NOTICE : when no argument was provided the repl is automaticaly launched
//if(bcv_launch_iteractive_repl_on(!(ac ~ &(1))))
//goto _bcv_end ;
if (!(ac &~(1)))
{
//! launch interactive shell
(void) setlinebuf(stdin) ;
bcrepl_shell(__nptr);
goto _bcv_end;
}


if(bcv_launch_interactive_repl_on(NO_ARGS))
goto _bcv_end ;


//!NOTICE : long options are note handled ...
//!NOTICE : probably -h and -v (help and version)
//!TODO : make support for long option
Expand Down
23 changes: 16 additions & 7 deletions src/baseconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <string.h>
#include <ctype.h>
#include "baseconv.h"
#include "bcvrepl.h"


char bc_global_buffer[0xff]={0} ;
uf64_t __allbase_enable__ = (BIN|CHR|OCT|HEX|429496729600);
Expand Down Expand Up @@ -103,7 +105,8 @@ void bcv_guess_base(const char * restrict num)
{

uf64_t options = __allbase_enable__,
resolve_option=__allbase_enable__,
restore_option=__allbase_enable__,
excluded =0 ,
value = 0 ;
char indicator = tolower(*(num+1) & 0xff ) ;

Expand Down Expand Up @@ -132,14 +135,20 @@ void bcv_guess_base(const char * restrict num)
goto _end;
}


uf64_t exclude= (__allbase_enable__ ^ options) ;
__allbase_enable__^=exclude;
bcv_print(value) ;

__allbase_enable__ = resolve_option ;

excluded= (__allbase_enable__ ^ options) ;
__allbase_enable__^=excluded;
bcv_print(value) ;
__allbase_enable__ = restore_option ;

_end:
return ;
}

int bcv_launch_interactive_repl_on(int check_shell_argument)
{
if(check_shell_argument)
bcrepl_shell(__nptr /*default prompt */) ;

return 0;
}
4 changes: 3 additions & 1 deletion src/baseconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
}\
}

#define bcvtol(input , base) strtol(input , 00 , base)

#define SHOWHEX(__expr, __it ,__out) \
SHOWBASE_EXPR(__expr ,__it, "0x","%c", __out)
Expand Down Expand Up @@ -95,6 +96,7 @@ struct __bcb_t
int _index ;
};

#include "bcvrepl.h"
//!TODO : Use memory stream instead
extern char bc_global_buffer[0xff] ;
extern uf64_t __allbase_enable__;
Expand Down Expand Up @@ -191,6 +193,6 @@ __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) ;

__BCX(int) bcv_launch_interactive_repl_on(int no_args) ;

#endif //!__BASECONV
12 changes: 11 additions & 1 deletion src/bcvrepl.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ void bcrepl_shell(const char * prompt)
bzero(prompt_buffer , bcrepl_buffer_limit) ;
fflush(stdin) ;
}
exit(EXIT_SUCCESS) ;
}

void bcrepl_customize(user_prompt_custom_shell custom_prompt , const char * prompt)
Expand All @@ -63,6 +64,15 @@ char * bcrepl_token_search(const char * bcrpl_inline_buffer)
}


static uf64_t bcrepl_analyse_braw(const char * raw_buffer)
{
uf64_t value = strtol(raw_buffer , 00 , 10);
if (!value && is_printable(raw_buffer))
value = *raw_buffer & 0xff ;

return value ;
}

void bcrepl_compute(const char * buffer)
{

Expand All @@ -78,7 +88,7 @@ void bcrepl_compute(const char * buffer)
vtok = bcrepl_process(buffer_clone , *(should_be_tokinezed) & 0xff);
else
{
value = strtol(buffer_clone , 00 , 10) ;
value = bcrepl_analyse_braw(buffer_clone);
value ? bcv_print(value) : bcv_guess_base(buffer_clone) ;
bcrepl_show_helper(buffer_clone) ;

Expand Down
16 changes: 8 additions & 8 deletions src/bcvrepl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# define bcvrepl_export
#endif

#include "bcv_conf.h"
#include "baseconv.h"
#include "bcv_conf.h"
#include "baseconv.h"

#if defined(__linux__)
#include <term.h>
Expand All @@ -37,6 +37,8 @@ static inline __attribute__((constructor)) void init_tty(void)
#define GREEN __SETAF(COLOR_GREEN)
#define RED __SETAF(COLOR_RED)
#define YELLOW __SETAF(COLOR_YELLOW)
#define INFO __SETAF(COLOR_CYAN)

#define __reset tputs(reset, 1, putchar )

#define apply(__statement , __color_attr) \
Expand Down Expand Up @@ -77,15 +79,14 @@ extern char * program_invocation_short_name ;
#endif



typedef typeof(void(const char * __restrict__)) * user_prompt_custom_shell ;

/* @fn bcrepl_shell(const char * _Nullable)
* @brief define the shell prompt
* @param const char * - if Null the default shell prompt is used
* */
bcvrepl_export void
bcrepl_shell(const char * __prompt) ;
bcvrepl_export void __attribute__((noreturn))
bcrepl_shell(const char * __prompt) ;


bcvrepl_export void
Expand All @@ -112,10 +113,9 @@ bcrepl_listen_special_cmd(const char *__buffer) ;
bcvrepl_export void
__trimlower(char *__cmd);

bcvrepl_export char * bcrepl_token_search(const char * __restrict__) ;
static uf64_t bcrepl_analyse_braw(const char * __restrict__ raw_input_buffer) ;

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