diff options
author | Freya Murphy <freya@freyacat.org> | 2024-09-11 12:06:09 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2024-09-11 12:06:09 -0400 |
commit | e3d2e31377030e84066bed4bbc04bf6c56206305 (patch) | |
tree | d5e7428212606a0f64d5b2e628b3f507948b8e2f /masm/strtbl.c | |
parent | joe (diff) | |
download | mips-e3d2e31377030e84066bed4bbc04bf6c56206305.tar.gz mips-e3d2e31377030e84066bed4bbc04bf6c56206305.tar.bz2 mips-e3d2e31377030e84066bed4bbc04bf6c56206305.zip |
refactor
Diffstat (limited to '')
-rw-r--r-- | masm/strtbl.c | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/masm/strtbl.c b/masm/strtbl.c deleted file mode 100644 index 7bdbbea..0000000 --- a/masm/strtbl.c +++ /dev/null @@ -1,54 +0,0 @@ -#include <merror.h> -#include <string.h> -#include <stdlib.h> - -#include "asm.h" - -int strtbl_get_str(struct str_table *str_tbl, const char *str, size_t *res) -{ - for (size_t i = 0; i < str_tbl->size; i ++) { - if (strcmp(str_tbl->ptr + i, str) == 0) { - if (res != NULL) - *res = i; - return M_SUCCESS; - } - } - - return M_ERROR; -} - -int strtbl_write_str(struct str_table *str_tbl, const char *str, size_t *res) -{ - if (strtbl_get_str(str_tbl, str, res) == M_SUCCESS) - return M_SUCCESS; - - size_t len = strlen(str); - char *new = realloc(str_tbl->ptr, str_tbl->size + len + 1); - if (new == NULL) - return M_ERROR; - str_tbl->ptr = new; - memcpy(str_tbl->ptr + str_tbl->size, str, len + 1); - - if (res != NULL) - *res = str_tbl->size; - - str_tbl->size += len + 1; - return M_SUCCESS; -} - -int strtbl_init(struct str_table *str_tbl) -{ - str_tbl->size = 1; - str_tbl->ptr = malloc(1); - if (str_tbl->ptr == NULL) { - ERROR("cannot alloc"); - return M_ERROR; - } - *str_tbl->ptr = '\0'; - return M_SUCCESS; -} - -void strtbl_free(struct str_table *str_tbl) -{ - free(str_tbl->ptr); -} |