[Pkg-wmaker-commits] [wmitime] 107/127: wmitime: Improve locale support.

Doug Torrance dtorrance-guest at moszumanska.debian.org
Sat Aug 22 01:34:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

dtorrance-guest pushed a commit to branch master
in repository wmitime.

commit 80d331be7fe19c8b6f095704732b11b79fef2415
Author: Doug Torrance <dtorrance at monmouthcollege.edu>
Date:   Sat Dec 20 01:57:04 2014 -0600

    wmitime: Improve locale support.
    
    Previously, wmitime only had support for English, French, and (in Debian
    only) Hungarian.  In addition, the choice was made at compile time.
    
    This patch adds run-time support for any language using the Latin alphabet.
    The locale is determined by the user's environment or may be specified on
    the command line with the "-l" option.  Note that users whose environment
    specifies a non-Latin locale may wish to use, e.g., "-l C", as otherwise
    no date will appear.
    
    Note that, for simplicity, the month and day are now displayed as "01 JAN"
    as opposed to "JAN 01".  (Previously, the former format was used for English
    and the latter for French.)
---
 Makefile   |  3 +--
 french.h   | 30 -----------------------------
 language.h | 35 ---------------------------------
 wmitime.c  | 65 +++++++++++++++++++++++++++++++++++++++-----------------------
 4 files changed, 42 insertions(+), 91 deletions(-)

diff --git a/Makefile b/Makefile
index c928067..e9029c0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,3 @@
-#LANG = fr
 LIBS   = -lXpm -lXext -lX11 -lm
 CFLAGS = -O2 -Wall
 OBJS =	wmitime.o \
@@ -10,7 +9,7 @@ PREFIX = /usr/local
 BINDIR = $(PREFIX)/bin
 
 .c.o:
-	$(CC) $(CPPFLAGS) $(CFLAGS) -D$(LANG) -c $< -o $*.o
+	$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $*.o
 
 wmitime: $(OBJS)
 	$(CC) $(LDFLAGS) -o wmitime $^ $(LIBS)
diff --git a/french.h b/french.h
deleted file mode 100644
index 17d86f0..0000000
--- a/french.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// french.h
-// Created by Pierre-Marie.Allemand at capway.com
-// 08-jan-1999
-
-static char daynames[7][3] =
-{
-    {"Di"},
-    {"Lu"},
-    {"Ma"},
-    {"Me"},
-    {"Je"},
-    {"Ve"},
-    {"Sa"}
-};
-
-static char monthnames[12][4] =
-{
-    {"Jan"},
-    {"Fev"},
-    {"Mar"},
-    {"Avr"},
-    {"Mai"},
-    {"Jun"},
-    {"Jui"},
-    {"Aou"},
-    {"Sep"},
-    {"Oct"},
-    {"Nov"},
-    {"Dec"}
-};
diff --git a/language.h b/language.h
deleted file mode 100644
index 88b67a1..0000000
--- a/language.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// language.h
-
-static char daynames[7][3] =
-{
-    {"Su"},
-    {"Mo"},
-    {"Tu"},
-    {"We"},
-    {"Th"},
-    {"Fr"},
-    {"Sa"}
-};
-
-static char monthnames[12][4] =
-{
-    {"Jan"},
-    {"Feb"},
-    {"Mar"},
-    {"Apr"},
-    {"May"},
-    {"Jun"},
-    {"Jul"},
-    {"Aug"},
-    {"Sep"},
-    {"Oct"},
-    {"Nov"},
-    {"Dec"}
-};
-
-
-
-
-
-
-
diff --git a/wmitime.c b/wmitime.c
index e72d16a..c29deaa 100644
--- a/wmitime.c
+++ b/wmitime.c
@@ -16,6 +16,9 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <math.h>
+#include <locale.h>
+#include <langinfo.h>
+#include <iconv.h>
 
 #include <sys/wait.h>
 #include <sys/stat.h>
@@ -31,16 +34,6 @@
 #include "wmgeneral/wmgeneral.h"
 #include "wmgeneral/misc.h"
 
-#ifdef fr_FR
-#define fr
-#endif
-
-#ifdef fr
-#include "french.h"
-#else
-#include "language.h"
-#endif
-
 #include "wmitime-master.xpm"
 char wmitime_mask_bits[64*64];
 int  wmitime_mask_width = 64;
@@ -61,6 +54,7 @@ extern	char **environ;
 char	*ProgName;
 
 char uconfig_file[256];
+char locale[256];
 
 time_t		curtime;
 time_t		prevtime;
@@ -95,6 +89,7 @@ int main(int argc, char *argv[]) {
 	int		i;
 
     uconfig_file[0] = 0;
+    locale[0] = 0;
 
 	/* Parse Command Line */
 
@@ -137,6 +132,13 @@ int main(int argc, char *argv[]) {
                     TwelveHour = 1;
                 }
                 break;
+            case 'l' :
+                if (argc > (i+1))
+                {
+                    strcpy(locale, argv[i+1]);
+                    i++;
+                }
+                break;
             default:
 				usage();
 				exit(0);
@@ -145,6 +147,11 @@ int main(int argc, char *argv[]) {
 		}
 	}
 
+	if (setlocale(LC_ALL, locale) == NULL)
+	    fprintf(stderr,
+		    "warning: locale '%s' not recognized; defaulting to '%s'.",
+		    locale, setlocale(LC_ALL, NULL));
+
 	wmitime_routine(argc, argv);
 
 	return 0;
@@ -365,28 +372,37 @@ void DrawStdTime(void)
 
 void DrawDate(void)
 {
-    char BlitStr[20];
+    char OrigBlitStr[20], BlitStr[20];
+    char *inbuf, *outbuf;
+    size_t inbytesleft, outbytesleft;
+    iconv_t cd;
 
-    sprintf(BlitStr, "%s", daynames[clk->tm_wday]);
+    cd = iconv_open("ASCII//TRANSLIT", nl_langinfo(CODESET));
+
+    inbuf = OrigBlitStr;
+    outbuf = BlitStr;
+    inbytesleft = sizeof OrigBlitStr;
+    outbytesleft = sizeof BlitStr;
+
+    sprintf(OrigBlitStr, "%s", nl_langinfo(ABDAY_1 + clk->tm_wday));
+    iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+    BlitStr[2] = 0;
     BlitString( BlitStr, 6, 50);
 
-#ifdef fr
+    inbuf = OrigBlitStr;
+    outbuf = BlitStr;
+    inbytesleft = sizeof OrigBlitStr;
+    outbytesleft = sizeof BlitStr;
 
-    // French date model
-    sprintf(BlitStr, "%s", monthnames[clk->tm_mon]);
+    sprintf(OrigBlitStr, "%s", nl_langinfo(ABMON_1 + clk->tm_mon));
+    iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
+    BlitStr[3] = 0;
     BlitString( BlitStr, 40, 50);
 
-    sprintf(BlitStr, "%02i", clk->tm_mday);
-    BlitString( BlitStr, 25, 50);
-#else
-
-    sprintf(BlitStr, "%s", monthnames[clk->tm_mon]);
-    BlitString( BlitStr, 25, 50);
+    iconv_close(cd);
 
     sprintf(BlitStr, "%02i", clk->tm_mday);
-    BlitString( BlitStr, 45, 50);
-
-#endif
+    BlitString( BlitStr, 25, 50);
 }
 
 void DrawInetWheel(void)
@@ -706,6 +722,7 @@ void usage(void)
 	fprintf(stderr, "    -display <display name>\n");
 	fprintf(stderr, "    -geometry +XPOS+YPOS      initial window position\n");
 //    fprintf(stderr, "    -c <filename>             use specified config file\n");
+	fprintf(stderr, "    -l <locale>               specify locale\n");
     fprintf(stderr, "    -h                        this help screen\n");
 	fprintf(stderr, "    -v                        print the version number\n");
     fprintf(stderr, "\n");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmitime.git



More information about the Pkg-wmaker-commits mailing list