summaryrefslogtreecommitdiff
path: root/filter.c
diff options
context:
space:
mode:
authorJohn Millaway <john43@users.sourceforge.net>2006-03-21 21:22:33 +0000
committerJohn Millaway <john43@users.sourceforge.net>2006-03-21 21:22:33 +0000
commit84807fceb85ea583aedd2a0701966a484acb0d35 (patch)
treedb4299c1edcb07c33dcd74f2411e5a17f90b63da /filter.c
parentd71e70468f7f654b56941eb73a3e5cf15fca6091 (diff)
Reverted previous input filter changes.
Added noop macro to scanner output. Modified scan.l to escape m4 quotes found in user code.
Diffstat (limited to 'filter.c')
-rw-r--r--filter.c83
1 files changed, 20 insertions, 63 deletions
diff --git a/filter.c b/filter.c
index 409f044..e60e083 100644
--- a/filter.c
+++ b/filter.c
@@ -126,7 +126,7 @@ struct filter *filter_create_int (struct filter *chain,
* @param chain The head of the chain.
* @return true on success.
*/
-bool filter_apply_chain (struct filter * chain, const bool parent_to_child)
+bool filter_apply_chain (struct filter * chain)
{
int pid, pipes[2];
@@ -135,7 +135,7 @@ bool filter_apply_chain (struct filter * chain, const bool parent_to_child)
* to be children of the main flex process.
*/
if (chain)
- filter_apply_chain (chain->next, parent_to_child);
+ filter_apply_chain (chain->next);
else
return true;
@@ -154,29 +154,17 @@ bool filter_apply_chain (struct filter * chain, const bool parent_to_child)
if (pid == 0) {
/* child */
- /* For the parent_to_child direction, we need stdin (the FILE* stdin)
- * to connect to this new pipe. There is no portable way to set stdin
- * to a new file descriptor, as stdin is not an lvalue on some systems
- * (BSD). So we dup the new pipe onto the stdin descriptor and use a
- * no-op fseek to sync the stream. This is a Hail Mary situation. It
- * seems to work. Note that the same concept applies, but opposite,
- * for child_to_parent filters.
+ /* We need stdin (the FILE* stdin) to connect to this new pipe.
+ * There is no portable way to set stdin to a new file descriptor,
+ * as stdin is not an lvalue on some systems (BSD).
+ * So we dup the new pipe onto the stdin descriptor and use a no-op fseek
+ * to sync the stream. This is a Hail Mary situation. It seems to work.
*/
-
- if (parent_to_child){
- close (pipes[1]);
- if (dup2 (pipes[0], fileno (stdin)) == -1)
- flexfatal (_("dup2(pipes[0],0)"));
- close (pipes[0]);
- fseek (stdin, 0, SEEK_CUR);
- }
- else{
- close (pipes[0]);
- if (dup2 (pipes[1], fileno (stdout)) == -1)
- flexfatal (_("dup2(pipes[1],1)"));
- close (pipes[1]);
- fseek (stdout, 0, SEEK_CUR);
- }
+ close (pipes[1]);
+ if (dup2 (pipes[0], fileno (stdin)) == -1)
+ flexfatal (_("dup2(pipes[0],0)"));
+ close (pipes[0]);
+ fseek (stdin, 0, SEEK_CUR);
/* run as a filter, either internally or by exec */
if (chain->filter_func) {
@@ -196,20 +184,11 @@ bool filter_apply_chain (struct filter * chain, const bool parent_to_child)
}
/* Parent */
- if (parent_to_child){
- close (pipes[0]);
- if (dup2 (pipes[1], fileno (stdout)) == -1)
- flexfatal (_("dup2(pipes[1],1)"));
- close (pipes[1]);
- fseek (stdout, 0, SEEK_CUR);
- }
- else{
- close (pipes[1]);
- if (dup2 (pipes[0], fileno (stdin)) == -1)
- flexfatal (_("dup2(pipes[0],0)"));
- close (pipes[0]);
- fseek (stdin, 0, SEEK_CUR);
- }
+ close (pipes[0]);
+ if (dup2 (pipes[1], fileno (stdout)) == -1)
+ flexfatal (_("dup2(pipes[1],1)"));
+ close (pipes[1]);
+ fseek (stdout, 0, SEEK_CUR);
return true;
}
@@ -267,7 +246,7 @@ int filter_tee_header (struct filter *chain)
if (freopen ((char *) chain->extra, "w", stdout) == NULL)
flexfatal (_("freopen(headerfilename) failed"));
- filter_apply_chain (chain->next, true);
+ filter_apply_chain (chain->next);
to_h = stdout;
}
@@ -279,6 +258,7 @@ int filter_tee_header (struct filter *chain)
fputs ("m4_changecom`'m4_dnl\n", to_h);
fputs ("m4_changequote`'m4_dnl\n", to_h);
fputs ("m4_changequote([[,]])[[]]m4_dnl\n", to_h);
+ fputs ("m4_define([[M4_YY_NOOP]])[[]]m4_dnl\n", to_h);
fputs ("m4_define( [[M4_YY_IN_HEADER]],[[]])m4_dnl\n",
to_h);
fprintf (to_h, "#ifndef %sHEADER_H\n", prefix);
@@ -294,6 +274,7 @@ int filter_tee_header (struct filter *chain)
fputs ("m4_changecom`'m4_dnl\n", to_c);
fputs ("m4_changequote`'m4_dnl\n", to_c);
fputs ("m4_changequote([[,]])[[]]m4_dnl\n", to_c);
+ fputs ("m4_define([[M4_YY_NOOP]])[[]]m4_dnl\n", to_c);
fprintf (to_c, "m4_define( [[M4_YY_OUTFILE_NAME]],[[%s]])m4_dnl\n",
outfilename ? outfilename : "<stdout>");
@@ -424,28 +405,4 @@ int filter_fix_linedirs (struct filter *chain)
return 0;
}
-/* set_input_file - open the given file (if NULL, stdin) for scanning */
-
-void set_input_file( file )
-char *file;
-{
- /* Preprocess the input to quote m4 escapes.*/
- if ( file && strcmp( file, "-" ) )
- {
- infilename = copy_string( file );
- yyin = fopen( infilename, "r" );
-
- if ( yyin == NULL )
- lerrsf( _( "can't open %s" ), file );
- }
-
- else
- {
- yyin = stdin;
- infilename = copy_string( "<stdin>" );
- }
-
- linenum = 1;
-}
-
/* vim:set expandtab cindent tabstop=4 softtabstop=4 shiftwidth=4 textwidth=0: */