[Tux4kids-commits] r180 - tuxtype/trunk/tuxtype

David Bruce dbruce-guest at alioth.debian.org
Fri May 11 11:16:17 UTC 2007


Author: dbruce-guest
Date: 2007-05-11 11:16:16 +0000 (Fri, 11 May 2007)
New Revision: 180

Modified:
   tuxtype/trunk/tuxtype/alphabet.c
   tuxtype/trunk/tuxtype/funcs.h
   tuxtype/trunk/tuxtype/gettext.c
   tuxtype/trunk/tuxtype/globals.h
   tuxtype/trunk/tuxtype/loaders.c
Log:
UTF-8, setlocale() work


Modified: tuxtype/trunk/tuxtype/alphabet.c
===================================================================
--- tuxtype/trunk/tuxtype/alphabet.c	2007-05-09 16:06:27 UTC (rev 179)
+++ tuxtype/trunk/tuxtype/alphabet.c	2007-05-11 11:16:16 UTC (rev 180)
@@ -15,7 +15,6 @@
  *   (at your option) any later version.                                   *
  *                                                                         *
  ***************************************************************************/
-#include <locale.h>
 
 #include "globals.h"
 #include "funcs.h"
@@ -405,16 +404,7 @@
 
   WORD_qty = 0;
 
-  /* We need to set the locale to something supporting UTF-8 - AFAIK, */
-  /* it can be any UTF-8 locale, not necessarily the specific one     */
-  /* for the language being used (but I could be wrong - DSB)         */
-  if (!setlocale(LC_CTYPE, "nn_NO.UTF-8")) /* temporary example */
-  {
-    fprintf(stderr, "Could not set requested UTF-8 locale, fallback to en_US.UTF-8\n");
-    if (!setlocale(LC_CTYPE, "en_US.UTF-8"))
-      fprintf(stderr, "Cannot support UTF-8, ASCII-only words will be used\n");
-  }
-	/* --- open the file --- */
+  /* --- open the file --- */
 
   wordFile = fopen( wordFn, "r" );
 

Modified: tuxtype/trunk/tuxtype/funcs.h
===================================================================
--- tuxtype/trunk/tuxtype/funcs.h	2007-05-09 16:06:27 UTC (rev 179)
+++ tuxtype/trunk/tuxtype/funcs.h	2007-05-11 11:16:16 UTC (rev 180)
@@ -47,7 +47,7 @@
 
 /* in gettext.c */
 extern unsigned char *gettext( unsigned char *in );
-extern int  load_trans( char *file );
+extern int  load_trans(char* file);
 
 /* in pause.c */
 extern int  Pause( void );

Modified: tuxtype/trunk/tuxtype/gettext.c
===================================================================
--- tuxtype/trunk/tuxtype/gettext.c	2007-05-09 16:06:27 UTC (rev 179)
+++ tuxtype/trunk/tuxtype/gettext.c	2007-05-11 11:16:16 UTC (rev 180)
@@ -23,6 +23,8 @@
  * we don't expect too large of a list (famous last words!)
  */
 
+/* FIXME not sure if this file's code is UTF-8 compatible DSB */
+
 struct node {
 	unsigned char *in;          // the english
 	unsigned char *out;         // the translation
@@ -100,7 +102,7 @@
 		{
 			unsigned char mode='O';
 			int i;
-			for (i=0; i<strlen(str); i++) {
+			for (i = 0; i < strlen(str); i++) {
 				if (mode == 'O') {
 					switch (str[i]) {
 						case '"': mode = 'I'; break;

Modified: tuxtype/trunk/tuxtype/globals.h
===================================================================
--- tuxtype/trunk/tuxtype/globals.h	2007-05-09 16:06:27 UTC (rev 179)
+++ tuxtype/trunk/tuxtype/globals.h	2007-05-11 11:16:16 UTC (rev 180)
@@ -43,6 +43,7 @@
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <dirent.h>
+#include <locale.h>
 
 #include "../config.h"
 

Modified: tuxtype/trunk/tuxtype/loaders.c
===================================================================
--- tuxtype/trunk/tuxtype/loaders.c	2007-05-09 16:06:27 UTC (rev 179)
+++ tuxtype/trunk/tuxtype/loaders.c	2007-05-11 11:16:16 UTC (rev 180)
@@ -56,26 +56,37 @@
   return 0;
 }
 
-void LoadLang( void ) {
-	char fn[FNLEN];
+void LoadLang( void )
+{
+  char fn[FNLEN];
 
-	/* we only need to load a lang.po file if we
-	 * are actually using a theme, so this is a little
-	 * different than the other loaders 
-	 */ 
+  /* we only need to load a lang.po file if we
+   * are actually using a theme, so this is a little
+   * different than the other loaders 
+   */ 
 
-	if (useEnglish) {
-		/* clear translations and return! */
-		return;
-	}
+  if (useEnglish)
+  {
+    /* We need to set the locale to something supporting UTF-8: */
+    if (!setlocale(LC_CTYPE, "en_US.UTF-8"))
+      fprintf(stderr, "Cannot support UTF-8, ASCII-only words will be used\n");
+    return;
+  }
 
-	/* --- create full path to the lang.po file --- */
+  /* --- create full path to the lang.po file --- */
+  sprintf( fn, "%s/lang.po", realPath[0]);
 
-	sprintf( fn, "%s/lang.po", realPath[0]);
-	if (load_trans( fn )) {
-		/* failed to find a lang.po file, clear gettext & return */
-		return;
-	}
+  /* FIXME should have program try to setlocale() to lang-specific locale -  */
+  /* for now, at least get a default UTF-8 encoding set: */
+  if (!setlocale(LC_CTYPE, "en_US.UTF-8"))
+    fprintf(stderr, "Cannot support UTF-8, ASCII-only words will be used\n");
+
+  /* This function confusingly returns 0 if successful! */
+  if (0 != load_trans( fn ))  /* Meaning it failed! */
+  {
+    /* failed to find a lang.po file, clear gettext & return */
+    return;
+  }
 }
 
 int max( int n1, int n2 ) {




More information about the Tux4kids-commits mailing list