1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-09 13:41:45 +00:00

Add strings

This commit is contained in:
Such Meme, Many Skill 2020-03-31 20:13:39 +02:00
parent 9efbbc9317
commit 034384622f
4 changed files with 140 additions and 4 deletions

View file

@ -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}
};

View file

@ -267,5 +267,6 @@ void tester(char *path){
f_close(&scriptin);
str_int_clear();
str_jmp_clear();
str_str_clear();
btn_wait();
}

View file

@ -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;
}

View file

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