date: make help text more understandable; small shrink
text data bss dec hex filename 799025 641 7380 807046 c5086 busybox_old 799009 641 7380 807030 c5076 busybox_unstripped
This commit is contained in:
parent
92e13c2a11
commit
9ce4ae8142
104
coreutils/date.c
104
coreutils/date.c
@ -39,70 +39,70 @@ static void maybe_set_utc(int opt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
int date_main(int argc, char **argv)
|
int date_main(int argc ATTRIBUTE_UNUSED, char **argv)
|
||||||
{
|
{
|
||||||
time_t tm;
|
|
||||||
struct tm tm_time;
|
struct tm tm_time;
|
||||||
|
time_t tm;
|
||||||
unsigned opt;
|
unsigned opt;
|
||||||
int ifmt = -1;
|
int ifmt = -1;
|
||||||
char *date_str = NULL;
|
char *date_str;
|
||||||
char *date_fmt = NULL;
|
char *fmt_dt2str;
|
||||||
char *filename = NULL;
|
char *fmt_str2dt;
|
||||||
char *isofmt_arg;
|
char *filename;
|
||||||
char *hintfmt_arg;
|
char *isofmt_arg = NULL;
|
||||||
|
|
||||||
opt_complementary = "d--s:s--d"
|
opt_complementary = "d--s:s--d"
|
||||||
USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
|
USE_FEATURE_DATE_ISOFMT(":R--I:I--R");
|
||||||
opt = getopt32(argv, "Rs:ud:r:"
|
opt = getopt32(argv, "Rs:ud:r:"
|
||||||
USE_FEATURE_DATE_ISOFMT("I::D:"),
|
USE_FEATURE_DATE_ISOFMT("I::D:"),
|
||||||
&date_str, &date_str, &filename
|
&date_str, &date_str, &filename
|
||||||
USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &hintfmt_arg));
|
USE_FEATURE_DATE_ISOFMT(, &isofmt_arg, &fmt_str2dt));
|
||||||
|
argv += optind;
|
||||||
maybe_set_utc(opt);
|
maybe_set_utc(opt);
|
||||||
|
|
||||||
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_TIMESPEC)) {
|
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_TIMESPEC)) {
|
||||||
if (!isofmt_arg) {
|
ifmt = 0; /* default is date */
|
||||||
ifmt = 0; /* default is date */
|
if (isofmt_arg) {
|
||||||
} else {
|
static const char isoformats[] ALIGN1 =
|
||||||
static const char *const isoformats[] = {
|
"date\0""hours\0""minutes\0""seconds\0";
|
||||||
"date", "hours", "minutes", "seconds"
|
ifmt = index_in_strings(isoformats, isofmt_arg);
|
||||||
};
|
if (ifmt < 0)
|
||||||
|
bb_show_usage();
|
||||||
for (ifmt = 0; ifmt < 4; ifmt++)
|
|
||||||
if (!strcmp(isofmt_arg, isoformats[ifmt]))
|
|
||||||
goto found;
|
|
||||||
/* parse error */
|
|
||||||
bb_show_usage();
|
|
||||||
found: ;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX, date_fmt == NULL from this always */
|
fmt_dt2str = NULL;
|
||||||
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+')) {
|
if (argv[0] && argv[0][0] == '+') {
|
||||||
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
fmt_dt2str = &argv[0][1]; /* Skip over the '+' */
|
||||||
} else if (date_str == NULL) {
|
argv++;
|
||||||
|
}
|
||||||
|
if (!(opt & (DATE_OPT_SET | DATE_OPT_DATE))) {
|
||||||
opt |= DATE_OPT_SET;
|
opt |= DATE_OPT_SET;
|
||||||
date_str = argv[optind];
|
date_str = argv[0]; /* can be NULL */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
|
||||||
if (filename) {
|
if (opt & DATE_OPT_REFERENCE) {
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
xstat(filename, &statbuf);
|
xstat(filename, &statbuf);
|
||||||
tm = statbuf.st_mtime;
|
tm = statbuf.st_mtime;
|
||||||
} else
|
} else
|
||||||
time(&tm);
|
time(&tm);
|
||||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||||
/* Zero out fields - take her back to midnight! */
|
|
||||||
|
/* If date string is given, update tm_time, and maybe set date */
|
||||||
if (date_str != NULL) {
|
if (date_str != NULL) {
|
||||||
|
/* Zero out fields - take her back to midnight! */
|
||||||
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 (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_HINT)) {
|
if (ENABLE_FEATURE_DATE_ISOFMT && (opt & DATE_OPT_HINT)) {
|
||||||
strptime(date_str, hintfmt_arg, &tm_time);
|
if (strptime(date_str, fmt_str2dt, &tm_time) == NULL)
|
||||||
|
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||||
} else if (strchr(date_str, ':') != NULL) {
|
} else if (strchr(date_str, ':') != NULL) {
|
||||||
/* Parse input and assign appropriately to tm_time */
|
/* Parse input and assign appropriately to tm_time */
|
||||||
|
|
||||||
@ -181,55 +181,53 @@ int date_main(int argc, char **argv)
|
|||||||
/* Display output */
|
/* Display output */
|
||||||
|
|
||||||
/* Deal with format string */
|
/* Deal with format string */
|
||||||
|
if (fmt_dt2str == NULL) {
|
||||||
if (date_fmt == NULL) {
|
|
||||||
int i;
|
int i;
|
||||||
date_fmt = xzalloc(32);
|
fmt_dt2str = xzalloc(32);
|
||||||
if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) {
|
if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) {
|
||||||
strcpy(date_fmt, "%Y-%m-%d");
|
strcpy(fmt_dt2str, "%Y-%m-%d");
|
||||||
if (ifmt > 0) {
|
if (ifmt > 0) {
|
||||||
i = 8;
|
i = 8;
|
||||||
date_fmt[i++] = 'T';
|
fmt_dt2str[i++] = 'T';
|
||||||
date_fmt[i++] = '%';
|
fmt_dt2str[i++] = '%';
|
||||||
date_fmt[i++] = 'H';
|
fmt_dt2str[i++] = 'H';
|
||||||
if (ifmt > 1) {
|
if (ifmt > 1) {
|
||||||
date_fmt[i++] = ':';
|
fmt_dt2str[i++] = ':';
|
||||||
date_fmt[i++] = '%';
|
fmt_dt2str[i++] = '%';
|
||||||
date_fmt[i++] = 'M';
|
fmt_dt2str[i++] = 'M';
|
||||||
}
|
if (ifmt > 2) {
|
||||||
if (ifmt > 2) {
|
fmt_dt2str[i++] = ':';
|
||||||
date_fmt[i++] = ':';
|
fmt_dt2str[i++] = '%';
|
||||||
date_fmt[i++] = '%';
|
fmt_dt2str[i++] = 'S';
|
||||||
date_fmt[i++] = 'S';
|
}
|
||||||
}
|
}
|
||||||
format_utc:
|
format_utc:
|
||||||
date_fmt[i++] = '%';
|
fmt_dt2str[i++] = '%';
|
||||||
date_fmt[i] = (opt & DATE_OPT_UTC) ? 'Z' : 'z';
|
fmt_dt2str[i] = (opt & DATE_OPT_UTC) ? 'Z' : 'z';
|
||||||
}
|
}
|
||||||
} else if (opt & DATE_OPT_RFC2822) {
|
} else if (opt & DATE_OPT_RFC2822) {
|
||||||
/* Undo busybox.c for date -R */
|
/* Undo busybox.c for date -R */
|
||||||
if (ENABLE_LOCALE_SUPPORT)
|
if (ENABLE_LOCALE_SUPPORT)
|
||||||
setlocale(LC_TIME, "C");
|
setlocale(LC_TIME, "C");
|
||||||
strcpy(date_fmt, "%a, %d %b %Y %H:%M:%S ");
|
strcpy(fmt_dt2str, "%a, %d %b %Y %H:%M:%S ");
|
||||||
i = 22;
|
i = 22;
|
||||||
goto format_utc;
|
goto format_utc;
|
||||||
} else /* default case */
|
} else /* default case */
|
||||||
date_fmt = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
||||||
}
|
}
|
||||||
|
|
||||||
#define date_buf bb_common_bufsiz1
|
#define date_buf bb_common_bufsiz1
|
||||||
if (*date_fmt == '\0') {
|
if (*fmt_dt2str == '\0') {
|
||||||
/* With no format string, just print a blank line */
|
/* With no format string, just print a blank line */
|
||||||
date_buf[0] = '\0';
|
date_buf[0] = '\0';
|
||||||
} else {
|
} else {
|
||||||
/* Handle special conversions */
|
/* Handle special conversions */
|
||||||
|
if (strncmp(fmt_dt2str, "%f", 2) == 0) {
|
||||||
if (strncmp(date_fmt, "%f", 2) == 0) {
|
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||||
date_fmt = (char*)"%Y.%m.%d-%H:%M:%S";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate output string */
|
/* Generate output string */
|
||||||
strftime(date_buf, sizeof(date_buf), date_fmt, &tm_time);
|
strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time);
|
||||||
}
|
}
|
||||||
puts(date_buf);
|
puts(date_buf);
|
||||||
|
|
||||||
|
@ -558,22 +558,30 @@
|
|||||||
"world\n"
|
"world\n"
|
||||||
|
|
||||||
#define date_trivial_usage \
|
#define date_trivial_usage \
|
||||||
"[OPTION]... [MMDDhhmm[[CC]YY][.ss]] [+FORMAT]"
|
"[OPTION]... [+FMT] [TIME]"
|
||||||
#define date_full_usage \
|
#define date_full_usage \
|
||||||
"Display current time in the given FORMAT, or set system date\n" \
|
"Display time (using +FMT), or set time\n" \
|
||||||
"\nOptions:" \
|
"\nOptions:" \
|
||||||
|
"\n -u Work in UTC (don't convert to local time)" \
|
||||||
"\n -R Output RFC-822 compliant date string" \
|
"\n -R Output RFC-822 compliant date string" \
|
||||||
"\n -d STRING Display time described by STRING, not 'now'" \
|
|
||||||
USE_FEATURE_DATE_ISOFMT( \
|
USE_FEATURE_DATE_ISOFMT( \
|
||||||
"\n -I[TIMESPEC] Output an ISO-8601 compliant date/time string" \
|
"\n -I[SPEC] Output ISO-8601 compliant date string" \
|
||||||
"\n TIMESPEC='date' (or missing) for date only," \
|
"\n SPEC='date' (default) for date only," \
|
||||||
"\n 'hours', 'minutes', or 'seconds' for date and" \
|
"\n 'hours', 'minutes', or 'seconds' for date and" \
|
||||||
"\n time to the indicated precision" \
|
"\n time to the indicated precision" \
|
||||||
"\n -D hint Use 'hint' as date format, via strptime()" \
|
|
||||||
) \
|
) \
|
||||||
"\n -s STRING Set time described by STRING" \
|
"\n -d TIME Display TIME, not 'now'" \
|
||||||
"\n -r FILE Display the last modification time of FILE" \
|
"\n -r FILE Display last modification time of FILE" \
|
||||||
"\n -u Print or sets Coordinated Universal Time" \
|
"\n [-s] TIME Set time to TIME" \
|
||||||
|
USE_FEATURE_DATE_ISOFMT( \
|
||||||
|
"\n -D FMT Use FMT for str->date conversion" \
|
||||||
|
) \
|
||||||
|
"\n" \
|
||||||
|
"\nRecognized formats for TIME:" \
|
||||||
|
"\n [hh:]mm:ss" \
|
||||||
|
"\n mon.day-hh:mm[:ss]" \
|
||||||
|
"\n year.mon.day-hh:mm[:ss]" \
|
||||||
|
"\n MMDDhhmm[[YY]YY][.ss]" \
|
||||||
|
|
||||||
#define date_example_usage \
|
#define date_example_usage \
|
||||||
"$ date\n" \
|
"$ date\n" \
|
||||||
|
Loading…
Reference in New Issue
Block a user