src/newgrf_config.cpp
changeset 9088 d60882689d41
parent 8710 52015340050c
child 10429 1b99254f9607
child 10655 b862a4add8b0
equal deleted inserted replaced
9087:c6ff1721bb00 9088:d60882689d41
   275 	if (FillGRFDetails(c, false)) {
   275 	if (FillGRFDetails(c, false)) {
   276 		if (_all_grfs == NULL) {
   276 		if (_all_grfs == NULL) {
   277 			_all_grfs = c;
   277 			_all_grfs = c;
   278 		} else {
   278 		} else {
   279 			/* Insert file into list at a position determined by its
   279 			/* Insert file into list at a position determined by its
   280 				* name, so the list is sorted as we go along */
   280 			 * name, so the list is sorted as we go along */
   281 			GRFConfig **pd, *d;
   281 			GRFConfig **pd, *d;
   282 			bool stop = false;
   282 			bool stop = false;
   283 			for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
   283 			for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
   284 				if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
   284 				if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
   285 				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
   285 				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
   286 				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
   286 				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
   287 				 *  just after the first with the same name. Avoids doubles in the list. */
   287 				 *  just after the first with the same name. Avoids doubles in the list. */
   288 				if (strcasecmp(c->name, d->name) <= 0) stop = true;
   288 				if (strcasecmp(c->name, d->name) <= 0) {
   289 				else if (stop) break;
   289 					stop = true;
       
   290 				} else if (stop) {
       
   291 					break;
       
   292 				}
   290 			}
   293 			}
   291 			if (added) {
   294 			if (added) {
   292 				c->next = d;
   295 				c->next = d;
   293 				*pd = c;
   296 				*pd = c;
   294 			}
   297 			}
   297 		added = false;
   300 		added = false;
   298 	}
   301 	}
   299 
   302 
   300 	if (!added) {
   303 	if (!added) {
   301 		/* File couldn't be opened, or is either not a NewGRF or is a
   304 		/* File couldn't be opened, or is either not a NewGRF or is a
   302 			* 'system' NewGRF or it's already known, so forget about it. */
   305 		 * 'system' NewGRF or it's already known, so forget about it. */
   303 		free(c->filename);
   306 		free(c->filename);
   304 		free(c->name);
   307 		free(c->name);
   305 		free(c->info);
   308 		free(c->info);
   306 		free(c);
   309 		free(c);
   307 	}
   310 	}