summaryrefslogtreecommitdiffhomepage
path: root/coreutils/date.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-06-20 09:01:58 +0000
committerEric Andersen <andersen@codepoet.org>2003-06-20 09:01:58 +0000
commit8876fb2f59a0b515b3121d5894933eef88ce566a (patch)
treef67de9320202043aca8ded20fb80d668c3b0c2d8 /coreutils/date.c
parentdfce3536ace2bcd38bdd3731841998ce344d786e (diff)
last_patch89 from vodz:
Manuel, I rewrite bb_getopt_ulflags() function for more universal usage. My version support now: - options with arguments (optional arg as GNU extension also) - complementaly and/or incomplementaly and/or incongruously and/or list options - long_opt (all applets may have long option, add supporting is trivial) This realisation full compatibile from your version. Code size grow 480 bytes, but only coreutils/* over compensate this size after using new function. Last patch reduced over 800 bytes and not full applied to all. "mkdir" and "mv" applets have long_opt now for demonstrate trivial addition support long_opt with usage new bb_getopt_ulflags(). Complementaly and/or incomplementaly and/or incongruously and/or list options logic is not trivial, but new "cut" and "grep" applets using this logic for examples with full demostrating. New "grep" applet reduced over 300 bytes. Mark, Also. I removed bug from "grep" applet. $ echo a b | busybox grep -e a b a b a b But right is printing one only. --w vodz
Diffstat (limited to 'coreutils/date.c')
-rw-r--r--coreutils/date.c65
1 files changed, 28 insertions, 37 deletions
diff --git a/coreutils/date.c b/coreutils/date.c
index afbedb90d..6e7aa1f0c 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -120,74 +120,65 @@ int date_main(int argc, char **argv)
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
- int c;
- int set_time = 0;
- int rfc822 = 0;
- int utc = 0;
+ int set_time;
+ int rfc822;
+ int utc;
int use_arg = 0;
time_t tm;
+ unsigned long opt;
struct tm tm_time;
#ifdef CONFIG_FEATURE_DATE_ISOFMT
int ifmt = 0;
+ char *isofmt_arg;
# define GETOPT_ISOFMT "I::"
#else
# define GETOPT_ISOFMT
#endif
-
- /* Interpret command line args */
- while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT)) != EOF) {
- switch (c) {
- case 'R':
- rfc822 = 1;
- break;
- case 's':
- set_time = 1;
- if ((date_str != NULL) || ((date_str = optarg) == NULL)) {
- bb_show_usage();
- }
- break;
- case 'u':
- utc = 1;
+ bb_opt_complementaly = "d~ds:s~ds";
+ opt = bb_getopt_ulflags(argc, argv, "Rs:ud:" GETOPT_ISOFMT,
+ &date_str, &date_str
+#ifdef CONFIG_FEATURE_DATE_ISOFMT
+ , &isofmt_arg
+#endif
+ );
+ rfc822 = opt & 1;
+ set_time = opt & 2;
+ utc = opt & 4;
+ if(utc) {
if (putenv("TZ=UTC0") != 0)
bb_error_msg_and_die(bb_msg_memory_exhausted);
- break;
- case 'd':
- use_arg = 1;
- if ((date_str != NULL) || ((date_str = optarg) == NULL))
+ }
+ use_arg = opt & 8;
+ if(opt & 0x80000000UL)
bb_show_usage();
- break;
#ifdef CONFIG_FEATURE_DATE_ISOFMT
- case 'I':
- if (!optarg)
+ if(opt & 16) {
+ if (!isofmt_arg)
ifmt = 1;
else {
- int ifmt_len = bb_strlen(optarg);
+ int ifmt_len = bb_strlen(isofmt_arg);
if ((ifmt_len <= 4)
- && (strncmp(optarg, "date", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "date", ifmt_len) == 0)) {
ifmt = 1;
} else if ((ifmt_len <= 5)
- && (strncmp(optarg, "hours", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) {
ifmt = 2;
} else if ((ifmt_len <= 7)
- && (strncmp(optarg, "minutes", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) {
ifmt = 3;
} else if ((ifmt_len <= 7)
- && (strncmp(optarg, "seconds", ifmt_len) == 0)) {
+ && (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) {
ifmt = 4;
}
}
- if (ifmt) {
- break; /* else bb_show_usage(); */
- }
-#endif
- default:
+ if (!ifmt) {
bb_show_usage();
}
}
-
+#endif
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
date_fmt = &argv[optind][1]; /* Skip over the '+' */