mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-22 02:33:03 +00:00
maint: xfdopen, and scope reduction.
* src/files.h, src/files.c (xfdopen): New. * src/output.c (output_skeleton): Use it. Reduce the scope of argv.
This commit is contained in:
@@ -134,6 +134,15 @@ xfclose (FILE *ptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FILE *
|
||||||
|
xfdopen (int fd, char const *mode)
|
||||||
|
{
|
||||||
|
FILE *res = fdopen (fd, mode);
|
||||||
|
if (! res)
|
||||||
|
error (EXIT_FAILURE, get_errno (), "fdopen");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------------.
|
/*------------------------------------------------------------------.
|
||||||
| Compute ALL_BUT_EXT, ALL_BUT_TAB_EXT and output files extensions. |
|
| Compute ALL_BUT_EXT, ALL_BUT_TAB_EXT and output files extensions. |
|
||||||
`------------------------------------------------------------------*/
|
`------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -65,7 +65,8 @@ void compute_output_file_names (void);
|
|||||||
void output_file_names_free (void);
|
void output_file_names_free (void);
|
||||||
void output_file_name_check (char **file_name);
|
void output_file_name_check (char **file_name);
|
||||||
|
|
||||||
FILE *xfopen (const char *name, const char *mode);
|
FILE *xfopen (const char *name, char const *mode);
|
||||||
void xfclose (FILE *ptr);
|
void xfclose (FILE *ptr);
|
||||||
|
FILE *xfdopen (int fd, char const *mode);
|
||||||
|
|
||||||
#endif /* !FILES_H_ */
|
#endif /* !FILES_H_ */
|
||||||
|
|||||||
19
src/output.c
19
src/output.c
@@ -571,7 +571,6 @@ static void
|
|||||||
output_skeleton (void)
|
output_skeleton (void)
|
||||||
{
|
{
|
||||||
int filter_fd[2];
|
int filter_fd[2];
|
||||||
char const *argv[10];
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
/* Compute the names of the package data dir and skeleton files. */
|
/* Compute the names of the package data dir and skeleton files. */
|
||||||
@@ -602,6 +601,7 @@ output_skeleton (void)
|
|||||||
<http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
|
<http://lists.gnu.org/archive/html/bug-bison/2008-07/msg00000.html>
|
||||||
for details. */
|
for details. */
|
||||||
{
|
{
|
||||||
|
char const *argv[10];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
argv[i++] = m4;
|
argv[i++] = m4;
|
||||||
|
|
||||||
@@ -627,11 +627,12 @@ output_skeleton (void)
|
|||||||
argv[i++] = skel;
|
argv[i++] = skel;
|
||||||
argv[i++] = NULL;
|
argv[i++] = NULL;
|
||||||
aver (i <= ARRAY_CARDINALITY (argv));
|
aver (i <= ARRAY_CARDINALITY (argv));
|
||||||
|
|
||||||
|
/* The ugly cast is because gnulib gets the const-ness wrong. */
|
||||||
|
pid = create_pipe_bidi ("m4", m4, (char **)(void*)argv, false, true,
|
||||||
|
true, filter_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The ugly cast is because gnulib gets the const-ness wrong. */
|
|
||||||
pid = create_pipe_bidi ("m4", m4, (char **)(void*)argv, false, true,
|
|
||||||
true, filter_fd);
|
|
||||||
free (m4sugar);
|
free (m4sugar);
|
||||||
free (m4bison);
|
free (m4bison);
|
||||||
free (skel);
|
free (skel);
|
||||||
@@ -639,10 +640,7 @@ output_skeleton (void)
|
|||||||
if (trace_flag & trace_muscles)
|
if (trace_flag & trace_muscles)
|
||||||
muscles_output (stderr);
|
muscles_output (stderr);
|
||||||
{
|
{
|
||||||
FILE *out = fdopen (filter_fd[1], "w");
|
FILE *out = xfdopen (filter_fd[1], "w");
|
||||||
if (! out)
|
|
||||||
error (EXIT_FAILURE, get_errno (),
|
|
||||||
"fdopen");
|
|
||||||
muscles_output (out);
|
muscles_output (out);
|
||||||
xfclose (out);
|
xfclose (out);
|
||||||
}
|
}
|
||||||
@@ -650,10 +648,7 @@ output_skeleton (void)
|
|||||||
/* Read and process m4's output. */
|
/* Read and process m4's output. */
|
||||||
timevar_push (TV_M4);
|
timevar_push (TV_M4);
|
||||||
{
|
{
|
||||||
FILE *in = fdopen (filter_fd[0], "r");
|
FILE *in = xfdopen (filter_fd[0], "r");
|
||||||
if (! in)
|
|
||||||
error (EXIT_FAILURE, get_errno (),
|
|
||||||
"fdopen");
|
|
||||||
scan_skel (in);
|
scan_skel (in);
|
||||||
/* scan_skel should have read all of M4's output. Otherwise, when we
|
/* scan_skel should have read all of M4's output. Otherwise, when we
|
||||||
close the pipe, we risk letting M4 report a broken-pipe to the
|
close the pipe, we risk letting M4 report a broken-pipe to the
|
||||||
|
|||||||
Reference in New Issue
Block a user