On 2005-03-29 01:35 +0200, Andre Majorel wrote: > OK. http://www.teaser.fr/~amajorel/yadex/yadex-1.7.900.tar.gz The default game definition file search path is broken. The attached patch fixes it. -- André Majorel <amajorel@xxxxxxxxx> http://www.teaser.fr/~amajorel/
Fixes a bug in Yadex 1.7.900 (YGD files not found through the default search path). AYM 2005-04-01 diff -uaNr yadex-1.7.900/src/game.cc yadex-1.7.901/src/game.cc --- yadex-1.7.900/src/game.cc 2005-03-28 14:14:21.000000000 +0200 +++ yadex-1.7.901/src/game.cc 2005-04-01 11:30:58.000000000 +0200 @@ -76,13 +76,17 @@ al_saps (basename, ".ygd", sizeof basename - 1); /* Locate the game definition file. */ -if (ygd_user_path != NULL) { - Locate locate (ygd_user_path, basename, false); // -G first - const char *pathname = locate.get_next (); + Locate locate; + const char *pathname = NULL; + if (ygd_user_path != NULL) + { + locate.set (ygd_user_path, basename, false); // -G first + pathname = locate.get_next (); + } if (pathname == NULL) { - Locate locate (yadex_share_path, basename, false); // System path second + locate.set (yadex_share_path, basename, false); // System path second pathname = locate.get_next (); } if (pathname == NULL) diff -uaNr yadex-1.7.900/src/locate.cc yadex-1.7.901/src/locate.cc --- yadex-1.7.900/src/locate.cc 2003-04-24 22:44:26.000000000 +0200 +++ yadex-1.7.901/src/locate.cc 2005-04-01 11:09:53.000000000 +0200 @@ -4,7 +4,7 @@ */ /* -This file is copyright André Majorel 2003. +This file is copyright André Majorel 2003, 2005. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the @@ -32,6 +32,26 @@ /* * Locate::Locate - ctor + */ +Locate::Locate () : + initialised (false) +{ +} + + +/* + * Locate::Locate - ctor + * + * The parameters are the same as those of set(). + */ +Locate::Locate (const char *const *search_path, const char *name, bool backw) +{ + set (search_path, name, backw); +} + + +/* + * Locate::set - set the search parameters * * - search_path points to a NULL-terminated array of C * strings (char *) constituting the search path. The @@ -47,14 +67,17 @@ * * - backwards is the direction in which the search path is * walked. true is front-to-back, false is back-to-front. + * + * Implies rewind(). */ -Locate::Locate (const char *const *search_path, const char *name, bool backw) +void Locate::set (const char *const *search_path, const char *name, bool backw) { this->search_path = search_path; this->name = name; this->backwards = backw; absolute = is_absolute (name); rewound = true; + initialised = true; rewind (); } @@ -65,9 +88,18 @@ * Calling this method will cause the next call to * get_next() to return the first match, as if get_next() * had never been called. + * + * If the search parameters have not been set yet, emits a warning + * with warn() and returns without doing anything. */ void Locate::rewind () { + if (! initialised) + { + warn ("Locate: rewind() called before set()"); + return; + } + rewound = true; if (backwards) @@ -90,9 +122,18 @@ * a null pointer if there are no more matches left. The * returned pointer is valid until get_next() is called * again or the Locate object is destroyed. + * + * If the search parameters have not been set, emits a warning with + * warn() and returns a NULL pointer. */ const char *Locate::get_next () { + if (! initialised) + { + warn ("Locate: get_next() called before set()"); + return NULL; + } + if (absolute) { if (! rewound) // Result has exactly one element diff -uaNr yadex-1.7.900/src/locate.h yadex-1.7.901/src/locate.h --- yadex-1.7.900/src/locate.h 2003-04-24 22:44:33.000000000 +0200 +++ yadex-1.7.901/src/locate.h 2005-04-01 11:13:05.000000000 +0200 @@ -4,7 +4,7 @@ */ /* -This file is copyright André Majorel 2003. +This file is copyright André Majorel 2003, 2005. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the @@ -27,11 +27,14 @@ class Locate { public : + Locate (); Locate (const char *const *search_path, const char *name, bool backwards); + void set (const char *const *search_path, const char *name, bool backwards); void rewind (); const char *get_next (); private : + bool initialised; const char *const *search_path; const char *name; bool absolute;