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

Various improvements to scripting lang

- Errors will now be more precise, there are now 2 separate errors for a function lookup failure and a failure inside a function
- Errors will now show which line number they failed at, instead of the character offset
- Minus values are not considered errors anymore, however, printing them does not work well
- Gotos now make a @RETURN variable to make making functions easier
This commit is contained in:
Such Meme, Many Skill 2020-05-15 20:17:31 +02:00
parent f49245e4ab
commit 6934e1422f
6 changed files with 79 additions and 61 deletions

View file

@ -21,10 +21,11 @@ enum utils_err_codes_te_call {
ERR_EMMC_WRITE_FAILED, ERR_EMMC_WRITE_FAILED,
ERR_FILE_TOO_BIG_FOR_DEST, ERR_FILE_TOO_BIG_FOR_DEST,
ERR_SD_EJECTED, ERR_SD_EJECTED,
ERR_PARSE_FAIL, ERR_SCRIPT_LOOKUP_FAIL,
ERR_CANNOT_COPY_FILE_TO_FS_PART, ERR_CANNOT_COPY_FILE_TO_FS_PART,
ERR_NO_DESTINATION, ERR_NO_DESTINATION,
ERR_INI_PARSE_FAIL ERR_INI_PARSE_FAIL,
ERR_IN_FUNC
}; };
extern const char *utils_err_codes_te[]; extern const char *utils_err_codes_te[];

View file

@ -50,10 +50,11 @@ const char *utils_err_codes_te[] = { // these start at 50
"EMMC WRITE FAILED", "EMMC WRITE FAILED",
"FILE TOO BIG FOR DEST", "FILE TOO BIG FOR DEST",
"SD EJECTED", "SD EJECTED",
"PARSING FAILED", "FUNC LOOKUP FAIL",
"CANNOT COPY FILE TO FS PART", "CANNOT COPY FILE TO FS PART",
"NO DESTINATION", "NO DESTINATION",
"INI PARSE FAIL" "INI PARSE FAIL",
"ERR IN FUNC"
}; };
/* /*
const char *pkg2names[] = { const char *pkg2names[] = {

View file

@ -52,7 +52,7 @@ u32 gfx_errDisplay(const char *src_func, int err, int loc){
if (err < 15) if (err < 15)
gfx_printf("Desc: %s\n", utils_err_codes[err]); gfx_printf("Desc: %s\n", utils_err_codes[err]);
else if (err >= ERR_SAME_LOC && err <= ERR_INI_PARSE_FAIL) else if (err >= ERR_SAME_LOC && err <= ERR_IN_FUNC)
gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]); gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]);
if (loc) if (loc)

View file

@ -74,14 +74,14 @@ int part_printf(){
if (argv[i][0] == '@'){ if (argv[i][0] == '@'){
int toprintint; int toprintint;
if (parseIntInput(argv[i], &toprintint)) if (parseIntInput(argv[i], &toprintint))
return -1; return INFUNC_FAIL;
gfx_printf("%d", toprintint); gfx_printf("%d", toprintint);
} }
else { else {
char *toprintstring; char *toprintstring;
if (parseStringInput(argv[i], &toprintstring)) if (parseStringInput(argv[i], &toprintstring))
return -1; return INFUNC_FAIL;
gfx_printf(toprintstring); gfx_printf(toprintstring);
} }
@ -94,7 +94,7 @@ int part_printf(){
int part_print_int(){ int part_print_int(){
int toprint; int toprint;
if (parseIntInput(argv[0], &toprint)) if (parseIntInput(argv[0], &toprint))
return -1; return INFUNC_FAIL;
SWAPCOLOR(currentcolor); SWAPCOLOR(currentcolor);
gfx_printf("%s: %d\n", argv[0], toprint); gfx_printf("%s: %d\n", argv[0], toprint);
@ -107,7 +107,7 @@ int part_Wait(){
SWAPCOLOR(currentcolor); SWAPCOLOR(currentcolor);
if (parseIntInput(argv[0], &arg)) if (parseIntInput(argv[0], &arg))
return -1; return INFUNC_FAIL;
begintime = get_tmr_s(); begintime = get_tmr_s();
@ -122,9 +122,9 @@ int part_Wait(){
int part_Check(){ int part_Check(){
int left, right; int left, right;
if (parseIntInput(argv[0], &left)) if (parseIntInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseIntInput(argv[2], &right)) if (parseIntInput(argv[2], &right))
return -1; return INFUNC_FAIL;
if (!strcmp(argv[1], "==")) if (!strcmp(argv[1], "=="))
return (left == right); return (left == right);
@ -139,13 +139,13 @@ int part_Check(){
else if (!strcmp(argv[1], "<")) else if (!strcmp(argv[1], "<"))
return (left < right); return (left < right);
else else
return -1; return INFUNC_FAIL;
} }
int part_if(){ int part_if(){
int condition; int condition;
if (parseIntInput(argv[0], &condition)) if (parseIntInput(argv[0], &condition))
return -1; return INFUNC_FAIL;
getfollowingchar('{'); getfollowingchar('{');
@ -167,7 +167,7 @@ int part_if(){
int part_if_args(){ int part_if_args(){
int condition; int condition;
if ((condition = part_Check()) < 0) if ((condition = part_Check()) < 0)
return -1; return INFUNC_FAIL;
getfollowingchar('{'); getfollowingchar('{');
@ -180,9 +180,9 @@ int part_if_args(){
int part_Math(){ int part_Math(){
int left, right; int left, right;
if (parseIntInput(argv[0], &left)) if (parseIntInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseIntInput(argv[2], &right)) if (parseIntInput(argv[2], &right))
return -1; return INFUNC_FAIL;
switch (argv[1][0]){ switch (argv[1][0]){
case '+': case '+':
@ -194,7 +194,7 @@ int part_Math(){
case '/': case '/':
return left / right; return left / right;
} }
return -1; return INFUNC_FAIL;
} }
int part_SetInt(){ int part_SetInt(){
@ -206,9 +206,9 @@ int part_SetInt(){
int part_SetString(){ int part_SetString(){
char *arg0; char *arg0;
if (parseStringInput(argv[0], &arg0)) if (parseStringInput(argv[0], &arg0))
return -1; return INFUNC_FAIL;
if (argv[1][0] != '$') if (argv[1][0] != '$')
return -1; return INFUNC_FAIL;
str_str_add(argv[1], arg0); str_str_add(argv[1], arg0);
return 0; return 0;
@ -218,11 +218,11 @@ int part_SetStringIndex(){
int index; int index;
char *out; char *out;
if (parseIntInput(argv[0], &index)) if (parseIntInput(argv[0], &index))
return -1; return INFUNC_FAIL;
if (argv[1][0] != '$') if (argv[1][0] != '$')
return -1; return INFUNC_FAIL;
if (str_str_index(index, &out)) if (str_str_index(index, &out))
return -1; return INFUNC_FAIL;
str_str_add(argv[1], out); str_str_add(argv[1], out);
return 0; return 0;
@ -231,7 +231,10 @@ int part_SetStringIndex(){
int part_goto(){ int part_goto(){
int target = 0; int target = 0;
if (parseIntInput(argv[0], &target)) if (parseIntInput(argv[0], &target))
return -1; return INFUNC_FAIL;
str_int_add("@RETURN", (int)f_tell(&scriptin));
f_lseek(&scriptin, target); f_lseek(&scriptin, target);
return 0; return 0;
} }
@ -239,14 +242,14 @@ int part_goto(){
int part_invert(){ int part_invert(){
int arg; int arg;
if (parseIntInput(argv[0], &arg)) if (parseIntInput(argv[0], &arg))
return -1; return INFUNC_FAIL;
return (arg) ? 0 : 1; return (arg) ? 0 : 1;
} }
int part_fs_exists(){ int part_fs_exists(){
char *path; char *path;
if (parseStringInput(argv[0], &path)) if (parseStringInput(argv[0], &path))
return -1; return INFUNC_FAIL;
return fsutil_checkfile(path); return fsutil_checkfile(path);
} }
@ -260,7 +263,7 @@ int part_ConnectMMC(){
else if (!strcmp(arg, "EMUMMC")) else if (!strcmp(arg, "EMUMMC"))
connect_mmc(EMUMMC); connect_mmc(EMUMMC);
else else
return -1; return INFUNC_FAIL;
return 0; return 0;
} }
@ -292,11 +295,11 @@ int part_Pause(){
int part_addstrings(){ int part_addstrings(){
char *combined, *left, *middle; char *combined, *left, *middle;
if (parseStringInput(argv[0], &left)) if (parseStringInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseStringInput(argv[1], &middle)) if (parseStringInput(argv[1], &middle))
return -1; return INFUNC_FAIL;
if (argv[2][0] != '$') if (argv[2][0] != '$')
return -1; return INFUNC_FAIL;
combined = calloc(strlen(left) + strlen(middle) + 1, sizeof(char)); combined = calloc(strlen(left) + strlen(middle) + 1, sizeof(char));
sprintf(combined, "%s%s", left, middle); sprintf(combined, "%s%s", left, middle);
@ -309,7 +312,7 @@ int part_addstrings(){
int part_setColor(){ int part_setColor(){
char *arg; char *arg;
if (parseStringInput(argv[0], &arg)) if (parseStringInput(argv[0], &arg))
return -1; return INFUNC_FAIL;
if (!strcmp(arg, "RED")) if (!strcmp(arg, "RED"))
currentcolor = COLOR_RED; currentcolor = COLOR_RED;
@ -326,7 +329,7 @@ int part_setColor(){
else if (!strcmp(arg, "WHITE")) else if (!strcmp(arg, "WHITE"))
currentcolor = COLOR_WHITE; currentcolor = COLOR_WHITE;
else else
return -1; return INFUNC_FAIL;
return 0; return 0;
} }
@ -340,9 +343,9 @@ int part_fs_Move(){
char *left, *right; char *left, *right;
if (parseStringInput(argv[0], &left)) if (parseStringInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseStringInput(argv[1], &right)) if (parseStringInput(argv[1], &right))
return -1; return INFUNC_FAIL;
int res; int res;
res = f_rename(left, right); res = f_rename(left, right);
@ -356,7 +359,7 @@ int part_fs_Delete(){
char *arg; char *arg;
if (parseStringInput(argv[0], &arg)) if (parseStringInput(argv[0], &arg))
return -1; return INFUNC_FAIL;
int res; int res;
res = f_unlink(arg); res = f_unlink(arg);
@ -370,7 +373,7 @@ int part_fs_DeleteRecursive(){
char *arg; char *arg;
if (parseStringInput(argv[0], &arg)) if (parseStringInput(argv[0], &arg))
return -1; return INFUNC_FAIL;
return fsact_del_recursive(arg); return fsact_del_recursive(arg);
} }
@ -379,9 +382,9 @@ int part_fs_Copy(){
char *left, *right; char *left, *right;
if (parseStringInput(argv[0], &left)) if (parseStringInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseStringInput(argv[1], &right)) if (parseStringInput(argv[1], &right))
return -1; return INFUNC_FAIL;
return fsact_copy(left, right, COPY_MODE_PRINT); return fsact_copy(left, right, COPY_MODE_PRINT);
} }
@ -390,9 +393,9 @@ int part_fs_CopyRecursive(){
char *left, *right; char *left, *right;
if (parseStringInput(argv[0], &left)) if (parseStringInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseStringInput(argv[1], &right)) if (parseStringInput(argv[1], &right))
return -1; return INFUNC_FAIL;
return fsact_copy_recursive(left, right); return fsact_copy_recursive(left, right);
} }
@ -401,7 +404,7 @@ int part_fs_MakeDir(){
char *arg; char *arg;
if (parseStringInput(argv[0], &arg)) if (parseStringInput(argv[0], &arg))
return -1; return INFUNC_FAIL;
int res; int res;
res = f_mkdir(arg); res = f_mkdir(arg);
@ -418,10 +421,10 @@ int part_fs_OpenDir(){
char *path; char *path;
if (parseStringInput(argv[0], &path)) if (parseStringInput(argv[0], &path))
return -1; return INFUNC_FAIL;
if (f_opendir(&dir, path)) if (f_opendir(&dir, path))
return -1; return INFUNC_FAIL;
isdirvalid = true; isdirvalid = true;
str_int_add("@ISDIRVALID", isdirvalid); str_int_add("@ISDIRVALID", isdirvalid);
@ -440,7 +443,7 @@ int part_fs_CloseDir(){
int part_fs_ReadDir(){ int part_fs_ReadDir(){
if (!isdirvalid) if (!isdirvalid)
return -1; return INFUNC_FAIL;
if (!f_readdir(&dir, &fno) && fno.fname[0]){ if (!f_readdir(&dir, &fno) && fno.fname[0]){
str_str_add("$FILENAME", fno.fname); str_str_add("$FILENAME", fno.fname);
@ -457,16 +460,16 @@ int part_setPrintPos(){
int left, right; int left, right;
if (parseIntInput(argv[0], &left)) if (parseIntInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseIntInput(argv[1], &right)) if (parseIntInput(argv[1], &right))
return -1; return INFUNC_FAIL;
if (left > 78) if (left > 78)
return -1; return INFUNC_FAIL;
if (right > 42) if (right > 42)
return -1; return INFUNC_FAIL;
gfx_con_setpos(left * 16, right * 16); gfx_con_setpos(left * 16, right * 16);
return 0; return 0;
@ -476,9 +479,9 @@ int part_stringcompare(){
char *left, *right; char *left, *right;
if (parseStringInput(argv[0], &left)) if (parseStringInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseStringInput(argv[1], &right)) if (parseStringInput(argv[1], &right))
return -1; return INFUNC_FAIL;
return (strcmp(left, right)) ? 0 : 1; return (strcmp(left, right)) ? 0 : 1;
} }
@ -486,11 +489,11 @@ int part_stringcompare(){
int part_fs_combinePath(){ int part_fs_combinePath(){
char *combined, *left, *middle; char *combined, *left, *middle;
if (parseStringInput(argv[0], &left)) if (parseStringInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseStringInput(argv[1], &middle)) if (parseStringInput(argv[1], &middle))
return -1; return INFUNC_FAIL;
if (argv[2][0] != '$') if (argv[2][0] != '$')
return -1; return INFUNC_FAIL;
combined = fsutil_getnextloc(left, middle); combined = fsutil_getnextloc(left, middle);
@ -503,9 +506,9 @@ int part_mmc_dumpPart(){
char *left, *right; char *left, *right;
if (parseStringInput(argv[0], &left)) if (parseStringInput(argv[0], &left))
return -1; return INFUNC_FAIL;
if (parseStringInput(argv[1], &right)) if (parseStringInput(argv[1], &right))
return -1; return INFUNC_FAIL;
if (!strcmp(left, "BOOT")){ if (!strcmp(left, "BOOT")){
return emmcDumpBoot(right); return emmcDumpBoot(right);
@ -519,10 +522,10 @@ int part_mmc_restorePart(){
char *path; char *path;
if (parseStringInput(argv[0], &path)) if (parseStringInput(argv[0], &path))
return -1; return INFUNC_FAIL;
if (currentlyMounted < 0) if (currentlyMounted < 0)
return -1; return INFUNC_FAIL;
return mmcFlashFile(path, currentlyMounted, false); return mmcFlashFile(path, currentlyMounted, false);
} }
@ -531,9 +534,9 @@ int part_fs_extractBisFile(){
char *path, *outfolder; char *path, *outfolder;
if (parseStringInput(argv[0], &path)) if (parseStringInput(argv[0], &path))
return -1; return INFUNC_FAIL;
if (parseStringInput(argv[1], &outfolder)) if (parseStringInput(argv[1], &outfolder))
return -1; return INFUNC_FAIL;
return extract_bis_file(path, outfolder); return extract_bis_file(path, outfolder);
} }
@ -547,6 +550,8 @@ int part_getPos(){
return (int)f_tell(&scriptin); return (int)f_tell(&scriptin);
} }
str_fnc_struct functions[] = { str_fnc_struct functions[] = {
{"printf", part_printf, 255}, {"printf", part_printf, 255},
{"printInt", part_print_int, 1}, {"printInt", part_print_int, 1},
@ -596,8 +601,8 @@ int run_function(char *func_name, int *out){
continue; continue;
*out = functions[i].value(); *out = functions[i].value();
return (*out < 0) ? -1 : 0; return (*out == INFUNC_FAIL) ? -1 : 0;
} }
} }
return -1; return -2;
} }

View file

@ -220,7 +220,16 @@ void mainparser(){
printerrors = true; printerrors = true;
//gfx_printf("%s|%s|%d", funcbuff, argv[0], argc); //gfx_printf("%s|%s|%d", funcbuff, argv[0], argc);
//btn_wait(); //btn_wait();
gfx_errDisplay("mainparser", ERR_PARSE_FAIL, f_tell(&scriptin)); int lineNumber = 1;
u64 end = f_tell(&scriptin);
f_lseek(&scriptin, 0);
while (f_tell(&scriptin) < end && !f_eof(&scriptin)){
if (getnextchar() == '\n')
lineNumber++;
}
gfx_errDisplay((res == -1) ? funcbuff : "run_function", (res == -1) ? ERR_IN_FUNC : ERR_SCRIPT_LOOKUP_FAIL, lineNumber);
forceExit = true; forceExit = true;
//gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]); //gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]);
} }

View file

@ -1,5 +1,7 @@
#pragma once #pragma once
#define INFUNC_FAIL (int)0xC0000000
void runScript(char *path); void runScript(char *path);
void skipbrackets(); void skipbrackets();
void getfollowingchar(char end); void getfollowingchar(char end);