From 0530ad59afca536d95f12bfaeb0fa03d45f3b698 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20Sch=C3=B6bel?= <jonathan@xn--schbel-yxa.info> Date: Wed, 12 Oct 2022 18:52:27 +0200 Subject: [PATCH] unused function SH_Text_enlarge The function SH_Text_enlarge was used as the common functionality of SH_Text_append_string and SH_Text_append_text. It was first ported to the new internal data structure, but then integrated into the function SH_Text_append_string, because the function SH_Text_append_text doesn't need it anymore and having the user calling it is now not as useful as originally intended, both for the user and the library, so it shouldn't be exposed. Also the method SH_Text_append_string is easier to implement, if it is written as a single function. Neithertheless it is commited here for future reference. --- src/text.c.Text_enlarge | 90 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/text.c.Text_enlarge diff --git a/src/text.c.Text_enlarge b/src/text.c.Text_enlarge new file mode 100644 index 0000000..b28c3b4 --- /dev/null +++ b/src/text.c.Text_enlarge @@ -0,0 +1,90 @@ + +//~ static inline bool +//~ Text_enlarge (struct SH_Text * text, size_t size, + //~ struct text_segment ** last, struct SH_Error * error) +//~ { + //~ size_t new_size; + //~ struct text_segment * seg; + + //~ for (seg = text->data; seg->next != NULL; seg = seg->next); + + //~ if (size == SIZE_MAX) + //~ { + //~ ERROR1 ("Maximum length of SH_Text reached.\n"); + + //~ if (error != NULL) + //~ { + //~ error->type = DOMAIN_ERROR; + //~ } + + //~ return FALSE; + //~ } + //~ else if (SIZE_MAX - size < seg->size) + //~ { + //~ seg->next = malloc (sizeof (struct text_segment)); + + //~ if (seg->next == NULL) + //~ { + //~ ERROR1 ("Memory allocation for SH_Text data " + //~ "failed.\n"); + + //~ if (error != NULL) + //~ { + //~ error->type = ALLOCATION_FAILED; + //~ } + + //~ return FALSE; + //~ } + + //~ seg = seg->next; + //~ seg->length = 0; + //~ seg->size = 0; + //~ seg->text = NULL; + //~ seg->next = NULL; + //~ } + //~ else + //~ { + //~ size += seg->size; + //~ } + + + //~ /* if both operands were integers, + //~ * this operation would fail + //~ * as the division will behave like + //~ * calling floor in the first place. */ + //~ new_size = (size_t) ceilf ((float) size / (float) CHUNK_SIZE); + //~ if (new_size > (SIZE_MAX / (float) CHUNK_SIZE)) + //~ { + //~ new_size = size; + //~ } + //~ else + //~ { + //~ new_size *= CHUNK_SIZE; + //~ } + + //~ seg->text = realloc (seg->text, new_size * sizeof (char)); + + //~ if (errno == ENOMEM) + //~ { + //~ ERROR1 ("Memory allocation for SH_Text data failed.\n"); + + //~ if (error != NULL) + //~ { + //~ error->type = ALLOCATION_FAILED; + //~ } + + //~ return FALSE; + //~ } + + //~ seg->size = new_size; + + //~ *last = seg; + + //~ if (error != NULL) + //~ { + //~ error->type = SUCCESS; + //~ } + + //~ return TRUE; +//~ } + -- GitLab