[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: minor refactoring
From: |
Akim Demaille |
Subject: |
FYI: minor refactoring |
Date: |
Fri, 15 Jun 2012 11:59:13 +0200 |
These two were waiting in some cleanup branch. Just pushed
in master.
From aed41cf9a0dde045bf93c9241dfdd62d75fe3d18 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Fri, 25 May 2012 14:36:32 +0200
Subject: [PATCH 1/2] maint: space changes
* configure.ac, src/complain.c: space changes.
---
configure.ac | 3 ++-
src/complain.c | 9 +++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/configure.ac b/configure.ac
index 95a1b02..0facd4a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,6 +73,7 @@ if test "$enable_gcc_warnings" = yes; then
warn_c='-Wbad-function-cast -Wmissing-declarations -Wmissing-prototypes
-Wshadow -Wstrict-prototypes'
warn_cxx='-Wnoexcept'
+
AC_LANG_PUSH([C])
for i in $warn_common $warn_c;
do
@@ -89,7 +90,7 @@ if test "$enable_gcc_warnings" = yes; then
do
gl_WARN_ADD([$i], [WARN_CXXFLAGS])
done
- gl_WARN_ADD([ -Wzero-as-null-pointer-constant], [WARN_CXXFLAGS],
+ gl_WARN_ADD([-Wzero-as-null-pointer-constant], [WARN_CXXFLAGS],
[AC_LANG_PROGRAM([], [nullptr])])
gl_WARN_ADD([-Werror], [WERROR_CXXFLAGS])
# Warnings for the test suite only.
diff --git a/src/complain.c b/src/complain.c
index 18432b4..6c7a8ec 100644
--- a/src/complain.c
+++ b/src/complain.c
@@ -74,10 +74,11 @@ error_message (location *loc,
vfprintf (stderr, message, args);
{
size_t l = strlen (message);
- if (l < 2 || message[l-2] != ':' || message[l-1] != ' ') {
- putc ('\n', stderr);
- fflush (stderr);
- }
+ if (l < 2 || message[l-2] != ':' || message[l-1] != ' ')
+ {
+ putc ('\n', stderr);
+ fflush (stderr);
+ }
}
}
--
1.7.10.4
From 22539284f3220db77eae57f1c06846753c20de43 Mon Sep 17 00:00:00 2001
From: Akim Demaille <address@hidden>
Date: Fri, 15 Jun 2012 11:56:13 +0200
Subject: [PATCH 2/2] 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.
---
src/files.c | 9 +++++++++
src/files.h | 3 ++-
src/output.c | 19 +++++++------------
3 files changed, 18 insertions(+), 13 deletions(-)
diff --git a/src/files.c b/src/files.c
index b7000cf..91c0c10 100644
--- a/src/files.c
+++ b/src/files.c
@@ -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. |
`------------------------------------------------------------------*/
diff --git a/src/files.h b/src/files.h
index 8f0bec0..e727d11 100644
--- a/src/files.h
+++ b/src/files.h
@@ -65,7 +65,8 @@ void compute_output_file_names (void);
void output_file_names_free (void);
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);
+FILE *xfdopen (int fd, char const *mode);
#endif /* !FILES_H_ */
diff --git a/src/output.c b/src/output.c
index 37b15cf..76895d6 100644
--- a/src/output.c
+++ b/src/output.c
@@ -571,7 +571,6 @@ static void
output_skeleton (void)
{
int filter_fd[2];
- char const *argv[10];
pid_t pid;
/* 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>
for details. */
{
+ char const *argv[10];
int i = 0;
argv[i++] = m4;
@@ -627,11 +627,12 @@ output_skeleton (void)
argv[i++] = skel;
argv[i++] = NULL;
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 (m4bison);
free (skel);
@@ -639,10 +640,7 @@ output_skeleton (void)
if (trace_flag & trace_muscles)
muscles_output (stderr);
{
- FILE *out = fdopen (filter_fd[1], "w");
- if (! out)
- error (EXIT_FAILURE, get_errno (),
- "fdopen");
+ FILE *out = xfdopen (filter_fd[1], "w");
muscles_output (out);
xfclose (out);
}
@@ -650,10 +648,7 @@ output_skeleton (void)
/* Read and process m4's output. */
timevar_push (TV_M4);
{
- FILE *in = fdopen (filter_fd[0], "r");
- if (! in)
- error (EXIT_FAILURE, get_errno (),
- "fdopen");
+ FILE *in = xfdopen (filter_fd[0], "r");
scan_skel (in);
/* 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
--
1.7.10.4
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: minor refactoring,
Akim Demaille <=