simplify some strlen and strncmp usage

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@8051 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: a831fc21fde203dea27d140eae7d83b8d3825680
Former-commit-id: c5875f37189d1c96b330a4900823fd0128dd3bd1
This commit is contained in:
iobyte 2022-02-26 17:12:14 +00:00
parent ec2a02ae29
commit 7cbc8fadaf
6 changed files with 15 additions and 17 deletions

View file

@ -42,7 +42,7 @@
#define dlerror GetLastError
#endif
static const size_t SOFileExtLen = strlen(DLLEXT);
static const size_t SOFileExtLen = DLLEXTLEN;
/* Allocate the module interfaces info array */
tModInfo *GfModInfoAllocate(int maxItf)

View file

@ -24,6 +24,7 @@
// Common file name extensions
#define TRKEXT "xml"
#define PARAMEXT ".xml"
#define PARAMEXTLEN 4
#define RESULTEXT ".xml"
// Windows -----------------------------------------------------------------
@ -35,12 +36,14 @@
// File name extensions
#define DLLEXT ".dll"
#define DLLEXTLEN 4
// Linux -------------------------------------------------------------------
#else // WIN32
// File name extensions
#define DLLEXT ".so"
#define DLLEXTLEN 3
#endif // WIN32

View file

@ -31,7 +31,7 @@
#include "tgf.h"
#include "os.h"
static const size_t SOFileExtLen = strlen(DLLEXT);
static const size_t SOFileExtLen = DLLEXTLEN;
/*
* Function

View file

@ -112,30 +112,25 @@ void GfDrivers::reload()
// Determine the module name.
std::string strModName(pCurModule->sopath);
strModName.erase(strlen(pCurModule->sopath) - strlen(DLLEXT)); // Truncate file ext.
strModName.erase(strModName.size() - DLLEXTLEN); // Truncate file ext.
const size_t nLastSlashInd = strModName.rfind('/');
if (nLastSlashInd != std::string::npos)
strModName = strModName.substr(nLastSlashInd+1); // Remove heading folder path.
// Load the module XML descriptor file (try user settings first, and then installed one)
std::ostringstream ossRobotFileName;
ossRobotFileName << "drivers/" << strModName
<< '/' << strModName << PARAMEXT;
void *hparmRobot =
GfParmReadFileLocal(ossRobotFileName.str(), GFPARM_RMODE_STD | GFPARM_RMODE_REREAD);
std::string strRobotFileName = "drivers/" + strModName + '/' + strModName + PARAMEXT;
void *hparmRobot = GfParmReadFileLocal(strRobotFileName, GFPARM_RMODE_STD | GFPARM_RMODE_REREAD);
if (!hparmRobot)
{
hparmRobot =
GfParmReadFile(ossRobotFileName.str(), GFPARM_RMODE_STD | GFPARM_RMODE_REREAD);
}
hparmRobot = GfParmReadFile(strRobotFileName, GFPARM_RMODE_STD | GFPARM_RMODE_REREAD);
if (!hparmRobot)
{
// Do not waste log with drivers that do not exists or do not have to exist!
if (strncmp("dandroid",strModName.c_str(),8) == 0)
if (strModName.compare(0, 8, "dandroid") == 0)
continue;
else if (strncmp("usr",strModName.c_str(),3) == 0)
else if (strModName.compare(0, 3, "usr") == 0)
continue;
else if (strncmp("replay",strModName.c_str(),6) == 0)
else if (strModName.compare(0, 6, "replay") == 0)
continue;
GfLogError("No usable '%s' driver (%s.xml not found or not readable)\n",

View file

@ -111,7 +111,7 @@ GfRaceManagers::GfRaceManagers()
}
std::string strRaceManId(pFile->name);
strRaceManId.erase(strlen(pFile->name) - strlen(PARAMEXT));
strRaceManId.erase(strlen(pFile->name) - PARAMEXTLEN);
if (!hparmRaceMan)
{
GfLogInfo("GfRaceManagers : Ignoring race manager %s (failed to read from config/raceman/%s in %s and %s)\n",

View file

@ -100,7 +100,7 @@ rmSaveRaceToConfigFile(const char *filename)
// Determine the full path-name of the target race config file (add .xml ext. if not there).
std::ostringstream ossTgtFileName;
ossTgtFileName << GfLocalDir() << "config/raceman/" << pRaceMan->getId() << '/' << filename;
if (ossTgtFileName.str().rfind(PARAMEXT) != ossTgtFileName.str().length() - strlen(PARAMEXT))
if (ossTgtFileName.str().rfind(PARAMEXT) != ossTgtFileName.str().length() - PARAMEXTLEN)
ossTgtFileName << PARAMEXT;
// Copy the main file to the selected one (overwrite if already there).