summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2007-08-06 16:44:24 +0000
committerPaul Eggert <eggert@cs.ucla.edu>2007-08-06 16:44:24 +0000
commit0253ee27eb11b96be8cba141e7e066787b5904c3 (patch)
treef824b18dd4ad1b0a92adf95427f6277cbd184221
parentfb7fde6f658ac18b7ab7ca61dca9a290cc8c3348 (diff)
downloadgnulib-0253ee27eb11b96be8cba141e7e066787b5904c3.tar.gz
* NEWS: Describe interface changes to human, xstrtol.
* lib/human.h: Include <xstrtol.h>. (human_options): Return enum strtol_error, not int. Remove bool arg; take int * instead. * lib/human.c: Don't include "gettext.h". (_): Remove; no longer used. Don't include <xstrtol.h>, since human.h does it. (human_options): Adjust to abovementioned interface changes. Do not report error to stderr; that's now the caller's responsibility. * lib/xstrtol.c (main) [defined TESTING_XSTRTO]: Adjust to interface change. * lib/xstrtol.h (_STRTOL_ERROR): Take Option, Arg rather than Str, Argument_type_string. All uses changed. Put " argument" in diagnostics to make them clearer. Change wording of suffix message for clarity. (STRTOL_FATAL_ERROR): Take Option, Arg rather than Str, Argument_type_string. (STRTOL_FATAL_WARN): Remove; no longer used. * modules/human (Depends-on): Remove gettext-h.
-rw-r--r--ChangeLog24
-rw-r--r--NEWS11
-rw-r--r--lib/human.c17
-rw-r--r--lib/human.h6
-rw-r--r--lib/xstrtol.c6
-rw-r--r--lib/xstrtol.h29
-rw-r--r--modules/human1
7 files changed, 63 insertions, 31 deletions
diff --git a/ChangeLog b/ChangeLog
index bd9b2e9c40..342db9f504 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,27 @@
+2007-08-06 Paul Eggert <eggert@cs.ucla.edu>
+ and Bruno Haible <bruno@clisp.org>
+
+ * NEWS: Describe interface changes to human, xstrtol.
+ * lib/human.h: Include <xstrtol.h>.
+ (human_options): Return enum strtol_error, not int. Remove
+ bool arg; take int * instead.
+ * lib/human.c: Don't include "gettext.h".
+ (_): Remove; no longer used.
+ Don't include <xstrtol.h>, since human.h does it.
+ (human_options): Adjust to abovementioned interface changes.
+ Do not report error to stderr; that's now the caller's
+ responsibility.
+ * lib/xstrtol.c (main) [defined TESTING_XSTRTO]: Adjust to
+ interface change.
+ * lib/xstrtol.h (_STRTOL_ERROR): Take Option, Arg rather than
+ Str, Argument_type_string. All uses changed. Put " argument"
+ in diagnostics to make them clearer. Change wording of suffix
+ message for clarity.
+ (STRTOL_FATAL_ERROR): Take Option, Arg rather than Str,
+ Argument_type_string.
+ (STRTOL_FATAL_WARN): Remove; no longer used.
+ * modules/human (Depends-on): Remove gettext-h.
+
2007-08-06 Simon Josefsson <simon@josefsson.org>
* build-aux/maint.mk, build-aux/GNUmakefile: Relicense to GPLv3+.
diff --git a/NEWS b/NEWS
index dd230cb505..51c3f0b728 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,17 @@ User visible incompatible changes
Date Modules Changes
+2007-08-04 human The function human_options no longer reports an
+ error to standard error; that is now the
+ caller's responsibility. It returns an
+ error code of type enum strtol_error
+ instead of the integer option value, and stores
+ the option value via a new int * argument.
+ xstrtol The first two arguments of STRTOL_FATAL_ERROR
+ are now an option name and option argument
+ instead of an option argument and a type string,
+ STRTOL_FAIL_WARN is removed.
+
2007-07-14 gpl, lgpl New Texinfo versions with no sectioning commands.
2007-07-10 version-etc Output now mentions GPLv3+, not GPLv2+. Use
diff --git a/lib/human.c b/lib/human.c
index ecf4c97ce5..592f830751 100644
--- a/lib/human.c
+++ b/lib/human.c
@@ -1,7 +1,7 @@
/* human.c -- print human readable file size
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006 Free Software Foundation, Inc.
+ 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
@@ -28,13 +28,9 @@
#include <stdlib.h>
#include <string.h>
-#include "gettext.h"
-#define _(msgid) gettext (msgid)
-
#include <argmatch.h>
#include <error.h>
#include <intprops.h>
-#include <xstrtol.h>
/* The maximum length of a suffix like "KiB". */
#define HUMAN_READABLE_SUFFIX_LENGTH_MAX 3
@@ -463,17 +459,14 @@ humblock (char const *spec, uintmax_t *block_size, int *options)
return LONGINT_OK;
}
-int
-human_options (char const *spec, bool report_errors, uintmax_t *block_size)
+enum strtol_error
+human_options (char const *spec, int *opts, uintmax_t *block_size)
{
- int opts;
- strtol_error e = humblock (spec, block_size, &opts);
+ strtol_error e = humblock (spec, block_size, opts);
if (*block_size == 0)
{
*block_size = default_block_size ();
e = LONGINT_INVALID;
}
- if (e != LONGINT_OK && report_errors)
- STRTOL_FATAL_ERROR (spec, _("block size"), e);
- return opts;
+ return e;
}
diff --git a/lib/human.h b/lib/human.h
index 44b8b36d57..95fc930042 100644
--- a/lib/human.h
+++ b/lib/human.h
@@ -1,7 +1,7 @@
/* human.h -- print human readable file size
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006 Free Software Foundation, Inc.
+ 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
@@ -27,6 +27,8 @@
# include <stdint.h>
# include <unistd.h>
+# include <xstrtol.h>
+
/* A conservative bound on the maximum length of a human-readable string.
The output can be the square of the largest uintmax_t, so double
its size before converting to a bound.
@@ -78,6 +80,6 @@ enum
char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
-int human_options (char const *, bool, uintmax_t *);
+enum strtol_error human_options (char const *, int *, uintmax_t *);
#endif /* HUMAN_H_ */
diff --git a/lib/xstrtol.c b/lib/xstrtol.c
index c4557a0064..d57b3da853 100644
--- a/lib/xstrtol.c
+++ b/lib/xstrtol.c
@@ -1,7 +1,7 @@
/* A more useful interface to strtol.
- Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006
- Free Software Foundation, Inc.
+ 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
@@ -254,7 +254,7 @@ main (int argc, char **argv)
}
else
{
- STRTOL_FATAL_ERROR (argv[i], "arg", s_err);
+ STRTOL_FATAL_ERROR ("arg", argv[i], s_err);
}
}
exit (0);
diff --git a/lib/xstrtol.h b/lib/xstrtol.h
index 475728aa44..4df140c2ef 100644
--- a/lib/xstrtol.h
+++ b/lib/xstrtol.h
@@ -1,6 +1,6 @@
/* A more useful interface to strtol.
- Copyright (C) 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004, 2006
+ 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
@@ -50,7 +50,13 @@ _DECLARE_XSTRTOL (xstrtoul, unsigned long int)
_DECLARE_XSTRTOL (xstrtoimax, intmax_t)
_DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
-# define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
+/* 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. */
+# define _STRTOL_ERROR(Exit_code, Option, Arg, Err) \
do \
{ \
switch ((Err)) \
@@ -59,29 +65,26 @@ _DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
abort (); \
\
case LONGINT_INVALID: \
- error ((Exit_code), 0, gettext ("invalid %s `%s'"), \
- (Argument_type_string), (Str)); \
+ 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 character following %s in `%s'"), \
- (Argument_type_string), (Str)); \
+ gettext ("invalid suffix in %s argument `%s'"), \
+ Option, Arg); \
break; \
\
case LONGINT_OVERFLOW: \
- error ((Exit_code), 0, gettext ("%s `%s' too large"), \
- (Argument_type_string), (Str)); \
+ error (Exit_code, 0, gettext ("%s argument `%s' too large"), \
+ Option, Arg); \
break; \
} \
} \
while (0)
-# define STRTOL_FATAL_ERROR(Str, Argument_type_string, Err) \
- _STRTOL_ERROR (exit_failure, Str, Argument_type_string, Err)
-
-# define STRTOL_FAIL_WARN(Str, Argument_type_string, Err) \
- _STRTOL_ERROR (0, Str, Argument_type_string, Err)
+# define STRTOL_FATAL_ERROR(Option, Arg, Err) \
+ _STRTOL_ERROR (exit_failure, Option, Arg, Err)
#endif /* not XSTRTOL_H_ */
diff --git a/modules/human b/modules/human
index 092253ff53..566b559238 100644
--- a/modules/human
+++ b/modules/human
@@ -8,7 +8,6 @@ lib/human.c
m4/human.m4
Depends-on:
-gettext-h
argmatch
error
intprops