[Tux4kids-commits] r150 - in tuxmath/trunk: docs src

David Bruce dbruce-guest at alioth.debian.org
Mon Apr 9 22:34:36 UTC 2007


Author: dbruce-guest
Date: 2007-04-09 22:34:35 +0000 (Mon, 09 Apr 2007)
New Revision: 150

Modified:
   tuxmath/trunk/docs/changelog
   tuxmath/trunk/src/titlescreen.c
   tuxmath/trunk/src/titlescreen.h
Log:
Lesson order bug fixed


Modified: tuxmath/trunk/docs/changelog
===================================================================
--- tuxmath/trunk/docs/changelog	2007-04-07 19:49:41 UTC (rev 149)
+++ tuxmath/trunk/docs/changelog	2007-04-09 22:34:35 UTC (rev 150)
@@ -1,5 +1,12 @@
 changelog for "tuxmath"
 
+2007.Apr.09 (svn.debian.org/tux4kids - revision 150)
+  Game:
+    * Fixed lesson order bug - code now explicitly sorts the
+      lesson files by alphabetical order of filenames.
+
+      David Bruce <dbruce at tampabay.rr.com>
+
 2007.Apr.07 (svn.debian.org/tux4kids - revision 149)
   Game:
     * Partially implemented high-score table in place (no support

Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c	2007-04-07 19:49:41 UTC (rev 149)
+++ tuxmath/trunk/src/titlescreen.c	2007-04-09 22:34:35 UTC (rev 150)
@@ -50,6 +50,13 @@
     unsigned char type;
 } blits[MAX_UPDATES];
 
+typedef struct lesson_entry {
+  unsigned char filename[NAME_BUF_SIZE];  //List of lesson file names
+  unsigned char display_name[NAME_BUF_SIZE]; //List of lesson names for display
+} lesson_entry;
+
+lesson_entry lesson_list[MAX_LESSONS];
+
 // globals from tuxtype's globals.h defined outside of titlescreen.c (in tuxtype):
 //int show_tux4kids;
 int debugOn; //FIXME switch to TUXMATH_DEBUG
@@ -159,6 +166,7 @@
 void UpdateScreen(int* frame);
 void AddRect(SDL_Rect* src, SDL_Rect* dst);
 void InitEngine(void);
+int compare_lesson_entries(const lesson_entry* a, const lesson_entry* b);
 
 /***********************************************************/
 /*                                                         */
@@ -568,23 +576,25 @@
 
       case OPTIONS:
       {
-        NotImplemented();
-        redraw = 1;
+//        NotImplemented();
+//        redraw = 1;
 
-/*      options();    // Still using old options() for now:
-
-        if (Opts_MenuMusic())
+        if (read_user_config_file())
         {
-          audioMusicUnload();
-        }
+          if (Opts_MenuMusic())
+          {
+            audioMusicUnload();
+          }
 
-        game();
+          game();
+          write_user_config_file();
 
-        if (Opts_MenuMusic())
-        {
-          audioMusicLoad( "tuxi.ogg", -1 );
+          if (Opts_MenuMusic())
+          {
+            audioMusicLoad( "tuxi.ogg", -1 );
+          }
+          redraw = 1;
         }
-        redraw = 1;*/
         break;
       }
 
@@ -1653,12 +1663,10 @@
   int tux_frame = 0;
   int click_flag = 1;
 
+  /* FIXME:Move file stuff into fileops.c.*/
   unsigned char lesson_path[PATH_MAX];             //Path to lesson directory
-  const int name_buf_size = 200;
   char* fgets_return_val;
-  unsigned char lesson_list[MAX_LESSONS][name_buf_size];  //List of lesson file names
-  unsigned char lesson_names[MAX_LESSONS][name_buf_size]; //List of lesson names for display
-  unsigned char name_buf[name_buf_size];
+  unsigned char name_buf[NAME_BUF_SIZE];
 
   DIR* lesson_dir = NULL;
   struct dirent* lesson_file = NULL;
@@ -1704,14 +1712,14 @@
 
     /* FIXME Should somehow test each file to see if it is a tuxmath config file */
     /* Put file name into array of names found in lesson directory */
-    sprintf(lesson_list[lessons], "%s/%s", lesson_path, lesson_file->d_name);
+    sprintf(lesson_list[lessons].filename, "%s/%s", lesson_path, lesson_file->d_name);
 
 #ifdef TUXMATH_DEBUG
-    fprintf(stderr, "Found lesson file %d:\t%s\n", lessons, lesson_list[lessons]);
+    fprintf(stderr, "Found lesson file %d:\t%s\n", lessons, lesson_list[lessons].filename);
 #endif
 
     /* load the name for the lesson from the file ... (1st line) */
-    tempFile = fopen(lesson_list[lessons], "r");
+    tempFile = fopen(lesson_list[lessons].filename, "r");
 
     if (tempFile==NULL)
     {
@@ -1720,7 +1728,7 @@
       continue;
     }
 
-    fgets_return_val = fgets(name_buf,name_buf_size,tempFile);
+    fgets_return_val = fgets(name_buf, NAME_BUF_SIZE, tempFile);
     if (fgets_return_val == NULL) {
       continue;
     }
@@ -1739,28 +1747,28 @@
            ((name_buf[i] == '#') ||
            (name_buf[i] == ';') ||
            isspace(name_buf[i])) &&
-           (i < name_buf_size);
+           (i < NAME_BUF_SIZE);
            i++  )
     {
       length--;
     }
     /* Now copy the rest of the first line into the list: */
-    /* Note the length+1 is needed so that the final \0 is copied! */
-    memmove(&lesson_names[lessons], &name_buf[i], length+1); 
+    /* Note that "length + 1" is needed so that the final \0 is copied! */
+    memmove(&lesson_list[lessons].display_name, &name_buf[i], length + 1); 
     lessons++;
     fclose(tempFile);
   } while (1);        // Loop will end when 'break' encountered
 
   closedir(lesson_dir);	
 
-  
-
+  /* FIXME The lesson list does not necessarily come out in alphabetical order. */
+  /* Sort the list into proper order:           */
+  qsort(lesson_list, lessons, sizeof(struct lesson_entry), compare_lesson_entries);
   /* Display the list of lessons for the player to select: */
   for (i = 0; i < lessons; i++)
   {
-    titles[i] = black_outline( _(lesson_names[i]), default_font, &white );
-    select[i] = black_outline( _(lesson_names[i]), default_font, &yellow);
-    printf("Lesson %d: %s\n", i, lesson_names[i]);
+    titles[i] = black_outline( _(lesson_list[i].display_name), default_font, &white );
+    select[i] = black_outline( _(lesson_list[i].display_name), default_font, &yellow);
   }
 
 //   if (images[IMG_MENU_BKG])
@@ -1904,7 +1912,7 @@
               read_global_config_file();
 
               /* Now read the selected file and play the "mission": */ 
-              if (read_named_config_file(lesson_list[loc]))
+              if (read_named_config_file(lesson_list[loc].filename))
               {
                 if (Opts_MenuMusic())  //Turn menu music off for game
                 {
@@ -1921,7 +1929,7 @@
               }
               else  // Something went wrong - could not read config file:
               {
-                fprintf(stderr, "\nCould not find file: %s\n", lesson_list[loc]);
+                fprintf(stderr, "\nCould not find file: %s\n", lesson_list[loc].filename);
                 stop = 1;
               }
               break;
@@ -1989,7 +1997,7 @@
               read_global_config_file();
 
               /* Now read the selected file and play the "mission": */ 
-              if (read_named_config_file(lesson_list[loc]))
+              if (read_named_config_file(lesson_list[loc].filename))
               {
                 if (Opts_MenuMusic())  //Turn menu music off for game
                   {audioMusicUnload();}
@@ -2002,7 +2010,7 @@
               }
               else  // Something went wrong - could not read config file:
               {
-                fprintf(stderr, "\nCould not find file: %s\n", lesson_list[loc]);
+                fprintf(stderr, "\nCould not find file: %s\n", lesson_list[loc].filename);
                 stop = 1;
               }
               break;
@@ -2456,3 +2464,9 @@
         blits[i].dstrect = &dstupdate[i];
     }
 }
+
+/* This is needed for qsort() for lesson table: */
+int compare_lesson_entries(const lesson_entry* a, const lesson_entry* b)
+{
+  return strcmp(a->filename, b->filename);
+}

Modified: tuxmath/trunk/src/titlescreen.h
===================================================================
--- tuxmath/trunk/src/titlescreen.h	2007-04-07 19:49:41 UTC (rev 149)
+++ tuxmath/trunk/src/titlescreen.h	2007-04-09 22:34:35 UTC (rev 150)
@@ -117,6 +117,7 @@
 #define MAX_LESSONS 100
 #define MAX_NUM_WORDS   500
 #define MAX_WORD_SIZE   8
+#define NAME_BUF_SIZE 200
 
 //MAX_UPDATES needed for TransWipe() and friends:
 #define MAX_UPDATES 180




More information about the Tux4kids-commits mailing list