summaryrefslogtreecommitdiffabout
path: root/src
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 /src
parent590e208c40797206fd6a93651fc59e0b68eeb545 (diff)
downloadwydawca-f569a6f2628b9ddef4dfb4424aff2dad644a8f19.tar.gz
wydawca-f569a6f2628b9ddef4dfb4424aff2dad644a8f19.tar.bz2
Improve the txtacc interface.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-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
10 files changed, 25 insertions, 16 deletions
diff --git a/src/builtin.c b/src/builtin.c
index 0a76738..9d1063c 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -224,7 +224,7 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
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++)
{
diff --git a/src/cmdline.opt b/src/cmdline.opt
index afa1949..f92f48f 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -211,11 +211,15 @@ 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
@@ -511,7 +511,7 @@ run_check_script (const char *script, struct file_triplet *trp,
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))
diff --git a/src/meta.c b/src/meta.c
index 61dc334..059fe6e 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -133,7 +133,7 @@ meta_expand_string (const char *string, struct metadef *def, void *data,
txtacc_grow (acc, p, 1);
}
txtacc_1grow (acc, 0);
- res = xstrdup (txtacc_finish (acc));
+ res = txtacc_finish (acc, 1);
txtacc_free (acc);
return res;
}
diff --git a/src/process.c b/src/process.c
index 281c26b..e41709d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -36,7 +36,7 @@ register_spool (struct spool *spool)
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;
}
diff --git a/src/report.c b/src/report.c
index 929bfff..0e87ac9 100644
--- a/src/report.c
+++ b/src/report.c
@@ -50,5 +50,5 @@ 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
@@ -72,7 +72,7 @@ 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 */
diff --git a/src/txtacc.c b/src/txtacc.c
index c094c22..91659f6 100644
--- a/src/txtacc.c
+++ b/src/txtacc.c
@@ -121,11 +121,12 @@ txtacc_grow (struct txtacc *acc, const char *buf, size_t size)
}
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))
{
@@ -135,7 +136,6 @@ txtacc_finish (struct txtacc *acc)
case 1:
txtent = acc->cur->head->data;
acc->cur->head->data = NULL;
- grecs_list_append (acc->mem, txtent);
txtacc_entry_tailor (txtent);
break;
@@ -156,7 +156,12 @@ txtacc_finish (struct txtacc *acc)
}
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
diff --git a/src/verify.c b/src/verify.c
index b3233e8..a49983c 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -171,7 +171,7 @@ fill_project_name (struct file_triplet *trp)
}
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;
diff --git a/src/wydawca.h b/src/wydawca.h
index ef1ff86..2307bad 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -567,4 +567,4 @@ void txtacc_grow (struct txtacc *acc, const char *buf, size_t size);
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.