diff options
author | Eric Blake <ebb9@byu.net> | 2007-08-08 12:45:54 +0000 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2007-08-08 12:45:54 +0000 |
commit | c7110f3b833159c91e8cbe6a14349174aeef4ab6 (patch) | |
tree | b1f30e57f6dab6db962d6ac823191b940964c6d6 /lib | |
parent | fe32d83182dd651bbdaee9a8b6a54c6e3ad9ad2e (diff) | |
download | gnulib-c7110f3b833159c91e8cbe6a14349174aeef4ab6.tar.gz |
Move xstrtol messages into gnulib domain, when --pobase is used.
* lib/xstrtol.h (_STRTOL_ERROR): Move messages out of macro...
* lib/xstrtol-error.c (xstrtol_error): ...into new file.
* modules/xstrtol (Files): Distribute new file.
* m4/xstrtol.m4 (gl_XSTRTOL): Build new file.
* lib/xstrtol.c (TESTING_XSTRTO): Move tests...
* tests/test-xstrtol.c: ...into new file.
* tests/test-xstrtoul.c: Also test xstrtoul.
* tests/test-xstrtoimax.c: Also test xstrtoimax.
* tests/test-xstrtoumax.c: Also test xstrtoumax.
* tests/test-xstrtol.sh: Drive the tests.
* tests/test-xstrtoimax.sh: Likewise.
* tests/test-xstrtoumax.sh: Likewise.
* modules/xstrtol-tests: New module.
* modules/xstrtoimax-tests: Likewise.
* modules/xstrtoumax-tests: Likewise.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/xstrtol-error.c | 59 | ||||
-rw-r--r-- | lib/xstrtol.c | 34 | ||||
-rw-r--r-- | lib/xstrtol.h | 33 |
3 files changed, 62 insertions, 64 deletions
diff --git a/lib/xstrtol-error.c b/lib/xstrtol-error.c new file mode 100644 index 0000000000..5316fc0aba --- /dev/null +++ b/lib/xstrtol-error.c @@ -0,0 +1,59 @@ +/* A more useful interface to strtol. + + Copyright (C) 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004, 2006, 2007 + Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include <config.h> +#include "xstrtol.h" + +#include "error.h" +#include "gettext.h" + +#define _(str) gettext (str) + +/* Report an error for an out-of-range integer argument. + EXIT_CODE is the exit code (0 for a non-fatal error). + OPTION is the option that takes the argument + (usually starting with one or two minus signs). + ARG is the option's argument. + ERR is the error code returned by one of the xstrto* functions. */ +void +xstrtol_error (int exit_code, char const *option, char const *arg, + strtol_error err) +{ + switch (err) + { + default: + abort (); + + case LONGINT_INVALID: + error (exit_code, 0, _("invalid %s argument `%s'"), + option, arg); + break; + + case LONGINT_INVALID_SUFFIX_CHAR: + case LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW: + error (exit_code, 0, _("invalid suffix in %s argument `%s'"), + option, arg); + break; + + case LONGINT_OVERFLOW: + error (exit_code, 0, _("%s argument `%s' too large"), + option, arg); + break; + } +} diff --git a/lib/xstrtol.c b/lib/xstrtol.c index d57b3da853..ed5bcdd0b2 100644 --- a/lib/xstrtol.c +++ b/lib/xstrtol.c @@ -227,37 +227,3 @@ __xstrtol (const char *s, char **ptr, int strtol_base, *val = tmp; return err; } - -#ifdef TESTING_XSTRTO - -# include <stdio.h> -# include "error.h" - -char *program_name; - -int -main (int argc, char **argv) -{ - strtol_error s_err; - int i; - - program_name = argv[0]; - for (i=1; i<argc; i++) - { - char *p; - __strtol_t val; - - s_err = __xstrtol (argv[i], &p, 0, &val, "bckmw"); - if (s_err == LONGINT_OK) - { - printf ("%s->%lu (%s)\n", argv[i], val, p); - } - else - { - STRTOL_FATAL_ERROR ("arg", argv[i], s_err); - } - } - exit (0); -} - -#endif /* TESTING_XSTRTO */ diff --git a/lib/xstrtol.h b/lib/xstrtol.h index 4df140c2ef..96fc4d23e4 100644 --- a/lib/xstrtol.h +++ b/lib/xstrtol.h @@ -24,8 +24,6 @@ # include <inttypes.h> -# include "gettext.h" - # ifndef _STRTOL_ERROR enum strtol_error { @@ -56,35 +54,10 @@ _DECLARE_XSTRTOL (xstrtoumax, uintmax_t) (usually starting with one or two minus signs). ARG is the option's argument. ERR is the error code returned by one of the xstrto* functions. */ -# define _STRTOL_ERROR(Exit_code, Option, Arg, Err) \ - do \ - { \ - switch ((Err)) \ - { \ - default: \ - abort (); \ - \ - case LONGINT_INVALID: \ - error (Exit_code, 0, gettext ("invalid %s argument `%s'"), \ - Option, Arg); \ - break; \ - \ - case LONGINT_INVALID_SUFFIX_CHAR: \ - case LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW: \ - error ((Exit_code), 0, \ - gettext ("invalid suffix in %s argument `%s'"), \ - Option, Arg); \ - break; \ - \ - case LONGINT_OVERFLOW: \ - error (Exit_code, 0, gettext ("%s argument `%s' too large"), \ - Option, Arg); \ - break; \ - } \ - } \ - while (0) +void xstrtol_error (int exit_code, char const *option, char const *arg, + strtol_error err); # define STRTOL_FATAL_ERROR(Option, Arg, Err) \ - _STRTOL_ERROR (exit_failure, Option, Arg, Err) + xstrtol_error (exit_failure, Option, Arg, Err) #endif /* not XSTRTOL_H_ */ |