|
@ -8,10 +8,16 @@ char* string_init(const char *str) { // new string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
char* string_join(const char *base, const char *add) { // combine string
|
|
|
char* string_join(const char *base, const char *add) { // combine string
|
|
|
char *ret = (char*)malloc(sizeof(char) * (strlen(base) + strlen(add) + 1)); |
|
|
char *ret = (char *)malloc(strlen(base) + strlen(add) + 1); |
|
|
return strcat(strcpy(ret, base), add); |
|
|
return strcat(strcpy(ret, base), add); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t* uint32_init(uint32_t number) { // new uint32 (by malloc)
|
|
|
|
|
|
uint32_t *data = (uint32_t *)malloc(sizeof(uint32_t)); |
|
|
|
|
|
*data = number; |
|
|
|
|
|
return data; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
char** string_list_init() { // init string list
|
|
|
char** string_list_init() { // init string list
|
|
|
char **string_list = (char **)malloc(sizeof(char *)); |
|
|
char **string_list = (char **)malloc(sizeof(char *)); |
|
|
*string_list = NULL; // list end sign
|
|
|
*string_list = NULL; // list end sign
|
|
@ -20,7 +26,7 @@ char** string_list_init() { // init string list |
|
|
|
|
|
|
|
|
uint32_t string_list_len(char **string_list) { // get len of string list
|
|
|
uint32_t string_list_len(char **string_list) { // get len of string list
|
|
|
uint32_t num = 0; |
|
|
uint32_t num = 0; |
|
|
while(string_list[num++] != NULL); // get string list size
|
|
|
while(string_list[num++] != NULL); // get list size
|
|
|
return num - 1; |
|
|
return num - 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -32,10 +38,11 @@ char** string_list_append(char **string_list, const char *string) { // add new s |
|
|
return string_list; |
|
|
return string_list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: string list free
|
|
|
|
|
|
void string_list_free(char **string_list) { // free string list
|
|
|
void string_list_free(char **string_list) { // free string list
|
|
|
// free every string
|
|
|
for (char **string = string_list; *string != NULL; ++string) { |
|
|
// free list itself
|
|
|
free(*string); |
|
|
|
|
|
} |
|
|
|
|
|
free(string_list); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
char* string_list_dump(char **string_list) { // ['a', 'b', 'c', ...]
|
|
|
char* string_list_dump(char **string_list) { // ['a', 'b', 'c', ...]
|
|
@ -52,25 +59,19 @@ char* string_list_dump(char **string_list) { // ['a', 'b', 'c', ...] |
|
|
return strcat(string_ret, "]"); |
|
|
return strcat(string_ret, "]"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint32_t** uint32_list_init() { |
|
|
uint32_t** uint32_list_init() { // init uint32 list
|
|
|
uint32_t **int_list = (uint32_t **)malloc(sizeof(uint32_t *)); |
|
|
uint32_t **uint32_list = (uint32_t **)malloc(sizeof(uint32_t *)); |
|
|
*int_list = NULL; |
|
|
*uint32_list = NULL; |
|
|
return int_list; |
|
|
return uint32_list; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t* uint32_init(uint32_t number) { |
|
|
|
|
|
uint32_t *data = (uint32_t *)malloc(sizeof(uint32_t)); |
|
|
|
|
|
*data = number; |
|
|
|
|
|
return data; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint32_t uint32_list_len(uint32_t **int_list) { |
|
|
uint32_t uint32_list_len(uint32_t **uint32_list) { // get len of uint32 list
|
|
|
uint32_t num = 0; |
|
|
uint32_t num = 0; |
|
|
while(int_list[num++] != NULL); // get int list size
|
|
|
while(uint32_list[num++] != NULL); // get list size
|
|
|
return num - 1; |
|
|
return num - 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
uint32_t** uint32_list_append(uint32_t **uint32_list, uint32_t number) { |
|
|
uint32_t** uint32_list_append(uint32_t **uint32_list, uint32_t number) { // add new uint32 at the end of list
|
|
|
uint32_t len = uint32_list_len(uint32_list); |
|
|
uint32_t len = uint32_list_len(uint32_list); |
|
|
uint32_list = (uint32_t **)realloc(uint32_list, sizeof(uint32_t *) * (len + 2)); |
|
|
uint32_list = (uint32_t **)realloc(uint32_list, sizeof(uint32_t *) * (len + 2)); |
|
|
uint32_list[len] = uint32_init(number); |
|
|
uint32_list[len] = uint32_init(number); |
|
@ -78,22 +79,25 @@ uint32_t** uint32_list_append(uint32_t **uint32_list, uint32_t number) { |
|
|
return uint32_list; |
|
|
return uint32_list; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void uint32_list_free(uint32_t **uint32_list) { // free uint32 list
|
|
|
|
|
|
for (uint32_t **number = uint32_list; *number != NULL; ++number) { |
|
|
|
|
|
free(*number); |
|
|
|
|
|
} |
|
|
|
|
|
free(uint32_list); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
char* uint32_list_dump(uint32_t **uint32_list) { // [1, 2, 3, ...]
|
|
|
char* uint32_list_dump(uint32_t **uint32_list) { // [1, 2, 3, ...]
|
|
|
if (uint32_list_len(uint32_list) == 0) { |
|
|
if (uint32_list_len(uint32_list) == 0) { |
|
|
return string_init("[]"); // empty int list
|
|
|
return string_init("[]"); // empty int list
|
|
|
} |
|
|
} |
|
|
char uint32_str[12]; |
|
|
char uint32_str[12]; |
|
|
char *string_ret = (char *)malloc(2); |
|
|
char *string_ret = (char *)malloc(2); |
|
|
string_ret[0] = '['; |
|
|
strcpy(string_ret, "["); |
|
|
string_ret[1] = '\0'; |
|
|
|
|
|
for (uint32_t **number = uint32_list; *number != NULL; ++number) { |
|
|
for (uint32_t **number = uint32_list; *number != NULL; ++number) { |
|
|
sprintf(uint32_str, "%d", **number); |
|
|
sprintf(uint32_str, "%d", **number); |
|
|
string_ret = (char*)realloc(string_ret, strlen(string_ret) + 15); |
|
|
string_ret = (char*)realloc(string_ret, strlen(string_ret) + 15); |
|
|
string_ret = strcat(strcat(string_ret, uint32_str), ", "); |
|
|
string_ret = strcat(strcat(string_ret, uint32_str), ", "); |
|
|
} |
|
|
} |
|
|
string_ret[strlen(string_ret) - 2] = ']'; |
|
|
string_ret[strlen(string_ret) - 2] = '\0'; |
|
|
string_ret[strlen(string_ret) - 1] = '\0'; |
|
|
return strcat(string_ret, "]"); |
|
|
return string_ret; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// TODO: uint32 list free
|
|
|
|
|
|