define option names to be clearer, simplify nested if statements, remove

un-needed if statement, minor indenting change
This commit is contained in:
Glenn L McGrath 2004-02-17 07:51:31 +00:00
parent 7e8f41cb5b
commit 5f11541bd4

View File

@ -114,6 +114,11 @@ static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
return (tm_time); return (tm_time);
} }
#define DATE_OPT_RFC2822 0x01
#define DATE_OPT_SET 0x02
#define DATE_OPT_UTC 0x04
#define DATE_OPT_DATE 0x08
#define DATE_OPT_REFERENCE 0x10
int date_main(int argc, char **argv) int date_main(int argc, char **argv)
{ {
@ -121,7 +126,6 @@ int date_main(int argc, char **argv)
char *date_fmt = NULL; char *date_fmt = NULL;
char *t_buff; char *t_buff;
int set_time; int set_time;
int rfc822;
int utc; int utc;
int use_arg = 0; int use_arg = 0;
time_t tm; time_t tm;
@ -143,21 +147,19 @@ int date_main(int argc, char **argv)
, &isofmt_arg , &isofmt_arg
#endif #endif
); );
rfc822 = opt & 1; set_time = opt & DATE_OPT_SET;
set_time = opt & 2; utc = opt & DATE_OPT_UTC;
utc = opt & 4; if ((utc) && (putenv("TZ=UTC0") != 0)) {
if(utc) {
if (putenv("TZ=UTC0") != 0)
bb_error_msg_and_die(bb_msg_memory_exhausted); bb_error_msg_and_die(bb_msg_memory_exhausted);
} }
use_arg = opt & 8; use_arg = opt & DATE_OPT_DATE;
if(opt & 0x80000000UL) if(opt & 0x80000000UL)
bb_show_usage(); bb_show_usage();
#ifdef CONFIG_FEATURE_DATE_ISOFMT #ifdef CONFIG_FEATURE_DATE_ISOFMT
if(opt & 16) { if(opt & DATE_OPT_REFERENCE) {
if (!isofmt_arg) if (!isofmt_arg) {
ifmt = 1; ifmt = 1;
else { } else {
int ifmt_len = bb_strlen(isofmt_arg); int ifmt_len = bb_strlen(isofmt_arg);
if ((ifmt_len <= 4) if ((ifmt_len <= 4)
@ -197,11 +199,8 @@ int date_main(int argc, char **argv)
tm_time.tm_sec = 0; tm_time.tm_sec = 0;
tm_time.tm_min = 0; tm_time.tm_min = 0;
tm_time.tm_hour = 0; tm_time.tm_hour = 0;
}
/* Process any date input to UNIX time since 1 Jan 1970 */ /* Process any date input to UNIX time since 1 Jan 1970 */
if (date_str != NULL) {
if (strchr(date_str, ':') != NULL) { if (strchr(date_str, ':') != NULL) {
date_conv_ftime(&tm_time, date_str); date_conv_ftime(&tm_time, date_str);
} else { } else {
@ -246,7 +245,7 @@ int date_main(int argc, char **argv)
default: default:
#endif #endif
date_fmt = date_fmt =
(rfc822 (opt & DATE_OPT_RFC2822
? (utc ? "%a, %e %b %Y %H:%M:%S GMT" : ? (utc ? "%a, %e %b %Y %H:%M:%S GMT" :
"%a, %e %b %Y %H:%M:%S %z") : "%a %b %e %H:%M:%S %Z %Y"); "%a, %e %b %Y %H:%M:%S %z") : "%a %b %e %H:%M:%S %Z %Y");