* 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 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+.
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
/* 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
#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
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;
}
/* 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
# 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.
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_ */
/* 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
}
else
{
- STRTOL_FATAL_ERROR (argv[i], "arg", s_err);
+ STRTOL_FATAL_ERROR ("arg", argv[i], s_err);
}
}
exit (0);
/* 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
_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)) \
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_ */
m4/human.m4
Depends-on:
-gettext-h
argmatch
error
intprops