[Tux4kids-commits] r1503 - tuxtype/trunk/src

Matthew Trey treymd-guest at alioth.debian.org
Thu Sep 10 18:32:03 UTC 2009


Author: treymd-guest
Date: 2009-09-10 18:32:03 +0000 (Thu, 10 Sep 2009)
New Revision: 1503

Modified:
   tuxtype/trunk/src/funcs.h
   tuxtype/trunk/src/scripting.c
   tuxtype/trunk/src/titlescreen.c
Log:
Added code in scripting to recognize xml comments, changed name of TestLesson() to XMLLesson()

Modified: tuxtype/trunk/src/funcs.h
===================================================================
--- tuxtype/trunk/src/funcs.h	2009-09-10 16:13:59 UTC (rev 1502)
+++ tuxtype/trunk/src/funcs.h	2009-09-10 18:32:03 UTC (rev 1503)
@@ -92,7 +92,7 @@
 
 
 /* In scripting.c: */
-int TestLesson(void);
+int XMLLesson(void);
 void ProjectInfo(void);
 void InstructCascade(void);
 void InstructLaser(void);

Modified: tuxtype/trunk/src/scripting.c
===================================================================
--- tuxtype/trunk/src/scripting.c	2009-09-10 16:13:59 UTC (rev 1502)
+++ tuxtype/trunk/src/scripting.c	2009-09-10 18:32:03 UTC (rev 1503)
@@ -107,9 +107,9 @@
   run_script();
 }
 
-/* NOTE - confusing function name - this is the function that allows the user */
+/* This is the function that allows the user */
 /* to select a lesson from the menu.                                          */
-int TestLesson(void)
+int XMLLesson(void)
 {
   SDL_Surface* titles[MAX_LESSONS] = {NULL};
   SDL_Surface* select[MAX_LESSONS] = {NULL};
@@ -130,7 +130,7 @@
   DIR* script_dir = NULL;
   struct dirent* script_file = NULL;
 
-  LOG("Entering TestLesson():\n");
+  LOG("Entering XMLLesson():\n");
 
   /* First look in theme path, if desired: */
   if (!settings.use_english)
@@ -156,7 +156,7 @@
 
   if (!found)
   {
-    fprintf(stderr, "TestLesson(): Error finding script directory!\n");
+    fprintf(stderr, "XMLLesson(): Error finding script directory!\n");
     return 0;
   }
 
@@ -219,7 +219,7 @@
   /* Get out if needed surface not loaded successfully: */
   if (!CurrentBkgd() || !left || !right)
   {
-    fprintf(stderr, "TestLesson(): needed image not available\n");
+    fprintf(stderr, "XMLLesson(): needed image not available\n");
   
     for (i = 0; i < num_scripts; i++)
     {
@@ -416,7 +416,7 @@
   run_script();
   SDL_ShowCursor(1);
 
-  LOG("Leave TestLesson()\n");
+  LOG("Leave XMLLesson()\n");
 
   return 1;
 }
@@ -536,6 +536,62 @@
     if (fscanf_result == EOF)
       break;
 
+    if (strncmp("<!--", str, 4) == 0)
+    {
+        /* -- comment section found, ignore everything until comment close -- */
+        int found = 0;
+        char* tmpStr;
+
+        do
+        {
+            for ( tmpStr = str; strlen(tmpStr) >= 3; ++tmpStr )
+            {    
+                 if (strncmp("-->",tmpStr, 3) == 0)
+                 {
+                     found = 1;
+                     tmpStr += 3;
+                     if (strlen(tmpStr) > 0)
+                     {
+                         // copy the rest of the line into str for processing
+                         strncpy(str, tmpStr, strlen(tmpStr));
+                     }
+                     else
+                     {
+                         // str needs another line, this one is used up
+                         fscanf_result = fscanf(f, "%[^\n]\n", str);
+                         
+                         // we may get consecutive comment lines
+                         if (fscanf_result != EOF && strncmp("<!--", str, 4) == 0)
+                         {
+                             found = 0;
+                             tmpStr = str;
+                         }
+                     }
+                 }
+            }
+
+            if (!found)
+            {
+                fscanf_result = fscanf(f, "%[^\n]\n", str);
+                tmpStr = str;
+            }
+
+        } while ( fscanf_result != EOF && !found );
+        
+        /* -- if we reached the end of the file and saw no close to the comment, generate a warning -- */
+        if ( !found && fscanf_result == EOF )
+        {
+            fprintf(stderr, "XML Warning: End of file reached looking for the end of a comment.\n", fn);
+            break;
+        }
+
+        /* -- don't continue processing if at EOF -- */
+        if (fscanf_result == EOF)
+        {
+            break;
+        }
+    }
+
     if (strncmp("<script", str, 7) == 0)
     {
       /* -- allocate space for the lesson info -- */
@@ -1101,7 +1157,9 @@
                 continue;
 
               tmp[toshow] = 0;
+ 
               img = SimpleText(tmp, (int)curItem->size, col);
+
               if (img)
               { 
                 if (img->w + 20 < screen->w)

Modified: tuxtype/trunk/src/titlescreen.c
===================================================================
--- tuxtype/trunk/src/titlescreen.c	2009-09-10 16:13:59 UTC (rev 1502)
+++ tuxtype/trunk/src/titlescreen.c	2009-09-10 18:32:03 UTC (rev 1503)
@@ -507,7 +507,7 @@
       if (settings.menu_music)
         MusicUnload( );
 
-      TestLesson();
+      XMLLesson();
 
       load_media();
 




More information about the Tux4kids-commits mailing list