[Tux4kids-commits] r880 - tuxtype/trunk/src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Tue Feb 10 22:58:32 UTC 2009
Author: dbruce-guest
Date: 2009-02-10 22:58:31 +0000 (Tue, 10 Feb 2009)
New Revision: 880
Removed:
tuxtype/trunk/src/iconv_string.c
tuxtype/trunk/src/iconv_string.h
Modified:
tuxtype/trunk/src/Makefile.am
tuxtype/trunk/src/SDL_extras.c
tuxtype/trunk/src/SDL_extras.h
tuxtype/trunk/src/alphabet.c
tuxtype/trunk/src/convert_utf.c
tuxtype/trunk/src/funcs.h
tuxtype/trunk/src/practice.c
tuxtype/trunk/src/scripting.c
tuxtype/trunk/src/theme.c
Log:
code cleanup - going through and fixing as many compiler warnings as possible
Modified: tuxtype/trunk/src/Makefile.am
===================================================================
--- tuxtype/trunk/src/Makefile.am 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/Makefile.am 2009-02-10 22:58:31 UTC (rev 880)
@@ -45,7 +45,6 @@
pause.c \
convert_utf.c \
options.c \
- iconv_string.c \
mysetenv.c
TuxType_SOURCES = $(tuxtype_SOURCES)
@@ -62,7 +61,6 @@
SDL_extras.h \
snow.h \
convert_utf.h \
- iconv_string.h \
gettext.h \
compiler.h \
mysetenv.h
Modified: tuxtype/trunk/src/SDL_extras.c
===================================================================
--- tuxtype/trunk/src/SDL_extras.c 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/SDL_extras.c 2009-02-10 22:58:31 UTC (rev 880)
@@ -255,70 +255,100 @@
Currently this works only with RGBA images, but this is largely to
make the (fast) pointer arithmetic work out; it could be easily
generalized to other image types. */
-SDL_Surface* Blend(SDL_Surface *S1,SDL_Surface *S2,float gamma)
+SDL_Surface* Blend(SDL_Surface* S1, SDL_Surface* S2, float gamma)
{
- SDL_PixelFormat *fmt1,*fmt2;
- Uint8 r1,r2,g1,g2,b1,b2,a1,a2;
- SDL_Surface *tmpS,*ret;
- Uint32 *cpix1,*epix1,*cpix2,*epix2;
+ SDL_PixelFormat *fmt1, *fmt2;
+ Uint8 r1, r2, g1, g2, b1, b2, a1, a2;
+ SDL_Surface *tmpS, *ret;
+ Uint32 *cpix1, *epix1, *cpix2, *epix2;
float gamflip;
- gamflip = 1.0-gamma;
- if (gamma < 0 || gamflip < 0) {
+ if (!S1)
+ return NULL;
+
+ fmt1 = fmt2 = NULL;
+ tmpS = ret = NULL;
+
+ gamflip = 1.0 - gamma;
+ if (gamma < 0 || gamflip < 0)
+ {
perror("gamma must be between 0 and 1");
exit(0);
}
+
fmt1 = S1->format;
- if (fmt1->BitsPerPixel != 32) {
+
+ if (fmt1 && fmt1->BitsPerPixel != 32)
+ {
perror("This works only with RGBA images");
return S1;
}
- if (S2 != NULL) {
+ if (S2 != NULL)
+ {
fmt2 = S2->format;
- if (fmt2->BitsPerPixel != 32) {
- perror("This works only with RGBA images");
- return S1;
+ if (fmt2->BitsPerPixel != 32)
+ {
+ perror("This works only with RGBA images");
+ return S1;
}
// Check that both images have the same width dimension
- if (S1->w != S2->w) {
+ if (S1->w != S2->w)
+ {
printf("S1->w %d, S2->w %d; S1->h %d, S2->h %d\n",
- S1->w,S2->w,S1->h,S2->h);
+ S1->w, S2->w, S1->h, S2->h);
printf("Both images must have the same width dimensions\n");
return S1;
}
}
- tmpS = SDL_ConvertSurface(S1,fmt1,SDL_SWSURFACE);
- SDL_LockSurface(tmpS);
+ tmpS = SDL_ConvertSurface(S1, fmt1, SDL_SWSURFACE);
+ if (tmpS == NULL)
+ {
+ perror("SDL_ConvertSurface() failed");
+ return S1;
+ }
+ if (-1 == SDL_LockSurface(tmpS))
+ {
+ perror("SDL_LockSurface() failed");
+ return S1;
+ }
+
// We're going to go through the pixels in reverse order, to start
// from the bottom of each image. That way, we can blend things that
// are not of the same height and have them align at the bottom.
// So the "ending pixel" (epix) will be before the first pixel, and
// the current pixel (cpix) will be the last pixel.
- epix1 = (Uint32*) tmpS->pixels-1;
- cpix1 = epix1 + tmpS->w*tmpS->h;
- if (S2 != NULL) {
- SDL_LockSurface(S2);
- epix2 = (Uint32*) S2->pixels-1;
- cpix2 = epix2 + S2->w*S2->h;
- } else {
+ epix1 = (Uint32*) tmpS->pixels - 1;
+ cpix1 = epix1 + tmpS->w * tmpS->h;
+ if (S2 != NULL
+ && (SDL_LockSurface(S2) != -1))
+ {
+ epix2 = (Uint32*) S2->pixels - 1;
+ cpix2 = epix2 + S2->w * S2->h;
+ }
+ else
+ {
epix2 = epix1;
cpix2 = cpix1;
}
- for (; cpix1 > epix1; cpix1--,cpix2--) {
- SDL_GetRGBA(*cpix1,fmt1,&r1,&g1,&b1,&a1);
- a1 = gamma*a1;
- if (S2 != NULL && cpix2 > epix2) {
- SDL_GetRGBA(*cpix2,fmt2,&r2,&g2,&b2,&a2);
- r1 = gamma*r1 + gamflip*r2;
- g1 = gamma*g1 + gamflip*g2;
- b1 = gamma*b1 + gamflip*b2;
- a1 += gamflip*a2;
+ for (; cpix1 > epix1; cpix1--, cpix2--)
+ {
+ SDL_GetRGBA(*cpix1, fmt1, &r1, &g1, &b1, &a1);
+ a1 = gamma * a1;
+ if (S2 != NULL && cpix2 > epix2)
+ {
+ SDL_GetRGBA(*cpix2, fmt2, &r2, &g2, &b2, &a2);
+ r1 = gamma * r1 + gamflip * r2;
+ g1 = gamma * g1 + gamflip * g2;
+ b1 = gamma * b1 + gamflip * b2;
+ a1 += gamflip * a2;
}
*cpix1 = SDL_MapRGBA(fmt1,r1,g1,b1,a1);
}
+
SDL_UnlockSurface(tmpS);
+
if (S2 != NULL)
SDL_UnlockSurface(S2);
@@ -385,7 +415,7 @@
/* background. The appearance can be tuned by adjusting the number of */
/* background copies and the offset where the foreground text is */
/* finally written (see below). */
-SDL_Surface* BlackOutline(const char *t, TTF_Font *font, SDL_Color *c)
+SDL_Surface* BlackOutline(const char *t, const TTF_Font *font, const SDL_Color *c)
{
SDL_Surface* out = NULL;
SDL_Surface* black_letters = NULL;
@@ -419,7 +449,7 @@
black_letters = SDLPango_CreateSurfaceDraw(context);
}
else {
- black_letters = TTF_RenderUTF8_Blended(font, t, black);
+ black_letters = TTF_RenderUTF8_Blended((TTF_Font*)font, t, black);
}
#endif
@@ -468,7 +498,7 @@
}
else
{
- white_letters = TTF_RenderUTF8_Blended(font, t, *c);
+ white_letters = TTF_RenderUTF8_Blended((TTF_Font*)font, t, *c);
}
#endif
@@ -515,7 +545,7 @@
if (!black_letters)
{
- fprintf (stderr, "Warning - BlackOutline_Unicode() could not create image for %S\n", t);
+ fprintf (stderr, "Warning - BlackOutline_Unicode() could not create image for %S\n", (wchar_t*)t);
return NULL;
}
@@ -557,7 +587,7 @@
}
-SDL_Surface* BlackOutline_w(wchar_t* t, const TTF_Font* font, const SDL_Color* c, int size)
+SDL_Surface* BlackOutline_w(const wchar_t* t, const TTF_Font* font, const SDL_Color* c, int size)
{
wchar_t wchar_tmp[1024];
char tmp[1024];
Modified: tuxtype/trunk/src/SDL_extras.h
===================================================================
--- tuxtype/trunk/src/SDL_extras.h 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/SDL_extras.h 2009-02-10 22:58:31 UTC (rev 880)
@@ -42,16 +42,16 @@
void SwitchScreenMode(void);
int WaitForKeypress(void);
SDL_Surface* Blend(SDL_Surface *S1, SDL_Surface *S2,float gamma);
-SDL_Surface *zoom(SDL_Surface * src, int new_w, int new_h);
+SDL_Surface* zoom(SDL_Surface * src, int new_w, int new_h);
void ScaleDPIforFS(void);
void ResetDPI(void);
/* These functions are the only code in the program that directly use SDL_Pango */
/* If SDL_Pango not available, they fall back to SDL_ttf or do nothing, */
/* as appropriate. */
-SDL_Surface* BlackOutline(const char *t, TTF_Font* font, SDL_Color* c);
+SDL_Surface* BlackOutline(const char *t, const TTF_Font* font, const SDL_Color* c);
SDL_Surface* BlackOutline_Unicode(const Uint16* t, const TTF_Font* font, const SDL_Color* c);
-SDL_Surface* BlackOutline_w(wchar_t* t, const TTF_Font* font, const SDL_Color* c, int size);
+SDL_Surface* BlackOutline_w(const wchar_t* t, const TTF_Font* font, const SDL_Color* c, int size);
void init_SDLPango_Context();
void free_SDLPango_Context();
void reset_DPI_SDLPango_Context(float dpi_x, float dpi_y);
Modified: tuxtype/trunk/src/alphabet.c
===================================================================
--- tuxtype/trunk/src/alphabet.c 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/alphabet.c 2009-02-10 22:58:31 UTC (rev 880)
@@ -38,7 +38,7 @@
} uni_glyph;
/* These are the arrays for the red and white letters: */
-static uni_glyph char_glyphs[MAX_UNICODES] = {0, NULL, NULL};
+static uni_glyph char_glyphs[MAX_UNICODES] = {{0, NULL, NULL}};
/* An individual item in the list of unicode characters in the keyboard setup. */
/* Basically, just the Unicode value for the key and the finger used to type it. */
@@ -57,11 +57,10 @@
/* List with one entry for each typable character in keyboard setup - has the */
/* Unicode value of the key and the associated fingering. */
-static kbd_char keyboard_list[MAX_UNICODES] = {0, -1,0,0,-1};
+static kbd_char keyboard_list[MAX_UNICODES] = {{0, -1, {0}, 0, -1}};
-static TTF_Font* font = NULL;
/* Used for word list functions (see below): */
static int num_words;
@@ -74,12 +73,12 @@
/* Local function prototypes: */
static void gen_char_list(void);
static int add_char(wchar_t uc);
-static void set_letters(unsigned char* t);
-static void show_letters(void);
+//static void set_letters(signed char* t);
+//static void show_letters(void);
static void clear_keyboard(void);
static int unicode_in_key_list(wchar_t uni_char);
int check_needed_unicodes_str(const wchar_t* s);
-int map_keys(wchar_t wide_char,kbd_char* keyboard_entry);
+int map_keys(wchar_t wide_char, kbd_char* keyboard_entry);
@@ -95,7 +94,7 @@
/* all this does now is fiddle with the ALPHABET and FINGER arrays */
int LoadKeyboard(void)
{
- unsigned char fn[FNLEN];
+ char fn[FNLEN];
int found = 0;
clear_keyboard();
@@ -130,11 +129,11 @@
DEBUGCODE{fprintf(stderr, "fn = %s\n", fn);}
{
- unsigned char str[255];
+ char str[255];
wchar_t wide_str[255];
- FILE* f;
- int i = 0, j = 0, k = 0;
+ FILE* f = NULL;
+ int k = 0;
f = fopen( fn, "r" );
@@ -144,18 +143,19 @@
return 0;
}
-
do
{
- fscanf( f, "%[^\n]\n", str);
+ int fscanf_result = fscanf( f, "%[^\n]\n", str);
+
+ if (fscanf_result == EOF)
+ break;
/* Convert to wcs from UTF-8, if needed; */
- //mbstowcs(wide_str, str, strlen(str) + 1);
ConvertFromUTF8(wide_str, str, 255);
/* Line must have 3 chars (if more, rest are ignored) */
/* Format is: FINGER|Char e.g "3|d" */
/* wide_str[0] == finger used to type char */
- /* wide_str[1] =='|'
+ /* wide_str[1] =='|' */
/* wide_str[2] == Unicode value of character */
/* FIXME - this might be a good place to use a */
@@ -170,7 +170,7 @@
{
DEBUGCODE
{
- fprintf(stderr, "Adding key: Unicode char = '%C'\tUnicode value = %d\tfinger = %d\n",
+ fprintf(stderr, "Adding key: Unicode char = '%C'\tUnicode value = %d\tfinger = %ld\n",
wide_str[2], wide_str[2], wcstol(&wide_str[0], NULL, 0));
}
@@ -287,15 +287,14 @@
}
-void GetKeyShift(int index, char *buf)
+void GetKeyShift(int index, char* buf)
{
- if(keyboard_list[index].shift==0)
- sprintf(buf,"keyboard/keyboard_None.png");
- else
- if(keyboard_list[index].shift==1)
- sprintf(buf,"keyboard/keyboard_D00.png");
- else
- sprintf(buf,"keyboard/keyboard_D12.png", settings.default_data_path);
+ if(keyboard_list[index].shift == 0)
+ sprintf(buf,"keyboard/keyboard_None.png");
+ else if(keyboard_list[index].shift == 1)
+ sprintf(buf,"keyboard/keyboard_D00.png");
+ else
+ sprintf(buf,"%s/images/keyboard/keyboard_D12.png", settings.default_data_path);
}
@@ -325,57 +324,57 @@
-/* FIXME dead code but could be useful*/
-static void show_letters(void)
-{
- int i, l = 0;
- SDL_Surface* abit;
- SDL_Rect dst;
- int stop = 0;
- unsigned char t[255];
+// /* FIXME dead code but could be useful*/
+// static void show_letters(void)
+// {
+// int i, l = 0;
+// SDL_Surface* abit;
+// SDL_Rect dst;
+// int stop = 0;
+// unsigned char t[255];
+//
+// for (i=0; i<256; i++)
+// if (ALPHABET[i])
+// t[l++]=i;
+//
+// t[l] = 0;
+//
+// abit = BlackOutline(t, font, &white);
+//
+// dst.x = 320 - (abit->w / 2);
+// dst.y = 275;
+// dst.w = abit->w;
+// dst.h = abit->h;
+//
+// SDL_BlitSurface(abit, NULL, screen, &dst);
+//
+// SDL_FreeSurface(abit);
+//
+// abit = BlackOutline("Alphabet Set To:", font, &white);
+// dst.x = 320 - (abit->w / 2);
+// dst.y = 200;
+// dst.w = abit->w;
+// dst.h = abit->h;
+//
+// SDL_BlitSurface(abit, NULL, screen, &dst);
+//
+// SDL_UpdateRect(screen, 0, 0, 0 ,0);
+//
+// while (!stop)
+// while (SDL_PollEvent(&event))
+// switch (event.type) {
+// case SDL_QUIT:
+// exit(0);
+// case SDL_KEYDOWN:
+// case SDL_MOUSEBUTTONDOWN:
+// stop = 1;
+// }
+//
+// SDL_FreeSurface(abit);
+// }
- for (i=0; i<256; i++)
- if (ALPHABET[i])
- t[l++]=i;
- t[l] = 0;
- abit = BlackOutline(t, font, &white);
-
- dst.x = 320 - (abit->w / 2);
- dst.y = 275;
- dst.w = abit->w;
- dst.h = abit->h;
-
- SDL_BlitSurface(abit, NULL, screen, &dst);
-
- SDL_FreeSurface(abit);
-
- abit = BlackOutline("Alphabet Set To:", font, &white);
- dst.x = 320 - (abit->w / 2);
- dst.y = 200;
- dst.w = abit->w;
- dst.h = abit->h;
-
- SDL_BlitSurface(abit, NULL, screen, &dst);
-
- SDL_UpdateRect(screen, 0, 0, 0 ,0);
-
- while (!stop)
- while (SDL_PollEvent(&event))
- switch (event.type) {
- case SDL_QUIT:
- exit(0);
- case SDL_KEYDOWN:
- case SDL_MOUSEBUTTONDOWN:
- stop = 1;
- }
-
- SDL_FreeSurface(abit);
-}
-
-
-
/* Returns a random Unicode char from the char_glyphs list: */
/* --- get a letter --- */
wchar_t GetRandLetter(void)
@@ -485,7 +484,8 @@
int GenerateWordList(const char* wordFn)
{
int j;
- unsigned char temp_word[FNLEN];
+ int ret;
+ char temp_word[FNLEN];
wchar_t temp_wide_word[FNLEN];
size_t length;
@@ -512,11 +512,12 @@
DEBUGCODE { fprintf(stderr, "WORD FILE OPENNED @ %s\n", wordFn); }
/* ignore the title (i.e. first line) */
- fscanf( wordFile, "%[^\n]\n", temp_word);
+ /* (compiler complains unless we inspect return value) */
+ ret = fscanf( wordFile, "%[^\n]\n", temp_word);
while (!feof(wordFile) && (num_words < MAX_NUM_WORDS))
{
- fscanf( wordFile, "%[^\n]\n", temp_word);
+ ret = fscanf( wordFile, "%[^\n]\n", temp_word);
DEBUGCODE {fprintf(stderr, "temp_word = %s\n", temp_word);}
for (j = 0; j < strlen(temp_word); j++)
@@ -526,10 +527,8 @@
}
/* Convert from UTF-8 to wcs and make sure word is usable: */
- /* NOTE need to add one to length arg so terminating '\0' gets added: */
- //length = mbstowcs(temp_wide_word, temp_word, strlen(temp_word) + 1);
+ length = ConvertFromUTF8(temp_wide_word, temp_word, FNLEN);
- length = ConvertFromUTF8(temp_wide_word, temp_word, FNLEN);
DOUT(length);
if (length == -1) /* Means invalid UTF-8 sequence or conversion failed */
@@ -582,11 +581,11 @@
DOUT(num_words);
-// if (num_words == 0)
-// UseAlphabet( );
-
- fclose(wordFile);
-
+ if (wordFile)
+ {
+ fclose(wordFile);
+ wordFile = NULL;
+ }
/* Make list of all unicode characters used in word list: */
/* (we use this to check to make sure all are "typable"); */
gen_char_list();
@@ -709,7 +708,7 @@
/* successfully rendered based on the Unicode values given in keyboard.lst. */
/* If not, then the list contains characters that will not display and (if */
/* keyboard.lst is correct) cannot be typed. Most likely, this means that */
-/* keyboard.lst is not correct.
+/* keyboard.lst is not correct. */
/* Returns 1 if all needed chars found, 0 otherwise. */
int CheckNeededGlyphs(void)
{
@@ -1178,7 +1177,7 @@
case 'B':new.y+=36;new.x+=23;break;
case 'C':new.y+=66;new.x+=33;break;
case 'D':new.y+=96;new.x+=23;break;
- case 'E':new.y+126;break;
+ case 'E':new.y+=126; break;
default: render=0;break;
}
if(!render)
@@ -1206,58 +1205,63 @@
}
-void updatekeylist(int key,char ch)
+void updatekeylist(int key, char ch)
{
- wchar_t;
- keyboard_list[key].latin_char=ch;
- wchar_t wtmp=ch;
- map_keys(wtmp,&keyboard_list[key]);
+ keyboard_list[key].latin_char = ch;
+ wchar_t wtmp = ch;
+ map_keys(wtmp, &keyboard_list[key]);
}
-/* FIXME get rid of UTF8 conversion - the unicode value is just a uint16, we should */
-/* definitely be able to figure out how to get it written into a file -DSB */
+
+/* FIXME this is _always_ going to fail - everything in DATA_PREFIX */
+/* is supposed to be read-only as far as a regular user is concerned. */
+/* Not sure why would want the program to be able to modify the */
+/* keyboard map, anyway - DSB. */
void savekeyboard(void)
{
- unsigned char fn[FNLEN];
- FILE *fp;
- int i;
- wchar_t tmp[2];
- char buf[FNLEN];
- tmp[1]=0;
- if(!settings.use_english)
- sprintf(fn , "%s/keyboard.lst", settings.theme_data_path);
- else
- sprintf(fn , "%s/keyboard.lst", settings.default_data_path);
+ char fn[FNLEN];
+ FILE* fp = NULL;
+ int i = 0;
+ wchar_t uni;
- fp=fopen(fn,"w");
- if (fp == NULL)
- {
- LOG("savekeyboard() - could not open keyboard.lst\n");
- return 0;
- }
- for(i=0;i<num_chars_used;i++)
- {
- tmp[0]=keyboard_list[i].unicode_value;
- /**********fprintf(fp,"%d|%C\n",keyboard_list[i].finger,keyboard_list[i].unicode_value); doesnt work, so the unicode value is converted into a char string*/
- ConvertToUTF8(tmp, buf, FNLEN);
- if(keyboard_list[i].finger==-1)
- {
- fprintf(fp,"%s\n",buf);
- }
- else
- if(keyboard_list[i].latin_char==-1)
- {
- fprintf(fp,"%d|%s\n",keyboard_list[i].finger,buf);
- }
- else
- {
- fprintf(fp,"%d|%s|%c\n",keyboard_list[i].finger,buf,keyboard_list[i].latin_char);
- }
- }
- fclose(fp);
+ if(!settings.use_english)
+ sprintf(fn , "%s/keyboard.lst", settings.theme_data_path);
+ else
+ sprintf(fn , "%s/keyboard.lst", settings.default_data_path);
+
+ /* We aren't supposed to be able to modify DATA! */
+ fp = fopen(fn,"w");
+ if (fp == NULL)
+ {
+ LOG("savekeyboard() - could not open keyboard.lst for saving\n");
+ return;
+ }
+
+ for(i = 0; i < num_chars_used; i++)
+ {
+ uni = (wchar_t)keyboard_list[i].unicode_value;
+
+ if(keyboard_list[i].finger == -1)
+ {
+ fprintf(fp,"%C\n", uni);
+ }
+ else if(keyboard_list[i].latin_char == -1)
+ {
+ fprintf(fp,"%d|%C\n",keyboard_list[i].finger, uni);
+ }
+ else
+ {
+ fprintf(fp,"%d|%C|%c\n", keyboard_list[i].finger, uni, keyboard_list[i].latin_char);
+ }
+ }
+ fclose(fp);
}
+
+
/****************************************************************/
+
+
/****************************************************/
/* */
/* Local ("private") functions: */
@@ -1310,7 +1314,7 @@
/* Can be called multiple times on different strings */
/* to accumulate entire repertoire - call ResetCharList() */
/* to start over */
-void GenCharListFromString(const unsigned char* UTF8_str)
+void GenCharListFromString(const char* UTF8_str)
{
int i = 0;
wchar_t wchar_buf[MAX_UNICODES];
@@ -1332,24 +1336,25 @@
-/* FIXME this function is currently dead code */
-/* --- setup the alphabet --- */
-static void set_letters(unsigned char *t) {
- int i;
+// /* FIXME this function is currently dead code */
+// /* --- setup the alphabet --- */
+// static void set_letters(char *t)
+// {
+// int i;
+//
+// ALPHABET_SIZE = 0;
+// for (i=0; i<256; i++)
+// ALPHABET[i]=0;
+//
+// for (i=0; i<strlen(t); i++)
+// if (t[i]!=' ') {
+// ALPHABET[(int)t[i]]=1;
+// ALPHABET_SIZE++;
+// }
+// }
- ALPHABET_SIZE = 0;
- for (i=0; i<256; i++)
- ALPHABET[i]=0;
- for (i=0; i<strlen(t); i++)
- if (t[i]!=' ') {
- ALPHABET[(int)t[i]]=1;
- ALPHABET_SIZE++;
- }
-}
-
-
/* Checks to see if the argument is already in the list and adds */
/* it if necessary. Returns 1 if char added, 0 if already in list, */
/* -1 if list already up to maximum size: */
Modified: tuxtype/trunk/src/convert_utf.c
===================================================================
--- tuxtype/trunk/src/convert_utf.c 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/convert_utf.c 2009-02-10 22:58:31 UTC (rev 880)
@@ -50,24 +50,18 @@
/* NOTE although we *should* be just able to pass "wchar_t" as the out_type, */
/* iconv_open() segfaults on Windows if this is done - grrr.... */
#ifdef WIN32
- DEBUGCODE {fprintf(stderr, "WIN32, using UTF-16LE for wchar_t\n");}
conv_descr = iconv_open("UTF-16LE", "UTF-8");
#else
- DEBUGCODE {fprintf(stderr, "Using wchar_t for wchar_t\n");}
conv_descr = iconv_open("wchar_t", "UTF-8");
#endif
bytes_converted = iconv(conv_descr,
- &UTF8_word, &in_length,
- &wchar_start, &out_length);
- LOG("completed iconv()\n");
-
+ (char**) &UTF8_word, &in_length,
+ (char**) &wchar_start, &out_length);
iconv_close(conv_descr);
-
wcsncpy(wide_word, temp_wchar, max_length);
DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): wide_word = %S\n", wide_word);}
- DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): temp_wchar = %S\n", temp_wchar);}
return wcslen(wide_word);
}
@@ -106,25 +100,18 @@
/* NOTE although we *should* be just able to pass "wchar_t" as the in_type, */
/* iconv_open() segfaults on Windows if this is done - grrr.... */
#ifdef WIN32
- DEBUGCODE {fprintf(stderr, "WIN32, using UTF-16LE for wchar_t\n");}
conv_descr = iconv_open("UTF-8", "UTF-16LE");
#else
- DEBUGCODE {fprintf(stderr, "Using wchar_t for wchar_t\n");}
conv_descr = iconv_open("UTF-8", "wchar_t");
#endif
bytes_converted = iconv(conv_descr,
- &wide_word, &in_length,
-// &UTF8_word, &out_length);
- &UTF8_Start, &out_length);
- LOG("completed iconv()\n");
-
+ (char**) &wide_word, &in_length,
+ (char**) &UTF8_Start, &out_length);
iconv_close(conv_descr);
-
strncpy(UTF8_word, temp_UTF8, max_length);
DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): UTF8_word = %s\n", UTF8_word);}
- DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): temp_UTF8 = %s\n", temp_UTF8);}
return strlen(UTF8_word);
}
Modified: tuxtype/trunk/src/funcs.h
===================================================================
--- tuxtype/trunk/src/funcs.h 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/funcs.h 2009-02-10 22:58:31 UTC (rev 880)
@@ -31,7 +31,7 @@
void ClearWordList(void);
void FreeLetters(void);
int GenerateWordList(const char* wordFn);
-void GenCharListFromString(const unsigned char* UTF8_str);
+void GenCharListFromString(const char* UTF8_str);
void ResetCharList(void);
wchar_t GetLetter(void);
wchar_t* GetWord(void);
@@ -42,6 +42,7 @@
int RenderLetters(const TTF_Font* letter_font);
int GetIndex(wchar_t uni_char);
void GetKeyShift(int index, char *buf);
+int GetShift(int i);
void GetKeyPos(int index, char *buf);
void GetWrongKeyPos(int index, char *buf);
//int map_keys(wchar_t *wide_str,keymap key);
Deleted: tuxtype/trunk/src/iconv_string.c
===================================================================
--- tuxtype/trunk/src/iconv_string.c 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/iconv_string.c 2009-02-10 22:58:31 UTC (rev 880)
@@ -1,154 +0,0 @@
-/* Copyright (C) 1999-2001, 2003 Bruno Haible.
- This file is not part of the GNU LIBICONV Library.
- This file is put into the public domain. */
-
-#include "iconv_string.h"
-#include <iconv.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define tmpbufsize 4096
-
-int iconv_string (const char* tocode, const char* fromcode,
- const char* start, const char* end,
- char** resultp, size_t* lengthp)
-{
- iconv_t cd = iconv_open(tocode,fromcode);
- size_t length;
- char* result;
- if (cd == (iconv_t)(-1)) {
- if (errno != EINVAL)
- return -1;
- /* Unsupported fromcode or tocode. Check whether the caller requested
- autodetection. */
- if (!strcmp(fromcode,"autodetect_utf8")) {
- int ret;
- /* Try UTF-8 first. There are very few ISO-8859-1 inputs that would
- be valid UTF-8, but many UTF-8 inputs are valid ISO-8859-1. */
- ret = iconv_string(tocode,"UTF-8",start,end,resultp,lengthp);
- if (!(ret < 0 && errno == EILSEQ))
- return ret;
- ret = iconv_string(tocode,"ISO-8859-1",start,end,resultp,lengthp);
- return ret;
- }
- if (!strcmp(fromcode,"autodetect_jp")) {
- int ret;
- /* Try 7-bit encoding first. If the input contains bytes >= 0x80,
- it will fail. */
- ret = iconv_string(tocode,"ISO-2022-JP-2",start,end,resultp,lengthp);
- if (!(ret < 0 && errno == EILSEQ))
- return ret;
- /* Try EUC-JP next. Short SHIFT_JIS inputs may come out wrong. This
- is unavoidable. People will condemn SHIFT_JIS.
- If we tried SHIFT_JIS first, then some short EUC-JP inputs would
- come out wrong, and people would condemn EUC-JP and Unix, which
- would not be good. */
- ret = iconv_string(tocode,"EUC-JP",start,end,resultp,lengthp);
- if (!(ret < 0 && errno == EILSEQ))
- return ret;
- /* Finally try SHIFT_JIS. */
- ret = iconv_string(tocode,"SHIFT_JIS",start,end,resultp,lengthp);
- return ret;
- }
- if (!strcmp(fromcode,"autodetect_kr")) {
- int ret;
- /* Try 7-bit encoding first. If the input contains bytes >= 0x80,
- it will fail. */
- ret = iconv_string(tocode,"ISO-2022-KR",start,end,resultp,lengthp);
- if (!(ret < 0 && errno == EILSEQ))
- return ret;
- /* Finally try EUC-KR. */
- ret = iconv_string(tocode,"EUC-KR",start,end,resultp,lengthp);
- return ret;
- }
- errno = EINVAL;
- return -1;
- }
- /* Determine the length we need. */
- {
- size_t count = 0;
- char tmpbuf[tmpbufsize];
- const char* inptr = start;
- size_t insize = end-start;
- while (insize > 0) {
- char* outptr = tmpbuf;
- size_t outsize = tmpbufsize;
- size_t res = iconv(cd,&inptr,&insize,&outptr,&outsize);
- if (res == (size_t)(-1) && errno != E2BIG) {
- if (errno == EINVAL)
- break;
- else {
- int saved_errno = errno;
- iconv_close(cd);
- errno = saved_errno;
- return -1;
- }
- }
- count += outptr-tmpbuf;
- }
- {
- char* outptr = tmpbuf;
- size_t outsize = tmpbufsize;
- size_t res = iconv(cd,NULL,NULL,&outptr,&outsize);
- if (res == (size_t)(-1)) {
- int saved_errno = errno;
- iconv_close(cd);
- errno = saved_errno;
- return -1;
- }
- count += outptr-tmpbuf;
- }
- length = count;
- }
- if (lengthp != NULL)
- *lengthp = length;
- if (resultp == NULL) {
- iconv_close(cd);
- return 0;
- }
- result = (*resultp == NULL ? malloc(length) : realloc(*resultp,length));
- *resultp = result;
- if (length == 0) {
- iconv_close(cd);
- return 0;
- }
- if (result == NULL) {
- iconv_close(cd);
- errno = ENOMEM;
- return -1;
- }
- iconv(cd,NULL,NULL,NULL,NULL); /* return to the initial state */
- /* Do the conversion for real. */
- {
- const char* inptr = start;
- size_t insize = end-start;
- char* outptr = result;
- size_t outsize = length;
- while (insize > 0) {
- size_t res = iconv(cd,&inptr,&insize,&outptr,&outsize);
- if (res == (size_t)(-1)) {
- if (errno == EINVAL)
- break;
- else {
- int saved_errno = errno;
- iconv_close(cd);
- errno = saved_errno;
- return -1;
- }
- }
- }
- {
- size_t res = iconv(cd,NULL,NULL,&outptr,&outsize);
- if (res == (size_t)(-1)) {
- int saved_errno = errno;
- iconv_close(cd);
- errno = saved_errno;
- return -1;
- }
- }
- if (outsize != 0) abort();
- }
- iconv_close(cd);
- return 0;
-}
Deleted: tuxtype/trunk/src/iconv_string.h
===================================================================
--- tuxtype/trunk/src/iconv_string.h 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/iconv_string.h 2009-02-10 22:58:31 UTC (rev 880)
@@ -1,47 +0,0 @@
-/* Copyright (C) 1999-2001 Bruno Haible.
- This file is not part of the GNU LIBICONV Library.
- This file is put into the public domain. */
-
-/*
- * This C function converts an entire string from one encoding to another,
- * using iconv. Easier to use than iconv() itself, and supports autodetect
- * encodings on input.
- *
- * int iconv_string (const char* tocode, const char* fromcode,
- * const char* start, const char* end,
- * char** resultp, size_t* lengthp)
- *
- * Converts a memory region given in encoding FROMCODE to a new memory
- * region in encoding TOCODE. FROMCODE and TOCODE are as for iconv_open(3),
- * except that FROMCODE may be one of the values
- * "autodetect_utf8" supports ISO-8859-1 and UTF-8
- * "autodetect_jp" supports EUC-JP, ISO-2022-JP-2 and SHIFT_JIS
- * "autodetect_kr" supports EUC-KR and ISO-2022-KR
- * The input is in the memory region between start (inclusive) and end
- * (exclusive). If resultp is not NULL, the output string is stored in
- * *resultp; malloc/realloc is used to allocate the result.
- *
- * This function does not treat zero characters specially.
- *
- * Return value: 0 if successful, otherwise -1 and errno set. Particular
- * errno values: EILSEQ and ENOMEM.
- *
- * Example:
- * const char* s = ...;
- * char* result = NULL;
- * if (iconv_string("UCS-4-INTERNAL", "autodetect_utf8",
- * s, s+strlen(s)+1, &result, NULL) < 0)
- * perror("iconv_string");
- *
- */
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern int iconv_string (const char* tocode, const char* fromcode, const char* start, const char* end, char** resultp, size_t* lengthp);
-
-#ifdef __cplusplus
-}
-#endif
Modified: tuxtype/trunk/src/practice.c
===================================================================
--- tuxtype/trunk/src/practice.c 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/practice.c 2009-02-10 22:58:31 UTC (rev 880)
@@ -103,11 +103,10 @@
static int find_next_wrap(const wchar_t* wstr, const TTF_Font* font, int width);
static void recalc_positions(void);
static void calc_font_sizes(void);
-static void next_letter(wchar_t *t, int c);
+static void display_next_letter(wchar_t* str, Uint16 index);
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(char t);
+//static void show(char t);
SDL_Surface* GetKeypress1(int index);
SDL_Surface* GetKeypress2(int index);
SDL_Surface* GetWrongKeypress(int index);
@@ -137,7 +136,6 @@
float accuracy = 0;
int cur_phrase = 0;
int keytimes[MAX_PHRASE_LENGTH] = {0};
- int next_line = 0;
char time_str[20];
char chars_typed_str[20];
char cpm_str[20];
@@ -375,8 +373,8 @@
} /* ----------- End of switch(state) statement-------------- */
- /* This blits "Next letter %c" onto the screen - confusing! */
- next_letter(phrases[cur_phrase], cursor);
+ /* This blits the next character onto the screen in a large font: */
+ display_next_letter(phrases[cur_phrase], cursor);
while (SDL_PollEvent(&event))
{
@@ -733,7 +731,6 @@
{
/* Draw Tux celebrating: */
{
- int i = 0;
int done = 0;
PlaySound(cheer);
@@ -858,7 +855,6 @@
{
int i;
char fn[FNLEN];
- char let[5];
int load_failed = 0;
DEBUGCODE { printf("Entering practice_load_media\n"); }
@@ -1219,24 +1215,24 @@
}
-/* looks like dead code: */
-static void show(char t)
-{
- SDL_Rect dst;
- SDL_Surface* s = NULL;
+// /* looks like dead code: */
+// static void show(char t)
+// {
+// SDL_Rect dst;
+// SDL_Surface* s = NULL;
+//
+// s = GetWhiteGlyph((int)t);
+// if (!s)
+// return;
+//
+// dst.x = 320 - (s->w/2);
+// dst.y = 100;
+// dst.w = s->w;
+// dst.h = s->h;
+// SDL_BlitSurface(s, NULL, screen, &dst);
+// }
- s = GetWhiteGlyph((int)t);
- if (!s)
- return;
- dst.x = 320 - (s->w/2);
- dst.y = 100;
- dst.w = s->w;
- dst.h = s->h;
- SDL_BlitSurface(s, NULL, screen, &dst);
-}
-
-
/* Looks for phrases.txt in theme, then in default if not found, */
/* loads it into phrases[][] array. Returns number of phrases */
/* successfully loaded. */
@@ -1280,10 +1276,14 @@
/* NOTE we need to convert to wchar_t so just fscanf won't work! */
while (!feof(fp) && num_phrases <= MAX_PHRASES)
{
- fscanf(fp, "%[^\n]\n", buf);
- ConvertFromUTF8(phrases[num_phrases], buf, MAX_PHRASE_LENGTH);
- DEBUGCODE {printf("phrase %d:\t%S\n", num_phrases, phrases[num_phrases]);}
- num_phrases++;
+ /* Similar check to above but compiler complains unless we */
+ /* inspect return value of fscanf(): */
+ if (EOF != fscanf(fp, "%[^\n]\n", buf))
+ {
+ ConvertFromUTF8(phrases[num_phrases], buf, MAX_PHRASE_LENGTH);
+ DEBUGCODE {printf("phrase %d:\t%S\n", num_phrases, phrases[num_phrases]);}
+ num_phrases++;
+ }
}
if (num_phrases > MAX_PHRASES)
@@ -1370,7 +1370,7 @@
/* Need to convert to UTF8 because couldn't get UNICODE version to work: */
ConvertToUTF8(buf, UTF8buf, MAX_PHRASE_LENGTH);
/* Now check width of string: */
- if (-1 == TTF_SizeUTF8(font, UTF8buf, &test_w, NULL))
+ if (-1 == TTF_SizeUTF8((TTF_Font*)font, UTF8buf, &test_w, NULL))
{
/* An error occurred: */
return -1;
@@ -1413,66 +1413,18 @@
}
-static void print_at(const wchar_t *pphrase, int wrap, int x, int y)
-{
- int z = 0;
- SDL_Surface* tmp;
- SDL_Rect dst;
- dst.x = x;
- dst.y = y;
- //font = LoadFont(settings.theme_font_name, 30);
- DEBUGCODE
- {
- printf("\n\n\nEntering print_at with : %S\n",pphrase);
- printf("wrap = %d\t wsclen() = %d\n", wrap, wcslen(pphrase));
- }
-
-
- if (wrap == wcslen(pphrase))
- {
- LOG("Wrap not needed\n");
-
- tmp = BlackOutline_w(pphrase, medfont, &white, wrap);
- if (tmp)
- {
- SDL_BlitSurface(tmp, NULL, screen, &dst);
- SDL_FreeSurface(tmp);
- tmp = NULL;
- }
- }
- else
- {
- LOG("Line length exceeded - wrap required\n");
-
- tmp = BlackOutline_w(pphrase, medfont, &white, wrap + 1);
- if (tmp)
- {
- SDL_BlitSurface(tmp, NULL, screen, &dst);
- dst.y += tmp->h; // move "cursor" down for next line
- SDL_FreeSurface(tmp);
- tmp = NULL;
- }
-
- tmp = BlackOutline_w(pphrase+wrap+1, medfont, &white, wcslen(pphrase));
- if (tmp)
- {
- SDL_BlitSurface(tmp, NULL, screen, &dst);
- SDL_FreeSurface(tmp);
- }
- }
- //TTF_CloseFont(font);
- // DEBUGCODE { exit(-1); }
- DEBUGCODE { printf("Leaving print_at \n\n\n"); }
-}
-
+/* FIXME this isn't very safe because index could be out of allocated string, */
+/* and there a very good way to test for this within this function. */
/* Displays the next letter to be typed in a large font */
-static void next_letter(wchar_t *t, int c)
+static void display_next_letter(wchar_t *str, Uint16 index)
{
- int i;
Uint16 ltr[2];
SDL_Surface* s = NULL;
- ltr[0] = t[c];
+ if (!str || (index >= MAX_PHRASE_LENGTH))
+ return;
+
+ ltr[0] = str[index];
ltr[1] = '\0';
s = BlackOutline_Unicode(ltr, bigfont, &white);
@@ -1486,6 +1438,7 @@
}
}
+
SDL_Surface* GetKeypress1(int index)
{
char buf[50];
@@ -1493,6 +1446,7 @@
return (LoadImage(buf, IMG_ALPHA));
}
+
SDL_Surface* GetWrongKeypress(int index)
{
char buf[50];
@@ -1500,6 +1454,7 @@
return (LoadImage(buf, IMG_ALPHA));
}
+
SDL_Surface* GetKeypress2(int index)
{
char buf[50];
Modified: tuxtype/trunk/src/scripting.c
===================================================================
--- tuxtype/trunk/src/scripting.c 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/scripting.c 2009-02-10 22:58:31 UTC (rev 880)
@@ -19,6 +19,7 @@
#include "scripting.h"
#define MAX_LESSONS 100
#include "SDL_extras.h"
+#include "convert_utf.h"
/* Local function prototypes: */
static void clear_items(itemType* i);
@@ -132,8 +133,8 @@
int num_scripts = 0;
int found = 0;
int i;
- unsigned char script_path[FNLEN];
- unsigned char script_filenames[MAX_LESSONS][200];
+ char script_path[FNLEN];
+ char script_filenames[MAX_LESSONS][200];
char fn[FNLEN];
DIR* script_dir = NULL;
@@ -537,7 +538,11 @@
do
{
- fscanf(f, "%[^\n]\n", str);
+ /* Compiler complains if we don't inspect result of fscanf() */
+ int fscanf_result = fscanf(f, "%[^\n]\n", str);
+ if (fscanf_result == EOF)
+ break;
+
if (strncmp("<script", str, 7) == 0)
{
/* -- allocate space for the lesson info -- */
@@ -1260,7 +1265,7 @@
case itemPRAC:
{
wchar_t wide_buf[FNLEN];
- ConvertFromUTF8(wide_buf, curItem->data);
+ ConvertFromUTF8(wide_buf, curItem->data, FNLEN);
if (curItem->goal > 0)
{
//printf( "goal is %d\n", curItem->goal );
Modified: tuxtype/trunk/src/theme.c
===================================================================
--- tuxtype/trunk/src/theme.c 2009-02-09 20:55:25 UTC (rev 879)
+++ tuxtype/trunk/src/theme.c 2009-02-10 22:58:31 UTC (rev 880)
@@ -49,9 +49,9 @@
int themes = 1;
int i;
- unsigned char fn[FNLEN];
- unsigned char themeNames[MAX_LANGUAGES][FNLEN];
- unsigned char themePaths[MAX_LANGUAGES][FNLEN];
+ char fn[FNLEN];
+ char themeNames[MAX_LANGUAGES][FNLEN];
+ char themePaths[MAX_LANGUAGES][FNLEN];
int old_use_english;
char old_theme_path[FNLEN];
More information about the Tux4kids-commits
mailing list