[Tux4kids-commits] r1624 - in tuxtype/trunk: data/scripts src
David Bruce
dbruce-guest at alioth.debian.org
Wed Oct 28 15:50:23 UTC 2009
Author: dbruce-guest
Date: 2009-10-28 15:50:23 +0000 (Wed, 28 Oct 2009)
New Revision: 1624
Removed:
tuxtype/trunk/data/scripts/00_Scripting_Sample.xml
Modified:
tuxtype/trunk/src/scripting.c
Log:
removed unneeded example (have plenty of examples now)
Deleted: tuxtype/trunk/data/scripts/00_Scripting_Sample.xml
===================================================================
--- tuxtype/trunk/data/scripts/00_Scripting_Sample.xml 2009-10-28 15:50:11 UTC (rev 1623)
+++ tuxtype/trunk/data/scripts/00_Scripting_Sample.xml 2009-10-28 15:50:23 UTC (rev 1624)
@@ -1,66 +0,0 @@
-<script title="Test Lesson" bgcolor="#3f4f1f">
- <page title="Introduction to Example Lesson">
- <text align="center">The Lesson that follows is only an example</text>
- <text align="center">lesson to help you to see how to write lessons.</text>
- <text align="center">To start writing your own lessons, edit the file,</text>
- <text align="center">"Lesson_1.xml" in your "tuxtype/data/scripts"</text>
- <text align="center">directory.</text>
- <text align="center" y="300"> PRESS SPACE TO START THE LESSON!</text>
- <waitforinput/>
- </page>
- <page title="Home Row Keys" bgcolor="#3f7f3f">
- <img src="/keyboard/keyboard-us.png" x="45" y="220"/>
- <text align="center">In this exercise we practice the home row keys.</text>
- <text align="center">asdfjkl;asdfjkl;asdfjkl;</text>
- <text align="center">To start practicing hit the p key</text>
- <text color="#000000" x="100" y="280">A</text>
- <text color="#000000" x="130" y="280">S</text>
- <text color="#000000" x="160" y="280">D</text>
- <text color="#000000" x="190" y="280">F</text>
- <text color="#000000" x="320" y="273">J</text>
- <text color="#000000" x="350" y="273">K</text>
- <text color="#000000" x="380" y="273">L</text>
- <text color="#000000" x="410" y="273">;</text>
- <waitforchar/>
- <prac goal="15">asdfjkl;asdfjkl;asdfjkl;</prac>
- <prac>asdfjkl;asdfjkl;asdfjkl;</prac>
- <prac>asdfjkl;asdfjkl;asdfjkl;</prac>
- </page>
- <page>
- <img src="keyboard/space.png" x="200" y="160"/>
- <img src="keyboard/larrow.png" x="460" y="18"/>
- <img src="keyboard/esc.png" x="515" y="50"/>
- <text align="center">Great Job!</text>
- <text align="left"> To repeat the last exercise, press</text>
- <text align="center">To go back to the main menu hit</text>
- <text align="center">To continue on to the next exercise,</text>
- <text align="center">press</text>
- <text align="center">Space</text>
- <text></text>
- <text></text>
- <text></text>
- <text align="center">Next Exercise:</text>
- <text align="center">lad lass dad sad fad gas had jag ask;</text>
- <waitforinput/>
- </page>
- <page title="Home Row Keys" bgcolor="#b07bc6">
- <img src="/keyboard/keyboard-us.png" x="45" y="220"/>
- <text align="center">In this exercise we practice the home row keys,</text>
- <text align="center">but, a little bit differently!</text>
- <text align="center">See how fast you are at this one!</text>
- <text align="center">lad lass dad sad fad gas had jag ask;</text>
- <text align="center">To start practicing hit the p key</text>
- <text color="#000000" x="100" y="280">A</text>
- <text color="#000000" x="130" y="280">S</text>
- <text color="#000000" x="160" y="280">D</text>
- <text color="#000000" x="190" y="280">F</text>
- <text color="#000000" x="320" y="273">J</text>
- <text color="#000000" x="350" y="273">K</text>
- <text color="#000000" x="380" y="273">L</text>
- <text color="#000000" x="410" y="273">;</text>
- <waitforchar/>
- <prac>lad lass dad sad fad gas had jag ask; lad lass dad sad fad gas had jag ask;</prac>
- <prac>lad lass dad sad fad gas had jag ask; lad lass dad sad fad gas had jag ask;</prac>
- <prac>lad lass dad sad fad gas had jag ask; lad lass dad sad fad gas had jag ask;</prac>
- </page>
-</script>
Modified: tuxtype/trunk/src/scripting.c
===================================================================
--- tuxtype/trunk/src/scripting.c 2009-10-28 15:50:11 UTC (rev 1623)
+++ tuxtype/trunk/src/scripting.c 2009-10-28 15:50:23 UTC (rev 1624)
@@ -20,11 +20,7 @@
#define MAX_LESSONS 100
#include "SDL_extras.h"
#include "convert_utf.h"
-
-/* Use our replacement scandir() if platform lacks it: */
-#ifndef HAVE_SCANDIR
#include "scandir.h"
-#endif
/* Local function prototypes: */
static void clear_items(itemType* i);
@@ -36,7 +32,7 @@
static char hex2int(char b, char s);
static int load_script(const char* fn);
static void run_script(void);
-
+static int is_xml_file(const struct dirent* xml_dirent);
/************************************************************************/
/* */
/* "Public" functions (callable throughout program) */
@@ -122,19 +118,26 @@
SDL_Rect leftRect, rightRect;
SDL_Rect titleRects[8];
- int stop = 0;
- int loc = 0;
- int old_loc = 1;
+ char* fgets_return_val;
+ int nchars;
+ struct dirent **script_list_dirents = NULL;
+ int i = 0;
+ int scriptIterator = 0; //Iterator over matching files in script dir
+ int length = 0;
+ int scripts = 0; //Iterator over accepted (& parsed) script files
int num_scripts = 0;
- int found = 0;
- int i;
char script_path[FNLEN];
- char script_filenames[MAX_LESSONS][200];
+ char script_filenames[MAX_LESSONS][FNLEN];
char fn[FNLEN];
+ DIR* script_dir = NULL;
- DIR* script_dir = NULL;
struct dirent* script_file = NULL;
+ int stop = 0;
+ int loc = 0;
+ int old_loc = 1;
+ int found = 0;
+
LOG("Entering XMLLesson():\n");
/* First look in theme path, if desired: */
@@ -172,41 +175,93 @@
DEBUGCODE { fprintf(stderr, "script_path is: %s\n", script_path); }
- /* FIXME looks like a place for scandir() - or our own w32_scandir() */
/* create a list of all the .xml files */
+ num_scripts = scandir(script_path, &script_list_dirents, is_xml_file, alphasort);
- script_dir = opendir(script_path);
-
- do
+ for (scriptIterator = 0, scripts = 0;
+ scriptIterator < num_scripts && scripts < MAX_LESSONS;
+ scriptIterator++)
{
- script_file = readdir(script_dir);
- if (!script_file)
- break;
+ /* Copy over the filename: */
+ nchars = snprintf(script_filenames[scripts], FNLEN, "%s",
+ script_list_dirents[scriptIterator]->d_name);
- /* must have at least '.xml' at the end */
- if (strlen(script_file->d_name) < 5)
+ /* Skip (actually clobber) any invalid or undesired files: */
+ if (nchars < 0 || nchars >= FNLEN)
continue;
-
/* Don't show project info file or instructions files */
- if (strcmp(script_file->d_name, "projectInfo.xml") == 0 ||
- strcmp(script_file->d_name, "laser.xml") == 0 ||
- strcmp(script_file->d_name, "cascade.xml") == 0)
+ if (strcmp(script_filenames[scripts], "projectInfo.xml") == 0 ||
+ strcmp(script_filenames[scripts], "laser.xml") == 0 ||
+ strcmp(script_filenames[scripts], "cascade.xml") == 0)
continue;
+ DEBUGCODE
+ {
+ fprintf(stderr, "Found script file %d:\t%s\n", scripts, script_filenames[scripts]);
+ }
+ /* Increment the iterator for correctly-parsed lesson files */
+ scripts++;
+ }
- if (strcmp(&script_file->d_name[strlen(script_file->d_name) - 4],".xml"))
- continue;
+// DEBUGCODE
+ {
+ fprintf(stderr, "Before undesired files screened out:\n");
+ for(i = 0; i < num_scripts; i++)
+ fprintf(stderr, "script %d filename: %s\n", i,
+ script_list_dirents[i]->d_name);
+ fprintf(stderr, "After undesired files screened out:\n");
+ for(i = 0; i < scripts; i++)
+ fprintf(stderr, "script %d filename: %s\n", i,
+ script_filenames[i]);
+ }
- sprintf(script_filenames[num_scripts], "%s", script_file->d_name);
- num_scripts++;
- DEBUGCODE { fprintf(stderr, "Adding XML file no. %d: %s\n",
- num_scripts, script_filenames[num_scripts]); }
- } while (1); /* Leave loop when readdir() returns NULL */
+ /* Now free the individual dirents. We do this on a second pass */
+ /* because of the "continue" approach used to error handling. */
+ for (scriptIterator = 0; scriptIterator < num_scripts; scriptIterator++)
+ free(script_list_dirents[scriptIterator]);
+ free(script_list_dirents);
- closedir(script_dir);
+ /* Adjust num_scripts for any skipped files: */
+ num_scripts = scripts;
+//START OF OLD IMPLEMENTATION
+// num_scripts = 0;
+// script_dir = opendir(script_path);
+// do
+// {
+// script_file = readdir(script_dir);
+// if (!script_file)
+// break;
+//
+// /* must have at least '.xml' at the end */
+// if (strlen(script_file->d_name) < 5)
+// continue;
+//
+// /* Don't show project info file or instructions files */
+// if (strcmp(script_file->d_name, "projectInfo.xml") == 0 ||
+// strcmp(script_file->d_name, "laser.xml") == 0 ||
+// strcmp(script_file->d_name, "cascade.xml") == 0)
+// continue;
+//
+//
+// if (strcmp(&script_file->d_name[strlen(script_file->d_name) - 4],".xml"))
+// continue;
+//
+// sprintf(script_filenames[num_scripts], "%s", script_file->d_name);
+// num_scripts++;
+// DEBUGCODE { fprintf(stderr, "Adding XML file no. %d: %s\n",
+// num_scripts, script_filenames[num_scripts]); }
+//
+// } while (1); /* Leave loop when readdir() returns NULL */
+//
+// closedir(script_dir);
+
+// END OF OLD IMPLEMENTATION
+
+
+
DEBUGCODE { fprintf(stderr, "Found %d . xml file(s) in script dir\n", num_scripts); }
@@ -1573,3 +1628,12 @@
curScript = NULL;
}
}
+
+
+/* NOTE we just check to see if the name ends in ".xml", but we don't */
+/* verify that it really contains XML. */
+static int is_xml_file(const struct dirent* xml_dirent)
+{
+ const char* ending = &xml_dirent->d_name[strlen(xml_dirent->d_name) - 4];
+ return (0 == strncasecmp(ending, ".xml", 4));
+}
More information about the Tux4kids-commits
mailing list