|
|
|
@ -90,13 +90,38 @@ CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename) |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID SectionDump(SECTIONPTR abstractSection) |
|
|
|
|
StringArray ConfigFileSplitKey(CONST_STRPTR key) |
|
|
|
|
{ |
|
|
|
|
struct Section* section = (struct Section*)abstractSection; |
|
|
|
|
if( section != NULL && section->lines != NULL ) |
|
|
|
|
{ |
|
|
|
|
ArrayForEach(LINEPTR, aLine, section->lines, LineDump(aLine);); |
|
|
|
|
// a key is "foo.bar.baz.blah" where "foo" is the primary section name
|
|
|
|
|
// "bar.baz" is the secondary section name and "blah" is the variable name.
|
|
|
|
|
// In this case we'll just break it down into the canonical section name,
|
|
|
|
|
// foo.bar.baz and the variable name blah.
|
|
|
|
|
|
|
|
|
|
StringArray result = StringArrayNew(); |
|
|
|
|
StringArray parts = StringArrayNew(); |
|
|
|
|
STRPTR sectionPart = NULL; |
|
|
|
|
STRPTR varPart = NULL; |
|
|
|
|
|
|
|
|
|
STRPTR token = NULL; |
|
|
|
|
// we need to make a copy of the key because strtok modifies it.
|
|
|
|
|
STRPTR keyCopy = AllocVec(strlen(key)+1, MEMF_CLEAR); |
|
|
|
|
CopyMem(key, keyCopy, strlen(key)); |
|
|
|
|
|
|
|
|
|
token = strtok(keyCopy, "."); |
|
|
|
|
while (token != NULL) |
|
|
|
|
{ |
|
|
|
|
StringArrayAppendAndRetain(parts, token); |
|
|
|
|
token = strtok(NULL, "."); |
|
|
|
|
} |
|
|
|
|
FreeVec(keyCopy); |
|
|
|
|
|
|
|
|
|
// now we join all but the last part
|
|
|
|
|
sectionPart = StringArrayJoinedParts(parts, '.', SizeOfArray(parts)-1); |
|
|
|
|
StringArrayAppend(result, sectionPart); // its been alloced so dont copy
|
|
|
|
|
varPart = (STRPTR)ArrayBackValue(STRPTR, parts); |
|
|
|
|
StringArrayAppendAndRetain(result, varPart); // its a reference so copy
|
|
|
|
|
StringArrayFree(parts); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID ConfigFileDump(CONFIGFILEPTR abstractConfigFile) |
|
|
|
@ -357,6 +382,15 @@ VOID SectionAddLine(SECTIONPTR abstractSection, LINEPTR abstractLine) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID SectionDump(SECTIONPTR abstractSection) |
|
|
|
|
{ |
|
|
|
|
struct Section* section = (struct Section*)abstractSection; |
|
|
|
|
if( section != NULL && section->lines != NULL ) |
|
|
|
|
{ |
|
|
|
|
ArrayForEach(LINEPTR, aLine, section->lines, LineDump(aLine);); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID SectionFree(SECTIONPTR abstractSection) |
|
|
|
|
{ |
|
|
|
|
struct Section* section = (struct Section*)abstractSection; |
|
|
|
|