+2007-08-04 Paul Eggert <eggert@cs.ucla.edu>
+
+ Adapt to new human and xstrtol API.
+ * src/df.c (long_options): Prepend "--" to long options that
+ OPT_STR might decode.
+ * src/du.c (long_options): Likewise.
+ * src/od.c (long_options): Likewise.
+ * src/sort.c (long_options): Likewise.
+ * src/df.c (main): Adjust to new human and xstrtol API.
+ * src/du.c (main): Likewise.
+ * src/ls.c (decode_switches): Likewise.
+ * src/od.c (main): Likewise.
+ * src/pr.c (first_last_page): Likewise. New argument OPTION.
+ All callers changed.
+ * src/sort.c (specify_sort_size): New arg OPTION. All callers
+ changed. Adjust to new xstrtol API.
+ * src/system.h (opt_str_storage): New static var.
+ (OPT_STR, LONG_OPT_STR, OPT_STR_INIT): New macros.
+
2007-08-02 Jim Meyering <jim@meyering.net>
Adjust one more test to accommodate the recent fts change.
static struct option const long_options[] =
{
{"all", no_argument, NULL, 'a'},
- {"block-size", required_argument, NULL, 'B'},
+ {OPT_STR_INIT ("block-size"), required_argument, NULL, 'B'},
{"inodes", no_argument, NULL, 'i'},
{"human-readable", no_argument, NULL, 'h'},
{"si", no_argument, NULL, 'H'},
int
main (int argc, char **argv)
{
- int c;
struct stat *stats IF_LINT (= 0);
initialize_main (&argc, &argv);
posix_format = false;
exit_status = EXIT_SUCCESS;
- while ((c = getopt_long (argc, argv, "aB:iF:hHklmPTt:vx:", long_options, NULL))
- != -1)
+ for (;;)
{
+ 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);
+ {
+ enum strtol_error e = human_options (optarg, &human_output_opts,
+ &output_block_size);
+ if (e != LONGINT_OK)
+ STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg, e);
+ }
break;
case 'i':
inode_format = true;
output_block_size = (getenv ("POSIXLY_CORRECT") ? 512 : 1024);
}
else
- human_output_opts = human_options (getenv ("DF_BLOCK_SIZE"), false,
- &output_block_size);
+ human_options (getenv ("DF_BLOCK_SIZE"),
+ &human_output_opts, &output_block_size);
}
/* Fail if the same file system type was both selected and excluded. */
{
{"all", no_argument, NULL, 'a'},
{"apparent-size", no_argument, NULL, APPARENT_SIZE_OPTION},
- {"block-size", required_argument, NULL, 'B'},
+ {OPT_STR_INIT ("block-size"), required_argument, NULL, 'B'},
{"bytes", no_argument, NULL, 'b'},
{"count-links", no_argument, NULL, 'l'},
{"dereference", no_argument, NULL, 'L'},
int
main (int argc, char **argv)
{
- int c;
char *cwd_only[2];
bool max_depth_specified = false;
char **files;
exclude = new_exclude ();
- human_output_opts = human_options (getenv ("DU_BLOCK_SIZE"), false,
- &output_block_size);
+ human_options (getenv ("DU_BLOCK_SIZE"),
+ &human_output_opts, &output_block_size);
- while ((c = getopt_long (argc, argv, DEBUG_OPT "0abchHklmsxB:DLPSX:",
- long_options, NULL)) != -1)
+ for (;;)
{
+ 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
break;
case 'B':
- human_output_opts = human_options (optarg, true, &output_block_size);
+ {
+ enum strtol_error e = human_options (optarg, &human_output_opts,
+ &output_block_size);
+ if (e != LONGINT_OK)
+ STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg, e);
+ }
break;
case 'D': /* This will eventually be 'H' (-H), too. */
{
char const *ls_block_size = getenv ("LS_BLOCK_SIZE");
- human_output_opts = human_options (ls_block_size, false,
- &output_block_size);
+ human_options (ls_block_size,
+ &human_output_opts, &output_block_size);
if (ls_block_size || getenv ("BLOCK_SIZE"))
file_output_block_size = output_block_size;
}
break;
case BLOCK_SIZE_OPTION:
- human_output_opts = human_options (optarg, true, &output_block_size);
- file_output_block_size = output_block_size;
+ {
+ enum strtol_error e = human_options (optarg, &human_output_opts,
+ &output_block_size);
+ if (e != LONGINT_OK)
+ STRTOL_FATAL_ERROR ("--block-size", optarg, e);
+ file_output_block_size = output_block_size;
+ }
break;
case SI_OPTION:
/* od -- dump files in octal and other formats
- Copyright (C) 92, 1995-2006 Free Software Foundation, Inc.
+ Copyright (C) 92, 1995-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
static struct option const long_options[] =
{
- {"skip-bytes", required_argument, NULL, 'j'},
+ {OPT_STR_INIT ("skip-bytes"), required_argument, NULL, 'j'},
{"address-radix", required_argument, NULL, 'A'},
- {"read-bytes", required_argument, NULL, 'N'},
+ {OPT_STR_INIT ("read-bytes"), required_argument, NULL, 'N'},
{"format", required_argument, NULL, 't'},
{"output-duplicates", no_argument, NULL, 'v'},
- {"strings", optional_argument, NULL, 'S'},
+ {OPT_STR_INIT ("strings"), optional_argument, NULL, 'S'},
{"traditional", no_argument, NULL, TRADITIONAL_OPTION},
- {"width", optional_argument, NULL, 'w'},
+ {OPT_STR_INIT ("width"), optional_argument, NULL, 'w'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
int
main (int argc, char **argv)
{
- int c;
int n_files;
size_t i;
int l_c_m;
address_pad_len = 7;
flag_dump_strings = false;
- while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
- != -1)
+ for (;;)
{
uintmax_t tmp;
enum strtol_error s_err;
+ int oi = -1;
+ int c = getopt_long (argc, argv, short_options, long_options, &oi);
+ if (c == -1)
+ break;
switch (c)
{
modern = true;
s_err = xstrtoumax (optarg, NULL, 0, &n_bytes_to_skip, multipliers);
if (s_err != LONGINT_OK)
- STRTOL_FATAL_ERROR (optarg, _("skip argument"), s_err);
+ STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg, s_err);
break;
case 'N':
s_err = xstrtoumax (optarg, NULL, 0, &max_bytes_to_format,
multipliers);
if (s_err != LONGINT_OK)
- STRTOL_FATAL_ERROR (optarg, _("limit argument"), s_err);
+ STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg, s_err);
break;
case 'S':
{
s_err = xstrtoumax (optarg, NULL, 0, &tmp, multipliers);
if (s_err != LONGINT_OK)
- STRTOL_FATAL_ERROR (optarg, _("minimum string length"), s_err);
+ STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg,
+ s_err);
/* The minimum string length may be no larger than SIZE_MAX,
since we may allocate a buffer of this size. */
uintmax_t w_tmp;
s_err = xstrtoumax (optarg, NULL, 10, &w_tmp, "");
if (s_err != LONGINT_OK)
- STRTOL_FATAL_ERROR (optarg, _("width specification"), s_err);
+ STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg,
+ s_err);
if (SIZE_MAX < w_tmp)
error (EXIT_FAILURE, 0, _("%s is too large"), optarg);
desired_width = w_tmp;
using option +FIRST_PAGE:LAST_PAGE */
static bool
-first_last_page (char const *pages)
+first_last_page (char const *option, char const *pages)
{
char *p;
uintmax_t first;
uintmax_t last = UINTMAX_MAX;
strtol_error err = xstrtoumax (pages, &p, 10, &first, "");
if (err != LONGINT_OK && err != LONGINT_INVALID_SUFFIX_CHAR)
- _STRTOL_ERROR (EXIT_FAILURE, pages, _("page range"), err);
+ STRTOL_FATAL_ERROR (option, pages, err);
if (p == pages || !first)
return false;
char const *p1 = p + 1;
err = xstrtoumax (p1, &p, 10, &last, "");
if (err != LONGINT_OK)
- _STRTOL_ERROR (EXIT_FAILURE, pages, _("page range"), err);
+ STRTOL_FATAL_ERROR (option, pages, err);
if (p1 == p || last < first)
return false;
}
case 1: /* Non-option argument. */
/* long option --page dominates old `+FIRST_PAGE ...'. */
if (! (first_page_number == 0
- && *optarg == '+' && first_last_page (optarg + 1)))
+ && *optarg == '+' && first_last_page ("+", optarg + 1)))
file_names[n_files++] = optarg;
break;
if (! optarg)
error (EXIT_FAILURE, 0,
_("`--pages=FIRST_PAGE[:LAST_PAGE]' missing argument"));
- else if (! first_last_page (optarg))
+ else if (! first_last_page ("--pages", optarg))
error (EXIT_FAILURE, 0, _("Invalid page range %s"),
quote (optarg));
break;
{"output", required_argument, NULL, 'o'},
{"reverse", no_argument, NULL, 'r'},
{"stable", no_argument, NULL, 's'},
- {"buffer-size", required_argument, NULL, 'S'},
+ {OPT_STR_INIT ("buffer-size"), required_argument, NULL, 'S'},
{"field-separator", required_argument, NULL, 't'},
{"temporary-directory", required_argument, NULL, 'T'},
{"unique", no_argument, NULL, 'u'},
/* Specify the amount of main memory to use when sorting. */
static void
-specify_sort_size (char const *s)
+specify_sort_size (char const *option, char const *s)
{
uintmax_t n;
char *suffix;
e = LONGINT_OVERFLOW;
}
- STRTOL_FATAL_ERROR (s, _("sort size"), e);
+ STRTOL_FATAL_ERROR (option, s, e);
}
/* Return the default sort size. */
pedantic and a file was seen, unless the POSIX version
predates 1003.1-2001 and -c was not seen and the operand is
"-o FILE" or "-oFILE". */
+ int oi = -1;
if (c == -1
|| (posixly_correct && nfiles != 0
&& argv[optind][0] == '-' && argv[optind][1] == 'o'
&& (argv[optind][2] || optind + 1 != argc)))
|| ((c = getopt_long (argc, argv, short_options,
- long_options, NULL))
+ long_options, &oi))
== -1))
{
if (argc <= optind)
break;
case 'S':
- specify_sort_size (optarg);
+ specify_sort_size (OPT_STR (oi, c, long_options), optarg);
break;
case 't':
bugs (typically your translation team's web or email address). */
printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT);
}
+
+/* Use OPT_IDX to decide whether to return either a short option
+ string "-C", or a long option string derived from LONG_OPTION.
+ OPT_IDX is -1 if the short option C was used; otherwise it is an
+ index into LONG_OPTIONS, which should have a name preceded by two
+ '-' characters. */
+static char opt_str_storage[3] = {'-', 0, 0};
+#define OPT_STR(opt_idx, c, long_options) \
+ ((opt_idx) < 0 \
+ ? (opt_str_storage[1] = c, opt_str_storage) \
+ : LONG_OPT_STR (opt_idx, long_options))
+
+/* Likewise, but assume OPT_IDX is nonnegative. */
+#define LONG_OPT_STR(opt_idx, long_options) ((long_options)[opt_idx].name - 2)
+
+/* Define an option string that will be used with OPT_STR or LONG_OPT_STR. */
+#define OPT_STR_INIT(name) ("--" name + 2)