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.

Conflicts:

	doc/bison.texinfo
	src/parse-gram.y
This commit is contained in:
Akim Demaille
2012-02-18 19:19:26 +01:00
parent 24bb5f8fb7
commit dd5611579b
10 changed files with 20 additions and 13 deletions

View File

@@ -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

1
cfg.mk
View File

@@ -47,7 +47,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

View File

@@ -9366,8 +9366,8 @@ calcxx_driver::scan_begin ()
yyin = stdin;
else if (!(yyin = fopen (file.c_str (), "r")))
@{
error (std::string ("cannot open ") + file);
exit (1);
error (std::string ("cannot open ") + file + ": " + strerror(errno));
exit (EXIT_FAILURE);
@}
@}
@@ -10045,11 +10045,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;
}

View File

@@ -291,9 +291,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;

1
lib/.gitignore vendored
View File

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

1
m4/.gitignore vendored
View File

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

View File

@@ -759,7 +759,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);
}
}

View File

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

View File

@@ -347,8 +347,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;

View File

@@ -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;