src/newgrf_config.cpp
changeset 7571 501649a5f47e
parent 7034 e2d80a01d9c1
child 7572 817d4302228e
equal deleted inserted replaced
7570:5d5d9b6af0ef 7571:501649a5f47e
   313 					_all_grfs = c;
   313 					_all_grfs = c;
   314 				} else {
   314 				} else {
   315 					/* Insert file into list at a position determined by its
   315 					/* Insert file into list at a position determined by its
   316 					 * name, so the list is sorted as we go along */
   316 					 * name, so the list is sorted as we go along */
   317 					GRFConfig **pd, *d;
   317 					GRFConfig **pd, *d;
       
   318 					bool stop = false;
   318 					for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
   319 					for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
   319 						if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
   320 						if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
   320 						if (strcasecmp(c->name, d->name) <= 0) break;
   321 						/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
       
   322 						*  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
       
   323 						*  just after the first with the same name. Avoids doubles in the list. */
       
   324 						if (strcasecmp(c->name, d->name) <= 0) stop = true;
       
   325 						else if (stop) break;
   321 					}
   326 					}
   322 					if (added) {
   327 					if (added) {
   323 						c->next = d;
   328 						c->next = d;
   324 						*pd = c;
   329 						*pd = c;
   325 					}
   330 					}