aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-11 12:13:09 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-11 12:13:09 +0300
commit590e208c40797206fd6a93651fc59e0b68eeb545 (patch)
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')
-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
@@ -43,12 +43,13 @@ wydawca_SOURCES=\
wydawca.h\
mail.h\
mail.c\
vtab.c\
null.c\
timer.c\
+ txtacc.c\
report.c
BUILT_SOURCES=cmdline.h
EXTRA_DIST=cmdline.opt pp-setup update-2.0.awk
SUFFIXES=.opt .c .h
diff --git a/src/builtin.c b/src/builtin.c
index 412a2e7..0a76738 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -146,13 +146,13 @@ parse_cmp_type (const char *pat, strcmp_fn *cmpfn, int *rf)
}
return 0;
}
struct builtin_data_storage
{
- struct obstack stk;
+ struct txtacc *acc;
char **wp;
};
static int default_ncol[] = {
4, /* project-uploader: name, realname, email, pubkey */
2, /* project-owner: email, realname */
@@ -161,25 +161,25 @@ static int default_ncol[] = {
int
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;
int ncol = default_ncol[dict->id];
if (dict->parmc == 0)
{
dict->nrow = dict->ncol = 0;
return 0;
}
- obstack_init (&stk);
+ acc = txtacc_create ();
for (i = 0; i < dict->parmc; i++)
{
char *pat = dict->parmv[i];
if (pat[0] == '/')
@@ -195,39 +195,39 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
if (cmpfn (pat, req, flags))
{
size_t j;
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++;
}
i += ncol;
}
dict->nrow = count;
dict->ncol = ncol;
if (count == 0)
{
- obstack_free (&stk, NULL);
+ txtacc_free (acc);
bds = NULL;
rc = 1;
}
else
{
size_t i;
char *p;
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++)
{
bds->wp[i] = p;
p += strlen (p) + 1;
}
@@ -242,13 +242,13 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
int
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;
}
return 0;
}
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 4c3d22f..afa1949 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -11,14 +11,13 @@
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/>. */
-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;
static int
string_cmp (const void *elt1, const void *elt2)
@@ -149,25 +148,22 @@ END
OPTION(define,D,SYMBOL[=VALUE],
[<define a preprocessor symbol>])
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,
[<use COMMAND instead of the default preprocessor>])
BEGIN
grecs_preprocessor = optarg;
@@ -210,16 +206,16 @@ END
OPTIONS_END
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
@@ -495,26 +495,26 @@ run_check_script (const char *script, struct file_triplet *trp,
logmsg (LOG_DEBUG, _("reading script output..."));
while (getline (&buf, &size, fp) > 0)
{
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);
fclose (fp);
waitpid (pid, &status, 0);
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))
{
status = WEXITSTATUS (status);
if (status)
diff --git a/src/lock.c b/src/lock.c
index 9e73463..32367de 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -173,13 +173,13 @@ expire_stale_lock (const char *file)
}
static char *
host_name ()
{
static char *hostbuf = NULL;
- size_t size;
+ size_t size = 0;
int rc;
if (hostbuf)
return hostbuf;
do
diff --git a/src/meta.c b/src/meta.c
index 30d3041..61dc334 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -51,32 +51,32 @@ find_expansion_word (const char *kw, size_t len,
char *
meta_expand_string (const char *string, struct metadef *def, void *data,
struct dictionary *dict, void *handle)
{
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;
case '-':
if (*++p)
p++;
@@ -89,22 +89,22 @@ meta_expand_string (const char *string, struct metadef *def, void *data,
if (dict)
{
char *newval;
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;
default:
if ((s = find_expansion_char (*p, def, data)) != NULL)
@@ -118,26 +118,26 @@ meta_expand_string (const char *string, struct metadef *def, void *data,
if (dict)
{
char *newval;
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;
}
void
meta_free (struct metadef *def)
{
diff --git a/src/report.c b/src/report.c
index b09c7c7..929bfff 100644
--- a/src/report.c
+++ b/src/report.c
@@ -13,23 +13,22 @@
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"
-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
report_add (const char *fmt, ...)
{
va_list ap;
@@ -38,18 +37,18 @@ report_add (const char *fmt, ...)
va_start (ap, fmt);
grecs_vasprintf (&str, &size, fmt, ap);
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);
}
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
@@ -51,13 +51,13 @@ hash_triplet_free (void *data)
free (tp->file[i].name);
}
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; )
{
struct uploader_info *next = up->next;
free (up);
@@ -68,14 +68,14 @@ hash_triplet_free (void *data)
}
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 */
void
register_file (struct file_info *finfo, const struct spool *spool)
{
@@ -102,13 +102,13 @@ register_file (struct file_info *finfo, const struct spool *spool)
if (!ret)
grecs_alloc_die ();
free (key.name);
if (install)
{
ret->spool = spool;
- obstack_init (&ret->obstk);
+ ret->acc = txtacc_create ();
}
ret->file[finfo->type] = *finfo;
}
/* Return true if any part of the triplet TRP was modified more than
TTL seconds ago */
diff --git a/src/txtacc.c b/src/txtacc.c
new file mode 100644
index 0000000..c094c22
--- /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
@@ -166,15 +166,15 @@ fill_project_name (struct file_triplet *trp)
if (len == 0)
{
logmsg (LOG_ERR, _("%s: empty `directory' directive"),
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;
return 0;
}
diff --git a/src/wydawca.c b/src/wydawca.c
index bda3065..cc1815b 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -13,13 +13,12 @@
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"
#include "mail.h"
-#include "argmatch.h"
char *program_name;
uid_t wydawca_uid;
gid_t wydawca_gid;
size_t wydawca_supp_groupc;
gid_t *wydawca_supp_groups;
diff --git a/src/wydawca.h b/src/wydawca.h
index 8d5dd34..ef1ff86 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -43,15 +43,12 @@
#include <sysexits.h>
#include <mailutils/types.h>
#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"
#include "grecs.h"
#include "wordsplit.h"
@@ -169,13 +166,13 @@ struct file_triplet
const struct spool *spool; /* Owning spool */
char *relative_dir; /* Directory relative to spool->dest_dir */
char **directive; /* Decoded directive pairs (key: value\0) */
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;
struct uploader_info *uploader;
/* Special data for template formatting */
char *project; /* Triplet project name (if known) */
@@ -555,6 +552,19 @@ int tcpwrap_access(int fd);
/* userprivs.c */
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.