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;
|
int nr;
|
||||||
|
|
||||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
nr = sscanf(t_string, "%2d%2d%2d%2d%d", &(tm_time->tm_mon),
|
||||||
&(tm_time->tm_mon),
|
&(tm_time->tm_mday), &(tm_time->tm_hour), &(tm_time->tm_min),
|
||||||
&(tm_time->tm_mday),
|
&(tm_time->tm_year));
|
||||||
&(tm_time->tm_hour),
|
|
||||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
|
||||||
|
|
||||||
if (nr < 4 || nr > 5) {
|
if (nr < 4 || nr > 5) {
|
||||||
error_msg_and_die(invalid_date, t_string);
|
error_msg_and_die(invalid_date, t_string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* correct for century - minor Y2K problem here? */
|
/* correct for century - minor Y2K problem here? */
|
||||||
if (tm_time->tm_year >= 1900)
|
if (tm_time->tm_year >= 1900) {
|
||||||
tm_time->tm_year -= 1900;
|
tm_time->tm_year -= 1900;
|
||||||
|
}
|
||||||
/* adjust date */
|
/* adjust date */
|
||||||
tm_time->tm_mon -= 1;
|
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 */
|
/* Parse input and assign appropriately to tm_time */
|
||||||
|
|
||||||
if (t=*tm_time,sscanf(t_string, "%d:%d:%d",
|
if (t =
|
||||||
&t.tm_hour, &t.tm_min, &t.tm_sec) == 3) {
|
*tm_time, sscanf(t_string, "%d:%d:%d", &t.tm_hour, &t.tm_min,
|
||||||
|
&t.tm_sec) == 3) {
|
||||||
/* no adjustments needed */
|
/* no adjustments needed */
|
||||||
|
} else if (t =
|
||||||
} else if (t=*tm_time,sscanf(t_string, "%d:%d",
|
*tm_time, sscanf(t_string, "%d:%d", &t.tm_hour,
|
||||||
&t.tm_hour, &t.tm_min) == 2) {
|
&t.tm_min) == 2) {
|
||||||
/* no adjustments needed */
|
/* no adjustments needed */
|
||||||
|
} else if (t =
|
||||||
|
*tm_time, sscanf(t_string, "%d.%d-%d:%d:%d", &t.tm_mon,
|
||||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d:%d",
|
&t.tm_mday, &t.tm_hour, &t.tm_min,
|
||||||
&t.tm_mon,
|
&t.tm_sec) == 5) {
|
||||||
&t.tm_mday,
|
/* Adjust dates from 1-12 to 0-11 */
|
||||||
&t.tm_hour,
|
t.tm_mon -= 1;
|
||||||
&t.tm_min, &t.tm_sec) == 5) {
|
} else if (t =
|
||||||
|
*tm_time, sscanf(t_string, "%d.%d-%d:%d", &t.tm_mon,
|
||||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
&t.tm_mday, &t.tm_hour, &t.tm_min) == 4) {
|
||||||
|
/* Adjust dates from 1-12 to 0-11 */
|
||||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d",
|
t.tm_mon -= 1;
|
||||||
&t.tm_mon,
|
} else if (t =
|
||||||
&t.tm_mday,
|
*tm_time, sscanf(t_string, "%d.%d.%d-%d:%d:%d", &t.tm_year,
|
||||||
&t.tm_hour, &t.tm_min) == 4) {
|
&t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min,
|
||||||
|
&t.tm_sec) == 6) {
|
||||||
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) {
|
|
||||||
|
|
||||||
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",
|
*tm_time, sscanf(t_string, "%d.%d.%d-%d:%d", &t.tm_year,
|
||||||
&t.tm_year,
|
&t.tm_mon, &t.tm_mday, &t.tm_hour,
|
||||||
&t.tm_mon,
|
&t.tm_min) == 5) {
|
||||||
&t.tm_mday,
|
|
||||||
&t.tm_hour, &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 {
|
||||||
error_msg_and_die(invalid_date, t_string);
|
error_msg_and_die(invalid_date, t_string);
|
||||||
}
|
}
|
||||||
@ -142,6 +130,7 @@ int date_main(int argc, char **argv)
|
|||||||
|
|
||||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||||
int ifmt = 0;
|
int ifmt = 0;
|
||||||
|
|
||||||
# define GETOPT_ISOFMT "I::"
|
# define GETOPT_ISOFMT "I::"
|
||||||
#else
|
#else
|
||||||
# define GETOPT_ISOFMT
|
# define GETOPT_ISOFMT
|
||||||
@ -176,17 +165,23 @@ int date_main(int argc, char **argv)
|
|||||||
else {
|
else {
|
||||||
int ifmt_len = xstrlen(optarg);
|
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;
|
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;
|
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;
|
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;
|
ifmt = 4;
|
||||||
}
|
}
|
||||||
if ( ifmt )
|
}
|
||||||
break; // else show_usage();
|
if (ifmt) {
|
||||||
|
break; /* else show_usage(); */
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
show_usage();
|
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 '+' */
|
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
||||||
else if (date_str == NULL) {
|
} else if (date_str == NULL) {
|
||||||
set_time = 1;
|
set_time = 1;
|
||||||
date_str = argv[optind];
|
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
|
/* Now we have parsed all the information except the date format
|
||||||
which depends on whether the clock is being set or read */
|
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 */
|
/* Correct any day of week and day of year etc. fields */
|
||||||
tm = mktime(&tm_time);
|
tm = mktime(&tm_time);
|
||||||
if (tm < 0)
|
if (tm < 0) {
|
||||||
error_msg_and_die(invalid_date, date_str);
|
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);
|
error_msg_and_die(memory_exhausted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if setting time, set it */
|
/* if setting time, set it */
|
||||||
if (set_time) {
|
if (set_time && (stime(&tm) < 0)) {
|
||||||
if (stime(&tm) < 0) {
|
|
||||||
perror_msg("cannot set date");
|
perror_msg("cannot set date");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* Display output */
|
/* Display output */
|
||||||
|
|
||||||
@ -266,11 +253,10 @@ int date_main(int argc, char **argv)
|
|||||||
case 0:
|
case 0:
|
||||||
default:
|
default:
|
||||||
#endif
|
#endif
|
||||||
date_fmt = (rfc822
|
date_fmt =
|
||||||
? (utc
|
(rfc822
|
||||||
? "%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, %e %b %Y %H:%M:%S %z") : "%a %b %e %H:%M:%S %Z %Y");
|
||||||
: "%a %b %e %H:%M:%S %Z %Y");
|
|
||||||
|
|
||||||
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
#ifdef CONFIG_FEATURE_DATE_ISOFMT
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user