summaryrefslogtreecommitdiffabout
path: root/src/txtacc.c
Side-by-side diff
Diffstat (limited to 'src/txtacc.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/txtacc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/txtacc.c b/src/txtacc.c
index 91659f6..442e27e 100644
--- a/src/txtacc.c
+++ b/src/txtacc.c
@@ -25,26 +25,26 @@ struct txtacc_entry
#define TXTACC_BUFSIZE 1024
#define txtacc_entry_freesize(e) ((e)->size - (e)->len)
struct txtacc
{
struct grecs_list *cur; /* Current build list */
struct grecs_list *mem; /* List of already allocated elements */
};
static struct txtacc_entry *
txtacc_alloc_entry (struct grecs_list *list, size_t size)
{
- struct txtacc_entry *p = xmalloc (sizeof (*p));
- p->buf = xmalloc (size);
+ struct txtacc_entry *p = grecs_malloc (sizeof (*p));
+ p->buf = grecs_malloc (size);
p->size = size;
p->len = 0;
grecs_list_append (list, p);
return p;
}
static struct txtacc_entry *
txtacc_cur_entry (struct txtacc *acc)
{
struct txtacc_entry *ent;
if (grecs_list_size (acc->cur) == 0)
@@ -80,25 +80,25 @@ txtacc_entry_free (void *p)
{
if (p)
{
struct txtacc_entry *ent = p;
free (ent->buf);
free (ent);
}
}
struct txtacc *
txtacc_create ()
{
- struct txtacc *acc = xmalloc (sizeof (*acc));
+ struct txtacc *acc = grecs_malloc (sizeof (*acc));
acc->cur = grecs_list_create ();
acc->cur->free_entry = txtacc_entry_free;
acc->mem = grecs_list_create ();
acc->mem->free_entry = txtacc_entry_free;
return acc;
}
void
txtacc_free (struct txtacc *acc)
{
grecs_list_free (acc->cur);
grecs_list_free (acc->mem);
@@ -128,55 +128,57 @@ txtacc_finish (struct txtacc *acc, int steal)
size_t size;
char *p;
switch (grecs_list_size (acc->cur))
{
case 0:
return NULL;
case 1:
txtent = acc->cur->head->data;
acc->cur->head->data = NULL;
txtacc_entry_tailor (txtent);
+ grecs_list_append (acc->mem, txtent);
break;
default:
size = 0;
for (ep = acc->cur->head; ep; ep = ep->next)
{
txtent = ep->data;
size += txtent->len;
}
txtent = txtacc_alloc_entry (acc->mem, size);
for (ep = acc->cur->head; ep; ep = ep->next)
{
struct txtacc_entry *tp = ep->data;
txtacc_entry_append (txtent, tp->buf, tp->len);
}
}
grecs_list_clear (acc->cur);
p = txtent->buf;
if (steal)
- free (txtent);
- else
- grecs_list_append (acc->mem, txtent);
+ {
+ grecs_list_remove_tail (acc->mem);
+ free (txtent);
+ }
return p;
}
void
txtacc_free_string (struct txtacc *acc, char *str)
{
struct grecs_list_entry *ep;
for (ep = acc->mem->head; ep; ep = ep->next)
{
struct txtacc_entry *tp = ep->data;
if (tp->buf == str)
{
- grecs_list_remove_entry(acc->mem, ep);
+ grecs_list_remove_entry (acc->mem, ep);
free (tp->buf);
return;
}
}
}

Return to:

Send suggestions and report system problems to the System administrator.