summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-11 21:05:00 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2011-05-11 21:05:00 (GMT)
commitf569a6f2628b9ddef4dfb4424aff2dad644a8f19 (patch) (side-by-side diff)
tree6d6e5b03bc97198c2002703591fe5e751978130c
parent590e208c40797206fd6a93651fc59e0b68eeb545 (diff)
downloadwydawca-f569a6f2628b9ddef4dfb4424aff2dad644a8f19.tar.gz
wydawca-f569a6f2628b9ddef4dfb4424aff2dad644a8f19.tar.bz2
Improve the txtacc interface.
Diffstat (more/less context) (ignore whitespace changes)
m---------grecs0
-rw-r--r--src/builtin.c2
-rw-r--r--src/cmdline.opt14
-rw-r--r--src/directive.c2
-rw-r--r--src/meta.c2
-rw-r--r--src/process.c2
-rw-r--r--src/report.c2
-rw-r--r--src/triplet.c2
-rw-r--r--src/txtacc.c11
-rw-r--r--src/verify.c2
-rw-r--r--src/wydawca.h2
11 files changed, 25 insertions, 16 deletions
diff --git a/grecs b/grecs
-Subproject 3e5d6e9683d5d3efa3a82556d0f73892d674ed7
+Subproject f8ca129aaf4876dfa9778c34ed5bd8a669ca22e
diff --git a/src/builtin.c b/src/builtin.c
index 0a76738..9d1063c 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -215,25 +215,25 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
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->acc = acc;
- p = txtacc_finish (acc);
+ p = txtacc_finish (acc, 0);
for (i = 0; i < count; i++)
{
bds->wp[i] = p;
p += strlen (p) + 1;
}
rc = 0;
}
dict->storage = bds;
return rc;
diff --git a/src/cmdline.opt b/src/cmdline.opt
index afa1949..f92f48f 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -202,20 +202,24 @@ BEGIN
config_help ();
exit (0);
END
OPTIONS_END
void
parse_options(int argc, char *argv[])
{
GETOPT(argc, argv)
if (pp_cmd_acc && grecs_preprocessor)
{
- 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;
+ char *cmd;
+ size_t len = strlen (grecs_preprocessor);
+ txtacc_1grow (pp_cmd_acc, 0);
+ txtacc_grow (pp_cmd_acc, grecs_preprocessor, len + 1);
+ cmd = txtacc_finish (pp_cmd_acc, 1);
txtacc_free (pp_cmd_acc);
+ memmove (cmd + len + 1, cmd, strlen (cmd) + 1);
+ memcpy (cmd, grecs_preprocessor, len);
+ cmd[len] = ' ';
+ grecs_preprocessor = cmd;
}
}
diff --git a/src/directive.c b/src/directive.c
index 1f11d77..08a14df 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -502,25 +502,25 @@ run_check_script (const char *script, struct file_triplet *trp,
total += size;
}
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 = txtacc_finish (trp->acc);
+ trp->check_diag = txtacc_finish (trp->acc, 0);
trp->check_result = status;
if (WIFEXITED (status))
{
status = WEXITSTATUS (status);
if (status)
{
logmsg (LOG_ERR, "%s for %s@%s returned %d",
descr, trp->name, trp->spool->tag, status);
return 1;
}
else if (debug_level > 2)
diff --git a/src/meta.c b/src/meta.c
index 61dc334..059fe6e 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -124,25 +124,25 @@ meta_expand_string (const char *string, struct metadef *def, void *data,
txtacc_grow (acc, newval, len);
free (newval);
}
else
txtacc_grow (acc, s, len);
p++;
}
}
else
txtacc_grow (acc, p, 1);
}
txtacc_1grow (acc, 0);
- res = xstrdup (txtacc_finish (acc));
+ res = txtacc_finish (acc, 1);
txtacc_free (acc);
return res;
}
void
meta_free (struct metadef *def)
{
for (; def->kw; def++)
{
if (def->storage)
{
free (def->storage);
diff --git a/src/process.c b/src/process.c
index 281c26b..e41709d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -27,25 +27,25 @@ static struct spool_list *spool_list;
void
register_spool (struct spool *spool)
{
struct spool_list *sp = xmalloc (sizeof *sp);
sp->spool = *spool;
sp->next = spool_list;
spool_list = sp;
}
static int
spool_check_alias (struct spool *spool, const char *name)
{
- if (spool->aliases && grecs_list_locate (spool->aliases, name))
+ if (spool->aliases && grecs_list_locate (spool->aliases, (char*) name))
return 1;
return 0;
}
struct spool *
wydawca_find_spool (const char *name)
{
struct spool_list *sp;
for (sp = spool_list; sp; sp = sp->next)
{
if (strcmp (sp->spool.tag, name) == 0
diff --git a/src/report.c b/src/report.c
index 929bfff..0e87ac9 100644
--- a/src/report.c
+++ b/src/report.c
@@ -41,14 +41,14 @@ report_add (const char *fmt, ...)
if (str)
{
txtacc_grow (report_acc, str, strlen (str));
txtacc_1grow (report_acc, '\n');
}
free (str);
}
void
report_finish ()
{
txtacc_1grow (report_acc, 0);
- report_string = txtacc_finish (report_acc);
+ report_string = txtacc_finish (report_acc, 0);
}
diff --git a/src/triplet.c b/src/triplet.c
index c214385..3083c64 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -63,25 +63,25 @@ hash_triplet_free (void *data)
free (up);
up = next;
}
free (tp);
}
char *
triplet_strdup (struct file_triplet *tp, const char *str)
{
size_t len = strlen (str);
txtacc_grow (tp->acc, str, len + 1);
- return txtacc_finish (tp->acc);
+ return txtacc_finish (tp->acc, 0);
}
/* Register a file in the triplet table */
void
register_file (struct file_info *finfo, const struct spool *spool)
{
struct file_triplet key, *ret;
int install = 1;
if (!triplet_table)
{
triplet_table = grecs_symtab_create (sizeof (struct file_triplet),
diff --git a/src/txtacc.c b/src/txtacc.c
index c094c22..91659f6 100644
--- a/src/txtacc.c
+++ b/src/txtacc.c
@@ -112,60 +112,65 @@ txtacc_grow (struct txtacc *acc, const char *buf, size_t 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)
+txtacc_finish (struct txtacc *acc, int steal)
{
struct grecs_list_entry *ep;
struct txtacc_entry *txtent;
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;
- 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;
+ p = txtent->buf;
+ if (steal)
+ free (txtent);
+ else
+ grecs_list_append (acc->mem, 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);
diff --git a/src/verify.c b/src/verify.c
index b3233e8..a49983c 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -162,25 +162,25 @@ fill_project_name (struct file_triplet *trp)
p = strchr (trp->relative_dir, '/');
if (p)
{
size_t len = p - trp->relative_dir;
if (len == 0)
{
logmsg (LOG_ERR, _("%s: empty `directory' directive"),
trp->file[file_directive].name);
return 1;
}
txtacc_grow (trp->acc, trp->relative_dir, len);
txtacc_1grow (trp->acc, 0);
- trp->project = txtacc_finish (trp->acc);
+ trp->project = txtacc_finish (trp->acc, 0);
}
else
trp->project = trp->relative_dir;
return 0;
}
struct uploader_info *
new_uploader_info (struct uploader_info *src)
{
struct uploader_info *p = xmalloc (sizeof (*p));
p->next = NULL;
diff --git a/src/wydawca.h b/src/wydawca.h
index ef1ff86..2307bad 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -558,13 +558,13 @@ 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);
+char *txtacc_finish (struct txtacc *acc, int steal);

Return to:

Send suggestions and report system problems to the System administrator.