1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-09 13:41:45 +00:00

[script] Remove jump list & add if_check that works like if(check())

This commit is contained in:
Such Meme, Many Skill 2020-04-12 19:21:09 +02:00
parent e892e69929
commit 15e1210179
4 changed files with 54 additions and 32 deletions

View file

@ -103,6 +103,29 @@ int part_Wait(){
return 0;
}
int part_Check(){
int left, right;
if (parseIntInput(argv[0], &left))
return -1;
if (parseIntInput(argv[2], &right))
return -1;
if (!strcmp(argv[1], "=="))
return (left == right);
else if (!strcmp(argv[1], "!="))
return (left != right);
else if (!strcmp(argv[1], ">="))
return (left >= right);
else if (!strcmp(argv[1], "<="))
return (left <= right);
else if (!strcmp(argv[1], ">"))
return (left > right);
else if (!strcmp(argv[1], "<"))
return (left < right);
else
return -1;
}
int part_if(){
int condition;
if (parseIntInput(argv[0], &condition))
@ -125,6 +148,19 @@ int part_if(){
*/
}
int part_if_args(){
int condition;
if ((condition = part_Check()) < 0)
return -1;
getfollowingchar('{');
if (!condition)
skipbrackets();
return 0;
}
int part_Math(){
int left, right;
if (parseIntInput(argv[0], &left))
@ -145,29 +181,6 @@ int part_Math(){
return -1;
}
int part_Check(){
int left, right;
if (parseIntInput(argv[0], &left))
return -1;
if (parseIntInput(argv[2], &right))
return -1;
if (!strcmp(argv[1], "=="))
return (left == right);
else if (!strcmp(argv[1], "!="))
return (left != right);
else if (!strcmp(argv[1], ">="))
return (left >= right);
else if (!strcmp(argv[1], "<="))
return (left <= right);
else if (!strcmp(argv[1], ">"))
return (left > right);
else if (!strcmp(argv[1], "<"))
return (left < right);
else
return -1;
}
int part_SetInt(){
int out;
parseIntInput(argv[0], &out);
@ -200,8 +213,8 @@ int part_SetStringIndex(){
}
int part_goto(){
u64 target = 0;
if (parseJmpInput(argv[0], &target))
int target = 0;
if (parseIntInput(argv[0], &target))
return -1;
f_lseek(&scriptin, target);
return 0;
@ -510,12 +523,17 @@ int part_clearscreen(){
return 0;
}
int part_getPos(){
return (int)f_tell(&scriptin);
}
str_fnc_struct functions[] = {
{"printf", part_printf, 1},
{"printInt", part_print_int, 1},
{"setPrintPos", part_setPrintPos, 2},
{"clearscreen", part_clearscreen, 0},
{"if", part_if, 1},
{"if", part_if_args, 3}, // function overloading
{"math", part_Math, 3},
{"check", part_Check, 3},
{"setInt", part_SetInt, 1},
@ -542,6 +560,7 @@ str_fnc_struct functions[] = {
{"mmc_mount", part_MountMMC, 1},
{"mmc_dumpPart", part_mmc_dumpPart, 2},
{"mmc_restorePart", part_mmc_restorePart, 1},
{"getPosition", part_getPos, 0},
{"pause", part_Pause, 0},
{"wait", part_Wait, 1},
{"exit", part_Exit, 0},
@ -552,12 +571,10 @@ int run_function(char *func_name, int *out){
for (u32 i = 0; functions[i].key != NULL; i++){
if (!strcmp(functions[i].key, func_name)){
if (argc != functions[i].arg_count)
return -2;
continue;
*out = functions[i].value();
if (*out < 0)
return -1;
return 0;
return (*out < 0) ? -1 : 0;
}
}
return -1;

View file

@ -201,6 +201,7 @@ void mainparser(){
getnextvalidchar();
}
/*
if (currentchar == '?'){
char *jumpname;
jumpname = readtilchar(';', ' ');
@ -209,6 +210,7 @@ void mainparser(){
getfollowingchar('\n');
return;
}
*/
functionparser();
@ -301,7 +303,7 @@ void runScript(char *path){
f_close(&scriptin);
str_int_clear();
str_jmp_clear();
//str_jmp_clear();
str_str_clear();
free(path_local);
//btn_wait();

View file

@ -17,7 +17,7 @@
static dict_str_int *str_int_table = NULL;
static dict_str_str *str_str_table = NULL;
static dict_str_loc *str_jmp_table = NULL;
//static dict_str_loc *str_jmp_table = NULL;
int str_int_add(char *key, int value){
char *key_local;
@ -91,7 +91,7 @@ void str_int_printall(){
temp = temp->next;
}
}
/*
int str_jmp_add(char *key, u64 value){
char *key_local;
dict_str_loc *keyvaluepair;
@ -161,6 +161,7 @@ void str_jmp_clear(){
}
str_jmp_table = NULL;
}
*/
int str_str_add(char *key, char *value){
char *key_local, *value_local;

View file

@ -23,9 +23,11 @@ int str_int_add(char *key, int value);
int str_int_find(char *key, int *out);
void str_int_clear();
void str_int_printall();
/*
int str_jmp_add(char *key, u64 value);
int str_jmp_find(char *key, u64 *out);
void str_jmp_clear();
*/
int str_str_add(char *key, char *value);
int str_str_find(char *key, char **out);
int str_str_index(int index, char **out);