[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
xstrtol.h vs. gnulib-tool --pobase
From: |
Eric Blake |
Subject: |
xstrtol.h vs. gnulib-tool --pobase |
Date: |
Tue, 7 Aug 2007 15:33:40 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
My complaint about including translatable strings in xstrtol.h has still not
been resolved. The problem is that if you use the new ./gnulib-tool --pobase
option, you are assuming that all gnulib source files will belong to the gnulib
domain, using gettext.h's redefinition of gettext to dgettext
(DEFAULT_TEXT_DOMAIN). However, DEFAULT_TEXT_DOMAIN is only defined when
compiling the .c files that make up the gnulib library; it is undefined when
compiling the main package, and it is the main package that includes xstrtol.h
and makes the actual gettext call. In other words, even after using --pobase,
the main package would STILL have to list gnulib/xstrtol.h in its own
POTFILES.in, contrary to the intent of --pobase.
This patch implements a solution - move the translatable strings into a .c
file, so that they are owned by gnulib's POTFILES.in and the actual [d]gettext
call occurs within the library. It also moves the testsuite out of xstrtol.c
into the tests directory, so that I could automate the tests with './gnulib-
tool --with-tests --test xstrtoimax xstrtoumax'. It fixes some bugs in the
test in the process, since previously for xstrtoimax, it was attempting to
print an intmax_t by using %lu. OK to apply?
2007-08-07 Eric Blake <address@hidden>
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.
Index: lib/xstrtol-error.c
===================================================================
RCS file: lib/xstrtol-error.c
diff -N lib/xstrtol-error.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/xstrtol-error.c 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,61 @@
+/* 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"
+
+#ifndef _
+# define _(str) gettext (str)
+#endif
+
+/* 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;
+ }
+}
Index: lib/xstrtol.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/xstrtol.c,v
retrieving revision 1.42
diff -u -p -r1.42 xstrtol.c
--- lib/xstrtol.c 6 Aug 2007 16:44:25 -0000 1.42
+++ lib/xstrtol.c 7 Aug 2007 15:16:13 -0000
@@ -227,37 +227,3 @@ __xstrtol (const char *s, char **ptr, in
*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 */
Index: lib/xstrtol.h
===================================================================
RCS file: /sources/gnulib/gnulib/lib/xstrtol.h,v
retrieving revision 1.25
diff -u -p -r1.25 xstrtol.h
--- lib/xstrtol.h 6 Aug 2007 16:44:25 -0000 1.25
+++ lib/xstrtol.h 7 Aug 2007 15:16:13 -0000
@@ -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_ */
Index: m4/xstrtol.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/xstrtol.m4,v
retrieving revision 1.10
diff -u -p -r1.10 xstrtol.m4
--- m4/xstrtol.m4 21 Aug 2006 06:11:26 -0000 1.10
+++ m4/xstrtol.m4 7 Aug 2007 15:16:13 -0000
@@ -1,5 +1,6 @@
-#serial 9
-dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+#serial 10
+dnl Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software
+dnl Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
@@ -8,4 +9,5 @@ AC_DEFUN([gl_XSTRTOL],
[
AC_LIBOBJ([xstrtol])
AC_LIBOBJ([xstrtoul])
+ AC_LIBOBJ([xstrtol-error])
])
Index: modules/xstrtoimax-tests
===================================================================
RCS file: modules/xstrtoimax-tests
diff -N modules/xstrtoimax-tests
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/xstrtoimax-tests 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,14 @@
+Files:
+tests/test-xstrtoimax.c
+tests/test-xstrtoimax.sh
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-xstrtoimax.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
+check_PROGRAMS += test-xstrtoimax
+EXTRA_DIST += test-xstrtoimax.sh
+test_xstrtoimax_LDADD = $(LDADD) @LIBINTL@
Index: modules/xstrtol
===================================================================
RCS file: /sources/gnulib/gnulib/modules/xstrtol,v
retrieving revision 1.16
diff -u -p -r1.16 xstrtol
--- modules/xstrtol 19 Oct 2006 07:51:14 -0000 1.16
+++ modules/xstrtol 7 Aug 2007 15:16:13 -0000
@@ -5,6 +5,7 @@ Files:
lib/xstrtol.h
lib/xstrtol.c
lib/xstrtoul.c
+lib/xstrtol-error.c
m4/xstrtol.m4
Depends-on:
Index: modules/xstrtol-tests
===================================================================
RCS file: modules/xstrtol-tests
diff -N modules/xstrtol-tests
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/xstrtol-tests 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,16 @@
+Files:
+tests/test-xstrtol.c
+tests/test-xstrtoul.c
+tests/test-xstrtol.sh
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-xstrtol.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
+check_PROGRAMS += test-xstrtol test-xstrtoul
+EXTRA_DIST += test-xstrtol.sh
+test_xstrtol_LDADD = $(LDADD) @LIBINTL@
+test_xstrtoul_LDADD = $(LDADD) @LIBINTL@
Index: modules/xstrtoumax-tests
===================================================================
RCS file: modules/xstrtoumax-tests
diff -N modules/xstrtoumax-tests
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/xstrtoumax-tests 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,14 @@
+Files:
+tests/test-xstrtoumax.c
+tests/test-xstrtoumax.sh
+
+Depends-on:
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-xstrtoumax.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@'
+check_PROGRAMS += test-xstrtoumax
+EXTRA_DIST += test-xstrtoumax.sh
+test_xstrtoumax_LDADD = $(LDADD) @LIBINTL@
Index: tests/test-xstrtoimax.c
===================================================================
RCS file: tests/test-xstrtoimax.c
diff -N tests/test-xstrtoimax.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-xstrtoimax.c 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,4 @@
+#define __xstrtol xstrtoimax
+#define __strtol_t intmax_t
+#define __spec PRIdMAX
+#include "test-xstrtol.c"
Index: tests/test-xstrtoimax.sh
===================================================================
RCS file: tests/test-xstrtoimax.sh
diff -N tests/test-xstrtoimax.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-xstrtoimax.sh 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="t-xstrtoimax.tmp t-xstrtoimax.xo"
+: > t-xstrtoimax.tmp
+too_big=99999999999999999999999999999999999999999999999999999999999999999999
+result=0
+
+# test xstrtoimax
+./test-xstrtoimax${EXEEXT} 1 >> t-xstrtoimax.tmp 2>&1 || result=1
+./test-xstrtoimax${EXEEXT} -1 >> t-xstrtoimax.tmp 2>&1 || result=1
+./test-xstrtoimax${EXEEXT} 1k >> t-xstrtoimax.tmp 2>&1 || result=1
+./test-xstrtoimax${EXEEXT} ${too_big}h >> t-xstrtoimax.tmp 2>&1 && result=1
+./test-xstrtoimax${EXEEXT} $too_big >> t-xstrtoimax.tmp 2>&1 && result=1
+./test-xstrtoimax${EXEEXT} x >> t-xstrtoimax.tmp 2>&1 && result=1
+./test-xstrtoimax${EXEEXT} 9x >> t-xstrtoimax.tmp 2>&1 && result=1
+
+# normalize output
+sed -e 's/^[^:]*: //' < t-xstrtoimax.tmp > t-xstrtoimax.xo
+mv t-xstrtoimax.xo t-xstrtoimax.tmp
+
+# compare expected output
+cat > t-xstrtoimax.xo <<EOF
+1->1 ()
+-1->-1 ()
+1k->1024 ()
+invalid suffix in arg argument \`${too_big}h'
+arg argument \`$too_big' too large
+invalid arg argument \`x'
+invalid suffix in arg argument \`9x'
+EOF
+
+diff t-xstrtoimax.xo t-xstrtoimax.tmp || result=1
+
+rm -fr $tmpfiles
+
+exit $result
Index: tests/test-xstrtol.c
===================================================================
RCS file: tests/test-xstrtol.c
diff -N tests/test-xstrtol.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-xstrtol.c 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,59 @@
+/* Test of xstrtol module.
+ Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+ 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 <inttypes.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "xstrtol.h"
+#include "error.h"
+
+#ifndef __xstrtol
+# define __xstrtol xstrtol
+# define __strtol_t long int
+# define __spec "ld"
+#endif
+
+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->%" __spec " (%s)\n", argv[i], val, p);
+ }
+ else
+ {
+ STRTOL_FATAL_ERROR ("arg", argv[i], s_err);
+ }
+ }
+ exit (0);
+}
Index: tests/test-xstrtol.sh
===================================================================
RCS file: tests/test-xstrtol.sh
diff -N tests/test-xstrtol.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-xstrtol.sh 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,55 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="t-xstrtol.tmp t-xstrtol.xo"
+: > t-xstrtol.tmp
+too_big=99999999999999999999999999999999999999999999999999999999999999999999
+result=0
+
+# test xstrtol
+./test-xstrtol${EXEEXT} 1 >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtol${EXEEXT} -1 >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtol${EXEEXT} 1k >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtol${EXEEXT} ${too_big}h >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtol${EXEEXT} $too_big >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtol${EXEEXT} x >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtol${EXEEXT} 9x >> t-xstrtol.tmp 2>&1 && result=1
+
+# test xstrtoul
+./test-xstrtoul${EXEEXT} 1 >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtoul${EXEEXT} -1 >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtoul${EXEEXT} 1k >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtoul${EXEEXT} ${too_big}h >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtoul${EXEEXT} $too_big >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtoul${EXEEXT} x >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtoul${EXEEXT} 9x >> t-xstrtol.tmp 2>&1 && result=1
+
+# normalize output
+sed -e 's/^[^:]*: //' < t-xstrtol.tmp > t-xstrtol.xo
+mv t-xstrtol.xo t-xstrtol.tmp
+
+# compare expected output
+cat > t-xstrtol.xo <<EOF
+1->1 ()
+-1->-1 ()
+1k->1024 ()
+invalid suffix in arg argument \`${too_big}h'
+arg argument \`$too_big' too large
+invalid arg argument \`x'
+invalid suffix in arg argument \`9x'
+1->1 ()
+invalid arg argument \`-1'
+1k->1024 ()
+invalid suffix in arg argument \`${too_big}h'
+arg argument \`$too_big' too large
+invalid arg argument \`x'
+invalid suffix in arg argument \`9x'
+EOF
+
+diff t-xstrtol.xo t-xstrtol.tmp || result=1
+
+rm -fr $tmpfiles
+
+exit $result
Index: tests/test-xstrtoul.c
===================================================================
RCS file: tests/test-xstrtoul.c
diff -N tests/test-xstrtoul.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-xstrtoul.c 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,4 @@
+#define __xstrtol xstrtoul
+#define __strtol_t unsigned long int
+#define __spec "lu"
+#include "test-xstrtol.c"
Index: tests/test-xstrtoumax.c
===================================================================
RCS file: tests/test-xstrtoumax.c
diff -N tests/test-xstrtoumax.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-xstrtoumax.c 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,4 @@
+#define __xstrtol xstrtoumax
+#define __strtol_t uintmax_t
+#define __spec PRIuMAX
+#include "test-xstrtol.c"
Index: tests/test-xstrtoumax.sh
===================================================================
RCS file: tests/test-xstrtoumax.sh
diff -N tests/test-xstrtoumax.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ tests/test-xstrtoumax.sh 7 Aug 2007 15:16:13 -0000
@@ -0,0 +1,39 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="t-xstrtoumax.tmp t-xstrtoumax.xo"
+: > t-xstrtoumax.tmp
+too_big=99999999999999999999999999999999999999999999999999999999999999999999
+result=0
+
+# test xstrtoumax
+./test-xstrtoumax${EXEEXT} 1 >> t-xstrtoumax.tmp 2>&1 || result=1
+./test-xstrtoumax${EXEEXT} -1 >> t-xstrtoumax.tmp 2>&1 && result=1
+./test-xstrtoumax${EXEEXT} 1k >> t-xstrtoumax.tmp 2>&1 || result=1
+./test-xstrtoumax${EXEEXT} ${too_big}h >> t-xstrtoumax.tmp 2>&1 && result=1
+./test-xstrtoumax${EXEEXT} $too_big >> t-xstrtoumax.tmp 2>&1 && result=1
+./test-xstrtoumax${EXEEXT} x >> t-xstrtoumax.tmp 2>&1 && result=1
+./test-xstrtoumax${EXEEXT} 9x >> t-xstrtoumax.tmp 2>&1 && result=1
+
+# normalize output
+sed -e 's/^[^:]*: //' < t-xstrtoumax.tmp > t-xstrtoumax.xo
+mv t-xstrtoumax.xo t-xstrtoumax.tmp
+
+# compare expected output
+cat > t-xstrtoumax.xo <<EOF
+1->1 ()
+invalid arg argument \`-1'
+1k->1024 ()
+invalid suffix in arg argument \`${too_big}h'
+arg argument \`$too_big' too large
+invalid arg argument \`x'
+invalid suffix in arg argument \`9x'
+EOF
+
+diff t-xstrtoumax.xo t-xstrtoumax.tmp || result=1
+
+rm -fr $tmpfiles
+
+exit $result
- xstrtol.h vs. gnulib-tool --pobase,
Eric Blake <=