remove 1 CR, correct strange bb_opt_complementally, add #if 0 and XXX-comment: pleace examine this\!

This commit is contained in:
"Vladimir N. Oleynik" 2005-10-12 14:36:42 +00:00
parent 3ebb895218
commit 3ade65fc04

View File

@ -84,35 +84,31 @@ static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
/* Parse input and assign appropriately to tm_time */ /* Parse input and assign appropriately to tm_time */
if (t = if (t = *tm_time, sscanf(t_string, "%d:%d:%d", &t.tm_hour, &t.tm_min,
*tm_time, sscanf(t_string, "%d:%d:%d", &t.tm_hour, &t.tm_min,
&t.tm_sec) == 3) { &t.tm_sec) == 3) {
/* no adjustments needed */ /* no adjustments needed */
} else if (t = } else if (t = *tm_time, sscanf(t_string, "%d:%d", &t.tm_hour,
*tm_time, sscanf(t_string, "%d:%d", &t.tm_hour,
&t.tm_min) == 2) { &t.tm_min) == 2) {
/* no adjustments needed */ /* no adjustments needed */
} else if (t = } else if (t = *tm_time, sscanf(t_string, "%d.%d-%d:%d:%d", &t.tm_mon,
*tm_time, sscanf(t_string, "%d.%d-%d:%d:%d", &t.tm_mon, &t.tm_mday, &t.tm_hour,
&t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_min, &t.tm_sec) == 5) {
&t.tm_sec) == 5) {
/* Adjust dates from 1-12 to 0-11 */ /* Adjust dates from 1-12 to 0-11 */
t.tm_mon -= 1; t.tm_mon -= 1;
} else if (t = } else if (t = *tm_time, sscanf(t_string, "%d.%d-%d:%d", &t.tm_mon,
*tm_time, sscanf(t_string, "%d.%d-%d:%d", &t.tm_mon, &t.tm_mday,
&t.tm_mday, &t.tm_hour, &t.tm_min) == 4) { &t.tm_hour, &t.tm_min) == 4) {
/* Adjust dates from 1-12 to 0-11 */ /* Adjust dates from 1-12 to 0-11 */
t.tm_mon -= 1; t.tm_mon -= 1;
} else if (t = } else if (t = *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d:%d", &t.tm_year,
*tm_time, sscanf(t_string, "%d.%d.%d-%d:%d:%d", &t.tm_year, &t.tm_mon, &t.tm_mday,
&t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_hour, &t.tm_min,
&t.tm_sec) == 6) { &t.tm_sec) == 6) {
t.tm_year -= 1900; /* Adjust years */ t.tm_year -= 1900; /* Adjust years */
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
} else if (t = } else if (t = *tm_time, sscanf(t_string, "%d.%d.%d-%d:%d", &t.tm_year,
*tm_time, sscanf(t_string, "%d.%d.%d-%d:%d", &t.tm_year, &t.tm_mon, &t.tm_mday,
&t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_hour, &t.tm_min) == 5) {
&t.tm_min) == 5) {
t.tm_year -= 1900; /* Adjust years */ t.tm_year -= 1900; /* Adjust years */
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */ t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
} else { } else {
@ -137,7 +133,9 @@ int date_main(int argc, char **argv)
char *date_fmt = NULL; char *date_fmt = NULL;
int set_time; int set_time;
int utc; int utc;
#if 0
int use_arg = 0; int use_arg = 0;
#endif
time_t tm; time_t tm;
unsigned long opt; unsigned long opt;
struct tm tm_time; struct tm tm_time;
@ -151,7 +149,7 @@ int date_main(int argc, char **argv)
#else #else
# define GETOPT_ISOFMT # define GETOPT_ISOFMT
#endif #endif
bb_opt_complementally = "?d~ds:s~ds"; bb_opt_complementally = "?d~s:s~d";
opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT, opt = bb_getopt_ulflags(argc, argv, "Rs:ud:r:" GETOPT_ISOFMT,
&date_str, &date_str, &filename &date_str, &date_str, &filename
#ifdef CONFIG_FEATURE_DATE_ISOFMT #ifdef CONFIG_FEATURE_DATE_ISOFMT
@ -160,10 +158,12 @@ int date_main(int argc, char **argv)
); );
set_time = opt & DATE_OPT_SET; set_time = opt & DATE_OPT_SET;
utc = opt & DATE_OPT_UTC; utc = opt & DATE_OPT_UTC;
if ((utc) && (putenv("TZ=UTC0") != 0)) { if (utc && putenv("TZ=UTC0") != 0) {
bb_error_msg_and_die(bb_msg_memory_exhausted); bb_error_msg_and_die(bb_msg_memory_exhausted);
} }
#if 0
use_arg = opt & DATE_OPT_DATE; use_arg = opt & DATE_OPT_DATE;
#endif
#ifdef CONFIG_FEATURE_DATE_ISOFMT #ifdef CONFIG_FEATURE_DATE_ISOFMT
if(opt & DATE_OPT_TIMESPEC) { if(opt & DATE_OPT_TIMESPEC) {
if (!isofmt_arg) { if (!isofmt_arg) {
@ -171,17 +171,17 @@ int date_main(int argc, char **argv)
} else { } else {
int ifmt_len = bb_strlen(isofmt_arg); int ifmt_len = bb_strlen(isofmt_arg);
if ((ifmt_len <= 4) if (ifmt_len <= 4
&& (strncmp(isofmt_arg, "date", ifmt_len) == 0)) { && strncmp(isofmt_arg, "date", ifmt_len) == 0) {
ifmt = 1; ifmt = 1;
} else if ((ifmt_len <= 5) } else if (ifmt_len <= 5
&& (strncmp(isofmt_arg, "hours", ifmt_len) == 0)) { && strncmp(isofmt_arg, "hours", ifmt_len) == 0) {
ifmt = 2; ifmt = 2;
} else if ((ifmt_len <= 7) } else if (ifmt_len <= 7
&& (strncmp(isofmt_arg, "minutes", ifmt_len) == 0)) { && strncmp(isofmt_arg, "minutes", ifmt_len) == 0) {
ifmt = 3; ifmt = 3;
} else if ((ifmt_len <= 7) } else if (ifmt_len <= 7
&& (strncmp(isofmt_arg, "seconds", ifmt_len) == 0)) { && strncmp(isofmt_arg, "seconds", ifmt_len) == 0) {
ifmt = 4; ifmt = 4;
} }
} }
@ -191,6 +191,7 @@ int date_main(int argc, char **argv)
} }
#endif #endif
/* XXX, date_fmt == NULL from this always */
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) { if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
date_fmt = &argv[optind][1]; /* Skip over the '+' */ date_fmt = &argv[optind][1]; /* Skip over the '+' */
} else if (date_str == NULL) { } else if (date_str == NULL) {
@ -204,7 +205,7 @@ int date_main(int argc, char **argv)
if(filename) { if(filename) {
struct stat statbuf; struct stat statbuf;
if(stat(filename,&statbuf)) if(stat(filename,&statbuf))
bb_perror_msg_and_die("File '%s' not found.\n",filename); bb_perror_msg_and_die("File '%s' not found.", filename);
tm=statbuf.st_mtime; tm=statbuf.st_mtime;
} else time(&tm); } else time(&tm);
memcpy(&tm_time, localtime(&tm), sizeof(tm_time)); memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
@ -227,12 +228,12 @@ int date_main(int argc, char **argv)
if (tm < 0) { if (tm < 0) {
bb_error_msg_and_die(bb_msg_invalid_date, date_str); bb_error_msg_and_die(bb_msg_invalid_date, date_str);
} }
if (utc && (putenv("TZ=UTC0") != 0)) { if (utc && putenv("TZ=UTC0") != 0) {
bb_error_msg_and_die(bb_msg_memory_exhausted); bb_error_msg_and_die(bb_msg_memory_exhausted);
} }
/* if setting time, set it */ /* if setting time, set it */
if (set_time && (stime(&tm) < 0)) { if (set_time && stime(&tm) < 0) {
bb_perror_msg("cannot set date"); bb_perror_msg("cannot set date");
} }
} }