1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-29 15:22:09 +00:00

add functions, fix bugs

This commit is contained in:
Such Meme, Many Skill 2020-03-31 22:01:20 +02:00
parent 034384622f
commit 45a732c388
2 changed files with 43 additions and 14 deletions

View file

@ -16,6 +16,7 @@
#include "variables.h" #include "variables.h"
#include "../utils/utils.h" #include "../utils/utils.h"
#include "functions.h" #include "functions.h"
#include "../fs/fsutils.h"
extern FIL scriptin; extern FIL scriptin;
extern char **argv; extern char **argv;
@ -164,6 +165,21 @@ int part_goto(){
return 0; 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[] = { str_fnc_struct functions[] = {
{"printf", part_printf, 1}, {"printf", part_printf, 1},
{"printInt", part_print_int, 1}, {"printInt", part_print_int, 1},
@ -174,6 +190,8 @@ str_fnc_struct functions[] = {
{"goto", part_goto, 1}, {"goto", part_goto, 1},
{"setString", part_SetString, 2}, {"setString", part_SetString, 2},
{"setStringIndex", part_SetStringIndex, 2}, {"setStringIndex", part_SetStringIndex, 2},
{"invert", part_invert, 1},
{"fs_exists", part_fs_exists, 1},
{NULL, NULL, 0} {NULL, NULL, 0}
}; };

View file

@ -32,11 +32,13 @@ u32 splitargs(char* in) {
// arg like '5, "6", @arg7' // arg like '5, "6", @arg7'
u32 i, current = 0, count = countchars(in, ',') + 1, len = strlen(in), curcount = 0; u32 i, current = 0, count = countchars(in, ',') + 1, len = strlen(in), curcount = 0;
/*
if (argv != NULL) { if (argv != NULL) {
for (i = 0; argv[i] != NULL; i++) for (i = 0; argv[i] != NULL; i++)
free(argv[i]); free(argv[i]);
free(argv); free(argv);
} }
*/
argv = calloc(count + 1, sizeof(char*)); argv = calloc(count + 1, sizeof(char*));
@ -130,8 +132,10 @@ void functionparser(){
FSIZE_t fileoffset; FSIZE_t fileoffset;
u32 argsize = 0; u32 argsize = 0;
/*
if (funcbuff != NULL) if (funcbuff != NULL)
free(funcbuff); free(funcbuff);
*/
funcbuff = readtilchar('(', ' '); funcbuff = readtilchar('(', ' ');
@ -195,11 +199,10 @@ void mainparser(){
res = run_function(funcbuff, &out); res = run_function(funcbuff, &out);
if (res < 0){ if (res < 0){
printerrors = true; printerrors = true;
gfx_errDisplay("mainparser", ERR_PARSE_FAIL, 0);
forceExit = true;
//gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]);
btn_wait(); btn_wait();
gfx_errDisplay("mainparser", ERR_PARSE_FAIL, f_tell(&scriptin));
forceExit = true;
//gfx_printf("Func: %s\nArg1: %s\n", funcbuff, argv[0]);
} }
else { else {
str_int_add("@RESULT", out); str_int_add("@RESULT", out);
@ -209,7 +212,22 @@ void mainparser(){
} }
//gfx_printf("\nGoing to next func %c\n", currentchar); //gfx_printf("\nGoing to next func %c\n", currentchar);
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); free(variable);
}
} }
void skipbrackets(){ void skipbrackets(){
@ -231,6 +249,7 @@ void skipbrackets(){
void tester(char *path){ void tester(char *path){
int res; int res;
forceExit = false; forceExit = false;
currentchar = 0;
gfx_clearscreen(); gfx_clearscreen();
res = f_open(&scriptin, path, FA_READ | FA_OPEN_EXISTING); 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_add("@BTN_VOL-", 0); str_int_add("@BTN_VOL-", 0);
//str_int_printall();
printerrors = false; printerrors = false;
while (!f_eof(&scriptin) && !forceExit){ while (!f_eof(&scriptin) && !forceExit){
mainparser(); mainparser();
} }
if (funcbuff != NULL)
free(funcbuff);
if (argv != NULL) {
for (int i = 0; argv[i] != NULL; i++)
free(argv[i]);
free(argv);
}
printerrors = true; printerrors = true;
//str_int_printall(); //str_int_printall();