Run through indent, fix comments
This commit is contained in:
parent
a199b17253
commit
03195fc16f
120
coreutils/date.c
120
coreutils/date.c
@ -48,19 +48,18 @@ static struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
{
|
||||
int nr;
|
||||
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
||||
&(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday),
|
||||
&(tm_time->tm_hour),
|
||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d", &(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday), &(tm_time->tm_hour), &(tm_time->tm_min),
|
||||
&(tm_time->tm_year));
|
||||
|
||||
if (nr < 4 || nr > 5) {
|
||||
error_msg_and_die(invalid_date, t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if (tm_time->tm_year >= 1900)
|
||||
if (tm_time->tm_year >= 1900) {
|
||||
tm_time->tm_year -= 1900;
|
||||
}
|
||||
/* adjust date */
|
||||
tm_time->tm_mon -= 1;
|
||||
|
||||
@ -77,48 +76,37 @@ static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if (t=*tm_time,sscanf(t_string, "%d:%d:%d",
|
||||
&t.tm_hour, &t.tm_min, &t.tm_sec) == 3) {
|
||||
if (t =
|
||||
*tm_time, sscanf(t_string, "%d:%d:%d", &t.tm_hour, &t.tm_min,
|
||||
&t.tm_sec) == 3) {
|
||||
/* no adjustments needed */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d:%d",
|
||||
&t.tm_hour, &t.tm_min) == 2) {
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d:%d", &t.tm_hour,
|
||||
&t.tm_min) == 2) {
|
||||
/* no adjustments needed */
|
||||
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d:%d",
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour,
|
||||
&t.tm_min, &t.tm_sec) == 5) {
|
||||
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d",
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour, &t.tm_min) == 4) {
|
||||
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d:%d",
|
||||
&t.tm_year,
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour,
|
||||
&t.tm_min, &t.tm_sec) == 6) {
|
||||
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d.%d-%d:%d:%d", &t.tm_mon,
|
||||
&t.tm_mday, &t.tm_hour, &t.tm_min,
|
||||
&t.tm_sec) == 5) {
|
||||
/* Adjust dates from 1-12 to 0-11 */
|
||||
t.tm_mon -= 1;
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d.%d-%d:%d", &t.tm_mon,
|
||||
&t.tm_mday, &t.tm_hour, &t.tm_min) == 4) {
|
||||
/* Adjust dates from 1-12 to 0-11 */
|
||||
t.tm_mon -= 1;
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d.%d.%d-%d:%d:%d", &t.tm_year,
|
||||
&t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min,
|
||||
&t.tm_sec) == 6) {
|
||||
t.tm_year -= 1900; /* Adjust years */
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d",
|
||||
&t.tm_year,
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour, &t.tm_min) == 5) {
|
||||
} else if (t =
|
||||
*tm_time, sscanf(t_string, "%d.%d.%d-%d:%d", &t.tm_year,
|
||||
&t.tm_mon, &t.tm_mday, &t.tm_hour,
|
||||
&t.tm_min) == 5) {
|
||||
t.tm_year -= 1900; /* Adjust years */
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else {
|
||||
error_msg_and_die(invalid_date, t_string);
|
||||
}
|
||||
@ -142,6 +130,7 @@ int date_main(int argc, char **argv)
|
||||
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
int ifmt = 0;
|
||||
|
||||
# define GETOPT_ISOFMT "I::"
|
||||
#else
|
||||
# define GETOPT_ISOFMT
|
||||
@ -176,17 +165,23 @@ int date_main(int argc, char **argv)
|
||||
else {
|
||||
int ifmt_len = xstrlen(optarg);
|
||||
|
||||
if (( ifmt_len <= 4 ) && ( strncmp ( optarg, "date", ifmt_len ) == 0 ))
|
||||
if ((ifmt_len <= 4)
|
||||
&& (strncmp(optarg, "date", ifmt_len) == 0)) {
|
||||
ifmt = 1;
|
||||
else if (( ifmt_len <= 5 ) && ( strncmp ( optarg, "hours", ifmt_len ) == 0 ))
|
||||
} else if ((ifmt_len <= 5)
|
||||
&& (strncmp(optarg, "hours", ifmt_len) == 0)) {
|
||||
ifmt = 2;
|
||||
else if (( ifmt_len <= 7 ) && ( strncmp ( optarg, "minutes", ifmt_len ) == 0 ))
|
||||
} else if ((ifmt_len <= 7)
|
||||
&& (strncmp(optarg, "minutes", ifmt_len) == 0)) {
|
||||
ifmt = 3;
|
||||
else if (( ifmt_len <= 7 ) && ( strncmp ( optarg, "seconds", ifmt_len ) == 0 ))
|
||||
} else if ((ifmt_len <= 7)
|
||||
&& (strncmp(optarg, "seconds", ifmt_len) == 0)) {
|
||||
ifmt = 4;
|
||||
}
|
||||
if ( ifmt )
|
||||
break; // else show_usage();
|
||||
}
|
||||
if (ifmt) {
|
||||
break; /* else show_usage(); */
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
show_usage();
|
||||
@ -194,18 +189,12 @@ int date_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
|
||||
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 '+' */
|
||||
else if (date_str == NULL) {
|
||||
} else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = argv[optind];
|
||||
}
|
||||
#if 0
|
||||
else {
|
||||
error_msg("date_str='%s' date_fmt='%s'\n", date_str, date_fmt);
|
||||
show_usage();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
@ -230,20 +219,18 @@ int date_main(int argc, char **argv)
|
||||
|
||||
/* Correct any day of week and day of year etc. fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0)
|
||||
if (tm < 0) {
|
||||
error_msg_and_die(invalid_date, date_str);
|
||||
if ( utc ) {
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
}
|
||||
if (utc && (putenv("TZ=UTC0") != 0)) {
|
||||
error_msg_and_die(memory_exhausted);
|
||||
}
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
if (set_time && (stime(&tm) < 0)) {
|
||||
perror_msg("cannot set date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display output */
|
||||
|
||||
@ -266,11 +253,10 @@ int date_main(int argc, char **argv)
|
||||
case 0:
|
||||
default:
|
||||
#endif
|
||||
date_fmt = (rfc822
|
||||
? (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");
|
||||
date_fmt =
|
||||
(rfc822
|
||||
? (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");
|
||||
|
||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user