From 9aff029ee43822a45077598f0275f3b01011875c Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Mon, 30 Mar 2020 20:15:07 +0200 Subject: [PATCH 01/17] Start script rewrite --- source/tegraexplorer/fs/filemenu.c | 5 +- source/tegraexplorer/script/script.c | 161 +++++++++++++++ source/tegraexplorer/script/script.h | 3 + source/tegraexplorer/utils/script.c | 287 --------------------------- source/tegraexplorer/utils/script.h | 2 +- 5 files changed, 168 insertions(+), 290 deletions(-) create mode 100644 source/tegraexplorer/script/script.c create mode 100644 source/tegraexplorer/script/script.h delete mode 100644 source/tegraexplorer/utils/script.c diff --git a/source/tegraexplorer/fs/filemenu.c b/source/tegraexplorer/fs/filemenu.c index d2792a0..68e9b3c 100644 --- a/source/tegraexplorer/fs/filemenu.c +++ b/source/tegraexplorer/fs/filemenu.c @@ -13,7 +13,7 @@ #include "../gfx/menu.h" #include "../common/types.h" #include "../../utils/sprintf.h" -#include "../utils/script.h" +#include "../script/script.h" #include "../emmc/emmcoperations.h" extern char *currentpath; @@ -165,7 +165,8 @@ int filemenu(menu_entry file){ launch_payload(fsutil_getnextloc(currentpath, file.name)); break; case FILE_SCRIPT: - ParseScript(fsutil_getnextloc(currentpath, file.name)); + //ParseScript(fsutil_getnextloc(currentpath, file.name)); + tester(fsutil_getnextloc(currentpath, file.name)); break; case FILE_HEXVIEW: viewbytes(fsutil_getnextloc(currentpath, file.name)); diff --git a/source/tegraexplorer/script/script.c b/source/tegraexplorer/script/script.c new file mode 100644 index 0000000..2940355 --- /dev/null +++ b/source/tegraexplorer/script/script.c @@ -0,0 +1,161 @@ +#include +#include "../../mem/heap.h" +#include "../gfx/gfxutils.h" +#include "../emmc/emmc.h" +#include "../../utils/types.h" +#include "../../libs/fatfs/ff.h" +#include "../../utils/sprintf.h" +#include "../../utils/btn.h" +#include "../../gfx/gfx.h" +#include "../../utils/util.h" +#include "../../storage/emummc.h" +#include "script.h" +#include "../common/common.h" +#include "../fs/fsactions.h" + + +u32 countchars(char* in, char target) { + u32 len = strlen(in); + u32 count = 0; + for (u32 i = 0; i < len; i++) { + if (in[i] == target) + count++; + } + return count; +} + +char **args = NULL; +u32 splitargs(char* in) { + // arg like '5, "6", @arg7' + u32 i, current = 0, count = countchars(in, ',') + 1, len = strlen(in), curcount = 0; + + if (args != NULL) { + for (i = 0; args[i] != NULL; i++) + free(args[i]); + free(args); + } + + args = calloc(count + 1, sizeof(char*)); + + for (i = 0; i < count; i++) + args[i] = calloc(128, sizeof(char)); + + + for (i = 0; i < len && curcount < count; i++) { + if (in[i] == ',') { + curcount++; + current = 0; + } + else if (in[i] == '@' || in[i] == '$') { + while (in[i] != ',' && in[i] != ' ' && in[i] != ')' && i < len) { + args[curcount][current++] = in[i++]; + } + i--; + } + else if (in[i] >= '0' && in[i] <= '9') + args[curcount][current++] = in[i]; + else if (in[i] == '"') { + i++; + while (in[i] != '"') { + args[curcount][current++] = in[i++]; + } + } + } + return count; +} + +FIL scriptin; +UINT endByte = 0; +int forceExit = false; +char currentchar = 0; + +char getnextchar(){ + f_read(&scriptin, ¤tchar, sizeof(char), &endByte); + + if (sizeof(char) != endByte) + forceExit = true; + + gfx_printf("|%c|", currentchar); + return currentchar; +} + +void getfollowingchar(char end){ + while (currentchar != end){ + getnextchar(); + if (currentchar == '"'){ + while (getnextchar() != '"'); + } + } +} + +void getnextvalidchar(){ + while (!((currentchar >= '0' && currentchar <= 'Z') || (currentchar >= 'a' && currentchar <= 'z') || currentchar == '#' || currentchar == '@')) + getnextchar(); +} + +void mainparser(){ + char *unsplitargs; + FSIZE_t curoffset; + u32 argsize = 0; + + getnextvalidchar(); + + if (currentchar == '#'){ + getfollowingchar('\n'); + return; + } + + gfx_printf("Getting func name...\n"); + char *funcbuff = calloc(20, sizeof(char)); + for (int i = 0; i < 19 && currentchar != '(' && currentchar != ' '; i++){ + funcbuff[i] = currentchar; + getnextchar(); + } + gfx_printf("Skipping to next (...\n"); + getfollowingchar('('); + getnextchar(); + + curoffset = f_tell(&scriptin); + gfx_printf("Skipping to next )...\n"); + getfollowingchar(')'); + argsize = f_tell(&scriptin) - curoffset; + f_lseek(&scriptin, curoffset - 1); + + gfx_printf("Getting args...\nSize: %d\n", argsize); + getnextchar(); + unsplitargs = calloc(argsize, sizeof(char)); + for (int i = 0; i < argsize; i++){ + unsplitargs[i] = currentchar; + getnextchar(); + } + + gfx_printf("Splitting args...\n"); + int argcount = splitargs(unsplitargs); + + gfx_printf("\n\nFunc: %s\n", funcbuff); + gfx_printf("Split: %s\n", unsplitargs); + + for (int i = 0; i < argcount; i++) + gfx_printf("%d | %s\n", i, args[i]); + + free(unsplitargs); + free(funcbuff); +} + +void tester(char *path){ + int res; + + gfx_clearscreen(); + + res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING); + if (res != FR_OK){ + gfx_errDisplay("ParseScript", res, 1); + return; + } + + printerrors = false; + + + mainparser(); + btn_wait(); +} \ No newline at end of file diff --git a/source/tegraexplorer/script/script.h b/source/tegraexplorer/script/script.h new file mode 100644 index 0000000..5b35982 --- /dev/null +++ b/source/tegraexplorer/script/script.h @@ -0,0 +1,3 @@ +#pragma once + +void tester(char *path); \ No newline at end of file diff --git a/source/tegraexplorer/utils/script.c b/source/tegraexplorer/utils/script.c deleted file mode 100644 index 6caa565..0000000 --- a/source/tegraexplorer/utils/script.c +++ /dev/null @@ -1,287 +0,0 @@ -#include -#include "../../mem/heap.h" -#include "../gfx/gfxutils.h" -#include "../emmc/emmc.h" -#include "../../utils/types.h" -#include "../../libs/fatfs/ff.h" -#include "../../utils/sprintf.h" -#include "../../utils/btn.h" -#include "../../gfx/gfx.h" -#include "../../utils/util.h" -#include "../../storage/emummc.h" -#include "script.h" -#include "../common/common.h" -#include "../fs/fsactions.h" - -#include - -char func[11] = "", args[2][128] = {"", ""}; -int res, errcode; -const int scriptver = 140; -bool forceExit = false; -u32 currentcolor; - -void Part_CheckFile(){ - FILINFO fno; - errcode = f_stat(args[0], &fno); -} - -void Part_SetColor(){ - if (strcmpcheck(args[0], "RED")) - currentcolor = COLOR_RED; - else if (strcmpcheck(args[0], "ORANGE")) - currentcolor = COLOR_ORANGE; - else if (strcmpcheck(args[0], "YELLOW")) - currentcolor = COLOR_YELLOW; - else if (strcmpcheck(args[0], "GREEN")) - currentcolor = COLOR_GREEN; - else if (strcmpcheck(args[0], "BLUE")) - currentcolor = COLOR_BLUE; - else if (strcmpcheck(args[0], "VIOLET")) - currentcolor = COLOR_VIOLET; - else if (strcmpcheck(args[0], "WHITE")) - currentcolor = COLOR_WHITE; -} - -void Part_Wait(){ - int waitamount, begintime; - SWAPCOLOR(currentcolor); - - waitamount = atoi(args[0]); - begintime = get_tmr_s(); - - while (begintime + waitamount > get_tmr_s()){ - gfx_printf("\r ", (begintime + waitamount) - get_tmr_s()); - } - - gfx_printf("\r \r"); -} - -void Part_VersionCheck(){ - int givenversion = atoi(args[0]); - - if (givenversion > scriptver){ - gfx_printf("Script required version is too high\nUpdate TegraExplorer!"); - btn_wait(); - forceExit = true; - } -} - -void Part_Move(){ - errcode = f_rename(args[0], args[1]); - if (errcode) - f_rename(args[0], args[1]); -} - -void Part_Delete(){ - errcode = f_unlink(args[0]); - if (errcode) - f_unlink(args[0]); -} - -void Part_DeleteRecursive(){ - errcode = fsact_del_recursive(args[0]); -} - -void Part_Copy(){ - errcode = fsact_copy(args[0], args[1], COPY_MODE_PRINT); -} - -void Part_RecursiveCopy(){ - errcode = fsact_copy_recursive(args[0], args[1]); -} - -void Part_MakeFolder(){ - errcode = f_mkdir(args[0]); - if (errcode) - f_mkdir(args[0]); -} - -void Part_ConnectMMC(){ - if (strcmpcheck(args[0], "SYSMMC")) - connect_mmc(SYSMMC); - if (strcmpcheck(args[0], "EMUMMC")) - connect_mmc(EMUMMC); -} - -void Part_MountMMC(){ - errcode = mount_mmc(args[0], 2); -} - -void Part_Print(){ - RESETCOLOR; - SWAPCOLOR(currentcolor); - gfx_printf("%s\n", args[0]); -} - -void Part_ErrorPrint(){ - RESETCOLOR; - SWAPCOLOR(COLOR_RED); - gfx_printf("Errorcode: %d\n", errcode); -} - -void Part_Exit(){ - forceExit = true; -} - -u8 buttons_pressed = 0; -void Part_WaitOnUser(){ - buttons_pressed = btn_wait(); -} - -script_parts parts[] = { - {"COPY", Part_Copy, 2}, - {"COPY-R", Part_RecursiveCopy, 2}, - {"MKDIR", Part_MakeFolder, 1}, - {"CON_MMC", Part_ConnectMMC, 1}, - {"MNT_MMC", Part_MountMMC, 1}, - {"PRINT", Part_Print, 1}, - {"ERRPRINT", Part_ErrorPrint, 0}, - {"EXIT", Part_Exit, 0}, - {"PAUSE", Part_WaitOnUser, 0}, - {"DEL", Part_Delete, 1}, - {"DEL-R", Part_DeleteRecursive, 1}, - {"MOVE", Part_Move, 2}, - {"VERSION", Part_VersionCheck, 1}, - {"WAIT", Part_Wait, 1}, - {"COLOR", Part_SetColor, 1}, - {"CHECKPATH", Part_CheckFile, 1}, - {"NULL", NULL, -1} -}; - -int ParsePart(){ - int i; - for (i = 0; parts[i].arg_amount != -1; i++){ - if (strcmpcheck(func, parts[i].name)) - return i; - } - gfx_printf("Parsing error...\nPress any key to continue"); - btn_wait(); - forceExit = true; - printerrors = true; - return -1; -} - -FIL in; -UINT endByte = 0; - -char GetNextByte(){ - char single; - f_read(&in, &single, sizeof(char), &endByte); - - if (sizeof(char) != endByte) - forceExit = true; - - return single; -} - -void ParseScript(char* path){ - char currentchar; - int strlength; - bool inifstatement = false; - forceExit = false; - currentcolor = COLOR_WHITE; - - gfx_clearscreen(); - - res = f_open(&in, path, FA_READ | FA_OPEN_EXISTING); - if (res != FR_OK){ - gfx_errDisplay("ParseScript", res, 1); - return; - } - - printerrors = false; - - while (!forceExit){ - currentchar = GetNextByte(); - - if (endByte == 0 || currentchar == (char)EOF) - break; - - switch(currentchar){ - case '{': - if (!inifstatement) - while (currentchar != '}') - currentchar = GetNextByte(); - - break; - case '}': - if (inifstatement) - inifstatement = false; - - break; - case '<': - strlength = 0; - currentchar = GetNextByte(); - - while (currentchar != '>'){ - func[strlength++] = currentchar; - currentchar = GetNextByte(); - } - func[strlength] = '\0'; - - res = ParsePart(); - if (res == -1) - break; - - for (int i = 0; i < parts[res].arg_amount; i++){ - while (currentchar != 0x22) - currentchar = GetNextByte(); - - strlength = 0; - currentchar = GetNextByte(); - while (currentchar != 0x22){ - args[i][strlength++] = currentchar; - currentchar = GetNextByte(); - } - args[i][strlength] = '\0'; - - if (i < parts[res].arg_amount) - currentchar = GetNextByte(); - } - parts[res].handler(); - break; - case '$': - strlength = 0; - currentchar = GetNextByte(); - - while (currentchar != '$'){ - func[strlength++] = currentchar; - currentchar = GetNextByte(); - } - func[strlength] = '\0'; - - if (strcmpcheck(func, "ERROR") || strcmpcheck(func, "TRUE")){ - inifstatement = (errcode); - } - else if (strcmpcheck(func, "NOERROR") || strcmpcheck(func, "FALSE")){ - inifstatement = (!errcode); - } - else if (strcmpcheck(func, "BTN_POWER")){ - inifstatement = (buttons_pressed & BTN_POWER); - } - else if (strcmpcheck(func, "BTN_VOL+")){ - inifstatement = (buttons_pressed & BTN_VOL_UP); - } - else if (strcmpcheck(func, "BTN_VOL-")){ - inifstatement = (buttons_pressed & BTN_VOL_DOWN); - } - else if (strcmpcheck(func, "EMUMMC")){ - inifstatement = (emu_cfg.enabled); - } - else if (strcmpcheck(func, "NOEMUMMC")){ - inifstatement = (!emu_cfg.enabled); - } - - if (inifstatement) - while(currentchar != '{') - currentchar = GetNextByte(); - - break; - - } - } - - printerrors = true; - f_close(&in); -} \ No newline at end of file diff --git a/source/tegraexplorer/utils/script.h b/source/tegraexplorer/utils/script.h index 079ca92..fc122b3 100644 --- a/source/tegraexplorer/utils/script.h +++ b/source/tegraexplorer/utils/script.h @@ -8,4 +8,4 @@ typedef struct _script_parts { short arg_amount; } script_parts; -void ParseScript(char* path); +//void ParseScript(char* path); From 887972d67c88e63ae1930e46c3d5811537bf81d8 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Mon, 30 Mar 2020 22:40:59 +0200 Subject: [PATCH 02/17] Add arg recognition + more command reading --- source/tegraexplorer/script/script.c | 151 ++++++++++++++++++--------- 1 file changed, 103 insertions(+), 48 deletions(-) diff --git a/source/tegraexplorer/script/script.c b/source/tegraexplorer/script/script.c index 2940355..8a05d09 100644 --- a/source/tegraexplorer/script/script.c +++ b/source/tegraexplorer/script/script.c @@ -24,21 +24,22 @@ u32 countchars(char* in, char target) { return count; } -char **args = NULL; +char **argv = NULL; +u32 argc; u32 splitargs(char* in) { // arg like '5, "6", @arg7' u32 i, current = 0, count = countchars(in, ',') + 1, len = strlen(in), curcount = 0; - if (args != NULL) { - for (i = 0; args[i] != NULL; i++) - free(args[i]); - free(args); + if (argv != NULL) { + for (i = 0; argv[i] != NULL; i++) + free(argv[i]); + free(argv); } - args = calloc(count + 1, sizeof(char*)); + argv = calloc(count + 1, sizeof(char*)); for (i = 0; i < count; i++) - args[i] = calloc(128, sizeof(char)); + argv[i] = calloc(128, sizeof(char)); for (i = 0; i < len && curcount < count; i++) { @@ -48,16 +49,16 @@ u32 splitargs(char* in) { } else if (in[i] == '@' || in[i] == '$') { while (in[i] != ',' && in[i] != ' ' && in[i] != ')' && i < len) { - args[curcount][current++] = in[i++]; + argv[curcount][current++] = in[i++]; } i--; } else if (in[i] >= '0' && in[i] <= '9') - args[curcount][current++] = in[i]; + argv[curcount][current++] = in[i]; else if (in[i] == '"') { i++; while (in[i] != '"') { - args[curcount][current++] = in[i++]; + argv[curcount][current++] = in[i++]; } } } @@ -75,71 +76,121 @@ char getnextchar(){ if (sizeof(char) != endByte) forceExit = true; - gfx_printf("|%c|", currentchar); + //gfx_printf("|%c|", currentchar); return currentchar; } void getfollowingchar(char end){ while (currentchar != end){ - getnextchar(); if (currentchar == '"'){ while (getnextchar() != '"'); } + getnextchar(); } } void getnextvalidchar(){ - while (!((currentchar >= '0' && currentchar <= 'Z') || (currentchar >= 'a' && currentchar <= 'z') || currentchar == '#' || currentchar == '@')) + while ((!((currentchar >= '0' && currentchar <= 'Z') || (currentchar >= 'a' && currentchar <= 'z') || currentchar == '#' || currentchar == '@') && !f_eof(&scriptin)) || currentchar == ';') getnextchar(); } -void mainparser(){ +void functionparser(){ char *unsplitargs; - FSIZE_t curoffset; + FSIZE_t fileoffset; u32 argsize = 0; + //gfx_printf("getting func %c\n", currentchar); + char *funcbuff = calloc(20, sizeof(char)); + for (int i = 0; i < 19 && currentchar != '(' && currentchar != ' '; i++){ + funcbuff[i] = currentchar; + getnextchar(); + } + getfollowingchar('('); + getnextchar(); + + //gfx_printf("getting arg len %c\n", currentchar); + + fileoffset = f_tell(&scriptin); + getfollowingchar(')'); + argsize = f_tell(&scriptin) - fileoffset; + f_lseek(&scriptin, fileoffset - 1); + + getnextchar(); + + //gfx_printf("getting args %c\n", currentchar); + + unsplitargs = calloc(argsize + 1, sizeof(char)); + for (int i = 0; i < argsize; i++){ + unsplitargs[i] = currentchar; + getnextchar(); + } + + //gfx_printf("parsing args %c\n", currentchar); + argc = splitargs(unsplitargs); + getnextchar(); + + gfx_printf("\n\nFunc: %s\n", funcbuff, currentchar); + gfx_printf("Split: %s\n", unsplitargs); + + for (int i = 0; i < argc; i++) + gfx_printf("%d | %s\n", i, argv[i]); + + free(unsplitargs); + free(funcbuff); +} + +char *gettargetvar(){ + char *variable = NULL; + FSIZE_t fileoffset; + u32 varsize = 0; + + fileoffset = f_tell(&scriptin); + getfollowingchar('='); + varsize = f_tell(&scriptin) - fileoffset; + f_lseek(&scriptin, fileoffset - 1); + + variable = calloc(varsize + 1, sizeof(char)); + + getnextchar(); + for (int i = 0; i < varsize; i++){ + if (currentchar == ' ') + break; + + variable[i] = currentchar; + getnextchar(); + } + + getfollowingchar('='); + getnextchar(); + + return variable; +} + +void mainparser(){ + char *variable = NULL; + FSIZE_t fileoffset; + u32 varsize = 0; + getnextvalidchar(); + if (f_eof(&scriptin)) + return; + if (currentchar == '#'){ getfollowingchar('\n'); return; } - gfx_printf("Getting func name...\n"); - char *funcbuff = calloc(20, sizeof(char)); - for (int i = 0; i < 19 && currentchar != '(' && currentchar != ' '; i++){ - funcbuff[i] = currentchar; - getnextchar(); - } - gfx_printf("Skipping to next (...\n"); - getfollowingchar('('); - getnextchar(); - - curoffset = f_tell(&scriptin); - gfx_printf("Skipping to next )...\n"); - getfollowingchar(')'); - argsize = f_tell(&scriptin) - curoffset; - f_lseek(&scriptin, curoffset - 1); - - gfx_printf("Getting args...\nSize: %d\n", argsize); - getnextchar(); - unsplitargs = calloc(argsize, sizeof(char)); - for (int i = 0; i < argsize; i++){ - unsplitargs[i] = currentchar; - getnextchar(); + if (currentchar == '@'){ + variable = gettargetvar(); + getnextvalidchar(); } - gfx_printf("Splitting args...\n"); - int argcount = splitargs(unsplitargs); + functionparser(); + if (variable != NULL) + gfx_printf("target: %s", variable); - gfx_printf("\n\nFunc: %s\n", funcbuff); - gfx_printf("Split: %s\n", unsplitargs); - - for (int i = 0; i < argcount; i++) - gfx_printf("%d | %s\n", i, args[i]); - - free(unsplitargs); - free(funcbuff); + free(variable); } void tester(char *path){ @@ -152,10 +203,14 @@ void tester(char *path){ gfx_errDisplay("ParseScript", res, 1); return; } + printerrors = false; + while (!f_eof(&scriptin)){ + mainparser(); + } - mainparser(); + f_close(&scriptin); btn_wait(); } \ No newline at end of file From c4783fc2ca3b8436307278e9ab4363f36cd425fa Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Tue, 31 Mar 2020 00:09:23 +0200 Subject: [PATCH 03/17] Cleanup --- source/tegraexplorer/script/script.c | 69 +++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/source/tegraexplorer/script/script.c b/source/tegraexplorer/script/script.c index 8a05d09..349be90 100644 --- a/source/tegraexplorer/script/script.c +++ b/source/tegraexplorer/script/script.c @@ -94,22 +94,81 @@ void getnextvalidchar(){ getnextchar(); } +char *makestr(u32 size, char ignore){ + char *str; + u32 count = 0; + + str = calloc(size + 1, sizeof(char)); + for (u32 i = 0; i < size; i++){ + getnextchar(); + if (ignore != 0 && ignore == currentchar) + continue; + + str[count++] = currentchar; + } + + return str; +} +/* +char *makestrstrip(u32 size){ + char *str; + int count = 0; + + str = calloc(size + 1, sizeof(char)); + for (u32 i = 0; i < size;){ + if (currentchar == '"'){ + getnextchar(); + i++; + while (getnextchar() != '"') + i++; + } + else if (currentchar == ' '){ + while (getnextchar() == ' ') + i++; + } + else{ + getnextchar(); + i++; + } + + str[count++] = currentchar; + } + + return str; +} +*/ + +char *readtilchar(char end, char ignore){ // this will strip spaces unless it's enclosed in a "" + FSIZE_t offset, size; + + offset = f_tell(&scriptin); + getfollowingchar(end); + size = f_tell(&scriptin) - offset; + f_lseek(&scriptin, offset - 1); + + return makestr((u32)size, ignore); +} + void functionparser(){ char *unsplitargs; FSIZE_t fileoffset; u32 argsize = 0; //gfx_printf("getting func %c\n", currentchar); - char *funcbuff = calloc(20, sizeof(char)); + char *funcbuff = readtilchar('(', 0); + /*calloc(20, sizeof(char)); for (int i = 0; i < 19 && currentchar != '(' && currentchar != ' '; i++){ funcbuff[i] = currentchar; getnextchar(); } + */ + getfollowingchar('('); getnextchar(); //gfx_printf("getting arg len %c\n", currentchar); + /* fileoffset = f_tell(&scriptin); getfollowingchar(')'); argsize = f_tell(&scriptin) - fileoffset; @@ -124,10 +183,13 @@ void functionparser(){ unsplitargs[i] = currentchar; getnextchar(); } + */ + unsplitargs = readtilchar(')', 0); //gfx_printf("parsing args %c\n", currentchar); argc = splitargs(unsplitargs); getnextchar(); + getnextchar(); gfx_printf("\n\nFunc: %s\n", funcbuff, currentchar); gfx_printf("Split: %s\n", unsplitargs); @@ -135,6 +197,7 @@ void functionparser(){ for (int i = 0; i < argc; i++) gfx_printf("%d | %s\n", i, argv[i]); + //gfx_printf("\ncurrent char: %c", currentchar); free(unsplitargs); free(funcbuff); } @@ -144,6 +207,7 @@ char *gettargetvar(){ FSIZE_t fileoffset; u32 varsize = 0; + /* fileoffset = f_tell(&scriptin); getfollowingchar('='); varsize = f_tell(&scriptin) - fileoffset; @@ -159,6 +223,9 @@ char *gettargetvar(){ variable[i] = currentchar; getnextchar(); } + */ + + variable = readtilchar('=', ' '); getfollowingchar('='); getnextchar(); From 33a64abfb0155a0955441d8af1952e773f9da914 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Tue, 31 Mar 2020 00:16:46 +0200 Subject: [PATCH 04/17] Small fixes --- source/tegraexplorer/gfx/menu.c | 2 +- source/tegraexplorer/script/script.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/tegraexplorer/gfx/menu.c b/source/tegraexplorer/gfx/menu.c index c10c300..a85e6df 100644 --- a/source/tegraexplorer/gfx/menu.c +++ b/source/tegraexplorer/gfx/menu.c @@ -73,7 +73,7 @@ int menu_make(menu_entry *entries, int amount, char *toptext){ if (calculatedamount){ SWAPCOLOR(COLOR_DEFAULT); SWAPBGCOLOR(COLOR_WHITE); - gfx_printf("%3d entries\n", amount); + gfx_printf("%3d entries\n", calculatedamount); RESETCOLOR; } else diff --git a/source/tegraexplorer/script/script.c b/source/tegraexplorer/script/script.c index 349be90..d0a505f 100644 --- a/source/tegraexplorer/script/script.c +++ b/source/tegraexplorer/script/script.c @@ -155,7 +155,7 @@ void functionparser(){ u32 argsize = 0; //gfx_printf("getting func %c\n", currentchar); - char *funcbuff = readtilchar('(', 0); + char *funcbuff = readtilchar('(', ' '); /*calloc(20, sizeof(char)); for (int i = 0; i < 19 && currentchar != '(' && currentchar != ' '; i++){ funcbuff[i] = currentchar; From 38f349618fe8272f79992ded90e92cb7d5b03532 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Tue, 31 Mar 2020 14:24:34 +0200 Subject: [PATCH 05/17] Add functions and int vars --- source/tegraexplorer/fs/filemenu.c | 2 +- source/tegraexplorer/script/functions.c | 66 ++++++++++++++ source/tegraexplorer/script/functions.h | 13 +++ .../script/{script.c => parser.c} | 57 ++++++++++-- source/tegraexplorer/script/parser.h | 5 ++ source/tegraexplorer/script/script.h | 3 - source/tegraexplorer/script/variables.c | 89 +++++++++++++++++++ source/tegraexplorer/script/variables.h | 25 ++++++ 8 files changed, 250 insertions(+), 10 deletions(-) create mode 100644 source/tegraexplorer/script/functions.c create mode 100644 source/tegraexplorer/script/functions.h rename source/tegraexplorer/script/{script.c => parser.c} (82%) create mode 100644 source/tegraexplorer/script/parser.h delete mode 100644 source/tegraexplorer/script/script.h create mode 100644 source/tegraexplorer/script/variables.c create mode 100644 source/tegraexplorer/script/variables.h diff --git a/source/tegraexplorer/fs/filemenu.c b/source/tegraexplorer/fs/filemenu.c index 68e9b3c..428004c 100644 --- a/source/tegraexplorer/fs/filemenu.c +++ b/source/tegraexplorer/fs/filemenu.c @@ -13,7 +13,7 @@ #include "../gfx/menu.h" #include "../common/types.h" #include "../../utils/sprintf.h" -#include "../script/script.h" +#include "../script/parser.h" #include "../emmc/emmcoperations.h" extern char *currentpath; diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c new file mode 100644 index 0000000..fb8515b --- /dev/null +++ b/source/tegraexplorer/script/functions.c @@ -0,0 +1,66 @@ +#include +#include +#include "../../mem/heap.h" +#include "../gfx/gfxutils.h" +#include "../emmc/emmc.h" +#include "../../utils/types.h" +#include "../../libs/fatfs/ff.h" +#include "../../utils/sprintf.h" +#include "../../utils/btn.h" +#include "../../gfx/gfx.h" +#include "../../utils/util.h" +#include "../../storage/emummc.h" +#include "parser.h" +#include "../common/common.h" +#include "../fs/fsactions.h" +#include "variables.h" +#include "../utils/utils.h" +#include "functions.h" + +extern FIL scriptin; +extern char **argv; +extern u32 argc; + +int part_printf(){ + gfx_printf(argv[0]); + gfx_printf("\n"); + return 0; +} + +int part_if(){ + int condition; + if (argv[0][0] == '@'){ + if (str_int_find(argv[0], &condition)) + return -10; + } + else + condition = atoi(argv[0]); + + getfollowingchar('{'); + + if (condition) + return 0; + else { + skipbrackets(); + return 0; + } +} + +str_fnc_struct functions[] = { + {"printf", part_printf, 1}, + {"if", part_if, 1}, + {NULL, NULL, 0} +}; + +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; + + *out = functions[i].value(); + return 0; + } + } + return -1; +} \ No newline at end of file diff --git a/source/tegraexplorer/script/functions.h b/source/tegraexplorer/script/functions.h new file mode 100644 index 0000000..ac9e03d --- /dev/null +++ b/source/tegraexplorer/script/functions.h @@ -0,0 +1,13 @@ +#pragma once +#include "../../utils/types.h" + +typedef void (*func_void_ptr)(); +typedef int (*func_int_ptr)(); + +typedef struct { + char *key; + func_int_ptr value; + u8 arg_count; +} str_fnc_struct; + +int run_function(char *func_name, int *out); \ No newline at end of file diff --git a/source/tegraexplorer/script/script.c b/source/tegraexplorer/script/parser.c similarity index 82% rename from source/tegraexplorer/script/script.c rename to source/tegraexplorer/script/parser.c index d0a505f..863d740 100644 --- a/source/tegraexplorer/script/script.c +++ b/source/tegraexplorer/script/parser.c @@ -9,9 +9,11 @@ #include "../../gfx/gfx.h" #include "../../utils/util.h" #include "../../storage/emummc.h" -#include "script.h" +#include "parser.h" #include "../common/common.h" #include "../fs/fsactions.h" +#include "functions.h" +#include "variables.h" u32 countchars(char* in, char target) { @@ -90,7 +92,7 @@ void getfollowingchar(char end){ } void getnextvalidchar(){ - while ((!((currentchar >= '0' && currentchar <= 'Z') || (currentchar >= 'a' && currentchar <= 'z') || currentchar == '#' || currentchar == '@') && !f_eof(&scriptin)) || currentchar == ';') + while ((!((currentchar >= 'A' && currentchar <= 'Z') || (currentchar >= 'a' && currentchar <= 'z') || currentchar == '#' || currentchar == '@') && !f_eof(&scriptin)) /*|| currentchar == ';' */) getnextchar(); } @@ -149,13 +151,18 @@ char *readtilchar(char end, char ignore){ // this will strip spaces unless it's return makestr((u32)size, ignore); } + +char *funcbuff = NULL; void functionparser(){ char *unsplitargs; FSIZE_t fileoffset; u32 argsize = 0; + if (funcbuff != NULL) + free(funcbuff); + //gfx_printf("getting func %c\n", currentchar); - char *funcbuff = readtilchar('(', ' '); + funcbuff = readtilchar('(', ' '); /*calloc(20, sizeof(char)); for (int i = 0; i < 19 && currentchar != '(' && currentchar != ' '; i++){ funcbuff[i] = currentchar; @@ -176,7 +183,7 @@ void functionparser(){ getnextchar(); - //gfx_printf("getting args %c\n", currentchar); + gfx_printf("getting args %c\n", currentchar); unsplitargs = calloc(argsize + 1, sizeof(char)); for (int i = 0; i < argsize; i++){ @@ -191,15 +198,16 @@ void functionparser(){ getnextchar(); getnextchar(); + /* gfx_printf("\n\nFunc: %s\n", funcbuff, currentchar); gfx_printf("Split: %s\n", unsplitargs); for (int i = 0; i < argc; i++) gfx_printf("%d | %s\n", i, argv[i]); + */ //gfx_printf("\ncurrent char: %c", currentchar); free(unsplitargs); - free(funcbuff); } char *gettargetvar(){ @@ -235,6 +243,7 @@ char *gettargetvar(){ void mainparser(){ char *variable = NULL; + int res, out = 0; FSIZE_t fileoffset; u32 varsize = 0; @@ -254,12 +263,38 @@ void mainparser(){ } functionparser(); + /* if (variable != NULL) - gfx_printf("target: %s", variable); + gfx_printf("target: %s\n", variable); + */ + //gfx_printf("Func: %s\n", funcbuff); + res = run_function(funcbuff, &out); + str_int_add("@RESULT", res); + + if (variable != NULL) + str_int_add(variable, res); + + //gfx_printf("\nGoing to next func %c\n", currentchar); free(variable); } +void skipbrackets(){ + u32 bracketcounter = 0; + + getfollowingchar('{'); + getnextchar(); + + while (currentchar != '}' || bracketcounter != 0){ + if (currentchar == '{') + bracketcounter++; + else if (currentchar == '}') + bracketcounter--; + + getnextchar(); + } +} + void tester(char *path){ int res; @@ -271,6 +306,12 @@ void tester(char *path){ return; } + //add builtin vars + str_int_add("@EMUMMC", emu_cfg.enabled); + str_int_add("@RESULT", 0); + str_int_add("@BTN_POWER", 0); + str_int_add("@BTN_VOL+", 0); + str_int_add("@BTN_VOL-", 0); printerrors = false; @@ -278,6 +319,10 @@ void tester(char *path){ mainparser(); } + printerrors = true; + //str_int_printall(); + f_close(&scriptin); + str_int_clear(); btn_wait(); } \ No newline at end of file diff --git a/source/tegraexplorer/script/parser.h b/source/tegraexplorer/script/parser.h new file mode 100644 index 0000000..2c42b86 --- /dev/null +++ b/source/tegraexplorer/script/parser.h @@ -0,0 +1,5 @@ +#pragma once + +void tester(char *path); +void skipbrackets(); +void getfollowingchar(char end); \ No newline at end of file diff --git a/source/tegraexplorer/script/script.h b/source/tegraexplorer/script/script.h deleted file mode 100644 index 5b35982..0000000 --- a/source/tegraexplorer/script/script.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -void tester(char *path); \ No newline at end of file diff --git a/source/tegraexplorer/script/variables.c b/source/tegraexplorer/script/variables.c new file mode 100644 index 0000000..70ec073 --- /dev/null +++ b/source/tegraexplorer/script/variables.c @@ -0,0 +1,89 @@ +#include +#include "../../mem/heap.h" +#include "../gfx/gfxutils.h" +#include "../emmc/emmc.h" +#include "../../utils/types.h" +#include "../../libs/fatfs/ff.h" +#include "../../utils/sprintf.h" +#include "../../utils/btn.h" +#include "../../gfx/gfx.h" +#include "../../utils/util.h" +#include "../../storage/emummc.h" +#include "parser.h" +#include "../common/common.h" +#include "../fs/fsactions.h" +#include "variables.h" +#include "../utils/utils.h" + +static dict_str_int *str_int_table = NULL; +static dict_str_str *str_str_table = NULL; +static dict_str_loc *str_jmp_table = NULL; + +int str_int_add(char *key, int value){ + char *key_local; + dict_str_int *keyvaluepair; + + utils_copystring(key, &key_local); + + keyvaluepair = calloc(1, sizeof(keyvaluepair)); + keyvaluepair->key = key_local; + keyvaluepair->value = value; + keyvaluepair->next = NULL; + if (str_int_table == NULL){ + str_int_table = keyvaluepair; + } + else { + dict_str_int *temp; + temp = str_int_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_int_find(char *key, int *out){ + dict_str_int *temp; + temp = str_int_table; + while (temp != NULL){ + if (!strcmp(temp->key, key)){ + *out = temp->value; + return 0; + } + temp = temp->next; + } + + return -1; +} + +void str_int_clear(){ + dict_str_int *cur, *next; + cur = str_int_table; + + while (cur != NULL){ + next = cur->next; + free(cur->key); + free(cur); + cur = next; + } +} + +void str_int_printall(){ + dict_str_int *temp; + temp = str_int_table; + while (temp != NULL){ + gfx_printf("%s -> %d\n", temp->key, temp->value); + temp = temp->next; + } +} \ No newline at end of file diff --git a/source/tegraexplorer/script/variables.h b/source/tegraexplorer/script/variables.h new file mode 100644 index 0000000..6f34133 --- /dev/null +++ b/source/tegraexplorer/script/variables.h @@ -0,0 +1,25 @@ +#pragma once +#include "../../utils/types.h" + +typedef struct _dict_str_int { + char *key; + int value; + struct _dict_str_int *next; +} dict_str_int; + +typedef struct _dict_str_str { + char *key; + char *value; + struct _dict_str_str *next; +} dict_str_str; + +typedef struct _dict_str_loc { + char *key; + u64 value; + struct _dict_str_loc *next; +} 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 From 30afcddd3a2565f8651a50653e1178eadfbb8dde Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Tue, 31 Mar 2020 15:34:19 +0200 Subject: [PATCH 06/17] more functions, cleanup and simple error checking --- source/tegraexplorer/common/common.h | 3 +- source/tegraexplorer/common/strings.c | 3 +- source/tegraexplorer/gfx/gfxutils.c | 2 +- source/tegraexplorer/script/functions.c | 75 ++++++++++++++-- source/tegraexplorer/script/parser.c | 114 +++++------------------- 5 files changed, 96 insertions(+), 101 deletions(-) diff --git a/source/tegraexplorer/common/common.h b/source/tegraexplorer/common/common.h index 31c7b61..d163e58 100644 --- a/source/tegraexplorer/common/common.h +++ b/source/tegraexplorer/common/common.h @@ -20,7 +20,8 @@ enum utils_err_codes_te_call { ERR_EMMC_READ_FAILED, ERR_EMMC_WRITE_FAILED, ERR_FILE_TOO_BIG_FOR_DEST, - ERR_SD_EJECTED + ERR_SD_EJECTED, + ERR_PARSE_FAIL }; extern const char *utils_err_codes_te[]; diff --git a/source/tegraexplorer/common/strings.c b/source/tegraexplorer/common/strings.c index 6271bf7..5d25aee 100644 --- a/source/tegraexplorer/common/strings.c +++ b/source/tegraexplorer/common/strings.c @@ -49,7 +49,8 @@ const char *utils_err_codes_te[] = { // these start at 50 "EMMC READ FAILED", "EMMC WRITE FAILED", "FILE TOO BIG FOR DEST", - "SD EJECTED" + "SD EJECTED", + "PARSING FAILED" }; const char *pkg2names[] = { diff --git a/source/tegraexplorer/gfx/gfxutils.c b/source/tegraexplorer/gfx/gfxutils.c index 144b126..4c60510 100644 --- a/source/tegraexplorer/gfx/gfxutils.c +++ b/source/tegraexplorer/gfx/gfxutils.c @@ -54,7 +54,7 @@ int gfx_errDisplay(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_SD_EJECTED) + else if (err >= ERR_SAME_LOC && err <= ERR_PARSE_FAIL) gfx_printf("Desc: %s\n", utils_err_codes_te[err - 50]); if (loc) diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index fb8515b..1ec84b9 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -21,20 +21,35 @@ extern FIL scriptin; extern char **argv; extern u32 argc; +int parseIntInput(char *in, int *out){ + if (in[0] == '@'){ + if (str_int_find(argv[0], out)) + return -1; + } + else + *out = atoi(in); + + return 0; +} + int part_printf(){ gfx_printf(argv[0]); gfx_printf("\n"); return 0; } +int part_print_int(){ + int toprint; + if (parseIntInput(argv[0], &toprint)) + return -1; + gfx_printf("%s: %d\n", argv[0], toprint); + return 0; +} + int part_if(){ int condition; - if (argv[0][0] == '@'){ - if (str_int_find(argv[0], &condition)) - return -10; - } - else - condition = atoi(argv[0]); + if (parseIntInput(argv[0], &condition)) + return -1; getfollowingchar('{'); @@ -46,9 +61,55 @@ int part_if(){ } } +int part_Math(){ + int left, right; + if (parseIntInput(argv[0], &left)) + return -1; + if (parseIntInput(argv[2], &right)) + return -1; + + switch (argv[1][0]){ + case '+': + return left + right; + case '-': + return left - right; + case '*': + return left * right; + case '/': + return left * right; + } + 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; +} + str_fnc_struct functions[] = { {"printf", part_printf, 1}, + {"print_int", part_print_int, 1}, {"if", part_if, 1}, + {"math", part_Math, 3}, + {"check", part_Check, 3}, {NULL, NULL, 0} }; @@ -59,6 +120,8 @@ int run_function(char *func_name, int *out){ return -2; *out = functions[i].value(); + if (*out < 0) + return -1; return 0; } } diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index 863d740..d6aa5dc 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -111,36 +111,8 @@ char *makestr(u32 size, char ignore){ return str; } -/* -char *makestrstrip(u32 size){ - char *str; - int count = 0; - str = calloc(size + 1, sizeof(char)); - for (u32 i = 0; i < size;){ - if (currentchar == '"'){ - getnextchar(); - i++; - while (getnextchar() != '"') - i++; - } - else if (currentchar == ' '){ - while (getnextchar() == ' ') - i++; - } - else{ - getnextchar(); - i++; - } - - str[count++] = currentchar; - } - - return str; -} -*/ - -char *readtilchar(char end, char ignore){ // this will strip spaces unless it's enclosed in a "" +char *readtilchar(char end, char ignore){ FSIZE_t offset, size; offset = f_tell(&scriptin); @@ -161,52 +133,17 @@ void functionparser(){ if (funcbuff != NULL) free(funcbuff); - //gfx_printf("getting func %c\n", currentchar); funcbuff = readtilchar('(', ' '); - /*calloc(20, sizeof(char)); - for (int i = 0; i < 19 && currentchar != '(' && currentchar != ' '; i++){ - funcbuff[i] = currentchar; - getnextchar(); - } - */ getfollowingchar('('); getnextchar(); - //gfx_printf("getting arg len %c\n", currentchar); - - /* - fileoffset = f_tell(&scriptin); - getfollowingchar(')'); - argsize = f_tell(&scriptin) - fileoffset; - f_lseek(&scriptin, fileoffset - 1); - - getnextchar(); - - gfx_printf("getting args %c\n", currentchar); - - unsplitargs = calloc(argsize + 1, sizeof(char)); - for (int i = 0; i < argsize; i++){ - unsplitargs[i] = currentchar; - getnextchar(); - } - */ unsplitargs = readtilchar(')', 0); - //gfx_printf("parsing args %c\n", currentchar); argc = splitargs(unsplitargs); getnextchar(); getnextchar(); - /* - gfx_printf("\n\nFunc: %s\n", funcbuff, currentchar); - gfx_printf("Split: %s\n", unsplitargs); - - for (int i = 0; i < argc; i++) - gfx_printf("%d | %s\n", i, argv[i]); - */ - - //gfx_printf("\ncurrent char: %c", currentchar); free(unsplitargs); } @@ -215,24 +152,6 @@ char *gettargetvar(){ FSIZE_t fileoffset; u32 varsize = 0; - /* - fileoffset = f_tell(&scriptin); - getfollowingchar('='); - varsize = f_tell(&scriptin) - fileoffset; - f_lseek(&scriptin, fileoffset - 1); - - variable = calloc(varsize + 1, sizeof(char)); - - getnextchar(); - for (int i = 0; i < varsize; i++){ - if (currentchar == ' ') - break; - - variable[i] = currentchar; - getnextchar(); - } - */ - variable = readtilchar('=', ' '); getfollowingchar('='); @@ -263,17 +182,19 @@ void mainparser(){ } functionparser(); - /* - if (variable != NULL) - gfx_printf("target: %s\n", variable); - */ - //gfx_printf("Func: %s\n", funcbuff); res = run_function(funcbuff, &out); - str_int_add("@RESULT", res); + if (res < 0){ + printerrors = true; + gfx_errDisplay("mainparser", ERR_PARSE_FAIL, 0); + forceExit = true; + } + else { + str_int_add("@RESULT", out); - if (variable != NULL) - str_int_add(variable, res); + if (variable != NULL) + str_int_add(variable, out); + } //gfx_printf("\nGoing to next func %c\n", currentchar); free(variable); @@ -297,7 +218,7 @@ void skipbrackets(){ void tester(char *path){ int res; - + forceExit = false; gfx_clearscreen(); res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING); @@ -315,10 +236,19 @@ void tester(char *path){ printerrors = false; - while (!f_eof(&scriptin)){ + while (!f_eof(&scriptin) && !forceExit){ mainparser(); } + if (funcbuff != NULL) + free(funcbuff); + + if (argv != NULL) { + for (int i = 0; argv[i] != NULL; i++) + free(argv[i]); + free(argv); + } + printerrors = true; //str_int_printall(); 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 07/17] 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 From 034384622f8c3291e5d5f4dfb404db0073f2cc1a Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Tue, 31 Mar 2020 20:13:39 +0200 Subject: [PATCH 08/17] Add strings --- source/tegraexplorer/script/functions.c | 39 +++++++++- source/tegraexplorer/script/parser.c | 1 + source/tegraexplorer/script/variables.c | 98 ++++++++++++++++++++++++- source/tegraexplorer/script/variables.h | 6 +- 4 files changed, 140 insertions(+), 4 deletions(-) diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index e775517..a793d74 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -43,8 +43,23 @@ int parseJmpInput(char *in, u64 *out){ return -1; } +int parseStringInput(char *in, char **out){ + if (in[0] == '$'){ + if (str_str_find(in, out)) + return -1; + else + return 0; + } + else{ + *out = in; + return 0; + } +} + int part_printf(){ - gfx_printf(argv[0]); + char *toprint; + parseStringInput(argv[0], &toprint); + gfx_printf(toprint); gfx_printf("\n"); return 0; } @@ -121,6 +136,26 @@ int part_SetInt(){ return out; } +int part_SetString(){ + if (argv[1][0] != '$') + return -1; + str_str_add(argv[1], argv[0]); + return 0; +} + +int part_SetStringIndex(){ + int index; + char *out; + if (parseIntInput(argv[0], &index)) + return -1; + if (argv[1][0] != '$') + return -1; + if (str_str_index(index, &out)) + return -1; + str_str_add(argv[1], out); + return 0; +} + int part_goto(){ u64 target = 0; if (parseJmpInput(argv[0], &target)) @@ -137,6 +172,8 @@ str_fnc_struct functions[] = { {"check", part_Check, 3}, {"setInt", part_SetInt, 1}, {"goto", part_goto, 1}, + {"setString", part_SetString, 2}, + {"setStringIndex", part_SetStringIndex, 2}, {NULL, NULL, 0} }; diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index a900784..af0faa9 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -267,5 +267,6 @@ void tester(char *path){ f_close(&scriptin); str_int_clear(); str_jmp_clear(); + str_str_clear(); btn_wait(); } \ No newline at end of file diff --git a/source/tegraexplorer/script/variables.c b/source/tegraexplorer/script/variables.c index 86e250c..81fe63c 100644 --- a/source/tegraexplorer/script/variables.c +++ b/source/tegraexplorer/script/variables.c @@ -29,6 +29,7 @@ int str_int_add(char *key, int value){ keyvaluepair->key = key_local; keyvaluepair->value = value; keyvaluepair->next = NULL; + if (str_int_table == NULL){ str_int_table = keyvaluepair; } @@ -37,6 +38,8 @@ int str_int_add(char *key, int value){ temp = str_int_table; while (temp != NULL){ if (!strcmp(temp->key, key_local)){ + free(keyvaluepair); + free(key_local); temp->value = value; return 0; } @@ -93,13 +96,15 @@ 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); - + + utils_copystring(key, &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; } @@ -108,6 +113,9 @@ int str_jmp_add(char *key, u64 value){ temp = str_jmp_table; while (temp != NULL){ if (!strcmp(temp->key, key_local)){ + free(keyvaluepair); + free(key_local); + temp->value = value; return 0; } @@ -152,4 +160,90 @@ void str_jmp_clear(){ cur = next; } str_jmp_table = NULL; +} + +int str_str_add(char *key, char *value){ + char *key_local, *value_local; + dict_str_str *keyvaluepair; + //gfx_printf("Adding |%s|\n", key_local); + utils_copystring(value, &value_local); + utils_copystring(key, &key_local); + + keyvaluepair = calloc(1, sizeof(dict_str_str)); + keyvaluepair->key = key_local; + keyvaluepair->value = value_local; + keyvaluepair->next = NULL; + + if (str_str_table == NULL){ + str_str_table = keyvaluepair; + } + else { + dict_str_str *temp; + temp = str_str_table; + while (temp != NULL){ + if (!strcmp(temp->key, key_local)){ + free(keyvaluepair); + free(key_local); + + free(temp->value); + temp->value = value_local; + return 0; + } + + if (temp->next == NULL){ + temp->next = keyvaluepair; + return 0; + } + + temp = temp->next; + } + } + + return 0; +} + +int str_str_find(char *key, char **out){ + dict_str_str *temp; + temp = str_str_table; + + while (temp != NULL){ + if (!strcmp(temp->key, key)){ + *out = temp->value; + return 0; + } + temp = temp->next; + } + + return -1; +} + +int str_str_index(int index, char **out){ + dict_str_str *temp; + temp = str_str_table; + + for (int i = 0; i < (index - 1); i++){ + if (temp == NULL) + return -1; + temp = temp->next; + } + + if (temp == NULL) + return -1; + + *out = temp->value; + return 0; +} + +void str_str_clear(){ + dict_str_str *cur, *next; + cur = str_str_table; + + while (cur != NULL){ + next = cur->next; + free(cur->key); + free(cur->value); + free(cur); + cur = next; + } + str_str_table = NULL; } \ No newline at end of file diff --git a/source/tegraexplorer/script/variables.h b/source/tegraexplorer/script/variables.h index a7a7634..61c7612 100644 --- a/source/tegraexplorer/script/variables.h +++ b/source/tegraexplorer/script/variables.h @@ -25,4 +25,8 @@ 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(); \ No newline at end of file +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); +void str_str_clear(); \ No newline at end of file From 45a732c388ee4aaa962fa68634f60ba8fc73356f Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Tue, 31 Mar 2020 22:01:20 +0200 Subject: [PATCH 09/17] add functions, fix bugs --- source/tegraexplorer/script/functions.c | 18 ++++++++++++ source/tegraexplorer/script/parser.c | 39 ++++++++++++++++--------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index a793d74..fa63650 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -16,6 +16,7 @@ #include "variables.h" #include "../utils/utils.h" #include "functions.h" +#include "../fs/fsutils.h" extern FIL scriptin; extern char **argv; @@ -164,6 +165,21 @@ int part_goto(){ return 0; } +int part_invert(){ + int arg; + if (parseIntInput(argv[0], &arg)) + return -1; + return (arg) ? 0 : 1; +} + +int part_fs_exists(){ + char *path; + if (parseStringInput(argv[0], &path)) + return -1; + + return fsutil_checkfile(path); +} + str_fnc_struct functions[] = { {"printf", part_printf, 1}, {"printInt", part_print_int, 1}, @@ -174,6 +190,8 @@ str_fnc_struct functions[] = { {"goto", part_goto, 1}, {"setString", part_SetString, 2}, {"setStringIndex", part_SetStringIndex, 2}, + {"invert", part_invert, 1}, + {"fs_exists", part_fs_exists, 1}, {NULL, NULL, 0} }; diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index af0faa9..ec935f7 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -32,11 +32,13 @@ u32 splitargs(char* in) { // arg like '5, "6", @arg7' u32 i, current = 0, count = countchars(in, ',') + 1, len = strlen(in), curcount = 0; + /* if (argv != NULL) { for (i = 0; argv[i] != NULL; i++) free(argv[i]); free(argv); } + */ argv = calloc(count + 1, sizeof(char*)); @@ -130,8 +132,10 @@ void functionparser(){ FSIZE_t fileoffset; u32 argsize = 0; + /* if (funcbuff != NULL) free(funcbuff); + */ funcbuff = readtilchar('(', ' '); @@ -195,11 +199,10 @@ void mainparser(){ res = run_function(funcbuff, &out); if (res < 0){ printerrors = true; - gfx_errDisplay("mainparser", ERR_PARSE_FAIL, 0); - forceExit = true; - - //gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]); btn_wait(); + gfx_errDisplay("mainparser", ERR_PARSE_FAIL, f_tell(&scriptin)); + forceExit = true; + //gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]); } else { str_int_add("@RESULT", out); @@ -209,7 +212,22 @@ void mainparser(){ } //gfx_printf("\nGoing to next func %c\n", currentchar); - free(variable); + + if (funcbuff != NULL){ + free(funcbuff); + funcbuff = NULL; + } + + if (argv != NULL) { + for (int i = 0; argv[i] != NULL; i++) + free(argv[i]); + free(argv); + argv = NULL; + } + + if (variable != NULL){ + free(variable); + } } void skipbrackets(){ @@ -231,6 +249,7 @@ void skipbrackets(){ void tester(char *path){ int res; forceExit = false; + currentchar = 0; gfx_clearscreen(); res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING); @@ -246,21 +265,13 @@ void tester(char *path){ str_int_add("@BTN_VOL+", 0); str_int_add("@BTN_VOL-", 0); + //str_int_printall(); printerrors = false; while (!f_eof(&scriptin) && !forceExit){ mainparser(); } - if (funcbuff != NULL) - free(funcbuff); - - if (argv != NULL) { - for (int i = 0; argv[i] != NULL; i++) - free(argv[i]); - free(argv); - } - printerrors = true; //str_int_printall(); From 0e39c8dda91d11119a39597f51cf2deefc561514 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Wed, 1 Apr 2020 00:17:45 +0200 Subject: [PATCH 10/17] add more functions --- source/tegraexplorer/fs/filemenu.c | 2 +- source/tegraexplorer/mainmenu.c | 4 +- source/tegraexplorer/script/functions.c | 118 +++++++++++++++++++++++- source/tegraexplorer/script/parser.c | 23 ++++- source/tegraexplorer/utils/script.h | 11 --- 5 files changed, 137 insertions(+), 21 deletions(-) delete mode 100644 source/tegraexplorer/utils/script.h diff --git a/source/tegraexplorer/fs/filemenu.c b/source/tegraexplorer/fs/filemenu.c index 428004c..32a6f8b 100644 --- a/source/tegraexplorer/fs/filemenu.c +++ b/source/tegraexplorer/fs/filemenu.c @@ -145,7 +145,7 @@ int filemenu(menu_entry file){ } SETBIT(fs_menu_file[7].property, ISHIDE, !(strstr(file.name, ".bin") != NULL && file.property & ISKB)); - SETBIT(fs_menu_file[8].property, ISHIDE, !(strstr(file.name, ".tegrascript") != NULL)); + SETBIT(fs_menu_file[8].property, ISHIDE, !(strstr(file.name, ".te") != NULL)); SETBIT(fs_menu_file[10].property, ISHIDE, !(strstr(file.name, ".bis") != NULL)); SETBIT(fs_menu_file[11].property, ISHIDE, !(strstr(file.name, ".bis") != NULL)); diff --git a/source/tegraexplorer/mainmenu.c b/source/tegraexplorer/mainmenu.c index f76b381..5991df2 100644 --- a/source/tegraexplorer/mainmenu.c +++ b/source/tegraexplorer/mainmenu.c @@ -6,7 +6,7 @@ #include "../utils/btn.h" #include "emmc/emmc.h" #include "../storage/emummc.h" -#include "utils/script.h" +#include "script/functions.h" #include "common/common.h" #include "gfx/menu.h" @@ -127,7 +127,7 @@ void MainMenu_Exit(){ } //todo declock bpmp } -part_handler mainmenu_functions[] = { +func_void_ptr mainmenu_functions[] = { MainMenu_SDCard, MainMenu_EMMC, MainMenu_EMMC, diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index fa63650..241d2c6 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -17,10 +17,12 @@ #include "../utils/utils.h" #include "functions.h" #include "../fs/fsutils.h" +#include "../../utils/sprintf.h" extern FIL scriptin; extern char **argv; extern u32 argc; +extern int forceExit; int parseIntInput(char *in, int *out){ if (in[0] == '@'){ @@ -57,8 +59,10 @@ int parseStringInput(char *in, char **out){ } } +u32 currentcolor = COLOR_WHITE; int part_printf(){ char *toprint; + SWAPCOLOR(currentcolor); parseStringInput(argv[0], &toprint); gfx_printf(toprint); gfx_printf("\n"); @@ -73,6 +77,24 @@ int part_print_int(){ return 0; } +int part_Wait(){ + int arg; + u32 begintime; + SWAPCOLOR(currentcolor); + + if (parseIntInput(argv[0], &arg)) + return -1; + + begintime = get_tmr_s(); + + while (begintime + arg > get_tmr_s()){ + gfx_printf("\r ", (begintime + arg) - get_tmr_s()); + } + + gfx_printf("\r \r"); + return 0; +} + int part_if(){ int condition; if (parseIntInput(argv[0], &condition)) @@ -105,7 +127,7 @@ int part_Math(){ case '/': return left * right; } - return 0; + return -1; } int part_Check(){ @@ -138,9 +160,13 @@ int part_SetInt(){ } int part_SetString(){ + char *arg0; + if (parseStringInput(argv[0], &arg0)) + return -1; if (argv[1][0] != '$') return -1; - str_str_add(argv[1], argv[0]); + + str_str_add(argv[1], arg0); return 0; } @@ -180,6 +206,87 @@ int part_fs_exists(){ return fsutil_checkfile(path); } +int part_ConnectMMC(){ + char *arg; + parseStringInput(argv[0], &arg); + + if (!strcmp(arg, "SYSMMC")) + connect_mmc(SYSMMC); + else if (!strcmp(arg, "EMUMMC")) + connect_mmc(EMUMMC); + else + return -1; + + return 0; +} + +int part_MountMMC(){ + char *arg; + parseStringInput(argv[0], &arg); + return mount_mmc(arg, 2); +} + +int part_Pause(){ + int res; + + while (btn_read() != 0); + + res = btn_wait(); + + str_int_add("@BTN_POWER", (res & BTN_POWER)); + str_int_add("@BTN_VOL+", (res & BTN_VOL_UP)); + str_int_add("@BTN_VOL-", (res & BTN_VOL_DOWN)); + + return res; +} + +int part_addstrings(){ + char *combined, *left, *middle; + if (parseStringInput(argv[0], &left)) + return -1; + if (parseStringInput(argv[1], &middle)) + return -1; + if (argv[2][0] != '$') + return -1; + + combined = calloc(strlen(left) + strlen(middle) + 1, sizeof(char)); + sprintf(combined, "%s%s", left, middle); + + str_str_add(argv[2], combined); + free(combined); + return 0; +} + +int part_setColor(){ + char *arg; + if (parseStringInput(argv[0], &arg)) + return -1; + + if (!strcmp(arg, "RED")) + currentcolor = COLOR_RED; + else if (!strcmp(arg, "ORANGE")) + currentcolor = COLOR_ORANGE; + else if (!strcmp(arg, "YELLOW")) + currentcolor = COLOR_YELLOW; + else if (!strcmp(arg, "GREEN")) + currentcolor = COLOR_GREEN; + else if (!strcmp(arg, "BLUE")) + currentcolor = COLOR_BLUE; + else if (!strcmp(arg, "VIOLET")) + currentcolor = COLOR_VIOLET; + else if (!strcmp(arg, "WHITE")) + currentcolor = COLOR_WHITE; + else + return -1; + + return 0; +} + +int part_Exit(){ + forceExit = true; + return 0; +} + str_fnc_struct functions[] = { {"printf", part_printf, 1}, {"printInt", part_print_int, 1}, @@ -190,8 +297,15 @@ str_fnc_struct functions[] = { {"goto", part_goto, 1}, {"setString", part_SetString, 2}, {"setStringIndex", part_SetStringIndex, 2}, + {"setColor", part_setColor, 1}, + {"combineStrings", part_addstrings, 3}, {"invert", part_invert, 1}, {"fs_exists", part_fs_exists, 1}, + {"mmc_connect", part_ConnectMMC, 1}, + {"mmc_mount", part_MountMMC, 1}, + {"pause", part_Pause, 0}, + {"wait", part_Wait, 1}, + {"exit", part_Exit, 0}, {NULL, NULL, 0} }; diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index ec935f7..6c3d34c 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -120,6 +120,10 @@ char *readtilchar(char end, char ignore){ offset = f_tell(&scriptin); getfollowingchar(end); size = f_tell(&scriptin) - offset; + + if (size <= 0) + return NULL; + f_lseek(&scriptin, offset - 1); return makestr((u32)size, ignore); @@ -144,8 +148,13 @@ void functionparser(){ unsplitargs = readtilchar(')', 0); - argc = splitargs(unsplitargs); - getnextchar(); + if (unsplitargs != NULL){ + argc = splitargs(unsplitargs); + getnextchar(); + } + else { + argc = 0; + } getnextchar(); free(unsplitargs); @@ -199,7 +208,8 @@ void mainparser(){ res = run_function(funcbuff, &out); if (res < 0){ printerrors = true; - btn_wait(); + //gfx_printf("%s|%s|%d", funcbuff, argv[0], argc); + //btn_wait(); gfx_errDisplay("mainparser", ERR_PARSE_FAIL, f_tell(&scriptin)); forceExit = true; //gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]); @@ -246,10 +256,12 @@ void skipbrackets(){ } } +extern u32 currentcolor; void tester(char *path){ int res; forceExit = false; currentchar = 0; + currentcolor = COLOR_WHITE; gfx_clearscreen(); res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING); @@ -257,6 +269,8 @@ void tester(char *path){ gfx_errDisplay("ParseScript", res, 1); return; } + + printerrors = false; //add builtin vars str_int_add("@EMUMMC", emu_cfg.enabled); @@ -266,7 +280,6 @@ void tester(char *path){ str_int_add("@BTN_VOL-", 0); //str_int_printall(); - printerrors = false; while (!f_eof(&scriptin) && !forceExit){ mainparser(); @@ -279,5 +292,5 @@ void tester(char *path){ str_int_clear(); str_jmp_clear(); str_str_clear(); - btn_wait(); + //btn_wait(); } \ No newline at end of file diff --git a/source/tegraexplorer/utils/script.h b/source/tegraexplorer/utils/script.h deleted file mode 100644 index fc122b3..0000000 --- a/source/tegraexplorer/utils/script.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#define strcmpcheck(x, y) (!strcmp(x, y)) - -typedef void (*part_handler)(); -typedef struct _script_parts { - char name[11]; - part_handler handler; - short arg_amount; -} script_parts; - -//void ParseScript(char* path); From 0e60746179dcf32699e596453f84520ccd4ca1fa Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Wed, 1 Apr 2020 00:41:55 +0200 Subject: [PATCH 11/17] Add fs functions: Rewrite should be done --- source/tegraexplorer/fs/fsactions.c | 30 ++++----- source/tegraexplorer/script/functions.c | 82 +++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 15 deletions(-) diff --git a/source/tegraexplorer/fs/fsactions.c b/source/tegraexplorer/fs/fsactions.c index d193d89..63200aa 100644 --- a/source/tegraexplorer/fs/fsactions.c +++ b/source/tegraexplorer/fs/fsactions.c @@ -23,22 +23,22 @@ int fsact_copy(const char *locin, const char *locout, u8 options){ if (!strcmp(locin, locout)){ gfx_errDisplay("copy", ERR_SAME_LOC, 1); - return -1; + return 1; } if ((res = f_open(&in, locin, FA_READ | FA_OPEN_EXISTING))){ gfx_errDisplay("copy", res, 2); - return -1; + return 1; } if (f_stat(locin, &in_info)){ gfx_errDisplay("copy", res, 3); - return -1; + return 1; } if (f_open(&out, locout, FA_CREATE_ALWAYS | FA_WRITE)){ gfx_errDisplay("copy", res, 4); - return -1; + return 1; } buff = malloc (BUFSIZE); @@ -48,17 +48,17 @@ int fsact_copy(const char *locin, const char *locout, u8 options){ while (sizeoffile > 0){ if ((res = f_read(&in, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp1))){ gfx_errDisplay("copy", res, 5); - return -1; + return 1; } if ((res = f_write(&out, buff, (sizeoffile > BUFSIZE) ? BUFSIZE : sizeoffile, &temp2))){ gfx_errDisplay("copy", res, 6); - return -1; + return 1; } if (temp1 != temp2){ gfx_errDisplay("copy", ERR_DISK_WRITE_FAILED, 7); - return -1; + return 1; } sizeoffile -= temp1; @@ -84,7 +84,7 @@ int fsact_copy(const char *locin, const char *locout, u8 options){ if ((res = f_chmod(locout, in_info.fattrib, 0x3A))){ gfx_errDisplay("copy", res, 8); - return -1; + return 1; } f_stat(locin, &in_info); //somehow stops fatfs from being weird @@ -103,7 +103,7 @@ int fsact_del_recursive(char *path){ if ((res = f_opendir(&dir, localpath))){ gfx_errDisplay("del_recursive", res, 1); - return -1; + return 1; } while (!f_readdir(&dir, &fno) && fno.fname[0]){ @@ -117,7 +117,7 @@ int fsact_del_recursive(char *path){ if ((res = f_unlink(fsutil_getnextloc(localpath, fno.fname)))){ gfx_errDisplay("del_recursive", res, 2); - return -1; + return 1; } } } @@ -126,7 +126,7 @@ int fsact_del_recursive(char *path){ if ((res = f_unlink(localpath))){ gfx_errDisplay("del_recursive", res, 3); - return -1; + return 1; } free(localpath); @@ -148,7 +148,7 @@ int fsact_copy_recursive(char *path, char *dstpath){ if ((res = f_opendir(&dir, startpath))){ gfx_errDisplay("copy_recursive", res, 1); - return -1; + return 1; } f_mkdir(destpath); @@ -166,7 +166,7 @@ int fsact_copy_recursive(char *path, char *dstpath){ if ((res = fsact_copy(temp, fsutil_getnextloc(destpath, fno.fname), COPY_MODE_PRINT))){ gfx_errDisplay("copy_recursive", res, 2); - return -1; + return 1; } free(temp); @@ -177,12 +177,12 @@ int fsact_copy_recursive(char *path, char *dstpath){ if ((res = (f_stat(startpath, &fno)))){ gfx_errDisplay("copy_recursive", res, 3); - return -1; + return 1; } if ((res = f_chmod(destpath, fno.fattrib, 0x3A))){ gfx_errDisplay("copy_recursive", res, 4); - return -1; + return 1; } free(startpath); diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index 241d2c6..8b20886 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -18,6 +18,7 @@ #include "functions.h" #include "../fs/fsutils.h" #include "../../utils/sprintf.h" +#include "../fs/fsactions.h" extern FIL scriptin; extern char **argv; @@ -287,6 +288,81 @@ int part_Exit(){ return 0; } +int part_fs_Move(){ + char *left, *right; + + if (parseStringInput(argv[0], &left)) + return -1; + if (parseStringInput(argv[1], &right)) + return -1; + + int res; + res = f_rename(left, right); + if (res) + res = f_rename(left, right); + + return res; +} + +int part_fs_Delete(){ + char *arg; + + if (parseStringInput(argv[0], &arg)) + return -1; + + int res; + res = f_unlink(arg); + if (res) + res = f_unlink(arg); + + return res; +} + +int part_fs_DeleteRecursive(){ + char *arg; + + if (parseStringInput(argv[0], &arg)) + return -1; + + return fsact_del_recursive(arg); +} + +int part_fs_Copy(){ + char *left, *right; + + if (parseStringInput(argv[0], &left)) + return -1; + if (parseStringInput(argv[1], &right)) + return -1; + + return fsact_copy(left, right, COPY_MODE_PRINT); +} + +int part_fs_CopyRecursive(){ + char *left, *right; + + if (parseStringInput(argv[0], &left)) + return -1; + if (parseStringInput(argv[1], &right)) + return -1; + + return fsact_copy_recursive(left, right); +} + +int part_fs_MakeDir(){ + char *arg; + + if (parseStringInput(argv[0], &arg)) + return -1; + + int res; + res = f_mkdir(arg); + if (res) + res = f_mkdir(arg); + + return res; +} + str_fnc_struct functions[] = { {"printf", part_printf, 1}, {"printInt", part_print_int, 1}, @@ -301,6 +377,12 @@ str_fnc_struct functions[] = { {"combineStrings", part_addstrings, 3}, {"invert", part_invert, 1}, {"fs_exists", part_fs_exists, 1}, + {"fs_move", part_fs_Move, 2}, + {"fs_mkdir", part_fs_MakeDir, 1}, + {"fs_del", part_fs_Delete, 1}, + {"fs_delRecursive", part_fs_DeleteRecursive, 1}, + {"fs_copy", part_fs_Copy, 2}, + {"fs_copyRecursive", part_fs_CopyRecursive, 2}, {"mmc_connect", part_ConnectMMC, 1}, {"mmc_mount", part_MountMMC, 1}, {"pause", part_Pause, 0}, From f4388272630d5bb7b4c5a63ba6ceef7ba4e5c7fb Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Wed, 1 Apr 2020 13:57:25 +0200 Subject: [PATCH 12/17] add more functions --- source/tegraexplorer/fs/filemenu.c | 1 + source/tegraexplorer/script/functions.c | 71 ++++++++++++++++++++++++- source/tegraexplorer/script/parser.c | 9 ++-- source/tegraexplorer/script/variables.c | 2 +- 4 files changed, 75 insertions(+), 8 deletions(-) diff --git a/source/tegraexplorer/fs/filemenu.c b/source/tegraexplorer/fs/filemenu.c index 32a6f8b..1516daa 100644 --- a/source/tegraexplorer/fs/filemenu.c +++ b/source/tegraexplorer/fs/filemenu.c @@ -167,6 +167,7 @@ int filemenu(menu_entry file){ case FILE_SCRIPT: //ParseScript(fsutil_getnextloc(currentpath, file.name)); tester(fsutil_getnextloc(currentpath, file.name)); + fsreader_readfolder(currentpath); break; case FILE_HEXVIEW: viewbytes(fsutil_getnextloc(currentpath, file.name)); diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index 8b20886..ee86755 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -63,8 +63,10 @@ int parseStringInput(char *in, char **out){ u32 currentcolor = COLOR_WHITE; int part_printf(){ char *toprint; + if (parseStringInput(argv[0], &toprint)) + return -1; + SWAPCOLOR(currentcolor); - parseStringInput(argv[0], &toprint); gfx_printf(toprint); gfx_printf("\n"); return 0; @@ -74,6 +76,8 @@ int part_print_int(){ int toprint; if (parseIntInput(argv[0], &toprint)) return -1; + + SWAPCOLOR(currentcolor); gfx_printf("%s: %d\n", argv[0], toprint); return 0; } @@ -363,9 +367,71 @@ int part_fs_MakeDir(){ return res; } +DIR dir; +FILINFO fno; +int isdirvalid = false; +int part_fs_OpenDir(){ + char *path; + + if (parseStringInput(argv[0], &path)) + return -1; + + if (f_opendir(&dir, path)) + return -1; + + isdirvalid = true; + str_int_add("@ISDIRVALID", isdirvalid); + return 0; +} + +int part_fs_CloseDir(){ + if (!isdirvalid) + return 0; + + f_closedir(&dir); + isdirvalid = false; + str_int_add("@ISDIRVALID", isdirvalid); + return 0; +} + +int part_fs_ReadDir(){ + if (!isdirvalid) + return -1; + + if (!f_readdir(&dir, &fno) && fno.fname[0]){ + str_str_add("$FSOBJNAME", fno.fname); + str_int_add("@ISDIR", (fno.fattrib & AM_DIR) ? 1 : 0); + } + else { + part_fs_CloseDir(); + } + + return 0; +} + +int part_setPrintPos(){ + int left, right; + + if (parseIntInput(argv[0], &left)) + return -1; + + if (parseIntInput(argv[1], &right)) + return -1; + + if (left > 42) + return -1; + + if (right > 78) + return -1; + + gfx_con_setpos(left * 16, right * 16); + return 0; +} + str_fnc_struct functions[] = { {"printf", part_printf, 1}, {"printInt", part_print_int, 1}, + {"setPrintPos", part_setPrintPos, 2}, {"if", part_if, 1}, {"math", part_Math, 3}, {"check", part_Check, 3}, @@ -383,6 +449,9 @@ str_fnc_struct functions[] = { {"fs_delRecursive", part_fs_DeleteRecursive, 1}, {"fs_copy", part_fs_Copy, 2}, {"fs_copyRecursive", part_fs_CopyRecursive, 2}, + {"fs_openDir", part_fs_OpenDir, 1}, + {"fs_closeDir", part_fs_CloseDir, 0}, + {"fs_readDir", part_fs_ReadDir, 0}, {"mmc_connect", part_ConnectMMC, 1}, {"mmc_mount", part_MountMMC, 1}, {"pause", part_Pause, 0}, diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index 6c3d34c..e449d1c 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -14,6 +14,7 @@ #include "../fs/fsactions.h" #include "functions.h" #include "variables.h" +#include "../fs/fsreader.h" u32 countchars(char* in, char target) { @@ -133,8 +134,6 @@ char *readtilchar(char end, char ignore){ char *funcbuff = NULL; void functionparser(){ char *unsplitargs; - FSIZE_t fileoffset; - u32 argsize = 0; /* if (funcbuff != NULL) @@ -162,8 +161,6 @@ void functionparser(){ char *gettargetvar(){ char *variable = NULL; - FSIZE_t fileoffset; - u32 varsize = 0; variable = readtilchar('=', ' '); @@ -176,8 +173,6 @@ char *gettargetvar(){ void mainparser(){ char *variable = NULL; int res, out = 0; - FSIZE_t fileoffset; - u32 varsize = 0; getnextvalidchar(); @@ -257,6 +252,7 @@ void skipbrackets(){ } extern u32 currentcolor; +extern char *currentpath; void tester(char *path){ int res; forceExit = false; @@ -278,6 +274,7 @@ void tester(char *path){ str_int_add("@BTN_POWER", 0); str_int_add("@BTN_VOL+", 0); str_int_add("@BTN_VOL-", 0); + str_str_add("$CURRENTPATH", currentpath); //str_int_printall(); diff --git a/source/tegraexplorer/script/variables.c b/source/tegraexplorer/script/variables.c index 81fe63c..26cb559 100644 --- a/source/tegraexplorer/script/variables.c +++ b/source/tegraexplorer/script/variables.c @@ -221,7 +221,7 @@ int str_str_index(int index, char **out){ dict_str_str *temp; temp = str_str_table; - for (int i = 0; i < (index - 1); i++){ + for (int i = 0; i < index; i++){ if (temp == NULL) return -1; temp = temp->next; From 5b32937f8fe4938a3b88f730646f90dc090898fb Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Wed, 1 Apr 2020 16:37:32 +0200 Subject: [PATCH 13/17] add stringcompare function, fix some returns --- source/tegraexplorer/emmc/emmc.c | 6 +++--- source/tegraexplorer/script/functions.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/source/tegraexplorer/emmc/emmc.c b/source/tegraexplorer/emmc/emmc.c index 7485a92..60b2fc2 100644 --- a/source/tegraexplorer/emmc/emmc.c +++ b/source/tegraexplorer/emmc/emmc.c @@ -67,7 +67,7 @@ int connect_part(const char *partition){ system_part = nx_emmc_part_find(&gpt, partition); if (!system_part) { gfx_errDisplay("connect_mmc_part", ERR_PART_NOT_FOUND, 0); - return -1; + return 1; } return 0; @@ -81,11 +81,11 @@ int mount_mmc(const char *partition, const int biskeynumb){ se_aes_key_set(9, bis_key[biskeynumb] + 0x10, 0x10); if (connect_part(partition)) - return -1; + return 1; if ((res = f_mount(&emmc, "emmc:", 1))) { gfx_errDisplay("mount_mmc", res, 0); - return -1; + return 1; } return 0; diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index ee86755..3462e12 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -65,7 +65,7 @@ int part_printf(){ char *toprint; if (parseStringInput(argv[0], &toprint)) return -1; - + SWAPCOLOR(currentcolor); gfx_printf(toprint); gfx_printf("\n"); @@ -428,6 +428,17 @@ int part_setPrintPos(){ return 0; } +int part_stringcompare(){ + char *left, *right; + + if (parseStringInput(argv[0], &left)) + return -1; + if (parseStringInput(argv[1], &right)) + return -1; + + return (strcmp(left, right)) ? 0 : 1; +} + str_fnc_struct functions[] = { {"printf", part_printf, 1}, {"printInt", part_print_int, 1}, @@ -441,6 +452,7 @@ str_fnc_struct functions[] = { {"setStringIndex", part_SetStringIndex, 2}, {"setColor", part_setColor, 1}, {"combineStrings", part_addstrings, 3}, + {"compareStrings", part_stringcompare, 2}, {"invert", part_invert, 1}, {"fs_exists", part_fs_exists, 1}, {"fs_move", part_fs_Move, 2}, From d0799e3cd10db776bae6a2990eef66d8da27b6c7 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Wed, 1 Apr 2020 16:48:36 +0200 Subject: [PATCH 14/17] Rename some variables --- source/tegraexplorer/fs/filemenu.c | 2 +- source/tegraexplorer/script/functions.c | 2 +- source/tegraexplorer/script/parser.c | 2 +- source/tegraexplorer/script/parser.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/source/tegraexplorer/fs/filemenu.c b/source/tegraexplorer/fs/filemenu.c index 1516daa..8a52f0e 100644 --- a/source/tegraexplorer/fs/filemenu.c +++ b/source/tegraexplorer/fs/filemenu.c @@ -166,7 +166,7 @@ int filemenu(menu_entry file){ break; case FILE_SCRIPT: //ParseScript(fsutil_getnextloc(currentpath, file.name)); - tester(fsutil_getnextloc(currentpath, file.name)); + runScript(fsutil_getnextloc(currentpath, file.name)); fsreader_readfolder(currentpath); break; case FILE_HEXVIEW: diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index 3462e12..7c6bf85 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -399,7 +399,7 @@ int part_fs_ReadDir(){ return -1; if (!f_readdir(&dir, &fno) && fno.fname[0]){ - str_str_add("$FSOBJNAME", fno.fname); + str_str_add("$FILENAME", fno.fname); str_int_add("@ISDIR", (fno.fattrib & AM_DIR) ? 1 : 0); } else { diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index e449d1c..3df90f5 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -253,7 +253,7 @@ void skipbrackets(){ extern u32 currentcolor; extern char *currentpath; -void tester(char *path){ +void runScript(char *path){ int res; forceExit = false; currentchar = 0; diff --git a/source/tegraexplorer/script/parser.h b/source/tegraexplorer/script/parser.h index 2c42b86..8df9fea 100644 --- a/source/tegraexplorer/script/parser.h +++ b/source/tegraexplorer/script/parser.h @@ -1,5 +1,5 @@ #pragma once -void tester(char *path); +void runScript(char *path); void skipbrackets(); void getfollowingchar(char end); \ No newline at end of file From 440a9219807b8b640bb171988732bd763a261504 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Wed, 1 Apr 2020 19:43:37 +0200 Subject: [PATCH 15/17] small fixes --- source/tegraexplorer/script/functions.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index 7c6bf85..4cc42fb 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -107,12 +107,19 @@ int part_if(){ getfollowingchar('{'); + if (!condition) + skipbrackets(); + + return 0; + + /* if (condition) return 0; else { skipbrackets(); return 0; } + */ } int part_Math(){ @@ -130,7 +137,7 @@ int part_Math(){ case '*': return left * right; case '/': - return left * right; + return left / right; } return -1; } From 744f90611a497540e73507c7570b5ff50e631cd3 Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Wed, 1 Apr 2020 23:44:28 +0200 Subject: [PATCH 16/17] Fix commas causing issues, fix some freeze cases --- source/tegraexplorer/gfx/gfxutils.c | 3 +++ source/tegraexplorer/script/parser.c | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/source/tegraexplorer/gfx/gfxutils.c b/source/tegraexplorer/gfx/gfxutils.c index 4c60510..72a04f9 100644 --- a/source/tegraexplorer/gfx/gfxutils.c +++ b/source/tegraexplorer/gfx/gfxutils.c @@ -63,6 +63,9 @@ int gfx_errDisplay(char *src_func, int err, int loc){ gfx_printf("\nPress any button to return"); RESETCOLOR; + + while (btn_read() != 0); + return btn_wait(); } diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index 3df90f5..9c764d9 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -21,6 +21,14 @@ u32 countchars(char* in, char target) { u32 len = strlen(in); u32 count = 0; for (u32 i = 0; i < len; i++) { + if (in[i] == '"'){ + i++; + while (in[i] != '"'){ + i++; + if (i >= len) + return -1; + } + } if (in[i] == target) count++; } @@ -31,7 +39,11 @@ char **argv = NULL; u32 argc; u32 splitargs(char* in) { // arg like '5, "6", @arg7' - u32 i, current = 0, count = countchars(in, ',') + 1, len = strlen(in), curcount = 0; + u32 i, current = 0, count = 1, len = strlen(in), curcount = 0; + + if ((count += countchars(in, ',')) < 0){ + return 0; + } /* if (argv != NULL) { @@ -86,9 +98,9 @@ char getnextchar(){ } void getfollowingchar(char end){ - while (currentchar != end){ + while (currentchar != end && !f_eof(&scriptin)){ if (currentchar == '"'){ - while (getnextchar() != '"'); + while (getnextchar() != '"' && !f_eof(&scriptin)); } getnextchar(); } @@ -241,7 +253,7 @@ void skipbrackets(){ getfollowingchar('{'); getnextchar(); - while (currentchar != '}' || bracketcounter != 0){ + while ((currentchar != '}' || bracketcounter != 0) && !f_eof(&scriptin)){ if (currentchar == '{') bracketcounter++; else if (currentchar == '}') From 8832b240a4eee69ad341efd0beb39c0f491061fa Mon Sep 17 00:00:00 2001 From: "Such Meme, Many Skill" Date: Fri, 3 Apr 2020 19:07:42 +0200 Subject: [PATCH 17/17] Add fs_combinePath() --- source/tegraexplorer/script/functions.c | 17 +++++++++++++++++ source/tegraexplorer/script/parser.c | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/source/tegraexplorer/script/functions.c b/source/tegraexplorer/script/functions.c index 4cc42fb..0efd63a 100644 --- a/source/tegraexplorer/script/functions.c +++ b/source/tegraexplorer/script/functions.c @@ -446,6 +446,22 @@ int part_stringcompare(){ return (strcmp(left, right)) ? 0 : 1; } +int part_fs_combinePath(){ + char *combined, *left, *middle; + if (parseStringInput(argv[0], &left)) + return -1; + if (parseStringInput(argv[1], &middle)) + return -1; + if (argv[2][0] != '$') + return -1; + + combined = fsutil_getnextloc(left, middle); + + str_str_add(argv[2], combined); + free(combined); + return 0; +} + str_fnc_struct functions[] = { {"printf", part_printf, 1}, {"printInt", part_print_int, 1}, @@ -471,6 +487,7 @@ str_fnc_struct functions[] = { {"fs_openDir", part_fs_OpenDir, 1}, {"fs_closeDir", part_fs_CloseDir, 0}, {"fs_readDir", part_fs_ReadDir, 0}, + {"fs_combinePath", part_fs_combinePath, 3}, {"mmc_connect", part_ConnectMMC, 1}, {"mmc_mount", part_MountMMC, 1}, {"pause", part_Pause, 0}, diff --git a/source/tegraexplorer/script/parser.c b/source/tegraexplorer/script/parser.c index 9c764d9..13ffb64 100644 --- a/source/tegraexplorer/script/parser.c +++ b/source/tegraexplorer/script/parser.c @@ -15,7 +15,7 @@ #include "functions.h" #include "variables.h" #include "../fs/fsreader.h" - +#include "../utils/utils.h" u32 countchars(char* in, char target) { u32 len = strlen(in); @@ -267,10 +267,12 @@ extern u32 currentcolor; extern char *currentpath; void runScript(char *path){ int res; + char *path_local = NULL; forceExit = false; currentchar = 0; currentcolor = COLOR_WHITE; gfx_clearscreen(); + utils_copystring(path, &path_local); res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING); if (res != FR_OK){ @@ -301,5 +303,6 @@ void runScript(char *path){ str_int_clear(); str_jmp_clear(); str_str_clear(); + free(path_local); //btn_wait(); } \ No newline at end of file