1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-09-18 21:13:24 +01: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 "../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}
};

View file

@ -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();