Skip to content

Commit

Permalink
Refactor: All filesys path composition utilities now return AutoStr
Browse files Browse the repository at this point in the history
The one exception being PathDirectory, where the results string is
provided by the caller.
  • Loading branch information
danij-deng committed Aug 25, 2012
1 parent 31af6e4 commit c156dce
Show file tree
Hide file tree
Showing 24 changed files with 84 additions and 111 deletions.
4 changes: 2 additions & 2 deletions doomsday/engine/portable/include/dam_main.h
Expand Up @@ -45,9 +45,9 @@ void DAM_Shutdown(void);
* within the archived map cache where maps from the specified source will reside.
*
* @param sourcePath Path to the primary resource file for the original map data.
* @return The composed path. Must be destroyed with Str_Delete().
* @return The composed path.
*/
ddstring_t* DAM_ComposeCacheDir(const char* sourcePath);
AutoStr* DAM_ComposeCacheDir(const char* sourcePath);

boolean DAM_AttemptMapLoad(const Uri* uri);

Expand Down
5 changes: 2 additions & 3 deletions doomsday/engine/portable/include/fs_main.h
Expand Up @@ -278,9 +278,8 @@ void F_Close(DFile* file);
/// Completely destroy this file; close if open, clear references and any acquired identifiers.
void F_Delete(DFile* file);

/// @return Must be free'd with Str_Delete
ddstring_t* F_ComposeLumpPath2(abstractfile_t* file, int lumpIdx, char delimiter);
ddstring_t* F_ComposeLumpPath(abstractfile_t* file, int lumpIdx); /*delimiter='/'*/
AutoStr* F_ComposeLumpPath2(abstractfile_t* file, int lumpIdx, char delimiter);
AutoStr* F_ComposeLumpPath(abstractfile_t* file, int lumpIdx); /*delimiter='/'*/

struct pathdirectorynode_s* F_LumpDirectoryNode(abstractfile_t* file, int lumpIdx);

Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/portable/include/resourcenamespace.h
Expand Up @@ -102,10 +102,10 @@ void ResourceNamespace_ClearSearchPaths(resourcenamespace_t* rn, resourcenamespa
* Compose the list of search paths into a delimited string.
*
* @param delimiter Discreet paths will be delimited by this character.
* @return Resultant string which should be released with Str_Delete().
* @return Resultant string.
*/
ddstring_t* ResourceNamespace_ComposeSearchPathList2(resourcenamespace_t* rn, char delimiter);
ddstring_t* ResourceNamespace_ComposeSearchPathList(resourcenamespace_t* rn); /*delimiter= ';'*/
AutoStr* ResourceNamespace_ComposeSearchPathList2(resourcenamespace_t* rn, char delimiter);
AutoStr* ResourceNamespace_ComposeSearchPathList(resourcenamespace_t* rn); /*delimiter= ';'*/

int ResourceNamespace_IterateSearchPaths2(resourcenamespace_t* rn,
int (*callback) (const Uri* uri, int flags, void* paramaters), void* paramaters);
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/portable/include/sys_reslocator.h
Expand Up @@ -128,7 +128,7 @@ void F_CreateNamespacesForFileResourcePaths(void);
* @return Newly created hash name. Ownership passes to the caller who should
* ensure to release it with Str_Delete when done.
*/
ddstring_t* F_ComposeHashNameForFilePath(const ddstring_t* filePath);
AutoStr* F_ComposeHashNameForFilePath(const Str* filePath);

/**
* This is a hash function. It uses the resource name to generate a
Expand All @@ -141,8 +141,8 @@ resourcenamespace_namehash_key_t F_HashKeyForAlphaNumericNameIgnoreCase(const dd
#define F_HashKeyForFilePathHashName F_HashKeyForAlphaNumericNameIgnoreCase

resourcenamespace_t* F_CreateResourceNamespace(const char* name,
FileDirectory* directory, ddstring_t* (*composeHashNameFunc) (const ddstring_t* path),
resourcenamespace_namehash_key_t (*hashNameFunc) (const ddstring_t* name), byte flags);
FileDirectory* directory, AutoStr* (*composeHashNameFunc) (const Str* path),
resourcenamespace_namehash_key_t (*hashNameFunc) (const Str* name), byte flags);

/**
* @param rni Unique identifier of the namespace to add to.
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/include/wadfile.h
Expand Up @@ -46,7 +46,7 @@ int WadFile_PublishLumpsToDirectory(WadFile* wad, struct lumpdirectory_s* direct

struct pathdirectorynode_s* WadFile_LumpDirectoryNode(WadFile* wad, int lumpIdx);

ddstring_t* WadFile_ComposeLumpPath(WadFile* wad, int lumpIdx, char delimiter);
AutoStr* WadFile_ComposeLumpPath(WadFile* wad, int lumpIdx, char delimiter);

const LumpInfo* WadFile_LumpInfo(WadFile* wad, int lumpIdx);

Expand Down
5 changes: 2 additions & 3 deletions doomsday/engine/portable/include/zipfile.h
Expand Up @@ -93,10 +93,9 @@ const LumpInfo* ZipFile_LumpInfo(ZipFile* zip, int lumpIdx);
* @param zip ZipFile instance.
* @param lumpIdx Logical index for the lump.
* @param delimiter Delimit directory separators using this character (default: '/').
* @return String containing the full path. Has to be destroyed with Str_Delete()
* once it is no longer needed.
* @return String containing the full path.
*/
ddstring_t* ZipFile_ComposeLumpPath(ZipFile* zip, int lumpIdx, char delimiter);
AutoStr* ZipFile_ComposeLumpPath(ZipFile* zip, int lumpIdx, char delimiter);

/**
* Read the data associated with the specified lump index into @a buffer.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/audiodriver.c
Expand Up @@ -128,10 +128,10 @@ static boolean loadAudioDriver(driver_t* driver, const char* name)

if(name && name[0])
{
ddstring_t libPath;
Str libPath;

// Compose the name using the prefix "ds".
Str_Init(&libPath);
Str_InitStd(&libPath);
#ifdef WIN32
Str_Appendf(&libPath, "%sds%s.dll", ddBinPath, name);
#elif defined(MACOSX)
Expand Down
19 changes: 9 additions & 10 deletions doomsday/engine/portable/src/dam_main.c
Expand Up @@ -164,22 +164,22 @@ static ushort calculateIdentifierForMapPath(const char* path)
return 0; // Unreachable.
}

ddstring_t* DAM_ComposeCacheDir(const char* sourcePath)
AutoStr* DAM_ComposeCacheDir(const char* sourcePath)
{
const ddstring_t* gameIdentityKey;
const Str* gameIdentityKey;
ushort mapPathIdentifier;
ddstring_t mapFileName;
ddstring_t* path;
Str mapFileName;
AutoStr* path;

if(!sourcePath || !sourcePath[0]) return NULL;

gameIdentityKey = Game_IdentityKey(theGame);
mapPathIdentifier = calculateIdentifierForMapPath(sourcePath);
Str_Init(&mapFileName);
Str_InitStd(&mapFileName);
F_FileName(&mapFileName, sourcePath);

// Compose the final path.
path = Str_New();
path = AutoStr_NewStd();
Str_Appendf(path, "%s%s/%s-%04X/", mapCacheDir, Str_Text(gameIdentityKey),
Str_Text(&mapFileName), mapPathIdentifier);
F_ExpandBasePath(path, path);
Expand Down Expand Up @@ -249,8 +249,8 @@ boolean DAM_AttemptMapLoad(const Uri* uri)
// We've not yet attempted to load this map.
const char* mapId = Str_Text(Uri_Path(uri));
lumpnum_t markerLump;
ddstring_t* cachedMapDir;
ddstring_t cachedMapPath;
AutoStr* cachedMapDir;
Str cachedMapPath;

markerLump = F_CheckLumpNumForName2(mapId, true /*quiet please*/);
if(0 > markerLump) return false;
Expand All @@ -260,7 +260,7 @@ boolean DAM_AttemptMapLoad(const Uri* uri)
F_MakePath(Str_Text(cachedMapDir));

// Compose the full path to the cached map data file.
Str_Init(&cachedMapPath);
Str_InitStd(&cachedMapPath);
F_FileName(&cachedMapPath, F_LumpName(markerLump));
Str_Append(&cachedMapPath, ".dcm");
Str_Prepend(&cachedMapPath, Str_Text(cachedMapDir));
Expand All @@ -269,7 +269,6 @@ boolean DAM_AttemptMapLoad(const Uri* uri)
dam = createArchivedMap(uri, &cachedMapPath);
addArchivedMap(dam);

Str_Delete(cachedMapDir);
Str_Free(&cachedMapPath);
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/dd_input.c
Expand Up @@ -1598,7 +1598,7 @@ void Rend_RenderKeyStateVisual(inputdev_t* device, uint keyID, const Point2Raw*
origin.x = _origin? _origin->x : 0;
origin.y = _origin? _origin->y : 0;

Str_Init(&label);
Str_InitStd(&label);

// Compose the key label.
if(key->name)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/def_read.c
Expand Up @@ -2660,14 +2660,14 @@ static int DED_ReadData(ded_t* ded, const char* buffer, const char* _sourceFile)

int DED_Read(ded_t* ded, const char* path)
{
ddstring_t transPath;
Str transPath;
size_t bufferedDefSize;
char* bufferedDef;
DFile* file;
int result;

// Compose the (possibly-translated) path.
Str_Init(&transPath);
Str_InitStd(&transPath);
Str_Set(&transPath, path);
F_FixSlashes(&transPath, &transPath);
F_ExpandBasePath(&transPath, &transPath);
Expand Down
3 changes: 1 addition & 2 deletions doomsday/engine/portable/src/dfile.c
Expand Up @@ -121,11 +121,10 @@ DFile* DFileBuilder_NewFromAbstractFileLump(abstractfile_t* container, int lumpI
(unsigned long) file->_size);
#if _DEBUG
VERBOSE2(
ddstring_t* path = F_ComposeLumpPath(container, lumpIdx);
AutoStr* path = F_ComposeLumpPath(container, lumpIdx);
Con_Printf("DFile [%p] buffering \"%s:%s\"...\n", (void*)file,
F_PrettyPath(Str_Text(AbstractFile_Path(container))),
F_PrettyPath(Str_Text(path)));
Str_Delete(path);
)
#endif
F_ReadLumpSection(container, lumpIdx, (uint8_t*)file->_data, 0, info->size);
Expand Down
7 changes: 3 additions & 4 deletions doomsday/engine/portable/src/edit_map.c
Expand Up @@ -1917,10 +1917,10 @@ boolean MPE_End(void)
{
// Yes, write the cached map data file.
lumpnum_t markerLumpNum = F_CheckLumpNumForName2(Str_Text(Uri_Path(gamemap->uri)), true);
ddstring_t* cachedMapDir = DAM_ComposeCacheDir(F_LumpSourceFile(markerLumpNum));
ddstring_t cachedMapPath;
AutoStr* cachedMapDir = DAM_ComposeCacheDir(F_LumpSourceFile(markerLumpNum));
Str cachedMapPath;

Str_Init(&cachedMapPath);
Str_InitStd(&cachedMapPath);
F_FileName(&cachedMapPath, F_LumpName(markerLumpNum));
Str_Append(&cachedMapPath, ".dcm");
Str_Prepend(&cachedMapPath, Str_Text(cachedMapDir));
Expand All @@ -1932,7 +1932,6 @@ boolean MPE_End(void)
// Archive this map!
DAM_MapWrite(gamemap, Str_Text(&cachedMapPath));

Str_Delete(cachedMapDir);
Str_Free(&cachedMapPath);
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/filedirectory.cpp
Expand Up @@ -220,7 +220,7 @@ int de::FileDirectory::addChildNodes(de::PathDirectoryNode* node, int flags,
ddstring_t searchPattern;

// Compose the search pattern.
Str_Init(&searchPattern);
Str_InitStd(&searchPattern);
node->composePath(&searchPattern, NULL, '/');
// We're interested in *everything*.
Str_AppendChar(&searchPattern, '*');
Expand Down
10 changes: 4 additions & 6 deletions doomsday/engine/portable/src/fs_main.c
Expand Up @@ -1005,7 +1005,7 @@ PathDirectoryNode* F_LumpDirectoryNode(abstractfile_t* fsObject, int lumpIdx)
}
}

ddstring_t* F_ComposeLumpPath2(abstractfile_t* fsObject, int lumpIdx, char delimiter)
AutoStr* F_ComposeLumpPath2(abstractfile_t* fsObject, int lumpIdx, char delimiter)
{
assert(fsObject);
switch(AbstractFile_Type(fsObject))
Expand All @@ -1020,7 +1020,7 @@ ddstring_t* F_ComposeLumpPath2(abstractfile_t* fsObject, int lumpIdx, char delim
}
}

ddstring_t* F_ComposeLumpPath(abstractfile_t* fsObject, int lumpIdx)
AutoStr* F_ComposeLumpPath(abstractfile_t* fsObject, int lumpIdx)
{
return F_ComposeLumpPath2(fsObject, lumpIdx, '/');
}
Expand Down Expand Up @@ -1346,7 +1346,7 @@ static int findLumpWorker(const LumpInfo* lumpInfo, void* paramaters)
{
findlumpworker_paramaters_t* p = (findlumpworker_paramaters_t*)paramaters;
PathDirectoryNode* node = F_LumpDirectoryNode(lumpInfo->container, lumpInfo->lumpIdx);
ddstring_t* filePath = NULL;
AutoStr* filePath = NULL;
boolean patternMatched;
int result = 0; // Continue iteration.
assert(lumpInfo && p);
Expand All @@ -1372,7 +1372,6 @@ static int findLumpWorker(const LumpInfo* lumpInfo, void* paramaters)
result = p->callback(filePath, PT_LEAF, p->paramaters);
}

if(filePath) Str_Delete(filePath);
return result;
}

Expand Down Expand Up @@ -1946,12 +1945,11 @@ DFile* F_OpenLump(lumpnum_t absoluteLumpNum)
abstractfile_t* container = F_FindFileForLumpNum2(absoluteLumpNum, &lumpIdx);
if(container)
{
ddstring_t* path = F_ComposeLumpPath(container, lumpIdx);
AutoStr* path = F_ComposeLumpPath(container, lumpIdx);
abstractfile_t* fsObject = newLumpFile(
DFileBuilder_NewFromAbstractFileLump(container, lumpIdx, false),
Str_Text(path), F_LumpInfo(container, lumpIdx));

Str_Delete(path);
if(fsObject)
{
return FileList_AddBack(openFiles, DFileBuilder_NewFromAbstractFile(fsObject));
Expand Down
16 changes: 6 additions & 10 deletions doomsday/engine/portable/src/lumpdirectory.c
Expand Up @@ -381,7 +381,7 @@ lumpnum_t LumpDirectory_IndexForPath(LumpDirectory* ld, const char* path)

typedef struct {
lumpdirectory_lumprecord_t* record;
ddstring_t* path;
AutoStr* path;
int origIndex;
} lumpsortinfo_t;

Expand Down Expand Up @@ -437,9 +437,6 @@ static void LumpDirectory_Prune(LumpDirectory* ld)
}

// Free temporary storage.
sortInfo = sortInfoSet;
for(i = 0; i < ld->numRecords; ++i, sortInfo++)
Str_Delete(sortInfo->path);
free(sortInfoSet);

// Peform the prune. Do this one lump at a time, respecting the possibly-sorted order.
Expand Down Expand Up @@ -473,13 +470,12 @@ void LumpDirectory_Print(LumpDirectory* ld)
for(i = 0; i < ld->numRecords; ++i)
{
const LumpInfo* lumpInfo = ld->records[i].lumpInfo;
ddstring_t* path = F_ComposeLumpPath(lumpInfo->container, lumpInfo->lumpIdx);
AutoStr* path = F_ComposeLumpPath(lumpInfo->container, lumpInfo->lumpIdx);
Con_Printf("%04i - \"%s:%s\" (size: %lu bytes%s)\n", i,
F_PrettyPath(Str_Text(AbstractFile_Path(lumpInfo->container))),
F_PrettyPath(Str_Text(path)),
(unsigned long) lumpInfo->size,
(lumpInfo->compressedSize != lumpInfo->size? " compressed" : ""));
Str_Delete(path);
F_PrettyPath(Str_Text(AbstractFile_Path(lumpInfo->container))),
F_PrettyPath(Str_Text(path)),
(unsigned long) lumpInfo->size,
(lumpInfo->compressedSize != lumpInfo->size? " compressed" : ""));
}
Con_Printf("---End of lumps---\n");
}
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/m_misc.c
Expand Up @@ -999,7 +999,7 @@ int M_ScreenShot(const char* name, int bits)

/*
byte* screen = (byte*) GL_GrabScreen();
ddstring_t fullName;
Str fullName;
FILE* file;
if(!screen)
Expand All @@ -1009,7 +1009,7 @@ int M_ScreenShot(const char* name, int bits)
}
// Compose the final file name.
Str_Init(&fullName); Str_Set(&fullName, name);
Str_InitStd(&fullName); Str_Set(&fullName, name);
if(!F_FindFileExtension(Str_Text(&fullName)))
Str_Append(&fullName, ".tga");
F_ToNativeSlashes(&fullName, &fullName);
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/net_demo.c
Expand Up @@ -136,7 +136,7 @@ boolean Demo_BeginRecording(const char* fileName, int plrNum)
return false;

// Compose the real file name.
Str_Init(&buf);
Str_InitStd(&buf);
Str_Appendf(&buf, "%s%s", demoPath, fileName);
F_ExpandBasePath(&buf, &buf);
F_ToNativeSlashes(&buf, &buf);
Expand Down Expand Up @@ -325,7 +325,7 @@ boolean Demo_BeginPlayback(const char* fileName)
}}

// Compose the real file name.
Str_Init(&buf);
Str_InitStd(&buf);
Str_Set(&buf, fileName);
if(!F_IsAbsolute(&buf))
{
Expand Down
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/p_control.c
Expand Up @@ -287,7 +287,7 @@ void P_MaintainControlDoubleClicks(int playerNum, int control, float pos)
nowTime - db->previousClickTime < (uint) MAX_OF(0, doubleClickThresholdMilliseconds))
{
ddevent_t event;
ddstring_t* symbolicName = Str_New();
Str* symbolicName = Str_NewStd();

db->triggered = true;

Expand Down

0 comments on commit c156dce

Please sign in to comment.