Make the day/month ordering dependent on the current locale by

testing the locale at program startup and setting a flag, then
using that flag to determine appropriate strftime() arguments.
This commit is contained in:
kientzle 2004-07-15 03:14:46 +00:00
parent a27f47d57c
commit 47308fc5b0
4 changed files with 17 additions and 4 deletions

View File

@ -47,6 +47,9 @@ struct option {
#define no_argument 0
#define required_argument 1
#endif
#ifdef HAVE_NL_LANGINFO_D_MD_ORDER
#include <langinfo.h>
#endif
#include <locale.h>
#include <pwd.h>
#include <stdio.h>
@ -163,6 +166,9 @@ main(int argc, char **argv)
if (setlocale(LC_ALL, "") == NULL)
bsdtar_warnc(bsdtar, 0, "Failed to set default locale");
#ifdef HAVE_NL_LANGINFO_D_MD_ORDER
bsdtar->day_first = (*nl_langinfo(D_MD_ORDER) == 'd');
#endif
mode = '\0';
possible_help_request = 0;

View File

@ -63,6 +63,7 @@ struct bsdtar {
char option_stdout; /* -p */
char option_unlink_first; /* -U */
char option_warn_links; /* -l */
char day_first; /* show day before month in -tv output */
/* If >= 0, then close this when done. */
int fd;

View File

@ -43,6 +43,9 @@
#define HAVE_CHFLAGS 1
#define ARCHIVE_STAT_MTIME_NANOS(st) (st)->st_mtimespec.tv_nsec
/* nl_langinfo supports D_MD_ORDER (FreeBSD extension) */
#define HAVE_NL_LANGINFO_D_MD_ORDER 1
#if __FreeBSD__ > 4
#define HAVE_GETOPT_LONG 1
#define HAVE_POSIX_ACL 1

View File

@ -209,6 +209,7 @@ list_item_verbose(struct bsdtar *bsdtar, struct archive_entry *entry)
char tmp[100];
size_t w;
const char *p;
const char *fmt;
time_t tim;
static time_t now;
@ -277,11 +278,13 @@ list_item_verbose(struct bsdtar *bsdtar, struct archive_entry *entry)
/* Format the time using 'ls -l' conventions. */
tim = (time_t)st->st_mtime;
if (tim < now - 6*30*24*60*60 || tim > now + 6*30*24*60*60)
strftime(tmp, sizeof(tmp), "%b %e %Y", localtime(&tim));
if (abs(tim - now) > (365/2)*86400)
fmt = bsdtar->day_first ? "%e %b %Y" : "%b %e %Y";
else
strftime(tmp, sizeof(tmp), "%b %e %R", localtime(&tim));
safe_fprintf(out, " %s %s", tmp, archive_entry_pathname(entry));
fmt = bsdtar->day_first ? "%e %b %R" : "%b %e %R";
strftime(tmp, sizeof(tmp), fmt, localtime(&tim));
fprintf(out, " %s ", tmp);
safe_fprintf(out, "%s", archive_entry_pathname(entry));
/* Extra information for links. */
if (archive_entry_hardlink(entry)) /* Hard link */