summaryrefslogtreecommitdiff
path: root/src/newgrf_config.cpp
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-09-13 18:28:56 +0000
committertruelight <truelight@openttd.org>2007-09-13 18:28:56 +0000
commit70772e9cc92b7be6651a615bb8cafd3948097ee3 (patch)
treeb593f601f2d77d443054fbd96a9eb15f49f1406d /src/newgrf_config.cpp
parentbf17a96b630302b5e5ec538b9665745aebfee108 (diff)
downloadopenttd-70772e9cc92b7be6651a615bb8cafd3948097ee3.tar.xz
(svn r11097) -Codechange: for easy future extension of NewGRF Scanning, split up the functions a bit
Diffstat (limited to 'src/newgrf_config.cpp')
-rw-r--r--src/newgrf_config.cpp84
1 files changed, 44 insertions, 40 deletions
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 2e30841b4..70e068450 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -270,12 +270,54 @@ compatible_grf:
return res;
}
+static bool ScanPathAddGrf(const char *filename)
+{
+ GRFConfig *c = CallocT<GRFConfig>(1);
+ c->filename = strdup(filename);
+
+ bool added = true;
+ if (FillGRFDetails(c, false)) {
+ if (_all_grfs == NULL) {
+ _all_grfs = c;
+ } else {
+ /* Insert file into list at a position determined by its
+ * name, so the list is sorted as we go along */
+ GRFConfig **pd, *d;
+ bool stop = false;
+ for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
+ if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
+ /* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
+ * before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
+ * just after the first with the same name. Avoids doubles in the list. */
+ if (strcasecmp(c->name, d->name) <= 0) stop = true;
+ else if (stop) break;
+ }
+ if (added) {
+ c->next = d;
+ *pd = c;
+ }
+ }
+ } else {
+ added = false;
+ }
-extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
+ if (!added) {
+ /* File couldn't be opened, or is either not a NewGRF or is a
+ * 'system' NewGRF or it's already known, so forget about it. */
+ free(c->filename);
+ free(c->name);
+ free(c->info);
+ free(c);
+ }
+
+ return added;
+}
/* Scan a path for NewGRFs */
static uint ScanPath(const char *path, int basepath_length)
{
+ extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
+
uint num = 0;
struct stat sb;
struct dirent *dirent;
@@ -304,45 +346,7 @@ static uint ScanPath(const char *path, int basepath_length)
if (ext == NULL) continue;
if (strcasecmp(ext, ".grf") != 0) continue;
- GRFConfig *c = CallocT<GRFConfig>(1);
- c->filename = strdup(filename + basepath_length);
-
- bool added = true;
- if (FillGRFDetails(c, false)) {
- if (_all_grfs == NULL) {
- _all_grfs = c;
- } else {
- /* Insert file into list at a position determined by its
- * name, so the list is sorted as we go along */
- GRFConfig **pd, *d;
- bool stop = false;
- for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
- if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
- /* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
- * before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
- * just after the first with the same name. Avoids doubles in the list. */
- if (strcasecmp(c->name, d->name) <= 0) stop = true;
- else if (stop) break;
- }
- if (added) {
- c->next = d;
- *pd = c;
- }
- }
- } else {
- added = false;
- }
-
- if (!added) {
- /* File couldn't be opened, or is either not a NewGRF or is a
- * 'system' NewGRF or it's already known, so forget about it. */
- free(c->filename);
- free(c->name);
- free(c->info);
- free(c);
- } else {
- num++;
- }
+ if (ScanPathAddGrf(filename + basepath_length)) num++;
}
}