From cef563141a3f1bfe8d8f2bf5211598df57e4ec0f Mon Sep 17 00:00:00 2001 From: Darkvater Date: Mon, 31 Jul 2006 22:11:34 +0000 Subject: (svn r5684) - Codechange: create an strtolower() function that uses tolower() on a whole string and apply it in the places this was used. --- fileio.c | 36 +++++++++++------------------------- gfxinit.c | 6 ++---- string.c | 8 ++++++++ string.h | 3 +++ 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/fileio.c b/fileio.c index 338c7f50a..4d2e800cc 100644 --- a/fileio.c +++ b/fileio.c @@ -4,11 +4,9 @@ #include "openttd.h" #include "fileio.h" #include "functions.h" +#include "string.h" #include "macros.h" #include "variables.h" -#if defined(UNIX) || defined(__OS2__) -#include // required for tolower() -#endif /*************************************************/ /* FILE IO ROUTINES ******************************/ @@ -114,20 +112,16 @@ bool FiosCheckFileExists(const char *filename) f = fopen(buf, "rb"); #if !defined(WIN32) - if (f == NULL) { - char *s; - // Make lower case and try again - for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++) - *s = tolower(*s); + if (f == NULL) { // Make lower case and try again + strtolower(buf + strlen(_path.data_dir) - 1); f = fopen(buf, "rb"); #if defined SECOND_DATA_DIR - // tries in the 2nd data directory + // tries in the 2nd data directory if (f == NULL) { sprintf(buf, "%s%s", _path.second_data_dir, filename); - for (s = buf + strlen(_path.second_data_dir) - 1; *s != 0; s++) - *s = tolower(*s); - f = fopen(buf, "rb"); + strtolower(buf + strlen(_path.second_data_dir) - 1); + f = fopen(buf, "rb"); } #endif } @@ -151,18 +145,14 @@ FILE *FioFOpenFile(const char *filename) f = fopen(buf, "rb"); #if !defined(WIN32) if (f == NULL) { - char *s; - // Make lower case and try again - for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++) - *s = tolower(*s); + strtolower(buf + strlen(_path.data_dir) - 1); f = fopen(buf, "rb"); #if defined SECOND_DATA_DIR // tries in the 2nd data directory if (f == NULL) { sprintf(buf, "%s%s", _path.second_data_dir, filename); - for (s = buf + strlen(_path.second_data_dir) - 1; *s != 0; s++) - *s = tolower(*s); + strtolower(buf + strlen(_path.second_data_dir) - 1); f = fopen(buf, "rb"); } #endif @@ -182,19 +172,15 @@ void FioOpenFile(int slot, const char *filename) f = fopen(buf, "rb"); #if !defined(WIN32) if (f == NULL) { - char *s; - // Make lower case and try again - for (s = buf + strlen(_path.data_dir) - 1; *s != 0; s++) - *s = tolower(*s); + strtolower(buf + strlen(_path.data_dir) - 1); f = fopen(buf, "rb"); #if defined SECOND_DATA_DIR // tries in the 2nd data directory if (f == NULL) { sprintf(buf, "%s%s", _path.second_data_dir, filename); - for (s = buf + strlen(_path.second_data_dir) - 1; *s != 0; s++) - *s = tolower(*s); - f = fopen(buf, "rb"); + strtolower(buf + strlen(_path.second_data_dir) - 1); + f = fopen(buf, "rb"); } if (f == NULL) diff --git a/gfxinit.c b/gfxinit.c index 522687627..fbc0e1e9c 100644 --- a/gfxinit.c +++ b/gfxinit.c @@ -9,6 +9,7 @@ #include "spritecache.h" #include "table/sprites.h" #include "fileio.h" +#include "string.h" #include "newgrf.h" #include "md5.h" #include "variables.h" @@ -123,10 +124,7 @@ static bool FileMD5(const MD5File file, bool warn) #if !defined(WIN32) if (f == NULL) { - char *s; - // make lower case and check again - for (s = buf + strlen(_path.data_dir) - 1; *s != '\0'; s++) - *s = tolower(*s); + strtolower(buf + strlen(_path.data_dir) - 1); f = fopen(buf, "rb"); } #endif diff --git a/string.c b/string.c index 18428527d..c4d3e8371 100644 --- a/string.c +++ b/string.c @@ -4,6 +4,9 @@ #include "string.h" #include +#if defined(UNIX) || defined(__OS2__) +#include // required for tolower() +#endif void ttd_strlcat(char *dst, const char *src, size_t size) { @@ -63,3 +66,8 @@ void str_validate(char *str) for (; *str != '\0'; str++) if (!IsValidAsciiChar(*str)) *str = '?'; } + +void strtolower(char *str) +{ + for (; *str != '\0'; str++) *str = tolower(*str); +} diff --git a/string.h b/string.h index cbe3881db..39be2309b 100644 --- a/string.h +++ b/string.h @@ -29,6 +29,9 @@ char* CDECL str_fmt(const char* str, ...); * replaces them with a question mark '?' */ 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 * so on [we need a special filter here later] * @param key character to be checked -- cgit v1.2.3-70-g09d2