diff options
author | Jim Meyering <jim@meyering.net> | 2002-02-11 22:58:59 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2002-02-11 22:58:59 +0000 |
commit | d614857d034cb01e21bc3a10d8fc2426b7f1df4a (patch) | |
tree | 8fbdc111692d2267751c0848e2a84fb65ace6980 /src | |
parent | 8abf13fa9460dd07e310833a6162547922acf0c9 (diff) | |
download | coreutils-d614857d034cb01e21bc3a10d8fc2426b7f1df4a.tar.xz |
Add more support for POSIX 1003.1-2001, which requires removal
for support of obsolete "-DIGITS" option syntax in nice, and
which prohibits options with optional arguments like date's
-I option.
(ISO_8601_OPTION): New enum value.
(long_options): Use it.
(short_options): New constant.
(usage): Document the change.
(main): Conform to POSIX 1003.1-2001 if
POSIX2_VERSION says to, otherwise warn of obsolete usage if
OBSOLETE_OPTION_WARNINGS is nonzero and if not POSIXLY_CORRECT.
Diffstat (limited to 'src')
-rw-r--r-- | src/date.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/date.c b/src/date.c index c52a02925..39f8db830 100644 --- a/src/date.c +++ b/src/date.c @@ -79,11 +79,20 @@ static int iso_8601_format = 0; /* If non-zero, display time in RFC-(2)822 format for mail or news. */ static int rfc_format = 0; +/* For long options that have no equivalent short option, use a + non-character as a pseudo short option, starting with CHAR_MAX + 1. */ +enum +{ + ISO_8601_OPTION = CHAR_MAX + 1 +}; + +static char const short_options[] = "d:f:I" OPTARG_POSIX "r:Rs:u"; + static struct option const long_options[] = { {"date", required_argument, NULL, 'd'}, {"file", required_argument, NULL, 'f'}, - {"iso-8601", optional_argument, NULL, 'I'}, + {"iso-8601", optional_argument, NULL, ISO_8601_OPTION}, {"reference", required_argument, NULL, 'r'}, {"rfc-822", no_argument, NULL, 'R'}, {"set", required_argument, NULL, 's'}, @@ -125,7 +134,17 @@ Display the current time in the given FORMAT, or set the system date.\n\ \n\ -d, --date=STRING display time described by STRING, not `now'\n\ -f, --file=DATEFILE like --date once for each line of DATEFILE\n\ - -I, --iso-8601[=TIMESPEC] output an ISO-8601 compliant date/time string.\n\ +"), stdout); + if (POSIX2_VERSION < 200112) + fputs (_("\ + -ITIMESPEC, --iso-8601[=TIMESPEC] output date/time in ISO 8601 format.\n\ + -I (obsolete) same as -Idate\n\ +"), stdout); + else + fputs (_("\ + -I TIMESPEC, --iso-8601[=TIMESPEC] output date/time in ISO 8601 format.\n\ +"), stdout); + fputs(_("\ TIMESPEC=`date' (or missing) for date only,\n\ `hours', `minutes', or `seconds' for date and\n\ time to the indicated precision.\n\ @@ -305,7 +324,7 @@ main (int argc, char **argv) close_stdout_set_status (2); atexit (close_stdout); - while ((optc = getopt_long (argc, argv, "d:f:I::r:Rs:u", long_options, NULL)) + while ((optc = getopt_long (argc, argv, short_options, long_options, NULL)) != -1) switch (optc) { @@ -318,6 +337,12 @@ main (int argc, char **argv) batch_file = optarg; break; case 'I': + if (POSIX2_VERSION < 200112 && OBSOLETE_OPTION_WARNINGS + && ! optarg && ! getenv ("POSIXLY_CORRECT")) + error (0, 0, + _("warning: `-I' option is obsolete; use `--iso-8601'")); + /* Fall through. */ + case ISO_8601_OPTION: iso_8601_format = (optarg ? XARGMATCH ("--iso-8601", optarg, time_spec_string, time_spec) |