From e2794c96be81352d2af6c6648b7ee208d298b7fb Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 18 Oct 2019 14:52:44 -0400 Subject: [PATCH] Replace str_t with struct str --- include/str.h | 10 ++++------ src/main.c | 12 ++++++------ src/string.c | 10 +++++----- diff --git a/include/str.h b/include/str.h index 45d15ec27fa19e498d15c133399c5a9a286c59f7..ab7ba690080ddf4328edeb8a0e1c10813bca7c7a 100644 --- a/include/str.h +++ b/include/str.h @@ -7,11 +7,9 @@ char *str; size_t len, size; }; -typedef struct str str_t; - -str_t *str_create(); -void str_free(str_t *str); -void str_reset(str_t *str); -int str_append_ch(str_t *str, uint32_t ch); +struct str *str_create(); +void str_free(struct str *str); +void str_reset(struct str *str); +int str_append_ch(struct str *str, uint32_t ch); #endif diff --git a/src/main.c b/src/main.c index 19a134cea3fde65effda8397732ebe953931b3a4..3251a44fa6eb87e3e98caba4a4974b01de0cfcf5 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ char *strstr(const char *haystack, const char *needle); char *strerror(int errnum); static int parse_section(struct parser *p) { - str_t *section = str_create(); + struct str *section = str_create(); uint32_t ch; while ((ch = parser_getch(p)) != UTF8_INVALID) { if (ch < 0x80 && isdigit(ch)) { @@ -43,8 +43,8 @@ parser_fatal(p, "Expected manual section"); return -1; } -static str_t *parse_extra(struct parser *p) { - str_t *extra = str_create(); +static struct str *parse_extra(struct parser *p) { + struct str *extra = str_create(); int ret = str_append_ch(extra, '"'); assert(ret != -1); uint32_t ch; @@ -66,9 +66,9 @@ return NULL; } static void parse_preamble(struct parser *p) { - str_t *name = str_create(); + struct str *name = str_create(); int ex = 0; - str_t *extras[2] = { NULL }; + struct str *extras[2] = { NULL }; int section = -1; uint32_t ch; time_t date_time; @@ -446,7 +446,7 @@ }; struct table_cell { enum table_align align; - str_t *contents; + struct str *contents; struct table_cell *next; }; diff --git a/src/string.c b/src/string.c index 98bc0394a2f15171fb113acb5a9286a7454f22e7..aaf44d0bd8a29a94deef9dc8b9bed98f8f277c74 100644 --- a/src/string.c +++ b/src/string.c @@ -3,7 +3,7 @@ #include #include "str.h" #include "unicode.h" -static int ensure_capacity(str_t *str, size_t len) { +static int ensure_capacity(struct str *str, size_t len) { if (len + 1 >= str->size) { char *new = realloc(str->str, str->size * 2); if (!new) { @@ -15,8 +15,8 @@ } return 1; } -str_t *str_create() { - str_t *str = calloc(sizeof(str_t), 1); +struct str *str_create() { + struct str *str = calloc(sizeof(struct str), 1); str->str = malloc(16); str->size = 16; str->len = 0; @@ -24,13 +24,13 @@ str->str[0] = '\0'; return str; } -void str_free(str_t *str) { +void str_free(struct str *str) { if (!str) return; free(str->str); free(str); } -int str_append_ch(str_t *str, uint32_t ch) { +int str_append_ch(struct str *str, uint32_t ch) { int size = utf8_chsize(ch); if (size <= 0) { return -1; -- 2.48.1