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
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data.set_quoted('BCV_VERSION',meson.project_version())
data.set_quoted('BCV_DISCLAIMER', bcv_copyright)
data.set_quoted('BCV_VERSION_STR', 'bcv version '+meson.project_version()+'\\012')
data.set_quoted('BCV_VERSTRLONG' , 'baseconverter version '+meson.project_version()+' by KerHack-Libre')
data.set_quoted('BCV_HINT', 'Tip: type [?]or[h] for help and [!]or[v] for version'+'\\012')

configure_file(
output: 'bcv_conf.h',
Expand Down
83 changes: 63 additions & 20 deletions src/bcvrepl.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>

#include "baseconv.h"
#include "bcvrepl.h"
Expand All @@ -16,15 +17,15 @@
void bcrepl_shell(const char * prompt)
{
const char * prmpt = !prompt ? pname : prompt ;
int proceed =1 ;
int proceed =1,
line = 0;
char prompt_buffer[bcrepl_buffer_limit]={0};
int line = 0;
fprintf(stdout , "%s" , BCV_STARTUP_MESG) ;
bcv_info("%s" , BCV_STARTUP_MESG) ;

while (proceed, ++line)
{

//!BCV_SUCCESS()
apply( printf(bpf, line, prmpt , bcrepl_symbole_prompt) , GREEN) ;
bcv_success(bpf , line , prmpt , bcrepl_symbole_prompt) ;

if(!(fgets(prompt_buffer , bcrepl_buffer_limit, stdin)))
continue ;
Expand Down Expand Up @@ -116,31 +117,73 @@ void bcrepl_compute(const char * buffer)
case 'c':
out = bc_chr(value); break ;
default :
//BCV_WARN("|-> W: Unknow operation type 'h' or '?' to print the usage\n")

apply(fprintf(stderr ,"|-> W: Unknow operation type 'h' or '?' to print the usage\n")
,YELLOW) ;
bcv_warning("|-> W: Unknow operation type 'h' or '?' to print the usage \012");
break ;
}
if (!out)
return ;

//BCV_ERR()
apply(printf(" |-> %s\012", out) , RED) ;
bcv_error("|-> %s\012", out) ;

}

void bcrepl_listen_special_cmd(const char * buffer)
{
char * cmd = strdup(buffer) ;
__trimlower(cmd) ;

if(0 == strcmp(cmd, "quit") || \
0 == strcmp(cmd, "exit"))
{
free(cmd) ;
exit(0) ;
}

if(bcrepl_special_cmd_ops(cmd , C_CHRAY(EXIT_COMMANDS) , exiting_command))
free(cmd),exit(0) ;

bcrepl_special_cmd_ops(cmd , C_CHRAY(INFORMATION_COMMANDS),sinfo_command);

free(cmd) ;

}

static int bcrepl_special_cmd_ops(char * cmd ,char * const * listofcmd, bcrcmd_sops cmdop)
{
unsigned char *ccmd =00,
icmd=~0;
int status = 0 ;
while(*(listofcmd+ ++icmd))
{
ccmd = *(listofcmd+icmd);
if(cmdop(cmd, ccmd))
status^=1 ;
}

return status ;
}

int exiting_command(const char * cmd , ...)
{
int once = 1 ;
va_list ap ;
va_start(ap , once) ;
char * ccmd = va_arg(ap , char *) ;
va_end(ap) ;

return (0 == strcmp(cmd ,ccmd));
}

int sinfo_command(const char * cmd , ...)
{

int once = 1 ;
va_list ap ;
va_start(ap , once) ;
char * ccmd = va_arg(ap , char *) ;
va_end(ap) ;


if(!strcmp(cmd , ccmd))
{
puts("Please see the LICENSE file ") ;
//TODO : read the license file
}

return 0 ;
}

void __trimlower(char* bcv_cmd)
Expand Down Expand Up @@ -195,9 +238,9 @@ 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 'h': bcv_info("%s%s\012", USAGE , BCV_VERSION_STR) ; break;
case '!':
case 'v': fprintf(stdout , "%s\012", BCV_STARTUP_MESG) ; break ;
case 'v': bcv_info("%s\012", BCV_STARTUP_MESG) ; break ;
}

}
48 changes: 39 additions & 9 deletions src/bcvrepl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#if defined(__linux__)
#include <term.h>
#include <curses.h>
//#include "bcvtty"

/* @fn init_tty(void)
* @brief setting up terminal for curses attribute
* */
Expand Down Expand Up @@ -44,26 +46,39 @@ static inline __attribute__((constructor)) void init_tty(void)
#define apply(__statement , __color_attr) \
__color_attr;__statement; __reset

#else /* NOTICE : NO SUPPORT FOR WINDOW*/
#define bcv_success(...)\
apply(fprintf(stdout,__VA_ARGS__), GREEN)

# define GREEN
# define RED
# define YELLOW
# define apply(__statement , __color_attr /*!ignored*/) __statement
#endif
#define bcv_warning(...)\
apply(fprintf(stdout,__VA_ARGS__),YELLOW)

#define bcv_error(...)\
apply(fprintf(stderr,__VA_ARGS__), RED)

#define bcv_info(...) \
apply(fprintf(stdout ,__VA_ARGS__),INFO)

#endif

#define BCV_STARTUP_MESG \
BCV_VERSION_STR\
BCV_DISCLAIMER
BCV_DISCLAIMER\
BCV_HINT

#define __nptr (void *) 0

#if !defined(BCVRPL_SEPS)
#define BCVRPL_SEPS {\
0x2f,0x20,\
0x28,0x23,\
0x24,0x25,\
0x0}
#endif

#define C_CHRAY(litteral_constant_array) (char * const []) litteral_constant_array

#define EXIT_COMMANDS {"quit","exit",0}
#define INFORMATION_COMMANDS {"license",0}

#define bcrepl_symbole_prompt 0x3e
#define bcrepl_buffer_limit 0x50
Expand All @@ -78,7 +93,7 @@ extern char * program_invocation_short_name ;
# define pname "bcv"
#endif


typedef typeof(int(const char * __restrict , ...)) *bcrcmd_sops ;
typedef typeof(void(const char * __restrict__)) * user_prompt_custom_shell ;

/* @fn bcrepl_shell(const char * _Nullable)
Expand Down Expand Up @@ -113,9 +128,24 @@ bcrepl_listen_special_cmd(const char *__buffer) ;
bcvrepl_export void
__trimlower(char *__cmd);

/* @fn exiting_command(const char * _NonNullable )
* @brief listen basic command command like exit or quit
* @parm const char * - command
* @return 1 - 0
*/
bcvrepl_export int __attribute__((weak))
exiting_command(const char * cmd, ...);

bcvrepl_export int __attribute__((weak))
sinfo_command(const char * cmd, ...) ;
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 ]) ;


static int bcrepl_special_cmd_ops(char * cmd ,
char *const listofcmd[restrict 1],
bcrcmd_sops cmdop) ;

#endif //!bcv_repl_h