fileio.c
changeset 4200 a45420ba0c23
parent 4077 d3022f976946
child 4201 3004bdee457d
equal deleted inserted replaced
4199:61cb1593cbf9 4200:a45420ba0c23
     2 
     2 
     3 #include "stdafx.h"
     3 #include "stdafx.h"
     4 #include "openttd.h"
     4 #include "openttd.h"
     5 #include "fileio.h"
     5 #include "fileio.h"
     6 #include "functions.h"
     6 #include "functions.h"
       
     7 #include "string.h"
     7 #include "macros.h"
     8 #include "macros.h"
     8 #include "variables.h"
     9 #include "variables.h"
     9 #if defined(UNIX) || defined(__OS2__)
       
    10 #include <ctype.h> // required for tolower()
       
    11 #endif
       
    12 
    10 
    13 /*************************************************/
    11 /*************************************************/
    14 /* FILE IO ROUTINES ******************************/
    12 /* FILE IO ROUTINES ******************************/
    15 /*************************************************/
    13 /*************************************************/
    16 
    14 
   112 
   110 
   113 	sprintf(buf, "%s%s", _path.data_dir, filename);
   111 	sprintf(buf, "%s%s", _path.data_dir, filename);
   114 
   112 
   115 	f = fopen(buf, "rb");
   113 	f = fopen(buf, "rb");
   116 #if !defined(WIN32)
   114 #if !defined(WIN32)
   117 	if (f == NULL) {
   115 	if (f == NULL) { // Make lower case and try again
   118 		char *s;
   116 		strtolower(buf + strlen(_path.data_dir) - 1);
   119 		// Make lower case and try again
       
   120 		for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++)
       
   121 			*s = tolower(*s);
       
   122 		f = fopen(buf, "rb");
   117 		f = fopen(buf, "rb");
   123 
   118 
   124 #if defined SECOND_DATA_DIR
   119 #if defined SECOND_DATA_DIR
   125 	// tries in the 2nd data directory
   120 		// tries in the 2nd data directory
   126 		if (f == NULL) {
   121 		if (f == NULL) {
   127 			sprintf(buf, "%s%s", _path.second_data_dir, filename);
   122 			sprintf(buf, "%s%s", _path.second_data_dir, filename);
   128 			for (s = buf + strlen(_path.second_data_dir) - 1; *s != 0; s++)
   123 			strtolower(buf + strlen(_path.second_data_dir) - 1);
   129 			*s = tolower(*s);
   124 			f = fopen(buf, "rb");
   130 		f = fopen(buf, "rb");
       
   131 		}
   125 		}
   132 #endif
   126 #endif
   133 	}
   127 	}
   134 #endif
   128 #endif
   135 
   129 
   149 	sprintf(buf, "%s%s", _path.data_dir, filename);
   143 	sprintf(buf, "%s%s", _path.data_dir, filename);
   150 
   144 
   151 	f = fopen(buf, "rb");
   145 	f = fopen(buf, "rb");
   152 #if !defined(WIN32)
   146 #if !defined(WIN32)
   153 	if (f == NULL) {
   147 	if (f == NULL) {
   154 		char *s;
   148 		strtolower(buf + strlen(_path.data_dir) - 1);
   155 		// Make lower case and try again
       
   156 		for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++)
       
   157 			*s = tolower(*s);
       
   158 		f = fopen(buf, "rb");
   149 		f = fopen(buf, "rb");
   159 
   150 
   160 #if defined SECOND_DATA_DIR
   151 #if defined SECOND_DATA_DIR
   161 		// tries in the 2nd data directory
   152 		// tries in the 2nd data directory
   162 		if (f == NULL) {
   153 		if (f == NULL) {
   163 			sprintf(buf, "%s%s", _path.second_data_dir, filename);
   154 			sprintf(buf, "%s%s", _path.second_data_dir, filename);
   164 			for (s = buf + strlen(_path.second_data_dir) - 1; *s != 0; s++)
   155 			strtolower(buf + strlen(_path.second_data_dir) - 1);
   165 				*s = tolower(*s);
       
   166 			f = fopen(buf, "rb");
   156 			f = fopen(buf, "rb");
   167 		}
   157 		}
   168 #endif
   158 #endif
   169 	}
   159 	}
   170 #endif
   160 #endif
   180 	sprintf(buf, "%s%s", _path.data_dir, filename);
   170 	sprintf(buf, "%s%s", _path.data_dir, filename);
   181 
   171 
   182 	f = fopen(buf, "rb");
   172 	f = fopen(buf, "rb");
   183 #if !defined(WIN32)
   173 #if !defined(WIN32)
   184 	if (f == NULL) {
   174 	if (f == NULL) {
   185 		char *s;
   175 		strtolower(buf + strlen(_path.data_dir) - 1);
   186 		// Make lower case and try again
       
   187 		for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++)
       
   188 			*s = tolower(*s);
       
   189 		f = fopen(buf, "rb");
   176 		f = fopen(buf, "rb");
   190 
   177 
   191 #if defined SECOND_DATA_DIR
   178 #if defined SECOND_DATA_DIR
   192 	// tries in the 2nd data directory
   179 	// tries in the 2nd data directory
   193 		if (f == NULL) {
   180 		if (f == NULL) {
   194 			sprintf(buf, "%s%s", _path.second_data_dir, filename);
   181 			sprintf(buf, "%s%s", _path.second_data_dir, filename);
   195 			for (s = buf + strlen(_path.second_data_dir) - 1; *s != 0; s++)
   182 			strtolower(buf + strlen(_path.second_data_dir) - 1);
   196 			*s = tolower(*s);
   183 			f = fopen(buf, "rb");
   197 		f = fopen(buf, "rb");
       
   198 		}
   184 		}
   199 
   185 
   200 	if (f == NULL)
   186 	if (f == NULL)
   201 		sprintf(buf, "%s%s", _path.data_dir, filename);	//makes it print the primary datadir path instead of the secundary one
   187 		sprintf(buf, "%s%s", _path.data_dir, filename);	//makes it print the primary datadir path instead of the secundary one
   202 
   188