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-861f7616d084
master
Giel van Schijndel 2008-07-24 16:13:03 +00:00
parent e8efe132f8
commit e3a7f0cab8
8 changed files with 29 additions and 20 deletions

View File

@ -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 */ /* 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; STR_ID *psID;
ASSERT( psRes != NULL, "strresGetIDString: Invalid string res pointer" ); ASSERT(psRes != NULL, "Invalid string res pointer");
psID = treapFind(psRes->psIDTreap, pIDStr); psID = treapFind(psRes->psIDTreap, pIDStr);
if (!psID) if (!psID)
{ {
*ppStoredID = NULL; return NULL;
return false;
} }
*ppStoredID = psID->pIDStr; return psID->pIDStr;
return true;
} }

View File

@ -35,8 +35,11 @@ extern void strresDestroy(struct STR_RES *psRes);
/* Return the ID number for an ID string */ /* Return the ID number for an ID string */
extern BOOL strresGetIDNum(struct STR_RES *psRes, const char *pIDStr, UDWORD *pIDNum); 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 */ /* Get the string from an ID number */
extern char *strresGetString(struct STR_RES *psRes, UDWORD id); extern char *strresGetString(struct STR_RES *psRes, UDWORD id);

View File

@ -158,7 +158,8 @@ BOOL loadFeatureStats(const char *pFeatureData, UDWORD bufferSize)
psFeature->baseWidth = (UWORD)Width; psFeature->baseWidth = (UWORD)Width;
psFeature->baseBreadth = (UWORD)Breadth; psFeature->baseBreadth = (UWORD)Breadth;
if (!allocateName(&psFeature->pName, featureName)) psFeature->pName = allocateName(featureName);
if (!psFeature->pName)
{ {
return false; return false;
} }

View File

@ -903,7 +903,8 @@ static BOOL loadWallFunction(const char *pData)
//store the structure name - cannot set the stat pointer here because structures //store the structure name - cannot set the stat pointer here because structures
//haven't been loaded in yet! //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 ); debug( LOG_ERROR, "Structure Stats Invalid for function - %s", functionName );
abort(); abort();

View File

@ -272,7 +272,8 @@ BOOL loadResearch(const char *pResearchData, UDWORD bufferSize)
sscanf(pResearchData,"%[^','],", ResearchName); sscanf(pResearchData,"%[^','],", ResearchName);
//allocate storage for the name //allocate storage for the name
if (!allocateName(&pResearch->pName, ResearchName)) pResearch->pName = allocateName(ResearchName);
if (!pResearch->pName)
{ {
return false; return false;
} }

View File

@ -210,7 +210,9 @@ void statsDealloc(COMPONENT_STATS* pStats, UDWORD listSize, UDWORD structureSize
static BOOL allocateStatName(BASE_STATS* pStat, const char *Name) 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 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 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 char* const storeName = strresGetIDString(psStringRes, name);
if (!strresGetIDString(psStringRes, pName, ppStore))
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(); abort();
return false; return NULL;
} }
return true;
return storeName;
} }

View File

@ -267,7 +267,7 @@ extern SDWORD getCompFromResName(UDWORD compType, const char *pName);
/*returns the weapon sub class based on the string name passed in */ /*returns the weapon sub class based on the string name passed in */
extern bool getWeaponSubClass(const char* subClass, WEAPON_SUBCLASS* wclass); 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*/ /*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) //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); extern BOOL getResourceName(const char *pName);
/*return the name to display for the interface - valid for OBJECTS and STATS*/ /*return the name to display for the interface - valid for OBJECTS and STATS*/

View File

@ -592,7 +592,8 @@ BOOL loadStructureStats(const char *pStructData, UDWORD bufferSize)
#endif #endif
//allocate storage for the name //allocate storage for the name
if (!allocateName(&psStructure->pName, StructureName)) psStructure->pName = allocateName(StructureName);
if (!psStructure->pName)
{ {
return false; return false;
} }