mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-15 17:02:53 +08:00
add cfg for shell, add 'c' 'sh' cmd for debuger
This commit is contained in:
parent
e4363d03a2
commit
461164ec81
@ -1,17 +1,23 @@
|
|||||||
#include "PikaDebug_Debuger.h"
|
#include "PikaDebug_Debuger.h"
|
||||||
|
|
||||||
static enum shell_state __obj_shellLineHandler_obj_run(PikaObj *self, char *input_line){
|
extern PikaObj* __pikaMain;
|
||||||
/* exit */
|
static enum shell_state __obj_shellLineHandler_obj_run(PikaObj* self,
|
||||||
if (strEqu("exit()", input_line)) {
|
char* input_line) {
|
||||||
|
/* continue */
|
||||||
|
if (strEqu("c", input_line)) {
|
||||||
/* exit pika shell */
|
/* exit pika shell */
|
||||||
return SHELL_STATE_EXIT;
|
return SHELL_STATE_EXIT;
|
||||||
}
|
}
|
||||||
/* run single line */
|
if (strEqu("sh", input_line)) {
|
||||||
obj_run(self, input_line);
|
/* exit pika shell */
|
||||||
return SHELL_STATE_CONTINUE;
|
pikaScriptShell(__pikaMain);
|
||||||
|
return SHELL_STATE_CONTINUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern PikaObj* __pikaMain;
|
|
||||||
void PikaDebug_Debuger_set_trace(PikaObj* self) {
|
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);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,23 @@
|
|||||||
#include "PikaDebug_Debuger.h"
|
#include "PikaDebug_Debuger.h"
|
||||||
|
|
||||||
static enum shell_state __obj_shellLineHandler_obj_run(PikaObj *self, char *input_line){
|
extern PikaObj* __pikaMain;
|
||||||
/* exit */
|
static enum shell_state __obj_shellLineHandler_obj_run(PikaObj* self,
|
||||||
if (strEqu("exit()", input_line)) {
|
char* input_line) {
|
||||||
|
/* continue */
|
||||||
|
if (strEqu("c", input_line)) {
|
||||||
/* exit pika shell */
|
/* exit pika shell */
|
||||||
return SHELL_STATE_EXIT;
|
return SHELL_STATE_EXIT;
|
||||||
}
|
}
|
||||||
/* run single line */
|
if (strEqu("sh", input_line)) {
|
||||||
obj_run(self, input_line);
|
/* exit pika shell */
|
||||||
return SHELL_STATE_CONTINUE;
|
pikaScriptShell(__pikaMain);
|
||||||
|
return SHELL_STATE_CONTINUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern PikaObj* __pikaMain;
|
|
||||||
void PikaDebug_Debuger_set_trace(PikaObj* self) {
|
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);
|
||||||
}
|
}
|
||||||
|
@ -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 rxBuff[PIKA_SHELL_LINE_BUFF_SIZE] = {0};
|
||||||
char *input_line = NULL;
|
char* input_line = NULL;
|
||||||
uint8_t is_in_block = 0;
|
uint8_t is_in_block = 0;
|
||||||
__platform_printf(">>> ");
|
__platform_printf(cfg->prefix);
|
||||||
while (1) {
|
while (1) {
|
||||||
char inputChar = __platform_getchar();
|
char inputChar = __platform_getchar();
|
||||||
__platform_printf("%c", inputChar);
|
__platform_printf("%c", inputChar);
|
||||||
@ -591,7 +593,8 @@ void obj_shellLineProcess(PikaObj* self, __obj_shellLineHandler_t __lineHandler_
|
|||||||
if (rxBuff[0] != ' ') {
|
if (rxBuff[0] != ' ') {
|
||||||
is_in_block = 0;
|
is_in_block = 0;
|
||||||
input_line = obj_getStr(self, "shell_buff");
|
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;
|
break;
|
||||||
}
|
}
|
||||||
__platform_printf(">>> ");
|
__platform_printf(">>> ");
|
||||||
@ -601,21 +604,23 @@ void obj_shellLineProcess(PikaObj* self, __obj_shellLineHandler_t __lineHandler_
|
|||||||
__clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE);
|
__clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* go in block */
|
if (0 != strGetSize(rxBuff)) {
|
||||||
if (rxBuff[strGetSize(rxBuff) - 1] == ':') {
|
/* go in block */
|
||||||
is_in_block = 1;
|
if (rxBuff[strGetSize(rxBuff) - 1] == ':') {
|
||||||
char _n = '\n';
|
is_in_block = 1;
|
||||||
strAppendWithSize(rxBuff, &_n, 1);
|
char _n = '\n';
|
||||||
obj_setStr(self, "shell_buff", rxBuff);
|
strAppendWithSize(rxBuff, &_n, 1);
|
||||||
__clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE);
|
obj_setStr(self, "shell_buff", rxBuff);
|
||||||
__platform_printf("... ");
|
__clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE);
|
||||||
continue;
|
__platform_printf("... ");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
input_line = rxBuff;
|
input_line = rxBuff;
|
||||||
if(SHELL_STATE_EXIT == __lineHandler_fun(self, input_line)){
|
if (SHELL_STATE_EXIT == __lineHandler_fun(self, input_line)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
__platform_printf(">>> ");
|
__platform_printf(cfg->prefix);
|
||||||
|
|
||||||
__clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE);
|
__clearBuff(rxBuff, PIKA_SHELL_LINE_BUFF_SIZE);
|
||||||
continue;
|
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 */
|
/* exit */
|
||||||
if (strEqu("exit()", input_line)) {
|
if (strEqu("exit()", input_line)) {
|
||||||
/* exit pika shell */
|
/* exit pika shell */
|
||||||
@ -634,8 +640,11 @@ static enum shell_state __obj_shellLineHandler_obj_run(PikaObj *self, char *inpu
|
|||||||
return SHELL_STATE_CONTINUE;
|
return SHELL_STATE_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pikaScriptShell(PikaObj *self){
|
void pikaScriptShell(PikaObj* self) {
|
||||||
obj_shellLineProcess(self, __obj_shellLineHandler_obj_run);
|
struct shell_config cfg = {
|
||||||
|
.prefix = ">>> ",
|
||||||
|
};
|
||||||
|
obj_shellLineProcess(self, __obj_shellLineHandler_obj_run, &cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void obj_setErrorCode(PikaObj* self, int32_t errCode) {
|
void obj_setErrorCode(PikaObj* self, int32_t errCode) {
|
||||||
|
@ -28,16 +28,14 @@
|
|||||||
#ifndef _Process__H
|
#ifndef _Process__H
|
||||||
#define _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__
|
//#define __PLOOC_CLASS_USE_STRICT_TEMPLATE__
|
||||||
|
|
||||||
#if defined(__PIKA_OBJ_CLASS_IMPLEMENT)
|
#if defined(__PIKA_OBJ_CLASS_IMPLEMENT)
|
||||||
# define __PLOOC_CLASS_IMPLEMENT__
|
#define __PLOOC_CLASS_IMPLEMENT__
|
||||||
#elif defined(__PIKA_OBJ_CLASS_INHERIT__)
|
#elif defined(__PIKA_OBJ_CLASS_INHERIT__)
|
||||||
# define __PLOOC_CLASS_INHERIT__
|
#define __PLOOC_CLASS_INHERIT__
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "__pika_ooc.h"
|
#include "__pika_ooc.h"
|
||||||
@ -59,7 +57,6 @@ struct PikaObj_t {
|
|||||||
Args* list;
|
Args* list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// def_class(PikaObj,
|
// def_class(PikaObj,
|
||||||
|
|
||||||
// private_member(
|
// private_member(
|
||||||
@ -160,12 +157,16 @@ int fast_atoi(char* src);
|
|||||||
char* fast_itoa(char* buf, uint32_t val);
|
char* fast_itoa(char* buf, uint32_t val);
|
||||||
|
|
||||||
/* shell */
|
/* shell */
|
||||||
void pikaScriptShell(PikaObj *self);
|
void pikaScriptShell(PikaObj* self);
|
||||||
enum shell_state{
|
enum shell_state { SHELL_STATE_CONTINUE, SHELL_STATE_EXIT };
|
||||||
SHELL_STATE_CONTINUE,
|
typedef enum shell_state (*__obj_shellLineHandler_t)(PikaObj*, char*);
|
||||||
SHELL_STATE_EXIT
|
|
||||||
|
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
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user