src/newgrf_config.cpp
branchNewGRF_ports
changeset 6878 7d1ff2f621c7
parent 6872 1c4a4a609f85
child 10724 68a692eacf22
equal deleted inserted replaced
6877:889301acc299 6878:7d1ff2f621c7
   301 	if (FillGRFDetails(c, false)) {
   301 	if (FillGRFDetails(c, false)) {
   302 		if (_all_grfs == NULL) {
   302 		if (_all_grfs == NULL) {
   303 			_all_grfs = c;
   303 			_all_grfs = c;
   304 		} else {
   304 		} else {
   305 			/* Insert file into list at a position determined by its
   305 			/* Insert file into list at a position determined by its
   306 				* name, so the list is sorted as we go along */
   306 			 * name, so the list is sorted as we go along */
   307 			GRFConfig **pd, *d;
   307 			GRFConfig **pd, *d;
   308 			bool stop = false;
   308 			bool stop = false;
   309 			for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
   309 			for (pd = &_all_grfs; (d = *pd) != NULL; pd = &d->next) {
   310 				if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
   310 				if (c->grfid == d->grfid && memcmp(c->md5sum, d->md5sum, sizeof(c->md5sum)) == 0) added = false;
   311 				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
   311 				/* Because there can be multiple grfs with the same name, make sure we checked all grfs with the same name,
   312 				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
   312 				 *  before inserting the entry. So insert a new grf at the end of all grfs with the same name, instead of
   313 				 *  just after the first with the same name. Avoids doubles in the list. */
   313 				 *  just after the first with the same name. Avoids doubles in the list. */
   314 				if (strcasecmp(c->name, d->name) <= 0) stop = true;
   314 				if (strcasecmp(c->name, d->name) <= 0) {
   315 				else if (stop) break;
   315 					stop = true;
       
   316 				} else if (stop) {
       
   317 					break;
       
   318 				}
   316 			}
   319 			}
   317 			if (added) {
   320 			if (added) {
   318 				c->next = d;
   321 				c->next = d;
   319 				*pd = c;
   322 				*pd = c;
   320 			}
   323 			}
   323 		added = false;
   326 		added = false;
   324 	}
   327 	}
   325 
   328 
   326 	if (!added) {
   329 	if (!added) {
   327 		/* File couldn't be opened, or is either not a NewGRF or is a
   330 		/* File couldn't be opened, or is either not a NewGRF or is a
   328 			* 'system' NewGRF or it's already known, so forget about it. */
   331 		 * 'system' NewGRF or it's already known, so forget about it. */
   329 		free(c->filename);
   332 		free(c->filename);
   330 		free(c->name);
   333 		free(c->name);
   331 		free(c->info);
   334 		free(c->info);
   332 		free(c);
   335 		free(c);
   333 	}
   336 	}