aboutsummaryrefslogtreecommitdiff
path: root/filter.c
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2013-04-30 23:49:23 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2013-04-30 23:49:23 +0000
commit13a0f001a6ab7539b25c7c3d3bdde6e762bf7048 (patch)
tree1b00f7df67c04abe9ac5ac8ad06da4a6490be03e /filter.c
parent6916e47018a8c6788dae5b227a259d86ccd41e52 (diff)
downloadsrc-13a0f001a6ab7539b25c7c3d3bdde6e762bf7048.tar.gz
src-13a0f001a6ab7539b25c7c3d3bdde6e762bf7048.zip
Import flex 2.5.37.vendor/flex/2.5.37
Notes
Notes: svn path=/vendor/flex/dist/; revision=250125 svn path=/vendor/flex/2.5.37/; revision=250126; tag=vendor/flex/2.5.37
Diffstat (limited to 'filter.c')
-rw-r--r--filter.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/filter.c b/filter.c
index b0c7bf1edb09..c82f7f8938a1 100644
--- a/filter.c
+++ b/filter.c
@@ -48,6 +48,8 @@ struct filter *filter_create_ext (struct filter *chain, const char *cmd,
/* allocate and initialize new filter */
f = (struct filter *) flex_alloc (sizeof (struct filter));
+ if (!f)
+ flexerror (_("flex_alloc failed (f) in filter_create_ext"));
memset (f, 0, sizeof (*f));
f->filter_func = NULL;
f->extra = NULL;
@@ -67,6 +69,8 @@ struct filter *filter_create_ext (struct filter *chain, const char *cmd,
f->argv =
(const char **) flex_alloc (sizeof (char *) *
(max_args + 1));
+ if (!f->argv)
+ flexerror (_("flex_alloc failed (f->argv) in filter_create_ext"));
f->argv[f->argc++] = cmd;
va_start (ap, cmd);
@@ -104,6 +108,8 @@ struct filter *filter_create_int (struct filter *chain,
/* allocate and initialize new filter */
f = (struct filter *) flex_alloc (sizeof (struct filter));
+ if (!f)
+ flexerror (_("flex_alloc failed in filter_create_int"));
memset (f, 0, sizeof (*f));
f->next = NULL;
f->argc = 0;
@@ -129,6 +135,10 @@ struct filter *filter_create_int (struct filter *chain,
bool filter_apply_chain (struct filter * chain)
{
int pid, pipes[2];
+ int r;
+ const int readsz = 512;
+ char *buf;
+
/* Tricky recursion, since we want to begin the chain
* at the END. Why? Because we need all the forked processes
@@ -145,6 +155,7 @@ bool filter_apply_chain (struct filter * chain)
fflush (stdout);
fflush (stderr);
+
if (pipe (pipes) == -1)
flexerror (_("pipe failed"));
@@ -161,6 +172,7 @@ bool filter_apply_chain (struct filter * chain)
* to sync the stream. This is a Hail Mary situation. It seems to work.
*/
close (pipes[1]);
+clearerr(stdin);
if (dup2 (pipes[0], fileno (stdin)) == -1)
flexfatal (_("dup2(pipes[0],0)"));
close (pipes[0]);
@@ -177,7 +189,8 @@ bool filter_apply_chain (struct filter * chain)
else {
execvp (chain->argv[0],
(char **const) (chain->argv));
- flexfatal (_("exec failed"));
+ lerrsf_fatal ( _("exec of %s failed"),
+ chain->argv[0]);
}
exit (1);
@@ -279,6 +292,8 @@ int filter_tee_header (struct filter *chain)
outfilename ? outfilename : "<stdout>");
buf = (char *) flex_alloc (readsz);
+ if (!buf)
+ flexerror (_("flex_alloc failed in filter_tee_header"));
while (fgets (buf, readsz, stdin)) {
fputs (buf, to_c);
if (write_header)
@@ -296,13 +311,13 @@ int filter_tee_header (struct filter *chain)
fputs ("m4_undefine( [[M4_YY_IN_HEADER]])m4_dnl\n", to_h);
fflush (to_h);
- if (ferror (to_h))
- lerrsf (_("error writing output file %s"),
- (char *) chain->extra);
+ if (ferror (to_h))
+ lerrsf (_("error writing output file %s"),
+ (char *) chain->extra);
- else if (fclose (to_h))
- lerrsf (_("error closing output file %s"),
- (char *) chain->extra);
+ else if (fclose (to_h))
+ lerrsf (_("error closing output file %s"),
+ (char *) chain->extra);
}
fflush (to_c);
@@ -338,6 +353,8 @@ int filter_fix_linedirs (struct filter *chain)
return 0;
buf = (char *) flex_alloc (readsz);
+ if (!buf)
+ flexerror (_("flex_alloc failed in filter_fix_linedirs"));
while (fgets (buf, readsz, stdin)) {
@@ -345,7 +362,7 @@ int filter_fix_linedirs (struct filter *chain)
/* Check for #line directive. */
if (buf[0] == '#'
- && regexec (&regex_linedir, buf, 3, m, 0) == 0) {
+ && regexec (&regex_linedir, buf, 3, m, 0) == 0) {
int num;
char *fname;