[Tux4kids-commits] r839 - tuxtype/trunk/src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Mon Jan 12 01:30:09 UTC 2009
Author: dbruce-guest
Date: 2009-01-12 01:30:09 +0000 (Mon, 12 Jan 2009)
New Revision: 839
Added:
tuxtype/trunk/src/mysetenv.c
tuxtype/trunk/src/mysetenv.h
Modified:
tuxtype/trunk/src/Makefile.am
tuxtype/trunk/src/Makefile.in
tuxtype/trunk/src/loaders.c
tuxtype/trunk/src/main.c
tuxtype/trunk/src/playgame.c
tuxtype/trunk/src/setup.c
Log:
added my_setenv() from GNU Gettext FAQ to help make i18n on Win more reliable
Modified: tuxtype/trunk/src/Makefile.am
===================================================================
--- tuxtype/trunk/src/Makefile.am 2009-01-11 22:07:03 UTC (rev 838)
+++ tuxtype/trunk/src/Makefile.am 2009-01-12 01:30:09 UTC (rev 839)
@@ -42,7 +42,8 @@
pause.c \
ConvertUTF.c \
options.c \
- iconv_string.c
+ iconv_string.c \
+ mysetenv.c
TuxType_SOURCES = $(tuxtype_SOURCES)
# The rc file has something to do with the icon in Windows, IIRC
@@ -60,6 +61,7 @@
ConvertUTF.h \
iconv_string.h \
gettext.h \
- compiler.h
+ compiler.h \
+ mysetenv.h
Modified: tuxtype/trunk/src/Makefile.in
===================================================================
--- tuxtype/trunk/src/Makefile.in 2009-01-11 22:07:03 UTC (rev 838)
+++ tuxtype/trunk/src/Makefile.in 2009-01-12 01:30:09 UTC (rev 839)
@@ -69,7 +69,7 @@
practice.$(OBJEXT) audio.$(OBJEXT) snow.$(OBJEXT) \
scripting.$(OBJEXT) SDL_extras.$(OBJEXT) pixels.$(OBJEXT) \
pause.$(OBJEXT) ConvertUTF.$(OBJEXT) options.$(OBJEXT) \
- iconv_string.$(OBJEXT)
+ iconv_string.$(OBJEXT) mysetenv.$(OBJEXT)
am_TuxType_OBJECTS = $(am__objects_1)
TuxType_OBJECTS = $(am_TuxType_OBJECTS)
TuxType_LDADD = $(LDADD)
@@ -80,7 +80,7 @@
practice.$(OBJEXT) audio.$(OBJEXT) snow.$(OBJEXT) \
scripting.$(OBJEXT) SDL_extras.$(OBJEXT) pixels.$(OBJEXT) \
pause.$(OBJEXT) ConvertUTF.$(OBJEXT) options.$(OBJEXT) \
- iconv_string.$(OBJEXT)
+ iconv_string.$(OBJEXT) mysetenv.$(OBJEXT)
tuxtype_OBJECTS = $(am_tuxtype_OBJECTS)
tuxtype_LDADD = $(LDADD)
tuxtype_DEPENDENCIES =
@@ -282,7 +282,8 @@
pause.c \
ConvertUTF.c \
options.c \
- iconv_string.c
+ iconv_string.c \
+ mysetenv.c
TuxType_SOURCES = $(tuxtype_SOURCES)
# The rc file has something to do with the icon in Windows, IIRC
@@ -299,7 +300,8 @@
ConvertUTF.h \
iconv_string.h \
gettext.h \
- compiler.h
+ compiler.h \
+ mysetenv.h
all: all-am
@@ -378,6 +380,7 @@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/laser.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/loaders.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/main.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/mysetenv.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/options.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pause.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/pixels.Po at am__quote@
Modified: tuxtype/trunk/src/loaders.c
===================================================================
--- tuxtype/trunk/src/loaders.c 2009-01-11 22:07:03 UTC (rev 838)
+++ tuxtype/trunk/src/loaders.c 2009-01-12 01:30:09 UTC (rev 839)
@@ -20,6 +20,7 @@
#include "globals.h"
#include "funcs.h"
#include "SDL_extras.h"
+#include "mysetenv.h"
static SDL_Surface* win_bkgd = NULL;
static SDL_Surface* fullscr_bkgd = NULL;
@@ -63,7 +64,7 @@
return 0;
}
-
+/* FIXME not sure we need to call *textdomain() functions again here */
/* FIXME need to read language's font name, if needed - e.g. Russian. */
/* also should have return value reflect success or failure. */
void LoadLang(void)
@@ -87,17 +88,16 @@
fprintf(stderr, "After gettext() call\n");
}
-#ifdef WIN32
- snprintf(buf, "LANG=%s", settings.theme_locale_name);
- buf[10] = '\0'; //terminate after location e.g. "LANG=en_US" rather than "LANG=en_US.utf8"
- putenv(buf);
+ /* Also set LANG as fallback because setlocale() unreliable */
+ /* on some Windows versions, AFAICT */
+ snprintf(buf, 30, "%s", settings.theme_locale_name);
+ buf[5] = '\0'; //en_US" rather than "en_US.utf8"
+ DEBUGCODE { fprintf(stderr, "buf is: %s\n", buf); }
- DEBUGCODE
+ if (my_setenv("LANG", buf) == -1)
{
- fprintf(stderr, "buf is %s\n", buf);
+ fprintf(stderr, "Warning - could not set LANG to %s\n\n", buf);
}
-
-#endif
return;
}
@@ -262,17 +262,17 @@
// oldDebug = settings.debug_on; // suppress output for now
// settings.debug_on = 0;
- DEBUGCODE { fprintf(stderr, "LoadImage: loading %s\n", datafile ); }
+// DEBUGCODE { fprintf(stderr, "LoadImage: loading %s\n", datafile ); }
/* Look for image under theme path if desired: */
if (!settings.use_english && !(mode & IMG_NO_THEME))
{
sprintf(fn, "%s/images/%s", settings.theme_data_path, datafile);
- DEBUGCODE { fprintf(stderr, "LoadImage: looking in %s\n", fn); }
+// DEBUGCODE { fprintf(stderr, "LoadImage: looking in %s\n", fn); }
tmp_pic = IMG_Load(fn);
- if (tmp_pic != NULL)
- DEBUGCODE { fprintf(stderr, "Graphics file %s successfully loaded\n", fn);}
+ if (tmp_pic != NULL){}
+// DEBUGCODE { fprintf(stderr, "Graphics file %s successfully loaded\n", fn);}
else
DEBUGCODE { fprintf(stderr, "Warning: graphics file %s could not be loaded\n", fn);}
}
@@ -281,11 +281,11 @@
if (!tmp_pic)
{
sprintf(fn, "%s/images/%s", settings.default_data_path, datafile);
- DEBUGCODE { fprintf(stderr, "LoadImage: looking in %s\n", fn); }
+// DEBUGCODE { fprintf(stderr, "LoadImage: looking in %s\n", fn); }
tmp_pic = IMG_Load(fn);
- if (tmp_pic != NULL)
- DEBUGCODE { fprintf(stderr, "Graphics file %s successfully loaded\n", fn);}
+ if (tmp_pic != NULL){}
+// DEBUGCODE { fprintf(stderr, "Graphics file %s successfully loaded\n", fn);}
else
DEBUGCODE { fprintf(stderr, "Warning: graphics file %s could not be loaded\n", fn);}
}
@@ -340,7 +340,7 @@
}
}
- LOG( "LoadImage(): Done\n" );
+// LOG( "LoadImage(): Done\n" );
// settings.debug_on = oldDebug;
Modified: tuxtype/trunk/src/main.c
===================================================================
--- tuxtype/trunk/src/main.c 2009-01-11 22:07:03 UTC (rev 838)
+++ tuxtype/trunk/src/main.c 2009-01-12 01:30:09 UTC (rev 839)
@@ -44,7 +44,10 @@
srand(time(NULL));
Opts_Initialize(); // First, initialize settings with hard-coded defaults
+ // This sets settings.default_data_path to the default theme file path:
+ SetupPaths(NULL);
LoadSettings(); // Second, read saved any saved settings
+
// Third, check command line args as these should override saved settings
if (argc > 1) /* FIXME this could go into something like HandleCommandArgs() */
{
@@ -150,11 +153,6 @@
}
- // This sets settings.default_data_path to the default theme file path:
- SetupPaths(NULL);
-
-
-
lib_flags = SDL_INIT_VIDEO;
lib_flags |= SDL_INIT_AUDIO;
Added: tuxtype/trunk/src/mysetenv.c
===================================================================
--- tuxtype/trunk/src/mysetenv.c (rev 0)
+++ tuxtype/trunk/src/mysetenv.c 2009-01-12 01:30:09 UTC (rev 839)
@@ -0,0 +1,43 @@
+/* This file written by Bruno Haible and provided in GNU Gettext FAQ
+ to help with difficulties using Gettext under Windows. */
+
+#include <string.h>
+ #include <stdlib.h>
+ #if defined _WIN32
+ # include <windows.h>
+ #endif
+
+ int my_setenv (const char * name, const char * value) {
+ size_t namelen = strlen(name);
+ size_t valuelen = (value==NULL ? 0 : strlen(value));
+ #if defined _WIN32
+ /* On Woe32, each process has two copies of the environment variables,
+ one managed by the OS and one managed by the C library. We set
+ the value in both locations, so that other software that looks in
+ one place or the other is guaranteed to see the value. Even if it's
+ a bit slow. See also
+ <http://article.gmane.org/gmane.comp.gnu.mingw.user/8272>
+ <http://article.gmane.org/gmane.comp.gnu.mingw.user/8273>
+ <http://www.cygwin.com/ml/cygwin/1999-04/msg00478.html> */
+ if (!SetEnvironmentVariableA(name,value))
+ return -1;
+ #endif
+ #if defined(HAVE_PUTENV)
+ char* buffer = (char*)malloc(namelen+1+valuelen+1);
+ if (!buffer)
+ return -1; /* no need to set errno = ENOMEM */
+ memcpy(buffer,name,namelen);
+ if (value != NULL) {
+ buffer[namelen] = '=';
+ memcpy(buffer+namelen+1,value,valuelen);
+ buffer[namelen+1+valuelen] = 0;
+ } else
+ buffer[namelen] = 0;
+ return putenv(buffer);
+ #elif defined(HAVE_SETENV)
+ return setenv(name,value,1);
+ #else
+ /* Uh oh, neither putenv() nor setenv() ... */
+ return -1;
+ #endif
+ }
Added: tuxtype/trunk/src/mysetenv.h
===================================================================
--- tuxtype/trunk/src/mysetenv.h (rev 0)
+++ tuxtype/trunk/src/mysetenv.h 2009-01-12 01:30:09 UTC (rev 839)
@@ -0,0 +1,12 @@
+//
+// C Interface: mysetenv
+//
+// Description: example code from GNU Gettext FAQ - freely distributed
+//
+//
+#ifndef MY_SETENV_H
+#define MY_SETENV_H
+
+int my_setenv(const char * name, const char * value);
+
+#endif
\ No newline at end of file
Modified: tuxtype/trunk/src/playgame.c
===================================================================
--- tuxtype/trunk/src/playgame.c 2009-01-11 22:07:03 UTC (rev 838)
+++ tuxtype/trunk/src/playgame.c 2009-01-12 01:30:09 UTC (rev 839)
@@ -1131,11 +1131,18 @@
static void display_msg(const unsigned char* msg, int x, int y)
{
- SDL_Surface* m;
- m = TTF_RenderUTF8_Shaded(label_font, msg, white, white);
- EraseObject(m, x, y);
- DrawObject(m, x, y);
- SDL_FreeSurface(m);
+ if (msg == NULL || msg[0] == '\0')
+ return;
+
+ SDL_Surface* m;
+ m = TTF_RenderUTF8_Shaded(label_font, msg, white, white);
+
+ if (m)
+ {
+ EraseObject(m, x, y);
+ DrawObject(m, x, y);
+ SDL_FreeSurface(m);
+ }
}
/***************************
@@ -1202,22 +1209,27 @@
i = 0;
needed_places = strlen(numnuts);
- if (needed_places < FNLEN && needed_places <= places) {
- if (places > 0) {
- for (i = 1; i <= (places - needed_places); i++) {
+ if (needed_places < FNLEN && needed_places <= places)
+ {
+ if (places > 0)
+ {
+ for (i = 1; i <= (places - needed_places); i++)
+ {
DrawObject(number[0], x, y);
x += number[0]->w;
}
}
}
- for (i = 0; i < needed_places; i++) {
- uddernumber = numnuts[i] - '0';
- DrawObject(number[uddernumber], x, y);
- x += number[uddernumber]->w;
+ for (i = 0; i < needed_places; i++)
+ {
+ uddernumber = numnuts[i] - '0';
+ DrawObject(number[uddernumber], x, y);
+ x += number[uddernumber]->w;
}
}
+
/*************************
EraseNumbers: Erase numbers
from the screen. See "usage"
@@ -1626,7 +1638,8 @@
letter_x = fish_object[which].x + (j * fishy->frame[0]->w) + x_inset;
letter_y = fish_object[which].y + y_inset;
- DrawObject(letter_surface, letter_x, letter_y);
+ if(letter_surface != NULL)
+ DrawObject(letter_surface, letter_x, letter_y);
}
}
/* LOG ("Leaving DrawFish()\n");*/
Modified: tuxtype/trunk/src/setup.c
===================================================================
--- tuxtype/trunk/src/setup.c 2009-01-11 22:07:03 UTC (rev 838)
+++ tuxtype/trunk/src/setup.c 2009-01-12 01:30:09 UTC (rev 839)
@@ -271,16 +271,17 @@
fscanf(fp, "%[^=]=%[^\n]\n", setting, value );
DEBUGCODE {fprintf(stderr, "%s = %s", setting, value );}
-
- if (strncmp( setting, "lang", FNLEN ) == 0 )
+ //For now we are not reading or saving the language selection:
+// if (strncmp( setting, "lang", FNLEN ) == 0 )
+// {
+// DEBUGCODE {fprintf(stderr, "LoadSettings: Setting language to %s\n", value);}
+// strncpy(settings.lang, value, FNLEN - 1);
+// setting_found = 1;
+// SetupPaths(value); /* Does this really belong here? */
+// }
+// else
+ if (strncmp( setting, "o_lives", FNLEN ) == 0 )
{
- DEBUGCODE {fprintf(stderr, "LoadSettings: Setting language to %s\n", value);}
- strncpy(settings.lang, value, FNLEN - 1);
- setting_found = 1;
- SetupPaths(value); /* Does this really belong here? */
- }
- else if (strncmp( setting, "o_lives", FNLEN ) == 0 )
- {
DEBUGCODE {fprintf(stderr, "LoadSettings: Setting lives to %s\n", value);}
settings.o_lives = atoi(value);
setting_found = 1;
@@ -370,8 +371,10 @@
}
/* Save all the settings here! */
- if (strncmp(settings.theme_name, "", FNLEN) != 0)
- fprintf( settingsFile, "lang=%s\n", settings.theme_name );
+//NOTE for now, don't save theme because things get screwed up if the language
+// doesn't match the LANG environmental variable - DSB
+// if (strncmp(settings.theme_name, "", FNLEN) != 0)
+// fprintf( settingsFile, "lang=%s\n", settings.theme_name );
if (settings.o_lives > 9)
fprintf( settingsFile, "o_lives=%d\n", settings.o_lives );
More information about the Tux4kids-commits
mailing list