summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-11 09:13:09 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-05-11 09:13:09 (GMT)
commit590e208c40797206fd6a93651fc59e0b68eeb545 (patch) (side-by-side diff)
treed7abd0ca33b3355b1a27760bf9850e445fafd607 /src
parentdb81e378576dcc5510032c72060e48e562f208c9 (diff)
downloadwydawca-590e208c40797206fd6a93651fc59e0b68eeb545.tar.gz
wydawca-590e208c40797206fd6a93651fc59e0b68eeb545.tar.bz2
Remove obstack.
* src/txtacc.c: New file. * gnulib.modules: Remove obstack. * src/wydawca.h (txtacc_create, txtacc_free) (txtacc_free_string, txtacc_grow) (txtacc_finish): New functions. (txtacc_1grow): New macro.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/Makefile.am1
-rw-r--r--src/builtin.c16
-rw-r--r--src/cmdline.opt24
-rw-r--r--src/directive.c6
-rw-r--r--src/lock.c2
-rw-r--r--src/meta.c26
-rw-r--r--src/report.c17
-rw-r--r--src/triplet.c8
-rw-r--r--src/txtacc.c177
-rw-r--r--src/verify.c6
-rw-r--r--src/wydawca.c1
-rw-r--r--src/wydawca.h18
12 files changed, 242 insertions, 60 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8fd7d94..8139849 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -46,6 +46,7 @@ wydawca_SOURCES=\
vtab.c\
null.c\
timer.c\
+ txtacc.c\
report.c
BUILT_SOURCES=cmdline.h
diff --git a/src/builtin.c b/src/builtin.c
index 412a2e7..0a76738 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -149,7 +149,7 @@ parse_cmp_type (const char *pat, strcmp_fn *cmpfn, int *rf)
struct builtin_data_storage
{
- struct obstack stk;
+ struct txtacc *acc;
char **wp;
};
@@ -164,7 +164,7 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
int i;
int rc;
size_t count = 0;
- struct obstack stk;
+ struct txtacc *acc;
int flags = 0;
strcmp_fn cmpfn = cmp_exact;
struct builtin_data_storage *bds;
@@ -176,7 +176,7 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
return 0;
}
- obstack_init (&stk);
+ acc = txtacc_create ();
for (i = 0; i < dict->parmc; i++)
{
@@ -198,7 +198,7 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
for (j = 1; j <= ncol; j++)
{
char *val = dict->parmv[i + j];
- obstack_grow (&stk, val, strlen (val) + 1);
+ txtacc_grow (acc, val, strlen (val) + 1);
}
count++;
}
@@ -211,7 +211,7 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
if (count == 0)
{
- obstack_free (&stk, NULL);
+ txtacc_free (acc);
bds = NULL;
rc = 1;
}
@@ -223,8 +223,8 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
bds = xmalloc (sizeof (*bds));
count *= ncol;
bds->wp = xcalloc (count, sizeof (bds->wp[0]));
- bds->stk = stk;
- p = obstack_finish (&stk);
+ bds->acc = acc;
+ p = txtacc_finish (acc);
for (i = 0; i < count; i++)
{
@@ -245,7 +245,7 @@ builtin_free_result (struct dictionary *dict, void *handle)
if (dict->storage)
{
struct builtin_data_storage *bds = dict->storage;
- obstack_free (&bds->stk, NULL);
+ txtacc_free (bds->acc);
free (bds->wp);
free (bds);
dict->storage = NULL;
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 4c3d22f..afa1949 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -14,8 +14,7 @@
You should have received a copy of the GNU General Public License along
with wydawca. If not, see <http://www.gnu.org/licenses/>. */
-static struct obstack pp_cmd_stack;
-static int pp_cmd_stack_init;
+static struct txtacc *pp_cmd_acc;
static struct grecs_list *source_list;
static struct grecs_list *tag_list;
@@ -152,19 +151,16 @@ OPTION(define,D,SYMBOL[=VALUE],
BEGIN
char *p;
- if (!pp_cmd_stack_init)
- {
- obstack_init (&pp_cmd_stack);
- pp_cmd_stack_init = 1;
- }
- obstack_grow (&pp_cmd_stack, " \"-D", 4);
+ if (!pp_cmd_acc)
+ pp_cmd_acc = txtacc_create ();
+ txtacc_grow (pp_cmd_acc, " \"-D", 4);
for (p = optarg; *p; p++)
{
if (*p == '\\' || *p == '"')
- obstack_1grow (&pp_cmd_stack, '\\');
- obstack_1grow (&pp_cmd_stack, *p);
+ txtacc_1grow (pp_cmd_acc, '\\');
+ txtacc_1grow (pp_cmd_acc, *p);
}
- obstack_1grow (&pp_cmd_stack, '"');
+ txtacc_1grow (pp_cmd_acc, '"');
END
OPTION(preprocessor,,COMMAND,
@@ -213,13 +209,13 @@ void
parse_options(int argc, char *argv[])
{
GETOPT(argc, argv)
- if (pp_cmd_stack_init && grecs_preprocessor)
+ if (pp_cmd_acc && grecs_preprocessor)
{
- char *defs = obstack_finish (&pp_cmd_stack);
+ char *defs = txtacc_finish (pp_cmd_acc);
char *cmd = xmalloc (strlen (grecs_preprocessor) + strlen (defs) + 1);
strcpy (cmd, grecs_preprocessor);
strcat (cmd, defs);
grecs_preprocessor = cmd;
- obstack_free (&pp_cmd_stack, NULL);
+ txtacc_free (pp_cmd_acc);
}
}
diff --git a/src/directive.c b/src/directive.c
index 34e5feb..1f11d77 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -498,10 +498,10 @@ run_check_script (const char *script, struct file_triplet *trp,
size_t len = strlen (buf);
if (debug_level > 2)
logmsg (LOG_DEBUG, _("read: %s"), buf);
- obstack_grow (&trp->obstk, buf, len);
+ txtacc_grow (trp->acc, buf, len);
total += size;
}
- obstack_1grow (&trp->obstk, 0);
+ txtacc_1grow (trp->acc, 0);
if (debug_level > 2)
logmsg (LOG_DEBUG, _("bytes read: %lu"), (unsigned long)total);
@@ -511,7 +511,7 @@ run_check_script (const char *script, struct file_triplet *trp,
signal (SIGCHLD, oldsig);
if (total)
- trp->check_diag = obstack_finish (&trp->obstk);
+ trp->check_diag = txtacc_finish (trp->acc);
trp->check_result = status;
if (WIFEXITED (status))
diff --git a/src/lock.c b/src/lock.c
index 9e73463..32367de 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -176,7 +176,7 @@ static char *
host_name ()
{
static char *hostbuf = NULL;
- size_t size;
+ size_t size = 0;
int rc;
if (hostbuf)
diff --git a/src/meta.c b/src/meta.c
index 30d3041..61dc334 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -54,26 +54,26 @@ meta_expand_string (const char *string, struct metadef *def, void *data,
{
const char *p, *s;
char *res;
- struct obstack stk;
+ struct txtacc *acc;
if (!string)
return NULL;
- obstack_init (&stk);
+ acc = txtacc_create ();
for (p = string; *p;)
{
char *e;
size_t len = strcspn (p, "$");
- obstack_grow (&stk, p, len);
+ txtacc_grow (acc, p, len);
p += len;
if (*p == '$')
{
switch (*++p)
{
case '$':
- obstack_grow (&stk, p, 1);
+ txtacc_grow (acc, p, 1);
p++;
break;
@@ -92,16 +92,16 @@ meta_expand_string (const char *string, struct metadef *def, void *data,
size_t len;
/* FIXME: Return value? */
dictionary_quote_string (dict, handle, s, &newval, &len);
- obstack_grow (&stk, newval, len);
+ txtacc_grow (acc, newval, len);
free (newval);
}
else
- obstack_grow (&stk, s, strlen (s));
+ txtacc_grow (acc, s, strlen (s));
p = e + 1;
}
else
{
- obstack_grow (&stk, p - 1, 2);
+ txtacc_grow (acc, p - 1, 2);
p++;
}
break;
@@ -121,20 +121,20 @@ meta_expand_string (const char *string, struct metadef *def, void *data,
size_t len;
/* FIXME: Return value? */
dictionary_quote_string (dict, handle, s, &newval, &len);
- obstack_grow (&stk, newval, len);
+ txtacc_grow (acc, newval, len);
free (newval);
}
else
- obstack_grow (&stk, s, len);
+ txtacc_grow (acc, s, len);
p++;
}
}
else
- obstack_grow (&stk, p, 1);
+ txtacc_grow (acc, p, 1);
}
- obstack_1grow (&stk, 0);
- res = xstrdup (obstack_finish (&stk));
- obstack_free (&stk, NULL);
+ txtacc_1grow (acc, 0);
+ res = xstrdup (txtacc_finish (acc));
+ txtacc_free (acc);
return res;
}
diff --git a/src/report.c b/src/report.c
index b09c7c7..929bfff 100644
--- a/src/report.c
+++ b/src/report.c
@@ -16,17 +16,16 @@
#include "wydawca.h"
-static struct obstack report_stk;
-static int report_stk_inited;
+static struct txtacc *report_acc;
char *report_string;
void
report_init ()
{
- if (!report_stk_inited)
- obstack_init (&report_stk);
+ if (!report_acc)
+ report_acc = txtacc_create ();
else
- obstack_free (&report_stk, report_string);
+ txtacc_free_string (report_acc, report_string);
}
void
@@ -41,8 +40,8 @@ report_add (const char *fmt, ...)
va_end (ap);
if (str)
{
- obstack_grow (&report_stk, str, strlen (str));
- obstack_1grow (&report_stk, '\n');
+ txtacc_grow (report_acc, str, strlen (str));
+ txtacc_1grow (report_acc, '\n');
}
free (str);
}
@@ -50,6 +49,6 @@ report_add (const char *fmt, ...)
void
report_finish ()
{
- obstack_1grow (&report_stk, 0);
- report_string = obstack_finish (&report_stk);
+ txtacc_1grow (report_acc, 0);
+ report_string = txtacc_finish (report_acc);
}
diff --git a/src/triplet.c b/src/triplet.c
index bfd58e5..c214385 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -54,7 +54,7 @@ hash_triplet_free (void *data)
free (tp->directive);
free (tp->blurb);
free (tp->tmp);
- obstack_free (&tp->obstk, NULL);
+ txtacc_free (tp->acc);
/* Free uploader list */
for (up = tp->uploader_list; up; )
@@ -71,8 +71,8 @@ char *
triplet_strdup (struct file_triplet *tp, const char *str)
{
size_t len = strlen (str);
- obstack_grow (&tp->obstk, str, len + 1);
- return obstack_finish (&tp->obstk);
+ txtacc_grow (tp->acc, str, len + 1);
+ return txtacc_finish (tp->acc);
}
/* Register a file in the triplet table */
@@ -105,7 +105,7 @@ register_file (struct file_info *finfo, const struct spool *spool)
if (install)
{
ret->spool = spool;
- obstack_init (&ret->obstk);
+ ret->acc = txtacc_create ();
}
ret->file[finfo->type] = *finfo;
}
diff --git a/src/txtacc.c b/src/txtacc.c
new file mode 100644
index 0000000..c094c22
--- a/dev/null
+++ b/src/txtacc.c
@@ -0,0 +1,177 @@
+/* wydawca - automatic release submission daemon
+ Copyright (C) 2007, 2009, 2010 Sergey Poznyakoff
+
+ Wydawca is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 3 of the License, or (at your
+ option) any later version.
+
+ Wydawca is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with wydawca. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "wydawca.h"
+
+struct txtacc_entry
+{
+ char *buf; /* Text buffer */
+ size_t size; /* Buffer size */
+ size_t len; /* Actual number of bytes in buffer */
+};
+#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);
+ 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)
+ return txtacc_alloc_entry (acc->cur, TXTACC_BUFSIZE);
+ ent = acc->cur->tail->data;
+ if (txtacc_entry_freesize (ent) == 0)
+ ent = txtacc_alloc_entry (acc->cur, TXTACC_BUFSIZE);
+ return ent;
+}
+
+static void
+txtacc_entry_append (struct txtacc_entry *ent, const char *p, size_t size)
+{
+ memcpy (ent->buf + ent->len, p, size);
+ ent->len += size;
+}
+
+static void
+txtacc_entry_tailor (struct txtacc_entry *ent)
+{
+ if (ent->size > ent->len)
+ {
+ char *p = realloc (ent->buf, ent->len);
+ if (!p)
+ return;
+ ent->buf = p;
+ ent->size = ent->len;
+ }
+}
+
+static void
+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));
+ 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);
+ free (acc);
+}
+
+void
+txtacc_grow (struct txtacc *acc, const char *buf, size_t size)
+{
+ while (size)
+ {
+ struct txtacc_entry *ent = txtacc_cur_entry (acc);
+ size_t rest = txtacc_entry_freesize (ent);
+ if (rest > size)
+ rest = size;
+ txtacc_entry_append (ent, buf, rest);
+ buf += rest;
+ size -= rest;
+ }
+}
+
+char *
+txtacc_finish (struct txtacc *acc)
+{
+ struct grecs_list_entry *ep;
+ struct txtacc_entry *txtent;
+ size_t size;
+
+ switch (grecs_list_size (acc->cur))
+ {
+ case 0:
+ return NULL;
+
+ case 1:
+ txtent = acc->cur->head->data;
+ acc->cur->head->data = NULL;
+ grecs_list_append (acc->mem, txtent);
+ txtacc_entry_tailor (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);
+ return txtent->buf;
+}
+
+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);
+ free (tp->buf);
+ return;
+ }
+ }
+}
+
diff --git a/src/verify.c b/src/verify.c
index 93fd28b..b3233e8 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -169,9 +169,9 @@ fill_project_name (struct file_triplet *trp)
trp->file[file_directive].name);
return 1;
}
- obstack_grow (&trp->obstk, trp->relative_dir, len);
- obstack_1grow (&trp->obstk, 0);
- trp->project = obstack_finish (&trp->obstk);
+ txtacc_grow (trp->acc, trp->relative_dir, len);
+ txtacc_1grow (trp->acc, 0);
+ trp->project = txtacc_finish (trp->acc);
}
else
trp->project = trp->relative_dir;
diff --git a/src/wydawca.c b/src/wydawca.c
index bda3065..cc1815b 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -16,7 +16,6 @@
#include "wydawca.h"
#include "mail.h"
-#include "argmatch.h"
char *program_name;
uid_t wydawca_uid;
diff --git a/src/wydawca.h b/src/wydawca.h
index 8d5dd34..ef1ff86 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -46,9 +46,6 @@
#include <mailutils/url.h>
#include <mailutils/errno.h>
-#define obstack_chunk_alloc malloc
-#define obstack_chunk_free free
-#include "obstack.h"
#include "error.h"
#include "xalloc.h"
#include "backupfile.h"
@@ -172,7 +169,7 @@ struct file_triplet
char *blurb; /* Block of directives: directive[i] points here */
char *tmp; /* Temporary storage */
size_t tmpsize; /* Size of memory allocated in tmp */
- struct obstack obstk; /* Obstack for string allocation */
+ struct txtacc *acc; /* Text accumulator for string allocation */
/* User data */
size_t uploader_count;
struct uploader_info *uploader_list;
@@ -558,3 +555,16 @@ int wydawca_userprivs (uid_t uid, gid_t gid, gid_t *grplist, size_t ngrp);
int push_dir (const char *dirname);
int pop_dir (void);
char *getcwd_alloc (void);
+
+struct txtacc *txtacc_create (void);
+void txtacc_free (struct txtacc *acc);
+void txtacc_free_string (struct txtacc *acc, char *str);
+void txtacc_grow (struct txtacc *acc, const char *buf, size_t size);
+#define txtacc_1grow(acc, c) \
+ do \
+ { \
+ char __ch = c; \
+ txtacc_grow (acc, &__ch, 1); \
+ } \
+ while (0)
+char *txtacc_finish (struct txtacc *acc);

Return to:

Send suggestions and report system problems to the System administrator.