[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: xstrtol.h
From: |
Bruno Haible |
Subject: |
Re: xstrtol.h |
Date: |
Thu, 26 Jul 2007 00:48:56 +0200 |
User-agent: |
KMail/1.5.4 |
Hi Jim,
Jim Meyering wrote on Sunday:
> +2007-07-22 Jim Meyering <address@hidden>
> +
> + 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 <address@hidden>
Bruno Haible <address@hidden>
* 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;
}
uu
Description: Text Data
- Re: POTFILES.in updates?, (continued)
- Re: POTFILES.in updates?, Eric Blake, 2007/07/19
- Re: xstrtol.h (was: Re: POTFILES.in updates?), Bruno Haible, 2007/07/21
- Re: xstrtol.h, Jim Meyering, 2007/07/21
- Re: xstrtol.h, Bruno Haible, 2007/07/22
- Re: xstrtol.h, Eric Blake, 2007/07/22
- Re: xstrtol.h, Jim Meyering, 2007/07/22
- Re: xstrtol.h, Ben Pfaff, 2007/07/22
- Re: xstrtol.h, Jim Meyering, 2007/07/22
- Re: xstrtol.h, Jim Meyering, 2007/07/22
- Re: xstrtol.h, Jim Meyering, 2007/07/22
- Re: xstrtol.h,
Bruno Haible <=
- human interface change?!? [Re: xstrtol.h, Jim Meyering, 2007/07/26
- Re: human interface change?!? [Re: xstrtol.h, Bruno Haible, 2007/07/26
- Re: human interface change?!? [Re: xstrtol.h, Jim Meyering, 2007/07/26
Re: POTFILES.in updates?, Eric Blake, 2007/07/19
Re: POTFILES.in updates?, Karl Berry, 2007/07/23