From 9efbbc9317b7a9c148ff95a507b3d9cbe9ed9b84 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Tue, 31 Mar 2020 17:58:09 +0200 Subject: [PATCH] Add functions, Add goto's --- source/tegraexplorer/script/functions.c | 29 ++++++++++- source/tegraexplorer/script/parser.c | 17 ++++++- source/tegraexplorer/script/variables.c | 68 ++++++++++++++++++++++++- source/tegraexplorer/script/variables.h | 5 +- 4 files changed, 114 insertions(+), 5 deletions(-) diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index 1ec84b9..e775517 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -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} }; diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index d6aa5dc..a900784 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -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(); } \ No newline at end of file diff --git a/source/tegraexplorer/script/variables.c b/source/tegraexplorer/script/variables.c index 70ec073..86e250c 100644 --- a/source/tegraexplorer/script/variables.c +++ b/source/tegraexplorer/script/variables.c @@ -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; } \ No newline at end of file diff --git a/source/tegraexplorer/script/variables.h b/source/tegraexplorer/script/variables.h index 6f34133..a7a7634 100644 --- a/source/tegraexplorer/script/variables.h +++ b/source/tegraexplorer/script/variables.h @@ -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(); \ No newline at end of file +void str_int_printall(); +int str_jmp_add(char *key, u64 value); +int str_jmp_find(char *key, u64 *out); +void str_jmp_clear(); \ No newline at end of file