diff options
Diffstat (limited to 'thirdparty/bullet/Bullet3Common/b3FileUtils.h')
-rw-r--r-- | thirdparty/bullet/Bullet3Common/b3FileUtils.h | 85 |
1 files changed, 40 insertions, 45 deletions
diff --git a/thirdparty/bullet/Bullet3Common/b3FileUtils.h b/thirdparty/bullet/Bullet3Common/b3FileUtils.h index b5e8225cf0..9ded17eaaf 100644 --- a/thirdparty/bullet/Bullet3Common/b3FileUtils.h +++ b/thirdparty/bullet/Bullet3Common/b3FileUtils.h @@ -3,7 +3,7 @@ #include <stdio.h> #include "b3Scalar.h" -#include <stddef.h>//ptrdiff_h +#include <stddef.h> //ptrdiff_h #include <string.h> struct b3FileUtils @@ -17,42 +17,42 @@ struct b3FileUtils static bool findFile(const char* orgFileName, char* relativeFileName, int maxRelativeFileNameMaxLen) { - FILE* f=0; - f = fopen(orgFileName,"rb"); - if (f) - { + FILE* f = 0; + f = fopen(orgFileName, "rb"); + if (f) + { //printf("original file found: [%s]\n", orgFileName); - sprintf(relativeFileName,"%s", orgFileName); + sprintf(relativeFileName, "%s", orgFileName); fclose(f); return true; } - //printf("Trying various directories, relative to current working directory\n"); - const char* prefix[]={"./","./data/","../data/","../../data/","../../../data/","../../../../data/"}; - int numPrefixes = sizeof(prefix)/sizeof(const char*); - - f=0; - bool fileFound = false; + //printf("Trying various directories, relative to current working directory\n"); + const char* prefix[] = {"./", "./data/", "../data/", "../../data/", "../../../data/", "../../../../data/"}; + int numPrefixes = sizeof(prefix) / sizeof(const char*); - for (int i=0;!f && i<numPrefixes;i++) - { + f = 0; + bool fileFound = false; + + for (int i = 0; !f && i < numPrefixes; i++) + { #ifdef _MSC_VER - sprintf_s(relativeFileName,maxRelativeFileNameMaxLen,"%s%s",prefix[i],orgFileName); + sprintf_s(relativeFileName, maxRelativeFileNameMaxLen, "%s%s", prefix[i], orgFileName); #else - sprintf(relativeFileName,"%s%s",prefix[i],orgFileName); + sprintf(relativeFileName, "%s%s", prefix[i], orgFileName); #endif - f = fopen(relativeFileName,"rb"); - if (f) - { - fileFound = true; - break; - } - } + f = fopen(relativeFileName, "rb"); if (f) { - fclose(f); + fileFound = true; + break; } - + } + if (f) + { + fclose(f); + } + return fileFound; } @@ -60,8 +60,8 @@ struct b3FileUtils { size_t const patlen = strlen(pattern); size_t patcnt = 0; - const char * oriptr; - const char * patloc; + const char* oriptr; + const char* patloc; // find how many times the pattern occurs in the original string for (oriptr = name; (patloc = strstr(oriptr, pattern)); oriptr = patloc + patlen) { @@ -70,29 +70,27 @@ struct b3FileUtils return oriptr; } - - static int extractPath(const char* fileName, char* path, int maxPathLength) { const char* stripped = strip2(fileName, "/"); stripped = strip2(stripped, "\\"); - ptrdiff_t len = stripped-fileName; - b3Assert((len+1)<maxPathLength); + ptrdiff_t len = stripped - fileName; + b3Assert((len + 1) < maxPathLength); - if (len && ((len+1)<maxPathLength)) + if (len && ((len + 1) < maxPathLength)) { - - for (int i=0;i<len;i++) + for (int i = 0; i < len; i++) { path[i] = fileName[i]; } - path[len]=0; - } else + path[len] = 0; + } + else { len = 0; - b3Assert(maxPathLength>0); - if (maxPathLength>0) + b3Assert(maxPathLength > 0); + if (maxPathLength > 0) { path[len] = 0; } @@ -102,23 +100,21 @@ struct b3FileUtils static char toLowerChar(const char t) { - if (t>=(char)'A' && t<=(char)'Z') + if (t >= (char)'A' && t <= (char)'Z') return t + ((char)'a' - (char)'A'); else return t; } - static void toLower(char* str) { - int len=strlen(str); - for (int i=0;i<len;i++) + int len = strlen(str); + for (int i = 0; i < len; i++) { str[i] = toLowerChar(str[i]); } } - /*static const char* strip2(const char* name, const char* pattern) { size_t const patlen = strlen(pattern); @@ -133,6 +129,5 @@ struct b3FileUtils return oriptr; } */ - }; -#endif //B3_FILE_UTILS_H +#endif //B3_FILE_UTILS_H |