Hi Jim,
Jim Meyering wrote on Sunday:
> +2007-07-22 Jim Meyering <[EMAIL PROTECTED]>
> +
> + Make some invalid-integer diagnostics easier to translate properly.
> + * src/system.h (OPT_STR): Define.
> + (opt_str): New function.
> + * src/od.c (main): Declare new local, oi.
> + Set it via the call to getopt_long.
> + Use its value to build the option string we pass to STRTOL_FATAL_ERROR.
> + * src/pr.c (first_last_page): Use the not-translated string, "--pages"
> + in diagnostics about invalid arguments.
> + * src/sort.c (specify_sort_size): Add a parameter. Update callers.
> + (main): Use new macro to pass required string to specify_sort_size.
Looks all fine to me (except that I usually avoid strncpy, because it wastes
time filling in zero bytes).
I am committing your patch to xstrtol.h, with updated variable names and
comments. Also, a corresponding change to the 'human' module. Find attached
the corresponding coreutils change (untested but obvious).
2007-07-25 Jim Meyering <[EMAIL PROTECTED]>
Bruno Haible <[EMAIL PROTECTED]>
* lib/xstrtol.h (_STRTOL_ERROR): Change third argument from a
localized noun to an option name.
(STRTOL_FATAL_ERROR, STRTOL_FAIL_WARN): Likewise.
* lib/human.h (human_options): Insert a third argument.
* lib/human.h (human_options): Likewise. Pass it to STRTOL_FATAL_ERROR.
*** lib/xstrtol.h 19 Oct 2006 07:51:14 -0000 1.22
--- lib/xstrtol.h 25 Jul 2007 22:38:02 -0000
***************
*** 1,6 ****
/* A more useful interface to strtol.
! Copyright (C) 1995, 1996, 1998, 1999, 2001, 2002, 2003, 2004, 2006
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
--- 1,6 ----
/* A more useful interface to strtol.
! Copyright (C) 1995, 1996, 1998, 1999, 2001-2004, 2006-2007
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
***************
*** 50,56 ****
_DECLARE_XSTRTOL (xstrtoimax, intmax_t)
_DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
! # define _STRTOL_ERROR(Exit_code, Str, Argument_type_string, Err) \
do \
{ \
switch ((Err)) \
--- 50,63 ----
_DECLARE_XSTRTOL (xstrtoimax, intmax_t)
_DECLARE_XSTRTOL (xstrtoumax, uintmax_t)
! /* Signal an error for an out-of-range integer argument, through the error()
! function.
! EXIT_CODE is the exit code (0 for a non-fatal error).
! STR is the value of the given argument value.
! OPTION is the option that takes the argument (usually starting with one
! or two minus signs).
! ERR is the error code returned by one of the xstrto* functions. */
! # define _STRTOL_ERROR(Exit_code, Str, Option, Err) \
do \
{ \
switch ((Err)) \
***************
*** 59,87 ****
abort (); \
\
case LONGINT_INVALID: \
! error ((Exit_code), 0, gettext ("invalid %s `%s'"), \
! (Argument_type_string), (Str)); \
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)); \
break; \
\
case LONGINT_OVERFLOW: \
! error ((Exit_code), 0, gettext ("%s `%s' too large"), \
! (Argument_type_string), (Str)); \
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)
#endif /* not XSTRTOL_H_ */
--- 66,94 ----
abort (); \
\
case LONGINT_INVALID: \
! error ((Exit_code), 0, gettext ("invalid %s argument `%s'"), \
! (Option), (Str)); \
break; \
\
case LONGINT_INVALID_SUFFIX_CHAR: \
case LONGINT_INVALID_SUFFIX_CHAR | LONGINT_OVERFLOW: \
error ((Exit_code), 0, \
! gettext ("invalid character following %s argument in `%s'"), \
! (Option), (Str)); \
break; \
\
case LONGINT_OVERFLOW: \
! error ((Exit_code), 0, gettext ("%s argument `%s' too large"), \
! (Option), (Str)); \
break; \
} \
} \
while (0)
! # define STRTOL_FATAL_ERROR(Str, Option, Err) \
! _STRTOL_ERROR (exit_failure, Str, Option, Err)
! # define STRTOL_FAIL_WARN(Str, Option, Err) \
! _STRTOL_ERROR (0, Str, Option, Err)
#endif /* not XSTRTOL_H_ */
*** NEWS 14 Jul 2007 16:25:53 -0000 1.24
--- NEWS 25 Jul 2007 22:38:02 -0000
***************
*** 6,11 ****
--- 6,15 ----
Date Modules Changes
+ 2007-07-26 human The function human_options takes an additional
+ third argument, the option that introduced the
+ argument that was passed to a xstrto* function.
+
2007-07-14 gpl, lgpl New Texinfo versions with no sectioning commands.
2007-07-10 version-etc Output now mentions GPLv3+, not GPLv2+. Use
*** lib/human.h 21 Aug 2006 06:11:26 -0000 1.15
--- lib/human.h 25 Jul 2007 22:38:02 -0000
***************
*** 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.
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
--- 1,7 ----
/* human.h -- print human readable file size
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 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
***************
*** 78,83 ****
char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
! int human_options (char const *, bool, uintmax_t *);
#endif /* HUMAN_H_ */
--- 78,83 ----
char *human_readable (uintmax_t, char *, int, uintmax_t, uintmax_t);
! int human_options (char const *, bool, char const *, uintmax_t *);
#endif /* HUMAN_H_ */
*** lib/human.c 5 Oct 2006 21:23:21 -0000 1.34
--- lib/human.c 25 Jul 2007 22:38:02 -0000
***************
*** 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.
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
--- 1,7 ----
/* human.c -- print human readable file size
Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 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
***************
*** 464,470 ****
}
int
! human_options (char const *spec, bool report_errors, uintmax_t *block_size)
{
int opts;
strtol_error e = humblock (spec, block_size, &opts);
--- 464,471 ----
}
int
! human_options (char const *spec, bool report_errors, char const *option,
! uintmax_t *block_size)
{
int opts;
strtol_error e = humblock (spec, block_size, &opts);
***************
*** 474,479 ****
e = LONGINT_INVALID;
}
if (e != LONGINT_OK && report_errors)
! STRTOL_FATAL_ERROR (spec, _("block size"), e);
return opts;
}
--- 475,480 ----
e = LONGINT_INVALID;
}
if (e != LONGINT_OK && report_errors)
! STRTOL_FATAL_ERROR (spec, option, e);
return opts;
}
diff --git a/src/df.c b/src/df.c
index 41bda87..f4844e7 100644
--- a/src/df.c
+++ b/src/df.c
@@ -798,16 +798,22 @@ main (int argc, char **argv)
posix_format = false;
exit_status = EXIT_SUCCESS;
- while ((c = getopt_long (argc, argv, "aB:iF:hHklmPTt:vx:", long_options, NULL))
- != -1)
+ while (true)
{
+ int oi = -1;
+ int c = getopt_long (argc, argv, "aB:iF:hHklmPTt:vx:", long_options, &oi);
+ if (c == -1)
+ break;
+
switch (c)
{
case 'a':
show_all_fs = true;
break;
case 'B':
- human_output_opts = human_options (optarg, true, &output_block_size);
+ human_output_opts =
+ human_options (optarg, true, OPT_STR (oi, c, long_options),
+ &output_block_size);
break;
case 'i':
inode_format = true;
@@ -874,7 +880,7 @@ main (int argc, char **argv)
}
else
human_output_opts = human_options (getenv ("DF_BLOCK_SIZE"), false,
- &output_block_size);
+ NULL, &output_block_size);
}
/* Fail if the same file system type was both selected and excluded. */
diff --git a/src/du.c b/src/du.c
index 57678d9..cbfbbb5 100644
--- a/src/du.c
+++ b/src/du.c
@@ -697,12 +697,17 @@ main (int argc, char **argv)
exclude = new_exclude ();
- human_output_opts = human_options (getenv ("DU_BLOCK_SIZE"), false,
+ human_output_opts = human_options (getenv ("DU_BLOCK_SIZE"), false, NULL,
&output_block_size);
- while ((c = getopt_long (argc, argv, DEBUG_OPT "0abchHklmsxB:DLPSX:",
- long_options, NULL)) != -1)
+ while (true)
{
+ int oi = -1;
+ int c = getopt_long (argc, argv, DEBUG_OPT "0abchHklmsxB:DLPSX:",
+ long_options, &oi);
+ if (c == -1)
+ break;
+
switch (c)
{
#if DU_DEBUG
@@ -793,7 +798,9 @@ main (int argc, char **argv)
break;
case 'B':
- human_output_opts = human_options (optarg, true, &output_block_size);
+ human_output_opts =
+ human_options (optarg, true, OPT_STR (oi, c, long_options),
+ &output_block_size);
break;
case 'D': /* This will eventually be 'H' (-H), too. */
diff --git a/src/ls.c b/src/ls.c
index ee73622..c29b62a 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1450,7 +1450,7 @@ decode_switches (int argc, char **argv)
{
char const *ls_block_size = getenv ("LS_BLOCK_SIZE");
- human_output_opts = human_options (ls_block_size, false,
+ human_output_opts = human_options (ls_block_size, false, NULL,
&output_block_size);
if (ls_block_size || getenv ("BLOCK_SIZE"))
file_output_block_size = output_block_size;
@@ -1506,10 +1506,15 @@ decode_switches (int argc, char **argv)
}
}
- while ((c = getopt_long (argc, argv,
- "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ1",
- long_options, NULL)) != -1)
+ while (true)
{
+ int oi = -1;
+ int c = getopt_long (argc, argv,
+ "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ1",
+ long_options, &oi);
+ if (c == -1)
+ break;
+
switch (c)
{
case 'a':
@@ -1793,7 +1798,9 @@ decode_switches (int argc, char **argv)
break;
case BLOCK_SIZE_OPTION:
- human_output_opts = human_options (optarg, true, &output_block_size);
+ human_output_opts =
+ human_options (optarg, true, OPT_STR (oi, c, long_options),
+ &output_block_size);
file_output_block_size = output_block_size;
break;