|
|
|
@ -21,7 +21,7 @@ STATIC LINEPTR configFileReadLine(BPTR file); |
|
|
|
|
// - STRUCTS -----------------------------------------------------------------------------
|
|
|
|
|
struct ConfigFile |
|
|
|
|
{ |
|
|
|
|
CONST_STRPTR filename; |
|
|
|
|
STRPTR filename; |
|
|
|
|
SECTIONSTOREPTR sectionStore; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
@ -38,6 +38,10 @@ VOID ConfigFileFree(CONFIGFILEPTR abstractConfigFile) |
|
|
|
|
{ |
|
|
|
|
SectionStoreFree(configFile->sectionStore); |
|
|
|
|
} |
|
|
|
|
if( configFile->filename != NULL ) |
|
|
|
|
{ |
|
|
|
|
FreeVec(configFile->filename); |
|
|
|
|
} |
|
|
|
|
FreeVec(configFile); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -52,6 +56,8 @@ CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename) |
|
|
|
|
LINEPTR line = NULL; |
|
|
|
|
result = AllocVec(sizeof(struct ConfigFile), MEMF_CLEAR); |
|
|
|
|
result->sectionStore = SectionStoreNew(); |
|
|
|
|
result->filename = AllocVec(strlen(filename)+1, MEMF_CLEAR); |
|
|
|
|
CopyMem(filename, result->filename, strlen(filename)); |
|
|
|
|
while( (line = configFileReadLine(configFile)) != NULL ) |
|
|
|
|
{ |
|
|
|
|
SectionStoreAddLineToCurrentSection(result->sectionStore, line); |
|
|
|
@ -63,6 +69,33 @@ CONFIGFILEPTR ConfigFileRead(CONST_STRPTR filename) |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID ConfigFileSave(CONFIGFILEPTR abstractConfigFile) |
|
|
|
|
{ |
|
|
|
|
struct ConfigFile* configFile = (struct ConfigFile*)abstractConfigFile; |
|
|
|
|
BPTR file = Open(configFile->filename, MODE_NEWFILE); |
|
|
|
|
if( file != 0 ) |
|
|
|
|
{ |
|
|
|
|
ConfigFileWrite(abstractConfigFile, file); |
|
|
|
|
Close(file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VOID ConfigFileWrite(CONFIGFILEPTR abstractConfigFile, BPTR file) |
|
|
|
|
{ |
|
|
|
|
ULONG index = 0; |
|
|
|
|
ULONG count = 0; |
|
|
|
|
struct ConfigFile* configFile = (struct ConfigFile*)abstractConfigFile; |
|
|
|
|
if( configFile != NULL ) |
|
|
|
|
{ |
|
|
|
|
count = SectionStoreSectionCount(configFile->sectionStore); |
|
|
|
|
for( index = 0; index < count; index++ ) |
|
|
|
|
{ |
|
|
|
|
SECTIONPTR section = SectionStoreSectionAt(configFile->sectionStore, index); |
|
|
|
|
SectionWrite(section, file); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringArray ConfigFileSubsectionsForSection(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR primarySection) |
|
|
|
|
{ |
|
|
|
|