[Tux4kids-commits] r673 - in tuxtype/branches/tuxtype-soc-mh: . src

lummeh-guest at alioth.debian.org lummeh-guest at alioth.debian.org
Tue Aug 26 07:28:54 UTC 2008


Author: lummeh-guest
Date: 2008-08-26 07:28:53 +0000 (Tue, 26 Aug 2008)
New Revision: 673

Added:
   tuxtype/branches/tuxtype-soc-mh/src/ConvertUTF.c
   tuxtype/branches/tuxtype-soc-mh/src/ConvertUTF.h
   tuxtype/branches/tuxtype-soc-mh/src/Makefile.am
   tuxtype/branches/tuxtype-soc-mh/src/Makefile.in
   tuxtype/branches/tuxtype-soc-mh/src/SDLMain.h
   tuxtype/branches/tuxtype-soc-mh/src/SDL_extras.c
   tuxtype/branches/tuxtype-soc-mh/src/SDL_extras.h
   tuxtype/branches/tuxtype-soc-mh/src/alphabet.c
   tuxtype/branches/tuxtype-soc-mh/src/audio.c
   tuxtype/branches/tuxtype-soc-mh/src/compiler.h
   tuxtype/branches/tuxtype-soc-mh/src/funcs.h
   tuxtype/branches/tuxtype-soc-mh/src/gettext.c
   tuxtype/branches/tuxtype-soc-mh/src/globals.h
   tuxtype/branches/tuxtype-soc-mh/src/highscores.c
   tuxtype/branches/tuxtype-soc-mh/src/keyboard.lst
   tuxtype/branches/tuxtype-soc-mh/src/laser.c
   tuxtype/branches/tuxtype-soc-mh/src/laser.h
   tuxtype/branches/tuxtype-soc-mh/src/loaders.c
   tuxtype/branches/tuxtype-soc-mh/src/main.c
   tuxtype/branches/tuxtype-soc-mh/src/options.c
   tuxtype/branches/tuxtype-soc-mh/src/pause.c
   tuxtype/branches/tuxtype-soc-mh/src/phrases.txt
   tuxtype/branches/tuxtype-soc-mh/src/pixels.c
   tuxtype/branches/tuxtype-soc-mh/src/pixels.h
   tuxtype/branches/tuxtype-soc-mh/src/playgame.c
   tuxtype/branches/tuxtype-soc-mh/src/playgame.h
   tuxtype/branches/tuxtype-soc-mh/src/practice.c
   tuxtype/branches/tuxtype-soc-mh/src/profiles.c
   tuxtype/branches/tuxtype-soc-mh/src/profilesgui.c
   tuxtype/branches/tuxtype-soc-mh/src/scripting.c
   tuxtype/branches/tuxtype-soc-mh/src/scripting.h
   tuxtype/branches/tuxtype-soc-mh/src/setup.c
   tuxtype/branches/tuxtype-soc-mh/src/snow.c
   tuxtype/branches/tuxtype-soc-mh/src/snow.h
   tuxtype/branches/tuxtype-soc-mh/src/theme.c
   tuxtype/branches/tuxtype-soc-mh/src/titlescreen.c
   tuxtype/branches/tuxtype-soc-mh/src/titlescreen.h
   tuxtype/branches/tuxtype-soc-mh/src/wordsperminute.c
Removed:
   tuxtype/branches/tuxtype-soc-mh/ConvertUTF.c
   tuxtype/branches/tuxtype-soc-mh/ConvertUTF.h
   tuxtype/branches/tuxtype-soc-mh/Makefile.am
   tuxtype/branches/tuxtype-soc-mh/Makefile.in
   tuxtype/branches/tuxtype-soc-mh/SDLMain.h
   tuxtype/branches/tuxtype-soc-mh/SDL_extras.c
   tuxtype/branches/tuxtype-soc-mh/SDL_extras.h
   tuxtype/branches/tuxtype-soc-mh/alphabet.c
   tuxtype/branches/tuxtype-soc-mh/audio.c
   tuxtype/branches/tuxtype-soc-mh/compiler.h
   tuxtype/branches/tuxtype-soc-mh/funcs.h
   tuxtype/branches/tuxtype-soc-mh/gettext.c
   tuxtype/branches/tuxtype-soc-mh/globals.h
   tuxtype/branches/tuxtype-soc-mh/highscores.c
   tuxtype/branches/tuxtype-soc-mh/keyboard.lst
   tuxtype/branches/tuxtype-soc-mh/laser.c
   tuxtype/branches/tuxtype-soc-mh/laser.h
   tuxtype/branches/tuxtype-soc-mh/loaders.c
   tuxtype/branches/tuxtype-soc-mh/main.c
   tuxtype/branches/tuxtype-soc-mh/options.c
   tuxtype/branches/tuxtype-soc-mh/pause.c
   tuxtype/branches/tuxtype-soc-mh/phrases.txt
   tuxtype/branches/tuxtype-soc-mh/pixels.c
   tuxtype/branches/tuxtype-soc-mh/pixels.h
   tuxtype/branches/tuxtype-soc-mh/playgame.c
   tuxtype/branches/tuxtype-soc-mh/playgame.h
   tuxtype/branches/tuxtype-soc-mh/practice.c
   tuxtype/branches/tuxtype-soc-mh/profiles.c
   tuxtype/branches/tuxtype-soc-mh/profilesgui.c
   tuxtype/branches/tuxtype-soc-mh/scripting.c
   tuxtype/branches/tuxtype-soc-mh/scripting.h
   tuxtype/branches/tuxtype-soc-mh/setup.c
   tuxtype/branches/tuxtype-soc-mh/snow.c
   tuxtype/branches/tuxtype-soc-mh/snow.h
   tuxtype/branches/tuxtype-soc-mh/theme.c
   tuxtype/branches/tuxtype-soc-mh/titlescreen.c
   tuxtype/branches/tuxtype-soc-mh/titlescreen.h
   tuxtype/branches/tuxtype-soc-mh/wordsperminute.c
Log:


Deleted: tuxtype/branches/tuxtype-soc-mh/ConvertUTF.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/ConvertUTF.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/ConvertUTF.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,539 +0,0 @@
-/*
- * Copyright 2001-2004 Unicode, Inc.
- * 
- * Disclaimer
- * 
- * This source code is provided as is by Unicode, Inc. No claims are
- * made as to fitness for any particular purpose. No warranties of any
- * kind are expressed or implied. The recipient agrees to determine
- * applicability of information provided. If this file has been
- * purchased on magnetic or optical media from Unicode, Inc., the
- * sole remedy for any claim will be exchange of defective media
- * within 90 days of receipt.
- * 
- * Limitations on Rights to Redistribute This Code
- * 
- * Unicode, Inc. hereby grants the right to freely use the information
- * supplied in this file in the creation of products supporting the
- * Unicode Standard, and to make copies of this file in any form
- * for internal or external distribution as long as this notice
- * remains attached.
- */
-
-/* ---------------------------------------------------------------------
-
-    Conversions between UTF32, UTF-16, and UTF-8. Source code file.
-    Author: Mark E. Davis, 1994.
-    Rev History: Rick McGowan, fixes & updates May 2001.
-    Sept 2001: fixed const & error conditions per
-	mods suggested by S. Parent & A. Lillich.
-    June 2002: Tim Dodd added detection and handling of incomplete
-	source sequences, enhanced error detection, added casts
-	to eliminate compiler warnings.
-    July 2003: slight mods to back out aggressive FFFE detection.
-    Jan 2004: updated switches in from-UTF8 conversions.
-    Oct 2004: updated to use UNI_MAX_LEGAL_UTF32 in UTF-32 conversions.
-
-    See the header file "ConvertUTF.h" for complete documentation.
-
------------------------------------------------------------------------- */
-
-
-#include "ConvertUTF.h"
-#ifdef CVTUTF_DEBUG
-#include <stdio.h>
-#endif
-
-static const int halfShift  = 10; /* used for shifting by 10 bits */
-
-static const UTF32 halfBase = 0x0010000UL;
-static const UTF32 halfMask = 0x3FFUL;
-
-#define UNI_SUR_HIGH_START  (UTF32)0xD800
-#define UNI_SUR_HIGH_END    (UTF32)0xDBFF
-#define UNI_SUR_LOW_START   (UTF32)0xDC00
-#define UNI_SUR_LOW_END     (UTF32)0xDFFF
-#define false	   0
-#define true	    1
-
-/* --------------------------------------------------------------------- */
-
-ConversionResult ConvertUTF32toUTF16 (
-	const UTF32** sourceStart, const UTF32* sourceEnd, 
-	UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
-    ConversionResult result = conversionOK;
-    const UTF32* source = *sourceStart;
-    UTF16* target = *targetStart;
-    while (source < sourceEnd) {
-	UTF32 ch;
-	if (target >= targetEnd) {
-	    result = targetExhausted; break;
-	}
-	ch = *source++;
-	if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
-	    /* UTF-16 surrogate values are illegal in UTF-32; 0xffff or 0xfffe are both reserved values */
-	    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
-		if (flags == strictConversion) {
-		    --source; /* return to the illegal value itself */
-		    result = sourceIllegal;
-		    break;
-		} else {
-		    *target++ = UNI_REPLACEMENT_CHAR;
-		}
-	    } else {
-		*target++ = (UTF16)ch; /* normal case */
-	    }
-	} else if (ch > UNI_MAX_LEGAL_UTF32) {
-	    if (flags == strictConversion) {
-		result = sourceIllegal;
-	    } else {
-		*target++ = UNI_REPLACEMENT_CHAR;
-	    }
-	} else {
-	    /* target is a character in range 0xFFFF - 0x10FFFF. */
-	    if (target + 1 >= targetEnd) {
-		--source; /* Back up source pointer! */
-		result = targetExhausted; break;
-	    }
-	    ch -= halfBase;
-	    *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
-	    *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
-	}
-    }
-    *sourceStart = source;
-    *targetStart = target;
-    return result;
-}
-
-/* --------------------------------------------------------------------- */
-
-ConversionResult ConvertUTF16toUTF32 (
-	const UTF16** sourceStart, const UTF16* sourceEnd, 
-	UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
-    ConversionResult result = conversionOK;
-    const UTF16* source = *sourceStart;
-    UTF32* target = *targetStart;
-    UTF32 ch, ch2;
-    while (source < sourceEnd) {
-	const UTF16* oldSource = source; /*  In case we have to back up because of target overflow. */
-	ch = *source++;
-	/* If we have a surrogate pair, convert to UTF32 first. */
-	if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
-	    /* If the 16 bits following the high surrogate are in the source buffer... */
-	    if (source < sourceEnd) {
-		ch2 = *source;
-		/* If it's a low surrogate, convert to UTF32. */
-		if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
-		    ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
-			+ (ch2 - UNI_SUR_LOW_START) + halfBase;
-		    ++source;
-		} else if (flags == strictConversion) { /* it's an unpaired high surrogate */
-		    --source; /* return to the illegal value itself */
-		    result = sourceIllegal;
-		    break;
-		}
-	    } else { /* We don't have the 16 bits following the high surrogate. */
-		--source; /* return to the high surrogate */
-		result = sourceExhausted;
-		break;
-	    }
-	} else if (flags == strictConversion) {
-	    /* UTF-16 surrogate values are illegal in UTF-32 */
-	    if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
-		--source; /* return to the illegal value itself */
-		result = sourceIllegal;
-		break;
-	    }
-	}
-	if (target >= targetEnd) {
-	    source = oldSource; /* Back up source pointer! */
-	    result = targetExhausted; break;
-	}
-	*target++ = ch;
-    }
-    *sourceStart = source;
-    *targetStart = target;
-#ifdef CVTUTF_DEBUG
-if (result == sourceIllegal) {
-    fprintf(stderr, "ConvertUTF16toUTF32 illegal seq 0x%04x,%04x\n", ch, ch2);
-    fflush(stderr);
-}
-#endif
-    return result;
-}
-
-/* --------------------------------------------------------------------- */
-
-/*
- * Index into the table below with the first byte of a UTF-8 sequence to
- * get the number of trailing bytes that are supposed to follow it.
- * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
- * left as-is for anyone who may want to do such conversion, which was
- * allowed in earlier algorithms.
- */
-static const char trailingBytesForUTF8[256] = {
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
-    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
-};
-
-/*
- * Magic values subtracted from a buffer value during UTF8 conversion.
- * This table contains as many values as there might be trailing bytes
- * in a UTF-8 sequence.
- */
-static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL, 
-		     0x03C82080UL, 0xFA082080UL, 0x82082080UL };
-
-/*
- * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
- * into the first byte, depending on how many bytes follow.  There are
- * as many entries in this table as there are UTF-8 sequence types.
- * (I.e., one byte sequence, two byte... etc.). Remember that sequencs
- * for *legal* UTF-8 will be 4 or fewer bytes total.
- */
-static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
-
-/* --------------------------------------------------------------------- */
-
-/* The interface converts a whole buffer to avoid function-call overhead.
- * Constants have been gathered. Loops & conditionals have been removed as
- * much as possible for efficiency, in favor of drop-through switches.
- * (See "Note A" at the bottom of the file for equivalent code.)
- * If your compiler supports it, the "isLegalUTF8" call can be turned
- * into an inline function.
- */
-
-/* --------------------------------------------------------------------- */
-
-ConversionResult ConvertUTF16toUTF8 (
-	const UTF16** sourceStart, const UTF16* sourceEnd, 
-	UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
-    ConversionResult result = conversionOK;
-    const UTF16* source = *sourceStart;
-    UTF8* target = *targetStart;
-    while (source < sourceEnd) {
-	UTF32 ch;
-	unsigned short bytesToWrite = 0;
-	const UTF32 byteMask = 0xBF;
-	const UTF32 byteMark = 0x80; 
-	const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */
-	ch = *source++;
-	/* If we have a surrogate pair, convert to UTF32 first. */
-	if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
-	    /* If the 16 bits following the high surrogate are in the source buffer... */
-	    if (source < sourceEnd) {
-		UTF32 ch2 = *source;
-		/* If it's a low surrogate, convert to UTF32. */
-		if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
-		    ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
-			+ (ch2 - UNI_SUR_LOW_START) + halfBase;
-		    ++source;
-		} else if (flags == strictConversion) { /* it's an unpaired high surrogate */
-		    --source; /* return to the illegal value itself */
-		    result = sourceIllegal;
-		    break;
-		}
-	    } else { /* We don't have the 16 bits following the high surrogate. */
-		--source; /* return to the high surrogate */
-		result = sourceExhausted;
-		break;
-	    }
-	} else if (flags == strictConversion) {
-	    /* UTF-16 surrogate values are illegal in UTF-32 */
-	    if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
-		--source; /* return to the illegal value itself */
-		result = sourceIllegal;
-		break;
-	    }
-	}
-	/* Figure out how many bytes the result will require */
-	if (ch < (UTF32)0x80) {	     bytesToWrite = 1;
-	} else if (ch < (UTF32)0x800) {     bytesToWrite = 2;
-	} else if (ch < (UTF32)0x10000) {   bytesToWrite = 3;
-	} else if (ch < (UTF32)0x110000) {  bytesToWrite = 4;
-	} else {			    bytesToWrite = 3;
-					    ch = UNI_REPLACEMENT_CHAR;
-	}
-
-	target += bytesToWrite;
-	if (target > targetEnd) {
-	    source = oldSource; /* Back up source pointer! */
-	    target -= bytesToWrite; result = targetExhausted; break;
-	}
-	switch (bytesToWrite) { /* note: everything falls through. */
-	    case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
-	    case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
-	    case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
-	    case 1: *--target =  (UTF8)(ch | firstByteMark[bytesToWrite]);
-	}
-	target += bytesToWrite;
-    }
-    *sourceStart = source;
-    *targetStart = target;
-    return result;
-}
-
-/* --------------------------------------------------------------------- */
-
-/*
- * Utility routine to tell whether a sequence of bytes is legal UTF-8.
- * This must be called with the length pre-determined by the first byte.
- * If not calling this from ConvertUTF8to*, then the length can be set by:
- *  length = trailingBytesForUTF8[*source]+1;
- * and the sequence is illegal right away if there aren't that many bytes
- * available.
- * If presented with a length > 4, this returns false.  The Unicode
- * definition of UTF-8 goes up to 4-byte sequences.
- */
-
-static Boolean isLegalUTF8(const UTF8 *source, int length) {
-    UTF8 a;
-    const UTF8 *srcptr = source+length;
-    switch (length) {
-    default: return false;
-	/* Everything else falls through when "true"... */
-    case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
-    case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
-    case 2: if ((a = (*--srcptr)) > 0xBF) return false;
-
-	switch (*source) {
-	    /* no fall-through in this inner switch */
-	    case 0xE0: if (a < 0xA0) return false; break;
-	    case 0xED: if (a > 0x9F) return false; break;
-	    case 0xF0: if (a < 0x90) return false; break;
-	    case 0xF4: if (a > 0x8F) return false; break;
-	    default:   if (a < 0x80) return false;
-	}
-
-    case 1: if (*source >= 0x80 && *source < 0xC2) return false;
-    }
-    if (*source > 0xF4) return false;
-    return true;
-}
-
-/* --------------------------------------------------------------------- */
-
-/*
- * Exported function to return whether a UTF-8 sequence is legal or not.
- * This is not used here; it's just exported.
- */
-Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {
-    int length = trailingBytesForUTF8[*source]+1;
-    if (source+length > sourceEnd) {
-	return false;
-    }
-    return isLegalUTF8(source, length);
-}
-
-/* --------------------------------------------------------------------- */
-
-ConversionResult ConvertUTF8toUTF16 (
-	const UTF8** sourceStart, const UTF8* sourceEnd, 
-	UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
-    ConversionResult result = conversionOK;
-    const UTF8* source = *sourceStart;
-    UTF16* target = *targetStart;
-    while (source < sourceEnd) {
-	UTF32 ch = 0;
-	unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
-	if (source + extraBytesToRead >= sourceEnd) {
-	    result = sourceExhausted; break;
-	}
-	/* Do this check whether lenient or strict */
-	if (! isLegalUTF8(source, extraBytesToRead+1)) {
-	    result = sourceIllegal;
-	    break;
-	}
-	/*
-	 * The cases all fall through. See "Note A" below.
-	 */
-	switch (extraBytesToRead) {
-	    case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
-	    case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
-	    case 3: ch += *source++; ch <<= 6;
-	    case 2: ch += *source++; ch <<= 6;
-	    case 1: ch += *source++; ch <<= 6;
-	    case 0: ch += *source++;
-	}
-	ch -= offsetsFromUTF8[extraBytesToRead];
-
-	if (target >= targetEnd) {
-	    source -= (extraBytesToRead+1); /* Back up source pointer! */
-	    result = targetExhausted; break;
-	}
-	if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
-	    /* UTF-16 surrogate values are illegal in UTF-32 */
-	    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
-		if (flags == strictConversion) {
-		    source -= (extraBytesToRead+1); /* return to the illegal value itself */
-		    result = sourceIllegal;
-		    break;
-		} else {
-		    *target++ = UNI_REPLACEMENT_CHAR;
-		}
-	    } else {
-		*target++ = (UTF16)ch; /* normal case */
-	    }
-	} else if (ch > UNI_MAX_UTF16) {
-	    if (flags == strictConversion) {
-		result = sourceIllegal;
-		source -= (extraBytesToRead+1); /* return to the start */
-		break; /* Bail out; shouldn't continue */
-	    } else {
-		*target++ = UNI_REPLACEMENT_CHAR;
-	    }
-	} else {
-	    /* target is a character in range 0xFFFF - 0x10FFFF. */
-	    if (target + 1 >= targetEnd) {
-		source -= (extraBytesToRead+1); /* Back up source pointer! */
-		result = targetExhausted; break;
-	    }
-	    ch -= halfBase;
-	    *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
-	    *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
-	}
-    }
-    *sourceStart = source;
-    *targetStart = target;
-    return result;
-}
-
-/* --------------------------------------------------------------------- */
-
-ConversionResult ConvertUTF32toUTF8 (
-	const UTF32** sourceStart, const UTF32* sourceEnd, 
-	UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
-    ConversionResult result = conversionOK;
-    const UTF32* source = *sourceStart;
-    UTF8* target = *targetStart;
-    while (source < sourceEnd) {
-	UTF32 ch;
-	unsigned short bytesToWrite = 0;
-	const UTF32 byteMask = 0xBF;
-	const UTF32 byteMark = 0x80; 
-	ch = *source++;
-	if (flags == strictConversion ) {
-	    /* UTF-16 surrogate values are illegal in UTF-32 */
-	    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
-		--source; /* return to the illegal value itself */
-		result = sourceIllegal;
-		break;
-	    }
-	}
-	/*
-	 * Figure out how many bytes the result will require. Turn any
-	 * illegally large UTF32 things (> Plane 17) into replacement chars.
-	 */
-	if (ch < (UTF32)0x80) {	     bytesToWrite = 1;
-	} else if (ch < (UTF32)0x800) {     bytesToWrite = 2;
-	} else if (ch < (UTF32)0x10000) {   bytesToWrite = 3;
-	} else if (ch <= UNI_MAX_LEGAL_UTF32) {  bytesToWrite = 4;
-	} else {			    bytesToWrite = 3;
-					    ch = UNI_REPLACEMENT_CHAR;
-					    result = sourceIllegal;
-	}
-	
-	target += bytesToWrite;
-	if (target > targetEnd) {
-	    --source; /* Back up source pointer! */
-	    target -= bytesToWrite; result = targetExhausted; break;
-	}
-	switch (bytesToWrite) { /* note: everything falls through. */
-	    case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
-	    case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
-	    case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
-	    case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]);
-	}
-	target += bytesToWrite;
-    }
-    *sourceStart = source;
-    *targetStart = target;
-    return result;
-}
-
-/* --------------------------------------------------------------------- */
-
-ConversionResult ConvertUTF8toUTF32 (
-	const UTF8** sourceStart, const UTF8* sourceEnd, 
-	UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
-    ConversionResult result = conversionOK;
-    const UTF8* source = *sourceStart;
-    UTF32* target = *targetStart;
-    while (source < sourceEnd) {
-	UTF32 ch = 0;
-	unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
-	if (source + extraBytesToRead >= sourceEnd) {
-	    result = sourceExhausted; break;
-	}
-	/* Do this check whether lenient or strict */
-	if (! isLegalUTF8(source, extraBytesToRead+1)) {
-	    result = sourceIllegal;
-	    break;
-	}
-	/*
-	 * The cases all fall through. See "Note A" below.
-	 */
-	switch (extraBytesToRead) {
-	    case 5: ch += *source++; ch <<= 6;
-	    case 4: ch += *source++; ch <<= 6;
-	    case 3: ch += *source++; ch <<= 6;
-	    case 2: ch += *source++; ch <<= 6;
-	    case 1: ch += *source++; ch <<= 6;
-	    case 0: ch += *source++;
-	}
-	ch -= offsetsFromUTF8[extraBytesToRead];
-
-	if (target >= targetEnd) {
-	    source -= (extraBytesToRead+1); /* Back up the source pointer! */
-	    result = targetExhausted; break;
-	}
-	if (ch <= UNI_MAX_LEGAL_UTF32) {
-	    /*
-	     * UTF-16 surrogate values are illegal in UTF-32, and anything
-	     * over Plane 17 (> 0x10FFFF) is illegal.
-	     */
-	    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
-		if (flags == strictConversion) {
-		    source -= (extraBytesToRead+1); /* return to the illegal value itself */
-		    result = sourceIllegal;
-		    break;
-		} else {
-		    *target++ = UNI_REPLACEMENT_CHAR;
-		}
-	    } else {
-		*target++ = ch;
-	    }
-	} else { /* i.e., ch > UNI_MAX_LEGAL_UTF32 */
-	    result = sourceIllegal;
-	    *target++ = UNI_REPLACEMENT_CHAR;
-	}
-    }
-    *sourceStart = source;
-    *targetStart = target;
-    return result;
-}
-
-/* ---------------------------------------------------------------------
-
-    Note A.
-    The fall-through switches in UTF-8 reading code save a
-    temp variable, some decrements & conditionals.  The switches
-    are equivalent to the following loop:
-	{
-	    int tmpBytesToRead = extraBytesToRead+1;
-	    do {
-		ch += *source++;
-		--tmpBytesToRead;
-		if (tmpBytesToRead) ch <<= 6;
-	    } while (tmpBytesToRead > 0);
-	}
-    In UTF-8 writing code, the switches on "bytesToWrite" are
-    similarly unrolled loops.
-
-   --------------------------------------------------------------------- */

Deleted: tuxtype/branches/tuxtype-soc-mh/ConvertUTF.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/ConvertUTF.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/ConvertUTF.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,149 +0,0 @@
-/*
- * Copyright 2001-2004 Unicode, Inc.
- * 
- * Disclaimer
- * 
- * This source code is provided as is by Unicode, Inc. No claims are
- * made as to fitness for any particular purpose. No warranties of any
- * kind are expressed or implied. The recipient agrees to determine
- * applicability of information provided. If this file has been
- * purchased on magnetic or optical media from Unicode, Inc., the
- * sole remedy for any claim will be exchange of defective media
- * within 90 days of receipt.
- * 
- * Limitations on Rights to Redistribute This Code
- * 
- * Unicode, Inc. hereby grants the right to freely use the information
- * supplied in this file in the creation of products supporting the
- * Unicode Standard, and to make copies of this file in any form
- * for internal or external distribution as long as this notice
- * remains attached.
- */
-
-/* ---------------------------------------------------------------------
-
-    Conversions between UTF32, UTF-16, and UTF-8.  Header file.
-
-    Several funtions are included here, forming a complete set of
-    conversions between the three formats.  UTF-7 is not included
-    here, but is handled in a separate source file.
-
-    Each of these routines takes pointers to input buffers and output
-    buffers.  The input buffers are const.
-
-    Each routine converts the text between *sourceStart and sourceEnd,
-    putting the result into the buffer between *targetStart and
-    targetEnd. Note: the end pointers are *after* the last item: e.g. 
-    *(sourceEnd - 1) is the last item.
-
-    The return result indicates whether the conversion was successful,
-    and if not, whether the problem was in the source or target buffers.
-    (Only the first encountered problem is indicated.)
-
-    After the conversion, *sourceStart and *targetStart are both
-    updated to point to the end of last text successfully converted in
-    the respective buffers.
-
-    Input parameters:
-	sourceStart - pointer to a pointer to the source buffer.
-		The contents of this are modified on return so that
-		it points at the next thing to be converted.
-	targetStart - similarly, pointer to pointer to the target buffer.
-	sourceEnd, targetEnd - respectively pointers to the ends of the
-		two buffers, for overflow checking only.
-
-    These conversion functions take a ConversionFlags argument. When this
-    flag is set to strict, both irregular sequences and isolated surrogates
-    will cause an error.  When the flag is set to lenient, both irregular
-    sequences and isolated surrogates are converted.
-
-    Whether the flag is strict or lenient, all illegal sequences will cause
-    an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,
-    or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code
-    must check for illegal sequences.
-
-    When the flag is set to lenient, characters over 0x10FFFF are converted
-    to the replacement character; otherwise (when the flag is set to strict)
-    they constitute an error.
-
-    Output parameters:
-	The value "sourceIllegal" is returned from some routines if the input
-	sequence is malformed.  When "sourceIllegal" is returned, the source
-	value will point to the illegal value that caused the problem. E.g.,
-	in UTF-8 when a sequence is malformed, it points to the start of the
-	malformed sequence.  
-
-    Author: Mark E. Davis, 1994.
-    Rev History: Rick McGowan, fixes & updates May 2001.
-		 Fixes & updates, Sept 2001.
-
------------------------------------------------------------------------- */
-
-/* ---------------------------------------------------------------------
-    The following 4 definitions are compiler-specific.
-    The C standard does not guarantee that wchar_t has at least
-    16 bits, so wchar_t is no less portable than unsigned short!
-    All should be unsigned values to avoid sign extension during
-    bit mask & shift operations.
------------------------------------------------------------------------- */
-
-typedef unsigned long	UTF32;	/* at least 32 bits */
-typedef unsigned short	UTF16;	/* at least 16 bits */
-typedef unsigned char	UTF8;	/* typically 8 bits */
-typedef unsigned char	Boolean; /* 0 or 1 */
-
-/* Some fundamental constants */
-#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
-#define UNI_MAX_BMP (UTF32)0x0000FFFF
-#define UNI_MAX_UTF16 (UTF32)0x0010FFFF
-#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
-#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
-
-typedef enum {
-	conversionOK, 		/* conversion successful */
-	sourceExhausted,	/* partial character in source, but hit end */
-	targetExhausted,	/* insuff. room in target for conversion */
-	sourceIllegal		/* source sequence is illegal/malformed */
-} ConversionResult;
-
-typedef enum {
-	strictConversion = 0,
-	lenientConversion
-} ConversionFlags;
-
-/* This is for C++ and does no harm in C */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-ConversionResult ConvertUTF8toUTF16 (
-		const UTF8** sourceStart, const UTF8* sourceEnd, 
-		UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
-
-ConversionResult ConvertUTF16toUTF8 (
-		const UTF16** sourceStart, const UTF16* sourceEnd, 
-		UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
-		
-ConversionResult ConvertUTF8toUTF32 (
-		const UTF8** sourceStart, const UTF8* sourceEnd, 
-		UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
-
-ConversionResult ConvertUTF32toUTF8 (
-		const UTF32** sourceStart, const UTF32* sourceEnd, 
-		UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
-		
-ConversionResult ConvertUTF16toUTF32 (
-		const UTF16** sourceStart, const UTF16* sourceEnd, 
-		UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
-
-ConversionResult ConvertUTF32toUTF16 (
-		const UTF32** sourceStart, const UTF32* sourceEnd, 
-		UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
-
-Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);
-
-#ifdef __cplusplus
-}
-#endif
-
-/* --------------------------------------------------------------------- */

Deleted: tuxtype/branches/tuxtype-soc-mh/Makefile.am
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/Makefile.am	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/Makefile.am	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,9 +0,0 @@
-## Makefile.am for tuxtype - data:
-## Process with Automake to create Makefile.in
-
-SUBDIRS = images scripts sounds themes words fonts
-
-tuxtypedatadir = $(pkgdatadir)/data
-
-dist_tuxtypedata_DATA = keyboard.lst \
-			phrases.txt

Deleted: tuxtype/branches/tuxtype-soc-mh/Makefile.in
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/Makefile.in	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/Makefile.in	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,525 +0,0 @@
-# Makefile.in generated by automake 1.10.1 from Makefile.am.
-# @configure_input@
-
-# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-# 2003, 2004, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
-# This Makefile.in is free software; the Free Software Foundation
-# gives unlimited permission to copy and/or distribute it,
-# with or without modifications, as long as this notice is preserved.
-
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
-# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
-# PARTICULAR PURPOSE.
-
- at SET_MAKE@
-
-VPATH = @srcdir@
-pkgdatadir = $(datadir)/@PACKAGE@
-pkglibdir = $(libdir)/@PACKAGE@
-pkgincludedir = $(includedir)/@PACKAGE@
-am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
-install_sh_DATA = $(install_sh) -c -m 644
-install_sh_PROGRAM = $(install_sh) -c
-install_sh_SCRIPT = $(install_sh) -c
-INSTALL_HEADER = $(INSTALL_DATA)
-transform = $(program_transform_name)
-NORMAL_INSTALL = :
-PRE_INSTALL = :
-POST_INSTALL = :
-NORMAL_UNINSTALL = :
-PRE_UNINSTALL = :
-POST_UNINSTALL = :
-build_triplet = @build@
-host_triplet = @host@
-target_triplet = @target@
-subdir = data
-DIST_COMMON = $(dist_tuxtypedata_DATA) $(srcdir)/Makefile.am \
-	$(srcdir)/Makefile.in
-ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
-	$(top_srcdir)/configure.ac
-am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
-	$(ACLOCAL_M4)
-mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
-CONFIG_HEADER = $(top_builddir)/config.h
-CONFIG_CLEAN_FILES =
-SOURCES =
-DIST_SOURCES =
-RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
-	html-recursive info-recursive install-data-recursive \
-	install-dvi-recursive install-exec-recursive \
-	install-html-recursive install-info-recursive \
-	install-pdf-recursive install-ps-recursive install-recursive \
-	installcheck-recursive installdirs-recursive pdf-recursive \
-	ps-recursive uninstall-recursive
-am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
-am__vpath_adj = case $$p in \
-    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
-    *) f=$$p;; \
-  esac;
-am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
-am__installdirs = "$(DESTDIR)$(tuxtypedatadir)"
-dist_tuxtypedataDATA_INSTALL = $(INSTALL_DATA)
-DATA = $(dist_tuxtypedata_DATA)
-RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
-  distclean-recursive maintainer-clean-recursive
-ETAGS = etags
-CTAGS = ctags
-DIST_SUBDIRS = $(SUBDIRS)
-DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
-ACLOCAL = @ACLOCAL@
-AMTAR = @AMTAR@
-AUTOCONF = @AUTOCONF@
-AUTOHEADER = @AUTOHEADER@
-AUTOMAKE = @AUTOMAKE@
-AWK = @AWK@
-CC = @CC@
-CCDEPMODE = @CCDEPMODE@
-CFLAGS = @CFLAGS@
-CPP = @CPP@
-CPPFLAGS = @CPPFLAGS@
-CYGPATH_W = @CYGPATH_W@
-DEFS = @DEFS@
-DEPDIR = @DEPDIR@
-ECHO_C = @ECHO_C@
-ECHO_N = @ECHO_N@
-ECHO_T = @ECHO_T@
-EGREP = @EGREP@
-EXEEXT = @EXEEXT@
-GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
-GMSGFMT = @GMSGFMT@
-GMSGFMT_015 = @GMSGFMT_015@
-GREP = @GREP@
-INSTALL = @INSTALL@
-INSTALL_DATA = @INSTALL_DATA@
-INSTALL_PROGRAM = @INSTALL_PROGRAM@
-INSTALL_SCRIPT = @INSTALL_SCRIPT@
-INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
-INTLLIBS = @INTLLIBS@
-INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
-LDFLAGS = @LDFLAGS@
-LIBICONV = @LIBICONV@
-LIBINTL = @LIBINTL@
-LIBOBJS = @LIBOBJS@
-LIBS = @LIBS@
-LN_S = @LN_S@
-LTLIBICONV = @LTLIBICONV@
-LTLIBINTL = @LTLIBINTL@
-LTLIBOBJS = @LTLIBOBJS@
-MAKEINFO = @MAKEINFO@
-MKDIR_P = @MKDIR_P@
-MSGFMT = @MSGFMT@
-MSGFMT_015 = @MSGFMT_015@
-MSGMERGE = @MSGMERGE@
-NSIS = @NSIS@
-NSI_DLL_DIR = @NSI_DLL_DIR@
-NSI_INSTALL_DIR = @NSI_INSTALL_DIR@
-OBJEXT = @OBJEXT@
-PACKAGE = @PACKAGE@
-PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
-PACKAGE_NAME = @PACKAGE_NAME@
-PACKAGE_STRING = @PACKAGE_STRING@
-PACKAGE_TARNAME = @PACKAGE_TARNAME@
-PACKAGE_VERSION = @PACKAGE_VERSION@
-PATH_SEPARATOR = @PATH_SEPARATOR@
-POSUB = @POSUB@
-SDL_CFLAGS = @SDL_CFLAGS@
-SDL_CONFIG = @SDL_CONFIG@
-SDL_LIBS = @SDL_LIBS@
-SET_MAKE = @SET_MAKE@
-SHELL = @SHELL@
-STRIP = @STRIP@
-USE_NLS = @USE_NLS@
-VERSION = @VERSION@
-WINDRES = @WINDRES@
-XGETTEXT = @XGETTEXT@
-XGETTEXT_015 = @XGETTEXT_015@
-XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@
-abs_builddir = @abs_builddir@
-abs_srcdir = @abs_srcdir@
-abs_top_builddir = @abs_top_builddir@
-abs_top_srcdir = @abs_top_srcdir@
-ac_ct_CC = @ac_ct_CC@
-am__include = @am__include@
-am__leading_dot = @am__leading_dot@
-am__quote = @am__quote@
-am__tar = @am__tar@
-am__untar = @am__untar@
-bindir = @bindir@
-build = @build@
-build_alias = @build_alias@
-build_cpu = @build_cpu@
-build_os = @build_os@
-build_vendor = @build_vendor@
-builddir = @builddir@
-datadir = @datadir@
-datarootdir = @datarootdir@
-docdir = @docdir@
-dvidir = @dvidir@
-exec_prefix = @exec_prefix@
-host = @host@
-host_alias = @host_alias@
-host_cpu = @host_cpu@
-host_os = @host_os@
-host_vendor = @host_vendor@
-htmldir = @htmldir@
-includedir = @includedir@
-infodir = @infodir@
-install_sh = @install_sh@
-libdir = @libdir@
-libexecdir = @libexecdir@
-localedir = @localedir@
-localstatedir = @localstatedir@
-mandir = @mandir@
-mkdir_p = @mkdir_p@
-oldincludedir = @oldincludedir@
-pdfdir = @pdfdir@
-prefix = @prefix@
-program_transform_name = @program_transform_name@
-psdir = @psdir@
-sbindir = @sbindir@
-sharedstatedir = @sharedstatedir@
-srcdir = @srcdir@
-sysconfdir = @sysconfdir@
-target = @target@
-target_alias = @target_alias@
-target_cpu = @target_cpu@
-target_os = @target_os@
-target_vendor = @target_vendor@
-top_builddir = @top_builddir@
-top_srcdir = @top_srcdir@
-SUBDIRS = images scripts sounds themes words fonts
-tuxtypedatadir = $(pkgdatadir)/data
-dist_tuxtypedata_DATA = keyboard.lst \
-			phrases.txt
-
-all: all-recursive
-
-.SUFFIXES:
-$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
-	@for dep in $?; do \
-	  case '$(am__configure_deps)' in \
-	    *$$dep*) \
-	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
-		&& exit 0; \
-	      exit 1;; \
-	  esac; \
-	done; \
-	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  data/Makefile'; \
-	cd $(top_srcdir) && \
-	  $(AUTOMAKE) --foreign  data/Makefile
-.PRECIOUS: Makefile
-Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
-	@case '$?' in \
-	  *config.status*) \
-	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
-	  *) \
-	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
-	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
-	esac;
-
-$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-
-$(top_srcdir)/configure:  $(am__configure_deps)
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
-	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
-install-dist_tuxtypedataDATA: $(dist_tuxtypedata_DATA)
-	@$(NORMAL_INSTALL)
-	test -z "$(tuxtypedatadir)" || $(MKDIR_P) "$(DESTDIR)$(tuxtypedatadir)"
-	@list='$(dist_tuxtypedata_DATA)'; for p in $$list; do \
-	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
-	  f=$(am__strip_dir) \
-	  echo " $(dist_tuxtypedataDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(tuxtypedatadir)/$$f'"; \
-	  $(dist_tuxtypedataDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(tuxtypedatadir)/$$f"; \
-	done
-
-uninstall-dist_tuxtypedataDATA:
-	@$(NORMAL_UNINSTALL)
-	@list='$(dist_tuxtypedata_DATA)'; for p in $$list; do \
-	  f=$(am__strip_dir) \
-	  echo " rm -f '$(DESTDIR)$(tuxtypedatadir)/$$f'"; \
-	  rm -f "$(DESTDIR)$(tuxtypedatadir)/$$f"; \
-	done
-
-# This directory's subdirectories are mostly independent; you can cd
-# into them and run `make' without going through this Makefile.
-# To change the values of `make' variables: instead of editing Makefiles,
-# (1) if the variable is set in `config.status', edit `config.status'
-#     (which will cause the Makefiles to be regenerated when you run `make');
-# (2) otherwise, pass the desired values on the `make' command line.
-$(RECURSIVE_TARGETS):
-	@failcom='exit 1'; \
-	for f in x $$MAKEFLAGS; do \
-	  case $$f in \
-	    *=* | --[!k]*);; \
-	    *k*) failcom='fail=yes';; \
-	  esac; \
-	done; \
-	dot_seen=no; \
-	target=`echo $@ | sed s/-recursive//`; \
-	list='$(SUBDIRS)'; for subdir in $$list; do \
-	  echo "Making $$target in $$subdir"; \
-	  if test "$$subdir" = "."; then \
-	    dot_seen=yes; \
-	    local_target="$$target-am"; \
-	  else \
-	    local_target="$$target"; \
-	  fi; \
-	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
-	  || eval $$failcom; \
-	done; \
-	if test "$$dot_seen" = "no"; then \
-	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
-	fi; test -z "$$fail"
-
-$(RECURSIVE_CLEAN_TARGETS):
-	@failcom='exit 1'; \
-	for f in x $$MAKEFLAGS; do \
-	  case $$f in \
-	    *=* | --[!k]*);; \
-	    *k*) failcom='fail=yes';; \
-	  esac; \
-	done; \
-	dot_seen=no; \
-	case "$@" in \
-	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
-	  *) list='$(SUBDIRS)' ;; \
-	esac; \
-	rev=''; for subdir in $$list; do \
-	  if test "$$subdir" = "."; then :; else \
-	    rev="$$subdir $$rev"; \
-	  fi; \
-	done; \
-	rev="$$rev ."; \
-	target=`echo $@ | sed s/-recursive//`; \
-	for subdir in $$rev; do \
-	  echo "Making $$target in $$subdir"; \
-	  if test "$$subdir" = "."; then \
-	    local_target="$$target-am"; \
-	  else \
-	    local_target="$$target"; \
-	  fi; \
-	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
-	  || eval $$failcom; \
-	done && test -z "$$fail"
-tags-recursive:
-	list='$(SUBDIRS)'; for subdir in $$list; do \
-	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
-	done
-ctags-recursive:
-	list='$(SUBDIRS)'; for subdir in $$list; do \
-	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
-	done
-
-ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
-	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
-	mkid -fID $$unique
-tags: TAGS
-
-TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
-	tags=; \
-	here=`pwd`; \
-	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
-	  include_option=--etags-include; \
-	  empty_fix=.; \
-	else \
-	  include_option=--include; \
-	  empty_fix=; \
-	fi; \
-	list='$(SUBDIRS)'; for subdir in $$list; do \
-	  if test "$$subdir" = .; then :; else \
-	    test ! -f $$subdir/TAGS || \
-	      tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
-	  fi; \
-	done; \
-	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
-	if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
-	  test -n "$$unique" || unique=$$empty_fix; \
-	  $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
-	    $$tags $$unique; \
-	fi
-ctags: CTAGS
-CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
-		$(TAGS_FILES) $(LISP)
-	tags=; \
-	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
-	unique=`for i in $$list; do \
-	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
-	  done | \
-	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
-	      END { if (nonempty) { for (i in files) print i; }; }'`; \
-	test -z "$(CTAGS_ARGS)$$tags$$unique" \
-	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
-	     $$tags $$unique
-
-GTAGS:
-	here=`$(am__cd) $(top_builddir) && pwd` \
-	  && cd $(top_srcdir) \
-	  && gtags -i $(GTAGS_ARGS) $$here
-
-distclean-tags:
-	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
-
-distdir: $(DISTFILES)
-	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
-	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
-	list='$(DISTFILES)'; \
-	  dist_files=`for file in $$list; do echo $$file; done | \
-	  sed -e "s|^$$srcdirstrip/||;t" \
-	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
-	case $$dist_files in \
-	  */*) $(MKDIR_P) `echo "$$dist_files" | \
-			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
-			   sort -u` ;; \
-	esac; \
-	for file in $$dist_files; do \
-	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
-	  if test -d $$d/$$file; then \
-	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
-	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
-	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
-	    fi; \
-	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
-	  else \
-	    test -f $(distdir)/$$file \
-	    || cp -p $$d/$$file $(distdir)/$$file \
-	    || exit 1; \
-	  fi; \
-	done
-	list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
-	  if test "$$subdir" = .; then :; else \
-	    test -d "$(distdir)/$$subdir" \
-	    || $(MKDIR_P) "$(distdir)/$$subdir" \
-	    || exit 1; \
-	    distdir=`$(am__cd) $(distdir) && pwd`; \
-	    top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
-	    (cd $$subdir && \
-	      $(MAKE) $(AM_MAKEFLAGS) \
-	        top_distdir="$$top_distdir" \
-	        distdir="$$distdir/$$subdir" \
-		am__remove_distdir=: \
-		am__skip_length_check=: \
-	        distdir) \
-	      || exit 1; \
-	  fi; \
-	done
-check-am: all-am
-check: check-recursive
-all-am: Makefile $(DATA)
-installdirs: installdirs-recursive
-installdirs-am:
-	for dir in "$(DESTDIR)$(tuxtypedatadir)"; do \
-	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
-	done
-install: install-recursive
-install-exec: install-exec-recursive
-install-data: install-data-recursive
-uninstall: uninstall-recursive
-
-install-am: all-am
-	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
-
-installcheck: installcheck-recursive
-install-strip:
-	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
-	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
-	  `test -z '$(STRIP)' || \
-	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
-mostlyclean-generic:
-
-clean-generic:
-
-distclean-generic:
-	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
-
-maintainer-clean-generic:
-	@echo "This command is intended for maintainers to use"
-	@echo "it deletes files that may require special tools to rebuild."
-clean: clean-recursive
-
-clean-am: clean-generic mostlyclean-am
-
-distclean: distclean-recursive
-	-rm -f Makefile
-distclean-am: clean-am distclean-generic distclean-tags
-
-dvi: dvi-recursive
-
-dvi-am:
-
-html: html-recursive
-
-info: info-recursive
-
-info-am:
-
-install-data-am: install-dist_tuxtypedataDATA
-
-install-dvi: install-dvi-recursive
-
-install-exec-am:
-
-install-html: install-html-recursive
-
-install-info: install-info-recursive
-
-install-man:
-
-install-pdf: install-pdf-recursive
-
-install-ps: install-ps-recursive
-
-installcheck-am:
-
-maintainer-clean: maintainer-clean-recursive
-	-rm -f Makefile
-maintainer-clean-am: distclean-am maintainer-clean-generic
-
-mostlyclean: mostlyclean-recursive
-
-mostlyclean-am: mostlyclean-generic
-
-pdf: pdf-recursive
-
-pdf-am:
-
-ps: ps-recursive
-
-ps-am:
-
-uninstall-am: uninstall-dist_tuxtypedataDATA
-
-.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) install-am \
-	install-strip
-
-.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
-	all all-am check check-am clean clean-generic ctags \
-	ctags-recursive distclean distclean-generic distclean-tags \
-	distdir dvi dvi-am html html-am info info-am install \
-	install-am install-data install-data-am \
-	install-dist_tuxtypedataDATA install-dvi install-dvi-am \
-	install-exec install-exec-am install-html install-html-am \
-	install-info install-info-am install-man install-pdf \
-	install-pdf-am install-ps install-ps-am install-strip \
-	installcheck installcheck-am installdirs installdirs-am \
-	maintainer-clean maintainer-clean-generic mostlyclean \
-	mostlyclean-generic pdf pdf-am ps ps-am tags tags-recursive \
-	uninstall uninstall-am uninstall-dist_tuxtypedataDATA
-
-# Tell versions [3.59,3.63) of GNU make to not export all variables.
-# Otherwise a system limit (for SysV at least) may be exceeded.
-.NOEXPORT:

Deleted: tuxtype/branches/tuxtype-soc-mh/SDLMain.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/SDLMain.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/SDLMain.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,19 +0,0 @@
-/*   SDLMain.m - main entry point for our Cocoa-ized SDL app
-       Initial Version: Darrell Walisser <dwaliss1 at purdue.edu>
-       Non-NIB-Code & other changes: Max Horn <max at quendi.de>
-
-    Feel free to customize this file to suit your needs
-*/
-
-#import <Cocoa/Cocoa.h>
-
- at interface SDLMain : NSObject
-{
-}
-- (IBAction)prefsMenu:(id)sender;
-- (IBAction)newGame:(id)sender;
-- (IBAction)openGame:(id)sender;
-- (IBAction)saveGame:(id)sender;
-- (IBAction)saveGameAs:(id)sender;
-- (IBAction)help:(id)sender;
- at end

Deleted: tuxtype/branches/tuxtype-soc-mh/SDL_extras.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/SDL_extras.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/SDL_extras.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,722 +0,0 @@
-/*
-*  C Implementation: SDL_extras
-*
-* Description: a few handy functions for using SDL graphics.
-*
-*
-* Author: David Bruce,,, <dbruce at tampabay.rr.com>, (C) 2007
-*
-* Copyright: GPL v3 or later
-*
-*/
-#include <math.h>
-
-#include "SDL_extras.h"
-#include "globals.h"
-#include "pixels.h"
-
-
-#ifdef HAVE_LIBSDL_PANGO
-#include "SDL_Pango.h"
-#endif
-
-
-/* DrawButton() creates and draws a translucent button with */
-/* rounded ends.  All colors and alpha values are supported.*/
-void DrawButton(SDL_Rect* target_rect,
-                int radius,
-                Uint8 r, Uint8 g, Uint8 b, Uint8 a)
-{
-  /* NOTE - we use a 32-bit temp surface even if we have a 16-bit */
-  /* screen - it gets converted during blitting.                  */
-  SDL_Surface* tmp_surf = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,
-                                          target_rect->w,
-                                          target_rect->h,
-                                          32,
-                                          rmask, gmask, bmask, amask);
-  Uint32 color = SDL_MapRGBA(tmp_surf->format, r, g, b, a);
-  SDL_FillRect(tmp_surf, NULL, color);
-  RoundCorners(tmp_surf, radius);
-
-  SDL_BlitSurface(tmp_surf, NULL, screen, target_rect);
-  SDL_FreeSurface(tmp_surf);
-}
-
-
-
-void RoundCorners(SDL_Surface* s, Uint16 radius)
-{
-  int y = 0;
-  int x_dist, y_dist;
-  Uint32* p = NULL;
-  Uint32 alpha_mask;
-  int bytes_per_pix;
-
-  if (!s)
-    return;
-  if (SDL_LockSurface(s) == -1)
-    return;
-
-  bytes_per_pix = s->format->BytesPerPixel;
-  if (bytes_per_pix != 4)
-    return;
-
-  /* radius cannot be more than half of width or height: */
-  if (radius > (s->w)/2)
-    radius = (s->w)/2;
-  if (radius > (s->h)/2)
-    radius = (s->h)/2;
-
-
-  alpha_mask = s->format->Amask;
-
-  /* Now round off corners: */
-  /* upper left:            */
-  for (y = 0; y < radius; y++)
-  {
-    p = (Uint32*)(s->pixels + (y * s->pitch));
-    x_dist = radius;
-    y_dist = radius - y;
-
-    while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
-    {
-      /* (make pixel (x,y) transparent) */
-      *p = *p & ~alpha_mask;
-      p++;
-      x_dist--;
-    }
-  }
-
-  /* upper right:            */
-  for (y = 0; y < radius; y++)
-  {
-    /* start at end of top row: */
-    p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
-
-    x_dist = radius;
-    y_dist = radius - y;
-
-    while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
-    {
-      /* (make pixel (x,y) transparent) */
-      *p = *p & ~alpha_mask;
-      p--;
-      x_dist--;
-    }
-  }
-
-  /* bottom left:            */
-  for (y = (s->h - 1); y > (s->h - radius); y--)
-  {
-    /* start at beginning of bottom row */
-    p = (Uint32*)(s->pixels + (y * s->pitch));
-    x_dist = radius;
-    y_dist = y - (s->h - radius);
-
-    while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
-    {
-      /* (make pixel (x,y) transparent) */
-      *p = *p & ~alpha_mask;
-      p++;
-      x_dist--;
-    }
-  }
-
-  /* bottom right:            */
-  for (y = (s->h - 1); y > (s->h - radius); y--)
-  {
-    /* start at end of bottom row */
-    p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
-    x_dist = radius;
-    y_dist = y - (s->h - radius);
-
-    while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
-    {
-      /* (make pixel (x,y) transparent) */
-      *p = *p & ~alpha_mask;
-      p--;
-      x_dist--;
-    }
-  }
-  SDL_UnlockSurface(s);
-}
-
-
-/**********************
- Flip:
-   input: a SDL_Surface, x, y
-   output: a copy of the SDL_Surface flipped via rules:
-
-     if x is a nonzero value, then flip horizontally
-     if y is a nonzero value, then flip vertically
-
-     note: you can have it flip both
-**********************/
-SDL_Surface* Flip( SDL_Surface *in, int x, int y ) {
-        SDL_Surface *out, *tmp;
-        SDL_Rect from_rect, to_rect;
-        Uint32        flags;
-        Uint32  colorkey=0;
-
-        /* --- grab the settings for the incoming pixmap --- */
-
-        SDL_LockSurface(in);
-        flags = in->flags;
-
-        /* --- change in's flags so ignore colorkey & alpha --- */
-
-        if (flags & SDL_SRCCOLORKEY) {
-                in->flags &= ~SDL_SRCCOLORKEY;
-                colorkey = in->format->colorkey;
-        }
-        if (flags & SDL_SRCALPHA) {
-                in->flags &= ~SDL_SRCALPHA;
-        }
-
-        SDL_UnlockSurface(in);
-
-        /* --- create our new surface --- */
-
-        out = SDL_CreateRGBSurface(
-                SDL_SWSURFACE,
-                in->w, in->h, 32, rmask, gmask, bmask, amask);
-
-        /* --- flip horizontally if requested --- */
-
-        if (x) {
-                from_rect.h = to_rect.h = in->h;
-                from_rect.w = to_rect.w = 1;
-                from_rect.y = to_rect.y = 0;
-                from_rect.x = 0;
-                to_rect.x = in->w - 1;
-
-                do {
-                        SDL_BlitSurface(in, &from_rect, out, &to_rect);
-                        from_rect.x++;
-                        to_rect.x--;
-                } while (to_rect.x >= 0);
-        }
-
-        /* --- flip vertically if requested --- */
-
-        if (y) {
-                from_rect.h = to_rect.h = 1;
-                from_rect.w = to_rect.w = in->w;
-                from_rect.x = to_rect.x = 0;
-                from_rect.y = 0;
-                to_rect.y = in->h - 1;
-
-                do {
-                        SDL_BlitSurface(in, &from_rect, out, &to_rect);
-                        from_rect.y++;
-                        to_rect.y--;
-                } while (to_rect.y >= 0);
-        }
-
-        /* --- restore colorkey & alpha on in and setup out the same --- */
-
-        SDL_LockSurface(in);
-
-        if (flags & SDL_SRCCOLORKEY) {
-                in->flags |= SDL_SRCCOLORKEY;
-                in->format->colorkey = colorkey;
-                tmp = SDL_DisplayFormat(out);
-                SDL_FreeSurface(out);
-                out = tmp;
-                out->flags |= SDL_SRCCOLORKEY;
-                out->format->colorkey = colorkey;
-        } else if (flags & SDL_SRCALPHA) {
-                in->flags |= SDL_SRCALPHA;
-                tmp = SDL_DisplayFormatAlpha(out);
-                SDL_FreeSurface(out);
-                out = tmp;
-        } else {
-                tmp = SDL_DisplayFormat(out);
-                SDL_FreeSurface(out);
-                out = tmp;
-        }
-
-        SDL_UnlockSurface(in);
-
-        return out;
-}
-
-/* Blend two surfaces together. The third argument is between 0.0 and
-   1.0, and represents the weight assigned to the first surface.  If
-   the pointer to the second surface is NULL, this performs fading.
-
-   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_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) {
-    perror("gamma must be between 0 and 1");
-    exit(0);
-  }
-  fmt1 = S1->format;
-  if (fmt1->BitsPerPixel != 32) {
-    perror("This works only with RGBA images");
-    return S1;
-  }
-  if (S2 != NULL) {
-    fmt2 = S2->format;
-    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) {
-      printf("S1->w %d, S2->w %d;  S1->h %d, S2->h %d\n",
-             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);
-  // 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 {
-    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;
-    }
-    *cpix1 = SDL_MapRGBA(fmt1,r1,g1,b1,a1);
-  }
-  SDL_UnlockSurface(tmpS);
-  if (S2 != NULL)
-    SDL_UnlockSurface(S2);
-
-  ret = SDL_DisplayFormatAlpha(tmpS);
-  SDL_FreeSurface(tmpS);
-
-  return ret;
-}
-#ifdef HAVE_LIBSDL_PANGO
-
-SDLPango_Context *context = NULL;
-
-void init_SDLPango_Context()
-{
-   if((context =  SDLPango_CreateContext_GivenFontDesc(settings.theme_font_name))==NULL)
-	   context =  SDLPango_CreateContext();
-   SDLPango_SetBaseDirection(context, SDLPANGO_DIRECTION_LTR);
-   SDLPango_SetDpi(context, 125.0, 125.0);
-}
-void free_SDLPango_Context()
-{
-  if(context != NULL)
-    SDLPango_FreeContext(context);
-  context = NULL;
-}
-#endif
-
-
-/* BlackOutline() creates a surface containing text of the designated */
-/* foreground color, surrounded by a black shadow, on a transparent    */
-/* 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* out = NULL;
-  SDL_Surface* black_letters = NULL;
-  SDL_Surface* white_letters = NULL;
-  SDL_Surface* bg = NULL;
-  SDL_Rect dstrect;
-  Uint32 color_key;
-
-  if (!t || !font || !c)
-  {
-    fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
-    return NULL;
-  }
- 
-#ifndef HAVE_LIBSDL_PANGO
-  black_letters = TTF_RenderUTF8_Blended(font, t, black);
-#else
-  if( context != NULL)
-  {
-    SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_BLACK_LETTER);
-    SDLPango_SetText(context, t, -1);
-    black_letters = SDLPango_CreateSurfaceDraw(context);
-  }
-  else {
-    black_letters = TTF_RenderUTF8_Blended(font, t, black);
-  }
-#endif
-
-  if (!black_letters)
-  {
-    fprintf (stderr, "Warning - BlackOutline() could not create image for %s\n", t);
-    return NULL;
-  }
-
-  bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
-                            (black_letters->w) + 5,
-                            (black_letters->h) + 5,
-                             32,
-                             rmask, gmask, bmask, amask);
-  /* Use color key for eventual transparency: */
-  color_key = SDL_MapRGB(bg->format, 01, 01, 01);
-  SDL_FillRect(bg, NULL, color_key);
-
-  /* Now draw black outline/shadow 2 pixels on each side: */
-  dstrect.w = black_letters->w;
-  dstrect.h = black_letters->h;
-
-  /* NOTE: can make the "shadow" more or less pronounced by */
-  /* changing the parameters of these loops.                */
-  for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
-    for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
-      SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
-
-  SDL_FreeSurface(black_letters);
-
-  /* --- Put the color version of the text on top! --- */
-#ifndef HAVE_LIBSDL_PANGO
-  white_letters = TTF_RenderUTF8_Blended(font, t, *c);
-#else
-  if( context != NULL)
-  {
-    SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_WHITE_LETTER);
-    white_letters = SDLPango_CreateSurfaceDraw(context);
-  }
-  else {
-    white_letters = TTF_RenderUTF8_Blended(font, t, *c);
-  }
-#endif
-
-  dstrect.x = 1;
-  dstrect.y = 1;
-  SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
-  SDL_FreeSurface(white_letters);
-
-  /* --- Convert to the screen format for quicker blits --- */
-  SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
-  out = SDL_DisplayFormatAlpha(bg);
-  SDL_FreeSurface(bg);
-
-  return out;
-}
-
-
-/* This version takes a wide character string and renders it with the */
-/* Unicode string versions of the SDL_ttf functions:                  */
-SDL_Surface* BlackOutline_Unicode(const Uint16* t, const TTF_Font* font, const SDL_Color* c)
-{
-  SDL_Surface* out = NULL;
-  SDL_Surface* black_letters = NULL;
-  SDL_Surface* white_letters = NULL;
-  SDL_Surface* bg = NULL;
-  SDL_Rect dstrect;
-  Uint32 color_key;
-
-  if (!font || !c)
-  {
-    fprintf(stderr, "BlackOutline_wchar(): invalid ptr parameter, returning.");
-    return NULL;
-  }
-                                        /* (cast to stop compiler complaint) */
-  black_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, black);
-
-  if (!black_letters)
-  {
-    fprintf (stderr, "Warning - BlackOutline_wchar() could not create image for %S\n", t);
-    return NULL;
-  }
-
-  bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
-                            (black_letters->w) + 5,
-                            (black_letters->h) + 5,
-                             32,
-                             rmask, gmask, bmask, amask);
-  /* Use color key for eventual transparency: */
-  color_key = SDL_MapRGB(bg->format, 10, 10, 10);
-  SDL_FillRect(bg, NULL, color_key);
-
-  /* Now draw black outline/shadow 2 pixels on each side: */
-  dstrect.w = black_letters->w;
-  dstrect.h = black_letters->h;
-
-  /* NOTE: can make the "shadow" more or less pronounced by */
-  /* changing the parameters of these loops.                */
-  for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
-    for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
-      SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
-
-  SDL_FreeSurface(black_letters);
-
-  /* --- Put the color version of the text on top! --- */
-                                       /* (cast to stop compiler complaint) */
-  white_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, *c);
-  dstrect.x = 1;
-  dstrect.y = 1;
-  SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
-  SDL_FreeSurface(white_letters);
-
-  /* --- Convert to the screen format for quicker blits --- */
-  SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
-  out = SDL_DisplayFormatAlpha(bg);
-  SDL_FreeSurface(bg);
-
-  return out;
-}
-
-
-SDL_Surface* BlackOutline_w(wchar_t* t, const TTF_Font* font, const SDL_Color* c, int size)
-{
-	wchar_t wchar_tmp[512];
-	char tmp[512];
-	int i;
-	wcsncpy( wchar_tmp, t, size);
-	wchar_tmp[size]=0;
-	i=ConvertToUTF8( wchar_tmp, tmp);
-	tmp[i]=0;
-	return BlackOutline(tmp, font, c);
-}
-
-
-int inRect( SDL_Rect r, int x, int y) {
-        if ((x < r.x) || (y < r.y) || (x > r.x + r.w) || (y > r.y + r.h))
-                return 0;
-        return 1;
-}
-
-/* Darkens the screen by a factor of 2^bits */
-void DarkenScreen(Uint8 bits)
-{
-#if BPP == 32
-  Uint32* p;
-#elif BPP == 16
-  Uint16* p;
-#else
-  return;
-#endif
-
-  Uint32 rm = screen->format->Rmask;
-  Uint32 gm = screen->format->Gmask;
-  Uint32 bm = screen->format->Bmask;
-
-
-  int x, y;
-
-  /* (realistically, 1 and 2 are the only useful values) */
-  if (bits > 8)
-    return;
-
-  p = screen->pixels;
-
-  for (y = 0; y < screen->h; y++)
-  {
-    for (x = 0; x < screen->w; x++)
-    {
-      *p = (((*p&rm)>>bits)&rm)
-         | (((*p&gm)>>bits)&gm)
-         | (((*p&bm)>>bits)&bm);
-      p++;
-    }
-  }
-}
-
-
-void SwitchScreenMode(void)
-{
-  int window = (screen->flags & SDL_FULLSCREEN);
-  SDL_Surface* oldscreen = screen;
-
-  if (!window)
-  {
-    screen = SDL_SetVideoMode(fs_res_x,
-                              fs_res_y,
-                              BPP,
-                              SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);
-  }
-  else
-  {
-    screen = SDL_SetVideoMode(RES_X,
-                              RES_Y,
-                              BPP,
-                              SDL_SWSURFACE|SDL_HWPALETTE);
-
-  }
-
-  if (screen == NULL)
-  {
-    fprintf(stderr,
-            "\nError: I could not switch to %s mode.\n"
-            "The Simple DirectMedia error that occured was:\n"
-            "%s\n\n",
-            window ? "windowed" : "fullscreen",
-            SDL_GetError());
-    screen = oldscreen;
-  }
-  else
-  {
-    SDL_FreeSurface(oldscreen);
-    oldscreen = NULL;
-    SDL_UpdateRect(screen, 0, 0, 0, 0);
-  }
-
-}
-
-
-int WaitForKeypress(void)
-{
-  SDL_Event evt;
-  while (1)
-    while (SDL_PollEvent(&evt) )
-      if (evt.type == SDL_KEYDOWN)
-        return evt.key.keysym.sym;
-      else SDL_Delay(50);
-}
-/* Swiped shamelessly from TuxPaint
-   Based on code from: http://www.codeproject.com/cs/media/imageprocessing4.asp
-   copyright 2002 Christian Graus */
-
-SDL_Surface* zoom(SDL_Surface* src, int new_w, int new_h)
-{
-  SDL_Surface* s;
-
-  /* These function pointers will point to the appropriate */
-  /* putpixel() and getpixel() variants to be used in the  */
-  /* current colorspace:                                   */
-  void (*putpixel) (SDL_Surface*, int, int, Uint32);
-  Uint32(*getpixel) (SDL_Surface*, int, int);
-
-  float xscale, yscale;
-  int x, y;
-  int floor_x, ceil_x,
-        floor_y, ceil_y;
-  float fraction_x, fraction_y,
-        one_minus_x, one_minus_y;
-  float n1, n2;
-  Uint8 r1, g1, b1, a1;
-  Uint8 r2, g2, b2, a2;
-  Uint8 r3, g3, b3, a3;
-  Uint8 r4, g4, b4, a4;
-  Uint8 r, g, b, a;
-
-  /* Create surface for zoom: */
-
-  s = SDL_CreateRGBSurface(src->flags,        /* SDL_SWSURFACE, */
-                           new_w, new_h, src->format->BitsPerPixel,
-                           src->format->Rmask,
-                           src->format->Gmask,
-                           src->format->Bmask,
-                           src->format->Amask);
-
-  if (s == NULL)
-  {
-    fprintf(stderr, "\nError: Can't build zoom surface\n"
-            "The Simple DirectMedia Layer error that occurred was:\n"
-            "%s\n\n", SDL_GetError());
-    return NULL;
-//    cleanup();
-//    exit(1);
-  }
-
-
-  /* Now assign function pointers to correct functions based */
-  /* on data format of original and zoomed surfaces:         */
-  getpixel = getpixels[src->format->BytesPerPixel];
-  putpixel = putpixels[s->format->BytesPerPixel];
-
-  SDL_LockSurface(src);
-  SDL_LockSurface(s);
-
-  xscale = (float) src->w / (float) new_w;
-  yscale = (float) src->h / (float) new_h;
-
-  for (x = 0; x < new_w; x++)
-  {
-    for (y = 0; y < new_h; y++)
-    {
-      /* Here we calculate the new RGBA values for each pixel */
-      /* using a "weighted average" of the four pixels in the */
-      /* corresponding location in the orginal surface:       */
-
-      /* figure out which original pixels to use in the calc: */
-      floor_x = floor((float) x * xscale);
-      ceil_x = floor_x + 1;
-      if (ceil_x >= src->w)
-        ceil_x = floor_x;
-
-      floor_y = floor((float) y * yscale);
-      ceil_y = floor_y + 1;
-      if (ceil_y >= src->h)
-        ceil_y = floor_y;
-
-      fraction_x = x * xscale - floor_x;
-      fraction_y = y * yscale - floor_y;
-
-      one_minus_x = 1.0 - fraction_x;
-      one_minus_y = 1.0 - fraction_y;
-
-      /* Grab their values:  */
-      SDL_GetRGBA(getpixel(src, floor_x, floor_y), src->format,
-                  &r1, &g1, &b1, &a1);
-      SDL_GetRGBA(getpixel(src, ceil_x,  floor_y), src->format,
-                  &r2, &g2, &b2, &a2);
-      SDL_GetRGBA(getpixel(src, floor_x, ceil_y),  src->format,
-                  &r3, &g3, &b3, &a3);
-      SDL_GetRGBA(getpixel(src, ceil_x,  ceil_y),  src->format,
-                  &r4, &g4, &b4, &a4);
-
-      /* Create the weighted averages: */
-      n1 = (one_minus_x * r1 + fraction_x * r2);
-      n2 = (one_minus_x * r3 + fraction_x * r4);
-      r = (one_minus_y * n1 + fraction_y * n2);
-
-      n1 = (one_minus_x * g1 + fraction_x * g2);
-      n2 = (one_minus_x * g3 + fraction_x * g4);
-      g = (one_minus_y * n1 + fraction_y * n2);
-
-      n1 = (one_minus_x * b1 + fraction_x * b2);
-      n2 = (one_minus_x * b3 + fraction_x * b4);
-      b = (one_minus_y * n1 + fraction_y * n2);
-
-      n1 = (one_minus_x * a1 + fraction_x * a2);
-      n2 = (one_minus_x * a3 + fraction_x * a4);
-      a = (one_minus_y * n1 + fraction_y * n2);
-
-      /* and put them into our new surface: */
-      putpixel(s, x, y, SDL_MapRGBA(s->format, r, g, b, a));
-
-    }
-  }
-
-  SDL_UnlockSurface(s);
-  SDL_UnlockSurface(src);
-
-  return s;
-}
-

Deleted: tuxtype/branches/tuxtype-soc-mh/SDL_extras.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/SDL_extras.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/SDL_extras.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,54 +0,0 @@
-//
-// C Interface: SDL_extras
-//
-// Description: A few handy functions for using SDL graphics.
-//
-//
-// Author: David Bruce,,, <dbruce at tampabay.rr.com>, (C) 2007
-//
-// Copyright: See COPYING file that comes with this distribution
-// (briefly, GPL v3 or later).
-//
-
-#ifndef SDL_EXTRAS_H
-#define SDL_EXTRAS_H
-
-#include "SDL.h"
-#include "SDL_ttf.h"
-
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-#define rmask 0xff000000
-#define gmask 0x00ff0000
-#define bmask 0x0000ff00
-#define amask 0x000000ff
-#else
-#define rmask 0x000000ff
-#define gmask 0x0000ff00
-#define bmask 0x00ff0000
-#define amask 0xff000000
-#endif
-
-#ifdef HAVE_LIBSDL_PANGO
-//#ifdef SDL_Pango
-#include "SDL_Pango.h"
-
-extern SDLPango_Context *context;
-void init_SDLPango_Context();
-void free_SDLPango_Context();
-#endif
-
-void DrawButton(SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
-void RoundCorners(SDL_Surface* s, Uint16 radius);
-SDL_Surface* Flip(SDL_Surface *in, int x, int y);
-SDL_Surface* BlackOutline(const char *t, TTF_Font* font, 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);
-int  inRect(SDL_Rect r, int x, int y);
-void DarkenScreen(Uint8 bits);
-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);
-
-
-#endif

Deleted: tuxtype/branches/tuxtype-soc-mh/alphabet.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/alphabet.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/alphabet.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,1817 +0,0 @@
-/***************************************************************************
-                          alphabet.c 
- -  description: Init SDL
-                             -------------------
-    begin                : Jan 6 2003
-    copyright            : (C) 2003 by Jesse Andrews
-    email                : jdandr2 at tux4kids.net
-Revised extensively: 2008
-Sreyas Kurumanghat <k.sreyas at gmail.com>
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-
-/* Needed to handle rendering issues for Indic languages*/
-#ifndef WIN32
-#ifndef MACOSX
-#include <SDL_Pango.h>
-#endif
-#endif
-
-/* Needed to convert UTF-8 under Windows because we don't have glibc: */
-#include "ConvertUTF.h"  
-
-#include "globals.h"
-#include "funcs.h"
-
-
-/* NOTE these are externed in globals.h so not static */
-/* the colors we use throughout the game */
-SDL_Color black;
-SDL_Color gray;
-SDL_Color dark_blue;
-SDL_Color red;
-SDL_Color white;
-SDL_Color yellow;
-
-
-
-/* An individual item in the list of cached unicode characters that are rendered at   */
-/* the start of each game.                                                            */
-typedef struct uni_glyph {
-  wchar_t unicode_value;
-  SDL_Surface* white_glyph;
-  SDL_Surface* red_glyph;
-} uni_glyph;
-
-/* These are the arrays for the red and white letters: */
-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. */
-/*typedef struct keymap {
-	char keyname[5];
-	int shift;
-} keymap;*/
-typedef struct kbd_char {
-  wchar_t unicode_value;
-  char finger;
-	//keymap key;
-	char keyname[5];
-	int shift;
-	char latin_char;
-} kbd_char;
-
-/* 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 TTF_Font* font = NULL;
-
-/* Used for word list functions (see below): */
-static int num_words;
-static wchar_t word_list[MAX_NUM_WORDS][MAX_WORD_SIZE + 1];
-static wchar_t char_list[MAX_UNICODES];  // List of distinct letters in word list
-static int num_chars_used = 0;       // Number of different letters in word list
-
-
-
-/* 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 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);
-
-#ifndef WIN32
-#ifndef MACOSX
-static SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color* cl);
-#endif
-#endif
-
-
-
-/*****************************************************/
-/*                                                   */
-/*          "Public" Functions                       */
-/*                                                   */
-/*****************************************************/
-
-
-
-/* FIXME would be better to get keymap from system somehow (SDL? X11?) - */
-/* all this does now is fiddle with the ALPHABET and FINGER arrays */
-int LoadKeyboard(void)
-{
-  unsigned char fn[FNLEN];
-  int found = 0;
-
-  clear_keyboard();
-
-  /* First look for keyboard.lst in theme path, if desired: */
-  if (!settings.use_english)
-  {
-    sprintf(fn , "%s/keyboard.lst", settings.theme_data_path);
-    if (CheckFile(fn))
-    {
-      found = 1;
-    }
-  }
-
-  /* Now look in default path if desired or needed: */
-  if (!found)
-  {
-    sprintf(fn , "%s/keyboard.lst", settings.default_data_path);
-    if (CheckFile(fn))
-    {
-      found = 1;
-    }
-  }
-
-  if (!found)
-  {
-    fprintf(stderr, "LoadKeyboard(): Error finding file for keyboard setup!\n");
-    return 0;
-  }
-  
-  /* fn should now contain valid path to keyboard.lst: */
-  DEBUGCODE{fprintf(stderr, "fn = %s\n", fn);}
-
-  {
-    unsigned char str[255];
-    wchar_t wide_str[255];
-
-    FILE* f;
-    int i = 0, j = 0, k = 0;
-
-    f = fopen( fn, "r" );
-
-    if (f == NULL)
-    {
-      LOG("LoadKeyboard() - could not open keyboard.lst\n");
-      return 0;
-    }
-
-
-    do
-    {
-      fscanf( f, "%[^\n]\n", str);
-      /* Convert to wcs from UTF-8, if needed; */
-      //mbstowcs(wide_str, str, strlen(str) + 1);
-      ConvertFromUTF8(wide_str, str);
-
-      /* 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[2] == Unicode value of character          */
-
-      /* FIXME - this might be a good place to use a    */
-      /* hash table to avoid n^2 performance problems.  */
-      /* Some sanity checks:  */
-      if ((wcslen(wide_str) >=3)
-       && (wcstol(&wide_str[0], NULL, 0) >=0)   /* These lines just make sure the */
-       && (wcstol(&wide_str[0], NULL, 0) < 10)  /* finger is between 0 and 10     */
-       && (wide_str[1] == '|')
-       && (k < MAX_UNICODES)
-       && !unicode_in_key_list(wide_str[2])) /* Make sure char not already added */
-      {
-        DEBUGCODE
-        {
-          fprintf(stderr, "Adding key: Unicode char = '%C'\tUnicode value = %d\tfinger = %d\n",
-                  wide_str[2], wide_str[2], wcstol(&wide_str[0], NULL, 0)); 
-	}
-
-        /* Just plug values into array: */
-        keyboard_list[k].unicode_value = wide_str[2];
-        keyboard_list[k].finger = wcstol(&wide_str[0], NULL, 0);
-	if (wcslen(wide_str) <5)
-	{
-		if(!settings.use_english)
-		{
-			map_keys(-1,&keyboard_list[k]);
-			keyboard_list[k].latin_char=-1;
-			keyboard_list[k].finger = wcstol(&wide_str[0], NULL, 0);
-		}
-		else
-		{
-			map_keys(wide_str[2],&keyboard_list[k]);
-			keyboard_list[k].latin_char=wide_str[2];
-		}
-	}
-	else
-	{
-		map_keys(wide_str[4],&keyboard_list[k]);
-		keyboard_list[k].latin_char=wide_str[4];
-	}
-        k++;
-      }
-	else
-	{
-		if(wcslen(wide_str)==1)
-		{
-			if(!settings.use_english)
-			{
-				keyboard_list[k].unicode_value = wide_str[0];
-				map_keys(-1,&keyboard_list[k]);
-				keyboard_list[k].latin_char=-1;
-			}
-			else
-			{
-				keyboard_list[k].unicode_value = wide_str[0];
-				map_keys(-1,&keyboard_list[k]);
-				keyboard_list[k].latin_char=wide_str[0];
-			}
-			k++;
-		}
-		
-	}
-			
-    } while (!feof(f));
-
-
-    fclose(f);
-    LOG("Leaving LoadKeyboard()\n");
-    return 1;
-  }
-}
-
-/* Returns the finger hint(0-9) associated with a given Unicode value */
-/* in the keyboard_list:                                              */
-/* Returns -1 if somehow no finger associated with a Unicode value    */
-/* in the list (shouldn't happen).                                    */
-/* Returns -2 if Unicode value not in list.                           */
-int GetFinger(int i)
-{
-  if (i == -1)
-  {
-    fprintf(stderr, "GetFinger() - Unicode char '%C' not found in list.\n");
-    return -2;
-  }
-
-  if ((keyboard_list[i].finger < 0)
-   || (keyboard_list[i].finger > 9))
-  {
-    fprintf(stderr, "GetFinger() - Unicode char '%C' has no valid finger.\n");
-    return -1;
-  }  
-
-  return (int)keyboard_list[i].finger; /* Keep compiler from complaining */
-}
-
-int GetShift(int i)
-{
-	return keyboard_list[i].shift;
-}
-
-int GetIndex(wchar_t uni_char)
-{
-  int i = 0;
-
-  while ((i < MAX_UNICODES)
-     &&  (keyboard_list[i].unicode_value != uni_char))
-  {
-    i++;
-  }
-
-  if (i == MAX_UNICODES)
-  {
-    fprintf(stderr, "GetIndex - Unicode char '%C' not found in list.\n", uni_char);
-    return -1;
-  }
-
-  return i;
-}
-
-void GetKeyPos(int index, char *buf)
-{
-	sprintf(buf,"keyboard/keyboard_%s.png", keyboard_list[index].keyname);	
-}
-
-void GetWrongKeyPos(int index, char *buf)
-{
-	sprintf(buf,"keyboard/keyboardN_%s.png", keyboard_list[index].keyname);
-}
-
-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);			
-}
-wchar_t GetLastKey()
-{
-	if(!num_chars_used)
-		return -1;
-	else
-		return keyboard_list[num_chars_used-1].unicode_value;
-} 
-int unicode_in_key_list(wchar_t uni_char)
-{
-  int i = 0;
-  while ((i < MAX_UNICODES)
-     &&  (keyboard_list[i].unicode_value != uni_char))
-  {
-    i++;
-  }
-  if (i == MAX_UNICODES)
-    return 0;
-  else
-    return 1;
-}
-
-// /* NOTE if we can consistently use SDLPango on all platforms, we can simply */
-// /* rename the pango version to BlackOutline() and get rid of this one.      */
-// /* The input for this function should be UTF-8.                             */
-// SDL_Surface* BlackOutline(const unsigned char* t, const TTF_Font* font, const SDL_Color* c)
-// {
-//   SDL_Surface* out = NULL;
-//   SDL_Surface* black_letters = NULL;
-//   SDL_Surface* white_letters = NULL;
-//   SDL_Surface* bg = NULL;
-//   SDL_Rect dstrect;
-//   Uint32 color_key;
-// 
-//   LOG("Entering BlackOutline()\n");
-// 
-// /* Simply passthrough to SDLPango version if available (i.e. not under Windows):*/
-// #ifndef WIN32
-// #ifndef MACOSX
-// return BlackOutline_SDLPango(t, font, c);
-// #endif
-// #endif
-// 
-// 
-//   if (!t || !font || !c)
-//   {
-//     fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
-//     return NULL;
-//   }
-// 
-//   black_letters = TTF_RenderUTF8_Blended((TTF_Font*)font, t, black);
-// 
-//   if (!black_letters)
-//   {
-//     fprintf (stderr, "Warning - BlackOutline() could not create image for %s\n", t);
-//     return NULL;
-//   }
-// 
-//   bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
-//                             (black_letters->w) + 5,
-//                             (black_letters->h) + 5,
-//                              32,
-//                              RMASK, GMASK, BMASK, AMASK);
-//   /* Use color key for eventual transparency: */
-//   color_key = SDL_MapRGB(bg->format, 10, 10, 10);
-//   SDL_FillRect(bg, NULL, color_key);
-// 
-//   /* Now draw black outline/shadow 2 pixels on each side: */
-//   dstrect.w = black_letters->w;
-//   dstrect.h = black_letters->h;
-// 
-//   /* NOTE: can make the "shadow" more or less pronounced by */
-//   /* changing the parameters of these loops.                */
-//   for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
-//     for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
-//       SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
-// 
-//   SDL_FreeSurface(black_letters);
-// 
-//   /* --- Put the color version of the text on top! --- */
-//   /* NOTE we cast away the 'const-ness' to keep compliler from complaining: */
-//   white_letters = TTF_RenderUTF8_Blended((TTF_Font*)font, t, *c);
-//   dstrect.x = 1;
-//   dstrect.y = 1;
-//   SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
-//   SDL_FreeSurface(white_letters);
-// 
-//   /* --- Convert to the screen format for quicker blits --- */
-//   SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
-//   out = SDL_DisplayFormatAlpha(bg);
-//   SDL_FreeSurface(bg);
-// 
-//   LOG("Leaving BlackOutline()\n");
-// 
-//   return out;
-// }
-
-
-
-#ifndef WIN32
-#ifndef MACOSX
-/*Convert SDL_Colour to SDLPango_Matrix*/
-
-SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color *cl)
-{
-  SDLPango_Matrix *colour;
-  colour=malloc(sizeof(SDLPango_Matrix));
-  int k;
-  for(k=0;k<4;k++){
-  	(*colour).m[0][k]=(*cl).r;
-  	(*colour).m[1][k]=(*cl).g;
-  	(*colour).m[2][k]=(*cl).b;
-  }
-  (*colour).m[3][0]=0;
-  (*colour).m[3][1]=255;
-  (*colour).m[3][2]=0;
-  (*colour).m[3][3]=0;
-
-  return colour;
-}
-
-
-
-// /* This version basically uses the SDLPango lib instead of */
-// /* TTF_RenderUTF*_Blended() to properly render Indic text. */
-// SDL_Surface* BlackOutline_SDLPango(const unsigned char* t, const TTF_Font* font, const SDL_Color* c)
-// {
-//   SDL_Surface* out = NULL;
-//   SDL_Surface* black_letters = NULL;
-//   SDL_Surface* white_letters = NULL;
-//   SDL_Surface* bg = NULL;
-//   SDL_Rect dstrect;
-//   Uint32 color_key;
-//   /* To covert SDL_Colour to SDLPango_Matrix */
-//   SDLPango_Matrix* colour = NULL;
-//   /* Create a context which contains Pango objects.*/
-//   SDLPango_Context* context = NULL;
-// 
-//   LOG("\nEntering BlackOutline_SDLPango()\n");
-//   DEBUGCODE{ fprintf(stderr, "will attempt to render: %s\n", t); }
-// 
-//   if (!t || !font || !c)
-//   {
-//     fprintf(stderr, "BlackOutline_SDLPango(): invalid ptr parameter, returning.");
-//     return NULL;
-//   }
-// 
-//   /* SDLPango crashes on 64 bit machines if passed empty string - Debian Bug#439071 */
-//   if (*t == '\0')
-//   {
-//     fprintf(stderr, "BlackOutline_SDLPango(): empty string arg - must return to avoid segfault.");
-//     return NULL;
-//   }
-// 
-//   colour = SDL_Colour_to_SDLPango_Matrix(c);
-//   
-//   /* Create the context */
-//   context = SDLPango_CreateContext();	
-//   SDLPango_SetDpi(context, 125.0, 125.0);
-//   /* Set the color */
-//   SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_BLACK_LETTER );
-//   SDLPango_SetBaseDirection(context, SDLPANGO_DIRECTION_LTR);
-//   /* Set text to context */ 
-//   SDLPango_SetMarkup(context, t, -1); 
-// 
-//   if (!context)
-//   {
-//     fprintf (stderr, "In BlackOutline_SDLPango(), could not create context for %s", t);
-//     return NULL;
-//   }
-// 
-//   black_letters = SDLPango_CreateSurfaceDraw(context);
-// 
-//   if (!black_letters)
-//   {
-//     fprintf (stderr, "Warning - BlackOutline_SDLPango() could not create image for %s\n", t);
-//     return NULL;
-//   }
-// 
-//   bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
-//                             (black_letters->w) + 5,
-//                             (black_letters->h) + 5,
-//                              32,
-//                              RMASK, GMASK, BMASK, AMASK);
-//   if (!bg)
-//   {
-//     fprintf (stderr, "Warning - BlackOutline()_SDLPango - bg creation failed\n");
-//     SDL_FreeSurface(black_letters);
-//     return NULL;
-//   }
-// 
-//   /* Draw text on a existing surface */
-//   SDLPango_Draw(context, bg, 0, 0);
-// 
-//   /* Use color key for eventual transparency: */
-//   color_key = SDL_MapRGB(bg->format, 10, 10, 10);
-//   SDL_FillRect(bg, NULL, color_key);
-// 
-//   /* Now draw black outline/shadow 2 pixels on each side: */
-//   dstrect.w = black_letters->w;
-//   dstrect.h = black_letters->h;
-// 
-//   /* NOTE: can make the "shadow" more or less pronounced by */
-//   /* changing the parameters of these loops.                */
-//   for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
-//     for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
-//       SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
-// 
-//   SDL_FreeSurface(black_letters);
-// 
-//   /* --- Put the color version of the text on top! --- */
-//   SDLPango_SetDefaultColor(context, colour);
-//   white_letters = SDLPango_CreateSurfaceDraw(context);
-//   dstrect.x = 1;
-//   dstrect.y = 1;
-//   SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
-//   SDL_FreeSurface(white_letters);
-// 
-//   /* --- Convert to the screen format for quicker blits --- */
-//   SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
-//   out = SDL_DisplayFormatAlpha(bg);
-//   SDL_FreeSurface(bg);
-// 
-//   LOG("Leaving BlackOutline_SDLPango()\n\n");
-// 
-//   return out;
-// }
-
-#endif
-#endif
-/* End of win32-excluded coded */
-
-
-
-
-// /* This version takes a wide character string and renders it with the */
-// /* Unicode string versions of the SDL_ttf functions:                  */
-// SDL_Surface* BlackOutline_Unicode(const Uint16* t, const TTF_Font* font, const SDL_Color* c)
-// {
-//   SDL_Surface* out = NULL;
-//   SDL_Surface* black_letters = NULL;
-//   SDL_Surface* white_letters = NULL;
-//   SDL_Surface* bg = NULL;
-//   SDL_Rect dstrect;
-//   Uint32 color_key;
-// 
-//   if (!font || !c)
-//   {
-//     fprintf(stderr, "BlackOutline_wchar(): invalid ptr parameter, returning.");
-//     return NULL;
-//   }
-//                                         /* (cast to stop compiler complaint) */
-//   black_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, black);
-// 
-//   if (!black_letters)
-//   {
-//     fprintf (stderr, "Warning - BlackOutline_wchar() could not create image for %S\n", t);
-//     return NULL;
-//   }
-// 
-//   bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
-//                             (black_letters->w) + 5,
-//                             (black_letters->h) + 5,
-//                              32,
-//                              RMASK, GMASK, BMASK, AMASK);
-//   /* Use color key for eventual transparency: */
-//   color_key = SDL_MapRGB(bg->format, 10, 10, 10);
-//   SDL_FillRect(bg, NULL, color_key);
-// 
-//   /* Now draw black outline/shadow 2 pixels on each side: */
-//   dstrect.w = black_letters->w;
-//   dstrect.h = black_letters->h;
-// 
-//   /* NOTE: can make the "shadow" more or less pronounced by */
-//   /* changing the parameters of these loops.                */
-//   for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
-//     for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
-//       SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
-// 
-//   SDL_FreeSurface(black_letters);
-// 
-//   /* --- Put the color version of the text on top! --- */
-//                                        /* (cast to stop compiler complaint) */
-//   white_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, *c);
-//   dstrect.x = 1;
-//   dstrect.y = 1;
-//   SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
-//   SDL_FreeSurface(white_letters);
-// 
-//   /* --- Convert to the screen format for quicker blits --- */
-//   SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
-//   out = SDL_DisplayFormatAlpha(bg);
-//   SDL_FreeSurface(bg);
-// 
-//   return out;
-// }
-
-
-/* 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);
-}
-
-
-/* Returns a random Unicode char from the char_glyphs list: */
-/* --- get a letter --- */
-wchar_t GetRandLetter(void)
-{
-  static wchar_t last = -1; // we don't want to return same letter twice in a row
-  wchar_t letter;
-  int i = 0;
-
-  if (!num_chars_used)
-  {
-    fprintf(stderr, "GetRandLetter() - no letters in list!\n");
-    last = -1;
-    return -1;
-  }
-
-  do
-  {
-    i = rand() % num_chars_used;
-    letter = char_glyphs[i].unicode_value;
-  } while (letter == last);
-
-  last = letter;
-
-  return letter;
-}
-
-/******************************************************************************
-*                           WORD FILE & DATA STRUCTURE                        *
-******************************************************************************/
-
-
-
-/* ClearWordList: clears the number of words
- */
-void ClearWordList(void)
-{
-  int i;
-  for (i = 0; i < num_words; i++)
-  {
-    word_list[i][0] = '\0';
-  }
-  num_words = 0;
-}
-
-/* FIXME need a better i18n-compatible way to do this: */
-/* UseAlphabet(): setups the word_list so that it really
- * returns a LETTER when GetWord() is called
- */
-// void UseAlphabet(void)
-// {
-// 	int i;
-// 
-// 	LOG("Entering UseAlphabet()\n");
-// 
-// 	num_words = 0;
-// 	/* This totally mucks up i18n abilities :( */
-// 	for (i=65; i<90; i++) 
-// 	{
-// 		//if (ALPHABET[i])
-//                 {
-// 			word_list[num_words][0] = (unsigned char)i;
-// 			word_list[num_words][1] = '\0';
-// 			num_words++;
-// 
-// 			DEBUGCODE { fprintf(stderr, "Adding %c\n", (unsigned char)i); }
-// 		}
-// 	}
-// 	/* Make sure list is terminated with null character */
-// 	word_list[num_words][0] = '\0';
-// 
-// 	/* Make list of all unicode characters used in word list: */
-// 	gen_char_list();
-// 
-// 	DOUT(num_words);
-// 	LOG("Leaving UseAlphabet()\n");
-// }
-
-/* GetWord: returns a random word that wasn't returned
- * the previous time (unless there is only 1 word!!!)
- */
-wchar_t* GetWord(void)
-{
-	static int last_choice = -1;
-	int choice;
-
-	LOG("Entering GetWord()\n");
-	DEBUGCODE { fprintf(stderr, "num_words is: %d\n", num_words); }
-
-	/* Now count list to make sure num_words is correct: */
-
-	num_words = 0;
-	while (word_list[num_words][0] != '\0')
-	{
-	  num_words++;
-	}
-
-	DEBUGCODE { fprintf(stderr, "After count, num_words is: %d\n", num_words); }
-
-        if (0 == num_words)
-	{
-	  LOG("No words in list\n");
-          return NULL;
-	}
-
-        if (num_words > MAX_NUM_WORDS)
-	{
-	  LOG("Error: num_words greater than array size\n");
-          return NULL;
-	}
-
-        if (num_words < 0)
-	{
-	  LOG("Error: num_words negative\n");
-          return NULL;
-	}
-
-	do {
-		choice = (rand() % num_words);
-	} while ((choice == last_choice) || (num_words < 2));
-
-	last_choice = choice;
-
-	/* NOTE need %S rather than %s because of wide characters */
-	DEBUGCODE { fprintf(stderr, "Selected word is: %S\n", word_list[choice]); }
-
-	return word_list[choice];
-}
-
-
-
-/* GenerateWordList(): adds the words from a given wordlist
- * it ignores any words too long or that has bad
- * character (such as #)
- */
-
-/* Now returns the number of words in the list, so if no words */
-/* returns "false"                                             */
-int GenerateWordList(const char* wordFn)
-{
-  int j;
-  unsigned char temp_word[FNLEN];
-  wchar_t temp_wide_word[FNLEN];
-  size_t length;
-
-  FILE* wordFile=NULL;
-
-  DEBUGCODE { fprintf(stderr, "Entering GenerateWordList() for file: %s\n", wordFn); }
-
-  num_words = 0;
-
-  /* --- open the file --- */
-
-  wordFile = fopen( wordFn, "r" );
-
-  if ( wordFile == NULL )
-  {
-    fprintf(stderr, "ERROR: could not load wordlist: %s\n", wordFn );
-//    UseAlphabet( );
-    return 0;
-  }
-
-
-  /* --- load words from file named as argument: */
-
-  DEBUGCODE { fprintf(stderr, "WORD FILE OPENNED @ %s\n", wordFn); }
-
-  /* ignore the title (i.e. first line) */
-  fscanf( wordFile, "%[^\n]\n", temp_word);
-
-  while (!feof(wordFile) && (num_words < MAX_NUM_WORDS))
-  {
-    fscanf( wordFile, "%[^\n]\n", temp_word);
-    DEBUGCODE {fprintf(stderr, "temp_word = %s\n", temp_word);}
-
-    for (j = 0; j < strlen(temp_word); j++)
-    {
-      if (temp_word[j] == '\n' || temp_word[j] == '\r')
-        temp_word[j] = '\0';
-    }
-
-    /* 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);
-    DOUT(length);
-
-    if (length == -1)  /* Means invalid UTF-8 sequence or conversion failed */
-    {
-      fprintf(stderr, "Word '%s' not added - invalid UTF-8 sequence!\n", temp_word);
-      continue;
-    }
-
-    if (length == 0)
-    {
-      fprintf(stderr, "Word '%ls' not added - length is zero\n", temp_wide_word);
-      continue;
-    }
-
-    if (length > MAX_WORD_SIZE)
-    {
-      fprintf(stderr, "Word '%s' not added - exceeds %d characters\n",
-              temp_word, MAX_WORD_SIZE);
-      continue;
-    }
-
-    if (num_words >= MAX_NUM_WORDS)
-    {
-      fprintf(stderr, "Word '%s' not added - list has reached max of %d characters\n",
-              temp_word, MAX_NUM_WORDS);
-      continue;
-    }
-
-    if (!check_needed_unicodes_str(temp_wide_word))
-    {
-      fprintf(stderr, "Word '%S' not added - contains Unicode chars not in keyboard list\n",
-              temp_wide_word);
-      continue;
-    }
-
-    /* If we make it to here, OK to add word: */
-    /* NOTE we have to add one to the length argument */
-    /* to include the terminating null.  */
-    DEBUGCODE
-    {
-      fprintf(stderr, "Adding word: %ls\n", temp_wide_word);
-    }
-
-    wcsncpy(word_list[num_words], temp_wide_word, strlen(temp_word) + 1);
-    num_words++;
-  }
-        
-  /* Make sure list is terminated with null character */
-  word_list[num_words][0] = '\0';
-
-  DOUT(num_words);
-
-//  if (num_words == 0)
-//    UseAlphabet( );
-
-  fclose(wordFile);
-
-  /* Make list of all unicode characters used in word list: */
-  /* (we use this to check to make sure all are "typable"); */
-  gen_char_list();
-
-  LOG("Leaving GenerateWordList()\n");
-
-  return (num_words);
-}
-
-
-
-
-
-
-/* This version creates the letters using TTF_RenderUNICODE_Blended */
-int RenderLetters(const TTF_Font* letter_font)
-{
-  Uint16 t[2];
-  int i, j;  /* i is chars attempted, j is chars actually rendered. */
-
-  if (!letter_font)
-  {
-    fprintf(stderr, "RenderLetters() - invalid TTF_Font* argument!\n");
-    return 0;
-  }
-
-  i = j = num_chars_used = 0;
-
-  t[1] = '\0';
-
-  while (i < MAX_UNICODES)
-  {
-    t[0] = keyboard_list[i].unicode_value;
-
-    if (t[0] != 0)
-    {
-      DEBUGCODE
-      {
-        fprintf(stderr, "Creating SDL_Surface for list element %d, char = '%lc', Unicode value = %d\n", i, *t, *t);
-      }
-
-      char_glyphs[j].unicode_value = t[0];
-      char_glyphs[j].white_glyph = BlackOutline_Unicode(t, letter_font, &white);
-      char_glyphs[j].red_glyph = BlackOutline_Unicode(t, letter_font, &red);
-
-      j++;
-      num_chars_used++;
-    }
-    i++;
-  }
-
-  return num_chars_used;
-}
-
-
-
-void FreeLetters(void)
-{
-  int i;
-
-  for (i = 0; i < num_chars_used; i++)
-  {
-    SDL_FreeSurface(char_glyphs[i].white_glyph);
-    SDL_FreeSurface(char_glyphs[i].red_glyph);
-    char_glyphs[i].unicode_value = 0;
-    char_glyphs[i].white_glyph = NULL;
-    char_glyphs[i].red_glyph = NULL;
-  } 
-  /* List now empty: */
-  num_chars_used = 0;
-}
-
-
-SDL_Surface* GetWhiteGlyph(wchar_t t)
-{
-  int i;
-
-  for (i = 0;
-       (char_glyphs[i].unicode_value != t) && (i <= num_chars_used);
-       i++)
-  {}
-
-  /* Now return appropriate pointer: */
-  if (i > num_chars_used)
-  {
-    /* Didn't find character: */
-    fprintf(stderr, "Could not find glyph for Unicode char '%C', value = %d\n", t, t);
-    return NULL;
-  }
-  
-  /* Return corresponding surface for blitting: */
-  return char_glyphs[i].white_glyph;
-}
-
-
-
-SDL_Surface* GetRedGlyph(wchar_t t)
-{
-  int i;
-
-  for (i = 0;
-       char_glyphs[i].unicode_value != t && i <= num_chars_used;
-       i++)
-  {}
-
-  /* Now return appropriate pointer: */
-  if (i > num_chars_used)
-  {
-    /* Didn't find character: */
-    fprintf(stderr, "Could not find glyph for unicode character %lc\n", t);
-    return NULL;
-  }
-  
-  /* Return corresponding surface for blitting: */
-  return char_glyphs[i].red_glyph;
-}
-
-
-/* Checks to see if all of the glyphs needed by the word list have been     */
-/* 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.
-/* Returns 1 if all needed chars found, 0 otherwise.                        */
-int CheckNeededGlyphs(void)
-{
-  int i = 0;
-
-  while ((i < MAX_UNICODES)
-      && (char_list[i] != '\0'))
-  {
-    if (!GetWhiteGlyph(char_list[i]))
-    {
-      fprintf(stderr, "\nCheckNeededGlyphs() - needed char '%C' (Unicode value = %d) not found.\n",
-              char_list[i], char_list[i]);
-      fprintf(stderr, "This probably means that the theme's 'keyboard.lst' file is incorrect or incomplete.\n");
-      return 0;
-    }
-    i++;
-  }
-  LOG("CheckNeededGlyphs() - all chars found.\n");
-  return 1;
-}
-
-int check_needed_unicodes_str(const wchar_t* s)
-{
-  int i = 0;
-
-  while ((i < MAX_WORD_SIZE)
-      && (s[i] != '\0'))
-  {
-    if (!unicode_in_key_list(s[i]))
-    {
-      fprintf(stderr, "\ncheck_needed_unicodes_str() - needed char '%C' (Unicode value = %d) not found.\n",
-              s[i], s[i]);
-      return 0;
-    }
-    i++;
-  }
-  return 1;
-}
-
-/* This function just tidies up all the ptr args needed for      */
-/* ConvertUTF8toUTF32() from Unicode, Inc. into a neat wrapper.  */
-/* 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 i = 0;
-  ConversionResult result;
-  UTF8 temp_UTF8[FNLEN];
-  UTF32 temp_UTF32[FNLEN];
-
-  const UTF8* UTF8_Start = temp_UTF8;
-  const UTF8* UTF8_End = &temp_UTF8[FNLEN-1];
-  UTF32* UTF32_Start = temp_UTF32;
-  UTF32* UTF32_End = &temp_UTF32[FNLEN-1];
-
-  strncpy(temp_UTF8, UTF8_word, FNLEN);
-
-  ConvertUTF8toUTF32(&UTF8_Start, UTF8_End,
-                     &UTF32_Start, UTF32_End, 0);
-
-  wide_word[0] = '\0';
-
-  while ((i < FNLEN) && (temp_UTF32[i] != '\0'))
-  {
-    wide_word[i] = temp_UTF32[i];
-    i++; 
-  }
-
-  if (i >= FNLEN)
-  {
-    fprintf(stderr, "convert_from_UTF8(): buffer overflow\n");
-    return -1;
-  }
-  else  //need terminating null:
-  {
-    wide_word[i] = '\0';
-  }
-
-  DEBUGCODE {fprintf(stderr, "wide_word = %ls\n", wide_word);}
-
-  return wcslen(wide_word);
-}
-
-
-/* Now this uses GNU iconv and works correctly!   */
-/* This probably could be simplified - not certain */
-/* we have to copy into and out of the buffers     */
-
-/******************To be used for savekeyboard*************/
-/***Converts wchar_t string to char string*****************/
-int ConvertToUTF8(wchar_t* wide_word, unsigned char* UTF8_word)
-{
-  int i = 0;
-  UTF8 temp_UTF8[FNLEN];
-  UTF32 temp_UTF32[FNLEN];
-
-  UTF8* UTF8_Start = &temp_UTF8[0];
-  UTF8* UTF8_End = &temp_UTF8[FNLEN - 1];
-  const UTF32* UTF32_Start = &temp_UTF32[0];
-  const UTF32* UTF32_End = &temp_UTF32[FNLEN - 1];
-  
-  iconv_t conv_descr;
-  size_t bytes_converted;
-  size_t in_length = (size_t)FNLEN;
-  size_t out_length = (size_t)FNLEN;
-  wcsncpy(temp_UTF32, wide_word, FNLEN);
-
-  DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): wide_word = %S\n", wide_word);}
-  DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): temp_UTF32 = %S\n", temp_UTF32);}
-
-  conv_descr = iconv_open ("UTF-8", "UTF-32");
-  bytes_converted = iconv(conv_descr,
-                          &UTF32_Start, &in_length,
-                          &UTF8_Start, &out_length);
-  iconv_close(conv_descr);
-
-  UTF8_word[0] = 0;
-
-  while ((i < FNLEN) && (temp_UTF8[i] != 0))
-  {
-    UTF8_word[i] = temp_UTF8[i];
-    i++; 
-  }
-
-  if (i >= FNLEN)
-  {
-    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);}
-
-  return strlen(UTF8_word);
-}
-
-
-
-/******************************************************************/
-int map_keys(wchar_t wide_char,kbd_char* keyboard_entry)
-{
-	switch(wide_char)
-	{
-		case '`':strcpy(keyboard_entry->keyname,"A00");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=0;
-			break;
-		case '~':strcpy(keyboard_entry->keyname,"A00");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=0;
-			break;
-		case '1':strcpy(keyboard_entry->keyname,"A01");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=0;
-			break;
-		case '!':strcpy(keyboard_entry->keyname,"A01");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=0;
-			break;
-		case '2':strcpy(keyboard_entry->keyname,"A02");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=1;
-			break;
-		case '@':strcpy(keyboard_entry->keyname,"A02");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=1;
-			break;
-		case '3':strcpy(keyboard_entry->keyname,"A03");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=2;
-			break;
-		case '#':strcpy(keyboard_entry->keyname,"A03");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=2;
-			break;
-		case '4':strcpy(keyboard_entry->keyname,"A04");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=3;
-			break;
-		case '$':strcpy(keyboard_entry->keyname,"A04");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=3;
-			break;
-		case '5':strcpy(keyboard_entry->keyname,"A05");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=4;
-			break;
-		case '%':strcpy(keyboard_entry->keyname,"A05");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=4;
-			break;
-		case '6':strcpy(keyboard_entry->keyname,"A06");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=5;
-			break;
-		case '^':strcpy(keyboard_entry->keyname,"A06");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=5;
-			break;
-		case '7':strcpy(keyboard_entry->keyname,"A07");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=7;
-			break;
-		case '&':strcpy(keyboard_entry->keyname,"A07");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=6;
-			break;
-		case '8':strcpy(keyboard_entry->keyname,"A08");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=7;
-			break;
-		case '*':strcpy(keyboard_entry->keyname,"A08");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=7;
-			break;
-		case '9':strcpy(keyboard_entry->keyname,"A09");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=8;
-			break;
-		case '(':strcpy(keyboard_entry->keyname,"A09");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=8;
-			break;
-		case '0':strcpy(keyboard_entry->keyname,"A10");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case ')':strcpy(keyboard_entry->keyname,"A10");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;
-		case '-':strcpy(keyboard_entry->keyname,"A11");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case '_':strcpy(keyboard_entry->keyname,"A11");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;
-		case '=':strcpy(keyboard_entry->keyname,"A12");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case '+':strcpy(keyboard_entry->keyname,"A12");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;
-		case '\\':strcpy(keyboard_entry->keyname,"A13");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case '|':strcpy(keyboard_entry->keyname,"A13");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;
-		case 'q':strcpy(keyboard_entry->keyname,"B01");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=0;
-			break;
-		case 'Q':strcpy(keyboard_entry->keyname,"B01");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=0;
-			break;
-		case 'w':strcpy(keyboard_entry->keyname,"B02");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=1;
-			break;
-		case 'W':strcpy(keyboard_entry->keyname,"B02");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=1;
-			break;
-		case 'e':strcpy(keyboard_entry->keyname,"B03");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=2;
-			break;
-		case 'E':strcpy(keyboard_entry->keyname,"B03");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=3;
-			break;
-		case 'r':strcpy(keyboard_entry->keyname,"B04");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=3;
-			break;
-		case 'R':strcpy(keyboard_entry->keyname,"B04");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=3;
-			break;
-		case 't':strcpy(keyboard_entry->keyname,"B05");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=4;
-			break;
-		case 'T':strcpy(keyboard_entry->keyname,"B05");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=4;
-			break;
-		case 'y':strcpy(keyboard_entry->keyname,"B06");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=5;
-			break;
-		case 'Y':strcpy(keyboard_entry->keyname,"B06");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=5;
-			break;
-		case 'u':strcpy(keyboard_entry->keyname,"B07");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=6;
-			break;
-		case 'U':strcpy(keyboard_entry->keyname,"B07");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=6;
-			break;
-		case 'i':strcpy(keyboard_entry->keyname,"B08");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=7;
-			break;
-		case 'I':strcpy(keyboard_entry->keyname,"B08");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=7;
-			break;
-		case 'o':strcpy(keyboard_entry->keyname,"B09");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=8;
-			break;
-		case 'O':strcpy(keyboard_entry->keyname,"B09");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=8;
-			break;
-		case 'p':strcpy(keyboard_entry->keyname,"B10");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case 'P':strcpy(keyboard_entry->keyname,"B10");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;
-		case '[':strcpy(keyboard_entry->keyname,"B11");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case '{':strcpy(keyboard_entry->keyname,"B11");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;
-		case ']':strcpy(keyboard_entry->keyname,"B12");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case '}':strcpy(keyboard_entry->keyname,"B12");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;
-		case 'a':strcpy(keyboard_entry->keyname,"C01");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=0;
-			break;
-		case 'A':strcpy(keyboard_entry->keyname,"C01");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=0;
-			break;
-		case 's':strcpy(keyboard_entry->keyname,"C02");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=1;
-			break;
-		case 'S':strcpy(keyboard_entry->keyname,"C02");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=1;
-			break;
-		case 'd':strcpy(keyboard_entry->keyname,"C03");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=2;
-			break;
-		case 'D':strcpy(keyboard_entry->keyname,"C03");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=2;
-			break;
-		case 'f':strcpy(keyboard_entry->keyname,"C04");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=3;
-			break;
-		case 'F':strcpy(keyboard_entry->keyname,"C04");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=3;
-			break;
-		case 'g':strcpy(keyboard_entry->keyname,"C05");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=4;
-			break;
-		case 'G':strcpy(keyboard_entry->keyname,"C05");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=4;
-			break;
-		case 'h':strcpy(keyboard_entry->keyname,"C06");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=5;
-			break;
-		case 'H':strcpy(keyboard_entry->keyname,"C06");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=5;
-			break;
-		case 'j':strcpy(keyboard_entry->keyname,"C07");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=6;
-			break;
-		case 'J':strcpy(keyboard_entry->keyname,"C07");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=6;
-			break;
-		case 'k':strcpy(keyboard_entry->keyname,"C08");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=7;
-			break;
-		case 'K':strcpy(keyboard_entry->keyname,"C08");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=7;
-			break;
-		case 'l':strcpy(keyboard_entry->keyname,"C09");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=8;
-			break;
-		case 'L':strcpy(keyboard_entry->keyname,"C09");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=8;
-			break;
-		case ';':strcpy(keyboard_entry->keyname,"C10");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case ':':strcpy(keyboard_entry->keyname,"C10");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;			
-		case '\'':strcpy(keyboard_entry->keyname,"C11");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case '"':strcpy(keyboard_entry->keyname,"C11");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;
-		case 'z':strcpy(keyboard_entry->keyname,"D01");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=0;
-			break;
-		case 'Z':strcpy(keyboard_entry->keyname,"D01");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=0;
-			break;
-		case 'x':strcpy(keyboard_entry->keyname,"D02");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=1;
-			break;
-		case 'X':strcpy(keyboard_entry->keyname,"D02");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=1;
-			break;
-		case 'c':strcpy(keyboard_entry->keyname,"D03");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=2;
-			break;
-		case 'C':strcpy(keyboard_entry->keyname,"D03");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=2;
-			break;
-		case 'v':strcpy(keyboard_entry->keyname,"D04");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=3;
-			break;
-		case 'V':strcpy(keyboard_entry->keyname,"D04");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=3;
-			break;
-		case 'b':strcpy(keyboard_entry->keyname,"D05");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=4;
-			break;
-		case 'B':strcpy(keyboard_entry->keyname,"D05");
-			keyboard_entry->shift=2;
-			keyboard_entry->finger=4;
-			break;
-		case 'n':strcpy(keyboard_entry->keyname,"D06");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=5;
-			break;
-		case 'N':strcpy(keyboard_entry->keyname,"D06");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=5;
-			break;
-		case 'm':strcpy(keyboard_entry->keyname,"D07");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=6;
-			break;
-		case 'M':strcpy(keyboard_entry->keyname,"D07");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=6;
-			break;
-		case ',':strcpy(keyboard_entry->keyname,"D08");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=7;
-			break;
-		case '<':strcpy(keyboard_entry->keyname,"D08");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=7;
-			break;
-		case '.':strcpy(keyboard_entry->keyname,"D09");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=8;
-			break;
-		case '>':strcpy(keyboard_entry->keyname,"D09");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=8;
-			break;
-		case '/':strcpy(keyboard_entry->keyname,"D10");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=9;
-			break;
-		case '?':strcpy(keyboard_entry->keyname,"D10");
-			keyboard_entry->shift=1;
-			keyboard_entry->finger=9;
-			break;
-		case ' ':strcpy(keyboard_entry->keyname,"E03");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=5;
-			break;
-		default:strcpy(keyboard_entry->keyname,"None");
-			keyboard_entry->shift=0;
-			keyboard_entry->finger=-1;
-			break;
-	}
-}
-
-void GenerateKeyboard(SDL_Surface* keyboard)
-{
-	SDL_Surface* tmp = NULL;
-	SDL_Rect new;
-	int i;
-	int col;
-	char row;
-	int render=1;
-	Uint16 t[2];
-	TTF_Font* smallfont = NULL;
-	DEBUGCODE { printf("Entering GenerateKeyboard\n"); }
-	t[1] = '\0';
-	smallfont = LoadFont(settings.theme_font_name, 15);
-	if(!smallfont)
-	{
-		DEBUGCODE { printf("Error loading font\n"); }
-		return;
-	}
-	for(i=0;i < num_chars_used;i++)
-	{
-		render=1;
-		new.x=0;
-		new.y=0;
-		new.w=5;
-		new.h=5;
-		t[0]=keyboard_list[i].unicode_value;
-		sscanf(keyboard_list[i].keyname,"%c%d",&row,&col);
-		switch(row)
-		{
-			case 'A':new.y+=6;new.x+=13;break;
-			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;
-			default: render=0;break;
-		}
-		if(!render)
-			continue;
-		new.x+=31*col;
-		if(keyboard_list[i].shift>0)
-		{
-					new.x-=9;
-					if(new.y<9)
-						new.y-=5;
-					else
-						new.y-=9;
-		}
-		DEBUGCODE { printf("Making %d : %C\n",i,keyboard_list[i].unicode_value); }
-		//tmp=BlackOutline_Unicode(t, smallfont, &black);
-		tmp=TTF_RenderUNICODE_Blended((TTF_Font*)smallfont, t, black);
-		if(tmp==NULL)
-		{
-			DEBUGCODE { printf("Error Making %d : %C\n",i,keyboard_list[i].unicode_value); }
-		}
-		SDL_BlitSurface(tmp, NULL, keyboard, &new);
-	}	
-	TTF_CloseFont(smallfont);
-	DEBUGCODE { printf("Leaving GenerateKeyboard\n"); }
-}
-void updatekeylist(int key,char ch)
-{
-	wchar_t;
-	keyboard_list[key].latin_char=ch;
-	wchar_t wtmp=ch;
-	map_keys(wtmp,&keyboard_list[key]);
-}
-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);
-
-	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);
-		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);
-}
-/****************************************************************/
-
-/****************************************************/
-/*                                                  */
-/*       Local ("private") functions:               */
-/*                                                  */
-/****************************************************/
-
-
-/* Creates a list of distinct Unicode characters in */
-/* word_list[][] (so the program knows what         */
-/* needs to be rendered for the games)              */
-static void gen_char_list(void)
-{
-  int i, j;
-  i = j = 0;
-  char_list[0] = '\0';
-
-  while (word_list[i][0] != '\0' && i < MAX_NUM_WORDS) 
-  {
-    j = 0;
-
-    while (word_list[i][j]!= '\0' && j < MAX_WORD_SIZE)
-    {
-      add_char(word_list[i][j]);
-      j++;
-    }
-
-    i++;
-  }
-
-  DEBUGCODE
-  {
-    fprintf(stderr, "char_list = %S\n", char_list);
-  }
-}
-
-
-
-void ResetCharList(void)
-{
-  char_list[0] = '\0';
-}
-
-
-
-/* Creates a list of distinct Unicode characters in       */
-/* the argument string for subsequent rendering.          */
-/* Like gen_char_list() but takes a string argument       */
-/* instead of going through the currently selected        */
-/* word list. Argument should be UTF-8                    */
-/* Can be called multiple times on different strings      */
-/* to accumulate entire repertoire - call ResetCharList() */
-/* to start over                                          */
-void GenCharListFromString(const unsigned char* UTF8_str)
-{
-  int i = 0;
-  wchar_t wchar_buf[MAX_UNICODES];
-
-  ConvertFromUTF8(wchar_buf, UTF8_str);
-
-  /* FNLEN is max length of phrase (I think) */
-  while (wchar_buf[i] != '\0' && i < FNLEN) 
-  {
-    add_char(wchar_buf[i]);
-    i++;
-  }
-
-  DEBUGCODE
-  {
-    fprintf(stderr, "char_list = %S\n", char_list);
-  }
-}
-
-
-
-/* FIXME this function is currently dead code */
-/* --- setup the alphabet --- */
-static void set_letters(unsigned 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++;
-		}
-}
-
-
-
-/* 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:                           */
-/* FIXME performance would be better with hashtable                 */
-static int add_char(wchar_t uc)
-{
-  int i = 0;
-  while ((char_list[i] != uc)
-      && (char_list[i] != '\0')
-      && (i < MAX_UNICODES - 1))          //Because 1 need for null terminator
-  {
-    i++;
-  }
-
-  /* unicode already in list: */
-  if (char_list[i] == uc)
-  {
-    DEBUGCODE{ fprintf(stderr,
-                       "Unicode value: %d\tcharacter %lc already in list\n",
-                        uc, uc);}
-    return 0;
-  }
-
-  if (char_list[i] == '\0')
-  {
-    DEBUGCODE{ fprintf(stderr, "Adding unicode value: %d\tcharacter %lc\n", uc, uc);}
-    char_list[i] = uc;
-    char_list[i + 1] = '\0';
-    return 1;
-  }
-
-  if (i == MAX_UNICODES - 1)            //Because 1 need for null terminator
-  {
-    LOG ("Unable to add unicode - list at max capacity");
-    return -1;
-  }
-}
-
-
-
-static void clear_keyboard(void)
-{
-  int i = 0;
-  for (i = 0; i < MAX_UNICODES; i++)
-  {
-    keyboard_list[i].unicode_value = 0;
-    keyboard_list[i].finger = -1;
-  }
-}
-
-
-

Deleted: tuxtype/branches/tuxtype-soc-mh/audio.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/audio.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/audio.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,66 +0,0 @@
-/***************************************************************************
- -  file: audio.c
- -  description: this file contains audio related functions
-                            -------------------
-    begin                : Jan 22, 2003
-    copyright            : Sam Hart, Jesse Andrews (C) 2003
-    email                : tuxtype-dev at tux4kids.net
-***************************************************************************/
-
-/***************************************************************************
-*                                                                         *
-*   This program is free software; you can redistribute it and/or modify  *
-*   it under the terms of the GNU General Public License as published by  *
-*   the Free Software Foundation; either version 2 of the License, or     *
-*   (at your option) any later version.                                   *
-*                                                                         *
-***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-
-static Mix_Music* defaultMusic = NULL; // holds music for audioMusicLoad/unload
-
-
-void PlaySound(Mix_Chunk* snd) {
-	if (!settings.sys_sound) return;
-
-	Mix_PlayChannel(-1, snd, 0);
-}
-
-/* MusicLoad attempts to load and play the music file 
- * Note: loops == -1 means forever
- */
-void MusicLoad(const char *musicFilename, int loops ) {
-	if (!settings.sys_sound) return;
-
-	MusicUnload(); // make sure defaultMusic is clear
-
-	defaultMusic = LoadMusic( musicFilename );
-	Mix_PlayMusic( defaultMusic, loops );
-}
-
-/* MusicUnload attempts to unload any music data that was
- * loaded using the audioMusicLoad function
- */
-void MusicUnload( void ) {
-	if (!settings.sys_sound) return;
-
-	if ( defaultMusic )
-		Mix_FreeMusic( defaultMusic );
-
-	defaultMusic = NULL;
-}
-
-/* audioMusicPlay attempts to play the passed music data. 
- * if a music file was loaded using the audioMusicLoad
- * it will be stopped and unloaded
- * Note: loops == -1 means forever
- */
-void MusicPlay(Mix_Music* musicData, int loops)
-{ 
-  if (!settings.sys_sound) return;
-  /* Stop previous music before playing new one: */
-  MusicUnload();	
-  Mix_PlayMusic(musicData, loops);
-}

Deleted: tuxtype/branches/tuxtype-soc-mh/compiler.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/compiler.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/compiler.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,157 +0,0 @@
-/*
-  compiler.h
-
-  Compiler-specific #defines and such
-  for Tux Paint
-
-  Mostly by Albert Cahalan <albert at users.sf.net>
-  Copyright (c) 2002-2006
-
-  http://www.newbreedsoftware.com/tuxpaint/
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-  (See COPYING.txt)
-
-  June 14, 2002 - February 18, 2006
-  $Id: compiler.h,v 1.5 2006/08/27 21:00:55 wkendrick Exp $
-
-  June 09, 2008:
-  Brought into TuxMath by Brendan Luchen as part of pixel-manipulation
-  code, with blessings of Bill Kendrick.
-
-*/
-
-#ifdef WIN32
-/* Horrible, dangerous macros. */
-/*
-  The SDL stderr redirection trick doesn't seem to work for perror().
-  This does pretty much the same thing.
-*/
-#define perror(str) ({ \
-  if ( (str) && *(str) ) \
-    fprintf(stderr,"%s : ",(str)); \
-  fprintf(stderr, \
-          "%s [%d]\n", \
-          (errno<_sys_nerr)?_sys_errlist[errno]:"unknown",errno ); \
-})
-
-/*
-  MinGW implementation of isspace() crashes on some Win98 boxes
-  if c is 'out-of-range'.
-*/
-#define isspace(c) (((c) == 0x20) || ((c) >= 0x09 && (c) <= 0x0D))
-
-/*
-  WIN32 and MINGW don't have strcasestr().
-*/
-#define NOMINMAX
-#include "shlwapi.h"
-#define strcasestr StrStrI
-#endif /* WIN32 */
-
-
-
-
-#ifdef __GNUC__
-// This version has strict type checking for safety.
-// See the "unnecessary" pointer comparison. (from Linux)
-#define min(x,y) ({ \
-  typeof(x) _x = (x);     \
-  typeof(y) _y = (y);     \
-  (void) (&_x == &_y);            \
-  _x < _y ? _x : _y; })
-#define max(x,y) ({ \
-  typeof(x) _x = (x);     \
-  typeof(y) _y = (y);     \
-  (void) (&_x == &_y);            \
-  _x > _y ? _x : _y; })
-#else
-#define min(a,b) (((a) < (b)) ? (a) : (b))
-#define max(a,b) (((a) > (b)) ? (a) : (b))
-#endif
-
-#define clamp(lo,value,hi)    (min(max(value,lo),hi))
-
-
-// since gcc-2.5
-#ifdef __GNUC__
-#define NORETURN __attribute__((__noreturn__))
-#define FUNCTION __attribute__((__const__))	// no access to global mem, even via ptr, and no side effect
-#else
-#define NORETURN
-#define FUNCTION
-#endif
-
-#if !defined(restrict) && __STDC_VERSION__ < 199901
-#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92
-#define restrict __restrict__
-#else
-#warning No restrict keyword?
-#define restrict
-#endif
-#endif
-
-
-#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
-// won't alias anything, and aligned enough for anything
-#define MALLOC __attribute__ ((__malloc__))
-// no side effect, may read globals
-#ifndef WIN32
-#define PURE __attribute__ ((__pure__))
-#endif
-// tell gcc what to expect:   if(unlikely(err)) die(err);
-#define likely(x)       __builtin_expect(!!(x),1)
-#define unlikely(x)     __builtin_expect(!!(x),0)
-#define expected(x,y)   __builtin_expect((x),(y))
-#else
-#define MALLOC
-#define PURE
-#define likely(x)       (x)
-#define unlikely(x)     (x)
-#define expected(x,y)   (x)
-#endif
-
-
-#ifdef __powerpc__
-// Ticks at 1/4  the memory bus clock (24.907667 MHz on Albert's Mac Cube)
-// This is good for 80-second diff or 160-second total.
-#define CLOCK_ASM(tbl) asm volatile("mftb %0" : "=r" (tbl))
-#define CLOCK_TYPE unsigned long
-#ifndef CLOCK_SPEED
-// #warning Benchmark times are based on a 99.63 MHz memory bus.
-#define CLOCK_SPEED 24907667.0
-#endif
-#endif
-
-#ifdef __i386__
-#define CLOCK_ASM(tbl) asm volatile("rdtsc" : "=A" (tbl))
-#define CLOCK_TYPE unsigned long long
-#ifndef CLOCK_SPEED
-// #warning Benchmark times are based on a 450 MHz CPU.
-#define CLOCK_SPEED 450000000.0
-#endif
-#endif
-
-#ifndef CLOCK_ASM
-// #warning No idea how to read CPU cycles for you, sorry.
-#define CLOCK_ASM(tbl)
-#define CLOCK_TYPE unsigned long
-#define CLOCK_SPEED 1000000000.0
-#endif
-
-#ifdef NO_ASM
-#undef CLOCK_ASM
-#define CLOCK_ASM(x) x=42
-#endif

Deleted: tuxtype/branches/tuxtype-soc-mh/funcs.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/funcs.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/funcs.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,153 +0,0 @@
-/***************************************************************************
-                          funcs.h
-  description: function header
-                             -------------------
-    begin                : Sat May 6 2000
-    copyright            : (C) 2000 by Sam Hart
-    email                : hart at geekcomix.com
- 
-  Modified by David Bruce
-  dbruce at tampabay.rr.com
-  2007
-
-***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-/* NOTE - there is no reason to declare functions using "extern", as all */
-/* non-local functions are visible throughout the program.               */ 
-
-
-/* In alphabet.c */
-//SDL_Surface* BlackOutline(const unsigned 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);
-
-#ifndef WIN32
-//SDL_Surface* BlackOutline_SDLPango(const unsigned char* t, const TTF_Font* font, const SDL_Color* c);
-#endif
-
-/* (still in alphabet.c:) */
-int CheckNeededGlyphs(void);
-void ClearWordList(void);
-int ConvertFromUTF8(wchar_t* wide_word, const unsigned char* UTF8_word);
-void FreeLetters(void);
-int GenerateWordList(const char* wordFn);
-void GenCharListFromString(const unsigned char* UTF8_str);
-void ResetCharList(void);
-wchar_t GetLetter(void);
-wchar_t* GetWord(void);
-SDL_Surface* GetWhiteGlyph(wchar_t t);
-SDL_Surface* GetRedGlyph(wchar_t t);
-int LoadKeyboard(void);
-int GetFinger(int i);
-int RenderLetters(const TTF_Font* letter_font);
-int GetIndex(wchar_t uni_char);
-void GetKeyShift(int index, char *buf);
-void GetKeyPos(int index, char *buf);
-void GetWrongKeyPos(int index, char *buf);
-//int map_keys(wchar_t *wide_str,keymap key);
-void GenerateKeyboard(SDL_Surface* keyboard);
-void updatekeylist(int key,char ch);
-void savekeyboard(void);
-wchar_t GetLastKey(void);
-
-
-//void UseAlphabet(void);
-
-
-/* In audio.c:   */
-void PlaySound(Mix_Chunk* snd);
-void MusicLoad(const char* musicFilename, int repeatQty);
-void MusicUnload(void);
-void MusicPlay(Mix_Music* musicData, int repeatQty);
-
-
-/* In gettext.c:  */
-//unsigned char* gettext(const unsigned char* in);
-//int Load_PO_File(const char* file);
-
-
-/* In laser.c:        */
-int PlayLaserGame(int diff_level);
-
-
-/* In loaders.c: */
-int CheckFile(const char* file);
-sprite* FlipSprite(sprite* in, int X, int Y);
-void FreeSprite(sprite* gfx);
-TTF_Font* LoadFont(const char* fontfile, int fontsize);
-SDL_Surface* LoadImage(const char* datafile, int mode);
-int LoadBothBkgds(const char* datafile);
-SDL_Surface* CurrentBkgd(void);
-void FreeBothBkgds(void);
-void LoadLang(void);
-Mix_Music* LoadMusic(const char* datafile);
-Mix_Chunk* LoadSound(const char* datafile);
-sprite* LoadSprite(const char* name, int MODE);
-
-/* In options.c: */
-void Opts_Initialize(void);
-
-/* In pause.c: */
-int  Pause(void);
-
-
-/* In playgame.c: */
-int PlayCascade(int level);
-void InitEngine(void);
-int TransWipe(SDL_Surface* newbkg, int type, int var1, int var2);
-
-
-/* In practice.c: */
-int Phrases(wchar_t* practice_phrase);
-static void next_letter(wchar_t *t, int c);
-
-
-/* In scripting.c: */
-int TestLesson(void);
-void ProjectInfo(void);
-void InstructCascade(void);
-void InstructLaser(void);
-
-
-/* In setup.c: */
-void GraphicsInit(void);
-void LibInit(Uint32 lib_flags);
-void LoadSettings(void);
-void SaveSettings(void);
-int SetupPaths(const char* theme_dir);
-void Cleanup(void);
-
-/* In theme.c: */
-void ChooseTheme(void);
-
-
-/* In titlescreen.c: */
-//void SwitchScreenMode(void);
-void TitleScreen(void);
-
-/* In profiles.c: */
-void loadProfile(int numProfiles);
-void saveProfile(int numProfiles);
-void updatePersonalScore(int score);
-void updateWPM(int wpm);
-
-/* In profilesgui.c: */
-void profilesSelector(void);
-
-/* In wordsperminute.c: */
-void wpm();
-
-/* In highscore.c: */
-void displayScores(void);
-void saveHighScores(void);
-void load_highscores(void);
-void checkHighScores(int score);
-void checkWPM(int wpm);
\ No newline at end of file

Deleted: tuxtype/branches/tuxtype-soc-mh/gettext.c
===================================================================

Deleted: tuxtype/branches/tuxtype-soc-mh/globals.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/globals.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/globals.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,268 +0,0 @@
-/***************************************************************************
-                          globals.h
-  description: global varis
-                             -------------------
-    begin                : Fri May 5 2000
-    copyright            : (C) 2000 by Sam Hart
-    email                : hart at geekcomix.com
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#define to_upper(c) (((c) >= 'a' && (c) <= 'z') ? (c) -32 : (c))
-#define COL2RGB( col ) SDL_MapRGB( screen->format, col->r, col->g, col->b )
-
-#define FNLEN	200
-
-#define RES_X	640
-#define RES_Y	480
-#define BPP	32
-
-#ifdef WIN32 
-#undef DATA_PREFIX
-#define DATA_PREFIX ".//"
-#endif
-
-#ifndef __GLOBALS_H__
-#define __GLOBALS_H__
-
-#define MAX_SPRITE_FRAMES 30
-
-
-//#define LOCALEDIR "/usr/local/share"
-
-#include <string.h>
-#include <wchar.h>
-#include <math.h>
-#include <time.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <dirent.h>
-#include <locale.h>
-
-#include "../config.h"
-
-#include <SDL/SDL.h>
-#include <SDL/SDL_image.h>
-#include <SDL/SDL_mixer.h>
-#include <SDL/SDL_ttf.h>
-
-//#include "i18n.h"
-#include <libintl.h>
-
-
-
-#endif //  __GLOBALS_H__
-
-#define NEXT_FRAME(SPRITE) if ((SPRITE)->num_frames) (SPRITE)->cur = (((SPRITE)->cur)+1) % (SPRITE)->num_frames;
-#define REWIND(SPRITE) (SPRITE)->cur = 0;
-
-#define MIN(x,y) ((x) < (y) ? (x) : (y))
-#define MAX(x,y) ((x) > (y) ? (x) : (y))
-
-/* Goal is to have all global settings here */
-/* (renamed from 'settings' to match tuxmath) */
-typedef struct game_option_type{
-  char default_data_path[FNLEN];
-  char theme_data_path[FNLEN];
-  char user_settings_path[FNLEN];
-  char global_settings_path[FNLEN];
-  char theme_name[FNLEN];
-  char lang[FNLEN];
-  char theme_font_name[FNLEN];
-  char theme_locale_name[FNLEN];
-  int use_english;
-  int fullscreen;
-  int sys_sound;
-  int sfx_volume;
-  int mus_volume;
-  int menu_music;
-  int menu_sound;
-  int speed_up;
-  int show_tux4kids;
-  int debug_on;
-  int o_lives;
-  int sound_vol;
-  int numProfiles;//tracks total number of profiles, limited to 8
-  int hidden; // Read the README file in the image directory for info on this ;)
-} game_option_type;
-
-/* Default values for game_option_type struct */
-/* They can be changed in the struct to other values at run-time */
-#define DEFAULT_MENU_FONT       "AndikaDesRevG.ttf"
-#define DEFAULT_GAME_FONT       "AndikaDesRevG.ttf" 
-#define DEFAULT_LOCALE		"en_GB.UTF-8"
-#define DEFAULT_USE_ENGLISH 1
-#define DEFAULT_FULLSCREEN 1
-#define DEFAULT_SYS_SOUND 1
-#define DEFAULT_SFX_VOLUME 100
-#define DEFAULT_MUS_VOLUME 100
-#define DEFAULT_MENU_MUSIC 1
-#define DEFAULT_MENU_SOUND 1
-#define DEFAULT_SPEED_UP 0
-#define DEFAULT_SHOW_TUX4KIDS 1
-#define DEFAULT_DEBUG_ON 0
-#define DEFAULT_O_LIVES 0
-#define DEFAULT_SOUND_VOL 100
-#define DEFAULT_HIDDEN 0
-
-/* I put global highscore data here.. seemed more appropriate than not */
-#define DEFAULT_GNAME			"Tux"
-#define DEFAULT_GHIGHSCORE1		80000
-#define DEFAULT_GHIGHSCORE2		70000
-#define DEFAULT_GHIGHSCORE3		60000
-#define DEFAULT_GHIGHSCORE4		50000
-#define DEFAULT_GHIGHSCORE5		40000
-#define DEFAULT_GHIGHSCORE6		30000
-#define DEFAULT_GHIGHSCORE7		20000
-#define DEFAULT_GHIGHSCORE8		10000
-#define DEFAULT_GWPM_FASTEST 	60
-#define DEFAULT_GWPM_AVERAGE 	30
-#define DEFAULT_GWPM_LOWEST 	5
-
-typedef struct {
-  SDL_Surface* frame[MAX_SPRITE_FRAMES];
-  SDL_Surface* default_img;
-  int num_frames;
-  int cur;
-} sprite;
-
-#define _(String) gettext(String)
-#define gettext_noop(String) (String)
-
-
-/* LOGGING works as such:
- *
- * - Use LOG if you want to output a string LOG( "Hello World");
- *   
- * - Use DOUT if you want to output a value of a variable and the
- *   name of the variable gives enough context:
- *   DOUT( specialCode );  would add to stderr: "specialCode = 1\n" or
- *   whatever value specialCode had
- *   
- * - Use DEBUGCODE if you need to do something more complicated like
- *   DEBUGCODE { fprintf(stderr, "examining letter %d\n", x); }
- *   since DOUT(x) "x = 1\n" gives little information since x is used
- *   all over the place!
- */
-
-#define LOG( str ) if (settings.debug_on) fprintf( stderr, str );
-#define DEBUGCODE if (settings.debug_on) 
-#define DOUT(x) if (settings.debug_on) fprintf(stderr, "%s = %d\n", #x, x);
-
-// #if SDL_BYTEORDER == SDL_BIG_ENDIAN
-// #define RMASK 0xff000000
-// #define GMASK 0x00ff0000
-// #define BMASK 0x0000ff00
-// #define AMASK 0x000000ff
-// #else
-// #define RMASK 0x000000ff
-// #define GMASK 0x0000ff00
-// #define BMASK 0x00ff0000
-// #define AMASK 0xff000000
-// #endif
-
-
-
-#define MENU_FONT_SIZE	20
-#define GAME_FONT_SIZE	20
-
-/* Limits on word list size, word length, and on the number of distinct characters */
-/* that can be present within a word list: */
-#define MAX_NUM_WORDS   500
-#define MAX_WORD_SIZE   8
-#define MAX_UNICODES    1024
-
-#define WAIT_MS		2500
-#define	FRAMES_PER_SEC	50
-#define FULL_CIRCLE	140
-
-/* Menu Prototypes */
-enum Game_Type { 
-  QUIT_GAME, CASCADE, OPTIONS, LESSONS, WPM, HIGH_SCORES,
-  INSTRUCT_CASCADE, CASCADE1, CASCADE2, CASCADE3, CASCADE4,
-  INSTRUCT_LASER, LASER1, LASER2, LASER3, LASER4,
-  FREETYPE, ASDF, ALL, MAIN, SET_LANGUAGE, PROJECT_INFO, NOT_CODED,
-  LEVEL1, LEVEL2, LEVEL3, LEVEL4, LASER, INSTRUCT, EDIT_WORDLIST, NONE};
-
-/* Title sequence constants */
-#define PRE_ANIM_FRAMES	 10
-#define PRE_FRAME_MULT	 3
-#define MENU_SEP	 20
-
-
-#define IMG_REGULAR  0x01
-#define IMG_COLORKEY 0x02
-#define IMG_ALPHA    0x04
-#define IMG_MODES    0x07
-
-#define IMG_NOT_REQUIRED 0x10
-#define IMG_NO_THEME     0x20
-
-/* Values for menu button drawing: */
-#define REG_RGBA 16,16,96,96
-#define SEL_RGBA 16,16,128,128
-
-//Game difficulty levels
-enum { EASY, MEDIUM, HARD, INSANE, INF_PRACT };
-#define NUM_LEVELS  4
-
-extern game_option_type settings;
-
-/* FIXME get rid of as much global data as possible, esp. pointers */
-
-extern SDL_Surface* screen;
-/* these will store the resolution used by the OS when we start, so we */
-/* can run fullscreen at the user's preferred resolution:              */
-extern uint fs_res_x;
-extern uint fs_res_y;
-
-//extern TTF_Font* font;
-extern SDL_Event  event;
-
-extern SDL_Color black;
-extern SDL_Color gray;
-extern SDL_Color dark_blue;
-extern SDL_Color red;
-extern SDL_Color white;
-extern SDL_Color yellow;
-
-extern SDL_Surface* letters[255]; /* Will be going away */
-
-/* These need some work to support Unicode & i18n: */
-extern wchar_t ALPHABET[256];
-extern int ALPHABET_SIZE;
-
-
-enum {
-	WIN_WAV,
-	BITE_WAV,
-	LOSE_WAV,
-	RUN_WAV,
-	SPLAT_WAV,
-	WINFINAL_WAV,
-	EXCUSEME_WAV,
-	PAUSE_WAV,
-	NUM_WAVES
-};
-
-#define MUSIC_FADE_OUT_MS	80
-
-enum {
-    WIPE_BLINDS_VERT,
-    WIPE_BLINDS_HORIZ,
-    WIPE_BLINDS_BOX,
-    RANDOM_WIPE,
-
-    NUM_WIPES
-};
-
-

Deleted: tuxtype/branches/tuxtype-soc-mh/highscores.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/highscores.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/highscores.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,533 +0,0 @@
-#include "globals.h"
-#include "funcs.h"
-#include "profiles.c"
-
-//tracks laser scores, and wpm stats
-typedef struct highscores{ //structure for global highscores
-  	char *highscore1_name;
-  	int ghighscore1;
-  	char *highscore2_name;
-  	int ghighscore2;
-  	char *highscore3_name;
-  	int ghighscore3;
-  	char *highscore4_name;
-  	int ghighscore4;
-  	char *highscore5_name;
-  	int ghighscore5;
-  	char *highscore6_name;
-  	int ghighscore6;
-  	char *highscore7_name;
-  	int ghighscore7;
-  	char *highscore8_name;
-  	int ghighscore8;
-  	char *wpm_fastest_name;
-  	int wpm_fastest;
-  	char *wpm_average_name;
-  	int wpm_average;
-  	char *wpm_slowest_name;
-  	int wpm_slowest;
-  } highscores;
-  
-  static SDL_Surface* bg = NULL;
-  static TTF_Font* font = NULL;
-  
-typedef struct highscore_entry{
-	int score;
-	char name[32];
-}highscore_entry;
-
-	highscore_entry scoresdisplay[11]; 
-	highscore_entry personalScores[12];
-  	extern highscores hscores;
-
-int load_highscores_filename(const char*);
-int load_highscores_fp(FILE*);
-void loadGlobalScores(void);
-void loadPersonalScores(void);
-void highscores_load_media(void);
-void highscores_unload_media(void);
- 
-void saveHighScores()//called before exiting game, no need to write until then.
-{
-	char fn[FNLEN];
-	FILE* highscores_file;
-		
-		#ifdef WIN32
-			_mkdir( "userdata" ); 
-			snprintf( fn, FNLEN-1, "userdata/highscores.txt" );
-		#else
-			snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
-			mkdir( fn, 0755 );
-			snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/highscores.txt", getenv("HOME") );
-		#endif
-			
-		highscores_file = fopen(fn, "w");
-		
-		if (highscores_file == NULL) 
-		{
-				printf("Save_Highscores: Highscores file cannot be created!\n");
-				return;
-		}
-		
-		fprintf( highscores_file, "HighScore1=%d\tname1=%s\n", hscores.ghighscore1, &hscores.highscore1_name);
-		fprintf( highscores_file, "HighScore2=%d\tname2=%s\n", hscores.ghighscore1, &hscores.highscore2_name);
-		fprintf( highscores_file, "HighScore3=%d\tname3=%s\n", hscores.ghighscore1, &hscores.highscore3_name);
-		fprintf( highscores_file, "HighScore4=%d\tname4=%s\n", hscores.ghighscore1, &hscores.highscore4_name);
-		fprintf( highscores_file, "HighScore5=%d\tname5=%s\n", hscores.ghighscore1, &hscores.highscore5_name);
-		fprintf( highscores_file, "HighScore6=%d\tname6=%s\n", hscores.ghighscore1, &hscores.highscore6_name);
-		fprintf( highscores_file, "HighScore7=%d\tname7=%s\n", hscores.ghighscore1, &hscores.highscore7_name);
-		fprintf( highscores_file, "HighScore8=%d\tname8=%s\n", hscores.ghighscore1, &hscores.highscore8_name);
-		fprintf( highscores_file, "Fastest_WPM=%d\twname1=%s\n", hscores.wpm_fastest, &hscores.wpm_fastest_name);
-		fprintf( highscores_file, "Highest_average_WPM=%d\twname2=%s\n", hscores.wpm_average, &hscores.wpm_average_name);
-		fprintf( highscores_file, "Slowest_WPM=%d\twname3=%s\n", hscores.wpm_slowest, &hscores.wpm_slowest_name);
-		
-		fclose(highscores_file);
-}
-
-void displayScores() //loads global high scores and individual high scores to display
-{
-	int finished = 0;
-	SDL_Surface* score_surfs[11] = {NULL};
-	SDL_Surface* personal_surfs[12] = {NULL};
-	
-	char score_strings[11][42] = {{'\0'}};
-	char personal_strings[12][10] = {{'\0'}};
-
-	SDL_Rect score_rects[11];
-	SDL_Rect personal_rects[12];
-	SDL_Rect table_bg1, table_bg2; //1 is global, 2 is personal
-
-	const int max_width = 300;
-	int score_table_y = 100;
-	
-	SDL_Surface* srfc = NULL;
-	SDL_Rect text_rect;
-
-	TTF_Font* title_font = LoadFont(DEFAULT_GAME_FONT, 32);
-	TTF_Font* player_font = LoadFont(DEFAULT_GAME_FONT, 14);
-	
-	if (!player_font || !title_font)
-	{
-		return;
-	}
-	
-	highscores_load_media();
-	  
-	while (!finished)
-	{
-		start = SDL_GetTicks();
-
-		/* Check for user events: */
-		while (SDL_PollEvent(&event)) 
-		{
-			switch (event.type)
-			{
-				case SDL_QUIT:
-				{
-					finished = 1;
-				}
-	        }
-		}
-		loadGlobalScores();
-		loadPersonalScores();
-		if (bg)
-		{
-			SDL_BlitSurface(bg, NULL, screen, NULL );
-		}
-		table_bg1.x = 10;
-		table_bg1.y = 5;
-		table_bg1.w = max_width;
-		table_bg1.h = screen->h - 10;
-		
-		table-bg2.x = 330
-		table_bg2.y = 5;
-		table bg2.w = max_width;
-		table_bg2.h = screen->h - 10;
-		
-		srfc = BlackOutline(_("Hall Of Fame"), title_font, &yellow);
-		if (srfc)
-		{
-			/* Now blit text and free surface: */
-			SDL_BlitSurface(srfc, NULL, screen, &text_rect);
-			SDL_FreeSurface(srfc);
-			srfc = NULL;
-		}
-		if (title_font)
-		{
-			srfc = BlackOutline(_("Hall of Fame"), title_font, &white);
-		}
-		if (srfc)
-		{
-			text_rect.x = (screen->w)/2 - (srfc->w)/2; 
-			text_rect.y += text_rect.h;
-			text_rect.w = srfc->w;
-			text_rect.h = srfc->h;
-			SDL_BlitSurface(srfc, NULL, screen, &text_rect);
-			SDL_FreeSurface(srfc);
-			srfc = NULL;
-			score_table_y = text_rect.y + text_rect.h;
-		}
-		for (i = 0; i < 11; i++)
-		{
-			/* Get data for global entries: */
-			sprintf(score_strings[i],
-					"%d.	 %s	 %d",
-					i + 1,   /* Add one to get common-language place number */
-					scoresdisplay[i].score,
-					scoresdisplay[i].name));
-
-			/* Clear out old surfaces and update: */
-
-			score_surfs[i] = BlackOutline(score_strings[i], player_font, &white);
-
-			/* Get out if BlackOutline() fails: */
-			if (!score_surfs[i])
-			{
-		          continue;
-			}
-		         
-			/* Set up entries in vertical column: */
-			if (0 == i)
-			{
-				score_rects[i].y = score_table_y;
-			}
-			else
-			{
-		          score_rects[i].y = personal_rects[i - 1].y + personal_rects[i - 1].h;
-			}
-			score_rects[i].x = 20;
-			score_rects[i].h = score_surfs[i]->h;
-			score_rects[i].w = max_width;
-
-			SDL_BlitSurface(score_surfs[i], NULL, screen, &score_rects[i]);
-			SDL_FreeSurface(score_surfs[i]);
-			score_surfs[i] = NULL;
-		}
-		for (i = 0; i < 12; i++)
-		{
-			/* Get data for personal entries: */
-			sprintf(personal_strings[i],
-					"%d.	 %d",
-					i + 1,   /* Add one to get common-language place number */
-					personalScores[i].score);
-
-			/* Clear out old surfaces and update: */
-
-			personal_surfs[i] = BlackOutline(score_strings[i], player_font, &white);
-
-			/* Get out if BlackOutline() fails: */
-			if (!personal_surfs[i])
-			{
-				continue;
-			}
-					         
-			/* Set up entries in vertical column: */
-			if (0 == i)
-			{
-				personal_rects[i].y = score_table_y;
-			}
-			else
-			{
-				personal_rects[i].y = personal_rects[i - 1].y + personal_rects[i - 1].h;
-			}
-			personal_rects[i].x = 340;
-			personal_rects[i].h = score_surfs[i]->h;
-			personal_rects[i].w = max_width;
-
-			SDL_BlitSurface(score_surfs[i], NULL, screen, &personal_rects[i]);
-			SDL_FreeSurface(score_surfs[i]);
-			score_surfs[i] = NULL;
-		}
-		/* Update screen: */
-		SDL_UpdateRect(screen, 0, 0, 0, 0);
-	}
-	while ((SDL_GetTicks() - start) < 33)
-	{
-		SDL_Delay(20);
-	}
-	frame++;
-	// End of while (!finished) loop
-	TTF_CloseFont(title_font);
-	TTF_CloseFont(player_font);
-	title_font = player_font = NULL;
-	highscore_unload_media();
-}
-void load_highscores()
-{
-	char fn[FNLEN];
-
-	#ifdef WIN32
-	snprintf(fn, FNLEN - 1, "userdata/highscores.txt");
-  	LOG("WIN32 defined\n");
-	#else
-  	snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/highscores.txt", getenv("HOME"));
-  	LOG("WIN32 not defined\n");
-	#endif
-		
-  	load_highscores_filename(fn);
-	
-}
-
-static int load_highscores_filename(const char* fn)
-{
-	FILE* fp = fopen(fn, "r");
-	
-	if (!fp)
-	{
-		fprintf(stderr, "load_highscores_filename(): Incorrect pointer\n");
-	    return;
-	}
-	
-	if (!load_highscores_fp(fp))
-	{
-		fprintf(stderr, "Could not find any highscores.\n");
-	    fclose(fp);
-	    return 0;
-	}
-	
-	fclose(fp);
-	return 1;
-}
-
-static int load_highscores_fp(FILE* fp)
-{
-  char highscores[FNLEN];
-  char value[FNLEN];
-  int highscores_found = 0;
-
-  if (!fp)
-  {
-    fprintf(stderr, "load_highscores_fp() - FILE* parameter NULL\n");
-    return 0;
-  }
-
-  /* load all the highscores here */
-  while (!feof(fp))
-  {
-    fscanf(fp, "%[^=]=%[^\n]\n", highscores, value );
-
-    if (strncmp( highscores, "Highscore1", FNLEN ) == 0 )
-    {
-    	hscores.ghighscore1 = atoi(value);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "name1", FNLEN ) == 0 )
-    {
-    	strncpy(hscores.highscore1_name, value, FNLEN - 1);
-    	highscores_found = 1;
-   }
-    else if (strncmp( highscores, "Highscore2", FNLEN ) == 0 )
-    {
-    	hscores.ghighscore2 = atoi(value);
-    	highscores_found = 1;
-    }
-    else if (strncmp(highscores, "name2", FNLEN) == 0)
-    {
-    	strncpy(hscores.highscore2_name, value, FNLEN - 1);
-    	highscores_found = 1;
-    }
-    else if (strncmp(highscores, "Highscore3", FNLEN) == 0)
-    {
-    	hscores.ghighscore3 = atoi(value);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "name3", FNLEN ) == 0 )
-    {
-    	strncpy(hscores.highscore3_name, value, FNLEN - 1);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "Highscore4", FNLEN ) == 0 )
-    {
-    	hscores.ghighscore4 = atoi(value);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "name4", FNLEN ) == 0 )
-    {
-    	strncpy(hscores.highscore4_name, value, FNLEN - 1);
-    	highscores_found = 1;
-	}
-    else if (strncmp( highscores, "Highscore5", FNLEN ) == 0 )
-    {
-    	hscores.ghighscore5 = atoi(value);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "name5", FNLEN ) == 0 )
-    {
-    	strncpy(hscores.highscore5_name, value, FNLEN - 1);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "Highscore6", FNLEN ) == 0 )
-    {
-    	hscores.ghighscore6 = atoi(value);
-        highscores_found = 1;
-    }
-    else if (strncmp( highscores, "name6", FNLEN ) == 0 )
-    {
-    	strncpy(hscores.highscore6_name, value, FNLEN - 1);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "Highscore7", FNLEN ) == 0 )
-    {
-    	hscores.ghighscore7 = atoi(value);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "name7", FNLEN ) == 0 )
-    {
-    	strncpy(hscores.highscore7_name, value, FNLEN - 1);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "Highscore8", FNLEN ) == 0 )
-  	{
-    	hscores.ghighscore8 = atoi(value);
-    	highscores_found = 1;
-  	}
-    else if (strncmp( highscores, "name8", FNLEN ) == 0 )
-    {
-    	strncpy(hscores.highscore8_name, value, FNLEN - 1);
-    	highscores_found = 1;
-    }
-    else if (strncmp( highscores, "Fastest_WPM", FNLEN ) == 0 )
- 	{
-    	hscores.wpm_fastest = atoi(value);
-    	highscores_found = 1;
-   	}
-    else if (strncmp( highscores, "wname1", FNLEN ) == 0 )
-   	{
-    	strncpy(hscores.wpm_fastest_name, value, FNLEN - 1);
-    	highscores_found = 1;
-   	}
-    else if (strncmp( highscores, "Highest_average_WPM", FNLEN ) == 0 )	
-    {
-	  	hscores.wpm_average = atoi(value);
-	 	highscores_found = 1;
-	}
-    else if (strncmp( highscores, "wname2", FNLEN ) == 0 )
-   	{
-    	strncpy(hscores.wpm_average_name, value, FNLEN - 1);
-    	highscores_found = 1;
-   	}
-    else if (strncmp( highscores, "Slowest_WPM", FNLEN ) == 0 )
-  	{
-      	 hscores.wpm_slowest = atoi(value);
-      	 highscores_found = 1;
-   	}
-    else if (strncmp( highscores, "wname3", FNLEN ) == 0 )
-   	{
-    	strncpy(hscores.wpm_slowest_name, value, FNLEN - 1);
-      	highscores_found = 1;
-   	}
-    else
-    {
-      DEBUGCODE {fprintf(stderr, "load_highscores_fp(): unrecognized string: %s", value);}
-    }
-    
-  }
-
-  if (highscores_found)
-  {
-    return 1;
-  }
-  else
-  {
-    fprintf(stderr, "load_highscores_fp() - no highscores in file - empty or corrupt?\n");
-    return 0;
-  }
-}
-
-void loadGlobalScores()
-{
-	scoresdisplay[0].score = hscores.ghighscore1;
-	scoresdisplay[1].score = hscores.ghighscore2;
-	scoresdisplay[2].score = hscores.ghighscore3;
-	scoresdisplay[3].score = hscores.ghighscore4;
-	scoresdisplay[4].score = hscores.ghighscore5;
-	scoresdisplay[5].score = hscores.ghighscore6;
-	scoresdisplay[6].score = hscores.ghighscore7;
-	scoresdisplay[7].score = hscores.ghighscore8;
-	scoresdisplay[8].score = hscores.wpm_fastest;
-	scoresdisplay[9].score = hscores.wpm_average;
-	scoresdisplay[10].score= hscores.wpm_slowest;
-	
-	scoresdisplay[0].name = hscores.highscore1_name;
-	scoresdisplay[0].name = hscores.highscore2_name;
-	scoresdisplay[0].name = hscores.highscore3_name;
-	scoresdisplay[0].name = hscores.highscore4_name;
-	scoresdisplay[0].name = hscores.highscore5_name;
-	scoresdisplay[0].name = hscores.highscore6_name;
-	scoresdisplay[0].name = hscores.highscore7_name;
-	scoresdisplay[0].name = hscores.highscore8_name;
-	scoresdisplay[0].name = hscores.wpm_fastest_name;
-	scoresdisplay[0].name = hscores.wpm_average_name;
-	scoresdisplay[0].name =hscores.wpm_slowest_name;
-}
-
-void loadPersonalScores() 
-{
-	
-	personalScores[0].score = activeProfile.highscore1;
-	personalScores[1].score = activeProfile.highscore2;
-	personalScores[2].score = activeProfile.highscore3;
-	personalScores[3].score = activeProfile.highscore4;
-	personalScores[4].score = activeProfile.highscore5;
-	personalScores[5].score = activeProfile.highscore6;
-	personalScores[6].score = activeProfile.highscore7;
-	personalScores[7].score = activeProfile.highscore8;
-	personalScores[8].score = activeProfile.wpm_fastest;
-	personalScores[9].score = activeProfile.wpm_average;
-	personalScores[10].score = activeProfile.wpm_slowest;
-	personalScores[11].core = activeProfile.wpm_taken;
-
-}
-void checkHighScores(int score) //checks to see if score qualifies as a high score, adds
-{
-	int temp, count = 1;
-	int checkScore = score;
-	do
-	{
-		if(checkScore > hscores.ghighscore(count))
-		{
-			temp = hscores.ghighscore(count);
-			hscores.ghighscore(count) = checkScore;
-			hscores.highscore(count)_name = activeProfile.profileName;
-			checkScore = temp;
-		}
-	}
-	while(checkScore < hscores.ghighscore(count) && count <=8);
-}
-
-void checkWPM(int wpm) //checks global wpm and updates if necessary
-{
-	if(wpm > hscores.wpm_fastest)
-	{
-		hscores.wpm_fastest_name = activeProfile.profileName;
-		hscores.wpm_fastest = wpm;
-	}
-	if(wpm < hscores.wpm_slowest)
-	{
-		hscores.wpm_slowest_name = activeProfile.profileName;
-		hscores.wpm_slowest = wpm;
-	}
-	if(activeProfile.wpm_average > hscores.wpm_average)
-	{
-		hscores.wpm_average_name = activeProfile.profileName;
-		hscores.wpm_average = activeProfile.wpm_average;
-	}
-}
-
-static void highscores_load_media()
-{
-	int load_failed = 0;
-
-	bg = LoadImage("main_bkg.png", IMG_ALPHA);
-	
-	if(load_failed || !bg)
-	{
-		highscores_unload_media();
-	}
-}
-
-static void highscores_unload_media()
-{
-	SDL_FreeSurface(bg);
-	bg = NULL;
-}
\ No newline at end of file

Deleted: tuxtype/branches/tuxtype-soc-mh/keyboard.lst
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/keyboard.lst	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/keyboard.lst	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,70 +0,0 @@
-# Default (English) keyboard.lst file
-0|A
-0|a
-3|B
-3|b
-2|C
-2|c
-2|D
-2|d
-2|E
-2|e
-3|F
-3|f
-3|G
-3|g
-6|H
-6|h
-7|I
-7|i
-6|J
-6|j
-7|K
-7|k
-8|L
-8|l
-6|M
-6|m
-6|N
-6|n
-8|O
-8|o
-9|P
-9|p
-0|Q
-0|q
-3|R
-3|r
-1|S
-1|s
-3|T
-3|t
-6|U
-6|u
-3|V
-3|v
-1|W
-1|w
-1|X
-1|x
-6|Y
-6|y
-0|Z
-0|z
-5| 
-0|!
-0|@
-0|#
-0|1
-0|2
-0|3
-0|4
-0|5
-0|6
-0|7
-0|8
-0|9
-0|0
-7|,
-8|.
-9|;

Deleted: tuxtype/branches/tuxtype-soc-mh/laser.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/laser.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/laser.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,1124 +0,0 @@
-/***************************************************************************
- -  file: laser.c
- -  description: a modification of TuxMath for typing :)
-                            -------------------
-    begin                : 
-    copyright            : Bill Kendrick (C) 2002
-                           Jesse Andrews (C) 2003
-    email                : tuxtype-dev at tux4kids.net
-***************************************************************************/
-
-/***************************************************************************
-*                                                                         *
-*   This program is free software; you can redistribute it and/or modify  *
-*   it under the terms of the GNU General Public License as published by  *
-*   the Free Software Foundation; either version 2 of the License, or     *
-*   (at your option) any later version.                                   *
-*                                                                         *
-***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-#include "laser.h"
-
-
-#define FPS (1000 / 15)   /* 15 fps max */
-#define CITY_EXPL_START 3 * 5  /* Must be mult. of 5 (number of expl frames) */
-#define COMET_EXPL_START 2 * 2 /* Must be mult. of 2 (number of expl frames) */
-#define ANIM_FRAME_START 4 * 2 /* Must be mult. of 2 (number of tux frames) */
-#define GAMEOVER_COUNTER_START 75
-#define LEVEL_START_WAIT_START 20
-#define LASER_START 5
-#define NUM_ANS 8
-#define COMET_ZAP_FONT_SIZE 32
-
-/* Local (to laser.c) 'globals': */
-static sprite* shield = NULL;
-static SDL_Surface* images[NUM_IMAGES] = {NULL};
-static Mix_Chunk* sounds[NUM_SOUNDS] = {NULL};
-static Mix_Music* musics[NUM_MUSICS] = {NULL};
-static TTF_Font* font = NULL;
-
-static int wave, speed, score, pre_wave_score, num_attackers, distanceMoved;
-static wchar_t ans[NUM_ANS];
-static int ans_num;
-
-static comet_type comets[MAX_COMETS];
-static city_type cities[NUM_CITIES];
-static laser_type laser;
-
-/* Local function prototypes: */
-static void laser_add_comet(int diff_level);
-static void laser_add_score(int inc);
-static void laser_draw_console_image(int i);
-static void laser_draw_let(wchar_t c, int x, int y);
-static void laser_draw_line(int x1, int y1, int x2, int y2, int r, int g, int b);
-static void laser_draw_numbers(const unsigned char* str, int x);
-static void laser_load_data(void);
-static void laser_reset_level(int diff_level);
-static void laser_putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel);
-static void laser_unload_data(void);
-static void calc_city_pos(void);
-static void recalc_comet_pos(void);
-
-/* --- MAIN GAME FUNCTION!!! --- */
-
-/* TODO modify game to allow longer words (12 chars or so) */
-
-int PlayLaserGame(int diff_level)
-{
-	int i, img, done, quit, frame, lowest, lowest_y, 
-	    tux_img, old_tux_img, tux_pressing, tux_anim, tux_anim_frame,
-	    tux_same_counter, level_start_wait, num_cities_alive,
-	    num_comets_alive, paused, picked_comet, 
-	    gameover;
-
-	Uint16 key_unicode;
-
-	SDL_Event event;
-	Uint32    last_time, now_time;
-	SDLKey    key;
-	SDL_Rect  src, dest;
-	/* str[] is a buffer to draw the scores, waves, etc. (don't need wchar_t) */
-	unsigned char str[64]; 
-
-	LOG( "starting Comet Zap game\n" );
-	DOUT( diff_level );
-
-	SDL_ShowCursor(0);
-	laser_load_data();
-
-	/* Clear window: */
-  
-	SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
-	SDL_Flip(screen);
-
-	/* --- MAIN GAME LOOP: --- */
-
-	done = 0;
-	quit = 0;
-	src.w = src.h = 0;
-
-	/* Prepare to start the game: */
-  
-	wave = 1;
-	score = 0;
-	gameover = 0;
-	level_start_wait = LEVEL_START_WAIT_START;
-
-	
-  /* (Create and position cities) */
-  for (i = 0; i < NUM_CITIES; i++)
-  {
-    cities[i].alive = 1;
-    cities[i].expl = 0;
-    cities[i].shields = 1;
-  }
-
-  /* figure out x placement: */
-  calc_city_pos();
-
-  num_cities_alive = NUM_CITIES;
-  num_comets_alive = 0;
-
-
-	/* (Clear laser) */
-
-	laser.alive = 0;
-
-  
-	/* Reset remaining stuff: */
- 
-	laser_reset_level(diff_level);
-  
-	/* --- MAIN GAME LOOP!!! --- */
-  
-	frame = 0;
-	paused = 0;
-	picked_comet = -1;
-	tux_img = IMG_TUX_RELAX1;
-	tux_anim = -1;
-	tux_anim_frame = 0;
-	tux_same_counter = 0;
-	ans_num = 0;
-
-	MusicPlay(musics[MUS_GAME + (rand() % NUM_MUSICS)], 0);
-
-	do {
-
-		frame++;
-		last_time = SDL_GetTicks();
-
-		old_tux_img = tux_img;
-		tux_pressing = 0;
-
-		/* Handle any incoming events: */
-     
-		while (SDL_PollEvent(&event) > 0) {
-
-			if (event.type == SDL_QUIT) {
-				/* Window close event - quit! */
-				exit(0);
-	      
-			} else if (event.type == SDL_KEYDOWN) {
-
-				key = event.key.keysym.sym;
-				if (key == SDLK_F10) 
-                                {
-				  SwitchScreenMode();
-                                  calc_city_pos();
-                                  recalc_comet_pos();
-                                }
-				if (key == SDLK_F11)
-					SDL_SaveBMP( screen, "laser.bmp");
-
-				if (key == SDLK_ESCAPE)
-					paused = 1;
-
-				/* --- eat other keys until level wait has passed --- */ 
-				if (level_start_wait > 0) 
-					key = SDLK_UNKNOWN;
-				
-				key_unicode = event.key.keysym.unicode;
-				//key_unicode = event.key.keysym.unicode & 0xff;
-
-				DEBUGCODE
-				{
-				  fprintf(stderr, "key_unicode = %d\n", key_unicode);
-				}
-
-				/* For now, tuxtype is case-insensitive for input, */
-                                /* with only uppercase for answers:                */
-                                if (key_unicode >= 97 && key_unicode <= 122)
-                                  key_unicode -= 32;  //convert lowercase to uppercase
-                                if (key_unicode >= 224 && key_unicode <= 255)
-                                  key_unicode -= 32; //same for non-US chars
-
-				LOG ("After checking for lower case:\n");
-				DEBUGCODE
-				{
-				  fprintf(stderr,
-                                   "key_unicode = %d\n", key_unicode);
-				}
-				/* Now update with case-folded value: */
-				ans[ans_num++] = key_unicode;
-
-			}
-		}
-      
-      
-		/* Handle answer: */
-
-		for (;ans_num>0;ans_num--) {
-
-			/*  Pick the lowest shootable comet which has the right answer: */
-	
-			lowest_y = 0;
-			lowest = -1;
-	
-			for (i = 0; i < MAX_COMETS; i++)
-				if (comets[i].alive
-				 && comets[i].shootable 
-				 && comets[i].expl == 0
-				 && comets[i].ch == ans[ans_num -1 ] 
-				 && comets[i].y > lowest_y)
-				{
-					lowest = i;
-					lowest_y = comets[i].y;
-				}
-	
-	
-			/* If there was an comet with this answer, destroy it! */
-	
-			if (lowest != -1) {
-
-				/* Destroy comet: */
-		  
-				comets[lowest].expl = COMET_EXPL_START;
-				/* Make next letter in word shootable: */
-				comets[lowest].shootable = 0;
-                                if (comets[lowest].next)
-                                  comets[lowest].next->shootable = 1;
-
-				/* Fire laser: */
-				laser.alive = LASER_START;
-
-				/* this is a hack so drawing to the center of the screen works */
-				if (abs(comets[lowest].x - screen->w/2) < 10) {
-					laser.x1 = screen->w / 2;
-					laser.y1 = screen->h;
-	    
-					laser.x2 = laser.x1;
-					laser.y2 = comets[lowest].y;
-				} else {
-					laser.x1 = screen->w / 2;
-					laser.y1 = screen->h;
-	    
-					laser.x2 = comets[lowest].x;
-					laser.y2 = comets[lowest].y;
-				}
-	    
-				PlaySound(sounds[SND_LASER]);
-	    
-				/* 50% of the time.. */
-	    
-				if (0 == (rand() % 2))  {
-
-					/* ... pick an animation to play: */ 
-					if (0 == (rand() % 2))
-						tux_anim = IMG_TUX_YES1;
-					else
-						tux_anim = IMG_TUX_YAY1;
-	        
-					tux_anim_frame = ANIM_FRAME_START;
-				}
-
-				/* Increment score: */
-
-				laser_add_score( (diff_level+1) * 5 * ((screen->h - comets[lowest].y)/20 ));
-
-			} else {
-
-				/* Didn't hit anything! */
-	    
-				PlaySound(sounds[SND_BUZZ]);
-	    
-				if (0 == (rand() % 2))
-					tux_img = IMG_TUX_DRAT;
-				else
-					tux_img = IMG_TUX_YIPE;
-
-				laser_add_score( -25 * wave);
-			}
-		}
-
-      
-		/* Handle start-wait countdown: */
-      
-		if (level_start_wait > 0) {
-
-			level_start_wait--;
-	  
-			if (level_start_wait > LEVEL_START_WAIT_START / 4)
-				tux_img = IMG_TUX_RELAX1;
-			else if (level_start_wait > 0)
-				tux_img = IMG_TUX_RELAX2;
-			else
-				tux_img = IMG_TUX_SIT;
-	  
-			if (level_start_wait == LEVEL_START_WAIT_START / 4)
-				PlaySound(sounds[SND_ALARM]);
-		}
-
-      
-		/* If Tux pressed a button, pick a new (different!) stance: */
-	  
-		if (tux_pressing) {
-			while (tux_img == old_tux_img)
-				tux_img = IMG_TUX_CONSOLE1 + (rand() % 3);
-
-			playsound(sounds[SND_CLICK]);
-		}
-      
-      
-		/* If Tux is being animated, show the animation: */
-
-		if (tux_anim != -1) {
-			tux_anim_frame--;
-
-			if (tux_anim_frame < 0)
-				tux_anim = -1;
-			else
-				tux_img = tux_anim + 1 - (tux_anim_frame / (ANIM_FRAME_START / 2));
-		}
-
-
-		/* Reset Tux to sitting if he's been doing nothing for a while: */
-
-		if (old_tux_img == tux_img) {
-			tux_same_counter++;
-
-			if (tux_same_counter >= 20)
-				old_tux_img = tux_img = IMG_TUX_SIT;
-			if (tux_same_counter >= 60)
-				old_tux_img = tux_img = IMG_TUX_RELAX1;
-		} else
-			tux_same_counter = 0;
-
-
-		/* Handle comets: */
-     
-		num_comets_alive = 0;
-
-		distanceMoved += speed;
-      
-		for (i = 0; i < MAX_COMETS; i++) {
-			if (comets[i].alive) {
-
-				num_comets_alive++;
-
-				comets[i].x = comets[i].x + 0;
-				comets[i].y = comets[i].y + speed;
-	      
-				if (comets[i].y >= (screen->h - images[IMG_CITY_BLUE]->h) && comets[i].expl == 0) {
-
-					/* Disable shields or destroy city: */
-		      
-					if (cities[comets[i].city].shields) {
-						cities[comets[i].city].shields = 0;
-						PlaySound(sounds[SND_SHIELDSDOWN]);
-						laser_add_score(-500 * (diff_level+1));
-					} else {
-						cities[comets[i].city].expl = CITY_EXPL_START;
-						PlaySound(sounds[SND_EXPLOSION]);
-						laser_add_score(-1000 * (diff_level+1));
-					}
-
-					tux_anim = IMG_TUX_FIST1;
-					tux_anim_frame = ANIM_FRAME_START;
-
-					/* Destroy comet: */
-
-					comets[i].expl = COMET_EXPL_START;
-				}
-
-				/* Handle comet explosion animation: */
-
-				if (comets[i].expl != 0) {
-					comets[i].expl--;
-
-					if (comets[i].expl == 0)
-						comets[i].alive = 0;
-				}
-			}
-		}
-
-
-		/* Handle laser: */
-
-		if (laser.alive > 0)
-			laser.alive--;
-     
-		/* Comet time! */
-
-		if (level_start_wait == 0 && (frame % 5) == 0 && gameover == 0) {
-			if (num_attackers > 0) {
-
-				/* More comets to add during this wave! */
-		
-				if ((num_comets_alive < 2 || ((rand() % 4) == 0)) && distanceMoved > 40) {
-					distanceMoved = 0;
-					laser_add_comet(diff_level);
-					num_attackers--;
-				}
-			} else {
-				if (num_comets_alive == 0) {
-
-					/* Time for the next wave! */
-
-					/* FIXME: End of level stuff goes here */
-
-					if (num_cities_alive > 0) {
-
-						/* Go on to the next wave: */
-						wave++;
-						laser_reset_level(diff_level);
-
-					} else {
-
-						/* No more cities!  Game over! */
-						gameover = GAMEOVER_COUNTER_START;
-					}
-				}
-			}
-		}
-
-
-		/* Handle cities: */
-     
-		num_cities_alive = 0;
-
-		for (i = 0; i < NUM_CITIES; i++) 
-			if (cities[i].alive) {
-
-				num_cities_alive++;
-
-				/* Handle animated explosion: */
-
-				if (cities[i].expl) {
-					cities[i].expl--;
-		  
-					if (cities[i].expl == 0)
-						cities[i].alive = 0;
-				}
-			}
-                        
-
-		/* Handle game-over: */
-
-		if (gameover > 0) {
-			gameover--;
-
-			if (gameover == 0)
-			{
-				done = 1;
-				checkHighScores(score);
-				updatePersonalScore(score);
-				
-			}
-		}
-                
-                if ((num_cities_alive==0) && (gameover == 0))
-                    gameover = GAMEOVER_COUNTER_START;
-      
-		/* Draw background: */
-     
-		SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
-
-		/* Draw wave: */
-
-		dest.x = 0;
-		dest.y = 0;
-		dest.w = images[IMG_WAVE]->w;
-		dest.h = images[IMG_WAVE]->h;
-
-		SDL_BlitSurface(images[IMG_WAVE], NULL, screen, &dest);
-
-		sprintf(str, "%d", wave);
-		laser_draw_numbers(str, images[IMG_WAVE]->w + (images[IMG_NUMBERS]->w / 10));
-
-
-		/* Draw score: */
-
-		dest.x = (screen->w - ((images[IMG_NUMBERS]->w / 10) * 7) - images[IMG_SCORE]->w);
-		dest.y = 0;
-		dest.w = images[IMG_SCORE]->w;
-		dest.h = images[IMG_SCORE]->h;
-
-		SDL_BlitSurface(images[IMG_SCORE], NULL, screen, &dest);
-      
-		sprintf(str, "%.6d", score);
-		laser_draw_numbers(str, screen->w - ((images[IMG_NUMBERS]->w / 10) * 6));
-      
-      
-		/* Draw comets: */
-      
-		for (i = 0; i < MAX_COMETS; i++) 
-			if (comets[i].alive) {
-
-				/* Decide which image to display: */
-				if (comets[i].expl == 0)
-					img = IMG_COMET1 + ((frame + i) % 3);
-				else
-					img = (IMG_COMETEX2 - (comets[i].expl / (COMET_EXPL_START / 2)));
-	      
-
-				/* Draw it! */
-
-				dest.x = comets[i].x - (images[img]->w / 2);
-				dest.y = comets[i].y - images[img]->h;
-				dest.w = images[img]->w;
-				dest.h = images[img]->h;
-	      
-				SDL_BlitSurface(images[img], NULL, screen, &dest);
-			}
-
-
-		/* Draw letters: */
-
-		for (i = 0; i < MAX_COMETS; i++)
-			if (comets[i].alive && comets[i].expl == 0)
-				laser_draw_let(comets[i].ch, comets[i].x, comets[i].y);
-      
-		/* Draw cities: */
-      
-		if (frame%2 == 0) NEXT_FRAME(shield);
-		for (i = 0; i < NUM_CITIES; i++) {
-
-			/* Decide which image to display: */
-	 
-			if (cities[i].alive) {
-				if (cities[i].expl == 0)
-					img = IMG_CITY_BLUE;
-				else
-					img = (IMG_CITY_BLUE_EXPL5 - (cities[i].expl / (CITY_EXPL_START / 5)));
-			} else 
-				img = IMG_CITY_BLUE_DEAD;
-	  
-	  
-			/* Change image to appropriate color: */
-	  
-			img += ((wave % MAX_CITY_COLORS) * (IMG_CITY_GREEN - IMG_CITY_BLUE));
-	  
-	  
-			/* Draw it! */
-	  
-			dest.x = cities[i].x - (images[img]->w / 2);
-			dest.y = (screen->h) - (images[img]->h);
-			dest.w = (images[img]->w);
-			dest.h = (images[img]->h);
-	  
-			SDL_BlitSurface(images[img], NULL, screen, &dest);
-
-			/* Draw sheilds: */
-
-			if (cities[i].shields) {
-
-				dest.x = cities[i].x - (shield->frame[shield->cur]->w / 2);
-				dest.h = (screen->h) - (shield->frame[shield->cur]->h);
-				dest.w = src.w;
-				dest.h = src.h;
-				SDL_BlitSurface( shield->frame[shield->cur], NULL, screen, &dest);
-
-			}
-		}
-
-
-		/* Draw laser: */
-
-		if (laser.alive)
-			laser_draw_line(laser.x1, laser.y1, laser.x2, laser.y2, 255 / (LASER_START - laser.alive),
-			                192 / (LASER_START - laser.alive), 64);
-
-		laser_draw_console_image(IMG_CONSOLE);
-
-		if (gameover > 0)
-			tux_img = IMG_TUX_FIST1 + ((frame / 2) % 2);
-
-		laser_draw_console_image(tux_img);
-
-
-		/* Draw "Game Over" */
-
-		if (gameover > 0) {
-
-			dest.x = (screen->w - images[IMG_GAMEOVER]->w) / 2;
-			dest.y = (screen->h - images[IMG_GAMEOVER]->h) / 2;
-			dest.w = images[IMG_GAMEOVER]->w;
-			dest.h = images[IMG_GAMEOVER]->h;
-	
-			SDL_BlitSurface(images[IMG_GAMEOVER], NULL, screen, &dest);
-		}
-      
-      
-		/* Swap buffers: */
-      
-		SDL_Flip(screen);
-
-
-		/* If we're in "PAUSE" mode, pause! */
-
-		if (paused) {
-			quit = Pause();
-			paused = 0;
-		}
-
-      
-		/* Keep playing music: */
-      
-		if (settings.sys_sound && !Mix_PlayingMusic())
-			MusicPlay(musics[MUS_GAME + (rand() % NUM_MUSICS)], 0);
-      
-		/* Pause (keep frame-rate event) */
-      
-		now_time = SDL_GetTicks();
-		if (now_time < last_time + FPS)
-			SDL_Delay(last_time + FPS - now_time);
-	}
-		while (!done && !quit);
-
-  
-  /* Free backgrounds: */
-  FreeBothBkgds();
-
-	/* Stop music: */
-	if ((settings.sys_sound) && (Mix_PlayingMusic()))
-		Mix_HaltMusic();
- 
-	laser_unload_data();
- 
-	return 1;
-}
-
-
-/*****************************************************/
-/*                                                   */
-/*          Local ("private") functions:             */
-/*                                                   */
-/*****************************************************/
-
-
-static void calc_city_pos(void)
-{
-  int i = 0;
-
-  for (i = 0; i < NUM_CITIES; i++)
-  {
-    if (NUM_CITIES % 2 == 0)
-    {
-      /* Left vs. Right - makes room for Tux and the console */
-      if (i < NUM_CITIES / 2)
-      {
-        cities[i].x = (((screen->w / (NUM_CITIES + 1)) * i)
-                      + ((images[IMG_CITY_BLUE] -> w) / 2));
-      }
-      else
-      {
-        cities[i].x = screen->w
-                    - screen->w/(NUM_CITIES + 1) * (i - NUM_CITIES/2)
-                    + images[IMG_CITY_BLUE]->w/2;
-      }
-    }
-    else
-    {
-      /* put them in order across the bottom of     *
-      * the screen so we can do words in order!!! */
-      cities[i].x = i*screen->w/(NUM_CITIES)
-                    + images[IMG_CITY_BLUE]->w/2;
-    }
-  }
-}
-
-/* Update the x position of comets when resolution changes: */
-/* Must call calc_city_pos() first for this to work! */
-static void recalc_comet_pos(void)
-{
-  int i, target;
-
-  for (i = 0; i < MAX_COMETS; i++)
-  {
-    /* Set each live comet's x to that of its target city: */
-    if (comets[i].alive == 1)
-    {
-      target = comets[i].city;
-      comets[i].x = cities[target].x;
-    }
-  }
-}
-
-
-/* --- Load all media --- */
-static void laser_load_data(void)
-{
-	int i;
-
-	/* Create the SDL_Surfaces for all of the characters */
-        /* used in the word list: */
-	font = LoadFont(settings.theme_font_name, COMET_ZAP_FONT_SIZE);
-	RenderLetters(font);
-
-	/* Load images: */
-	for (i = 0; i < NUM_IMAGES; i++) 
-		images[i] = LoadImage(image_filenames[i], IMG_ALPHA);
-	shield = LoadSprite( "cities/shield", IMG_ALPHA );
-
-	if (settings.sys_sound) {
-		for (i = 0; i < NUM_SOUNDS; i++)
-			sounds[i] = LoadSound(sound_filenames[i]);
-
-		for (i = 0; i < NUM_MUSICS; i++)
-			musics[i] = LoadMusic(music_filenames[i]);
-	}
-
-//	PauseLoadMedia();
-}
-
-
-/* --- unload all media --- */
-static void laser_unload_data(void) {
-	int i;
-
-	FreeLetters();
-
-	for (i = 0; i < NUM_IMAGES; i++)
-		SDL_FreeSurface(images[i]);
-
-	if (settings.sys_sound) {
-		for (i = 0; i < NUM_SOUNDS; i++)
-			Mix_FreeChunk(sounds[i]);
-		for (i = 0; i < NUM_MUSICS; i++)
-			Mix_FreeMusic(musics[i]);
-	}
-
-	FreeSprite(shield);
-        shield = NULL;
-
-//	PauseUnloadMedia();
-
-	TTF_CloseFont(font);
-        font = NULL;
-}
-
-
-/* Reset stuff for the next level! */
-
-static void laser_reset_level(int diff_level)
-{
-  unsigned char fname[1024];
-  static int last_bkgd = -1;
-  int i;
-  
-  /* Clear all comets: */
-  
-  for (i = 0; i < MAX_COMETS; i++)
-    comets[i].alive = 0;
-  
-  /* Load diffrent random background image: */
-  LOG("Loading background in laser_reset_level()\n");
-
-  do {
-    i = rand() % NUM_BKGDS;
-    DOUT(i);
-  }
-  while (i == last_bkgd);
-
-  last_bkgd = i;
-
-  DOUT(i);
-
-  sprintf(fname, "backgrounds/%d.jpg", i);
-
-  LOG("Will try to load file:");
-  LOG(fname);
-
-  FreeBothBkgds(); // LoadBothBkgds() actually does this just in case
-
-  LoadBothBkgds(fname);
-
-  if (CurrentBkgd() == NULL)
-  {
-    fprintf(stderr,
-     "\nWarning: Could not load background image:\n"
-     "%s\n"
-     "The Simple DirectMedia error that ocurred was: %s\n",
-     fname, SDL_GetError());
-  }
-
-  /* Record score before this wave: */
-
-  pre_wave_score = score;
-
-  /* Set number of attackers & speed for this wave: */
-
-  switch (diff_level) {
-    case 0 : speed = 1 + (wave/5); num_attackers=15; break;
-    case 1 : speed = 1 + (wave/4); num_attackers=15; break;
-    case 2 : speed = 1 + ((wave<<1)/3); num_attackers=(wave<<1); break;
-    case 3 : speed = 1 + wave; num_attackers=(wave<<1); break;
-    default: LOG("diff_level not recognized!\n");
-  }
-
-  distanceMoved = 100; // so that we don't have to wait to start the level
-  LOG("Leaving laser_reset_level()\n");
-}
-
-
-/* Add an comet to the game (if there's room): */
-
-static void laser_add_comet(int diff_level) {
-
-	int target, location = 0;
-	static int last = -1;
-	int targeted[NUM_CITIES] = { 0 };
-	int add = (rand() % (diff_level + 2));
-
-	LOG ("Entering laser_add_comet()\n");
-	DEBUGCODE { fprintf(stderr, "Adding %d comets \n", add); }
-
-	if (0 == NUM_CITIES % 2) /* Even number of cities */
-	{
-          LOG("NUM_CITIES is even\n");
-	  while ((add > 0) && (location != MAX_COMETS))
-	  {
-            /* Look for a free comet slot: */
-            while ((comets[location].alive == 1) && (location < MAX_COMETS))
-            {
-              location++; 
-            }
-            if (location < MAX_COMETS)
-            {
-              comets[location].alive = 1;
-              /* Pick a city to attack: */
-              do
-              { 
-                target = (rand() % NUM_CITIES);
-              } while (target == last || targeted[target] == 1);
-
-              last = target;
-              targeted[target] = 1;
-
-              /* Set comet to target that city: */
-              comets[location].city = target; 
-
-              /* Start at the top, above the city in question: */
-              comets[location].x = cities[target].x;
-              comets[location].y = 0;
-
-              /* Pick a letter */
-              comets[location].ch = GetLetter();
-              /* single letters always shootable: */
-              comets[location].shootable = 1;
-              comets[location].next = NULL;
-
-              add--;
-            }
-            DEBUGCODE {if (location == MAX_COMETS) 
-			printf("Location == MAX_COMETS, we have max on screen\n");}
-	  } 
-	}
-	else /* Odd number of cities (is this a hack that means we are using words?) */
-        {
-          LOG("NUM_CITIES is odd\n");
-          wchar_t* word = GetWord();
-          int i = 0;
-          comet_type* prev_comet = NULL;
-
-          DEBUGCODE {fprintf(stderr, "word is: %S\tlength is: %d\n", word, (int)wcslen(word));}
-          do
-          { 
-  	    target = rand() % (NUM_CITIES - wcslen(word) + 1);
-          } while (target == last);
-          last = target;
-
-		for (i=0; i < wcslen(word); i++)
-		{
- 			while ((comets[location].alive == 1) && (location < MAX_COMETS))
-				location++; 
-
-  			if (location < MAX_COMETS)
-			{
-				/* First comet in word is shootable: */
-				if (0 == i)
-				  comets[location].shootable = 1;
-				else
-				  comets[location].shootable = 0;
-
-				comets[location].alive = 1;
-				comets[location].city = target + i; 
-				comets[location].x = cities[target + i].x;
-				comets[location].y = 0;
-				comets[location].ch = word[i];
-				comets[location].next = NULL;
-
-				/* Take care of link from previous letter's comet: */
-				if (prev_comet)
-				  prev_comet->next = &comets[location];
-				/* Save pointer for next time through: */
-                                prev_comet = &comets[location];
-
-				DEBUGCODE {fprintf(stderr, "Assigning letter to comet: %C\n", word[i]);}
-			}
-		}
-	}
-	LOG ("Leaving laser_add_comet()\n");
-}
-
-
-/* Draw numbers/symbols over the attacker: */
-
-static void laser_draw_let(wchar_t c, int x, int y)
-{
-  /* Draw letter in correct place relative to comet: */
-  const int offset_x = -10; /* Values determined by trial and error: */
-  const int offset_y = -50;
-
-  SDL_Rect dst;
-  SDL_Surface* s;
-  dst.x = x + offset_x;
-  dst.y = y + offset_y;
-  s = GetWhiteGlyph(c);
-  if (s)
-    SDL_BlitSurface(s, NULL, screen, &dst); 
-}
-
-
-/* Draw status numbers: */
-
-static void laser_draw_numbers(const unsigned char* str, int x)
-{
-  int i, cur_x, c;
-  SDL_Rect src, dest;
-
-
-  cur_x = x;
-
-
-  /* Draw each character: */
-  
-  for (i = 0; i < strlen(str); i++)
-    {
-      c = -1;
-
-
-      /* Determine which character to display: */
-      
-      if (str[i] >= '0' && str[i] <= '9')
-	c = str[i] - '0';
-      
-
-      /* Display this character! */
-      
-      if (c != -1)
-	{
-	  src.x = c * (images[IMG_NUMBERS]->w / 10);
-	  src.y = 0;
-	  src.w = (images[IMG_NUMBERS]->w / 10);
-	  src.h = images[IMG_NUMBERS]->h;
-	  
-	  dest.x = cur_x;
-	  dest.y = 0;
-	  dest.w = src.w;
-	  dest.h = src.h;
-	  
-	  SDL_BlitSurface(images[IMG_NUMBERS], &src,
-			  screen, &dest);
-
-
-          /* Move the 'cursor' one character width: */
-
-	  cur_x = cur_x + (images[IMG_NUMBERS]->w / 10);
-	}
-    }
-}
-
-/* Draw a line: */
-
-static void laser_draw_line(int x1, int y1, int x2, int y2, int red, int grn, int blu)
-{
-  int dx, dy, tmp;
-  float m, b;
-  Uint32 pixel;
-  SDL_Rect dest;
- 
-  pixel = SDL_MapRGB(screen->format, red, grn, blu);
-
-  dx = x2 - x1;
-  dy = y2 - y1;
-
-  laser_putpixel(screen, x1, y1, pixel);
-  
-  if (dx != 0)
-  {
-    m = ((float) dy) / ((float) dx);
-    b = y1 - m * x1;
-
-    if (x2 > x1)
-      dx = 1;
-    else
-      dx = -1;
-
-    while (x1 != x2)
-    {
-      x1 = x1 + dx;
-      y1 = m * x1 + b;
-      
-      laser_putpixel(screen, x1, y1, pixel);
-    }
-  }
-  else
-  {
-    if (y1 > y2)
-    {
-      tmp = y1;
-      y1 = y2;
-      y2 = tmp;
-    }
-    
-    dest.x = x1;
-    dest.y = y1;
-    dest.w = 3;
-    dest.h = y2 - y1;
-
-    SDL_FillRect(screen, &dest, pixel);
-  }
-}
-
-
-/* Draw a single pixel into the surface: */
-
-static void laser_putpixel(SDL_Surface * surface, int x, int y, Uint32 pixel)
-{
-#ifdef PUTPIXEL_RAW
-  int bpp;
-  Uint8 * p;
-  
-  /* Determine bytes-per-pixel for the surface in question: */
-  
-  bpp = surface->format->BytesPerPixel;
-  
-  
-  /* Set a pointer to the exact location in memory of the pixel
-     in question: */
-  
-  p = (Uint8 *) (surface->pixels +       /* Start at beginning of RAM */
-                 (y * surface->pitch) +  /* Go down Y lines */
-                 (x * bpp));             /* Go in X pixels */
-  
-  
-  /* Assuming the X/Y values are within the bounds of this surface... */
-  
-  if (x >= 0 && y >= 0 && x < surface -> w && y < surface -> h)
-    {
-      /* Set the (correctly-sized) piece of data in the surface's RAM
-         to the pixel value sent in: */
-      
-      if (bpp == 1)
-        *p = pixel;
-      else if (bpp == 2)
-        *(Uint16 *)p = pixel;
-      else if (bpp == 3)
-        {
-          if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
-            {
-              p[0] = (pixel >> 16) & 0xff;
-              p[1] = (pixel >> 8) & 0xff;
-              p[2] = pixel & 0xff;
-            }
-          else
-            {
-              p[0] = pixel & 0xff;
-              p[1] = (pixel >> 8) & 0xff;
-              p[2] = (pixel >> 16) & 0xff;
-            }
-        }
-      else if (bpp == 4)
-        {
-          *(Uint32 *)p = pixel;
-        }
-    }
-#else
-  SDL_Rect dest;
-
-  dest.x = x;
-  dest.y = y;
-  dest.w = 3;
-  dest.h = 4;
-
-  SDL_FillRect(surface, &dest, pixel);
-#endif
-}
-
-
-/* Draw image at lower center of screen: */
-
-static void laser_draw_console_image(int i)
-{
-  SDL_Rect dest;
-
-  dest.x = (screen->w - images[i]->w) / 2;
-  dest.y = (screen->h - images[i]->h);
-  dest.w = images[i]->w;
-  dest.h = images[i]->h;
-
-  SDL_BlitSurface(images[i], NULL, screen, &dest);
-}
-
-
-/* Increment score: */
-
-static void laser_add_score(int inc)
-{
-  score += inc;
-  if (score < 0) score = 0;
-}
-

Deleted: tuxtype/branches/tuxtype-soc-mh/laser.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/laser.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/laser.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,188 +0,0 @@
-
-#ifndef LASER_H
-#define LASER_H
-
-#define MAX_COMETS 30
-#define NUM_CITIES 9   /* MUST BE AN EVEN NUMBER! */
-
-#define NUM_BKGDS 5
-#define MAX_CITY_COLORS 4
-
-typedef struct comet_type {
-  int alive;
-  int expl;
-  int city;
-  int x, y;
-  int shootable;
-  struct comet_type* next;
-  wchar_t ch;
-} comet_type;
-
-typedef struct city_type {
-  int alive, expl, shields;
-  int x;
-} city_type;
-
-typedef struct laser_type {
-  int alive;
-  int x1, y1;
-  int x2, y2;
-} laser_type;
-
-enum {
-  IMG_TUX_HELMET1,
-  IMG_TUX_HELMET2,
-  IMG_TUX_HELMET3,
-  IMG_CITY_BLUE,
-  IMG_CITY_BLUE_EXPL1,
-  IMG_CITY_BLUE_EXPL2,
-  IMG_CITY_BLUE_EXPL3,
-  IMG_CITY_BLUE_EXPL4,
-  IMG_CITY_BLUE_EXPL5,
-  IMG_CITY_BLUE_DEAD,
-  IMG_CITY_GREEN,
-  IMG_CITY_GREEN_EXPL1,
-  IMG_CITY_GREEN_EXPL2,
-  IMG_CITY_GREEN_EXPL3,
-  IMG_CITY_GREEN_EXPL4,
-  IMG_CITY_GREEN_EXPL5,
-  IMG_CITY_GREEN_DEAD,
-  IMG_CITY_ORANGE,
-  IMG_CITY_ORANGE_EXPL1,
-  IMG_CITY_ORANGE_EXPL2,
-  IMG_CITY_ORANGE_EXPL3,
-  IMG_CITY_ORANGE_EXPL4,
-  IMG_CITY_ORANGE_EXPL5,
-  IMG_CITY_ORANGE_DEAD,
-  IMG_CITY_RED,
-  IMG_CITY_RED_EXPL1,
-  IMG_CITY_RED_EXPL2,
-  IMG_CITY_RED_EXPL3,
-  IMG_CITY_RED_EXPL4,
-  IMG_CITY_RED_EXPL5,
-  IMG_CITY_RED_DEAD,
-  IMG_COMET1,
-  IMG_COMET2,
-  IMG_COMET3,
-  IMG_COMETEX1,
-  IMG_COMETEX2,
-  IMG_CONSOLE,
-  IMG_TUX_CONSOLE1,
-  IMG_TUX_CONSOLE2,
-  IMG_TUX_CONSOLE3,
-  IMG_TUX_CONSOLE4,
-  IMG_TUX_RELAX1,
-  IMG_TUX_RELAX2,
-  IMG_TUX_DRAT,
-  IMG_TUX_YIPE,
-  IMG_TUX_YAY1,
-  IMG_TUX_YAY2,
-  IMG_TUX_YES1,
-  IMG_TUX_YES2,
-  IMG_TUX_SIT,
-  IMG_TUX_FIST1,
-  IMG_TUX_FIST2,
-  IMG_WAVE,
-  IMG_SCORE,
-  IMG_NUMBERS,
-  IMG_GAMEOVER,
-  NUM_IMAGES
-};
-
-
-static unsigned char * image_filenames[NUM_IMAGES] = {
-  "status/tux_helmet1.png",
-  "status/tux_helmet2.png",
-  "status/tux_helmet3.png", 
-  "cities/city-blue.png",
-  "cities/csplode-blue-1.png",
-  "cities/csplode-blue-2.png",
-  "cities/csplode-blue-3.png",
-  "cities/csplode-blue-4.png",
-  "cities/csplode-blue-5.png",
-  "cities/cdead-blue.png",
-  "cities/city-green.png",
-  "cities/csplode-green-1.png",
-  "cities/csplode-green-2.png",
-  "cities/csplode-green-3.png",
-  "cities/csplode-green-4.png",
-  "cities/csplode-green-5.png",
-  "cities/cdead-green.png",
-  "cities/city-orange.png",
-  "cities/csplode-orange-1.png",
-  "cities/csplode-orange-2.png",
-  "cities/csplode-orange-3.png",
-  "cities/csplode-orange-4.png",
-  "cities/csplode-orange-5.png",
-  "cities/cdead-orange.png",
-  "cities/city-red.png",
-  "cities/csplode-red-1.png",
-  "cities/csplode-red-2.png",
-  "cities/csplode-red-3.png",
-  "cities/csplode-red-4.png",
-  "cities/csplode-red-5.png",
-  "cities/cdead-red.png",
-  "comets/comet1.png",
-  "comets/comet2.png",
-  "comets/comet3.png",
-  "comets/cometex1.png",
-  "comets/cometex2.png",
-  "tux/console.png",
-  "tux/tux-console1.png",
-  "tux/tux-console2.png",
-  "tux/tux-console3.png",
-  "tux/tux-console4.png",
-  "tux/tux-relax1.png",
-  "tux/tux-relax2.png",
-  "tux/tux-drat.png",
-  "tux/tux-yipe.png",
-  "tux/tux-yay1.png",
-  "tux/tux-yay2.png",
-  "tux/tux-yes1.png",
-  "tux/tux-yes2.png",
-  "tux/tux-sit.png",
-  "tux/tux-fist0.png",
-  "tux/tux-fist1.png",
-  "status/wave.png",
-  "status/score.png",
-  "status/numbers.png",
-  "status/gameover.png"
-};
-
-enum {
-  SND_POP,
-  SND_LASER,
-  SND_BUZZ,
-  SND_ALARM,
-  SND_SHIELDSDOWN,
-  SND_EXPLOSION,
-  SND_CLICK,
-  NUM_SOUNDS
-};
-
-
-static unsigned char * sound_filenames[NUM_SOUNDS] = {
-  "pop.wav",
-  "laser.wav",
-  "buzz.wav",
-  "alarm.wav",
-  "shieldsdown.wav",
-  "explosion.wav",
-  "click.wav"
-};
-
-
-enum {
-  MUS_GAME,
-  MUS_GAME2,
-  MUS_GAME3,
-  NUM_MUSICS
-};
-
-static unsigned char * music_filenames[NUM_MUSICS] = {
-  "game.mod",
-  "game2.mod",
-  "game3.mod"
-};
-
-#endif

Deleted: tuxtype/branches/tuxtype-soc-mh/loaders.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/loaders.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/loaders.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,508 +0,0 @@
-/***************************************************************************
- -  file: loaders.c
- -  description: Functions to load multimedia for Tux Typing
-                             -------------------
-    begin                : Thu May 4 2000
-    copyright            : (C) 2000 by Sam Hart
-                         : (C) 2003 by Jesse Andrews
-    email                : tuxtype-dev at tux4kids.net
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-#include "SDL_extras.h"
-
-static SDL_Surface* win_bkgd = NULL;
-static SDL_Surface* fullscr_bkgd = NULL;
-
-/* Local function prototypes: */
-static int max(int n1, int n2);
-//static SDL_Surface* flip(SDL_Surface *in, int x, int y);
-
-/* Returns 1 if valid file, 2 if valid dir, 0 if neither: */
-int CheckFile(const char* file)
-{
-  FILE* fp = NULL;
-  DIR* dp = NULL;
-
-  if (!file)
-  {
-    fprintf(stderr, "CheckFile(): invalid char* argument!");
-    return;
-  }
-
-  DEBUGCODE {fprintf(stderr, "CheckFile() - checking: %s\n", file);} 
-
-  dp = opendir(file);
-  if (dp)
-  {
-    LOG("Opened successfully as DIR\n");
-
-    closedir(dp);
-    return 2;
-  }
-
-  fp = fopen(file, "r");
-  if (fp)
-  {
-    LOG("Opened successfully as FILE\n");
-    fclose(fp);
-    return 1;
-  }
-
-  LOG("Unable to open as either FILE or DIR\n");
-  return 0;
-}
-
-
-/* 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)
-{
-
-	setlocale(LC_ALL,settings.theme_locale_name);
-	bindtextdomain(PACKAGE,"/usr/local/share/locale");
-        textdomain(PACKAGE);
-	return;
-
-}
-
-int max(int n1, int n2)
-{
-	return (n1 > n2 ? n1 : n2);
-}
-
-// /**********************
-//  Flip:
-//    input: a SDL_Surface, x, y
-//    output: a copy of the SDL_Surface flipped via rules:
-// 
-//      if x is a positive value, then flip horizontally
-//      if y is a positive value, then flip vertically
-// 
-//      note: you can have it flip both
-// **********************/
-// SDL_Surface* flip(SDL_Surface* in, int x, int y ) {
-// 	SDL_Surface *out, *tmp;
-// 	SDL_Rect from_rect, to_rect;
-// 	Uint32	flags;
-// 	Uint32  colorkey=0;
-// 
-// 	/* --- grab the settings for the incoming pixmap --- */
-// 
-// 	SDL_LockSurface(in);
-// 	flags = in->flags;
-// 
-// 	/* --- change in's flags so ignore colorkey & alpha --- */
-// 
-// 	if (flags & SDL_SRCCOLORKEY) {
-// 		in->flags &= ~SDL_SRCCOLORKEY;
-// 		colorkey = in->format->colorkey;
-// 	}
-// 	if (flags & SDL_SRCALPHA) {
-// 		in->flags &= ~SDL_SRCALPHA;
-// 	}
-// 
-// 	SDL_UnlockSurface(in);
-// 
-// 	/* --- create our new surface --- */
-// 
-// 	out = SDL_CreateRGBSurface(
-// 		SDL_SWSURFACE,
-// 		in->w, in->h, 32, RMASK, GMASK, BMASK, AMASK);
-// 
-// 	/* --- flip horizontally if requested --- */
-// 
-// 	if (x) {
-// 		from_rect.h = to_rect.h = in->h;
-// 		from_rect.w = to_rect.w = 1;
-// 		from_rect.y = to_rect.y = 0;
-// 		from_rect.x = 0;
-// 		to_rect.x = in->w - 1;
-// 
-// 		do {
-// 			SDL_BlitSurface(in, &from_rect, out, &to_rect);
-// 			from_rect.x++;
-// 			to_rect.x--;
-// 		} while (to_rect.x >= 0);
-// 	}
-// 
-// 	/* --- flip vertically if requested --- */
-// 
-// 	if (y) {
-// 		from_rect.h = to_rect.h = 1;
-// 		from_rect.w = to_rect.w = in->w;
-// 		from_rect.x = to_rect.x = 0;
-// 		from_rect.y = 0;
-// 		to_rect.y = in->h - 1;
-// 
-// 		do {
-// 			SDL_BlitSurface(in, &from_rect, out, &to_rect);
-// 			from_rect.y++;
-// 			to_rect.y--;
-// 		} while (to_rect.y >= 0);
-// 	}
-// 
-// 	/* --- restore colorkey & alpha on in and setup out the same --- */
-// 
-// 	SDL_LockSurface(in);
-// 
-// 	if (flags & SDL_SRCCOLORKEY) {
-// 		in->flags |= SDL_SRCCOLORKEY;
-// 		in->format->colorkey = colorkey;
-// 		tmp = SDL_DisplayFormat(out);
-// 		SDL_FreeSurface(out);
-// 		out = tmp;
-// 		out->flags |= SDL_SRCCOLORKEY;
-// 		out->format->colorkey = colorkey;
-// 	} else if (flags & SDL_SRCALPHA) {
-// 		in->flags |= SDL_SRCALPHA;
-// 		tmp = SDL_DisplayFormatAlpha(out);
-// 		SDL_FreeSurface(out);
-// 		out = tmp;
-// 	} else {
-// 		tmp = SDL_DisplayFormat(out);
-// 		SDL_FreeSurface(out);
-// 		out = tmp;
-// 	}
-// 
-// 	SDL_UnlockSurface(in);
-// 
-// 	return out;
-// }
-
-
-/* FIXME need code to search for font paths on different platforms */
-TTF_Font* LoadFont(const char* font_name, int font_size )
-{
-  TTF_Font* loaded_font = NULL;
-  char fn[FNLEN];
-  int i;
-
-  /* try to find font in default data dir: */
-  sprintf(fn, "%s/fonts/%s", settings.default_data_path, font_name );
-
-  DEBUGCODE { fprintf(stderr, "LoadFont(): looking for %s using data paths\n", fn); }
-
-  /* try to load the font, if successful, return font*/
-  loaded_font = TTF_OpenFont(fn, font_size);
-  if (loaded_font != NULL)
-    return loaded_font;
-		
-
-  /* HACK hard-coded for Debian (and current exact font names): */ 
-
-  if (strncmp(font_name, "AndikaDesRevG.ttf", FNLEN ) == 0)
-    sprintf(fn, "/usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevG.ttf");
-  else if (strncmp(font_name, "DoulosSILR.ttf", FNLEN ) == 0)
-    sprintf(fn, "/usr/share/fonts/truetype/ttf-sil-doulos/DoulosSILR.ttf");
-  else if (strncmp(font_name, "lohit_hi.ttf", FNLEN ) == 0)
-    sprintf(fn, "/usr/share/fonts/truetype/ttf-devanagari-fonts/lohit_hi.ttf");
-  else if (strncmp(font_name, "Rachana_w01.ttf", FNLEN ) == 0)
-    sprintf(fn, "/usr/share/fonts/truetype/ttf-malayalam-fonts/Rachana_w01.ttf");
-
-
-
-  DEBUGCODE { fprintf(stderr, "LoadFont(): looking for %s\n in OS' font path\n", fn); }
-
-  /* try to load the font, if successful, return font*/
-  loaded_font = TTF_OpenFont(fn, font_size);
-  if (loaded_font != NULL)
-    return loaded_font;
-
-  fprintf(stderr, "LoadFont(): Error - couldn't load font: %s\n", fn);
-  return NULL;
-}
-
-/***********************
-	LoadImage : Load an image and set transparent if requested
-************************/
-SDL_Surface* LoadImage(const char* datafile, int mode)
-{
-  int oldDebug;  //so we can turn off debug output for this func only
-  SDL_Surface* tmp_pic = NULL, *final_pic = NULL;
-  char fn[FNLEN];
-
-//  oldDebug = settings.debug_on;  // suppress output for now
-//  settings.debug_on = 0;
-
-  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); }
-
-    tmp_pic = IMG_Load(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);}
-  }
-
-  /* If we don't have a valid image yet, try the default path: */
-  if (!tmp_pic)
-  {
-    sprintf(fn, "%s/images/%s", settings.default_data_path, datafile);
-    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);}
-    else
-      DEBUGCODE { fprintf(stderr, "Warning: graphics file %s could not be loaded\n", fn);}
-  }
-
-  /* Couldn't load image - action depends on whether image is essential: */
-  if (!tmp_pic)
-  {
-    if (mode & IMG_NOT_REQUIRED)
-    { 
-//      settings.debug_on = oldDebug;
-      return NULL;
-    }
-
-    fprintf(stderr, "ERROR could not load required graphics file %s\n", datafile);
-    exit(1);
-  }
-
-
-  /* If we get to here, success - setup the image in the proper format: */
-
-  switch (mode & IMG_MODES)
-  {
-    case IMG_REGULAR:
-    { 
-      final_pic = SDL_DisplayFormat(tmp_pic);
-      SDL_FreeSurface(tmp_pic);
-      break;
-    }
-
-    case IMG_ALPHA:
-    {
-      final_pic = SDL_DisplayFormatAlpha(tmp_pic);
-      SDL_FreeSurface(tmp_pic);
-      break;
-    }
-
-    case IMG_COLORKEY:
-    {
-      SDL_LockSurface(tmp_pic);
-      SDL_SetColorKey(tmp_pic,
-                      (SDL_SRCCOLORKEY | SDL_RLEACCEL),
-                      SDL_MapRGB(tmp_pic->format, 255, 255, 0));
-      final_pic = SDL_DisplayFormat(tmp_pic);
-      SDL_FreeSurface(tmp_pic);
-      break;
-    }
-
-    default:
-    {
-      LOG ("Image mode not recognized\n");
-    }
-  }
-
-  LOG( "LoadImage(): Done\n" );
-
-//  settings.debug_on = oldDebug;
-
-  return (final_pic);
-}
-
-
-
-/**********************
-LoadBothBkgds() : loads two scaled images: one for the user's native 
-resolution and one for 640x480 fullscreen. 
-Returns: the number of images that were scaled
-**********************/
-int LoadBothBkgds(const char* datafile)
-{
-  int ret = 0;
-  SDL_Surface* orig = NULL;
-  
-  //Avoid memory leak in case something else already loaded:
-  FreeBothBkgds();
-
-  LOG("Entering LoadBothBkgds()\n");
-
-  orig = LoadImage(datafile, IMG_REGULAR);
-
-  DEBUGCODE
-  {
-     printf("Scaling %dx%d to: %dx%d, %dx%d\n", 
-           orig->w, orig->h, RES_X, RES_Y, fs_res_x, fs_res_y);
-  }
-
-  if (orig->w == RES_X && orig->h == RES_Y)
-  {
-    win_bkgd = orig;
-  }
-  else
-  {
-    win_bkgd = zoom(orig, RES_X, RES_Y);
-    ++ret;
-  }
-  
-  if (orig->w == fs_res_x && orig->h == fs_res_y)
-  {
-    fullscr_bkgd = orig;
-  }
-  else
-  {
-    fullscr_bkgd = zoom(orig, fs_res_x, fs_res_y);
-    ++ret;
-  }
-  
-  if (ret == 2) //orig won't be used at all
-    SDL_FreeSurface(orig);
-    
-  DEBUGCODE
-  {
-    printf("%d images scaled\nLeaving LoadBothBkgds()\n", ret);
-  }
-  return ret;
-}
-
-
-SDL_Surface* CurrentBkgd(void)
-{
-  if (!screen)
-    return NULL;
-  if (screen->flags & SDL_FULLSCREEN)
-    return fullscr_bkgd;
-  else
-    return win_bkgd;
-}
-
-void FreeBothBkgds(void)
-{
-  if (win_bkgd)
-    SDL_FreeSurface(win_bkgd);
-  win_bkgd = NULL;
-
-  if (fullscr_bkgd)
-    SDL_FreeSurface(fullscr_bkgd);
-  fullscr_bkgd = NULL;
-}
-
-
-sprite* FlipSprite(sprite* in, int X, int Y ) {
-	sprite* out;
-
-	out = malloc(sizeof(sprite));
-	if (in->default_img != NULL)
-		out->default_img = Flip( in->default_img, X, Y );
-	else
-		out->default_img = NULL;
-	for ( out->num_frames=0; out->num_frames<in->num_frames; out->num_frames++ )
-		out->frame[out->num_frames] = Flip( in->frame[out->num_frames], X, Y );
-	out->cur = 0;
-	return out;
-}
-
-sprite* LoadSprite(const char* name, int MODE ) {
-	sprite *new_sprite;
-	char fn[FNLEN];
-	int x;
-
-	/* JA --- HACK check out what has changed with new code */
-
-	new_sprite = malloc(sizeof(sprite));
-
-	sprintf(fn, "%sd.png", name);
-	new_sprite->default_img = LoadImage( fn, MODE|IMG_NOT_REQUIRED );
-	for (x = 0; x < MAX_SPRITE_FRAMES; x++) {
-		sprintf(fn, "%s%d.png", name, x);
-		new_sprite->frame[x] = LoadImage( fn, MODE|IMG_NOT_REQUIRED );
-		if ( new_sprite->frame[x] == NULL ) {
-			new_sprite->cur = 0;
-			new_sprite->num_frames = x;
-			break;
-		}
-	}
-
-	DEBUGCODE {
-		fprintf( stderr, "loading sprite %s - contains %d frames\n",
-		        name, new_sprite->num_frames );
-	}
-
-	return new_sprite;
-}
-
-void FreeSprite(sprite* gfx )
-{
-  int x;
-
-  if (!gfx)
-    return;
- 
-  for (x = 0; x < gfx->num_frames; x++)
-    SDL_FreeSurface(gfx->frame[x]);
-  SDL_FreeSurface(gfx->default_img);
-  free(gfx);
-}
-
-/***************************
-	LoadSound : Load a sound/music patch from a file.
-****************************/
-Mix_Chunk* LoadSound(const char* datafile )
-{ 
-  Mix_Chunk* tempChunk = NULL;
-  char fn[FNLEN];
-
-  /* First look under theme path if desired: */
-  if (!settings.use_english)
-  {
-    sprintf(fn , "%s/sounds/%s", settings.theme_data_path, datafile);
-    tempChunk = Mix_LoadWAV(fn);
-    if (tempChunk)
-      return tempChunk;
-  }
-
-  /* If nothing loaded yet, try default path: */
-  if (!tempChunk)
-  {
-    sprintf(fn , "%s/sounds/%s", settings.default_data_path, datafile);
-    tempChunk = Mix_LoadWAV(fn);
-    return tempChunk;
-  }
-}
-
-
-/************************
-	LoadMusic : Load
-	music from a datafile
-*************************/
-Mix_Music* LoadMusic(const char* datafile )
-{ 
-  Mix_Music* temp_music = NULL;
-  char fn[FNLEN];
-
-  /* First look under theme path if desired: */
-  if (!settings.use_english)
-  {
-    sprintf(fn , "%s/sounds/%s", settings.theme_data_path, datafile);
-    temp_music = Mix_LoadMUS(fn);
-    if (temp_music)
-      return temp_music;
-  }
-
-  /* If nothing loaded yet, try default path: */
-  if (!temp_music)
-  {
-    sprintf(fn , "%s/sounds/%s", settings.default_data_path, datafile);
-    temp_music = Mix_LoadMUS(fn);
-    return temp_music;
-  }
-}

Deleted: tuxtype/branches/tuxtype-soc-mh/main.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/main.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/main.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,170 +0,0 @@
-/***************************************************************************
-                          main.c 
- -  description: main tux type file
-                             -------------------
-    begin                : Tue May  2 13:25:06 MST 2000
-    copyright            : (C) 2000 by Sam Hart
-                         : (C) 2003 by Jesse Andrews
-    email                : tuxtype-dev at tux4kids.net
- ***************************************************************************/
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-
-SDL_Surface* screen;
-
-
-SDL_Event  event;
-
-
-
-/********************
-  main : init stuff
-*********************/
-int main(int argc, char *argv[])
-{
-  Uint32 lib_flags = 0;
-  int i;
-
-  /* Initialize settings with hard-coded defaults: */ 
-  Opts_Initialize();
-  /* Put in preset highscores so there's something to compare */
-  hScores_Initialize();
-  profile_Initialize();
-
-  srand(time(NULL));
-
-  // This sets settings.default_data_path to the default theme file path:
-  SetupPaths(NULL);
-
-  LoadSettings();
-  DEBUGCODE { printf("Window setting from config file is: %d\n", settings.fullscreen);}
-
-  lib_flags = SDL_INIT_VIDEO;
-
-  /* FIXME this could go into something like HandleCommandArgs() */
-  // check command line args
-  if (argc > 1)
-  { 
-    for (i = 1; i < argc; i++)
-    {
-      if (  (strcmp(argv[i], "-h") == 0)
-         || (strcmp(argv[i], "--help") == 0)
-         || (strcmp(argv[i], "-help") == 0))
-      {
-        fprintf(stderr, "\nUsage:\n tuxtype [OPTION]...");
-        fprintf(stderr, "\n\nOptions:\n\n\t-h, --help, -help");
-        fprintf(stderr, "\n\t\tPrints this help message");
-        fprintf(stderr, "\n\n\t-f, --fullscreen");
-        fprintf(stderr, "\n\t\tSelects fullscreen display (default)");
-        fprintf(stderr, "\n\n\t-w, --window");
-        fprintf(stderr, "\n\t\tSelects windowed display (not fullscreen)");
-        fprintf(stderr, "\n\n\t-s, --sound");
-        fprintf(stderr, "\n\t\tAllow in-game sounds (default)");
-        fprintf(stderr, "\n\n\t-ns, --nosound");
-        fprintf(stderr, "\n\t\tDisables in-game sounds");
-        fprintf(stderr, "\n\n\t-t {THEME}, --theme {THEME}");
-        fprintf(stderr, "\n\t\tUse theme named {THEME}, if it exists");
-        fprintf(stderr, "\n\n\t-sp, --speed");
-        fprintf(stderr, "\n\t\tSpeed up gameplay (for use on slower");
-        fprintf(stderr, "\n\t\tmachines)");
-        fprintf(stderr, "\n\n\t-d, --debug");
-        fprintf(stderr, "\n\t\tEnable debug mode (output)\n");
-        fprintf(stderr, "\n\n\t-v, --version");
-        fprintf(stderr, "\n\t\tDisplay version number and exit\n");
-        exit(0);
-      }
-
-      if (  (strcmp(argv[i], "-v") == 0)
-         || (strcmp(argv[i], "--version") == 0))
-      {
-        fprintf(stderr, "\n%s, Version %s\n", PACKAGE, VERSION);
-        fprintf(stderr, "Copyright (C) Sam Hart <hart at geekcomix.com>, under the GPL\n");
-        fprintf(stderr, "-See COPYING file for more info... Thx ;)\n\n");
-        exit(0);
-      }
-
-      if (  (strcmp(argv[i], "-f") == 0)
-         || (strcmp(argv[i], "--fullscreen") == 0))
-        settings.fullscreen = 1;
-
-      if (  (strcmp(argv[i], "-w") == 0)
-         || (strcmp(argv[i], "--window") == 0))
-        settings.fullscreen = 0;
-
-      if (  (strcmp(argv[i], "-sp") == 0)
-         || (strcmp(argv[i], "--speed") == 0))
-        settings.speed_up = 1;
-
-      if (  (strcmp(argv[i], "-d") == 0)
-         || (strcmp(argv[i], "--debug") == 0))
-        settings.debug_on = 1;
-
-      if (  (strcmp(argv[i], "-s") == 0)
-         || (strcmp(argv[i], "--sound") == 0))
-        settings.sys_sound = 1;
-
-      if (  (strcmp(argv[i], "-ns") == 0)
-         || (strcmp(argv[i], "--nosound") == 0))
-        settings.sys_sound = 0;
-
-      if (  (strcmp(argv[i], "--hidden") == 0)
-         || (strcmp(argv[i], "-hidden") == 0))
-        settings.hidden = 1;
-
-      if (  (strcmp(argv[i], "-t") == 0)
-         || (strcmp(argv[i], "--theme") == 0))
-        SetupPaths(argv[++i]);
-    }
-  }
-
-  DEBUGCODE
-  {
-    fprintf(stderr, "\n%s, version %s BEGIN\n", PACKAGE, VERSION);
-  }
-
-  lib_flags |= SDL_INIT_AUDIO;
-
-  LibInit(lib_flags); /* calls SDL_Init(), TTF_Init(), some other settings */
-  GraphicsInit(); /* calls SDL_SetVideoMode(), a few others     */
-
-  #ifdef HAVE_LIBSDL_PANGO
-  init_SDLPango_Context();
-  #endif
-
-  if (settings.sys_sound)
-  {
-    Mix_VolumeMusic(settings.mus_volume);
-    Mix_Volume(-1, settings.sfx_volume);
-  }
-
-  /* FIXME: we should check config files/environment variables like LANG! */
-  LoadLang();
-  LoadKeyboard();
-  /* load highscores*/
-  load_highscores();
-
-  
-  /* Now actually play the game: */
-  TitleScreen();
-
-  /* save settings/profile/cores before exit */
-  SaveSettings();
-  saveProfile(activeProfile.profileNum);
-  saveHighScores();
-
-  /* Release heap: */
-  Cleanup();
-
-  LOG( "---GAME DONE, EXIT---- Thank you.\n" );
-
-  return EXIT_SUCCESS;
-}

Deleted: tuxtype/branches/tuxtype-soc-mh/options.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/options.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/options.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,93 +0,0 @@
-/***************************************************************************
- -  file: options.c
- -  description: Functions supporting settings struct for Tux Typing
-                             -------------------
-    begin                : Wed July 11 2007
-    copyright            : (C) 2000 by David Bruce
-                           dbruce at tampabay.rr.com
-
-    project email        : tuxmath-devel at sourceforge.net
-    website              : http://tux4kids.alioth.debian.org
-
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-
-/* Local function prototypes: */
-
-/* Global (for now) settings struct: */
-game_option_type settings;
-profiles activeProfile; //added globally since will be required globally
-highscores hscores;
-
-/* Simply stick all the default values into the settings struct: */
-void Opts_Initialize(void)
-{
-  strncpy(settings.theme_font_name, DEFAULT_MENU_FONT, FNLEN);
-  strncpy(settings.theme_locale_name, DEFAULT_LOCALE, FNLEN);
-  settings.use_english = DEFAULT_USE_ENGLISH;
-  settings.fullscreen = DEFAULT_FULLSCREEN;
-  settings.sys_sound = DEFAULT_SYS_SOUND;
-  settings.sfx_volume = DEFAULT_SFX_VOLUME;
-  settings.mus_volume = DEFAULT_MUS_VOLUME;
-  settings.menu_music = DEFAULT_MENU_MUSIC;
-  settings.menu_sound = DEFAULT_MENU_SOUND;
-  settings.speed_up = DEFAULT_SPEED_UP;
-  settings.show_tux4kids = DEFAULT_SHOW_TUX4KIDS;
-  settings.debug_on = DEFAULT_DEBUG_ON;
-  settings.o_lives = DEFAULT_O_LIVES;
-  settings.sound_vol = DEFAULT_SOUND_VOL;
-  settings.numProfiles = DEFAULT_PROFILES; //no profiles made yet, so default, which is 0
-  settings.hidden = DEFAULT_HIDDEN; 
-}
-
-void profile_Initialize(void) //first profile shouldn't have any scores...
-{
-	activeProfile.highscore1 	= 	0;
-	activeProfile.highscore2 	= 	0;
-	activeProfile.highscore3 	= 	0;
-	activeProfile.highscore4 	= 	0;
-	activeProfile.highscore5 	= 	0;
-	activeProfile.highscore6 	= 	0;
-	activeProfile.highscore7 	= 	0;
-	activeProfile.highscore8 	= 	0;
-	activeProfile.wpm_highest 	= 	0;
-	activeProfile.wpm_average 	= 	0;
-	activeProfile.wpm_slowest 	= 	0;
-	activeProfile.wpm_taken	 	=	0;
-}
-void hScores_Initialize(void)
-{
-	hscores.highscore1_name 	= DEFAULT_GNAME;
-	hscores.ghighscore1 		= DEFAULT_GHIGHSCORE1;
-	hscores.highscore2_name 	= DEFAULT_GNAME;
-	hscores.ghighscore2 		= DEFAULT_GHIGHSCORE2;
-	hscores.highscore3_name 	= DEFAULT_GNAME;
-	hscores.ghighscore3 		= DEFAULT_GHIGHSCORE3;
-	hscores.highscore4_name 	= DEFAULT_GNAME;
-	hscores.ghighscore4 		= DEFAULT_GHIGHSCORE4;
-	hscores.highscore5_name 	= DEFAULT_GNAME;
-	hscores.ghighscore5 		= DEFAULT_GHIGHSCORE5;
-	hscores.highscore6_name 	= DEFAULT_GNAME;
-	hscores.ghighscore6 		= DEFAULT_GHIGHSCORE6;
-	hscores.highscore7_name 	= DEFAULT_GNAME;
-	hscores.ghighscore7 		= DEFAULT_GHIGHSCORE7;
-	hscores.highscore8_name 	= DEFAULT_GNAME;
-	hscores.ghighscore8 		= DEFAULT_GHIGHSCORE8;
-	hscores.wpm_fastest_name 	= DEFAULT_GNAME;
-	hscores.wpm_fastest 		= DEFAULT_GWPM_FASTEST;
-	hscores.wpm_average_name 	= DEFAULT_GNAME;
-	hscores.wpm_average 		= DEFAULT_GWPM_AVERAGE;
-	hscores.wpm_slowest_name 	= DEFAULT_GNAME;
-	hscores.wpm_slowest 		= DEFAULT_GWPM_SLOWEST;
-}
\ No newline at end of file

Deleted: tuxtype/branches/tuxtype-soc-mh/pause.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/pause.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/pause.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,393 +0,0 @@
-/***************************************************************************
-pause.c 
--  description: pause screen for the games
--------------------
-begin                : Jan 22, 2003
-copyright            : (C) 2003 by Jesse Andrews
-email                : jdandr2 at uky.edu
-***************************************************************************/
-
-/***************************************************************************
-*                                                                         *
-*   This program is free software; you can redistribute it and/or modify  *
-*   it under the terms of the GNU General Public License as published by  *
-*   the Free Software Foundation; either version 2 of the License, or     *
-*   (at your option) any later version.                                   *
-*                                                                         *
-***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-#include "SDL_extras.h"
-
-static Mix_Chunk *pause_sfx = NULL;
-static SDL_Surface *up = NULL, *down = NULL, *left = NULL, *right = NULL;
-static SDL_Rect rectUp, rectDown, rectLeft, rectRight;
-static TTF_Font *f1 = NULL, *f2 = NULL;
-
-/* Local function prototypes: */
-//static void darkenscreen(void);
-static void draw_vols(int sfx, int mus);
-static void pause_draw(void);
-static void pause_load_media(void);
-static void pause_unload_media(void);
-
-// QUESTION: For usability sake, should escape return to the game
-//           and the user have to choose to quit the game, or ???
-/**********************
-Pause : Pause the game
-***********************/
-int Pause(void)
-{
-	int paused = 1;
-	int sfx_volume=0;
-	int old_sfx_volume;
-	int mus_volume=0;
-	int old_mus_volume;
-	int mousePressed = 0;
-	int quit=0;
-	int tocks=0;  // used for keeping track of when a tock has happened
-	SDL_Event event;
-
-	LOG( "Entering Pause()\n" );
-
-	pause_load_media();
-	/* --- stop all sounds, play pause noise --- */
-
-	if (settings.sys_sound) {
- 		Mix_Pause(-1);
-		Mix_PlayChannel(-1, pause_sfx, 0);
-		sfx_volume = Mix_Volume(-1, -1);  // get sfx volume w/o changing it
-		mus_volume = Mix_VolumeMusic(-1); // get mus volume w/o changing it
-	}
-
-	/* --- show the pause screen --- */
-
-	SDL_ShowCursor(1);
-
-	// Darken the screen...
-	DarkenScreen(1); 
-
-	pause_draw();
-
-	if (settings.sys_sound) {
-		draw_vols(sfx_volume, mus_volume);
-	}
-
-	SDL_Flip(screen);
-
-	SDL_EnableKeyRepeat( 1, 20 );
-
-	/* --- wait for space, click, or exit --- */
-
-	while (paused) {
-		old_sfx_volume = sfx_volume;
-		old_mus_volume = mus_volume;
-		while (SDL_PollEvent(&event)) 
-			switch (event.type) {
-				case SDL_QUIT: 
-					exit(0);
-					break;
-				case SDL_KEYUP:
-					if (settings.sys_sound && 
-					   ((event.key.keysym.sym == SDLK_RIGHT) ||
-					    (event.key.keysym.sym == SDLK_LEFT))) 
-					    	tocks = 0;
-					break;
-				case SDL_KEYDOWN:
-					if (event.key.keysym.sym == SDLK_SPACE) 
-						paused = 0;
-					if (event.key.keysym.sym == SDLK_ESCAPE) {
-						paused = 0;
-						quit = 1;
-					}
-					if (settings.sys_sound) { 
-						if (event.key.keysym.sym == SDLK_RIGHT) 
-							sfx_volume += 4;
-						if (event.key.keysym.sym == SDLK_LEFT) 
-							sfx_volume -= 4;
-						if (event.key.keysym.sym == SDLK_UP) 
-							mus_volume += 4;
-						if (event.key.keysym.sym == SDLK_DOWN) 
-							mus_volume -= 4;
-					}
-					break;
-				case SDL_MOUSEBUTTONDOWN:
-					mousePressed = 1;
-					tocks = 0;
-					break;
-				case SDL_MOUSEBUTTONUP:
-					mousePressed = 0;
-					break;
-
-					break;
-			}
-		if (settings.sys_sound && mousePressed) {
-			int x, y;
-
-			SDL_GetMouseState(&x, &y);
-			/* check to see if they clicked on a button */
-
-			if (inRect(rectUp, x, y)) {
-				mus_volume += 4;
-			} else if (inRect(rectDown, x, y)) {
-				mus_volume -= 4;
-			} else if (inRect(rectRight, x, y)) {
-				sfx_volume += 4;
-			} else if (inRect(rectLeft, x, y)) {
-				sfx_volume -= 4;
-			} else {
-
-				/* check to see if they clicked a bar */
-
-				if ((x > rectLeft.x + rectLeft.w) && (x < rectRight.x)) {
-					if ((y >= rectLeft.y) && (y <= rectLeft.y + rectLeft.h)) {
-						sfx_volume = 4+(int)(128.0 * ((x - rectLeft.x - rectLeft.w - 1.0) / (rectRight.x - rectLeft.x - rectLeft.w - 2.0)));
-					}
-					if ((y >= rectDown.y) && (y <= rectDown.y + rectDown.h)) {
-						mus_volume = 4+(int)(128.0 * ((x - rectLeft.x - rectLeft.w - 1.0) / (rectRight.x - rectLeft.x - rectLeft.w - 2.0)));
-					}
-
-				}
-			}
-		}
-
-		if (settings.sys_sound) {
-
-			if (sfx_volume > MIX_MAX_VOLUME)
-				sfx_volume = MIX_MAX_VOLUME;
-			if (sfx_volume < 0)
-				sfx_volume = 0;
-			if (mus_volume > MIX_MAX_VOLUME)
-				mus_volume = MIX_MAX_VOLUME;
-			if (mus_volume < 0)
-				mus_volume = 0;
-
-			if ((mus_volume != old_mus_volume) || 
-			    (sfx_volume != old_sfx_volume)) {
-
-				if (mus_volume != old_mus_volume)
-					Mix_VolumeMusic(mus_volume);
-
-				if (sfx_volume != old_sfx_volume) {
-					Mix_Volume(-1,sfx_volume);
-					if (tocks%4==0)
-						Mix_PlayChannel(-1, pause_sfx, 0);
-					tocks++;
-			    }
-
-				draw_vols(sfx_volume, mus_volume);
-				settings.mus_volume=mus_volume;
-				settings.sfx_volume=sfx_volume;
-				SDL_Flip(screen);
-			}
-		}
-
-		SDL_Delay(33);
-	}
-
-	/* --- Return to previous state --- */
-
-	SDL_EnableKeyRepeat( 0, SDL_DEFAULT_REPEAT_INTERVAL );
-
-	SDL_ShowCursor(0);
-
-	if (settings.sys_sound) {
-		Mix_PlayChannel(-1, pause_sfx, 0);
-		Mix_Resume(-1);
-	}
-
-	pause_unload_media();
-
-	LOG( "Leaving Pause()\n" );
-
-	return (quit);
-}
-
-
-static void pause_load_media(void) {
-	if (settings.sys_sound) 
-		pause_sfx = LoadSound( "tock.wav" );
-
-	up = LoadImage("up.png", IMG_ALPHA);
-	rectUp.w = up->w; rectUp.h = up->h;
-
-	down = LoadImage("down.png", IMG_ALPHA);
-	rectDown.w = down->w; rectDown.h = down->h;
-
-	left = LoadImage("left.png", IMG_ALPHA);
-	rectLeft.w = left->w; rectLeft.h = left->h;
-
-	right = LoadImage("right.png", IMG_ALPHA);
-	rectRight.w = right->w; rectRight.h = right->h;
-
-	f1 = LoadFont(settings.theme_font_name, 24);
-	f2 = LoadFont(settings.theme_font_name, 36);
-}
-
-static void pause_unload_media(void) {
-	if (settings.sys_sound)
-        {
-	  Mix_FreeChunk(pause_sfx);
-	  pause_sfx = NULL;
-        }
-	SDL_FreeSurface(up);
-	SDL_FreeSurface(down);
-	SDL_FreeSurface(left);
-	SDL_FreeSurface(right);
-        up = down = left = right = NULL;
-	TTF_CloseFont(f1);
-	TTF_CloseFont(f2);
-	f1 = f2 = NULL;
-}
-
-
-
-/******************************************/
-/*                                        */
-/*       Local ("private") functions      */
-/*                                        */
-/******************************************/
-
-
-
-static void pause_draw(void)
-{
-  SDL_Rect s;
-  SDL_Surface* t = NULL;
-
-  LOG("Entering pause_draw()\n");
-
-  rectLeft.y = rectRight.y = screen->h/2 - 40;
-  rectDown.y = rectUp.y = screen->h/2 + 60;
-
-  rectLeft.x = rectDown.x = screen->w/2 - (7*16) - rectLeft.w - 4;
-  rectRight.x = rectUp.x  = screen->w/2 + (7*16) + 4;
-
-  /* Avoid segfault if any needed SDL_Surfaces missing: */
-  if (settings.sys_sound
-    && left && right && down && up)
-  {
-    SDL_BlitSurface(left, NULL, screen, &rectLeft);
-    SDL_BlitSurface(right, NULL, screen, &rectRight);
-    SDL_BlitSurface(down, NULL, screen, &rectDown);
-    SDL_BlitSurface(up, NULL, screen, &rectUp);
-  }
-
-  if (settings.sys_sound)
-  {
-    t = BlackOutline(gettext("Sound Effects Volume"), f1, &white);
-    if (t)
-    {	
-      s.y = screen->h/2 - 80;
-      s.x = screen->w/2 - t->w/2;
-      SDL_BlitSurface(t, NULL, screen, &s);
-      SDL_FreeSurface(t);
-    }
-
-    t = BlackOutline(gettext("Music Volume"), f1, &white);
-    if (t)
-    {
-      s.y = screen->h/2 + 20;
-      s.x = screen->w/2 - t->w/2;
-      SDL_BlitSurface(t, NULL, screen, &s);
-      SDL_FreeSurface(t);
-    }
-  }
-  else  /* No sound: */
-  {
-    t = BlackOutline(gettext("Sound & Music Disabled"), f1, &white);
-    if (t)
-    {
-      s.y = screen->h/2 - 80;
-      s.x = screen->w/2 - t->w/2;
-      SDL_BlitSurface(t, NULL, screen, &s);
-      SDL_FreeSurface(t);
-    }
-  }
-
-  t = BlackOutline(gettext("Paused!"), f2, &white);
-  if (t)
-  {
-	s.y = screen->h/2 - 180; //60;
-	s.x = screen->w/2 - t->w/2;
-	SDL_BlitSurface(t, NULL, screen, &s);
-	SDL_FreeSurface(t);
-  }
-
-  t = BlackOutline(gettext("Press escape again to return to menu"), f1, &white);
-  if (t)
-  {
-    s.y = screen->h/2 + 160;
-    s.x = screen->w/2 - t->w/2;
-    SDL_BlitSurface(t, NULL, screen, &s);
-    SDL_FreeSurface(t);
-  }
-
-  t = BlackOutline(gettext("Press space bar to return to game"), f1, &white);
-  if (t)
-  {
-    s.y = screen->h/2 + 200;
-    s.x = screen->w/2 - t->w/2;
-    SDL_BlitSurface(t, NULL, screen, &s);
-    SDL_FreeSurface(t);
-  }
-
-  LOG("Leaving pause_draw()\n");
-}
-
-
-/* FIXME what if rectLeft and rectDown not initialized? - should be args */
-static void draw_vols(int sfx, int mus)
-{
-  SDL_Rect s,m;
-  int i;
-
-  s.y = rectLeft.y; 
-  m.y = rectDown.y;
-  m.w = s.w = 5;
-  s.x = rectLeft.x + rectLeft.w + 5;
-  m.x = rectDown.x + rectDown.w + 5;
-  m.h = s.h = 40;
-
-  for (i = 1; i<=32; i++)
-  {
-    if (sfx >= i * 4)
-      SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 127 + sfx));
-    else
-      SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 0));
-
-    if (mus >= i * 4)
-      SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 127 + mus));
-    else
-      SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 0));
-
-    m.x = s.x += 7;
-  }
-}
-
-// /* ==== fillscreen ====
-//  * RESULT: it will darken the screen by a factor of 4
-//  * WARNING: only works on 16bit screens right now!
-//  */
-// static void darkenscreen(void)
-// {
-//   Uint16 rm = screen->format->Rmask;
-//   Uint16 gm = screen->format->Gmask;
-//   Uint16 bm = screen->format->Bmask;
-//   Uint16* p; 
-//   int x, y;
-// 
-//   p = screen->pixels;
-// 
-//   for (y = 0; y < 480; y++) 
-//   {
-//     for (x = 0; x < 640; x++)
-//     {
-//       *p = (((*p&rm)>>2)&rm) | (((*p&gm)>>2)&gm) | (((*p&bm)>>2)&bm);
-//       p++;
-//     }
-//   }
-// }
-
-

Deleted: tuxtype/branches/tuxtype-soc-mh/phrases.txt
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/phrases.txt	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/phrases.txt	2008-08-26 07:28:53 UTC (rev 673)
@@ -1 +0,0 @@
-The quick brown fox jumps over the lazy dog.

Deleted: tuxtype/branches/tuxtype-soc-mh/pixels.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/pixels.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/pixels.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,257 +0,0 @@
-/*
-  pixels.c
-
-  For Tux Paint
-  Pixel read/write functions
-
-  Copyright (c) 2002-2006 by Bill Kendrick and others
-  bill at newbreedsoftware.com
-  http://www.newbreedsoftware.com/tuxpaint/
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-  (See COPYING.txt)
-
-  June 14, 2002 - February 17, 2006
-  $Id: pixels.c,v 1.3 2006/08/27 21:00:55 wkendrick Exp $
-*/
-
-#include "pixels.h"
-#include "compiler.h"
-//#include "debug.h"
-
-/* Draw a single pixel into the surface: */
-void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
-{
-  Uint8 *p;
-
-  /* Assuming the X/Y values are within the bounds of this surface... */
-  if (likely
-      (likely((unsigned) x < (unsigned) surface->w)
-       && likely((unsigned) y < (unsigned) surface->h)))
-  {
-    // Set a pointer to the exact location in memory of the pixel
-    p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start: beginning of RAM */
-                   (y * surface->pitch) +        /* Go down Y lines */
-                   x);                /* Go in X pixels */
-
-
-    /* Set the (correctly-sized) piece of data in the surface's RAM
-     *          to the pixel value sent in: */
-
-    *p = pixel;
-  }
-}
-
-/* Draw a single pixel into the surface: */
-void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
-{
-  Uint8 *p;
-
-  /* Assuming the X/Y values are within the bounds of this surface... */
-  if (likely
-      (likely((unsigned) x < (unsigned) surface->w)
-       && likely((unsigned) y < (unsigned) surface->h)))
-  {
-    // Set a pointer to the exact location in memory of the pixel
-    p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start: beginning of RAM */
-                   (y * surface->pitch) +        /* Go down Y lines */
-                   (x * 2));        /* Go in X pixels */
-
-
-    /* Set the (correctly-sized) piece of data in the surface's RAM
-     *          to the pixel value sent in: */
-
-    *(Uint16 *) p = pixel;
-  }
-}
-
-/* Draw a single pixel into the surface: */
-void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
-{
-  Uint8 *p;
-
-  /* Assuming the X/Y values are within the bounds of this surface... */
-  if (likely
-      (likely((unsigned) x < (unsigned) surface->w)
-       && likely((unsigned) y < (unsigned) surface->h)))
-  {
-    // Set a pointer to the exact location in memory of the pixel
-    p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start: beginning of RAM */
-                   (y * surface->pitch) +        /* Go down Y lines */
-                   (x * 3));        /* Go in X pixels */
-
-
-    /* Set the (correctly-sized) piece of data in the surface's RAM
-     *          to the pixel value sent in: */
-
-    if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
-    {
-      p[0] = (pixel >> 16) & 0xff;
-      p[1] = (pixel >> 8) & 0xff;
-      p[2] = pixel & 0xff;
-    }
-    else
-    {
-      p[0] = pixel & 0xff;
-      p[1] = (pixel >> 8) & 0xff;
-      p[2] = (pixel >> 16) & 0xff;
-    }
-
-  }
-}
-
-/* Draw a single pixel into the surface: */
-void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
-{
-  Uint8 *p;
-
-  /* Assuming the X/Y values are within the bounds of this surface... */
-  if (likely
-      (likely((unsigned) x < (unsigned) surface->w)
-       && likely((unsigned) y < (unsigned) surface->h)))
-  {
-    // Set a pointer to the exact location in memory of the pixel
-    p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start: beginning of RAM */
-                   (y * surface->pitch) +        /* Go down Y lines */
-                   (x * 4));        /* Go in X pixels */
-
-
-    /* Set the (correctly-sized) piece of data in the surface's RAM
-     *          to the pixel value sent in: */
-
-    *(Uint32 *) p = pixel;        // 32-bit display
-  }
-}
-
-/* Get a pixel: */
-Uint32 getpixel8(SDL_Surface * surface, int x, int y)
-{
-  Uint8 *p;
-
-  /* get the X/Y values within the bounds of this surface */
-  if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
-    x = (x < 0) ? 0 : surface->w - 1;
-  if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
-    y = (y < 0) ? 0 : surface->h - 1;
-
-  /* Set a pointer to the exact location in memory of the pixel
-     in question: */
-
-  p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start at top of RAM */
-                 (y * surface->pitch) +        /* Go down Y lines */
-                 x);                /* Go in X pixels */
-
-
-  /* Return the correctly-sized piece of data containing the
-   * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
-   * RGB value) */
-
-  return (*p);
-}
-
-/* Get a pixel: */
-Uint32 getpixel16(SDL_Surface * surface, int x, int y)
-{
-  Uint8 *p;
-
-  /* get the X/Y values within the bounds of this surface */
-  if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
-    x = (x < 0) ? 0 : surface->w - 1;
-  if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
-    y = (y < 0) ? 0 : surface->h - 1;
-
-  /* Set a pointer to the exact location in memory of the pixel
-     in question: */
-
-  p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start at top of RAM */
-                 (y * surface->pitch) +        /* Go down Y lines */
-                 (x * 2));        /* Go in X pixels */
-
-
-  /* Return the correctly-sized piece of data containing the
-   * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
-   * RGB value) */
-
-  return (*(Uint16 *) p);
-}
-
-/* Get a pixel: */
-Uint32 getpixel24(SDL_Surface * surface, int x, int y)
-{
-  Uint8 *p;
-  Uint32 pixel;
-
-  /* get the X/Y values within the bounds of this surface */
-  if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
-    x = (x < 0) ? 0 : surface->w - 1;
-  if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
-    y = (y < 0) ? 0 : surface->h - 1;
-
-  /* Set a pointer to the exact location in memory of the pixel
-     in question: */
-
-  p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start at top of RAM */
-                 (y * surface->pitch) +        /* Go down Y lines */
-                 (x * 3));        /* Go in X pixels */
-
-
-  /* Return the correctly-sized piece of data containing the
-   * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
-   * RGB value) */
-
-  /* Depending on the byte-order, it could be stored RGB or BGR! */
-
-  if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
-    pixel = p[0] << 16 | p[1] << 8 | p[2];
-  else
-    pixel = p[0] | p[1] << 8 | p[2] << 16;
-
-  return pixel;
-}
-
-/* Get a pixel: */
-Uint32 getpixel32(SDL_Surface * surface, int x, int y)
-{
-  Uint8 *p;
-
-  /* get the X/Y values within the bounds of this surface */
-  if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
-    x = (x < 0) ? 0 : surface->w - 1;
-  if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
-    y = (y < 0) ? 0 : surface->h - 1;
-
-  /* Set a pointer to the exact location in memory of the pixel
-     in question: */
-
-  p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start at top of RAM */
-                 (y * surface->pitch) +        /* Go down Y lines */
-                 (x * 4));        /* Go in X pixels */
-
-
-  /* Return the correctly-sized piece of data containing the
-   * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
-   * RGB value) */
-
-  return *(Uint32 *) p;                // 32-bit display
-}
-
-void (*putpixels[]) (SDL_Surface *, int, int, Uint32) =
-{
-putpixel8, putpixel8, putpixel16, putpixel24, putpixel32};
-
-
-Uint32(*getpixels[])(SDL_Surface *, int, int) =
-{
-getpixel8, getpixel8, getpixel16, getpixel24, getpixel32};

Deleted: tuxtype/branches/tuxtype-soc-mh/pixels.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/pixels.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/pixels.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,49 +0,0 @@
-/*
-  pixels.h
-
-  For Tux Paint
-  Pixel read/write functions
-
-  Copyright (c) 2002-2006 by Bill Kendrick and others
-  bill at newbreedsoftware.com
-  http://www.newbreedsoftware.com/tuxpaint/
-
-  This program is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published by
-  the Free Software Foundation; either version 2 of the License, or
-  (at your option) any later version.
-
-  This program is distributed in the hope that it will be useful,
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-  GNU General Public License for more details.
-
-  You should have received a copy of the GNU General Public License
-  along with this program; if not, write to the Free Software
-  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-  (See COPYING.txt)
-
-  June 14, 2002 - February 17, 2006
-  $Id: pixels.h,v 1.2 2006/08/27 21:00:55 wkendrick Exp $
-*/
-
-#ifndef PIXELS_H
-#define PIXELS_H
-
-#include "SDL.h"
-
-void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel);
-void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel);
-void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel);
-void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel);
-
-extern void (*putpixels[]) (SDL_Surface *, int, int, Uint32);
-
-Uint32 getpixel8(SDL_Surface * surface, int x, int y);
-Uint32 getpixel16(SDL_Surface * surface, int x, int y);
-Uint32 getpixel24(SDL_Surface * surface, int x, int y);
-Uint32 getpixel32(SDL_Surface * surface, int x, int y);
-
-extern Uint32(*getpixels[]) (SDL_Surface *, int, int);
-
-#endif

Deleted: tuxtype/branches/tuxtype-soc-mh/playgame.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/playgame.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/playgame.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,1808 +0,0 @@
-/***************************************************************************
-playgame.c 
--  description: Cascade game
--------------------
-begin                : Fri May 5 2000
-copyright            : (C) 2000 by Sam Hart
-                     : (C) 2003 by Jesse Andrews
-email                : tuxtype-dev at tux4kids.net
-***************************************************************************/
-
-/***************************************************************************
-*                                                                         *
-*   This program is free software; you can redistribute it and/or modify  *
-*   it under the terms of the GNU General Public License as published by  *
-*   the Free Software Foundation; either version 2 of the License, or     *
-*   (at your option) any later version.                                   *
-*                                                                         *
-***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-#include "playgame.h"
-#include "snow.h"
-#include "SDL_extras.h"
-
-#define _(String) gettext(String)
-
-//void add_words( int level );
-
-/* Should these be constants? */
-static int tux_max_width;                // the max width of the images of tux
-static int number_max_w;                 // the max width of a number image
-
-//int o_lives; // something cal is working on
-//int sound_vol;
-static TTF_Font* font = NULL;
-//static SDL_Surface* background = NULL;
-static SDL_Surface* level[NUM_LEVELS] = {NULL};
-static SDL_Surface* number[NUM_NUMS] = {NULL};
-static SDL_Surface* curlev = NULL;
-static SDL_Surface* lives = NULL;
-static SDL_Surface* fish = NULL;
-static SDL_Surface* congrats[CONGRATS_FRAMES] = {NULL};
-static SDL_Surface* ohno[OH_NO_FRAMES] = {NULL};
-static Mix_Chunk* sound[NUM_WAVES];
-
-static sprite* fishy = NULL;
-static sprite* splat = NULL;
-
-/* --- Data Structure for Dirty Blitting --- */
-static SDL_Rect srcupdate[MAX_UPDATES];
-static SDL_Rect dstupdate[MAX_UPDATES];
-static int numupdates = 0; // tracks how many blits to be done
-
-struct blit {
-    SDL_Surface* src;
-    SDL_Rect* srcrect;
-    SDL_Rect* dstrect;
-    unsigned char type;
-} blits[MAX_UPDATES];
-
-
-
-/* Local function prototypes: */
-static int AddRect(SDL_Rect* src, SDL_Rect* dst);
-static void AddSplat(int* splats, struct fishypoo* f, int* curlives, int* frame);
-static void CheckCollision(int fishies, int* fish_left, int frame );
-static void CheckFishies(int* fishies, int* splats);
-static int check_word(int f);
-static void display_msg(const unsigned char* msg, int x, int y);
-static void DrawBackground(void);
-static void draw_bar(int curlevel, int diflevel, int curlives,
-                     int oldlives, int fish_left, int oldfish_left);
-static void DrawFish(int which);
-static void DrawNumbers(int num, int x, int y, int places);
-static int DrawObject(SDL_Surface* surf, int x, int y);
-static int DrawSprite(sprite* gfx, int x, int y);
-static void EraseNumbers(int num, int x, int y, int places);
-static int EraseObject(SDL_Surface* surf, int x, int y);
-static int EraseSprite(sprite* img, int x, int y);
-static float float_restrict(float a, float x, float b);
-static void FreeGame(void);
-static int int_restrict(int a, int x, int b);
-static void LoadFishies(void);
-static void LoadOthers(void);
-static void LoadTuxAnims(void);
-static void MoveFishies(int* fishies, int* splats, int* lifes, int* frame);
-static void MoveTux(int frame, int fishies);
-static void next_tux_frame(void);
-static void ResetObjects(void);
-static void SpawnFishies(int diflevel, int* fishies, int* frame);
-static void UpdateScreen(int* frame);
-static void UpdateTux(wchar_t letter_pressed, int fishies, int frame);
-static void WaitFrame(void);
-
-
-
-/************************************************************************/
-/*                                                                      */ 
-/*         "Public" functions (callable throughout program)             */
-/*                                                                      */
-/************************************************************************/
-
-/*************************************************************************
-* PlayCascade : This is the main Cascade game loop               *
-*************************************************************************/
-int PlayCascade(int diflevel)
-{
-  unsigned char filename[FNLEN];
-  int still_playing = 1;
-  int playing_level = 1;
-  int setup_new_level = 1;
-  int won_level = 0;
-  int quitting = 0;
-  int curlevel = 0;
-  int i;
-  int curlives;
-  int oldlives = 0;
-  int oldfish_left = 0;
-  int fish_left;
-  int fishies = 0;
-  int local_max_fishies = 1;
-  int frame = 0;
-  int done_frames;
-  int splats = 0;
-  SDL_Event event;
-  SDL_Surface *temp_text[CONGRATS_FRAMES + OH_NO_FRAMES];
-  SDL_Rect text_rect;
-  int text_y_end;
-  int xamp;
-  int yamp;
-  int x_not;
-  int y_not;
-  int temp_text_frames;
-  int temp_text_count;
-  Uint16 key_unicode;
-
-  DEBUGCODE
-  {
-    fprintf(stderr, "->Entering PlayCascade(): level=%i\n", diflevel);
-  }
-
-  SDL_WarpMouse(screen->w / 2, screen->h / 2);
-  SDL_ShowCursor(0);
-
-//	SNOW_init();
-
-  LoadTuxAnims(); 
-  LoadFishies();
-  LoadOthers();
-  RenderLetters(font);
-  LOG( " Done rendering letters \n ");
-
-  /* Make sure everything in the word list is "typable" according to the current */
-  /* theme's keyboard.lst:                                                       */
-  if (!CheckNeededGlyphs())
-  {
-    fprintf(stderr, "PlayCascade() - did not find all needed characters in theme's "
-                    "keyboard.lst file - returning to menu!\n\n\n");
-    FreeGame();
-    return 0;
-  }
-
-
-  /*  --------- Begin outer game loop (cycles once per level): ------------- */
-
-  LOG( " starting game \n ");
-
-  while (still_playing)
-  {
-    /* FIXME split out as smaller function */
-    if (setup_new_level) 
-    {
-      switch (diflevel)
-      {
-        default:
-        case EASY:
-          fish_left = MAX_FISHIES_EASY;
-
-          if (settings.o_lives >  LIVES_INIT_EASY)
-            curlives = settings.o_lives;
-          else
-            curlives = LIVES_INIT_EASY;
-          break;
-
-        case MEDIUM:
-          fish_left = MAX_FISHIES_MEDIUM;
-
-          if (settings.o_lives >  LIVES_INIT_MEDIUM)
-            curlives = settings.o_lives;
-          else
-            curlives =  LIVES_INIT_MEDIUM;
-          break;
-
-        case HARD:
-          fish_left = MAX_FISHIES_HARD;
-
-          if (settings.o_lives >  LIVES_INIT_HARD)
-            curlives = settings.o_lives;
-          else
-            curlives =  LIVES_INIT_HARD;
-          break;
-      }
-
-      local_max_fishies = fish_left;
-
-      /* ------- Load and draw background: ----------------- */
-
-      if (curlevel != 0)
-      {
-        FreeBothBkgds();
-        //SDL_FreeSurface(background);
-      }
-
-      if (diflevel == INF_PRACT)
-        sprintf(filename, "pract.png");
-      else
-        sprintf(filename, "kcas%i_%i.jpg", diflevel+1, curlevel+1);
-
-      /* ---  Special Hidden Code  --- */
-
-      if (settings.hidden && curlevel == 3)
-        sprintf(filename, "hidden.jpg");
-
-      DEBUGCODE
-      {
-        fprintf(stderr, "->>Loading background: %s\n", filename);
-      }
-        LoadBothBkgds(filename);
-//      background = LoadImage( filename, IMG_REGULAR );
-//			SNOW_setBkg( background );
-
-      DrawBackground();
-
-      ResetObjects();
-
-      if (settings.sys_sound)
-      {
-        sprintf(filename, "kmus%i.wav", curlevel + 1);
-        MusicLoad( filename, -1 );
-      }
-
-      setup_new_level = 0;
-
-      LOG( "->>PLAYING THE GAME\n" );
-
-    }
-
-    /*  --------- Begin main game loop (cycles once per frame): ------------- */
-
-
-    while (playing_level)
-    {
-      oldlives = curlives;
-      oldfish_left = fish_left;
-
-      EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
-
-      /* --- Poll input queue, get keyboard info --- */
-      while (SDL_PollEvent(&event))
-      {
-        if ( event.type == SDL_QUIT )
-        {
-          exit(0); /* FIXME does memory get cleaned up properly if we do this? */
-        }
-        else
-        {
-          if (event.type == SDL_KEYDOWN)
-          {
-            if (event.key.keysym.sym == SDLK_F11) 
-              SDL_SaveBMP(screen, "screenshot.bmp");
-
-            if (event.key.keysym.sym == SDLK_F6)
-            {
-              settings.o_lives = settings.o_lives - 10;
-              curlives = curlives - 10;
-            }
-
-            if (event.key.keysym.sym == SDLK_F7)
-            {
-              settings.o_lives = settings.o_lives + 10;
-              curlives = curlives + 10;
-            }
-
-            if (event.key.keysym.sym == SDLK_F10)
-              SwitchScreenMode();
-
-            if (event.key.keysym.sym == SDLK_F12)
-            {
-//              SNOW_toggle();
-            }
-
-            if (event.key.keysym.sym == SDLK_ESCAPE)
-            {
-              /* Pause() returns 1 if quitting, */
-              /* 0 if returning to game:        */
-              if (Pause() == 1)
-              {
-                playing_level = 0;
-                still_playing = 0;
-                quitting = 1;
-              }
-              else  /* Returning to game */
-                DrawBackground();
-            }
-
-            /*----------------------------------------------------*/
-            /* Some other key - player is actually typing!!!!!!!! */
-            /*----------------------------------------------------*/
-
-            /* See what Unicode value was typed: */
-            key_unicode = event.key.keysym.unicode;
-
-            DEBUGCODE
-            {
-              fprintf(stderr,
-                      "\nkey_unicode = %d\twchar_t = %lc\t\n",
-                      key_unicode, key_unicode);
-            }
-
-            /* For now, the cascade game is case-insensitive for input, */
-            /* with only uppercase for answers:                         */
-            if (key_unicode >= 97 && key_unicode <= 122)
-              key_unicode -= 32;  //convert lowercase to uppercase
-            if (key_unicode >= 224 && key_unicode <= 255)
-              key_unicode -= 32; //same for non-US chars
-
-            LOG ("After checking for lower case:\n");
-            DEBUGCODE
-            {
-              fprintf(stderr,
-                      "key_unicode = %d\twchar_t = %lc\\n\n",
-                      key_unicode, key_unicode);
-            }
-
-            /* Now update with case-folded value: */
-            UpdateTux(key_unicode, fishies, frame);
-          }
-        }
-      }   /* ------ End of 'while' loop for handling user input ------- */
-
-
-
-      /* --- fishy updates --- */
-      if ((frame % 10) == 0)
-        NEXT_FRAME(fishy);
-
-      if (fishies < local_max_fishies)
-        SpawnFishies( diflevel, &fishies, &frame );
-
-      MoveTux(frame, fishies);
-      CheckCollision(fishies, &fish_left, frame);
-      DrawSprite(tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y);
-      MoveFishies(&fishies, &splats, &curlives, &frame);
-      CheckFishies(&fishies, &splats);
-//      SNOW_update();
-
-      /* --- update top score/info bar --- */
-
-      if (diflevel != INF_PRACT)
-      {
-        draw_bar(curlevel, diflevel, curlives, oldlives, fish_left, oldfish_left);
-
-        if (curlives <= 0)
-        {
-          playing_level = 0;
-          still_playing = 0;
-        }
-      }
-      else
-        fish_left = 1; // in practice there is always 1 fish left!
-
-      if (fish_left <= 0)
-      {
-        won_level = 1;
-        playing_level = 0;
-        curlevel++;
-        setup_new_level = 1;
-        still_playing = 1;
-      }
-
-      if (!quitting) 
-      {
-        /* This does all the blits that we have queued up this frame: */
-        UpdateScreen(&frame);
-
-        if (!settings.speed_up)
-          WaitFrame();
-      }
-    }  /* End per-frame game loop - level completed */
-
-
-    if (settings.sys_sound)
-      Mix_FadeOutMusic(MUSIC_FADE_OUT_MS);
-
-    DrawBackground();
-
-    /* Victory sequence, defeat sequence, or go to next level: */
-    if (quitting == 0)
-    {
-      /* Level completed successfully: */
-      if (won_level) 
-      {
-        if (curlevel < 4)  /* Advance to next level */
-        {
-          LOG( "--->NEXT LEVEL!\n" );
-          done_frames = MAX_END_FRAMES_BETWEEN_LEVELS;
-          playing_level = 1;
-          xamp = 0;
-          yamp = 0;
-          won_level = 0;
-        }
-        else
-        {
-          LOG( "--->WINNER!\n" );
-          done_frames = MAX_END_FRAMES_WIN_GAME;
-          still_playing = 0;
-          xamp = WIN_GAME_XAMP;
-          yamp = WIN_GAME_YAMP;
-
-          if (settings.sys_sound) 
-            Mix_PlayChannel(WINFINAL_WAV, sound[WINFINAL_WAV], 0);
-        }
-
-        if (settings.sys_sound) 
-          Mix_PlayChannel(WIN_WAV, sound[WIN_WAV], 0);
-
-        for (i = 0; i < CONGRATS_FRAMES; i++)
-          temp_text[i] = congrats[i];
-
-        temp_text_frames = CONGRATS_FRAMES;
-        tux_object.state = TUX_WINNING;
-
-      }
-      else  /* Did not win the level  :-(     */
-      {
-        LOG( "--->LOST :(\n" );
-        done_frames = MAX_END_FRAMES_GAMEOVER;
-        xamp = 0;
-        yamp = 0;
-
-        if (settings.sys_sound)
-          Mix_PlayChannel(LOSE_WAV, sound[LOSE_WAV], 0);
-
-        for (i = 0; i < OH_NO_FRAMES; i++)
-          temp_text[i] = ohno[i];
-
-        temp_text_frames = OH_NO_FRAMES;
-        tux_object.state = TUX_YIPING;
-      }
-
-      /* --- draw the animation here --- */
-
-      temp_text_count = 0;
-      text_y_end = (screen->h / 2) - (temp_text[0]->h / 2);
-      text_rect.x = (screen->w / 2) - (temp_text[0]->w / 2);
-      text_rect.y = screen->h - temp_text[0]->h - 1;
-      x_not = text_rect.x;
-
-      LOG( "--->Starting Ending Animation\n" );
-
-      for ( i=0; i<= done_frames; i++ ) 
-      {
-        temp_text_count = (temp_text_count+1) % temp_text_frames;
-
-        text_rect.y -= END_FRAME_DY;
-        y_not = text_rect.y;
-
-        if (text_rect.y < text_y_end)
-        {
-          y_not = text_y_end + yamp * sin(i / WIN_GAME_ANGLE_MULT);
-          text_rect.y = text_y_end;
-          text_rect.x = x_not + xamp * cos(i / WIN_GAME_ANGLE_MULT);
-        }
-
-        DrawSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
-        DrawObject(temp_text[temp_text_count], text_rect.x, y_not);
-        DrawObject(level[diflevel], 1, 1);
-        draw_bar(curlevel - 1, diflevel, curlives, oldlives, fish_left, oldfish_left);
-
-        next_tux_frame();
-//        SNOW_update();
-        /* Do all pending blits and increment frame counter: */
-        UpdateScreen(&frame);
-
-        EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
-        EraseObject(temp_text[temp_text_count], text_rect.x, y_not);
-
-        if (!settings.speed_up)
-          WaitFrame();
-      }  /* End of animation for end of game */
-
-    }  /* End of post-level wrap-up  */
-
-  }  /*   -------- End outer game loop -------------- */
-
-//  SNOW_on = 0;
-
-  LOG( "->Done with level... cleaning up\n" );
-
-  FreeGame();
-
-  LOG( "->PlayCascade(): END\n" );
-
-  return 1;
-}
-
-
-
-
-/***********************
- InitEngine
- ***********************/
-void InitEngine(void) {
-    int i;
-
-    /* --- Set up the update rectangle pointers --- */
-	
-    for (i = 0; i < MAX_UPDATES; ++i) {
-        blits[i].srcrect = &srcupdate[i];
-        blits[i].dstrect = &dstupdate[i];
-    }
-}
-
-
-
-/*************************************************/
-/* TransWipe: Performs various wipes to new bkgs */
-/*************************************************/
-/*
- * Given a wipe request type, and any variables
- * that wipe requires, will perform a wipe from
- * the current screen image to a new one.
- */
-int TransWipe(SDL_Surface* newbkg, int type, int var1, int var2)
-{
-    int i, j, x1, x2, y1, y2;
-    int step1, step2, step3, step4;
-    int frame;
-    SDL_Rect src;
-    SDL_Rect dst;
-
-    LOG("->TransWipe(): START\n");
-
-    if (!newbkg)
-    {
-      fprintf(stderr, "TransWipe() - 'newbkg' arg invalid!\n");
-      return 0;
-    }
-
-    numupdates = 0;
-    frame = 0;
-
-    if(newbkg->w == screen->w && newbkg->h == screen->h) {
-        if( type == RANDOM_WIPE )
-            type = (RANDOM_WIPE * ((float) rand()) / (RAND_MAX+1.0));
-
-        switch( type ) {
-            case WIPE_BLINDS_VERT: {
-                LOG("--+ Doing 'WIPE_BLINDS_VERT'\n");
-                /* var1 is num of divisions
-                   var2 is how many frames animation should take */
-                if( var1 < 1 ) var1 = 1;
-                if( var2 < 1 ) var2 = 1;
-                step1 = screen->w / var1;
-                step2 = step1 / var2;
-
-                for(i = 0; i <= var2; i++) {
-                    for(j = 0; j <= var1; j++) {
-                        x1 = step1 * (j - 0.5) - i * step2 + 1;
-                        x2 = step1 * (j - 0.5) + i * step2 + 1;
-                        src.x = x1;
-                        src.y = 0;
-                        src.w = step2;
-                        src.h = screen->h;
-                        dst.x = x2;
-                        dst.y = 0;
-                        dst.w = step2;
-                        dst.h = screen->h;
-                        SDL_BlitSurface(newbkg, &src, screen, &src);
-                        SDL_BlitSurface(newbkg, &dst, screen, &dst);
-                        AddRect(&src, &src);
-                        AddRect(&dst, &dst);
-                    }
-                    UpdateScreen(&frame);
-                }
-
-                src.x = 0;
-                src.y = 0;
-                src.w = screen->w;
-                src.h = screen->h;
-                SDL_BlitSurface(newbkg, NULL, screen, &src);
-                SDL_Flip(screen);
-
-                break;
-            } case WIPE_BLINDS_HORIZ: {
-                LOG("--+ Doing 'WIPE_BLINDS_HORIZ'\n");
-                /* var1 is num of divisions
-                   var2 is how many frames animation should take */
-                if( var1 < 1 ) var1 = 1;
-                if( var2 < 1 ) var2 = 1;
-                step1 = screen->h / var1;
-                step2 = step1 / var2;
-
-                for(i = 0; i <= var2; i++) {
-                    for(j = 0; j <= var1; j++) {
-                        y1 = step1 * (j - 0.5) - i * step2 + 1;
-                        y2 = step1 * (j - 0.5) + i * step2 + 1;
-                        src.x = 0;
-                        src.y = y1;
-                        src.w = screen->w;
-                        src.h = step2;
-                        dst.x = 0;
-                        dst.y = y2;
-                        dst.w = screen->w;
-                        dst.h = step2;
-                        SDL_BlitSurface(newbkg, &src, screen, &src);
-                        SDL_BlitSurface(newbkg, &dst, screen, &dst);
-                        AddRect(&src, &src);
-                        AddRect(&dst, &dst);
-                    }
-                    UpdateScreen(&frame);
-                }
-
-                src.x = 0;
-                src.y = 0;
-                src.w = screen->w;
-                src.h = screen->h;
-                SDL_BlitSurface(newbkg, NULL, screen, &src);
-                SDL_Flip(screen);
-
-                break;
-            } case WIPE_BLINDS_BOX: {
-                LOG("--+ Doing 'WIPE_BLINDS_BOX'\n");
-                /* var1 is num of divisions
-                   var2 is how many frames animation should take */
-                if( var1 < 1 ) var1 = 1;
-                if( var2 < 1 ) var2 = 1;
-                step1 = screen->w / var1;
-                step2 = step1 / var2;
-                step3 = screen->h / var1;
-                step4 = step1 / var2;
-
-                for(i = 0; i <= var2; i++) {
-                    for(j = 0; j <= var1; j++) {
-                        x1 = step1 * (j - 0.5) - i * step2 + 1;
-                        x2 = step1 * (j - 0.5) + i * step2 + 1;
-                        src.x = x1;
-                        src.y = 0;
-                        src.w = step2;
-                        src.h = screen->h;
-                        dst.x = x2;
-                        dst.y = 0;
-                        dst.w = step2;
-                        dst.h = screen->h;
-                        SDL_BlitSurface(newbkg, &src, screen, &src);
-                        SDL_BlitSurface(newbkg, &dst, screen, &dst);
-                        AddRect(&src, &src);
-                        AddRect(&dst, &dst);
-                        y1 = step3 * (j - 0.5) - i * step4 + 1;
-                        y2 = step3 * (j - 0.5) + i * step4 + 1;
-                        src.x = 0;
-                        src.y = y1;
-                        src.w = screen->w;
-                        src.h = step4;
-                        dst.x = 0;
-                        dst.y = y2;
-                        dst.w = screen->w;
-                        dst.h = step4;
-                        SDL_BlitSurface(newbkg, &src, screen, &src);
-                        SDL_BlitSurface(newbkg, &dst, screen, &dst);
-                        AddRect(&src, &src);
-                        AddRect(&dst, &dst);
-                    }
-                    UpdateScreen(&frame);
-                }
-
-                src.x = 0;
-                src.y = 0;
-                src.w = screen->w;
-                src.h = screen->h;
-                SDL_BlitSurface(newbkg, NULL, screen, &src);
-                SDL_Flip(screen);
-
-                break;
-            } default:
-                break;
-        }
-    }
-    return 1;
-}
-
-
-
-/************************************************************************/
-/*                                                                      */ 
-/*         "Private" functions (local to playgame.c)                    */
-/*                                                                      */
-/************************************************************************/
-
-
-
-static int check_word( int f ) {
-	int i;
-
-	if (wcslen(fish_object[f].word) > tux_object.wordlen) 
-		return 0;
-
-	for (i=0; i < wcslen(fish_object[f].word); i++) 
-		if (fish_object[f].word[i] != tux_object.word[tux_object.wordlen -                                           wcslen(fish_object[f].word) + i])
-			return 0;
-
-	return 1;
-}
-
-
-
-
-
-
-
-
-
-
-/***************************************
-	WaitFrame: wait for the next frame
-***************************************/
-void WaitFrame(void) {
-	static Uint32  next_tick = 0;
-	Uint32         this_tick = SDL_GetTicks();
-
-	if (this_tick < next_tick)
-		SDL_Delay(next_tick - this_tick);
-
-	next_tick = this_tick + (1000 / FRAMES_PER_SEC);
-}
-
-
-/****************************************************
- ResetObjects : Clear and reset all objects to dead
-****************************************************/
-
-static void ResetObjects(void)
-{
-  int i;
-
-  LOG("RESETTING OBJECTS\n");
-
-  for (i = 0; i < MAX_FISHIES_HARD + 1; i++)
-  {
-    fish_object[i] = null_fishy;
-    splat_object[i] = null_splat;
-  }
-
-  tux_object.facing = RIGHT;
-  tux_object.x = screen->w/2;
-  tux_object.y = screen->h - tux_object.spr[0][RIGHT]->frame[0]->h - 1;
-  tux_object.dx = 0;
-  tux_object.dy = 0;
-  tux_object.endx = tux_object.x;
-  tux_object.endy = tux_object.y;
-  tux_object.state = TUX_STANDING;
-  tux_object.word[0] = 0;
-  tux_object.wordlen = 0;
-
-  LOG( "OBJECTS RESET\n" );
-}
-
-
-static int DrawSprite(sprite* gfx, int x, int y)
-{
-  struct blit* update;
-
-  if (!gfx)
-  {
-    fprintf(stderr, "DrawSprite() - 'gfx' arg invalid!\n");
-    return 0;
-  }
-
-  update = &blits[numupdates++];
-
-  if(!update || !update->srcrect || !update->dstrect)
-  {
-    fprintf(stderr, "DrawSprite() - 'update' ptr invalid!\n");
-    return 0;
-  }
-
-  update->src = gfx->frame[gfx->cur];
-  update->srcrect->x = 0;
-  update->srcrect->y = 0;
-  update->srcrect->w = gfx->frame[gfx->cur]->w;
-  update->srcrect->h = gfx->frame[gfx->cur]->h;
-  update->dstrect->x = x;
-  update->dstrect->y = y;
-  update->dstrect->w = gfx->frame[gfx->cur]->w;
-  update->dstrect->h = gfx->frame[gfx->cur]->h;
-  update->type = 'D';
-
-  return 1;
-}
-
-/**********************
-DrawObject : Draw an object at the specified
-location. No respect to clipping!
-*************************/
-static int DrawObject(SDL_Surface* surf, int x, int y)
-{
-  struct blit *update;
-
-  if (!surf)
-  {
-    fprintf(stderr, "DrawObject() - invalid 'surf' arg!\n");
-    return 0;
-  }
-
-  update = &blits[numupdates++];
-
-  if(!update || !update->srcrect || !update->dstrect)
-  {
-    fprintf(stderr, "DrawObject() - 'update' ptr invalid!\n");
-    return 0;
-  }
-
-  update->src = surf;
-  update->srcrect->x = 0;
-  update->srcrect->y = 0;
-  update->srcrect->w = surf->w;
-  update->srcrect->h = surf->h;
-  update->dstrect->x = x;
-  update->dstrect->y = y;
-  update->dstrect->w = surf->w;
-  update->dstrect->h = surf->h;
-  update->type = 'D';
-
-  return 1;
-}
-
-/************************
-UpdateScreen : Update the screen and increment the frame num
-***************************/
-static void UpdateScreen(int* frame)
-{
-  int i;
-
-  LOG("Entering UpdateScreen()\n");
-
-  /* -- First erase everything we need to -- */
-  for (i = 0; i < numupdates; i++)
-  {
-    if (blits[i].type == 'E') 
-      SDL_LowerBlit(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
-  }
-
-  LOG("Done erasing\n");
-
-//  SNOW_erase();
-
-  /* -- then draw -- */ 
-  for (i = 0; i < numupdates; i++)
-  {
-    if (blits[i].type == 'D') 
-      SDL_BlitSurface(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
-  }
-
-  LOG("Done drawing\n");
-
-//  SNOW_draw();
-
-  /* -- update the screen only where we need to! -- */
-//  if (SNOW_on) 
-//    SDL_UpdateRects(screen, SNOW_add( (SDL_Rect*)&dstupdate, numupdates ), SNOW_rects);
-//  else 
-//    SDL_UpdateRects(screen, numupdates, dstupdate);
-
-  /* try something simpler for now: */
-  SDL_UpdateRect(screen, 0, 0, 0, 0);
-
-  numupdates = 0;
-  *frame = *frame + 1;
-
-  LOG("Leaving UpdateScreen()\n");
-}
-
-
-/* basically puts in an order to overdraw sprite with corresponding */
-/* rect of bkgd img                                                 */
-static int EraseSprite(sprite* img, int x, int y)
-{
-  struct blit* update;
-
-  if( !img 
-   || img->cur < 0
-   || img->cur > MAX_SPRITE_FRAMES
-   || !img->frame[img->cur])
-  {
-    fprintf(stderr, "EraseSprite() - invalid 'img' arg!\n");
-    return 0;
-  }
-
-  return EraseObject(img->frame[img->cur], x, y);
-}
-
-
-
-/*************************
-EraseObject : Erase an object from the screen
-**************************/
-static int EraseObject(SDL_Surface* surf, int x, int y)
-{
-  struct blit *update;
-
-  if(!surf)
-  {
-    fprintf(stderr, "EraseObject() - invalid 'surf' arg!\n");
-    return 0;
-  }
-
-  update = &blits[numupdates++];
-
-  if(!update || !update->srcrect || !update->dstrect)
-  {
-    fprintf(stderr, "EraseObject() - 'update' ptr invalid!\n");
-    return 0;
-  }
-
-  update->src = CurrentBkgd();
-//  update->src = background;
-  update->srcrect->x = x;
-  update->srcrect->y = y;
-  update->srcrect->w = surf->w;
-  update->srcrect->h = surf->h;
-
-  /* (reduce width or height of srcrect so it doesn't go past bkgd) */
-  if (update->srcrect->x + update->srcrect->w > CurrentBkgd()->w)
-    update->srcrect->w = CurrentBkgd()->w - update->srcrect->x;
-  if (update->srcrect->y + update->srcrect->h > CurrentBkgd()->h)
-    update->srcrect->h = CurrentBkgd()->h - update->srcrect->y;
-
-
-  update->dstrect->x = x;
-  update->dstrect->y = y;
-  update->dstrect->w = update->srcrect->w;
-  update->dstrect->h = update->srcrect->h; 
-  update->type = 'E';
-
-  return 1;
-}
-
-
-/******************************
-AddRect : Dont actually blit a surface,
-    but add a rect to be updated next
-    update
-*******************************/
-static int AddRect(SDL_Rect* src, SDL_Rect* dst)
-{
-
-  /*borrowed from SL's alien (and modified)*/
-  struct blit* update;
-
-  if(!src)
-  {
-    fprintf(stderr, "AddRect() - invalid 'src' arg!\n");
-    return 0;
-  }
-
-  if(!dst)
-  {
-    fprintf(stderr, "AddRect() - invalid 'dst' arg!\n");
-    return 0;
-  }
-
-  update = &blits[numupdates++];
-
-  if(!update || !update->srcrect || !update->dstrect)
-  {
-    fprintf(stderr, "AddRect() - 'update' ptr invalid!\n");
-    return 0;
-  }
-
-  update->srcrect->x = src->x;
-  update->srcrect->y = src->y;
-  update->srcrect->w = src->w;
-  update->srcrect->h = src->h;
-  update->dstrect->x = dst->x;
-  update->dstrect->y = dst->y;
-  update->dstrect->w = dst->w;
-  update->dstrect->h = dst->h;
-  update->type = 'I';
-
-  return 1;
-}
-
-/*********************
-LoadOthers : Load all other graphics
-**********************/
-static void LoadOthers(void)
-{
-	int i;
-	unsigned char filename[FNLEN];
-
-	LOG( "=LoadOthers()\n" );
-	DEBUGCODE
-	{
-	  fprintf(stderr, "settings.theme_font_name is %s\n",
-                  settings.theme_font_name);
-	}
-	font = LoadFont(settings.theme_font_name, GAME_FONT_SIZE);
-
-	curlev = BlackOutline(gettext("Level"), font, &white);
-	lives  = BlackOutline(gettext("Lives"), font, &white);
-	fish   = BlackOutline(gettext("Fish"), font, &white);
-
-	level[0] = BlackOutline(gettext("Easy"), font, &white);
-	level[1] = BlackOutline(gettext("Medium"), font, &white);
-	level[2] = BlackOutline(gettext("Hard"), font, &white);
-	level[3] = BlackOutline(gettext("Practice"), font, &white);
-
-	number_max_w = 0;
-	for (i = 0; i < NUM_NUMS; i++) {
-		sprintf(filename, "num_%i.png", i);
-		number[i] = LoadImage( filename, IMG_COLORKEY );
-		if (number[i]->w > number_max_w)
-			number_max_w = number[i]->w;
-	}
-
-	for (i = 0; i < CONGRATS_FRAMES; i++) {
-		congrats[i] = BlackOutline(gettext("Congratulations"), font, &white);
-	}
-
-	for (i = 0; i < OH_NO_FRAMES; i++) {
-		ohno[i] = BlackOutline(gettext("Oh No!"), font, &white);
-	}
-	
-	if (settings.sys_sound) {
-		LOG( "=Loading Sound FX\n" );
-
-		sound[WIN_WAV] = LoadSound( "win.wav" );
-		sound[WINFINAL_WAV] = LoadSound( "winfinal.wav" );
-		sound[BITE_WAV] = LoadSound( "bite.wav" );
-		sound[LOSE_WAV] = LoadSound( "lose.wav" );
-		sound[RUN_WAV] = LoadSound( "run.wav" );
-		sound[SPLAT_WAV] = LoadSound( "splat.wav" );
-		sound[EXCUSEME_WAV] = LoadSound( "excuseme.wav" );
-
-		LOG( "=Done Loading Sound FX\n" );
-	} else 
-		LOG( "=NO SOUND FX LOADED (not selected)\n" );
-
-//	PauseLoadMedia();
-
-	LOG( "=Setting NULL fish & splat & word\n" );
-
-	null_fishy.alive = 0;
-	null_fishy.can_eat = 0;
-	null_fishy.word = NULL;
-	null_fishy.x = 0;
-	null_fishy.y = 0;
-	null_fishy.dy = 0;
-
-	null_splat.x = 0;
-	null_splat.y = 0;
-	null_splat.alive = 0;
-
-	LOG( "=LoadOthers() END\n" );
-}
-
-static void display_msg(const unsigned char* msg, int x, int y)
-{
-	SDL_Surface* m;
-	m = TTF_RenderUTF8_Shaded(font, msg, white, white);
-	EraseObject(m, x, y);
-	DrawObject(m, x, y);
-	SDL_FreeSurface(m);
-}
-
-/***************************
-LoadFishies : Load the fish animations and graphics
-*****************************/
-static void LoadFishies(void)
-{
-	int i;
-
-	LOG( "=LoadFishies()\n" );
-
-	fishy = LoadSprite( "fishy", IMG_COLORKEY );
-	splat = LoadSprite( "splat", IMG_COLORKEY );
-
-	for (i = 0; i < MAX_FISHIES_HARD; i++) {
-		fish_object[i].alive = 1;
-		fish_object[i].can_eat = 0;
-		splat_object[i].alive = 0;
-	}
-
-	LOG( "=LoadFishies(): END\n" );
-}
-
-/******************************
-LoadTuxAnims : Load the Tux graphics and animations
-*******************************/
-static void LoadTuxAnims(void)
-{
-	int i;
-	int height = 0;                //temp width/height varis to determine max's
-
-	LOG( "=LoadTuxAnims(): Loading Tux Animations\n" );
-
-	for ( i=0; i < TUX_NUM_STATES; i++ ) {
-		tux_object.spr[i][RIGHT] = LoadSprite( tux_sprite_fns[i], IMG_COLORKEY ); 
-		tux_object.spr[i][LEFT] = FlipSprite( tux_object.spr[i][RIGHT], 1, 0 ); 
-	}
-
-	tux_max_width = tux_object.spr[TUX_STANDING][RIGHT]->frame[0]->w;
-	height        = tux_object.spr[TUX_STANDING][RIGHT]->frame[0]->h;
-
-	LOG( "=LoadTuxAnims(): END\n" );
-}
-
-/******************************
-DrawNumbers : Draw numbers at
-a certain x,y. See "usage"
-below
-*******************************/
-static void DrawNumbers(int num, int x, int y, int places)
-{
-//usage:
-//      num    = number to draw onscreen
-//      x, y   = coords to place number (starting upper left)
-//      places = number of places to fit it into (i.e., if
-//                                       number = 5 and places = 2, would draw "05")
-//                                       if places = 0, then will simply display as
-//                                       many as necessary
-    unsigned char numnuts[FNLEN];
-    int needed_places, i;
-    int uddernumber;
-
-    sprintf(numnuts, "%d", num);
-    i = 0;
-    needed_places = strlen(numnuts);
-
-    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;
-    }
-}
-
-/*************************
-EraseNumbers: Erase numbers
-from the screen. See "usage"
-*****************************/
-static void EraseNumbers(int num, int x, int y, int places)
-{
-//usage:
-//      num    = number to draw onscreen
-//      x, y   = coords to place number (starting upper left)
-//      places = number of places to fit it into (i.e., if
-//                                       number = 5 and places = 2, would draw "05")
-//                                       if places = 0, then will simply display as
-//                                       many as necessary
-    unsigned char numnuts[FNLEN];
-    int needed_places, i;
-    int uddernumber;
-
-    sprintf(numnuts, "%d", num);
-    i = 0;
-    needed_places = strlen(numnuts);
-
-    if (needed_places < FNLEN && needed_places <= places) {
-        if (places > 0) {
-            for (i = 1; i <= (places - needed_places); i++) {
-                EraseObject(number[0], x, y);
-                x += number[0]->w;
-            }
-        }
-    }
-    for (i = 0; i < needed_places; i++) {
-        uddernumber = numnuts[i] - '0';
-        EraseObject(number[uddernumber], x, y);
-        x += number[uddernumber]->w;
-    }
-}
-
-/**********************
-FreeGame : Free all
-the game elements
-***********************/
-static void FreeGame(void)
-{
-  int i;
-
-  FreeLetters();
-
-  if (font)
-    TTF_CloseFont(font);
-  font = NULL;
-
-  LOG( "FreeGame():\n-Freeing Tux Animations\n" );
-
-  for (i = 0; i < TUX_NUM_STATES; i++ )
-  {
-    if (tux_object.spr[i][RIGHT])
-      FreeSprite(tux_object.spr[i][RIGHT]);
-    tux_object.spr[i][RIGHT] = NULL;
-
-    if (tux_object.spr[i][LEFT])
-      FreeSprite(tux_object.spr[i][LEFT]);
-    tux_object.spr[i][LEFT] = NULL;
-  }
-
-  LOG( "-Freeing fishies\n" );
-
-  if (fishy)
-    FreeSprite(fishy);
-  if (splat)
-    FreeSprite(splat);
-  fishy = splat = NULL;
-
-  LOG( "-Freeing other game graphics\n" );
-
-  FreeBothBkgds();
-
-  if (curlev)
-    SDL_FreeSurface(curlev);
-  if (fish)
-    SDL_FreeSurface(fish);
-  if (lives)
-    SDL_FreeSurface(lives);
-  curlev = fish = lives = NULL;
-
-  for (i = 0; i < NUM_LEVELS; i++)
-  {
-    if (level[i])
-      SDL_FreeSurface(level[i]);
-    level[i] = NULL;
-  }
-  for (i = 0; i < NUM_NUMS; i++)
-  {
-    if (number[i])
-      SDL_FreeSurface(number[i]);
-    number[i] = NULL;
-  }
-  for (i = 0; i < CONGRATS_FRAMES; i++)
-  {
-    if (congrats[i])
-      SDL_FreeSurface(congrats[i]);
-    congrats[i] = NULL;
-  }
-  for (i = 0; i < OH_NO_FRAMES; i++)
-  {
-    if (ohno[i])
-      SDL_FreeSurface(ohno[i]);
-    ohno[i] = NULL;
-  }
-  if (settings.sys_sound)
-  {
-    LOG( "-Freeing sound\n" );
-    for (i = 0; i < NUM_WAVES; ++i)
-    {
-      if (sound[i])
-        Mix_FreeChunk(sound[i]);
-      sound[i] = NULL;
-    }
-  }
-
-//  PauseUnloadMedia();
-
-  LOG( "FreeGame(): END\n" );
-}
-
-/***************************
-DrawBackground : This
-function updates the entire
-background. Usefull when
-loading new backgrounds,
-or clearing game screen
-****************************/
-static void DrawBackground(void)
-{
-    struct blit *update;
-
-    LOG("-DrawBackground(): Updating entire background\n");
-
-    numupdates=0;  // drawing entire background writes over all other stuff, so don't draw them
-
-    update = &blits[numupdates++];
-    update->src = CurrentBkgd();
-
-    update->srcrect->x = update->dstrect->x = 0;
-    update->srcrect->y = update->dstrect->y = 0;
-    update->srcrect->w = update->dstrect->w = update->src->w;
-    update->srcrect->h = update->dstrect->h = update->src->h;
-
-    update->type = 'D';
-}
-
-/****************************
-SpawnFishies: Spawn the fishes
-in the key cascade game
-*****************************/
-static void SpawnFishies(int diflevel, int* fishies, int* frame)
-{
-	int i, spacing;
-	wchar_t* new_word;
-
-	switch (diflevel) {
-		case INF_PRACT:
-		case EASY:   spacing = FISH_SPACING_EASY; break;
-		case MEDIUM: spacing = FISH_SPACING_MEDIUM; break;
-		case HARD:   spacing = FISH_SPACING_HARD; break;
-	}
-
-	/* --- return without spawn if there isn't room yet --- */
-
-	for (i = 0; i < *fishies; i++)
-		if (fish_object[i].y < (fishy->frame[0]->h + spacing))
-			return;
-
-	/* See if we get a valid UTF-8 word from WORDS_get before we move on: */
-	/* Now that we are using UTF-8, some characters may be more than one byte, */
-	/* so we can't just use strlen() anymore - DSB.*/		
-	LOG( "=>Spawning fishy\n" );
-
-	new_word = GetWord();
-
-	if (!new_word)
-	{
-	  fprintf(stderr, "SpawnFishies() - could not get word - returning.\n");
-          return;
-	}
-
-	/* If we get to here, it should be OK to actually spawn the fishy: */
-	fish_object[*fishies].word = new_word;
-        fish_object[*fishies].len = wcslen(new_word);
-	fish_object[*fishies].alive = 1;
-	fish_object[*fishies].can_eat = 0;
-	fish_object[*fishies].w = fishy->frame[0]->w * fish_object[*fishies].len;
-	fish_object[*fishies].x = rand() % (screen->w - fish_object[*fishies].w);
-	fish_object[*fishies].y = 0;
-
-	/* set the percentage of the speed based on length */
-	fish_object[*fishies].dy = pow(0.92,fish_object[*fishies].len-1);
-	/* ex: a 9 letter word will be roughly twice as slow! 0.92^8 */
-
-	/* give it a random variance so the fish "crunch" isn't constant */
-	fish_object[*fishies].dy *= ((75 + rand() % 25)/100.0);
-	switch (diflevel) {
-		case INF_PRACT:
-			fish_object[*fishies].dy = DEFAULT_SPEED;
-			break;
-		case EASY:
-			fish_object[*fishies].dy *= MAX_SPEED_EASY;
-			break;
-		case MEDIUM:
-			fish_object[*fishies].dy *= MAX_SPEED_MEDIUM;
-			break;
-		case HARD:
-			fish_object[*fishies].dy *= MAX_SPEED_HARD;
-			break;
-   	}
-
-	fish_object[*fishies].splat_time = *frame + (480 - fishy->frame[0]->h - tux_object.spr[TUX_STANDING][0]->frame[0]->h)/fish_object[*fishies].dy;
-
-	DEBUGCODE {
-		/* NOTE need %S rather than %s because of wide characters */
-		fprintf(stderr, "Spawn fishy with word '%S'\n", fish_object[*fishies].word);
-		fprintf(stderr, "Byte length is: %d\n", wcslen(fish_object[*fishies].word));
-		fprintf(stderr, "UTF-8 char length is: %d\n", fish_object[*fishies].len);
-	}
-
-	*fishies = *fishies + 1;
-}
-
-/***************************
-CheckFishies : Check all the fishies and splats.
-               sort the splats and fishies
-****************************/
-static void CheckFishies(int* fishies, int* splats)
-{
-	int forward, backward;
-	struct fishypoo fish_temp;
-	struct splatter splat_temp;
-
-//	LOG( "CheckFishies\n" );
-
-	/* move any fish from the rear to fill up gaps in the
-	 * front
-	 */
-	forward = 0;
-	backward = MAX_FISHIES_HARD;
-	while (forward < backward) {
-		while (backward > 0 && !fish_object[backward].alive)
-			backward--;
-		while (forward < backward && fish_object[forward].alive)
-			forward++;
-		if ((fish_object[backward].alive) && (!fish_object[forward].alive)) {
-			/* swap alive to be infront of dead */
-			fish_temp = fish_object[backward];
-			fish_object[backward] = fish_object[forward];
-			fish_object[forward] = fish_temp;
-		}
-	}
-	
-	/* same thing for splats */
-
-	forward = 0;
-	backward = MAX_FISHIES_HARD;
-	while (forward < backward) {
-		while (backward > 0 && !splat_object[backward].alive)
-			backward--;
-		while (forward < backward && splat_object[forward].alive)
-			forward++;
-		if ((splat_object[backward].alive) && (!splat_object[forward].alive)) {
-			/* swap alive to be infront of dead */
-			splat_temp = splat_object[backward];
-			splat_object[backward] = splat_object[forward];
-			splat_object[forward] = splat_temp;
-		}
-	}
-
-	/* update the count for fishies & splats */
-
-	*splats = *fishies = 0;
-
-	for (forward = 0; forward < MAX_FISHIES_HARD; forward++)
-		if (fish_object[forward].alive)
-			*fishies+=1;
-		else
-			break;
-
-	for (forward = 0; forward < MAX_FISHIES_HARD; forward++)
-		if (splat_object[forward].alive)
-			*splats+=1;
-		else
-			break;
-}
-
-// Restrict x to a value in the range from a ... b
-static int int_restrict(int a, int x, int b) {
-	if (x < a) x = a;
-	if (x > b) x = b;
-	return x;
-}
-
-static float float_restrict(float a, float x, float b)
-{
-	if (x < a) x = a;
-	if (x > b) x = b;
-	return x;
-}
-
-/***************************
-AddSplat: A fish has died, add a splat where he used to be
-****************************/
-static void AddSplat(int* splats, struct fishypoo* f, int* curlives, int* frame) {
-	int i;
-
-	for ( i = 0; i < f->len; i++ ) {
-		splat_object[*splats].x = int_restrict( 0, f->x+(fishy->frame[0]->w*i) + ((fishy->frame[fishy->cur]->w)>>1)-((splat->frame[0]->w)>>1), screen->w-splat->frame[0]->h-1 );
-		splat_object[*splats].y = screen->h - splat->frame[0]->h - 1;
-		splat_object[*splats].alive = 10; // JA tweak here! frames of live of the splat
-		*splats = *splats + 1;
-	}
-
-	f->alive = 0;
-
-	*curlives = *curlives - 1;
-	if (*curlives <= 0)
-		*curlives = 0;
-
-	if ( settings.sys_sound ) 
-		Mix_PlayChannel(SPLAT_WAV, sound[SPLAT_WAV], 0);
-}
-
-
-
-
-static void DrawFish(int which)
-{
-/*        LOG ("Entering DrawFish()\n");*/
-	int j = 0;
-	int red_letters = 0;
-	int current_letter;
-	/* 'x_inset' and 'y_inset' are where the glyph to be drawn relative        */
-	/* the fishy graphic:                                                      */
-	const int x_inset = 10;
-        const int y_inset = 10;
-	/* letter_x and letter_y are where the upper left corner of the glyph needs */
-        /* to be located - (e.g. how SDL blitting understands locations)           */
-        int letter_x = 0;
-        int letter_y = 0;
-
-        SDL_Surface* letter_surface;
-
-	/* Make sure needed pointers are valid - if not, return: */
-        if (!fishy || !fishy->frame[0])
-	{
-          fprintf(stderr, "DrawFish() - returning, needed pointer invalid\n");
-          return;
-	}
-	    
-
-
-	/* Draw the fishies: */
-	for (j = 0; j < fish_object[which].len; j++)
-        {
-	  DrawSprite( fishy,
-                      fish_object[which].x + (fishy->frame[0]->w*j),
-                      fish_object[which].y);
-        }
-
-
-	/* Now we draw the letters on top of the fish: */
-	/* we only draw the letter if tux cannot eat it yet */
-	if (!fish_object[which].can_eat)
-	{
-		red_letters = -1;
-		j = 0;
-
-		/* figure out how many letters are red: */
-		while (j < tux_object.wordlen && red_letters == -1)
-		{
-		  int k;
-		  for (k = 0; k < tux_object.wordlen - j; k++)
-                  {
-                    if (fish_object[which].word[k] != tux_object.word[j + k]) 
-                      k = 100000;
-                  }
-
-                  if (k < 100000)
-                    red_letters = tux_object.wordlen - j;	
-                  else
-                    j++;
-		}
-	
-// 		LOG ("Preparing to draw letters:\n");
-
-		/* Now draw each letter: */
-		for (j = 0; j < wcslen(fish_object[which].word); j++)
-		{
-		  current_letter = (int)fish_object[which].word[j];
-
-		  if (j < red_letters)
-                    letter_surface = GetRedGlyph(current_letter);
-                  else
-                    letter_surface = GetWhiteGlyph(current_letter);
-
-		  /* Set "letter_x" and "letter_y to where we want the letter drawn: */
-		  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);
-		}
-	}
-/*        LOG ("Leaving DrawFish()\n");*/
-}
-
-/****************************
-MoveFishies : Display and
-move the fishies according
-to their settings
-*****************************/
-static void MoveFishies(int *fishies, int *splats, int *lifes, int *frame) {
-	int i, j;
-
-//	LOG("start MoveFishies\n");
-
-	for (i = 0; i < *fishies; i++)
-		if (fish_object[i].alive) {
-			for (j=0; j < fish_object[i].len; j++)
-				EraseSprite( fishy, fish_object[i].x + (fishy->frame[0]->w*j), fish_object[i].y );
-	            
-			fish_object[i].y += fish_object[i].dy;
-	
-			if (fish_object[i].y >= (screen->h) - fishy->frame[fishy->cur]->h - 1) 
-				AddSplat( splats, &fish_object[i], lifes, frame );
-		}
-	
-	for (i = 0; i < *fishies; i++)
-		if (fish_object[i].alive && fish_object[i].can_eat) 
-			DrawFish( i );
-
-	for (i = 0; i < *fishies; i++)
-		if (fish_object[i].alive && !fish_object[i].can_eat) 
-			DrawFish( i );
-
-	for (i = 0; i < *splats; i++) 
-		if (splat_object[i].alive) {
-			splat_object[i].alive--;
-			if (splat_object[i].alive>1)
-					DrawSprite( splat, splat_object[i].x, splat_object[i].y);
-				else 
-					EraseSprite( splat, splat_object[i].x, splat_object[i].y);
-		}
-
-//	LOG("end MoveFishies\n");
-}
-
-/* UpdateTux : anytime a key is pressed, we need check to
- * see if a fish can be eaten.  The fish that could hit
- * the bottom of the screen first should be choosen if 
- * two fishies match what is typed
- */
-void UpdateTux(wchar_t letter_pressed, int fishies, int frame) {
-	int i;
-	int time_it_splats=0;
-	int which=-1;
-
-	/* --- move our word array to make room if needed --- */
-
-	if (tux_object.wordlen == MAX_WORD_SIZE) {
-		for (i = 0; i < MAX_WORD_SIZE; i++) 
-			tux_object.word[i] = tux_object.word[i + 1];
-		tux_object.wordlen--;
-	}
-
-	/* --- add letter pressed to word array --- */
-
-	tux_object.word[tux_object.wordlen] = letter_pressed;
-	tux_object.wordlen++;
-	tux_object.word[tux_object.wordlen] = 0;
-
-	/* choose the word that matchs what has been typed  */
-	/* and will hit the ground first                    */
-	for (i = 0; i < fishies; i++) 
-		if ((fish_object[i].alive && !fish_object[i].can_eat) && check_word(i) && (time_it_splats > fish_object[i].splat_time || !time_it_splats)) {
-			time_it_splats = fish_object[i].splat_time;
-			which = i;
-		}
-
-	if (which!=-1) {
-		fish_object[which].can_eat = 1;
-		tux_object.wordlen = 0;
-		tux_object.word[0] = 0;
-	}
-
-}
-
-/*************************
-CheckCollision: Check
-for collisions between Tux
-and Fishies. If collided,
-perform appropriate action
-***************************/
-static void CheckCollision(int fishies, int *fish_left, int frame ) {
-	int i, j;
-
-//	LOG( "start CheckCollision\n" );
-
-	for (i = 0; i < fishies; i++) {
-		if ((fish_object[i].y >= tux_object.y - fishy->frame[0]->h) &&
-		    (fish_object[i].x + (fish_object[i].w-fishy->frame[0]->w)/2 >= tux_object.x) &&
-		    (fish_object[i].x + (fish_object[i].w+fishy->frame[0]->w)/2 <= tux_object.x + tux_max_width)) {
-
-			if (fish_object[i].can_eat) {
-                		LOG( "**EATING A FISHY** - in CheckCollision()\n" );
-
-				fish_object[i].alive = 0;
-				fish_object[i].can_eat = 0;
-
-				for (j = 0; j < fish_object[i].len; j++) 
-					EraseSprite(fishy, (fish_object[i].x + (j * fishy->frame[0]->w)), fish_object[i].y);
-
-				*fish_left = *fish_left - 1;
-
-				tux_object.state = TUX_GULPING;
-				REWIND(tux_object.spr[TUX_GULPING][tux_object.facing]);
-				tux_object.dx = 0;
-				tux_object.endx = tux_object.x;
-
-				if (settings.sys_sound) Mix_PlayChannel(BITE_WAV, sound[BITE_WAV], 0);
-
-			} else if (tux_object.state == TUX_STANDING) {
-				LOG( "***EXCUSE ME!** - in CheckCollision()\n" );
-
-				if (settings.sys_sound && !Mix_Playing(EXCUSEME_WAV))
-					Mix_PlayChannel(EXCUSEME_WAV, sound[EXCUSEME_WAV], 0);
-			}
-		}
-	}
-//	LOG( "end CheckCollision\n" );
-}
-
-static void next_tux_frame(void) {
-
-	if ( tux_object.state != TUX_GULPING ) {
-		NEXT_FRAME(tux_object.spr[tux_object.state][tux_object.facing]);
-	} else {
-		NEXT_FRAME(tux_object.spr[TUX_GULPING][tux_object.facing]);
-		if (tux_object.spr[TUX_GULPING][tux_object.facing]->cur==0) 
-			tux_object.state = TUX_STANDING;
-	}
-}
-
-/***********************************
-MoveTux : Update Tux's location & then blit him!
-************************************/
-static void MoveTux( int frame, int fishies ) {
-	int i;
-	int which=-1, time_to_splat=0;
-
-//	LOG( "MoveTux\n" );
-
-	EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
-
-	if (tux_object.state != TUX_GULPING) {
-		for (i=0; i<fishies; i++) 
-			if (fish_object[i].can_eat && (!time_to_splat || fish_object[i].splat_time < time_to_splat)) {
-				time_to_splat = fish_object[i].splat_time;
-				which = i;
-			}
-		if (which != -1) {
-			int endx = int_restrict( 0, fish_object[which].x + (fish_object[which].w/2) - (tux_object.spr[TUX_GULPING][RIGHT]->frame[0]->w / 2), screen->w - tux_max_width - 1 );
-			if (endx != tux_object.endx) {
-				tux_object.endx = endx;
-
-				if (tux_object.endx >= tux_object.x)
-					tux_object.facing = RIGHT;
-				else
-					tux_object.facing = LEFT;
-
-				/* see how fast we need to go to get there... */
-				if (time_to_splat - frame > (abs(tux_object.endx - tux_object.x) / WALKING_SPEED)) {
-					tux_object.dx = WALKING_SPEED;
-					tux_object.state = TUX_WALKING;
-
-					//stop running sound (if playing)                                               
-					if (settings.sys_sound && Mix_Playing(RUN_WAV))
-						Mix_HaltChannel(RUN_WAV);
-				} else {
-					if (time_to_splat > frame) 
-						tux_object.dx = float_restrict( MIN_RUNNING_SPEED, abs(tux_object.endx - tux_object.x) / (time_to_splat-frame), MAX_RUNNING_SPEED );
-					else {
-						tux_object.dx = MAX_RUNNING_SPEED;
-						if (settings.sys_sound && !Mix_Playing(RUN_WAV))
-							if (abs(tux_object.endx - tux_object.x) > 50)
-								Mix_PlayChannel(RUN_WAV, sound[RUN_WAV], 0);
-					}
-
-					tux_object.state = TUX_RUNNING;
-				}
-			}
-		}
-	}
-
-	/* --- move tux (if moving) --- */
-	
-	tux_object.x = float_restrict(0, tux_object.x + (tux_object.facing==RIGHT ? 1.0 : -1.0)*tux_object.dx, (screen->w - tux_max_width));
-
-	/* if done with certain frames, then reset to standing */
-
-	if (tux_object.state == TUX_WALKING || tux_object.state == TUX_RUNNING) {
-		if ((tux_object.facing == RIGHT && tux_object.x >= tux_object.endx) ||
-		    (tux_object.facing == LEFT && tux_object.x <= tux_object.endx)) {
-
-			LOG( "-In MoveTux(): returning tux to standing\n" );
-			tux_object.state = TUX_STANDING;
-			tux_object.dx = 0;
-			tux_object.x = tux_object.endx;
-		}
-	}
-
-	if ((frame % 8) == 0) next_tux_frame();
-}
-
-static void draw_bar(int curlevel, int diflevel, int curlives, int oldlives, int fish_left, int oldfish_left) {
-	/* --- draw difficulty --- */
-
-	DrawObject(level[diflevel], 1, 1);
-
-	/* --- draw level --- */
-	DrawObject(curlev, 1 + GRAPHIC_SPACE + level[diflevel]->w, 1);
-	DrawNumbers(curlevel + 1, 1 + 2 * GRAPHIC_SPACE + level[diflevel]->w + curlev->w, 1, 0);
-
-	/* --- draw lives --- */
-	DrawObject(lives, (screen->w) - (1+lives->w+fish->w+((MAX_FISHIES_DIGITS+1)*2*number_max_w)+GRAPHIC_SPACE), 1);
-
-	if (oldlives != curlives) {
-		EraseNumbers(oldlives, (screen->w) - (1+fish->w+((MAX_FISHIES_DIGITS+1)*2*number_max_w)+GRAPHIC_SPACE), 1, 0);
-		oldlives = curlives;
-	}
-
-	DrawNumbers(curlives, (screen->w) - (1 + fish->w + ((MAX_FISHIES_DIGITS + 1) * 2 * number_max_w) + GRAPHIC_SPACE), 1, 0);
-
-	/* --- draw fish left --- */
-	DrawObject(fish, (screen->w) - (1 + fish->w + (MAX_FISHIES_DIGITS * number_max_w)), 1);
-	if (oldfish_left != fish_left) {
-		EraseNumbers(oldfish_left, (screen->w) - (1 + (MAX_FISHIES_DIGITS * number_max_w)), 1, MAX_FISHIES_DIGITS);
-		oldfish_left = fish_left;
-	}
-	DrawNumbers(fish_left, (screen->w) - (1 + (MAX_FISHIES_DIGITS * number[4]->w)), 1, MAX_FISHIES_DIGITS);
-}
-
-
-
-
-
-
-

Deleted: tuxtype/branches/tuxtype-soc-mh/playgame.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/playgame.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/playgame.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,141 +0,0 @@
-/***************************************************************************
-                          playgame.h
-  description:
-                             -------------------
-    begin                : Fri May 12 2000
-    copyright            : (C) 2000 by Sam Hart
-    email                : hart at geekcomix.com
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#ifndef __PLAYGAME_H__
-#define __PLAYGAME_H__
-
-//definitions
-#define GRAPHIC_SPACE 4 //space between each status bar element in cascade
-
-#define NUM_NUMS 10	//"Mmmmm....Num-Nums...."
-
-#define CONGRATS_FRAMES	2	//number of frames for congrats animation
-#define OH_NO_FRAMES 1	//number of frames for "oh no!" losing animation
-#define MAX_END_FRAMES_BETWEEN_LEVELS 350	//number of frames between levels
-#define MAX_END_FRAMES_WIN_GAME 750	//number of frames at ending animation
-#define MAX_END_FRAMES_GAMEOVER 400	//number of frames at game over
-#define END_FRAME_DY 2	//rise speed of ending animation text
-#define WIN_GAME_XAMP 4	//the xamplitide of winning game text circular motion
-#define WIN_GAME_YAMP 4	//the yamplitude of winning game text circular motion
-#define WIN_GAME_ANGLE_MULT 4	//the angle multiplier for winning game text circ motion
-
-//tux frame lengths (number of frames each cell of animation frames on-screen)
-#define WALK_ONSCREEN	10
-#define RUN_ONSCREEN	8
-#define STAND_ONSCREEN	15
-#define GULP_ONSCREEN	10
-//tux default walking & running speeds
-#define WALKING_SPEED	1.5
-//#define WALKING_SPEED         1
-#define MIN_RUNNING_SPEED		4 * WALKING_SPEED
-#define MAX_RUNNING_SPEED		10 * WALKING_SPEED
-/*-- These last two are for future features --*/
-#define WIN_ONSCREEN		1
-#define YIPE_ONSCREEN		2
-
-//fishy defs
-#define MAX_FISHIES_EASY	15
-#define MAX_FISHIES_MEDIUM	30
-#define MAX_FISHIES_HARD	40
-#define MAX_FISHIES_DIGITS	2
-
-#define FISHY_ONSCREEN	10
-#define SPLAT_FRAMES	1
-#define SPLAT_ONSCREEN	4
-#define DEFAULT_SPEED	.3
-
-#define MAX_SPEED_EASY       0.4
-#define MAX_SPEED_MEDIUM     0.9
-#define MAX_SPEED_HARD       1.2
-
-#define FISH_SPACING_EASY    90
-#define FISH_SPACING_MEDIUM  40
-#define FISH_SPACING_HARD    30
-
-#define LIVES_INIT_EASY      5
-#define LIVES_INIT_MEDIUM    7
-#define LIVES_INIT_HARD      9
-
-#define MAX_UPDATES	3*(20+MAX_FISHIES_HARD)	//20 to account for text updates (I hope)
-
-/* The default alpha for slow moving words,
- note that 128 is optimized for speed! */
-#define DEFAULT_ALPHA 128
-
-typedef struct {
-    int frames;			//number of frames to display this object
-    SDL_Surface *image;
-} object;			//normal (non-RL) object
-
-struct fishypoo {
-    int alive;
-    int can_eat;
-    wchar_t* word;
-    double x, y;
-    int    w;
-    size_t len;
-    int    splat_time;
-    double dy;
-} fish_object[MAX_FISHIES_HARD + 1];
-
-struct fishypoo null_fishy;
-
-enum {
-	TUX_WALKING,
-	TUX_STANDING,
-	TUX_RUNNING,
-	TUX_GULPING,
-	TUX_WINNING,
-	TUX_YIPING,
-	TUX_NUM_STATES
-};
-
-static unsigned char* tux_sprite_fns[TUX_NUM_STATES] = {
-	"tux/walk",
-	"tux/stand",
-	"tux/run",
-	"tux/gulp",
-	"tux/win",
-	"tux/yipe"
-};
-
-#define RIGHT 0
-#define LEFT 1
-
-struct tuxguy {
-    int facing;
-    double x, y;
-    double dx, dy;
-    sprite *spr[TUX_NUM_STATES][2];
-    int endx, endy;
-    int state;
-    int wordlen;
-    wchar_t word[MAX_WORD_SIZE + 1];
-} tux_object;
-
-struct splatter {
-    double x, y;
-    int alive;
-} splat_object[MAX_FISHIES_HARD + 1];
-
-struct splatter null_splat;
-
-
-
-
-#endif

Deleted: tuxtype/branches/tuxtype-soc-mh/practice.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/practice.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/practice.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,799 +0,0 @@
-/**************************************************************************
-practice.c 
--  description: practice module
--------------------
-begin                : Friday Jan 25, 2003
-copyright            : (C) 2003 by Jesse Andrews
-email                : jdandr2 at uky.edu
-
-Revised extensively: 2007
-David Bruce <dbruce at tampabay.rr.com>
-Revised extensively: 2008
-Sreyas Kurumanghat <k.sreyas at gmail.com>
-***************************************************************************/
-
-/***************************************************************************
-*                                                                         *
-*   This program is free software; you can redistribute it and/or modify  *
-*   it under the terms of the GNU General Public License as published by  *
-*   the Free Software Foundation; either version 2 of the License, or     *
-*   (at your option) any later version.                                   *
-*                                                                         *
-***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-
-static SDL_Surface* bg = NULL;
-static SDL_Surface* hands = NULL;
-static SDL_Surface* hand_shift[3] = {NULL};
-static SDL_Surface* keyboard = NULL;
-static SDL_Surface* keypress1 = NULL;
-static SDL_Surface* keypress2 = NULL;
-static SDL_Surface* hand[11] = {NULL};
-static SDL_Rect hand_loc, letter_loc,keyboard_loc;
-static TTF_Font* font = NULL;
-
-static wchar_t phrase[255][FNLEN];
-
-static Mix_Chunk* wrong = NULL;
-
-/*local function prototypes: */
-static int get_phrase(const wchar_t* phr);
-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);
-SDL_Surface* GetKeypress1(int index);
-SDL_Surface* GetKeypress2(int index);
-SDL_Surface* GetWrongKeypress(int index);
-
-
-/************************************************************************/
-/*                                                                      */ 
-/*         "Public" functions (callable throughout program)             */
-/*                                                                      */
-/************************************************************************/
-
-
-/* FIXME this is not UTF-8/Unicode compatible */
-int Phrases(wchar_t* pphrase )
-{
-
-  /* TODO 
-  * 
-  * 
-  * 
-  */
-
-  /* FIXME make variable names more descriptive */
-  Uint32 start = 0, a = 0;
-  int quit = 0,
-      i = 0,
-      c = 0,
-      wp = 0,
-      z = 0,
-      total = 0,
-      state = 0;
-  int key[100] = {0};
-  int next_line=0;
-  SDL_Rect dst, dst2, dst4, mydest;
-  char keytime[20],
-       totaltime[20];
-  SDL_Surface* srfc = NULL;
-  SDL_Surface* tmpsurf = NULL;  
-  
-  if (!practice_load_media())
-  {
-    fprintf(stderr, "Phrases() - practice_load_media() failed, returning.\n");
-    return 0;
-  }
-
-  SDL_BlitSurface(bg, NULL, screen, NULL);
-  SDL_BlitSurface(keyboard, NULL, screen, &keyboard_loc);
-  SDL_BlitSurface(screen, NULL, bg, NULL);
-  SDL_BlitSurface(hands, NULL, screen, &hand_loc);
-  SDL_Flip(screen);
-
-  wp = get_phrase(pphrase);
-
-  if (!wcsncmp(phrase[0], (wchar_t*)"", 1))
-    wcsncpy(pphrase, phrase[0], 80);
-
-  srfc = GetWhiteGlyph(GetLastKey());
-
-  if (!srfc)
-  {
-    fprintf(stderr, "Phrases() - GetWhiteGlyph(GetLastKey()) not defined - bailing out.\n");
-    return 0;
-  }
-
-  dst.x = 320 - (srfc->w/2);
-  dst.y = 100;
-  dst.w = srfc->w;
-  dst.h = srfc->h;
-
-  dst2.x = 50;
-  dst2.y = 400;
-  dst2.w = srfc->w;
-  dst2.h = srfc->h;
-
-  dst4.x = 480;
-  dst4.y = 400;
-  dst4.w = 240;
-  dst4.h = 50;
-
-  dst.x = 40;
-
-  mydest.x = 0;
-  mydest.y = dst.y;
-  mydest.w = screen->w;
-  mydest.h = screen->h-mydest.y;
-
-  start = SDL_GetTicks();
-
-  do
-  {
-    switch (state)
-    {
-      case 0:
-        start = SDL_GetTicks();
-        SDL_BlitSurface(hands, NULL, screen, &hand_loc);
-        SDL_BlitSurface(keyboard, NULL, screen, &keyboard_loc);
-        state = 1;
-        break;
-
-      case 1:
-        if (SDL_GetTicks() - start > 500)
-        {
-          /* Show finger hint, if available. Note that GetFinger() */
-          /* returns negative values on error and never returns a  */
-          /* value greater than 9.                                 */
-          int key = GetIndex(pphrase[c]);
-          int fing = GetFinger(key);
-          int shift = GetShift(key);
-          keypress1= GetKeypress1(key);
-          keypress2= GetKeypress2(key);
-          if (!keypress1)
-          {
-				fprintf(stderr, "Phrases() - GetKeypress1 failed, returning.\n");
-				return 0;
-          }
-          if(!keypress2)
-          {
-				fprintf(stderr, "Phrases() - GetKeypress2 failed, returning.\n");
-				return 0;
-          }
-          SDL_BlitSurface(hands, NULL, screen, &hand_loc);
-          if (fing >= 0) 
-            SDL_BlitSurface(hand[fing], NULL, screen, &hand_loc);
-          SDL_BlitSurface(hand_shift[shift], NULL, screen, &hand_loc);
-          SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
-          SDL_BlitSurface(keypress2, NULL, screen, &keyboard_loc);
-          SDL_FreeSurface(keypress1);
-          SDL_FreeSurface(keypress2);
-          state = 2;
-        }
-        break;
-
-      case 2:
-        if (state == 2 && SDL_GetTicks() - start > 750)
-        {
-          state = 3;
-        }
-        break;
-
-      case 3:
-       SDL_BlitSurface(hands, NULL, screen, &hand_loc);
-       SDL_BlitSurface(keyboard, NULL, screen, &keyboard_loc);
-       state = 12;
-       break;  
-
-      case 4:
-        {
-          int key = GetIndex(pphrase[c]);
-          int fing = GetFinger(key);
-          int shift = GetShift(key);
-          keypress1= GetKeypress1(key);
-          keypress2= GetKeypress2(key);
-                    if (!keypress1)
-          {
-				fprintf(stderr, "Phrases() - GetKeypress1 failed, returning.\n");
-				return 0;
-          }
-          if(!keypress2)
-          {
-				fprintf(stderr, "Phrases() - GetKeypress2 failed, returning.\n");
-				return 0;
-          }
-          SDL_BlitSurface(hands, NULL, screen, &hand_loc);
-          if (fing >= 0) 
-            SDL_BlitSurface(hand[fing], NULL, screen, &hand_loc);
-          SDL_BlitSurface(hand_shift[shift], NULL, screen, &hand_loc);
-          SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
-          SDL_BlitSurface(keypress2, NULL, screen, &keyboard_loc);
-          SDL_FreeSurface(keypress1);
-          SDL_FreeSurface(keypress2);
-          state = 11;
-          break;
-        }
-
-      default:
-        state -= 2; // this is to make the flashing slower
-    }
-	next_letter(pphrase, c);
-
-    while  (SDL_PollEvent(&event))
-    {
-      if (event.type == SDL_KEYDOWN)
-      {
-        a = SDL_GetTicks();
-        key[c] = a - start;
-        total += key[c];
-        sprintf(keytime, "%.2f", (float) key[c] / 1000);
-        sprintf(totaltime, "%.2f", (float) total / 1000);
-        start = a;
-
-        if (event.key.keysym.sym == SDLK_ESCAPE)
-          quit = 1;
-	else
-        if (event.key.keysym.sym == SDLK_DOWN) 
-        {
-          //practice next phase in list
-          quit = 2;
-        }
-        else
-        {
-/**************************************************/
-		int key=GetIndex((wchar_t)event.key.keysym.unicode);
-		char tmp=-1;
-		switch(event.key.keysym.sym)
-		{
-			case  SDLK_BACKQUOTE:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='~';
-				else
-					tmp='`';
-				break;
-			case SDLK_COMMA:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='<';
-				else
-					tmp=',';
-				break;
-			case SDLK_MINUS:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='_';
-				else
-					tmp='-';
-				break;
-			case SDLK_PERIOD:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='>';
-				else
-					tmp='.';
-				break;
-			case SDLK_SLASH:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='?';
-				else
-					tmp='/';
-				break;
-			case SDLK_0:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp=')';
-				else
-					tmp='0';
-				break;
-			case SDLK_1:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='!';
-				else
-					tmp='1';
-				break;
-			case SDLK_2:
-					if(event.key.keysym.mod&KMOD_SHIFT)
-						tmp='@';
-					else
-						tmp='2';
-				break;
-			case SDLK_3:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='#';
-				else
-					tmp='3';
-				break;
-			case SDLK_4:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='$';
-				else
-					tmp='4';
-				break;
-			case SDLK_5:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='%';
-				else
-					tmp='5';
-				break;
-			case SDLK_6:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='^';
-				else
-					tmp='6';
-				break;
-			case SDLK_7:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='&';
-				else
-					tmp='7';
-				break;
-			case SDLK_8:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='*';
-				else
-					tmp='8';
-				break;
-			case SDLK_9:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='(';
-				else
-					tmp='9';
-				break;
-			case SDLK_SEMICOLON:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp=':';
-				else
-					tmp=';';
-				break;
-			case SDLK_EQUALS:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='+';
-				else
-					tmp='=';
-				break;
-			case SDLK_LEFTBRACKET:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='{';
-				else
-					tmp='[';
-				break;
-			case SDLK_BACKSLASH:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='|';
-				else
-					tmp='\\';
-				break;
-			case SDLK_RIGHTBRACKET:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='}';
-				else
-					tmp=']';
-				break;
-			case SDLK_QUOTE:
-				if(event.key.keysym.mod&KMOD_SHIFT)
-					tmp='"';
-				else
-					tmp='\'';
-				break;
-			case SDLK_SPACE:tmp=' ';
-				break;
-			case SDLK_a:tmp='a';
-				break;
-			case SDLK_b:tmp='b';
-				break;
-			case SDLK_c:tmp='c';
-				break;
-			case SDLK_d:tmp='d';
-				break;
-			case SDLK_e:tmp='e';
-				break;
-			case SDLK_f:tmp='f';
-				break;
-			case SDLK_g:tmp='g';
-				break;
-			case SDLK_h:tmp='h';
-				break;
-			case SDLK_i:tmp='i';
-				break;
-			case SDLK_j:tmp='j';
-				break;
-			case SDLK_k:tmp='k';
-				break;
-			case SDLK_l:tmp='l';
-				break;
-			case SDLK_m:tmp='m';
-				break;
-			case SDLK_n:tmp='n';
-				break;
-			case SDLK_o:tmp='o';
-				break;
-			case SDLK_p:tmp='p';
-				break;
-			case SDLK_q:tmp='q';
-				break;
-			case SDLK_r:tmp='r';
-				break;
-			case SDLK_s:tmp='s';
-				break;
-			case SDLK_t:tmp='t';
-				break;
-			case SDLK_u:tmp='u';
-				break;
-			case SDLK_v:tmp='v';
-				break;
-			case SDLK_w:tmp='w';
-				break;
-			case SDLK_x:tmp='x';
-				break;
-			case SDLK_y:tmp='y';
-				break;
-			case SDLK_z:tmp='z';
-				break;
-		}
-		if(event.key.keysym.mod&KMOD_SHIFT)
-			tmp=toupper(tmp);
-		updatekeylist(key,tmp);
-/****************************************************/
-          if (pphrase[c]==event.key.keysym.unicode)
-          {
-		c++;
-		state = 0;
-		dst2.x = 40;
-		dst4.x = 480;
-		
-		if (c==wp+2){
-			//c++;
-			dst.x=40;
-			dst.y=dst.y+dst.h;
-			mydest.y=dst.y;
-			mydest.h=screen->h-mydest.y;
-			next_line=1;
-		}
-		SDL_BlitSurface(bg, &mydest, screen, &mydest);
-		SDL_Flip(screen);
-		if(!next_line)
-			tmpsurf = BlackOutline_w(pphrase, font, &white, c);
-		else
-			tmpsurf = BlackOutline_w(pphrase+wp+1, font, &white, c-(wp+1));
-		SDL_BlitSurface(tmpsurf, NULL, screen, &dst);
-		SDL_FreeSurface(tmpsurf);
-		tmpsurf = NULL;
-		tmpsurf = BlackOutline(keytime, font, &white);
-		SDL_BlitSurface(tmpsurf, NULL, screen, &dst2);
-		SDL_FreeSurface(tmpsurf);
-		tmpsurf = NULL;	
-		tmpsurf = BlackOutline(totaltime, font, &white);
-		SDL_BlitSurface(tmpsurf, NULL, screen, &dst4);
-		SDL_FreeSurface(tmpsurf);
-		tmpsurf = NULL;
-		if (c==(wcslen(pphrase))){
-				wchar_t buf[10];
-				ConvertFromUTF8(buf, gettext("Great!"));
-				print_at(buf, wcslen(buf), 275, 200);
-				SDL_Flip(screen);
-				SDL_Delay(2500);
-				next_line=0;
-				quit=2;
-		}
-	}
-          else
-          {
-		int key = GetIndex((wchar_t)event.key.keysym.unicode);
-		keypress1= GetWrongKeypress(key);
-		SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
-		SDL_FreeSurface(keypress1);
-		state=0;
-		
-            if (event.key.keysym.sym != SDLK_RSHIFT
-             && event.key.keysym.sym != SDLK_LSHIFT)
-             PlaySound(wrong);
-          }
-        }
-      }
-    }
-    SDL_Flip(screen);
-    SDL_Delay(30);
-
-  }while (!quit);
-
-  savekeyboard();
-
-  practice_unload_media();
-
-  return quit;
-}
-
-
-
-/************************************************************************/
-/*                                                                      */ 
-/*       "Private" functions (local to practice.c)                      */
-/*                                                                      */
-/************************************************************************/
-
-
-static int practice_load_media(void)
-{
-  int i;	
-  unsigned char fn[FNLEN];
-  unsigned char let[5];
-  int load_failed = 0;
-  DEBUGCODE { printf("Entering practice_load_media\n"); }
-  LOG("Loading practice media\n");
-
-
-  hands = LoadImage("hands/hands.png", IMG_ALPHA);
-	hand_shift[0] = LoadImage("hands/none.png", IMG_ALPHA);
-	hand_shift[1] = LoadImage("hands/lshift.png", IMG_ALPHA);
-	hand_shift[2] = LoadImage("hands/rshift.png", IMG_ALPHA);
-	keyboard = LoadImage("keyboard/keyboard.png", IMG_ALPHA);
-	bg = LoadImage("main_bkg.png", IMG_ALPHA);
-  wrong = LoadSound("tock.wav");
-  font = LoadFont(settings.theme_font_name, 30);
-
-  for (i = 0; i < 10; i++)
-  {
-    sprintf(fn, "hands/%d.png", i);
-    hand[i] = LoadImage(fn, IMG_ALPHA);
-    if (!hand[i])
-      load_failed = 1;
-  }
-
-  /* Get out if anything failed to load: */
-  if (load_failed
-    ||!hands
-    ||!bg
-    ||!wrong
-    ||!font
-    ||!keyboard
-    ||!hand_shift[0]
-    ||!hand_shift[1]
-    ||!hand_shift[2])
-  {
-    fprintf(stderr, "practice_load_media() - failed to load needed media \n");
-    practice_unload_media;
-    return 0;
-  }
-
-  /* Should be safe from here on out: */
-  hand_loc.x = (screen->w/2) - (hand[0]->w/2);
-  hand_loc.y = screen->h - (hand[0]->h);
-  hand_loc.w = (hand[0]->w);
-  hand_loc.h = (hand[0]->h);
-
-	/********Position of keyboard image*/
-  keyboard_loc.x = screen->w/2 -keyboard->w/2; 
-  keyboard_loc.y = screen->h/2;
-  keyboard_loc.w = screen->w/8;
-  keyboard_loc.h = screen->h/8;
-
-  /* Now render letters for glyphs in alphabet: */
-  RenderLetters(font);
-  //TTF_CloseFont(font);  /* Don't need it after rendering done */
-  //font = NULL;
-  GenerateKeyboard(keyboard);
-
-  LOG("DONE - Loading practice media\n");
-  DEBUGCODE { printf("Leaving practice_load_media\n"); }
-  return 1;
-}
-
-
-
-static void practice_unload_media(void)
-{
-	int i;
-	SDL_FreeSurface(bg);
-        bg = NULL;
-	SDL_FreeSurface(hands);
-        hands = NULL;
-	for(i=0;i<3;i++)
-	{
-		SDL_FreeSurface(hand_shift[i]);
-	        hand_shift[i] = NULL;
-	}
-	SDL_FreeSurface(keyboard);
-        keyboard = NULL;
-	TTF_CloseFont(font);
-	font = NULL;
-	for (i=0; i<10; i++) 
-        {
-          SDL_FreeSurface(hand[i]);
-          hand[i] = NULL;
-        }
-	
-
-	Mix_FreeChunk(wrong);
-	wrong = NULL;
-}
-
-
-/* looks like dead code: */
-static void show(unsigned 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);
-}
-
-
-
-static int get_phrase(const wchar_t* phr)
-{
-  int pc = 0;  // 'phrase count' (?)
-  int pw[256] = { 0 };
-  int wp = 0, i = 0, c = 0, z = 0;
-  char fn[FNLEN];
-
-  int old_debug_on = settings.debug_on;
-  settings.debug_on = 1;
-
-  LOG("Entering get_phrase()\n");
-
-  /* If we didn't receive a phrase get the first one from the file...*/
-  if (wcsncmp((wchar_t*)"", phr, 40) == 0)
-  {
-    FILE* pf; /*   "phrase file"   */
-    /* set the phrases directory/file */
-    /* FIXME I think the phrases should be under data or the theme */
-#ifdef WIN32
-    snprintf(fn, FNLEN - 1, "userdata/phrases.txt");
-#else
-    snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/phrases.txt", getenv("HOME"));
-#endif
-
-    DEBUGCODE { printf("get_phrases(): phrases file is '%s'\n", fn ); }
-    LOG("get_phrases(): trying to open phrases file\n");
-    pf = fopen( fn, "r" );
-    if (pf == NULL) 
-      return(wp);  /* why not just 'return 0;' ??? */
-
-    /* So now copy each line into phrases array: */
-    while (!feof(pf) && pc < 256) 
-    {
-      fscanf( pf, "%[^\n]\n", phrase[pc] );
-      pc++;
-      DEBUGCODE {printf("%s", phrase[pc]);}
-    }
-    if (pc == 256)
-      LOG("File contains more than max allowed phrases - stopping\n");
-
-    fclose(pf);
-    pc--;
-  } 
-  else
-  {
-    pc = 1;
-    wcsncpy(phrase[0], phr, 80);
-  }
-
-  //Find wrapping point
-  for (c = 0; c <= pc; c++)
-  {
-    if (pw[c] < 50)  // If the phrase is less than 598 pixels wide
-    {
-      if (c == 0)
-      {
-        wp = wcslen(phrase[c]);
-        print_at(phrase[0], wp, 40, 10);
-      }
-    }
-    else
-    {
-      z = 0;
-      wp = 0;
-
-      for (i = 0; i < wcslen(phrase[c]); i++)
-      {
-        /* Should be safe (if no glyph, will have returned above) */
-        z ++;
-        if (wp == 0 && z > 50)
-        {
-          wp = i - 1;
-          break;
-        }
-      }
-
-      for (i = wp; i >= 0; i--)
-      {
-        if (wcsncmp((wchar_t*)" ", &phrase[c][i], 1) == 0)
-        {
-          wp = i-1;
-          break;
-        }
-      }
-
-      if (c == 0)
-      {
-        print_at(phrase[0], wp, 40, 10);
-      }
-    }
-  }
-
-  settings.debug_on = old_debug_on;
-
-  LOG("Leaving get_phrase()\n");
-  return(wp);
-}
-
-static void print_at(const wchar_t *pphrase, int wrap, int x, int y)
-{
-	int z=0;
-	SDL_Surface *tmp;
-	letter_loc.x = x;
-	letter_loc.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, font, &white, wrap);
-		letter_loc.w = tmp->w+5;
-		letter_loc.h = tmp->h+5;
-		SDL_BlitSurface(tmp, NULL, screen, &letter_loc);
-		SDL_FreeSurface(tmp);
-	}else{
-                LOG("Line length exceeded - wrap required\n");
-
-		tmp = BlackOutline_w(pphrase, font, &white, wrap+1);
-		letter_loc.w = tmp->w+5;
-		letter_loc.h = tmp->h+5;
-		SDL_BlitSurface(tmp, NULL, screen, &letter_loc);
-		SDL_FreeSurface(tmp);
-		letter_loc.x = 40;
-                // - (letter_loc.h/4) to account for free space at top and bottom of rendered letters
-		//SDL_FreeSurface(tmp);
-		letter_loc.y = letter_loc.y + letter_loc.h - (letter_loc.h/4);
-		tmp = BlackOutline_w(pphrase+wrap+1, font, &white, wcslen(pphrase));
-		letter_loc.w = tmp->w+5;
-		letter_loc.h = tmp->h+5;
-		SDL_BlitSurface(tmp, NULL, screen, &letter_loc);
-		SDL_FreeSurface(tmp);
-	}
-	//TTF_CloseFont(font);
-	// DEBUGCODE { exit(-1); }
-	DEBUGCODE { printf("Leaving print_at \n\n\n"); }
-}
-static void next_letter(wchar_t *t, int c)
-{
-	int i;
-	wchar_t buf[30];
-        i=ConvertFromUTF8(buf, gettext("Next letter "));
-	buf[i]=t[c];
-	buf[i+1]=0;
-        print_at(buf,wcslen(buf),215 ,420);
-}
-
-SDL_Surface* GetKeypress1(int index)
-{
-	char buf[50];
-	GetKeyPos(index,buf);
-	return (LoadImage(buf, IMG_ALPHA));
-}
-
-SDL_Surface* GetWrongKeypress(int index)
-{
-	char buf[50];
-	GetWrongKeyPos(index,buf);
-	return (LoadImage(buf, IMG_ALPHA));
-}
-
-SDL_Surface* GetKeypress2(int index)
-{
-	char buf[50];
-	GetKeyShift(index,buf);
-	return (LoadImage(buf, IMG_ALPHA));
-}

Deleted: tuxtype/branches/tuxtype-soc-mh/profiles.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/profiles.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/profiles.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,353 +0,0 @@
-#include "globals.h"
-#include "funcs.h"
-#include "profilesgui.c"
-
-typedef struct profiles{ //structure for profile in use
-    char* profileName;
-    int profileNum;
-    int highscore1;
-    int highscore2;
-    int highscore3;
-    int highscore4;
-    int highscore5;
-    int highscore6;
-    int highscore7;
-    int highscore8;
-    int wpm_fastest;
-    int wpm_average;
-    int wpm_slowest;
-    int wpm_taken;
-  }profiles;
-
-  extern profiles activeProfile;
-
-int load_profiles_filename(const char*, int);
-int load_profiles_fp(FILE*, int);
-
-void loadprofileName(char *name[][])
-{
-	char fn[FNLEN];
-	char *temp;
-	int count = 0;
-	int offset;
-	int search;
-	#ifdef WIN32
-		snprintf(fn, FNLEN - 1, "userdata/profiles.txt");
-	#else
-		snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/profiles.txt", getenv("HOME"));
-	#endif
-	  	
-	FILE* fp = fopen(fn, "r");
-	  	
-	 while(!feof(fp) && count < settings.numProfiles)
-	 {
-		 fgets(temp, 200, fp);
-		 if(strstr(temp, "profileNum"))
-		 {
-			 search = strlen(temp) - strnspn(temp, "=");
-			 fseek(fp, search *-1, SEEK_CUR);
-			 fgets(names[count][0], search-1, fp);
-			 /*skip the newline */
-			 feek(fp, 2, SEEK_CUR);
-		 }
-		 if(strstr(temp, "profileName"))
-		 {
-			 search = strlen(temp) - strspn(temp, "=");
-			 fseek(fp, search * -1, SEEK_CUR);
-			 fgets(names[count][1], search-1, fp);
-			 /* skip to next profile, after newline */
-			 fseek(fp, 2, SEEK_CUR);
-			 for(offset = 0; offset < 12; offset++)
-			 {
-				 fgets(temp, 200, fp);
-			 }
-			 count++;
-		 }
-	 }
-	 fclose(fp);
-}
-void loadProfile(int profilenum)
-{
-	char fn[FNLEN];
-
-	#ifdef WIN32
-		snprintf(fn, FNLEN - 1, "userdata/profiles.txt");
-	#else
-		snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/profiles.txt", getenv("HOME"));
-	#endif
-  	
-  	load_profiles_filename(fn, profilenum);
-}
-
-static int load_profiles_filename(const char* fn, int profilenum)
-{
-  FILE* fp = fopen(fn, "r");
-
-  if (!fp)
-  {
-    fprintf(stderr, "load_profiles_filename(): Incorrect pointer\n");
-    return;
-  }
-
-  if (!load_profiles_fp(fp, profilenum))
-  {
-    fprintf(stderr, "Could not find any profiles.\n");
-    fclose(fp);
-    return 0;
-  }
-
-  fclose(fp);
-  return 1;
-}
-
-static int load_profiles_fp(FILE* fp, int profilenum)
-{
-  char profiles[FNLEN];
-  char value[FNLEN];
-  int profile_found = 0;
-
-  if (!fp)
-  {
-    fprintf(stderr, "load_profiles_fp() - FILE* parameter NULL\n");
-    return 0;
-  }
-
-  /* we load the selected profile, based on number*/
-  while (!feof(fp))
-  {
-    fscanf(fp, "%[^=]=%[^\n]\n", profiles, value );
-
-    if (strncmp( profiles, "profileNum" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.profileNum = atoi(value);
-    	profile_found = 1;
-    }
-    else if (strncmp( profiles, "profileName" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	strncpy(activeProfile.profileName, value, FNLEN - 1);
-    	profiles_found = 1;
-   }
-    else if (strncmp( profiles, "highscore1_" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.highscore1 = atoi(value);
-    	profiles_found = 1;
-    }
-    else if (strncmp(profiles, "highscore2_" (*char)profilenum, FNLEN) == 0)
-    {
-    	activeProfile.highscore2 = atoi(value);
-    	profiles_found = 1;
-    }
-    else if (strncmp(profiles, "highscore3_" (*char)profilenum, FNLEN) == 0)
-    {
-    	activeProfile.highscore3 = atoi(value);
-    	profiles_found = 1;
-    }
-    else if (strncmp( profiles, "highscore4_" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.highscore4 = atoi(value);
-    	profiles_found = 1;
-    }
-    else if (strncmp( profiles, "highscore5_" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.highscore5 = atoi(value);
-    	profiles_found = 1;
-    }
-    else if (strncmp( profiles, "highscore6_" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.highscore6 = atoi(value);
-    	profiles_found = 1;
-	}
-    else if (strncmp( profiles, "highscore7_" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.highscore7 = atoi(value);
-    	profiles_found = 1;
-    }
-    else if (strncmp( profiles, "highscore8_" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.highscore8 = atoi(value);
-    	profiles_found = 1;
-    }
-    else if (strncmp( profiles, "wpmf" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.wpm_fastest = atoi(value);
-        profiles_found = 1;
-    }
-    else if (strncmp( profiles, "wpma" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.wpm_average = atoi(value);
-    	profiles_found = 1;
-    }
-    else if (strncmp( profiles, "wpms" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.wpm_slowest = atoi(value);
-    	profiles_found = 1;
-    }
-    else if (strncmp( profiles, "wpmt" (*char)profilenum, FNLEN ) == 0 )
-    {
-    	activeProfile.wpm_taken = atoi(value);
-    	profiles_found = 1;
-    }   
-  }
-
-  if (profiles_found)
-    return 1;
-  else
-  {
-    fprintf(stderr, "load_profiles_fp() - no profiles in file - empty or corrupt?\n");
-    return 0;
-  }
-}
-
-void saveProfile(int numprofiles) //called during "Create" on gui and before exit
-{
-	char fn[FNLEN];
-	FILE* profilesFile;
-	FILE* tempFile;
-	
-	activeProfile.profileNum = numprofiles;
-
-	/* set the profiles directory/file */
-
-	#ifdef WIN32
-		_mkdir( "userdata" );
-		snprintf( fn, FNLEN-1, "userdata/profiles.txt" );
-	#else
-		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
-		mkdir( fn, 0755 );
-		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/profiles.txt", getenv("HOME") );
-	#endif
-
-		profilesFile = fopen(fn, "r+" );
-
-		if (profilesFile == NULL)
-		{
-			printf("Save Profiles: Profiles file cannot be created!\n");
-		}
-		/* make sure it's valid*/
-		else if(settings.numProfiles <= activeProfile.profileNum)
-		{
-			//it's the last one/new one, just append it
-			if(settings.numProfiles == activeProfile.profileNum)
-			{
-				profilenum8=
-				fseek(profilesFile, SEEK_END, SEEK_SET) //append
-				fprintf(profilesFile, "profilenum%d=%d\n", 	activeProfile.profileNum, 	activeProfile.profileNum);
-				fprintf(profilesFile, "profilename%d=%s\n",	activeProfile.profileNum, 	activeProfile.profileName);
-				fprintf(profilesFile, "highscore1_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore1);
-				fprintf(profilesFile, "highscore2_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore2);
-				fprintf(profilesFile, "highscore3_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore3);
-				fprintf(profilesFile, "highscore4_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore4);
-				fprintf(profilesFile, "highscore5_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore5);
-				fprintf(profilesFile, "highscore6_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore6);
-				fprintf(profilesFile, "highscore7_%d=%d\n",	activeProfile.profileNum,	activeProfile.highscore7);
-				fprintf(profilesFile, "highscore8_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore8);
-				fprintf(profilesFile, "wpmf%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_fastest);
-				fprintf(profilesFile, "wpma%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_average);
-				fprintf(profilesFile, "wpms%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_slowest);
-				fprintf(profilesFile, "wpmt%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_taken);
-				
-				fclose(profilesFile);
-			}
-			/* make a tempfile to store data up to that profile
-			 * write updated profile, add in data from original file
-			 * because data has to be inserted, and best way to handle
-			 * it right now is to create a temp */
-			else
-			{
-				#ifdef WIN32
-					_mkdir( "userdata" );
-					snprintf( fn, FNLEN-1, "userdata/tempfile.txt" );
-				#else
-					snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
-					mkdir( fn, 0755 );
-					snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/tempfile.txt", getenv("HOME") );
-				#endif
-					
-				fopen(tempFile, "w");
-				
-				/* read all lines of data except those of the inserting
-				 * profile */
-				while(!feof(profilesFile))
-				{
-					/* shouldn't be anymore than 200 chars in a line */
-					char *temp;
-					fgets(temp, 200, profilesFile);
-					if(strcmp(temp, "profilenum" numprofiles"="numprofiles"\n") == 0)
-					{
-						int c;
-						//skip 13 data lines of the same profile
-						for(c = 0; c < 13; c++)
-						{
-							fgets(temp, 200, profilesFile);
-						}
-						fprintf(tempFile, "profilenum%d=%d\n", 	activeProfile.profileNum, 	activeProfile.profileNum);
-						fprintf(tempFile, "profilename%d=%s\n",	activeProfile.profileNum, 	activeProfile.profileName);
-						fprintf(tempFile, "highscore1_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore1);
-						fprintf(tempFile, "highscore2_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore2);
-						fprintf(tempFile, "highscore3_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore3);
-						fprintf(tempFile, "highscore4_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore4);
-						fprintf(tempFile, "highscore5_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore5);
-						fprintf(tempFile, "highscore6_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore6);
-						fprintf(tempFile, "highscore7_%d=%d\n",	activeProfile.profileNum,	activeProfile.highscore7);
-						fprintf(tempFile, "highscore8_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore8);
-						fprintf(tempFile, "wpmf%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_fastest);
-						fprintf(tempFile, "wpma%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_average);
-						fprintf(tempFile, "wpms%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_slowest);
-						fprintf(tempFile, "wpmt%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_taken);
-					}
-					else
-					{
-						fprintf(tempFile, temp);
-					}
-				}
-				fclose(tempFile);
-				fclose(profilesFile);
-				//overwrite original file with the tempfile
-				remove("userdata/profiles.txt");
-				rename("userdata/tempfile.txt", "userdata/profiles.txt");
-			}
-		}
-		else
-		{
-			 fprintf(stderr, "Invalid profile number.\n");
-			 fclose(profilesFile);
-		}
-}
-
-void updatePersonalScore(int score)
-{
-	int temp, count = 1;
-	int checkScore = score;
-	do
-	{
-		if(checkScore > activeProfile.highscore(count))
-		{
-			temp = activeProfile.highscore(count);
-			activeProfile.highscore(count) = score;
-			checkScore = temp;
-		}
-		count++;
-	}
-	while((checkScore < activeProfile.highscore(count)) && count <=8);
-}
-void updateWPM(int keystrokes)
-{
-#define time 30 //in seconds how long test lasted
-	
-	int numwords = keystrokes/5;
-	int wpm = numwords*2;
-	int tempaverage;
-	
-	if(wpm > activeProfile.wpm_fastest)
-	{
-		activeProfile.wpm_fastest = wpm;
-	}
-	
-	if(wpm < activeProfile.wpm_slowest)
-	{
-		activeProfile.wpm_slowest = wpm;
-	}
-	
-	tempaverage = activeProfile.wpm_taken*activeProfile.wpm_average;
-	activeProfile.wpm_average = (tempaverage + wpm)/activeProfile.wpm_taken++;
-}
\ No newline at end of file

Deleted: tuxtype/branches/tuxtype-soc-mh/profilesgui.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/profilesgui.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/profilesgui.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,668 +0,0 @@
-#include "globals.h"
-#include "funcs.h"
-#include "profiles.c"
-
-void createProfile(void);
-void selectProfile(void);
-void deleteProfile(void);
-int chooseProfiles(void);
-void nameEntry(char*, const char*, const char*);
-int inRect(SDL_Rect, int, int);
-
-
-void profilesSelector() //gui called upon clicking on the profile icon and at the start of titlescreen
-{
-	char *input;
-	if(!chooseProfiles() && (settings.numProfiles < 8))
-	{
-		createProfile();
-	}
-	else
-	{
-		/* TODO greyout createprofile/disable SDL handling
-		 * since there max profiles, if wanted.
-		 * Nothing needs to happen since there are too many
-		 * profiles\not the first time means display() worked*/
-		;
-	}
-
-}
-
-void createProfile()
-{
-	if(settings.numProfiles < 8)
-	{
-		nameEntry(activeProfile.profileName, "Create a Profile", "Enter a Name");
-		saveProfile(++settings.numProfiles);/*increments number of profiles in existence */
-		loadprofile(settings.numProfiles);
-	}
-	else
-	{
-		/* do nothing since too many*/
-	}
-	
-}
-void selectProfile(int location) //sets profile
-{
-	if (settings.numProfiles > 1 )
-	{
-		saveProfile(activeProfile.numProfile);
-		loadprofile(location)
-	}
-	else
-	{
-		loadprofile(location)
-	}
-
-
-	//erase window
-}
-
-void deleteProfile(int numprofile) //erases selected profile along with all data associated
-{
-	char fn[FNLEN];
-	FILE* profilesFile;
-	FILE* tempFile;
-	int found = 0;
-	int count;
-	
-	/* set the profiles directory/file */
-
-	#ifdef WIN32
-		_mkdir( "userdata" );
-		snprintf( fn, FNLEN-1, "userdata/profiles.txt" );
-	#else
-		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
-		mkdir( fn, 0755 );
-		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/profiles.txt", getenv("HOME") );
-	#endif
-
-	profilesFile = fopen(fn, "r" );
-
-	if (profilesFile == NULL)
-	{
-		printf("Save Profiles: Profiles file cannot be created!\n");
-	}
-	
-	#ifdef WIN32
-		_mkdir( "userdata" );
-		snprintf( fn, FNLEN-1, "userdata/tempfile.txt" );
-	#else
-		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
-		mkdir( fn, 0755 );
-		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/tempfile.txt", getenv("HOME") );
-	#endif
-					
-	fopen(tempFile, "w");
-				
-	/* read all lines of data except those of the inserting
-		 profile */
-	while(!feof(profilesFile))
-	{
-		int lines;
-		/* shouldn't be anymore than 200 chars in a line */
-		char *temp;
-		fgets(temp, 200, profilesFile);
-		if(strcmp(temp, "profilenum" (*char)numprofile"="(*char)numprofile) == 0)
-		{
-			//skip the deleted profile
-			for(int c = 0; c < 13; c++)
-			{
-				fgets(temp, 200, profilesFile);
-			}
-			found = 1;
-		}
-		else if(found) //need to decrement profile values afterward
-		{
-			char* i;
-			char* value;
-			int stringoffset;
-			int offset = numprofile + count;
-			//handle the different lines
-			for(lines = 0; lines < 14; lines++)
-			{
-				switch (lines)
-				{
-					case 0:
-					{
-						fprint(tempFile, "profileNum%d=%d\n",offset, offset))
-						break;
-					}
-					case 1:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "profileName%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;
-					}
-					case 2:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "highscore1_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;
-					}
-					case 3:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "highscore2_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;
-					}
-					case 4:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "highscore3_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;
-					}
-					case 5:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "highscore4_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;					
-					}
-					case 6:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "highscore5_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;					
-					}
-					case 7:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "highscore6_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;					
-					}
-					case 8:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "highscore7_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;					
-					}
-					case 9:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "highscore8_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;					
-					}
-					case 10:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "wpmf%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;
-					}
-					case 11:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "wpma%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;
-					}
-					case 12:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "wpms_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;
-					}
-					case 13:
-					{		
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "wpmt_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;
-					}
-					case 14:
-					{
-						stringoffset = strlen(temp) - strcspn(temp, "=");
-						fprint(tempFile, "highscore1_%d=", offset);
-						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
-						fgets(temp, 200, profilesFile);
-						fprint(tempFile,"%s", temp);
-						break;
-					}
-				}	
-			}
-			count++;
-		}
-		else //no need to do special work with the line
-		{
-			fprint(tempFile, temp);
-		}
-	}
-	settings.numProfiles--;
-	fclose(tempFile);
-	fclose(profilesFile);
-	//overwrite original file with the tempfile
-	remove("userdata/profiles.txt");
-	rename("userdata/tempfile.txt", "userdata/profiles.txt");
-}
-int chooseProfiles()
-{	
-	char *name[settings.numProfile][2];
-	SDL_Surface* titles[8] = {NULL};
-	SDL_Surface* select[8] = {NULL};
-	SDL_Surface* create = NULL, *select = NULL, *delete = NULL;
-	SDL_Surface* backg = NULL;
-	SDL_Rect createRect, selectRect, deleteRect;
-	SDL_Rect titleRects[8];
-	int stop = 0;
-	int loc = 0;
-	int old_loc = 1;
-	int i;
-
-	/* Render SDL_Surfaces for list entries: */
-	for (i = 0; i < settings.numProfiles; i++)
-	{
-		titles[i] = BlackOutline( name[i][1], font, &white );
-	    select[i] = BlackOutline( names[i][1], font, &yellow);
-	}
-
-	backg = LoadImage("main_bkg.png", IMG_REGULAR);
-	delete = LoadImage("delete.png", IMG_ALPHA);
-	create = LoadImage("create.png", IMG_ALPHA);
-	select = LoadImage("select.png", IMG_ALPHA);
-
-	/* Get out if needed surface not loaded successfully: */
-	if (!backg || !delete || !create || !select)
-	{
-		fprintf(stderr, "chooseProfile(): needed image not available\n");
-
-	    for (i = 0; i < settings.numProfiles; i++)
-	    {
-	    	SDL_FreeSurface(titles[i]);
-	    	SDL_FreeSurface(select[i]);
-	    	titles[i] = select[i] = NULL;
-	    }
-
-	    SDL_FreeSurface(backg);
-	    SDL_FreeSurface(left);
-	    SDL_FreeSurface(create)
-	    SDL_FreeSurface(select);
-	    backg = left = right = NULL;
-	    return 0;
-	}
-
-	deleteRect.w = delete->w; deleteRect.h = delete->h;
-	deleteRect.x = 80 - (deleteRect.w/2); deleteRect.y = 430;
-
-	createRect.w = create->w; createRect.h = delete->h;
-	createRect.x = 320 - (createRec.w/2); createRec.y = 430;
-	  
-	selectRect.w = select->w; selectRect.h = select->h;
-	selectRect.x = 560 - (rightRect.w/2); selectRect.y = 430;
-
-	/* set initial rect sizes */
-	titleRects[0].y = 30;
-	titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
-
-	for (i = 1; i < 8; i++)
-	{
-		titleRects[i].y = titleRects[i - 1].y + 50;
-	    titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
-	}
-
-	/* Main event loop for this screen: */
-	while (!stop)
-	{
-	  while (SDL_PollEvent(&event))
-	  {
-		  switch (event.type)
-	      {
-	        	case SDL_QUIT:
-	        	{
-	        		exit(0); /* FIXME may need to cleanup memory and exit more cleanly */
-	        		break;
-	        	}
-
-	        	case SDL_MOUSEMOTION:
-	        	{
-	        		for (i=0; (i<8) && (loc-(loc%8)+i<settings.numProfiles); i++)
-	        		{
-	        			if (inRect( titleRects[i], event.motion.x, event.motion.y ))
-	        			{
-	        				loc = loc-(loc%8)+i;
-	        				break;
-	        			}
-	        		}
-	        		break;
-	        	}
-
-	        	case SDL_MOUSEBUTTONDOWN:
-	        	{
-	        		if (inRect( deleteRect, event.button.x, event.button.y ))
-	        		{
-	        				deleteprofile(loc);
-	        				stop = 3;
-	        		}
-	        		if (inRect( createRect, event.button.x, event.button.y ))
-	        		{
-	        			createProfile();
-	        			break;
-	        		}
-	        		if (inRect(selectRect, event.button.x, event.button.y))
-	        		{
-	        			selectProfile(loc);
-	        			stop = 1;
-	        		}
-	        			break;
-	        		}
-	        	}
-	        	case SDL_KEYDOWN:
-	        		if (event.key.keysym.sym == SDLK_ESCAPE) 
-	        		{ 
-	        			stop = 1; 
-	        			break; 
-	        		}
-	        		if (event.key.keysym.sym == SDLK_RETURN) 
-	        		{
-	        			selectProfile(loc);
-	        			break;
-	        		}
-
-	        		if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP)) 
-	        		{
-	        			if (loc-(loc%8)-8 >= 0)
-	        			{
-	        				loc=loc-(loc%8)-8;
-	        			}
-	        		}
-
-	        		if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) 
-	        		{
-	        			if (loc-(loc%8)+8 < settings.numProfiles)
-	        			{
-	        				loc=(loc-(loc%8)+8);
-	        			}
-	        		}
-
-	        		if (event.key.keysym.sym == SDLK_UP) 
-	        		{
-	        			if (loc > 0)
-	        			{
-	        				loc--;
-	        			}
-	        		}
-
-	        		if (event.key.keysym.sym == SDLK_DOWN) 
-	        		{
-	        			if (loc+1<settings.numProfiles)
-	        			{
-	        				loc++;
-	        			}                    
-	        		}
-	  }
-	}
-
-	if (old_loc != loc) 
-	{
-		int start;
-
-		SDL_BlitSurface(backg, NULL, screen, NULL );
-
-		start = loc - (loc % 8);
-		for (i = start; i<MIN(start+8,settings.numProfiles); i++) 
-		{
-			titleRects[i%8].x = 320 - (titles[i]->w/2);
-			if (i == loc)
-			{
-				SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
-			}
-			else
-			{
-				SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
-			}               
-		}
-
-		SDL_UpdateRect(screen, 0, 0, 0 ,0);
-	}
-	SDL_Delay(40);
-	old_loc = loc;
-
-	  /* --- clear graphics before leaving function --- */
-	  for (i = 0; i < settings.numProfiles; i++)
-	  {
-	    SDL_FreeSurface(titles[i]);
-	    SDL_FreeSurface(select[i]);
-	    titles[i] = select[i] = NULL;
-	  }
-
-	  SDL_FreeSurface(backg);
-	  SDL_FreeSurface(delete);
-	  SDL_FreeSurface(create)
-	  SDL_FreeSurface(select);
-	  backg = left = right = NULL; /* Maybe overkill - about to be destroyed anyway */
-
-	  if (stop == 2)
-	  {
-	    return 0;
-	  }
-	  else if (stop == 3)
-	  {
-		  chooseProfiles();
-	  }
-
-	  return 1;
-}
-
-void nameEntry(char* name, const char* heading, const char* sub)
-{
-	/* should be long enough */
-	  char UTF8_buf[96] = {'\0'};
-	
-	  SDL_Rect loc;
-	  SDL_Rect redraw_rect;
-	
-	  int redraw = 0;
-	  int first_draw = 1;
-	  int finished = 0;
-	  int tux_frame = 0;
-	  Uint32 frames = 0;
-	  Uint32 start = 0;
-	  wchar_t wchar_buf[33] = {'\0'};
-	  TTF_Font* name_font = NULL;
-	  const int NAME_FONT_SIZE = 18;
-	  const int BG_Y = 100;
-	  const int BG_WIDTH = 400;
-	  const int BG_HEIGHT = 200;
-
-	  if (!name)
-	  {
-		  return;
-	  }
-	    
-	  name_font = LoadFont(DEFAULT_FONT_NAME, NAME_FONT_SIZE);
-	  if (!name_font)
-	  {
-		  return;
-	  }
-
-	  SDL_EnableUNICODE(SDL_ENABLE);
-
-  /* Draw translucent background for text: */
-	  
-	 SDL_Rect bg_rect;
-	 bg_rect.x = (screen->w)/2 - BG_WIDTH/2;
-	 bg_rect.y = BG_Y;
-	 bg_rect.w = BG_WIDTH;
-	 bg_rect.h = BG_HEIGHT;
-	 DrawButton(&bg_rect, REG_RGBA);
-	
-	 bg_rect.x += 10;
-	 bg_rect.y += 10;
-	 bg_rect.w -= 20;
-	 bg_rect.h = 60;
-	 DrawButton(&bg_rect, SEL_RGBA);
-	  
-
-  /* Draw heading: */
-  
-    SDL_Surface* s = outlineBox( heading, default_font, &white);
-    
-    if(s)
-    {
-    	loc.x = (screen->w/2) - (s->w/2);
-    	loc.y = 110;
-    	SDL_BlitSurface(s, NULL, screen, &loc);
-    	SDL_FreeSurface(s);
-    }
-
-    s = BlackOutline( sub, default_font, &white);
-    if(s)
-    {
-    	loc.x = (screen->w/2) - (s->w/2);
-    	loc.y = 140;
-    	SDL_BlitSurface(s, NULL, screen, &loc);
-    	SDL_FreeSurface(s);
-    }
-
-    /*update*/
-    SDL_UpdateRect(screen, 0, 0, 0, 0);
-
-    /*handle events*/
-    while (!finished)
-    {
-    	start = SDL_GetTicks();
-
-    	while (SDL_PollEvent(&event)) 
-    	{
-    		switch (event.type)
-    		{
-    			case SDL_QUIT:
-    			{
-    				cleanup();
-    			}
-
-    			case SDL_KEYDOWN:
-    			{
-    				switch (event.key.keysym.sym)
-    				{
-    					case SDLK_ESCAPE:
-    					case SDLK_RETURN:
-    					case SDLK_KP_ENTER:
-    					{
-    						finished = 1;
-    						playsound(SND_TOCK);
-    						break;
-    					}
-    					case SDLK_BACKSPACE:
-    					{
-    						if (wcslen(wchar_buf) > 0)
-    						{
-    							wchar_buf[(int)wcslen(wchar_buf) - 1] = '\0';
-    						}
-    						redraw = 1;
-    						break;
-    					}
-
-    					/* if key has unicode value, add it */
-    					default:
-    					{
-    						if ((event.key.keysym.unicode > 0)
-    								&& (wcslen(wchar_buf) < 32)) 
-    						{
-    							wchar_buf[(int)wcslen(wchar_buf)] = event.key.keysym.unicode;
-    							redraw = 1;
-    						} 
-    					}
-    				}
-
-    				/* Now draw name, if needed: */
-    				if (redraw)
-    				{
-    					SDL_Surface* s = NULL;
-    					redraw = 0;
-
-    					/* Convert text to UTF-8 so BlackOutline() can handle it: */
-    					wcstombs((char*) UTF8_buf, wchar_buf, 96);
-
-    					/* Redraw background and shading in area where we drew text last time: */ 
-    					if (!first_draw)
-    					{
-    						SDL_BlitSurface(screen, &redraw_rect, screen, &redraw_rect);
-    						DrawButton(&redraw_rect, REG_RGBA);
-    						SDL_UpdateRect(screen,
-    								redraw_rect.x,
-    								redraw_rect.y,
-    								redraw_rect.w,
-    								redraw_rect.h);
-    					}
-
-    					s = BlackOutline(UTF8_buf, name_font, &yellow);
-            
-    					if (s)
-    					{
-    						/* set up loc and blit: */
-    						loc.x = (screen->w/2) - (s->w/2);
-    						loc.y = 200;
-    						SDL_BlitSurface(s, NULL, screen, &loc);
-
-    						/* Remember where we drew so we can update background next time through:  */
-    						/* (for some reason we need to update a wider area to get clean image)    */
-    						redraw_rect.x = loc.x - 20;
-    						redraw_rect.y = loc.y - 10;
-    						redraw_rect.h = s->h + 20;
-    						redraw_rect.w = s->w + 40;
-    						first_draw = 0;
-
-    						SDL_UpdateRect(screen,
-    								redraw_rect.x,
-    								redraw_rect.y,
-    								redraw_rect.w,
-    								redraw_rect.h);
-    						SDL_FreeSurface(s);
-    						s = NULL;
-    					}
-    				}
-    			}
-    		}
-    	}
-
-    	/*stop frame rate from skipping */
-    	while ((SDL_GetTicks() - start) < 33)
-    	{
-    		SDL_Delay(20);
-    	}
-    	frames++;
-  }
-  TTF_CloseFont(name_font);
-
-  /* disable due to overhead */
-  SDL_EnableUNICODE(SDL_DISABLE);
-
-  /* Now copy name into location pointed to by arg: */ 
-  strncpy((char*)name, (char*)UTF8_buf, 96);
-}
\ No newline at end of file

Deleted: tuxtype/branches/tuxtype-soc-mh/scripting.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/scripting.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/scripting.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,1364 +0,0 @@
-/***************************************************************************
- -  file: scripting.c
- -  description: scripting for lessons & instructions ...
-                             -------------------
-    begin                : Sun Dec 28, 2003
-    copyright            : Jesse Andrews (C) 2003
-    email                : tuxtype-dev at tux4kids.net
-***************************************************************************/
-
-/***************************************************************************
-*                                                                         *
-*   This program is free software; you can redistribute it and/or modify  *
-*   it under the terms of the GNU General Public License as published by  *
-*   the Free Software Foundation; either version 2 of the License, or     *
-*   (at your option) any later version.                                   *
-*                                                                         *
-***************************************************************************/
-
-#include "scripting.h"
-
-/* Local function prototypes: */
-static void clear_items(itemType* i);
-static void clear_pages(pageType* p);
-static void close_script(void);
-static SDL_Color* get_color(const char* in);
-static int get_int(const char* in);
-static char* get_quote(const char* in);
-static char hex2int(char b, char s);
-static int load_script(const char* fn);
-static void run_script(void);
-
-/************************************************************************/
-/*                                                                      */ 
-/*         "Public" functions (callable throughout program)             */
-/*                                                                      */
-/************************************************************************/
-
-
-void InstructCascade(void)
-{
-  char fn[FNLEN]; 
-
-  /* Try theme script first: */
-  if (!settings.use_english)
-    sprintf( fn, "%s/scripts/cascade.xml", settings.theme_data_path);
-
-  if (load_script( fn ) == 0) /* meaning successful load */
-  {
-    run_script();
-    return;
-  }
-
-  /* If unsuccessful, fall back to default (English) script: */
-  sprintf( fn, "%s/scripts/cascade.xml", settings.default_data_path);
-  if (load_script( fn ) != 0)
-    return; // bail if any errors occur
-
-  run_script();
-}
-
-
-void InstructLaser(void)
-{
-  char fn[FNLEN]; 
-  int i;
-
-  /* Try theme script first: */
-  if (!settings.use_english)
-    sprintf( fn, "%s/scripts/laser.xml", settings.theme_data_path);
-
-  if (load_script( fn ) == 0) /* meaning successful load */
-  {
-    for (i = 0; i < 20; i++)
-    {
-      run_script();
-      SDL_Delay(500);
-    }
-    return;
-  }
-
-
-  /* If unsuccessful, fall back to default (English) script: */
-  sprintf( fn, "%s/scripts/laser.xml", settings.default_data_path);
-  if (load_script( fn ) != 0)
-    return; // bail if any errors occur
-
-  for (i = 0; i < 20; i++)
-  {
-    run_script();
-    SDL_Delay(500);
-  }
-}
-
-
-void ProjectInfo(void)
-{
-  char fn[FNLEN]; 
-
-  /* Try theme script first: */
-  if (!settings.use_english)
-    sprintf( fn, "%s/scripts/projectInfo.xml", settings.theme_data_path);
-
-  if (load_script( fn ) == 0) /* meaning successful load */
-  {
-    run_script();
-    return;
-  }
-
-  /* If unsuccessful, fall back to default (English) script: */
-  sprintf( fn, "%s/scripts/projectInfo.xml", settings.default_data_path);
-  if (load_script( fn ) != 0)
-    return; // bail if any errors occur
-
-  run_script();
-}
-
-
-int TestLesson(void)
-{
-  SDL_Surface* left = NULL, *right = NULL, *pointer = NULL, *bkg = NULL;
-  SDL_Surface* filenames[200] = {NULL};
-
-  SDL_Rect spot, arrow_area;
-  SDL_Rect leftRect, rightRect;
-  SDL_Rect titleRects[8];
-
-  TTF_Font* font = NULL;
-	
-  int stop = 0;
-  int loc = 0;
-  int old_loc = 1;
-  int i;
-  int c = 0;
-  int found = 0;
-	
-  char fn[FNLEN]; 
-  unsigned char wordlistFile[200][200];
-  unsigned char script_path[FNLEN];
-
-  DIR* wordsDir = NULL;
-  struct dirent* wordsFile = NULL;
-
-  LOG("\nEnter TestLesson()\n");
-
-  pointer = LoadImage( "right.png", IMG_ALPHA );
-  bkg = LoadImage( "main_bkg.png", IMG_REGULAR );
-  left = LoadImage("left.png", IMG_ALPHA);       
-  right = LoadImage("right.png", IMG_ALPHA);
-
-  if (!pointer || !bkg || !left ||!right)
-  {
-    fprintf(stderr, "TestLesson() - needed image not found\n");
-    /* Free anything that got loaded: */
-    SDL_FreeSurface(pointer);
-    SDL_FreeSurface(left);
-    SDL_FreeSurface(right);
-    SDL_FreeSurface(bkg);
-    pointer = left = right = bkg = NULL;
-    return 0;
-  }
-
-  SDL_ShowCursor(0);
-
-  /* find the directory to load wordlists from */
-  /* First look in theme path, if desired: */
-  if (!settings.use_english)
-  {
-    sprintf( script_path, "%s/scripts", settings.theme_data_path);
-    if (CheckFile(script_path))
-    {
-      DEBUGCODE { fprintf(stderr, "Using theme script dir: %s\n", script_path); }
-      found = 1;
-    }
-  }
-
-  /* Now look in default path if desired or needed: */
-  if (!found)
-  {
-    sprintf( script_path, "%s/scripts", settings.default_data_path);
-    if (CheckFile(script_path))
-    {
-      DEBUGCODE { fprintf(stderr, "Using theme script dir: %s\n", script_path); }
-      found = 1;
-    }
-  }
-
-  if (!found)
-  {
-    fprintf(stderr, "TestLesson(): Error finding script directory!\n");
-    return 0;
-  }
-
-  /* What is this location? */
-  spot.x = 60;
-  spot.y = 20;
-
-
-  /* create a list of all the .xml files */
-
-  wordsDir = opendir( script_path );	
-  font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
-  do
-  {
-    wordsFile = readdir(wordsDir);
-    if (!wordsFile)
-      break;
-
-    /* must have at least '.xml' at the end */
-    if (strlen(wordsFile->d_name) < 5)
-      continue;
-
-    if (strcmp(&wordsFile->d_name[strlen(wordsFile->d_name)-4],".xml"))
-      continue;
-
-    sprintf( wordlistFile[c], "%s", wordsFile->d_name );
-
-    DEBUGCODE { fprintf(stderr, "Adding XML file no. %d: %s\n", c, wordlistFile[c]); }
-
-
-    filenames[c] = TTF_RenderUTF8_Blended(font, wordsFile->d_name, white);
-    SDL_BlitSurface( filenames[c], NULL, screen, &spot );
-    SDL_FreeSurface(filenames[c]);
-    c++;
-    spot.y += MENU_FONT_SIZE;
-  } while (1); /* Leave loop when readdir() returns NULL */
-
-  TTF_CloseFont(font);
-  font = NULL;
-  closedir(wordsDir);	
-  wordsDir = NULL;
-  SDL_Flip(screen);
-
-  /* Should be safe - tested 'left' and 'right' above: */
-  leftRect.w = left->w; leftRect.h = left->h;
-  leftRect.x = 320 - 80 - (leftRect.w/2); leftRect.y = 430;
-
-  rightRect.w = right->w; rightRect.h = right->h;
-  rightRect.x = 320 + 80 - (rightRect.w/2); rightRect.y = 430;
-
-  /* set initial rect sizes */
-  titleRects[0].y = 30;
-  titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
-
-  for (i = 1; i < 8; i++)
-  { 
-    titleRects[i].y = titleRects[i-1].y + 50;
-    titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
-  }
-
-  arrow_area.x = 0;
-  arrow_area.y = 0;
-  arrow_area.w = 59;
-  arrow_area.h = 479;
-
-  while (!stop)
-  {
-    while (SDL_PollEvent(&event))
-    {
-      switch (event.type)
-      {
-        case SDL_QUIT:
-          exit(0);
-          break;
-        /* FIXME some of mouse code is wrong */
-        case SDL_MOUSEMOTION:
-          for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
-            if (inRect( titleRects[i], event.motion.x, event.motion.y ))
-            {
-              loc = loc-(loc%8)+i;
-              break;
-            }
-          break;
-
-        case SDL_MOUSEBUTTONDOWN:
-          if (inRect( leftRect, event.button.x, event.button.y ))
-            if (loc-(loc%8)-8 >= 0)
-            {
-              loc=loc-(loc%8)-8;
-              break;
-            }
-
-          if (inRect( rightRect, event.button.x, event.button.y ))
-            if (loc-(loc%8)+8 < c)
-            {
-              loc=loc-(loc%8)+8;
-              break;
-            }
-
-          for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
-            if (inRect(titleRects[i], event.button.x, event.button.y))
-            {
-//              loc = loc-(loc%8)+i;
-//              ClearWordList(); /* clear old selection */
-//               if (loc==0)
-//                 UseAlphabet(); 
-//               else
-//                 GenerateWordList(wordlistFile[loc]);
-// 
-//               stop = 1;
-//               break;
-            }
-          break;
-
-        case SDL_KEYDOWN:
-          if (event.key.keysym.sym == SDLK_ESCAPE)
-          { 
-            stop = 2;
-            break;
-          }
-
-          if (event.key.keysym.sym == SDLK_RETURN)
-          {
-            sprintf(fn, "%s/scripts/%s", settings.default_data_path, wordlistFile[loc]);
-            stop = 1;
-            break;
-          }
-
-          if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP))
-          {
-            if (loc-(loc%8)-8 >= 0)
-              loc=loc-(loc%8)-8;
-            SDL_ShowCursor(1);
-          }
-
-          if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN))
-          {
-            if (loc-(loc%8)+8 < c)
-              loc=(loc-(loc%8)+8);
-          }
-
-          if (event.key.keysym.sym == SDLK_UP)
-          {
-            if (loc > 0)
-              loc--;
-          }
-
-          if (event.key.keysym.sym == SDLK_DOWN)
-          {
-            if (loc+1< c)
-              loc++;
-          }
-      } /* End of 'switch(event.type)' loop */
-    }  /* End of 'while(SDL_PollEvent(&event))' loop */
-
-
-
-    if (old_loc != loc)
-    {
-      int start;
-      SDL_BlitSurface( bkg, &arrow_area, screen, NULL);
-
-      start = loc;
-      for (i = start; i < c; i++)
-      {
-        spot.x = 5;
-        spot.y = (i * MENU_FONT_SIZE) + 18;
-        if (i == loc)
-          SDL_BlitSurface(pointer, NULL, screen, &spot);
-      }
-
-      SDL_Flip(screen);
-    }
-
-      SDL_Delay(40);
-      old_loc = loc;
-  }   /*   End of 'while(!stop)' loop  */
-
-  SDL_FreeSurface(pointer);
-  SDL_FreeSurface(left);
-  SDL_FreeSurface(right);
-  SDL_FreeSurface(bkg);
-  pointer = left = right = bkg = NULL;
-
-  if (stop == 2)
-  {
-    LOG("Player pressed 'Esc' - leaving TestLesson\n");
-    return 1;
-  }
-
-  /* Getting to here means "stop == 1", try to run chosen script: */
-  if (load_script(fn) != 0)
-  {
-    fprintf(stderr, "load_script() failed to load '%s'\n");
-    return 0; // bail if any errors occur
-  }
-
-  DEBUGCODE { fprintf(stderr, "Attempting to run script: %s\n", fn); }
-
-  run_script();
-
-  /* FIXME - shouldn't we show the cursor if returning in other code paths? */
-  SDL_ShowCursor(1);
-
-  LOG("Leave TestLesson()\n");
-
-  return 1; 
-}
-
-
-
-/************************************************************************/
-/*                                                                      */ 
-/*         "Private" functions (local to scripting.c)                   */
-/*                                                                      */
-/************************************************************************/
-
-
-static char* get_quote(const char* in)
-{
-    int start, finish;
-    char *out;
-
-    for (start=0; start<strlen(in) && in[start] != '"'; start++);  // find the first "
-
-    if (start >= strlen(in)) return 0; // return null string if no " found
-
-    start++; // move past the "
-    
-    for (finish=start; finish<strlen(in) && in[finish] != '"'; finish++); // find the next "
-
-    if (finish >= strlen(in)) return 0; // return null string if no " found
-    
-    out = malloc(finish-start+2);
-    
-    snprintf(out, finish-start+1, &in[start]);
-    out[finish-start]=0;
-    
-    return out;
-}
-
-
-static int get_int(const char* in)
-{
-    char *t = get_quote(in);
-    int ans=-1;
-    if (t) {
-        ans = atoi(t);
-        free(t);
-    }
-    return ans;
-}
-
-
-static char hex2int(char b, char s)
-{
-    char ans=0;
-        
-    if      ((b>='0') && (b<='9'))       ans=16*(b-'0');
-    else if ((b>='A') && (b<='F'))       ans=16*(b-'A'+10);
-    else if ((b>='a') && (b<='f'))       ans=16*(b-'a'+10);
-    
-    if      ((s>='0') && (s<='9'))       ans+=(s-'0');
-    else if ((s>='A') && (s<='F'))       ans+=(s-'A'+10);
-    else if ((s>='a') && (s<='f'))       ans+=(s-'a'+10);
-
-    return ans;
-}
-
-
-static SDL_Color* get_color(const char* in)
-{
-    char* col;
-    SDL_Color* out=malloc(sizeof(SDL_Color));
-    col = get_quote(in);
-    
-    if ((strlen(col)==7) && (col[0] == '#')) {
-        out->r = hex2int( col[1], col[2] );
-        out->g = hex2int( col[3], col[4] );
-        out->b = hex2int( col[5], col[6] );
-    }
-    
-    free(col);
-    
-    return out;
-}
-
-scriptType* curScript = NULL;
-pageType* curPage = NULL;
-itemType* curItem = NULL;
-
-static int load_script(const char* fn)
-{
-  int i;
-  char str[FNLEN];
-  FILE* f = NULL;
-    
-  DEBUGCODE
-  {
-    fprintf(stderr, "\nEnter load_script() - attempt to load '%s'\n", fn);
-  }
-
-  if (curScript)
-  {
-    LOG( "previous script in memory, removing now!\n");
-    close_script();
-  }
-    
-
-  f = fopen(fn, "r");
-
-  if (f == NULL)
-  {
-    fprintf(stderr, "error loading script %s\n", fn);
-    return -1;
-  }
-
-  do
-  {
-    fscanf(f, "%[^\n]\n", str);
-    if (strncmp("<script", str, 7) == 0)
-    {
-      /* -- allocate space for the lesson info -- */
-      curScript = (scriptType*)calloc(1, sizeof(scriptType));
-      for (i = 7; i < strlen(str) && str[i] != '>'; i++) 
-      {
-        if ((str[i] == 't') && strncmp("title", &str[i], 5) == 0)
-          curScript->title = get_quote(&str[i + 5]);
-
-        if ((str[i]=='b') && strncmp("bgcolor", &str[i], 7) == 0)
-          curScript->bgcolor = get_color(&str[i + 7]);
-
-        if ((str[i]=='b') && strncmp("background", &str[i], 10) == 0)
-          curScript->background = get_quote(&str[i + 10]);
-
-        if ((str[i]=='f') && strncmp("fgcolor", &str[i], 7) == 0) 
-          curScript->fgcolor = get_color(&str[i + 7]); 
-      }
-    }
-    else if (strncmp("<page", str,  5)==0)
-    {
-      if (curScript==NULL)
-      {
-        fprintf(stderr, "CRITICAL XML ERROR: <page> should be in a <script> in file %s line (todo)", fn); exit(1);
-      }
-
-      if (curScript->pages==NULL)
-      {
-        curPage = (pageType *)calloc(1,sizeof(pageType));
-        curPage->prev = curPage;
-        curScript->pages = curPage; 
-      }
-      else
-      {
-        curPage->next = (pageType*)calloc(1, sizeof(pageType));
-        curPage->next->prev = curPage;
-        curPage = curPage->next;
-      }
-
-      for (i = 5; i < strlen(str) && str[i]!='>'; i++)
-      {
-        if ((str[i] == 'b') && strncmp("background", &str[i], 10) == 0) 
-          curPage->background = get_quote(&str[i + 10]);
-
-        if ((str[i]== 't') && strncmp("title", &str[i], 5) == 0) 
-          curPage->title = get_quote(&str[i + 5]);
-
-        if ((str[i] == 'b') && strncmp("bgcolor", &str[i], 7) == 0) 
-          curPage->bgcolor = get_color(&str[i + 7]);
-
-        if ((str[i] == 'f') && strncmp("fgcolor", &str[i], 7) == 0) 
-          curPage->fgcolor = get_color(&str[i + 7]);
-      }
-    }
-    else if (strncmp("<text", str,  5) == 0)
-    {
-      if (curPage == NULL)
-      {
-        fprintf(stderr, "CRITICAL XML ERROR: <text> should be in a <page> in file %s line (todo)", fn); exit(1);
-      }
-
-      if (curPage->items == NULL) 
-      {
-        curItem = (itemType*)calloc(1, sizeof(itemType));
-        curPage->items = curItem;
-      }
-      else
-      {
-        curItem->next = (itemType*)calloc(1, sizeof(itemType));
-        curItem = curItem->next;
-      }
-
-      curItem->type = itemTEXT;
-      curItem->x = curItem->y = -1;
-
-      for (i = 5; i<strlen(str) && str[i]!='>'; i++)
-      {
-        if ((str[i] == 's') && strncmp("size", &str[i], 4) == 0)
-          curItem->size = (char)get_int(&str[i + 4]);
-
-        if ((str[i] == 'a') && strncmp("align", &str[i], 5) == 0)
-        {
-          char* t = get_quote(&str[i+5]);
-
-          if (strlen(t)>=1)
-          {
-            if ((t[0] == 'l') || (t[0]=='L'))
-              curItem->align='l';	// left
-            if ((t[0] == 'c') || (t[0]=='C'))
-              curItem->align='c';	// center
-            if ((t[0] == 'r') || (t[0]=='R'))
-              curItem->align='r';	// right
-            if ((t[0] == 'm') || (t[0]=='M'))
-              curItem->align='c';	// let 'm'iddle work as "center"
-          }
-          free(t);
-        }
-
-        if ((str[i] == 'c') && strncmp("color", &str[i], 5) == 0)
-           curItem->color = get_color(&str[i + 5]);
-
-        if ((str[i]== 'x') && strncmp(" x=", &str[i - 1], 3) == 0)
-           curItem->x = get_int(&str[i + 2]);
-
-        if ((str[i] == 'y') && strncmp(" y=", &str[i - 1], 3) == 0)
-           curItem->y = get_int(&str[i + 2]);
-      }
-
-      /* --- grab the text between <text> and </text> --- */
-      {
-        int start, finish;
-
-        for (start = 5; start < strlen(str) - 5 && str[start] != '>'; start++);
-
-        start++; // advance passed the '>'
-
-        for (finish = strlen(str) - 6; finish > 5; finish--)
-           if (strncmp( "</text>", &str[finish], 7) == 0)
-             break;
-
-        finish--; // advance passed the '<'
-
-        if (start <= finish)
-        {
-          curItem->data = (char*)calloc(1, finish - start + 2);
-          strncpy(curItem->data, &str[start], finish - start + 1);
-        }
-        else
-        {
-          if (start == finish + 1)
-          {
-            curItem->data = (char*)calloc(1, 2);
-            curItem->data[0]=' ';
-          }
-        }
-      }
-
-    } 
-    else if (strncmp("<img", str, 4) == 0)
-    {
-      if (curPage == NULL)
-      {
-        fprintf(stderr,
-                "CRITICAL XML ERROR: <img> should be in a <page> in file %s line (todo)",
-               fn);
-        exit(1); //FIXME should call cleanup() or maybe just return without exiting
-      }
-
-      if (curPage->items == NULL)
-      {
-        curItem = (itemType*)calloc(1, sizeof(itemType));
-        curPage->items = curItem;
-      }
-      else 
-      {
-        curItem->next = (itemType*)calloc(1, sizeof(itemType));
-        curItem = curItem->next;
-      }
-
-      curItem->type = itemIMG;
-      curItem->x = curItem->y = -1;
-
-      for (i = 5; i < strlen(str); i++) 
-      {
-        if ((str[i] == 'o') && strncmp("onclickplay", &str[i], 11) == 0)
-          curItem->onclick = get_quote(&str[i + 3]);
-
-        if ((str[i] == 'x') && strncmp(" x=", &str[i - 1], 3) == 0)
-          curItem->x = get_int(&str[i + 2]);
-
-        if ((str[i] == 'y') && strncmp(" y=", &str[i - 1], 3) == 0)
-          curItem->y = get_int(&str[i + 2]);
-
-        if ((str[i] == 's') && strncmp("src", &str[i], 3) == 0)
-          curItem->data = get_quote(&str[i + 3]);
-
-        if ((str[i] == 'a') && strncmp("align", &str[i], 5) == 0)
-        {
-          char* t = get_quote(&str[i + 5]);
-
-          if (strlen(t) >= 1)
-          {
-            if ((t[0] == 'l') || (t[0] == 'L'))
-               curItem->align='l';	// left
-
-            if ((t[0] == 'c') || (t[0]=='C'))
-               curItem->align='c';	// center
-
-            if ((t[0] == 'r') || (t[0]=='R'))
-               curItem->align='r';	// right
-
-            if ((t[0] == 'm') || (t[0]=='M'))
-               curItem->align='c';	// let 'm'iddle work as "center"
-          }
-          free(t);
-        }
-      }
-    }
-    else if (strncmp("<wav", str, 4) == 0)
-    {
-      if (curPage == NULL)
-      { 
-        fprintf(stderr,
-                "CRITICAL XML ERROR: <wav> should be in a <page> in file %s line (todo)",
-                fn);
-        exit(1);  /* FIXME call Cleanup() to exit */
-      }
-
-      if (curPage->items == NULL)
-      {
-        curItem = (itemType*)calloc(1, sizeof(itemType));
-        curPage->items = curItem;
-      } 
-      else 
-      {
-        curItem->next = (itemType*)calloc(1, sizeof(itemType));
-        curItem = curItem->next;
-      }
-
-      curItem->type = itemWAV;
-      curItem->loop = 0;
-
-      for (i =5 ; i < strlen(str); i++)
-      {
-        if ((str[i] == 's') && strncmp("src", &str[i], 3) ==0 )
-          curItem->data = get_quote(&str[i + 3]);
-
-        if ((str[i] == 'l') && strncmp("loop", &str[i], 4) == 0)
-        {
-          char* t = get_quote(&str[i + 4]);
-
-          if (strlen(t) >= 1)
-          {
-            if ((t[0] == 't') || (t[0]=='T'))
-              curItem->loop = 1;
-          } 
-          free(t);
-        }
-      }
-    }
-    else if (strncmp("<prac", str, 5) == 0)
-    {
-      if (curPage == NULL)
-      {
-        fprintf(stderr,
-                "CRITICAL XML ERROR: <prac> should be in a <page> in file %s line (todo)",
-                fn);
-        exit(1); /* FIXME call cleanup() rather than exit() */
-      }
-
-      if (curPage->items == NULL)
-      {
-        curItem = (itemType*)calloc(1, sizeof(itemType));
-        curPage->items = curItem;
-      }
-      else
-      {
-        curItem->next = (itemType*)calloc(1, sizeof(itemType));
-        curItem = curItem->next;
-      }
-
-      curItem->type = itemPRAC;
-
-      for (i = 5; i < strlen(str) && str[i] != '>'; i++)
-      {
-        if ((str[i] == 's') && strncmp("size", &str[i], 4) == 0) 
-          curItem->size = (char)get_int( &str[i + 4]);
-
-        if ((str[i] == 'g') && strncmp("goal", &str[i], 4) == 0) 
-          curItem->goal = (char)get_int(&str[i + 4]);
-
-        if ((str[i] == 'a') && strncmp("align", &str[i], 5) == 0)
-        {
-          char* t = get_quote(&str[i + 5]);
-
-          if (strlen(t) >= 1)
-          {
-            if ((t[0] == 'l') || (t[0]=='L'))
-              curItem->align = 'l';	// left
-            if ((t[0] == 'c') || (t[0]=='C'))
-              curItem->align = 'c';	// center
-            if ((t[0] == 'r') || (t[0]=='R'))
-              curItem->align = 'r';	// right
-            if ((t[0] == 'm') || (t[0]=='M'))
-              curItem->align = 'c';	// let 'm'iddle work as "center"
-          }
-                   free(t);
-        }
-
-        if ((str[i] == 'c') && strncmp("color", &str[i], 5) == 0)
-          curItem->color = get_color(&str[i + 5]);
-      }
-
-      { /* --- grab the text between <prac> and </prac> --- */
-        int start, finish;
-
-        for (start = 5; start < strlen(str) - 5 && str[start] != '>'; start++);
-
-        start++; // advance passed the '>/* --- grab the text between <prac> and </prac> --- */'
-
-        for (finish = strlen(str) - 6; finish > 5; finish--)
-          if (strncmp("</prac>", &str[finish], 7) == 0)
-            break;
-
-        finish--; // advance passed the '<'
-
-        if (start <= finish)
-        {
-          curItem->data = (char*)calloc(1, finish - start + 2);
-          strncpy(curItem->data, &str[start], finish - start + 1);
-        }
-        else
-        {
-          if (start == finish + 1)
-          {
-            curItem->data = (char*)calloc(1, 2);
-            curItem->data[0]=' ';
-          }
-        }
-      }
-    }
-    else if (strncmp("<waitforinput", str, 13) == 0)
-    { 
-      if (curPage == NULL)
-      {
-        fprintf(stderr,
-               "CRITICAL XML ERROR: <waitforinput> should be in a <page> in file %s line (todo)",
-                fn);
-        exit(1);
-      }
-
-      if (curPage->items == NULL)
-      {
-        curItem = (itemType*)calloc(1, sizeof(itemType));
-        curPage->items = curItem;
-      } 
-      else
-      {
-        curItem->next = (itemType*)calloc(1, sizeof(itemType));
-        curItem = curItem->next;
-      }
-
-      curItem->type = itemWFIN;
-
-    }
-    else if (strncmp("<waitforchar",  str, 12) == 0)
-    { 
-      if (curPage == NULL)
-      {
-        fprintf(stderr,
-               "CRITICAL XML ERROR: <waitforchar> should be in a <page> in file %s line (todo)",
-               fn);
-        exit(1);
-      }
-
-      if (curPage->items == NULL)
-      {
-        curItem = (itemType*)calloc(1, sizeof(itemType));
-        curPage->items = curItem;
-      }
-      else
-      {
-        curItem->next = (itemType*)calloc(1, sizeof(itemType));
-        curItem = curItem->next;
-      }
-
-      curItem->type = itemWFCH;
-    }
-    else if (strncmp("</",str, 2) == 0)
-    {
-      /* do nothing */
-    }
-    else
-      fprintf(stderr, "not recognized: %s\n", str); 
-
-  } while(!feof(f));
-
-  fclose(f);
-
-  LOG("Leave load_script()\n");
-
-  return 0;
-}
-
-
-static void run_script(void)
-{
-  /* FIXME FNLEN doesn't make sense for size of these arrays */
-  Mix_Chunk* sounds[FNLEN] = {NULL};
-
-  /* --- for on mouse click on an image --- */
-  Mix_Chunk* clickWavs[FNLEN] = {NULL};
-  SDL_Rect   clickRects[FNLEN];
-
-  LOG("\nEnter run_script()\n");
-
-  if (!curScript)
-  {
-    fprintf(stderr, "run_script() - Error: curScript is NULL\n");
-    return;
-  }
-
-  curPage = curScript->pages;
-
-  while (curPage)
-  {
-    int y = 0;
-    int skip = 0;
-    int numWavs = 0;
-    int numClicks = 0;
-
-    curItem = curPage->items;
-
-    /* --- setup background color --- */
-    if (curPage->bgcolor)
-      SDL_FillRect( screen, NULL, COL2RGB(curPage->bgcolor));
-    else if (curScript->bgcolor)
-      SDL_FillRect(screen, NULL, COL2RGB(curScript->bgcolor));
-
-    /* --- setup background image --- */
-    if (curPage->background)
-    {
-      SDL_Surface* img = LoadImage(curPage->background, IMG_ALPHA|IMG_NOT_REQUIRED);
-      SDL_BlitSurface(img, NULL, screen, NULL);
-      SDL_FreeSurface(img);
-    }
-    else if (curScript->background)
-    {
-      SDL_Surface* img = LoadImage(curScript->background, IMG_ALPHA|IMG_NOT_REQUIRED);
-      SDL_BlitSurface(img, NULL, screen, NULL);
-      SDL_FreeSurface(img);
-    }
-
-    /* --- go through all the items in the page --- */
-    while (curItem)
-    {
-      switch (curItem->type)
-      {
-        case itemIMG:
-        {
-          SDL_Surface* img = LoadImage(curItem->data, IMG_ALPHA|IMG_NOT_REQUIRED);
-          if (img)
-          {
-            /* --- figure out where to put it! --- */
-            SDL_Rect loc;
-            loc.w = img->w;
-            loc.h = img->h;
-
-            /* --- if user specifies y location, use it --- */
-            if (curItem->y >= 0)
-            {
-              loc.y = curItem->y;
-            }
-            else
-            {
-              loc.y = y;
-              y += loc.h;
-            }
-
-            /* --- if user specifies x location, use it --- */
-            if (curItem->x >= 0)
-            {
-              loc.x = curItem->x;
-            }
-            else
-            {
-              switch (curItem->align)
-              {
-                case 'r':
-                  loc.x = (screen->w) - (loc.w);
-                  break;
-                case 'c':
-                  loc.x = ((screen->w) - (loc.w))/2;
-                  break;
-                default:
-                  loc.x = 0;
-                  break;
-              }
-            }
-
-            /* --- and blit! --- */
-            SDL_BlitSurface(img, NULL, screen, &loc);
-
-            /* --- does it do click and play --- */
-            if (curItem->onclick)
-            {
-              if (settings.sys_sound)
-                clickWavs[numClicks] = LoadSound(curItem->onclick);
-              clickRects[numClicks].x = loc.x;
-              clickRects[numClicks].y = loc.y;
-              clickRects[numClicks].w = loc.w;
-              clickRects[numClicks].h = loc.h;
-              numClicks++;
-            }
-          }
-          SDL_FreeSurface(img);
-          break;
-        }
-
-        case itemTEXT:
-        {
-          TTF_Font* myFont;
-          SDL_Surface* img;
-          SDL_Color* col;
-
-          int shown, toshow, w, h; // used to wrap text
-          char tmp[FNLEN];   // used to hold temp text for wrapping
-
-          /* --- create font & render text --- */
-          if (curItem->size > 0)
-            myFont = LoadFont(settings.theme_font_name, (int)curItem->size);
-          else
-            myFont = LoadFont(settings.theme_font_name, 24); // default size is 24
-
-          if (curItem->color)
-            col = curItem->color;
-          else if (curPage->fgcolor)
-            col = curPage->fgcolor;
-          else if (curScript->fgcolor)
-            col = curScript->fgcolor;
-          else 
-            col = &white;
-
-          shown = 0;
-
-
-          do 
-          {
-            int ok = 0;
-
-            if ((shown > 0) && (curItem->data[shown] == ' '))
-              shown++;
-            strncpy(tmp, &curItem->data[shown], FNLEN - 1);
-            tmp[FNLEN - 1] = 0;
-            tmp[strlen(curItem->data) - shown] = 0;
-
-            for (toshow = strlen(&curItem->data[shown]); !ok; toshow--)
-            {
-              if (toshow + 1 > FNLEN)
-                continue;
-
-              tmp[toshow] = 0;
-              TTF_SizeText(myFont, tmp, &w, &h);
-
-              if (w + 20 < screen->w)
-                ok = 1;
-            }
-
-            shown += toshow + 1;
-
-            img = TTF_RenderUTF8_Blended(myFont, tmp, *col);
-
-            if (img)
-            {
-              SDL_Rect loc;
-              /* --- figure out where to put it! --- */
-              loc.w = img->w;
-              loc.h = img->h;
-
-              /* --- if user specifies y location, use it --- */
-              if (curItem->y >= 0)
-                loc.y = curItem->y;
-              else 
-                loc.y=y; y+=loc.h;
-
-              /* --- if user specifies x location, use it --- */
-              if (curItem->x >= 0)
-                loc.x = curItem->x;
-              else 
-              {
-                switch (curItem->align)
-                {
-                  case 'r':
-                    loc.x = (screen->w) - (loc.w);
-                    break;
-                  case 'c':
-                    loc.x = ((screen->w) - (loc.w))/2;
-                    break;
-                  default:
-                    loc.x = 0;
-                  break;
-                }
-              }
-
-              /* --- and blit! --- */
-              SDL_BlitSurface( img, NULL, screen, &loc );
-              SDL_FreeSurface( img );
-            }
-                    
-          } while (shown + 1 < strlen(curItem->data));
-
-          TTF_CloseFont(myFont);
-          break;
-        }
-
-
-        case itemWAV:
-        {
-          // HACK, we need to make sure no more than 8 sounds or so..
-          sounds[numWavs] = LoadSound( curItem->data );
-          Mix_PlayChannel( numWavs, sounds[numWavs], -curItem->loop );
-          numWavs++;
-          break;
-        }
-
-
-        case itemWFIN:
-        {
-          int done = 0;
-
-          // Make sure everything is on screen 
-          SDL_Flip(screen);
-
-          while (!done)
-          {
-            SDL_Delay(100);
-
-            while (SDL_PollEvent(&event))
-            {
-              switch (event.type)
-              {
-                case SDL_MOUSEBUTTONDOWN:
-                {
-                  int j;
-
-                  for (j=0; j<numClicks; j++) 
-                  {
-                    if (inRect(clickRects[j], event.button.x, event.button.y))
-                     Mix_PlayChannel(numWavs + j, clickWavs[j], 0);
-                  }
-                  break;
-                }
-
-                case SDL_QUIT:
-                {
-                  curPage = NULL;
-                  done = 1;
-                  break;
-                }
-
-                case SDL_KEYDOWN: 
-                {
-                  switch (event.key.keysym.sym)
-                  {
-                    case SDLK_ESCAPE: 
-                      curPage = NULL;
-                      done = 1;
-                      break;  // quit
-                    case SDLK_LEFT: 
-                      curPage = curPage->prev;
-                      done = 1;
-                      break;
-                    case SDLK_RIGHT:
-                    case SDLK_SPACE:
-                    case SDLK_RETURN:
-                      curPage = curPage->next;
-                      skip = 1;
-                      done = 1;
-                      break;
-                    default:
-                      break;
-                  };
-
-                  break;
-                }
-              }
-            }
-          }
-        }
-        break;
-
-
-        case itemWFCH:
-        {
-          int done = 0;
-          // Make sure everything is on screen 
-          SDL_Flip(screen);
-
-          while (!done)
-          {
-            SDL_Delay(100);
-            while (SDL_PollEvent(&event))
-            {
-              switch (event.type)
-              {
-                case SDL_QUIT:
-                {
-                  curPage = NULL;
-                  done = 1;
-                  break;
-                }
-
-                case SDL_KEYDOWN: 
-                {
-                  switch (event.key.keysym.sym)
-                  {
-                    case SDLK_ESCAPE: 
-                    {
-                      curPage = NULL;
-                      done = 1;
-                      break;  // quit
-                    }
-                    case SDLK_p:
-                    {
-                      curPage = curPage->next;
-                      done = 1;
-                      break;
-                    }
-                    default:
-                      break;
-                  };
-                  break;
-                }
-              }
-            }
-          }
-        }
-        break;
-
-        case itemPRAC:
-        {
-          wchar_t wide_buf[FNLEN];
-          ConvertFromUTF8(wide_buf, curItem->data);
-          if (curItem->goal > 0)
-          {
-            //printf( "goal is %d\n", curItem->goal );
-            Phrases(wide_buf);
-          }
-          else
-          {
-            //printf( "No goal \n" );
-            Phrases(wide_buf);
-          }
-          break;
-        }
-
-        default:
-        {
-          /* do nothing */
-        }
-      }
-
-      if (curItem->next == NULL && curPage != NULL)
-      {
-        if (!skip)
-        {
-          curPage = curPage->next;
-          skip = 0;
-        }
-        break;
-      }
-      else
-        curItem = curItem->next;
-    }
-    SDL_Flip(screen);
-    SDL_Delay(30);
-        
-        
-    /* --- cleanup memory --- changing pages --- */
-    { 
-      int i;
-
-      if (settings.sys_sound)
-      {
-        for (i=0; i<numWavs; i++)
-        {
-          Mix_HaltChannel(i);
-          Mix_FreeChunk(sounds[i]);
-        }
-
-        for (i = 0; i < numClicks; i++)
-        {
-          Mix_HaltChannel(i + numWavs);
-          Mix_FreeChunk(clickWavs[i]);
-        }
-      }
-    }
-
-  } /* --- End of "while (curPage)" loop ----*/
-
-  LOG("Leave run_script()\n");
-}
-
-
-static void clear_items(itemType* i)
-{
-    itemType* n;
-
-    /* if i is null, will return harmlessly: */
-    while (i) {
-        n = i->next;  // remember the next guy
-
-        /* -- remove any data we are pointing to -- */
-        free(i->data);
-        free(i->onclick);
-        free(i->color);
-
-        /* -- remove ourselves --*/
-        free(i);
-
-        /* -- on to the next guy! -- */
-        i = n;
-    }
-}
-
-static void clear_pages(pageType* p)
-{
-    pageType* n;
-
-    /* if p is null, will return harmlessly: */
-    while (p) {
-        n = p->next;  // remember the next guy
-
-        /* -- remove all of our sub elements -- */
-        clear_items(p->items);
-
-        /* -- free anything we are pointing to --- */
-        free(p->background);
-        free(p->title);
-        free(p->bgcolor);
-        free(p->fgcolor);
-
-        /* -- free ourselves -- */
-        free(p);
-
-        /* -- on to the next --*/
-        p = n;
-    }
-}
-
-
-static void close_script(void)
-{
-  if (curScript)
-  {
-    /* -- remove all the pages we have --*/
-    clear_pages(curScript->pages);
-
-    /* -- remove attributes we are pointing to -- */
-    free(curScript->title);
-    free(curScript->bgcolor);
-    free(curScript->fgcolor);
-    free(curScript->background);
-
-    /* -- free yourself -- */
-    free(curScript); 
-
-    /* -- and remember you did -- */
-    curScript = NULL;
-  }
-}
-
-
-
-

Deleted: tuxtype/branches/tuxtype-soc-mh/scripting.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/scripting.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/scripting.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,64 +0,0 @@
-/***************************************************************************
- -  file: scripting.h
- -  description: types for scripting 
--------------------
-    begin                : Sun Dec 28, 2003
-    copyright            : Jesse Andrews (C) 2003
-    email                : tuxtype-dev at tux4kids.net
-***************************************************************************/
-
-/***************************************************************************
-*                                                                         *
-*   This program is free software; you can redistribute it and/or modify  *
-*   it under the terms of the GNU General Public License as published by  *
-*   the Free Software Foundation; either version 2 of the License, or     *
-*   (at your option) any later version.                                   *
-*                                                                         *
-***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-
-enum { itemTEXT, itemIMG, itemWAV, itemPRAC, itemWFIN, itemWFCH };
-
-/* linked list of elements for a page */
-struct item {
-        char type;		// text or img or wav enum type?
-        char *data;		// holds text/location for file (sound/image)
-        char *onclick;		// holds additional data
-        char size;		// holds font size if applicable
-        char align;             // holds 'L'eft, 'R'ight, 'C'enter for alignment
-        char loop;		// holds if sound files loop
-        int  goal;		// goal for practice session
-	int  x,y;		// for absolute positioning
-        SDL_Color *color;       // holds text color
-        
-        struct item *next; // the linked list part ... 
-};
-
-typedef struct item itemType;
-
-/* linked list of pages for a lesson */
-struct page {
-    itemType *items;	// linked list of elements
-    char *background;		// background image
-    char *title;		// title of the page
-    SDL_Color *bgcolor;		// background color
-    SDL_Color *fgcolor;		// default text color
-    
-    struct page *next;         // the linked list part ...
-    struct page *prev;         // the doubly-linked list part ...
-};
-
-typedef struct page pageType;
-
-struct script {
-    pageType *pages;		// linked list of pages
-    char *title;		// title of lesson
-    SDL_Color *bgcolor;         // default background color for all pages
-    SDL_Color *fgcolor;         // default foreground color for all text
-    char *background;		// default background image for all pages
-}; 
-
-typedef struct script scriptType;
-

Deleted: tuxtype/branches/tuxtype-soc-mh/setup.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/setup.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/setup.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,532 +0,0 @@
-/***************************************************************************
-                          setup.c 
- -  description: Init SDL
-                             -------------------
-    begin                : Thu May 4 2000
-    copyright            : (C) 2000 by Sam Hart
-                         : (C) 2003 by Jesse Andrews
-    email                : tuxtype-dev at tux4kids.net
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-
-#define NUM_PATHS 4
-
-
-/* FIXME this is a hack that can have unintended results */
-/* if the program is run from a path that has 'data' as a */
-/* subdir */
-const char PATHS[NUM_PATHS][FNLEN] = 
-{
-  DATA_PREFIX"/share/"PACKAGE"/data",
-  "/usr/share/"PACKAGE"/data",
-  "/usr/local/share/"PACKAGE"/data",
-  "./data"
-};
-
-uint fs_res_x = 0;
-uint fs_res_y = 0;
-
-/* Local function prototypes: */
-static int load_settings_fp(FILE* fp);
-static int load_settings_filename(const char* fn);
-
-/***************************
-	GraphicsInit: Initializes the graphic system
-****************************/
-void GraphicsInit(void)
-{
-  const SDL_VideoInfo* video_info = SDL_GetVideoInfo();
-  Uint32 surface_mode = 0;
-
-  if (video_info->hw_available)
-  {
-    surface_mode = SDL_HWSURFACE;
-    LOG("HW mode\n");
-  }
-  else
-  {
-    surface_mode = SDL_SWSURFACE;
-    LOG("SW mode\n");
-  }
-
-  // Determine the current resolution: this will be used as the
-  // fullscreen resolution, if the user wants fullscreen.
-  DEBUGCODE
-  {
-    fprintf(stderr, "Current resolution: w %d, h %d.\n", 
-            video_info->current_w, video_info->current_h);
-  }
-
-  /* For fullscreen, we try to use current resolution from OS: */
-  
-  fs_res_x = video_info->current_w;
-  fs_res_y = video_info->current_h;
-
-  if (settings.fullscreen == 1)
-  {
-    screen = SDL_SetVideoMode(fs_res_x, fs_res_y, BPP, SDL_FULLSCREEN | surface_mode);
-    if (screen == NULL)
-    {
-      fprintf(stderr,
-            "\nWarning: I could not open the display in fullscreen mode.\n"
-            "The Simple DirectMedia error that occured was:\n"
-            "%s\n\n", SDL_GetError());
-      settings.fullscreen = 0;
-    }
-  }
-
-  /* Either fullscreen not requested, or couldn't get fullscreen in SDL: */
-  if (settings.fullscreen == 0)
-  {
-    screen = SDL_SetVideoMode(RES_X, RES_Y, BPP, surface_mode);
-  }
-
-  /* Failed to get a usable screen - must bail out! */
-  if (screen == NULL)
-  {
-    fprintf(stderr,
-          "\nError: I could not open the display.\n"
-          "The Simple DirectMedia error that occured was:\n"
-          "%s\n\n", SDL_GetError());
-    exit(2);
-  }
-
-// 	LOG( "GraphicsInit - Initialize graphic system\n" );
-// 
-// 	DEBUGCODE {
-// 		fprintf(stderr, "-SDL Setting VidMode to %ix%ix%i\n", RES_X, RES_Y, BPP);
-// 	}
-// 
-// 	/* NOTE fullscreen vs. windowed is indicated by video_flags: */
-// 	if (settings.fullscreen)
-//         {
-// 	  video_flags = (SDL_FULLSCREEN | SDL_SWSURFACE | SDL_HWPALETTE);
-// 	} 
-//         else
-//         {
-// 	  video_flags = (SDL_SWSURFACE | SDL_HWPALETTE);
-// 	}
-// 
-// 	screen = SDL_SetVideoMode(RES_X, RES_Y, BPP, video_flags);
-// 
-// 	if (screen == NULL) {
-// 		fprintf(stderr, "Couldn't set %ix%i video mode: %s\n", RES_X, RES_Y, SDL_GetError());
-// 		exit(2);
-// 	}
-
-
-	LOG( "SDL_SetClipRect(screen, NULL):\n" );
-
-	SDL_SetClipRect(screen, NULL); // Let's set the appropriate clip rect  -- JA: is neccessary???  
-
-	LOG( "SDL_ShowCursor(0):\n" );
-
-	SDL_ShowCursor(0); // no cursor please
-
-	LOG( "SDL_WM_SetCaption(\"Tux Typing\", PACKAGE);\n" );
-
-	SDL_WM_SetCaption("Tux Typing", "tuxtype"); // Set window manager stuff
-
-	/* --- setup color we use --- */
-	black.r       = 0x00; black.g       = 0x00; black.b       = 0x00;
-        gray.r        = 0x80; gray.g        = 0x80; gray.b        = 0x80;
-	dark_blue.r   = 0x00; dark_blue.g   = 0x00; dark_blue.b   = 0x60; 
-	red.r         = 0xff; red.g         = 0x00; red.b         = 0x00;
-	white.r       = 0xff; white.g       = 0xff; white.b       = 0xff;
-	yellow.r      = 0xff; yellow.g      = 0xff; yellow.b      = 0x00; 
-
-	InitEngine();
-
-  DEBUGCODE 
-  {
-    video_info = SDL_GetVideoInfo();
-    fprintf(stderr, "-SDL VidMode successfully set to %ix%ix%i\n",
-            video_info->current_w,
-            video_info->current_h,
-            video_info->vfmt->BitsPerPixel);
-  }
-
-	LOG( "GraphicsInit():END\n" );
-}
-
-/****************************
-	LibInit : Init the SDL
-	library
-*****************************/
-void LibInit(Uint32 lib_flags)
-{
-	LOG( "LibInit():\n-About to init SDL Library\n" );
-
-	if (SDL_Init(lib_flags) < 0) 
-		/* FIXME this looks wrong - if no sys_sound, we don't init video??? */
-		if (settings.sys_sound) {
-			if (SDL_Init(SDL_INIT_VIDEO) < 0) {
-				fprintf(stderr, "Couldn't initialize SDL: %s\n",
-				SDL_GetError());
-				exit(2);
-			} else {
-				LOG( "Couldn't initialize SDL Sound\n" );
-				settings.sys_sound = 0;
-			}
-		}
-
-
-//	atexit(SDL_Quit); // fire and forget... 
-
-	LOG( "-SDL Library init'd successfully\n" );
-
-	/* FIXME should read settings before we do this: */ 
-	if (settings.sys_sound)
-        { 
-          if (Mix_OpenAudio(22050, AUDIO_S16, 1, 2048) == -1)
-          {
-            fprintf( stderr, "Warning: couldn't set 22050 Hz 8-bit audio\n - Reasons: %s\n", SDL_GetError());
-            settings.sys_sound=0;
-          }
-          else
-            LOG("Mix_OpenAudio() successful\n");
-        }
-
-	LOG( "-about to init SDL_ttf\n" );
-
-	if (TTF_Init() < 0) {
-		fprintf( stderr, "Couldn't initialize SDL_ttf\n" );
-		exit(2);
-	}
-
-//	atexit(TTF_Quit);
-
-	SDL_EnableKeyRepeat( 0, SDL_DEFAULT_REPEAT_INTERVAL );
-	/* Need this to get Unicode values from keysyms: */
-	SDL_EnableUNICODE(1);
-
-	LOG( "LibInit():END\n" );
-}
-
-/* Load the settings from a file... make sure to update SaveSettings if you change
- *  what can be saved/loaded 
- */
-void LoadSettings(void)
-{
-  char fn[FNLEN];
-// 	char setting[FNLEN];
-// 	char value[FNLEN];
-//	FILE *settingsFile;
-	
-  /* set the settings directory/file */
-
-#ifdef WIN32
-  snprintf(fn, FNLEN - 1, "userdata/settings.txt");
-  LOG("WIN32 defined\n");
-#else
-  snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/settings.txt", getenv("HOME"));
-  LOG("WIN32 not defined\n");
-#endif
-
-  DEBUGCODE { printf("LoadSettings: settings file is '%s'\n", fn ); }
-
-  LOG("LoadSettings: trying to open settings file\n");
-
-  load_settings_filename(fn);
-}
-
-
-
-/* Load the settings if given the complete pathname to the settings file.  Returns 1 if
-   able to call load_settings_fp() successfully on named file.
- */
-static int load_settings_filename(const char* fn)
-{
-  FILE* fp = fopen(fn, "r");
-
-  if (!fp)
-  {
-    fprintf(stderr, "load_settings_filename(): no theme-specific settings found%s\n",fn);
-    return;
-  }
-	
-  if (!load_settings_fp(fp))
-  {
-    fprintf(stderr, "No settings in settings file.\n");
-    fclose(fp); /* still need to close fp */
-    return 0;
-  }
-
-  /* Success! */
-  fclose(fp);
-  return 1;
-}
-
-
-/* Load the settings if given an open FILE* pointer to the settings file.  Returns 1 if
-   at least one setting value found, 0 otherwise. It does not close the FILE*.
- */
-static int load_settings_fp(FILE* fp)
-{
-  char setting[FNLEN]; /* these don't really need to be 'FNLEN' long */
-  char value[FNLEN];
-  int setting_found = 0;
-
-  if (!fp)
-  {
-    fprintf(stderr, "load_settings_fp() - FILE* parameter NULL\n");
-    return 0;
-  }
-
-  /* we load all the settings here */
-  while (!feof(fp))
-  {
-    fscanf(fp, "%[^=]=%[^\n]\n", setting, value );
-
-    DEBUGCODE {fprintf(stderr, "%s = %s", setting, value );}
-
-    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 lives to %s\n", value);}
-      settings.o_lives = atoi(value);
-      setting_found = 1;
-   }
-    else if (strncmp( setting, "mus_volume", FNLEN ) == 0 )
-    {
-      DEBUGCODE {fprintf(stderr, "LoadSettings: Setting music volume to %s\n", value);}
-      settings.mus_volume = atoi(value);
-      setting_found = 1;
-    }
-    else if (strncmp(setting, "sfx_volume", FNLEN) == 0)
-    {
-      DEBUGCODE {fprintf(stderr, "LoadSettings: Setting effects volume to %s\n", value);}
-      settings.sfx_volume = atoi(value);
-      setting_found = 1;
-    }
-    else if (strncmp(setting, "menu_music", FNLEN) == 0)
-    {
-      DEBUGCODE {fprintf(stderr, "LoadSettings: Setting menu music to %s\n", value);}
-      settings.menu_music = atoi(value);
-      setting_found = 1;
-    }
-    else if (strncmp( setting, "fullscreen", FNLEN ) == 0 )
-    {
-      settings.fullscreen = atoi(value);
-      setting_found = 1;
-    }
-    else if (strncmp( setting, "theme_font_name", FNLEN ) == 0 )
-    {
-      DEBUGCODE {fprintf(stderr, "load_settings_fp(): Setting theme font to %s\n", value);}
-      strncpy(settings.theme_font_name, value, FNLEN - 1);
-      setting_found = 1;
-    }
-    else if (strncmp( setting, "theme_locale_name", FNLEN ) == 0 )
-    {
-      DEBUGCODE {fprintf(stderr, "load_settings_fp(): Setting theme locale to %s\n", value);}
-      strncpy(settings.theme_locale_name, value, FNLEN - 1);
-      setting_found = 1;
-      fprintf(stderr, "load_settings_fp(): Setting theme locale to %s\n", value);
-    }
-    else
-      DEBUGCODE {fprintf(stderr, "load_settings_fp(): unrecognized string: %s\n", value);}
-
-  }
-
-
-  if (setting_found)
-    return 1;
-  else
-  {
-    fprintf(stderr, "load_settings_fp() - no settings in file - empty or corrupt?\n");
-    return 0;
-  }
-}
-
-
-
-/* Save the settings from a file... make sure to update LoadSettings if you change
- *  what can be saved/loaded 
- */
-void SaveSettings(void)
-{
-	char fn[FNLEN];
-	FILE* settingsFile;
-	
-	/* set the settings directory/file */
-
-	#ifdef WIN32
-		_mkdir( "userdata" );  // just in case try to create save location
-		snprintf( fn, FNLEN-1, "userdata/settings.txt" );
-	#else
-		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
-		mkdir( fn, 0755 ); // just in case try to create save location
-		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/settings.txt", getenv("HOME") );
-	#endif
-
-
-	DEBUGCODE { printf("SaveSettings: settings file is '%s'\n", fn ); }
-	
-	LOG("SaveSettings: trying to open settings file\n");
-	
-	settingsFile = fopen( fn, "w" );
-
-	if (settingsFile == NULL) {
-		printf("SaveSettings: Settings file cannot be created!\n");
-		return;
-	}
-	
-	/* Save all the settings here! */
-	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 );
-
-	fprintf( settingsFile, "mus_volume=%d\n", settings.mus_volume );
-	fprintf( settingsFile, "sfx_volume=%d\n", settings.sfx_volume );
-	fprintf( settingsFile, "menu_music=%d\n", settings.menu_music );
-	fprintf( settingsFile, "fullscreen=%d\n", settings.fullscreen);
-
-
-// 	if (screen->flags & SDL_FULLSCREEN){
-// 		fprintf( settingsFile, "fullscreen=%s\n", "1");
-// 	} else {
-// 		fprintf( settingsFile, "fullscreen=%s\n", "0");
-// 	}
-	fclose(settingsFile);
-}
-
-
-/* Check for default (English) and theme data paths and update settings struct. */
-/* Returns 0 if default data path not found, 1 if successfully located.         */
-/* If theme not found, still returns 1 but settings changed to use English.     */
-/* TODO should have this function set up the user and global settings paths.    */
-/* TODO settings should be re-loaded when theme changes.                        */
-
-int SetupPaths(const char* theme_dir)
-{
-  int i;
-  settings.use_english = 1; // default is to use English if we cannot find theme
-
-  /* First find default data path: */
-  for (i = 0; i < NUM_PATHS; i++)
-  {
-
-    DEBUGCODE
-    {
-      fprintf(stderr, "SetupPaths(): checking for '%s' as default data path\n", PATHS[i]);
-    }
-
-    if (CheckFile(PATHS[i]))
-    {
-      strncpy(settings.default_data_path, PATHS[i], FNLEN - 1);
-
-      DEBUGCODE
-      {
-        fprintf(stderr, "path '%s' found, copy to settings.default_data_path\n", PATHS[i]);
-      }
-      break;
-    }
-    else
-    {
-      DEBUGCODE
-      {
-        fprintf(stderr, "path '%s' not found.\n", PATHS[i]);
-      }
-    }
-  }
-
-  /* If we didn't find a data path, print error msg and get out: */
-  if (i >= NUM_PATHS) /* (shouldn't actually ever be > NUM_PATHS) */
-  {
-    fprintf(stderr, "SetupPaths(): Error - could not find data path.\n");
-    return 0;
-  }
-
-
-  /* Now look for theme directory: */
-  if (theme_dir != NULL)
-  {
-    char full_theme_path[FNLEN];
-    char theme_settings_path[FNLEN];
-
-    sprintf(full_theme_path, "%s/themes/%s", settings.default_data_path, theme_dir);
-
-    DEBUGCODE
-    {
-      fprintf(stderr, "SetupPaths(): checking for '%s' as theme path\n", full_theme_path);
-    }
-
-    if (CheckFile(full_theme_path)) /* Theme found - set it up! */
-    {
-      settings.use_english = 0;
-      strncpy(settings.theme_data_path, full_theme_path, FNLEN - 1);
-      DEBUGCODE
-      {
-        fprintf(stderr, "settings.theme_data_path is: %s\n", settings.theme_data_path);
-      }
- 
-      strncpy(settings.theme_name, theme_dir, FNLEN - 1);
-      /* (Need to do this in case we are changing from a theme with */
-      /* a special font to a theme that uses the default, but lacks */
-      /* an explicit statement to use the default(                  */
-      strncpy(settings.theme_font_name, DEFAULT_MENU_FONT, FNLEN);
-      
-
-      /* Load fontname or any other theme-specific settings: */
-      sprintf(theme_settings_path, "%s/settings.txt", full_theme_path);
-
-      DEBUGCODE
-      {
-        fprintf(stderr, "theme_settings_path is: %s\n", theme_settings_path);
-      }
-
-      load_settings_filename(theme_settings_path);
-    }
-    else /* Theme not found! */
-    {
-      settings.use_english = 1; // default is to use English if we cannot find theme
-      strcpy(settings.theme_name, "");
-      strncpy(settings.theme_font_name, DEFAULT_MENU_FONT, FNLEN);
-      strncpy(settings.theme_locale_name, DEFAULT_LOCALE,FNLEN);
-      fprintf(stderr, "SetupPaths(): could not find '%s'\n", full_theme_path);
-    }
-  }
-  else /* No theme name passed as arg so just use English: */
-  {
-    settings.use_english = 1; // default is to use English if we cannot find theme
-    strcpy(settings.theme_name, "");
-    strncpy(settings.theme_locale_name, DEFAULT_LOCALE,FNLEN);
-  }
-
-
-  DEBUGCODE
-  {
-    fprintf(stderr, "Leaving SetupPaths():\n");
-    fprintf(stderr, "default_data_path: '%s'\n", settings.default_data_path);
-    fprintf(stderr, "theme_data_path: '%s'\n\n", settings.theme_data_path);
-  }
-  return 1;	
-}
-
-
-void Cleanup(void)
-{
-  SDL_FreeSurface(screen);
-  screen = NULL;
-
-  SDL_Quit();
-  TTF_Quit();
-}

Deleted: tuxtype/branches/tuxtype-soc-mh/snow.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/snow.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/snow.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,272 +0,0 @@
-/***************************************************************************
- -  file: snow.c
- -  description: this file contains snow for the cascade game
--------------------
-begin                : March 12, 2003
-copyright            : (C) 2003 Jesse Andrews
-email                : tuxtype-dev at tux4kids.net
-***************************************************************************/
-
-/***************************************************************************
-*                                                                         *
-*   This program is free software; you can redistribute it and/or modify  *
-*   it under the terms of the GNU General Public License as published by  *
-*   the Free Software Foundation; either version 2 of the License, or     *
-*   (at your option) any later version.                                   *
-*                                                                         *
-***************************************************************************/
-
-#include <stdlib.h>
-#include "SDL.h"
-
-/* while it looks like you can just
- * change the number of planes, flakes,
- * etc and it will work all right, it is not
- * true.  Do not fiddle with number unless you
- * change the rest of the code to be the same!
- */
-
-#define NUM_PLANES 3
-
-extern SDL_Surface *screen;
-SDL_Surface* bkg;
-
-Uint16 snow_color;
-
-int wind = 0;
-int SNOW_on = 0;
-
-int NUM_FLAKES = 300;
-int PER_PLANE = 100; // should equal NUM_FLAKES/NUM_PLANES
-
-/* to get the real x location divide by 8 (>>3)
- */
-struct {
-	int x;
-	int y;
-} flake[300];
-
-/* used for the SDL_UpdateRects */
-SDL_Rect SNOW_rects[1000];
-
-/* pass add_wind +/- 1 --- it just adds a fraction in that direction! */
-void add_wind( int dir ) {
-
-	/* don't let the wind blow too hard */
-	if ( wind * dir > 16 )
-		return;
-	
-	if (dir > 0)
-		wind++;
-	else
-		wind--;
-}
-
-/* ### INTERNAL FUNCTION ### 
- * move_snow: updates the location of the flakes
- * based upon the wind and different "planes"
- * of the flakes
- */
-void move_snow(void) {
-	int i;
-	static int slowframe=1;
-	int ws=wind;
-
-	slowframe = !slowframe;
-	/* even though we only move the "slowest" every other frame,
-	 * the code is still updating them every single frame!!!
-	 * the SNOW_Rect data structure will need to be updated to fix this!
-	 * slowframe just cycles between updating the slowest and not!
-	 */
-	if (slowframe) {
-		for (i = 0; i<PER_PLANE; i++) {
-			flake[i].x += ws;
-			flake[i].y ++;
-		}
-	}
-
-	for (i = PER_PLANE; i<PER_PLANE<<1; i++) {
-		flake[i].x += ws;
-		flake[i].y += 1;
-	}
-
-	ws<<=1;
-	for (i = PER_PLANE<<1; i<NUM_FLAKES; i++) {
-		flake[i].x += ws;
-		flake[i].y += 2;
-	} 
-
-	for (i = 0; i<NUM_FLAKES; i++) {
-		/* if a flake hits the bottom, move to top randomly */
-		if (flake[i].y >= 478) {
-			flake[i].y = 0;
-			flake[i].x = (int)(8*639.0*rand()/(RAND_MAX+1.0));
-		}
-
-		/* if a flake hists the edge, move to the other edge randomly */
-		if (flake[i].x >= 638<<3) {
-			flake[i].x = 0;
-			flake[i].y = (int)(478.0*rand()/(RAND_MAX+1.0));
-		} else if (flake[i].x < 0) {
-			flake[i].x = 8*637;
-			flake[i].y = (int)(478.0*rand()/(RAND_MAX+1.0));
-		}
-
-		/* the first NUM_FLAKES are for erasing the last frame's FLAKES */
-		SNOW_rects[i].x = SNOW_rects[NUM_FLAKES+i].x;
-		SNOW_rects[i].y = SNOW_rects[NUM_FLAKES+i].y;
-		/* the next NUM_FLAKES are for bliting the new positions this frame */
-		SNOW_rects[NUM_FLAKES+i].x = flake[i].x>>3;
-		SNOW_rects[NUM_FLAKES+i].y = flake[i].y;
-	}
-}
-
-/* SNOW_draw: updates the screen surface
- * with the new flake pixels
- * note: y<<9 + y<<7 is short for y*640
- */
-void SNOW_draw(void) {
-	int i;
-	Uint16 *to;
-
-	/* we only draw if we are on and haven't toggled (see SNOW_Erase for more info */
-	if (SNOW_on!=1)
-		return;
-
-	for (i=0; i<NUM_FLAKES; i++) {
-		to = screen->pixels;
-		to += (SNOW_rects[NUM_FLAKES+i].y<<9) + (SNOW_rects[NUM_FLAKES+i].y<<7) + SNOW_rects[NUM_FLAKES+i].x;
-		*to = snow_color;
-		to += 1;
-		*to = snow_color;
-		to += 640;
-		*to = snow_color;
-		to -= 1;
-		*to = snow_color;
-	}
-}
-
-/* SNOW_erase: updates the screen surface
- * by replacing the previous flakes with
- * the background image (set via SNOW_setBkg).
- * This should be run before bliting any
- * graphics to the screen so you don't over-
- * write good images with background!
- *
- * note: y<<9 + y<<7 is short for y*640
- */
-void SNOW_erase(void) {
-	int i;
-	Uint16 *from, *to;
-
-	if (!SNOW_on)
-		return;
-
-	/* SNOW_on isn't a boolean variable, it is really
-	 * holding the state:
-	 *  0 means no snow
-	 *  1 means snow
-	 *  2 means the user has requested snowing to stop
-	 *          we cannot just stop snowing since we
-	 *          need to erase the previous frames snow
-	 *  3 means have erased the snow during the previous
-	 *          frame and can go back to waiting for
-	 *          snow to be turned on
-	 */
-	if (SNOW_on>1) {
-		if (SNOW_on == 3)
-			SNOW_on = 0;
-		else
-			SNOW_on++;
-	}
-
-	for (i=0; i<NUM_FLAKES; i++) {
-		to = screen->pixels;
-		from = bkg->pixels;
-		to += (SNOW_rects[i].y<<9) + (SNOW_rects[i].y<<7) + SNOW_rects[i].x;
-		from += (SNOW_rects[i].y<<9) + (SNOW_rects[i].y<<7) + SNOW_rects[i].x;
-		*to = *from;
-		to += 1;
-		from += 1;
-		*to = *from;
-		to += 640;
-		from += 640;
-		*to = *from;
-		to -= 1;
-		from -= 1;
-		*to = *from;
-	}
-}
-
-/* SNOW_setBkg: we need to have the  background
- * to erase snow flakes every frame
- */
-void SNOW_setBkg( SDL_Surface *img ) {
-	bkg = img;
-}
-
-/* SNOW_add: this adds the other rectangles that we need 
- * to update on the screen to the list and returns
- * the total number of items on the complete list
- * (flakes & regular stuff)
- */
-int SNOW_add( SDL_Rect *rs, int num ){
-	int i;
-	for (i=0; i<num; i++) {
-		SNOW_rects[(NUM_FLAKES<<1)+i].x = rs[i].x;
-		SNOW_rects[(NUM_FLAKES<<1)+i].y = rs[i].y;
-		SNOW_rects[(NUM_FLAKES<<1)+i].w = rs[i].w;
-		SNOW_rects[(NUM_FLAKES<<1)+i].h = rs[i].h;
-	}
-	return num + (NUM_FLAKES<<1);
-}
-
-/* SNOW_init: initing the snow "library" envoles
- * seting up the color for the snow, the inital
- * locations for the flakes and the size of the
- * snow rectangles
- */
-void SNOW_init( void ) {
-
-	int i;
-
-	snow_color = SDL_MapRGB( screen->format, 255, 255, 255 );
-	for (i=0; i<NUM_FLAKES; i++) {
-		flake[i].x = (int)(8*638.0*rand()/(RAND_MAX+1.0));
-		flake[i].y = (int)(480.0*rand()/(RAND_MAX+1.0));
-	}
-	for (i=0; i<2*NUM_FLAKES; i++) {
-		SNOW_rects[i].w = 2;
-		SNOW_rects[i].h = 2;
-	}
-}
-
-/* SNOW_toggle: toggles the snow on and off.
- * see SNOW_erase for a discription of what
- * SNOW_on means
- */
-void SNOW_toggle( void ) {
-	SNOW_on ++;
-}
-
-/* SNOW_update: update the wind with
- * a 10% prob of blowing further left
- * a 10% prob of blowing further right
- * and 80% of not changing.
- * AFTER updating the wind, we move all
- * the snow
- */
-void SNOW_update( void ) {
-	int rand_tmp = (int)(10.0*rand()/(RAND_MAX+1.0));
-
-	if (!SNOW_on)
-		return;
-
-	if (rand_tmp == 0)
-		add_wind(-1);
-	else if (rand_tmp == 1)
-		add_wind(+1);
-	
-	move_snow();
-}
-

Deleted: tuxtype/branches/tuxtype-soc-mh/snow.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/snow.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/snow.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,9 +0,0 @@
-extern int SNOW_on;
-extern SDL_Rect SNOW_rects[2000];
-extern int SNOW_add( SDL_Rect *rs, int num );
-extern void SNOW_toggle( void );
-extern void SNOW_draw( void );
-extern void SNOW_erase( void );
-extern void SNOW_setBkg( SDL_Surface *img );
-extern void SNOW_init( void );
-extern void SNOW_update( void );

Copied: tuxtype/branches/tuxtype-soc-mh/src/ConvertUTF.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/ConvertUTF.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/ConvertUTF.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/ConvertUTF.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,539 @@
+/*
+ * Copyright 2001-2004 Unicode, Inc.
+ * 
+ * Disclaimer
+ * 
+ * This source code is provided as is by Unicode, Inc. No claims are
+ * made as to fitness for any particular purpose. No warranties of any
+ * kind are expressed or implied. The recipient agrees to determine
+ * applicability of information provided. If this file has been
+ * purchased on magnetic or optical media from Unicode, Inc., the
+ * sole remedy for any claim will be exchange of defective media
+ * within 90 days of receipt.
+ * 
+ * Limitations on Rights to Redistribute This Code
+ * 
+ * Unicode, Inc. hereby grants the right to freely use the information
+ * supplied in this file in the creation of products supporting the
+ * Unicode Standard, and to make copies of this file in any form
+ * for internal or external distribution as long as this notice
+ * remains attached.
+ */
+
+/* ---------------------------------------------------------------------
+
+    Conversions between UTF32, UTF-16, and UTF-8. Source code file.
+    Author: Mark E. Davis, 1994.
+    Rev History: Rick McGowan, fixes & updates May 2001.
+    Sept 2001: fixed const & error conditions per
+	mods suggested by S. Parent & A. Lillich.
+    June 2002: Tim Dodd added detection and handling of incomplete
+	source sequences, enhanced error detection, added casts
+	to eliminate compiler warnings.
+    July 2003: slight mods to back out aggressive FFFE detection.
+    Jan 2004: updated switches in from-UTF8 conversions.
+    Oct 2004: updated to use UNI_MAX_LEGAL_UTF32 in UTF-32 conversions.
+
+    See the header file "ConvertUTF.h" for complete documentation.
+
+------------------------------------------------------------------------ */
+
+
+#include "ConvertUTF.h"
+#ifdef CVTUTF_DEBUG
+#include <stdio.h>
+#endif
+
+static const int halfShift  = 10; /* used for shifting by 10 bits */
+
+static const UTF32 halfBase = 0x0010000UL;
+static const UTF32 halfMask = 0x3FFUL;
+
+#define UNI_SUR_HIGH_START  (UTF32)0xD800
+#define UNI_SUR_HIGH_END    (UTF32)0xDBFF
+#define UNI_SUR_LOW_START   (UTF32)0xDC00
+#define UNI_SUR_LOW_END     (UTF32)0xDFFF
+#define false	   0
+#define true	    1
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF32toUTF16 (
+	const UTF32** sourceStart, const UTF32* sourceEnd, 
+	UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
+    ConversionResult result = conversionOK;
+    const UTF32* source = *sourceStart;
+    UTF16* target = *targetStart;
+    while (source < sourceEnd) {
+	UTF32 ch;
+	if (target >= targetEnd) {
+	    result = targetExhausted; break;
+	}
+	ch = *source++;
+	if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
+	    /* UTF-16 surrogate values are illegal in UTF-32; 0xffff or 0xfffe are both reserved values */
+	    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
+		if (flags == strictConversion) {
+		    --source; /* return to the illegal value itself */
+		    result = sourceIllegal;
+		    break;
+		} else {
+		    *target++ = UNI_REPLACEMENT_CHAR;
+		}
+	    } else {
+		*target++ = (UTF16)ch; /* normal case */
+	    }
+	} else if (ch > UNI_MAX_LEGAL_UTF32) {
+	    if (flags == strictConversion) {
+		result = sourceIllegal;
+	    } else {
+		*target++ = UNI_REPLACEMENT_CHAR;
+	    }
+	} else {
+	    /* target is a character in range 0xFFFF - 0x10FFFF. */
+	    if (target + 1 >= targetEnd) {
+		--source; /* Back up source pointer! */
+		result = targetExhausted; break;
+	    }
+	    ch -= halfBase;
+	    *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
+	    *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
+	}
+    }
+    *sourceStart = source;
+    *targetStart = target;
+    return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF16toUTF32 (
+	const UTF16** sourceStart, const UTF16* sourceEnd, 
+	UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
+    ConversionResult result = conversionOK;
+    const UTF16* source = *sourceStart;
+    UTF32* target = *targetStart;
+    UTF32 ch, ch2;
+    while (source < sourceEnd) {
+	const UTF16* oldSource = source; /*  In case we have to back up because of target overflow. */
+	ch = *source++;
+	/* If we have a surrogate pair, convert to UTF32 first. */
+	if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
+	    /* If the 16 bits following the high surrogate are in the source buffer... */
+	    if (source < sourceEnd) {
+		ch2 = *source;
+		/* If it's a low surrogate, convert to UTF32. */
+		if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
+		    ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
+			+ (ch2 - UNI_SUR_LOW_START) + halfBase;
+		    ++source;
+		} else if (flags == strictConversion) { /* it's an unpaired high surrogate */
+		    --source; /* return to the illegal value itself */
+		    result = sourceIllegal;
+		    break;
+		}
+	    } else { /* We don't have the 16 bits following the high surrogate. */
+		--source; /* return to the high surrogate */
+		result = sourceExhausted;
+		break;
+	    }
+	} else if (flags == strictConversion) {
+	    /* UTF-16 surrogate values are illegal in UTF-32 */
+	    if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
+		--source; /* return to the illegal value itself */
+		result = sourceIllegal;
+		break;
+	    }
+	}
+	if (target >= targetEnd) {
+	    source = oldSource; /* Back up source pointer! */
+	    result = targetExhausted; break;
+	}
+	*target++ = ch;
+    }
+    *sourceStart = source;
+    *targetStart = target;
+#ifdef CVTUTF_DEBUG
+if (result == sourceIllegal) {
+    fprintf(stderr, "ConvertUTF16toUTF32 illegal seq 0x%04x,%04x\n", ch, ch2);
+    fflush(stderr);
+}
+#endif
+    return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Index into the table below with the first byte of a UTF-8 sequence to
+ * get the number of trailing bytes that are supposed to follow it.
+ * Note that *legal* UTF-8 values can't have 4 or 5-bytes. The table is
+ * left as-is for anyone who may want to do such conversion, which was
+ * allowed in earlier algorithms.
+ */
+static const char trailingBytesForUTF8[256] = {
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+    2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
+};
+
+/*
+ * Magic values subtracted from a buffer value during UTF8 conversion.
+ * This table contains as many values as there might be trailing bytes
+ * in a UTF-8 sequence.
+ */
+static const UTF32 offsetsFromUTF8[6] = { 0x00000000UL, 0x00003080UL, 0x000E2080UL, 
+		     0x03C82080UL, 0xFA082080UL, 0x82082080UL };
+
+/*
+ * Once the bits are split out into bytes of UTF-8, this is a mask OR-ed
+ * into the first byte, depending on how many bytes follow.  There are
+ * as many entries in this table as there are UTF-8 sequence types.
+ * (I.e., one byte sequence, two byte... etc.). Remember that sequencs
+ * for *legal* UTF-8 will be 4 or fewer bytes total.
+ */
+static const UTF8 firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
+
+/* --------------------------------------------------------------------- */
+
+/* The interface converts a whole buffer to avoid function-call overhead.
+ * Constants have been gathered. Loops & conditionals have been removed as
+ * much as possible for efficiency, in favor of drop-through switches.
+ * (See "Note A" at the bottom of the file for equivalent code.)
+ * If your compiler supports it, the "isLegalUTF8" call can be turned
+ * into an inline function.
+ */
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF16toUTF8 (
+	const UTF16** sourceStart, const UTF16* sourceEnd, 
+	UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
+    ConversionResult result = conversionOK;
+    const UTF16* source = *sourceStart;
+    UTF8* target = *targetStart;
+    while (source < sourceEnd) {
+	UTF32 ch;
+	unsigned short bytesToWrite = 0;
+	const UTF32 byteMask = 0xBF;
+	const UTF32 byteMark = 0x80; 
+	const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */
+	ch = *source++;
+	/* If we have a surrogate pair, convert to UTF32 first. */
+	if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
+	    /* If the 16 bits following the high surrogate are in the source buffer... */
+	    if (source < sourceEnd) {
+		UTF32 ch2 = *source;
+		/* If it's a low surrogate, convert to UTF32. */
+		if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
+		    ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
+			+ (ch2 - UNI_SUR_LOW_START) + halfBase;
+		    ++source;
+		} else if (flags == strictConversion) { /* it's an unpaired high surrogate */
+		    --source; /* return to the illegal value itself */
+		    result = sourceIllegal;
+		    break;
+		}
+	    } else { /* We don't have the 16 bits following the high surrogate. */
+		--source; /* return to the high surrogate */
+		result = sourceExhausted;
+		break;
+	    }
+	} else if (flags == strictConversion) {
+	    /* UTF-16 surrogate values are illegal in UTF-32 */
+	    if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
+		--source; /* return to the illegal value itself */
+		result = sourceIllegal;
+		break;
+	    }
+	}
+	/* Figure out how many bytes the result will require */
+	if (ch < (UTF32)0x80) {	     bytesToWrite = 1;
+	} else if (ch < (UTF32)0x800) {     bytesToWrite = 2;
+	} else if (ch < (UTF32)0x10000) {   bytesToWrite = 3;
+	} else if (ch < (UTF32)0x110000) {  bytesToWrite = 4;
+	} else {			    bytesToWrite = 3;
+					    ch = UNI_REPLACEMENT_CHAR;
+	}
+
+	target += bytesToWrite;
+	if (target > targetEnd) {
+	    source = oldSource; /* Back up source pointer! */
+	    target -= bytesToWrite; result = targetExhausted; break;
+	}
+	switch (bytesToWrite) { /* note: everything falls through. */
+	    case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+	    case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+	    case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+	    case 1: *--target =  (UTF8)(ch | firstByteMark[bytesToWrite]);
+	}
+	target += bytesToWrite;
+    }
+    *sourceStart = source;
+    *targetStart = target;
+    return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Utility routine to tell whether a sequence of bytes is legal UTF-8.
+ * This must be called with the length pre-determined by the first byte.
+ * If not calling this from ConvertUTF8to*, then the length can be set by:
+ *  length = trailingBytesForUTF8[*source]+1;
+ * and the sequence is illegal right away if there aren't that many bytes
+ * available.
+ * If presented with a length > 4, this returns false.  The Unicode
+ * definition of UTF-8 goes up to 4-byte sequences.
+ */
+
+static Boolean isLegalUTF8(const UTF8 *source, int length) {
+    UTF8 a;
+    const UTF8 *srcptr = source+length;
+    switch (length) {
+    default: return false;
+	/* Everything else falls through when "true"... */
+    case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
+    case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
+    case 2: if ((a = (*--srcptr)) > 0xBF) return false;
+
+	switch (*source) {
+	    /* no fall-through in this inner switch */
+	    case 0xE0: if (a < 0xA0) return false; break;
+	    case 0xED: if (a > 0x9F) return false; break;
+	    case 0xF0: if (a < 0x90) return false; break;
+	    case 0xF4: if (a > 0x8F) return false; break;
+	    default:   if (a < 0x80) return false;
+	}
+
+    case 1: if (*source >= 0x80 && *source < 0xC2) return false;
+    }
+    if (*source > 0xF4) return false;
+    return true;
+}
+
+/* --------------------------------------------------------------------- */
+
+/*
+ * Exported function to return whether a UTF-8 sequence is legal or not.
+ * This is not used here; it's just exported.
+ */
+Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd) {
+    int length = trailingBytesForUTF8[*source]+1;
+    if (source+length > sourceEnd) {
+	return false;
+    }
+    return isLegalUTF8(source, length);
+}
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF8toUTF16 (
+	const UTF8** sourceStart, const UTF8* sourceEnd, 
+	UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags) {
+    ConversionResult result = conversionOK;
+    const UTF8* source = *sourceStart;
+    UTF16* target = *targetStart;
+    while (source < sourceEnd) {
+	UTF32 ch = 0;
+	unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
+	if (source + extraBytesToRead >= sourceEnd) {
+	    result = sourceExhausted; break;
+	}
+	/* Do this check whether lenient or strict */
+	if (! isLegalUTF8(source, extraBytesToRead+1)) {
+	    result = sourceIllegal;
+	    break;
+	}
+	/*
+	 * The cases all fall through. See "Note A" below.
+	 */
+	switch (extraBytesToRead) {
+	    case 5: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
+	    case 4: ch += *source++; ch <<= 6; /* remember, illegal UTF-8 */
+	    case 3: ch += *source++; ch <<= 6;
+	    case 2: ch += *source++; ch <<= 6;
+	    case 1: ch += *source++; ch <<= 6;
+	    case 0: ch += *source++;
+	}
+	ch -= offsetsFromUTF8[extraBytesToRead];
+
+	if (target >= targetEnd) {
+	    source -= (extraBytesToRead+1); /* Back up source pointer! */
+	    result = targetExhausted; break;
+	}
+	if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
+	    /* UTF-16 surrogate values are illegal in UTF-32 */
+	    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
+		if (flags == strictConversion) {
+		    source -= (extraBytesToRead+1); /* return to the illegal value itself */
+		    result = sourceIllegal;
+		    break;
+		} else {
+		    *target++ = UNI_REPLACEMENT_CHAR;
+		}
+	    } else {
+		*target++ = (UTF16)ch; /* normal case */
+	    }
+	} else if (ch > UNI_MAX_UTF16) {
+	    if (flags == strictConversion) {
+		result = sourceIllegal;
+		source -= (extraBytesToRead+1); /* return to the start */
+		break; /* Bail out; shouldn't continue */
+	    } else {
+		*target++ = UNI_REPLACEMENT_CHAR;
+	    }
+	} else {
+	    /* target is a character in range 0xFFFF - 0x10FFFF. */
+	    if (target + 1 >= targetEnd) {
+		source -= (extraBytesToRead+1); /* Back up source pointer! */
+		result = targetExhausted; break;
+	    }
+	    ch -= halfBase;
+	    *target++ = (UTF16)((ch >> halfShift) + UNI_SUR_HIGH_START);
+	    *target++ = (UTF16)((ch & halfMask) + UNI_SUR_LOW_START);
+	}
+    }
+    *sourceStart = source;
+    *targetStart = target;
+    return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF32toUTF8 (
+	const UTF32** sourceStart, const UTF32* sourceEnd, 
+	UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags) {
+    ConversionResult result = conversionOK;
+    const UTF32* source = *sourceStart;
+    UTF8* target = *targetStart;
+    while (source < sourceEnd) {
+	UTF32 ch;
+	unsigned short bytesToWrite = 0;
+	const UTF32 byteMask = 0xBF;
+	const UTF32 byteMark = 0x80; 
+	ch = *source++;
+	if (flags == strictConversion ) {
+	    /* UTF-16 surrogate values are illegal in UTF-32 */
+	    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
+		--source; /* return to the illegal value itself */
+		result = sourceIllegal;
+		break;
+	    }
+	}
+	/*
+	 * Figure out how many bytes the result will require. Turn any
+	 * illegally large UTF32 things (> Plane 17) into replacement chars.
+	 */
+	if (ch < (UTF32)0x80) {	     bytesToWrite = 1;
+	} else if (ch < (UTF32)0x800) {     bytesToWrite = 2;
+	} else if (ch < (UTF32)0x10000) {   bytesToWrite = 3;
+	} else if (ch <= UNI_MAX_LEGAL_UTF32) {  bytesToWrite = 4;
+	} else {			    bytesToWrite = 3;
+					    ch = UNI_REPLACEMENT_CHAR;
+					    result = sourceIllegal;
+	}
+	
+	target += bytesToWrite;
+	if (target > targetEnd) {
+	    --source; /* Back up source pointer! */
+	    target -= bytesToWrite; result = targetExhausted; break;
+	}
+	switch (bytesToWrite) { /* note: everything falls through. */
+	    case 4: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+	    case 3: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+	    case 2: *--target = (UTF8)((ch | byteMark) & byteMask); ch >>= 6;
+	    case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]);
+	}
+	target += bytesToWrite;
+    }
+    *sourceStart = source;
+    *targetStart = target;
+    return result;
+}
+
+/* --------------------------------------------------------------------- */
+
+ConversionResult ConvertUTF8toUTF32 (
+	const UTF8** sourceStart, const UTF8* sourceEnd, 
+	UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags) {
+    ConversionResult result = conversionOK;
+    const UTF8* source = *sourceStart;
+    UTF32* target = *targetStart;
+    while (source < sourceEnd) {
+	UTF32 ch = 0;
+	unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
+	if (source + extraBytesToRead >= sourceEnd) {
+	    result = sourceExhausted; break;
+	}
+	/* Do this check whether lenient or strict */
+	if (! isLegalUTF8(source, extraBytesToRead+1)) {
+	    result = sourceIllegal;
+	    break;
+	}
+	/*
+	 * The cases all fall through. See "Note A" below.
+	 */
+	switch (extraBytesToRead) {
+	    case 5: ch += *source++; ch <<= 6;
+	    case 4: ch += *source++; ch <<= 6;
+	    case 3: ch += *source++; ch <<= 6;
+	    case 2: ch += *source++; ch <<= 6;
+	    case 1: ch += *source++; ch <<= 6;
+	    case 0: ch += *source++;
+	}
+	ch -= offsetsFromUTF8[extraBytesToRead];
+
+	if (target >= targetEnd) {
+	    source -= (extraBytesToRead+1); /* Back up the source pointer! */
+	    result = targetExhausted; break;
+	}
+	if (ch <= UNI_MAX_LEGAL_UTF32) {
+	    /*
+	     * UTF-16 surrogate values are illegal in UTF-32, and anything
+	     * over Plane 17 (> 0x10FFFF) is illegal.
+	     */
+	    if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
+		if (flags == strictConversion) {
+		    source -= (extraBytesToRead+1); /* return to the illegal value itself */
+		    result = sourceIllegal;
+		    break;
+		} else {
+		    *target++ = UNI_REPLACEMENT_CHAR;
+		}
+	    } else {
+		*target++ = ch;
+	    }
+	} else { /* i.e., ch > UNI_MAX_LEGAL_UTF32 */
+	    result = sourceIllegal;
+	    *target++ = UNI_REPLACEMENT_CHAR;
+	}
+    }
+    *sourceStart = source;
+    *targetStart = target;
+    return result;
+}
+
+/* ---------------------------------------------------------------------
+
+    Note A.
+    The fall-through switches in UTF-8 reading code save a
+    temp variable, some decrements & conditionals.  The switches
+    are equivalent to the following loop:
+	{
+	    int tmpBytesToRead = extraBytesToRead+1;
+	    do {
+		ch += *source++;
+		--tmpBytesToRead;
+		if (tmpBytesToRead) ch <<= 6;
+	    } while (tmpBytesToRead > 0);
+	}
+    In UTF-8 writing code, the switches on "bytesToWrite" are
+    similarly unrolled loops.
+
+   --------------------------------------------------------------------- */

Copied: tuxtype/branches/tuxtype-soc-mh/src/ConvertUTF.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/ConvertUTF.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/ConvertUTF.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/ConvertUTF.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2001-2004 Unicode, Inc.
+ * 
+ * Disclaimer
+ * 
+ * This source code is provided as is by Unicode, Inc. No claims are
+ * made as to fitness for any particular purpose. No warranties of any
+ * kind are expressed or implied. The recipient agrees to determine
+ * applicability of information provided. If this file has been
+ * purchased on magnetic or optical media from Unicode, Inc., the
+ * sole remedy for any claim will be exchange of defective media
+ * within 90 days of receipt.
+ * 
+ * Limitations on Rights to Redistribute This Code
+ * 
+ * Unicode, Inc. hereby grants the right to freely use the information
+ * supplied in this file in the creation of products supporting the
+ * Unicode Standard, and to make copies of this file in any form
+ * for internal or external distribution as long as this notice
+ * remains attached.
+ */
+
+/* ---------------------------------------------------------------------
+
+    Conversions between UTF32, UTF-16, and UTF-8.  Header file.
+
+    Several funtions are included here, forming a complete set of
+    conversions between the three formats.  UTF-7 is not included
+    here, but is handled in a separate source file.
+
+    Each of these routines takes pointers to input buffers and output
+    buffers.  The input buffers are const.
+
+    Each routine converts the text between *sourceStart and sourceEnd,
+    putting the result into the buffer between *targetStart and
+    targetEnd. Note: the end pointers are *after* the last item: e.g. 
+    *(sourceEnd - 1) is the last item.
+
+    The return result indicates whether the conversion was successful,
+    and if not, whether the problem was in the source or target buffers.
+    (Only the first encountered problem is indicated.)
+
+    After the conversion, *sourceStart and *targetStart are both
+    updated to point to the end of last text successfully converted in
+    the respective buffers.
+
+    Input parameters:
+	sourceStart - pointer to a pointer to the source buffer.
+		The contents of this are modified on return so that
+		it points at the next thing to be converted.
+	targetStart - similarly, pointer to pointer to the target buffer.
+	sourceEnd, targetEnd - respectively pointers to the ends of the
+		two buffers, for overflow checking only.
+
+    These conversion functions take a ConversionFlags argument. When this
+    flag is set to strict, both irregular sequences and isolated surrogates
+    will cause an error.  When the flag is set to lenient, both irregular
+    sequences and isolated surrogates are converted.
+
+    Whether the flag is strict or lenient, all illegal sequences will cause
+    an error return. This includes sequences such as: <F4 90 80 80>, <C0 80>,
+    or <A0> in UTF-8, and values above 0x10FFFF in UTF-32. Conformant code
+    must check for illegal sequences.
+
+    When the flag is set to lenient, characters over 0x10FFFF are converted
+    to the replacement character; otherwise (when the flag is set to strict)
+    they constitute an error.
+
+    Output parameters:
+	The value "sourceIllegal" is returned from some routines if the input
+	sequence is malformed.  When "sourceIllegal" is returned, the source
+	value will point to the illegal value that caused the problem. E.g.,
+	in UTF-8 when a sequence is malformed, it points to the start of the
+	malformed sequence.  
+
+    Author: Mark E. Davis, 1994.
+    Rev History: Rick McGowan, fixes & updates May 2001.
+		 Fixes & updates, Sept 2001.
+
+------------------------------------------------------------------------ */
+
+/* ---------------------------------------------------------------------
+    The following 4 definitions are compiler-specific.
+    The C standard does not guarantee that wchar_t has at least
+    16 bits, so wchar_t is no less portable than unsigned short!
+    All should be unsigned values to avoid sign extension during
+    bit mask & shift operations.
+------------------------------------------------------------------------ */
+
+typedef unsigned long	UTF32;	/* at least 32 bits */
+typedef unsigned short	UTF16;	/* at least 16 bits */
+typedef unsigned char	UTF8;	/* typically 8 bits */
+typedef unsigned char	Boolean; /* 0 or 1 */
+
+/* Some fundamental constants */
+#define UNI_REPLACEMENT_CHAR (UTF32)0x0000FFFD
+#define UNI_MAX_BMP (UTF32)0x0000FFFF
+#define UNI_MAX_UTF16 (UTF32)0x0010FFFF
+#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF
+#define UNI_MAX_LEGAL_UTF32 (UTF32)0x0010FFFF
+
+typedef enum {
+	conversionOK, 		/* conversion successful */
+	sourceExhausted,	/* partial character in source, but hit end */
+	targetExhausted,	/* insuff. room in target for conversion */
+	sourceIllegal		/* source sequence is illegal/malformed */
+} ConversionResult;
+
+typedef enum {
+	strictConversion = 0,
+	lenientConversion
+} ConversionFlags;
+
+/* This is for C++ and does no harm in C */
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ConversionResult ConvertUTF8toUTF16 (
+		const UTF8** sourceStart, const UTF8* sourceEnd, 
+		UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
+
+ConversionResult ConvertUTF16toUTF8 (
+		const UTF16** sourceStart, const UTF16* sourceEnd, 
+		UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
+		
+ConversionResult ConvertUTF8toUTF32 (
+		const UTF8** sourceStart, const UTF8* sourceEnd, 
+		UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
+
+ConversionResult ConvertUTF32toUTF8 (
+		const UTF32** sourceStart, const UTF32* sourceEnd, 
+		UTF8** targetStart, UTF8* targetEnd, ConversionFlags flags);
+		
+ConversionResult ConvertUTF16toUTF32 (
+		const UTF16** sourceStart, const UTF16* sourceEnd, 
+		UTF32** targetStart, UTF32* targetEnd, ConversionFlags flags);
+
+ConversionResult ConvertUTF32toUTF16 (
+		const UTF32** sourceStart, const UTF32* sourceEnd, 
+		UTF16** targetStart, UTF16* targetEnd, ConversionFlags flags);
+
+Boolean isLegalUTF8Sequence(const UTF8 *source, const UTF8 *sourceEnd);
+
+#ifdef __cplusplus
+}
+#endif
+
+/* --------------------------------------------------------------------- */

Copied: tuxtype/branches/tuxtype-soc-mh/src/Makefile.am (from rev 672, tuxtype/branches/tuxtype-soc-mh/Makefile.am)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/Makefile.am	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/Makefile.am	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,9 @@
+## Makefile.am for tuxtype - data:
+## Process with Automake to create Makefile.in
+
+SUBDIRS = images scripts sounds themes words fonts
+
+tuxtypedatadir = $(pkgdatadir)/data
+
+dist_tuxtypedata_DATA = keyboard.lst \
+			phrases.txt

Copied: tuxtype/branches/tuxtype-soc-mh/src/Makefile.in (from rev 672, tuxtype/branches/tuxtype-soc-mh/Makefile.in)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/Makefile.in	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/Makefile.in	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,525 @@
+# Makefile.in generated by automake 1.10.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008  Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+ at SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+subdir = data
+DIST_COMMON = $(dist_tuxtypedata_DATA) $(srcdir)/Makefile.am \
+	$(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+SOURCES =
+DIST_SOURCES =
+RECURSIVE_TARGETS = all-recursive check-recursive dvi-recursive \
+	html-recursive info-recursive install-data-recursive \
+	install-dvi-recursive install-exec-recursive \
+	install-html-recursive install-info-recursive \
+	install-pdf-recursive install-ps-recursive install-recursive \
+	installcheck-recursive installdirs-recursive pdf-recursive \
+	ps-recursive uninstall-recursive
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+    $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+    *) f=$$p;; \
+  esac;
+am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
+am__installdirs = "$(DESTDIR)$(tuxtypedatadir)"
+dist_tuxtypedataDATA_INSTALL = $(INSTALL_DATA)
+DATA = $(dist_tuxtypedata_DATA)
+RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive	\
+  distclean-recursive maintainer-clean-recursive
+ETAGS = etags
+CTAGS = ctags
+DIST_SUBDIRS = $(SUBDIRS)
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
+GMSGFMT = @GMSGFMT@
+GMSGFMT_015 = @GMSGFMT_015@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+INTLLIBS = @INTLLIBS@
+INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBINTL = @LIBINTL@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBINTL = @LTLIBINTL@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+MSGFMT = @MSGFMT@
+MSGFMT_015 = @MSGFMT_015@
+MSGMERGE = @MSGMERGE@
+NSIS = @NSIS@
+NSI_DLL_DIR = @NSI_DLL_DIR@
+NSI_INSTALL_DIR = @NSI_INSTALL_DIR@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+POSUB = @POSUB@
+SDL_CFLAGS = @SDL_CFLAGS@
+SDL_CONFIG = @SDL_CONFIG@
+SDL_LIBS = @SDL_LIBS@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+USE_NLS = @USE_NLS@
+VERSION = @VERSION@
+WINDRES = @WINDRES@
+XGETTEXT = @XGETTEXT@
+XGETTEXT_015 = @XGETTEXT_015@
+XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_os = @target_os@
+target_vendor = @target_vendor@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+SUBDIRS = images scripts sounds themes words fonts
+tuxtypedatadir = $(pkgdatadir)/data
+dist_tuxtypedata_DATA = keyboard.lst \
+			phrases.txt
+
+all: all-recursive
+
+.SUFFIXES:
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+		&& exit 0; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign  data/Makefile'; \
+	cd $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign  data/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-dist_tuxtypedataDATA: $(dist_tuxtypedata_DATA)
+	@$(NORMAL_INSTALL)
+	test -z "$(tuxtypedatadir)" || $(MKDIR_P) "$(DESTDIR)$(tuxtypedatadir)"
+	@list='$(dist_tuxtypedata_DATA)'; for p in $$list; do \
+	  if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+	  f=$(am__strip_dir) \
+	  echo " $(dist_tuxtypedataDATA_INSTALL) '$$d$$p' '$(DESTDIR)$(tuxtypedatadir)/$$f'"; \
+	  $(dist_tuxtypedataDATA_INSTALL) "$$d$$p" "$(DESTDIR)$(tuxtypedatadir)/$$f"; \
+	done
+
+uninstall-dist_tuxtypedataDATA:
+	@$(NORMAL_UNINSTALL)
+	@list='$(dist_tuxtypedata_DATA)'; for p in $$list; do \
+	  f=$(am__strip_dir) \
+	  echo " rm -f '$(DESTDIR)$(tuxtypedatadir)/$$f'"; \
+	  rm -f "$(DESTDIR)$(tuxtypedatadir)/$$f"; \
+	done
+
+# This directory's subdirectories are mostly independent; you can cd
+# into them and run `make' without going through this Makefile.
+# To change the values of `make' variables: instead of editing Makefiles,
+# (1) if the variable is set in `config.status', edit `config.status'
+#     (which will cause the Makefiles to be regenerated when you run `make');
+# (2) otherwise, pass the desired values on the `make' command line.
+$(RECURSIVE_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	target=`echo $@ | sed s/-recursive//`; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    dot_seen=yes; \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done; \
+	if test "$$dot_seen" = "no"; then \
+	  $(MAKE) $(AM_MAKEFLAGS) "$$target-am" || exit 1; \
+	fi; test -z "$$fail"
+
+$(RECURSIVE_CLEAN_TARGETS):
+	@failcom='exit 1'; \
+	for f in x $$MAKEFLAGS; do \
+	  case $$f in \
+	    *=* | --[!k]*);; \
+	    *k*) failcom='fail=yes';; \
+	  esac; \
+	done; \
+	dot_seen=no; \
+	case "$@" in \
+	  distclean-* | maintainer-clean-*) list='$(DIST_SUBDIRS)' ;; \
+	  *) list='$(SUBDIRS)' ;; \
+	esac; \
+	rev=''; for subdir in $$list; do \
+	  if test "$$subdir" = "."; then :; else \
+	    rev="$$subdir $$rev"; \
+	  fi; \
+	done; \
+	rev="$$rev ."; \
+	target=`echo $@ | sed s/-recursive//`; \
+	for subdir in $$rev; do \
+	  echo "Making $$target in $$subdir"; \
+	  if test "$$subdir" = "."; then \
+	    local_target="$$target-am"; \
+	  else \
+	    local_target="$$target"; \
+	  fi; \
+	  (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $$local_target) \
+	  || eval $$failcom; \
+	done && test -z "$$fail"
+tags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) tags); \
+	done
+ctags-recursive:
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  test "$$subdir" = . || (cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) ctags); \
+	done
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonemtpy = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS: tags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	tags=; \
+	here=`pwd`; \
+	if ($(ETAGS) --etags-include --version) >/dev/null 2>&1; then \
+	  include_option=--etags-include; \
+	  empty_fix=.; \
+	else \
+	  include_option=--include; \
+	  empty_fix=; \
+	fi; \
+	list='$(SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test ! -f $$subdir/TAGS || \
+	      tags="$$tags $$include_option=$$here/$$subdir/TAGS"; \
+	  fi; \
+	done; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	    $$tags $$unique; \
+	fi
+ctags: CTAGS
+CTAGS: ctags-recursive $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	tags=; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$tags$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$tags $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && cd $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+	    fi; \
+	    cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+	  else \
+	    test -f $(distdir)/$$file \
+	    || cp -p $$d/$$file $(distdir)/$$file \
+	    || exit 1; \
+	  fi; \
+	done
+	list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
+	  if test "$$subdir" = .; then :; else \
+	    test -d "$(distdir)/$$subdir" \
+	    || $(MKDIR_P) "$(distdir)/$$subdir" \
+	    || exit 1; \
+	    distdir=`$(am__cd) $(distdir) && pwd`; \
+	    top_distdir=`$(am__cd) $(top_distdir) && pwd`; \
+	    (cd $$subdir && \
+	      $(MAKE) $(AM_MAKEFLAGS) \
+	        top_distdir="$$top_distdir" \
+	        distdir="$$distdir/$$subdir" \
+		am__remove_distdir=: \
+		am__skip_length_check=: \
+	        distdir) \
+	      || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-recursive
+all-am: Makefile $(DATA)
+installdirs: installdirs-recursive
+installdirs-am:
+	for dir in "$(DESTDIR)$(tuxtypedatadir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-recursive
+install-exec: install-exec-recursive
+install-data: install-data-recursive
+uninstall: uninstall-recursive
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-recursive
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-recursive
+
+clean-am: clean-generic mostlyclean-am
+
+distclean: distclean-recursive
+	-rm -f Makefile
+distclean-am: clean-am distclean-generic distclean-tags
+
+dvi: dvi-recursive
+
+dvi-am:
+
+html: html-recursive
+
+info: info-recursive
+
+info-am:
+
+install-data-am: install-dist_tuxtypedataDATA
+
+install-dvi: install-dvi-recursive
+
+install-exec-am:
+
+install-html: install-html-recursive
+
+install-info: install-info-recursive
+
+install-man:
+
+install-pdf: install-pdf-recursive
+
+install-ps: install-ps-recursive
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-recursive
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-recursive
+
+mostlyclean-am: mostlyclean-generic
+
+pdf: pdf-recursive
+
+pdf-am:
+
+ps: ps-recursive
+
+ps-am:
+
+uninstall-am: uninstall-dist_tuxtypedataDATA
+
+.MAKE: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) install-am \
+	install-strip
+
+.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
+	all all-am check check-am clean clean-generic ctags \
+	ctags-recursive distclean distclean-generic distclean-tags \
+	distdir dvi dvi-am html html-am info info-am install \
+	install-am install-data install-data-am \
+	install-dist_tuxtypedataDATA install-dvi install-dvi-am \
+	install-exec install-exec-am install-html install-html-am \
+	install-info install-info-am install-man install-pdf \
+	install-pdf-am install-ps install-ps-am install-strip \
+	installcheck installcheck-am installdirs installdirs-am \
+	maintainer-clean maintainer-clean-generic mostlyclean \
+	mostlyclean-generic pdf pdf-am ps ps-am tags tags-recursive \
+	uninstall uninstall-am uninstall-dist_tuxtypedataDATA
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:

Copied: tuxtype/branches/tuxtype-soc-mh/src/SDLMain.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/SDLMain.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/SDLMain.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/SDLMain.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,19 @@
+/*   SDLMain.m - main entry point for our Cocoa-ized SDL app
+       Initial Version: Darrell Walisser <dwaliss1 at purdue.edu>
+       Non-NIB-Code & other changes: Max Horn <max at quendi.de>
+
+    Feel free to customize this file to suit your needs
+*/
+
+#import <Cocoa/Cocoa.h>
+
+ at interface SDLMain : NSObject
+{
+}
+- (IBAction)prefsMenu:(id)sender;
+- (IBAction)newGame:(id)sender;
+- (IBAction)openGame:(id)sender;
+- (IBAction)saveGame:(id)sender;
+- (IBAction)saveGameAs:(id)sender;
+- (IBAction)help:(id)sender;
+ at end

Copied: tuxtype/branches/tuxtype-soc-mh/src/SDL_extras.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/SDL_extras.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/SDL_extras.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/SDL_extras.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,722 @@
+/*
+*  C Implementation: SDL_extras
+*
+* Description: a few handy functions for using SDL graphics.
+*
+*
+* Author: David Bruce,,, <dbruce at tampabay.rr.com>, (C) 2007
+*
+* Copyright: GPL v3 or later
+*
+*/
+#include <math.h>
+
+#include "SDL_extras.h"
+#include "globals.h"
+#include "pixels.h"
+
+
+#ifdef HAVE_LIBSDL_PANGO
+#include "SDL_Pango.h"
+#endif
+
+
+/* DrawButton() creates and draws a translucent button with */
+/* rounded ends.  All colors and alpha values are supported.*/
+void DrawButton(SDL_Rect* target_rect,
+                int radius,
+                Uint8 r, Uint8 g, Uint8 b, Uint8 a)
+{
+  /* NOTE - we use a 32-bit temp surface even if we have a 16-bit */
+  /* screen - it gets converted during blitting.                  */
+  SDL_Surface* tmp_surf = SDL_CreateRGBSurface(SDL_SWSURFACE|SDL_SRCALPHA,
+                                          target_rect->w,
+                                          target_rect->h,
+                                          32,
+                                          rmask, gmask, bmask, amask);
+  Uint32 color = SDL_MapRGBA(tmp_surf->format, r, g, b, a);
+  SDL_FillRect(tmp_surf, NULL, color);
+  RoundCorners(tmp_surf, radius);
+
+  SDL_BlitSurface(tmp_surf, NULL, screen, target_rect);
+  SDL_FreeSurface(tmp_surf);
+}
+
+
+
+void RoundCorners(SDL_Surface* s, Uint16 radius)
+{
+  int y = 0;
+  int x_dist, y_dist;
+  Uint32* p = NULL;
+  Uint32 alpha_mask;
+  int bytes_per_pix;
+
+  if (!s)
+    return;
+  if (SDL_LockSurface(s) == -1)
+    return;
+
+  bytes_per_pix = s->format->BytesPerPixel;
+  if (bytes_per_pix != 4)
+    return;
+
+  /* radius cannot be more than half of width or height: */
+  if (radius > (s->w)/2)
+    radius = (s->w)/2;
+  if (radius > (s->h)/2)
+    radius = (s->h)/2;
+
+
+  alpha_mask = s->format->Amask;
+
+  /* Now round off corners: */
+  /* upper left:            */
+  for (y = 0; y < radius; y++)
+  {
+    p = (Uint32*)(s->pixels + (y * s->pitch));
+    x_dist = radius;
+    y_dist = radius - y;
+
+    while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+    {
+      /* (make pixel (x,y) transparent) */
+      *p = *p & ~alpha_mask;
+      p++;
+      x_dist--;
+    }
+  }
+
+  /* upper right:            */
+  for (y = 0; y < radius; y++)
+  {
+    /* start at end of top row: */
+    p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
+
+    x_dist = radius;
+    y_dist = radius - y;
+
+    while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+    {
+      /* (make pixel (x,y) transparent) */
+      *p = *p & ~alpha_mask;
+      p--;
+      x_dist--;
+    }
+  }
+
+  /* bottom left:            */
+  for (y = (s->h - 1); y > (s->h - radius); y--)
+  {
+    /* start at beginning of bottom row */
+    p = (Uint32*)(s->pixels + (y * s->pitch));
+    x_dist = radius;
+    y_dist = y - (s->h - radius);
+
+    while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+    {
+      /* (make pixel (x,y) transparent) */
+      *p = *p & ~alpha_mask;
+      p++;
+      x_dist--;
+    }
+  }
+
+  /* bottom right:            */
+  for (y = (s->h - 1); y > (s->h - radius); y--)
+  {
+    /* start at end of bottom row */
+    p = (Uint32*)(s->pixels + ((y + 1) * s->pitch) - bytes_per_pix);
+    x_dist = radius;
+    y_dist = y - (s->h - radius);
+
+    while (((x_dist * x_dist) + (y_dist * y_dist)) > (radius * radius))
+    {
+      /* (make pixel (x,y) transparent) */
+      *p = *p & ~alpha_mask;
+      p--;
+      x_dist--;
+    }
+  }
+  SDL_UnlockSurface(s);
+}
+
+
+/**********************
+ Flip:
+   input: a SDL_Surface, x, y
+   output: a copy of the SDL_Surface flipped via rules:
+
+     if x is a nonzero value, then flip horizontally
+     if y is a nonzero value, then flip vertically
+
+     note: you can have it flip both
+**********************/
+SDL_Surface* Flip( SDL_Surface *in, int x, int y ) {
+        SDL_Surface *out, *tmp;
+        SDL_Rect from_rect, to_rect;
+        Uint32        flags;
+        Uint32  colorkey=0;
+
+        /* --- grab the settings for the incoming pixmap --- */
+
+        SDL_LockSurface(in);
+        flags = in->flags;
+
+        /* --- change in's flags so ignore colorkey & alpha --- */
+
+        if (flags & SDL_SRCCOLORKEY) {
+                in->flags &= ~SDL_SRCCOLORKEY;
+                colorkey = in->format->colorkey;
+        }
+        if (flags & SDL_SRCALPHA) {
+                in->flags &= ~SDL_SRCALPHA;
+        }
+
+        SDL_UnlockSurface(in);
+
+        /* --- create our new surface --- */
+
+        out = SDL_CreateRGBSurface(
+                SDL_SWSURFACE,
+                in->w, in->h, 32, rmask, gmask, bmask, amask);
+
+        /* --- flip horizontally if requested --- */
+
+        if (x) {
+                from_rect.h = to_rect.h = in->h;
+                from_rect.w = to_rect.w = 1;
+                from_rect.y = to_rect.y = 0;
+                from_rect.x = 0;
+                to_rect.x = in->w - 1;
+
+                do {
+                        SDL_BlitSurface(in, &from_rect, out, &to_rect);
+                        from_rect.x++;
+                        to_rect.x--;
+                } while (to_rect.x >= 0);
+        }
+
+        /* --- flip vertically if requested --- */
+
+        if (y) {
+                from_rect.h = to_rect.h = 1;
+                from_rect.w = to_rect.w = in->w;
+                from_rect.x = to_rect.x = 0;
+                from_rect.y = 0;
+                to_rect.y = in->h - 1;
+
+                do {
+                        SDL_BlitSurface(in, &from_rect, out, &to_rect);
+                        from_rect.y++;
+                        to_rect.y--;
+                } while (to_rect.y >= 0);
+        }
+
+        /* --- restore colorkey & alpha on in and setup out the same --- */
+
+        SDL_LockSurface(in);
+
+        if (flags & SDL_SRCCOLORKEY) {
+                in->flags |= SDL_SRCCOLORKEY;
+                in->format->colorkey = colorkey;
+                tmp = SDL_DisplayFormat(out);
+                SDL_FreeSurface(out);
+                out = tmp;
+                out->flags |= SDL_SRCCOLORKEY;
+                out->format->colorkey = colorkey;
+        } else if (flags & SDL_SRCALPHA) {
+                in->flags |= SDL_SRCALPHA;
+                tmp = SDL_DisplayFormatAlpha(out);
+                SDL_FreeSurface(out);
+                out = tmp;
+        } else {
+                tmp = SDL_DisplayFormat(out);
+                SDL_FreeSurface(out);
+                out = tmp;
+        }
+
+        SDL_UnlockSurface(in);
+
+        return out;
+}
+
+/* Blend two surfaces together. The third argument is between 0.0 and
+   1.0, and represents the weight assigned to the first surface.  If
+   the pointer to the second surface is NULL, this performs fading.
+
+   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_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) {
+    perror("gamma must be between 0 and 1");
+    exit(0);
+  }
+  fmt1 = S1->format;
+  if (fmt1->BitsPerPixel != 32) {
+    perror("This works only with RGBA images");
+    return S1;
+  }
+  if (S2 != NULL) {
+    fmt2 = S2->format;
+    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) {
+      printf("S1->w %d, S2->w %d;  S1->h %d, S2->h %d\n",
+             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);
+  // 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 {
+    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;
+    }
+    *cpix1 = SDL_MapRGBA(fmt1,r1,g1,b1,a1);
+  }
+  SDL_UnlockSurface(tmpS);
+  if (S2 != NULL)
+    SDL_UnlockSurface(S2);
+
+  ret = SDL_DisplayFormatAlpha(tmpS);
+  SDL_FreeSurface(tmpS);
+
+  return ret;
+}
+#ifdef HAVE_LIBSDL_PANGO
+
+SDLPango_Context *context = NULL;
+
+void init_SDLPango_Context()
+{
+   if((context =  SDLPango_CreateContext_GivenFontDesc(settings.theme_font_name))==NULL)
+	   context =  SDLPango_CreateContext();
+   SDLPango_SetBaseDirection(context, SDLPANGO_DIRECTION_LTR);
+   SDLPango_SetDpi(context, 125.0, 125.0);
+}
+void free_SDLPango_Context()
+{
+  if(context != NULL)
+    SDLPango_FreeContext(context);
+  context = NULL;
+}
+#endif
+
+
+/* BlackOutline() creates a surface containing text of the designated */
+/* foreground color, surrounded by a black shadow, on a transparent    */
+/* 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* out = NULL;
+  SDL_Surface* black_letters = NULL;
+  SDL_Surface* white_letters = NULL;
+  SDL_Surface* bg = NULL;
+  SDL_Rect dstrect;
+  Uint32 color_key;
+
+  if (!t || !font || !c)
+  {
+    fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
+    return NULL;
+  }
+ 
+#ifndef HAVE_LIBSDL_PANGO
+  black_letters = TTF_RenderUTF8_Blended(font, t, black);
+#else
+  if( context != NULL)
+  {
+    SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_BLACK_LETTER);
+    SDLPango_SetText(context, t, -1);
+    black_letters = SDLPango_CreateSurfaceDraw(context);
+  }
+  else {
+    black_letters = TTF_RenderUTF8_Blended(font, t, black);
+  }
+#endif
+
+  if (!black_letters)
+  {
+    fprintf (stderr, "Warning - BlackOutline() could not create image for %s\n", t);
+    return NULL;
+  }
+
+  bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
+                            (black_letters->w) + 5,
+                            (black_letters->h) + 5,
+                             32,
+                             rmask, gmask, bmask, amask);
+  /* Use color key for eventual transparency: */
+  color_key = SDL_MapRGB(bg->format, 01, 01, 01);
+  SDL_FillRect(bg, NULL, color_key);
+
+  /* Now draw black outline/shadow 2 pixels on each side: */
+  dstrect.w = black_letters->w;
+  dstrect.h = black_letters->h;
+
+  /* NOTE: can make the "shadow" more or less pronounced by */
+  /* changing the parameters of these loops.                */
+  for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
+    for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
+      SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
+
+  SDL_FreeSurface(black_letters);
+
+  /* --- Put the color version of the text on top! --- */
+#ifndef HAVE_LIBSDL_PANGO
+  white_letters = TTF_RenderUTF8_Blended(font, t, *c);
+#else
+  if( context != NULL)
+  {
+    SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_WHITE_LETTER);
+    white_letters = SDLPango_CreateSurfaceDraw(context);
+  }
+  else {
+    white_letters = TTF_RenderUTF8_Blended(font, t, *c);
+  }
+#endif
+
+  dstrect.x = 1;
+  dstrect.y = 1;
+  SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
+  SDL_FreeSurface(white_letters);
+
+  /* --- Convert to the screen format for quicker blits --- */
+  SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
+  out = SDL_DisplayFormatAlpha(bg);
+  SDL_FreeSurface(bg);
+
+  return out;
+}
+
+
+/* This version takes a wide character string and renders it with the */
+/* Unicode string versions of the SDL_ttf functions:                  */
+SDL_Surface* BlackOutline_Unicode(const Uint16* t, const TTF_Font* font, const SDL_Color* c)
+{
+  SDL_Surface* out = NULL;
+  SDL_Surface* black_letters = NULL;
+  SDL_Surface* white_letters = NULL;
+  SDL_Surface* bg = NULL;
+  SDL_Rect dstrect;
+  Uint32 color_key;
+
+  if (!font || !c)
+  {
+    fprintf(stderr, "BlackOutline_wchar(): invalid ptr parameter, returning.");
+    return NULL;
+  }
+                                        /* (cast to stop compiler complaint) */
+  black_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, black);
+
+  if (!black_letters)
+  {
+    fprintf (stderr, "Warning - BlackOutline_wchar() could not create image for %S\n", t);
+    return NULL;
+  }
+
+  bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
+                            (black_letters->w) + 5,
+                            (black_letters->h) + 5,
+                             32,
+                             rmask, gmask, bmask, amask);
+  /* Use color key for eventual transparency: */
+  color_key = SDL_MapRGB(bg->format, 10, 10, 10);
+  SDL_FillRect(bg, NULL, color_key);
+
+  /* Now draw black outline/shadow 2 pixels on each side: */
+  dstrect.w = black_letters->w;
+  dstrect.h = black_letters->h;
+
+  /* NOTE: can make the "shadow" more or less pronounced by */
+  /* changing the parameters of these loops.                */
+  for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
+    for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
+      SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
+
+  SDL_FreeSurface(black_letters);
+
+  /* --- Put the color version of the text on top! --- */
+                                       /* (cast to stop compiler complaint) */
+  white_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, *c);
+  dstrect.x = 1;
+  dstrect.y = 1;
+  SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
+  SDL_FreeSurface(white_letters);
+
+  /* --- Convert to the screen format for quicker blits --- */
+  SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
+  out = SDL_DisplayFormatAlpha(bg);
+  SDL_FreeSurface(bg);
+
+  return out;
+}
+
+
+SDL_Surface* BlackOutline_w(wchar_t* t, const TTF_Font* font, const SDL_Color* c, int size)
+{
+	wchar_t wchar_tmp[512];
+	char tmp[512];
+	int i;
+	wcsncpy( wchar_tmp, t, size);
+	wchar_tmp[size]=0;
+	i=ConvertToUTF8( wchar_tmp, tmp);
+	tmp[i]=0;
+	return BlackOutline(tmp, font, c);
+}
+
+
+int inRect( SDL_Rect r, int x, int y) {
+        if ((x < r.x) || (y < r.y) || (x > r.x + r.w) || (y > r.y + r.h))
+                return 0;
+        return 1;
+}
+
+/* Darkens the screen by a factor of 2^bits */
+void DarkenScreen(Uint8 bits)
+{
+#if BPP == 32
+  Uint32* p;
+#elif BPP == 16
+  Uint16* p;
+#else
+  return;
+#endif
+
+  Uint32 rm = screen->format->Rmask;
+  Uint32 gm = screen->format->Gmask;
+  Uint32 bm = screen->format->Bmask;
+
+
+  int x, y;
+
+  /* (realistically, 1 and 2 are the only useful values) */
+  if (bits > 8)
+    return;
+
+  p = screen->pixels;
+
+  for (y = 0; y < screen->h; y++)
+  {
+    for (x = 0; x < screen->w; x++)
+    {
+      *p = (((*p&rm)>>bits)&rm)
+         | (((*p&gm)>>bits)&gm)
+         | (((*p&bm)>>bits)&bm);
+      p++;
+    }
+  }
+}
+
+
+void SwitchScreenMode(void)
+{
+  int window = (screen->flags & SDL_FULLSCREEN);
+  SDL_Surface* oldscreen = screen;
+
+  if (!window)
+  {
+    screen = SDL_SetVideoMode(fs_res_x,
+                              fs_res_y,
+                              BPP,
+                              SDL_SWSURFACE|SDL_HWPALETTE|SDL_FULLSCREEN);
+  }
+  else
+  {
+    screen = SDL_SetVideoMode(RES_X,
+                              RES_Y,
+                              BPP,
+                              SDL_SWSURFACE|SDL_HWPALETTE);
+
+  }
+
+  if (screen == NULL)
+  {
+    fprintf(stderr,
+            "\nError: I could not switch to %s mode.\n"
+            "The Simple DirectMedia error that occured was:\n"
+            "%s\n\n",
+            window ? "windowed" : "fullscreen",
+            SDL_GetError());
+    screen = oldscreen;
+  }
+  else
+  {
+    SDL_FreeSurface(oldscreen);
+    oldscreen = NULL;
+    SDL_UpdateRect(screen, 0, 0, 0, 0);
+  }
+
+}
+
+
+int WaitForKeypress(void)
+{
+  SDL_Event evt;
+  while (1)
+    while (SDL_PollEvent(&evt) )
+      if (evt.type == SDL_KEYDOWN)
+        return evt.key.keysym.sym;
+      else SDL_Delay(50);
+}
+/* Swiped shamelessly from TuxPaint
+   Based on code from: http://www.codeproject.com/cs/media/imageprocessing4.asp
+   copyright 2002 Christian Graus */
+
+SDL_Surface* zoom(SDL_Surface* src, int new_w, int new_h)
+{
+  SDL_Surface* s;
+
+  /* These function pointers will point to the appropriate */
+  /* putpixel() and getpixel() variants to be used in the  */
+  /* current colorspace:                                   */
+  void (*putpixel) (SDL_Surface*, int, int, Uint32);
+  Uint32(*getpixel) (SDL_Surface*, int, int);
+
+  float xscale, yscale;
+  int x, y;
+  int floor_x, ceil_x,
+        floor_y, ceil_y;
+  float fraction_x, fraction_y,
+        one_minus_x, one_minus_y;
+  float n1, n2;
+  Uint8 r1, g1, b1, a1;
+  Uint8 r2, g2, b2, a2;
+  Uint8 r3, g3, b3, a3;
+  Uint8 r4, g4, b4, a4;
+  Uint8 r, g, b, a;
+
+  /* Create surface for zoom: */
+
+  s = SDL_CreateRGBSurface(src->flags,        /* SDL_SWSURFACE, */
+                           new_w, new_h, src->format->BitsPerPixel,
+                           src->format->Rmask,
+                           src->format->Gmask,
+                           src->format->Bmask,
+                           src->format->Amask);
+
+  if (s == NULL)
+  {
+    fprintf(stderr, "\nError: Can't build zoom surface\n"
+            "The Simple DirectMedia Layer error that occurred was:\n"
+            "%s\n\n", SDL_GetError());
+    return NULL;
+//    cleanup();
+//    exit(1);
+  }
+
+
+  /* Now assign function pointers to correct functions based */
+  /* on data format of original and zoomed surfaces:         */
+  getpixel = getpixels[src->format->BytesPerPixel];
+  putpixel = putpixels[s->format->BytesPerPixel];
+
+  SDL_LockSurface(src);
+  SDL_LockSurface(s);
+
+  xscale = (float) src->w / (float) new_w;
+  yscale = (float) src->h / (float) new_h;
+
+  for (x = 0; x < new_w; x++)
+  {
+    for (y = 0; y < new_h; y++)
+    {
+      /* Here we calculate the new RGBA values for each pixel */
+      /* using a "weighted average" of the four pixels in the */
+      /* corresponding location in the orginal surface:       */
+
+      /* figure out which original pixels to use in the calc: */
+      floor_x = floor((float) x * xscale);
+      ceil_x = floor_x + 1;
+      if (ceil_x >= src->w)
+        ceil_x = floor_x;
+
+      floor_y = floor((float) y * yscale);
+      ceil_y = floor_y + 1;
+      if (ceil_y >= src->h)
+        ceil_y = floor_y;
+
+      fraction_x = x * xscale - floor_x;
+      fraction_y = y * yscale - floor_y;
+
+      one_minus_x = 1.0 - fraction_x;
+      one_minus_y = 1.0 - fraction_y;
+
+      /* Grab their values:  */
+      SDL_GetRGBA(getpixel(src, floor_x, floor_y), src->format,
+                  &r1, &g1, &b1, &a1);
+      SDL_GetRGBA(getpixel(src, ceil_x,  floor_y), src->format,
+                  &r2, &g2, &b2, &a2);
+      SDL_GetRGBA(getpixel(src, floor_x, ceil_y),  src->format,
+                  &r3, &g3, &b3, &a3);
+      SDL_GetRGBA(getpixel(src, ceil_x,  ceil_y),  src->format,
+                  &r4, &g4, &b4, &a4);
+
+      /* Create the weighted averages: */
+      n1 = (one_minus_x * r1 + fraction_x * r2);
+      n2 = (one_minus_x * r3 + fraction_x * r4);
+      r = (one_minus_y * n1 + fraction_y * n2);
+
+      n1 = (one_minus_x * g1 + fraction_x * g2);
+      n2 = (one_minus_x * g3 + fraction_x * g4);
+      g = (one_minus_y * n1 + fraction_y * n2);
+
+      n1 = (one_minus_x * b1 + fraction_x * b2);
+      n2 = (one_minus_x * b3 + fraction_x * b4);
+      b = (one_minus_y * n1 + fraction_y * n2);
+
+      n1 = (one_minus_x * a1 + fraction_x * a2);
+      n2 = (one_minus_x * a3 + fraction_x * a4);
+      a = (one_minus_y * n1 + fraction_y * n2);
+
+      /* and put them into our new surface: */
+      putpixel(s, x, y, SDL_MapRGBA(s->format, r, g, b, a));
+
+    }
+  }
+
+  SDL_UnlockSurface(s);
+  SDL_UnlockSurface(src);
+
+  return s;
+}
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/SDL_extras.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/SDL_extras.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/SDL_extras.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/SDL_extras.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,54 @@
+//
+// C Interface: SDL_extras
+//
+// Description: A few handy functions for using SDL graphics.
+//
+//
+// Author: David Bruce,,, <dbruce at tampabay.rr.com>, (C) 2007
+//
+// Copyright: See COPYING file that comes with this distribution
+// (briefly, GPL v3 or later).
+//
+
+#ifndef SDL_EXTRAS_H
+#define SDL_EXTRAS_H
+
+#include "SDL.h"
+#include "SDL_ttf.h"
+
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+#define rmask 0xff000000
+#define gmask 0x00ff0000
+#define bmask 0x0000ff00
+#define amask 0x000000ff
+#else
+#define rmask 0x000000ff
+#define gmask 0x0000ff00
+#define bmask 0x00ff0000
+#define amask 0xff000000
+#endif
+
+#ifdef HAVE_LIBSDL_PANGO
+//#ifdef SDL_Pango
+#include "SDL_Pango.h"
+
+extern SDLPango_Context *context;
+void init_SDLPango_Context();
+void free_SDLPango_Context();
+#endif
+
+void DrawButton(SDL_Rect* target_rect, int radius, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
+void RoundCorners(SDL_Surface* s, Uint16 radius);
+SDL_Surface* Flip(SDL_Surface *in, int x, int y);
+SDL_Surface* BlackOutline(const char *t, TTF_Font* font, 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);
+int  inRect(SDL_Rect r, int x, int y);
+void DarkenScreen(Uint8 bits);
+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);
+
+
+#endif

Copied: tuxtype/branches/tuxtype-soc-mh/src/alphabet.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/alphabet.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/alphabet.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/alphabet.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,1817 @@
+/***************************************************************************
+                          alphabet.c 
+ -  description: Init SDL
+                             -------------------
+    begin                : Jan 6 2003
+    copyright            : (C) 2003 by Jesse Andrews
+    email                : jdandr2 at tux4kids.net
+Revised extensively: 2008
+Sreyas Kurumanghat <k.sreyas at gmail.com>
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+
+/* Needed to handle rendering issues for Indic languages*/
+#ifndef WIN32
+#ifndef MACOSX
+#include <SDL_Pango.h>
+#endif
+#endif
+
+/* Needed to convert UTF-8 under Windows because we don't have glibc: */
+#include "ConvertUTF.h"  
+
+#include "globals.h"
+#include "funcs.h"
+
+
+/* NOTE these are externed in globals.h so not static */
+/* the colors we use throughout the game */
+SDL_Color black;
+SDL_Color gray;
+SDL_Color dark_blue;
+SDL_Color red;
+SDL_Color white;
+SDL_Color yellow;
+
+
+
+/* An individual item in the list of cached unicode characters that are rendered at   */
+/* the start of each game.                                                            */
+typedef struct uni_glyph {
+  wchar_t unicode_value;
+  SDL_Surface* white_glyph;
+  SDL_Surface* red_glyph;
+} uni_glyph;
+
+/* These are the arrays for the red and white letters: */
+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. */
+/*typedef struct keymap {
+	char keyname[5];
+	int shift;
+} keymap;*/
+typedef struct kbd_char {
+  wchar_t unicode_value;
+  char finger;
+	//keymap key;
+	char keyname[5];
+	int shift;
+	char latin_char;
+} kbd_char;
+
+/* 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 TTF_Font* font = NULL;
+
+/* Used for word list functions (see below): */
+static int num_words;
+static wchar_t word_list[MAX_NUM_WORDS][MAX_WORD_SIZE + 1];
+static wchar_t char_list[MAX_UNICODES];  // List of distinct letters in word list
+static int num_chars_used = 0;       // Number of different letters in word list
+
+
+
+/* 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 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);
+
+#ifndef WIN32
+#ifndef MACOSX
+static SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color* cl);
+#endif
+#endif
+
+
+
+/*****************************************************/
+/*                                                   */
+/*          "Public" Functions                       */
+/*                                                   */
+/*****************************************************/
+
+
+
+/* FIXME would be better to get keymap from system somehow (SDL? X11?) - */
+/* all this does now is fiddle with the ALPHABET and FINGER arrays */
+int LoadKeyboard(void)
+{
+  unsigned char fn[FNLEN];
+  int found = 0;
+
+  clear_keyboard();
+
+  /* First look for keyboard.lst in theme path, if desired: */
+  if (!settings.use_english)
+  {
+    sprintf(fn , "%s/keyboard.lst", settings.theme_data_path);
+    if (CheckFile(fn))
+    {
+      found = 1;
+    }
+  }
+
+  /* Now look in default path if desired or needed: */
+  if (!found)
+  {
+    sprintf(fn , "%s/keyboard.lst", settings.default_data_path);
+    if (CheckFile(fn))
+    {
+      found = 1;
+    }
+  }
+
+  if (!found)
+  {
+    fprintf(stderr, "LoadKeyboard(): Error finding file for keyboard setup!\n");
+    return 0;
+  }
+  
+  /* fn should now contain valid path to keyboard.lst: */
+  DEBUGCODE{fprintf(stderr, "fn = %s\n", fn);}
+
+  {
+    unsigned char str[255];
+    wchar_t wide_str[255];
+
+    FILE* f;
+    int i = 0, j = 0, k = 0;
+
+    f = fopen( fn, "r" );
+
+    if (f == NULL)
+    {
+      LOG("LoadKeyboard() - could not open keyboard.lst\n");
+      return 0;
+    }
+
+
+    do
+    {
+      fscanf( f, "%[^\n]\n", str);
+      /* Convert to wcs from UTF-8, if needed; */
+      //mbstowcs(wide_str, str, strlen(str) + 1);
+      ConvertFromUTF8(wide_str, str);
+
+      /* 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[2] == Unicode value of character          */
+
+      /* FIXME - this might be a good place to use a    */
+      /* hash table to avoid n^2 performance problems.  */
+      /* Some sanity checks:  */
+      if ((wcslen(wide_str) >=3)
+       && (wcstol(&wide_str[0], NULL, 0) >=0)   /* These lines just make sure the */
+       && (wcstol(&wide_str[0], NULL, 0) < 10)  /* finger is between 0 and 10     */
+       && (wide_str[1] == '|')
+       && (k < MAX_UNICODES)
+       && !unicode_in_key_list(wide_str[2])) /* Make sure char not already added */
+      {
+        DEBUGCODE
+        {
+          fprintf(stderr, "Adding key: Unicode char = '%C'\tUnicode value = %d\tfinger = %d\n",
+                  wide_str[2], wide_str[2], wcstol(&wide_str[0], NULL, 0)); 
+	}
+
+        /* Just plug values into array: */
+        keyboard_list[k].unicode_value = wide_str[2];
+        keyboard_list[k].finger = wcstol(&wide_str[0], NULL, 0);
+	if (wcslen(wide_str) <5)
+	{
+		if(!settings.use_english)
+		{
+			map_keys(-1,&keyboard_list[k]);
+			keyboard_list[k].latin_char=-1;
+			keyboard_list[k].finger = wcstol(&wide_str[0], NULL, 0);
+		}
+		else
+		{
+			map_keys(wide_str[2],&keyboard_list[k]);
+			keyboard_list[k].latin_char=wide_str[2];
+		}
+	}
+	else
+	{
+		map_keys(wide_str[4],&keyboard_list[k]);
+		keyboard_list[k].latin_char=wide_str[4];
+	}
+        k++;
+      }
+	else
+	{
+		if(wcslen(wide_str)==1)
+		{
+			if(!settings.use_english)
+			{
+				keyboard_list[k].unicode_value = wide_str[0];
+				map_keys(-1,&keyboard_list[k]);
+				keyboard_list[k].latin_char=-1;
+			}
+			else
+			{
+				keyboard_list[k].unicode_value = wide_str[0];
+				map_keys(-1,&keyboard_list[k]);
+				keyboard_list[k].latin_char=wide_str[0];
+			}
+			k++;
+		}
+		
+	}
+			
+    } while (!feof(f));
+
+
+    fclose(f);
+    LOG("Leaving LoadKeyboard()\n");
+    return 1;
+  }
+}
+
+/* Returns the finger hint(0-9) associated with a given Unicode value */
+/* in the keyboard_list:                                              */
+/* Returns -1 if somehow no finger associated with a Unicode value    */
+/* in the list (shouldn't happen).                                    */
+/* Returns -2 if Unicode value not in list.                           */
+int GetFinger(int i)
+{
+  if (i == -1)
+  {
+    fprintf(stderr, "GetFinger() - Unicode char '%C' not found in list.\n");
+    return -2;
+  }
+
+  if ((keyboard_list[i].finger < 0)
+   || (keyboard_list[i].finger > 9))
+  {
+    fprintf(stderr, "GetFinger() - Unicode char '%C' has no valid finger.\n");
+    return -1;
+  }  
+
+  return (int)keyboard_list[i].finger; /* Keep compiler from complaining */
+}
+
+int GetShift(int i)
+{
+	return keyboard_list[i].shift;
+}
+
+int GetIndex(wchar_t uni_char)
+{
+  int i = 0;
+
+  while ((i < MAX_UNICODES)
+     &&  (keyboard_list[i].unicode_value != uni_char))
+  {
+    i++;
+  }
+
+  if (i == MAX_UNICODES)
+  {
+    fprintf(stderr, "GetIndex - Unicode char '%C' not found in list.\n", uni_char);
+    return -1;
+  }
+
+  return i;
+}
+
+void GetKeyPos(int index, char *buf)
+{
+	sprintf(buf,"keyboard/keyboard_%s.png", keyboard_list[index].keyname);	
+}
+
+void GetWrongKeyPos(int index, char *buf)
+{
+	sprintf(buf,"keyboard/keyboardN_%s.png", keyboard_list[index].keyname);
+}
+
+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);			
+}
+wchar_t GetLastKey()
+{
+	if(!num_chars_used)
+		return -1;
+	else
+		return keyboard_list[num_chars_used-1].unicode_value;
+} 
+int unicode_in_key_list(wchar_t uni_char)
+{
+  int i = 0;
+  while ((i < MAX_UNICODES)
+     &&  (keyboard_list[i].unicode_value != uni_char))
+  {
+    i++;
+  }
+  if (i == MAX_UNICODES)
+    return 0;
+  else
+    return 1;
+}
+
+// /* NOTE if we can consistently use SDLPango on all platforms, we can simply */
+// /* rename the pango version to BlackOutline() and get rid of this one.      */
+// /* The input for this function should be UTF-8.                             */
+// SDL_Surface* BlackOutline(const unsigned char* t, const TTF_Font* font, const SDL_Color* c)
+// {
+//   SDL_Surface* out = NULL;
+//   SDL_Surface* black_letters = NULL;
+//   SDL_Surface* white_letters = NULL;
+//   SDL_Surface* bg = NULL;
+//   SDL_Rect dstrect;
+//   Uint32 color_key;
+// 
+//   LOG("Entering BlackOutline()\n");
+// 
+// /* Simply passthrough to SDLPango version if available (i.e. not under Windows):*/
+// #ifndef WIN32
+// #ifndef MACOSX
+// return BlackOutline_SDLPango(t, font, c);
+// #endif
+// #endif
+// 
+// 
+//   if (!t || !font || !c)
+//   {
+//     fprintf(stderr, "BlackOutline(): invalid ptr parameter, returning.");
+//     return NULL;
+//   }
+// 
+//   black_letters = TTF_RenderUTF8_Blended((TTF_Font*)font, t, black);
+// 
+//   if (!black_letters)
+//   {
+//     fprintf (stderr, "Warning - BlackOutline() could not create image for %s\n", t);
+//     return NULL;
+//   }
+// 
+//   bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
+//                             (black_letters->w) + 5,
+//                             (black_letters->h) + 5,
+//                              32,
+//                              RMASK, GMASK, BMASK, AMASK);
+//   /* Use color key for eventual transparency: */
+//   color_key = SDL_MapRGB(bg->format, 10, 10, 10);
+//   SDL_FillRect(bg, NULL, color_key);
+// 
+//   /* Now draw black outline/shadow 2 pixels on each side: */
+//   dstrect.w = black_letters->w;
+//   dstrect.h = black_letters->h;
+// 
+//   /* NOTE: can make the "shadow" more or less pronounced by */
+//   /* changing the parameters of these loops.                */
+//   for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
+//     for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
+//       SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
+// 
+//   SDL_FreeSurface(black_letters);
+// 
+//   /* --- Put the color version of the text on top! --- */
+//   /* NOTE we cast away the 'const-ness' to keep compliler from complaining: */
+//   white_letters = TTF_RenderUTF8_Blended((TTF_Font*)font, t, *c);
+//   dstrect.x = 1;
+//   dstrect.y = 1;
+//   SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
+//   SDL_FreeSurface(white_letters);
+// 
+//   /* --- Convert to the screen format for quicker blits --- */
+//   SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
+//   out = SDL_DisplayFormatAlpha(bg);
+//   SDL_FreeSurface(bg);
+// 
+//   LOG("Leaving BlackOutline()\n");
+// 
+//   return out;
+// }
+
+
+
+#ifndef WIN32
+#ifndef MACOSX
+/*Convert SDL_Colour to SDLPango_Matrix*/
+
+SDLPango_Matrix* SDL_Colour_to_SDLPango_Matrix(const SDL_Color *cl)
+{
+  SDLPango_Matrix *colour;
+  colour=malloc(sizeof(SDLPango_Matrix));
+  int k;
+  for(k=0;k<4;k++){
+  	(*colour).m[0][k]=(*cl).r;
+  	(*colour).m[1][k]=(*cl).g;
+  	(*colour).m[2][k]=(*cl).b;
+  }
+  (*colour).m[3][0]=0;
+  (*colour).m[3][1]=255;
+  (*colour).m[3][2]=0;
+  (*colour).m[3][3]=0;
+
+  return colour;
+}
+
+
+
+// /* This version basically uses the SDLPango lib instead of */
+// /* TTF_RenderUTF*_Blended() to properly render Indic text. */
+// SDL_Surface* BlackOutline_SDLPango(const unsigned char* t, const TTF_Font* font, const SDL_Color* c)
+// {
+//   SDL_Surface* out = NULL;
+//   SDL_Surface* black_letters = NULL;
+//   SDL_Surface* white_letters = NULL;
+//   SDL_Surface* bg = NULL;
+//   SDL_Rect dstrect;
+//   Uint32 color_key;
+//   /* To covert SDL_Colour to SDLPango_Matrix */
+//   SDLPango_Matrix* colour = NULL;
+//   /* Create a context which contains Pango objects.*/
+//   SDLPango_Context* context = NULL;
+// 
+//   LOG("\nEntering BlackOutline_SDLPango()\n");
+//   DEBUGCODE{ fprintf(stderr, "will attempt to render: %s\n", t); }
+// 
+//   if (!t || !font || !c)
+//   {
+//     fprintf(stderr, "BlackOutline_SDLPango(): invalid ptr parameter, returning.");
+//     return NULL;
+//   }
+// 
+//   /* SDLPango crashes on 64 bit machines if passed empty string - Debian Bug#439071 */
+//   if (*t == '\0')
+//   {
+//     fprintf(stderr, "BlackOutline_SDLPango(): empty string arg - must return to avoid segfault.");
+//     return NULL;
+//   }
+// 
+//   colour = SDL_Colour_to_SDLPango_Matrix(c);
+//   
+//   /* Create the context */
+//   context = SDLPango_CreateContext();	
+//   SDLPango_SetDpi(context, 125.0, 125.0);
+//   /* Set the color */
+//   SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_BLACK_LETTER );
+//   SDLPango_SetBaseDirection(context, SDLPANGO_DIRECTION_LTR);
+//   /* Set text to context */ 
+//   SDLPango_SetMarkup(context, t, -1); 
+// 
+//   if (!context)
+//   {
+//     fprintf (stderr, "In BlackOutline_SDLPango(), could not create context for %s", t);
+//     return NULL;
+//   }
+// 
+//   black_letters = SDLPango_CreateSurfaceDraw(context);
+// 
+//   if (!black_letters)
+//   {
+//     fprintf (stderr, "Warning - BlackOutline_SDLPango() could not create image for %s\n", t);
+//     return NULL;
+//   }
+// 
+//   bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
+//                             (black_letters->w) + 5,
+//                             (black_letters->h) + 5,
+//                              32,
+//                              RMASK, GMASK, BMASK, AMASK);
+//   if (!bg)
+//   {
+//     fprintf (stderr, "Warning - BlackOutline()_SDLPango - bg creation failed\n");
+//     SDL_FreeSurface(black_letters);
+//     return NULL;
+//   }
+// 
+//   /* Draw text on a existing surface */
+//   SDLPango_Draw(context, bg, 0, 0);
+// 
+//   /* Use color key for eventual transparency: */
+//   color_key = SDL_MapRGB(bg->format, 10, 10, 10);
+//   SDL_FillRect(bg, NULL, color_key);
+// 
+//   /* Now draw black outline/shadow 2 pixels on each side: */
+//   dstrect.w = black_letters->w;
+//   dstrect.h = black_letters->h;
+// 
+//   /* NOTE: can make the "shadow" more or less pronounced by */
+//   /* changing the parameters of these loops.                */
+//   for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
+//     for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
+//       SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
+// 
+//   SDL_FreeSurface(black_letters);
+// 
+//   /* --- Put the color version of the text on top! --- */
+//   SDLPango_SetDefaultColor(context, colour);
+//   white_letters = SDLPango_CreateSurfaceDraw(context);
+//   dstrect.x = 1;
+//   dstrect.y = 1;
+//   SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
+//   SDL_FreeSurface(white_letters);
+// 
+//   /* --- Convert to the screen format for quicker blits --- */
+//   SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
+//   out = SDL_DisplayFormatAlpha(bg);
+//   SDL_FreeSurface(bg);
+// 
+//   LOG("Leaving BlackOutline_SDLPango()\n\n");
+// 
+//   return out;
+// }
+
+#endif
+#endif
+/* End of win32-excluded coded */
+
+
+
+
+// /* This version takes a wide character string and renders it with the */
+// /* Unicode string versions of the SDL_ttf functions:                  */
+// SDL_Surface* BlackOutline_Unicode(const Uint16* t, const TTF_Font* font, const SDL_Color* c)
+// {
+//   SDL_Surface* out = NULL;
+//   SDL_Surface* black_letters = NULL;
+//   SDL_Surface* white_letters = NULL;
+//   SDL_Surface* bg = NULL;
+//   SDL_Rect dstrect;
+//   Uint32 color_key;
+// 
+//   if (!font || !c)
+//   {
+//     fprintf(stderr, "BlackOutline_wchar(): invalid ptr parameter, returning.");
+//     return NULL;
+//   }
+//                                         /* (cast to stop compiler complaint) */
+//   black_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, black);
+// 
+//   if (!black_letters)
+//   {
+//     fprintf (stderr, "Warning - BlackOutline_wchar() could not create image for %S\n", t);
+//     return NULL;
+//   }
+// 
+//   bg = SDL_CreateRGBSurface(SDL_SWSURFACE,
+//                             (black_letters->w) + 5,
+//                             (black_letters->h) + 5,
+//                              32,
+//                              RMASK, GMASK, BMASK, AMASK);
+//   /* Use color key for eventual transparency: */
+//   color_key = SDL_MapRGB(bg->format, 10, 10, 10);
+//   SDL_FillRect(bg, NULL, color_key);
+// 
+//   /* Now draw black outline/shadow 2 pixels on each side: */
+//   dstrect.w = black_letters->w;
+//   dstrect.h = black_letters->h;
+// 
+//   /* NOTE: can make the "shadow" more or less pronounced by */
+//   /* changing the parameters of these loops.                */
+//   for (dstrect.x = 1; dstrect.x < 4; dstrect.x++)
+//     for (dstrect.y = 1; dstrect.y < 3; dstrect.y++)
+//       SDL_BlitSurface(black_letters , NULL, bg, &dstrect );
+// 
+//   SDL_FreeSurface(black_letters);
+// 
+//   /* --- Put the color version of the text on top! --- */
+//                                        /* (cast to stop compiler complaint) */
+//   white_letters = TTF_RenderUNICODE_Blended((TTF_Font*)font, t, *c);
+//   dstrect.x = 1;
+//   dstrect.y = 1;
+//   SDL_BlitSurface(white_letters, NULL, bg, &dstrect);
+//   SDL_FreeSurface(white_letters);
+// 
+//   /* --- Convert to the screen format for quicker blits --- */
+//   SDL_SetColorKey(bg, SDL_SRCCOLORKEY|SDL_RLEACCEL, color_key);
+//   out = SDL_DisplayFormatAlpha(bg);
+//   SDL_FreeSurface(bg);
+// 
+//   return out;
+// }
+
+
+/* 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);
+}
+
+
+/* Returns a random Unicode char from the char_glyphs list: */
+/* --- get a letter --- */
+wchar_t GetRandLetter(void)
+{
+  static wchar_t last = -1; // we don't want to return same letter twice in a row
+  wchar_t letter;
+  int i = 0;
+
+  if (!num_chars_used)
+  {
+    fprintf(stderr, "GetRandLetter() - no letters in list!\n");
+    last = -1;
+    return -1;
+  }
+
+  do
+  {
+    i = rand() % num_chars_used;
+    letter = char_glyphs[i].unicode_value;
+  } while (letter == last);
+
+  last = letter;
+
+  return letter;
+}
+
+/******************************************************************************
+*                           WORD FILE & DATA STRUCTURE                        *
+******************************************************************************/
+
+
+
+/* ClearWordList: clears the number of words
+ */
+void ClearWordList(void)
+{
+  int i;
+  for (i = 0; i < num_words; i++)
+  {
+    word_list[i][0] = '\0';
+  }
+  num_words = 0;
+}
+
+/* FIXME need a better i18n-compatible way to do this: */
+/* UseAlphabet(): setups the word_list so that it really
+ * returns a LETTER when GetWord() is called
+ */
+// void UseAlphabet(void)
+// {
+// 	int i;
+// 
+// 	LOG("Entering UseAlphabet()\n");
+// 
+// 	num_words = 0;
+// 	/* This totally mucks up i18n abilities :( */
+// 	for (i=65; i<90; i++) 
+// 	{
+// 		//if (ALPHABET[i])
+//                 {
+// 			word_list[num_words][0] = (unsigned char)i;
+// 			word_list[num_words][1] = '\0';
+// 			num_words++;
+// 
+// 			DEBUGCODE { fprintf(stderr, "Adding %c\n", (unsigned char)i); }
+// 		}
+// 	}
+// 	/* Make sure list is terminated with null character */
+// 	word_list[num_words][0] = '\0';
+// 
+// 	/* Make list of all unicode characters used in word list: */
+// 	gen_char_list();
+// 
+// 	DOUT(num_words);
+// 	LOG("Leaving UseAlphabet()\n");
+// }
+
+/* GetWord: returns a random word that wasn't returned
+ * the previous time (unless there is only 1 word!!!)
+ */
+wchar_t* GetWord(void)
+{
+	static int last_choice = -1;
+	int choice;
+
+	LOG("Entering GetWord()\n");
+	DEBUGCODE { fprintf(stderr, "num_words is: %d\n", num_words); }
+
+	/* Now count list to make sure num_words is correct: */
+
+	num_words = 0;
+	while (word_list[num_words][0] != '\0')
+	{
+	  num_words++;
+	}
+
+	DEBUGCODE { fprintf(stderr, "After count, num_words is: %d\n", num_words); }
+
+        if (0 == num_words)
+	{
+	  LOG("No words in list\n");
+          return NULL;
+	}
+
+        if (num_words > MAX_NUM_WORDS)
+	{
+	  LOG("Error: num_words greater than array size\n");
+          return NULL;
+	}
+
+        if (num_words < 0)
+	{
+	  LOG("Error: num_words negative\n");
+          return NULL;
+	}
+
+	do {
+		choice = (rand() % num_words);
+	} while ((choice == last_choice) || (num_words < 2));
+
+	last_choice = choice;
+
+	/* NOTE need %S rather than %s because of wide characters */
+	DEBUGCODE { fprintf(stderr, "Selected word is: %S\n", word_list[choice]); }
+
+	return word_list[choice];
+}
+
+
+
+/* GenerateWordList(): adds the words from a given wordlist
+ * it ignores any words too long or that has bad
+ * character (such as #)
+ */
+
+/* Now returns the number of words in the list, so if no words */
+/* returns "false"                                             */
+int GenerateWordList(const char* wordFn)
+{
+  int j;
+  unsigned char temp_word[FNLEN];
+  wchar_t temp_wide_word[FNLEN];
+  size_t length;
+
+  FILE* wordFile=NULL;
+
+  DEBUGCODE { fprintf(stderr, "Entering GenerateWordList() for file: %s\n", wordFn); }
+
+  num_words = 0;
+
+  /* --- open the file --- */
+
+  wordFile = fopen( wordFn, "r" );
+
+  if ( wordFile == NULL )
+  {
+    fprintf(stderr, "ERROR: could not load wordlist: %s\n", wordFn );
+//    UseAlphabet( );
+    return 0;
+  }
+
+
+  /* --- load words from file named as argument: */
+
+  DEBUGCODE { fprintf(stderr, "WORD FILE OPENNED @ %s\n", wordFn); }
+
+  /* ignore the title (i.e. first line) */
+  fscanf( wordFile, "%[^\n]\n", temp_word);
+
+  while (!feof(wordFile) && (num_words < MAX_NUM_WORDS))
+  {
+    fscanf( wordFile, "%[^\n]\n", temp_word);
+    DEBUGCODE {fprintf(stderr, "temp_word = %s\n", temp_word);}
+
+    for (j = 0; j < strlen(temp_word); j++)
+    {
+      if (temp_word[j] == '\n' || temp_word[j] == '\r')
+        temp_word[j] = '\0';
+    }
+
+    /* 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);
+    DOUT(length);
+
+    if (length == -1)  /* Means invalid UTF-8 sequence or conversion failed */
+    {
+      fprintf(stderr, "Word '%s' not added - invalid UTF-8 sequence!\n", temp_word);
+      continue;
+    }
+
+    if (length == 0)
+    {
+      fprintf(stderr, "Word '%ls' not added - length is zero\n", temp_wide_word);
+      continue;
+    }
+
+    if (length > MAX_WORD_SIZE)
+    {
+      fprintf(stderr, "Word '%s' not added - exceeds %d characters\n",
+              temp_word, MAX_WORD_SIZE);
+      continue;
+    }
+
+    if (num_words >= MAX_NUM_WORDS)
+    {
+      fprintf(stderr, "Word '%s' not added - list has reached max of %d characters\n",
+              temp_word, MAX_NUM_WORDS);
+      continue;
+    }
+
+    if (!check_needed_unicodes_str(temp_wide_word))
+    {
+      fprintf(stderr, "Word '%S' not added - contains Unicode chars not in keyboard list\n",
+              temp_wide_word);
+      continue;
+    }
+
+    /* If we make it to here, OK to add word: */
+    /* NOTE we have to add one to the length argument */
+    /* to include the terminating null.  */
+    DEBUGCODE
+    {
+      fprintf(stderr, "Adding word: %ls\n", temp_wide_word);
+    }
+
+    wcsncpy(word_list[num_words], temp_wide_word, strlen(temp_word) + 1);
+    num_words++;
+  }
+        
+  /* Make sure list is terminated with null character */
+  word_list[num_words][0] = '\0';
+
+  DOUT(num_words);
+
+//  if (num_words == 0)
+//    UseAlphabet( );
+
+  fclose(wordFile);
+
+  /* Make list of all unicode characters used in word list: */
+  /* (we use this to check to make sure all are "typable"); */
+  gen_char_list();
+
+  LOG("Leaving GenerateWordList()\n");
+
+  return (num_words);
+}
+
+
+
+
+
+
+/* This version creates the letters using TTF_RenderUNICODE_Blended */
+int RenderLetters(const TTF_Font* letter_font)
+{
+  Uint16 t[2];
+  int i, j;  /* i is chars attempted, j is chars actually rendered. */
+
+  if (!letter_font)
+  {
+    fprintf(stderr, "RenderLetters() - invalid TTF_Font* argument!\n");
+    return 0;
+  }
+
+  i = j = num_chars_used = 0;
+
+  t[1] = '\0';
+
+  while (i < MAX_UNICODES)
+  {
+    t[0] = keyboard_list[i].unicode_value;
+
+    if (t[0] != 0)
+    {
+      DEBUGCODE
+      {
+        fprintf(stderr, "Creating SDL_Surface for list element %d, char = '%lc', Unicode value = %d\n", i, *t, *t);
+      }
+
+      char_glyphs[j].unicode_value = t[0];
+      char_glyphs[j].white_glyph = BlackOutline_Unicode(t, letter_font, &white);
+      char_glyphs[j].red_glyph = BlackOutline_Unicode(t, letter_font, &red);
+
+      j++;
+      num_chars_used++;
+    }
+    i++;
+  }
+
+  return num_chars_used;
+}
+
+
+
+void FreeLetters(void)
+{
+  int i;
+
+  for (i = 0; i < num_chars_used; i++)
+  {
+    SDL_FreeSurface(char_glyphs[i].white_glyph);
+    SDL_FreeSurface(char_glyphs[i].red_glyph);
+    char_glyphs[i].unicode_value = 0;
+    char_glyphs[i].white_glyph = NULL;
+    char_glyphs[i].red_glyph = NULL;
+  } 
+  /* List now empty: */
+  num_chars_used = 0;
+}
+
+
+SDL_Surface* GetWhiteGlyph(wchar_t t)
+{
+  int i;
+
+  for (i = 0;
+       (char_glyphs[i].unicode_value != t) && (i <= num_chars_used);
+       i++)
+  {}
+
+  /* Now return appropriate pointer: */
+  if (i > num_chars_used)
+  {
+    /* Didn't find character: */
+    fprintf(stderr, "Could not find glyph for Unicode char '%C', value = %d\n", t, t);
+    return NULL;
+  }
+  
+  /* Return corresponding surface for blitting: */
+  return char_glyphs[i].white_glyph;
+}
+
+
+
+SDL_Surface* GetRedGlyph(wchar_t t)
+{
+  int i;
+
+  for (i = 0;
+       char_glyphs[i].unicode_value != t && i <= num_chars_used;
+       i++)
+  {}
+
+  /* Now return appropriate pointer: */
+  if (i > num_chars_used)
+  {
+    /* Didn't find character: */
+    fprintf(stderr, "Could not find glyph for unicode character %lc\n", t);
+    return NULL;
+  }
+  
+  /* Return corresponding surface for blitting: */
+  return char_glyphs[i].red_glyph;
+}
+
+
+/* Checks to see if all of the glyphs needed by the word list have been     */
+/* 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.
+/* Returns 1 if all needed chars found, 0 otherwise.                        */
+int CheckNeededGlyphs(void)
+{
+  int i = 0;
+
+  while ((i < MAX_UNICODES)
+      && (char_list[i] != '\0'))
+  {
+    if (!GetWhiteGlyph(char_list[i]))
+    {
+      fprintf(stderr, "\nCheckNeededGlyphs() - needed char '%C' (Unicode value = %d) not found.\n",
+              char_list[i], char_list[i]);
+      fprintf(stderr, "This probably means that the theme's 'keyboard.lst' file is incorrect or incomplete.\n");
+      return 0;
+    }
+    i++;
+  }
+  LOG("CheckNeededGlyphs() - all chars found.\n");
+  return 1;
+}
+
+int check_needed_unicodes_str(const wchar_t* s)
+{
+  int i = 0;
+
+  while ((i < MAX_WORD_SIZE)
+      && (s[i] != '\0'))
+  {
+    if (!unicode_in_key_list(s[i]))
+    {
+      fprintf(stderr, "\ncheck_needed_unicodes_str() - needed char '%C' (Unicode value = %d) not found.\n",
+              s[i], s[i]);
+      return 0;
+    }
+    i++;
+  }
+  return 1;
+}
+
+/* This function just tidies up all the ptr args needed for      */
+/* ConvertUTF8toUTF32() from Unicode, Inc. into a neat wrapper.  */
+/* 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 i = 0;
+  ConversionResult result;
+  UTF8 temp_UTF8[FNLEN];
+  UTF32 temp_UTF32[FNLEN];
+
+  const UTF8* UTF8_Start = temp_UTF8;
+  const UTF8* UTF8_End = &temp_UTF8[FNLEN-1];
+  UTF32* UTF32_Start = temp_UTF32;
+  UTF32* UTF32_End = &temp_UTF32[FNLEN-1];
+
+  strncpy(temp_UTF8, UTF8_word, FNLEN);
+
+  ConvertUTF8toUTF32(&UTF8_Start, UTF8_End,
+                     &UTF32_Start, UTF32_End, 0);
+
+  wide_word[0] = '\0';
+
+  while ((i < FNLEN) && (temp_UTF32[i] != '\0'))
+  {
+    wide_word[i] = temp_UTF32[i];
+    i++; 
+  }
+
+  if (i >= FNLEN)
+  {
+    fprintf(stderr, "convert_from_UTF8(): buffer overflow\n");
+    return -1;
+  }
+  else  //need terminating null:
+  {
+    wide_word[i] = '\0';
+  }
+
+  DEBUGCODE {fprintf(stderr, "wide_word = %ls\n", wide_word);}
+
+  return wcslen(wide_word);
+}
+
+
+/* Now this uses GNU iconv and works correctly!   */
+/* This probably could be simplified - not certain */
+/* we have to copy into and out of the buffers     */
+
+/******************To be used for savekeyboard*************/
+/***Converts wchar_t string to char string*****************/
+int ConvertToUTF8(wchar_t* wide_word, unsigned char* UTF8_word)
+{
+  int i = 0;
+  UTF8 temp_UTF8[FNLEN];
+  UTF32 temp_UTF32[FNLEN];
+
+  UTF8* UTF8_Start = &temp_UTF8[0];
+  UTF8* UTF8_End = &temp_UTF8[FNLEN - 1];
+  const UTF32* UTF32_Start = &temp_UTF32[0];
+  const UTF32* UTF32_End = &temp_UTF32[FNLEN - 1];
+  
+  iconv_t conv_descr;
+  size_t bytes_converted;
+  size_t in_length = (size_t)FNLEN;
+  size_t out_length = (size_t)FNLEN;
+  wcsncpy(temp_UTF32, wide_word, FNLEN);
+
+  DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): wide_word = %S\n", wide_word);}
+  DEBUGCODE {fprintf(stderr, "ConvertToUTF8(): temp_UTF32 = %S\n", temp_UTF32);}
+
+  conv_descr = iconv_open ("UTF-8", "UTF-32");
+  bytes_converted = iconv(conv_descr,
+                          &UTF32_Start, &in_length,
+                          &UTF8_Start, &out_length);
+  iconv_close(conv_descr);
+
+  UTF8_word[0] = 0;
+
+  while ((i < FNLEN) && (temp_UTF8[i] != 0))
+  {
+    UTF8_word[i] = temp_UTF8[i];
+    i++; 
+  }
+
+  if (i >= FNLEN)
+  {
+    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);}
+
+  return strlen(UTF8_word);
+}
+
+
+
+/******************************************************************/
+int map_keys(wchar_t wide_char,kbd_char* keyboard_entry)
+{
+	switch(wide_char)
+	{
+		case '`':strcpy(keyboard_entry->keyname,"A00");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=0;
+			break;
+		case '~':strcpy(keyboard_entry->keyname,"A00");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=0;
+			break;
+		case '1':strcpy(keyboard_entry->keyname,"A01");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=0;
+			break;
+		case '!':strcpy(keyboard_entry->keyname,"A01");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=0;
+			break;
+		case '2':strcpy(keyboard_entry->keyname,"A02");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=1;
+			break;
+		case '@':strcpy(keyboard_entry->keyname,"A02");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=1;
+			break;
+		case '3':strcpy(keyboard_entry->keyname,"A03");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=2;
+			break;
+		case '#':strcpy(keyboard_entry->keyname,"A03");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=2;
+			break;
+		case '4':strcpy(keyboard_entry->keyname,"A04");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=3;
+			break;
+		case '$':strcpy(keyboard_entry->keyname,"A04");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=3;
+			break;
+		case '5':strcpy(keyboard_entry->keyname,"A05");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=4;
+			break;
+		case '%':strcpy(keyboard_entry->keyname,"A05");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=4;
+			break;
+		case '6':strcpy(keyboard_entry->keyname,"A06");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=5;
+			break;
+		case '^':strcpy(keyboard_entry->keyname,"A06");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=5;
+			break;
+		case '7':strcpy(keyboard_entry->keyname,"A07");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=7;
+			break;
+		case '&':strcpy(keyboard_entry->keyname,"A07");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=6;
+			break;
+		case '8':strcpy(keyboard_entry->keyname,"A08");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=7;
+			break;
+		case '*':strcpy(keyboard_entry->keyname,"A08");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=7;
+			break;
+		case '9':strcpy(keyboard_entry->keyname,"A09");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=8;
+			break;
+		case '(':strcpy(keyboard_entry->keyname,"A09");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=8;
+			break;
+		case '0':strcpy(keyboard_entry->keyname,"A10");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case ')':strcpy(keyboard_entry->keyname,"A10");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;
+		case '-':strcpy(keyboard_entry->keyname,"A11");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case '_':strcpy(keyboard_entry->keyname,"A11");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;
+		case '=':strcpy(keyboard_entry->keyname,"A12");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case '+':strcpy(keyboard_entry->keyname,"A12");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;
+		case '\\':strcpy(keyboard_entry->keyname,"A13");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case '|':strcpy(keyboard_entry->keyname,"A13");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;
+		case 'q':strcpy(keyboard_entry->keyname,"B01");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=0;
+			break;
+		case 'Q':strcpy(keyboard_entry->keyname,"B01");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=0;
+			break;
+		case 'w':strcpy(keyboard_entry->keyname,"B02");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=1;
+			break;
+		case 'W':strcpy(keyboard_entry->keyname,"B02");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=1;
+			break;
+		case 'e':strcpy(keyboard_entry->keyname,"B03");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=2;
+			break;
+		case 'E':strcpy(keyboard_entry->keyname,"B03");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=3;
+			break;
+		case 'r':strcpy(keyboard_entry->keyname,"B04");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=3;
+			break;
+		case 'R':strcpy(keyboard_entry->keyname,"B04");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=3;
+			break;
+		case 't':strcpy(keyboard_entry->keyname,"B05");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=4;
+			break;
+		case 'T':strcpy(keyboard_entry->keyname,"B05");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=4;
+			break;
+		case 'y':strcpy(keyboard_entry->keyname,"B06");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=5;
+			break;
+		case 'Y':strcpy(keyboard_entry->keyname,"B06");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=5;
+			break;
+		case 'u':strcpy(keyboard_entry->keyname,"B07");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=6;
+			break;
+		case 'U':strcpy(keyboard_entry->keyname,"B07");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=6;
+			break;
+		case 'i':strcpy(keyboard_entry->keyname,"B08");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=7;
+			break;
+		case 'I':strcpy(keyboard_entry->keyname,"B08");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=7;
+			break;
+		case 'o':strcpy(keyboard_entry->keyname,"B09");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=8;
+			break;
+		case 'O':strcpy(keyboard_entry->keyname,"B09");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=8;
+			break;
+		case 'p':strcpy(keyboard_entry->keyname,"B10");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case 'P':strcpy(keyboard_entry->keyname,"B10");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;
+		case '[':strcpy(keyboard_entry->keyname,"B11");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case '{':strcpy(keyboard_entry->keyname,"B11");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;
+		case ']':strcpy(keyboard_entry->keyname,"B12");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case '}':strcpy(keyboard_entry->keyname,"B12");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;
+		case 'a':strcpy(keyboard_entry->keyname,"C01");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=0;
+			break;
+		case 'A':strcpy(keyboard_entry->keyname,"C01");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=0;
+			break;
+		case 's':strcpy(keyboard_entry->keyname,"C02");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=1;
+			break;
+		case 'S':strcpy(keyboard_entry->keyname,"C02");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=1;
+			break;
+		case 'd':strcpy(keyboard_entry->keyname,"C03");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=2;
+			break;
+		case 'D':strcpy(keyboard_entry->keyname,"C03");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=2;
+			break;
+		case 'f':strcpy(keyboard_entry->keyname,"C04");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=3;
+			break;
+		case 'F':strcpy(keyboard_entry->keyname,"C04");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=3;
+			break;
+		case 'g':strcpy(keyboard_entry->keyname,"C05");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=4;
+			break;
+		case 'G':strcpy(keyboard_entry->keyname,"C05");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=4;
+			break;
+		case 'h':strcpy(keyboard_entry->keyname,"C06");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=5;
+			break;
+		case 'H':strcpy(keyboard_entry->keyname,"C06");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=5;
+			break;
+		case 'j':strcpy(keyboard_entry->keyname,"C07");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=6;
+			break;
+		case 'J':strcpy(keyboard_entry->keyname,"C07");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=6;
+			break;
+		case 'k':strcpy(keyboard_entry->keyname,"C08");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=7;
+			break;
+		case 'K':strcpy(keyboard_entry->keyname,"C08");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=7;
+			break;
+		case 'l':strcpy(keyboard_entry->keyname,"C09");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=8;
+			break;
+		case 'L':strcpy(keyboard_entry->keyname,"C09");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=8;
+			break;
+		case ';':strcpy(keyboard_entry->keyname,"C10");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case ':':strcpy(keyboard_entry->keyname,"C10");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;			
+		case '\'':strcpy(keyboard_entry->keyname,"C11");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case '"':strcpy(keyboard_entry->keyname,"C11");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;
+		case 'z':strcpy(keyboard_entry->keyname,"D01");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=0;
+			break;
+		case 'Z':strcpy(keyboard_entry->keyname,"D01");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=0;
+			break;
+		case 'x':strcpy(keyboard_entry->keyname,"D02");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=1;
+			break;
+		case 'X':strcpy(keyboard_entry->keyname,"D02");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=1;
+			break;
+		case 'c':strcpy(keyboard_entry->keyname,"D03");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=2;
+			break;
+		case 'C':strcpy(keyboard_entry->keyname,"D03");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=2;
+			break;
+		case 'v':strcpy(keyboard_entry->keyname,"D04");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=3;
+			break;
+		case 'V':strcpy(keyboard_entry->keyname,"D04");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=3;
+			break;
+		case 'b':strcpy(keyboard_entry->keyname,"D05");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=4;
+			break;
+		case 'B':strcpy(keyboard_entry->keyname,"D05");
+			keyboard_entry->shift=2;
+			keyboard_entry->finger=4;
+			break;
+		case 'n':strcpy(keyboard_entry->keyname,"D06");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=5;
+			break;
+		case 'N':strcpy(keyboard_entry->keyname,"D06");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=5;
+			break;
+		case 'm':strcpy(keyboard_entry->keyname,"D07");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=6;
+			break;
+		case 'M':strcpy(keyboard_entry->keyname,"D07");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=6;
+			break;
+		case ',':strcpy(keyboard_entry->keyname,"D08");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=7;
+			break;
+		case '<':strcpy(keyboard_entry->keyname,"D08");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=7;
+			break;
+		case '.':strcpy(keyboard_entry->keyname,"D09");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=8;
+			break;
+		case '>':strcpy(keyboard_entry->keyname,"D09");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=8;
+			break;
+		case '/':strcpy(keyboard_entry->keyname,"D10");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=9;
+			break;
+		case '?':strcpy(keyboard_entry->keyname,"D10");
+			keyboard_entry->shift=1;
+			keyboard_entry->finger=9;
+			break;
+		case ' ':strcpy(keyboard_entry->keyname,"E03");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=5;
+			break;
+		default:strcpy(keyboard_entry->keyname,"None");
+			keyboard_entry->shift=0;
+			keyboard_entry->finger=-1;
+			break;
+	}
+}
+
+void GenerateKeyboard(SDL_Surface* keyboard)
+{
+	SDL_Surface* tmp = NULL;
+	SDL_Rect new;
+	int i;
+	int col;
+	char row;
+	int render=1;
+	Uint16 t[2];
+	TTF_Font* smallfont = NULL;
+	DEBUGCODE { printf("Entering GenerateKeyboard\n"); }
+	t[1] = '\0';
+	smallfont = LoadFont(settings.theme_font_name, 15);
+	if(!smallfont)
+	{
+		DEBUGCODE { printf("Error loading font\n"); }
+		return;
+	}
+	for(i=0;i < num_chars_used;i++)
+	{
+		render=1;
+		new.x=0;
+		new.y=0;
+		new.w=5;
+		new.h=5;
+		t[0]=keyboard_list[i].unicode_value;
+		sscanf(keyboard_list[i].keyname,"%c%d",&row,&col);
+		switch(row)
+		{
+			case 'A':new.y+=6;new.x+=13;break;
+			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;
+			default: render=0;break;
+		}
+		if(!render)
+			continue;
+		new.x+=31*col;
+		if(keyboard_list[i].shift>0)
+		{
+					new.x-=9;
+					if(new.y<9)
+						new.y-=5;
+					else
+						new.y-=9;
+		}
+		DEBUGCODE { printf("Making %d : %C\n",i,keyboard_list[i].unicode_value); }
+		//tmp=BlackOutline_Unicode(t, smallfont, &black);
+		tmp=TTF_RenderUNICODE_Blended((TTF_Font*)smallfont, t, black);
+		if(tmp==NULL)
+		{
+			DEBUGCODE { printf("Error Making %d : %C\n",i,keyboard_list[i].unicode_value); }
+		}
+		SDL_BlitSurface(tmp, NULL, keyboard, &new);
+	}	
+	TTF_CloseFont(smallfont);
+	DEBUGCODE { printf("Leaving GenerateKeyboard\n"); }
+}
+void updatekeylist(int key,char ch)
+{
+	wchar_t;
+	keyboard_list[key].latin_char=ch;
+	wchar_t wtmp=ch;
+	map_keys(wtmp,&keyboard_list[key]);
+}
+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);
+
+	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);
+		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);
+}
+/****************************************************************/
+
+/****************************************************/
+/*                                                  */
+/*       Local ("private") functions:               */
+/*                                                  */
+/****************************************************/
+
+
+/* Creates a list of distinct Unicode characters in */
+/* word_list[][] (so the program knows what         */
+/* needs to be rendered for the games)              */
+static void gen_char_list(void)
+{
+  int i, j;
+  i = j = 0;
+  char_list[0] = '\0';
+
+  while (word_list[i][0] != '\0' && i < MAX_NUM_WORDS) 
+  {
+    j = 0;
+
+    while (word_list[i][j]!= '\0' && j < MAX_WORD_SIZE)
+    {
+      add_char(word_list[i][j]);
+      j++;
+    }
+
+    i++;
+  }
+
+  DEBUGCODE
+  {
+    fprintf(stderr, "char_list = %S\n", char_list);
+  }
+}
+
+
+
+void ResetCharList(void)
+{
+  char_list[0] = '\0';
+}
+
+
+
+/* Creates a list of distinct Unicode characters in       */
+/* the argument string for subsequent rendering.          */
+/* Like gen_char_list() but takes a string argument       */
+/* instead of going through the currently selected        */
+/* word list. Argument should be UTF-8                    */
+/* Can be called multiple times on different strings      */
+/* to accumulate entire repertoire - call ResetCharList() */
+/* to start over                                          */
+void GenCharListFromString(const unsigned char* UTF8_str)
+{
+  int i = 0;
+  wchar_t wchar_buf[MAX_UNICODES];
+
+  ConvertFromUTF8(wchar_buf, UTF8_str);
+
+  /* FNLEN is max length of phrase (I think) */
+  while (wchar_buf[i] != '\0' && i < FNLEN) 
+  {
+    add_char(wchar_buf[i]);
+    i++;
+  }
+
+  DEBUGCODE
+  {
+    fprintf(stderr, "char_list = %S\n", char_list);
+  }
+}
+
+
+
+/* FIXME this function is currently dead code */
+/* --- setup the alphabet --- */
+static void set_letters(unsigned 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++;
+		}
+}
+
+
+
+/* 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:                           */
+/* FIXME performance would be better with hashtable                 */
+static int add_char(wchar_t uc)
+{
+  int i = 0;
+  while ((char_list[i] != uc)
+      && (char_list[i] != '\0')
+      && (i < MAX_UNICODES - 1))          //Because 1 need for null terminator
+  {
+    i++;
+  }
+
+  /* unicode already in list: */
+  if (char_list[i] == uc)
+  {
+    DEBUGCODE{ fprintf(stderr,
+                       "Unicode value: %d\tcharacter %lc already in list\n",
+                        uc, uc);}
+    return 0;
+  }
+
+  if (char_list[i] == '\0')
+  {
+    DEBUGCODE{ fprintf(stderr, "Adding unicode value: %d\tcharacter %lc\n", uc, uc);}
+    char_list[i] = uc;
+    char_list[i + 1] = '\0';
+    return 1;
+  }
+
+  if (i == MAX_UNICODES - 1)            //Because 1 need for null terminator
+  {
+    LOG ("Unable to add unicode - list at max capacity");
+    return -1;
+  }
+}
+
+
+
+static void clear_keyboard(void)
+{
+  int i = 0;
+  for (i = 0; i < MAX_UNICODES; i++)
+  {
+    keyboard_list[i].unicode_value = 0;
+    keyboard_list[i].finger = -1;
+  }
+}
+
+
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/audio.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/audio.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/audio.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/audio.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,66 @@
+/***************************************************************************
+ -  file: audio.c
+ -  description: this file contains audio related functions
+                            -------------------
+    begin                : Jan 22, 2003
+    copyright            : Sam Hart, Jesse Andrews (C) 2003
+    email                : tuxtype-dev at tux4kids.net
+***************************************************************************/
+
+/***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+
+static Mix_Music* defaultMusic = NULL; // holds music for audioMusicLoad/unload
+
+
+void PlaySound(Mix_Chunk* snd) {
+	if (!settings.sys_sound) return;
+
+	Mix_PlayChannel(-1, snd, 0);
+}
+
+/* MusicLoad attempts to load and play the music file 
+ * Note: loops == -1 means forever
+ */
+void MusicLoad(const char *musicFilename, int loops ) {
+	if (!settings.sys_sound) return;
+
+	MusicUnload(); // make sure defaultMusic is clear
+
+	defaultMusic = LoadMusic( musicFilename );
+	Mix_PlayMusic( defaultMusic, loops );
+}
+
+/* MusicUnload attempts to unload any music data that was
+ * loaded using the audioMusicLoad function
+ */
+void MusicUnload( void ) {
+	if (!settings.sys_sound) return;
+
+	if ( defaultMusic )
+		Mix_FreeMusic( defaultMusic );
+
+	defaultMusic = NULL;
+}
+
+/* audioMusicPlay attempts to play the passed music data. 
+ * if a music file was loaded using the audioMusicLoad
+ * it will be stopped and unloaded
+ * Note: loops == -1 means forever
+ */
+void MusicPlay(Mix_Music* musicData, int loops)
+{ 
+  if (!settings.sys_sound) return;
+  /* Stop previous music before playing new one: */
+  MusicUnload();	
+  Mix_PlayMusic(musicData, loops);
+}

Copied: tuxtype/branches/tuxtype-soc-mh/src/compiler.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/compiler.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/compiler.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/compiler.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,157 @@
+/*
+  compiler.h
+
+  Compiler-specific #defines and such
+  for Tux Paint
+
+  Mostly by Albert Cahalan <albert at users.sf.net>
+  Copyright (c) 2002-2006
+
+  http://www.newbreedsoftware.com/tuxpaint/
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  (See COPYING.txt)
+
+  June 14, 2002 - February 18, 2006
+  $Id: compiler.h,v 1.5 2006/08/27 21:00:55 wkendrick Exp $
+
+  June 09, 2008:
+  Brought into TuxMath by Brendan Luchen as part of pixel-manipulation
+  code, with blessings of Bill Kendrick.
+
+*/
+
+#ifdef WIN32
+/* Horrible, dangerous macros. */
+/*
+  The SDL stderr redirection trick doesn't seem to work for perror().
+  This does pretty much the same thing.
+*/
+#define perror(str) ({ \
+  if ( (str) && *(str) ) \
+    fprintf(stderr,"%s : ",(str)); \
+  fprintf(stderr, \
+          "%s [%d]\n", \
+          (errno<_sys_nerr)?_sys_errlist[errno]:"unknown",errno ); \
+})
+
+/*
+  MinGW implementation of isspace() crashes on some Win98 boxes
+  if c is 'out-of-range'.
+*/
+#define isspace(c) (((c) == 0x20) || ((c) >= 0x09 && (c) <= 0x0D))
+
+/*
+  WIN32 and MINGW don't have strcasestr().
+*/
+#define NOMINMAX
+#include "shlwapi.h"
+#define strcasestr StrStrI
+#endif /* WIN32 */
+
+
+
+
+#ifdef __GNUC__
+// This version has strict type checking for safety.
+// See the "unnecessary" pointer comparison. (from Linux)
+#define min(x,y) ({ \
+  typeof(x) _x = (x);     \
+  typeof(y) _y = (y);     \
+  (void) (&_x == &_y);            \
+  _x < _y ? _x : _y; })
+#define max(x,y) ({ \
+  typeof(x) _x = (x);     \
+  typeof(y) _y = (y);     \
+  (void) (&_x == &_y);            \
+  _x > _y ? _x : _y; })
+#else
+#define min(a,b) (((a) < (b)) ? (a) : (b))
+#define max(a,b) (((a) > (b)) ? (a) : (b))
+#endif
+
+#define clamp(lo,value,hi)    (min(max(value,lo),hi))
+
+
+// since gcc-2.5
+#ifdef __GNUC__
+#define NORETURN __attribute__((__noreturn__))
+#define FUNCTION __attribute__((__const__))	// no access to global mem, even via ptr, and no side effect
+#else
+#define NORETURN
+#define FUNCTION
+#endif
+
+#if !defined(restrict) && __STDC_VERSION__ < 199901
+#if __GNUC__ > 2 || __GNUC_MINOR__ >= 92
+#define restrict __restrict__
+#else
+#warning No restrict keyword?
+#define restrict
+#endif
+#endif
+
+
+#if __GNUC__ > 2 || __GNUC_MINOR__ >= 96
+// won't alias anything, and aligned enough for anything
+#define MALLOC __attribute__ ((__malloc__))
+// no side effect, may read globals
+#ifndef WIN32
+#define PURE __attribute__ ((__pure__))
+#endif
+// tell gcc what to expect:   if(unlikely(err)) die(err);
+#define likely(x)       __builtin_expect(!!(x),1)
+#define unlikely(x)     __builtin_expect(!!(x),0)
+#define expected(x,y)   __builtin_expect((x),(y))
+#else
+#define MALLOC
+#define PURE
+#define likely(x)       (x)
+#define unlikely(x)     (x)
+#define expected(x,y)   (x)
+#endif
+
+
+#ifdef __powerpc__
+// Ticks at 1/4  the memory bus clock (24.907667 MHz on Albert's Mac Cube)
+// This is good for 80-second diff or 160-second total.
+#define CLOCK_ASM(tbl) asm volatile("mftb %0" : "=r" (tbl))
+#define CLOCK_TYPE unsigned long
+#ifndef CLOCK_SPEED
+// #warning Benchmark times are based on a 99.63 MHz memory bus.
+#define CLOCK_SPEED 24907667.0
+#endif
+#endif
+
+#ifdef __i386__
+#define CLOCK_ASM(tbl) asm volatile("rdtsc" : "=A" (tbl))
+#define CLOCK_TYPE unsigned long long
+#ifndef CLOCK_SPEED
+// #warning Benchmark times are based on a 450 MHz CPU.
+#define CLOCK_SPEED 450000000.0
+#endif
+#endif
+
+#ifndef CLOCK_ASM
+// #warning No idea how to read CPU cycles for you, sorry.
+#define CLOCK_ASM(tbl)
+#define CLOCK_TYPE unsigned long
+#define CLOCK_SPEED 1000000000.0
+#endif
+
+#ifdef NO_ASM
+#undef CLOCK_ASM
+#define CLOCK_ASM(x) x=42
+#endif

Copied: tuxtype/branches/tuxtype-soc-mh/src/funcs.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/funcs.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/funcs.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/funcs.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,153 @@
+/***************************************************************************
+                          funcs.h
+  description: function header
+                             -------------------
+    begin                : Sat May 6 2000
+    copyright            : (C) 2000 by Sam Hart
+    email                : hart at geekcomix.com
+ 
+  Modified by David Bruce
+  dbruce at tampabay.rr.com
+  2007
+
+***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+/* NOTE - there is no reason to declare functions using "extern", as all */
+/* non-local functions are visible throughout the program.               */ 
+
+
+/* In alphabet.c */
+//SDL_Surface* BlackOutline(const unsigned 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);
+
+#ifndef WIN32
+//SDL_Surface* BlackOutline_SDLPango(const unsigned char* t, const TTF_Font* font, const SDL_Color* c);
+#endif
+
+/* (still in alphabet.c:) */
+int CheckNeededGlyphs(void);
+void ClearWordList(void);
+int ConvertFromUTF8(wchar_t* wide_word, const unsigned char* UTF8_word);
+void FreeLetters(void);
+int GenerateWordList(const char* wordFn);
+void GenCharListFromString(const unsigned char* UTF8_str);
+void ResetCharList(void);
+wchar_t GetLetter(void);
+wchar_t* GetWord(void);
+SDL_Surface* GetWhiteGlyph(wchar_t t);
+SDL_Surface* GetRedGlyph(wchar_t t);
+int LoadKeyboard(void);
+int GetFinger(int i);
+int RenderLetters(const TTF_Font* letter_font);
+int GetIndex(wchar_t uni_char);
+void GetKeyShift(int index, char *buf);
+void GetKeyPos(int index, char *buf);
+void GetWrongKeyPos(int index, char *buf);
+//int map_keys(wchar_t *wide_str,keymap key);
+void GenerateKeyboard(SDL_Surface* keyboard);
+void updatekeylist(int key,char ch);
+void savekeyboard(void);
+wchar_t GetLastKey(void);
+
+
+//void UseAlphabet(void);
+
+
+/* In audio.c:   */
+void PlaySound(Mix_Chunk* snd);
+void MusicLoad(const char* musicFilename, int repeatQty);
+void MusicUnload(void);
+void MusicPlay(Mix_Music* musicData, int repeatQty);
+
+
+/* In gettext.c:  */
+//unsigned char* gettext(const unsigned char* in);
+//int Load_PO_File(const char* file);
+
+
+/* In laser.c:        */
+int PlayLaserGame(int diff_level);
+
+
+/* In loaders.c: */
+int CheckFile(const char* file);
+sprite* FlipSprite(sprite* in, int X, int Y);
+void FreeSprite(sprite* gfx);
+TTF_Font* LoadFont(const char* fontfile, int fontsize);
+SDL_Surface* LoadImage(const char* datafile, int mode);
+int LoadBothBkgds(const char* datafile);
+SDL_Surface* CurrentBkgd(void);
+void FreeBothBkgds(void);
+void LoadLang(void);
+Mix_Music* LoadMusic(const char* datafile);
+Mix_Chunk* LoadSound(const char* datafile);
+sprite* LoadSprite(const char* name, int MODE);
+
+/* In options.c: */
+void Opts_Initialize(void);
+
+/* In pause.c: */
+int  Pause(void);
+
+
+/* In playgame.c: */
+int PlayCascade(int level);
+void InitEngine(void);
+int TransWipe(SDL_Surface* newbkg, int type, int var1, int var2);
+
+
+/* In practice.c: */
+int Phrases(wchar_t* practice_phrase);
+static void next_letter(wchar_t *t, int c);
+
+
+/* In scripting.c: */
+int TestLesson(void);
+void ProjectInfo(void);
+void InstructCascade(void);
+void InstructLaser(void);
+
+
+/* In setup.c: */
+void GraphicsInit(void);
+void LibInit(Uint32 lib_flags);
+void LoadSettings(void);
+void SaveSettings(void);
+int SetupPaths(const char* theme_dir);
+void Cleanup(void);
+
+/* In theme.c: */
+void ChooseTheme(void);
+
+
+/* In titlescreen.c: */
+//void SwitchScreenMode(void);
+void TitleScreen(void);
+
+/* In profiles.c: */
+void loadProfile(int numProfiles);
+void saveProfile(int numProfiles);
+void updatePersonalScore(int score);
+void updateWPM(int wpm);
+
+/* In profilesgui.c: */
+void profilesSelector(void);
+
+/* In wordsperminute.c: */
+void wpm();
+
+/* In highscore.c: */
+void displayScores(void);
+void saveHighScores(void);
+void load_highscores(void);
+void checkHighScores(int score);
+void checkWPM(int wpm);
\ No newline at end of file

Copied: tuxtype/branches/tuxtype-soc-mh/src/gettext.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/gettext.c)
===================================================================

Copied: tuxtype/branches/tuxtype-soc-mh/src/globals.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/globals.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/globals.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/globals.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,268 @@
+/***************************************************************************
+                          globals.h
+  description: global varis
+                             -------------------
+    begin                : Fri May 5 2000
+    copyright            : (C) 2000 by Sam Hart
+    email                : hart at geekcomix.com
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#define to_upper(c) (((c) >= 'a' && (c) <= 'z') ? (c) -32 : (c))
+#define COL2RGB( col ) SDL_MapRGB( screen->format, col->r, col->g, col->b )
+
+#define FNLEN	200
+
+#define RES_X	640
+#define RES_Y	480
+#define BPP	32
+
+#ifdef WIN32 
+#undef DATA_PREFIX
+#define DATA_PREFIX ".//"
+#endif
+
+#ifndef __GLOBALS_H__
+#define __GLOBALS_H__
+
+#define MAX_SPRITE_FRAMES 30
+
+
+//#define LOCALEDIR "/usr/local/share"
+
+#include <string.h>
+#include <wchar.h>
+#include <math.h>
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <locale.h>
+
+#include "../config.h"
+
+#include <SDL/SDL.h>
+#include <SDL/SDL_image.h>
+#include <SDL/SDL_mixer.h>
+#include <SDL/SDL_ttf.h>
+
+//#include "i18n.h"
+#include <libintl.h>
+
+
+
+#endif //  __GLOBALS_H__
+
+#define NEXT_FRAME(SPRITE) if ((SPRITE)->num_frames) (SPRITE)->cur = (((SPRITE)->cur)+1) % (SPRITE)->num_frames;
+#define REWIND(SPRITE) (SPRITE)->cur = 0;
+
+#define MIN(x,y) ((x) < (y) ? (x) : (y))
+#define MAX(x,y) ((x) > (y) ? (x) : (y))
+
+/* Goal is to have all global settings here */
+/* (renamed from 'settings' to match tuxmath) */
+typedef struct game_option_type{
+  char default_data_path[FNLEN];
+  char theme_data_path[FNLEN];
+  char user_settings_path[FNLEN];
+  char global_settings_path[FNLEN];
+  char theme_name[FNLEN];
+  char lang[FNLEN];
+  char theme_font_name[FNLEN];
+  char theme_locale_name[FNLEN];
+  int use_english;
+  int fullscreen;
+  int sys_sound;
+  int sfx_volume;
+  int mus_volume;
+  int menu_music;
+  int menu_sound;
+  int speed_up;
+  int show_tux4kids;
+  int debug_on;
+  int o_lives;
+  int sound_vol;
+  int numProfiles;//tracks total number of profiles, limited to 8
+  int hidden; // Read the README file in the image directory for info on this ;)
+} game_option_type;
+
+/* Default values for game_option_type struct */
+/* They can be changed in the struct to other values at run-time */
+#define DEFAULT_MENU_FONT       "AndikaDesRevG.ttf"
+#define DEFAULT_GAME_FONT       "AndikaDesRevG.ttf" 
+#define DEFAULT_LOCALE		"en_GB.UTF-8"
+#define DEFAULT_USE_ENGLISH 1
+#define DEFAULT_FULLSCREEN 1
+#define DEFAULT_SYS_SOUND 1
+#define DEFAULT_SFX_VOLUME 100
+#define DEFAULT_MUS_VOLUME 100
+#define DEFAULT_MENU_MUSIC 1
+#define DEFAULT_MENU_SOUND 1
+#define DEFAULT_SPEED_UP 0
+#define DEFAULT_SHOW_TUX4KIDS 1
+#define DEFAULT_DEBUG_ON 0
+#define DEFAULT_O_LIVES 0
+#define DEFAULT_SOUND_VOL 100
+#define DEFAULT_HIDDEN 0
+
+/* I put global highscore data here.. seemed more appropriate than not */
+#define DEFAULT_GNAME			"Tux"
+#define DEFAULT_GHIGHSCORE1		80000
+#define DEFAULT_GHIGHSCORE2		70000
+#define DEFAULT_GHIGHSCORE3		60000
+#define DEFAULT_GHIGHSCORE4		50000
+#define DEFAULT_GHIGHSCORE5		40000
+#define DEFAULT_GHIGHSCORE6		30000
+#define DEFAULT_GHIGHSCORE7		20000
+#define DEFAULT_GHIGHSCORE8		10000
+#define DEFAULT_GWPM_FASTEST 	60
+#define DEFAULT_GWPM_AVERAGE 	30
+#define DEFAULT_GWPM_LOWEST 	5
+
+typedef struct {
+  SDL_Surface* frame[MAX_SPRITE_FRAMES];
+  SDL_Surface* default_img;
+  int num_frames;
+  int cur;
+} sprite;
+
+#define _(String) gettext(String)
+#define gettext_noop(String) (String)
+
+
+/* LOGGING works as such:
+ *
+ * - Use LOG if you want to output a string LOG( "Hello World");
+ *   
+ * - Use DOUT if you want to output a value of a variable and the
+ *   name of the variable gives enough context:
+ *   DOUT( specialCode );  would add to stderr: "specialCode = 1\n" or
+ *   whatever value specialCode had
+ *   
+ * - Use DEBUGCODE if you need to do something more complicated like
+ *   DEBUGCODE { fprintf(stderr, "examining letter %d\n", x); }
+ *   since DOUT(x) "x = 1\n" gives little information since x is used
+ *   all over the place!
+ */
+
+#define LOG( str ) if (settings.debug_on) fprintf( stderr, str );
+#define DEBUGCODE if (settings.debug_on) 
+#define DOUT(x) if (settings.debug_on) fprintf(stderr, "%s = %d\n", #x, x);
+
+// #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+// #define RMASK 0xff000000
+// #define GMASK 0x00ff0000
+// #define BMASK 0x0000ff00
+// #define AMASK 0x000000ff
+// #else
+// #define RMASK 0x000000ff
+// #define GMASK 0x0000ff00
+// #define BMASK 0x00ff0000
+// #define AMASK 0xff000000
+// #endif
+
+
+
+#define MENU_FONT_SIZE	20
+#define GAME_FONT_SIZE	20
+
+/* Limits on word list size, word length, and on the number of distinct characters */
+/* that can be present within a word list: */
+#define MAX_NUM_WORDS   500
+#define MAX_WORD_SIZE   8
+#define MAX_UNICODES    1024
+
+#define WAIT_MS		2500
+#define	FRAMES_PER_SEC	50
+#define FULL_CIRCLE	140
+
+/* Menu Prototypes */
+enum Game_Type { 
+  QUIT_GAME, CASCADE, OPTIONS, LESSONS, WPM, HIGH_SCORES,
+  INSTRUCT_CASCADE, CASCADE1, CASCADE2, CASCADE3, CASCADE4,
+  INSTRUCT_LASER, LASER1, LASER2, LASER3, LASER4,
+  FREETYPE, ASDF, ALL, MAIN, SET_LANGUAGE, PROJECT_INFO, NOT_CODED,
+  LEVEL1, LEVEL2, LEVEL3, LEVEL4, LASER, INSTRUCT, EDIT_WORDLIST, NONE};
+
+/* Title sequence constants */
+#define PRE_ANIM_FRAMES	 10
+#define PRE_FRAME_MULT	 3
+#define MENU_SEP	 20
+
+
+#define IMG_REGULAR  0x01
+#define IMG_COLORKEY 0x02
+#define IMG_ALPHA    0x04
+#define IMG_MODES    0x07
+
+#define IMG_NOT_REQUIRED 0x10
+#define IMG_NO_THEME     0x20
+
+/* Values for menu button drawing: */
+#define REG_RGBA 16,16,96,96
+#define SEL_RGBA 16,16,128,128
+
+//Game difficulty levels
+enum { EASY, MEDIUM, HARD, INSANE, INF_PRACT };
+#define NUM_LEVELS  4
+
+extern game_option_type settings;
+
+/* FIXME get rid of as much global data as possible, esp. pointers */
+
+extern SDL_Surface* screen;
+/* these will store the resolution used by the OS when we start, so we */
+/* can run fullscreen at the user's preferred resolution:              */
+extern uint fs_res_x;
+extern uint fs_res_y;
+
+//extern TTF_Font* font;
+extern SDL_Event  event;
+
+extern SDL_Color black;
+extern SDL_Color gray;
+extern SDL_Color dark_blue;
+extern SDL_Color red;
+extern SDL_Color white;
+extern SDL_Color yellow;
+
+extern SDL_Surface* letters[255]; /* Will be going away */
+
+/* These need some work to support Unicode & i18n: */
+extern wchar_t ALPHABET[256];
+extern int ALPHABET_SIZE;
+
+
+enum {
+	WIN_WAV,
+	BITE_WAV,
+	LOSE_WAV,
+	RUN_WAV,
+	SPLAT_WAV,
+	WINFINAL_WAV,
+	EXCUSEME_WAV,
+	PAUSE_WAV,
+	NUM_WAVES
+};
+
+#define MUSIC_FADE_OUT_MS	80
+
+enum {
+    WIPE_BLINDS_VERT,
+    WIPE_BLINDS_HORIZ,
+    WIPE_BLINDS_BOX,
+    RANDOM_WIPE,
+
+    NUM_WIPES
+};
+
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/highscores.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/highscores.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/highscores.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/highscores.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,533 @@
+#include "globals.h"
+#include "funcs.h"
+#include "profiles.c"
+
+//tracks laser scores, and wpm stats
+typedef struct highscores{ //structure for global highscores
+  	char *highscore1_name;
+  	int ghighscore1;
+  	char *highscore2_name;
+  	int ghighscore2;
+  	char *highscore3_name;
+  	int ghighscore3;
+  	char *highscore4_name;
+  	int ghighscore4;
+  	char *highscore5_name;
+  	int ghighscore5;
+  	char *highscore6_name;
+  	int ghighscore6;
+  	char *highscore7_name;
+  	int ghighscore7;
+  	char *highscore8_name;
+  	int ghighscore8;
+  	char *wpm_fastest_name;
+  	int wpm_fastest;
+  	char *wpm_average_name;
+  	int wpm_average;
+  	char *wpm_slowest_name;
+  	int wpm_slowest;
+  } highscores;
+  
+  static SDL_Surface* bg = NULL;
+  static TTF_Font* font = NULL;
+  
+typedef struct highscore_entry{
+	int score;
+	char name[32];
+}highscore_entry;
+
+	highscore_entry scoresdisplay[11]; 
+	highscore_entry personalScores[12];
+  	extern highscores hscores;
+
+int load_highscores_filename(const char*);
+int load_highscores_fp(FILE*);
+void loadGlobalScores(void);
+void loadPersonalScores(void);
+void highscores_load_media(void);
+void highscores_unload_media(void);
+ 
+void saveHighScores()//called before exiting game, no need to write until then.
+{
+	char fn[FNLEN];
+	FILE* highscores_file;
+		
+		#ifdef WIN32
+			_mkdir( "userdata" ); 
+			snprintf( fn, FNLEN-1, "userdata/highscores.txt" );
+		#else
+			snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
+			mkdir( fn, 0755 );
+			snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/highscores.txt", getenv("HOME") );
+		#endif
+			
+		highscores_file = fopen(fn, "w");
+		
+		if (highscores_file == NULL) 
+		{
+				printf("Save_Highscores: Highscores file cannot be created!\n");
+				return;
+		}
+		
+		fprintf( highscores_file, "HighScore1=%d\tname1=%s\n", hscores.ghighscore1, &hscores.highscore1_name);
+		fprintf( highscores_file, "HighScore2=%d\tname2=%s\n", hscores.ghighscore1, &hscores.highscore2_name);
+		fprintf( highscores_file, "HighScore3=%d\tname3=%s\n", hscores.ghighscore1, &hscores.highscore3_name);
+		fprintf( highscores_file, "HighScore4=%d\tname4=%s\n", hscores.ghighscore1, &hscores.highscore4_name);
+		fprintf( highscores_file, "HighScore5=%d\tname5=%s\n", hscores.ghighscore1, &hscores.highscore5_name);
+		fprintf( highscores_file, "HighScore6=%d\tname6=%s\n", hscores.ghighscore1, &hscores.highscore6_name);
+		fprintf( highscores_file, "HighScore7=%d\tname7=%s\n", hscores.ghighscore1, &hscores.highscore7_name);
+		fprintf( highscores_file, "HighScore8=%d\tname8=%s\n", hscores.ghighscore1, &hscores.highscore8_name);
+		fprintf( highscores_file, "Fastest_WPM=%d\twname1=%s\n", hscores.wpm_fastest, &hscores.wpm_fastest_name);
+		fprintf( highscores_file, "Highest_average_WPM=%d\twname2=%s\n", hscores.wpm_average, &hscores.wpm_average_name);
+		fprintf( highscores_file, "Slowest_WPM=%d\twname3=%s\n", hscores.wpm_slowest, &hscores.wpm_slowest_name);
+		
+		fclose(highscores_file);
+}
+
+void displayScores() //loads global high scores and individual high scores to display
+{
+	int finished = 0;
+	SDL_Surface* score_surfs[11] = {NULL};
+	SDL_Surface* personal_surfs[12] = {NULL};
+	
+	char score_strings[11][42] = {{'\0'}};
+	char personal_strings[12][10] = {{'\0'}};
+
+	SDL_Rect score_rects[11];
+	SDL_Rect personal_rects[12];
+	SDL_Rect table_bg1, table_bg2; //1 is global, 2 is personal
+
+	const int max_width = 300;
+	int score_table_y = 100;
+	
+	SDL_Surface* srfc = NULL;
+	SDL_Rect text_rect;
+
+	TTF_Font* title_font = LoadFont(DEFAULT_GAME_FONT, 32);
+	TTF_Font* player_font = LoadFont(DEFAULT_GAME_FONT, 14);
+	
+	if (!player_font || !title_font)
+	{
+		return;
+	}
+	
+	highscores_load_media();
+	  
+	while (!finished)
+	{
+		start = SDL_GetTicks();
+
+		/* Check for user events: */
+		while (SDL_PollEvent(&event)) 
+		{
+			switch (event.type)
+			{
+				case SDL_QUIT:
+				{
+					finished = 1;
+				}
+	        }
+		}
+		loadGlobalScores();
+		loadPersonalScores();
+		if (bg)
+		{
+			SDL_BlitSurface(bg, NULL, screen, NULL );
+		}
+		table_bg1.x = 10;
+		table_bg1.y = 5;
+		table_bg1.w = max_width;
+		table_bg1.h = screen->h - 10;
+		
+		table-bg2.x = 330
+		table_bg2.y = 5;
+		table bg2.w = max_width;
+		table_bg2.h = screen->h - 10;
+		
+		srfc = BlackOutline(_("Hall Of Fame"), title_font, &yellow);
+		if (srfc)
+		{
+			/* Now blit text and free surface: */
+			SDL_BlitSurface(srfc, NULL, screen, &text_rect);
+			SDL_FreeSurface(srfc);
+			srfc = NULL;
+		}
+		if (title_font)
+		{
+			srfc = BlackOutline(_("Hall of Fame"), title_font, &white);
+		}
+		if (srfc)
+		{
+			text_rect.x = (screen->w)/2 - (srfc->w)/2; 
+			text_rect.y += text_rect.h;
+			text_rect.w = srfc->w;
+			text_rect.h = srfc->h;
+			SDL_BlitSurface(srfc, NULL, screen, &text_rect);
+			SDL_FreeSurface(srfc);
+			srfc = NULL;
+			score_table_y = text_rect.y + text_rect.h;
+		}
+		for (i = 0; i < 11; i++)
+		{
+			/* Get data for global entries: */
+			sprintf(score_strings[i],
+					"%d.	 %s	 %d",
+					i + 1,   /* Add one to get common-language place number */
+					scoresdisplay[i].score,
+					scoresdisplay[i].name));
+
+			/* Clear out old surfaces and update: */
+
+			score_surfs[i] = BlackOutline(score_strings[i], player_font, &white);
+
+			/* Get out if BlackOutline() fails: */
+			if (!score_surfs[i])
+			{
+		          continue;
+			}
+		         
+			/* Set up entries in vertical column: */
+			if (0 == i)
+			{
+				score_rects[i].y = score_table_y;
+			}
+			else
+			{
+		          score_rects[i].y = personal_rects[i - 1].y + personal_rects[i - 1].h;
+			}
+			score_rects[i].x = 20;
+			score_rects[i].h = score_surfs[i]->h;
+			score_rects[i].w = max_width;
+
+			SDL_BlitSurface(score_surfs[i], NULL, screen, &score_rects[i]);
+			SDL_FreeSurface(score_surfs[i]);
+			score_surfs[i] = NULL;
+		}
+		for (i = 0; i < 12; i++)
+		{
+			/* Get data for personal entries: */
+			sprintf(personal_strings[i],
+					"%d.	 %d",
+					i + 1,   /* Add one to get common-language place number */
+					personalScores[i].score);
+
+			/* Clear out old surfaces and update: */
+
+			personal_surfs[i] = BlackOutline(score_strings[i], player_font, &white);
+
+			/* Get out if BlackOutline() fails: */
+			if (!personal_surfs[i])
+			{
+				continue;
+			}
+					         
+			/* Set up entries in vertical column: */
+			if (0 == i)
+			{
+				personal_rects[i].y = score_table_y;
+			}
+			else
+			{
+				personal_rects[i].y = personal_rects[i - 1].y + personal_rects[i - 1].h;
+			}
+			personal_rects[i].x = 340;
+			personal_rects[i].h = score_surfs[i]->h;
+			personal_rects[i].w = max_width;
+
+			SDL_BlitSurface(score_surfs[i], NULL, screen, &personal_rects[i]);
+			SDL_FreeSurface(score_surfs[i]);
+			score_surfs[i] = NULL;
+		}
+		/* Update screen: */
+		SDL_UpdateRect(screen, 0, 0, 0, 0);
+	}
+	while ((SDL_GetTicks() - start) < 33)
+	{
+		SDL_Delay(20);
+	}
+	frame++;
+	// End of while (!finished) loop
+	TTF_CloseFont(title_font);
+	TTF_CloseFont(player_font);
+	title_font = player_font = NULL;
+	highscore_unload_media();
+}
+void load_highscores()
+{
+	char fn[FNLEN];
+
+	#ifdef WIN32
+	snprintf(fn, FNLEN - 1, "userdata/highscores.txt");
+  	LOG("WIN32 defined\n");
+	#else
+  	snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/highscores.txt", getenv("HOME"));
+  	LOG("WIN32 not defined\n");
+	#endif
+		
+  	load_highscores_filename(fn);
+	
+}
+
+static int load_highscores_filename(const char* fn)
+{
+	FILE* fp = fopen(fn, "r");
+	
+	if (!fp)
+	{
+		fprintf(stderr, "load_highscores_filename(): Incorrect pointer\n");
+	    return;
+	}
+	
+	if (!load_highscores_fp(fp))
+	{
+		fprintf(stderr, "Could not find any highscores.\n");
+	    fclose(fp);
+	    return 0;
+	}
+	
+	fclose(fp);
+	return 1;
+}
+
+static int load_highscores_fp(FILE* fp)
+{
+  char highscores[FNLEN];
+  char value[FNLEN];
+  int highscores_found = 0;
+
+  if (!fp)
+  {
+    fprintf(stderr, "load_highscores_fp() - FILE* parameter NULL\n");
+    return 0;
+  }
+
+  /* load all the highscores here */
+  while (!feof(fp))
+  {
+    fscanf(fp, "%[^=]=%[^\n]\n", highscores, value );
+
+    if (strncmp( highscores, "Highscore1", FNLEN ) == 0 )
+    {
+    	hscores.ghighscore1 = atoi(value);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "name1", FNLEN ) == 0 )
+    {
+    	strncpy(hscores.highscore1_name, value, FNLEN - 1);
+    	highscores_found = 1;
+   }
+    else if (strncmp( highscores, "Highscore2", FNLEN ) == 0 )
+    {
+    	hscores.ghighscore2 = atoi(value);
+    	highscores_found = 1;
+    }
+    else if (strncmp(highscores, "name2", FNLEN) == 0)
+    {
+    	strncpy(hscores.highscore2_name, value, FNLEN - 1);
+    	highscores_found = 1;
+    }
+    else if (strncmp(highscores, "Highscore3", FNLEN) == 0)
+    {
+    	hscores.ghighscore3 = atoi(value);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "name3", FNLEN ) == 0 )
+    {
+    	strncpy(hscores.highscore3_name, value, FNLEN - 1);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "Highscore4", FNLEN ) == 0 )
+    {
+    	hscores.ghighscore4 = atoi(value);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "name4", FNLEN ) == 0 )
+    {
+    	strncpy(hscores.highscore4_name, value, FNLEN - 1);
+    	highscores_found = 1;
+	}
+    else if (strncmp( highscores, "Highscore5", FNLEN ) == 0 )
+    {
+    	hscores.ghighscore5 = atoi(value);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "name5", FNLEN ) == 0 )
+    {
+    	strncpy(hscores.highscore5_name, value, FNLEN - 1);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "Highscore6", FNLEN ) == 0 )
+    {
+    	hscores.ghighscore6 = atoi(value);
+        highscores_found = 1;
+    }
+    else if (strncmp( highscores, "name6", FNLEN ) == 0 )
+    {
+    	strncpy(hscores.highscore6_name, value, FNLEN - 1);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "Highscore7", FNLEN ) == 0 )
+    {
+    	hscores.ghighscore7 = atoi(value);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "name7", FNLEN ) == 0 )
+    {
+    	strncpy(hscores.highscore7_name, value, FNLEN - 1);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "Highscore8", FNLEN ) == 0 )
+  	{
+    	hscores.ghighscore8 = atoi(value);
+    	highscores_found = 1;
+  	}
+    else if (strncmp( highscores, "name8", FNLEN ) == 0 )
+    {
+    	strncpy(hscores.highscore8_name, value, FNLEN - 1);
+    	highscores_found = 1;
+    }
+    else if (strncmp( highscores, "Fastest_WPM", FNLEN ) == 0 )
+ 	{
+    	hscores.wpm_fastest = atoi(value);
+    	highscores_found = 1;
+   	}
+    else if (strncmp( highscores, "wname1", FNLEN ) == 0 )
+   	{
+    	strncpy(hscores.wpm_fastest_name, value, FNLEN - 1);
+    	highscores_found = 1;
+   	}
+    else if (strncmp( highscores, "Highest_average_WPM", FNLEN ) == 0 )	
+    {
+	  	hscores.wpm_average = atoi(value);
+	 	highscores_found = 1;
+	}
+    else if (strncmp( highscores, "wname2", FNLEN ) == 0 )
+   	{
+    	strncpy(hscores.wpm_average_name, value, FNLEN - 1);
+    	highscores_found = 1;
+   	}
+    else if (strncmp( highscores, "Slowest_WPM", FNLEN ) == 0 )
+  	{
+      	 hscores.wpm_slowest = atoi(value);
+      	 highscores_found = 1;
+   	}
+    else if (strncmp( highscores, "wname3", FNLEN ) == 0 )
+   	{
+    	strncpy(hscores.wpm_slowest_name, value, FNLEN - 1);
+      	highscores_found = 1;
+   	}
+    else
+    {
+      DEBUGCODE {fprintf(stderr, "load_highscores_fp(): unrecognized string: %s", value);}
+    }
+    
+  }
+
+  if (highscores_found)
+  {
+    return 1;
+  }
+  else
+  {
+    fprintf(stderr, "load_highscores_fp() - no highscores in file - empty or corrupt?\n");
+    return 0;
+  }
+}
+
+void loadGlobalScores()
+{
+	scoresdisplay[0].score = hscores.ghighscore1;
+	scoresdisplay[1].score = hscores.ghighscore2;
+	scoresdisplay[2].score = hscores.ghighscore3;
+	scoresdisplay[3].score = hscores.ghighscore4;
+	scoresdisplay[4].score = hscores.ghighscore5;
+	scoresdisplay[5].score = hscores.ghighscore6;
+	scoresdisplay[6].score = hscores.ghighscore7;
+	scoresdisplay[7].score = hscores.ghighscore8;
+	scoresdisplay[8].score = hscores.wpm_fastest;
+	scoresdisplay[9].score = hscores.wpm_average;
+	scoresdisplay[10].score= hscores.wpm_slowest;
+	
+	scoresdisplay[0].name = hscores.highscore1_name;
+	scoresdisplay[0].name = hscores.highscore2_name;
+	scoresdisplay[0].name = hscores.highscore3_name;
+	scoresdisplay[0].name = hscores.highscore4_name;
+	scoresdisplay[0].name = hscores.highscore5_name;
+	scoresdisplay[0].name = hscores.highscore6_name;
+	scoresdisplay[0].name = hscores.highscore7_name;
+	scoresdisplay[0].name = hscores.highscore8_name;
+	scoresdisplay[0].name = hscores.wpm_fastest_name;
+	scoresdisplay[0].name = hscores.wpm_average_name;
+	scoresdisplay[0].name =hscores.wpm_slowest_name;
+}
+
+void loadPersonalScores() 
+{
+	
+	personalScores[0].score = activeProfile.highscore1;
+	personalScores[1].score = activeProfile.highscore2;
+	personalScores[2].score = activeProfile.highscore3;
+	personalScores[3].score = activeProfile.highscore4;
+	personalScores[4].score = activeProfile.highscore5;
+	personalScores[5].score = activeProfile.highscore6;
+	personalScores[6].score = activeProfile.highscore7;
+	personalScores[7].score = activeProfile.highscore8;
+	personalScores[8].score = activeProfile.wpm_fastest;
+	personalScores[9].score = activeProfile.wpm_average;
+	personalScores[10].score = activeProfile.wpm_slowest;
+	personalScores[11].core = activeProfile.wpm_taken;
+
+}
+void checkHighScores(int score) //checks to see if score qualifies as a high score, adds
+{
+	int temp, count = 1;
+	int checkScore = score;
+	do
+	{
+		if(checkScore > hscores.ghighscore(count))
+		{
+			temp = hscores.ghighscore(count);
+			hscores.ghighscore(count) = checkScore;
+			hscores.highscore(count)_name = activeProfile.profileName;
+			checkScore = temp;
+		}
+	}
+	while(checkScore < hscores.ghighscore(count) && count <=8);
+}
+
+void checkWPM(int wpm) //checks global wpm and updates if necessary
+{
+	if(wpm > hscores.wpm_fastest)
+	{
+		hscores.wpm_fastest_name = activeProfile.profileName;
+		hscores.wpm_fastest = wpm;
+	}
+	if(wpm < hscores.wpm_slowest)
+	{
+		hscores.wpm_slowest_name = activeProfile.profileName;
+		hscores.wpm_slowest = wpm;
+	}
+	if(activeProfile.wpm_average > hscores.wpm_average)
+	{
+		hscores.wpm_average_name = activeProfile.profileName;
+		hscores.wpm_average = activeProfile.wpm_average;
+	}
+}
+
+static void highscores_load_media()
+{
+	int load_failed = 0;
+
+	bg = LoadImage("main_bkg.png", IMG_ALPHA);
+	
+	if(load_failed || !bg)
+	{
+		highscores_unload_media();
+	}
+}
+
+static void highscores_unload_media()
+{
+	SDL_FreeSurface(bg);
+	bg = NULL;
+}
\ No newline at end of file

Copied: tuxtype/branches/tuxtype-soc-mh/src/keyboard.lst (from rev 672, tuxtype/branches/tuxtype-soc-mh/keyboard.lst)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/keyboard.lst	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/keyboard.lst	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,70 @@
+# Default (English) keyboard.lst file
+0|A
+0|a
+3|B
+3|b
+2|C
+2|c
+2|D
+2|d
+2|E
+2|e
+3|F
+3|f
+3|G
+3|g
+6|H
+6|h
+7|I
+7|i
+6|J
+6|j
+7|K
+7|k
+8|L
+8|l
+6|M
+6|m
+6|N
+6|n
+8|O
+8|o
+9|P
+9|p
+0|Q
+0|q
+3|R
+3|r
+1|S
+1|s
+3|T
+3|t
+6|U
+6|u
+3|V
+3|v
+1|W
+1|w
+1|X
+1|x
+6|Y
+6|y
+0|Z
+0|z
+5| 
+0|!
+0|@
+0|#
+0|1
+0|2
+0|3
+0|4
+0|5
+0|6
+0|7
+0|8
+0|9
+0|0
+7|,
+8|.
+9|;

Copied: tuxtype/branches/tuxtype-soc-mh/src/laser.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/laser.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/laser.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/laser.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,1124 @@
+/***************************************************************************
+ -  file: laser.c
+ -  description: a modification of TuxMath for typing :)
+                            -------------------
+    begin                : 
+    copyright            : Bill Kendrick (C) 2002
+                           Jesse Andrews (C) 2003
+    email                : tuxtype-dev at tux4kids.net
+***************************************************************************/
+
+/***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+#include "laser.h"
+
+
+#define FPS (1000 / 15)   /* 15 fps max */
+#define CITY_EXPL_START 3 * 5  /* Must be mult. of 5 (number of expl frames) */
+#define COMET_EXPL_START 2 * 2 /* Must be mult. of 2 (number of expl frames) */
+#define ANIM_FRAME_START 4 * 2 /* Must be mult. of 2 (number of tux frames) */
+#define GAMEOVER_COUNTER_START 75
+#define LEVEL_START_WAIT_START 20
+#define LASER_START 5
+#define NUM_ANS 8
+#define COMET_ZAP_FONT_SIZE 32
+
+/* Local (to laser.c) 'globals': */
+static sprite* shield = NULL;
+static SDL_Surface* images[NUM_IMAGES] = {NULL};
+static Mix_Chunk* sounds[NUM_SOUNDS] = {NULL};
+static Mix_Music* musics[NUM_MUSICS] = {NULL};
+static TTF_Font* font = NULL;
+
+static int wave, speed, score, pre_wave_score, num_attackers, distanceMoved;
+static wchar_t ans[NUM_ANS];
+static int ans_num;
+
+static comet_type comets[MAX_COMETS];
+static city_type cities[NUM_CITIES];
+static laser_type laser;
+
+/* Local function prototypes: */
+static void laser_add_comet(int diff_level);
+static void laser_add_score(int inc);
+static void laser_draw_console_image(int i);
+static void laser_draw_let(wchar_t c, int x, int y);
+static void laser_draw_line(int x1, int y1, int x2, int y2, int r, int g, int b);
+static void laser_draw_numbers(const unsigned char* str, int x);
+static void laser_load_data(void);
+static void laser_reset_level(int diff_level);
+static void laser_putpixel(SDL_Surface* surface, int x, int y, Uint32 pixel);
+static void laser_unload_data(void);
+static void calc_city_pos(void);
+static void recalc_comet_pos(void);
+
+/* --- MAIN GAME FUNCTION!!! --- */
+
+/* TODO modify game to allow longer words (12 chars or so) */
+
+int PlayLaserGame(int diff_level)
+{
+	int i, img, done, quit, frame, lowest, lowest_y, 
+	    tux_img, old_tux_img, tux_pressing, tux_anim, tux_anim_frame,
+	    tux_same_counter, level_start_wait, num_cities_alive,
+	    num_comets_alive, paused, picked_comet, 
+	    gameover;
+
+	Uint16 key_unicode;
+
+	SDL_Event event;
+	Uint32    last_time, now_time;
+	SDLKey    key;
+	SDL_Rect  src, dest;
+	/* str[] is a buffer to draw the scores, waves, etc. (don't need wchar_t) */
+	unsigned char str[64]; 
+
+	LOG( "starting Comet Zap game\n" );
+	DOUT( diff_level );
+
+	SDL_ShowCursor(0);
+	laser_load_data();
+
+	/* Clear window: */
+  
+	SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
+	SDL_Flip(screen);
+
+	/* --- MAIN GAME LOOP: --- */
+
+	done = 0;
+	quit = 0;
+	src.w = src.h = 0;
+
+	/* Prepare to start the game: */
+  
+	wave = 1;
+	score = 0;
+	gameover = 0;
+	level_start_wait = LEVEL_START_WAIT_START;
+
+	
+  /* (Create and position cities) */
+  for (i = 0; i < NUM_CITIES; i++)
+  {
+    cities[i].alive = 1;
+    cities[i].expl = 0;
+    cities[i].shields = 1;
+  }
+
+  /* figure out x placement: */
+  calc_city_pos();
+
+  num_cities_alive = NUM_CITIES;
+  num_comets_alive = 0;
+
+
+	/* (Clear laser) */
+
+	laser.alive = 0;
+
+  
+	/* Reset remaining stuff: */
+ 
+	laser_reset_level(diff_level);
+  
+	/* --- MAIN GAME LOOP!!! --- */
+  
+	frame = 0;
+	paused = 0;
+	picked_comet = -1;
+	tux_img = IMG_TUX_RELAX1;
+	tux_anim = -1;
+	tux_anim_frame = 0;
+	tux_same_counter = 0;
+	ans_num = 0;
+
+	MusicPlay(musics[MUS_GAME + (rand() % NUM_MUSICS)], 0);
+
+	do {
+
+		frame++;
+		last_time = SDL_GetTicks();
+
+		old_tux_img = tux_img;
+		tux_pressing = 0;
+
+		/* Handle any incoming events: */
+     
+		while (SDL_PollEvent(&event) > 0) {
+
+			if (event.type == SDL_QUIT) {
+				/* Window close event - quit! */
+				exit(0);
+	      
+			} else if (event.type == SDL_KEYDOWN) {
+
+				key = event.key.keysym.sym;
+				if (key == SDLK_F10) 
+                                {
+				  SwitchScreenMode();
+                                  calc_city_pos();
+                                  recalc_comet_pos();
+                                }
+				if (key == SDLK_F11)
+					SDL_SaveBMP( screen, "laser.bmp");
+
+				if (key == SDLK_ESCAPE)
+					paused = 1;
+
+				/* --- eat other keys until level wait has passed --- */ 
+				if (level_start_wait > 0) 
+					key = SDLK_UNKNOWN;
+				
+				key_unicode = event.key.keysym.unicode;
+				//key_unicode = event.key.keysym.unicode & 0xff;
+
+				DEBUGCODE
+				{
+				  fprintf(stderr, "key_unicode = %d\n", key_unicode);
+				}
+
+				/* For now, tuxtype is case-insensitive for input, */
+                                /* with only uppercase for answers:                */
+                                if (key_unicode >= 97 && key_unicode <= 122)
+                                  key_unicode -= 32;  //convert lowercase to uppercase
+                                if (key_unicode >= 224 && key_unicode <= 255)
+                                  key_unicode -= 32; //same for non-US chars
+
+				LOG ("After checking for lower case:\n");
+				DEBUGCODE
+				{
+				  fprintf(stderr,
+                                   "key_unicode = %d\n", key_unicode);
+				}
+				/* Now update with case-folded value: */
+				ans[ans_num++] = key_unicode;
+
+			}
+		}
+      
+      
+		/* Handle answer: */
+
+		for (;ans_num>0;ans_num--) {
+
+			/*  Pick the lowest shootable comet which has the right answer: */
+	
+			lowest_y = 0;
+			lowest = -1;
+	
+			for (i = 0; i < MAX_COMETS; i++)
+				if (comets[i].alive
+				 && comets[i].shootable 
+				 && comets[i].expl == 0
+				 && comets[i].ch == ans[ans_num -1 ] 
+				 && comets[i].y > lowest_y)
+				{
+					lowest = i;
+					lowest_y = comets[i].y;
+				}
+	
+	
+			/* If there was an comet with this answer, destroy it! */
+	
+			if (lowest != -1) {
+
+				/* Destroy comet: */
+		  
+				comets[lowest].expl = COMET_EXPL_START;
+				/* Make next letter in word shootable: */
+				comets[lowest].shootable = 0;
+                                if (comets[lowest].next)
+                                  comets[lowest].next->shootable = 1;
+
+				/* Fire laser: */
+				laser.alive = LASER_START;
+
+				/* this is a hack so drawing to the center of the screen works */
+				if (abs(comets[lowest].x - screen->w/2) < 10) {
+					laser.x1 = screen->w / 2;
+					laser.y1 = screen->h;
+	    
+					laser.x2 = laser.x1;
+					laser.y2 = comets[lowest].y;
+				} else {
+					laser.x1 = screen->w / 2;
+					laser.y1 = screen->h;
+	    
+					laser.x2 = comets[lowest].x;
+					laser.y2 = comets[lowest].y;
+				}
+	    
+				PlaySound(sounds[SND_LASER]);
+	    
+				/* 50% of the time.. */
+	    
+				if (0 == (rand() % 2))  {
+
+					/* ... pick an animation to play: */ 
+					if (0 == (rand() % 2))
+						tux_anim = IMG_TUX_YES1;
+					else
+						tux_anim = IMG_TUX_YAY1;
+	        
+					tux_anim_frame = ANIM_FRAME_START;
+				}
+
+				/* Increment score: */
+
+				laser_add_score( (diff_level+1) * 5 * ((screen->h - comets[lowest].y)/20 ));
+
+			} else {
+
+				/* Didn't hit anything! */
+	    
+				PlaySound(sounds[SND_BUZZ]);
+	    
+				if (0 == (rand() % 2))
+					tux_img = IMG_TUX_DRAT;
+				else
+					tux_img = IMG_TUX_YIPE;
+
+				laser_add_score( -25 * wave);
+			}
+		}
+
+      
+		/* Handle start-wait countdown: */
+      
+		if (level_start_wait > 0) {
+
+			level_start_wait--;
+	  
+			if (level_start_wait > LEVEL_START_WAIT_START / 4)
+				tux_img = IMG_TUX_RELAX1;
+			else if (level_start_wait > 0)
+				tux_img = IMG_TUX_RELAX2;
+			else
+				tux_img = IMG_TUX_SIT;
+	  
+			if (level_start_wait == LEVEL_START_WAIT_START / 4)
+				PlaySound(sounds[SND_ALARM]);
+		}
+
+      
+		/* If Tux pressed a button, pick a new (different!) stance: */
+	  
+		if (tux_pressing) {
+			while (tux_img == old_tux_img)
+				tux_img = IMG_TUX_CONSOLE1 + (rand() % 3);
+
+			playsound(sounds[SND_CLICK]);
+		}
+      
+      
+		/* If Tux is being animated, show the animation: */
+
+		if (tux_anim != -1) {
+			tux_anim_frame--;
+
+			if (tux_anim_frame < 0)
+				tux_anim = -1;
+			else
+				tux_img = tux_anim + 1 - (tux_anim_frame / (ANIM_FRAME_START / 2));
+		}
+
+
+		/* Reset Tux to sitting if he's been doing nothing for a while: */
+
+		if (old_tux_img == tux_img) {
+			tux_same_counter++;
+
+			if (tux_same_counter >= 20)
+				old_tux_img = tux_img = IMG_TUX_SIT;
+			if (tux_same_counter >= 60)
+				old_tux_img = tux_img = IMG_TUX_RELAX1;
+		} else
+			tux_same_counter = 0;
+
+
+		/* Handle comets: */
+     
+		num_comets_alive = 0;
+
+		distanceMoved += speed;
+      
+		for (i = 0; i < MAX_COMETS; i++) {
+			if (comets[i].alive) {
+
+				num_comets_alive++;
+
+				comets[i].x = comets[i].x + 0;
+				comets[i].y = comets[i].y + speed;
+	      
+				if (comets[i].y >= (screen->h - images[IMG_CITY_BLUE]->h) && comets[i].expl == 0) {
+
+					/* Disable shields or destroy city: */
+		      
+					if (cities[comets[i].city].shields) {
+						cities[comets[i].city].shields = 0;
+						PlaySound(sounds[SND_SHIELDSDOWN]);
+						laser_add_score(-500 * (diff_level+1));
+					} else {
+						cities[comets[i].city].expl = CITY_EXPL_START;
+						PlaySound(sounds[SND_EXPLOSION]);
+						laser_add_score(-1000 * (diff_level+1));
+					}
+
+					tux_anim = IMG_TUX_FIST1;
+					tux_anim_frame = ANIM_FRAME_START;
+
+					/* Destroy comet: */
+
+					comets[i].expl = COMET_EXPL_START;
+				}
+
+				/* Handle comet explosion animation: */
+
+				if (comets[i].expl != 0) {
+					comets[i].expl--;
+
+					if (comets[i].expl == 0)
+						comets[i].alive = 0;
+				}
+			}
+		}
+
+
+		/* Handle laser: */
+
+		if (laser.alive > 0)
+			laser.alive--;
+     
+		/* Comet time! */
+
+		if (level_start_wait == 0 && (frame % 5) == 0 && gameover == 0) {
+			if (num_attackers > 0) {
+
+				/* More comets to add during this wave! */
+		
+				if ((num_comets_alive < 2 || ((rand() % 4) == 0)) && distanceMoved > 40) {
+					distanceMoved = 0;
+					laser_add_comet(diff_level);
+					num_attackers--;
+				}
+			} else {
+				if (num_comets_alive == 0) {
+
+					/* Time for the next wave! */
+
+					/* FIXME: End of level stuff goes here */
+
+					if (num_cities_alive > 0) {
+
+						/* Go on to the next wave: */
+						wave++;
+						laser_reset_level(diff_level);
+
+					} else {
+
+						/* No more cities!  Game over! */
+						gameover = GAMEOVER_COUNTER_START;
+					}
+				}
+			}
+		}
+
+
+		/* Handle cities: */
+     
+		num_cities_alive = 0;
+
+		for (i = 0; i < NUM_CITIES; i++) 
+			if (cities[i].alive) {
+
+				num_cities_alive++;
+
+				/* Handle animated explosion: */
+
+				if (cities[i].expl) {
+					cities[i].expl--;
+		  
+					if (cities[i].expl == 0)
+						cities[i].alive = 0;
+				}
+			}
+                        
+
+		/* Handle game-over: */
+
+		if (gameover > 0) {
+			gameover--;
+
+			if (gameover == 0)
+			{
+				done = 1;
+				checkHighScores(score);
+				updatePersonalScore(score);
+				
+			}
+		}
+                
+                if ((num_cities_alive==0) && (gameover == 0))
+                    gameover = GAMEOVER_COUNTER_START;
+      
+		/* Draw background: */
+     
+		SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
+
+		/* Draw wave: */
+
+		dest.x = 0;
+		dest.y = 0;
+		dest.w = images[IMG_WAVE]->w;
+		dest.h = images[IMG_WAVE]->h;
+
+		SDL_BlitSurface(images[IMG_WAVE], NULL, screen, &dest);
+
+		sprintf(str, "%d", wave);
+		laser_draw_numbers(str, images[IMG_WAVE]->w + (images[IMG_NUMBERS]->w / 10));
+
+
+		/* Draw score: */
+
+		dest.x = (screen->w - ((images[IMG_NUMBERS]->w / 10) * 7) - images[IMG_SCORE]->w);
+		dest.y = 0;
+		dest.w = images[IMG_SCORE]->w;
+		dest.h = images[IMG_SCORE]->h;
+
+		SDL_BlitSurface(images[IMG_SCORE], NULL, screen, &dest);
+      
+		sprintf(str, "%.6d", score);
+		laser_draw_numbers(str, screen->w - ((images[IMG_NUMBERS]->w / 10) * 6));
+      
+      
+		/* Draw comets: */
+      
+		for (i = 0; i < MAX_COMETS; i++) 
+			if (comets[i].alive) {
+
+				/* Decide which image to display: */
+				if (comets[i].expl == 0)
+					img = IMG_COMET1 + ((frame + i) % 3);
+				else
+					img = (IMG_COMETEX2 - (comets[i].expl / (COMET_EXPL_START / 2)));
+	      
+
+				/* Draw it! */
+
+				dest.x = comets[i].x - (images[img]->w / 2);
+				dest.y = comets[i].y - images[img]->h;
+				dest.w = images[img]->w;
+				dest.h = images[img]->h;
+	      
+				SDL_BlitSurface(images[img], NULL, screen, &dest);
+			}
+
+
+		/* Draw letters: */
+
+		for (i = 0; i < MAX_COMETS; i++)
+			if (comets[i].alive && comets[i].expl == 0)
+				laser_draw_let(comets[i].ch, comets[i].x, comets[i].y);
+      
+		/* Draw cities: */
+      
+		if (frame%2 == 0) NEXT_FRAME(shield);
+		for (i = 0; i < NUM_CITIES; i++) {
+
+			/* Decide which image to display: */
+	 
+			if (cities[i].alive) {
+				if (cities[i].expl == 0)
+					img = IMG_CITY_BLUE;
+				else
+					img = (IMG_CITY_BLUE_EXPL5 - (cities[i].expl / (CITY_EXPL_START / 5)));
+			} else 
+				img = IMG_CITY_BLUE_DEAD;
+	  
+	  
+			/* Change image to appropriate color: */
+	  
+			img += ((wave % MAX_CITY_COLORS) * (IMG_CITY_GREEN - IMG_CITY_BLUE));
+	  
+	  
+			/* Draw it! */
+	  
+			dest.x = cities[i].x - (images[img]->w / 2);
+			dest.y = (screen->h) - (images[img]->h);
+			dest.w = (images[img]->w);
+			dest.h = (images[img]->h);
+	  
+			SDL_BlitSurface(images[img], NULL, screen, &dest);
+
+			/* Draw sheilds: */
+
+			if (cities[i].shields) {
+
+				dest.x = cities[i].x - (shield->frame[shield->cur]->w / 2);
+				dest.h = (screen->h) - (shield->frame[shield->cur]->h);
+				dest.w = src.w;
+				dest.h = src.h;
+				SDL_BlitSurface( shield->frame[shield->cur], NULL, screen, &dest);
+
+			}
+		}
+
+
+		/* Draw laser: */
+
+		if (laser.alive)
+			laser_draw_line(laser.x1, laser.y1, laser.x2, laser.y2, 255 / (LASER_START - laser.alive),
+			                192 / (LASER_START - laser.alive), 64);
+
+		laser_draw_console_image(IMG_CONSOLE);
+
+		if (gameover > 0)
+			tux_img = IMG_TUX_FIST1 + ((frame / 2) % 2);
+
+		laser_draw_console_image(tux_img);
+
+
+		/* Draw "Game Over" */
+
+		if (gameover > 0) {
+
+			dest.x = (screen->w - images[IMG_GAMEOVER]->w) / 2;
+			dest.y = (screen->h - images[IMG_GAMEOVER]->h) / 2;
+			dest.w = images[IMG_GAMEOVER]->w;
+			dest.h = images[IMG_GAMEOVER]->h;
+	
+			SDL_BlitSurface(images[IMG_GAMEOVER], NULL, screen, &dest);
+		}
+      
+      
+		/* Swap buffers: */
+      
+		SDL_Flip(screen);
+
+
+		/* If we're in "PAUSE" mode, pause! */
+
+		if (paused) {
+			quit = Pause();
+			paused = 0;
+		}
+
+      
+		/* Keep playing music: */
+      
+		if (settings.sys_sound && !Mix_PlayingMusic())
+			MusicPlay(musics[MUS_GAME + (rand() % NUM_MUSICS)], 0);
+      
+		/* Pause (keep frame-rate event) */
+      
+		now_time = SDL_GetTicks();
+		if (now_time < last_time + FPS)
+			SDL_Delay(last_time + FPS - now_time);
+	}
+		while (!done && !quit);
+
+  
+  /* Free backgrounds: */
+  FreeBothBkgds();
+
+	/* Stop music: */
+	if ((settings.sys_sound) && (Mix_PlayingMusic()))
+		Mix_HaltMusic();
+ 
+	laser_unload_data();
+ 
+	return 1;
+}
+
+
+/*****************************************************/
+/*                                                   */
+/*          Local ("private") functions:             */
+/*                                                   */
+/*****************************************************/
+
+
+static void calc_city_pos(void)
+{
+  int i = 0;
+
+  for (i = 0; i < NUM_CITIES; i++)
+  {
+    if (NUM_CITIES % 2 == 0)
+    {
+      /* Left vs. Right - makes room for Tux and the console */
+      if (i < NUM_CITIES / 2)
+      {
+        cities[i].x = (((screen->w / (NUM_CITIES + 1)) * i)
+                      + ((images[IMG_CITY_BLUE] -> w) / 2));
+      }
+      else
+      {
+        cities[i].x = screen->w
+                    - screen->w/(NUM_CITIES + 1) * (i - NUM_CITIES/2)
+                    + images[IMG_CITY_BLUE]->w/2;
+      }
+    }
+    else
+    {
+      /* put them in order across the bottom of     *
+      * the screen so we can do words in order!!! */
+      cities[i].x = i*screen->w/(NUM_CITIES)
+                    + images[IMG_CITY_BLUE]->w/2;
+    }
+  }
+}
+
+/* Update the x position of comets when resolution changes: */
+/* Must call calc_city_pos() first for this to work! */
+static void recalc_comet_pos(void)
+{
+  int i, target;
+
+  for (i = 0; i < MAX_COMETS; i++)
+  {
+    /* Set each live comet's x to that of its target city: */
+    if (comets[i].alive == 1)
+    {
+      target = comets[i].city;
+      comets[i].x = cities[target].x;
+    }
+  }
+}
+
+
+/* --- Load all media --- */
+static void laser_load_data(void)
+{
+	int i;
+
+	/* Create the SDL_Surfaces for all of the characters */
+        /* used in the word list: */
+	font = LoadFont(settings.theme_font_name, COMET_ZAP_FONT_SIZE);
+	RenderLetters(font);
+
+	/* Load images: */
+	for (i = 0; i < NUM_IMAGES; i++) 
+		images[i] = LoadImage(image_filenames[i], IMG_ALPHA);
+	shield = LoadSprite( "cities/shield", IMG_ALPHA );
+
+	if (settings.sys_sound) {
+		for (i = 0; i < NUM_SOUNDS; i++)
+			sounds[i] = LoadSound(sound_filenames[i]);
+
+		for (i = 0; i < NUM_MUSICS; i++)
+			musics[i] = LoadMusic(music_filenames[i]);
+	}
+
+//	PauseLoadMedia();
+}
+
+
+/* --- unload all media --- */
+static void laser_unload_data(void) {
+	int i;
+
+	FreeLetters();
+
+	for (i = 0; i < NUM_IMAGES; i++)
+		SDL_FreeSurface(images[i]);
+
+	if (settings.sys_sound) {
+		for (i = 0; i < NUM_SOUNDS; i++)
+			Mix_FreeChunk(sounds[i]);
+		for (i = 0; i < NUM_MUSICS; i++)
+			Mix_FreeMusic(musics[i]);
+	}
+
+	FreeSprite(shield);
+        shield = NULL;
+
+//	PauseUnloadMedia();
+
+	TTF_CloseFont(font);
+        font = NULL;
+}
+
+
+/* Reset stuff for the next level! */
+
+static void laser_reset_level(int diff_level)
+{
+  unsigned char fname[1024];
+  static int last_bkgd = -1;
+  int i;
+  
+  /* Clear all comets: */
+  
+  for (i = 0; i < MAX_COMETS; i++)
+    comets[i].alive = 0;
+  
+  /* Load diffrent random background image: */
+  LOG("Loading background in laser_reset_level()\n");
+
+  do {
+    i = rand() % NUM_BKGDS;
+    DOUT(i);
+  }
+  while (i == last_bkgd);
+
+  last_bkgd = i;
+
+  DOUT(i);
+
+  sprintf(fname, "backgrounds/%d.jpg", i);
+
+  LOG("Will try to load file:");
+  LOG(fname);
+
+  FreeBothBkgds(); // LoadBothBkgds() actually does this just in case
+
+  LoadBothBkgds(fname);
+
+  if (CurrentBkgd() == NULL)
+  {
+    fprintf(stderr,
+     "\nWarning: Could not load background image:\n"
+     "%s\n"
+     "The Simple DirectMedia error that ocurred was: %s\n",
+     fname, SDL_GetError());
+  }
+
+  /* Record score before this wave: */
+
+  pre_wave_score = score;
+
+  /* Set number of attackers & speed for this wave: */
+
+  switch (diff_level) {
+    case 0 : speed = 1 + (wave/5); num_attackers=15; break;
+    case 1 : speed = 1 + (wave/4); num_attackers=15; break;
+    case 2 : speed = 1 + ((wave<<1)/3); num_attackers=(wave<<1); break;
+    case 3 : speed = 1 + wave; num_attackers=(wave<<1); break;
+    default: LOG("diff_level not recognized!\n");
+  }
+
+  distanceMoved = 100; // so that we don't have to wait to start the level
+  LOG("Leaving laser_reset_level()\n");
+}
+
+
+/* Add an comet to the game (if there's room): */
+
+static void laser_add_comet(int diff_level) {
+
+	int target, location = 0;
+	static int last = -1;
+	int targeted[NUM_CITIES] = { 0 };
+	int add = (rand() % (diff_level + 2));
+
+	LOG ("Entering laser_add_comet()\n");
+	DEBUGCODE { fprintf(stderr, "Adding %d comets \n", add); }
+
+	if (0 == NUM_CITIES % 2) /* Even number of cities */
+	{
+          LOG("NUM_CITIES is even\n");
+	  while ((add > 0) && (location != MAX_COMETS))
+	  {
+            /* Look for a free comet slot: */
+            while ((comets[location].alive == 1) && (location < MAX_COMETS))
+            {
+              location++; 
+            }
+            if (location < MAX_COMETS)
+            {
+              comets[location].alive = 1;
+              /* Pick a city to attack: */
+              do
+              { 
+                target = (rand() % NUM_CITIES);
+              } while (target == last || targeted[target] == 1);
+
+              last = target;
+              targeted[target] = 1;
+
+              /* Set comet to target that city: */
+              comets[location].city = target; 
+
+              /* Start at the top, above the city in question: */
+              comets[location].x = cities[target].x;
+              comets[location].y = 0;
+
+              /* Pick a letter */
+              comets[location].ch = GetLetter();
+              /* single letters always shootable: */
+              comets[location].shootable = 1;
+              comets[location].next = NULL;
+
+              add--;
+            }
+            DEBUGCODE {if (location == MAX_COMETS) 
+			printf("Location == MAX_COMETS, we have max on screen\n");}
+	  } 
+	}
+	else /* Odd number of cities (is this a hack that means we are using words?) */
+        {
+          LOG("NUM_CITIES is odd\n");
+          wchar_t* word = GetWord();
+          int i = 0;
+          comet_type* prev_comet = NULL;
+
+          DEBUGCODE {fprintf(stderr, "word is: %S\tlength is: %d\n", word, (int)wcslen(word));}
+          do
+          { 
+  	    target = rand() % (NUM_CITIES - wcslen(word) + 1);
+          } while (target == last);
+          last = target;
+
+		for (i=0; i < wcslen(word); i++)
+		{
+ 			while ((comets[location].alive == 1) && (location < MAX_COMETS))
+				location++; 
+
+  			if (location < MAX_COMETS)
+			{
+				/* First comet in word is shootable: */
+				if (0 == i)
+				  comets[location].shootable = 1;
+				else
+				  comets[location].shootable = 0;
+
+				comets[location].alive = 1;
+				comets[location].city = target + i; 
+				comets[location].x = cities[target + i].x;
+				comets[location].y = 0;
+				comets[location].ch = word[i];
+				comets[location].next = NULL;
+
+				/* Take care of link from previous letter's comet: */
+				if (prev_comet)
+				  prev_comet->next = &comets[location];
+				/* Save pointer for next time through: */
+                                prev_comet = &comets[location];
+
+				DEBUGCODE {fprintf(stderr, "Assigning letter to comet: %C\n", word[i]);}
+			}
+		}
+	}
+	LOG ("Leaving laser_add_comet()\n");
+}
+
+
+/* Draw numbers/symbols over the attacker: */
+
+static void laser_draw_let(wchar_t c, int x, int y)
+{
+  /* Draw letter in correct place relative to comet: */
+  const int offset_x = -10; /* Values determined by trial and error: */
+  const int offset_y = -50;
+
+  SDL_Rect dst;
+  SDL_Surface* s;
+  dst.x = x + offset_x;
+  dst.y = y + offset_y;
+  s = GetWhiteGlyph(c);
+  if (s)
+    SDL_BlitSurface(s, NULL, screen, &dst); 
+}
+
+
+/* Draw status numbers: */
+
+static void laser_draw_numbers(const unsigned char* str, int x)
+{
+  int i, cur_x, c;
+  SDL_Rect src, dest;
+
+
+  cur_x = x;
+
+
+  /* Draw each character: */
+  
+  for (i = 0; i < strlen(str); i++)
+    {
+      c = -1;
+
+
+      /* Determine which character to display: */
+      
+      if (str[i] >= '0' && str[i] <= '9')
+	c = str[i] - '0';
+      
+
+      /* Display this character! */
+      
+      if (c != -1)
+	{
+	  src.x = c * (images[IMG_NUMBERS]->w / 10);
+	  src.y = 0;
+	  src.w = (images[IMG_NUMBERS]->w / 10);
+	  src.h = images[IMG_NUMBERS]->h;
+	  
+	  dest.x = cur_x;
+	  dest.y = 0;
+	  dest.w = src.w;
+	  dest.h = src.h;
+	  
+	  SDL_BlitSurface(images[IMG_NUMBERS], &src,
+			  screen, &dest);
+
+
+          /* Move the 'cursor' one character width: */
+
+	  cur_x = cur_x + (images[IMG_NUMBERS]->w / 10);
+	}
+    }
+}
+
+/* Draw a line: */
+
+static void laser_draw_line(int x1, int y1, int x2, int y2, int red, int grn, int blu)
+{
+  int dx, dy, tmp;
+  float m, b;
+  Uint32 pixel;
+  SDL_Rect dest;
+ 
+  pixel = SDL_MapRGB(screen->format, red, grn, blu);
+
+  dx = x2 - x1;
+  dy = y2 - y1;
+
+  laser_putpixel(screen, x1, y1, pixel);
+  
+  if (dx != 0)
+  {
+    m = ((float) dy) / ((float) dx);
+    b = y1 - m * x1;
+
+    if (x2 > x1)
+      dx = 1;
+    else
+      dx = -1;
+
+    while (x1 != x2)
+    {
+      x1 = x1 + dx;
+      y1 = m * x1 + b;
+      
+      laser_putpixel(screen, x1, y1, pixel);
+    }
+  }
+  else
+  {
+    if (y1 > y2)
+    {
+      tmp = y1;
+      y1 = y2;
+      y2 = tmp;
+    }
+    
+    dest.x = x1;
+    dest.y = y1;
+    dest.w = 3;
+    dest.h = y2 - y1;
+
+    SDL_FillRect(screen, &dest, pixel);
+  }
+}
+
+
+/* Draw a single pixel into the surface: */
+
+static void laser_putpixel(SDL_Surface * surface, int x, int y, Uint32 pixel)
+{
+#ifdef PUTPIXEL_RAW
+  int bpp;
+  Uint8 * p;
+  
+  /* Determine bytes-per-pixel for the surface in question: */
+  
+  bpp = surface->format->BytesPerPixel;
+  
+  
+  /* Set a pointer to the exact location in memory of the pixel
+     in question: */
+  
+  p = (Uint8 *) (surface->pixels +       /* Start at beginning of RAM */
+                 (y * surface->pitch) +  /* Go down Y lines */
+                 (x * bpp));             /* Go in X pixels */
+  
+  
+  /* Assuming the X/Y values are within the bounds of this surface... */
+  
+  if (x >= 0 && y >= 0 && x < surface -> w && y < surface -> h)
+    {
+      /* Set the (correctly-sized) piece of data in the surface's RAM
+         to the pixel value sent in: */
+      
+      if (bpp == 1)
+        *p = pixel;
+      else if (bpp == 2)
+        *(Uint16 *)p = pixel;
+      else if (bpp == 3)
+        {
+          if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+            {
+              p[0] = (pixel >> 16) & 0xff;
+              p[1] = (pixel >> 8) & 0xff;
+              p[2] = pixel & 0xff;
+            }
+          else
+            {
+              p[0] = pixel & 0xff;
+              p[1] = (pixel >> 8) & 0xff;
+              p[2] = (pixel >> 16) & 0xff;
+            }
+        }
+      else if (bpp == 4)
+        {
+          *(Uint32 *)p = pixel;
+        }
+    }
+#else
+  SDL_Rect dest;
+
+  dest.x = x;
+  dest.y = y;
+  dest.w = 3;
+  dest.h = 4;
+
+  SDL_FillRect(surface, &dest, pixel);
+#endif
+}
+
+
+/* Draw image at lower center of screen: */
+
+static void laser_draw_console_image(int i)
+{
+  SDL_Rect dest;
+
+  dest.x = (screen->w - images[i]->w) / 2;
+  dest.y = (screen->h - images[i]->h);
+  dest.w = images[i]->w;
+  dest.h = images[i]->h;
+
+  SDL_BlitSurface(images[i], NULL, screen, &dest);
+}
+
+
+/* Increment score: */
+
+static void laser_add_score(int inc)
+{
+  score += inc;
+  if (score < 0) score = 0;
+}
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/laser.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/laser.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/laser.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/laser.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,188 @@
+
+#ifndef LASER_H
+#define LASER_H
+
+#define MAX_COMETS 30
+#define NUM_CITIES 9   /* MUST BE AN EVEN NUMBER! */
+
+#define NUM_BKGDS 5
+#define MAX_CITY_COLORS 4
+
+typedef struct comet_type {
+  int alive;
+  int expl;
+  int city;
+  int x, y;
+  int shootable;
+  struct comet_type* next;
+  wchar_t ch;
+} comet_type;
+
+typedef struct city_type {
+  int alive, expl, shields;
+  int x;
+} city_type;
+
+typedef struct laser_type {
+  int alive;
+  int x1, y1;
+  int x2, y2;
+} laser_type;
+
+enum {
+  IMG_TUX_HELMET1,
+  IMG_TUX_HELMET2,
+  IMG_TUX_HELMET3,
+  IMG_CITY_BLUE,
+  IMG_CITY_BLUE_EXPL1,
+  IMG_CITY_BLUE_EXPL2,
+  IMG_CITY_BLUE_EXPL3,
+  IMG_CITY_BLUE_EXPL4,
+  IMG_CITY_BLUE_EXPL5,
+  IMG_CITY_BLUE_DEAD,
+  IMG_CITY_GREEN,
+  IMG_CITY_GREEN_EXPL1,
+  IMG_CITY_GREEN_EXPL2,
+  IMG_CITY_GREEN_EXPL3,
+  IMG_CITY_GREEN_EXPL4,
+  IMG_CITY_GREEN_EXPL5,
+  IMG_CITY_GREEN_DEAD,
+  IMG_CITY_ORANGE,
+  IMG_CITY_ORANGE_EXPL1,
+  IMG_CITY_ORANGE_EXPL2,
+  IMG_CITY_ORANGE_EXPL3,
+  IMG_CITY_ORANGE_EXPL4,
+  IMG_CITY_ORANGE_EXPL5,
+  IMG_CITY_ORANGE_DEAD,
+  IMG_CITY_RED,
+  IMG_CITY_RED_EXPL1,
+  IMG_CITY_RED_EXPL2,
+  IMG_CITY_RED_EXPL3,
+  IMG_CITY_RED_EXPL4,
+  IMG_CITY_RED_EXPL5,
+  IMG_CITY_RED_DEAD,
+  IMG_COMET1,
+  IMG_COMET2,
+  IMG_COMET3,
+  IMG_COMETEX1,
+  IMG_COMETEX2,
+  IMG_CONSOLE,
+  IMG_TUX_CONSOLE1,
+  IMG_TUX_CONSOLE2,
+  IMG_TUX_CONSOLE3,
+  IMG_TUX_CONSOLE4,
+  IMG_TUX_RELAX1,
+  IMG_TUX_RELAX2,
+  IMG_TUX_DRAT,
+  IMG_TUX_YIPE,
+  IMG_TUX_YAY1,
+  IMG_TUX_YAY2,
+  IMG_TUX_YES1,
+  IMG_TUX_YES2,
+  IMG_TUX_SIT,
+  IMG_TUX_FIST1,
+  IMG_TUX_FIST2,
+  IMG_WAVE,
+  IMG_SCORE,
+  IMG_NUMBERS,
+  IMG_GAMEOVER,
+  NUM_IMAGES
+};
+
+
+static unsigned char * image_filenames[NUM_IMAGES] = {
+  "status/tux_helmet1.png",
+  "status/tux_helmet2.png",
+  "status/tux_helmet3.png", 
+  "cities/city-blue.png",
+  "cities/csplode-blue-1.png",
+  "cities/csplode-blue-2.png",
+  "cities/csplode-blue-3.png",
+  "cities/csplode-blue-4.png",
+  "cities/csplode-blue-5.png",
+  "cities/cdead-blue.png",
+  "cities/city-green.png",
+  "cities/csplode-green-1.png",
+  "cities/csplode-green-2.png",
+  "cities/csplode-green-3.png",
+  "cities/csplode-green-4.png",
+  "cities/csplode-green-5.png",
+  "cities/cdead-green.png",
+  "cities/city-orange.png",
+  "cities/csplode-orange-1.png",
+  "cities/csplode-orange-2.png",
+  "cities/csplode-orange-3.png",
+  "cities/csplode-orange-4.png",
+  "cities/csplode-orange-5.png",
+  "cities/cdead-orange.png",
+  "cities/city-red.png",
+  "cities/csplode-red-1.png",
+  "cities/csplode-red-2.png",
+  "cities/csplode-red-3.png",
+  "cities/csplode-red-4.png",
+  "cities/csplode-red-5.png",
+  "cities/cdead-red.png",
+  "comets/comet1.png",
+  "comets/comet2.png",
+  "comets/comet3.png",
+  "comets/cometex1.png",
+  "comets/cometex2.png",
+  "tux/console.png",
+  "tux/tux-console1.png",
+  "tux/tux-console2.png",
+  "tux/tux-console3.png",
+  "tux/tux-console4.png",
+  "tux/tux-relax1.png",
+  "tux/tux-relax2.png",
+  "tux/tux-drat.png",
+  "tux/tux-yipe.png",
+  "tux/tux-yay1.png",
+  "tux/tux-yay2.png",
+  "tux/tux-yes1.png",
+  "tux/tux-yes2.png",
+  "tux/tux-sit.png",
+  "tux/tux-fist0.png",
+  "tux/tux-fist1.png",
+  "status/wave.png",
+  "status/score.png",
+  "status/numbers.png",
+  "status/gameover.png"
+};
+
+enum {
+  SND_POP,
+  SND_LASER,
+  SND_BUZZ,
+  SND_ALARM,
+  SND_SHIELDSDOWN,
+  SND_EXPLOSION,
+  SND_CLICK,
+  NUM_SOUNDS
+};
+
+
+static unsigned char * sound_filenames[NUM_SOUNDS] = {
+  "pop.wav",
+  "laser.wav",
+  "buzz.wav",
+  "alarm.wav",
+  "shieldsdown.wav",
+  "explosion.wav",
+  "click.wav"
+};
+
+
+enum {
+  MUS_GAME,
+  MUS_GAME2,
+  MUS_GAME3,
+  NUM_MUSICS
+};
+
+static unsigned char * music_filenames[NUM_MUSICS] = {
+  "game.mod",
+  "game2.mod",
+  "game3.mod"
+};
+
+#endif

Copied: tuxtype/branches/tuxtype-soc-mh/src/loaders.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/loaders.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/loaders.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/loaders.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,508 @@
+/***************************************************************************
+ -  file: loaders.c
+ -  description: Functions to load multimedia for Tux Typing
+                             -------------------
+    begin                : Thu May 4 2000
+    copyright            : (C) 2000 by Sam Hart
+                         : (C) 2003 by Jesse Andrews
+    email                : tuxtype-dev at tux4kids.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+#include "SDL_extras.h"
+
+static SDL_Surface* win_bkgd = NULL;
+static SDL_Surface* fullscr_bkgd = NULL;
+
+/* Local function prototypes: */
+static int max(int n1, int n2);
+//static SDL_Surface* flip(SDL_Surface *in, int x, int y);
+
+/* Returns 1 if valid file, 2 if valid dir, 0 if neither: */
+int CheckFile(const char* file)
+{
+  FILE* fp = NULL;
+  DIR* dp = NULL;
+
+  if (!file)
+  {
+    fprintf(stderr, "CheckFile(): invalid char* argument!");
+    return;
+  }
+
+  DEBUGCODE {fprintf(stderr, "CheckFile() - checking: %s\n", file);} 
+
+  dp = opendir(file);
+  if (dp)
+  {
+    LOG("Opened successfully as DIR\n");
+
+    closedir(dp);
+    return 2;
+  }
+
+  fp = fopen(file, "r");
+  if (fp)
+  {
+    LOG("Opened successfully as FILE\n");
+    fclose(fp);
+    return 1;
+  }
+
+  LOG("Unable to open as either FILE or DIR\n");
+  return 0;
+}
+
+
+/* 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)
+{
+
+	setlocale(LC_ALL,settings.theme_locale_name);
+	bindtextdomain(PACKAGE,"/usr/local/share/locale");
+        textdomain(PACKAGE);
+	return;
+
+}
+
+int max(int n1, int n2)
+{
+	return (n1 > n2 ? n1 : n2);
+}
+
+// /**********************
+//  Flip:
+//    input: a SDL_Surface, x, y
+//    output: a copy of the SDL_Surface flipped via rules:
+// 
+//      if x is a positive value, then flip horizontally
+//      if y is a positive value, then flip vertically
+// 
+//      note: you can have it flip both
+// **********************/
+// SDL_Surface* flip(SDL_Surface* in, int x, int y ) {
+// 	SDL_Surface *out, *tmp;
+// 	SDL_Rect from_rect, to_rect;
+// 	Uint32	flags;
+// 	Uint32  colorkey=0;
+// 
+// 	/* --- grab the settings for the incoming pixmap --- */
+// 
+// 	SDL_LockSurface(in);
+// 	flags = in->flags;
+// 
+// 	/* --- change in's flags so ignore colorkey & alpha --- */
+// 
+// 	if (flags & SDL_SRCCOLORKEY) {
+// 		in->flags &= ~SDL_SRCCOLORKEY;
+// 		colorkey = in->format->colorkey;
+// 	}
+// 	if (flags & SDL_SRCALPHA) {
+// 		in->flags &= ~SDL_SRCALPHA;
+// 	}
+// 
+// 	SDL_UnlockSurface(in);
+// 
+// 	/* --- create our new surface --- */
+// 
+// 	out = SDL_CreateRGBSurface(
+// 		SDL_SWSURFACE,
+// 		in->w, in->h, 32, RMASK, GMASK, BMASK, AMASK);
+// 
+// 	/* --- flip horizontally if requested --- */
+// 
+// 	if (x) {
+// 		from_rect.h = to_rect.h = in->h;
+// 		from_rect.w = to_rect.w = 1;
+// 		from_rect.y = to_rect.y = 0;
+// 		from_rect.x = 0;
+// 		to_rect.x = in->w - 1;
+// 
+// 		do {
+// 			SDL_BlitSurface(in, &from_rect, out, &to_rect);
+// 			from_rect.x++;
+// 			to_rect.x--;
+// 		} while (to_rect.x >= 0);
+// 	}
+// 
+// 	/* --- flip vertically if requested --- */
+// 
+// 	if (y) {
+// 		from_rect.h = to_rect.h = 1;
+// 		from_rect.w = to_rect.w = in->w;
+// 		from_rect.x = to_rect.x = 0;
+// 		from_rect.y = 0;
+// 		to_rect.y = in->h - 1;
+// 
+// 		do {
+// 			SDL_BlitSurface(in, &from_rect, out, &to_rect);
+// 			from_rect.y++;
+// 			to_rect.y--;
+// 		} while (to_rect.y >= 0);
+// 	}
+// 
+// 	/* --- restore colorkey & alpha on in and setup out the same --- */
+// 
+// 	SDL_LockSurface(in);
+// 
+// 	if (flags & SDL_SRCCOLORKEY) {
+// 		in->flags |= SDL_SRCCOLORKEY;
+// 		in->format->colorkey = colorkey;
+// 		tmp = SDL_DisplayFormat(out);
+// 		SDL_FreeSurface(out);
+// 		out = tmp;
+// 		out->flags |= SDL_SRCCOLORKEY;
+// 		out->format->colorkey = colorkey;
+// 	} else if (flags & SDL_SRCALPHA) {
+// 		in->flags |= SDL_SRCALPHA;
+// 		tmp = SDL_DisplayFormatAlpha(out);
+// 		SDL_FreeSurface(out);
+// 		out = tmp;
+// 	} else {
+// 		tmp = SDL_DisplayFormat(out);
+// 		SDL_FreeSurface(out);
+// 		out = tmp;
+// 	}
+// 
+// 	SDL_UnlockSurface(in);
+// 
+// 	return out;
+// }
+
+
+/* FIXME need code to search for font paths on different platforms */
+TTF_Font* LoadFont(const char* font_name, int font_size )
+{
+  TTF_Font* loaded_font = NULL;
+  char fn[FNLEN];
+  int i;
+
+  /* try to find font in default data dir: */
+  sprintf(fn, "%s/fonts/%s", settings.default_data_path, font_name );
+
+  DEBUGCODE { fprintf(stderr, "LoadFont(): looking for %s using data paths\n", fn); }
+
+  /* try to load the font, if successful, return font*/
+  loaded_font = TTF_OpenFont(fn, font_size);
+  if (loaded_font != NULL)
+    return loaded_font;
+		
+
+  /* HACK hard-coded for Debian (and current exact font names): */ 
+
+  if (strncmp(font_name, "AndikaDesRevG.ttf", FNLEN ) == 0)
+    sprintf(fn, "/usr/share/fonts/truetype/ttf-sil-andika/AndikaDesRevG.ttf");
+  else if (strncmp(font_name, "DoulosSILR.ttf", FNLEN ) == 0)
+    sprintf(fn, "/usr/share/fonts/truetype/ttf-sil-doulos/DoulosSILR.ttf");
+  else if (strncmp(font_name, "lohit_hi.ttf", FNLEN ) == 0)
+    sprintf(fn, "/usr/share/fonts/truetype/ttf-devanagari-fonts/lohit_hi.ttf");
+  else if (strncmp(font_name, "Rachana_w01.ttf", FNLEN ) == 0)
+    sprintf(fn, "/usr/share/fonts/truetype/ttf-malayalam-fonts/Rachana_w01.ttf");
+
+
+
+  DEBUGCODE { fprintf(stderr, "LoadFont(): looking for %s\n in OS' font path\n", fn); }
+
+  /* try to load the font, if successful, return font*/
+  loaded_font = TTF_OpenFont(fn, font_size);
+  if (loaded_font != NULL)
+    return loaded_font;
+
+  fprintf(stderr, "LoadFont(): Error - couldn't load font: %s\n", fn);
+  return NULL;
+}
+
+/***********************
+	LoadImage : Load an image and set transparent if requested
+************************/
+SDL_Surface* LoadImage(const char* datafile, int mode)
+{
+  int oldDebug;  //so we can turn off debug output for this func only
+  SDL_Surface* tmp_pic = NULL, *final_pic = NULL;
+  char fn[FNLEN];
+
+//  oldDebug = settings.debug_on;  // suppress output for now
+//  settings.debug_on = 0;
+
+  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); }
+
+    tmp_pic = IMG_Load(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);}
+  }
+
+  /* If we don't have a valid image yet, try the default path: */
+  if (!tmp_pic)
+  {
+    sprintf(fn, "%s/images/%s", settings.default_data_path, datafile);
+    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);}
+    else
+      DEBUGCODE { fprintf(stderr, "Warning: graphics file %s could not be loaded\n", fn);}
+  }
+
+  /* Couldn't load image - action depends on whether image is essential: */
+  if (!tmp_pic)
+  {
+    if (mode & IMG_NOT_REQUIRED)
+    { 
+//      settings.debug_on = oldDebug;
+      return NULL;
+    }
+
+    fprintf(stderr, "ERROR could not load required graphics file %s\n", datafile);
+    exit(1);
+  }
+
+
+  /* If we get to here, success - setup the image in the proper format: */
+
+  switch (mode & IMG_MODES)
+  {
+    case IMG_REGULAR:
+    { 
+      final_pic = SDL_DisplayFormat(tmp_pic);
+      SDL_FreeSurface(tmp_pic);
+      break;
+    }
+
+    case IMG_ALPHA:
+    {
+      final_pic = SDL_DisplayFormatAlpha(tmp_pic);
+      SDL_FreeSurface(tmp_pic);
+      break;
+    }
+
+    case IMG_COLORKEY:
+    {
+      SDL_LockSurface(tmp_pic);
+      SDL_SetColorKey(tmp_pic,
+                      (SDL_SRCCOLORKEY | SDL_RLEACCEL),
+                      SDL_MapRGB(tmp_pic->format, 255, 255, 0));
+      final_pic = SDL_DisplayFormat(tmp_pic);
+      SDL_FreeSurface(tmp_pic);
+      break;
+    }
+
+    default:
+    {
+      LOG ("Image mode not recognized\n");
+    }
+  }
+
+  LOG( "LoadImage(): Done\n" );
+
+//  settings.debug_on = oldDebug;
+
+  return (final_pic);
+}
+
+
+
+/**********************
+LoadBothBkgds() : loads two scaled images: one for the user's native 
+resolution and one for 640x480 fullscreen. 
+Returns: the number of images that were scaled
+**********************/
+int LoadBothBkgds(const char* datafile)
+{
+  int ret = 0;
+  SDL_Surface* orig = NULL;
+  
+  //Avoid memory leak in case something else already loaded:
+  FreeBothBkgds();
+
+  LOG("Entering LoadBothBkgds()\n");
+
+  orig = LoadImage(datafile, IMG_REGULAR);
+
+  DEBUGCODE
+  {
+     printf("Scaling %dx%d to: %dx%d, %dx%d\n", 
+           orig->w, orig->h, RES_X, RES_Y, fs_res_x, fs_res_y);
+  }
+
+  if (orig->w == RES_X && orig->h == RES_Y)
+  {
+    win_bkgd = orig;
+  }
+  else
+  {
+    win_bkgd = zoom(orig, RES_X, RES_Y);
+    ++ret;
+  }
+  
+  if (orig->w == fs_res_x && orig->h == fs_res_y)
+  {
+    fullscr_bkgd = orig;
+  }
+  else
+  {
+    fullscr_bkgd = zoom(orig, fs_res_x, fs_res_y);
+    ++ret;
+  }
+  
+  if (ret == 2) //orig won't be used at all
+    SDL_FreeSurface(orig);
+    
+  DEBUGCODE
+  {
+    printf("%d images scaled\nLeaving LoadBothBkgds()\n", ret);
+  }
+  return ret;
+}
+
+
+SDL_Surface* CurrentBkgd(void)
+{
+  if (!screen)
+    return NULL;
+  if (screen->flags & SDL_FULLSCREEN)
+    return fullscr_bkgd;
+  else
+    return win_bkgd;
+}
+
+void FreeBothBkgds(void)
+{
+  if (win_bkgd)
+    SDL_FreeSurface(win_bkgd);
+  win_bkgd = NULL;
+
+  if (fullscr_bkgd)
+    SDL_FreeSurface(fullscr_bkgd);
+  fullscr_bkgd = NULL;
+}
+
+
+sprite* FlipSprite(sprite* in, int X, int Y ) {
+	sprite* out;
+
+	out = malloc(sizeof(sprite));
+	if (in->default_img != NULL)
+		out->default_img = Flip( in->default_img, X, Y );
+	else
+		out->default_img = NULL;
+	for ( out->num_frames=0; out->num_frames<in->num_frames; out->num_frames++ )
+		out->frame[out->num_frames] = Flip( in->frame[out->num_frames], X, Y );
+	out->cur = 0;
+	return out;
+}
+
+sprite* LoadSprite(const char* name, int MODE ) {
+	sprite *new_sprite;
+	char fn[FNLEN];
+	int x;
+
+	/* JA --- HACK check out what has changed with new code */
+
+	new_sprite = malloc(sizeof(sprite));
+
+	sprintf(fn, "%sd.png", name);
+	new_sprite->default_img = LoadImage( fn, MODE|IMG_NOT_REQUIRED );
+	for (x = 0; x < MAX_SPRITE_FRAMES; x++) {
+		sprintf(fn, "%s%d.png", name, x);
+		new_sprite->frame[x] = LoadImage( fn, MODE|IMG_NOT_REQUIRED );
+		if ( new_sprite->frame[x] == NULL ) {
+			new_sprite->cur = 0;
+			new_sprite->num_frames = x;
+			break;
+		}
+	}
+
+	DEBUGCODE {
+		fprintf( stderr, "loading sprite %s - contains %d frames\n",
+		        name, new_sprite->num_frames );
+	}
+
+	return new_sprite;
+}
+
+void FreeSprite(sprite* gfx )
+{
+  int x;
+
+  if (!gfx)
+    return;
+ 
+  for (x = 0; x < gfx->num_frames; x++)
+    SDL_FreeSurface(gfx->frame[x]);
+  SDL_FreeSurface(gfx->default_img);
+  free(gfx);
+}
+
+/***************************
+	LoadSound : Load a sound/music patch from a file.
+****************************/
+Mix_Chunk* LoadSound(const char* datafile )
+{ 
+  Mix_Chunk* tempChunk = NULL;
+  char fn[FNLEN];
+
+  /* First look under theme path if desired: */
+  if (!settings.use_english)
+  {
+    sprintf(fn , "%s/sounds/%s", settings.theme_data_path, datafile);
+    tempChunk = Mix_LoadWAV(fn);
+    if (tempChunk)
+      return tempChunk;
+  }
+
+  /* If nothing loaded yet, try default path: */
+  if (!tempChunk)
+  {
+    sprintf(fn , "%s/sounds/%s", settings.default_data_path, datafile);
+    tempChunk = Mix_LoadWAV(fn);
+    return tempChunk;
+  }
+}
+
+
+/************************
+	LoadMusic : Load
+	music from a datafile
+*************************/
+Mix_Music* LoadMusic(const char* datafile )
+{ 
+  Mix_Music* temp_music = NULL;
+  char fn[FNLEN];
+
+  /* First look under theme path if desired: */
+  if (!settings.use_english)
+  {
+    sprintf(fn , "%s/sounds/%s", settings.theme_data_path, datafile);
+    temp_music = Mix_LoadMUS(fn);
+    if (temp_music)
+      return temp_music;
+  }
+
+  /* If nothing loaded yet, try default path: */
+  if (!temp_music)
+  {
+    sprintf(fn , "%s/sounds/%s", settings.default_data_path, datafile);
+    temp_music = Mix_LoadMUS(fn);
+    return temp_music;
+  }
+}

Copied: tuxtype/branches/tuxtype-soc-mh/src/main.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/main.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/main.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/main.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,170 @@
+/***************************************************************************
+                          main.c 
+ -  description: main tux type file
+                             -------------------
+    begin                : Tue May  2 13:25:06 MST 2000
+    copyright            : (C) 2000 by Sam Hart
+                         : (C) 2003 by Jesse Andrews
+    email                : tuxtype-dev at tux4kids.net
+ ***************************************************************************/
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+
+SDL_Surface* screen;
+
+
+SDL_Event  event;
+
+
+
+/********************
+  main : init stuff
+*********************/
+int main(int argc, char *argv[])
+{
+  Uint32 lib_flags = 0;
+  int i;
+
+  /* Initialize settings with hard-coded defaults: */ 
+  Opts_Initialize();
+  /* Put in preset highscores so there's something to compare */
+  hScores_Initialize();
+  profile_Initialize();
+
+  srand(time(NULL));
+
+  // This sets settings.default_data_path to the default theme file path:
+  SetupPaths(NULL);
+
+  LoadSettings();
+  DEBUGCODE { printf("Window setting from config file is: %d\n", settings.fullscreen);}
+
+  lib_flags = SDL_INIT_VIDEO;
+
+  /* FIXME this could go into something like HandleCommandArgs() */
+  // check command line args
+  if (argc > 1)
+  { 
+    for (i = 1; i < argc; i++)
+    {
+      if (  (strcmp(argv[i], "-h") == 0)
+         || (strcmp(argv[i], "--help") == 0)
+         || (strcmp(argv[i], "-help") == 0))
+      {
+        fprintf(stderr, "\nUsage:\n tuxtype [OPTION]...");
+        fprintf(stderr, "\n\nOptions:\n\n\t-h, --help, -help");
+        fprintf(stderr, "\n\t\tPrints this help message");
+        fprintf(stderr, "\n\n\t-f, --fullscreen");
+        fprintf(stderr, "\n\t\tSelects fullscreen display (default)");
+        fprintf(stderr, "\n\n\t-w, --window");
+        fprintf(stderr, "\n\t\tSelects windowed display (not fullscreen)");
+        fprintf(stderr, "\n\n\t-s, --sound");
+        fprintf(stderr, "\n\t\tAllow in-game sounds (default)");
+        fprintf(stderr, "\n\n\t-ns, --nosound");
+        fprintf(stderr, "\n\t\tDisables in-game sounds");
+        fprintf(stderr, "\n\n\t-t {THEME}, --theme {THEME}");
+        fprintf(stderr, "\n\t\tUse theme named {THEME}, if it exists");
+        fprintf(stderr, "\n\n\t-sp, --speed");
+        fprintf(stderr, "\n\t\tSpeed up gameplay (for use on slower");
+        fprintf(stderr, "\n\t\tmachines)");
+        fprintf(stderr, "\n\n\t-d, --debug");
+        fprintf(stderr, "\n\t\tEnable debug mode (output)\n");
+        fprintf(stderr, "\n\n\t-v, --version");
+        fprintf(stderr, "\n\t\tDisplay version number and exit\n");
+        exit(0);
+      }
+
+      if (  (strcmp(argv[i], "-v") == 0)
+         || (strcmp(argv[i], "--version") == 0))
+      {
+        fprintf(stderr, "\n%s, Version %s\n", PACKAGE, VERSION);
+        fprintf(stderr, "Copyright (C) Sam Hart <hart at geekcomix.com>, under the GPL\n");
+        fprintf(stderr, "-See COPYING file for more info... Thx ;)\n\n");
+        exit(0);
+      }
+
+      if (  (strcmp(argv[i], "-f") == 0)
+         || (strcmp(argv[i], "--fullscreen") == 0))
+        settings.fullscreen = 1;
+
+      if (  (strcmp(argv[i], "-w") == 0)
+         || (strcmp(argv[i], "--window") == 0))
+        settings.fullscreen = 0;
+
+      if (  (strcmp(argv[i], "-sp") == 0)
+         || (strcmp(argv[i], "--speed") == 0))
+        settings.speed_up = 1;
+
+      if (  (strcmp(argv[i], "-d") == 0)
+         || (strcmp(argv[i], "--debug") == 0))
+        settings.debug_on = 1;
+
+      if (  (strcmp(argv[i], "-s") == 0)
+         || (strcmp(argv[i], "--sound") == 0))
+        settings.sys_sound = 1;
+
+      if (  (strcmp(argv[i], "-ns") == 0)
+         || (strcmp(argv[i], "--nosound") == 0))
+        settings.sys_sound = 0;
+
+      if (  (strcmp(argv[i], "--hidden") == 0)
+         || (strcmp(argv[i], "-hidden") == 0))
+        settings.hidden = 1;
+
+      if (  (strcmp(argv[i], "-t") == 0)
+         || (strcmp(argv[i], "--theme") == 0))
+        SetupPaths(argv[++i]);
+    }
+  }
+
+  DEBUGCODE
+  {
+    fprintf(stderr, "\n%s, version %s BEGIN\n", PACKAGE, VERSION);
+  }
+
+  lib_flags |= SDL_INIT_AUDIO;
+
+  LibInit(lib_flags); /* calls SDL_Init(), TTF_Init(), some other settings */
+  GraphicsInit(); /* calls SDL_SetVideoMode(), a few others     */
+
+  #ifdef HAVE_LIBSDL_PANGO
+  init_SDLPango_Context();
+  #endif
+
+  if (settings.sys_sound)
+  {
+    Mix_VolumeMusic(settings.mus_volume);
+    Mix_Volume(-1, settings.sfx_volume);
+  }
+
+  /* FIXME: we should check config files/environment variables like LANG! */
+  LoadLang();
+  LoadKeyboard();
+  /* load highscores*/
+  load_highscores();
+
+  
+  /* Now actually play the game: */
+  TitleScreen();
+
+  /* save settings/profile/cores before exit */
+  SaveSettings();
+  saveProfile(activeProfile.profileNum);
+  saveHighScores();
+
+  /* Release heap: */
+  Cleanup();
+
+  LOG( "---GAME DONE, EXIT---- Thank you.\n" );
+
+  return EXIT_SUCCESS;
+}

Copied: tuxtype/branches/tuxtype-soc-mh/src/options.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/options.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/options.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/options.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,93 @@
+/***************************************************************************
+ -  file: options.c
+ -  description: Functions supporting settings struct for Tux Typing
+                             -------------------
+    begin                : Wed July 11 2007
+    copyright            : (C) 2000 by David Bruce
+                           dbruce at tampabay.rr.com
+
+    project email        : tuxmath-devel at sourceforge.net
+    website              : http://tux4kids.alioth.debian.org
+
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+
+/* Local function prototypes: */
+
+/* Global (for now) settings struct: */
+game_option_type settings;
+profiles activeProfile; //added globally since will be required globally
+highscores hscores;
+
+/* Simply stick all the default values into the settings struct: */
+void Opts_Initialize(void)
+{
+  strncpy(settings.theme_font_name, DEFAULT_MENU_FONT, FNLEN);
+  strncpy(settings.theme_locale_name, DEFAULT_LOCALE, FNLEN);
+  settings.use_english = DEFAULT_USE_ENGLISH;
+  settings.fullscreen = DEFAULT_FULLSCREEN;
+  settings.sys_sound = DEFAULT_SYS_SOUND;
+  settings.sfx_volume = DEFAULT_SFX_VOLUME;
+  settings.mus_volume = DEFAULT_MUS_VOLUME;
+  settings.menu_music = DEFAULT_MENU_MUSIC;
+  settings.menu_sound = DEFAULT_MENU_SOUND;
+  settings.speed_up = DEFAULT_SPEED_UP;
+  settings.show_tux4kids = DEFAULT_SHOW_TUX4KIDS;
+  settings.debug_on = DEFAULT_DEBUG_ON;
+  settings.o_lives = DEFAULT_O_LIVES;
+  settings.sound_vol = DEFAULT_SOUND_VOL;
+  settings.numProfiles = DEFAULT_PROFILES; //no profiles made yet, so default, which is 0
+  settings.hidden = DEFAULT_HIDDEN; 
+}
+
+void profile_Initialize(void) //first profile shouldn't have any scores...
+{
+	activeProfile.highscore1 	= 	0;
+	activeProfile.highscore2 	= 	0;
+	activeProfile.highscore3 	= 	0;
+	activeProfile.highscore4 	= 	0;
+	activeProfile.highscore5 	= 	0;
+	activeProfile.highscore6 	= 	0;
+	activeProfile.highscore7 	= 	0;
+	activeProfile.highscore8 	= 	0;
+	activeProfile.wpm_highest 	= 	0;
+	activeProfile.wpm_average 	= 	0;
+	activeProfile.wpm_slowest 	= 	0;
+	activeProfile.wpm_taken	 	=	0;
+}
+void hScores_Initialize(void)
+{
+	hscores.highscore1_name 	= DEFAULT_GNAME;
+	hscores.ghighscore1 		= DEFAULT_GHIGHSCORE1;
+	hscores.highscore2_name 	= DEFAULT_GNAME;
+	hscores.ghighscore2 		= DEFAULT_GHIGHSCORE2;
+	hscores.highscore3_name 	= DEFAULT_GNAME;
+	hscores.ghighscore3 		= DEFAULT_GHIGHSCORE3;
+	hscores.highscore4_name 	= DEFAULT_GNAME;
+	hscores.ghighscore4 		= DEFAULT_GHIGHSCORE4;
+	hscores.highscore5_name 	= DEFAULT_GNAME;
+	hscores.ghighscore5 		= DEFAULT_GHIGHSCORE5;
+	hscores.highscore6_name 	= DEFAULT_GNAME;
+	hscores.ghighscore6 		= DEFAULT_GHIGHSCORE6;
+	hscores.highscore7_name 	= DEFAULT_GNAME;
+	hscores.ghighscore7 		= DEFAULT_GHIGHSCORE7;
+	hscores.highscore8_name 	= DEFAULT_GNAME;
+	hscores.ghighscore8 		= DEFAULT_GHIGHSCORE8;
+	hscores.wpm_fastest_name 	= DEFAULT_GNAME;
+	hscores.wpm_fastest 		= DEFAULT_GWPM_FASTEST;
+	hscores.wpm_average_name 	= DEFAULT_GNAME;
+	hscores.wpm_average 		= DEFAULT_GWPM_AVERAGE;
+	hscores.wpm_slowest_name 	= DEFAULT_GNAME;
+	hscores.wpm_slowest 		= DEFAULT_GWPM_SLOWEST;
+}
\ No newline at end of file

Copied: tuxtype/branches/tuxtype-soc-mh/src/pause.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/pause.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/pause.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/pause.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,393 @@
+/***************************************************************************
+pause.c 
+-  description: pause screen for the games
+-------------------
+begin                : Jan 22, 2003
+copyright            : (C) 2003 by Jesse Andrews
+email                : jdandr2 at uky.edu
+***************************************************************************/
+
+/***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+#include "SDL_extras.h"
+
+static Mix_Chunk *pause_sfx = NULL;
+static SDL_Surface *up = NULL, *down = NULL, *left = NULL, *right = NULL;
+static SDL_Rect rectUp, rectDown, rectLeft, rectRight;
+static TTF_Font *f1 = NULL, *f2 = NULL;
+
+/* Local function prototypes: */
+//static void darkenscreen(void);
+static void draw_vols(int sfx, int mus);
+static void pause_draw(void);
+static void pause_load_media(void);
+static void pause_unload_media(void);
+
+// QUESTION: For usability sake, should escape return to the game
+//           and the user have to choose to quit the game, or ???
+/**********************
+Pause : Pause the game
+***********************/
+int Pause(void)
+{
+	int paused = 1;
+	int sfx_volume=0;
+	int old_sfx_volume;
+	int mus_volume=0;
+	int old_mus_volume;
+	int mousePressed = 0;
+	int quit=0;
+	int tocks=0;  // used for keeping track of when a tock has happened
+	SDL_Event event;
+
+	LOG( "Entering Pause()\n" );
+
+	pause_load_media();
+	/* --- stop all sounds, play pause noise --- */
+
+	if (settings.sys_sound) {
+ 		Mix_Pause(-1);
+		Mix_PlayChannel(-1, pause_sfx, 0);
+		sfx_volume = Mix_Volume(-1, -1);  // get sfx volume w/o changing it
+		mus_volume = Mix_VolumeMusic(-1); // get mus volume w/o changing it
+	}
+
+	/* --- show the pause screen --- */
+
+	SDL_ShowCursor(1);
+
+	// Darken the screen...
+	DarkenScreen(1); 
+
+	pause_draw();
+
+	if (settings.sys_sound) {
+		draw_vols(sfx_volume, mus_volume);
+	}
+
+	SDL_Flip(screen);
+
+	SDL_EnableKeyRepeat( 1, 20 );
+
+	/* --- wait for space, click, or exit --- */
+
+	while (paused) {
+		old_sfx_volume = sfx_volume;
+		old_mus_volume = mus_volume;
+		while (SDL_PollEvent(&event)) 
+			switch (event.type) {
+				case SDL_QUIT: 
+					exit(0);
+					break;
+				case SDL_KEYUP:
+					if (settings.sys_sound && 
+					   ((event.key.keysym.sym == SDLK_RIGHT) ||
+					    (event.key.keysym.sym == SDLK_LEFT))) 
+					    	tocks = 0;
+					break;
+				case SDL_KEYDOWN:
+					if (event.key.keysym.sym == SDLK_SPACE) 
+						paused = 0;
+					if (event.key.keysym.sym == SDLK_ESCAPE) {
+						paused = 0;
+						quit = 1;
+					}
+					if (settings.sys_sound) { 
+						if (event.key.keysym.sym == SDLK_RIGHT) 
+							sfx_volume += 4;
+						if (event.key.keysym.sym == SDLK_LEFT) 
+							sfx_volume -= 4;
+						if (event.key.keysym.sym == SDLK_UP) 
+							mus_volume += 4;
+						if (event.key.keysym.sym == SDLK_DOWN) 
+							mus_volume -= 4;
+					}
+					break;
+				case SDL_MOUSEBUTTONDOWN:
+					mousePressed = 1;
+					tocks = 0;
+					break;
+				case SDL_MOUSEBUTTONUP:
+					mousePressed = 0;
+					break;
+
+					break;
+			}
+		if (settings.sys_sound && mousePressed) {
+			int x, y;
+
+			SDL_GetMouseState(&x, &y);
+			/* check to see if they clicked on a button */
+
+			if (inRect(rectUp, x, y)) {
+				mus_volume += 4;
+			} else if (inRect(rectDown, x, y)) {
+				mus_volume -= 4;
+			} else if (inRect(rectRight, x, y)) {
+				sfx_volume += 4;
+			} else if (inRect(rectLeft, x, y)) {
+				sfx_volume -= 4;
+			} else {
+
+				/* check to see if they clicked a bar */
+
+				if ((x > rectLeft.x + rectLeft.w) && (x < rectRight.x)) {
+					if ((y >= rectLeft.y) && (y <= rectLeft.y + rectLeft.h)) {
+						sfx_volume = 4+(int)(128.0 * ((x - rectLeft.x - rectLeft.w - 1.0) / (rectRight.x - rectLeft.x - rectLeft.w - 2.0)));
+					}
+					if ((y >= rectDown.y) && (y <= rectDown.y + rectDown.h)) {
+						mus_volume = 4+(int)(128.0 * ((x - rectLeft.x - rectLeft.w - 1.0) / (rectRight.x - rectLeft.x - rectLeft.w - 2.0)));
+					}
+
+				}
+			}
+		}
+
+		if (settings.sys_sound) {
+
+			if (sfx_volume > MIX_MAX_VOLUME)
+				sfx_volume = MIX_MAX_VOLUME;
+			if (sfx_volume < 0)
+				sfx_volume = 0;
+			if (mus_volume > MIX_MAX_VOLUME)
+				mus_volume = MIX_MAX_VOLUME;
+			if (mus_volume < 0)
+				mus_volume = 0;
+
+			if ((mus_volume != old_mus_volume) || 
+			    (sfx_volume != old_sfx_volume)) {
+
+				if (mus_volume != old_mus_volume)
+					Mix_VolumeMusic(mus_volume);
+
+				if (sfx_volume != old_sfx_volume) {
+					Mix_Volume(-1,sfx_volume);
+					if (tocks%4==0)
+						Mix_PlayChannel(-1, pause_sfx, 0);
+					tocks++;
+			    }
+
+				draw_vols(sfx_volume, mus_volume);
+				settings.mus_volume=mus_volume;
+				settings.sfx_volume=sfx_volume;
+				SDL_Flip(screen);
+			}
+		}
+
+		SDL_Delay(33);
+	}
+
+	/* --- Return to previous state --- */
+
+	SDL_EnableKeyRepeat( 0, SDL_DEFAULT_REPEAT_INTERVAL );
+
+	SDL_ShowCursor(0);
+
+	if (settings.sys_sound) {
+		Mix_PlayChannel(-1, pause_sfx, 0);
+		Mix_Resume(-1);
+	}
+
+	pause_unload_media();
+
+	LOG( "Leaving Pause()\n" );
+
+	return (quit);
+}
+
+
+static void pause_load_media(void) {
+	if (settings.sys_sound) 
+		pause_sfx = LoadSound( "tock.wav" );
+
+	up = LoadImage("up.png", IMG_ALPHA);
+	rectUp.w = up->w; rectUp.h = up->h;
+
+	down = LoadImage("down.png", IMG_ALPHA);
+	rectDown.w = down->w; rectDown.h = down->h;
+
+	left = LoadImage("left.png", IMG_ALPHA);
+	rectLeft.w = left->w; rectLeft.h = left->h;
+
+	right = LoadImage("right.png", IMG_ALPHA);
+	rectRight.w = right->w; rectRight.h = right->h;
+
+	f1 = LoadFont(settings.theme_font_name, 24);
+	f2 = LoadFont(settings.theme_font_name, 36);
+}
+
+static void pause_unload_media(void) {
+	if (settings.sys_sound)
+        {
+	  Mix_FreeChunk(pause_sfx);
+	  pause_sfx = NULL;
+        }
+	SDL_FreeSurface(up);
+	SDL_FreeSurface(down);
+	SDL_FreeSurface(left);
+	SDL_FreeSurface(right);
+        up = down = left = right = NULL;
+	TTF_CloseFont(f1);
+	TTF_CloseFont(f2);
+	f1 = f2 = NULL;
+}
+
+
+
+/******************************************/
+/*                                        */
+/*       Local ("private") functions      */
+/*                                        */
+/******************************************/
+
+
+
+static void pause_draw(void)
+{
+  SDL_Rect s;
+  SDL_Surface* t = NULL;
+
+  LOG("Entering pause_draw()\n");
+
+  rectLeft.y = rectRight.y = screen->h/2 - 40;
+  rectDown.y = rectUp.y = screen->h/2 + 60;
+
+  rectLeft.x = rectDown.x = screen->w/2 - (7*16) - rectLeft.w - 4;
+  rectRight.x = rectUp.x  = screen->w/2 + (7*16) + 4;
+
+  /* Avoid segfault if any needed SDL_Surfaces missing: */
+  if (settings.sys_sound
+    && left && right && down && up)
+  {
+    SDL_BlitSurface(left, NULL, screen, &rectLeft);
+    SDL_BlitSurface(right, NULL, screen, &rectRight);
+    SDL_BlitSurface(down, NULL, screen, &rectDown);
+    SDL_BlitSurface(up, NULL, screen, &rectUp);
+  }
+
+  if (settings.sys_sound)
+  {
+    t = BlackOutline(gettext("Sound Effects Volume"), f1, &white);
+    if (t)
+    {	
+      s.y = screen->h/2 - 80;
+      s.x = screen->w/2 - t->w/2;
+      SDL_BlitSurface(t, NULL, screen, &s);
+      SDL_FreeSurface(t);
+    }
+
+    t = BlackOutline(gettext("Music Volume"), f1, &white);
+    if (t)
+    {
+      s.y = screen->h/2 + 20;
+      s.x = screen->w/2 - t->w/2;
+      SDL_BlitSurface(t, NULL, screen, &s);
+      SDL_FreeSurface(t);
+    }
+  }
+  else  /* No sound: */
+  {
+    t = BlackOutline(gettext("Sound & Music Disabled"), f1, &white);
+    if (t)
+    {
+      s.y = screen->h/2 - 80;
+      s.x = screen->w/2 - t->w/2;
+      SDL_BlitSurface(t, NULL, screen, &s);
+      SDL_FreeSurface(t);
+    }
+  }
+
+  t = BlackOutline(gettext("Paused!"), f2, &white);
+  if (t)
+  {
+	s.y = screen->h/2 - 180; //60;
+	s.x = screen->w/2 - t->w/2;
+	SDL_BlitSurface(t, NULL, screen, &s);
+	SDL_FreeSurface(t);
+  }
+
+  t = BlackOutline(gettext("Press escape again to return to menu"), f1, &white);
+  if (t)
+  {
+    s.y = screen->h/2 + 160;
+    s.x = screen->w/2 - t->w/2;
+    SDL_BlitSurface(t, NULL, screen, &s);
+    SDL_FreeSurface(t);
+  }
+
+  t = BlackOutline(gettext("Press space bar to return to game"), f1, &white);
+  if (t)
+  {
+    s.y = screen->h/2 + 200;
+    s.x = screen->w/2 - t->w/2;
+    SDL_BlitSurface(t, NULL, screen, &s);
+    SDL_FreeSurface(t);
+  }
+
+  LOG("Leaving pause_draw()\n");
+}
+
+
+/* FIXME what if rectLeft and rectDown not initialized? - should be args */
+static void draw_vols(int sfx, int mus)
+{
+  SDL_Rect s,m;
+  int i;
+
+  s.y = rectLeft.y; 
+  m.y = rectDown.y;
+  m.w = s.w = 5;
+  s.x = rectLeft.x + rectLeft.w + 5;
+  m.x = rectDown.x + rectDown.w + 5;
+  m.h = s.h = 40;
+
+  for (i = 1; i<=32; i++)
+  {
+    if (sfx >= i * 4)
+      SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 127 + sfx));
+    else
+      SDL_FillRect(screen, &s, SDL_MapRGB(screen->format, 0, 0, 0));
+
+    if (mus >= i * 4)
+      SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 127 + mus));
+    else
+      SDL_FillRect(screen, &m, SDL_MapRGB(screen->format, 0, 0, 0));
+
+    m.x = s.x += 7;
+  }
+}
+
+// /* ==== fillscreen ====
+//  * RESULT: it will darken the screen by a factor of 4
+//  * WARNING: only works on 16bit screens right now!
+//  */
+// static void darkenscreen(void)
+// {
+//   Uint16 rm = screen->format->Rmask;
+//   Uint16 gm = screen->format->Gmask;
+//   Uint16 bm = screen->format->Bmask;
+//   Uint16* p; 
+//   int x, y;
+// 
+//   p = screen->pixels;
+// 
+//   for (y = 0; y < 480; y++) 
+//   {
+//     for (x = 0; x < 640; x++)
+//     {
+//       *p = (((*p&rm)>>2)&rm) | (((*p&gm)>>2)&gm) | (((*p&bm)>>2)&bm);
+//       p++;
+//     }
+//   }
+// }
+
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/phrases.txt (from rev 672, tuxtype/branches/tuxtype-soc-mh/phrases.txt)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/phrases.txt	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/phrases.txt	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1 @@
+The quick brown fox jumps over the lazy dog.

Copied: tuxtype/branches/tuxtype-soc-mh/src/pixels.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/pixels.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/pixels.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/pixels.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,257 @@
+/*
+  pixels.c
+
+  For Tux Paint
+  Pixel read/write functions
+
+  Copyright (c) 2002-2006 by Bill Kendrick and others
+  bill at newbreedsoftware.com
+  http://www.newbreedsoftware.com/tuxpaint/
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  (See COPYING.txt)
+
+  June 14, 2002 - February 17, 2006
+  $Id: pixels.c,v 1.3 2006/08/27 21:00:55 wkendrick Exp $
+*/
+
+#include "pixels.h"
+#include "compiler.h"
+//#include "debug.h"
+
+/* Draw a single pixel into the surface: */
+void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel)
+{
+  Uint8 *p;
+
+  /* Assuming the X/Y values are within the bounds of this surface... */
+  if (likely
+      (likely((unsigned) x < (unsigned) surface->w)
+       && likely((unsigned) y < (unsigned) surface->h)))
+  {
+    // Set a pointer to the exact location in memory of the pixel
+    p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start: beginning of RAM */
+                   (y * surface->pitch) +        /* Go down Y lines */
+                   x);                /* Go in X pixels */
+
+
+    /* Set the (correctly-sized) piece of data in the surface's RAM
+     *          to the pixel value sent in: */
+
+    *p = pixel;
+  }
+}
+
+/* Draw a single pixel into the surface: */
+void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel)
+{
+  Uint8 *p;
+
+  /* Assuming the X/Y values are within the bounds of this surface... */
+  if (likely
+      (likely((unsigned) x < (unsigned) surface->w)
+       && likely((unsigned) y < (unsigned) surface->h)))
+  {
+    // Set a pointer to the exact location in memory of the pixel
+    p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start: beginning of RAM */
+                   (y * surface->pitch) +        /* Go down Y lines */
+                   (x * 2));        /* Go in X pixels */
+
+
+    /* Set the (correctly-sized) piece of data in the surface's RAM
+     *          to the pixel value sent in: */
+
+    *(Uint16 *) p = pixel;
+  }
+}
+
+/* Draw a single pixel into the surface: */
+void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel)
+{
+  Uint8 *p;
+
+  /* Assuming the X/Y values are within the bounds of this surface... */
+  if (likely
+      (likely((unsigned) x < (unsigned) surface->w)
+       && likely((unsigned) y < (unsigned) surface->h)))
+  {
+    // Set a pointer to the exact location in memory of the pixel
+    p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start: beginning of RAM */
+                   (y * surface->pitch) +        /* Go down Y lines */
+                   (x * 3));        /* Go in X pixels */
+
+
+    /* Set the (correctly-sized) piece of data in the surface's RAM
+     *          to the pixel value sent in: */
+
+    if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+    {
+      p[0] = (pixel >> 16) & 0xff;
+      p[1] = (pixel >> 8) & 0xff;
+      p[2] = pixel & 0xff;
+    }
+    else
+    {
+      p[0] = pixel & 0xff;
+      p[1] = (pixel >> 8) & 0xff;
+      p[2] = (pixel >> 16) & 0xff;
+    }
+
+  }
+}
+
+/* Draw a single pixel into the surface: */
+void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel)
+{
+  Uint8 *p;
+
+  /* Assuming the X/Y values are within the bounds of this surface... */
+  if (likely
+      (likely((unsigned) x < (unsigned) surface->w)
+       && likely((unsigned) y < (unsigned) surface->h)))
+  {
+    // Set a pointer to the exact location in memory of the pixel
+    p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start: beginning of RAM */
+                   (y * surface->pitch) +        /* Go down Y lines */
+                   (x * 4));        /* Go in X pixels */
+
+
+    /* Set the (correctly-sized) piece of data in the surface's RAM
+     *          to the pixel value sent in: */
+
+    *(Uint32 *) p = pixel;        // 32-bit display
+  }
+}
+
+/* Get a pixel: */
+Uint32 getpixel8(SDL_Surface * surface, int x, int y)
+{
+  Uint8 *p;
+
+  /* get the X/Y values within the bounds of this surface */
+  if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
+    x = (x < 0) ? 0 : surface->w - 1;
+  if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
+    y = (y < 0) ? 0 : surface->h - 1;
+
+  /* Set a pointer to the exact location in memory of the pixel
+     in question: */
+
+  p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start at top of RAM */
+                 (y * surface->pitch) +        /* Go down Y lines */
+                 x);                /* Go in X pixels */
+
+
+  /* Return the correctly-sized piece of data containing the
+   * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
+   * RGB value) */
+
+  return (*p);
+}
+
+/* Get a pixel: */
+Uint32 getpixel16(SDL_Surface * surface, int x, int y)
+{
+  Uint8 *p;
+
+  /* get the X/Y values within the bounds of this surface */
+  if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
+    x = (x < 0) ? 0 : surface->w - 1;
+  if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
+    y = (y < 0) ? 0 : surface->h - 1;
+
+  /* Set a pointer to the exact location in memory of the pixel
+     in question: */
+
+  p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start at top of RAM */
+                 (y * surface->pitch) +        /* Go down Y lines */
+                 (x * 2));        /* Go in X pixels */
+
+
+  /* Return the correctly-sized piece of data containing the
+   * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
+   * RGB value) */
+
+  return (*(Uint16 *) p);
+}
+
+/* Get a pixel: */
+Uint32 getpixel24(SDL_Surface * surface, int x, int y)
+{
+  Uint8 *p;
+  Uint32 pixel;
+
+  /* get the X/Y values within the bounds of this surface */
+  if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
+    x = (x < 0) ? 0 : surface->w - 1;
+  if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
+    y = (y < 0) ? 0 : surface->h - 1;
+
+  /* Set a pointer to the exact location in memory of the pixel
+     in question: */
+
+  p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start at top of RAM */
+                 (y * surface->pitch) +        /* Go down Y lines */
+                 (x * 3));        /* Go in X pixels */
+
+
+  /* Return the correctly-sized piece of data containing the
+   * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
+   * RGB value) */
+
+  /* Depending on the byte-order, it could be stored RGB or BGR! */
+
+  if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
+    pixel = p[0] << 16 | p[1] << 8 | p[2];
+  else
+    pixel = p[0] | p[1] << 8 | p[2] << 16;
+
+  return pixel;
+}
+
+/* Get a pixel: */
+Uint32 getpixel32(SDL_Surface * surface, int x, int y)
+{
+  Uint8 *p;
+
+  /* get the X/Y values within the bounds of this surface */
+  if (unlikely((unsigned) x > (unsigned) surface->w - 1u))
+    x = (x < 0) ? 0 : surface->w - 1;
+  if (unlikely((unsigned) y > (unsigned) surface->h - 1u))
+    y = (y < 0) ? 0 : surface->h - 1;
+
+  /* Set a pointer to the exact location in memory of the pixel
+     in question: */
+
+  p = (Uint8 *) (((Uint8 *) surface->pixels) +        /* Start at top of RAM */
+                 (y * surface->pitch) +        /* Go down Y lines */
+                 (x * 4));        /* Go in X pixels */
+
+
+  /* Return the correctly-sized piece of data containing the
+   * pixel's value (an 8-bit palette value, or a 16-, 24- or 32-bit
+   * RGB value) */
+
+  return *(Uint32 *) p;                // 32-bit display
+}
+
+void (*putpixels[]) (SDL_Surface *, int, int, Uint32) =
+{
+putpixel8, putpixel8, putpixel16, putpixel24, putpixel32};
+
+
+Uint32(*getpixels[])(SDL_Surface *, int, int) =
+{
+getpixel8, getpixel8, getpixel16, getpixel24, getpixel32};

Copied: tuxtype/branches/tuxtype-soc-mh/src/pixels.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/pixels.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/pixels.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/pixels.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,49 @@
+/*
+  pixels.h
+
+  For Tux Paint
+  Pixel read/write functions
+
+  Copyright (c) 2002-2006 by Bill Kendrick and others
+  bill at newbreedsoftware.com
+  http://www.newbreedsoftware.com/tuxpaint/
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+  (See COPYING.txt)
+
+  June 14, 2002 - February 17, 2006
+  $Id: pixels.h,v 1.2 2006/08/27 21:00:55 wkendrick Exp $
+*/
+
+#ifndef PIXELS_H
+#define PIXELS_H
+
+#include "SDL.h"
+
+void putpixel8(SDL_Surface * surface, int x, int y, Uint32 pixel);
+void putpixel16(SDL_Surface * surface, int x, int y, Uint32 pixel);
+void putpixel24(SDL_Surface * surface, int x, int y, Uint32 pixel);
+void putpixel32(SDL_Surface * surface, int x, int y, Uint32 pixel);
+
+extern void (*putpixels[]) (SDL_Surface *, int, int, Uint32);
+
+Uint32 getpixel8(SDL_Surface * surface, int x, int y);
+Uint32 getpixel16(SDL_Surface * surface, int x, int y);
+Uint32 getpixel24(SDL_Surface * surface, int x, int y);
+Uint32 getpixel32(SDL_Surface * surface, int x, int y);
+
+extern Uint32(*getpixels[]) (SDL_Surface *, int, int);
+
+#endif

Copied: tuxtype/branches/tuxtype-soc-mh/src/playgame.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/playgame.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/playgame.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/playgame.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,1808 @@
+/***************************************************************************
+playgame.c 
+-  description: Cascade game
+-------------------
+begin                : Fri May 5 2000
+copyright            : (C) 2000 by Sam Hart
+                     : (C) 2003 by Jesse Andrews
+email                : tuxtype-dev at tux4kids.net
+***************************************************************************/
+
+/***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+#include "playgame.h"
+#include "snow.h"
+#include "SDL_extras.h"
+
+#define _(String) gettext(String)
+
+//void add_words( int level );
+
+/* Should these be constants? */
+static int tux_max_width;                // the max width of the images of tux
+static int number_max_w;                 // the max width of a number image
+
+//int o_lives; // something cal is working on
+//int sound_vol;
+static TTF_Font* font = NULL;
+//static SDL_Surface* background = NULL;
+static SDL_Surface* level[NUM_LEVELS] = {NULL};
+static SDL_Surface* number[NUM_NUMS] = {NULL};
+static SDL_Surface* curlev = NULL;
+static SDL_Surface* lives = NULL;
+static SDL_Surface* fish = NULL;
+static SDL_Surface* congrats[CONGRATS_FRAMES] = {NULL};
+static SDL_Surface* ohno[OH_NO_FRAMES] = {NULL};
+static Mix_Chunk* sound[NUM_WAVES];
+
+static sprite* fishy = NULL;
+static sprite* splat = NULL;
+
+/* --- Data Structure for Dirty Blitting --- */
+static SDL_Rect srcupdate[MAX_UPDATES];
+static SDL_Rect dstupdate[MAX_UPDATES];
+static int numupdates = 0; // tracks how many blits to be done
+
+struct blit {
+    SDL_Surface* src;
+    SDL_Rect* srcrect;
+    SDL_Rect* dstrect;
+    unsigned char type;
+} blits[MAX_UPDATES];
+
+
+
+/* Local function prototypes: */
+static int AddRect(SDL_Rect* src, SDL_Rect* dst);
+static void AddSplat(int* splats, struct fishypoo* f, int* curlives, int* frame);
+static void CheckCollision(int fishies, int* fish_left, int frame );
+static void CheckFishies(int* fishies, int* splats);
+static int check_word(int f);
+static void display_msg(const unsigned char* msg, int x, int y);
+static void DrawBackground(void);
+static void draw_bar(int curlevel, int diflevel, int curlives,
+                     int oldlives, int fish_left, int oldfish_left);
+static void DrawFish(int which);
+static void DrawNumbers(int num, int x, int y, int places);
+static int DrawObject(SDL_Surface* surf, int x, int y);
+static int DrawSprite(sprite* gfx, int x, int y);
+static void EraseNumbers(int num, int x, int y, int places);
+static int EraseObject(SDL_Surface* surf, int x, int y);
+static int EraseSprite(sprite* img, int x, int y);
+static float float_restrict(float a, float x, float b);
+static void FreeGame(void);
+static int int_restrict(int a, int x, int b);
+static void LoadFishies(void);
+static void LoadOthers(void);
+static void LoadTuxAnims(void);
+static void MoveFishies(int* fishies, int* splats, int* lifes, int* frame);
+static void MoveTux(int frame, int fishies);
+static void next_tux_frame(void);
+static void ResetObjects(void);
+static void SpawnFishies(int diflevel, int* fishies, int* frame);
+static void UpdateScreen(int* frame);
+static void UpdateTux(wchar_t letter_pressed, int fishies, int frame);
+static void WaitFrame(void);
+
+
+
+/************************************************************************/
+/*                                                                      */ 
+/*         "Public" functions (callable throughout program)             */
+/*                                                                      */
+/************************************************************************/
+
+/*************************************************************************
+* PlayCascade : This is the main Cascade game loop               *
+*************************************************************************/
+int PlayCascade(int diflevel)
+{
+  unsigned char filename[FNLEN];
+  int still_playing = 1;
+  int playing_level = 1;
+  int setup_new_level = 1;
+  int won_level = 0;
+  int quitting = 0;
+  int curlevel = 0;
+  int i;
+  int curlives;
+  int oldlives = 0;
+  int oldfish_left = 0;
+  int fish_left;
+  int fishies = 0;
+  int local_max_fishies = 1;
+  int frame = 0;
+  int done_frames;
+  int splats = 0;
+  SDL_Event event;
+  SDL_Surface *temp_text[CONGRATS_FRAMES + OH_NO_FRAMES];
+  SDL_Rect text_rect;
+  int text_y_end;
+  int xamp;
+  int yamp;
+  int x_not;
+  int y_not;
+  int temp_text_frames;
+  int temp_text_count;
+  Uint16 key_unicode;
+
+  DEBUGCODE
+  {
+    fprintf(stderr, "->Entering PlayCascade(): level=%i\n", diflevel);
+  }
+
+  SDL_WarpMouse(screen->w / 2, screen->h / 2);
+  SDL_ShowCursor(0);
+
+//	SNOW_init();
+
+  LoadTuxAnims(); 
+  LoadFishies();
+  LoadOthers();
+  RenderLetters(font);
+  LOG( " Done rendering letters \n ");
+
+  /* Make sure everything in the word list is "typable" according to the current */
+  /* theme's keyboard.lst:                                                       */
+  if (!CheckNeededGlyphs())
+  {
+    fprintf(stderr, "PlayCascade() - did not find all needed characters in theme's "
+                    "keyboard.lst file - returning to menu!\n\n\n");
+    FreeGame();
+    return 0;
+  }
+
+
+  /*  --------- Begin outer game loop (cycles once per level): ------------- */
+
+  LOG( " starting game \n ");
+
+  while (still_playing)
+  {
+    /* FIXME split out as smaller function */
+    if (setup_new_level) 
+    {
+      switch (diflevel)
+      {
+        default:
+        case EASY:
+          fish_left = MAX_FISHIES_EASY;
+
+          if (settings.o_lives >  LIVES_INIT_EASY)
+            curlives = settings.o_lives;
+          else
+            curlives = LIVES_INIT_EASY;
+          break;
+
+        case MEDIUM:
+          fish_left = MAX_FISHIES_MEDIUM;
+
+          if (settings.o_lives >  LIVES_INIT_MEDIUM)
+            curlives = settings.o_lives;
+          else
+            curlives =  LIVES_INIT_MEDIUM;
+          break;
+
+        case HARD:
+          fish_left = MAX_FISHIES_HARD;
+
+          if (settings.o_lives >  LIVES_INIT_HARD)
+            curlives = settings.o_lives;
+          else
+            curlives =  LIVES_INIT_HARD;
+          break;
+      }
+
+      local_max_fishies = fish_left;
+
+      /* ------- Load and draw background: ----------------- */
+
+      if (curlevel != 0)
+      {
+        FreeBothBkgds();
+        //SDL_FreeSurface(background);
+      }
+
+      if (diflevel == INF_PRACT)
+        sprintf(filename, "pract.png");
+      else
+        sprintf(filename, "kcas%i_%i.jpg", diflevel+1, curlevel+1);
+
+      /* ---  Special Hidden Code  --- */
+
+      if (settings.hidden && curlevel == 3)
+        sprintf(filename, "hidden.jpg");
+
+      DEBUGCODE
+      {
+        fprintf(stderr, "->>Loading background: %s\n", filename);
+      }
+        LoadBothBkgds(filename);
+//      background = LoadImage( filename, IMG_REGULAR );
+//			SNOW_setBkg( background );
+
+      DrawBackground();
+
+      ResetObjects();
+
+      if (settings.sys_sound)
+      {
+        sprintf(filename, "kmus%i.wav", curlevel + 1);
+        MusicLoad( filename, -1 );
+      }
+
+      setup_new_level = 0;
+
+      LOG( "->>PLAYING THE GAME\n" );
+
+    }
+
+    /*  --------- Begin main game loop (cycles once per frame): ------------- */
+
+
+    while (playing_level)
+    {
+      oldlives = curlives;
+      oldfish_left = fish_left;
+
+      EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
+
+      /* --- Poll input queue, get keyboard info --- */
+      while (SDL_PollEvent(&event))
+      {
+        if ( event.type == SDL_QUIT )
+        {
+          exit(0); /* FIXME does memory get cleaned up properly if we do this? */
+        }
+        else
+        {
+          if (event.type == SDL_KEYDOWN)
+          {
+            if (event.key.keysym.sym == SDLK_F11) 
+              SDL_SaveBMP(screen, "screenshot.bmp");
+
+            if (event.key.keysym.sym == SDLK_F6)
+            {
+              settings.o_lives = settings.o_lives - 10;
+              curlives = curlives - 10;
+            }
+
+            if (event.key.keysym.sym == SDLK_F7)
+            {
+              settings.o_lives = settings.o_lives + 10;
+              curlives = curlives + 10;
+            }
+
+            if (event.key.keysym.sym == SDLK_F10)
+              SwitchScreenMode();
+
+            if (event.key.keysym.sym == SDLK_F12)
+            {
+//              SNOW_toggle();
+            }
+
+            if (event.key.keysym.sym == SDLK_ESCAPE)
+            {
+              /* Pause() returns 1 if quitting, */
+              /* 0 if returning to game:        */
+              if (Pause() == 1)
+              {
+                playing_level = 0;
+                still_playing = 0;
+                quitting = 1;
+              }
+              else  /* Returning to game */
+                DrawBackground();
+            }
+
+            /*----------------------------------------------------*/
+            /* Some other key - player is actually typing!!!!!!!! */
+            /*----------------------------------------------------*/
+
+            /* See what Unicode value was typed: */
+            key_unicode = event.key.keysym.unicode;
+
+            DEBUGCODE
+            {
+              fprintf(stderr,
+                      "\nkey_unicode = %d\twchar_t = %lc\t\n",
+                      key_unicode, key_unicode);
+            }
+
+            /* For now, the cascade game is case-insensitive for input, */
+            /* with only uppercase for answers:                         */
+            if (key_unicode >= 97 && key_unicode <= 122)
+              key_unicode -= 32;  //convert lowercase to uppercase
+            if (key_unicode >= 224 && key_unicode <= 255)
+              key_unicode -= 32; //same for non-US chars
+
+            LOG ("After checking for lower case:\n");
+            DEBUGCODE
+            {
+              fprintf(stderr,
+                      "key_unicode = %d\twchar_t = %lc\\n\n",
+                      key_unicode, key_unicode);
+            }
+
+            /* Now update with case-folded value: */
+            UpdateTux(key_unicode, fishies, frame);
+          }
+        }
+      }   /* ------ End of 'while' loop for handling user input ------- */
+
+
+
+      /* --- fishy updates --- */
+      if ((frame % 10) == 0)
+        NEXT_FRAME(fishy);
+
+      if (fishies < local_max_fishies)
+        SpawnFishies( diflevel, &fishies, &frame );
+
+      MoveTux(frame, fishies);
+      CheckCollision(fishies, &fish_left, frame);
+      DrawSprite(tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y);
+      MoveFishies(&fishies, &splats, &curlives, &frame);
+      CheckFishies(&fishies, &splats);
+//      SNOW_update();
+
+      /* --- update top score/info bar --- */
+
+      if (diflevel != INF_PRACT)
+      {
+        draw_bar(curlevel, diflevel, curlives, oldlives, fish_left, oldfish_left);
+
+        if (curlives <= 0)
+        {
+          playing_level = 0;
+          still_playing = 0;
+        }
+      }
+      else
+        fish_left = 1; // in practice there is always 1 fish left!
+
+      if (fish_left <= 0)
+      {
+        won_level = 1;
+        playing_level = 0;
+        curlevel++;
+        setup_new_level = 1;
+        still_playing = 1;
+      }
+
+      if (!quitting) 
+      {
+        /* This does all the blits that we have queued up this frame: */
+        UpdateScreen(&frame);
+
+        if (!settings.speed_up)
+          WaitFrame();
+      }
+    }  /* End per-frame game loop - level completed */
+
+
+    if (settings.sys_sound)
+      Mix_FadeOutMusic(MUSIC_FADE_OUT_MS);
+
+    DrawBackground();
+
+    /* Victory sequence, defeat sequence, or go to next level: */
+    if (quitting == 0)
+    {
+      /* Level completed successfully: */
+      if (won_level) 
+      {
+        if (curlevel < 4)  /* Advance to next level */
+        {
+          LOG( "--->NEXT LEVEL!\n" );
+          done_frames = MAX_END_FRAMES_BETWEEN_LEVELS;
+          playing_level = 1;
+          xamp = 0;
+          yamp = 0;
+          won_level = 0;
+        }
+        else
+        {
+          LOG( "--->WINNER!\n" );
+          done_frames = MAX_END_FRAMES_WIN_GAME;
+          still_playing = 0;
+          xamp = WIN_GAME_XAMP;
+          yamp = WIN_GAME_YAMP;
+
+          if (settings.sys_sound) 
+            Mix_PlayChannel(WINFINAL_WAV, sound[WINFINAL_WAV], 0);
+        }
+
+        if (settings.sys_sound) 
+          Mix_PlayChannel(WIN_WAV, sound[WIN_WAV], 0);
+
+        for (i = 0; i < CONGRATS_FRAMES; i++)
+          temp_text[i] = congrats[i];
+
+        temp_text_frames = CONGRATS_FRAMES;
+        tux_object.state = TUX_WINNING;
+
+      }
+      else  /* Did not win the level  :-(     */
+      {
+        LOG( "--->LOST :(\n" );
+        done_frames = MAX_END_FRAMES_GAMEOVER;
+        xamp = 0;
+        yamp = 0;
+
+        if (settings.sys_sound)
+          Mix_PlayChannel(LOSE_WAV, sound[LOSE_WAV], 0);
+
+        for (i = 0; i < OH_NO_FRAMES; i++)
+          temp_text[i] = ohno[i];
+
+        temp_text_frames = OH_NO_FRAMES;
+        tux_object.state = TUX_YIPING;
+      }
+
+      /* --- draw the animation here --- */
+
+      temp_text_count = 0;
+      text_y_end = (screen->h / 2) - (temp_text[0]->h / 2);
+      text_rect.x = (screen->w / 2) - (temp_text[0]->w / 2);
+      text_rect.y = screen->h - temp_text[0]->h - 1;
+      x_not = text_rect.x;
+
+      LOG( "--->Starting Ending Animation\n" );
+
+      for ( i=0; i<= done_frames; i++ ) 
+      {
+        temp_text_count = (temp_text_count+1) % temp_text_frames;
+
+        text_rect.y -= END_FRAME_DY;
+        y_not = text_rect.y;
+
+        if (text_rect.y < text_y_end)
+        {
+          y_not = text_y_end + yamp * sin(i / WIN_GAME_ANGLE_MULT);
+          text_rect.y = text_y_end;
+          text_rect.x = x_not + xamp * cos(i / WIN_GAME_ANGLE_MULT);
+        }
+
+        DrawSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
+        DrawObject(temp_text[temp_text_count], text_rect.x, y_not);
+        DrawObject(level[diflevel], 1, 1);
+        draw_bar(curlevel - 1, diflevel, curlives, oldlives, fish_left, oldfish_left);
+
+        next_tux_frame();
+//        SNOW_update();
+        /* Do all pending blits and increment frame counter: */
+        UpdateScreen(&frame);
+
+        EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
+        EraseObject(temp_text[temp_text_count], text_rect.x, y_not);
+
+        if (!settings.speed_up)
+          WaitFrame();
+      }  /* End of animation for end of game */
+
+    }  /* End of post-level wrap-up  */
+
+  }  /*   -------- End outer game loop -------------- */
+
+//  SNOW_on = 0;
+
+  LOG( "->Done with level... cleaning up\n" );
+
+  FreeGame();
+
+  LOG( "->PlayCascade(): END\n" );
+
+  return 1;
+}
+
+
+
+
+/***********************
+ InitEngine
+ ***********************/
+void InitEngine(void) {
+    int i;
+
+    /* --- Set up the update rectangle pointers --- */
+	
+    for (i = 0; i < MAX_UPDATES; ++i) {
+        blits[i].srcrect = &srcupdate[i];
+        blits[i].dstrect = &dstupdate[i];
+    }
+}
+
+
+
+/*************************************************/
+/* TransWipe: Performs various wipes to new bkgs */
+/*************************************************/
+/*
+ * Given a wipe request type, and any variables
+ * that wipe requires, will perform a wipe from
+ * the current screen image to a new one.
+ */
+int TransWipe(SDL_Surface* newbkg, int type, int var1, int var2)
+{
+    int i, j, x1, x2, y1, y2;
+    int step1, step2, step3, step4;
+    int frame;
+    SDL_Rect src;
+    SDL_Rect dst;
+
+    LOG("->TransWipe(): START\n");
+
+    if (!newbkg)
+    {
+      fprintf(stderr, "TransWipe() - 'newbkg' arg invalid!\n");
+      return 0;
+    }
+
+    numupdates = 0;
+    frame = 0;
+
+    if(newbkg->w == screen->w && newbkg->h == screen->h) {
+        if( type == RANDOM_WIPE )
+            type = (RANDOM_WIPE * ((float) rand()) / (RAND_MAX+1.0));
+
+        switch( type ) {
+            case WIPE_BLINDS_VERT: {
+                LOG("--+ Doing 'WIPE_BLINDS_VERT'\n");
+                /* var1 is num of divisions
+                   var2 is how many frames animation should take */
+                if( var1 < 1 ) var1 = 1;
+                if( var2 < 1 ) var2 = 1;
+                step1 = screen->w / var1;
+                step2 = step1 / var2;
+
+                for(i = 0; i <= var2; i++) {
+                    for(j = 0; j <= var1; j++) {
+                        x1 = step1 * (j - 0.5) - i * step2 + 1;
+                        x2 = step1 * (j - 0.5) + i * step2 + 1;
+                        src.x = x1;
+                        src.y = 0;
+                        src.w = step2;
+                        src.h = screen->h;
+                        dst.x = x2;
+                        dst.y = 0;
+                        dst.w = step2;
+                        dst.h = screen->h;
+                        SDL_BlitSurface(newbkg, &src, screen, &src);
+                        SDL_BlitSurface(newbkg, &dst, screen, &dst);
+                        AddRect(&src, &src);
+                        AddRect(&dst, &dst);
+                    }
+                    UpdateScreen(&frame);
+                }
+
+                src.x = 0;
+                src.y = 0;
+                src.w = screen->w;
+                src.h = screen->h;
+                SDL_BlitSurface(newbkg, NULL, screen, &src);
+                SDL_Flip(screen);
+
+                break;
+            } case WIPE_BLINDS_HORIZ: {
+                LOG("--+ Doing 'WIPE_BLINDS_HORIZ'\n");
+                /* var1 is num of divisions
+                   var2 is how many frames animation should take */
+                if( var1 < 1 ) var1 = 1;
+                if( var2 < 1 ) var2 = 1;
+                step1 = screen->h / var1;
+                step2 = step1 / var2;
+
+                for(i = 0; i <= var2; i++) {
+                    for(j = 0; j <= var1; j++) {
+                        y1 = step1 * (j - 0.5) - i * step2 + 1;
+                        y2 = step1 * (j - 0.5) + i * step2 + 1;
+                        src.x = 0;
+                        src.y = y1;
+                        src.w = screen->w;
+                        src.h = step2;
+                        dst.x = 0;
+                        dst.y = y2;
+                        dst.w = screen->w;
+                        dst.h = step2;
+                        SDL_BlitSurface(newbkg, &src, screen, &src);
+                        SDL_BlitSurface(newbkg, &dst, screen, &dst);
+                        AddRect(&src, &src);
+                        AddRect(&dst, &dst);
+                    }
+                    UpdateScreen(&frame);
+                }
+
+                src.x = 0;
+                src.y = 0;
+                src.w = screen->w;
+                src.h = screen->h;
+                SDL_BlitSurface(newbkg, NULL, screen, &src);
+                SDL_Flip(screen);
+
+                break;
+            } case WIPE_BLINDS_BOX: {
+                LOG("--+ Doing 'WIPE_BLINDS_BOX'\n");
+                /* var1 is num of divisions
+                   var2 is how many frames animation should take */
+                if( var1 < 1 ) var1 = 1;
+                if( var2 < 1 ) var2 = 1;
+                step1 = screen->w / var1;
+                step2 = step1 / var2;
+                step3 = screen->h / var1;
+                step4 = step1 / var2;
+
+                for(i = 0; i <= var2; i++) {
+                    for(j = 0; j <= var1; j++) {
+                        x1 = step1 * (j - 0.5) - i * step2 + 1;
+                        x2 = step1 * (j - 0.5) + i * step2 + 1;
+                        src.x = x1;
+                        src.y = 0;
+                        src.w = step2;
+                        src.h = screen->h;
+                        dst.x = x2;
+                        dst.y = 0;
+                        dst.w = step2;
+                        dst.h = screen->h;
+                        SDL_BlitSurface(newbkg, &src, screen, &src);
+                        SDL_BlitSurface(newbkg, &dst, screen, &dst);
+                        AddRect(&src, &src);
+                        AddRect(&dst, &dst);
+                        y1 = step3 * (j - 0.5) - i * step4 + 1;
+                        y2 = step3 * (j - 0.5) + i * step4 + 1;
+                        src.x = 0;
+                        src.y = y1;
+                        src.w = screen->w;
+                        src.h = step4;
+                        dst.x = 0;
+                        dst.y = y2;
+                        dst.w = screen->w;
+                        dst.h = step4;
+                        SDL_BlitSurface(newbkg, &src, screen, &src);
+                        SDL_BlitSurface(newbkg, &dst, screen, &dst);
+                        AddRect(&src, &src);
+                        AddRect(&dst, &dst);
+                    }
+                    UpdateScreen(&frame);
+                }
+
+                src.x = 0;
+                src.y = 0;
+                src.w = screen->w;
+                src.h = screen->h;
+                SDL_BlitSurface(newbkg, NULL, screen, &src);
+                SDL_Flip(screen);
+
+                break;
+            } default:
+                break;
+        }
+    }
+    return 1;
+}
+
+
+
+/************************************************************************/
+/*                                                                      */ 
+/*         "Private" functions (local to playgame.c)                    */
+/*                                                                      */
+/************************************************************************/
+
+
+
+static int check_word( int f ) {
+	int i;
+
+	if (wcslen(fish_object[f].word) > tux_object.wordlen) 
+		return 0;
+
+	for (i=0; i < wcslen(fish_object[f].word); i++) 
+		if (fish_object[f].word[i] != tux_object.word[tux_object.wordlen -                                           wcslen(fish_object[f].word) + i])
+			return 0;
+
+	return 1;
+}
+
+
+
+
+
+
+
+
+
+
+/***************************************
+	WaitFrame: wait for the next frame
+***************************************/
+void WaitFrame(void) {
+	static Uint32  next_tick = 0;
+	Uint32         this_tick = SDL_GetTicks();
+
+	if (this_tick < next_tick)
+		SDL_Delay(next_tick - this_tick);
+
+	next_tick = this_tick + (1000 / FRAMES_PER_SEC);
+}
+
+
+/****************************************************
+ ResetObjects : Clear and reset all objects to dead
+****************************************************/
+
+static void ResetObjects(void)
+{
+  int i;
+
+  LOG("RESETTING OBJECTS\n");
+
+  for (i = 0; i < MAX_FISHIES_HARD + 1; i++)
+  {
+    fish_object[i] = null_fishy;
+    splat_object[i] = null_splat;
+  }
+
+  tux_object.facing = RIGHT;
+  tux_object.x = screen->w/2;
+  tux_object.y = screen->h - tux_object.spr[0][RIGHT]->frame[0]->h - 1;
+  tux_object.dx = 0;
+  tux_object.dy = 0;
+  tux_object.endx = tux_object.x;
+  tux_object.endy = tux_object.y;
+  tux_object.state = TUX_STANDING;
+  tux_object.word[0] = 0;
+  tux_object.wordlen = 0;
+
+  LOG( "OBJECTS RESET\n" );
+}
+
+
+static int DrawSprite(sprite* gfx, int x, int y)
+{
+  struct blit* update;
+
+  if (!gfx)
+  {
+    fprintf(stderr, "DrawSprite() - 'gfx' arg invalid!\n");
+    return 0;
+  }
+
+  update = &blits[numupdates++];
+
+  if(!update || !update->srcrect || !update->dstrect)
+  {
+    fprintf(stderr, "DrawSprite() - 'update' ptr invalid!\n");
+    return 0;
+  }
+
+  update->src = gfx->frame[gfx->cur];
+  update->srcrect->x = 0;
+  update->srcrect->y = 0;
+  update->srcrect->w = gfx->frame[gfx->cur]->w;
+  update->srcrect->h = gfx->frame[gfx->cur]->h;
+  update->dstrect->x = x;
+  update->dstrect->y = y;
+  update->dstrect->w = gfx->frame[gfx->cur]->w;
+  update->dstrect->h = gfx->frame[gfx->cur]->h;
+  update->type = 'D';
+
+  return 1;
+}
+
+/**********************
+DrawObject : Draw an object at the specified
+location. No respect to clipping!
+*************************/
+static int DrawObject(SDL_Surface* surf, int x, int y)
+{
+  struct blit *update;
+
+  if (!surf)
+  {
+    fprintf(stderr, "DrawObject() - invalid 'surf' arg!\n");
+    return 0;
+  }
+
+  update = &blits[numupdates++];
+
+  if(!update || !update->srcrect || !update->dstrect)
+  {
+    fprintf(stderr, "DrawObject() - 'update' ptr invalid!\n");
+    return 0;
+  }
+
+  update->src = surf;
+  update->srcrect->x = 0;
+  update->srcrect->y = 0;
+  update->srcrect->w = surf->w;
+  update->srcrect->h = surf->h;
+  update->dstrect->x = x;
+  update->dstrect->y = y;
+  update->dstrect->w = surf->w;
+  update->dstrect->h = surf->h;
+  update->type = 'D';
+
+  return 1;
+}
+
+/************************
+UpdateScreen : Update the screen and increment the frame num
+***************************/
+static void UpdateScreen(int* frame)
+{
+  int i;
+
+  LOG("Entering UpdateScreen()\n");
+
+  /* -- First erase everything we need to -- */
+  for (i = 0; i < numupdates; i++)
+  {
+    if (blits[i].type == 'E') 
+      SDL_LowerBlit(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
+  }
+
+  LOG("Done erasing\n");
+
+//  SNOW_erase();
+
+  /* -- then draw -- */ 
+  for (i = 0; i < numupdates; i++)
+  {
+    if (blits[i].type == 'D') 
+      SDL_BlitSurface(blits[i].src, blits[i].srcrect, screen, blits[i].dstrect);
+  }
+
+  LOG("Done drawing\n");
+
+//  SNOW_draw();
+
+  /* -- update the screen only where we need to! -- */
+//  if (SNOW_on) 
+//    SDL_UpdateRects(screen, SNOW_add( (SDL_Rect*)&dstupdate, numupdates ), SNOW_rects);
+//  else 
+//    SDL_UpdateRects(screen, numupdates, dstupdate);
+
+  /* try something simpler for now: */
+  SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+  numupdates = 0;
+  *frame = *frame + 1;
+
+  LOG("Leaving UpdateScreen()\n");
+}
+
+
+/* basically puts in an order to overdraw sprite with corresponding */
+/* rect of bkgd img                                                 */
+static int EraseSprite(sprite* img, int x, int y)
+{
+  struct blit* update;
+
+  if( !img 
+   || img->cur < 0
+   || img->cur > MAX_SPRITE_FRAMES
+   || !img->frame[img->cur])
+  {
+    fprintf(stderr, "EraseSprite() - invalid 'img' arg!\n");
+    return 0;
+  }
+
+  return EraseObject(img->frame[img->cur], x, y);
+}
+
+
+
+/*************************
+EraseObject : Erase an object from the screen
+**************************/
+static int EraseObject(SDL_Surface* surf, int x, int y)
+{
+  struct blit *update;
+
+  if(!surf)
+  {
+    fprintf(stderr, "EraseObject() - invalid 'surf' arg!\n");
+    return 0;
+  }
+
+  update = &blits[numupdates++];
+
+  if(!update || !update->srcrect || !update->dstrect)
+  {
+    fprintf(stderr, "EraseObject() - 'update' ptr invalid!\n");
+    return 0;
+  }
+
+  update->src = CurrentBkgd();
+//  update->src = background;
+  update->srcrect->x = x;
+  update->srcrect->y = y;
+  update->srcrect->w = surf->w;
+  update->srcrect->h = surf->h;
+
+  /* (reduce width or height of srcrect so it doesn't go past bkgd) */
+  if (update->srcrect->x + update->srcrect->w > CurrentBkgd()->w)
+    update->srcrect->w = CurrentBkgd()->w - update->srcrect->x;
+  if (update->srcrect->y + update->srcrect->h > CurrentBkgd()->h)
+    update->srcrect->h = CurrentBkgd()->h - update->srcrect->y;
+
+
+  update->dstrect->x = x;
+  update->dstrect->y = y;
+  update->dstrect->w = update->srcrect->w;
+  update->dstrect->h = update->srcrect->h; 
+  update->type = 'E';
+
+  return 1;
+}
+
+
+/******************************
+AddRect : Dont actually blit a surface,
+    but add a rect to be updated next
+    update
+*******************************/
+static int AddRect(SDL_Rect* src, SDL_Rect* dst)
+{
+
+  /*borrowed from SL's alien (and modified)*/
+  struct blit* update;
+
+  if(!src)
+  {
+    fprintf(stderr, "AddRect() - invalid 'src' arg!\n");
+    return 0;
+  }
+
+  if(!dst)
+  {
+    fprintf(stderr, "AddRect() - invalid 'dst' arg!\n");
+    return 0;
+  }
+
+  update = &blits[numupdates++];
+
+  if(!update || !update->srcrect || !update->dstrect)
+  {
+    fprintf(stderr, "AddRect() - 'update' ptr invalid!\n");
+    return 0;
+  }
+
+  update->srcrect->x = src->x;
+  update->srcrect->y = src->y;
+  update->srcrect->w = src->w;
+  update->srcrect->h = src->h;
+  update->dstrect->x = dst->x;
+  update->dstrect->y = dst->y;
+  update->dstrect->w = dst->w;
+  update->dstrect->h = dst->h;
+  update->type = 'I';
+
+  return 1;
+}
+
+/*********************
+LoadOthers : Load all other graphics
+**********************/
+static void LoadOthers(void)
+{
+	int i;
+	unsigned char filename[FNLEN];
+
+	LOG( "=LoadOthers()\n" );
+	DEBUGCODE
+	{
+	  fprintf(stderr, "settings.theme_font_name is %s\n",
+                  settings.theme_font_name);
+	}
+	font = LoadFont(settings.theme_font_name, GAME_FONT_SIZE);
+
+	curlev = BlackOutline(gettext("Level"), font, &white);
+	lives  = BlackOutline(gettext("Lives"), font, &white);
+	fish   = BlackOutline(gettext("Fish"), font, &white);
+
+	level[0] = BlackOutline(gettext("Easy"), font, &white);
+	level[1] = BlackOutline(gettext("Medium"), font, &white);
+	level[2] = BlackOutline(gettext("Hard"), font, &white);
+	level[3] = BlackOutline(gettext("Practice"), font, &white);
+
+	number_max_w = 0;
+	for (i = 0; i < NUM_NUMS; i++) {
+		sprintf(filename, "num_%i.png", i);
+		number[i] = LoadImage( filename, IMG_COLORKEY );
+		if (number[i]->w > number_max_w)
+			number_max_w = number[i]->w;
+	}
+
+	for (i = 0; i < CONGRATS_FRAMES; i++) {
+		congrats[i] = BlackOutline(gettext("Congratulations"), font, &white);
+	}
+
+	for (i = 0; i < OH_NO_FRAMES; i++) {
+		ohno[i] = BlackOutline(gettext("Oh No!"), font, &white);
+	}
+	
+	if (settings.sys_sound) {
+		LOG( "=Loading Sound FX\n" );
+
+		sound[WIN_WAV] = LoadSound( "win.wav" );
+		sound[WINFINAL_WAV] = LoadSound( "winfinal.wav" );
+		sound[BITE_WAV] = LoadSound( "bite.wav" );
+		sound[LOSE_WAV] = LoadSound( "lose.wav" );
+		sound[RUN_WAV] = LoadSound( "run.wav" );
+		sound[SPLAT_WAV] = LoadSound( "splat.wav" );
+		sound[EXCUSEME_WAV] = LoadSound( "excuseme.wav" );
+
+		LOG( "=Done Loading Sound FX\n" );
+	} else 
+		LOG( "=NO SOUND FX LOADED (not selected)\n" );
+
+//	PauseLoadMedia();
+
+	LOG( "=Setting NULL fish & splat & word\n" );
+
+	null_fishy.alive = 0;
+	null_fishy.can_eat = 0;
+	null_fishy.word = NULL;
+	null_fishy.x = 0;
+	null_fishy.y = 0;
+	null_fishy.dy = 0;
+
+	null_splat.x = 0;
+	null_splat.y = 0;
+	null_splat.alive = 0;
+
+	LOG( "=LoadOthers() END\n" );
+}
+
+static void display_msg(const unsigned char* msg, int x, int y)
+{
+	SDL_Surface* m;
+	m = TTF_RenderUTF8_Shaded(font, msg, white, white);
+	EraseObject(m, x, y);
+	DrawObject(m, x, y);
+	SDL_FreeSurface(m);
+}
+
+/***************************
+LoadFishies : Load the fish animations and graphics
+*****************************/
+static void LoadFishies(void)
+{
+	int i;
+
+	LOG( "=LoadFishies()\n" );
+
+	fishy = LoadSprite( "fishy", IMG_COLORKEY );
+	splat = LoadSprite( "splat", IMG_COLORKEY );
+
+	for (i = 0; i < MAX_FISHIES_HARD; i++) {
+		fish_object[i].alive = 1;
+		fish_object[i].can_eat = 0;
+		splat_object[i].alive = 0;
+	}
+
+	LOG( "=LoadFishies(): END\n" );
+}
+
+/******************************
+LoadTuxAnims : Load the Tux graphics and animations
+*******************************/
+static void LoadTuxAnims(void)
+{
+	int i;
+	int height = 0;                //temp width/height varis to determine max's
+
+	LOG( "=LoadTuxAnims(): Loading Tux Animations\n" );
+
+	for ( i=0; i < TUX_NUM_STATES; i++ ) {
+		tux_object.spr[i][RIGHT] = LoadSprite( tux_sprite_fns[i], IMG_COLORKEY ); 
+		tux_object.spr[i][LEFT] = FlipSprite( tux_object.spr[i][RIGHT], 1, 0 ); 
+	}
+
+	tux_max_width = tux_object.spr[TUX_STANDING][RIGHT]->frame[0]->w;
+	height        = tux_object.spr[TUX_STANDING][RIGHT]->frame[0]->h;
+
+	LOG( "=LoadTuxAnims(): END\n" );
+}
+
+/******************************
+DrawNumbers : Draw numbers at
+a certain x,y. See "usage"
+below
+*******************************/
+static void DrawNumbers(int num, int x, int y, int places)
+{
+//usage:
+//      num    = number to draw onscreen
+//      x, y   = coords to place number (starting upper left)
+//      places = number of places to fit it into (i.e., if
+//                                       number = 5 and places = 2, would draw "05")
+//                                       if places = 0, then will simply display as
+//                                       many as necessary
+    unsigned char numnuts[FNLEN];
+    int needed_places, i;
+    int uddernumber;
+
+    sprintf(numnuts, "%d", num);
+    i = 0;
+    needed_places = strlen(numnuts);
+
+    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;
+    }
+}
+
+/*************************
+EraseNumbers: Erase numbers
+from the screen. See "usage"
+*****************************/
+static void EraseNumbers(int num, int x, int y, int places)
+{
+//usage:
+//      num    = number to draw onscreen
+//      x, y   = coords to place number (starting upper left)
+//      places = number of places to fit it into (i.e., if
+//                                       number = 5 and places = 2, would draw "05")
+//                                       if places = 0, then will simply display as
+//                                       many as necessary
+    unsigned char numnuts[FNLEN];
+    int needed_places, i;
+    int uddernumber;
+
+    sprintf(numnuts, "%d", num);
+    i = 0;
+    needed_places = strlen(numnuts);
+
+    if (needed_places < FNLEN && needed_places <= places) {
+        if (places > 0) {
+            for (i = 1; i <= (places - needed_places); i++) {
+                EraseObject(number[0], x, y);
+                x += number[0]->w;
+            }
+        }
+    }
+    for (i = 0; i < needed_places; i++) {
+        uddernumber = numnuts[i] - '0';
+        EraseObject(number[uddernumber], x, y);
+        x += number[uddernumber]->w;
+    }
+}
+
+/**********************
+FreeGame : Free all
+the game elements
+***********************/
+static void FreeGame(void)
+{
+  int i;
+
+  FreeLetters();
+
+  if (font)
+    TTF_CloseFont(font);
+  font = NULL;
+
+  LOG( "FreeGame():\n-Freeing Tux Animations\n" );
+
+  for (i = 0; i < TUX_NUM_STATES; i++ )
+  {
+    if (tux_object.spr[i][RIGHT])
+      FreeSprite(tux_object.spr[i][RIGHT]);
+    tux_object.spr[i][RIGHT] = NULL;
+
+    if (tux_object.spr[i][LEFT])
+      FreeSprite(tux_object.spr[i][LEFT]);
+    tux_object.spr[i][LEFT] = NULL;
+  }
+
+  LOG( "-Freeing fishies\n" );
+
+  if (fishy)
+    FreeSprite(fishy);
+  if (splat)
+    FreeSprite(splat);
+  fishy = splat = NULL;
+
+  LOG( "-Freeing other game graphics\n" );
+
+  FreeBothBkgds();
+
+  if (curlev)
+    SDL_FreeSurface(curlev);
+  if (fish)
+    SDL_FreeSurface(fish);
+  if (lives)
+    SDL_FreeSurface(lives);
+  curlev = fish = lives = NULL;
+
+  for (i = 0; i < NUM_LEVELS; i++)
+  {
+    if (level[i])
+      SDL_FreeSurface(level[i]);
+    level[i] = NULL;
+  }
+  for (i = 0; i < NUM_NUMS; i++)
+  {
+    if (number[i])
+      SDL_FreeSurface(number[i]);
+    number[i] = NULL;
+  }
+  for (i = 0; i < CONGRATS_FRAMES; i++)
+  {
+    if (congrats[i])
+      SDL_FreeSurface(congrats[i]);
+    congrats[i] = NULL;
+  }
+  for (i = 0; i < OH_NO_FRAMES; i++)
+  {
+    if (ohno[i])
+      SDL_FreeSurface(ohno[i]);
+    ohno[i] = NULL;
+  }
+  if (settings.sys_sound)
+  {
+    LOG( "-Freeing sound\n" );
+    for (i = 0; i < NUM_WAVES; ++i)
+    {
+      if (sound[i])
+        Mix_FreeChunk(sound[i]);
+      sound[i] = NULL;
+    }
+  }
+
+//  PauseUnloadMedia();
+
+  LOG( "FreeGame(): END\n" );
+}
+
+/***************************
+DrawBackground : This
+function updates the entire
+background. Usefull when
+loading new backgrounds,
+or clearing game screen
+****************************/
+static void DrawBackground(void)
+{
+    struct blit *update;
+
+    LOG("-DrawBackground(): Updating entire background\n");
+
+    numupdates=0;  // drawing entire background writes over all other stuff, so don't draw them
+
+    update = &blits[numupdates++];
+    update->src = CurrentBkgd();
+
+    update->srcrect->x = update->dstrect->x = 0;
+    update->srcrect->y = update->dstrect->y = 0;
+    update->srcrect->w = update->dstrect->w = update->src->w;
+    update->srcrect->h = update->dstrect->h = update->src->h;
+
+    update->type = 'D';
+}
+
+/****************************
+SpawnFishies: Spawn the fishes
+in the key cascade game
+*****************************/
+static void SpawnFishies(int diflevel, int* fishies, int* frame)
+{
+	int i, spacing;
+	wchar_t* new_word;
+
+	switch (diflevel) {
+		case INF_PRACT:
+		case EASY:   spacing = FISH_SPACING_EASY; break;
+		case MEDIUM: spacing = FISH_SPACING_MEDIUM; break;
+		case HARD:   spacing = FISH_SPACING_HARD; break;
+	}
+
+	/* --- return without spawn if there isn't room yet --- */
+
+	for (i = 0; i < *fishies; i++)
+		if (fish_object[i].y < (fishy->frame[0]->h + spacing))
+			return;
+
+	/* See if we get a valid UTF-8 word from WORDS_get before we move on: */
+	/* Now that we are using UTF-8, some characters may be more than one byte, */
+	/* so we can't just use strlen() anymore - DSB.*/		
+	LOG( "=>Spawning fishy\n" );
+
+	new_word = GetWord();
+
+	if (!new_word)
+	{
+	  fprintf(stderr, "SpawnFishies() - could not get word - returning.\n");
+          return;
+	}
+
+	/* If we get to here, it should be OK to actually spawn the fishy: */
+	fish_object[*fishies].word = new_word;
+        fish_object[*fishies].len = wcslen(new_word);
+	fish_object[*fishies].alive = 1;
+	fish_object[*fishies].can_eat = 0;
+	fish_object[*fishies].w = fishy->frame[0]->w * fish_object[*fishies].len;
+	fish_object[*fishies].x = rand() % (screen->w - fish_object[*fishies].w);
+	fish_object[*fishies].y = 0;
+
+	/* set the percentage of the speed based on length */
+	fish_object[*fishies].dy = pow(0.92,fish_object[*fishies].len-1);
+	/* ex: a 9 letter word will be roughly twice as slow! 0.92^8 */
+
+	/* give it a random variance so the fish "crunch" isn't constant */
+	fish_object[*fishies].dy *= ((75 + rand() % 25)/100.0);
+	switch (diflevel) {
+		case INF_PRACT:
+			fish_object[*fishies].dy = DEFAULT_SPEED;
+			break;
+		case EASY:
+			fish_object[*fishies].dy *= MAX_SPEED_EASY;
+			break;
+		case MEDIUM:
+			fish_object[*fishies].dy *= MAX_SPEED_MEDIUM;
+			break;
+		case HARD:
+			fish_object[*fishies].dy *= MAX_SPEED_HARD;
+			break;
+   	}
+
+	fish_object[*fishies].splat_time = *frame + (480 - fishy->frame[0]->h - tux_object.spr[TUX_STANDING][0]->frame[0]->h)/fish_object[*fishies].dy;
+
+	DEBUGCODE {
+		/* NOTE need %S rather than %s because of wide characters */
+		fprintf(stderr, "Spawn fishy with word '%S'\n", fish_object[*fishies].word);
+		fprintf(stderr, "Byte length is: %d\n", wcslen(fish_object[*fishies].word));
+		fprintf(stderr, "UTF-8 char length is: %d\n", fish_object[*fishies].len);
+	}
+
+	*fishies = *fishies + 1;
+}
+
+/***************************
+CheckFishies : Check all the fishies and splats.
+               sort the splats and fishies
+****************************/
+static void CheckFishies(int* fishies, int* splats)
+{
+	int forward, backward;
+	struct fishypoo fish_temp;
+	struct splatter splat_temp;
+
+//	LOG( "CheckFishies\n" );
+
+	/* move any fish from the rear to fill up gaps in the
+	 * front
+	 */
+	forward = 0;
+	backward = MAX_FISHIES_HARD;
+	while (forward < backward) {
+		while (backward > 0 && !fish_object[backward].alive)
+			backward--;
+		while (forward < backward && fish_object[forward].alive)
+			forward++;
+		if ((fish_object[backward].alive) && (!fish_object[forward].alive)) {
+			/* swap alive to be infront of dead */
+			fish_temp = fish_object[backward];
+			fish_object[backward] = fish_object[forward];
+			fish_object[forward] = fish_temp;
+		}
+	}
+	
+	/* same thing for splats */
+
+	forward = 0;
+	backward = MAX_FISHIES_HARD;
+	while (forward < backward) {
+		while (backward > 0 && !splat_object[backward].alive)
+			backward--;
+		while (forward < backward && splat_object[forward].alive)
+			forward++;
+		if ((splat_object[backward].alive) && (!splat_object[forward].alive)) {
+			/* swap alive to be infront of dead */
+			splat_temp = splat_object[backward];
+			splat_object[backward] = splat_object[forward];
+			splat_object[forward] = splat_temp;
+		}
+	}
+
+	/* update the count for fishies & splats */
+
+	*splats = *fishies = 0;
+
+	for (forward = 0; forward < MAX_FISHIES_HARD; forward++)
+		if (fish_object[forward].alive)
+			*fishies+=1;
+		else
+			break;
+
+	for (forward = 0; forward < MAX_FISHIES_HARD; forward++)
+		if (splat_object[forward].alive)
+			*splats+=1;
+		else
+			break;
+}
+
+// Restrict x to a value in the range from a ... b
+static int int_restrict(int a, int x, int b) {
+	if (x < a) x = a;
+	if (x > b) x = b;
+	return x;
+}
+
+static float float_restrict(float a, float x, float b)
+{
+	if (x < a) x = a;
+	if (x > b) x = b;
+	return x;
+}
+
+/***************************
+AddSplat: A fish has died, add a splat where he used to be
+****************************/
+static void AddSplat(int* splats, struct fishypoo* f, int* curlives, int* frame) {
+	int i;
+
+	for ( i = 0; i < f->len; i++ ) {
+		splat_object[*splats].x = int_restrict( 0, f->x+(fishy->frame[0]->w*i) + ((fishy->frame[fishy->cur]->w)>>1)-((splat->frame[0]->w)>>1), screen->w-splat->frame[0]->h-1 );
+		splat_object[*splats].y = screen->h - splat->frame[0]->h - 1;
+		splat_object[*splats].alive = 10; // JA tweak here! frames of live of the splat
+		*splats = *splats + 1;
+	}
+
+	f->alive = 0;
+
+	*curlives = *curlives - 1;
+	if (*curlives <= 0)
+		*curlives = 0;
+
+	if ( settings.sys_sound ) 
+		Mix_PlayChannel(SPLAT_WAV, sound[SPLAT_WAV], 0);
+}
+
+
+
+
+static void DrawFish(int which)
+{
+/*        LOG ("Entering DrawFish()\n");*/
+	int j = 0;
+	int red_letters = 0;
+	int current_letter;
+	/* 'x_inset' and 'y_inset' are where the glyph to be drawn relative        */
+	/* the fishy graphic:                                                      */
+	const int x_inset = 10;
+        const int y_inset = 10;
+	/* letter_x and letter_y are where the upper left corner of the glyph needs */
+        /* to be located - (e.g. how SDL blitting understands locations)           */
+        int letter_x = 0;
+        int letter_y = 0;
+
+        SDL_Surface* letter_surface;
+
+	/* Make sure needed pointers are valid - if not, return: */
+        if (!fishy || !fishy->frame[0])
+	{
+          fprintf(stderr, "DrawFish() - returning, needed pointer invalid\n");
+          return;
+	}
+	    
+
+
+	/* Draw the fishies: */
+	for (j = 0; j < fish_object[which].len; j++)
+        {
+	  DrawSprite( fishy,
+                      fish_object[which].x + (fishy->frame[0]->w*j),
+                      fish_object[which].y);
+        }
+
+
+	/* Now we draw the letters on top of the fish: */
+	/* we only draw the letter if tux cannot eat it yet */
+	if (!fish_object[which].can_eat)
+	{
+		red_letters = -1;
+		j = 0;
+
+		/* figure out how many letters are red: */
+		while (j < tux_object.wordlen && red_letters == -1)
+		{
+		  int k;
+		  for (k = 0; k < tux_object.wordlen - j; k++)
+                  {
+                    if (fish_object[which].word[k] != tux_object.word[j + k]) 
+                      k = 100000;
+                  }
+
+                  if (k < 100000)
+                    red_letters = tux_object.wordlen - j;	
+                  else
+                    j++;
+		}
+	
+// 		LOG ("Preparing to draw letters:\n");
+
+		/* Now draw each letter: */
+		for (j = 0; j < wcslen(fish_object[which].word); j++)
+		{
+		  current_letter = (int)fish_object[which].word[j];
+
+		  if (j < red_letters)
+                    letter_surface = GetRedGlyph(current_letter);
+                  else
+                    letter_surface = GetWhiteGlyph(current_letter);
+
+		  /* Set "letter_x" and "letter_y to where we want the letter drawn: */
+		  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);
+		}
+	}
+/*        LOG ("Leaving DrawFish()\n");*/
+}
+
+/****************************
+MoveFishies : Display and
+move the fishies according
+to their settings
+*****************************/
+static void MoveFishies(int *fishies, int *splats, int *lifes, int *frame) {
+	int i, j;
+
+//	LOG("start MoveFishies\n");
+
+	for (i = 0; i < *fishies; i++)
+		if (fish_object[i].alive) {
+			for (j=0; j < fish_object[i].len; j++)
+				EraseSprite( fishy, fish_object[i].x + (fishy->frame[0]->w*j), fish_object[i].y );
+	            
+			fish_object[i].y += fish_object[i].dy;
+	
+			if (fish_object[i].y >= (screen->h) - fishy->frame[fishy->cur]->h - 1) 
+				AddSplat( splats, &fish_object[i], lifes, frame );
+		}
+	
+	for (i = 0; i < *fishies; i++)
+		if (fish_object[i].alive && fish_object[i].can_eat) 
+			DrawFish( i );
+
+	for (i = 0; i < *fishies; i++)
+		if (fish_object[i].alive && !fish_object[i].can_eat) 
+			DrawFish( i );
+
+	for (i = 0; i < *splats; i++) 
+		if (splat_object[i].alive) {
+			splat_object[i].alive--;
+			if (splat_object[i].alive>1)
+					DrawSprite( splat, splat_object[i].x, splat_object[i].y);
+				else 
+					EraseSprite( splat, splat_object[i].x, splat_object[i].y);
+		}
+
+//	LOG("end MoveFishies\n");
+}
+
+/* UpdateTux : anytime a key is pressed, we need check to
+ * see if a fish can be eaten.  The fish that could hit
+ * the bottom of the screen first should be choosen if 
+ * two fishies match what is typed
+ */
+void UpdateTux(wchar_t letter_pressed, int fishies, int frame) {
+	int i;
+	int time_it_splats=0;
+	int which=-1;
+
+	/* --- move our word array to make room if needed --- */
+
+	if (tux_object.wordlen == MAX_WORD_SIZE) {
+		for (i = 0; i < MAX_WORD_SIZE; i++) 
+			tux_object.word[i] = tux_object.word[i + 1];
+		tux_object.wordlen--;
+	}
+
+	/* --- add letter pressed to word array --- */
+
+	tux_object.word[tux_object.wordlen] = letter_pressed;
+	tux_object.wordlen++;
+	tux_object.word[tux_object.wordlen] = 0;
+
+	/* choose the word that matchs what has been typed  */
+	/* and will hit the ground first                    */
+	for (i = 0; i < fishies; i++) 
+		if ((fish_object[i].alive && !fish_object[i].can_eat) && check_word(i) && (time_it_splats > fish_object[i].splat_time || !time_it_splats)) {
+			time_it_splats = fish_object[i].splat_time;
+			which = i;
+		}
+
+	if (which!=-1) {
+		fish_object[which].can_eat = 1;
+		tux_object.wordlen = 0;
+		tux_object.word[0] = 0;
+	}
+
+}
+
+/*************************
+CheckCollision: Check
+for collisions between Tux
+and Fishies. If collided,
+perform appropriate action
+***************************/
+static void CheckCollision(int fishies, int *fish_left, int frame ) {
+	int i, j;
+
+//	LOG( "start CheckCollision\n" );
+
+	for (i = 0; i < fishies; i++) {
+		if ((fish_object[i].y >= tux_object.y - fishy->frame[0]->h) &&
+		    (fish_object[i].x + (fish_object[i].w-fishy->frame[0]->w)/2 >= tux_object.x) &&
+		    (fish_object[i].x + (fish_object[i].w+fishy->frame[0]->w)/2 <= tux_object.x + tux_max_width)) {
+
+			if (fish_object[i].can_eat) {
+                		LOG( "**EATING A FISHY** - in CheckCollision()\n" );
+
+				fish_object[i].alive = 0;
+				fish_object[i].can_eat = 0;
+
+				for (j = 0; j < fish_object[i].len; j++) 
+					EraseSprite(fishy, (fish_object[i].x + (j * fishy->frame[0]->w)), fish_object[i].y);
+
+				*fish_left = *fish_left - 1;
+
+				tux_object.state = TUX_GULPING;
+				REWIND(tux_object.spr[TUX_GULPING][tux_object.facing]);
+				tux_object.dx = 0;
+				tux_object.endx = tux_object.x;
+
+				if (settings.sys_sound) Mix_PlayChannel(BITE_WAV, sound[BITE_WAV], 0);
+
+			} else if (tux_object.state == TUX_STANDING) {
+				LOG( "***EXCUSE ME!** - in CheckCollision()\n" );
+
+				if (settings.sys_sound && !Mix_Playing(EXCUSEME_WAV))
+					Mix_PlayChannel(EXCUSEME_WAV, sound[EXCUSEME_WAV], 0);
+			}
+		}
+	}
+//	LOG( "end CheckCollision\n" );
+}
+
+static void next_tux_frame(void) {
+
+	if ( tux_object.state != TUX_GULPING ) {
+		NEXT_FRAME(tux_object.spr[tux_object.state][tux_object.facing]);
+	} else {
+		NEXT_FRAME(tux_object.spr[TUX_GULPING][tux_object.facing]);
+		if (tux_object.spr[TUX_GULPING][tux_object.facing]->cur==0) 
+			tux_object.state = TUX_STANDING;
+	}
+}
+
+/***********************************
+MoveTux : Update Tux's location & then blit him!
+************************************/
+static void MoveTux( int frame, int fishies ) {
+	int i;
+	int which=-1, time_to_splat=0;
+
+//	LOG( "MoveTux\n" );
+
+	EraseSprite( tux_object.spr[tux_object.state][tux_object.facing], tux_object.x, tux_object.y );
+
+	if (tux_object.state != TUX_GULPING) {
+		for (i=0; i<fishies; i++) 
+			if (fish_object[i].can_eat && (!time_to_splat || fish_object[i].splat_time < time_to_splat)) {
+				time_to_splat = fish_object[i].splat_time;
+				which = i;
+			}
+		if (which != -1) {
+			int endx = int_restrict( 0, fish_object[which].x + (fish_object[which].w/2) - (tux_object.spr[TUX_GULPING][RIGHT]->frame[0]->w / 2), screen->w - tux_max_width - 1 );
+			if (endx != tux_object.endx) {
+				tux_object.endx = endx;
+
+				if (tux_object.endx >= tux_object.x)
+					tux_object.facing = RIGHT;
+				else
+					tux_object.facing = LEFT;
+
+				/* see how fast we need to go to get there... */
+				if (time_to_splat - frame > (abs(tux_object.endx - tux_object.x) / WALKING_SPEED)) {
+					tux_object.dx = WALKING_SPEED;
+					tux_object.state = TUX_WALKING;
+
+					//stop running sound (if playing)                                               
+					if (settings.sys_sound && Mix_Playing(RUN_WAV))
+						Mix_HaltChannel(RUN_WAV);
+				} else {
+					if (time_to_splat > frame) 
+						tux_object.dx = float_restrict( MIN_RUNNING_SPEED, abs(tux_object.endx - tux_object.x) / (time_to_splat-frame), MAX_RUNNING_SPEED );
+					else {
+						tux_object.dx = MAX_RUNNING_SPEED;
+						if (settings.sys_sound && !Mix_Playing(RUN_WAV))
+							if (abs(tux_object.endx - tux_object.x) > 50)
+								Mix_PlayChannel(RUN_WAV, sound[RUN_WAV], 0);
+					}
+
+					tux_object.state = TUX_RUNNING;
+				}
+			}
+		}
+	}
+
+	/* --- move tux (if moving) --- */
+	
+	tux_object.x = float_restrict(0, tux_object.x + (tux_object.facing==RIGHT ? 1.0 : -1.0)*tux_object.dx, (screen->w - tux_max_width));
+
+	/* if done with certain frames, then reset to standing */
+
+	if (tux_object.state == TUX_WALKING || tux_object.state == TUX_RUNNING) {
+		if ((tux_object.facing == RIGHT && tux_object.x >= tux_object.endx) ||
+		    (tux_object.facing == LEFT && tux_object.x <= tux_object.endx)) {
+
+			LOG( "-In MoveTux(): returning tux to standing\n" );
+			tux_object.state = TUX_STANDING;
+			tux_object.dx = 0;
+			tux_object.x = tux_object.endx;
+		}
+	}
+
+	if ((frame % 8) == 0) next_tux_frame();
+}
+
+static void draw_bar(int curlevel, int diflevel, int curlives, int oldlives, int fish_left, int oldfish_left) {
+	/* --- draw difficulty --- */
+
+	DrawObject(level[diflevel], 1, 1);
+
+	/* --- draw level --- */
+	DrawObject(curlev, 1 + GRAPHIC_SPACE + level[diflevel]->w, 1);
+	DrawNumbers(curlevel + 1, 1 + 2 * GRAPHIC_SPACE + level[diflevel]->w + curlev->w, 1, 0);
+
+	/* --- draw lives --- */
+	DrawObject(lives, (screen->w) - (1+lives->w+fish->w+((MAX_FISHIES_DIGITS+1)*2*number_max_w)+GRAPHIC_SPACE), 1);
+
+	if (oldlives != curlives) {
+		EraseNumbers(oldlives, (screen->w) - (1+fish->w+((MAX_FISHIES_DIGITS+1)*2*number_max_w)+GRAPHIC_SPACE), 1, 0);
+		oldlives = curlives;
+	}
+
+	DrawNumbers(curlives, (screen->w) - (1 + fish->w + ((MAX_FISHIES_DIGITS + 1) * 2 * number_max_w) + GRAPHIC_SPACE), 1, 0);
+
+	/* --- draw fish left --- */
+	DrawObject(fish, (screen->w) - (1 + fish->w + (MAX_FISHIES_DIGITS * number_max_w)), 1);
+	if (oldfish_left != fish_left) {
+		EraseNumbers(oldfish_left, (screen->w) - (1 + (MAX_FISHIES_DIGITS * number_max_w)), 1, MAX_FISHIES_DIGITS);
+		oldfish_left = fish_left;
+	}
+	DrawNumbers(fish_left, (screen->w) - (1 + (MAX_FISHIES_DIGITS * number[4]->w)), 1, MAX_FISHIES_DIGITS);
+}
+
+
+
+
+
+
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/playgame.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/playgame.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/playgame.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/playgame.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,141 @@
+/***************************************************************************
+                          playgame.h
+  description:
+                             -------------------
+    begin                : Fri May 12 2000
+    copyright            : (C) 2000 by Sam Hart
+    email                : hart at geekcomix.com
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef __PLAYGAME_H__
+#define __PLAYGAME_H__
+
+//definitions
+#define GRAPHIC_SPACE 4 //space between each status bar element in cascade
+
+#define NUM_NUMS 10	//"Mmmmm....Num-Nums...."
+
+#define CONGRATS_FRAMES	2	//number of frames for congrats animation
+#define OH_NO_FRAMES 1	//number of frames for "oh no!" losing animation
+#define MAX_END_FRAMES_BETWEEN_LEVELS 350	//number of frames between levels
+#define MAX_END_FRAMES_WIN_GAME 750	//number of frames at ending animation
+#define MAX_END_FRAMES_GAMEOVER 400	//number of frames at game over
+#define END_FRAME_DY 2	//rise speed of ending animation text
+#define WIN_GAME_XAMP 4	//the xamplitide of winning game text circular motion
+#define WIN_GAME_YAMP 4	//the yamplitude of winning game text circular motion
+#define WIN_GAME_ANGLE_MULT 4	//the angle multiplier for winning game text circ motion
+
+//tux frame lengths (number of frames each cell of animation frames on-screen)
+#define WALK_ONSCREEN	10
+#define RUN_ONSCREEN	8
+#define STAND_ONSCREEN	15
+#define GULP_ONSCREEN	10
+//tux default walking & running speeds
+#define WALKING_SPEED	1.5
+//#define WALKING_SPEED         1
+#define MIN_RUNNING_SPEED		4 * WALKING_SPEED
+#define MAX_RUNNING_SPEED		10 * WALKING_SPEED
+/*-- These last two are for future features --*/
+#define WIN_ONSCREEN		1
+#define YIPE_ONSCREEN		2
+
+//fishy defs
+#define MAX_FISHIES_EASY	15
+#define MAX_FISHIES_MEDIUM	30
+#define MAX_FISHIES_HARD	40
+#define MAX_FISHIES_DIGITS	2
+
+#define FISHY_ONSCREEN	10
+#define SPLAT_FRAMES	1
+#define SPLAT_ONSCREEN	4
+#define DEFAULT_SPEED	.3
+
+#define MAX_SPEED_EASY       0.4
+#define MAX_SPEED_MEDIUM     0.9
+#define MAX_SPEED_HARD       1.2
+
+#define FISH_SPACING_EASY    90
+#define FISH_SPACING_MEDIUM  40
+#define FISH_SPACING_HARD    30
+
+#define LIVES_INIT_EASY      5
+#define LIVES_INIT_MEDIUM    7
+#define LIVES_INIT_HARD      9
+
+#define MAX_UPDATES	3*(20+MAX_FISHIES_HARD)	//20 to account for text updates (I hope)
+
+/* The default alpha for slow moving words,
+ note that 128 is optimized for speed! */
+#define DEFAULT_ALPHA 128
+
+typedef struct {
+    int frames;			//number of frames to display this object
+    SDL_Surface *image;
+} object;			//normal (non-RL) object
+
+struct fishypoo {
+    int alive;
+    int can_eat;
+    wchar_t* word;
+    double x, y;
+    int    w;
+    size_t len;
+    int    splat_time;
+    double dy;
+} fish_object[MAX_FISHIES_HARD + 1];
+
+struct fishypoo null_fishy;
+
+enum {
+	TUX_WALKING,
+	TUX_STANDING,
+	TUX_RUNNING,
+	TUX_GULPING,
+	TUX_WINNING,
+	TUX_YIPING,
+	TUX_NUM_STATES
+};
+
+static unsigned char* tux_sprite_fns[TUX_NUM_STATES] = {
+	"tux/walk",
+	"tux/stand",
+	"tux/run",
+	"tux/gulp",
+	"tux/win",
+	"tux/yipe"
+};
+
+#define RIGHT 0
+#define LEFT 1
+
+struct tuxguy {
+    int facing;
+    double x, y;
+    double dx, dy;
+    sprite *spr[TUX_NUM_STATES][2];
+    int endx, endy;
+    int state;
+    int wordlen;
+    wchar_t word[MAX_WORD_SIZE + 1];
+} tux_object;
+
+struct splatter {
+    double x, y;
+    int alive;
+} splat_object[MAX_FISHIES_HARD + 1];
+
+struct splatter null_splat;
+
+
+
+
+#endif

Copied: tuxtype/branches/tuxtype-soc-mh/src/practice.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/practice.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/practice.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/practice.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,799 @@
+/**************************************************************************
+practice.c 
+-  description: practice module
+-------------------
+begin                : Friday Jan 25, 2003
+copyright            : (C) 2003 by Jesse Andrews
+email                : jdandr2 at uky.edu
+
+Revised extensively: 2007
+David Bruce <dbruce at tampabay.rr.com>
+Revised extensively: 2008
+Sreyas Kurumanghat <k.sreyas at gmail.com>
+***************************************************************************/
+
+/***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+
+static SDL_Surface* bg = NULL;
+static SDL_Surface* hands = NULL;
+static SDL_Surface* hand_shift[3] = {NULL};
+static SDL_Surface* keyboard = NULL;
+static SDL_Surface* keypress1 = NULL;
+static SDL_Surface* keypress2 = NULL;
+static SDL_Surface* hand[11] = {NULL};
+static SDL_Rect hand_loc, letter_loc,keyboard_loc;
+static TTF_Font* font = NULL;
+
+static wchar_t phrase[255][FNLEN];
+
+static Mix_Chunk* wrong = NULL;
+
+/*local function prototypes: */
+static int get_phrase(const wchar_t* phr);
+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);
+SDL_Surface* GetKeypress1(int index);
+SDL_Surface* GetKeypress2(int index);
+SDL_Surface* GetWrongKeypress(int index);
+
+
+/************************************************************************/
+/*                                                                      */ 
+/*         "Public" functions (callable throughout program)             */
+/*                                                                      */
+/************************************************************************/
+
+
+/* FIXME this is not UTF-8/Unicode compatible */
+int Phrases(wchar_t* pphrase )
+{
+
+  /* TODO 
+  * 
+  * 
+  * 
+  */
+
+  /* FIXME make variable names more descriptive */
+  Uint32 start = 0, a = 0;
+  int quit = 0,
+      i = 0,
+      c = 0,
+      wp = 0,
+      z = 0,
+      total = 0,
+      state = 0;
+  int key[100] = {0};
+  int next_line=0;
+  SDL_Rect dst, dst2, dst4, mydest;
+  char keytime[20],
+       totaltime[20];
+  SDL_Surface* srfc = NULL;
+  SDL_Surface* tmpsurf = NULL;  
+  
+  if (!practice_load_media())
+  {
+    fprintf(stderr, "Phrases() - practice_load_media() failed, returning.\n");
+    return 0;
+  }
+
+  SDL_BlitSurface(bg, NULL, screen, NULL);
+  SDL_BlitSurface(keyboard, NULL, screen, &keyboard_loc);
+  SDL_BlitSurface(screen, NULL, bg, NULL);
+  SDL_BlitSurface(hands, NULL, screen, &hand_loc);
+  SDL_Flip(screen);
+
+  wp = get_phrase(pphrase);
+
+  if (!wcsncmp(phrase[0], (wchar_t*)"", 1))
+    wcsncpy(pphrase, phrase[0], 80);
+
+  srfc = GetWhiteGlyph(GetLastKey());
+
+  if (!srfc)
+  {
+    fprintf(stderr, "Phrases() - GetWhiteGlyph(GetLastKey()) not defined - bailing out.\n");
+    return 0;
+  }
+
+  dst.x = 320 - (srfc->w/2);
+  dst.y = 100;
+  dst.w = srfc->w;
+  dst.h = srfc->h;
+
+  dst2.x = 50;
+  dst2.y = 400;
+  dst2.w = srfc->w;
+  dst2.h = srfc->h;
+
+  dst4.x = 480;
+  dst4.y = 400;
+  dst4.w = 240;
+  dst4.h = 50;
+
+  dst.x = 40;
+
+  mydest.x = 0;
+  mydest.y = dst.y;
+  mydest.w = screen->w;
+  mydest.h = screen->h-mydest.y;
+
+  start = SDL_GetTicks();
+
+  do
+  {
+    switch (state)
+    {
+      case 0:
+        start = SDL_GetTicks();
+        SDL_BlitSurface(hands, NULL, screen, &hand_loc);
+        SDL_BlitSurface(keyboard, NULL, screen, &keyboard_loc);
+        state = 1;
+        break;
+
+      case 1:
+        if (SDL_GetTicks() - start > 500)
+        {
+          /* Show finger hint, if available. Note that GetFinger() */
+          /* returns negative values on error and never returns a  */
+          /* value greater than 9.                                 */
+          int key = GetIndex(pphrase[c]);
+          int fing = GetFinger(key);
+          int shift = GetShift(key);
+          keypress1= GetKeypress1(key);
+          keypress2= GetKeypress2(key);
+          if (!keypress1)
+          {
+				fprintf(stderr, "Phrases() - GetKeypress1 failed, returning.\n");
+				return 0;
+          }
+          if(!keypress2)
+          {
+				fprintf(stderr, "Phrases() - GetKeypress2 failed, returning.\n");
+				return 0;
+          }
+          SDL_BlitSurface(hands, NULL, screen, &hand_loc);
+          if (fing >= 0) 
+            SDL_BlitSurface(hand[fing], NULL, screen, &hand_loc);
+          SDL_BlitSurface(hand_shift[shift], NULL, screen, &hand_loc);
+          SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
+          SDL_BlitSurface(keypress2, NULL, screen, &keyboard_loc);
+          SDL_FreeSurface(keypress1);
+          SDL_FreeSurface(keypress2);
+          state = 2;
+        }
+        break;
+
+      case 2:
+        if (state == 2 && SDL_GetTicks() - start > 750)
+        {
+          state = 3;
+        }
+        break;
+
+      case 3:
+       SDL_BlitSurface(hands, NULL, screen, &hand_loc);
+       SDL_BlitSurface(keyboard, NULL, screen, &keyboard_loc);
+       state = 12;
+       break;  
+
+      case 4:
+        {
+          int key = GetIndex(pphrase[c]);
+          int fing = GetFinger(key);
+          int shift = GetShift(key);
+          keypress1= GetKeypress1(key);
+          keypress2= GetKeypress2(key);
+                    if (!keypress1)
+          {
+				fprintf(stderr, "Phrases() - GetKeypress1 failed, returning.\n");
+				return 0;
+          }
+          if(!keypress2)
+          {
+				fprintf(stderr, "Phrases() - GetKeypress2 failed, returning.\n");
+				return 0;
+          }
+          SDL_BlitSurface(hands, NULL, screen, &hand_loc);
+          if (fing >= 0) 
+            SDL_BlitSurface(hand[fing], NULL, screen, &hand_loc);
+          SDL_BlitSurface(hand_shift[shift], NULL, screen, &hand_loc);
+          SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
+          SDL_BlitSurface(keypress2, NULL, screen, &keyboard_loc);
+          SDL_FreeSurface(keypress1);
+          SDL_FreeSurface(keypress2);
+          state = 11;
+          break;
+        }
+
+      default:
+        state -= 2; // this is to make the flashing slower
+    }
+	next_letter(pphrase, c);
+
+    while  (SDL_PollEvent(&event))
+    {
+      if (event.type == SDL_KEYDOWN)
+      {
+        a = SDL_GetTicks();
+        key[c] = a - start;
+        total += key[c];
+        sprintf(keytime, "%.2f", (float) key[c] / 1000);
+        sprintf(totaltime, "%.2f", (float) total / 1000);
+        start = a;
+
+        if (event.key.keysym.sym == SDLK_ESCAPE)
+          quit = 1;
+	else
+        if (event.key.keysym.sym == SDLK_DOWN) 
+        {
+          //practice next phase in list
+          quit = 2;
+        }
+        else
+        {
+/**************************************************/
+		int key=GetIndex((wchar_t)event.key.keysym.unicode);
+		char tmp=-1;
+		switch(event.key.keysym.sym)
+		{
+			case  SDLK_BACKQUOTE:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='~';
+				else
+					tmp='`';
+				break;
+			case SDLK_COMMA:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='<';
+				else
+					tmp=',';
+				break;
+			case SDLK_MINUS:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='_';
+				else
+					tmp='-';
+				break;
+			case SDLK_PERIOD:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='>';
+				else
+					tmp='.';
+				break;
+			case SDLK_SLASH:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='?';
+				else
+					tmp='/';
+				break;
+			case SDLK_0:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp=')';
+				else
+					tmp='0';
+				break;
+			case SDLK_1:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='!';
+				else
+					tmp='1';
+				break;
+			case SDLK_2:
+					if(event.key.keysym.mod&KMOD_SHIFT)
+						tmp='@';
+					else
+						tmp='2';
+				break;
+			case SDLK_3:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='#';
+				else
+					tmp='3';
+				break;
+			case SDLK_4:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='$';
+				else
+					tmp='4';
+				break;
+			case SDLK_5:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='%';
+				else
+					tmp='5';
+				break;
+			case SDLK_6:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='^';
+				else
+					tmp='6';
+				break;
+			case SDLK_7:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='&';
+				else
+					tmp='7';
+				break;
+			case SDLK_8:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='*';
+				else
+					tmp='8';
+				break;
+			case SDLK_9:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='(';
+				else
+					tmp='9';
+				break;
+			case SDLK_SEMICOLON:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp=':';
+				else
+					tmp=';';
+				break;
+			case SDLK_EQUALS:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='+';
+				else
+					tmp='=';
+				break;
+			case SDLK_LEFTBRACKET:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='{';
+				else
+					tmp='[';
+				break;
+			case SDLK_BACKSLASH:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='|';
+				else
+					tmp='\\';
+				break;
+			case SDLK_RIGHTBRACKET:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='}';
+				else
+					tmp=']';
+				break;
+			case SDLK_QUOTE:
+				if(event.key.keysym.mod&KMOD_SHIFT)
+					tmp='"';
+				else
+					tmp='\'';
+				break;
+			case SDLK_SPACE:tmp=' ';
+				break;
+			case SDLK_a:tmp='a';
+				break;
+			case SDLK_b:tmp='b';
+				break;
+			case SDLK_c:tmp='c';
+				break;
+			case SDLK_d:tmp='d';
+				break;
+			case SDLK_e:tmp='e';
+				break;
+			case SDLK_f:tmp='f';
+				break;
+			case SDLK_g:tmp='g';
+				break;
+			case SDLK_h:tmp='h';
+				break;
+			case SDLK_i:tmp='i';
+				break;
+			case SDLK_j:tmp='j';
+				break;
+			case SDLK_k:tmp='k';
+				break;
+			case SDLK_l:tmp='l';
+				break;
+			case SDLK_m:tmp='m';
+				break;
+			case SDLK_n:tmp='n';
+				break;
+			case SDLK_o:tmp='o';
+				break;
+			case SDLK_p:tmp='p';
+				break;
+			case SDLK_q:tmp='q';
+				break;
+			case SDLK_r:tmp='r';
+				break;
+			case SDLK_s:tmp='s';
+				break;
+			case SDLK_t:tmp='t';
+				break;
+			case SDLK_u:tmp='u';
+				break;
+			case SDLK_v:tmp='v';
+				break;
+			case SDLK_w:tmp='w';
+				break;
+			case SDLK_x:tmp='x';
+				break;
+			case SDLK_y:tmp='y';
+				break;
+			case SDLK_z:tmp='z';
+				break;
+		}
+		if(event.key.keysym.mod&KMOD_SHIFT)
+			tmp=toupper(tmp);
+		updatekeylist(key,tmp);
+/****************************************************/
+          if (pphrase[c]==event.key.keysym.unicode)
+          {
+		c++;
+		state = 0;
+		dst2.x = 40;
+		dst4.x = 480;
+		
+		if (c==wp+2){
+			//c++;
+			dst.x=40;
+			dst.y=dst.y+dst.h;
+			mydest.y=dst.y;
+			mydest.h=screen->h-mydest.y;
+			next_line=1;
+		}
+		SDL_BlitSurface(bg, &mydest, screen, &mydest);
+		SDL_Flip(screen);
+		if(!next_line)
+			tmpsurf = BlackOutline_w(pphrase, font, &white, c);
+		else
+			tmpsurf = BlackOutline_w(pphrase+wp+1, font, &white, c-(wp+1));
+		SDL_BlitSurface(tmpsurf, NULL, screen, &dst);
+		SDL_FreeSurface(tmpsurf);
+		tmpsurf = NULL;
+		tmpsurf = BlackOutline(keytime, font, &white);
+		SDL_BlitSurface(tmpsurf, NULL, screen, &dst2);
+		SDL_FreeSurface(tmpsurf);
+		tmpsurf = NULL;	
+		tmpsurf = BlackOutline(totaltime, font, &white);
+		SDL_BlitSurface(tmpsurf, NULL, screen, &dst4);
+		SDL_FreeSurface(tmpsurf);
+		tmpsurf = NULL;
+		if (c==(wcslen(pphrase))){
+				wchar_t buf[10];
+				ConvertFromUTF8(buf, gettext("Great!"));
+				print_at(buf, wcslen(buf), 275, 200);
+				SDL_Flip(screen);
+				SDL_Delay(2500);
+				next_line=0;
+				quit=2;
+		}
+	}
+          else
+          {
+		int key = GetIndex((wchar_t)event.key.keysym.unicode);
+		keypress1= GetWrongKeypress(key);
+		SDL_BlitSurface(keypress1, NULL, screen, &keyboard_loc);
+		SDL_FreeSurface(keypress1);
+		state=0;
+		
+            if (event.key.keysym.sym != SDLK_RSHIFT
+             && event.key.keysym.sym != SDLK_LSHIFT)
+             PlaySound(wrong);
+          }
+        }
+      }
+    }
+    SDL_Flip(screen);
+    SDL_Delay(30);
+
+  }while (!quit);
+
+  savekeyboard();
+
+  practice_unload_media();
+
+  return quit;
+}
+
+
+
+/************************************************************************/
+/*                                                                      */ 
+/*       "Private" functions (local to practice.c)                      */
+/*                                                                      */
+/************************************************************************/
+
+
+static int practice_load_media(void)
+{
+  int i;	
+  unsigned char fn[FNLEN];
+  unsigned char let[5];
+  int load_failed = 0;
+  DEBUGCODE { printf("Entering practice_load_media\n"); }
+  LOG("Loading practice media\n");
+
+
+  hands = LoadImage("hands/hands.png", IMG_ALPHA);
+	hand_shift[0] = LoadImage("hands/none.png", IMG_ALPHA);
+	hand_shift[1] = LoadImage("hands/lshift.png", IMG_ALPHA);
+	hand_shift[2] = LoadImage("hands/rshift.png", IMG_ALPHA);
+	keyboard = LoadImage("keyboard/keyboard.png", IMG_ALPHA);
+	bg = LoadImage("main_bkg.png", IMG_ALPHA);
+  wrong = LoadSound("tock.wav");
+  font = LoadFont(settings.theme_font_name, 30);
+
+  for (i = 0; i < 10; i++)
+  {
+    sprintf(fn, "hands/%d.png", i);
+    hand[i] = LoadImage(fn, IMG_ALPHA);
+    if (!hand[i])
+      load_failed = 1;
+  }
+
+  /* Get out if anything failed to load: */
+  if (load_failed
+    ||!hands
+    ||!bg
+    ||!wrong
+    ||!font
+    ||!keyboard
+    ||!hand_shift[0]
+    ||!hand_shift[1]
+    ||!hand_shift[2])
+  {
+    fprintf(stderr, "practice_load_media() - failed to load needed media \n");
+    practice_unload_media;
+    return 0;
+  }
+
+  /* Should be safe from here on out: */
+  hand_loc.x = (screen->w/2) - (hand[0]->w/2);
+  hand_loc.y = screen->h - (hand[0]->h);
+  hand_loc.w = (hand[0]->w);
+  hand_loc.h = (hand[0]->h);
+
+	/********Position of keyboard image*/
+  keyboard_loc.x = screen->w/2 -keyboard->w/2; 
+  keyboard_loc.y = screen->h/2;
+  keyboard_loc.w = screen->w/8;
+  keyboard_loc.h = screen->h/8;
+
+  /* Now render letters for glyphs in alphabet: */
+  RenderLetters(font);
+  //TTF_CloseFont(font);  /* Don't need it after rendering done */
+  //font = NULL;
+  GenerateKeyboard(keyboard);
+
+  LOG("DONE - Loading practice media\n");
+  DEBUGCODE { printf("Leaving practice_load_media\n"); }
+  return 1;
+}
+
+
+
+static void practice_unload_media(void)
+{
+	int i;
+	SDL_FreeSurface(bg);
+        bg = NULL;
+	SDL_FreeSurface(hands);
+        hands = NULL;
+	for(i=0;i<3;i++)
+	{
+		SDL_FreeSurface(hand_shift[i]);
+	        hand_shift[i] = NULL;
+	}
+	SDL_FreeSurface(keyboard);
+        keyboard = NULL;
+	TTF_CloseFont(font);
+	font = NULL;
+	for (i=0; i<10; i++) 
+        {
+          SDL_FreeSurface(hand[i]);
+          hand[i] = NULL;
+        }
+	
+
+	Mix_FreeChunk(wrong);
+	wrong = NULL;
+}
+
+
+/* looks like dead code: */
+static void show(unsigned 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);
+}
+
+
+
+static int get_phrase(const wchar_t* phr)
+{
+  int pc = 0;  // 'phrase count' (?)
+  int pw[256] = { 0 };
+  int wp = 0, i = 0, c = 0, z = 0;
+  char fn[FNLEN];
+
+  int old_debug_on = settings.debug_on;
+  settings.debug_on = 1;
+
+  LOG("Entering get_phrase()\n");
+
+  /* If we didn't receive a phrase get the first one from the file...*/
+  if (wcsncmp((wchar_t*)"", phr, 40) == 0)
+  {
+    FILE* pf; /*   "phrase file"   */
+    /* set the phrases directory/file */
+    /* FIXME I think the phrases should be under data or the theme */
+#ifdef WIN32
+    snprintf(fn, FNLEN - 1, "userdata/phrases.txt");
+#else
+    snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/phrases.txt", getenv("HOME"));
+#endif
+
+    DEBUGCODE { printf("get_phrases(): phrases file is '%s'\n", fn ); }
+    LOG("get_phrases(): trying to open phrases file\n");
+    pf = fopen( fn, "r" );
+    if (pf == NULL) 
+      return(wp);  /* why not just 'return 0;' ??? */
+
+    /* So now copy each line into phrases array: */
+    while (!feof(pf) && pc < 256) 
+    {
+      fscanf( pf, "%[^\n]\n", phrase[pc] );
+      pc++;
+      DEBUGCODE {printf("%s", phrase[pc]);}
+    }
+    if (pc == 256)
+      LOG("File contains more than max allowed phrases - stopping\n");
+
+    fclose(pf);
+    pc--;
+  } 
+  else
+  {
+    pc = 1;
+    wcsncpy(phrase[0], phr, 80);
+  }
+
+  //Find wrapping point
+  for (c = 0; c <= pc; c++)
+  {
+    if (pw[c] < 50)  // If the phrase is less than 598 pixels wide
+    {
+      if (c == 0)
+      {
+        wp = wcslen(phrase[c]);
+        print_at(phrase[0], wp, 40, 10);
+      }
+    }
+    else
+    {
+      z = 0;
+      wp = 0;
+
+      for (i = 0; i < wcslen(phrase[c]); i++)
+      {
+        /* Should be safe (if no glyph, will have returned above) */
+        z ++;
+        if (wp == 0 && z > 50)
+        {
+          wp = i - 1;
+          break;
+        }
+      }
+
+      for (i = wp; i >= 0; i--)
+      {
+        if (wcsncmp((wchar_t*)" ", &phrase[c][i], 1) == 0)
+        {
+          wp = i-1;
+          break;
+        }
+      }
+
+      if (c == 0)
+      {
+        print_at(phrase[0], wp, 40, 10);
+      }
+    }
+  }
+
+  settings.debug_on = old_debug_on;
+
+  LOG("Leaving get_phrase()\n");
+  return(wp);
+}
+
+static void print_at(const wchar_t *pphrase, int wrap, int x, int y)
+{
+	int z=0;
+	SDL_Surface *tmp;
+	letter_loc.x = x;
+	letter_loc.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, font, &white, wrap);
+		letter_loc.w = tmp->w+5;
+		letter_loc.h = tmp->h+5;
+		SDL_BlitSurface(tmp, NULL, screen, &letter_loc);
+		SDL_FreeSurface(tmp);
+	}else{
+                LOG("Line length exceeded - wrap required\n");
+
+		tmp = BlackOutline_w(pphrase, font, &white, wrap+1);
+		letter_loc.w = tmp->w+5;
+		letter_loc.h = tmp->h+5;
+		SDL_BlitSurface(tmp, NULL, screen, &letter_loc);
+		SDL_FreeSurface(tmp);
+		letter_loc.x = 40;
+                // - (letter_loc.h/4) to account for free space at top and bottom of rendered letters
+		//SDL_FreeSurface(tmp);
+		letter_loc.y = letter_loc.y + letter_loc.h - (letter_loc.h/4);
+		tmp = BlackOutline_w(pphrase+wrap+1, font, &white, wcslen(pphrase));
+		letter_loc.w = tmp->w+5;
+		letter_loc.h = tmp->h+5;
+		SDL_BlitSurface(tmp, NULL, screen, &letter_loc);
+		SDL_FreeSurface(tmp);
+	}
+	//TTF_CloseFont(font);
+	// DEBUGCODE { exit(-1); }
+	DEBUGCODE { printf("Leaving print_at \n\n\n"); }
+}
+static void next_letter(wchar_t *t, int c)
+{
+	int i;
+	wchar_t buf[30];
+        i=ConvertFromUTF8(buf, gettext("Next letter "));
+	buf[i]=t[c];
+	buf[i+1]=0;
+        print_at(buf,wcslen(buf),215 ,420);
+}
+
+SDL_Surface* GetKeypress1(int index)
+{
+	char buf[50];
+	GetKeyPos(index,buf);
+	return (LoadImage(buf, IMG_ALPHA));
+}
+
+SDL_Surface* GetWrongKeypress(int index)
+{
+	char buf[50];
+	GetWrongKeyPos(index,buf);
+	return (LoadImage(buf, IMG_ALPHA));
+}
+
+SDL_Surface* GetKeypress2(int index)
+{
+	char buf[50];
+	GetKeyShift(index,buf);
+	return (LoadImage(buf, IMG_ALPHA));
+}

Copied: tuxtype/branches/tuxtype-soc-mh/src/profiles.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/profiles.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/profiles.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/profiles.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,353 @@
+#include "globals.h"
+#include "funcs.h"
+#include "profilesgui.c"
+
+typedef struct profiles{ //structure for profile in use
+    char* profileName;
+    int profileNum;
+    int highscore1;
+    int highscore2;
+    int highscore3;
+    int highscore4;
+    int highscore5;
+    int highscore6;
+    int highscore7;
+    int highscore8;
+    int wpm_fastest;
+    int wpm_average;
+    int wpm_slowest;
+    int wpm_taken;
+  }profiles;
+
+  extern profiles activeProfile;
+
+int load_profiles_filename(const char*, int);
+int load_profiles_fp(FILE*, int);
+
+void loadprofileName(char *name[][])
+{
+	char fn[FNLEN];
+	char *temp;
+	int count = 0;
+	int offset;
+	int search;
+	#ifdef WIN32
+		snprintf(fn, FNLEN - 1, "userdata/profiles.txt");
+	#else
+		snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/profiles.txt", getenv("HOME"));
+	#endif
+	  	
+	FILE* fp = fopen(fn, "r");
+	  	
+	 while(!feof(fp) && count < settings.numProfiles)
+	 {
+		 fgets(temp, 200, fp);
+		 if(strstr(temp, "profileNum"))
+		 {
+			 search = strlen(temp) - strnspn(temp, "=");
+			 fseek(fp, search *-1, SEEK_CUR);
+			 fgets(names[count][0], search-1, fp);
+			 /*skip the newline */
+			 feek(fp, 2, SEEK_CUR);
+		 }
+		 if(strstr(temp, "profileName"))
+		 {
+			 search = strlen(temp) - strspn(temp, "=");
+			 fseek(fp, search * -1, SEEK_CUR);
+			 fgets(names[count][1], search-1, fp);
+			 /* skip to next profile, after newline */
+			 fseek(fp, 2, SEEK_CUR);
+			 for(offset = 0; offset < 12; offset++)
+			 {
+				 fgets(temp, 200, fp);
+			 }
+			 count++;
+		 }
+	 }
+	 fclose(fp);
+}
+void loadProfile(int profilenum)
+{
+	char fn[FNLEN];
+
+	#ifdef WIN32
+		snprintf(fn, FNLEN - 1, "userdata/profiles.txt");
+	#else
+		snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/profiles.txt", getenv("HOME"));
+	#endif
+  	
+  	load_profiles_filename(fn, profilenum);
+}
+
+static int load_profiles_filename(const char* fn, int profilenum)
+{
+  FILE* fp = fopen(fn, "r");
+
+  if (!fp)
+  {
+    fprintf(stderr, "load_profiles_filename(): Incorrect pointer\n");
+    return;
+  }
+
+  if (!load_profiles_fp(fp, profilenum))
+  {
+    fprintf(stderr, "Could not find any profiles.\n");
+    fclose(fp);
+    return 0;
+  }
+
+  fclose(fp);
+  return 1;
+}
+
+static int load_profiles_fp(FILE* fp, int profilenum)
+{
+  char profiles[FNLEN];
+  char value[FNLEN];
+  int profile_found = 0;
+
+  if (!fp)
+  {
+    fprintf(stderr, "load_profiles_fp() - FILE* parameter NULL\n");
+    return 0;
+  }
+
+  /* we load the selected profile, based on number*/
+  while (!feof(fp))
+  {
+    fscanf(fp, "%[^=]=%[^\n]\n", profiles, value );
+
+    if (strncmp( profiles, "profileNum" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.profileNum = atoi(value);
+    	profile_found = 1;
+    }
+    else if (strncmp( profiles, "profileName" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	strncpy(activeProfile.profileName, value, FNLEN - 1);
+    	profiles_found = 1;
+   }
+    else if (strncmp( profiles, "highscore1_" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.highscore1 = atoi(value);
+    	profiles_found = 1;
+    }
+    else if (strncmp(profiles, "highscore2_" (*char)profilenum, FNLEN) == 0)
+    {
+    	activeProfile.highscore2 = atoi(value);
+    	profiles_found = 1;
+    }
+    else if (strncmp(profiles, "highscore3_" (*char)profilenum, FNLEN) == 0)
+    {
+    	activeProfile.highscore3 = atoi(value);
+    	profiles_found = 1;
+    }
+    else if (strncmp( profiles, "highscore4_" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.highscore4 = atoi(value);
+    	profiles_found = 1;
+    }
+    else if (strncmp( profiles, "highscore5_" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.highscore5 = atoi(value);
+    	profiles_found = 1;
+    }
+    else if (strncmp( profiles, "highscore6_" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.highscore6 = atoi(value);
+    	profiles_found = 1;
+	}
+    else if (strncmp( profiles, "highscore7_" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.highscore7 = atoi(value);
+    	profiles_found = 1;
+    }
+    else if (strncmp( profiles, "highscore8_" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.highscore8 = atoi(value);
+    	profiles_found = 1;
+    }
+    else if (strncmp( profiles, "wpmf" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.wpm_fastest = atoi(value);
+        profiles_found = 1;
+    }
+    else if (strncmp( profiles, "wpma" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.wpm_average = atoi(value);
+    	profiles_found = 1;
+    }
+    else if (strncmp( profiles, "wpms" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.wpm_slowest = atoi(value);
+    	profiles_found = 1;
+    }
+    else if (strncmp( profiles, "wpmt" (*char)profilenum, FNLEN ) == 0 )
+    {
+    	activeProfile.wpm_taken = atoi(value);
+    	profiles_found = 1;
+    }   
+  }
+
+  if (profiles_found)
+    return 1;
+  else
+  {
+    fprintf(stderr, "load_profiles_fp() - no profiles in file - empty or corrupt?\n");
+    return 0;
+  }
+}
+
+void saveProfile(int numprofiles) //called during "Create" on gui and before exit
+{
+	char fn[FNLEN];
+	FILE* profilesFile;
+	FILE* tempFile;
+	
+	activeProfile.profileNum = numprofiles;
+
+	/* set the profiles directory/file */
+
+	#ifdef WIN32
+		_mkdir( "userdata" );
+		snprintf( fn, FNLEN-1, "userdata/profiles.txt" );
+	#else
+		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
+		mkdir( fn, 0755 );
+		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/profiles.txt", getenv("HOME") );
+	#endif
+
+		profilesFile = fopen(fn, "r+" );
+
+		if (profilesFile == NULL)
+		{
+			printf("Save Profiles: Profiles file cannot be created!\n");
+		}
+		/* make sure it's valid*/
+		else if(settings.numProfiles <= activeProfile.profileNum)
+		{
+			//it's the last one/new one, just append it
+			if(settings.numProfiles == activeProfile.profileNum)
+			{
+				profilenum8=
+				fseek(profilesFile, SEEK_END, SEEK_SET) //append
+				fprintf(profilesFile, "profilenum%d=%d\n", 	activeProfile.profileNum, 	activeProfile.profileNum);
+				fprintf(profilesFile, "profilename%d=%s\n",	activeProfile.profileNum, 	activeProfile.profileName);
+				fprintf(profilesFile, "highscore1_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore1);
+				fprintf(profilesFile, "highscore2_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore2);
+				fprintf(profilesFile, "highscore3_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore3);
+				fprintf(profilesFile, "highscore4_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore4);
+				fprintf(profilesFile, "highscore5_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore5);
+				fprintf(profilesFile, "highscore6_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore6);
+				fprintf(profilesFile, "highscore7_%d=%d\n",	activeProfile.profileNum,	activeProfile.highscore7);
+				fprintf(profilesFile, "highscore8_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore8);
+				fprintf(profilesFile, "wpmf%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_fastest);
+				fprintf(profilesFile, "wpma%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_average);
+				fprintf(profilesFile, "wpms%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_slowest);
+				fprintf(profilesFile, "wpmt%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_taken);
+				
+				fclose(profilesFile);
+			}
+			/* make a tempfile to store data up to that profile
+			 * write updated profile, add in data from original file
+			 * because data has to be inserted, and best way to handle
+			 * it right now is to create a temp */
+			else
+			{
+				#ifdef WIN32
+					_mkdir( "userdata" );
+					snprintf( fn, FNLEN-1, "userdata/tempfile.txt" );
+				#else
+					snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
+					mkdir( fn, 0755 );
+					snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/tempfile.txt", getenv("HOME") );
+				#endif
+					
+				fopen(tempFile, "w");
+				
+				/* read all lines of data except those of the inserting
+				 * profile */
+				while(!feof(profilesFile))
+				{
+					/* shouldn't be anymore than 200 chars in a line */
+					char *temp;
+					fgets(temp, 200, profilesFile);
+					if(strcmp(temp, "profilenum" numprofiles"="numprofiles"\n") == 0)
+					{
+						int c;
+						//skip 13 data lines of the same profile
+						for(c = 0; c < 13; c++)
+						{
+							fgets(temp, 200, profilesFile);
+						}
+						fprintf(tempFile, "profilenum%d=%d\n", 	activeProfile.profileNum, 	activeProfile.profileNum);
+						fprintf(tempFile, "profilename%d=%s\n",	activeProfile.profileNum, 	activeProfile.profileName);
+						fprintf(tempFile, "highscore1_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore1);
+						fprintf(tempFile, "highscore2_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore2);
+						fprintf(tempFile, "highscore3_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore3);
+						fprintf(tempFile, "highscore4_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore4);
+						fprintf(tempFile, "highscore5_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore5);
+						fprintf(tempFile, "highscore6_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore6);
+						fprintf(tempFile, "highscore7_%d=%d\n",	activeProfile.profileNum,	activeProfile.highscore7);
+						fprintf(tempFile, "highscore8_%d=%d\n", activeProfile.profileNum,	activeProfile.highscore8);
+						fprintf(tempFile, "wpmf%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_fastest);
+						fprintf(tempFile, "wpma%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_average);
+						fprintf(tempFile, "wpms%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_slowest);
+						fprintf(tempFile, "wpmt%d=%d\n", 		activeProfile.profileNum,	activeProfile.wpm_taken);
+					}
+					else
+					{
+						fprintf(tempFile, temp);
+					}
+				}
+				fclose(tempFile);
+				fclose(profilesFile);
+				//overwrite original file with the tempfile
+				remove("userdata/profiles.txt");
+				rename("userdata/tempfile.txt", "userdata/profiles.txt");
+			}
+		}
+		else
+		{
+			 fprintf(stderr, "Invalid profile number.\n");
+			 fclose(profilesFile);
+		}
+}
+
+void updatePersonalScore(int score)
+{
+	int temp, count = 1;
+	int checkScore = score;
+	do
+	{
+		if(checkScore > activeProfile.highscore(count))
+		{
+			temp = activeProfile.highscore(count);
+			activeProfile.highscore(count) = score;
+			checkScore = temp;
+		}
+		count++;
+	}
+	while((checkScore < activeProfile.highscore(count)) && count <=8);
+}
+void updateWPM(int keystrokes)
+{
+#define time 30 //in seconds how long test lasted
+	
+	int numwords = keystrokes/5;
+	int wpm = numwords*2;
+	int tempaverage;
+	
+	if(wpm > activeProfile.wpm_fastest)
+	{
+		activeProfile.wpm_fastest = wpm;
+	}
+	
+	if(wpm < activeProfile.wpm_slowest)
+	{
+		activeProfile.wpm_slowest = wpm;
+	}
+	
+	tempaverage = activeProfile.wpm_taken*activeProfile.wpm_average;
+	activeProfile.wpm_average = (tempaverage + wpm)/activeProfile.wpm_taken++;
+}
\ No newline at end of file

Copied: tuxtype/branches/tuxtype-soc-mh/src/profilesgui.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/profilesgui.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/profilesgui.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/profilesgui.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,668 @@
+#include "globals.h"
+#include "funcs.h"
+#include "profiles.c"
+
+void createProfile(void);
+void selectProfile(void);
+void deleteProfile(void);
+int chooseProfiles(void);
+void nameEntry(char*, const char*, const char*);
+int inRect(SDL_Rect, int, int);
+
+
+void profilesSelector() //gui called upon clicking on the profile icon and at the start of titlescreen
+{
+	char *input;
+	if(!chooseProfiles() && (settings.numProfiles < 8))
+	{
+		createProfile();
+	}
+	else
+	{
+		/* TODO greyout createprofile/disable SDL handling
+		 * since there max profiles, if wanted.
+		 * Nothing needs to happen since there are too many
+		 * profiles\not the first time means display() worked*/
+		;
+	}
+
+}
+
+void createProfile()
+{
+	if(settings.numProfiles < 8)
+	{
+		nameEntry(activeProfile.profileName, "Create a Profile", "Enter a Name");
+		saveProfile(++settings.numProfiles);/*increments number of profiles in existence */
+		loadprofile(settings.numProfiles);
+	}
+	else
+	{
+		/* do nothing since too many*/
+	}
+	
+}
+void selectProfile(int location) //sets profile
+{
+	if (settings.numProfiles > 1 )
+	{
+		saveProfile(activeProfile.numProfile);
+		loadprofile(location)
+	}
+	else
+	{
+		loadprofile(location)
+	}
+
+
+	//erase window
+}
+
+void deleteProfile(int numprofile) //erases selected profile along with all data associated
+{
+	char fn[FNLEN];
+	FILE* profilesFile;
+	FILE* tempFile;
+	int found = 0;
+	int count;
+	
+	/* set the profiles directory/file */
+
+	#ifdef WIN32
+		_mkdir( "userdata" );
+		snprintf( fn, FNLEN-1, "userdata/profiles.txt" );
+	#else
+		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
+		mkdir( fn, 0755 );
+		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/profiles.txt", getenv("HOME") );
+	#endif
+
+	profilesFile = fopen(fn, "r" );
+
+	if (profilesFile == NULL)
+	{
+		printf("Save Profiles: Profiles file cannot be created!\n");
+	}
+	
+	#ifdef WIN32
+		_mkdir( "userdata" );
+		snprintf( fn, FNLEN-1, "userdata/tempfile.txt" );
+	#else
+		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
+		mkdir( fn, 0755 );
+		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/tempfile.txt", getenv("HOME") );
+	#endif
+					
+	fopen(tempFile, "w");
+				
+	/* read all lines of data except those of the inserting
+		 profile */
+	while(!feof(profilesFile))
+	{
+		int lines;
+		/* shouldn't be anymore than 200 chars in a line */
+		char *temp;
+		fgets(temp, 200, profilesFile);
+		if(strcmp(temp, "profilenum" (*char)numprofile"="(*char)numprofile) == 0)
+		{
+			//skip the deleted profile
+			for(int c = 0; c < 13; c++)
+			{
+				fgets(temp, 200, profilesFile);
+			}
+			found = 1;
+		}
+		else if(found) //need to decrement profile values afterward
+		{
+			char* i;
+			char* value;
+			int stringoffset;
+			int offset = numprofile + count;
+			//handle the different lines
+			for(lines = 0; lines < 14; lines++)
+			{
+				switch (lines)
+				{
+					case 0:
+					{
+						fprint(tempFile, "profileNum%d=%d\n",offset, offset))
+						break;
+					}
+					case 1:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "profileName%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;
+					}
+					case 2:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "highscore1_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;
+					}
+					case 3:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "highscore2_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;
+					}
+					case 4:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "highscore3_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;
+					}
+					case 5:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "highscore4_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;					
+					}
+					case 6:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "highscore5_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;					
+					}
+					case 7:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "highscore6_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;					
+					}
+					case 8:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "highscore7_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;					
+					}
+					case 9:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "highscore8_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;					
+					}
+					case 10:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "wpmf%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;
+					}
+					case 11:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "wpma%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;
+					}
+					case 12:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "wpms_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;
+					}
+					case 13:
+					{		
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "wpmt_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;
+					}
+					case 14:
+					{
+						stringoffset = strlen(temp) - strcspn(temp, "=");
+						fprint(tempFile, "highscore1_%d=", offset);
+						fseek(profilesFile, stringoffset * -1 , SEEK_CUR);
+						fgets(temp, 200, profilesFile);
+						fprint(tempFile,"%s", temp);
+						break;
+					}
+				}	
+			}
+			count++;
+		}
+		else //no need to do special work with the line
+		{
+			fprint(tempFile, temp);
+		}
+	}
+	settings.numProfiles--;
+	fclose(tempFile);
+	fclose(profilesFile);
+	//overwrite original file with the tempfile
+	remove("userdata/profiles.txt");
+	rename("userdata/tempfile.txt", "userdata/profiles.txt");
+}
+int chooseProfiles()
+{	
+	char *name[settings.numProfile][2];
+	SDL_Surface* titles[8] = {NULL};
+	SDL_Surface* select[8] = {NULL};
+	SDL_Surface* create = NULL, *select = NULL, *delete = NULL;
+	SDL_Surface* backg = NULL;
+	SDL_Rect createRect, selectRect, deleteRect;
+	SDL_Rect titleRects[8];
+	int stop = 0;
+	int loc = 0;
+	int old_loc = 1;
+	int i;
+
+	/* Render SDL_Surfaces for list entries: */
+	for (i = 0; i < settings.numProfiles; i++)
+	{
+		titles[i] = BlackOutline( name[i][1], font, &white );
+	    select[i] = BlackOutline( names[i][1], font, &yellow);
+	}
+
+	backg = LoadImage("main_bkg.png", IMG_REGULAR);
+	delete = LoadImage("delete.png", IMG_ALPHA);
+	create = LoadImage("create.png", IMG_ALPHA);
+	select = LoadImage("select.png", IMG_ALPHA);
+
+	/* Get out if needed surface not loaded successfully: */
+	if (!backg || !delete || !create || !select)
+	{
+		fprintf(stderr, "chooseProfile(): needed image not available\n");
+
+	    for (i = 0; i < settings.numProfiles; i++)
+	    {
+	    	SDL_FreeSurface(titles[i]);
+	    	SDL_FreeSurface(select[i]);
+	    	titles[i] = select[i] = NULL;
+	    }
+
+	    SDL_FreeSurface(backg);
+	    SDL_FreeSurface(left);
+	    SDL_FreeSurface(create)
+	    SDL_FreeSurface(select);
+	    backg = left = right = NULL;
+	    return 0;
+	}
+
+	deleteRect.w = delete->w; deleteRect.h = delete->h;
+	deleteRect.x = 80 - (deleteRect.w/2); deleteRect.y = 430;
+
+	createRect.w = create->w; createRect.h = delete->h;
+	createRect.x = 320 - (createRec.w/2); createRec.y = 430;
+	  
+	selectRect.w = select->w; selectRect.h = select->h;
+	selectRect.x = 560 - (rightRect.w/2); selectRect.y = 430;
+
+	/* set initial rect sizes */
+	titleRects[0].y = 30;
+	titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
+
+	for (i = 1; i < 8; i++)
+	{
+		titleRects[i].y = titleRects[i - 1].y + 50;
+	    titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
+	}
+
+	/* Main event loop for this screen: */
+	while (!stop)
+	{
+	  while (SDL_PollEvent(&event))
+	  {
+		  switch (event.type)
+	      {
+	        	case SDL_QUIT:
+	        	{
+	        		exit(0); /* FIXME may need to cleanup memory and exit more cleanly */
+	        		break;
+	        	}
+
+	        	case SDL_MOUSEMOTION:
+	        	{
+	        		for (i=0; (i<8) && (loc-(loc%8)+i<settings.numProfiles); i++)
+	        		{
+	        			if (inRect( titleRects[i], event.motion.x, event.motion.y ))
+	        			{
+	        				loc = loc-(loc%8)+i;
+	        				break;
+	        			}
+	        		}
+	        		break;
+	        	}
+
+	        	case SDL_MOUSEBUTTONDOWN:
+	        	{
+	        		if (inRect( deleteRect, event.button.x, event.button.y ))
+	        		{
+	        				deleteprofile(loc);
+	        				stop = 3;
+	        		}
+	        		if (inRect( createRect, event.button.x, event.button.y ))
+	        		{
+	        			createProfile();
+	        			break;
+	        		}
+	        		if (inRect(selectRect, event.button.x, event.button.y))
+	        		{
+	        			selectProfile(loc);
+	        			stop = 1;
+	        		}
+	        			break;
+	        		}
+	        	}
+	        	case SDL_KEYDOWN:
+	        		if (event.key.keysym.sym == SDLK_ESCAPE) 
+	        		{ 
+	        			stop = 1; 
+	        			break; 
+	        		}
+	        		if (event.key.keysym.sym == SDLK_RETURN) 
+	        		{
+	        			selectProfile(loc);
+	        			break;
+	        		}
+
+	        		if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP)) 
+	        		{
+	        			if (loc-(loc%8)-8 >= 0)
+	        			{
+	        				loc=loc-(loc%8)-8;
+	        			}
+	        		}
+
+	        		if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) 
+	        		{
+	        			if (loc-(loc%8)+8 < settings.numProfiles)
+	        			{
+	        				loc=(loc-(loc%8)+8);
+	        			}
+	        		}
+
+	        		if (event.key.keysym.sym == SDLK_UP) 
+	        		{
+	        			if (loc > 0)
+	        			{
+	        				loc--;
+	        			}
+	        		}
+
+	        		if (event.key.keysym.sym == SDLK_DOWN) 
+	        		{
+	        			if (loc+1<settings.numProfiles)
+	        			{
+	        				loc++;
+	        			}                    
+	        		}
+	  }
+	}
+
+	if (old_loc != loc) 
+	{
+		int start;
+
+		SDL_BlitSurface(backg, NULL, screen, NULL );
+
+		start = loc - (loc % 8);
+		for (i = start; i<MIN(start+8,settings.numProfiles); i++) 
+		{
+			titleRects[i%8].x = 320 - (titles[i]->w/2);
+			if (i == loc)
+			{
+				SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
+			}
+			else
+			{
+				SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
+			}               
+		}
+
+		SDL_UpdateRect(screen, 0, 0, 0 ,0);
+	}
+	SDL_Delay(40);
+	old_loc = loc;
+
+	  /* --- clear graphics before leaving function --- */
+	  for (i = 0; i < settings.numProfiles; i++)
+	  {
+	    SDL_FreeSurface(titles[i]);
+	    SDL_FreeSurface(select[i]);
+	    titles[i] = select[i] = NULL;
+	  }
+
+	  SDL_FreeSurface(backg);
+	  SDL_FreeSurface(delete);
+	  SDL_FreeSurface(create)
+	  SDL_FreeSurface(select);
+	  backg = left = right = NULL; /* Maybe overkill - about to be destroyed anyway */
+
+	  if (stop == 2)
+	  {
+	    return 0;
+	  }
+	  else if (stop == 3)
+	  {
+		  chooseProfiles();
+	  }
+
+	  return 1;
+}
+
+void nameEntry(char* name, const char* heading, const char* sub)
+{
+	/* should be long enough */
+	  char UTF8_buf[96] = {'\0'};
+	
+	  SDL_Rect loc;
+	  SDL_Rect redraw_rect;
+	
+	  int redraw = 0;
+	  int first_draw = 1;
+	  int finished = 0;
+	  int tux_frame = 0;
+	  Uint32 frames = 0;
+	  Uint32 start = 0;
+	  wchar_t wchar_buf[33] = {'\0'};
+	  TTF_Font* name_font = NULL;
+	  const int NAME_FONT_SIZE = 18;
+	  const int BG_Y = 100;
+	  const int BG_WIDTH = 400;
+	  const int BG_HEIGHT = 200;
+
+	  if (!name)
+	  {
+		  return;
+	  }
+	    
+	  name_font = LoadFont(DEFAULT_FONT_NAME, NAME_FONT_SIZE);
+	  if (!name_font)
+	  {
+		  return;
+	  }
+
+	  SDL_EnableUNICODE(SDL_ENABLE);
+
+  /* Draw translucent background for text: */
+	  
+	 SDL_Rect bg_rect;
+	 bg_rect.x = (screen->w)/2 - BG_WIDTH/2;
+	 bg_rect.y = BG_Y;
+	 bg_rect.w = BG_WIDTH;
+	 bg_rect.h = BG_HEIGHT;
+	 DrawButton(&bg_rect, REG_RGBA);
+	
+	 bg_rect.x += 10;
+	 bg_rect.y += 10;
+	 bg_rect.w -= 20;
+	 bg_rect.h = 60;
+	 DrawButton(&bg_rect, SEL_RGBA);
+	  
+
+  /* Draw heading: */
+  
+    SDL_Surface* s = outlineBox( heading, default_font, &white);
+    
+    if(s)
+    {
+    	loc.x = (screen->w/2) - (s->w/2);
+    	loc.y = 110;
+    	SDL_BlitSurface(s, NULL, screen, &loc);
+    	SDL_FreeSurface(s);
+    }
+
+    s = BlackOutline( sub, default_font, &white);
+    if(s)
+    {
+    	loc.x = (screen->w/2) - (s->w/2);
+    	loc.y = 140;
+    	SDL_BlitSurface(s, NULL, screen, &loc);
+    	SDL_FreeSurface(s);
+    }
+
+    /*update*/
+    SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+    /*handle events*/
+    while (!finished)
+    {
+    	start = SDL_GetTicks();
+
+    	while (SDL_PollEvent(&event)) 
+    	{
+    		switch (event.type)
+    		{
+    			case SDL_QUIT:
+    			{
+    				cleanup();
+    			}
+
+    			case SDL_KEYDOWN:
+    			{
+    				switch (event.key.keysym.sym)
+    				{
+    					case SDLK_ESCAPE:
+    					case SDLK_RETURN:
+    					case SDLK_KP_ENTER:
+    					{
+    						finished = 1;
+    						playsound(SND_TOCK);
+    						break;
+    					}
+    					case SDLK_BACKSPACE:
+    					{
+    						if (wcslen(wchar_buf) > 0)
+    						{
+    							wchar_buf[(int)wcslen(wchar_buf) - 1] = '\0';
+    						}
+    						redraw = 1;
+    						break;
+    					}
+
+    					/* if key has unicode value, add it */
+    					default:
+    					{
+    						if ((event.key.keysym.unicode > 0)
+    								&& (wcslen(wchar_buf) < 32)) 
+    						{
+    							wchar_buf[(int)wcslen(wchar_buf)] = event.key.keysym.unicode;
+    							redraw = 1;
+    						} 
+    					}
+    				}
+
+    				/* Now draw name, if needed: */
+    				if (redraw)
+    				{
+    					SDL_Surface* s = NULL;
+    					redraw = 0;
+
+    					/* Convert text to UTF-8 so BlackOutline() can handle it: */
+    					wcstombs((char*) UTF8_buf, wchar_buf, 96);
+
+    					/* Redraw background and shading in area where we drew text last time: */ 
+    					if (!first_draw)
+    					{
+    						SDL_BlitSurface(screen, &redraw_rect, screen, &redraw_rect);
+    						DrawButton(&redraw_rect, REG_RGBA);
+    						SDL_UpdateRect(screen,
+    								redraw_rect.x,
+    								redraw_rect.y,
+    								redraw_rect.w,
+    								redraw_rect.h);
+    					}
+
+    					s = BlackOutline(UTF8_buf, name_font, &yellow);
+            
+    					if (s)
+    					{
+    						/* set up loc and blit: */
+    						loc.x = (screen->w/2) - (s->w/2);
+    						loc.y = 200;
+    						SDL_BlitSurface(s, NULL, screen, &loc);
+
+    						/* Remember where we drew so we can update background next time through:  */
+    						/* (for some reason we need to update a wider area to get clean image)    */
+    						redraw_rect.x = loc.x - 20;
+    						redraw_rect.y = loc.y - 10;
+    						redraw_rect.h = s->h + 20;
+    						redraw_rect.w = s->w + 40;
+    						first_draw = 0;
+
+    						SDL_UpdateRect(screen,
+    								redraw_rect.x,
+    								redraw_rect.y,
+    								redraw_rect.w,
+    								redraw_rect.h);
+    						SDL_FreeSurface(s);
+    						s = NULL;
+    					}
+    				}
+    			}
+    		}
+    	}
+
+    	/*stop frame rate from skipping */
+    	while ((SDL_GetTicks() - start) < 33)
+    	{
+    		SDL_Delay(20);
+    	}
+    	frames++;
+  }
+  TTF_CloseFont(name_font);
+
+  /* disable due to overhead */
+  SDL_EnableUNICODE(SDL_DISABLE);
+
+  /* Now copy name into location pointed to by arg: */ 
+  strncpy((char*)name, (char*)UTF8_buf, 96);
+}
\ No newline at end of file

Copied: tuxtype/branches/tuxtype-soc-mh/src/scripting.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/scripting.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/scripting.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/scripting.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,1364 @@
+/***************************************************************************
+ -  file: scripting.c
+ -  description: scripting for lessons & instructions ...
+                             -------------------
+    begin                : Sun Dec 28, 2003
+    copyright            : Jesse Andrews (C) 2003
+    email                : tuxtype-dev at tux4kids.net
+***************************************************************************/
+
+/***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************/
+
+#include "scripting.h"
+
+/* Local function prototypes: */
+static void clear_items(itemType* i);
+static void clear_pages(pageType* p);
+static void close_script(void);
+static SDL_Color* get_color(const char* in);
+static int get_int(const char* in);
+static char* get_quote(const char* in);
+static char hex2int(char b, char s);
+static int load_script(const char* fn);
+static void run_script(void);
+
+/************************************************************************/
+/*                                                                      */ 
+/*         "Public" functions (callable throughout program)             */
+/*                                                                      */
+/************************************************************************/
+
+
+void InstructCascade(void)
+{
+  char fn[FNLEN]; 
+
+  /* Try theme script first: */
+  if (!settings.use_english)
+    sprintf( fn, "%s/scripts/cascade.xml", settings.theme_data_path);
+
+  if (load_script( fn ) == 0) /* meaning successful load */
+  {
+    run_script();
+    return;
+  }
+
+  /* If unsuccessful, fall back to default (English) script: */
+  sprintf( fn, "%s/scripts/cascade.xml", settings.default_data_path);
+  if (load_script( fn ) != 0)
+    return; // bail if any errors occur
+
+  run_script();
+}
+
+
+void InstructLaser(void)
+{
+  char fn[FNLEN]; 
+  int i;
+
+  /* Try theme script first: */
+  if (!settings.use_english)
+    sprintf( fn, "%s/scripts/laser.xml", settings.theme_data_path);
+
+  if (load_script( fn ) == 0) /* meaning successful load */
+  {
+    for (i = 0; i < 20; i++)
+    {
+      run_script();
+      SDL_Delay(500);
+    }
+    return;
+  }
+
+
+  /* If unsuccessful, fall back to default (English) script: */
+  sprintf( fn, "%s/scripts/laser.xml", settings.default_data_path);
+  if (load_script( fn ) != 0)
+    return; // bail if any errors occur
+
+  for (i = 0; i < 20; i++)
+  {
+    run_script();
+    SDL_Delay(500);
+  }
+}
+
+
+void ProjectInfo(void)
+{
+  char fn[FNLEN]; 
+
+  /* Try theme script first: */
+  if (!settings.use_english)
+    sprintf( fn, "%s/scripts/projectInfo.xml", settings.theme_data_path);
+
+  if (load_script( fn ) == 0) /* meaning successful load */
+  {
+    run_script();
+    return;
+  }
+
+  /* If unsuccessful, fall back to default (English) script: */
+  sprintf( fn, "%s/scripts/projectInfo.xml", settings.default_data_path);
+  if (load_script( fn ) != 0)
+    return; // bail if any errors occur
+
+  run_script();
+}
+
+
+int TestLesson(void)
+{
+  SDL_Surface* left = NULL, *right = NULL, *pointer = NULL, *bkg = NULL;
+  SDL_Surface* filenames[200] = {NULL};
+
+  SDL_Rect spot, arrow_area;
+  SDL_Rect leftRect, rightRect;
+  SDL_Rect titleRects[8];
+
+  TTF_Font* font = NULL;
+	
+  int stop = 0;
+  int loc = 0;
+  int old_loc = 1;
+  int i;
+  int c = 0;
+  int found = 0;
+	
+  char fn[FNLEN]; 
+  unsigned char wordlistFile[200][200];
+  unsigned char script_path[FNLEN];
+
+  DIR* wordsDir = NULL;
+  struct dirent* wordsFile = NULL;
+
+  LOG("\nEnter TestLesson()\n");
+
+  pointer = LoadImage( "right.png", IMG_ALPHA );
+  bkg = LoadImage( "main_bkg.png", IMG_REGULAR );
+  left = LoadImage("left.png", IMG_ALPHA);       
+  right = LoadImage("right.png", IMG_ALPHA);
+
+  if (!pointer || !bkg || !left ||!right)
+  {
+    fprintf(stderr, "TestLesson() - needed image not found\n");
+    /* Free anything that got loaded: */
+    SDL_FreeSurface(pointer);
+    SDL_FreeSurface(left);
+    SDL_FreeSurface(right);
+    SDL_FreeSurface(bkg);
+    pointer = left = right = bkg = NULL;
+    return 0;
+  }
+
+  SDL_ShowCursor(0);
+
+  /* find the directory to load wordlists from */
+  /* First look in theme path, if desired: */
+  if (!settings.use_english)
+  {
+    sprintf( script_path, "%s/scripts", settings.theme_data_path);
+    if (CheckFile(script_path))
+    {
+      DEBUGCODE { fprintf(stderr, "Using theme script dir: %s\n", script_path); }
+      found = 1;
+    }
+  }
+
+  /* Now look in default path if desired or needed: */
+  if (!found)
+  {
+    sprintf( script_path, "%s/scripts", settings.default_data_path);
+    if (CheckFile(script_path))
+    {
+      DEBUGCODE { fprintf(stderr, "Using theme script dir: %s\n", script_path); }
+      found = 1;
+    }
+  }
+
+  if (!found)
+  {
+    fprintf(stderr, "TestLesson(): Error finding script directory!\n");
+    return 0;
+  }
+
+  /* What is this location? */
+  spot.x = 60;
+  spot.y = 20;
+
+
+  /* create a list of all the .xml files */
+
+  wordsDir = opendir( script_path );	
+  font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
+  do
+  {
+    wordsFile = readdir(wordsDir);
+    if (!wordsFile)
+      break;
+
+    /* must have at least '.xml' at the end */
+    if (strlen(wordsFile->d_name) < 5)
+      continue;
+
+    if (strcmp(&wordsFile->d_name[strlen(wordsFile->d_name)-4],".xml"))
+      continue;
+
+    sprintf( wordlistFile[c], "%s", wordsFile->d_name );
+
+    DEBUGCODE { fprintf(stderr, "Adding XML file no. %d: %s\n", c, wordlistFile[c]); }
+
+
+    filenames[c] = TTF_RenderUTF8_Blended(font, wordsFile->d_name, white);
+    SDL_BlitSurface( filenames[c], NULL, screen, &spot );
+    SDL_FreeSurface(filenames[c]);
+    c++;
+    spot.y += MENU_FONT_SIZE;
+  } while (1); /* Leave loop when readdir() returns NULL */
+
+  TTF_CloseFont(font);
+  font = NULL;
+  closedir(wordsDir);	
+  wordsDir = NULL;
+  SDL_Flip(screen);
+
+  /* Should be safe - tested 'left' and 'right' above: */
+  leftRect.w = left->w; leftRect.h = left->h;
+  leftRect.x = 320 - 80 - (leftRect.w/2); leftRect.y = 430;
+
+  rightRect.w = right->w; rightRect.h = right->h;
+  rightRect.x = 320 + 80 - (rightRect.w/2); rightRect.y = 430;
+
+  /* set initial rect sizes */
+  titleRects[0].y = 30;
+  titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
+
+  for (i = 1; i < 8; i++)
+  { 
+    titleRects[i].y = titleRects[i-1].y + 50;
+    titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
+  }
+
+  arrow_area.x = 0;
+  arrow_area.y = 0;
+  arrow_area.w = 59;
+  arrow_area.h = 479;
+
+  while (!stop)
+  {
+    while (SDL_PollEvent(&event))
+    {
+      switch (event.type)
+      {
+        case SDL_QUIT:
+          exit(0);
+          break;
+        /* FIXME some of mouse code is wrong */
+        case SDL_MOUSEMOTION:
+          for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
+            if (inRect( titleRects[i], event.motion.x, event.motion.y ))
+            {
+              loc = loc-(loc%8)+i;
+              break;
+            }
+          break;
+
+        case SDL_MOUSEBUTTONDOWN:
+          if (inRect( leftRect, event.button.x, event.button.y ))
+            if (loc-(loc%8)-8 >= 0)
+            {
+              loc=loc-(loc%8)-8;
+              break;
+            }
+
+          if (inRect( rightRect, event.button.x, event.button.y ))
+            if (loc-(loc%8)+8 < c)
+            {
+              loc=loc-(loc%8)+8;
+              break;
+            }
+
+          for (i=0; (i<8) && (loc-(loc%8)+i<c); i++)
+            if (inRect(titleRects[i], event.button.x, event.button.y))
+            {
+//              loc = loc-(loc%8)+i;
+//              ClearWordList(); /* clear old selection */
+//               if (loc==0)
+//                 UseAlphabet(); 
+//               else
+//                 GenerateWordList(wordlistFile[loc]);
+// 
+//               stop = 1;
+//               break;
+            }
+          break;
+
+        case SDL_KEYDOWN:
+          if (event.key.keysym.sym == SDLK_ESCAPE)
+          { 
+            stop = 2;
+            break;
+          }
+
+          if (event.key.keysym.sym == SDLK_RETURN)
+          {
+            sprintf(fn, "%s/scripts/%s", settings.default_data_path, wordlistFile[loc]);
+            stop = 1;
+            break;
+          }
+
+          if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP))
+          {
+            if (loc-(loc%8)-8 >= 0)
+              loc=loc-(loc%8)-8;
+            SDL_ShowCursor(1);
+          }
+
+          if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN))
+          {
+            if (loc-(loc%8)+8 < c)
+              loc=(loc-(loc%8)+8);
+          }
+
+          if (event.key.keysym.sym == SDLK_UP)
+          {
+            if (loc > 0)
+              loc--;
+          }
+
+          if (event.key.keysym.sym == SDLK_DOWN)
+          {
+            if (loc+1< c)
+              loc++;
+          }
+      } /* End of 'switch(event.type)' loop */
+    }  /* End of 'while(SDL_PollEvent(&event))' loop */
+
+
+
+    if (old_loc != loc)
+    {
+      int start;
+      SDL_BlitSurface( bkg, &arrow_area, screen, NULL);
+
+      start = loc;
+      for (i = start; i < c; i++)
+      {
+        spot.x = 5;
+        spot.y = (i * MENU_FONT_SIZE) + 18;
+        if (i == loc)
+          SDL_BlitSurface(pointer, NULL, screen, &spot);
+      }
+
+      SDL_Flip(screen);
+    }
+
+      SDL_Delay(40);
+      old_loc = loc;
+  }   /*   End of 'while(!stop)' loop  */
+
+  SDL_FreeSurface(pointer);
+  SDL_FreeSurface(left);
+  SDL_FreeSurface(right);
+  SDL_FreeSurface(bkg);
+  pointer = left = right = bkg = NULL;
+
+  if (stop == 2)
+  {
+    LOG("Player pressed 'Esc' - leaving TestLesson\n");
+    return 1;
+  }
+
+  /* Getting to here means "stop == 1", try to run chosen script: */
+  if (load_script(fn) != 0)
+  {
+    fprintf(stderr, "load_script() failed to load '%s'\n");
+    return 0; // bail if any errors occur
+  }
+
+  DEBUGCODE { fprintf(stderr, "Attempting to run script: %s\n", fn); }
+
+  run_script();
+
+  /* FIXME - shouldn't we show the cursor if returning in other code paths? */
+  SDL_ShowCursor(1);
+
+  LOG("Leave TestLesson()\n");
+
+  return 1; 
+}
+
+
+
+/************************************************************************/
+/*                                                                      */ 
+/*         "Private" functions (local to scripting.c)                   */
+/*                                                                      */
+/************************************************************************/
+
+
+static char* get_quote(const char* in)
+{
+    int start, finish;
+    char *out;
+
+    for (start=0; start<strlen(in) && in[start] != '"'; start++);  // find the first "
+
+    if (start >= strlen(in)) return 0; // return null string if no " found
+
+    start++; // move past the "
+    
+    for (finish=start; finish<strlen(in) && in[finish] != '"'; finish++); // find the next "
+
+    if (finish >= strlen(in)) return 0; // return null string if no " found
+    
+    out = malloc(finish-start+2);
+    
+    snprintf(out, finish-start+1, &in[start]);
+    out[finish-start]=0;
+    
+    return out;
+}
+
+
+static int get_int(const char* in)
+{
+    char *t = get_quote(in);
+    int ans=-1;
+    if (t) {
+        ans = atoi(t);
+        free(t);
+    }
+    return ans;
+}
+
+
+static char hex2int(char b, char s)
+{
+    char ans=0;
+        
+    if      ((b>='0') && (b<='9'))       ans=16*(b-'0');
+    else if ((b>='A') && (b<='F'))       ans=16*(b-'A'+10);
+    else if ((b>='a') && (b<='f'))       ans=16*(b-'a'+10);
+    
+    if      ((s>='0') && (s<='9'))       ans+=(s-'0');
+    else if ((s>='A') && (s<='F'))       ans+=(s-'A'+10);
+    else if ((s>='a') && (s<='f'))       ans+=(s-'a'+10);
+
+    return ans;
+}
+
+
+static SDL_Color* get_color(const char* in)
+{
+    char* col;
+    SDL_Color* out=malloc(sizeof(SDL_Color));
+    col = get_quote(in);
+    
+    if ((strlen(col)==7) && (col[0] == '#')) {
+        out->r = hex2int( col[1], col[2] );
+        out->g = hex2int( col[3], col[4] );
+        out->b = hex2int( col[5], col[6] );
+    }
+    
+    free(col);
+    
+    return out;
+}
+
+scriptType* curScript = NULL;
+pageType* curPage = NULL;
+itemType* curItem = NULL;
+
+static int load_script(const char* fn)
+{
+  int i;
+  char str[FNLEN];
+  FILE* f = NULL;
+    
+  DEBUGCODE
+  {
+    fprintf(stderr, "\nEnter load_script() - attempt to load '%s'\n", fn);
+  }
+
+  if (curScript)
+  {
+    LOG( "previous script in memory, removing now!\n");
+    close_script();
+  }
+    
+
+  f = fopen(fn, "r");
+
+  if (f == NULL)
+  {
+    fprintf(stderr, "error loading script %s\n", fn);
+    return -1;
+  }
+
+  do
+  {
+    fscanf(f, "%[^\n]\n", str);
+    if (strncmp("<script", str, 7) == 0)
+    {
+      /* -- allocate space for the lesson info -- */
+      curScript = (scriptType*)calloc(1, sizeof(scriptType));
+      for (i = 7; i < strlen(str) && str[i] != '>'; i++) 
+      {
+        if ((str[i] == 't') && strncmp("title", &str[i], 5) == 0)
+          curScript->title = get_quote(&str[i + 5]);
+
+        if ((str[i]=='b') && strncmp("bgcolor", &str[i], 7) == 0)
+          curScript->bgcolor = get_color(&str[i + 7]);
+
+        if ((str[i]=='b') && strncmp("background", &str[i], 10) == 0)
+          curScript->background = get_quote(&str[i + 10]);
+
+        if ((str[i]=='f') && strncmp("fgcolor", &str[i], 7) == 0) 
+          curScript->fgcolor = get_color(&str[i + 7]); 
+      }
+    }
+    else if (strncmp("<page", str,  5)==0)
+    {
+      if (curScript==NULL)
+      {
+        fprintf(stderr, "CRITICAL XML ERROR: <page> should be in a <script> in file %s line (todo)", fn); exit(1);
+      }
+
+      if (curScript->pages==NULL)
+      {
+        curPage = (pageType *)calloc(1,sizeof(pageType));
+        curPage->prev = curPage;
+        curScript->pages = curPage; 
+      }
+      else
+      {
+        curPage->next = (pageType*)calloc(1, sizeof(pageType));
+        curPage->next->prev = curPage;
+        curPage = curPage->next;
+      }
+
+      for (i = 5; i < strlen(str) && str[i]!='>'; i++)
+      {
+        if ((str[i] == 'b') && strncmp("background", &str[i], 10) == 0) 
+          curPage->background = get_quote(&str[i + 10]);
+
+        if ((str[i]== 't') && strncmp("title", &str[i], 5) == 0) 
+          curPage->title = get_quote(&str[i + 5]);
+
+        if ((str[i] == 'b') && strncmp("bgcolor", &str[i], 7) == 0) 
+          curPage->bgcolor = get_color(&str[i + 7]);
+
+        if ((str[i] == 'f') && strncmp("fgcolor", &str[i], 7) == 0) 
+          curPage->fgcolor = get_color(&str[i + 7]);
+      }
+    }
+    else if (strncmp("<text", str,  5) == 0)
+    {
+      if (curPage == NULL)
+      {
+        fprintf(stderr, "CRITICAL XML ERROR: <text> should be in a <page> in file %s line (todo)", fn); exit(1);
+      }
+
+      if (curPage->items == NULL) 
+      {
+        curItem = (itemType*)calloc(1, sizeof(itemType));
+        curPage->items = curItem;
+      }
+      else
+      {
+        curItem->next = (itemType*)calloc(1, sizeof(itemType));
+        curItem = curItem->next;
+      }
+
+      curItem->type = itemTEXT;
+      curItem->x = curItem->y = -1;
+
+      for (i = 5; i<strlen(str) && str[i]!='>'; i++)
+      {
+        if ((str[i] == 's') && strncmp("size", &str[i], 4) == 0)
+          curItem->size = (char)get_int(&str[i + 4]);
+
+        if ((str[i] == 'a') && strncmp("align", &str[i], 5) == 0)
+        {
+          char* t = get_quote(&str[i+5]);
+
+          if (strlen(t)>=1)
+          {
+            if ((t[0] == 'l') || (t[0]=='L'))
+              curItem->align='l';	// left
+            if ((t[0] == 'c') || (t[0]=='C'))
+              curItem->align='c';	// center
+            if ((t[0] == 'r') || (t[0]=='R'))
+              curItem->align='r';	// right
+            if ((t[0] == 'm') || (t[0]=='M'))
+              curItem->align='c';	// let 'm'iddle work as "center"
+          }
+          free(t);
+        }
+
+        if ((str[i] == 'c') && strncmp("color", &str[i], 5) == 0)
+           curItem->color = get_color(&str[i + 5]);
+
+        if ((str[i]== 'x') && strncmp(" x=", &str[i - 1], 3) == 0)
+           curItem->x = get_int(&str[i + 2]);
+
+        if ((str[i] == 'y') && strncmp(" y=", &str[i - 1], 3) == 0)
+           curItem->y = get_int(&str[i + 2]);
+      }
+
+      /* --- grab the text between <text> and </text> --- */
+      {
+        int start, finish;
+
+        for (start = 5; start < strlen(str) - 5 && str[start] != '>'; start++);
+
+        start++; // advance passed the '>'
+
+        for (finish = strlen(str) - 6; finish > 5; finish--)
+           if (strncmp( "</text>", &str[finish], 7) == 0)
+             break;
+
+        finish--; // advance passed the '<'
+
+        if (start <= finish)
+        {
+          curItem->data = (char*)calloc(1, finish - start + 2);
+          strncpy(curItem->data, &str[start], finish - start + 1);
+        }
+        else
+        {
+          if (start == finish + 1)
+          {
+            curItem->data = (char*)calloc(1, 2);
+            curItem->data[0]=' ';
+          }
+        }
+      }
+
+    } 
+    else if (strncmp("<img", str, 4) == 0)
+    {
+      if (curPage == NULL)
+      {
+        fprintf(stderr,
+                "CRITICAL XML ERROR: <img> should be in a <page> in file %s line (todo)",
+               fn);
+        exit(1); //FIXME should call cleanup() or maybe just return without exiting
+      }
+
+      if (curPage->items == NULL)
+      {
+        curItem = (itemType*)calloc(1, sizeof(itemType));
+        curPage->items = curItem;
+      }
+      else 
+      {
+        curItem->next = (itemType*)calloc(1, sizeof(itemType));
+        curItem = curItem->next;
+      }
+
+      curItem->type = itemIMG;
+      curItem->x = curItem->y = -1;
+
+      for (i = 5; i < strlen(str); i++) 
+      {
+        if ((str[i] == 'o') && strncmp("onclickplay", &str[i], 11) == 0)
+          curItem->onclick = get_quote(&str[i + 3]);
+
+        if ((str[i] == 'x') && strncmp(" x=", &str[i - 1], 3) == 0)
+          curItem->x = get_int(&str[i + 2]);
+
+        if ((str[i] == 'y') && strncmp(" y=", &str[i - 1], 3) == 0)
+          curItem->y = get_int(&str[i + 2]);
+
+        if ((str[i] == 's') && strncmp("src", &str[i], 3) == 0)
+          curItem->data = get_quote(&str[i + 3]);
+
+        if ((str[i] == 'a') && strncmp("align", &str[i], 5) == 0)
+        {
+          char* t = get_quote(&str[i + 5]);
+
+          if (strlen(t) >= 1)
+          {
+            if ((t[0] == 'l') || (t[0] == 'L'))
+               curItem->align='l';	// left
+
+            if ((t[0] == 'c') || (t[0]=='C'))
+               curItem->align='c';	// center
+
+            if ((t[0] == 'r') || (t[0]=='R'))
+               curItem->align='r';	// right
+
+            if ((t[0] == 'm') || (t[0]=='M'))
+               curItem->align='c';	// let 'm'iddle work as "center"
+          }
+          free(t);
+        }
+      }
+    }
+    else if (strncmp("<wav", str, 4) == 0)
+    {
+      if (curPage == NULL)
+      { 
+        fprintf(stderr,
+                "CRITICAL XML ERROR: <wav> should be in a <page> in file %s line (todo)",
+                fn);
+        exit(1);  /* FIXME call Cleanup() to exit */
+      }
+
+      if (curPage->items == NULL)
+      {
+        curItem = (itemType*)calloc(1, sizeof(itemType));
+        curPage->items = curItem;
+      } 
+      else 
+      {
+        curItem->next = (itemType*)calloc(1, sizeof(itemType));
+        curItem = curItem->next;
+      }
+
+      curItem->type = itemWAV;
+      curItem->loop = 0;
+
+      for (i =5 ; i < strlen(str); i++)
+      {
+        if ((str[i] == 's') && strncmp("src", &str[i], 3) ==0 )
+          curItem->data = get_quote(&str[i + 3]);
+
+        if ((str[i] == 'l') && strncmp("loop", &str[i], 4) == 0)
+        {
+          char* t = get_quote(&str[i + 4]);
+
+          if (strlen(t) >= 1)
+          {
+            if ((t[0] == 't') || (t[0]=='T'))
+              curItem->loop = 1;
+          } 
+          free(t);
+        }
+      }
+    }
+    else if (strncmp("<prac", str, 5) == 0)
+    {
+      if (curPage == NULL)
+      {
+        fprintf(stderr,
+                "CRITICAL XML ERROR: <prac> should be in a <page> in file %s line (todo)",
+                fn);
+        exit(1); /* FIXME call cleanup() rather than exit() */
+      }
+
+      if (curPage->items == NULL)
+      {
+        curItem = (itemType*)calloc(1, sizeof(itemType));
+        curPage->items = curItem;
+      }
+      else
+      {
+        curItem->next = (itemType*)calloc(1, sizeof(itemType));
+        curItem = curItem->next;
+      }
+
+      curItem->type = itemPRAC;
+
+      for (i = 5; i < strlen(str) && str[i] != '>'; i++)
+      {
+        if ((str[i] == 's') && strncmp("size", &str[i], 4) == 0) 
+          curItem->size = (char)get_int( &str[i + 4]);
+
+        if ((str[i] == 'g') && strncmp("goal", &str[i], 4) == 0) 
+          curItem->goal = (char)get_int(&str[i + 4]);
+
+        if ((str[i] == 'a') && strncmp("align", &str[i], 5) == 0)
+        {
+          char* t = get_quote(&str[i + 5]);
+
+          if (strlen(t) >= 1)
+          {
+            if ((t[0] == 'l') || (t[0]=='L'))
+              curItem->align = 'l';	// left
+            if ((t[0] == 'c') || (t[0]=='C'))
+              curItem->align = 'c';	// center
+            if ((t[0] == 'r') || (t[0]=='R'))
+              curItem->align = 'r';	// right
+            if ((t[0] == 'm') || (t[0]=='M'))
+              curItem->align = 'c';	// let 'm'iddle work as "center"
+          }
+                   free(t);
+        }
+
+        if ((str[i] == 'c') && strncmp("color", &str[i], 5) == 0)
+          curItem->color = get_color(&str[i + 5]);
+      }
+
+      { /* --- grab the text between <prac> and </prac> --- */
+        int start, finish;
+
+        for (start = 5; start < strlen(str) - 5 && str[start] != '>'; start++);
+
+        start++; // advance passed the '>/* --- grab the text between <prac> and </prac> --- */'
+
+        for (finish = strlen(str) - 6; finish > 5; finish--)
+          if (strncmp("</prac>", &str[finish], 7) == 0)
+            break;
+
+        finish--; // advance passed the '<'
+
+        if (start <= finish)
+        {
+          curItem->data = (char*)calloc(1, finish - start + 2);
+          strncpy(curItem->data, &str[start], finish - start + 1);
+        }
+        else
+        {
+          if (start == finish + 1)
+          {
+            curItem->data = (char*)calloc(1, 2);
+            curItem->data[0]=' ';
+          }
+        }
+      }
+    }
+    else if (strncmp("<waitforinput", str, 13) == 0)
+    { 
+      if (curPage == NULL)
+      {
+        fprintf(stderr,
+               "CRITICAL XML ERROR: <waitforinput> should be in a <page> in file %s line (todo)",
+                fn);
+        exit(1);
+      }
+
+      if (curPage->items == NULL)
+      {
+        curItem = (itemType*)calloc(1, sizeof(itemType));
+        curPage->items = curItem;
+      } 
+      else
+      {
+        curItem->next = (itemType*)calloc(1, sizeof(itemType));
+        curItem = curItem->next;
+      }
+
+      curItem->type = itemWFIN;
+
+    }
+    else if (strncmp("<waitforchar",  str, 12) == 0)
+    { 
+      if (curPage == NULL)
+      {
+        fprintf(stderr,
+               "CRITICAL XML ERROR: <waitforchar> should be in a <page> in file %s line (todo)",
+               fn);
+        exit(1);
+      }
+
+      if (curPage->items == NULL)
+      {
+        curItem = (itemType*)calloc(1, sizeof(itemType));
+        curPage->items = curItem;
+      }
+      else
+      {
+        curItem->next = (itemType*)calloc(1, sizeof(itemType));
+        curItem = curItem->next;
+      }
+
+      curItem->type = itemWFCH;
+    }
+    else if (strncmp("</",str, 2) == 0)
+    {
+      /* do nothing */
+    }
+    else
+      fprintf(stderr, "not recognized: %s\n", str); 
+
+  } while(!feof(f));
+
+  fclose(f);
+
+  LOG("Leave load_script()\n");
+
+  return 0;
+}
+
+
+static void run_script(void)
+{
+  /* FIXME FNLEN doesn't make sense for size of these arrays */
+  Mix_Chunk* sounds[FNLEN] = {NULL};
+
+  /* --- for on mouse click on an image --- */
+  Mix_Chunk* clickWavs[FNLEN] = {NULL};
+  SDL_Rect   clickRects[FNLEN];
+
+  LOG("\nEnter run_script()\n");
+
+  if (!curScript)
+  {
+    fprintf(stderr, "run_script() - Error: curScript is NULL\n");
+    return;
+  }
+
+  curPage = curScript->pages;
+
+  while (curPage)
+  {
+    int y = 0;
+    int skip = 0;
+    int numWavs = 0;
+    int numClicks = 0;
+
+    curItem = curPage->items;
+
+    /* --- setup background color --- */
+    if (curPage->bgcolor)
+      SDL_FillRect( screen, NULL, COL2RGB(curPage->bgcolor));
+    else if (curScript->bgcolor)
+      SDL_FillRect(screen, NULL, COL2RGB(curScript->bgcolor));
+
+    /* --- setup background image --- */
+    if (curPage->background)
+    {
+      SDL_Surface* img = LoadImage(curPage->background, IMG_ALPHA|IMG_NOT_REQUIRED);
+      SDL_BlitSurface(img, NULL, screen, NULL);
+      SDL_FreeSurface(img);
+    }
+    else if (curScript->background)
+    {
+      SDL_Surface* img = LoadImage(curScript->background, IMG_ALPHA|IMG_NOT_REQUIRED);
+      SDL_BlitSurface(img, NULL, screen, NULL);
+      SDL_FreeSurface(img);
+    }
+
+    /* --- go through all the items in the page --- */
+    while (curItem)
+    {
+      switch (curItem->type)
+      {
+        case itemIMG:
+        {
+          SDL_Surface* img = LoadImage(curItem->data, IMG_ALPHA|IMG_NOT_REQUIRED);
+          if (img)
+          {
+            /* --- figure out where to put it! --- */
+            SDL_Rect loc;
+            loc.w = img->w;
+            loc.h = img->h;
+
+            /* --- if user specifies y location, use it --- */
+            if (curItem->y >= 0)
+            {
+              loc.y = curItem->y;
+            }
+            else
+            {
+              loc.y = y;
+              y += loc.h;
+            }
+
+            /* --- if user specifies x location, use it --- */
+            if (curItem->x >= 0)
+            {
+              loc.x = curItem->x;
+            }
+            else
+            {
+              switch (curItem->align)
+              {
+                case 'r':
+                  loc.x = (screen->w) - (loc.w);
+                  break;
+                case 'c':
+                  loc.x = ((screen->w) - (loc.w))/2;
+                  break;
+                default:
+                  loc.x = 0;
+                  break;
+              }
+            }
+
+            /* --- and blit! --- */
+            SDL_BlitSurface(img, NULL, screen, &loc);
+
+            /* --- does it do click and play --- */
+            if (curItem->onclick)
+            {
+              if (settings.sys_sound)
+                clickWavs[numClicks] = LoadSound(curItem->onclick);
+              clickRects[numClicks].x = loc.x;
+              clickRects[numClicks].y = loc.y;
+              clickRects[numClicks].w = loc.w;
+              clickRects[numClicks].h = loc.h;
+              numClicks++;
+            }
+          }
+          SDL_FreeSurface(img);
+          break;
+        }
+
+        case itemTEXT:
+        {
+          TTF_Font* myFont;
+          SDL_Surface* img;
+          SDL_Color* col;
+
+          int shown, toshow, w, h; // used to wrap text
+          char tmp[FNLEN];   // used to hold temp text for wrapping
+
+          /* --- create font & render text --- */
+          if (curItem->size > 0)
+            myFont = LoadFont(settings.theme_font_name, (int)curItem->size);
+          else
+            myFont = LoadFont(settings.theme_font_name, 24); // default size is 24
+
+          if (curItem->color)
+            col = curItem->color;
+          else if (curPage->fgcolor)
+            col = curPage->fgcolor;
+          else if (curScript->fgcolor)
+            col = curScript->fgcolor;
+          else 
+            col = &white;
+
+          shown = 0;
+
+
+          do 
+          {
+            int ok = 0;
+
+            if ((shown > 0) && (curItem->data[shown] == ' '))
+              shown++;
+            strncpy(tmp, &curItem->data[shown], FNLEN - 1);
+            tmp[FNLEN - 1] = 0;
+            tmp[strlen(curItem->data) - shown] = 0;
+
+            for (toshow = strlen(&curItem->data[shown]); !ok; toshow--)
+            {
+              if (toshow + 1 > FNLEN)
+                continue;
+
+              tmp[toshow] = 0;
+              TTF_SizeText(myFont, tmp, &w, &h);
+
+              if (w + 20 < screen->w)
+                ok = 1;
+            }
+
+            shown += toshow + 1;
+
+            img = TTF_RenderUTF8_Blended(myFont, tmp, *col);
+
+            if (img)
+            {
+              SDL_Rect loc;
+              /* --- figure out where to put it! --- */
+              loc.w = img->w;
+              loc.h = img->h;
+
+              /* --- if user specifies y location, use it --- */
+              if (curItem->y >= 0)
+                loc.y = curItem->y;
+              else 
+                loc.y=y; y+=loc.h;
+
+              /* --- if user specifies x location, use it --- */
+              if (curItem->x >= 0)
+                loc.x = curItem->x;
+              else 
+              {
+                switch (curItem->align)
+                {
+                  case 'r':
+                    loc.x = (screen->w) - (loc.w);
+                    break;
+                  case 'c':
+                    loc.x = ((screen->w) - (loc.w))/2;
+                    break;
+                  default:
+                    loc.x = 0;
+                  break;
+                }
+              }
+
+              /* --- and blit! --- */
+              SDL_BlitSurface( img, NULL, screen, &loc );
+              SDL_FreeSurface( img );
+            }
+                    
+          } while (shown + 1 < strlen(curItem->data));
+
+          TTF_CloseFont(myFont);
+          break;
+        }
+
+
+        case itemWAV:
+        {
+          // HACK, we need to make sure no more than 8 sounds or so..
+          sounds[numWavs] = LoadSound( curItem->data );
+          Mix_PlayChannel( numWavs, sounds[numWavs], -curItem->loop );
+          numWavs++;
+          break;
+        }
+
+
+        case itemWFIN:
+        {
+          int done = 0;
+
+          // Make sure everything is on screen 
+          SDL_Flip(screen);
+
+          while (!done)
+          {
+            SDL_Delay(100);
+
+            while (SDL_PollEvent(&event))
+            {
+              switch (event.type)
+              {
+                case SDL_MOUSEBUTTONDOWN:
+                {
+                  int j;
+
+                  for (j=0; j<numClicks; j++) 
+                  {
+                    if (inRect(clickRects[j], event.button.x, event.button.y))
+                     Mix_PlayChannel(numWavs + j, clickWavs[j], 0);
+                  }
+                  break;
+                }
+
+                case SDL_QUIT:
+                {
+                  curPage = NULL;
+                  done = 1;
+                  break;
+                }
+
+                case SDL_KEYDOWN: 
+                {
+                  switch (event.key.keysym.sym)
+                  {
+                    case SDLK_ESCAPE: 
+                      curPage = NULL;
+                      done = 1;
+                      break;  // quit
+                    case SDLK_LEFT: 
+                      curPage = curPage->prev;
+                      done = 1;
+                      break;
+                    case SDLK_RIGHT:
+                    case SDLK_SPACE:
+                    case SDLK_RETURN:
+                      curPage = curPage->next;
+                      skip = 1;
+                      done = 1;
+                      break;
+                    default:
+                      break;
+                  };
+
+                  break;
+                }
+              }
+            }
+          }
+        }
+        break;
+
+
+        case itemWFCH:
+        {
+          int done = 0;
+          // Make sure everything is on screen 
+          SDL_Flip(screen);
+
+          while (!done)
+          {
+            SDL_Delay(100);
+            while (SDL_PollEvent(&event))
+            {
+              switch (event.type)
+              {
+                case SDL_QUIT:
+                {
+                  curPage = NULL;
+                  done = 1;
+                  break;
+                }
+
+                case SDL_KEYDOWN: 
+                {
+                  switch (event.key.keysym.sym)
+                  {
+                    case SDLK_ESCAPE: 
+                    {
+                      curPage = NULL;
+                      done = 1;
+                      break;  // quit
+                    }
+                    case SDLK_p:
+                    {
+                      curPage = curPage->next;
+                      done = 1;
+                      break;
+                    }
+                    default:
+                      break;
+                  };
+                  break;
+                }
+              }
+            }
+          }
+        }
+        break;
+
+        case itemPRAC:
+        {
+          wchar_t wide_buf[FNLEN];
+          ConvertFromUTF8(wide_buf, curItem->data);
+          if (curItem->goal > 0)
+          {
+            //printf( "goal is %d\n", curItem->goal );
+            Phrases(wide_buf);
+          }
+          else
+          {
+            //printf( "No goal \n" );
+            Phrases(wide_buf);
+          }
+          break;
+        }
+
+        default:
+        {
+          /* do nothing */
+        }
+      }
+
+      if (curItem->next == NULL && curPage != NULL)
+      {
+        if (!skip)
+        {
+          curPage = curPage->next;
+          skip = 0;
+        }
+        break;
+      }
+      else
+        curItem = curItem->next;
+    }
+    SDL_Flip(screen);
+    SDL_Delay(30);
+        
+        
+    /* --- cleanup memory --- changing pages --- */
+    { 
+      int i;
+
+      if (settings.sys_sound)
+      {
+        for (i=0; i<numWavs; i++)
+        {
+          Mix_HaltChannel(i);
+          Mix_FreeChunk(sounds[i]);
+        }
+
+        for (i = 0; i < numClicks; i++)
+        {
+          Mix_HaltChannel(i + numWavs);
+          Mix_FreeChunk(clickWavs[i]);
+        }
+      }
+    }
+
+  } /* --- End of "while (curPage)" loop ----*/
+
+  LOG("Leave run_script()\n");
+}
+
+
+static void clear_items(itemType* i)
+{
+    itemType* n;
+
+    /* if i is null, will return harmlessly: */
+    while (i) {
+        n = i->next;  // remember the next guy
+
+        /* -- remove any data we are pointing to -- */
+        free(i->data);
+        free(i->onclick);
+        free(i->color);
+
+        /* -- remove ourselves --*/
+        free(i);
+
+        /* -- on to the next guy! -- */
+        i = n;
+    }
+}
+
+static void clear_pages(pageType* p)
+{
+    pageType* n;
+
+    /* if p is null, will return harmlessly: */
+    while (p) {
+        n = p->next;  // remember the next guy
+
+        /* -- remove all of our sub elements -- */
+        clear_items(p->items);
+
+        /* -- free anything we are pointing to --- */
+        free(p->background);
+        free(p->title);
+        free(p->bgcolor);
+        free(p->fgcolor);
+
+        /* -- free ourselves -- */
+        free(p);
+
+        /* -- on to the next --*/
+        p = n;
+    }
+}
+
+
+static void close_script(void)
+{
+  if (curScript)
+  {
+    /* -- remove all the pages we have --*/
+    clear_pages(curScript->pages);
+
+    /* -- remove attributes we are pointing to -- */
+    free(curScript->title);
+    free(curScript->bgcolor);
+    free(curScript->fgcolor);
+    free(curScript->background);
+
+    /* -- free yourself -- */
+    free(curScript); 
+
+    /* -- and remember you did -- */
+    curScript = NULL;
+  }
+}
+
+
+
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/scripting.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/scripting.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/scripting.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/scripting.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,64 @@
+/***************************************************************************
+ -  file: scripting.h
+ -  description: types for scripting 
+-------------------
+    begin                : Sun Dec 28, 2003
+    copyright            : Jesse Andrews (C) 2003
+    email                : tuxtype-dev at tux4kids.net
+***************************************************************************/
+
+/***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+
+enum { itemTEXT, itemIMG, itemWAV, itemPRAC, itemWFIN, itemWFCH };
+
+/* linked list of elements for a page */
+struct item {
+        char type;		// text or img or wav enum type?
+        char *data;		// holds text/location for file (sound/image)
+        char *onclick;		// holds additional data
+        char size;		// holds font size if applicable
+        char align;             // holds 'L'eft, 'R'ight, 'C'enter for alignment
+        char loop;		// holds if sound files loop
+        int  goal;		// goal for practice session
+	int  x,y;		// for absolute positioning
+        SDL_Color *color;       // holds text color
+        
+        struct item *next; // the linked list part ... 
+};
+
+typedef struct item itemType;
+
+/* linked list of pages for a lesson */
+struct page {
+    itemType *items;	// linked list of elements
+    char *background;		// background image
+    char *title;		// title of the page
+    SDL_Color *bgcolor;		// background color
+    SDL_Color *fgcolor;		// default text color
+    
+    struct page *next;         // the linked list part ...
+    struct page *prev;         // the doubly-linked list part ...
+};
+
+typedef struct page pageType;
+
+struct script {
+    pageType *pages;		// linked list of pages
+    char *title;		// title of lesson
+    SDL_Color *bgcolor;         // default background color for all pages
+    SDL_Color *fgcolor;         // default foreground color for all text
+    char *background;		// default background image for all pages
+}; 
+
+typedef struct script scriptType;
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/setup.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/setup.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/setup.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/setup.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,532 @@
+/***************************************************************************
+                          setup.c 
+ -  description: Init SDL
+                             -------------------
+    begin                : Thu May 4 2000
+    copyright            : (C) 2000 by Sam Hart
+                         : (C) 2003 by Jesse Andrews
+    email                : tuxtype-dev at tux4kids.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+
+#define NUM_PATHS 4
+
+
+/* FIXME this is a hack that can have unintended results */
+/* if the program is run from a path that has 'data' as a */
+/* subdir */
+const char PATHS[NUM_PATHS][FNLEN] = 
+{
+  DATA_PREFIX"/share/"PACKAGE"/data",
+  "/usr/share/"PACKAGE"/data",
+  "/usr/local/share/"PACKAGE"/data",
+  "./data"
+};
+
+uint fs_res_x = 0;
+uint fs_res_y = 0;
+
+/* Local function prototypes: */
+static int load_settings_fp(FILE* fp);
+static int load_settings_filename(const char* fn);
+
+/***************************
+	GraphicsInit: Initializes the graphic system
+****************************/
+void GraphicsInit(void)
+{
+  const SDL_VideoInfo* video_info = SDL_GetVideoInfo();
+  Uint32 surface_mode = 0;
+
+  if (video_info->hw_available)
+  {
+    surface_mode = SDL_HWSURFACE;
+    LOG("HW mode\n");
+  }
+  else
+  {
+    surface_mode = SDL_SWSURFACE;
+    LOG("SW mode\n");
+  }
+
+  // Determine the current resolution: this will be used as the
+  // fullscreen resolution, if the user wants fullscreen.
+  DEBUGCODE
+  {
+    fprintf(stderr, "Current resolution: w %d, h %d.\n", 
+            video_info->current_w, video_info->current_h);
+  }
+
+  /* For fullscreen, we try to use current resolution from OS: */
+  
+  fs_res_x = video_info->current_w;
+  fs_res_y = video_info->current_h;
+
+  if (settings.fullscreen == 1)
+  {
+    screen = SDL_SetVideoMode(fs_res_x, fs_res_y, BPP, SDL_FULLSCREEN | surface_mode);
+    if (screen == NULL)
+    {
+      fprintf(stderr,
+            "\nWarning: I could not open the display in fullscreen mode.\n"
+            "The Simple DirectMedia error that occured was:\n"
+            "%s\n\n", SDL_GetError());
+      settings.fullscreen = 0;
+    }
+  }
+
+  /* Either fullscreen not requested, or couldn't get fullscreen in SDL: */
+  if (settings.fullscreen == 0)
+  {
+    screen = SDL_SetVideoMode(RES_X, RES_Y, BPP, surface_mode);
+  }
+
+  /* Failed to get a usable screen - must bail out! */
+  if (screen == NULL)
+  {
+    fprintf(stderr,
+          "\nError: I could not open the display.\n"
+          "The Simple DirectMedia error that occured was:\n"
+          "%s\n\n", SDL_GetError());
+    exit(2);
+  }
+
+// 	LOG( "GraphicsInit - Initialize graphic system\n" );
+// 
+// 	DEBUGCODE {
+// 		fprintf(stderr, "-SDL Setting VidMode to %ix%ix%i\n", RES_X, RES_Y, BPP);
+// 	}
+// 
+// 	/* NOTE fullscreen vs. windowed is indicated by video_flags: */
+// 	if (settings.fullscreen)
+//         {
+// 	  video_flags = (SDL_FULLSCREEN | SDL_SWSURFACE | SDL_HWPALETTE);
+// 	} 
+//         else
+//         {
+// 	  video_flags = (SDL_SWSURFACE | SDL_HWPALETTE);
+// 	}
+// 
+// 	screen = SDL_SetVideoMode(RES_X, RES_Y, BPP, video_flags);
+// 
+// 	if (screen == NULL) {
+// 		fprintf(stderr, "Couldn't set %ix%i video mode: %s\n", RES_X, RES_Y, SDL_GetError());
+// 		exit(2);
+// 	}
+
+
+	LOG( "SDL_SetClipRect(screen, NULL):\n" );
+
+	SDL_SetClipRect(screen, NULL); // Let's set the appropriate clip rect  -- JA: is neccessary???  
+
+	LOG( "SDL_ShowCursor(0):\n" );
+
+	SDL_ShowCursor(0); // no cursor please
+
+	LOG( "SDL_WM_SetCaption(\"Tux Typing\", PACKAGE);\n" );
+
+	SDL_WM_SetCaption("Tux Typing", "tuxtype"); // Set window manager stuff
+
+	/* --- setup color we use --- */
+	black.r       = 0x00; black.g       = 0x00; black.b       = 0x00;
+        gray.r        = 0x80; gray.g        = 0x80; gray.b        = 0x80;
+	dark_blue.r   = 0x00; dark_blue.g   = 0x00; dark_blue.b   = 0x60; 
+	red.r         = 0xff; red.g         = 0x00; red.b         = 0x00;
+	white.r       = 0xff; white.g       = 0xff; white.b       = 0xff;
+	yellow.r      = 0xff; yellow.g      = 0xff; yellow.b      = 0x00; 
+
+	InitEngine();
+
+  DEBUGCODE 
+  {
+    video_info = SDL_GetVideoInfo();
+    fprintf(stderr, "-SDL VidMode successfully set to %ix%ix%i\n",
+            video_info->current_w,
+            video_info->current_h,
+            video_info->vfmt->BitsPerPixel);
+  }
+
+	LOG( "GraphicsInit():END\n" );
+}
+
+/****************************
+	LibInit : Init the SDL
+	library
+*****************************/
+void LibInit(Uint32 lib_flags)
+{
+	LOG( "LibInit():\n-About to init SDL Library\n" );
+
+	if (SDL_Init(lib_flags) < 0) 
+		/* FIXME this looks wrong - if no sys_sound, we don't init video??? */
+		if (settings.sys_sound) {
+			if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+				fprintf(stderr, "Couldn't initialize SDL: %s\n",
+				SDL_GetError());
+				exit(2);
+			} else {
+				LOG( "Couldn't initialize SDL Sound\n" );
+				settings.sys_sound = 0;
+			}
+		}
+
+
+//	atexit(SDL_Quit); // fire and forget... 
+
+	LOG( "-SDL Library init'd successfully\n" );
+
+	/* FIXME should read settings before we do this: */ 
+	if (settings.sys_sound)
+        { 
+          if (Mix_OpenAudio(22050, AUDIO_S16, 1, 2048) == -1)
+          {
+            fprintf( stderr, "Warning: couldn't set 22050 Hz 8-bit audio\n - Reasons: %s\n", SDL_GetError());
+            settings.sys_sound=0;
+          }
+          else
+            LOG("Mix_OpenAudio() successful\n");
+        }
+
+	LOG( "-about to init SDL_ttf\n" );
+
+	if (TTF_Init() < 0) {
+		fprintf( stderr, "Couldn't initialize SDL_ttf\n" );
+		exit(2);
+	}
+
+//	atexit(TTF_Quit);
+
+	SDL_EnableKeyRepeat( 0, SDL_DEFAULT_REPEAT_INTERVAL );
+	/* Need this to get Unicode values from keysyms: */
+	SDL_EnableUNICODE(1);
+
+	LOG( "LibInit():END\n" );
+}
+
+/* Load the settings from a file... make sure to update SaveSettings if you change
+ *  what can be saved/loaded 
+ */
+void LoadSettings(void)
+{
+  char fn[FNLEN];
+// 	char setting[FNLEN];
+// 	char value[FNLEN];
+//	FILE *settingsFile;
+	
+  /* set the settings directory/file */
+
+#ifdef WIN32
+  snprintf(fn, FNLEN - 1, "userdata/settings.txt");
+  LOG("WIN32 defined\n");
+#else
+  snprintf(fn, FNLEN - 1, (const char*)"%s/.tuxtype/settings.txt", getenv("HOME"));
+  LOG("WIN32 not defined\n");
+#endif
+
+  DEBUGCODE { printf("LoadSettings: settings file is '%s'\n", fn ); }
+
+  LOG("LoadSettings: trying to open settings file\n");
+
+  load_settings_filename(fn);
+}
+
+
+
+/* Load the settings if given the complete pathname to the settings file.  Returns 1 if
+   able to call load_settings_fp() successfully on named file.
+ */
+static int load_settings_filename(const char* fn)
+{
+  FILE* fp = fopen(fn, "r");
+
+  if (!fp)
+  {
+    fprintf(stderr, "load_settings_filename(): no theme-specific settings found%s\n",fn);
+    return;
+  }
+	
+  if (!load_settings_fp(fp))
+  {
+    fprintf(stderr, "No settings in settings file.\n");
+    fclose(fp); /* still need to close fp */
+    return 0;
+  }
+
+  /* Success! */
+  fclose(fp);
+  return 1;
+}
+
+
+/* Load the settings if given an open FILE* pointer to the settings file.  Returns 1 if
+   at least one setting value found, 0 otherwise. It does not close the FILE*.
+ */
+static int load_settings_fp(FILE* fp)
+{
+  char setting[FNLEN]; /* these don't really need to be 'FNLEN' long */
+  char value[FNLEN];
+  int setting_found = 0;
+
+  if (!fp)
+  {
+    fprintf(stderr, "load_settings_fp() - FILE* parameter NULL\n");
+    return 0;
+  }
+
+  /* we load all the settings here */
+  while (!feof(fp))
+  {
+    fscanf(fp, "%[^=]=%[^\n]\n", setting, value );
+
+    DEBUGCODE {fprintf(stderr, "%s = %s", setting, value );}
+
+    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 lives to %s\n", value);}
+      settings.o_lives = atoi(value);
+      setting_found = 1;
+   }
+    else if (strncmp( setting, "mus_volume", FNLEN ) == 0 )
+    {
+      DEBUGCODE {fprintf(stderr, "LoadSettings: Setting music volume to %s\n", value);}
+      settings.mus_volume = atoi(value);
+      setting_found = 1;
+    }
+    else if (strncmp(setting, "sfx_volume", FNLEN) == 0)
+    {
+      DEBUGCODE {fprintf(stderr, "LoadSettings: Setting effects volume to %s\n", value);}
+      settings.sfx_volume = atoi(value);
+      setting_found = 1;
+    }
+    else if (strncmp(setting, "menu_music", FNLEN) == 0)
+    {
+      DEBUGCODE {fprintf(stderr, "LoadSettings: Setting menu music to %s\n", value);}
+      settings.menu_music = atoi(value);
+      setting_found = 1;
+    }
+    else if (strncmp( setting, "fullscreen", FNLEN ) == 0 )
+    {
+      settings.fullscreen = atoi(value);
+      setting_found = 1;
+    }
+    else if (strncmp( setting, "theme_font_name", FNLEN ) == 0 )
+    {
+      DEBUGCODE {fprintf(stderr, "load_settings_fp(): Setting theme font to %s\n", value);}
+      strncpy(settings.theme_font_name, value, FNLEN - 1);
+      setting_found = 1;
+    }
+    else if (strncmp( setting, "theme_locale_name", FNLEN ) == 0 )
+    {
+      DEBUGCODE {fprintf(stderr, "load_settings_fp(): Setting theme locale to %s\n", value);}
+      strncpy(settings.theme_locale_name, value, FNLEN - 1);
+      setting_found = 1;
+      fprintf(stderr, "load_settings_fp(): Setting theme locale to %s\n", value);
+    }
+    else
+      DEBUGCODE {fprintf(stderr, "load_settings_fp(): unrecognized string: %s\n", value);}
+
+  }
+
+
+  if (setting_found)
+    return 1;
+  else
+  {
+    fprintf(stderr, "load_settings_fp() - no settings in file - empty or corrupt?\n");
+    return 0;
+  }
+}
+
+
+
+/* Save the settings from a file... make sure to update LoadSettings if you change
+ *  what can be saved/loaded 
+ */
+void SaveSettings(void)
+{
+	char fn[FNLEN];
+	FILE* settingsFile;
+	
+	/* set the settings directory/file */
+
+	#ifdef WIN32
+		_mkdir( "userdata" );  // just in case try to create save location
+		snprintf( fn, FNLEN-1, "userdata/settings.txt" );
+	#else
+		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype", getenv("HOME") );
+		mkdir( fn, 0755 ); // just in case try to create save location
+		snprintf( fn, FNLEN-1, (const char*)"%s/.tuxtype/settings.txt", getenv("HOME") );
+	#endif
+
+
+	DEBUGCODE { printf("SaveSettings: settings file is '%s'\n", fn ); }
+	
+	LOG("SaveSettings: trying to open settings file\n");
+	
+	settingsFile = fopen( fn, "w" );
+
+	if (settingsFile == NULL) {
+		printf("SaveSettings: Settings file cannot be created!\n");
+		return;
+	}
+	
+	/* Save all the settings here! */
+	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 );
+
+	fprintf( settingsFile, "mus_volume=%d\n", settings.mus_volume );
+	fprintf( settingsFile, "sfx_volume=%d\n", settings.sfx_volume );
+	fprintf( settingsFile, "menu_music=%d\n", settings.menu_music );
+	fprintf( settingsFile, "fullscreen=%d\n", settings.fullscreen);
+
+
+// 	if (screen->flags & SDL_FULLSCREEN){
+// 		fprintf( settingsFile, "fullscreen=%s\n", "1");
+// 	} else {
+// 		fprintf( settingsFile, "fullscreen=%s\n", "0");
+// 	}
+	fclose(settingsFile);
+}
+
+
+/* Check for default (English) and theme data paths and update settings struct. */
+/* Returns 0 if default data path not found, 1 if successfully located.         */
+/* If theme not found, still returns 1 but settings changed to use English.     */
+/* TODO should have this function set up the user and global settings paths.    */
+/* TODO settings should be re-loaded when theme changes.                        */
+
+int SetupPaths(const char* theme_dir)
+{
+  int i;
+  settings.use_english = 1; // default is to use English if we cannot find theme
+
+  /* First find default data path: */
+  for (i = 0; i < NUM_PATHS; i++)
+  {
+
+    DEBUGCODE
+    {
+      fprintf(stderr, "SetupPaths(): checking for '%s' as default data path\n", PATHS[i]);
+    }
+
+    if (CheckFile(PATHS[i]))
+    {
+      strncpy(settings.default_data_path, PATHS[i], FNLEN - 1);
+
+      DEBUGCODE
+      {
+        fprintf(stderr, "path '%s' found, copy to settings.default_data_path\n", PATHS[i]);
+      }
+      break;
+    }
+    else
+    {
+      DEBUGCODE
+      {
+        fprintf(stderr, "path '%s' not found.\n", PATHS[i]);
+      }
+    }
+  }
+
+  /* If we didn't find a data path, print error msg and get out: */
+  if (i >= NUM_PATHS) /* (shouldn't actually ever be > NUM_PATHS) */
+  {
+    fprintf(stderr, "SetupPaths(): Error - could not find data path.\n");
+    return 0;
+  }
+
+
+  /* Now look for theme directory: */
+  if (theme_dir != NULL)
+  {
+    char full_theme_path[FNLEN];
+    char theme_settings_path[FNLEN];
+
+    sprintf(full_theme_path, "%s/themes/%s", settings.default_data_path, theme_dir);
+
+    DEBUGCODE
+    {
+      fprintf(stderr, "SetupPaths(): checking for '%s' as theme path\n", full_theme_path);
+    }
+
+    if (CheckFile(full_theme_path)) /* Theme found - set it up! */
+    {
+      settings.use_english = 0;
+      strncpy(settings.theme_data_path, full_theme_path, FNLEN - 1);
+      DEBUGCODE
+      {
+        fprintf(stderr, "settings.theme_data_path is: %s\n", settings.theme_data_path);
+      }
+ 
+      strncpy(settings.theme_name, theme_dir, FNLEN - 1);
+      /* (Need to do this in case we are changing from a theme with */
+      /* a special font to a theme that uses the default, but lacks */
+      /* an explicit statement to use the default(                  */
+      strncpy(settings.theme_font_name, DEFAULT_MENU_FONT, FNLEN);
+      
+
+      /* Load fontname or any other theme-specific settings: */
+      sprintf(theme_settings_path, "%s/settings.txt", full_theme_path);
+
+      DEBUGCODE
+      {
+        fprintf(stderr, "theme_settings_path is: %s\n", theme_settings_path);
+      }
+
+      load_settings_filename(theme_settings_path);
+    }
+    else /* Theme not found! */
+    {
+      settings.use_english = 1; // default is to use English if we cannot find theme
+      strcpy(settings.theme_name, "");
+      strncpy(settings.theme_font_name, DEFAULT_MENU_FONT, FNLEN);
+      strncpy(settings.theme_locale_name, DEFAULT_LOCALE,FNLEN);
+      fprintf(stderr, "SetupPaths(): could not find '%s'\n", full_theme_path);
+    }
+  }
+  else /* No theme name passed as arg so just use English: */
+  {
+    settings.use_english = 1; // default is to use English if we cannot find theme
+    strcpy(settings.theme_name, "");
+    strncpy(settings.theme_locale_name, DEFAULT_LOCALE,FNLEN);
+  }
+
+
+  DEBUGCODE
+  {
+    fprintf(stderr, "Leaving SetupPaths():\n");
+    fprintf(stderr, "default_data_path: '%s'\n", settings.default_data_path);
+    fprintf(stderr, "theme_data_path: '%s'\n\n", settings.theme_data_path);
+  }
+  return 1;	
+}
+
+
+void Cleanup(void)
+{
+  SDL_FreeSurface(screen);
+  screen = NULL;
+
+  SDL_Quit();
+  TTF_Quit();
+}

Copied: tuxtype/branches/tuxtype-soc-mh/src/snow.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/snow.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/snow.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/snow.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,272 @@
+/***************************************************************************
+ -  file: snow.c
+ -  description: this file contains snow for the cascade game
+-------------------
+begin                : March 12, 2003
+copyright            : (C) 2003 Jesse Andrews
+email                : tuxtype-dev at tux4kids.net
+***************************************************************************/
+
+/***************************************************************************
+*                                                                         *
+*   This program is free software; you can redistribute it and/or modify  *
+*   it under the terms of the GNU General Public License as published by  *
+*   the Free Software Foundation; either version 2 of the License, or     *
+*   (at your option) any later version.                                   *
+*                                                                         *
+***************************************************************************/
+
+#include <stdlib.h>
+#include "SDL.h"
+
+/* while it looks like you can just
+ * change the number of planes, flakes,
+ * etc and it will work all right, it is not
+ * true.  Do not fiddle with number unless you
+ * change the rest of the code to be the same!
+ */
+
+#define NUM_PLANES 3
+
+extern SDL_Surface *screen;
+SDL_Surface* bkg;
+
+Uint16 snow_color;
+
+int wind = 0;
+int SNOW_on = 0;
+
+int NUM_FLAKES = 300;
+int PER_PLANE = 100; // should equal NUM_FLAKES/NUM_PLANES
+
+/* to get the real x location divide by 8 (>>3)
+ */
+struct {
+	int x;
+	int y;
+} flake[300];
+
+/* used for the SDL_UpdateRects */
+SDL_Rect SNOW_rects[1000];
+
+/* pass add_wind +/- 1 --- it just adds a fraction in that direction! */
+void add_wind( int dir ) {
+
+	/* don't let the wind blow too hard */
+	if ( wind * dir > 16 )
+		return;
+	
+	if (dir > 0)
+		wind++;
+	else
+		wind--;
+}
+
+/* ### INTERNAL FUNCTION ### 
+ * move_snow: updates the location of the flakes
+ * based upon the wind and different "planes"
+ * of the flakes
+ */
+void move_snow(void) {
+	int i;
+	static int slowframe=1;
+	int ws=wind;
+
+	slowframe = !slowframe;
+	/* even though we only move the "slowest" every other frame,
+	 * the code is still updating them every single frame!!!
+	 * the SNOW_Rect data structure will need to be updated to fix this!
+	 * slowframe just cycles between updating the slowest and not!
+	 */
+	if (slowframe) {
+		for (i = 0; i<PER_PLANE; i++) {
+			flake[i].x += ws;
+			flake[i].y ++;
+		}
+	}
+
+	for (i = PER_PLANE; i<PER_PLANE<<1; i++) {
+		flake[i].x += ws;
+		flake[i].y += 1;
+	}
+
+	ws<<=1;
+	for (i = PER_PLANE<<1; i<NUM_FLAKES; i++) {
+		flake[i].x += ws;
+		flake[i].y += 2;
+	} 
+
+	for (i = 0; i<NUM_FLAKES; i++) {
+		/* if a flake hits the bottom, move to top randomly */
+		if (flake[i].y >= 478) {
+			flake[i].y = 0;
+			flake[i].x = (int)(8*639.0*rand()/(RAND_MAX+1.0));
+		}
+
+		/* if a flake hists the edge, move to the other edge randomly */
+		if (flake[i].x >= 638<<3) {
+			flake[i].x = 0;
+			flake[i].y = (int)(478.0*rand()/(RAND_MAX+1.0));
+		} else if (flake[i].x < 0) {
+			flake[i].x = 8*637;
+			flake[i].y = (int)(478.0*rand()/(RAND_MAX+1.0));
+		}
+
+		/* the first NUM_FLAKES are for erasing the last frame's FLAKES */
+		SNOW_rects[i].x = SNOW_rects[NUM_FLAKES+i].x;
+		SNOW_rects[i].y = SNOW_rects[NUM_FLAKES+i].y;
+		/* the next NUM_FLAKES are for bliting the new positions this frame */
+		SNOW_rects[NUM_FLAKES+i].x = flake[i].x>>3;
+		SNOW_rects[NUM_FLAKES+i].y = flake[i].y;
+	}
+}
+
+/* SNOW_draw: updates the screen surface
+ * with the new flake pixels
+ * note: y<<9 + y<<7 is short for y*640
+ */
+void SNOW_draw(void) {
+	int i;
+	Uint16 *to;
+
+	/* we only draw if we are on and haven't toggled (see SNOW_Erase for more info */
+	if (SNOW_on!=1)
+		return;
+
+	for (i=0; i<NUM_FLAKES; i++) {
+		to = screen->pixels;
+		to += (SNOW_rects[NUM_FLAKES+i].y<<9) + (SNOW_rects[NUM_FLAKES+i].y<<7) + SNOW_rects[NUM_FLAKES+i].x;
+		*to = snow_color;
+		to += 1;
+		*to = snow_color;
+		to += 640;
+		*to = snow_color;
+		to -= 1;
+		*to = snow_color;
+	}
+}
+
+/* SNOW_erase: updates the screen surface
+ * by replacing the previous flakes with
+ * the background image (set via SNOW_setBkg).
+ * This should be run before bliting any
+ * graphics to the screen so you don't over-
+ * write good images with background!
+ *
+ * note: y<<9 + y<<7 is short for y*640
+ */
+void SNOW_erase(void) {
+	int i;
+	Uint16 *from, *to;
+
+	if (!SNOW_on)
+		return;
+
+	/* SNOW_on isn't a boolean variable, it is really
+	 * holding the state:
+	 *  0 means no snow
+	 *  1 means snow
+	 *  2 means the user has requested snowing to stop
+	 *          we cannot just stop snowing since we
+	 *          need to erase the previous frames snow
+	 *  3 means have erased the snow during the previous
+	 *          frame and can go back to waiting for
+	 *          snow to be turned on
+	 */
+	if (SNOW_on>1) {
+		if (SNOW_on == 3)
+			SNOW_on = 0;
+		else
+			SNOW_on++;
+	}
+
+	for (i=0; i<NUM_FLAKES; i++) {
+		to = screen->pixels;
+		from = bkg->pixels;
+		to += (SNOW_rects[i].y<<9) + (SNOW_rects[i].y<<7) + SNOW_rects[i].x;
+		from += (SNOW_rects[i].y<<9) + (SNOW_rects[i].y<<7) + SNOW_rects[i].x;
+		*to = *from;
+		to += 1;
+		from += 1;
+		*to = *from;
+		to += 640;
+		from += 640;
+		*to = *from;
+		to -= 1;
+		from -= 1;
+		*to = *from;
+	}
+}
+
+/* SNOW_setBkg: we need to have the  background
+ * to erase snow flakes every frame
+ */
+void SNOW_setBkg( SDL_Surface *img ) {
+	bkg = img;
+}
+
+/* SNOW_add: this adds the other rectangles that we need 
+ * to update on the screen to the list and returns
+ * the total number of items on the complete list
+ * (flakes & regular stuff)
+ */
+int SNOW_add( SDL_Rect *rs, int num ){
+	int i;
+	for (i=0; i<num; i++) {
+		SNOW_rects[(NUM_FLAKES<<1)+i].x = rs[i].x;
+		SNOW_rects[(NUM_FLAKES<<1)+i].y = rs[i].y;
+		SNOW_rects[(NUM_FLAKES<<1)+i].w = rs[i].w;
+		SNOW_rects[(NUM_FLAKES<<1)+i].h = rs[i].h;
+	}
+	return num + (NUM_FLAKES<<1);
+}
+
+/* SNOW_init: initing the snow "library" envoles
+ * seting up the color for the snow, the inital
+ * locations for the flakes and the size of the
+ * snow rectangles
+ */
+void SNOW_init( void ) {
+
+	int i;
+
+	snow_color = SDL_MapRGB( screen->format, 255, 255, 255 );
+	for (i=0; i<NUM_FLAKES; i++) {
+		flake[i].x = (int)(8*638.0*rand()/(RAND_MAX+1.0));
+		flake[i].y = (int)(480.0*rand()/(RAND_MAX+1.0));
+	}
+	for (i=0; i<2*NUM_FLAKES; i++) {
+		SNOW_rects[i].w = 2;
+		SNOW_rects[i].h = 2;
+	}
+}
+
+/* SNOW_toggle: toggles the snow on and off.
+ * see SNOW_erase for a discription of what
+ * SNOW_on means
+ */
+void SNOW_toggle( void ) {
+	SNOW_on ++;
+}
+
+/* SNOW_update: update the wind with
+ * a 10% prob of blowing further left
+ * a 10% prob of blowing further right
+ * and 80% of not changing.
+ * AFTER updating the wind, we move all
+ * the snow
+ */
+void SNOW_update( void ) {
+	int rand_tmp = (int)(10.0*rand()/(RAND_MAX+1.0));
+
+	if (!SNOW_on)
+		return;
+
+	if (rand_tmp == 0)
+		add_wind(-1);
+	else if (rand_tmp == 1)
+		add_wind(+1);
+	
+	move_snow();
+}
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/snow.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/snow.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/snow.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/snow.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,9 @@
+extern int SNOW_on;
+extern SDL_Rect SNOW_rects[2000];
+extern int SNOW_add( SDL_Rect *rs, int num );
+extern void SNOW_toggle( void );
+extern void SNOW_draw( void );
+extern void SNOW_erase( void );
+extern void SNOW_setBkg( SDL_Surface *img );
+extern void SNOW_init( void );
+extern void SNOW_update( void );

Copied: tuxtype/branches/tuxtype-soc-mh/src/theme.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/theme.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/theme.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/theme.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,328 @@
+/***************************************************************************
+                          theme.c 
+ -  description: theme related code
+                             -------------------
+    begin                : Jan 6 2003
+    copyright            : (C) 2003 by Jesse Andrews et al
+    email                : jdandr2 at tux4kids.net
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+
+
+SDL_Surface* letters[255] = {NULL}; //get rid of this
+wchar_t ALPHABET[256];
+int ALPHABET_SIZE;
+
+
+#define MAX_LANGUAGES 100
+
+
+
+void ChooseTheme(void)
+{
+  SDL_Surface* titles[MAX_LANGUAGES] = {NULL};
+  SDL_Surface* select[MAX_LANGUAGES] = {NULL};
+  SDL_Surface* left = NULL;
+  SDL_Surface* right = NULL;
+  SDL_Surface* world = NULL;
+  SDL_Surface* map = NULL;
+  SDL_Surface* photo = NULL;
+  SDL_Rect leftRect, rightRect;
+  SDL_Rect worldRect, photoRect;
+  SDL_Rect titleRects[8];
+  TTF_Font* font = NULL;  
+  int stop = 0;
+  int loc = 0;
+  int old_loc = 1;
+
+  int themes = 1;
+  int i;
+  unsigned char fn[FNLEN];
+  unsigned char themeNames[MAX_LANGUAGES][FNLEN];
+  unsigned char themePaths[MAX_LANGUAGES][FNLEN];
+
+  int old_use_english;
+  char old_theme_path[FNLEN];
+
+  DIR* themesDir = NULL;
+  struct dirent* themesFile = NULL;
+
+  /* save previous settings in case we back out: */
+  old_use_english = settings.use_english;
+  strncpy(old_theme_path, settings.theme_data_path, FNLEN - 1);
+
+  sprintf(fn, "%s/themes/", settings.default_data_path);
+  themesDir = opendir(fn);
+
+  if (!themesDir)
+  {
+    fprintf(stderr, "ChooseTheme() - cannot open themes directory!");
+    return;
+  }
+
+  do  /* Iterate until readdir() returns NULL: */
+  {
+    themesFile = readdir(themesDir);
+    if (!themesFile)
+      break;
+
+    /* we ignore any hidden file and CVS */
+    if (themesFile->d_name[0] == '.') 
+      continue;
+    if (strcmp("CVS", themesFile->d_name)==0)
+      continue;
+
+    /* check to see if it is a directory */
+    sprintf(fn, "%s/themes/%s", settings.default_data_path, themesFile->d_name);
+
+    /* CheckFile() returns 2 if dir, 1 if file, 0 if neither: */
+    if (CheckFile(fn) == 2)
+    {
+      /* HACK: we should get the names from file :) */
+      strncpy( themeNames[themes], themesFile->d_name, FNLEN-1);
+      /* Make sure theme name is capitalized: */
+      themeNames[themes][0] = toupper(themeNames[themes][0]);
+      strncpy( themePaths[themes++], themesFile->d_name, FNLEN-1 );
+    }
+  } while (1);
+
+  closedir(themesDir);
+
+  settings.use_english = 1;
+  // HACK: is font empty now???
+  font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
+
+  titles[0] = BlackOutline( "English", font, &white );
+  select[0] = BlackOutline( "English", font, &yellow);
+  for (i = 1; i < themes; i++)
+  {
+    titles[i] = BlackOutline( themeNames[i], font, &white );
+    select[i] = BlackOutline( themeNames[i], font, &yellow);
+  }
+
+  LoadBothBkgds("main_bkg.png");
+
+  world = LoadImage("world.png", IMG_ALPHA);
+  left = LoadImage("left.png", IMG_ALPHA);
+  right = LoadImage("right.png", IMG_ALPHA);
+
+  if (!world || !left || !right || !CurrentBkgd())
+  {
+    fprintf(stderr, "ChooseTheme() - could not load needed image.\n");
+    return;
+  }
+
+  worldRect.x = screen->w - world->w;
+  worldRect.w = world->w;
+  worldRect.y = 10;
+  worldRect.h = world->h;
+
+  leftRect.w = left->w;
+  leftRect.h = left->h;
+  leftRect.x = 160 - 80 - (leftRect.w/2);
+  leftRect.y = 430;
+
+  rightRect.w = right->w;
+  rightRect.h = right->h;
+  rightRect.x = 160 + 80 - (rightRect.w/2); 
+  rightRect.y = 430;
+
+  /* set initial rect sizes */
+  titleRects[0].y = 30;
+  titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
+  for (i = 1; i < 8; i++)
+  {
+    titleRects[i].y = titleRects[i - 1].y + 50;
+    titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
+  }
+
+  TTF_CloseFont(font);
+  font = NULL;
+  settings.use_english = old_use_english;
+
+  while (!stop)
+  {
+    while (SDL_PollEvent(&event)) 
+      switch (event.type)
+      {
+        case SDL_QUIT:
+        exit(0);
+        break;
+
+        case SDL_MOUSEMOTION:
+          for (i = 0; (i < 8) && (loc - (loc%8) + i < themes); i++)
+            if (inRect( titleRects[i], event.motion.x, event.motion.y ))
+            {
+              loc = loc-(loc%8)+i;
+              break;
+            }
+
+          break;
+
+        case SDL_MOUSEBUTTONDOWN: 
+          if (inRect( leftRect, event.button.x, event.button.y )) 
+            if (loc-(loc%8)-8 >= 0)
+            {
+              loc=loc-(loc%8)-8;
+              break;
+            }
+
+          if (inRect( rightRect, event.button.x, event.button.y )) 
+            if (loc-(loc%8)+8 < themes)
+            {
+              loc=loc-(loc%8)+8;
+              break;
+            }
+
+          for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++) 
+            if (inRect(titleRects[i], event.button.x, event.button.y))
+            {
+              loc = loc-(loc%8)+i;
+              if (loc)
+              {
+                /* --- set theme --- */
+                SetupPaths(themePaths[loc]);
+              }
+              else
+              {
+                /* --- english --- */
+                SetupPaths(NULL);
+              }
+
+              stop = 1;
+              break;
+            }
+          break;
+
+        case SDL_KEYDOWN:
+          if (event.key.keysym.sym == SDLK_ESCAPE)
+          {
+            settings.use_english = old_use_english;
+            strncpy(settings.theme_data_path, old_theme_path, FNLEN - 1);
+            stop = 1; 
+            break; 
+          }
+
+          if (event.key.keysym.sym == SDLK_RETURN)
+          { 
+            if (loc)
+            {
+              /* --- set theme --- */
+              SetupPaths(themePaths[loc]);
+            }
+            else
+            {
+              /* --- English --- */
+              SetupPaths(NULL);
+            }
+
+            stop = 1;
+            break;
+          }
+
+          if ((event.key.keysym.sym == SDLK_LEFT)
+           || (event.key.keysym.sym == SDLK_PAGEUP))
+          {
+            if (loc-(loc%8)-8 >= 0) 
+              loc=loc-(loc%8)-8;
+          }
+
+          if ((event.key.keysym.sym == SDLK_RIGHT)
+           || (event.key.keysym.sym == SDLK_PAGEDOWN))
+          {
+            if (loc-(loc%8)+8 < themes)
+              loc=(loc-(loc%8)+8);
+          }
+
+          if (event.key.keysym.sym == SDLK_UP)
+          {
+            if (loc > 0)
+              loc--;
+          }
+
+          if (event.key.keysym.sym == SDLK_DOWN)
+          {
+            if (loc+1<themes)
+              loc++;
+          }
+        }
+
+    if (old_loc != loc)
+    {
+      int start;
+
+      SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL );
+      SDL_BlitSurface( world, NULL, screen, &worldRect );
+
+      if (loc)
+        SetupPaths(themePaths[loc]);
+      else
+        SetupPaths(NULL);
+
+      map = LoadImage( "map.png", IMG_ALPHA|IMG_NOT_REQUIRED );
+      if (map)
+      {
+        SDL_BlitSurface( map, NULL, screen, &worldRect );
+        SDL_FreeSurface( map );
+      }
+
+      photo = LoadImage( "photo.png", IMG_ALPHA|IMG_NOT_REQUIRED );
+      if (photo)
+      {
+        photoRect.x = 480 - (photo->w/2);
+        photoRect.y = 250;
+        photoRect.w = photo->w;
+        photoRect.h = photo->h;
+        SDL_BlitSurface( photo, NULL, screen, &photoRect );
+        SDL_FreeSurface( photo );
+      }
+
+      start = loc - (loc % 8);
+
+      for (i = start; i<MIN(start+8,themes); i++)
+      {
+        titleRects[i%8].x = 160 - (titles[i]->w/2);
+
+        if (i == loc)
+          SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
+        else
+          SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
+      }
+
+      /* --- draw buttons --- */
+      if (start>0) 
+        SDL_BlitSurface( left, NULL, screen, &leftRect );
+
+      if (start+8<themes) 
+        SDL_BlitSurface( right, NULL, screen, &rightRect );
+
+      SDL_UpdateRect(screen, 0, 0, 0 ,0);
+    }
+    SDL_Delay(40);
+    old_loc = loc;
+  }
+
+  /* --- clear graphics before quitting --- */ 
+
+  for (i = 0; i<themes; i++)
+  {
+    SDL_FreeSurface(titles[i]);
+    SDL_FreeSurface(select[i]);
+  }
+
+  SDL_FreeSurface(world);
+  SDL_FreeSurface(left);
+  SDL_FreeSurface(right);
+
+}

Copied: tuxtype/branches/tuxtype-soc-mh/src/titlescreen.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/titlescreen.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/titlescreen.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/titlescreen.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,1576 @@
+/***************************************************************************
+ -  file: titlescreen.c
+ -  description: splash, title and menu screen functionality 
+                            ------------------
+    begin                : Thur May 4 2000
+    copyright            : (C) 2000 by Sam Hart
+                         : (C) 2003 by Jesse Andrews
+    email                : tuxtype-dev at tux4kids.net
+***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#include "globals.h"
+#include "funcs.h"
+#include "titlescreen.h"
+#include "SDL_extras.h"
+
+/* --- media for menus --- */
+
+/* images of regular and selected text of menu items: */
+static SDL_Surface* reg_text[TITLE_MENU_ITEMS + 1][TITLE_MENU_DEPTH + 1] = {NULL};
+static SDL_Surface* sel_text[TITLE_MENU_ITEMS + 1][TITLE_MENU_DEPTH + 1] = {NULL};
+/* this will contain pointers to all of the menu 'icons' */
+static sprite* menu_gfx[TITLE_MENU_ITEMS + 1][TITLE_MENU_DEPTH + 1] = {NULL};
+
+/* Background images for windowed and fullscreen modes: */
+static SDL_Surface* win_bkgd = NULL; //640x480 background (windowed)
+static SDL_Surface* fullscr_bkgd = NULL; //native resolution (fullscreen)
+
+/* --- other media --- */
+static SDL_Surface* title = NULL;
+static SDL_Surface* speaker = NULL;
+static SDL_Surface* speakeroff = NULL;
+static SDL_Surface* profiles = NULL;
+static sprite* Tux = NULL;
+static Mix_Chunk* snd_move = NULL;
+static Mix_Chunk* snd_select = NULL;
+static TTF_Font* font = NULL;
+
+/* --- locations we need --- */
+static SDL_Rect text_dst[TITLE_MENU_ITEMS + 1];     // location of menu text
+static SDL_Rect menu_gfxdest[TITLE_MENU_ITEMS + 1]; // location of menu sprite
+static SDL_Rect menu_button[TITLE_MENU_ITEMS + 1];  // menu mouse event buttons
+/* keep track of the width of each menu: */
+static int menu_width[TITLE_MENU_DEPTH + 1];
+
+static SDL_Rect Tuxdest;
+static SDL_Rect Titledest;
+static SDL_Rect spkrdest;
+static SDL_Rect cursor;
+static SDL_Rect profilesdest;
+
+/* Local function prototypes: */
+static void show_logo(void);
+static int load_media(void);
+static void load_menu(void);
+static void recalc_rects(void);
+static int chooseWordlist(void);
+static void not_implemented(void);
+static void unload_media(void);
+static void unload_menu(void);
+
+/* --- menu text --- */
+
+/* --- define menu structure --- */
+/* (these values are all in the Game_Type enum in globals.h) */
+const int menu_item[][7]= {{0, 0,         0,         0,          0},
+			   {0, CASCADE,   	LEVEL1,    	LEVEL1,	NOT_CODED },
+			   {0, LASER,     	LEVEL2,    	LEVEL2,	FREETYPE   },
+			   {0, LESSONS,  	LEVEL3,    	LEVEL3,	PROJECT_INFO },
+			   {0, WPM,			INSTRUCT,	LEVEL4,	HIGH_SCORES},
+			   {0, OPTIONS,   	MAIN,  		MAIN,	SET_LANGUAGE},
+			   {0, QUIT_GAME, 	0,      	0,  	MAIN}};
+
+/* --- menu icons --- */ //no icons wpm or highscore
+const unsigned char *menu_icon[][7]=
+{{"", "", 			"", 		"", 		""},
+ {"", "cascade",	"easy",   	"grade1_", 	"list"   },
+ {"", "comet",   	"medium", 	"grade2_", 	"practice" },
+ {"", "lesson",		"hard",   	"grade3_", 	"keyboard"   },
+ {"", "WPM", 		"tutor",  	"grade4_", 	"highscores" },
+ {"", "tux_config",	"main",  	"main", 	"lang" },
+ {"", "quit",    	"",   		"",    		"main"   }};
+
+/* --- menu text --- */
+static const char *menu_text[]=
+{{"", "",            					"",             				"",            					""    },
+ {"", gettext_noop("Fish Cascade"), 	gettext_noop("Easy"),       	gettext_noop("Space Cadet"), 	gettext_noop("Edit Word Lists")},
+ {"", gettext_noop("Comet Zap"),		gettext_noop("Medium"),       	gettext_noop("Pilot"),       	gettext_noop("Practice")},
+ {"", gettext_noop("Lessons"),			gettext_noop("Hard"),         	gettext_noop("Ace"),         	gettext_noop("Project Info")},
+ {"", gettext_noop("WPM Calculator"),	gettext_noop("Instructions"), 	gettext_noop("Commander"), 		gettext_noop("High Scores")},
+ {"", gettext_noop("Options"),      	gettext_noop("Main Menu"), 		gettext_noop("Main Menu"),   	gettext_noop("Setup Language")},
+ {"", gettext_noop("Quit"),         	"",    							"",   							gettext_noop("Main Menu")}};
+
+
+
+/************************************************************************/
+/*                                                                      */ 
+/*         "Public" functions (callable throughout program)             */
+/*                                                                      */
+/************************************************************************/
+
+
+/****************************************
+* TitleScreen: Display the title screen *
+*****************************************
+* display title screen, get input
+*/
+void TitleScreen(void)
+{
+
+  Uint32 frame = 0;
+  Uint32 start = 0;
+
+  /* NOTE for 'depth', think pages like a restaurant menu, */
+  /* not heirarchical depth - choice of term is misleading */
+  int menu_depth; // how deep we are in the menu
+
+  int i, j, tux_frame = 0;
+  int done = 0;
+  int firstloop = 1;
+  int menu_opt = NONE;
+  int sub_menu = NONE;
+  int update_locs = 1;
+  int redraw = 0;
+  int key_menu = 1;
+  int old_key_menu = 5;
+  wchar_t phrase[128];
+  FILE *fp;
+  unsigned char fn[FNLEN];
+  int found = 0;
+  unsigned char str[1000];
+
+
+  if (settings.sys_sound)
+  {
+    settings.menu_sound = 1;
+    settings.menu_music = 1;
+  }
+
+  
+  /* FIXME phrase(s) should come from file */
+
+  ConvertFromUTF8(phrase, "The quick brown fox jumps over the lazy dog.");
+
+//  wcscpy(phrase, "Now is the time for all good men to come to the aid of their country.");
+  start = SDL_GetTicks();
+
+
+  /*
+  * Display the Standby screen.... 
+  */
+  show_logo();
+
+  /* Load media and menu data: */
+  if (!load_media())
+  {
+    fprintf(stderr, "TitleScreen - load_media() failed!");
+    return;
+  }
+
+  SDL_WM_GrabInput(SDL_GRAB_ON); // User input goes to TuxType, not window manager
+
+
+  /***************************
+  * Tux and Title animations *
+  ***************************/
+
+  LOG( "->Now Animating Tux and Title onto the screen\n" );
+
+  Tuxdest.x = 0;
+  Tuxdest.y = screen->h;
+  Tuxdest.w = Tux->frame[0]->w;
+  Tuxdest.h = Tux->frame[0]->h;
+
+  Titledest.x = screen->w;
+  Titledest.y = 10;
+  Titledest.w = title->w;
+  Titledest.h = title->h;
+
+  spkrdest.x = screen->w - speaker->w - 10;
+  spkrdest.y = screen->h - speaker->h - 10;
+  spkrdest.w = speaker->w;
+  spkrdest.h = speaker->h;
+  
+  profilesdest.x = 572;
+  profilesdest.y = 420;
+  profilesdest.w = profiles->w; 
+  profilesdest.h = profiles->h;
+
+  /* --- wait if the first time in the game --- */
+
+  if (settings.show_tux4kids)
+  {
+    while ((SDL_GetTicks() - start) < 2000)
+    {
+      SDL_Delay(50);
+    }
+    settings.show_tux4kids = 0;
+  }
+
+  SDL_ShowCursor(1);    
+  /* FIXME not sure the next line works in Windows: */
+  TransWipe(CurrentBkgd(), RANDOM_WIPE, 10, 20);
+  /* Make sure background gets drawn (since TransWipe() doesn't */
+  /* seem to work reliably as of yet):                          */
+  SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
+  SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+  /* --- Pull tux & logo onscreen --- */
+  for (i = 0; i <= (PRE_ANIM_FRAMES * PRE_FRAME_MULT); i++)
+  {
+    start = SDL_GetTicks();
+    SDL_BlitSurface(CurrentBkgd(), &Tuxdest, screen, &Tuxdest);
+    SDL_BlitSurface(CurrentBkgd(), &Titledest, screen, &Titledest);
+
+    Tuxdest.y -= Tux->frame[0]->h / (PRE_ANIM_FRAMES * PRE_FRAME_MULT);
+    Titledest.x -= (screen->w) / (PRE_ANIM_FRAMES * PRE_FRAME_MULT);
+
+    SDL_BlitSurface(Tux->frame[0], NULL, screen, &Tuxdest);
+    SDL_BlitSurface(title, NULL, screen, &Titledest);
+
+    SDL_UpdateRect(screen, Tuxdest.x, Tuxdest.y, Tuxdest.w, Tuxdest.h);
+    SDL_UpdateRect(screen, Titledest.x, Titledest.y, Titledest.w + 40, Titledest.h);
+
+    while ((SDL_GetTicks() - start) < 33) 
+    {
+      SDL_Delay(2);
+    }
+  }
+
+  recalc_rects();
+
+  /* Pick speaker graphic according to whether music is on: */
+  if ( settings.menu_music )
+    SDL_BlitSurface(speaker, NULL, screen, &spkrdest);
+  else
+    SDL_BlitSurface(speakeroff, NULL, screen, &spkrdest);
+
+  /* Start playing menu music if desired: */
+  if (settings.menu_music)
+    MusicLoad( "tuxi.ogg", -1 );
+
+  LOG( "Tux and Title are in place now\n" );
+
+  /* Move mouse to top button: */
+  cursor.x = menu_button[1].x + (menu_button[1].w / 2);
+  cursor.y = menu_button[1].y + (3 * menu_button[1].h / 4);
+  SDL_WarpMouse(cursor.x, cursor.y);
+  SDL_WM_GrabInput(SDL_GRAB_OFF);
+
+
+  /****************************
+  * Main Loop Starts Here ... *
+  ****************************/
+
+
+  menu_depth = 1;
+  firstloop = 1;
+  Tuxdest.y = screen->h - Tux->frame[0]->h;
+
+  profilesSelector();
+  
+  while (!done) 
+  {
+
+    start=SDL_GetTicks();
+
+    /* ---process input queue --- */
+
+    menu_opt = NONE; // clear the option so we don't change twice!
+
+    old_key_menu = key_menu;
+
+    /* Retrieve any user interface events: */
+    while (SDL_PollEvent(&event))
+    {
+      switch (event.type)
+      {
+
+        case SDL_MOUSEMOTION:
+        {
+          cursor.x = event.motion.x;
+          cursor.y = event.motion.y;
+          break;
+        }
+
+
+        /* Handle mouse clicks based on mouse location: */
+        case SDL_MOUSEBUTTONDOWN:
+        {
+          cursor.x = event.motion.x;
+          cursor.y = event.motion.y;
+
+          for (j = 1; j <= TITLE_MENU_ITEMS; j++)
+          {
+            if (inRect(menu_button[j], cursor.x, cursor.y))
+            {
+              menu_opt = menu_item[j][menu_depth];
+              if (settings.menu_sound)
+              {
+                PlaySound(snd_select);
+              }
+              DEBUGCODE
+              {
+                fprintf(stderr, "->>BUTTON CLICK menu_opt = %d\n", menu_opt);
+                fprintf(stderr, "->J = %d menu_depth=%d\n", j, menu_depth);
+              }
+            }
+          }
+
+          /* If mouse over speaker, toggle menu music off or on: */
+          if (inRect(spkrdest, cursor.x, cursor.y))
+          {
+            if (settings.menu_music)
+            {
+              MusicUnload();
+              settings.menu_music = 0;
+            }
+            else
+            {
+              settings.menu_music = 1;
+              MusicLoad("tuxi.ogg", -1);
+            }
+            redraw = 1;
+          }
+          /* If mouse is over profiles, call selector */
+          if ((cursor.x >= profilesdest.x && cursor.x <= (profilesdest.x + profilesdest.w)) &&
+        		  (cursor.y >= profilesdest.y && cursor.y <= (profilesdest.y + profilesdest.h)))
+          {
+        	  profilesSelector();
+          }
+          break;
+        }
+
+
+
+        case SDL_QUIT:
+        {
+          menu_opt = QUIT_GAME;
+          break;
+        }
+
+
+        /* Handle key press events based on key value: */
+        case SDL_KEYDOWN:
+        {
+          switch (event.key.keysym.sym)
+          {
+            case SDLK_ESCAPE:
+            {
+              /* Go to main menu (if in submenu) or quit: */
+              if (menu_depth != 1) 
+                menu_opt = MAIN;
+              else
+                menu_opt = QUIT_GAME;
+
+              if (settings.menu_sound)
+                PlaySound(snd_select);
+              break;
+            }
+
+
+            /* Toggle screen mode: */
+            case SDLK_F10:
+            {
+              SwitchScreenMode();
+              recalc_rects();
+              redraw = 1;
+              break;
+            }
+
+
+            /* Toggle menu music: */
+            case SDLK_F11:
+            {
+              if (settings.menu_music)
+              {
+                MusicUnload( );
+                settings.menu_music = 0;
+              }
+              else
+              {
+                settings.menu_music = 1;
+                MusicLoad("tuxi.ogg", -1);
+              }
+              redraw = 1;
+              break;
+            }
+
+
+            /* --- reload translation/graphics/media: for themers/translaters --- */
+            case SDLK_F12:
+            {
+              unload_media();
+              LoadLang();
+              load_media();
+              redraw = 1;
+              break;
+            }
+
+
+            case SDLK_UP:
+            {
+              if (settings.menu_sound)
+                PlaySound(snd_move);
+              key_menu--;
+              if (key_menu < 1)
+                key_menu = 5;
+              break;
+            }
+
+
+            case SDLK_DOWN:
+            {
+              key_menu++;
+              if (settings.menu_sound)
+                PlaySound(snd_move);
+              if (key_menu > 5)
+                key_menu = 1;
+              break;
+            }
+
+
+            case SDLK_RETURN:
+            {
+              if (key_menu)
+              {
+                menu_opt = menu_item[key_menu][menu_depth];
+                if (settings.menu_sound)
+                  PlaySound(snd_select);
+              }
+              break;
+            }
+
+
+            default:     /* Some other key pressed - do nothing: */
+            {
+              break;
+            }
+          }             /* End of switch(event.key.keysym.sym) statement */
+        }               /* End of case: SDL_KEYDOWN: */
+
+
+        default:        /* Some other type of SDL event - do nothing;    */
+        {
+          break;
+        }
+      }                 /* End of switch(event.type) statement           */
+    }	              /* End of while (SDL_PollEvent(&event)) loop     */
+
+
+
+    /* --- warp mouse to follow keyboard input --- */
+
+    if (old_key_menu != key_menu)
+    {
+      cursor.x = menu_button[key_menu].x + (menu_button[key_menu].w / 2);
+      cursor.y = menu_button[key_menu].y + (3 * menu_button[key_menu].h / 4);
+      SDL_WarpMouse(cursor.x, cursor.y);
+    }
+
+
+
+    /* --- do menu processing --- */
+
+
+    if (menu_opt == QUIT_GAME)
+      done = 1;
+
+
+    if (menu_opt == LASER)
+    {
+      menu_depth = LASER_SUBMENU;
+      sub_menu = LASER;
+      update_locs = 1;
+      redraw = 1;
+    }
+
+
+    if (menu_opt == CASCADE)
+    {
+      menu_depth = CASCADE_SUBMENU;
+      sub_menu = CASCADE;
+      update_locs = 1;
+      redraw=1;
+    }
+
+
+    if (menu_opt == OPTIONS)
+    {
+      menu_depth = OPTIONS_SUBMENU;
+      sub_menu = OPTIONS;
+      update_locs = 1;
+      redraw = 1;
+    }
+
+
+    if (menu_opt == MAIN)
+    {
+      menu_depth = ROOTMENU;
+      update_locs = 1;
+      redraw = 1;
+    }
+
+
+    if (menu_opt == NOT_CODED)
+    {
+      not_implemented();
+      redraw = 1;
+    }
+
+
+    if (menu_opt == PROJECT_INFO)
+    {
+      ProjectInfo();
+      redraw = 1;
+    }
+
+
+    if (menu_opt == LESSONS)
+    {
+      SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
+      SDL_Flip( screen );
+      unload_media();
+
+      if (settings.menu_music)
+        MusicUnload( );
+
+      TestLesson();
+
+      load_media();
+      redraw = 1;
+
+      if (settings.menu_music)
+        MusicLoad( "tuxi.ogg", -1 );
+    }
+
+
+    if (menu_opt == SET_LANGUAGE)
+    {
+      unload_media();
+      ChooseTheme();
+      LoadLang();
+      LoadKeyboard();
+      load_media();
+      redraw = 1;
+
+      if (settings.menu_music)
+        MusicLoad( "tuxi.ogg", -1 );
+    }
+
+
+    if (menu_opt == LEVEL1)
+    {  
+      if (chooseWordlist()) 
+      {
+        unload_media();
+
+        switch (sub_menu)
+        {
+          case CASCADE: PlayCascade( EASY ); break;
+          case LASER:   PlayLaserGame(  EASY ); break;
+        }
+      }
+
+      load_media();
+
+      if (settings.menu_music)
+        MusicLoad("tuxi.ogg", -1);
+
+      redraw = 1;
+    }
+
+
+    if (menu_opt == LEVEL2)
+    {
+      if (chooseWordlist())
+      {
+        unload_media();
+
+        switch (sub_menu)
+        {
+          case CASCADE: PlayCascade( MEDIUM ); break;
+          case LASER:   PlayLaserGame(  MEDIUM ); break;
+        }
+
+
+        if (settings.menu_music)
+          MusicLoad( "tuxi.ogg", -1 );
+      }
+
+      load_media();
+      redraw = 1;
+    }
+
+
+
+    if (menu_opt == LEVEL3)
+    {
+      if (chooseWordlist())
+      {
+        unload_media();
+
+        switch (sub_menu)
+        {
+          case CASCADE: PlayCascade( HARD ); break;
+          case LASER:   PlayLaserGame(  HARD ); break;
+        }
+
+
+        if (settings.menu_music)
+          MusicLoad( "tuxi.ogg", -1 );
+      }
+
+      load_media();
+      redraw = 1;
+    }
+
+
+
+    if (menu_opt == LEVEL4)
+    {
+      if (chooseWordlist())
+      {
+        unload_media();
+
+        switch (sub_menu)
+        {
+          case CASCADE: PlayCascade( INSANE ); break;
+          case LASER:   PlayLaserGame(  INSANE ); break;
+        }
+
+        if (settings.menu_music)
+          MusicLoad( "tuxi.ogg", -1 );
+      }
+
+      load_media();
+      redraw = 1;
+    }
+
+
+
+    if (menu_opt == INSTRUCT)
+    {
+      unload_media();
+
+      switch (sub_menu)
+      {
+        case CASCADE: InstructCascade(); break;
+        case LASER:   InstructLaser();   break;
+      }
+
+      load_media();
+
+      if (settings.menu_music)
+        MusicLoad( "tuxi.ogg", -1 );
+
+      redraw = 1;
+    }
+
+
+
+    if (menu_opt == FREETYPE)
+    {
+      unload_media();
+      found = 0;
+
+      if (!settings.use_english)
+      {
+        sprintf(fn , "%s/phrases.txt", settings.theme_data_path);
+        if (CheckFile(fn))
+          found = 1;
+
+        /* Now look in default path if desired or needed: */
+        if (!found)
+        {
+          sprintf(fn , "%s/words/words3.txt", settings.theme_data_path);
+          if (CheckFile(fn))
+            found = 1;
+        }
+
+        if (!found)
+        {
+          sprintf(fn , "%s/words/words2.txt", settings.theme_data_path);
+          if (CheckFile(fn))
+            found = 1;
+        }
+
+        if (!found)
+        {
+          sprintf(fn , "%s/words/words1.txt", settings.theme_data_path);
+          if (CheckFile(fn))
+            found = 1;
+        }
+      }
+
+      /* Now checking English: */
+      if (!found)
+      {
+        sprintf(fn , "%s/phrases.txt", settings.default_data_path);
+        if (CheckFile(fn))
+          found = 1;
+      }
+
+      /* Now do Phrases activity if phrase loaded successfully: */
+      if (found)
+      {
+        fp=fopen(fn,"r");
+        fscanf( fp, "%[^\n]\n", str);
+        ConvertFromUTF8(phrase, str);
+        Phrases( phrase );
+        //Practice();
+        load_media();
+        redraw = 1;
+        fclose(fp);
+      }
+      else
+      {
+        fprintf(stderr, "LoadKeyboard(): Error finding file for keyboard setup!\n");
+      }
+    }
+    
+    if(menu_opt == WPM)
+    {
+    	
+    }
+    
+    if(menu_opt == HIGH_SCORES)
+
+    /* ------ End menu_opt processing ----------- */
+
+
+
+    if (redraw)
+    {
+      LOG("TitleScreen() - redraw requested\n");
+      recalc_rects();
+
+      SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL); 
+      SDL_BlitSurface(title, NULL, screen, &Titledest);
+
+      if ( settings.menu_music )
+        SDL_BlitSurface(speaker, NULL, screen, &spkrdest);
+      else
+        SDL_BlitSurface(speakeroff, NULL, screen, &spkrdest);
+
+      /* Screen will be updated due to update_locs - see ~30 lines down: */
+//      SDL_UpdateRect(screen, 0, 0, 0, 0);
+      frame = redraw = 0;   // so we redraw tux
+      update_locs = 1;      // so we redraw menu
+      firstloop = 1;
+    }
+
+
+
+    /* --- create new menu screen when needed --- */
+
+    if (update_locs)
+    {
+      LOG("TitleScreen() - update_locs requested\n");
+
+      /* --- erase the last menu --- */
+      for (i = 1; i <= TITLE_MENU_ITEMS; i++)
+      {
+        text_dst[i].x = screen->w/2 - 70;//290;
+        text_dst[i].w = reg_text[i][menu_depth]->w;
+        text_dst[i].h = reg_text[i][menu_depth]->h;
+        SDL_BlitSurface(CurrentBkgd(), &menu_button[i], screen, &menu_button[i]);
+        menu_button[i].w = menu_width[menu_depth] + 20;
+      }
+
+
+      update_locs = 0;
+
+      /* --- draw the full menu --- */
+
+      for (j = 1; j <= TITLE_MENU_ITEMS; j++)
+      {
+        DOUT(j);
+        DrawButton(&menu_button[j], 10, REG_RGBA);
+        if (reg_text[j][menu_depth] != NULL)
+          SDL_BlitSurface(reg_text[j][menu_depth], NULL, screen, &text_dst[j]);
+        if (menu_gfx[j][menu_depth] != NULL)
+          SDL_BlitSurface(menu_gfx[j][menu_depth]->default_img, NULL, screen, &menu_gfxdest[j]);
+      }
+
+      SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+      LOG("TitleScreen() - update_locs completed\n");
+    }
+
+
+
+    /* --- make tux blink --- */
+
+    switch (frame % TUX6)
+    {
+      case 0:    tux_frame = 1; break;
+      case TUX1: tux_frame = 2; break;
+      case TUX2: tux_frame = 3; break;
+      case TUX3: tux_frame = 4; break;			
+      case TUX4: tux_frame = 3; break;
+      case TUX5: tux_frame = 2; break;
+      default: tux_frame = 0;
+    }
+
+    if (tux_frame)
+    {
+      SDL_Rect blink_src, blink_dest;
+      blink_src.x = 0;
+      blink_src.y = 0;
+      blink_src.w = Tuxdest.w;
+      blink_src.h = Tuxdest.h;
+      blink_dest.x = Tuxdest.x + blink_src.x;
+      blink_dest.y = Tuxdest.y + blink_src.y;
+      blink_dest.w = blink_src.w;
+      blink_dest.h = blink_src.h;
+//      SDL_BlitSurface(CurrentBkgd(), , screen, &Tuxdest);
+      SDL_BlitSurface(Tux->frame[tux_frame - 1], &blink_src, screen, &blink_dest);
+    }
+
+
+    /* --- check if mouse is in a menu option --- */
+
+    key_menu = 0;
+
+    for (j = 1; j <= TITLE_MENU_ITEMS; j++)
+    {
+      if ((cursor.x >= menu_button[j].x && cursor.x <= (menu_button[j].x + menu_button[j].w)) &&
+          (cursor.y >= menu_button[j].y && cursor.y <= (menu_button[j].y + menu_button[j].h)))
+      {
+        key_menu = j; // update menu to point
+        break;        // Don't need to check rest of menu
+      }
+    }
+
+
+    /* --- return old selection to unselected state --- */
+
+    if (old_key_menu && (key_menu != old_key_menu))
+    {
+      SDL_BlitSurface(CurrentBkgd(), &menu_button[old_key_menu], screen, &menu_button[old_key_menu]);
+      DrawButton(&menu_button[old_key_menu], 10, REG_RGBA);
+      SDL_BlitSurface(reg_text[old_key_menu][menu_depth], NULL, screen, &text_dst[old_key_menu]);
+      SDL_BlitSurface(menu_gfx[old_key_menu][menu_depth]->default_img, NULL, screen, &menu_gfxdest[old_key_menu]);
+    }
+
+
+    /* --- draw current selection --- */
+
+    if ((key_menu != 0) &&
+       ((old_key_menu != key_menu) || (frame % 5 == 0))) // Redraw every fifth frame?
+    {
+      if (key_menu != old_key_menu)
+      {
+        REWIND(menu_gfx[key_menu][menu_depth]);
+        PlaySound(snd_move);
+      }
+
+      SDL_BlitSurface(CurrentBkgd(), &menu_button[key_menu], screen, &menu_button[key_menu]);
+      DrawButton(&menu_button[key_menu], 10, SEL_RGBA);
+      SDL_BlitSurface(sel_text[key_menu][menu_depth], NULL, screen, &text_dst[key_menu]);
+      SDL_BlitSurface(menu_gfx[key_menu][menu_depth]->frame[menu_gfx[key_menu][menu_depth]->cur], NULL, screen, &menu_gfxdest[key_menu]);
+
+      NEXT_FRAME(menu_gfx[key_menu][menu_depth]);
+    }
+
+
+    // HACK This is still more than we need to update every frame but
+    // it cuts cpu on my machine %60 so it seems better...
+    if ( settings.menu_music )
+      SDL_BlitSurface(speaker, NULL, screen, &spkrdest);
+    else
+      SDL_BlitSurface(speakeroff, NULL, screen, &spkrdest);
+
+    SDL_UpdateRect(screen, spkrdest.x, spkrdest.y, spkrdest.w, spkrdest.h);
+
+    for (i = 1; i < 6; i++)
+    {
+      SDL_UpdateRect(screen, menu_button[i].x, menu_button[i].y, menu_button[i].w, menu_button[i].h);
+    }
+
+    if (tux_frame)
+      SDL_UpdateRect(screen, Tuxdest.x, Tuxdest.y, Tuxdest.w, Tuxdest.h);
+
+    if (firstloop)
+      SDL_UpdateRect(screen, Tuxdest.x, Tuxdest.y, Tuxdest.w, Tuxdest.h);
+
+    firstloop = 0;
+
+    /* Wait so we keep frame rate constant: */
+    while ((SDL_GetTicks() - start) < 33)
+    {
+      SDL_Delay(20);
+    }
+
+    frame++;
+  } /* ----------- End of 'while(!done)' loop ------------  */
+
+
+
+  LOG( "->>Freeing title screen images\n" );
+
+  unload_media();
+
+  LOG( "->TitleScreen():END \n" );
+}
+
+
+
+/************************************************************************/
+/*                                                                      */ 
+/*       "Private" functions (local to titlescreen.c)                   */
+/*                                                                      */
+/************************************************************************/
+
+static void show_logo(void)
+{
+  if (settings.show_tux4kids)
+  {
+    SDL_Rect logo_rect;
+    SDL_Surface* t4k_logo = LoadImage("standby.png", IMG_REGULAR|IMG_NO_THEME);
+    
+    if (t4k_logo) /* Avoid segfault */
+    { 
+      logo_rect.x = screen->w/2 - t4k_logo->w/2;  // Center horizontally
+      logo_rect.y = screen->h/2 - t4k_logo->h/2;  // Center vertically
+      logo_rect.w = t4k_logo->w;
+      logo_rect.h = t4k_logo->h;
+
+      /* Black out screen: */
+      SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
+      SDL_BlitSurface(t4k_logo, NULL, screen, &logo_rect);
+      SDL_UpdateRect(screen, 0, 0, 0, 0);
+      SDL_FreeSurface(t4k_logo);  // Unload image
+    }
+    else
+      fprintf(stderr, "Couldn't load 'standby.png'\n");
+  }
+}
+
+
+/* Renders the menu text for all items and loads the associated */
+/* animated sprites, if any.                                    */
+static void load_menu(void)
+{
+  unsigned char fn[FNLEN];
+  int max, i, j;
+
+  SDL_ShowCursor(1);
+
+  LOG("loading & parsing menu\n");
+
+  for (j = 1; j <= TITLE_MENU_DEPTH; j++)  /* Each 'depth' is a different menu */
+  {
+    max = 0;
+    for (i = 1; i <= TITLE_MENU_ITEMS; i++)
+    {
+      DEBUGCODE
+      {
+        fprintf(stderr, "i = '%d'\tj = '%d'\ttext = '%s'\n",
+                i, j,  gettext((unsigned char*)menu_text[j+5*i]));
+      }
+
+      /* --- create text surfaces --- */
+      reg_text[i][j] = BlackOutline( gettext((unsigned char*)menu_text[j+5*i]), font, &white);
+      sel_text[i][j] = BlackOutline( gettext((unsigned char*)menu_text[j+5*i]), font, &yellow);
+
+      /* (first make sure ptr valid to avoid segfault) */
+      if (sel_text[i][j] && sel_text[i][j]->w > max)
+        max = sel_text[i][j]->w;
+
+      /* --- load animated icon for menu item --- */
+      sprintf(fn, "menu/%s", menu_icon[i][j]);
+      menu_gfx[i][j] = LoadSprite(fn, IMG_ALPHA);
+    }
+    menu_width[j] = max + 20 + 40; // Not clear where '20' and '40' are coming from
+  }
+
+  recalc_rects();
+}
+
+
+
+static void recalc_rects(void)
+{
+  int i = 0;
+
+  Tuxdest.x = 0;
+  Tuxdest.y = screen->h - Tux->frame[0]->h;
+  Tuxdest.w = Tux->frame[0]->w;
+  Tuxdest.h = Tux->frame[0]->h;
+
+  Titledest.x = 0;
+  Titledest.y = 10;
+  Titledest.w = title->w;
+  Titledest.h = title->h;
+
+  spkrdest.x = screen->w - speaker->w - profiles->w - 10;
+  spkrdest.y = screen->h - speaker->h - 10;
+  spkrdest.w = speaker->w;
+  spkrdest.h = speaker->h;
+  
+  profilesdest.x = screen->w - speaker->w - 10;
+  profilesdest.y = screen->h - profiles->h - 10;
+  profilesdest.w = profiles->w; 
+  profilesdest.h = profiles->h;
+  /* --- setup menu item destinations --- */
+  menu_button[1].x = screen->w/2 - 120; //240;
+  menu_button[1].y = 100;
+  menu_button[1].w = menu_width[1];  //calc from width of widest menu item
+  menu_button[1].h = 50;
+
+  menu_gfxdest[1].x = menu_button[1].x + 6; // inset graphic by (6, 4) */
+  menu_gfxdest[1].y = menu_button[1].y + 4;
+  menu_gfxdest[1].w = 40;
+  menu_gfxdest[1].h = 50;
+
+  text_dst[1].x = screen->w/2 - 70;//290;
+  text_dst[1].y = menu_button[1].y + 15;
+
+  /* FIXME each menu item drawn hardcoded 60 pixels below last - */
+  /* perhaps increment should be "menu_button[j-1].h + MENU_ITEM_GAP" */
+  for (i = 2; i < 6; i++) 
+  {
+    /* --- setup location of button text --- */
+    text_dst[i].x = screen->w/2 - 70;
+    text_dst[i].y = text_dst[i - 1].y + 60;
+
+    /* --- setup location of button background --- */
+    menu_button[i].x = menu_button[i - 1].x;
+    menu_button[i].y = menu_button[i - 1].y + 60;
+    menu_button[i].w = menu_button[i - 1].w;
+    menu_button[i].h = menu_button[i - 1].h;
+
+    /* --- setup location of animated icon --- */
+    menu_gfxdest[i].x = menu_gfxdest[i - 1].x;
+    menu_gfxdest[i].y = menu_gfxdest[i - 1].y + 60;
+    menu_gfxdest[i].w = menu_gfxdest[i - 1].w;
+    menu_gfxdest[i].h = menu_gfxdest[i - 1].h;
+  }
+}
+
+
+
+static void unload_menu(void)
+{
+  int i,j;
+  printf("enter unload_menu()\n");
+
+  for (i = 1; i <= TITLE_MENU_ITEMS; i++)
+  {
+    for (j = 1; j <= TITLE_MENU_DEPTH; j++)
+    {
+      if (reg_text[i][j])
+        SDL_FreeSurface(reg_text[i][j]);
+      if (sel_text[i][j])
+        SDL_FreeSurface(sel_text[i][j]);
+      if (menu_gfx[i][j])
+        FreeSprite(menu_gfx[i][j]);
+      reg_text[i][j] = sel_text[i][j] = NULL;
+      menu_gfx[i][j] = NULL;
+    }
+  }
+}
+
+
+static int load_media(void)
+{
+  DEBUGCODE
+  {
+    fprintf(stderr, "Entering load_media():\n");
+    fprintf(stderr, "default_data_path = %s\n", settings.default_data_path);
+    fprintf(stderr, "theme_data_path = %s\n", settings.theme_data_path);
+  }
+
+  /* Make sure everything is unloaded before we start: */
+  /* FIXME have not been to do this to run without crashing: */
+  //unload_media();
+
+  /* --- load sounds --- */
+  if (settings.menu_sound)
+  {
+    snd_move = LoadSound("tock.wav");
+    snd_select = LoadSound("pop.wav");
+    if (!snd_move || !snd_select)
+    {
+      fprintf(stderr, "Could not load menu sounds - turning menu_sound off\n");
+      settings.menu_sound = 0;
+    }
+  }
+ 
+  /* --- load graphics --- */
+  LoadBothBkgds("main_bkg.png");
+  title = LoadImage( "title1.png", IMG_ALPHA );
+  speaker = LoadImage( "sound.png", IMG_ALPHA );
+  speakeroff = LoadImage( "nosound.png", IMG_ALPHA );
+  profiles = LoadImage("profiles.png", IMG_ALPHA)
+//  sel = LoadSprite("menu/sel", IMG_ALPHA);
+//  reg = LoadSprite("menu/reg", IMG_ALPHA);
+  Tux = LoadSprite("tux", IMG_ALPHA);
+
+  DEBUGCODE
+  {
+    fprintf(stderr, "titlescreen.c load_media(): settings.theme_font_name is %s\n",
+            settings.theme_font_name);
+  }
+  font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
+
+  /* Make sure we were successful: */
+  if (!CurrentBkgd()
+   || !title
+   || !speaker
+   || !speakeroff
+   || !profiles
+   || !Tux
+   || !font)
+  {
+    fprintf(stderr, "load_media() - could not load all needed files\n");
+    unload_media();
+    return 0;
+  }
+
+  /* Should probably call this directly from TitleScreen() */
+  load_menu();
+  return 1;
+}
+
+
+
+static void unload_media(void)
+{
+  LOG("Entering unload_media():\n");
+
+  /* --- unload sounds --- */
+  if (settings.menu_sound){
+ 
+    if (snd_move)
+    { 
+      Mix_FreeChunk(snd_move);
+      snd_move = NULL;
+    }
+    if (snd_select)
+    { 
+      Mix_FreeChunk(snd_select);
+      snd_select = NULL;
+    }
+  }
+
+  /* --- unload graphics --- */
+  if (title)
+  {
+    SDL_FreeSurface(title);
+    title = NULL;
+  }
+  if (speaker)
+  {
+    SDL_FreeSurface(speaker);
+    speaker = NULL;
+  }
+  if (speakeroff)
+  {
+    SDL_FreeSurface(speakeroff);
+    speakeroff = NULL;
+  }
+  if(profiles)
+  {
+	  SDL_FreeSurface(profiles);
+	  profiles = NULL;
+  }
+
+  FreeBothBkgds();
+
+  if (Tux)
+  {
+    FreeSprite(Tux);
+    Tux = NULL;
+  }
+
+  if (font)
+  {
+    TTF_CloseFont(font);
+    font = NULL;
+  }
+
+  LOG("Leaving load_media():\n");
+
+  unload_menu();
+}
+
+
+static void not_implemented(void)
+{
+  SDL_Surface *s1 = NULL, *s2 = NULL, *s3 = NULL, *s4 = NULL;
+  sprite* tux = NULL;
+  SDL_Rect loc;
+  int finished = 0, i;
+
+  LOG( "NotImplemented() - creating text\n" );
+
+  s1 = BlackOutline( gettext_noop("Work In Progress!"), font, &white);
+  s2 = BlackOutline( gettext_noop("This feature is not ready yet"), font, &white);
+  s3 = BlackOutline( gettext_noop("Discuss the future of TuxTyping at"), font, &white);
+
+  /* we always want the URL in english */
+  /* NOTE: all fonts are almost certain to include glyphs for ASCII, */
+  /* so the following "english_font" hackery is probably unnecessary: */
+  if (!settings.use_english)
+  {
+    TTF_Font *english_font;
+    settings.use_english = 1;
+    english_font = LoadFont(DEFAULT_MENU_FONT, MENU_FONT_SIZE);
+    s4 = BlackOutline( "http://tuxtype.sf.net/forums", english_font, &white);
+    TTF_CloseFont(english_font);
+    settings.use_english = 0;
+  }
+  else 
+    s4 = BlackOutline( "http://tuxtype.sf.net/forums", font, &white);
+
+  tux = LoadSprite("tux/tux-egypt", IMG_ALPHA);
+
+  if (s1 && s2 && s3 && s4 && tux)
+  {
+    LOG( "NotImplemented() - drawing screen\n" );
+
+    SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
+    loc.x = screen->w/2 - (s1->w/2); loc.y = 10;
+    SDL_BlitSurface( s1, NULL, screen, &loc);
+    loc.x = screen->w/2 - (s2->w/2); loc.y = 60;
+    SDL_BlitSurface( s2, NULL, screen, &loc);
+    loc.x = screen->w/2 - (s3->w/2); loc.y = screen->h/2 + 160;
+    SDL_BlitSurface(s3, NULL, screen, &loc);
+    loc.x = screen->w/2 - (s4->w/2); loc.y = screen->h/2 + 200;
+    SDL_BlitSurface( s4, NULL, screen, &loc);
+
+    loc.x = screen->w/2 - (tux->frame[0]->w/2);
+    loc.y = screen->h - 280;
+    loc.w = tux->frame[0]->w;
+    loc.h = tux->frame[0]->h;
+    SDL_BlitSurface( tux->frame[tux->cur], NULL, screen, &loc);
+
+    SDL_UpdateRect(screen, 0, 0, 0, 0);
+
+    i = 0;
+
+    while (!finished)
+    {
+      while (SDL_PollEvent(&event)) 
+      {
+        switch (event.type)
+        {
+          case SDL_QUIT:
+            exit(0);
+          case SDL_MOUSEBUTTONDOWN:
+          case SDL_KEYDOWN:
+            finished = 1;
+        }
+      }
+
+      i++;
+
+      if (i %5 == 0)
+      {
+        NEXT_FRAME(tux);
+        SDL_BlitSurface(CurrentBkgd(), &loc, screen, &loc);
+        SDL_BlitSurface(tux->frame[tux->cur], NULL, screen, &loc);
+        SDL_UpdateRect(screen, loc.x, loc.y, loc.w, loc.h);
+      }
+
+      SDL_Delay(40);
+    }
+  }
+  else
+    fprintf(stderr, "NotImplemented() - could not load needed graphic\n");
+
+  SDL_FreeSurface(s1);
+  SDL_FreeSurface(s2);
+  SDL_FreeSurface(s3);
+  SDL_FreeSurface(s4);
+  s1 = s2 = s3 = s4 = NULL;
+  FreeSprite(tux);
+  tux = NULL;
+}
+
+
+
+
+#define MAX_WORD_LISTS 100
+
+/* returns 0 if user pressed escape ...
+ *         1 if word list was set correctly
+ */
+static int chooseWordlist(void)
+{
+  SDL_Surface* titles[MAX_WORD_LISTS] = {NULL};
+  SDL_Surface* select[MAX_WORD_LISTS] = {NULL};
+  SDL_Surface* left = NULL, *right = NULL;
+  SDL_Rect leftRect, rightRect;
+  SDL_Rect titleRects[8];
+  int stop = 0;
+  int loc = 0;
+  int old_loc = 1;
+  int lists = 0;
+  int i;
+  unsigned char wordPath[FNLEN];
+  unsigned char wordlistFile[MAX_WORD_LISTS][200];
+  unsigned char wordlistName[MAX_WORD_LISTS][200];
+
+  DIR* wordsDir = NULL;
+  struct dirent* wordsFile = NULL;
+  FILE* tempFile = NULL;
+
+  LOG("Entering chooseWordlist():\n");
+
+  /* find the directory to load wordlists from */
+
+  /* Check under theme directory first, if theme selected: */
+  if (!settings.use_english)  /* Using theme: */
+  {
+    sprintf(wordPath,"%s/words", settings.theme_data_path);
+    if (!CheckFile(wordPath))
+    {
+      fprintf(stderr, "chooseWordList() - theme contains no wordlist dir \n");
+      return 0;
+    }
+  }
+  else  /* No theme selected - using English: */
+  {
+    sprintf(wordPath,"%s/words", settings.default_data_path);
+    if (!CheckFile(wordPath))
+    {
+      fprintf(stderr, "chooseWordList() - data path contains no wordlist dir \n");
+      return 0;
+    }
+  }
+
+  /* If we get to here, we know there is at least a wordlist directory */
+  /* but not necessarily any valid files.                              */
+
+  DEBUGCODE { fprintf(stderr, "wordPath is: %s\n", wordPath); }
+
+
+  /* FIXME looks like a place for scandir() - or our own w32_scandir() */
+  /* create a list of all the .txt files */
+
+  wordsDir = opendir( wordPath );	
+
+  do
+  {
+    wordsFile = readdir(wordsDir);
+    if (!wordsFile)
+      break; /* Loop continues until break occurs */
+
+    /* must have at least .txt at the end */
+    if (strlen(wordsFile->d_name) < 5)
+      continue;
+
+    if (strcmp(&wordsFile->d_name[strlen(wordsFile->d_name)-4],".txt"))
+      continue;
+
+    sprintf(wordlistFile[lists], "%s/%s", wordPath, wordsFile->d_name);
+
+    /* load the name for the wordlist from the file ... (1st line) */
+    tempFile = fopen( wordlistFile[lists], "r" );
+    if (!tempFile)
+      continue;
+
+    fscanf(tempFile, "%[^\n]\n", wordlistName[lists]);
+
+    /* check to see if it has a \r at the end of it (dos format!) */
+    if (wordlistName[lists][strlen(wordlistName[lists]) - 1] == '\r')
+      wordlistName[lists][strlen(wordlistName[lists]) - 1] = '\0';
+
+    lists++;
+
+    fclose(tempFile);
+  } while (1); /* Loop continues until break occurs */
+
+  closedir(wordsDir);	
+ 
+ DEBUGCODE { fprintf(stderr, "Found %d .txt file(s) in words dir\n", lists); }
+
+
+
+  /* let the user pick the list */
+
+  /* Render SDL_Surfaces for list entries: */
+//  titles[0] = BlackOutline( _("Alphabet"), font, &white );
+//  select[0] = BlackOutline( _("Alphabet"), font, &yellow);
+
+  /* NOTE - no longer hard-coding titles[0] to be alphabet - themes  */
+  /* should include a regular word list file called "alphabet.txt"   */
+  /* Should sort the list and always put the alphabet file first, if */
+  /* present.                                                        */
+  for (i = 0; i < lists; i++)
+  {
+    titles[i] = BlackOutline( wordlistName[i], font, &white );
+    select[i] = BlackOutline( wordlistName[i], font, &yellow);
+  }
+
+  left = LoadImage("left.png", IMG_ALPHA);
+  right = LoadImage("right.png", IMG_ALPHA);
+
+  /* Get out if needed surface not loaded successfully: */
+  if (!CurrentBkgd() || !left || !right)
+  {
+    fprintf(stderr, "chooseWordList(): needed image not available\n");
+  
+    for (i = 0; i < lists; i++)
+    {
+      SDL_FreeSurface(titles[i]);
+      SDL_FreeSurface(select[i]);
+      titles[i] = select[i] = NULL;
+    }
+
+    SDL_FreeSurface(left);
+    SDL_FreeSurface(right);
+    left = right = NULL;
+
+    return 0;
+  }
+  
+
+
+  leftRect.w = left->w;
+  leftRect.h = left->h;
+  leftRect.x = screen->w/2 - 80 - (leftRect.w/2);
+  leftRect.y = screen->h/2 - 50;
+
+  rightRect.w = right->w; rightRect.h = right->h;
+  rightRect.x = screen->w/2 + 80 - (rightRect.w/2); rightRect.y = screen->h/2 - 50;
+
+  /* set initial rect sizes */
+  titleRects[0].y = 30;
+  titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
+
+  for (i = 1; i < 8; i++)
+  { 
+    titleRects[i].y = titleRects[i - 1].y + 50;
+    titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
+  }
+
+  /* Main event loop for this screen: */
+  while (!stop)
+  {
+    while (SDL_PollEvent(&event))
+    {
+      switch (event.type)
+      {
+        case SDL_QUIT:
+          exit(0); /* FIXME may need to cleanup memory and exit more cleanly */
+          break;
+
+        case SDL_MOUSEMOTION:
+          for (i=0; (i<8) && (loc-(loc%8)+i<lists); i++)
+            if (inRect( titleRects[i], event.motion.x, event.motion.y ))
+            {
+              loc = loc-(loc%8)+i;
+              break;
+            }
+          break;
+
+        case SDL_MOUSEBUTTONDOWN:
+                                        if (inRect( leftRect, event.button.x, event.button.y ))
+                                                if (loc-(loc%8)-8 >= 0) {
+                                                        loc=loc-(loc%8)-8;
+                                                        break;
+                                                }
+                                        if (inRect( rightRect, event.button.x, event.button.y ))
+                                                if (loc-(loc%8)+8 < lists) {
+                                                        loc=loc-(loc%8)+8;
+                                                        break;
+                                                }
+                                        for (i=0; (i<8) && (loc-(loc%8)+i<lists); i++)
+                                                if (inRect(titleRects[i], event.button.x, event.button.y)) {
+                                                        loc = loc-(loc%8)+i;
+							ClearWordList(); /* clear old selection */
+							//if (loc==0)
+							//  UseAlphabet(); 
+							//else
+							GenerateWordList(wordlistFile[loc]); 
+                                                        stop = 1;
+                                                        break;
+                                                }
+                                        break;
+                                case SDL_KEYDOWN:
+                                        if (event.key.keysym.sym == SDLK_ESCAPE) { stop = 2; break; }
+                                        if (event.key.keysym.sym == SDLK_RETURN) {
+						ClearWordList(); /* clear old selection */
+						//if (loc==0)
+						//  UseAlphabet(); 
+						//else
+						GenerateWordList(wordlistFile[loc]); 
+                                                stop = 1;
+                                                break;
+                                        }
+
+                                        if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP)) {
+                                                if (loc-(loc%8)-8 >= 0)
+                                                        loc=loc-(loc%8)-8;
+                                        }
+
+                                        if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) {
+                                                if (loc-(loc%8)+8 < lists)
+                                                        loc=(loc-(loc%8)+8);
+                                        }
+
+                                        if (event.key.keysym.sym == SDLK_UP) {
+                                                if (loc > 0)
+                                                        loc--;
+                                        }
+
+                                        if (event.key.keysym.sym == SDLK_DOWN) {
+                                                if (loc+1<lists)
+                                                        loc++;
+                                        }
+      }
+    }
+
+    if (old_loc != loc) {
+                        int start;
+
+                        SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL );
+
+                        start = loc - (loc % 8);
+                        for (i = start; i<MIN(start+8,lists); i++) {
+                                titleRects[i%8].x = screen->w/2 - (titles[i]->w/2);
+                                if (i == loc)
+                                        SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
+                                else
+                                        SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
+                        }
+
+                        /* --- draw buttons --- */
+
+                        if (start>0)
+                                SDL_BlitSurface( left, NULL, screen, &leftRect );
+
+                        if (start+8<lists)
+                                SDL_BlitSurface( right, NULL, screen, &rightRect );
+
+                        SDL_UpdateRect(screen, 0, 0, 0 ,0);
+                }
+                SDL_Delay(40);
+                old_loc = loc;
+  }
+
+  /* --- clear graphics before leaving function --- */ 
+  for (i = 0; i<lists; i++)
+  {
+    SDL_FreeSurface(titles[i]);
+    SDL_FreeSurface(select[i]);
+    titles[i] = select[i] = NULL;
+  }
+
+  SDL_FreeSurface(left);
+  SDL_FreeSurface(right);
+  left = right = NULL; /* Maybe overkill - about to be destroyed anyway */
+
+  DEBUGCODE { fprintf( stderr, "Leaving chooseWordlist();\n" ); }
+
+  if (stop == 2)
+    return 0;
+
+  return 1;
+}
+
+

Copied: tuxtype/branches/tuxtype-soc-mh/src/titlescreen.h (from rev 672, tuxtype/branches/tuxtype-soc-mh/titlescreen.h)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/titlescreen.h	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/titlescreen.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,19 @@
+
+/* --- SETUP MENU OPTIONS --- */
+
+#define TITLE_MENU_ITEMS                6 //originally 5
+#define TITLE_MENU_DEPTH                4
+
+#define OPTIONS_SUBMENU                 5 //originally
+#define LASER_SUBMENU	        	3
+#define CASCADE_SUBMENU	        	2
+#define ROOTMENU		        1
+
+
+/* --- timings for tux blinking --- */
+#define TUX1                            115
+#define TUX2                            118
+#define TUX3                            121
+#define TUX4                            124
+#define TUX5                            127
+#define TUX6                            130

Copied: tuxtype/branches/tuxtype-soc-mh/src/wordsperminute.c (from rev 672, tuxtype/branches/tuxtype-soc-mh/wordsperminute.c)
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/src/wordsperminute.c	                        (rev 0)
+++ tuxtype/branches/tuxtype-soc-mh/src/wordsperminute.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -0,0 +1,361 @@
+//Words per minute mode
+
+//currently only has an english file..
+//only calculates wpm if they finish the set, otherwise ignore
+#include "globals.h"
+#include "funcs.h"
+
+typedef struct lines{
+	wchar_t words[][]; 
+	int wcount; /* number of words in line */
+	int finished; /* chars that have to be typed to finish line */
+}lines;
+
+	lines typeline;
+	lines previewline;
+	lines templine;
+ 
+static SDL_Surface* bg = NULL;
+static letter_loc;
+static TTF_Font* font = NULL;
+int charsfinished;
+static Mix_Chunk* wrong = NULL;
+
+lines getTypeLine(void);
+lines getPreviewLine(void);
+void copyToTempLine(lines);
+static int wpm_load_media(void);
+static void wpm_unload_media(void);
+static void print_at(const wchar_t* pphrase, int wrap, int x, int y);
+void displayTypeLine(lines, int);
+void displayPreviewLine(lines, int);
+
+int wpm()
+{
+	Uint32 time = 30000, elapsed; /* 30 seconds */
+  	int quit = 0,
+  	i = 0,
+  	count = 0,
+  	wp = 0,
+  	z = 0;
+  	SDL_Rect dst;
+  	SDL_Surface* srfc = NULL;
+
+  	if (!wpm_load_media())
+  	{
+  		fprintf(stderr, "wpm() - wpm_load_media() failed, returning.\n");
+  		return 0;
+  	}
+
+  	SDL_BlitSurface(bg, NULL, screen, NULL);
+  	SDL_Flip(screen);
+
+  	srfc = GetWhiteGlyph(65);
+
+  	if (!srfc)
+  	{
+  		fprintf(stderr, "wpm() - GetWhiteGlyph(65) not defined - bailing out.\n");
+  		return 0;
+  	}
+  	
+  	dst.x = 40;
+  	dst.y = 10;
+  	dst.w = srfc->w;
+  	dst.h = srfc->h;
+  	
+  	getTypeLine();
+  	getPreviewLine();
+  	displayTypeLine(typeline, 1);
+  	displayPreviewLine(previewline, 1);
+
+  	copyToTempLine(typeline); //copy active to temp
+  	do
+  	{
+  		while  (SDL_PollEvent(&event))
+  		{
+  			if (event.type == SDL_KEYDOWN)
+  			{
+  				if (event.key.keysym.sym == SDLK_ESCAPE)
+  				{
+  					quit = 1;
+  				}
+  				else
+  				{
+  					if (templine.words[c]==(wchar_t)event.key.keysym.unicode)
+  					{
+  						srfc = GetRedGlyph(event.key.keysym.unicode);
+  						if (srfc)
+  						{
+  							SDL_BlitSurface(srfc, NULL, screen, &dst);
+  							dst.x = (dst.x + srfc->w) - 5;
+  						}
+  						charsfinished++;
+  						c++;
+  						templine.finished--;
+  					}
+  					else
+  					{
+  						if (event.key.keysym.sym != SDLK_RSHIFT
+  								&& event.key.keysym.sym != SDLK_LSHIFT)
+  						{
+  							PlaySound(wrong);
+  						}
+  					}
+  				}
+  			}
+  		}
+  		if(templine.finished <= 0)
+  		{
+  			displayTypeLine(templine, 0); //erase top line
+  			copyToTempFile(previewline); //copy preview to temp
+  			displayTypeLine(tempfile, 1); //move preview to active
+  			displayPreviewLine(previewline, 0) //erase bottom
+  			getPreviewLine(); //get new bottom
+  			displayPreviewLine(previewline, 1) //display bottom
+  		}
+  		SDL_Flip(screen);
+  		SDL_Delay(30);
+  		elapsed = time - SDL_GetTicks();
+  	}
+  	while (!quit && elapsed > 0);
+  	if (elapsed)
+  	{
+  		updateWPM(charsfinished);
+  		checkWPM(charsfinished);
+  	}
+  wpm_unload_media();
+
+  return 1;
+}
+
+static int wpm_load_media(void)
+{
+  int i;
+  unsigned char fn[FNLEN];
+  unsigned char let[5];
+
+  LOG("Loading wpm media\n");
+
+
+  bg = LoadImage("main_bkg.png", IMG_ALPHA);
+  wrong = LoadSound("tock.wav");
+  font = LoadFont(settings.theme_font_name, 30);
+
+  /* Get out if anything failed to load: */
+  if (!bg
+    ||!wrong
+    ||!font)
+  {
+    fprintf(stderr, "wpm_load_media() - failed to load needed media \n");
+    wpm_unload_media();
+    return 0;
+  }
+
+  /* Now render letters for glyphs in alphabet: */
+  RenderLetters(font);
+  TTF_CloseFont(font);  /* Don't need it after rendering done */
+  font = NULL;
+
+  LOG("DONE - Loading wpm media\n");
+  return 1;
+}
+
+static void wpm_unload_media(void)
+{
+	int i;
+	SDL_FreeSurface(bg);
+	bg = NULL;
+	Mix_FreeChunk(wrong);
+	wrong = NULL;
+}
+void getTypeLine()
+{
+	int count = 0;
+	int linewidth = 0; //keep lines to 598 pixels
+	typeline.finished = 0 ;
+	typeline.wcount = 0;
+	do
+	{
+		typeline.words[typeline.wcount] = strcat(GetWord(), " ");
+		typeline.wcount++;
+		SDL_Surface* let = NULL;
+		for (count = 0; count <= typeline.wcount; count++)
+		{							
+			i = 0;
+			while( i < wcslen(typeline.words[count]) && linewidth < 598)
+			{
+				let = GetWhiteGlyph((int)typeline.words[count][i]);
+				if (let)
+				{
+					linewidth+= let->w - 5;
+					typeline.finished++;
+				}	
+				else
+				{
+					fprintf(stderr, "getTypeLine() - needed glyph not available\n");
+					return;
+				}
+				i++;
+			}
+		}
+	}
+	while(linewidth < 598);
+	typeline.words[count] = NULL;
+	typeline.wcount--;
+}
+void getPreviewLine()
+{
+	int count = 0;
+	int linewidth = 0; //keep it to a line 598 pixels
+	previewline.wcount = 0;
+	previewline.finished = 0;
+	do
+	{
+		previewline.words[previewline.wcount] = strcat(GetWord(), " ");
+		previewline.wcount++;
+		SDL_Surface* let = NULL;
+		for (count = 0; count <= previewline.wcount; count++)
+		{							
+			i = 0;
+			while( i < wcslen(previewline.words[count]) && linewidth < 598)
+			{
+				let = GetWhiteGlyph((int)previewline.words[count][i]);
+				if (let)
+				{
+					linewidth+= let->w - 5;
+					previewline.finished++;
+				}	
+				else
+				{
+					fprintf(stderr, "getTypeLine() - needed glyph not available\n");
+					return;
+				}
+				i++;
+			}
+		}
+	}
+	while(linewidth < 598);
+	previewline.words[count] = NULL;
+	previewline.wcount--;
+}
+void displayTypeLine(lines tline, int switcher)
+{
+	int i = 0;
+	int count;
+	SDL_Surface* surf = NULL;
+	letter_loc.x = 40;
+	letter_loc.y = 10;
+	letter_loc.w = GetWhiteGlyph(65)->w;
+	letter_loc.h = GetWhiteGlyph(65)->h;
+	
+	if(switcher)
+	{
+		for (count = 0; count < wcslen(tline.words[count]); count++)
+		{
+			for(i = 0; i < wcslen(tline.words[count][i]); i++)
+			{
+				surf = GetWhiteGlyph(tline.words[count][i]);
+				if (surf)
+				{
+					SDL_BlitSurface(surf, NULL, screen, &letter_loc);
+					letter_loc.x = (letter_loc.x + surf->w) - 5;
+				}
+				else
+				{
+					fprintf(stderr, "print_at(): needed glyph for %C not found\n",
+							pphrase[z]);
+				}
+			}
+		}
+	}
+	else //cleanup because old
+	{
+		for (count = 0; count < wcslen(tline.words[count]); count++)
+		{
+			for(i = 0; i < wcslen(tline.words[count][i]); i++)
+			{
+				surf = GetWhiteGlyph(tline.words[count][i]);
+				if (surf)
+				{
+					letter_loc.x = (letter_loc.x + surf->w) - 5;
+					SDL_FreeSurface(surf);
+				}
+			}
+		}
+	}
+}
+void displayPreviewLine(lines pline, int switcher)
+{	
+	int i = 0;
+	int count;
+	SDL_Surface* surf = NULL;
+	letter_loc.x = 40
+	letter_loc.w = GetWhiteGlyph(65)->w;
+	letter_loc.h = GetWhiteGlyph(65)->h;
+	letter_loc.y = 10 + letter_loc.h -(letter_loc.h/4);
+	if(switcher)
+	{
+		for (count = 0; count < wcslen(pline.words[count]); count++)
+		{
+			for(i = 0; i < wcslen(pline.words[count][i]); i++)
+			{
+				surf = GetWhiteGlyph(pline.words[count][i]);
+				if (surf)
+				{
+					SDL_BlitSurface(surf, NULL, screen, &letter_loc);
+					letter_loc.x = (letter_loc.x + surf->w) - 5;
+				}
+				else
+				{
+					fprintf(stderr, "print_at(): needed glyph for %C not found\n",
+							pphrase[z]);
+				}
+			}
+		}
+	}
+	else //cleanup because old
+	{
+		for (count = 0; count < wcslen(pline.words[count]); count++)
+		{
+			for(i = 0; i < wcslen(pline.words[count][i]); i++)
+			{
+				surf = GetWhiteGlyph(pline.words[count][i]);
+				if (surf)
+				{
+					letter_loc.x = (letter_loc.x + surf->w) - 5;
+					SDL_FreeSurface(surf);
+				}
+			}
+		}
+	}
+}
+void copyToTemp(lines x)
+{
+	int count = 0;
+	templine.wcount = 0;
+	templine.finished = 0;
+	do
+	{
+		templine.words[templine.wcount] = x.word[count];
+		templine.wcount++;
+		SDL_Surface* let = NULL;
+		for (count = 0; count <= x.wcount; count++)
+		{							
+			i = 0;
+			while( i < wcslen(x.words[count]))
+			{
+				let = GetWhiteGlyph((int)x.words[count][i]);
+				if (let)
+				{
+					templine.finished++;
+				}	
+				else
+				{
+					fprintf(stderr, "getTypeLine() - needed glyph not available\n");
+					return;
+				}
+				i++;
+			}
+		}
+	}
+}

Deleted: tuxtype/branches/tuxtype-soc-mh/theme.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/theme.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/theme.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,328 +0,0 @@
-/***************************************************************************
-                          theme.c 
- -  description: theme related code
-                             -------------------
-    begin                : Jan 6 2003
-    copyright            : (C) 2003 by Jesse Andrews et al
-    email                : jdandr2 at tux4kids.net
- ***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-
-
-SDL_Surface* letters[255] = {NULL}; //get rid of this
-wchar_t ALPHABET[256];
-int ALPHABET_SIZE;
-
-
-#define MAX_LANGUAGES 100
-
-
-
-void ChooseTheme(void)
-{
-  SDL_Surface* titles[MAX_LANGUAGES] = {NULL};
-  SDL_Surface* select[MAX_LANGUAGES] = {NULL};
-  SDL_Surface* left = NULL;
-  SDL_Surface* right = NULL;
-  SDL_Surface* world = NULL;
-  SDL_Surface* map = NULL;
-  SDL_Surface* photo = NULL;
-  SDL_Rect leftRect, rightRect;
-  SDL_Rect worldRect, photoRect;
-  SDL_Rect titleRects[8];
-  TTF_Font* font = NULL;  
-  int stop = 0;
-  int loc = 0;
-  int old_loc = 1;
-
-  int themes = 1;
-  int i;
-  unsigned char fn[FNLEN];
-  unsigned char themeNames[MAX_LANGUAGES][FNLEN];
-  unsigned char themePaths[MAX_LANGUAGES][FNLEN];
-
-  int old_use_english;
-  char old_theme_path[FNLEN];
-
-  DIR* themesDir = NULL;
-  struct dirent* themesFile = NULL;
-
-  /* save previous settings in case we back out: */
-  old_use_english = settings.use_english;
-  strncpy(old_theme_path, settings.theme_data_path, FNLEN - 1);
-
-  sprintf(fn, "%s/themes/", settings.default_data_path);
-  themesDir = opendir(fn);
-
-  if (!themesDir)
-  {
-    fprintf(stderr, "ChooseTheme() - cannot open themes directory!");
-    return;
-  }
-
-  do  /* Iterate until readdir() returns NULL: */
-  {
-    themesFile = readdir(themesDir);
-    if (!themesFile)
-      break;
-
-    /* we ignore any hidden file and CVS */
-    if (themesFile->d_name[0] == '.') 
-      continue;
-    if (strcmp("CVS", themesFile->d_name)==0)
-      continue;
-
-    /* check to see if it is a directory */
-    sprintf(fn, "%s/themes/%s", settings.default_data_path, themesFile->d_name);
-
-    /* CheckFile() returns 2 if dir, 1 if file, 0 if neither: */
-    if (CheckFile(fn) == 2)
-    {
-      /* HACK: we should get the names from file :) */
-      strncpy( themeNames[themes], themesFile->d_name, FNLEN-1);
-      /* Make sure theme name is capitalized: */
-      themeNames[themes][0] = toupper(themeNames[themes][0]);
-      strncpy( themePaths[themes++], themesFile->d_name, FNLEN-1 );
-    }
-  } while (1);
-
-  closedir(themesDir);
-
-  settings.use_english = 1;
-  // HACK: is font empty now???
-  font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
-
-  titles[0] = BlackOutline( "English", font, &white );
-  select[0] = BlackOutline( "English", font, &yellow);
-  for (i = 1; i < themes; i++)
-  {
-    titles[i] = BlackOutline( themeNames[i], font, &white );
-    select[i] = BlackOutline( themeNames[i], font, &yellow);
-  }
-
-  LoadBothBkgds("main_bkg.png");
-
-  world = LoadImage("world.png", IMG_ALPHA);
-  left = LoadImage("left.png", IMG_ALPHA);
-  right = LoadImage("right.png", IMG_ALPHA);
-
-  if (!world || !left || !right || !CurrentBkgd())
-  {
-    fprintf(stderr, "ChooseTheme() - could not load needed image.\n");
-    return;
-  }
-
-  worldRect.x = screen->w - world->w;
-  worldRect.w = world->w;
-  worldRect.y = 10;
-  worldRect.h = world->h;
-
-  leftRect.w = left->w;
-  leftRect.h = left->h;
-  leftRect.x = 160 - 80 - (leftRect.w/2);
-  leftRect.y = 430;
-
-  rightRect.w = right->w;
-  rightRect.h = right->h;
-  rightRect.x = 160 + 80 - (rightRect.w/2); 
-  rightRect.y = 430;
-
-  /* set initial rect sizes */
-  titleRects[0].y = 30;
-  titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
-  for (i = 1; i < 8; i++)
-  {
-    titleRects[i].y = titleRects[i - 1].y + 50;
-    titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
-  }
-
-  TTF_CloseFont(font);
-  font = NULL;
-  settings.use_english = old_use_english;
-
-  while (!stop)
-  {
-    while (SDL_PollEvent(&event)) 
-      switch (event.type)
-      {
-        case SDL_QUIT:
-        exit(0);
-        break;
-
-        case SDL_MOUSEMOTION:
-          for (i = 0; (i < 8) && (loc - (loc%8) + i < themes); i++)
-            if (inRect( titleRects[i], event.motion.x, event.motion.y ))
-            {
-              loc = loc-(loc%8)+i;
-              break;
-            }
-
-          break;
-
-        case SDL_MOUSEBUTTONDOWN: 
-          if (inRect( leftRect, event.button.x, event.button.y )) 
-            if (loc-(loc%8)-8 >= 0)
-            {
-              loc=loc-(loc%8)-8;
-              break;
-            }
-
-          if (inRect( rightRect, event.button.x, event.button.y )) 
-            if (loc-(loc%8)+8 < themes)
-            {
-              loc=loc-(loc%8)+8;
-              break;
-            }
-
-          for (i=0; (i<8) && (loc-(loc%8)+i<themes); i++) 
-            if (inRect(titleRects[i], event.button.x, event.button.y))
-            {
-              loc = loc-(loc%8)+i;
-              if (loc)
-              {
-                /* --- set theme --- */
-                SetupPaths(themePaths[loc]);
-              }
-              else
-              {
-                /* --- english --- */
-                SetupPaths(NULL);
-              }
-
-              stop = 1;
-              break;
-            }
-          break;
-
-        case SDL_KEYDOWN:
-          if (event.key.keysym.sym == SDLK_ESCAPE)
-          {
-            settings.use_english = old_use_english;
-            strncpy(settings.theme_data_path, old_theme_path, FNLEN - 1);
-            stop = 1; 
-            break; 
-          }
-
-          if (event.key.keysym.sym == SDLK_RETURN)
-          { 
-            if (loc)
-            {
-              /* --- set theme --- */
-              SetupPaths(themePaths[loc]);
-            }
-            else
-            {
-              /* --- English --- */
-              SetupPaths(NULL);
-            }
-
-            stop = 1;
-            break;
-          }
-
-          if ((event.key.keysym.sym == SDLK_LEFT)
-           || (event.key.keysym.sym == SDLK_PAGEUP))
-          {
-            if (loc-(loc%8)-8 >= 0) 
-              loc=loc-(loc%8)-8;
-          }
-
-          if ((event.key.keysym.sym == SDLK_RIGHT)
-           || (event.key.keysym.sym == SDLK_PAGEDOWN))
-          {
-            if (loc-(loc%8)+8 < themes)
-              loc=(loc-(loc%8)+8);
-          }
-
-          if (event.key.keysym.sym == SDLK_UP)
-          {
-            if (loc > 0)
-              loc--;
-          }
-
-          if (event.key.keysym.sym == SDLK_DOWN)
-          {
-            if (loc+1<themes)
-              loc++;
-          }
-        }
-
-    if (old_loc != loc)
-    {
-      int start;
-
-      SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL );
-      SDL_BlitSurface( world, NULL, screen, &worldRect );
-
-      if (loc)
-        SetupPaths(themePaths[loc]);
-      else
-        SetupPaths(NULL);
-
-      map = LoadImage( "map.png", IMG_ALPHA|IMG_NOT_REQUIRED );
-      if (map)
-      {
-        SDL_BlitSurface( map, NULL, screen, &worldRect );
-        SDL_FreeSurface( map );
-      }
-
-      photo = LoadImage( "photo.png", IMG_ALPHA|IMG_NOT_REQUIRED );
-      if (photo)
-      {
-        photoRect.x = 480 - (photo->w/2);
-        photoRect.y = 250;
-        photoRect.w = photo->w;
-        photoRect.h = photo->h;
-        SDL_BlitSurface( photo, NULL, screen, &photoRect );
-        SDL_FreeSurface( photo );
-      }
-
-      start = loc - (loc % 8);
-
-      for (i = start; i<MIN(start+8,themes); i++)
-      {
-        titleRects[i%8].x = 160 - (titles[i]->w/2);
-
-        if (i == loc)
-          SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
-        else
-          SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
-      }
-
-      /* --- draw buttons --- */
-      if (start>0) 
-        SDL_BlitSurface( left, NULL, screen, &leftRect );
-
-      if (start+8<themes) 
-        SDL_BlitSurface( right, NULL, screen, &rightRect );
-
-      SDL_UpdateRect(screen, 0, 0, 0 ,0);
-    }
-    SDL_Delay(40);
-    old_loc = loc;
-  }
-
-  /* --- clear graphics before quitting --- */ 
-
-  for (i = 0; i<themes; i++)
-  {
-    SDL_FreeSurface(titles[i]);
-    SDL_FreeSurface(select[i]);
-  }
-
-  SDL_FreeSurface(world);
-  SDL_FreeSurface(left);
-  SDL_FreeSurface(right);
-
-}

Deleted: tuxtype/branches/tuxtype-soc-mh/titlescreen.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/titlescreen.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/titlescreen.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,1576 +0,0 @@
-/***************************************************************************
- -  file: titlescreen.c
- -  description: splash, title and menu screen functionality 
-                            ------------------
-    begin                : Thur May 4 2000
-    copyright            : (C) 2000 by Sam Hart
-                         : (C) 2003 by Jesse Andrews
-    email                : tuxtype-dev at tux4kids.net
-***************************************************************************/
-
-/***************************************************************************
- *                                                                         *
- *   This program is free software; you can redistribute it and/or modify  *
- *   it under the terms of the GNU General Public License as published by  *
- *   the Free Software Foundation; either version 2 of the License, or     *
- *   (at your option) any later version.                                   *
- *                                                                         *
- ***************************************************************************/
-
-#include "globals.h"
-#include "funcs.h"
-#include "titlescreen.h"
-#include "SDL_extras.h"
-
-/* --- media for menus --- */
-
-/* images of regular and selected text of menu items: */
-static SDL_Surface* reg_text[TITLE_MENU_ITEMS + 1][TITLE_MENU_DEPTH + 1] = {NULL};
-static SDL_Surface* sel_text[TITLE_MENU_ITEMS + 1][TITLE_MENU_DEPTH + 1] = {NULL};
-/* this will contain pointers to all of the menu 'icons' */
-static sprite* menu_gfx[TITLE_MENU_ITEMS + 1][TITLE_MENU_DEPTH + 1] = {NULL};
-
-/* Background images for windowed and fullscreen modes: */
-static SDL_Surface* win_bkgd = NULL; //640x480 background (windowed)
-static SDL_Surface* fullscr_bkgd = NULL; //native resolution (fullscreen)
-
-/* --- other media --- */
-static SDL_Surface* title = NULL;
-static SDL_Surface* speaker = NULL;
-static SDL_Surface* speakeroff = NULL;
-static SDL_Surface* profiles = NULL;
-static sprite* Tux = NULL;
-static Mix_Chunk* snd_move = NULL;
-static Mix_Chunk* snd_select = NULL;
-static TTF_Font* font = NULL;
-
-/* --- locations we need --- */
-static SDL_Rect text_dst[TITLE_MENU_ITEMS + 1];     // location of menu text
-static SDL_Rect menu_gfxdest[TITLE_MENU_ITEMS + 1]; // location of menu sprite
-static SDL_Rect menu_button[TITLE_MENU_ITEMS + 1];  // menu mouse event buttons
-/* keep track of the width of each menu: */
-static int menu_width[TITLE_MENU_DEPTH + 1];
-
-static SDL_Rect Tuxdest;
-static SDL_Rect Titledest;
-static SDL_Rect spkrdest;
-static SDL_Rect cursor;
-static SDL_Rect profilesdest;
-
-/* Local function prototypes: */
-static void show_logo(void);
-static int load_media(void);
-static void load_menu(void);
-static void recalc_rects(void);
-static int chooseWordlist(void);
-static void not_implemented(void);
-static void unload_media(void);
-static void unload_menu(void);
-
-/* --- menu text --- */
-
-/* --- define menu structure --- */
-/* (these values are all in the Game_Type enum in globals.h) */
-const int menu_item[][7]= {{0, 0,         0,         0,          0},
-			   {0, CASCADE,   	LEVEL1,    	LEVEL1,	NOT_CODED },
-			   {0, LASER,     	LEVEL2,    	LEVEL2,	FREETYPE   },
-			   {0, LESSONS,  	LEVEL3,    	LEVEL3,	PROJECT_INFO },
-			   {0, WPM,			INSTRUCT,	LEVEL4,	HIGH_SCORES},
-			   {0, OPTIONS,   	MAIN,  		MAIN,	SET_LANGUAGE},
-			   {0, QUIT_GAME, 	0,      	0,  	MAIN}};
-
-/* --- menu icons --- */ //no icons wpm or highscore
-const unsigned char *menu_icon[][7]=
-{{"", "", 			"", 		"", 		""},
- {"", "cascade",	"easy",   	"grade1_", 	"list"   },
- {"", "comet",   	"medium", 	"grade2_", 	"practice" },
- {"", "lesson",		"hard",   	"grade3_", 	"keyboard"   },
- {"", "WPM", 		"tutor",  	"grade4_", 	"highscores" },
- {"", "tux_config",	"main",  	"main", 	"lang" },
- {"", "quit",    	"",   		"",    		"main"   }};
-
-/* --- menu text --- */
-static const char *menu_text[]=
-{{"", "",            					"",             				"",            					""    },
- {"", gettext_noop("Fish Cascade"), 	gettext_noop("Easy"),       	gettext_noop("Space Cadet"), 	gettext_noop("Edit Word Lists")},
- {"", gettext_noop("Comet Zap"),		gettext_noop("Medium"),       	gettext_noop("Pilot"),       	gettext_noop("Practice")},
- {"", gettext_noop("Lessons"),			gettext_noop("Hard"),         	gettext_noop("Ace"),         	gettext_noop("Project Info")},
- {"", gettext_noop("WPM Calculator"),	gettext_noop("Instructions"), 	gettext_noop("Commander"), 		gettext_noop("High Scores")},
- {"", gettext_noop("Options"),      	gettext_noop("Main Menu"), 		gettext_noop("Main Menu"),   	gettext_noop("Setup Language")},
- {"", gettext_noop("Quit"),         	"",    							"",   							gettext_noop("Main Menu")}};
-
-
-
-/************************************************************************/
-/*                                                                      */ 
-/*         "Public" functions (callable throughout program)             */
-/*                                                                      */
-/************************************************************************/
-
-
-/****************************************
-* TitleScreen: Display the title screen *
-*****************************************
-* display title screen, get input
-*/
-void TitleScreen(void)
-{
-
-  Uint32 frame = 0;
-  Uint32 start = 0;
-
-  /* NOTE for 'depth', think pages like a restaurant menu, */
-  /* not heirarchical depth - choice of term is misleading */
-  int menu_depth; // how deep we are in the menu
-
-  int i, j, tux_frame = 0;
-  int done = 0;
-  int firstloop = 1;
-  int menu_opt = NONE;
-  int sub_menu = NONE;
-  int update_locs = 1;
-  int redraw = 0;
-  int key_menu = 1;
-  int old_key_menu = 5;
-  wchar_t phrase[128];
-  FILE *fp;
-  unsigned char fn[FNLEN];
-  int found = 0;
-  unsigned char str[1000];
-
-
-  if (settings.sys_sound)
-  {
-    settings.menu_sound = 1;
-    settings.menu_music = 1;
-  }
-
-  
-  /* FIXME phrase(s) should come from file */
-
-  ConvertFromUTF8(phrase, "The quick brown fox jumps over the lazy dog.");
-
-//  wcscpy(phrase, "Now is the time for all good men to come to the aid of their country.");
-  start = SDL_GetTicks();
-
-
-  /*
-  * Display the Standby screen.... 
-  */
-  show_logo();
-
-  /* Load media and menu data: */
-  if (!load_media())
-  {
-    fprintf(stderr, "TitleScreen - load_media() failed!");
-    return;
-  }
-
-  SDL_WM_GrabInput(SDL_GRAB_ON); // User input goes to TuxType, not window manager
-
-
-  /***************************
-  * Tux and Title animations *
-  ***************************/
-
-  LOG( "->Now Animating Tux and Title onto the screen\n" );
-
-  Tuxdest.x = 0;
-  Tuxdest.y = screen->h;
-  Tuxdest.w = Tux->frame[0]->w;
-  Tuxdest.h = Tux->frame[0]->h;
-
-  Titledest.x = screen->w;
-  Titledest.y = 10;
-  Titledest.w = title->w;
-  Titledest.h = title->h;
-
-  spkrdest.x = screen->w - speaker->w - 10;
-  spkrdest.y = screen->h - speaker->h - 10;
-  spkrdest.w = speaker->w;
-  spkrdest.h = speaker->h;
-  
-  profilesdest.x = 572;
-  profilesdest.y = 420;
-  profilesdest.w = profiles->w; 
-  profilesdest.h = profiles->h;
-
-  /* --- wait if the first time in the game --- */
-
-  if (settings.show_tux4kids)
-  {
-    while ((SDL_GetTicks() - start) < 2000)
-    {
-      SDL_Delay(50);
-    }
-    settings.show_tux4kids = 0;
-  }
-
-  SDL_ShowCursor(1);    
-  /* FIXME not sure the next line works in Windows: */
-  TransWipe(CurrentBkgd(), RANDOM_WIPE, 10, 20);
-  /* Make sure background gets drawn (since TransWipe() doesn't */
-  /* seem to work reliably as of yet):                          */
-  SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
-  SDL_UpdateRect(screen, 0, 0, 0, 0);
-
-  /* --- Pull tux & logo onscreen --- */
-  for (i = 0; i <= (PRE_ANIM_FRAMES * PRE_FRAME_MULT); i++)
-  {
-    start = SDL_GetTicks();
-    SDL_BlitSurface(CurrentBkgd(), &Tuxdest, screen, &Tuxdest);
-    SDL_BlitSurface(CurrentBkgd(), &Titledest, screen, &Titledest);
-
-    Tuxdest.y -= Tux->frame[0]->h / (PRE_ANIM_FRAMES * PRE_FRAME_MULT);
-    Titledest.x -= (screen->w) / (PRE_ANIM_FRAMES * PRE_FRAME_MULT);
-
-    SDL_BlitSurface(Tux->frame[0], NULL, screen, &Tuxdest);
-    SDL_BlitSurface(title, NULL, screen, &Titledest);
-
-    SDL_UpdateRect(screen, Tuxdest.x, Tuxdest.y, Tuxdest.w, Tuxdest.h);
-    SDL_UpdateRect(screen, Titledest.x, Titledest.y, Titledest.w + 40, Titledest.h);
-
-    while ((SDL_GetTicks() - start) < 33) 
-    {
-      SDL_Delay(2);
-    }
-  }
-
-  recalc_rects();
-
-  /* Pick speaker graphic according to whether music is on: */
-  if ( settings.menu_music )
-    SDL_BlitSurface(speaker, NULL, screen, &spkrdest);
-  else
-    SDL_BlitSurface(speakeroff, NULL, screen, &spkrdest);
-
-  /* Start playing menu music if desired: */
-  if (settings.menu_music)
-    MusicLoad( "tuxi.ogg", -1 );
-
-  LOG( "Tux and Title are in place now\n" );
-
-  /* Move mouse to top button: */
-  cursor.x = menu_button[1].x + (menu_button[1].w / 2);
-  cursor.y = menu_button[1].y + (3 * menu_button[1].h / 4);
-  SDL_WarpMouse(cursor.x, cursor.y);
-  SDL_WM_GrabInput(SDL_GRAB_OFF);
-
-
-  /****************************
-  * Main Loop Starts Here ... *
-  ****************************/
-
-
-  menu_depth = 1;
-  firstloop = 1;
-  Tuxdest.y = screen->h - Tux->frame[0]->h;
-
-  profilesSelector();
-  
-  while (!done) 
-  {
-
-    start=SDL_GetTicks();
-
-    /* ---process input queue --- */
-
-    menu_opt = NONE; // clear the option so we don't change twice!
-
-    old_key_menu = key_menu;
-
-    /* Retrieve any user interface events: */
-    while (SDL_PollEvent(&event))
-    {
-      switch (event.type)
-      {
-
-        case SDL_MOUSEMOTION:
-        {
-          cursor.x = event.motion.x;
-          cursor.y = event.motion.y;
-          break;
-        }
-
-
-        /* Handle mouse clicks based on mouse location: */
-        case SDL_MOUSEBUTTONDOWN:
-        {
-          cursor.x = event.motion.x;
-          cursor.y = event.motion.y;
-
-          for (j = 1; j <= TITLE_MENU_ITEMS; j++)
-          {
-            if (inRect(menu_button[j], cursor.x, cursor.y))
-            {
-              menu_opt = menu_item[j][menu_depth];
-              if (settings.menu_sound)
-              {
-                PlaySound(snd_select);
-              }
-              DEBUGCODE
-              {
-                fprintf(stderr, "->>BUTTON CLICK menu_opt = %d\n", menu_opt);
-                fprintf(stderr, "->J = %d menu_depth=%d\n", j, menu_depth);
-              }
-            }
-          }
-
-          /* If mouse over speaker, toggle menu music off or on: */
-          if (inRect(spkrdest, cursor.x, cursor.y))
-          {
-            if (settings.menu_music)
-            {
-              MusicUnload();
-              settings.menu_music = 0;
-            }
-            else
-            {
-              settings.menu_music = 1;
-              MusicLoad("tuxi.ogg", -1);
-            }
-            redraw = 1;
-          }
-          /* If mouse is over profiles, call selector */
-          if ((cursor.x >= profilesdest.x && cursor.x <= (profilesdest.x + profilesdest.w)) &&
-        		  (cursor.y >= profilesdest.y && cursor.y <= (profilesdest.y + profilesdest.h)))
-          {
-        	  profilesSelector();
-          }
-          break;
-        }
-
-
-
-        case SDL_QUIT:
-        {
-          menu_opt = QUIT_GAME;
-          break;
-        }
-
-
-        /* Handle key press events based on key value: */
-        case SDL_KEYDOWN:
-        {
-          switch (event.key.keysym.sym)
-          {
-            case SDLK_ESCAPE:
-            {
-              /* Go to main menu (if in submenu) or quit: */
-              if (menu_depth != 1) 
-                menu_opt = MAIN;
-              else
-                menu_opt = QUIT_GAME;
-
-              if (settings.menu_sound)
-                PlaySound(snd_select);
-              break;
-            }
-
-
-            /* Toggle screen mode: */
-            case SDLK_F10:
-            {
-              SwitchScreenMode();
-              recalc_rects();
-              redraw = 1;
-              break;
-            }
-
-
-            /* Toggle menu music: */
-            case SDLK_F11:
-            {
-              if (settings.menu_music)
-              {
-                MusicUnload( );
-                settings.menu_music = 0;
-              }
-              else
-              {
-                settings.menu_music = 1;
-                MusicLoad("tuxi.ogg", -1);
-              }
-              redraw = 1;
-              break;
-            }
-
-
-            /* --- reload translation/graphics/media: for themers/translaters --- */
-            case SDLK_F12:
-            {
-              unload_media();
-              LoadLang();
-              load_media();
-              redraw = 1;
-              break;
-            }
-
-
-            case SDLK_UP:
-            {
-              if (settings.menu_sound)
-                PlaySound(snd_move);
-              key_menu--;
-              if (key_menu < 1)
-                key_menu = 5;
-              break;
-            }
-
-
-            case SDLK_DOWN:
-            {
-              key_menu++;
-              if (settings.menu_sound)
-                PlaySound(snd_move);
-              if (key_menu > 5)
-                key_menu = 1;
-              break;
-            }
-
-
-            case SDLK_RETURN:
-            {
-              if (key_menu)
-              {
-                menu_opt = menu_item[key_menu][menu_depth];
-                if (settings.menu_sound)
-                  PlaySound(snd_select);
-              }
-              break;
-            }
-
-
-            default:     /* Some other key pressed - do nothing: */
-            {
-              break;
-            }
-          }             /* End of switch(event.key.keysym.sym) statement */
-        }               /* End of case: SDL_KEYDOWN: */
-
-
-        default:        /* Some other type of SDL event - do nothing;    */
-        {
-          break;
-        }
-      }                 /* End of switch(event.type) statement           */
-    }	              /* End of while (SDL_PollEvent(&event)) loop     */
-
-
-
-    /* --- warp mouse to follow keyboard input --- */
-
-    if (old_key_menu != key_menu)
-    {
-      cursor.x = menu_button[key_menu].x + (menu_button[key_menu].w / 2);
-      cursor.y = menu_button[key_menu].y + (3 * menu_button[key_menu].h / 4);
-      SDL_WarpMouse(cursor.x, cursor.y);
-    }
-
-
-
-    /* --- do menu processing --- */
-
-
-    if (menu_opt == QUIT_GAME)
-      done = 1;
-
-
-    if (menu_opt == LASER)
-    {
-      menu_depth = LASER_SUBMENU;
-      sub_menu = LASER;
-      update_locs = 1;
-      redraw = 1;
-    }
-
-
-    if (menu_opt == CASCADE)
-    {
-      menu_depth = CASCADE_SUBMENU;
-      sub_menu = CASCADE;
-      update_locs = 1;
-      redraw=1;
-    }
-
-
-    if (menu_opt == OPTIONS)
-    {
-      menu_depth = OPTIONS_SUBMENU;
-      sub_menu = OPTIONS;
-      update_locs = 1;
-      redraw = 1;
-    }
-
-
-    if (menu_opt == MAIN)
-    {
-      menu_depth = ROOTMENU;
-      update_locs = 1;
-      redraw = 1;
-    }
-
-
-    if (menu_opt == NOT_CODED)
-    {
-      not_implemented();
-      redraw = 1;
-    }
-
-
-    if (menu_opt == PROJECT_INFO)
-    {
-      ProjectInfo();
-      redraw = 1;
-    }
-
-
-    if (menu_opt == LESSONS)
-    {
-      SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
-      SDL_Flip( screen );
-      unload_media();
-
-      if (settings.menu_music)
-        MusicUnload( );
-
-      TestLesson();
-
-      load_media();
-      redraw = 1;
-
-      if (settings.menu_music)
-        MusicLoad( "tuxi.ogg", -1 );
-    }
-
-
-    if (menu_opt == SET_LANGUAGE)
-    {
-      unload_media();
-      ChooseTheme();
-      LoadLang();
-      LoadKeyboard();
-      load_media();
-      redraw = 1;
-
-      if (settings.menu_music)
-        MusicLoad( "tuxi.ogg", -1 );
-    }
-
-
-    if (menu_opt == LEVEL1)
-    {  
-      if (chooseWordlist()) 
-      {
-        unload_media();
-
-        switch (sub_menu)
-        {
-          case CASCADE: PlayCascade( EASY ); break;
-          case LASER:   PlayLaserGame(  EASY ); break;
-        }
-      }
-
-      load_media();
-
-      if (settings.menu_music)
-        MusicLoad("tuxi.ogg", -1);
-
-      redraw = 1;
-    }
-
-
-    if (menu_opt == LEVEL2)
-    {
-      if (chooseWordlist())
-      {
-        unload_media();
-
-        switch (sub_menu)
-        {
-          case CASCADE: PlayCascade( MEDIUM ); break;
-          case LASER:   PlayLaserGame(  MEDIUM ); break;
-        }
-
-
-        if (settings.menu_music)
-          MusicLoad( "tuxi.ogg", -1 );
-      }
-
-      load_media();
-      redraw = 1;
-    }
-
-
-
-    if (menu_opt == LEVEL3)
-    {
-      if (chooseWordlist())
-      {
-        unload_media();
-
-        switch (sub_menu)
-        {
-          case CASCADE: PlayCascade( HARD ); break;
-          case LASER:   PlayLaserGame(  HARD ); break;
-        }
-
-
-        if (settings.menu_music)
-          MusicLoad( "tuxi.ogg", -1 );
-      }
-
-      load_media();
-      redraw = 1;
-    }
-
-
-
-    if (menu_opt == LEVEL4)
-    {
-      if (chooseWordlist())
-      {
-        unload_media();
-
-        switch (sub_menu)
-        {
-          case CASCADE: PlayCascade( INSANE ); break;
-          case LASER:   PlayLaserGame(  INSANE ); break;
-        }
-
-        if (settings.menu_music)
-          MusicLoad( "tuxi.ogg", -1 );
-      }
-
-      load_media();
-      redraw = 1;
-    }
-
-
-
-    if (menu_opt == INSTRUCT)
-    {
-      unload_media();
-
-      switch (sub_menu)
-      {
-        case CASCADE: InstructCascade(); break;
-        case LASER:   InstructLaser();   break;
-      }
-
-      load_media();
-
-      if (settings.menu_music)
-        MusicLoad( "tuxi.ogg", -1 );
-
-      redraw = 1;
-    }
-
-
-
-    if (menu_opt == FREETYPE)
-    {
-      unload_media();
-      found = 0;
-
-      if (!settings.use_english)
-      {
-        sprintf(fn , "%s/phrases.txt", settings.theme_data_path);
-        if (CheckFile(fn))
-          found = 1;
-
-        /* Now look in default path if desired or needed: */
-        if (!found)
-        {
-          sprintf(fn , "%s/words/words3.txt", settings.theme_data_path);
-          if (CheckFile(fn))
-            found = 1;
-        }
-
-        if (!found)
-        {
-          sprintf(fn , "%s/words/words2.txt", settings.theme_data_path);
-          if (CheckFile(fn))
-            found = 1;
-        }
-
-        if (!found)
-        {
-          sprintf(fn , "%s/words/words1.txt", settings.theme_data_path);
-          if (CheckFile(fn))
-            found = 1;
-        }
-      }
-
-      /* Now checking English: */
-      if (!found)
-      {
-        sprintf(fn , "%s/phrases.txt", settings.default_data_path);
-        if (CheckFile(fn))
-          found = 1;
-      }
-
-      /* Now do Phrases activity if phrase loaded successfully: */
-      if (found)
-      {
-        fp=fopen(fn,"r");
-        fscanf( fp, "%[^\n]\n", str);
-        ConvertFromUTF8(phrase, str);
-        Phrases( phrase );
-        //Practice();
-        load_media();
-        redraw = 1;
-        fclose(fp);
-      }
-      else
-      {
-        fprintf(stderr, "LoadKeyboard(): Error finding file for keyboard setup!\n");
-      }
-    }
-    
-    if(menu_opt == WPM)
-    {
-    	
-    }
-    
-    if(menu_opt == HIGH_SCORES)
-
-    /* ------ End menu_opt processing ----------- */
-
-
-
-    if (redraw)
-    {
-      LOG("TitleScreen() - redraw requested\n");
-      recalc_rects();
-
-      SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL); 
-      SDL_BlitSurface(title, NULL, screen, &Titledest);
-
-      if ( settings.menu_music )
-        SDL_BlitSurface(speaker, NULL, screen, &spkrdest);
-      else
-        SDL_BlitSurface(speakeroff, NULL, screen, &spkrdest);
-
-      /* Screen will be updated due to update_locs - see ~30 lines down: */
-//      SDL_UpdateRect(screen, 0, 0, 0, 0);
-      frame = redraw = 0;   // so we redraw tux
-      update_locs = 1;      // so we redraw menu
-      firstloop = 1;
-    }
-
-
-
-    /* --- create new menu screen when needed --- */
-
-    if (update_locs)
-    {
-      LOG("TitleScreen() - update_locs requested\n");
-
-      /* --- erase the last menu --- */
-      for (i = 1; i <= TITLE_MENU_ITEMS; i++)
-      {
-        text_dst[i].x = screen->w/2 - 70;//290;
-        text_dst[i].w = reg_text[i][menu_depth]->w;
-        text_dst[i].h = reg_text[i][menu_depth]->h;
-        SDL_BlitSurface(CurrentBkgd(), &menu_button[i], screen, &menu_button[i]);
-        menu_button[i].w = menu_width[menu_depth] + 20;
-      }
-
-
-      update_locs = 0;
-
-      /* --- draw the full menu --- */
-
-      for (j = 1; j <= TITLE_MENU_ITEMS; j++)
-      {
-        DOUT(j);
-        DrawButton(&menu_button[j], 10, REG_RGBA);
-        if (reg_text[j][menu_depth] != NULL)
-          SDL_BlitSurface(reg_text[j][menu_depth], NULL, screen, &text_dst[j]);
-        if (menu_gfx[j][menu_depth] != NULL)
-          SDL_BlitSurface(menu_gfx[j][menu_depth]->default_img, NULL, screen, &menu_gfxdest[j]);
-      }
-
-      SDL_UpdateRect(screen, 0, 0, 0, 0);
-
-      LOG("TitleScreen() - update_locs completed\n");
-    }
-
-
-
-    /* --- make tux blink --- */
-
-    switch (frame % TUX6)
-    {
-      case 0:    tux_frame = 1; break;
-      case TUX1: tux_frame = 2; break;
-      case TUX2: tux_frame = 3; break;
-      case TUX3: tux_frame = 4; break;			
-      case TUX4: tux_frame = 3; break;
-      case TUX5: tux_frame = 2; break;
-      default: tux_frame = 0;
-    }
-
-    if (tux_frame)
-    {
-      SDL_Rect blink_src, blink_dest;
-      blink_src.x = 0;
-      blink_src.y = 0;
-      blink_src.w = Tuxdest.w;
-      blink_src.h = Tuxdest.h;
-      blink_dest.x = Tuxdest.x + blink_src.x;
-      blink_dest.y = Tuxdest.y + blink_src.y;
-      blink_dest.w = blink_src.w;
-      blink_dest.h = blink_src.h;
-//      SDL_BlitSurface(CurrentBkgd(), , screen, &Tuxdest);
-      SDL_BlitSurface(Tux->frame[tux_frame - 1], &blink_src, screen, &blink_dest);
-    }
-
-
-    /* --- check if mouse is in a menu option --- */
-
-    key_menu = 0;
-
-    for (j = 1; j <= TITLE_MENU_ITEMS; j++)
-    {
-      if ((cursor.x >= menu_button[j].x && cursor.x <= (menu_button[j].x + menu_button[j].w)) &&
-          (cursor.y >= menu_button[j].y && cursor.y <= (menu_button[j].y + menu_button[j].h)))
-      {
-        key_menu = j; // update menu to point
-        break;        // Don't need to check rest of menu
-      }
-    }
-
-
-    /* --- return old selection to unselected state --- */
-
-    if (old_key_menu && (key_menu != old_key_menu))
-    {
-      SDL_BlitSurface(CurrentBkgd(), &menu_button[old_key_menu], screen, &menu_button[old_key_menu]);
-      DrawButton(&menu_button[old_key_menu], 10, REG_RGBA);
-      SDL_BlitSurface(reg_text[old_key_menu][menu_depth], NULL, screen, &text_dst[old_key_menu]);
-      SDL_BlitSurface(menu_gfx[old_key_menu][menu_depth]->default_img, NULL, screen, &menu_gfxdest[old_key_menu]);
-    }
-
-
-    /* --- draw current selection --- */
-
-    if ((key_menu != 0) &&
-       ((old_key_menu != key_menu) || (frame % 5 == 0))) // Redraw every fifth frame?
-    {
-      if (key_menu != old_key_menu)
-      {
-        REWIND(menu_gfx[key_menu][menu_depth]);
-        PlaySound(snd_move);
-      }
-
-      SDL_BlitSurface(CurrentBkgd(), &menu_button[key_menu], screen, &menu_button[key_menu]);
-      DrawButton(&menu_button[key_menu], 10, SEL_RGBA);
-      SDL_BlitSurface(sel_text[key_menu][menu_depth], NULL, screen, &text_dst[key_menu]);
-      SDL_BlitSurface(menu_gfx[key_menu][menu_depth]->frame[menu_gfx[key_menu][menu_depth]->cur], NULL, screen, &menu_gfxdest[key_menu]);
-
-      NEXT_FRAME(menu_gfx[key_menu][menu_depth]);
-    }
-
-
-    // HACK This is still more than we need to update every frame but
-    // it cuts cpu on my machine %60 so it seems better...
-    if ( settings.menu_music )
-      SDL_BlitSurface(speaker, NULL, screen, &spkrdest);
-    else
-      SDL_BlitSurface(speakeroff, NULL, screen, &spkrdest);
-
-    SDL_UpdateRect(screen, spkrdest.x, spkrdest.y, spkrdest.w, spkrdest.h);
-
-    for (i = 1; i < 6; i++)
-    {
-      SDL_UpdateRect(screen, menu_button[i].x, menu_button[i].y, menu_button[i].w, menu_button[i].h);
-    }
-
-    if (tux_frame)
-      SDL_UpdateRect(screen, Tuxdest.x, Tuxdest.y, Tuxdest.w, Tuxdest.h);
-
-    if (firstloop)
-      SDL_UpdateRect(screen, Tuxdest.x, Tuxdest.y, Tuxdest.w, Tuxdest.h);
-
-    firstloop = 0;
-
-    /* Wait so we keep frame rate constant: */
-    while ((SDL_GetTicks() - start) < 33)
-    {
-      SDL_Delay(20);
-    }
-
-    frame++;
-  } /* ----------- End of 'while(!done)' loop ------------  */
-
-
-
-  LOG( "->>Freeing title screen images\n" );
-
-  unload_media();
-
-  LOG( "->TitleScreen():END \n" );
-}
-
-
-
-/************************************************************************/
-/*                                                                      */ 
-/*       "Private" functions (local to titlescreen.c)                   */
-/*                                                                      */
-/************************************************************************/
-
-static void show_logo(void)
-{
-  if (settings.show_tux4kids)
-  {
-    SDL_Rect logo_rect;
-    SDL_Surface* t4k_logo = LoadImage("standby.png", IMG_REGULAR|IMG_NO_THEME);
-    
-    if (t4k_logo) /* Avoid segfault */
-    { 
-      logo_rect.x = screen->w/2 - t4k_logo->w/2;  // Center horizontally
-      logo_rect.y = screen->h/2 - t4k_logo->h/2;  // Center vertically
-      logo_rect.w = t4k_logo->w;
-      logo_rect.h = t4k_logo->h;
-
-      /* Black out screen: */
-      SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
-      SDL_BlitSurface(t4k_logo, NULL, screen, &logo_rect);
-      SDL_UpdateRect(screen, 0, 0, 0, 0);
-      SDL_FreeSurface(t4k_logo);  // Unload image
-    }
-    else
-      fprintf(stderr, "Couldn't load 'standby.png'\n");
-  }
-}
-
-
-/* Renders the menu text for all items and loads the associated */
-/* animated sprites, if any.                                    */
-static void load_menu(void)
-{
-  unsigned char fn[FNLEN];
-  int max, i, j;
-
-  SDL_ShowCursor(1);
-
-  LOG("loading & parsing menu\n");
-
-  for (j = 1; j <= TITLE_MENU_DEPTH; j++)  /* Each 'depth' is a different menu */
-  {
-    max = 0;
-    for (i = 1; i <= TITLE_MENU_ITEMS; i++)
-    {
-      DEBUGCODE
-      {
-        fprintf(stderr, "i = '%d'\tj = '%d'\ttext = '%s'\n",
-                i, j,  gettext((unsigned char*)menu_text[j+5*i]));
-      }
-
-      /* --- create text surfaces --- */
-      reg_text[i][j] = BlackOutline( gettext((unsigned char*)menu_text[j+5*i]), font, &white);
-      sel_text[i][j] = BlackOutline( gettext((unsigned char*)menu_text[j+5*i]), font, &yellow);
-
-      /* (first make sure ptr valid to avoid segfault) */
-      if (sel_text[i][j] && sel_text[i][j]->w > max)
-        max = sel_text[i][j]->w;
-
-      /* --- load animated icon for menu item --- */
-      sprintf(fn, "menu/%s", menu_icon[i][j]);
-      menu_gfx[i][j] = LoadSprite(fn, IMG_ALPHA);
-    }
-    menu_width[j] = max + 20 + 40; // Not clear where '20' and '40' are coming from
-  }
-
-  recalc_rects();
-}
-
-
-
-static void recalc_rects(void)
-{
-  int i = 0;
-
-  Tuxdest.x = 0;
-  Tuxdest.y = screen->h - Tux->frame[0]->h;
-  Tuxdest.w = Tux->frame[0]->w;
-  Tuxdest.h = Tux->frame[0]->h;
-
-  Titledest.x = 0;
-  Titledest.y = 10;
-  Titledest.w = title->w;
-  Titledest.h = title->h;
-
-  spkrdest.x = screen->w - speaker->w - profiles->w - 10;
-  spkrdest.y = screen->h - speaker->h - 10;
-  spkrdest.w = speaker->w;
-  spkrdest.h = speaker->h;
-  
-  profilesdest.x = screen->w - speaker->w - 10;
-  profilesdest.y = screen->h - profiles->h - 10;
-  profilesdest.w = profiles->w; 
-  profilesdest.h = profiles->h;
-  /* --- setup menu item destinations --- */
-  menu_button[1].x = screen->w/2 - 120; //240;
-  menu_button[1].y = 100;
-  menu_button[1].w = menu_width[1];  //calc from width of widest menu item
-  menu_button[1].h = 50;
-
-  menu_gfxdest[1].x = menu_button[1].x + 6; // inset graphic by (6, 4) */
-  menu_gfxdest[1].y = menu_button[1].y + 4;
-  menu_gfxdest[1].w = 40;
-  menu_gfxdest[1].h = 50;
-
-  text_dst[1].x = screen->w/2 - 70;//290;
-  text_dst[1].y = menu_button[1].y + 15;
-
-  /* FIXME each menu item drawn hardcoded 60 pixels below last - */
-  /* perhaps increment should be "menu_button[j-1].h + MENU_ITEM_GAP" */
-  for (i = 2; i < 6; i++) 
-  {
-    /* --- setup location of button text --- */
-    text_dst[i].x = screen->w/2 - 70;
-    text_dst[i].y = text_dst[i - 1].y + 60;
-
-    /* --- setup location of button background --- */
-    menu_button[i].x = menu_button[i - 1].x;
-    menu_button[i].y = menu_button[i - 1].y + 60;
-    menu_button[i].w = menu_button[i - 1].w;
-    menu_button[i].h = menu_button[i - 1].h;
-
-    /* --- setup location of animated icon --- */
-    menu_gfxdest[i].x = menu_gfxdest[i - 1].x;
-    menu_gfxdest[i].y = menu_gfxdest[i - 1].y + 60;
-    menu_gfxdest[i].w = menu_gfxdest[i - 1].w;
-    menu_gfxdest[i].h = menu_gfxdest[i - 1].h;
-  }
-}
-
-
-
-static void unload_menu(void)
-{
-  int i,j;
-  printf("enter unload_menu()\n");
-
-  for (i = 1; i <= TITLE_MENU_ITEMS; i++)
-  {
-    for (j = 1; j <= TITLE_MENU_DEPTH; j++)
-    {
-      if (reg_text[i][j])
-        SDL_FreeSurface(reg_text[i][j]);
-      if (sel_text[i][j])
-        SDL_FreeSurface(sel_text[i][j]);
-      if (menu_gfx[i][j])
-        FreeSprite(menu_gfx[i][j]);
-      reg_text[i][j] = sel_text[i][j] = NULL;
-      menu_gfx[i][j] = NULL;
-    }
-  }
-}
-
-
-static int load_media(void)
-{
-  DEBUGCODE
-  {
-    fprintf(stderr, "Entering load_media():\n");
-    fprintf(stderr, "default_data_path = %s\n", settings.default_data_path);
-    fprintf(stderr, "theme_data_path = %s\n", settings.theme_data_path);
-  }
-
-  /* Make sure everything is unloaded before we start: */
-  /* FIXME have not been to do this to run without crashing: */
-  //unload_media();
-
-  /* --- load sounds --- */
-  if (settings.menu_sound)
-  {
-    snd_move = LoadSound("tock.wav");
-    snd_select = LoadSound("pop.wav");
-    if (!snd_move || !snd_select)
-    {
-      fprintf(stderr, "Could not load menu sounds - turning menu_sound off\n");
-      settings.menu_sound = 0;
-    }
-  }
- 
-  /* --- load graphics --- */
-  LoadBothBkgds("main_bkg.png");
-  title = LoadImage( "title1.png", IMG_ALPHA );
-  speaker = LoadImage( "sound.png", IMG_ALPHA );
-  speakeroff = LoadImage( "nosound.png", IMG_ALPHA );
-  profiles = LoadImage("profiles.png", IMG_ALPHA)
-//  sel = LoadSprite("menu/sel", IMG_ALPHA);
-//  reg = LoadSprite("menu/reg", IMG_ALPHA);
-  Tux = LoadSprite("tux", IMG_ALPHA);
-
-  DEBUGCODE
-  {
-    fprintf(stderr, "titlescreen.c load_media(): settings.theme_font_name is %s\n",
-            settings.theme_font_name);
-  }
-  font = LoadFont(settings.theme_font_name, MENU_FONT_SIZE);
-
-  /* Make sure we were successful: */
-  if (!CurrentBkgd()
-   || !title
-   || !speaker
-   || !speakeroff
-   || !profiles
-   || !Tux
-   || !font)
-  {
-    fprintf(stderr, "load_media() - could not load all needed files\n");
-    unload_media();
-    return 0;
-  }
-
-  /* Should probably call this directly from TitleScreen() */
-  load_menu();
-  return 1;
-}
-
-
-
-static void unload_media(void)
-{
-  LOG("Entering unload_media():\n");
-
-  /* --- unload sounds --- */
-  if (settings.menu_sound){
- 
-    if (snd_move)
-    { 
-      Mix_FreeChunk(snd_move);
-      snd_move = NULL;
-    }
-    if (snd_select)
-    { 
-      Mix_FreeChunk(snd_select);
-      snd_select = NULL;
-    }
-  }
-
-  /* --- unload graphics --- */
-  if (title)
-  {
-    SDL_FreeSurface(title);
-    title = NULL;
-  }
-  if (speaker)
-  {
-    SDL_FreeSurface(speaker);
-    speaker = NULL;
-  }
-  if (speakeroff)
-  {
-    SDL_FreeSurface(speakeroff);
-    speakeroff = NULL;
-  }
-  if(profiles)
-  {
-	  SDL_FreeSurface(profiles);
-	  profiles = NULL;
-  }
-
-  FreeBothBkgds();
-
-  if (Tux)
-  {
-    FreeSprite(Tux);
-    Tux = NULL;
-  }
-
-  if (font)
-  {
-    TTF_CloseFont(font);
-    font = NULL;
-  }
-
-  LOG("Leaving load_media():\n");
-
-  unload_menu();
-}
-
-
-static void not_implemented(void)
-{
-  SDL_Surface *s1 = NULL, *s2 = NULL, *s3 = NULL, *s4 = NULL;
-  sprite* tux = NULL;
-  SDL_Rect loc;
-  int finished = 0, i;
-
-  LOG( "NotImplemented() - creating text\n" );
-
-  s1 = BlackOutline( gettext_noop("Work In Progress!"), font, &white);
-  s2 = BlackOutline( gettext_noop("This feature is not ready yet"), font, &white);
-  s3 = BlackOutline( gettext_noop("Discuss the future of TuxTyping at"), font, &white);
-
-  /* we always want the URL in english */
-  /* NOTE: all fonts are almost certain to include glyphs for ASCII, */
-  /* so the following "english_font" hackery is probably unnecessary: */
-  if (!settings.use_english)
-  {
-    TTF_Font *english_font;
-    settings.use_english = 1;
-    english_font = LoadFont(DEFAULT_MENU_FONT, MENU_FONT_SIZE);
-    s4 = BlackOutline( "http://tuxtype.sf.net/forums", english_font, &white);
-    TTF_CloseFont(english_font);
-    settings.use_english = 0;
-  }
-  else 
-    s4 = BlackOutline( "http://tuxtype.sf.net/forums", font, &white);
-
-  tux = LoadSprite("tux/tux-egypt", IMG_ALPHA);
-
-  if (s1 && s2 && s3 && s4 && tux)
-  {
-    LOG( "NotImplemented() - drawing screen\n" );
-
-    SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL);
-    loc.x = screen->w/2 - (s1->w/2); loc.y = 10;
-    SDL_BlitSurface( s1, NULL, screen, &loc);
-    loc.x = screen->w/2 - (s2->w/2); loc.y = 60;
-    SDL_BlitSurface( s2, NULL, screen, &loc);
-    loc.x = screen->w/2 - (s3->w/2); loc.y = screen->h/2 + 160;
-    SDL_BlitSurface(s3, NULL, screen, &loc);
-    loc.x = screen->w/2 - (s4->w/2); loc.y = screen->h/2 + 200;
-    SDL_BlitSurface( s4, NULL, screen, &loc);
-
-    loc.x = screen->w/2 - (tux->frame[0]->w/2);
-    loc.y = screen->h - 280;
-    loc.w = tux->frame[0]->w;
-    loc.h = tux->frame[0]->h;
-    SDL_BlitSurface( tux->frame[tux->cur], NULL, screen, &loc);
-
-    SDL_UpdateRect(screen, 0, 0, 0, 0);
-
-    i = 0;
-
-    while (!finished)
-    {
-      while (SDL_PollEvent(&event)) 
-      {
-        switch (event.type)
-        {
-          case SDL_QUIT:
-            exit(0);
-          case SDL_MOUSEBUTTONDOWN:
-          case SDL_KEYDOWN:
-            finished = 1;
-        }
-      }
-
-      i++;
-
-      if (i %5 == 0)
-      {
-        NEXT_FRAME(tux);
-        SDL_BlitSurface(CurrentBkgd(), &loc, screen, &loc);
-        SDL_BlitSurface(tux->frame[tux->cur], NULL, screen, &loc);
-        SDL_UpdateRect(screen, loc.x, loc.y, loc.w, loc.h);
-      }
-
-      SDL_Delay(40);
-    }
-  }
-  else
-    fprintf(stderr, "NotImplemented() - could not load needed graphic\n");
-
-  SDL_FreeSurface(s1);
-  SDL_FreeSurface(s2);
-  SDL_FreeSurface(s3);
-  SDL_FreeSurface(s4);
-  s1 = s2 = s3 = s4 = NULL;
-  FreeSprite(tux);
-  tux = NULL;
-}
-
-
-
-
-#define MAX_WORD_LISTS 100
-
-/* returns 0 if user pressed escape ...
- *         1 if word list was set correctly
- */
-static int chooseWordlist(void)
-{
-  SDL_Surface* titles[MAX_WORD_LISTS] = {NULL};
-  SDL_Surface* select[MAX_WORD_LISTS] = {NULL};
-  SDL_Surface* left = NULL, *right = NULL;
-  SDL_Rect leftRect, rightRect;
-  SDL_Rect titleRects[8];
-  int stop = 0;
-  int loc = 0;
-  int old_loc = 1;
-  int lists = 0;
-  int i;
-  unsigned char wordPath[FNLEN];
-  unsigned char wordlistFile[MAX_WORD_LISTS][200];
-  unsigned char wordlistName[MAX_WORD_LISTS][200];
-
-  DIR* wordsDir = NULL;
-  struct dirent* wordsFile = NULL;
-  FILE* tempFile = NULL;
-
-  LOG("Entering chooseWordlist():\n");
-
-  /* find the directory to load wordlists from */
-
-  /* Check under theme directory first, if theme selected: */
-  if (!settings.use_english)  /* Using theme: */
-  {
-    sprintf(wordPath,"%s/words", settings.theme_data_path);
-    if (!CheckFile(wordPath))
-    {
-      fprintf(stderr, "chooseWordList() - theme contains no wordlist dir \n");
-      return 0;
-    }
-  }
-  else  /* No theme selected - using English: */
-  {
-    sprintf(wordPath,"%s/words", settings.default_data_path);
-    if (!CheckFile(wordPath))
-    {
-      fprintf(stderr, "chooseWordList() - data path contains no wordlist dir \n");
-      return 0;
-    }
-  }
-
-  /* If we get to here, we know there is at least a wordlist directory */
-  /* but not necessarily any valid files.                              */
-
-  DEBUGCODE { fprintf(stderr, "wordPath is: %s\n", wordPath); }
-
-
-  /* FIXME looks like a place for scandir() - or our own w32_scandir() */
-  /* create a list of all the .txt files */
-
-  wordsDir = opendir( wordPath );	
-
-  do
-  {
-    wordsFile = readdir(wordsDir);
-    if (!wordsFile)
-      break; /* Loop continues until break occurs */
-
-    /* must have at least .txt at the end */
-    if (strlen(wordsFile->d_name) < 5)
-      continue;
-
-    if (strcmp(&wordsFile->d_name[strlen(wordsFile->d_name)-4],".txt"))
-      continue;
-
-    sprintf(wordlistFile[lists], "%s/%s", wordPath, wordsFile->d_name);
-
-    /* load the name for the wordlist from the file ... (1st line) */
-    tempFile = fopen( wordlistFile[lists], "r" );
-    if (!tempFile)
-      continue;
-
-    fscanf(tempFile, "%[^\n]\n", wordlistName[lists]);
-
-    /* check to see if it has a \r at the end of it (dos format!) */
-    if (wordlistName[lists][strlen(wordlistName[lists]) - 1] == '\r')
-      wordlistName[lists][strlen(wordlistName[lists]) - 1] = '\0';
-
-    lists++;
-
-    fclose(tempFile);
-  } while (1); /* Loop continues until break occurs */
-
-  closedir(wordsDir);	
- 
- DEBUGCODE { fprintf(stderr, "Found %d .txt file(s) in words dir\n", lists); }
-
-
-
-  /* let the user pick the list */
-
-  /* Render SDL_Surfaces for list entries: */
-//  titles[0] = BlackOutline( _("Alphabet"), font, &white );
-//  select[0] = BlackOutline( _("Alphabet"), font, &yellow);
-
-  /* NOTE - no longer hard-coding titles[0] to be alphabet - themes  */
-  /* should include a regular word list file called "alphabet.txt"   */
-  /* Should sort the list and always put the alphabet file first, if */
-  /* present.                                                        */
-  for (i = 0; i < lists; i++)
-  {
-    titles[i] = BlackOutline( wordlistName[i], font, &white );
-    select[i] = BlackOutline( wordlistName[i], font, &yellow);
-  }
-
-  left = LoadImage("left.png", IMG_ALPHA);
-  right = LoadImage("right.png", IMG_ALPHA);
-
-  /* Get out if needed surface not loaded successfully: */
-  if (!CurrentBkgd() || !left || !right)
-  {
-    fprintf(stderr, "chooseWordList(): needed image not available\n");
-  
-    for (i = 0; i < lists; i++)
-    {
-      SDL_FreeSurface(titles[i]);
-      SDL_FreeSurface(select[i]);
-      titles[i] = select[i] = NULL;
-    }
-
-    SDL_FreeSurface(left);
-    SDL_FreeSurface(right);
-    left = right = NULL;
-
-    return 0;
-  }
-  
-
-
-  leftRect.w = left->w;
-  leftRect.h = left->h;
-  leftRect.x = screen->w/2 - 80 - (leftRect.w/2);
-  leftRect.y = screen->h/2 - 50;
-
-  rightRect.w = right->w; rightRect.h = right->h;
-  rightRect.x = screen->w/2 + 80 - (rightRect.w/2); rightRect.y = screen->h/2 - 50;
-
-  /* set initial rect sizes */
-  titleRects[0].y = 30;
-  titleRects[0].w = titleRects[0].h = titleRects[0].x = 0;
-
-  for (i = 1; i < 8; i++)
-  { 
-    titleRects[i].y = titleRects[i - 1].y + 50;
-    titleRects[i].w = titleRects[i].h = titleRects[i].x = 0;
-  }
-
-  /* Main event loop for this screen: */
-  while (!stop)
-  {
-    while (SDL_PollEvent(&event))
-    {
-      switch (event.type)
-      {
-        case SDL_QUIT:
-          exit(0); /* FIXME may need to cleanup memory and exit more cleanly */
-          break;
-
-        case SDL_MOUSEMOTION:
-          for (i=0; (i<8) && (loc-(loc%8)+i<lists); i++)
-            if (inRect( titleRects[i], event.motion.x, event.motion.y ))
-            {
-              loc = loc-(loc%8)+i;
-              break;
-            }
-          break;
-
-        case SDL_MOUSEBUTTONDOWN:
-                                        if (inRect( leftRect, event.button.x, event.button.y ))
-                                                if (loc-(loc%8)-8 >= 0) {
-                                                        loc=loc-(loc%8)-8;
-                                                        break;
-                                                }
-                                        if (inRect( rightRect, event.button.x, event.button.y ))
-                                                if (loc-(loc%8)+8 < lists) {
-                                                        loc=loc-(loc%8)+8;
-                                                        break;
-                                                }
-                                        for (i=0; (i<8) && (loc-(loc%8)+i<lists); i++)
-                                                if (inRect(titleRects[i], event.button.x, event.button.y)) {
-                                                        loc = loc-(loc%8)+i;
-							ClearWordList(); /* clear old selection */
-							//if (loc==0)
-							//  UseAlphabet(); 
-							//else
-							GenerateWordList(wordlistFile[loc]); 
-                                                        stop = 1;
-                                                        break;
-                                                }
-                                        break;
-                                case SDL_KEYDOWN:
-                                        if (event.key.keysym.sym == SDLK_ESCAPE) { stop = 2; break; }
-                                        if (event.key.keysym.sym == SDLK_RETURN) {
-						ClearWordList(); /* clear old selection */
-						//if (loc==0)
-						//  UseAlphabet(); 
-						//else
-						GenerateWordList(wordlistFile[loc]); 
-                                                stop = 1;
-                                                break;
-                                        }
-
-                                        if ((event.key.keysym.sym == SDLK_LEFT) || (event.key.keysym.sym == SDLK_PAGEUP)) {
-                                                if (loc-(loc%8)-8 >= 0)
-                                                        loc=loc-(loc%8)-8;
-                                        }
-
-                                        if ((event.key.keysym.sym == SDLK_RIGHT) || (event.key.keysym.sym == SDLK_PAGEDOWN)) {
-                                                if (loc-(loc%8)+8 < lists)
-                                                        loc=(loc-(loc%8)+8);
-                                        }
-
-                                        if (event.key.keysym.sym == SDLK_UP) {
-                                                if (loc > 0)
-                                                        loc--;
-                                        }
-
-                                        if (event.key.keysym.sym == SDLK_DOWN) {
-                                                if (loc+1<lists)
-                                                        loc++;
-                                        }
-      }
-    }
-
-    if (old_loc != loc) {
-                        int start;
-
-                        SDL_BlitSurface(CurrentBkgd(), NULL, screen, NULL );
-
-                        start = loc - (loc % 8);
-                        for (i = start; i<MIN(start+8,lists); i++) {
-                                titleRects[i%8].x = screen->w/2 - (titles[i]->w/2);
-                                if (i == loc)
-                                        SDL_BlitSurface(select[loc], NULL, screen, &titleRects[i%8]);
-                                else
-                                        SDL_BlitSurface(titles[i], NULL, screen, &titleRects[i%8]);
-                        }
-
-                        /* --- draw buttons --- */
-
-                        if (start>0)
-                                SDL_BlitSurface( left, NULL, screen, &leftRect );
-
-                        if (start+8<lists)
-                                SDL_BlitSurface( right, NULL, screen, &rightRect );
-
-                        SDL_UpdateRect(screen, 0, 0, 0 ,0);
-                }
-                SDL_Delay(40);
-                old_loc = loc;
-  }
-
-  /* --- clear graphics before leaving function --- */ 
-  for (i = 0; i<lists; i++)
-  {
-    SDL_FreeSurface(titles[i]);
-    SDL_FreeSurface(select[i]);
-    titles[i] = select[i] = NULL;
-  }
-
-  SDL_FreeSurface(left);
-  SDL_FreeSurface(right);
-  left = right = NULL; /* Maybe overkill - about to be destroyed anyway */
-
-  DEBUGCODE { fprintf( stderr, "Leaving chooseWordlist();\n" ); }
-
-  if (stop == 2)
-    return 0;
-
-  return 1;
-}
-
-

Deleted: tuxtype/branches/tuxtype-soc-mh/titlescreen.h
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/titlescreen.h	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/titlescreen.h	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,19 +0,0 @@
-
-/* --- SETUP MENU OPTIONS --- */
-
-#define TITLE_MENU_ITEMS                6 //originally 5
-#define TITLE_MENU_DEPTH                4
-
-#define OPTIONS_SUBMENU                 5 //originally
-#define LASER_SUBMENU	        	3
-#define CASCADE_SUBMENU	        	2
-#define ROOTMENU		        1
-
-
-/* --- timings for tux blinking --- */
-#define TUX1                            115
-#define TUX2                            118
-#define TUX3                            121
-#define TUX4                            124
-#define TUX5                            127
-#define TUX6                            130

Deleted: tuxtype/branches/tuxtype-soc-mh/wordsperminute.c
===================================================================
--- tuxtype/branches/tuxtype-soc-mh/wordsperminute.c	2008-08-26 07:22:40 UTC (rev 672)
+++ tuxtype/branches/tuxtype-soc-mh/wordsperminute.c	2008-08-26 07:28:53 UTC (rev 673)
@@ -1,361 +0,0 @@
-//Words per minute mode
-
-//currently only has an english file..
-//only calculates wpm if they finish the set, otherwise ignore
-#include "globals.h"
-#include "funcs.h"
-
-typedef struct lines{
-	wchar_t words[][]; 
-	int wcount; /* number of words in line */
-	int finished; /* chars that have to be typed to finish line */
-}lines;
-
-	lines typeline;
-	lines previewline;
-	lines templine;
- 
-static SDL_Surface* bg = NULL;
-static letter_loc;
-static TTF_Font* font = NULL;
-int charsfinished;
-static Mix_Chunk* wrong = NULL;
-
-lines getTypeLine(void);
-lines getPreviewLine(void);
-void copyToTempLine(lines);
-static int wpm_load_media(void);
-static void wpm_unload_media(void);
-static void print_at(const wchar_t* pphrase, int wrap, int x, int y);
-void displayTypeLine(lines, int);
-void displayPreviewLine(lines, int);
-
-int wpm()
-{
-	Uint32 time = 30000, elapsed; /* 30 seconds */
-  	int quit = 0,
-  	i = 0,
-  	count = 0,
-  	wp = 0,
-  	z = 0;
-  	SDL_Rect dst;
-  	SDL_Surface* srfc = NULL;
-
-  	if (!wpm_load_media())
-  	{
-  		fprintf(stderr, "wpm() - wpm_load_media() failed, returning.\n");
-  		return 0;
-  	}
-
-  	SDL_BlitSurface(bg, NULL, screen, NULL);
-  	SDL_Flip(screen);
-
-  	srfc = GetWhiteGlyph(65);
-
-  	if (!srfc)
-  	{
-  		fprintf(stderr, "wpm() - GetWhiteGlyph(65) not defined - bailing out.\n");
-  		return 0;
-  	}
-  	
-  	dst.x = 40;
-  	dst.y = 10;
-  	dst.w = srfc->w;
-  	dst.h = srfc->h;
-  	
-  	getTypeLine();
-  	getPreviewLine();
-  	displayTypeLine(typeline, 1);
-  	displayPreviewLine(previewline, 1);
-
-  	copyToTempLine(typeline); //copy active to temp
-  	do
-  	{
-  		while  (SDL_PollEvent(&event))
-  		{
-  			if (event.type == SDL_KEYDOWN)
-  			{
-  				if (event.key.keysym.sym == SDLK_ESCAPE)
-  				{
-  					quit = 1;
-  				}
-  				else
-  				{
-  					if (templine.words[c]==(wchar_t)event.key.keysym.unicode)
-  					{
-  						srfc = GetRedGlyph(event.key.keysym.unicode);
-  						if (srfc)
-  						{
-  							SDL_BlitSurface(srfc, NULL, screen, &dst);
-  							dst.x = (dst.x + srfc->w) - 5;
-  						}
-  						charsfinished++;
-  						c++;
-  						templine.finished--;
-  					}
-  					else
-  					{
-  						if (event.key.keysym.sym != SDLK_RSHIFT
-  								&& event.key.keysym.sym != SDLK_LSHIFT)
-  						{
-  							PlaySound(wrong);
-  						}
-  					}
-  				}
-  			}
-  		}
-  		if(templine.finished <= 0)
-  		{
-  			displayTypeLine(templine, 0); //erase top line
-  			copyToTempFile(previewline); //copy preview to temp
-  			displayTypeLine(tempfile, 1); //move preview to active
-  			displayPreviewLine(previewline, 0) //erase bottom
-  			getPreviewLine(); //get new bottom
-  			displayPreviewLine(previewline, 1) //display bottom
-  		}
-  		SDL_Flip(screen);
-  		SDL_Delay(30);
-  		elapsed = time - SDL_GetTicks();
-  	}
-  	while (!quit && elapsed > 0);
-  	if (elapsed)
-  	{
-  		updateWPM(charsfinished);
-  		checkWPM(charsfinished);
-  	}
-  wpm_unload_media();
-
-  return 1;
-}
-
-static int wpm_load_media(void)
-{
-  int i;
-  unsigned char fn[FNLEN];
-  unsigned char let[5];
-
-  LOG("Loading wpm media\n");
-
-
-  bg = LoadImage("main_bkg.png", IMG_ALPHA);
-  wrong = LoadSound("tock.wav");
-  font = LoadFont(settings.theme_font_name, 30);
-
-  /* Get out if anything failed to load: */
-  if (!bg
-    ||!wrong
-    ||!font)
-  {
-    fprintf(stderr, "wpm_load_media() - failed to load needed media \n");
-    wpm_unload_media();
-    return 0;
-  }
-
-  /* Now render letters for glyphs in alphabet: */
-  RenderLetters(font);
-  TTF_CloseFont(font);  /* Don't need it after rendering done */
-  font = NULL;
-
-  LOG("DONE - Loading wpm media\n");
-  return 1;
-}
-
-static void wpm_unload_media(void)
-{
-	int i;
-	SDL_FreeSurface(bg);
-	bg = NULL;
-	Mix_FreeChunk(wrong);
-	wrong = NULL;
-}
-void getTypeLine()
-{
-	int count = 0;
-	int linewidth = 0; //keep lines to 598 pixels
-	typeline.finished = 0 ;
-	typeline.wcount = 0;
-	do
-	{
-		typeline.words[typeline.wcount] = strcat(GetWord(), " ");
-		typeline.wcount++;
-		SDL_Surface* let = NULL;
-		for (count = 0; count <= typeline.wcount; count++)
-		{							
-			i = 0;
-			while( i < wcslen(typeline.words[count]) && linewidth < 598)
-			{
-				let = GetWhiteGlyph((int)typeline.words[count][i]);
-				if (let)
-				{
-					linewidth+= let->w - 5;
-					typeline.finished++;
-				}	
-				else
-				{
-					fprintf(stderr, "getTypeLine() - needed glyph not available\n");
-					return;
-				}
-				i++;
-			}
-		}
-	}
-	while(linewidth < 598);
-	typeline.words[count] = NULL;
-	typeline.wcount--;
-}
-void getPreviewLine()
-{
-	int count = 0;
-	int linewidth = 0; //keep it to a line 598 pixels
-	previewline.wcount = 0;
-	previewline.finished = 0;
-	do
-	{
-		previewline.words[previewline.wcount] = strcat(GetWord(), " ");
-		previewline.wcount++;
-		SDL_Surface* let = NULL;
-		for (count = 0; count <= previewline.wcount; count++)
-		{							
-			i = 0;
-			while( i < wcslen(previewline.words[count]) && linewidth < 598)
-			{
-				let = GetWhiteGlyph((int)previewline.words[count][i]);
-				if (let)
-				{
-					linewidth+= let->w - 5;
-					previewline.finished++;
-				}	
-				else
-				{
-					fprintf(stderr, "getTypeLine() - needed glyph not available\n");
-					return;
-				}
-				i++;
-			}
-		}
-	}
-	while(linewidth < 598);
-	previewline.words[count] = NULL;
-	previewline.wcount--;
-}
-void displayTypeLine(lines tline, int switcher)
-{
-	int i = 0;
-	int count;
-	SDL_Surface* surf = NULL;
-	letter_loc.x = 40;
-	letter_loc.y = 10;
-	letter_loc.w = GetWhiteGlyph(65)->w;
-	letter_loc.h = GetWhiteGlyph(65)->h;
-	
-	if(switcher)
-	{
-		for (count = 0; count < wcslen(tline.words[count]); count++)
-		{
-			for(i = 0; i < wcslen(tline.words[count][i]); i++)
-			{
-				surf = GetWhiteGlyph(tline.words[count][i]);
-				if (surf)
-				{
-					SDL_BlitSurface(surf, NULL, screen, &letter_loc);
-					letter_loc.x = (letter_loc.x + surf->w) - 5;
-				}
-				else
-				{
-					fprintf(stderr, "print_at(): needed glyph for %C not found\n",
-							pphrase[z]);
-				}
-			}
-		}
-	}
-	else //cleanup because old
-	{
-		for (count = 0; count < wcslen(tline.words[count]); count++)
-		{
-			for(i = 0; i < wcslen(tline.words[count][i]); i++)
-			{
-				surf = GetWhiteGlyph(tline.words[count][i]);
-				if (surf)
-				{
-					letter_loc.x = (letter_loc.x + surf->w) - 5;
-					SDL_FreeSurface(surf);
-				}
-			}
-		}
-	}
-}
-void displayPreviewLine(lines pline, int switcher)
-{	
-	int i = 0;
-	int count;
-	SDL_Surface* surf = NULL;
-	letter_loc.x = 40
-	letter_loc.w = GetWhiteGlyph(65)->w;
-	letter_loc.h = GetWhiteGlyph(65)->h;
-	letter_loc.y = 10 + letter_loc.h -(letter_loc.h/4);
-	if(switcher)
-	{
-		for (count = 0; count < wcslen(pline.words[count]); count++)
-		{
-			for(i = 0; i < wcslen(pline.words[count][i]); i++)
-			{
-				surf = GetWhiteGlyph(pline.words[count][i]);
-				if (surf)
-				{
-					SDL_BlitSurface(surf, NULL, screen, &letter_loc);
-					letter_loc.x = (letter_loc.x + surf->w) - 5;
-				}
-				else
-				{
-					fprintf(stderr, "print_at(): needed glyph for %C not found\n",
-							pphrase[z]);
-				}
-			}
-		}
-	}
-	else //cleanup because old
-	{
-		for (count = 0; count < wcslen(pline.words[count]); count++)
-		{
-			for(i = 0; i < wcslen(pline.words[count][i]); i++)
-			{
-				surf = GetWhiteGlyph(pline.words[count][i]);
-				if (surf)
-				{
-					letter_loc.x = (letter_loc.x + surf->w) - 5;
-					SDL_FreeSurface(surf);
-				}
-			}
-		}
-	}
-}
-void copyToTemp(lines x)
-{
-	int count = 0;
-	templine.wcount = 0;
-	templine.finished = 0;
-	do
-	{
-		templine.words[templine.wcount] = x.word[count];
-		templine.wcount++;
-		SDL_Surface* let = NULL;
-		for (count = 0; count <= x.wcount; count++)
-		{							
-			i = 0;
-			while( i < wcslen(x.words[count]))
-			{
-				let = GetWhiteGlyph((int)x.words[count][i]);
-				if (let)
-				{
-					templine.finished++;
-				}	
-				else
-				{
-					fprintf(stderr, "getTypeLine() - needed glyph not available\n");
-					return;
-				}
-				i++;
-			}
-		}
-	}
-}




More information about the Tux4kids-commits mailing list