Add functions, Add goto's
This commit is contained in:
@@ -25,7 +25,7 @@ int str_int_add(char *key, int value){
|
||||
|
||||
utils_copystring(key, &key_local);
|
||||
|
||||
keyvaluepair = calloc(1, sizeof(keyvaluepair));
|
||||
keyvaluepair = calloc(1, sizeof(dict_str_int));
|
||||
keyvaluepair->key = key_local;
|
||||
keyvaluepair->value = value;
|
||||
keyvaluepair->next = NULL;
|
||||
@@ -77,6 +77,7 @@ void str_int_clear(){
|
||||
free(cur);
|
||||
cur = next;
|
||||
}
|
||||
str_int_table = NULL;
|
||||
}
|
||||
|
||||
void str_int_printall(){
|
||||
@@ -86,4 +87,69 @@ void str_int_printall(){
|
||||
gfx_printf("%s -> %d\n", temp->key, temp->value);
|
||||
temp = temp->next;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
else {
|
||||
dict_str_loc *temp;
|
||||
temp = str_jmp_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_jmp_find(char *key, u64 *out){
|
||||
dict_str_loc *temp;
|
||||
temp = str_jmp_table;
|
||||
//gfx_printf("Searching |%s|\n", key);
|
||||
while (temp != NULL){
|
||||
if (!strcmp(temp->key, key)){
|
||||
//gfx_printf("Key found!\n", temp->value);
|
||||
*out = temp->value;
|
||||
return 0;
|
||||
}
|
||||
temp = temp->next;
|
||||
}
|
||||
|
||||
//gfx_printf("no key!\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void str_jmp_clear(){
|
||||
dict_str_loc *cur, *next;
|
||||
cur = str_jmp_table;
|
||||
|
||||
while (cur != NULL){
|
||||
next = cur->next;
|
||||
free(cur->key);
|
||||
free(cur);
|
||||
cur = next;
|
||||
}
|
||||
str_jmp_table = NULL;
|
||||
}
|
||||
Reference in New Issue
Block a user