mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-12-26 11:26:05 +00:00
Add functions and int vars
This commit is contained in:
parent
33a64abfb0
commit
38f349618f
8 changed files with 250 additions and 10 deletions
|
@ -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;
|
||||
|
|
66
source/tegraexplorer/script/functions.c
Normal file
66
source/tegraexplorer/script/functions.c
Normal file
|
@ -0,0 +1,66 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#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;
|
||||
}
|
13
source/tegraexplorer/script/functions.h
Normal file
13
source/tegraexplorer/script/functions.h
Normal file
|
@ -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);
|
|
@ -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();
|
||||
}
|
5
source/tegraexplorer/script/parser.h
Normal file
5
source/tegraexplorer/script/parser.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
#pragma once
|
||||
|
||||
void tester(char *path);
|
||||
void skipbrackets();
|
||||
void getfollowingchar(char end);
|
|
@ -1,3 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
void tester(char *path);
|
89
source/tegraexplorer/script/variables.c
Normal file
89
source/tegraexplorer/script/variables.c
Normal file
|
@ -0,0 +1,89 @@
|
|||
#include <string.h>
|
||||
#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;
|
||||
}
|
||||
}
|
25
source/tegraexplorer/script/variables.h
Normal file
25
source/tegraexplorer/script/variables.h
Normal file
|
@ -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();
|
Loading…
Reference in a new issue