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) (show 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
@@ -221,13 +221,13 @@ builtin_lookup (struct dictionary *dict, void *handle, const char *req)
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;
}
diff --git a/src/cmdline.opt b/src/cmdline.opt
index afa1949..f92f48f 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -208,14 +208,18 @@ 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
@@ -508,13 +508,13 @@ run_check_script (const char *script, struct file_triplet *trp,
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)
diff --git a/src/meta.c b/src/meta.c
index 61dc334..059fe6e 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -130,13 +130,13 @@ meta_expand_string (const char *string, struct metadef *def, void *data,
}
}
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)
diff --git a/src/process.c b/src/process.c
index 281c26b..e41709d 100644
--- a/src/process.c
+++ b/src/process.c
@@ -33,13 +33,13 @@ register_spool (struct spool *spool)
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)
diff --git a/src/report.c b/src/report.c
index 929bfff..0e87ac9 100644
--- a/src/report.c
+++ b/src/report.c
@@ -47,8 +47,8 @@ report_add (const char *fmt, ...)
}
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
@@ -69,13 +69,13 @@ hash_triplet_free (void *data)
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)
{
diff --git a/src/txtacc.c b/src/txtacc.c
index c094c22..91659f6 100644
--- a/src/txtacc.c
+++ b/src/txtacc.c
@@ -118,27 +118,27 @@ txtacc_grow (struct txtacc *acc, const char *buf, size_t size)
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)
@@ -153,13 +153,18 @@ txtacc_finish (struct txtacc *acc)
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;
diff --git a/src/verify.c b/src/verify.c
index b3233e8..a49983c 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -168,13 +168,13 @@ fill_project_name (struct file_triplet *trp)
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;
}
diff --git a/src/wydawca.h b/src/wydawca.h
index ef1ff86..2307bad 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -564,7 +564,7 @@ void txtacc_grow (struct txtacc *acc, const char *buf, size_t size);
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.