- /* Interpret command line args */
- while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) {
- switch (c) {
- case 'R':
- rfc822 = 1;
- break;
- case 's':
- set_time = 1;
- if ((date_str != NULL) || ((date_str = optarg) == NULL)) {
- usage(date_usage);
- }
- break;
- case 'u':
- utc = 1;
- if (putenv("TZ=UTC0") != 0)
- error_msg_and_die(memory_exhausted);
- break;
- case 'd':
- use_arg = 1;
- if ((date_str != NULL) || ((date_str = optarg) == NULL))
- usage(date_usage);
- break;
- default:
- usage(date_usage);
+# define GETOPT_ISOFMT "I::"
+#else
+# define GETOPT_ISOFMT
+#endif
+ bb_opt_complementaly = "d~ds:s~ds";
+ opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT,
+ &date_str, &date_str, &filename
+#ifdef CONFIG_FEATURE_DATE_ISOFMT
+ , &isofmt_arg
+#endif
+ );
+ set_time = opt & DATE_OPT_SET;
+ utc = opt & DATE_OPT_UTC;
+ if ((utc) && (putenv("TZ=UTC0") != 0)) {
+ bb_error_msg_and_die(bb_msg_memory_exhausted);
+ }
+ use_arg = opt & DATE_OPT_DATE;
+ if(opt & BB_GETOPT_ERROR)
+ bb_show_usage();
+#ifdef CONFIG_FEATURE_DATE_ISOFMT
+ if(opt & DATE_OPT_TIMESPEC) {
+ if (!isofmt_arg) {
+ ifmt = 1;
+ } else {
+ int ifmt_len = bb_strlen(isofmt_arg);
+
+ if ((ifmt_len <= 4)
+ && (strncmp(isofmt_arg, "date", ifmt_len) == 0)) {
+ ifmt = 1;
+ } else if ((ifmt_len <= 5)
+ && (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) {
+ ifmt = 2;
+ } else if ((ifmt_len <= 7)
+ && (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) {
+ ifmt = 3;
+ } else if ((ifmt_len <= 7)
+ && (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) {
+ ifmt = 4;
+ }
+ }
+ if (!ifmt) {
+ bb_show_usage();