1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-22 11:56:42 +00:00

Add functions, Add goto's

This commit is contained in:
Such Meme, Many Skill 2020-03-31 17:58:09 +02:00
parent 30afcddd3a
commit 9efbbc9317
4 changed files with 114 additions and 5 deletions

View file

@ -32,6 +32,17 @@ int parseIntInput(char *in, int *out){
return 0;
}
int parseJmpInput(char *in, u64 *out){
if (in[0] == '?'){
if (str_jmp_find(argv[0], out))
return -1;
else
return 0;
}
else
return -1;
}
int part_printf(){
gfx_printf(argv[0]);
gfx_printf("\n");
@ -104,12 +115,28 @@ int part_Check(){
return -1;
}
int part_SetInt(){
int out;
parseIntInput(argv[0], &out);
return out;
}
int part_goto(){
u64 target = 0;
if (parseJmpInput(argv[0], &target))
return -1;
f_lseek(&scriptin, target);
return 0;
}
str_fnc_struct functions[] = {
{"printf", part_printf, 1},
{"print_int", part_print_int, 1},
{"printInt", part_print_int, 1},
{"if", part_if, 1},
{"math", part_Math, 3},
{"check", part_Check, 3},
{"setInt", part_SetInt, 1},
{"goto", part_goto, 1},
{NULL, NULL, 0}
};

View file

@ -49,7 +49,7 @@ u32 splitargs(char* in) {
curcount++;
current = 0;
}
else if (in[i] == '@' || in[i] == '$') {
else if (in[i] == '@' || in[i] == '$' || in[i] == '?') {
while (in[i] != ',' && in[i] != ' ' && in[i] != ')' && i < len) {
argv[curcount][current++] = in[i++];
}
@ -92,7 +92,7 @@ void getfollowingchar(char end){
}
void getnextvalidchar(){
while ((!((currentchar >= 'A' && currentchar <= 'Z') || (currentchar >= 'a' && currentchar <= 'z') || currentchar == '#' || currentchar == '@') && !f_eof(&scriptin)) /*|| currentchar == ';' */)
while ((!((currentchar >= '?' && currentchar <= 'Z') || (currentchar >= 'a' && currentchar <= 'z') || currentchar == '#') && !f_eof(&scriptin)) /*|| currentchar == ';' */)
getnextchar();
}
@ -181,6 +181,15 @@ void mainparser(){
getnextvalidchar();
}
if (currentchar == '?'){
char *jumpname;
jumpname = readtilchar(';', ' ');
getnextchar();
str_jmp_add(jumpname, f_tell(&scriptin));
getfollowingchar('\n');
return;
}
functionparser();
res = run_function(funcbuff, &out);
@ -188,6 +197,9 @@ void mainparser(){
printerrors = true;
gfx_errDisplay("mainparser", ERR_PARSE_FAIL, 0);
forceExit = true;
//gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]);
btn_wait();
}
else {
str_int_add("@RESULT", out);
@ -254,5 +266,6 @@ void tester(char *path){
f_close(&scriptin);
str_int_clear();
str_jmp_clear();
btn_wait();
}

View file

@ -25,7 +25,7 @@ int str_int_add(char *key, int value){
utils_copystring(key, &key_local);
keyvaluepair = calloc(1, sizeof(keyvaluepair));
keyvaluepair = calloc(1, sizeof(dict_str_int));
keyvaluepair->key = key_local;
keyvaluepair->value = value;
keyvaluepair->next = NULL;
@ -77,6 +77,7 @@ void str_int_clear(){
free(cur);
cur = next;
}
str_int_table = NULL;
}
void str_int_printall(){
@ -86,4 +87,69 @@ void str_int_printall(){
gfx_printf("%s -> %d\n", temp->key, temp->value);
temp = temp->next;
}
}
int str_jmp_add(char *key, u64 value){
char *key_local;
dict_str_loc *keyvaluepair;
utils_copystring(key, &key_local);
//gfx_printf("Adding |%s|\n", key_local);
keyvaluepair = calloc(1, sizeof(dict_str_loc));
keyvaluepair->key = key_local;
keyvaluepair->value = value;
keyvaluepair->next = NULL;
if (str_jmp_table == NULL){
str_jmp_table = keyvaluepair;
}
else {
dict_str_loc *temp;
temp = str_jmp_table;
while (temp != NULL){
if (!strcmp(temp->key, key_local)){
temp->value = value;
return 0;
}
if (temp->next == NULL){
temp->next = keyvaluepair;
return 0;
}
temp = temp->next;
}
}
return 0;
}
int str_jmp_find(char *key, u64 *out){
dict_str_loc *temp;
temp = str_jmp_table;
//gfx_printf("Searching |%s|\n", key);
while (temp != NULL){
if (!strcmp(temp->key, key)){
//gfx_printf("Key found!\n", temp->value);
*out = temp->value;
return 0;
}
temp = temp->next;
}
//gfx_printf("no key!\n");
return -1;
}
void str_jmp_clear(){
dict_str_loc *cur, *next;
cur = str_jmp_table;
while (cur != NULL){
next = cur->next;
free(cur->key);
free(cur);
cur = next;
}
str_jmp_table = NULL;
}

View file

@ -22,4 +22,7 @@ typedef struct _dict_str_loc {
int str_int_add(char *key, int value);
int str_int_find(char *key, int *out);
void str_int_clear();
void str_int_printall();
void str_int_printall();
int str_jmp_add(char *key, u64 value);
int str_jmp_find(char *key, u64 *out);
void str_jmp_clear();