pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: How to change mail/thunderbird date format?



Christian Biere wrote:
> Rhialto wrote:
> > I just installed mail/thunderbird from the stable pkgsrc branch.
> > It shows dates as 08/18/08 which I find quite annoying; I want either
> > 2008-08-18 or 18-08-2008 (preferably the latter).
> 
> My personal babble:
> 2008-08-18 conforms to ISO 8601, an international standard. You might
> want to get used to it. The latter SHOULD be illegal. I don't think
> it is officially used in any country. Use of '-' implies ISO 8601.
> 18.08.2008 would be fine. It's used in Germany for example.
>  
> > Googling suggests that one should be able to set LC_TIME=en_GB or some
> > other country, which thunderbird is supposed to obey. See for instance
> > http://leuf.net/ww/wikidn?ThunderbirdAndDateFormat or
> > http://kb.mozillazine.org/Date_display_format#Configuring_the_date.2Ftime_system_settings_on_your_computer
> >  .
> > 
> > Unfortunately this does not seem to work.
> > 
> > I tried all kinds of variants including the character set as
> > en_GB.ISO8859-1 or en_GB.ISO88591 or en_GB.iso-8859-1.
>  
> I assume you use NetBSD. If so, read the BUGS section of setlocale(3).
> You're not going to like it. In a nutshell: NetBSD only supports
> LC_CTYPE (the character encoding) of any locale setting.
> 
> > Does anyone have some other idea?

DIY with LD_PRELOAD. See attached source code. I leave it up to the
reader implementing handling of all formats. For Thunderbird, you
probably only need %c, %X and %x.

-- 
Christian
/*
 * Compile as shared object (very platform/compile dependend):
 * cc -W -Wall -Wformat -Wshadow -shared % -o strftime_override.so
 *
 * Add -DDEBUG to print the format string passed to strftime() to /dev/tty.
 *
 * Use and test:
 * LD_PRELOAD=./strftime_override.so date +%x
 */

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <dlfcn.h>
#include <errno.h>

#ifdef DEBUG
#include <unistd.h>
#include <fcntl.h>
#endif /* DEBUG */

typedef void (*func_ptr)(void);
typedef size_t (*strftime_func_ptr)(char *, size_t, const char *, const struct 
tm *);

size_t strftime(char *, size_t, const char *, const struct tm *)
        __attribute__((alias ("strftime_hack")));

static func_ptr
get_libc_symbol(const char *symbol)
{
  static void *handle;
  static const func_ptr zero_func;
  func_ptr func = zero_func;

#ifdef RTLD_NEXT
  handle = RTLD_NEXT;
#else /* !RTLD_NEXT */
  if (!handle) {
    handle = dlopen("libc.so", RTLD_NOW);
  }
#endif /* RTLD_NEXT */

  if (handle) {
    func = dlsym(handle, symbol);
    if (!func) {
      errno = ENOSYS;
    }
  } else {
    errno = ENOENT;
  }

  return func;
}

static inline void
trace(const char *format)
{
        (void) format;
#ifdef DEBUG
        {
                int fd = open("/dev/tty", O_WRONLY, 0);
                if (fd >= 0) {
                        write(fd, format, strlen(format));
                        write(fd, "\n", 1);
                        close(fd);
                }
        }
#endif  /* DEBUG */
}


size_t
strftime_real(char *buf, size_t maxsize,
        const char *format, const struct tm *timeptr)
{
        static strftime_func_ptr func;
        if (!func) {
                func = (strftime_func_ptr) get_libc_symbol("strftime");
        }
        return (*func)(buf, maxsize, format, timeptr);
}

size_t
strftime_hack(char *buf, size_t maxsize,
        const char *format, const struct tm *timeptr)
{
        if (format && buf && maxsize > 0 && timeptr) {
                trace(format);  
                if (0 == strcmp(format, "%x")) {
                        size_t len;
                
                        len = snprintf(buf, maxsize, "%4u-%02u-%02u",
                                timeptr->tm_year + 1900,
                                timeptr->tm_mon + 1,
                                timeptr->tm_mday);
                        return len < maxsize ? len : 0;
                }
                /* TODO: Handle more formats */
        }
        return strftime_real(buf, maxsize, format, timeptr);
}


Home | Main Index | Thread Index | Old Index