[Tux4kids-commits] r233 - in tuxmath/trunk: data/images/sprites docs nsis src
dbruce-guest at alioth.debian.org
dbruce-guest at alioth.debian.org
Sat Sep 8 10:18:20 UTC 2007
Author: dbruce-guest
Date: 2007-09-08 10:18:19 +0000 (Sat, 08 Sep 2007)
New Revision: 233
Modified:
tuxmath/trunk/data/images/sprites/Makefile
tuxmath/trunk/docs/changelog
tuxmath/trunk/nsis/tuxmath.nsi
tuxmath/trunk/nsis/tuxmath_with_conf.nsi
tuxmath/trunk/src/fileops.c
tuxmath/trunk/src/titlescreen.c
Log:
Code:
* Added replacement function for scandir() (called "w32_scandir() ) because scandir isn't available under Windows - or at least isn't supported by mingw32.
Modified: tuxmath/trunk/data/images/sprites/Makefile
===================================================================
--- tuxmath/trunk/data/images/sprites/Makefile 2007-09-07 15:19:58 UTC (rev 232)
+++ tuxmath/trunk/data/images/sprites/Makefile 2007-09-08 10:18:19 UTC (rev 233)
@@ -36,7 +36,7 @@
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
- $(top_srcdir)/configure.in
+ $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@@ -77,19 +77,19 @@
MAINT = #
MAKEINFO = ${SHELL} /home/dbruce/tux4kids/tuxmath/trunk/missing --run makeinfo
MKDIR_P = /bin/mkdir -p
-NAME_VERSION = tuxmath-1.5.2
+NAME_VERSION = tuxmath-1.5.4
NSIS = /usr/bin/makensis
NSI_DLL_DIR = /home/dbruce/tuxmath_dll
NSI_INSTALL_DIR = mingw32
NSI_TUXMATH_CONF_DIR = no
OBJEXT = o
PACKAGE = tuxmath
-PACKAGE_BUGREPORT =
+PACKAGE_BUGREPORT = tuxmath-devel at lists.sourceforge.net
PACKAGE_DATA_DIR = data
-PACKAGE_NAME =
-PACKAGE_STRING =
-PACKAGE_TARNAME =
-PACKAGE_VERSION =
+PACKAGE_NAME = tuxmath
+PACKAGE_STRING = tuxmath 1.5.4
+PACKAGE_TARNAME = tuxmath
+PACKAGE_VERSION = 1.5.4
PATH_SEPARATOR = :
POW_LIB =
SDL_CFLAGS = -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT
@@ -98,7 +98,7 @@
SET_MAKE =
SHELL = /bin/sh
STRIP = i586-mingw32msvc-strip
-VERSION = 1.5.2
+VERSION = 1.5.4
WINDRES = /usr/bin/i586-mingw32msvc-windres
abs_builddir = /home/dbruce/tux4kids/tuxmath/trunk/data/images/sprites
abs_srcdir = /home/dbruce/tux4kids/tuxmath/trunk/data/images/sprites
@@ -119,7 +119,7 @@
builddir = .
datadir = ${datarootdir}
datarootdir = ${prefix}/share
-docdir = ${datarootdir}/doc/${PACKAGE}
+docdir = ${datarootdir}/doc/${PACKAGE_TARNAME}
dvidir = ${docdir}
exec_prefix = ${prefix}
host = i586-pc-mingw32msvc
Modified: tuxmath/trunk/docs/changelog
===================================================================
--- tuxmath/trunk/docs/changelog 2007-09-07 15:19:58 UTC (rev 232)
+++ tuxmath/trunk/docs/changelog 2007-09-08 10:18:19 UTC (rev 233)
@@ -1,5 +1,10 @@
+2007.Sep.08 (svn.debian.org/tux4kids - revision 233)
+ Code:
+ * Added replacement function for scandir() (called
+ "w32_scandir() ) because scandir isn't available
+ under Windows - or at least isn't supported by
+ mingw32.
-
2007.Sep.07 (svn.debian.org/tux4kids - revision 231)
Version 1.5.4
Modified: tuxmath/trunk/nsis/tuxmath.nsi
===================================================================
--- tuxmath/trunk/nsis/tuxmath.nsi 2007-09-07 15:19:58 UTC (rev 232)
+++ tuxmath/trunk/nsis/tuxmath.nsi 2007-09-08 10:18:19 UTC (rev 233)
@@ -2,7 +2,7 @@
# with a few tiny modifications by Phil Harper(philh at theopencd.org)
# modified for tuxmath by Yves Combe (yves at ycombe.net)
-!define PKG_VERSION "1.5.2"
+!define PKG_VERSION "1.5.4"
!define PKG_PREFIX "tuxmath"
!define APP_PREFIX "TuxMath"
Modified: tuxmath/trunk/nsis/tuxmath_with_conf.nsi
===================================================================
--- tuxmath/trunk/nsis/tuxmath_with_conf.nsi 2007-09-07 15:19:58 UTC (rev 232)
+++ tuxmath/trunk/nsis/tuxmath_with_conf.nsi 2007-09-08 10:18:19 UTC (rev 233)
@@ -2,7 +2,7 @@
# with a few tiny modifications by Phil Harper(philh at theopencd.org)
# modified for tuxmath by Yves Combe (yves at ycombe.net)
-!define PKG_VERSION "1.5.2"
+!define PKG_VERSION "1.5.4"
!define PKG_PREFIX "tuxmath"
!define APP_PREFIX "TuxMath"
Modified: tuxmath/trunk/src/fileops.c
===================================================================
--- tuxmath/trunk/src/fileops.c 2007-09-07 15:19:58 UTC (rev 232)
+++ tuxmath/trunk/src/fileops.c 2007-09-08 10:18:19 UTC (rev 233)
@@ -88,11 +88,127 @@
static int str_to_bool(const char* val);
static int read_config_file(FILE* fp, int file_type);
static int write_config_file(FILE* fp, int verbose);
+static int is_lesson_file(const struct dirent *lfdirent);
+
+
/* fix HOME on windows */
#ifdef BUILD_MINGW32
#include <windows.h>
+/* mingw32 doesn't support scandir() so this is our own replacement: */
+/* (modified from scandir() in glibc-2.3.6) - FSF - GPLv2+) */
+static int w32_scandir(const char* dir, struct dirent*** namelist);
+int w32_alphasort (const void *a, const void *b);
+
+struct scandir_cancel_struct
+{
+ DIR *dp;
+ void *v;
+ size_t cnt;
+};
+
+
+/* mingw32 doesn't support scandir() so this is our own replacement: */
+/* (modified from scandir() in glibc-2.3.6) - FSF - GPLv2+) */
+/* FIXME (maybe) this version doesn't check for allocation errors, */
+/* such as running out of memory. */
+int w32_scandir(const char* dir, struct dirent*** namelist)
+{
+ DIR* dp = opendir (dir);
+ struct dirent** v = NULL;
+ size_t vsize = 0;
+ struct scandir_cancel_struct c;
+ struct dirent* d = NULL;
+ int save;
+
+ if (dp == NULL)
+ return -1;
+// save = errno;
+// errno = 0;
+
+ c.dp = dp;
+ c.v = NULL;
+ c.cnt = 0;
+ //__libc_cleanup_push (cancel_handler, &c);
+
+ d = readdir(dp);
+
+ while (d != NULL) /* go until no more entries in lesson directory */
+ {
+ if (is_lesson_file(d)) /* if it's a lesson file, add it to list: */
+ {
+ struct dirent* vnew;
+ size_t dsize;
+
+// /* Ignore errors from select or readdir */
+// errno =0 ;
+
+ if (c.cnt == vsize)
+ {
+ struct dirent** new;
+
+ if (vsize == 0)
+ vsize = 10;
+ else
+ vsize *= 2;
+
+ new = (struct dirent**) realloc (v, vsize * sizeof (*v));
+
+ if (new == NULL)
+ break;
+
+ v = new;
+ c.v = (void *) v;
+ }
+
+ dsize = &d->d_name[strlen((const char*)&d->d_name) + 1] - (char *) d;
+ vnew = (struct dirent *) malloc (dsize);
+ if (vnew == NULL)
+ break;
+
+ v[c.cnt++] = (struct dirent *) memcpy (vnew, d, dsize);
+ }
+ /* read next entry: */
+ d = readdir(dp);
+ }
+
+// if (errno != 0)
+// {
+// save = errno;
+//
+// while (c.cnt > 0)
+// free (v[--c.cnt]);
+// free (v);
+// c.cnt = -1;
+// }
+// else
+ {
+ /* Sort the list if we have a comparison function to sort with. */
+ qsort (v, c.cnt, sizeof (*v), w32_alphasort);
+ *namelist = v;
+ }
+
+// __libc_cleanup_pop (0);
+
+ closedir(dp);
+// errno = save;
+
+ return c.cnt;
+
+}
+
+/* This is needed for qsort() for lesson table: */
+int
+w32_alphasort (const void *a, const void *b)
+{
+ return strcoll ((*(const struct dirent **) a)->d_name,
+ (*(const struct dirent **) b)->d_name);
+}
+
+
+
+
/* STOLEN from tuxpaint */
/*
@@ -478,12 +594,15 @@
return 0;
}
-int is_lesson_file(const struct dirent *lfdirent)
+/* NOTE the cast to "const char*" just prevents compiler from complaining */
+static int is_lesson_file(const struct dirent *lfdirent)
{
- return (0 == strncasecmp(&(lfdirent->d_name), "lesson", 6));
+ return (0 == strncasecmp((const char*)&(lfdirent->d_name), "lesson", 6));
/* FIXME Should somehow test each file to see if it is a tuxmath config file */
}
+
+
int parse_lesson_file_directory(void)
{
unsigned char lesson_path[PATH_MAX]; //Path to lesson directory
@@ -505,7 +624,13 @@
fprintf(stderr, "lesson_path is: %s\n", lesson_path);
#endif
- num_lessons = scandir(lesson_path,&lesson_list_dirents,is_lesson_file,alphasort);
+/* Use our home-brewed scandir() if platform doesn't have it in lib: */
+#ifdef BUILD_MINGW32
+ num_lessons = w32_scandir(lesson_path, &lesson_list_dirents);
+#else
+ num_lessons = scandir(lesson_path, &lesson_list_dirents, is_lesson_file, alphasort);
+#endif
+
if (num_lessons < 0) {
perror("scanning lesson directory");
num_lessons = 0;
@@ -2227,7 +2352,7 @@
}
/* Return -1 if any chars are non-digits: */
- ptr = val;
+ ptr = (char*)val;
while (*ptr)
{
if (!isdigit(*ptr))
@@ -2608,3 +2733,108 @@
return 1;
}
#endif
+
+
+
+// /* FIXME:Move file stuff into fileops.c.*/
+// /* Todo?: switch from readdir() to scandir() and use dynamic memory allocation? */
+// unsigned char lesson_path[PATH_MAX]; //Path to lesson directory
+// char* fgets_return_val;
+// unsigned char name_buf[NAME_BUF_SIZE];
+//
+// DIR* lesson_dir = NULL;
+// struct dirent* lesson_file = NULL;
+// FILE* tempFile = NULL;
+//
+// /* All pointers get explicitly set to NULL until used:*/
+// for (i = 0; i < MAX_LESSONS; i++)
+// {
+// titles[i] = NULL;
+// select[i] = NULL;
+// }
+//
+//
+// #ifdef TUXMATH_DEBUG #ifdef TUXMATH_DEBUG
+// fprintf(stderr, "Entering choose_config_file():\n"); fprintf(stderr, "Entering choose_config_file():\n");
+// #endif #endif
+//
+// /* find the directory containing the lesson files: */
+// sprintf(lesson_path, "%s/missions/lessons", DATA_PREFIX);
+//
+// #ifdef TUXMATH_DEBUG
+// fprintf(stderr, "lesson_path is: %s\n", lesson_path);
+// #endif
+//
+// /* create a list of all the lesson files */
+// lesson_dir = opendir(lesson_path);
+//
+// do
+// {
+// /* readdir() returns ptr to next file in dir AND resets ptr to following file: */
+// lesson_file = readdir(lesson_dir);
+// /* Get out when no more files: */
+// if (!lesson_file)
+// {
+// break;
+// }
+//
+// /* file names must begin with 'lesson' (case-insensitive) */
+// if (0 != strncasecmp(&lesson_file->d_name, "lesson", 6))
+// {
+// continue;
+// }
+//
+// /* 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].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].filename);
+// #endif
+//
+// /* load the name for the lesson from the file ... (1st line) */
+// tempFile = fopen(lesson_list[lessons].filename, "r");
+//
+// if (tempFile==NULL)
+// {
+// /* By leaving the current iteration without incrementing 'lessons', */
+// /* the bad file name will get clobbered next time through: */
+// continue;
+// }
+//
+// fgets_return_val = fgets(name_buf, NAME_BUF_SIZE, tempFile);
+// if (fgets_return_val == NULL) {
+// continue;
+// }
+//
+//
+// /* check to see if it has a \r at the end of it (dos format!) */
+// length = strlen(name_buf);
+// while (length>0 && (name_buf[length - 1] == '\r' || name_buf[length - 1] == '\n')) {
+// name_buf[length - 1] = '\0';
+// length--;
+// }
+//
+// /* Go past leading '#', ';', or whitespace: */
+// /* NOTE getting i to the correct value on exit is the main goal of the loop */
+// for ( i = 0;
+// ((name_buf[i] == '#') ||
+// (name_buf[i] == ';') ||
+// isspace(name_buf[i])) &&
+// (i < NAME_BUF_SIZE);
+// i++ )
+// {
+// length--;
+// }
+// /* Now copy the rest of the first line into the list: */
+// /* 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 (lessons < MAX_LESSONS); // 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); */*/
Modified: tuxmath/trunk/src/titlescreen.c
===================================================================
--- tuxmath/trunk/src/titlescreen.c 2007-09-07 15:19:58 UTC (rev 232)
+++ tuxmath/trunk/src/titlescreen.c 2007-09-08 10:18:19 UTC (rev 233)
@@ -164,7 +164,6 @@
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);
void ShowMessage(char* str1, char* str2, char* str3, char* str4);
/***********************************************************/
@@ -2408,8 +2407,4 @@
}
}
-/* 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);
-}
+
More information about the Tux4kids-commits
mailing list