Return the retrieved string from strresGetIDString and allocateName and use NULL to indicate failure.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5655 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
e8efe132f8
commit
e3a7f0cab8
|
@ -233,21 +233,19 @@ BOOL strresGetIDNum(STR_RES *psRes, const char *pIDStr, UDWORD *pIDNum)
|
|||
|
||||
|
||||
/* Return the ID stored ID string that matches the string passed in */
|
||||
BOOL strresGetIDString(STR_RES *psRes, const char *pIDStr, char **ppStoredID)
|
||||
char* strresGetIDString(STR_RES *psRes, const char *pIDStr)
|
||||
{
|
||||
STR_ID *psID;
|
||||
|
||||
ASSERT( psRes != NULL, "strresGetIDString: Invalid string res pointer" );
|
||||
ASSERT(psRes != NULL, "Invalid string res pointer");
|
||||
|
||||
psID = treapFind(psRes->psIDTreap, pIDStr);
|
||||
if (!psID)
|
||||
{
|
||||
*ppStoredID = NULL;
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*ppStoredID = psID->pIDStr;
|
||||
return true;
|
||||
return psID->pIDStr;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -35,8 +35,11 @@ extern void strresDestroy(struct STR_RES *psRes);
|
|||
/* Return the ID number for an ID string */
|
||||
extern BOOL strresGetIDNum(struct STR_RES *psRes, const char *pIDStr, UDWORD *pIDNum);
|
||||
|
||||
/* Return the stored ID string that matches the string passed in */
|
||||
extern BOOL strresGetIDString(struct STR_RES *psRes, const char *pIDStr, char **ppStoredID);
|
||||
/**
|
||||
* @return The stored ID string that matches the string passed in, or NULL if
|
||||
* no ID string could be found.
|
||||
*/
|
||||
extern char* strresGetIDString(struct STR_RES *psRes, const char *pIDStr);
|
||||
|
||||
/* Get the string from an ID number */
|
||||
extern char *strresGetString(struct STR_RES *psRes, UDWORD id);
|
||||
|
|
|
@ -158,7 +158,8 @@ BOOL loadFeatureStats(const char *pFeatureData, UDWORD bufferSize)
|
|||
psFeature->baseWidth = (UWORD)Width;
|
||||
psFeature->baseBreadth = (UWORD)Breadth;
|
||||
|
||||
if (!allocateName(&psFeature->pName, featureName))
|
||||
psFeature->pName = allocateName(featureName);
|
||||
if (!psFeature->pName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -903,7 +903,8 @@ static BOOL loadWallFunction(const char *pData)
|
|||
|
||||
//store the structure name - cannot set the stat pointer here because structures
|
||||
//haven't been loaded in yet!
|
||||
if (!allocateName(&psFunction->pStructName, structureName))
|
||||
psFunction->pStructName = allocateName(structureName);
|
||||
if (!psFunction->pStructName)
|
||||
{
|
||||
debug( LOG_ERROR, "Structure Stats Invalid for function - %s", functionName );
|
||||
abort();
|
||||
|
|
|
@ -272,7 +272,8 @@ BOOL loadResearch(const char *pResearchData, UDWORD bufferSize)
|
|||
sscanf(pResearchData,"%[^','],", ResearchName);
|
||||
|
||||
//allocate storage for the name
|
||||
if (!allocateName(&pResearch->pName, ResearchName))
|
||||
pResearch->pName = allocateName(ResearchName);
|
||||
if (!pResearch->pName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
18
src/stats.c
18
src/stats.c
|
@ -210,7 +210,9 @@ void statsDealloc(COMPONENT_STATS* pStats, UDWORD listSize, UDWORD structureSize
|
|||
|
||||
static BOOL allocateStatName(BASE_STATS* pStat, const char *Name)
|
||||
{
|
||||
return (allocateName(&pStat->pName, Name));
|
||||
pStat->pName = allocateName(Name);
|
||||
|
||||
return pStat != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2820,16 +2822,18 @@ bool getWeaponEffect(const char* weaponEffect, WEAPON_EFFECT* effect)
|
|||
looks up the name to get the resource associated with it - or allocates space
|
||||
and stores the name. Eventually ALL names will be 'resourced' for translation
|
||||
*/
|
||||
BOOL allocateName(char **ppStore, const char *pName)
|
||||
char* allocateName(const char* name)
|
||||
{
|
||||
//checks the name has been loaded as a resource and gets the storage pointer
|
||||
if (!strresGetIDString(psStringRes, pName, ppStore))
|
||||
char* const storeName = strresGetIDString(psStringRes, name);
|
||||
|
||||
if (!storeName)
|
||||
{
|
||||
debug( LOG_ERROR, "Unable to find string resource for %s", pName );
|
||||
debug(LOG_ERROR, "Unable to find string resource for %s", name);
|
||||
abort();
|
||||
return false;
|
||||
return NULL;
|
||||
}
|
||||
return true;
|
||||
|
||||
return storeName;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -267,7 +267,7 @@ extern SDWORD getCompFromResName(UDWORD compType, const char *pName);
|
|||
/*returns the weapon sub class based on the string name passed in */
|
||||
extern bool getWeaponSubClass(const char* subClass, WEAPON_SUBCLASS* wclass);
|
||||
/*either gets the name associated with the resource (if one) or allocates space and copies pName*/
|
||||
extern BOOL allocateName(char **ppStore, const char *pName);
|
||||
extern char* allocateName(const char* name);
|
||||
//converts the name read in from Access into the name which is used in the Stat lists (or ignores it)
|
||||
extern BOOL getResourceName(const char *pName);
|
||||
/*return the name to display for the interface - valid for OBJECTS and STATS*/
|
||||
|
|
|
@ -592,7 +592,8 @@ BOOL loadStructureStats(const char *pStructData, UDWORD bufferSize)
|
|||
#endif
|
||||
|
||||
//allocate storage for the name
|
||||
if (!allocateName(&psStructure->pName, StructureName))
|
||||
psStructure->pName = allocateName(StructureName);
|
||||
if (!psStructure->pName)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue