diff --git a/package/PikaDebug/PikaDebuger_Debuger.c b/package/PikaDebug/PikaDebuger_Debuger.c index 0bcd2ebec..d07d1ce70 100644 --- a/package/PikaDebug/PikaDebuger_Debuger.c +++ b/package/PikaDebug/PikaDebuger_Debuger.c @@ -1,17 +1,23 @@ #include "PikaDebug_Debuger.h" -static enum shell_state __obj_shellLineHandler_obj_run(PikaObj *self, char *input_line){ - /* exit */ - if (strEqu("exit()", input_line)) { +extern PikaObj* __pikaMain; +static enum shell_state __obj_shellLineHandler_obj_run(PikaObj* self, + char* input_line) { + /* continue */ + if (strEqu("c", input_line)) { /* exit pika shell */ return SHELL_STATE_EXIT; } - /* run single line */ - obj_run(self, input_line); - return SHELL_STATE_CONTINUE; + if (strEqu("sh", input_line)) { + /* exit pika shell */ + pikaScriptShell(__pikaMain); + return SHELL_STATE_CONTINUE; + } } -extern PikaObj* __pikaMain; void PikaDebug_Debuger_set_trace(PikaObj* self) { - obj_shellLineProcess(__pikaMain, __obj_shellLineHandler_obj_run); + struct shell_config cfg = { + .prefix = "(pika-debug) ", + }; + obj_shellLineProcess(__pikaMain, __obj_shellLineHandler_obj_run, &cfg); } diff --git a/port/linux/package/pikascript/pikascript-lib/PikaDebug/PikaDebuger_Debuger.c b/port/linux/package/pikascript/pikascript-lib/PikaDebug/PikaDebuger_Debuger.c index 0bcd2ebec..d07d1ce70 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaDebug/PikaDebuger_Debuger.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaDebug/PikaDebuger_Debuger.c @@ -1,17 +1,23 @@ #include "PikaDebug_Debuger.h" -static enum shell_state __obj_shellLineHandler_obj_run(PikaObj *self, char *input_line){ - /* exit */ - if (strEqu("exit()", input_line)) { +extern PikaObj* __pikaMain; +static enum shell_state __obj_shellLineHandler_obj_run(PikaObj* self, + char* input_line) { + /* continue */ + if (strEqu("c", input_line)) { /* exit pika shell */ return SHELL_STATE_EXIT; } - /* run single line */ - obj_run(self, input_line); - return SHELL_STATE_CONTINUE; + if (strEqu("sh", input_line)) { + /* exit pika shell */ + pikaScriptShell(__pikaMain); + return SHELL_STATE_CONTINUE; + } } -extern PikaObj* __pikaMain; void PikaDebug_Debuger_set_trace(PikaObj* self) { - obj_shellLineProcess(__pikaMain, __obj_shellLineHandler_obj_run); + struct shell_config cfg = { + .prefix = "(pika-debug) ", + }; + obj_shellLineProcess(__pikaMain, __obj_shellLineHandler_obj_run, &cfg); } diff --git a/src/PikaObj.c b/src/PikaObj.c index dece7182e..183b42f62 100644 --- a/src/PikaObj.c +++ b/src/PikaObj.c @@ -553,11 +553,13 @@ static void __clearBuff(char* buff, int size) { } } -void obj_shellLineProcess(PikaObj* self, __obj_shellLineHandler_t __lineHandler_fun) { +void obj_shellLineProcess(PikaObj* self, + __obj_shellLineHandler_t __lineHandler_fun, + struct shell_config* cfg) { char rxBuff[PIKA_SHELL_LINE_BUFF_SIZE] = {0}; - char *input_line = NULL; + char* input_line = NULL; uint8_t is_in_block = 0; - __platform_printf(">>> "); + __platform_printf(cfg->prefix); while (1) { char inputChar = __platform_getchar(); __platform_printf("%c", inputChar); @@ -591,7 +593,8 @@ void obj_shellLineProcess(PikaObj* self, __obj_shellLineHandler_t __lineHandler_ if (rxBuff[0] != ' ') { is_in_block = 0; input_line = obj_getStr(self, "shell_buff"); - if(SHELL_STATE_EXIT == __lineHandler_fun(self, input_line)){ + if (SHELL_STATE_EXIT == + __lineHandler_fun(self, input_line)) { break; } __platform_printf(">>> "); @@ -601,21 +604,23 @@ void obj_shellLineProcess(PikaObj* self, __obj_shellLineHandler_t __lineHandler_ __clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE); continue; } - /* go in block */ - if (rxBuff[strGetSize(rxBuff) - 1] == ':') { - is_in_block = 1; - char _n = '\n'; - strAppendWithSize(rxBuff, &_n, 1); - obj_setStr(self, "shell_buff", rxBuff); - __clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE); - __platform_printf("... "); - continue; + if (0 != strGetSize(rxBuff)) { + /* go in block */ + if (rxBuff[strGetSize(rxBuff) - 1] == ':') { + is_in_block = 1; + char _n = '\n'; + strAppendWithSize(rxBuff, &_n, 1); + obj_setStr(self, "shell_buff", rxBuff); + __clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE); + __platform_printf("... "); + continue; + } } input_line = rxBuff; - if(SHELL_STATE_EXIT == __lineHandler_fun(self, input_line)){ + if (SHELL_STATE_EXIT == __lineHandler_fun(self, input_line)) { break; } - __platform_printf(">>> "); + __platform_printf(cfg->prefix); __clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE); continue; @@ -623,7 +628,8 @@ void obj_shellLineProcess(PikaObj* self, __obj_shellLineHandler_t __lineHandler_ } } -static enum shell_state __obj_shellLineHandler_obj_run(PikaObj *self, char *input_line){ +static enum shell_state __obj_shellLineHandler_obj_run(PikaObj* self, + char* input_line) { /* exit */ if (strEqu("exit()", input_line)) { /* exit pika shell */ @@ -634,8 +640,11 @@ static enum shell_state __obj_shellLineHandler_obj_run(PikaObj *self, char *inpu return SHELL_STATE_CONTINUE; } -void pikaScriptShell(PikaObj *self){ - obj_shellLineProcess(self, __obj_shellLineHandler_obj_run); +void pikaScriptShell(PikaObj* self) { + struct shell_config cfg = { + .prefix = ">>> ", + }; + obj_shellLineProcess(self, __obj_shellLineHandler_obj_run, &cfg); } void obj_setErrorCode(PikaObj* self, int32_t errCode) { diff --git a/src/PikaObj.h b/src/PikaObj.h index bfd4b6fa2..b0280d209 100644 --- a/src/PikaObj.h +++ b/src/PikaObj.h @@ -28,17 +28,15 @@ #ifndef _Process__H #define _Process__H - - -/*! \NOTE: Make sure #include "plooc_class.h" is close to the class definition +/*! \NOTE: Make sure #include "plooc_class.h" is close to the class definition */ //#define __PLOOC_CLASS_USE_STRICT_TEMPLATE__ - -#if defined(__PIKA_OBJ_CLASS_IMPLEMENT) -# define __PLOOC_CLASS_IMPLEMENT__ -#elif defined(__PIKA_OBJ_CLASS_INHERIT__) -# define __PLOOC_CLASS_INHERIT__ -#endif + +#if defined(__PIKA_OBJ_CLASS_IMPLEMENT) +#define __PLOOC_CLASS_IMPLEMENT__ +#elif defined(__PIKA_OBJ_CLASS_INHERIT__) +#define __PLOOC_CLASS_INHERIT__ +#endif #include "__pika_ooc.h" @@ -59,9 +57,8 @@ struct PikaObj_t { Args* list; }; - // def_class(PikaObj, - + // private_member( // /* list */ // Args* list; @@ -160,12 +157,16 @@ int fast_atoi(char* src); char* fast_itoa(char* buf, uint32_t val); /* shell */ -void pikaScriptShell(PikaObj *self); -enum shell_state{ - SHELL_STATE_CONTINUE, - SHELL_STATE_EXIT +void pikaScriptShell(PikaObj* self); +enum shell_state { SHELL_STATE_CONTINUE, SHELL_STATE_EXIT }; +typedef enum shell_state (*__obj_shellLineHandler_t)(PikaObj*, char*); + +struct shell_config { + char* prefix; }; -typedef enum shell_state (*__obj_shellLineHandler_t)(PikaObj* , char*); -void obj_shellLineProcess(PikaObj* self, __obj_shellLineHandler_t __lineHandler_fun); + +void obj_shellLineProcess(PikaObj* self, + __obj_shellLineHandler_t __lineHandler_fun, + struct shell_config* cfg); #endif