1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-22 20:06:43 +00:00

Merge branch 'Script_Fuckery'

This commit is contained in:
Such Meme, Many Skill 2020-05-20 00:20:02 +02:00
commit f8394ae323
4 changed files with 97 additions and 47 deletions

View file

@ -288,6 +288,7 @@ int part_Pause(){
str_int_add("@BTN_DOWN", input->Ldown); str_int_add("@BTN_DOWN", input->Ldown);
str_int_add("@BTN_LEFT", input->Lleft); str_int_add("@BTN_LEFT", input->Lleft);
str_int_add("@BTN_RIGHT", input->Lright); str_int_add("@BTN_RIGHT", input->Lright);
str_int_add("@JOYCONN", hidConnected());
return input->buttons; return input->buttons;
} }
@ -550,7 +551,59 @@ int part_getPos(){
return (int)f_tell(&scriptin); return (int)f_tell(&scriptin);
} }
int part_subString(){
char *str, *sub;
int start, size;
if (parseStringInput(argv[0], &str))
return INFUNC_FAIL;
if (parseIntInput(argv[1], &start))
return INFUNC_FAIL;
if (parseIntInput(argv[2], &size))
return INFUNC_FAIL;
if (argv[3][0] != '$')
return INFUNC_FAIL;
if (start >= strlen(str))
return INFUNC_FAIL;
sub = utils_copyStringSize(str + start, size);
str_str_add(argv[3], sub);
free(sub);
return 0;
}
int part_inputString(){
char *start, *out;
int len;
if (parseStringInput(argv[0], &start))
return INFUNC_FAIL;
if (parseIntInput(argv[1], &len))
return INFUNC_FAIL;
if (argv[2][0] != '$')
return INFUNC_FAIL;
if (len > 39)
return INFUNC_FAIL;
out = utils_InputText(start, len);
if (out == NULL)
return 1;
str_str_add(argv[2], out);
free(out);
return 0;
}
int part_strLen(){
char *in;
if (parseStringInput(argv[0], &in))
return INFUNC_FAIL;
return strlen(in);
}
str_fnc_struct functions[] = { str_fnc_struct functions[] = {
{"printf", part_printf, 255}, {"printf", part_printf, 255},
@ -568,6 +621,9 @@ str_fnc_struct functions[] = {
{"setColor", part_setColor, 1}, {"setColor", part_setColor, 1},
{"combineStrings", part_addstrings, 3}, {"combineStrings", part_addstrings, 3},
{"compareStrings", part_stringcompare, 2}, {"compareStrings", part_stringcompare, 2},
{"subString", part_subString, 4},
{"inputString", part_inputString, 3},
{"stringLength", part_strLen, 1},
{"invert", part_invert, 1}, {"invert", part_invert, 1},
{"fs_exists", part_fs_exists, 1}, {"fs_exists", part_fs_exists, 1},
{"fs_move", part_fs_Move, 2}, {"fs_move", part_fs_Move, 2},

View file

@ -16,15 +16,15 @@
#include "variables.h" #include "variables.h"
#include "../fs/fsreader.h" #include "../fs/fsreader.h"
#include "../utils/utils.h" #include "../utils/utils.h"
#include "../../hid/hid.h"
u32 countchars(char* in, char target) { u32 countchars(const char* in, char target) {
u32 len = strlen(in); u32 len = strlen(in);
u32 count = 0; u32 count = 0;
for (u32 i = 0; i < len; i++) { for (u32 i = 0; i < len; i++) {
if (in[i] == '"'){ if (in[i] == '"'){
i++; while (in[++i] != '"'){
while (in[i] != '"'){
i++;
if (i >= len) if (i >= len)
return -1; return -1;
} }
@ -32,53 +32,46 @@ u32 countchars(char* in, char target) {
if (in[i] == target) if (in[i] == target)
count++; count++;
} }
return count; return count;
} }
char **argv = NULL; char **argv = NULL;
u32 argc; u32 argc;
u32 splitargs(char* in) { u32 splitargs(const char* in) {
// arg like '5, "6", @arg7' // arg like '5, "6", @arg7'
u32 i, current = 0, count = 1, len = strlen(in), curcount = 0; u32 i = 0, count = 1, len = strlen(in), curcount = 0, begin, end;
if ((count += countchars(in, ',')) < 0){ if ((count += countchars(in, ',')) < 0){
return 0; return 0;
} }
/*
if (argv != NULL) {
for (i = 0; argv[i] != NULL; i++)
free(argv[i]);
free(argv);
}
*/
argv = calloc(count + 1, sizeof(char*)); argv = calloc(count + 1, sizeof(char*));
for (i = 0; i < count; i++) while (i < len && curcount < count) {
argv[i] = calloc(96, sizeof(char)); while (in[i] == ' ' || in[i] == ',')
for (i = 0; i < len && curcount < count; i++) {
if (in[i] == ',') {
curcount++;
current = 0;
}
else if (in[i] == '@' || in[i] == '$') {
while (strrchr(", )", in[i]) == NULL && i < len) {
argv[curcount][current++] = in[i++];
}
i--;
}
//else if ((in[i] >= '0' && in[i] <= '9') || (in[i] >= '<' && in[i] <= '>') || in[i] == '+' || in[i] == '-' || in[i] == '*' || in[i] == '/')
else if (strrchr("0123456789<=>+-*/", in[i]) != NULL)
argv[curcount][current++] = in[i];
else if (in[i] == '"') {
i++; i++;
while (in[i] != '"') {
argv[curcount][current++] = in[i++]; begin = i;
while (strrchr(" ,)", in[i]) == NULL){
if (in[i] == '"'){
begin = i + 1;
while (in[++i] != '"'){
if (in[i] == '\0')
return 0;
} }
} }
i++;
}
end = i;
if (in[i - 1] == '"'){
end--;
}
argv[curcount++] = utils_copyStringSize(in + begin, (u32)(end - begin));
} }
return count; return count;
} }
@ -202,17 +195,6 @@ void mainparser(){
getnextvalidchar(); getnextvalidchar();
} }
/*
if (currentchar == '?'){
char *jumpname;
jumpname = readtilchar(';', ' ');
getnextchar();
str_jmp_add(jumpname, f_tell(&scriptin));
getfollowingchar('\n');
return;
}
*/
functionparser(); functionparser();
res = run_function(funcbuff, &out); res = run_function(funcbuff, &out);
@ -297,6 +279,7 @@ void runScript(char *path){
//add builtin vars //add builtin vars
str_int_add("@EMUMMC", emu_cfg.enabled); str_int_add("@EMUMMC", emu_cfg.enabled);
str_int_add("@RESULT", 0); str_int_add("@RESULT", 0);
str_int_add("@JOYCONN", hidConnected());
str_str_add("$CURRENTPATH", currentpath); str_str_add("$CURRENTPATH", currentpath);
//str_int_printall(); //str_int_printall();

View file

@ -193,3 +193,13 @@ char *utils_InputText(char *start, int maxLen){
return buff; return buff;
} }
char *utils_copyStringSize(const char *in, int size){
if (size > strlen(in) || size < 0)
size = strlen(in);
char *out = calloc(size + 1, 1);
//strncpy(out, in, size);
memcpy(out, in, size);
return out;
}

View file

@ -24,3 +24,4 @@ int utils_mmcMenu();
void utils_copystring(const char *in, char **out); void utils_copystring(const char *in, char **out);
char *utils_InputText(char *start, int maxLen); char *utils_InputText(char *start, int maxLen);
void utils_takeScreenshot(); void utils_takeScreenshot();
char *utils_copyStringSize(const char *in, int size);