diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2004-02-17 07:51:31 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2004-02-17 07:51:31 +0000 |
commit | 5f11541bd4a38b3191b690c238386b2fb98105ec (patch) | |
tree | 4a6c03544d61ce4b1fd18aa4b7465734fcbe9618 /coreutils/date.c | |
parent | 7e8f41cb5b0da04a3ff14f262ddf1b1016d475cf (diff) | |
download | busybox-w32-5f11541bd4a38b3191b690c238386b2fb98105ec.tar.gz busybox-w32-5f11541bd4a38b3191b690c238386b2fb98105ec.tar.bz2 busybox-w32-5f11541bd4a38b3191b690c238386b2fb98105ec.zip |
define option names to be clearer, simplify nested if statements, remove
un-needed if statement, minor indenting change
Diffstat (limited to 'coreutils/date.c')
-rw-r--r-- | coreutils/date.c | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/coreutils/date.c b/coreutils/date.c index 7d14ec325..46d2e1074 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -114,6 +114,11 @@ static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string) | |||
114 | return (tm_time); | 114 | return (tm_time); |
115 | } | 115 | } |
116 | 116 | ||
117 | #define DATE_OPT_RFC2822 0x01 | ||
118 | #define DATE_OPT_SET 0x02 | ||
119 | #define DATE_OPT_UTC 0x04 | ||
120 | #define DATE_OPT_DATE 0x08 | ||
121 | #define DATE_OPT_REFERENCE 0x10 | ||
117 | 122 | ||
118 | int date_main(int argc, char **argv) | 123 | int date_main(int argc, char **argv) |
119 | { | 124 | { |
@@ -121,7 +126,6 @@ int date_main(int argc, char **argv) | |||
121 | char *date_fmt = NULL; | 126 | char *date_fmt = NULL; |
122 | char *t_buff; | 127 | char *t_buff; |
123 | int set_time; | 128 | int set_time; |
124 | int rfc822; | ||
125 | int utc; | 129 | int utc; |
126 | int use_arg = 0; | 130 | int use_arg = 0; |
127 | time_t tm; | 131 | time_t tm; |
@@ -143,37 +147,35 @@ int date_main(int argc, char **argv) | |||
143 | , &isofmt_arg | 147 | , &isofmt_arg |
144 | #endif | 148 | #endif |
145 | ); | 149 | ); |
146 | rfc822 = opt & 1; | 150 | set_time = opt & DATE_OPT_SET; |
147 | set_time = opt & 2; | 151 | utc = opt & DATE_OPT_UTC; |
148 | utc = opt & 4; | 152 | if ((utc) && (putenv("TZ=UTC0") != 0)) { |
149 | if(utc) { | 153 | bb_error_msg_and_die(bb_msg_memory_exhausted); |
150 | if (putenv("TZ=UTC0") != 0) | ||
151 | bb_error_msg_and_die(bb_msg_memory_exhausted); | ||
152 | } | 154 | } |
153 | use_arg = opt & 8; | 155 | use_arg = opt & DATE_OPT_DATE; |
154 | if(opt & 0x80000000UL) | 156 | if(opt & 0x80000000UL) |
155 | bb_show_usage(); | 157 | bb_show_usage(); |
156 | #ifdef CONFIG_FEATURE_DATE_ISOFMT | 158 | #ifdef CONFIG_FEATURE_DATE_ISOFMT |
157 | if(opt & 16) { | 159 | if(opt & DATE_OPT_REFERENCE) { |
158 | if (!isofmt_arg) | 160 | if (!isofmt_arg) { |
159 | ifmt = 1; | 161 | ifmt = 1; |
160 | else { | 162 | } else { |
161 | int ifmt_len = bb_strlen(isofmt_arg); | 163 | int ifmt_len = bb_strlen(isofmt_arg); |
162 | 164 | ||
163 | if ((ifmt_len <= 4) | 165 | if ((ifmt_len <= 4) |
164 | && (strncmp(isofmt_arg, "date", ifmt_len) == 0)) { | 166 | && (strncmp(isofmt_arg, "date", ifmt_len) == 0)) { |
165 | ifmt = 1; | 167 | ifmt = 1; |
166 | } else if ((ifmt_len <= 5) | 168 | } else if ((ifmt_len <= 5) |
167 | && (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) { | 169 | && (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) { |
168 | ifmt = 2; | 170 | ifmt = 2; |
169 | } else if ((ifmt_len <= 7) | 171 | } else if ((ifmt_len <= 7) |
170 | && (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) { | 172 | && (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) { |
171 | ifmt = 3; | 173 | ifmt = 3; |
172 | } else if ((ifmt_len <= 7) | 174 | } else if ((ifmt_len <= 7) |
173 | && (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) { | 175 | && (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) { |
174 | ifmt = 4; | 176 | ifmt = 4; |
175 | } | ||
176 | } | 177 | } |
178 | } | ||
177 | if (!ifmt) { | 179 | if (!ifmt) { |
178 | bb_show_usage(); | 180 | bb_show_usage(); |
179 | } | 181 | } |
@@ -197,11 +199,8 @@ int date_main(int argc, char **argv) | |||
197 | tm_time.tm_sec = 0; | 199 | tm_time.tm_sec = 0; |
198 | tm_time.tm_min = 0; | 200 | tm_time.tm_min = 0; |
199 | tm_time.tm_hour = 0; | 201 | tm_time.tm_hour = 0; |
200 | } | ||
201 | |||
202 | /* Process any date input to UNIX time since 1 Jan 1970 */ | ||
203 | if (date_str != NULL) { | ||
204 | 202 | ||
203 | /* Process any date input to UNIX time since 1 Jan 1970 */ | ||
205 | if (strchr(date_str, ':') != NULL) { | 204 | if (strchr(date_str, ':') != NULL) { |
206 | date_conv_ftime(&tm_time, date_str); | 205 | date_conv_ftime(&tm_time, date_str); |
207 | } else { | 206 | } else { |
@@ -246,7 +245,7 @@ int date_main(int argc, char **argv) | |||
246 | default: | 245 | default: |
247 | #endif | 246 | #endif |
248 | date_fmt = | 247 | date_fmt = |
249 | (rfc822 | 248 | (opt & DATE_OPT_RFC2822 |
250 | ? (utc ? "%a, %e %b %Y %H:%M:%S GMT" : | 249 | ? (utc ? "%a, %e %b %Y %H:%M:%S GMT" : |
251 | "%a, %e %b %Y %H:%M:%S %z") : "%a %b %e %H:%M:%S %Z %Y"); | 250 | "%a, %e %b %Y %H:%M:%S %z") : "%a %b %e %H:%M:%S %Z %Y"); |
252 | 251 | ||