aboutsummaryrefslogtreecommitdiff
path: root/coreutils/date.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-06-20 09:01:58 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-06-20 09:01:58 +0000
commit3b4406c151cabd47b24d309dbbd9c5b19e9d6b33 (patch)
treef67de9320202043aca8ded20fb80d668c3b0c2d8 /coreutils/date.c
parent90e9e2c71f1e3ed8031334106594ef7fa9e0173b (diff)
downloadbusybox-w32-3b4406c151cabd47b24d309dbbd9c5b19e9d6b33.tar.gz
busybox-w32-3b4406c151cabd47b24d309dbbd9c5b19e9d6b33.tar.bz2
busybox-w32-3b4406c151cabd47b24d309dbbd9c5b19e9d6b33.zip
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 git-svn-id: svn://busybox.net/trunk/busybox@6939 69ca8d6d-28ef-0310-b511-8ec308f3f277
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)
120 char *date_str = NULL; 120 char *date_str = NULL;
121 char *date_fmt = NULL; 121 char *date_fmt = NULL;
122 char *t_buff; 122 char *t_buff;
123 int c; 123 int set_time;
124 int set_time = 0; 124 int rfc822;
125 int rfc822 = 0; 125 int utc;
126 int utc = 0;
127 int use_arg = 0; 126 int use_arg = 0;
128 time_t tm; 127 time_t tm;
128 unsigned long opt;
129 struct tm tm_time; 129 struct tm tm_time;
130 130
131#ifdef CONFIG_FEATURE_DATE_ISOFMT 131#ifdef CONFIG_FEATURE_DATE_ISOFMT
132 int ifmt = 0; 132 int ifmt = 0;
133 char *isofmt_arg;
133 134
134# define GETOPT_ISOFMT "I::" 135# define GETOPT_ISOFMT "I::"
135#else 136#else
136# define GETOPT_ISOFMT 137# define GETOPT_ISOFMT
137#endif 138#endif
138 139 bb_opt_complementaly = "d~ds:s~ds";
139 /* Interpret command line args */ 140 opt = bb_getopt_ulflags(argc, argv, "Rs:ud:" GETOPT_ISOFMT,
140 while ((c = getopt(argc, argv, "Rs:ud:" GETOPT_ISOFMT)) != EOF) { 141 &date_str, &date_str
141 switch (c) { 142#ifdef CONFIG_FEATURE_DATE_ISOFMT
142 case 'R': 143 , &isofmt_arg
143 rfc822 = 1; 144#endif
144 break; 145 );
145 case 's': 146 rfc822 = opt & 1;
146 set_time = 1; 147 set_time = opt & 2;
147 if ((date_str != NULL) || ((date_str = optarg) == NULL)) { 148 utc = opt & 4;
148 bb_show_usage(); 149 if(utc) {
149 }
150 break;
151 case 'u':
152 utc = 1;
153 if (putenv("TZ=UTC0") != 0) 150 if (putenv("TZ=UTC0") != 0)
154 bb_error_msg_and_die(bb_msg_memory_exhausted); 151 bb_error_msg_and_die(bb_msg_memory_exhausted);
155 break; 152 }
156 case 'd': 153 use_arg = opt & 8;
157 use_arg = 1; 154 if(opt & 0x80000000UL)
158 if ((date_str != NULL) || ((date_str = optarg) == NULL))
159 bb_show_usage(); 155 bb_show_usage();
160 break;
161#ifdef CONFIG_FEATURE_DATE_ISOFMT 156#ifdef CONFIG_FEATURE_DATE_ISOFMT
162 case 'I': 157 if(opt & 16) {
163 if (!optarg) 158 if (!isofmt_arg)
164 ifmt = 1; 159 ifmt = 1;
165 else { 160 else {
166 int ifmt_len = bb_strlen(optarg); 161 int ifmt_len = bb_strlen(isofmt_arg);
167 162
168 if ((ifmt_len <= 4) 163 if ((ifmt_len <= 4)
169 && (strncmp(optarg, "date", ifmt_len) == 0)) { 164 && (strncmp(isofmt_arg, "date", ifmt_len) == 0)) {
170 ifmt = 1; 165 ifmt = 1;
171 } else if ((ifmt_len <= 5) 166 } else if ((ifmt_len <= 5)
172 && (strncmp(optarg, "hours", ifmt_len) == 0)) { 167 && (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) {
173 ifmt = 2; 168 ifmt = 2;
174 } else if ((ifmt_len <= 7) 169 } else if ((ifmt_len <= 7)
175 && (strncmp(optarg, "minutes", ifmt_len) == 0)) { 170 && (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) {
176 ifmt = 3; 171 ifmt = 3;
177 } else if ((ifmt_len <= 7) 172 } else if ((ifmt_len <= 7)
178 && (strncmp(optarg, "seconds", ifmt_len) == 0)) { 173 && (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) {
179 ifmt = 4; 174 ifmt = 4;
180 } 175 }
181 } 176 }
182 if (ifmt) { 177 if (!ifmt) {
183 break; /* else bb_show_usage(); */
184 }
185#endif
186 default:
187 bb_show_usage(); 178 bb_show_usage();
188 } 179 }
189 } 180 }
190 181#endif
191 182
192 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) { 183 if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
193 date_fmt = &argv[optind][1]; /* Skip over the '+' */ 184 date_fmt = &argv[optind][1]; /* Skip over the '+' */