wmtime: Fixed Debian bug #661843. Applied a patch by Milan Cermak.
authorDoug Torrance <profzoom@hotmail.com>
Tue, 30 Oct 2012 20:56:52 +0000 (30 13:56 -0700)
committerCarlos R. Mafra <crmafra@gmail.com>
Tue, 30 Oct 2012 21:52:00 +0000 (30 21:52 +0000)
Package: wmtime
Version: 1.0b3-2
Severity: normal
Tags: upstream patch l10n

Hi,
the package wmtime claims that it supports localization. Looking into the code,
it seems more like date customization.
When claiming "localization", it should work as such - respecting LANG, LC_ALL,
etc. environment variables and use locales for the day and month abbreviations.

Please see my patch which adds such support.
Regards,
Milan Cermak

-- System Information:
Debian Release: 6.0.4
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.37.6 (SMP w/4 CPU cores; PREEMPT)
Locale: LANG=cs_CZ.UTF-8, LC_CTYPE=cs_CZ.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages wmtime depends on:
ii  libc6                         2.11.3-2   Embedded GNU C Library: Shared lib
ii  libx11-6                      2:1.3.3-4  X11 client-side library
ii  libxext6                      2:1.1.2-1  X11 miscellaneous extension librar
ii  libxpm4                       1:3.5.8-1  X11 pixmap library

wmtime recommends no packages.

wmtime suggests no packages.

-- no debconf information

wmtime/wmtime/wmtime.c

index 6f1a007..85cfbba 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 #include <math.h>
+#include <locale.h>
+#include <langinfo.h>
+#include <iconv.h>
+#include <ctype.h>
 
 #include <sys/wait.h>
 #include <sys/param.h>
@@ -148,7 +152,10 @@ int main(int argc, char *argv[]) {
                        }
                }
        }
-       get_lang();
+
+       if (setlocale(LC_ALL, "") != NULL)
+               get_lang();
+
        wmtime_routine(argc, argv);
        return 0;
 }
@@ -156,26 +163,44 @@ int main(int argc, char *argv[]) {
 /************/
 /* get_lang */
 /************/
-void get_lang(){
-   FILE *fp;
-   int i;
-   const int line_size = 5;
-   char line[line_size];
-   
-   fp=fopen("language","r");
-   if (fp) {
-          /* Grab the days of the week */
-       for (i=0;i<7;i++){
-                  fgets(line, line_size, fp);
-                  strncpy(day_of_week[i], line, 2);
-       };
-          /* Grab the names of the months */
-       for (i=0;i<12;i++){
-                  fgets(line, line_size, fp);
-                  strncpy(mon_of_year[i], line, 3);
-       };
-          fclose(fp);
-    };
+void get_lang(void)
+{
+       char langbuf[10], outbuf[10];
+       char *inp, *outp;
+       iconv_t icd;
+       int i, ret;
+       size_t insize, outsize;
+
+       icd = iconv_open("ASCII//TRANSLIT", nl_langinfo(CODESET));
+       if (icd < 0)
+               return;
+
+       for (i = 0; i < 7; i++) {
+               strncpy(langbuf, nl_langinfo(ABDAY_1 + i), 10);
+               insize = outsize = 10;
+               inp = langbuf;
+               outp = outbuf;
+               do {
+                       ret = iconv(icd, &inp, &insize, &outp, &outsize);
+               } while (outsize > 0 && ret > 0);
+               for (outp = outbuf, outsize = 0; *outp != 0 && outsize < 2;
+                   outp++, outsize++)
+                       day_of_week[i][outsize] = toupper(*outp);
+       }
+       for (i = 0; i < 12; i++) {
+               strncpy(langbuf, nl_langinfo(ABMON_1 + i), 10);
+               insize = outsize = 10;
+               inp = langbuf;
+               outp = outbuf;
+               do {
+                       ret = iconv(icd, &inp, &insize, &outp, &outsize);
+               } while (outsize > 0 && ret > 0);
+               for (outp = outbuf, outsize = 0; *outp != 0 && outsize < 3;
+                   outp++, outsize++)
+                       mon_of_year[i][outsize] = toupper(*outp);
+       }
+
+       iconv_close(icd);
 }
 
 /*******************************************************************************\