Skip to content

Commit

Permalink
fix BACKSPACE on other linux port (embd)
Browse files Browse the repository at this point in the history
  • Loading branch information
pikasTech committed Aug 12, 2023
1 parent e24f6e2 commit 951d833
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 305 deletions.
3 changes: 3 additions & 0 deletions port/linux/lcov.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
lcov --capture --directory build/package/pikascript/CMakeFiles/pikascript-core.dir/pikascript-core --output-file testHtml.info --test-name testHtml
genhtml -o result testHtml.info

280 changes: 276 additions & 4 deletions src/PikaObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1558,11 +1558,7 @@ char* shHistory_getNext(ShellHistory* self) {

#endif

#if __linux && PIKA_LINUX_BASH_ENABLE
#define PIKA_BACKSPACE() printf("\b \b")
#else
#define PIKA_BACKSPACE() pika_platform_printf(" \b")
#endif

#if __linux
#define PIKA_BACKSPACE_FORCE() printf("\b \b")
Expand Down Expand Up @@ -1610,6 +1606,9 @@ enum shellCTRL _inner_do_obj_runChar(PikaObj* self,
ShellConfig* shell) {
char* input_line = NULL;
enum shellCTRL ctrl = SHELL_CTRL_CONTINUE;
if (inputChar == 0x7F) {
inputChar = '\b';
}
if (g_REPL.no_echo == pika_false) {
#if __linux
printf("%c", inputChar);
Expand Down Expand Up @@ -4087,3 +4086,276 @@ PikaDict* New_PikaDict(void) {
pikaDict_init(self);
return self;
}

PIKA_RES pikaList_set(PikaList* self, int index, Arg* arg) {
char buff[11];
char* i_str = fast_itoa(buff, index);
int top = pikaList_getSize(self);
if (index > top) {
return PIKA_RES_ERR_OUT_OF_RANGE;
}
arg = arg_setName(arg, i_str);
args_setArg(_OBJ2LIST(self), arg);
return PIKA_RES_OK;
}

Arg* pikaList_get(PikaList* self, int index) {
pika_assert(NULL != self);
char buff[11];
char* i_str = fast_itoa(buff, index);
return args_getArg(_OBJ2LIST(self), i_str);
}

int pikaList_getInt(PikaList* self, int index) {
Arg* arg = pikaList_get(self, index);
return arg_getInt(arg);
}

pika_float pikaList_getFloat(PikaList* self, int index) {
Arg* arg = pikaList_get(self, index);
return arg_getFloat(arg);
}

char* pikaList_getStr(PikaList* self, int index) {
Arg* arg = pikaList_get(self, index);
return arg_getStr(arg);
}

void* pikaList_getPtr(PikaList* self, int index) {
Arg* arg = pikaList_get(self, index);
return arg_getPtr(arg);
}

PIKA_RES pikaList_append(PikaList* self, Arg* arg) {
if (NULL == arg) {
return PIKA_RES_ERR_ARG_NO_FOUND;
}
int top = pikaList_getSize(self);
char buff[11];
char* topStr = fast_itoa(buff, top);
Arg* arg_to_push = arg;
arg_setName(arg_to_push, topStr);
args_setArg(_OBJ2LIST(self), arg_to_push);
/* top++ */
return args_setInt(_OBJ2LIST(self), "top", top + 1);
}

void pikaList_deinit(PikaList* self) {
args_deinit(_OBJ2LIST(self));
}

void pikaTuple_deinit(PikaTuple* self) {
pikaList_deinit(self);
}

ArgType pikaList_getType(PikaList* self, int index) {
Arg* arg = pikaList_get(self, index);
return arg_getType(arg);
}

Arg* pikaList_pop_withIndex(PikaList* self, int index) {
int top = pikaList_getSize(self);
if (top <= 0) {
return NULL;
}
if (index < 0) {
index = top + index;
}
Arg* arg = pikaList_get(self, index);
Arg* res = arg_copy(arg);
pikaList_remove(self, arg);
return res;
}

Arg* pikaList_pop(PikaList* self) {
int top = pikaList_getSize(self);
if (top <= 0) {
return NULL;
}
return pikaList_pop_withIndex(self, top - 1);
}

PIKA_RES pikaList_remove(PikaList* self, Arg* arg) {
int top = pikaList_getSize(self);
int i_remove = 0;
if (top <= 0) {
return PIKA_RES_ERR_OUT_OF_RANGE;
}
for (int i = 0; i < top; i++) {
Arg* arg_now = pikaList_get(self, i);
if (arg_isEqual(arg_now, arg)) {
i_remove = i;
args_removeArg(_OBJ2LIST(self), arg_now);
break;
}
}
/* move args */
for (int i = i_remove + 1; i < top; i++) {
char buff[11];
char* i_str = fast_itoa(buff, i - 1);
Arg* arg_now = pikaList_get(self, i);
arg_setName(arg_now, i_str);
}
args_setInt(_OBJ2LIST(self), "top", top - 1);
return PIKA_RES_OK;
}

PIKA_RES pikaList_insert(PikaList* self, int index, Arg* arg) {
int top = pikaList_getSize(self);
if (index > top) {
return PIKA_RES_ERR_OUT_OF_RANGE;
}
/* move args */
for (int i = top - 1; i >= index; i--) {
char buff[11];
char* i_str = fast_itoa(buff, i + 1);
Arg* arg_now = pikaList_get(self, i);
arg_setName(arg_now, i_str);
}
char buff[11];
char* i_str = fast_itoa(buff, index);
Arg* arg_to_push = arg_copy(arg);
arg_setName(arg_to_push, i_str);
args_setArg(_OBJ2LIST(self), arg_to_push);
args_setInt(_OBJ2LIST(self), "top", top + 1);
return PIKA_RES_OK;
}

size_t pikaList_getSize(PikaList* self) {
if (NULL == self) {
return 0;
}
int64_t ret = args_getInt(_OBJ2LIST(self), "top");
pika_assert(ret >= 0);
return ret;
}

void pikaList_init(PikaObj* self) {
Args* list = New_args(NULL);
args_pushArg_name(list, "top", arg_newInt(0));
obj_setPtr(self, "list", list);
}

void pikaList_reverse(PikaList* self) {
pika_assert(NULL != self);
int top = pikaList_getSize(self);
for (int i = 0; i < top / 2; i++) {
Arg* arg_i = arg_copy(pikaList_get(self, i));
Arg* arg_top = arg_copy(pikaList_get(self, top - i - 1));
pikaList_set(self, i, arg_top);
pikaList_set(self, top - i - 1, arg_i);
}
}

Arg* pikaTuple_getArg(PikaTuple* self, int index) {
return pikaList_get(self, (index));
}

size_t pikaTuple_getSize(PikaTuple* self) {
if (self == NULL) {
return 0;
}
return pikaList_getSize(self);
}

int64_t pikaTuple_getInt(PikaTuple* self, int index) {
return pikaList_getInt(self, (index));
}

pika_float pikaTuple_getFloat(PikaTuple* self, int index) {
return pikaList_getFloat(self, (index));
}

char* pikaTuple_getStr(PikaTuple* self, int index) {
return pikaList_getStr(self, (index));
}

void* pikaTuple_getPtr(PikaTuple* self, int index) {
return pikaList_getPtr(self, (index));
}

ArgType pikaTuple_getType(PikaTuple* self, int index) {
return pikaList_getType(self, (index));
}

PIKA_RES pikaDict_setInt(PikaDict* self, char* name, int64_t val) {
return args_setInt(_OBJ2DICT(self), (name), (val));
}
PIKA_RES pikaDict_setFloat(PikaDict* self, char* name, pika_float val) {
return args_setFloat(_OBJ2DICT(self), (name), (val));
}
PIKA_RES pikaDict_setStr(PikaDict* self, char* name, char* val) {
return args_setStr(_OBJ2DICT(self), (name), (val));
}
PIKA_RES pikaDict_setPtr(PikaDict* self, char* name, void* val) {
return args_setPtr(_OBJ2DICT(self), (name), (val));
}

PIKA_RES _pikaDict_setVal(PikaDict* self, Arg* val) {
return args_setArg(_OBJ2DICT(self), (val));
}

PIKA_RES pikaDict_set(PikaDict* self, char* name, Arg* val) {
val = arg_setName(val, name);
_pikaDict_setVal(self, val);
return args_setStr(_OBJ2KEYS(self), (name), (name));
}

PIKA_RES pikaDict_removeArg(PikaDict* self, Arg* val) {
return args_removeArg(_OBJ2DICT(self), (val));
}

PIKA_RES pikaDict_setBytes(PikaDict* self,
char* name,
uint8_t* val,
size_t size) {
return args_setBytes(_OBJ2DICT(self), (name), (val), (size));
}

int64_t pikaDict_getInt(PikaDict* self, char* name) {
return args_getInt(_OBJ2DICT(self), (name));
}

pika_float pikaDict_getFloat(PikaDict* self, char* name) {
return args_getFloat(_OBJ2DICT(self), (name));
}

char* pikaDict_getStr(PikaDict* self, char* name) {
return args_getStr(_OBJ2DICT(self), (name));
}

void* pikaDict_getPtr(PikaDict* self, char* name) {
return args_getPtr(_OBJ2DICT(self), (name));
}

int pikaDict_getSize(PikaDict* self) {
return args_getSize(_OBJ2DICT(self));
}

Arg* pikaDict_getArgByidex(PikaDict* self, int index) {
return args_getArgByIndex(_OBJ2DICT(self), (index));
}

Arg* pikaDict_get(PikaDict* self, char* name) {
return args_getArg(_OBJ2DICT(self), (name));
}

int32_t pikaDict_isArgExist(PikaDict* self, char* name) {
return args_isArgExist(_OBJ2DICT(self), (name));
}

uint8_t* pikaDict_getBytes(PikaDict* self, char* name) {
return args_getBytes(_OBJ2DICT(self), (name));
}

ArgType pikaDict_getType(PikaDict* self, char* name) {
return args_getType(_OBJ2DICT(self), (name));
}

size_t pikaDict_getBytesSize(PikaDict* self, char* name) {
return args_getBytesSize(_OBJ2DICT(self), (name));
}

void pikaDict_deinit(PikaDict* self) {
obj_deinit(self);
}
Loading

0 comments on commit 951d833

Please sign in to comment.