1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-08 05:01:46 +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_FILE_TOO_BIG_FOR_DEST,
ERR_SD_EJECTED,
ERR_PARSE_FAIL,
ERR_SCRIPT_LOOKUP_FAIL,
ERR_CANNOT_COPY_FILE_TO_FS_PART,
ERR_NO_DESTINATION,
ERR_INI_PARSE_FAIL
ERR_INI_PARSE_FAIL,
ERR_IN_FUNC
};
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",
"FILE TOO BIG FOR DEST",
"SD EJECTED",
"PARSING FAILED",
"FUNC LOOKUP FAIL",
"CANNOT COPY FILE TO FS PART",
"NO DESTINATION",
"INI PARSE FAIL"
"INI PARSE FAIL",
"ERR IN FUNC"
};
/*
const char *pkg2names[] = {

View file

@ -52,7 +52,7 @@ u32 gfx_errDisplay(const char *src_func, int err, int loc){
if (err < 15)
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]);
if (loc)

View file

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

View file

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