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.
This commit is contained in:
Akim Demaille
2012-02-18 19:19:26 +01:00
parent eff97eb54a
commit d0f2b7f856
10 changed files with 18 additions and 11 deletions

View File

@@ -24,6 +24,7 @@ gnulib_modules='
javaexec-script ldexpl maintainer-makefile malloc-gnu mbschr mbsrchr javaexec-script ldexpl maintainer-makefile malloc-gnu mbschr mbsrchr
mbswidth obstack perror pipe-posix quote quotearg realloc-posix mbswidth obstack perror pipe-posix quote quotearg realloc-posix
spawn-pipe stdbool stpcpy strdup-posix strerror strtoul strverscmp spawn-pipe stdbool stpcpy strdup-posix strerror strtoul strverscmp
sysexits
unistd unistd-safer unlocked-io update-copyright unsetenv verify unistd unistd-safer unlocked-io update-copyright unsetenv verify
warnings xalloc xalloc-die xstrndup warnings xalloc xalloc-die xstrndup

1
cfg.mk
View File

@@ -43,7 +43,6 @@ local-checks-to-skip = \
sc_prohibit_atoi_atof \ sc_prohibit_atoi_atof \
sc_prohibit_doubled_word \ sc_prohibit_doubled_word \
sc_prohibit_empty_lines_at_EOF \ sc_prohibit_empty_lines_at_EOF \
sc_prohibit_magic_number_exit \
sc_prohibit_strcmp sc_prohibit_strcmp
# The local directory containing the checked-out copy of gnulib used in # The local directory containing the checked-out copy of gnulib used in

View File

@@ -9969,7 +9969,7 @@ calcxx_driver::scan_begin ()
else if (!(yyin = fopen (file.c_str (), "r"))) else if (!(yyin = fopen (file.c_str (), "r")))
@{ @{
error (std::string ("cannot open ") + file + ": " + strerror(errno)); 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"); yyin = fopen (file, "r");
if (!yyin) if (!yyin)
exit (2); {
perror ("fopen");
exit (EXIT_FAILURE);
}
/* One token only. */ /* One token only. */
yylex (); yylex ();
if (fclose (yyin) != 0) if (fclose (yyin) != 0)
exit (3); {
perror ("fclose");
exit (EXIT_FAILURE);
}
return 0; return 0;
} }

View File

@@ -528,9 +528,8 @@ yylex (void)
static int static int
power (int base, int exponent) power (int base, int exponent)
{ {
assert (0 <= exponent);
int res = 1; int res = 1;
if (exponent < 0)
exit (3);
for (/* Niente */; exponent; --exponent) for (/* Niente */; exponent; --exponent)
res *= base; res *= base;
return res; return res;

1
lib/.gitignore vendored
View File

@@ -263,3 +263,4 @@
/closeout.h /closeout.h
/fpending.c /fpending.c
/fpending.h /fpending.h
/sysexits.in.h

1
m4/.gitignore vendored
View File

@@ -167,3 +167,4 @@
/xalloc.m4 /xalloc.m4
/xsize.m4 /xsize.m4
/xstrndup.m4 /xstrndup.m4
/sysexits.m4

View File

@@ -804,7 +804,7 @@ version_check (location const *loc, char const *version)
{ {
complain_at (*loc, "require bison %s, but have %s", complain_at (*loc, "require bison %s, but have %s",
version, PACKAGE_VERSION); version, PACKAGE_VERSION);
exit (63); exit (EX_CONFIG);
} }
} }

View File

@@ -52,6 +52,7 @@
typedef size_t uintptr_t; typedef size_t uintptr_t;
#endif #endif
#include <sysexits.h>
/*---------. /*---------.
| Gnulib. | | Gnulib. |

View File

@@ -346,8 +346,7 @@ static int
power (int base, int exponent) power (int base, int exponent)
{ {
int res = 1; int res = 1;
if (exponent < 0) assert (0 <= exponent);
exit (3);
for (/* Niente */; exponent; --exponent) for (/* Niente */; exponent; --exponent)
res *= base; res *= base;
return res; return res;

View File

@@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# FIXME: Duplication with calc.at.
AT_BANNER([[Named references tests.]]) AT_BANNER([[Named references tests.]])
AT_SETUP([Tutorial calculator]) AT_SETUP([Tutorial calculator])
@@ -142,8 +143,7 @@ int yylex (void)
static int power (int base, int exponent) static int power (int base, int exponent)
{ {
int res = 1; int res = 1;
if (exponent < 0) assert (0 <= exponent);
exit (3);
for (/* Niente */; exponent; --exponent) for (/* Niente */; exponent; --exponent)
res *= base; res *= base;
return res; return res;