[Tux4kids-commits] r127 - tuxmath/trunk/src

Tim Holy tholy-guest at alioth.debian.org
Tue Mar 13 12:23:53 CET 2007


Author: tholy-guest
Date: 2007-03-13 11:23:53 +0000 (Tue, 13 Mar 2007)
New Revision: 127

Added:
   tuxmath/trunk/src/gettext.c
   tuxmath/trunk/src/title.c
   tuxmath/trunk/src/title.h
Log:
Add missing files; also a first test commit!

A    title.c
A    title.h
A    gettext.c


Added: tuxmath/trunk/src/gettext.c
===================================================================
--- tuxmath/trunk/src/gettext.c	2007-03-10 13:11:00 UTC (rev 126)
+++ tuxmath/trunk/src/gettext.c	2007-03-13 11:23:53 UTC (rev 127)
@@ -0,0 +1,189 @@
+/***************************************************************************
+gettext.c 
+-  description: a crossplatform minimal gettext library
+-------------------
+begin                : Sunday Feb 23, 2003
+copyright            : (C) 2003 by Jesse Andrews
+email                : jdandr2 at uky.edu
+
+    Modified for use in tuxmath by David Bruce - 2006.
+    email                : <dbruce at tampabay.rr.com>
+                           <tuxmath-devel at lists.sourceforge.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 <stdio.h>
+
+#include "titlescreen.h"
+
+/* we will store our list in a linked list since
+ * we don't expect too large of a list (famous last words!)
+ */
+
+struct node {
+	unsigned char *in;          // the english
+	unsigned char *out;         // the translation
+	struct node *next; // ptr to next in list, NULL if last
+};
+
+typedef struct node item; 
+
+item *HEAD=NULL;
+
+/* --- add a word to the linked list --- */
+
+void add_word(unsigned char *in, unsigned char *out) {
+	item *cur;
+	/* -- allocate space for the node in the list -- */
+	cur = (item *)malloc(sizeof(item));
+
+	/* -- allocate space for strings, and copy over -- */
+	cur->in = (unsigned char *)malloc(strlen(in)+2);
+	strncpy(cur->in, in, strlen(in)+1);
+	cur->out = (unsigned char *)malloc(strlen(out)+2);
+	strncpy(cur->out, out, strlen(out)+1);
+
+	/* -- add to the front of the list -- */
+	cur->next = HEAD;
+	HEAD = cur;
+}
+
+int load_trans(char *file) {
+	/* this function will load the passed file (a .po file)
+	 * if need be, it should erase any previously loaded
+	 * translations.
+	 *
+	 * the filename passed must exist!
+	 *
+	 * returns: 0 if ok
+	 * 	-1 if file could not be located
+	 * 	-2 if file has errors in it
+	 */
+
+	item *ptr;
+	FILE *f;
+	unsigned char str[FNLEN];
+	unsigned char in[FNLEN];
+	unsigned char out[FNLEN];
+
+	LOG( "Clearing previous translation list\n" );
+
+	while(HEAD != NULL) {
+		ptr = HEAD->next;
+		free(HEAD);
+		HEAD = ptr;
+	}
+
+	/* Yes, I know, I should use YACC/LEX
+	 * but, until you provide an GPL YACC/LEX 
+	 * implimentation on Mac OS _CLASSIC_, we have
+	 * to do things so they are portable, which
+	 * means, we have to parse our files by hand
+	 * using "state machines"
+	 */
+
+
+	LOG( "Loading translation file\n" );
+	f = fopen( file, "r" );
+
+	if (f == NULL) return -1;
+	
+	/* ### ADD ERROR CHECKING ### */
+
+	do {
+		fscanf(f, "%[^\n]\n", str);
+
+		/* get rid of any comments! */
+		{
+			unsigned char mode='O';
+			int i;
+			for (i=0; i<strlen(str); i++) {
+				if (mode == 'O') {
+					switch (str[i]) {
+						case '"': mode = 'I'; break;
+						case '#': str[i]='\0'; break;
+					}
+				} else {
+					switch (str[i]) {
+						case '\\': 
+							if (mode != 'S') mode = 'S';
+							else mode = 'I';
+							break;
+						case '"': 
+							if (mode != 'S') mode ='O'; 
+							break;
+						default:
+							mode = 'I'; // get rid of any /
+					}
+				}
+			}
+		}
+
+		/* we force msgid or msgstr to be at the begining of the line! */
+
+		if (strncmp(str, "msgid", 5) == 0) {
+			int start=0, endloc=0, i;
+			for (i=0; i<strlen(str); i++)
+				if (str[i] == '"') {
+					if (!start)
+						start = i;
+					else
+						endloc = i;
+				}
+			str[endloc]='\0';
+			strcpy(in, str+start+1);
+		}
+		if (strncmp(str, "msgstr", 6) == 0) {
+			int start=0,endloc=0, i;
+			for (i=0; i<strlen(str); i++)
+				if (str[i] == '"') {
+					if (!start)
+						start = i;
+					else
+						endloc = i;
+				}
+			str[endloc]='\0';
+			strcpy(out, str+start+1);
+			add_word(in, out);
+		}
+
+	} while( !feof(f) );
+
+	LOG( "Completed loading of translation file\n" );
+
+	return 0;
+}
+
+unsigned char * gettext( unsigned char *in ) {
+	/* this function will attempt to translate the string
+	 * "in" to an "translation of in" if one exists.
+	 * if it doesn't exist in the translation set, it 
+	 * returns "in".
+	 */
+
+	/* go through each time until we find what we want...
+	 * if the number of translated words we use increases, 
+	 * we should move to a hash table.
+	 */
+
+	item *cur=HEAD;
+
+	if (useEnglish)
+		return in;
+
+	while (cur != NULL) 
+		if (strcmp(cur->in, in) == 0)
+			return cur->out;
+		else
+			cur = cur->next;
+
+	/* if we didn't find anything return what we were asked */
+	return in;
+}

Added: tuxmath/trunk/src/title.c
===================================================================
--- tuxmath/trunk/src/title.c	2007-03-10 13:11:00 UTC (rev 126)
+++ tuxmath/trunk/src/title.c	2007-03-13 11:23:53 UTC (rev 127)
@@ -0,0 +1,323 @@
+/*
+  title.c
+
+  For TuxMath
+  The title screen function.
+
+  by Bill Kendrick
+  bill at newbreedsoftware.com
+  http://www.newbreedsoftware.com/
+
+
+  Part of "Tux4Kids" Project
+  http://www.tux4kids.org/
+      
+  August 26, 2001 - February 21, 2003
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <SDL.h>
+
+#include "tuxmath.h"
+#include "title.h"
+#include "fileops.h"
+#include "setup.h"
+#include "playsound.h"
+#include "options.h"
+
+#define START_DEMO_COUNTDOWN 150  /* Some time unit.. not sure yet :) */
+
+int title(void)
+{
+//   int i, cmd, old_cmd, done, img, blinking, widest, left, width, demo_countdown;
+//   SDL_Rect dest;
+//   SDL_Event event;
+//   Uint32 last_time, now_time;
+//   SDLKey key;
+//   
+// 
+//   /* Determine widest option image size: */
+// 
+//   widest = 0;
+//   for (i = 0; i < NUM_CMDS; i++)
+//     {
+//       if (images[IMG_CMD_PLAY + i]->w > widest)
+//         widest = images[IMG_CMD_PLAY + i]->w;
+//     }
+// 
+//   width = widest + 4 + 4 + images[IMG_TUX_HELMET1] -> w;
+//   left = (screen->w - width) / 2;
+//   
+//   
+//   /* Clear window: */
+//   
+//   SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
+//   
+//   
+//   /* Draw title: */
+//   
+//   dest.x = (screen->w - images[IMG_TITLE]->w) / 2;
+//   dest.y = 0;
+//   dest.w = images[IMG_TITLE]->w;
+//   dest.h = images[IMG_TITLE]->h;
+//   
+//   SDL_BlitSurface(images[IMG_TITLE], NULL, screen, &dest);
+//   
+//   
+//   /* Draw options: */
+//   
+//   for (i = 4; i >= 0; i--)
+//     {
+//       // dest.x = (32 - 2) - i;
+//       dest.x = left + 4 - i;
+//       dest.y = (images[IMG_TITLE]->h + 2) + (4 - i);
+//       // dest.w = (screen->w) - ((32 - 2) * 2) + (i * 2);
+//       dest.w = width + (i * 2);
+//       dest.h = (NUM_CMDS * images[IMG_TUX_HELMET1]->h + 2) + (i * 2);
+//       
+//       SDL_FillRect(screen, &dest,
+// 		   SDL_MapRGB(screen->format,
+// 			      200 - (i * 32),
+// 			      232 - (i * 32),
+// 			      255 - (i * 32)));
+//     }
+//   
+//   
+//   for (i = 0; i < NUM_CMDS; i++)
+//     {
+//       // dest.x = 32 + (images[IMG_TUX_HELMET1]->w + 4);
+//       dest.x = left + (images[IMG_TUX_HELMET1]->w) + 4;
+//       dest.y = (images[IMG_TITLE]->h + 8 + 
+// 		(i * images[IMG_TUX_HELMET1]->h));
+//       dest.w = images[IMG_TUX_HELMET1]->w;
+//       dest.h = images[IMG_TUX_HELMET1]->h;
+//       
+//       SDL_BlitSurface(images[IMG_CMD_PLAY + i], NULL, screen, &dest);
+//     }
+//   
+//   
+//   /* Draw "Tux4Kids" logo: */
+//   
+//   dest.x = (screen->w - images[IMG_TUX4KIDS]->w);
+//   dest.y = (screen->h - images[IMG_TUX4KIDS]->h);
+//   dest.w = images[IMG_TUX4KIDS]->w;
+//   dest.h = images[IMG_TUX4KIDS]->h;
+//   
+//   SDL_BlitSurface(images[IMG_TUX4KIDS], NULL, screen, &dest);
+// 
+// 
+//   /* Draw "New Breed Software" logo: */
+// 
+//   dest.x = 0;
+//   dest.y = (screen->h - images[IMG_NBS]->h);
+//   dest.w = images[IMG_NBS]->w;
+//   dest.h = images[IMG_NBS]->h;
+// 
+//   SDL_BlitSurface(images[IMG_NBS], NULL, screen, &dest);
+// 
+// 
+//   if (Opts_DemoMode())
+//   {
+//     dest.x = (screen->w - images[IMG_DEMO_SMALL]->w) / 2;
+//     dest.y = (screen->h - images[IMG_DEMO_SMALL]->h);
+//     dest.w = images[IMG_DEMO_SMALL]->w;
+//     dest.h = images[IMG_DEMO_SMALL]->h;
+// 
+//     SDL_BlitSurface(images[IMG_DEMO_SMALL], NULL, screen, &dest);
+//   }
+// 
+//   
+//   /* Flip the screen: */
+//   
+//   SDL_Flip(screen);
+//   
+//   
+//   
+//   /* --- MAIN TITLE SCREEN LOOP: --- */
+// 
+//   blinking = 0;
+//   cmd = 0;
+//   done = 0;
+//   demo_countdown = START_DEMO_COUNTDOWN;
+//   
+//   do
+//     {
+//       last_time = SDL_GetTicks();
+//       old_cmd = cmd;
+//       
+//       
+//       /* Handle any incoming events: */
+//        
+//       while (SDL_PollEvent(&event) > 0)
+// 	{
+// 	  if (event.type == SDL_QUIT)
+// 	    {
+// 	      /* Window close event - quit! */
+// 	      
+// 	      cmd = CMD_QUIT;
+// 	      done = 1;
+// 	    }
+// 	  else if (event.type == SDL_KEYDOWN)
+// 	    {
+// 	      key = event.key.keysym.sym;
+// 	      
+// 	      if ((key == SDLK_ESCAPE)
+//                 || (key == SDLK_q))
+// 		{
+// 		  /* Escape key or 'Q' - quit! */
+// 		  
+// 		  cmd = CMD_QUIT;
+// 		  done = 1;
+// 		}
+// 
+// 	      if (key == SDLK_p)
+// 		{
+// 		  /* 'P'- play! */
+// 		  
+// 		  cmd = CMD_GAME;
+// 		  done = 1;
+// 		}
+// 
+// 	      if (key == SDLK_o)
+// 		{
+// 		  /* 'O'- Options! */
+// 		  
+// 		  cmd = CMD_OPTIONS;
+// 		  done = 1;
+// 		}
+// 
+// 	      if (key == SDLK_c)
+// 		{
+// 		  /* 'C'- Credits! */
+// 		  
+// 		  cmd = CMD_CREDITS;
+// 		  done = 1;
+// 		}
+// 
+// 	      else if (key == SDLK_DOWN)
+// 		{
+// 		  demo_countdown = START_DEMO_COUNTDOWN;
+// 		  
+// 		  cmd++;
+// 		  
+// 		  if (cmd >= NUM_CMDS)
+// 		    cmd = NUM_CMDS - 1;
+// 		}
+// 	      else if (key == SDLK_UP)
+// 		{
+// 		  demo_countdown = START_DEMO_COUNTDOWN;
+// 
+// 		  cmd--;
+// 		  
+// 		  if (cmd < 0)
+// 		    cmd = 0;
+// 		}
+// 	      else if ((key == SDLK_RETURN) 
+//                     || (key == SDLK_KP_ENTER)
+//                     || (key == SDLK_SPACE))
+// 		{
+// 		  done = 1;
+// 		}
+// 	    }
+// 	  else if (event.type == SDL_MOUSEBUTTONDOWN)
+// 	  {
+//             /* Mouse click: */
+// 	
+// 	    if (event.button.x >= left &&
+// 	        event.button.x <= left + width &&
+// 		event.button.y >= images[IMG_TITLE]->h + 8 &&
+// 		event.button.y <= (images[IMG_TITLE]->h + 8 +
+// 		                   NUM_CMDS * images[IMG_TUX_HELMET1]->h))
+// 	    {
+// 	      cmd = ((event.button.y - (images[IMG_TITLE]->h + 8)) /
+// 	             images[IMG_TUX_HELMET1]->h);
+// 
+// 	      done = 1;
+// 	    }
+// 	  }
+// 	}
+//            
+//       
+//       
+//       /* Erase Tux (cursor) */
+//       
+//       if (cmd != old_cmd)
+// 	{
+// 	  blinking = 0;
+// 	  
+// 	  dest.x = left + 4;
+// 	  dest.y = (images[IMG_TITLE]->h + 8 + 
+// 		    (old_cmd * images[IMG_TUX_HELMET1]->h));
+// 	  dest.w = images[IMG_TUX_HELMET1]->w;
+// 	  dest.h = images[IMG_TUX_HELMET1]->h;
+// 	  
+// 	  SDL_FillRect(screen, &dest,
+// 		       SDL_MapRGB(screen->format, 200, 232, 255));
+// 
+// 	  playsound(SND_POP);
+// 	}
+//       
+//       
+//       /* Handling Tux (cursor) blinking: */
+//       
+//       if ((rand() % 50) == 0 && blinking == 0)
+// 	{
+// 	  blinking = 6;
+// 	}
+//       
+//       if (blinking > 0)
+// 	blinking--;
+//       
+//       
+//       /* Draw Tux (cursor) */
+//       
+//       dest.x = left + 4;
+//       dest.y = images[IMG_TITLE]->h + 8 + (cmd * images[IMG_TUX_HELMET1]->h);
+//       dest.w = images[IMG_TUX_HELMET1]->w;
+//       dest.h = images[IMG_TUX_HELMET1]->h;
+//       
+//       img = IMG_TUX_HELMET1;
+//       
+//       if (blinking >= 4 || (blinking >= 1 && blinking < 2))
+// 	img = IMG_TUX_HELMET2;
+//       else if (blinking >= 2 && blinking < 4)
+// 	img = IMG_TUX_HELMET3;
+//       
+//       SDL_BlitSurface(images[img], NULL, screen, &dest);
+// 
+//       SDL_Flip(screen);
+// 
+// 
+//       /* Handle demo countdown: */
+// 
+//       if (Opts_DemoMode())
+//       {
+// 	demo_countdown--;
+// 
+// 	if (demo_countdown == 0)
+// 	{
+// 	  cmd = CMD_GAME;
+// 	  done = 1;
+// 	}
+//       }
+// 
+//       
+//       /* Pause (keep frame-rate event) */
+//       
+//       now_time = SDL_GetTicks();
+//       if (now_time < last_time + (1000 / 20))
+// 	{
+// 	  SDL_Delay(last_time + (1000 / 20) - now_time);
+// 	}
+//     }
+//   while (!done);
+//   
+//   
+//   /* Return the chosen command: */
+//   
+//   return cmd;
+}

Added: tuxmath/trunk/src/title.h
===================================================================
--- tuxmath/trunk/src/title.h	2007-03-10 13:11:00 UTC (rev 126)
+++ tuxmath/trunk/src/title.h	2007-03-13 11:23:53 UTC (rev 127)
@@ -0,0 +1,32 @@
+/*
+  title.h
+
+  For TuxMath
+  The title screen function.
+
+  by Bill Kendrick
+  bill at newbreedsoftware.com
+  http://www.newbreedsoftware.com/
+
+
+  Part of "Tux4Kids" Project
+  http://www.tux4kids.org/
+      
+  August 26, 2001 - August 28, 2001
+*/
+
+
+#ifndef TITLE_H
+#define TITLE_H
+
+enum {
+  CMD_GAME,
+  CMD_OPTIONS,
+  CMD_CREDITS,
+  CMD_QUIT,
+  NUM_CMDS
+};
+
+int title(void);
+
+#endif




More information about the Tux4kids-commits mailing list