1
0
Fork 0

(svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used.

release/0.5
Darkvater 2006-07-31 22:11:34 +00:00
parent 17dc898805
commit cef563141a
4 changed files with 24 additions and 29 deletions

View File

@ -4,11 +4,9 @@
#include "openttd.h" #include "openttd.h"
#include "fileio.h" #include "fileio.h"
#include "functions.h" #include "functions.h"
#include "string.h"
#include "macros.h" #include "macros.h"
#include "variables.h" #include "variables.h"
#if defined(UNIX) || defined(__OS2__)
#include <ctype.h> // required for tolower()
#endif
/*************************************************/ /*************************************************/
/* FILE IO ROUTINES ******************************/ /* FILE IO ROUTINES ******************************/
@ -114,20 +112,16 @@ bool FiosCheckFileExists(const char *filename)
f = fopen(buf, "rb"); f = fopen(buf, "rb");
#if !defined(WIN32) #if !defined(WIN32)
if (f == NULL) { if (f == NULL) { // Make lower case and try again
char *s; strtolower(buf + strlen(_path.data_dir) - 1);
// Make lower case and try again
for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++)
*s = tolower(*s);
f = fopen(buf, "rb"); f = fopen(buf, "rb");
#if defined SECOND_DATA_DIR #if defined SECOND_DATA_DIR
// tries in the 2nd data directory // tries in the 2nd data directory
if (f == NULL) { if (f == NULL) {
sprintf(buf, "%s%s", _path.second_data_dir, filename); sprintf(buf, "%s%s", _path.second_data_dir, filename);
for (s = buf + strlen(_path.second_data_dir) - 1; *s != 0; s++) strtolower(buf + strlen(_path.second_data_dir) - 1);
*s = tolower(*s); f = fopen(buf, "rb");
f = fopen(buf, "rb");
} }
#endif #endif
} }
@ -151,18 +145,14 @@ FILE *FioFOpenFile(const char *filename)
f = fopen(buf, "rb"); f = fopen(buf, "rb");
#if !defined(WIN32) #if !defined(WIN32)
if (f == NULL) { if (f == NULL) {
char *s; strtolower(buf + strlen(_path.data_dir) - 1);
// Make lower case and try again
for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++)
*s = tolower(*s);
f = fopen(buf, "rb"); f = fopen(buf, "rb");
#if defined SECOND_DATA_DIR #if defined SECOND_DATA_DIR
// tries in the 2nd data directory // tries in the 2nd data directory
if (f == NULL) { if (f == NULL) {
sprintf(buf, "%s%s", _path.second_data_dir, filename); sprintf(buf, "%s%s", _path.second_data_dir, filename);
for (s = buf + strlen(_path.second_data_dir) - 1; *s != 0; s++) strtolower(buf + strlen(_path.second_data_dir) - 1);
*s = tolower(*s);
f = fopen(buf, "rb"); f = fopen(buf, "rb");
} }
#endif #endif
@ -182,19 +172,15 @@ void FioOpenFile(int slot, const char *filename)
f = fopen(buf, "rb"); f = fopen(buf, "rb");
#if !defined(WIN32) #if !defined(WIN32)
if (f == NULL) { if (f == NULL) {
char *s; strtolower(buf + strlen(_path.data_dir) - 1);
// Make lower case and try again
for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++)
*s = tolower(*s);
f = fopen(buf, "rb"); f = fopen(buf, "rb");
#if defined SECOND_DATA_DIR #if defined SECOND_DATA_DIR
// tries in the 2nd data directory // tries in the 2nd data directory
if (f == NULL) { if (f == NULL) {
sprintf(buf, "%s%s", _path.second_data_dir, filename); sprintf(buf, "%s%s", _path.second_data_dir, filename);
for (s = buf + strlen(_path.second_data_dir) - 1; *s != 0; s++) strtolower(buf + strlen(_path.second_data_dir) - 1);
*s = tolower(*s); f = fopen(buf, "rb");
f = fopen(buf, "rb");
} }
if (f == NULL) if (f == NULL)

View File

@ -9,6 +9,7 @@
#include "spritecache.h" #include "spritecache.h"
#include "table/sprites.h" #include "table/sprites.h"
#include "fileio.h" #include "fileio.h"
#include "string.h"
#include "newgrf.h" #include "newgrf.h"
#include "md5.h" #include "md5.h"
#include "variables.h" #include "variables.h"
@ -123,10 +124,7 @@ static bool FileMD5(const MD5File file, bool warn)
#if !defined(WIN32) #if !defined(WIN32)
if (f == NULL) { if (f == NULL) {
char *s; strtolower(buf + strlen(_path.data_dir) - 1);
// make lower case and check again
for (s = buf + strlen(_path.data_dir) - 1; *s != '\0'; s++)
*s = tolower(*s);
f = fopen(buf, "rb"); f = fopen(buf, "rb");
} }
#endif #endif

View File

@ -4,6 +4,9 @@
#include "string.h" #include "string.h"
#include <stdarg.h> #include <stdarg.h>
#if defined(UNIX) || defined(__OS2__)
#include <ctype.h> // required for tolower()
#endif
void ttd_strlcat(char *dst, const char *src, size_t size) void ttd_strlcat(char *dst, const char *src, size_t size)
{ {
@ -63,3 +66,8 @@ void str_validate(char *str)
for (; *str != '\0'; str++) for (; *str != '\0'; str++)
if (!IsValidAsciiChar(*str)) *str = '?'; if (!IsValidAsciiChar(*str)) *str = '?';
} }
void strtolower(char *str)
{
for (; *str != '\0'; str++) *str = tolower(*str);
}

View File

@ -29,6 +29,9 @@ char* CDECL str_fmt(const char* str, ...);
* replaces them with a question mark '?' */ * replaces them with a question mark '?' */
void str_validate(char *str); void str_validate(char *str);
/** Convert the given string to lowercase */
void strtolower(char *str);
/** Only allow valid ascii-function codes. Filter special codes like BELL and /** Only allow valid ascii-function codes. Filter special codes like BELL and
* so on [we need a special filter here later] * so on [we need a special filter here later]
* @param key character to be checked * @param key character to be checked