diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2005-04-26 16:41:03 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2005-04-26 16:41:03 +0000 |
commit | cf8a5565cf5b7a8972b22224a32ff8ffb3c8eea9 (patch) | |
tree | c7c11937dc07e0613ccdfdf0888b26ea15ebba9d /src | |
parent | 326343539121ccb118392b2b015e167520c5e123 (diff) | |
download | coreutils-cf8a5565cf5b7a8972b22224a32ff8ffb3c8eea9.tar.xz |
Remove posixver.h and its uses.
(shortopts): New constant. -DIGIT now always takes an optional arg.
(main): Revamp parsing of -DIGIT to let parse_tab_stops handle it.
Don't complain about -DIGIT.
Diffstat (limited to 'src')
-rw-r--r-- | src/expand.c | 76 |
1 files changed, 30 insertions, 46 deletions
diff --git a/src/expand.c b/src/expand.c index 4dcc985b0..4e172364d 100644 --- a/src/expand.c +++ b/src/expand.c @@ -40,7 +40,6 @@ #include <sys/types.h> #include "system.h" #include "error.h" -#include "posixver.h" #include "quote.h" #include "xstrndup.h" @@ -90,6 +89,8 @@ static bool have_read_stdin; /* The desired exit status. */ static int exit_status; +static char const shortopts[] = "it:0::1::2::3::4::5::6::7::8::9::"; + static struct option const longopts[] = { {"tabs", required_argument, NULL, 't'}, @@ -170,18 +171,16 @@ parse_tab_stops (char const *stops) have_tabval = true; num_start = stops; } - { - /* Detect overflow. */ - if (!DECIMAL_DIGIT_ACCUMULATE (tabval, *stops - '0', UINTMAX_MAX)) - { - size_t len = strspn (num_start, "0123456789"); - char *bad_num = xstrndup (num_start, len); - error (0, 0, _("tab stop is too large %s"), quote (bad_num)); - free (bad_num); - ok = false; - stops = num_start + len - 1; - } - } + + if (!DECIMAL_DIGIT_ACCUMULATE (tabval, *stops - '0', UINTMAX_MAX)) + { + size_t len = strspn (num_start, "0123456789"); + char *bad_num = xstrndup (num_start, len); + error (0, 0, _("tab stop is too large %s"), quote (bad_num)); + free (bad_num); + ok = false; + stops = num_start + len - 1; + } } else { @@ -371,12 +370,8 @@ expand (void) int main (int argc, char **argv) { - bool have_tabval = false; - uintmax_t tabval IF_LINT (= 0); int c; - bool obsolete_tablist = false; - initialize_main (&argc, &argv); program_name = argv[0]; setlocale (LC_ALL, ""); @@ -391,51 +386,40 @@ main (int argc, char **argv) tab_list = NULL; first_free_tab = 0; - while ((c = getopt_long (argc, argv, "it:,0123456789", longopts, NULL)) - != -1) + while ((c = getopt_long (argc, argv, shortopts, longopts, NULL)) != -1) { switch (c) { - case '?': - usage (EXIT_FAILURE); case 'i': convert_entire_line = false; break; + case 't': parse_tab_stops (optarg); break; - case ',': - if (have_tabval) - add_tab_stop (tabval); - have_tabval = false; - obsolete_tablist = true; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + if (optarg) + parse_tab_stops (optarg - 1); + else + { + char tab_stop[2]; + tab_stop[0] = c; + tab_stop[1] = '\0'; + parse_tab_stops (tab_stop); + } break; + case_GETOPT_HELP_CHAR; + case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS); + default: - if (!have_tabval) - { - tabval = 0; - have_tabval = true; - } - { - if (!DECIMAL_DIGIT_ACCUMULATE (tabval, c - '0', UINTMAX_MAX)) - error (EXIT_FAILURE, 0, _("tab stop value is too large")); - } - obsolete_tablist = true; - break; + usage (EXIT_FAILURE); } } - if (obsolete_tablist && 200112 <= posix2_version ()) - { - error (0, 0, _("`-LIST' option is obsolete; use `-t LIST'")); - usage (EXIT_FAILURE); - } - - if (have_tabval) - add_tab_stop (tabval); - validate_tab_stops (tab_list, first_free_tab); if (first_free_tab == 0) |