[Tux4kids-commits] r868 - tuxtype/trunk/src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Wed Feb 4 22:12:27 UTC 2009
Author: dbruce-guest
Date: 2009-02-04 22:12:27 +0000 (Wed, 04 Feb 2009)
New Revision: 868
Modified:
tuxtype/trunk/src/alphabet.c
tuxtype/trunk/src/funcs.h
tuxtype/trunk/src/practice.c
Log:
clean up of wchar_t to utf8 conversion code
Modified: tuxtype/trunk/src/alphabet.c
===================================================================
--- tuxtype/trunk/src/alphabet.c 2009-02-03 22:36:13 UTC (rev 867)
+++ tuxtype/trunk/src/alphabet.c 2009-02-04 22:12:27 UTC (rev 868)
@@ -762,7 +762,7 @@
/* It returns -1 on error, otherwise returns the length of the */
/* converted, null-terminated wchar_t* string now stored in the */
/* location of the 'wide_word' pointer. */
-int ConvertFromUTF8(wchar_t* wide_word, const unsigned char* UTF8_word)
+int ConvertFromUTF8(wchar_t* wide_word, const char* UTF8_word)
{
int i = 0;
ConversionResult result;
@@ -810,22 +810,21 @@
/******************To be used for savekeyboard*************/
/***Converts wchar_t string to char string*****************/
-int ConvertToUTF8(wchar_t* wide_word, unsigned char* UTF8_word)
+int ConvertToUTF8(const wchar_t* wide_word, char* UTF8_word)
{
int i = 0;
- unsigned char temp_UTF8[1024];
-// wchar_t temp_wchar_t[1024];
+ char temp_UTF8[1024];
+ /* NOTE we need this because iconv_open() needs a char**. We can't */
+ /* just pass "&temp_UTF8" because "temp_UTF8" is really a shorthand */
+ /* for "&temp_UTF8[0]", not its own memory location, so it doesn't */
+ /* have its own address. We ought to be able to do this directly into */
+ /* into the argument UTF8_word string, but so far have had errors. */
+ char* UTF8_Start = temp_UTF8;
- unsigned char* UTF8_Start = temp_UTF8;
- UTF8* UTF8_End = &temp_UTF8[1024 - 1];
-// const wchar_t* wchar_t_Start = &temp_wchar_t[0];
-// const wchar_t* wchar_t_End = &temp_wchar_t[1024 - 1];
-
iconv_t conv_descr;
size_t bytes_converted;
size_t in_length = (size_t)1024;
size_t out_length = (size_t)1024;
-// wcsncpy(temp_wchar_t, wide_word, 1024);
DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): wide_word = %S\n", wide_word);}
// DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): temp_wchar_t = %S\n", temp_wchar_t);}
@@ -843,30 +842,14 @@
bytes_converted = iconv(conv_descr,
&wide_word, &in_length,
-// &temp_UTF8, &out_length);
+// &UTF8_word, &out_length);
&UTF8_Start, &out_length);
LOG("completed iconv()\n");
iconv_close(conv_descr);
- UTF8_word[0] = 0;
+ strncpy(UTF8_word, temp_UTF8, 256);
- while ((i < 1024) && (temp_UTF8[i] != 0))
- {
- UTF8_word[i] = temp_UTF8[i];
- i++;
- }
-
- if (i >= 1024)
- {
- fprintf(stderr, "ConvertToUTF8(): buffer overflow\n");
- return -1;
- }
- else //need terminating null:
- {
- UTF8_word[i] = '\0';
- }
-
DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): UTF8_word = %s\n", UTF8_word);}
DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): temp_UTF8 = %s\n", temp_UTF8);}
Modified: tuxtype/trunk/src/funcs.h
===================================================================
--- tuxtype/trunk/src/funcs.h 2009-02-03 22:36:13 UTC (rev 867)
+++ tuxtype/trunk/src/funcs.h 2009-02-04 22:12:27 UTC (rev 868)
@@ -29,7 +29,8 @@
/* (still in alphabet.c:) */
int CheckNeededGlyphs(void);
void ClearWordList(void);
-int ConvertFromUTF8(wchar_t* wide_word, const unsigned char* UTF8_word);
+int ConvertFromUTF8(wchar_t* wide_word, const char* UTF8_word);
+int ConvertToUTF8(const wchar_t* wide_word, char* UTF8_word);
void FreeLetters(void);
int GenerateWordList(const char* wordFn);
void GenCharListFromString(const unsigned char* UTF8_str);
Modified: tuxtype/trunk/src/practice.c
===================================================================
--- tuxtype/trunk/src/practice.c 2009-02-03 22:36:13 UTC (rev 867)
+++ tuxtype/trunk/src/practice.c 2009-02-04 22:12:27 UTC (rev 868)
@@ -107,7 +107,7 @@
static int practice_load_media(void);
static void practice_unload_media(void);
static void print_at(const wchar_t* pphrase, int wrap, int x, int y);
-static void show(unsigned char t);
+static void show(char t);
SDL_Surface* GetKeypress1(int index);
SDL_Surface* GetKeypress2(int index);
SDL_Surface* GetWrongKeypress(int index);
@@ -857,8 +857,8 @@
static int practice_load_media(void)
{
int i;
- unsigned char fn[FNLEN];
- unsigned char let[5];
+ char fn[FNLEN];
+ char let[5];
int load_failed = 0;
DEBUGCODE { printf("Entering practice_load_media\n"); }
@@ -1220,7 +1220,7 @@
/* looks like dead code: */
-static void show(unsigned char t)
+static void show(char t)
{
SDL_Rect dst;
SDL_Surface* s = NULL;
@@ -1306,7 +1306,7 @@
static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width)
{
wchar_t buf[MAX_PHRASE_LENGTH];
- unsigned char UTF8buf[MAX_PHRASE_LENGTH];
+ char UTF8buf[MAX_PHRASE_LENGTH];
int word_end = -1;
int prev_word_end = -1;
More information about the Tux4kids-commits
mailing list