From 3d65ee22b64d9e0e826a1dd8cda9aa88db90f9de Mon Sep 17 00:00:00 2001 From: Alan C Francis Date: Fri, 5 Jan 2024 17:10:09 +0000 Subject: [PATCH] save original vs save a copy --- configfile.c | 10 ++++++++-- configfile.h | 3 ++- main.c | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/configfile.c b/configfile.c index 269eb97..22f2e12 100644 --- a/configfile.c +++ b/configfile.c @@ -82,10 +82,15 @@ CONFIGFILEPTR ConfigFileRead(BPTR configFile) return result; } -VOID ConfigFileSave(CONFIGFILEPTR abstractConfigFile) +VOID ConfigFileSaveOverwrite(CONFIGFILEPTR abstractConfigFile) { struct ConfigFile* configFile = (struct ConfigFile*)abstractConfigFile; - BPTR file = Open(configFile->filename, MODE_NEWFILE); + ConfigFileSaveCopyTo(abstractConfigFile, configFile->filename); +} + +VOID ConfigFileSaveCopyTo(CONFIGFILEPTR abstractConfigFile, STRPTR newFilename) +{ + BPTR file = Open(newFilename, MODE_NEWFILE); if( file != 0 ) { ConfigFileWrite(abstractConfigFile, file); @@ -93,6 +98,7 @@ VOID ConfigFileSave(CONFIGFILEPTR abstractConfigFile) } } + VOID ConfigFileWrite(CONFIGFILEPTR abstractConfigFile, BPTR file) { ULONG index = 0; diff --git a/configfile.h b/configfile.h index 29c39e9..b49aea2 100644 --- a/configfile.h +++ b/configfile.h @@ -32,7 +32,8 @@ VOID ConfigFileUnsetAll(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR compoundK VOID ConfigFileRemoveSection(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR canonicalName); VOID ConfigFileDump(CONFIGFILEPTR configFile); -VOID ConfigFileSave(CONFIGFILEPTR configFile); +VOID ConfigFileSaveOverwrite(CONFIGFILEPTR configFile); +VOID ConfigFileSaveCopyTo(CONFIGFILEPTR configFile, STRPTR newFilename); VOID ConfigFileWrite(CONFIGFILEPTR abstractConfigFile, BPTR file); Array ConfigFileSubsectionsForSection(CONFIGFILEPTR abstractConfigFile, CONST_STRPTR primarySection); diff --git a/main.c b/main.c index 00f5144..40a3636 100644 --- a/main.c +++ b/main.c @@ -62,7 +62,7 @@ WORD DoTheWork(STRPTR filename) StringArrayForEach(values, Printf("branch:[%s]\n",aString);); StringArrayFree(values, TRUE); } - ConfigFileSave(config); + ConfigFileSaveOverwrite(config); ConfigFileFree(config); }