summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2007-08-11 08:30:43 +0200
committerJim Meyering <jim@meyering.net>2007-08-11 08:32:50 +0200
commited31c612c12e603ce86073952018bf7f00f9cd59 (patch)
tree6b4a11c2f0f491d53127516d9e01fb1914fa9f76 /src
parentd243c0e840138cc5d8bf67c9d2a785bdbd74a8d9 (diff)
downloadcoreutils-ed31c612c12e603ce86073952018bf7f00f9cd59.tar.xz
Accommodate more xstrtol changes.
* src/df.c (long_options): Don't bother prepending "--" to long options that OPT_STR might decode, as that hack is no longer needed. (main): Invoke xstrtol_fatal rather than STRTOL_FATAL_ERROR. * src/du.c (long_options, main): Likewise. * src/ls.c (decode_switches): Likewise. * src/od.c (long_options, main): Likewise. * src/pr.c (first_last_page, main): Likewise. * src/sort.c (long_options, specify_sort_size): Likewise. * src/pr.c (first_last_page): Accept option index and option char instead of an assembled option string. All callers changed. * src/sort.c (specify_sort_size): Likewise. * src/system.h (OPT_STR, LONG_OPT_STR, short_opt_str, OPT_STR_INIT): Remove.
Diffstat (limited to 'src')
-rw-r--r--src/df.c4
-rw-r--r--src/du.c4
-rw-r--r--src/ls.c14
-rw-r--r--src/od.c18
-rw-r--r--src/pr.c19
-rw-r--r--src/sort.c8
-rw-r--r--src/system.h25
7 files changed, 36 insertions, 56 deletions
diff --git a/src/df.c b/src/df.c
index c2d1180b7..94cf330b5 100644
--- a/src/df.c
+++ b/src/df.c
@@ -121,7 +121,7 @@ enum
static struct option const long_options[] =
{
{"all", no_argument, NULL, 'a'},
- {OPT_STR_INIT ("block-size"), required_argument, NULL, 'B'},
+ {"block-size", required_argument, NULL, 'B'},
{"inodes", no_argument, NULL, 'i'},
{"human-readable", no_argument, NULL, 'h'},
{"si", no_argument, NULL, 'H'},
@@ -815,7 +815,7 @@ main (int argc, char **argv)
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);
+ xstrtol_fatal (e, oi, c, long_options, optarg);
}
break;
case 'i':
diff --git a/src/du.c b/src/du.c
index caacbb0bd..668107993 100644
--- a/src/du.c
+++ b/src/du.c
@@ -204,7 +204,7 @@ static struct option const long_options[] =
{
{"all", no_argument, NULL, 'a'},
{"apparent-size", no_argument, NULL, APPARENT_SIZE_OPTION},
- {OPT_STR_INIT ("block-size"), required_argument, NULL, 'B'},
+ {"block-size", required_argument, NULL, 'B'},
{"bytes", no_argument, NULL, 'b'},
{"count-links", no_argument, NULL, 'l'},
{"dereference", no_argument, NULL, 'L'},
@@ -796,7 +796,7 @@ main (int argc, char **argv)
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);
+ xstrtol_fatal (e, oi, c, long_options, optarg);
}
break;
diff --git a/src/ls.c b/src/ls.c
index 064a51f74..c6a15f60d 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1375,7 +1375,6 @@ main (int argc, char **argv)
static int
decode_switches (int argc, char **argv)
{
- int c;
char *time_style_option = NULL;
/* Record whether there is an option specifying sort type. */
@@ -1506,10 +1505,15 @@ decode_switches (int argc, char **argv)
}
}
- while ((c = getopt_long (argc, argv,
- "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ1",
- long_options, NULL)) != -1)
+ for (;;)
{
+ int oi = -1;
+ int c = getopt_long (argc, argv,
+ "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ1",
+ long_options, &oi);
+ if (c == -1)
+ break;
+
switch (c)
{
case 'a':
@@ -1797,7 +1801,7 @@ decode_switches (int argc, char **argv)
enum strtol_error e = human_options (optarg, &human_output_opts,
&output_block_size);
if (e != LONGINT_OK)
- STRTOL_FATAL_ERROR ("--block-size", optarg, e);
+ xstrtol_fatal (e, oi, 0, long_options, optarg);
file_output_block_size = output_block_size;
}
break;
diff --git a/src/od.c b/src/od.c
index 472c513e3..1e77f9208 100644
--- a/src/od.c
+++ b/src/od.c
@@ -281,14 +281,14 @@ enum
static struct option const long_options[] =
{
- {OPT_STR_INIT ("skip-bytes"), required_argument, NULL, 'j'},
+ {"skip-bytes", required_argument, NULL, 'j'},
{"address-radix", required_argument, NULL, 'A'},
- {OPT_STR_INIT ("read-bytes"), required_argument, NULL, 'N'},
+ {"read-bytes", required_argument, NULL, 'N'},
{"format", required_argument, NULL, 't'},
{"output-duplicates", no_argument, NULL, 'v'},
- {OPT_STR_INIT ("strings"), optional_argument, NULL, 'S'},
+ {"strings", optional_argument, NULL, 'S'},
{"traditional", no_argument, NULL, TRADITIONAL_OPTION},
- {OPT_STR_INIT ("width"), optional_argument, NULL, 'w'},
+ {"width", optional_argument, NULL, 'w'},
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
@@ -1655,7 +1655,7 @@ it must be one character from [doxn]"),
modern = true;
s_err = xstrtoumax (optarg, NULL, 0, &n_bytes_to_skip, multipliers);
if (s_err != LONGINT_OK)
- STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg, s_err);
+ xstrtol_fatal (s_err, oi, c, long_options, optarg);
break;
case 'N':
@@ -1665,7 +1665,7 @@ it must be one character from [doxn]"),
s_err = xstrtoumax (optarg, NULL, 0, &max_bytes_to_format,
multipliers);
if (s_err != LONGINT_OK)
- STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg, s_err);
+ xstrtol_fatal (s_err, oi, c, long_options, optarg);
break;
case 'S':
@@ -1676,8 +1676,7 @@ it must be one character from [doxn]"),
{
s_err = xstrtoumax (optarg, NULL, 0, &tmp, multipliers);
if (s_err != LONGINT_OK)
- STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg,
- s_err);
+ xstrtol_fatal (s_err, oi, c, long_options, optarg);
/* The minimum string length may be no larger than SIZE_MAX,
since we may allocate a buffer of this size. */
@@ -1749,8 +1748,7 @@ it must be one character from [doxn]"),
uintmax_t w_tmp;
s_err = xstrtoumax (optarg, NULL, 10, &w_tmp, "");
if (s_err != LONGINT_OK)
- STRTOL_FATAL_ERROR (OPT_STR (oi, c, long_options), optarg,
- s_err);
+ xstrtol_fatal (s_err, oi, c, long_options, optarg);
if (SIZE_MAX < w_tmp)
error (EXIT_FAILURE, 0, _("%s is too large"), optarg);
desired_width = w_tmp;
diff --git a/src/pr.c b/src/pr.c
index 329183b99..1ed79d652 100644
--- a/src/pr.c
+++ b/src/pr.c
@@ -796,14 +796,14 @@ cols_ready_to_print (void)
using option +FIRST_PAGE:LAST_PAGE */
static bool
-first_last_page (char const *option, char const *pages)
+first_last_page (int oi, char c, 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_FATAL_ERROR (option, pages, err);
+ xstrtol_fatal (err, oi, c, long_options, pages);
if (p == pages || !first)
return false;
@@ -813,7 +813,7 @@ first_last_page (char const *option, char const *pages)
char const *p1 = p + 1;
err = xstrtoumax (p1, &p, 10, &last, "");
if (err != LONGINT_OK)
- STRTOL_FATAL_ERROR (option, pages, err);
+ xstrtol_fatal (err, oi, c, long_options, pages);
if (p1 == p || last < first)
return false;
}
@@ -856,7 +856,6 @@ separator_string (const char *optarg_S)
int
main (int argc, char **argv)
{
- int c;
int n_files;
bool old_options = false;
bool old_w = false;
@@ -881,9 +880,13 @@ main (int argc, char **argv)
? xmalloc ((argc - 1) * sizeof (char *))
: NULL);
- while ((c = getopt_long (argc, argv, short_options, long_options, NULL))
- != -1)
+ for (;;)
{
+ int oi = -1;
+ int c = getopt_long (argc, argv, short_options, long_options, &oi);
+ if (c == -1)
+ break;
+
if (ISDIGIT (c))
{
/* Accumulate column-count digits specified via old-style options. */
@@ -902,7 +905,7 @@ main (int argc, char **argv)
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 (-2, '+', optarg + 1)))
file_names[n_files++] = optarg;
break;
@@ -911,7 +914,7 @@ main (int argc, char **argv)
if (! optarg)
error (EXIT_FAILURE, 0,
_("`--pages=FIRST_PAGE[:LAST_PAGE]' missing argument"));
- else if (! first_last_page ("--pages", optarg))
+ else if (! first_last_page (oi, 0, optarg))
error (EXIT_FAILURE, 0, _("Invalid page range %s"),
quote (optarg));
break;
diff --git a/src/sort.c b/src/sort.c
index dc7874a9e..620a4bc7c 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -414,7 +414,7 @@ static struct option const long_options[] =
{"output", required_argument, NULL, 'o'},
{"reverse", no_argument, NULL, 'r'},
{"stable", no_argument, NULL, 's'},
- {OPT_STR_INIT ("buffer-size"), required_argument, NULL, 'S'},
+ {"buffer-size", required_argument, NULL, 'S'},
{"field-separator", required_argument, NULL, 't'},
{"temporary-directory", required_argument, NULL, 'T'},
{"unique", no_argument, NULL, 'u'},
@@ -1032,7 +1032,7 @@ inittables (void)
/* Specify the amount of main memory to use when sorting. */
static void
-specify_sort_size (char const *option, char const *s)
+specify_sort_size (int oi, char c, char const *s)
{
uintmax_t n;
char *suffix;
@@ -1088,7 +1088,7 @@ specify_sort_size (char const *option, char const *s)
e = LONGINT_OVERFLOW;
}
- STRTOL_FATAL_ERROR (option, s, e);
+ xstrtol_fatal (e, oi, c, long_options, s);
}
/* Return the default sort size. */
@@ -3012,7 +3012,7 @@ main (int argc, char **argv)
break;
case 'S':
- specify_sort_size (OPT_STR (oi, c, long_options), optarg);
+ specify_sort_size (oi, c, optarg);
break;
case 't':
diff --git a/src/system.h b/src/system.h
index dcb13bad0..3c7f49d10 100644
--- a/src/system.h
+++ b/src/system.h
@@ -592,28 +592,3 @@ emit_bug_reporting_address (void)
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_OPTIONS.
- 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. */
-#define OPT_STR(opt_idx, c, long_options) \
- ((opt_idx) < 0 \
- ? short_opt_str (c) \
- : 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)
-
-/* Given the byte, C, return the string "-C" in static storage. */
-static inline char *
-short_opt_str (char c)
-{
- static char opt_str_storage[3] = {'-', 0, 0};
- opt_str_storage[1] = c;
- return opt_str_storage;
-}
-
-/* Define an option string that will be used with OPT_STR or LONG_OPT_STR. */
-#define OPT_STR_INIT(name) ("--" name + 2)