From 0253ee27eb11b96be8cba141e7e066787b5904c3 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 6 Aug 2007 16:44:24 +0000 Subject: [PATCH] * NEWS: Describe interface changes to human, xstrtol. * lib/human.h: Include . (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 , 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. --- ChangeLog | 24 ++++++++++++++++++++++++ NEWS | 11 +++++++++++ lib/human.c | 17 +++++------------ lib/human.h | 6 ++++-- lib/xstrtol.c | 6 +++--- lib/xstrtol.h | 29 ++++++++++++++++------------- modules/human | 1 - 7 files changed, 63 insertions(+), 31 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd9b2e9c4..342db9f50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2007-08-06 Paul Eggert + and Bruno Haible + + * NEWS: Describe interface changes to human, xstrtol. + * lib/human.h: Include . + (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 , 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 * build-aux/maint.mk, build-aux/GNUmakefile: Relicense to GPLv3+. diff --git a/NEWS b/NEWS index dd230cb50..51c3f0b72 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 ecf4c97ce..592f83075 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 #include -#include "gettext.h" -#define _(msgid) gettext (msgid) - #include #include #include -#include /* 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 44b8b36d5..95fc93004 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 # include +# include + /* 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 c4557a006..d57b3da85 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 475728aa4..4df140c2e 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 092253ff5..566b55923 100644 --- a/modules/human +++ b/modules/human @@ -8,7 +8,6 @@ lib/human.c m4/human.m4 Depends-on: -gettext-h argmatch error intprops -- 2.11.0