From 12bed465eb9dbd92469875fb74cb1d8966b47171 Mon Sep 17 00:00:00 2001 From: danij Date: Fri, 21 Oct 2011 06:10:21 +0100 Subject: [PATCH] Refactor ResourceRecord_SearchPathsAsStringList output to remove terminator We no longer require that path lists are terminated with a semicolon so do not add one by default ResourceRecord_SearchPathsAsStringList. --- .../engine/portable/include/resourcerecord.h | 2 +- doomsday/engine/portable/src/resourcerecord.c | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/doomsday/engine/portable/include/resourcerecord.h b/doomsday/engine/portable/include/resourcerecord.h index cf0d9b6624..f2de4b46e1 100644 --- a/doomsday/engine/portable/include/resourcerecord.h +++ b/doomsday/engine/portable/include/resourcerecord.h @@ -84,7 +84,7 @@ const ddstring_t* ResourceRecord_ResolvedPath(resourcerecord_t* rec, boolean can void ResourceRecord_Print(resourcerecord_t* rec, boolean printStatus); /** - * @return String list of paths separated (and terminated) with semicolons ';'. + * @return String list of paths delimited with semicolons. */ ddstring_t* ResourceRecord_SearchPathsAsStringList(resourcerecord_t* rec); diff --git a/doomsday/engine/portable/src/resourcerecord.c b/doomsday/engine/portable/src/resourcerecord.c index 8afe916956..75bd46d46f 100644 --- a/doomsday/engine/portable/src/resourcerecord.c +++ b/doomsday/engine/portable/src/resourcerecord.c @@ -39,26 +39,29 @@ static ddstring_t* buildSearchPathList(resourcerecord_t* rec) { assert(rec); { - int requiredLength = 0; + int i, requiredLength = 0; ddstring_t* pathList; - { int i; + if(!rec->_namesCount) + return 0; + for(i = 0; i < rec->_namesCount; ++i) requiredLength += Str_Length(rec->_names[i]); - } - requiredLength += rec->_namesCount; + requiredLength += rec->_namesCount - 1; - if(requiredLength == 0) + if(!requiredLength) return 0; // Build path list in reverse; newer paths have precedence. pathList = Str_New(); Str_Reserve(pathList, requiredLength); Str_Clear(pathList); - { int i; - for(i = rec->_namesCount-1; i >= 0; i--) - Str_Appendf(pathList, "%s;", Str_Text(rec->_names[i])); - } + + i = rec->_namesCount-1; + Str_Set(pathList, Str_Text(rec->_names[i--])); + for(; i >= 0; i--) + Str_Appendf(pathList, ";%s", Str_Text(rec->_names[i])); + return pathList; } }