summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkim Demaille <demaille@gostai.com>2012-02-18 19:19:26 +0100
committerAkim Demaille <demaille@gostai.com>2012-02-18 19:32:18 +0100
commitd0f2b7f8566c186f34392efeedbab08c2ae72129 (patch)
treea253b56163a4689dadbd019b74914f64b5780f90
parenteff97eb54a1ff17da66f9d1c746eb009feeba889 (diff)
downloadbison-d0f2b7f8566c186f34392efeedbab08c2ae72129.tar.gz
maint: avoid "magic number exit".
* cfg.mk (local-checks-to-skip): No longer skip it. * bootstrap.conf (gnulib_modules): Add sysexits. * doc/bison.texinfo, etc/bench.pl.in, src/parse-gram.y, * src/system.h, tests/calc.at, tests/named-refs.at: Use assert where appropriate instead of "if (...) exit". Use symbolic exit status elsewhere.
-rw-r--r--bootstrap.conf1
-rw-r--r--cfg.mk1
-rw-r--r--doc/bison.texinfo12
-rwxr-xr-xetc/bench.pl.in3
-rw-r--r--lib/.gitignore1
-rw-r--r--m4/.gitignore1
-rw-r--r--src/parse-gram.y2
-rw-r--r--src/system.h1
-rw-r--r--tests/calc.at3
-rw-r--r--tests/named-refs.at4
10 files changed, 18 insertions, 11 deletions
diff --git a/bootstrap.conf b/bootstrap.conf
index 757111ce..c8aac8dd 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -24,6 +24,7 @@ gnulib_modules='
javaexec-script ldexpl maintainer-makefile malloc-gnu mbschr mbsrchr
mbswidth obstack perror pipe-posix quote quotearg realloc-posix
spawn-pipe stdbool stpcpy strdup-posix strerror strtoul strverscmp
+ sysexits
unistd unistd-safer unlocked-io update-copyright unsetenv verify
warnings xalloc xalloc-die xstrndup
diff --git a/cfg.mk b/cfg.mk
index 03cbe642..cc9dbd1b 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -43,7 +43,6 @@ local-checks-to-skip = \
sc_prohibit_atoi_atof \
sc_prohibit_doubled_word \
sc_prohibit_empty_lines_at_EOF \
- sc_prohibit_magic_number_exit \
sc_prohibit_strcmp
# The local directory containing the checked-out copy of gnulib used in
diff --git a/doc/bison.texinfo b/doc/bison.texinfo
index cd687b90..7fb05155 100644
--- a/doc/bison.texinfo
+++ b/doc/bison.texinfo
@@ -9969,7 +9969,7 @@ calcxx_driver::scan_begin ()
else if (!(yyin = fopen (file.c_str (), "r")))
@{
error (std::string ("cannot open ") + file + ": " + strerror(errno));
- exit (1);
+ exit (EXIT_FAILURE);
@}
@}
@@ -10703,11 +10703,17 @@ yyparse (char const *file)
{
yyin = fopen (file, "r");
if (!yyin)
- exit (2);
+ {
+ perror ("fopen");
+ exit (EXIT_FAILURE);
+ }
/* One token only. */
yylex ();
if (fclose (yyin) != 0)
- exit (3);
+ {
+ perror ("fclose");
+ exit (EXIT_FAILURE);
+ }
return 0;
}
diff --git a/etc/bench.pl.in b/etc/bench.pl.in
index 7e604309..0bee4df1 100755
--- a/etc/bench.pl.in
+++ b/etc/bench.pl.in
@@ -528,9 +528,8 @@ yylex (void)
static int
power (int base, int exponent)
{
+ assert (0 <= exponent);
int res = 1;
- if (exponent < 0)
- exit (3);
for (/* Niente */; exponent; --exponent)
res *= base;
return res;
diff --git a/lib/.gitignore b/lib/.gitignore
index 5b14836b..832cab85 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -263,3 +263,4 @@
/closeout.h
/fpending.c
/fpending.h
+/sysexits.in.h
diff --git a/m4/.gitignore b/m4/.gitignore
index 01e5f645..90e5ae15 100644
--- a/m4/.gitignore
+++ b/m4/.gitignore
@@ -167,3 +167,4 @@
/xalloc.m4
/xsize.m4
/xstrndup.m4
+/sysexits.m4
diff --git a/src/parse-gram.y b/src/parse-gram.y
index 01b640df..9e5bbe61 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -804,7 +804,7 @@ version_check (location const *loc, char const *version)
{
complain_at (*loc, "require bison %s, but have %s",
version, PACKAGE_VERSION);
- exit (63);
+ exit (EX_CONFIG);
}
}
diff --git a/src/system.h b/src/system.h
index bd94c837..a3168db1 100644
--- a/src/system.h
+++ b/src/system.h
@@ -52,6 +52,7 @@
typedef size_t uintptr_t;
#endif
+#include <sysexits.h>
/*---------.
| Gnulib. |
diff --git a/tests/calc.at b/tests/calc.at
index b8e5612a..2f357137 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -346,8 +346,7 @@ static int
power (int base, int exponent)
{
int res = 1;
- if (exponent < 0)
- exit (3);
+ assert (0 <= exponent);
for (/* Niente */; exponent; --exponent)
res *= base;
return res;
diff --git a/tests/named-refs.at b/tests/named-refs.at
index 62c46211..2490d2df 100644
--- a/tests/named-refs.at
+++ b/tests/named-refs.at
@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# FIXME: Duplication with calc.at.
AT_BANNER([[Named references tests.]])
AT_SETUP([Tutorial calculator])
@@ -142,8 +143,7 @@ int yylex (void)
static int power (int base, int exponent)
{
int res = 1;
- if (exponent < 0)
- exit (3);
+ assert (0 <= exponent);
for (/* Niente */; exponent; --exponent)
res *= base;
return res;