diff --git a/apps/script_console.cpp b/apps/script_console.cpp index dafa599..35894a9 100644 --- a/apps/script_console.cpp +++ b/apps/script_console.cpp @@ -280,6 +280,19 @@ int ExternalFileWriteAll(ExecutionContext *context, Value *returnValue) { return 2; } +int ExternalFileAppend(ExecutionContext *context, Value *returnValue) { + STACK_POP_STRING_2(entryText, entryBytes, entry2Text, entry2Bytes); + returnValue->i = 0; + EsFileInformation information = EsFileOpen(entryText, entryBytes, ES_FILE_WRITE); + + if (information.error == ES_SUCCESS) { + returnValue->i = EsFileWriteSync(information.handle, information.size, entry2Bytes, entry2Text); + EsHandleClose(information.handle); + } + + return 2; +} + int ExternalFileGetSize(ExecutionContext *context, Value *returnValue) { STACK_POP_STRING(entryText, entryBytes); EsDirectoryChild information; diff --git a/util/script.c b/util/script.c index b1cd719..a338a78 100644 --- a/util/script.c +++ b/util/script.c @@ -509,6 +509,7 @@ char baseModuleSource[] = { "bool PathSetDefaultPrefixToScriptSourceDirectory() #extcall;" "str FileReadAll(str path) #extcall;" // TODO Returning an error? "bool FileWriteAll(str path, str x) #extcall;" // TODO Returning an error? + "bool FileAppend(str path, str x) #extcall;" // TODO Returning an error? "bool FileCopy(str source, str destination) #extcall;" "int FileGetSize(str path) #extcall;" // Returns -1 on error. TODO Returning an error code. @@ -704,6 +705,7 @@ int ExternalPathGetDefaultPrefix(ExecutionContext *context, Value *returnValue); int ExternalPathSetDefaultPrefixToScriptSourceDirectory(ExecutionContext *context, Value *returnValue); int ExternalFileReadAll(ExecutionContext *context, Value *returnValue); int ExternalFileWriteAll(ExecutionContext *context, Value *returnValue); +int ExternalFileAppend(ExecutionContext *context, Value *returnValue); int ExternalFileCopy(ExecutionContext *context, Value *returnValue); int ExternalFileGetSize(ExecutionContext *context, Value *returnValue); int ExternalPersistRead(ExecutionContext *context, Value *returnValue); @@ -742,6 +744,7 @@ ExternalFunction externalFunctions[] = { { .cName = "PathSetDefaultPrefixToScriptSourceDirectory", .callback = ExternalPathSetDefaultPrefixToScriptSourceDirectory }, { .cName = "FileReadAll", .callback = ExternalFileReadAll }, { .cName = "FileWriteAll", .callback = ExternalFileWriteAll }, + { .cName = "FileAppend", .callback = ExternalFileAppend }, { .cName = "FileCopy", .callback = ExternalFileCopy }, { .cName = "FileGetSize", .callback = ExternalFileGetSize }, { .cName = "PersistRead", .callback = ExternalPersistRead }, @@ -5507,6 +5510,23 @@ int ExternalFileWriteAll(ExecutionContext *context, Value *returnValue) { return 2; } +int ExternalFileAppend(ExecutionContext *context, Value *returnValue) { + STACK_POP_STRING_2(entryText, entryBytes, entry2Text, entry2Bytes); + returnValue->i = 0; + if (entryBytes == 0) return 2; + char *temporary = StringZeroTerminate(entryText, entryBytes); + if (!temporary) return 3; + FILE *f = fopen(temporary, "ab"); + + if (f) { + returnValue->i = entry2Bytes == fwrite(entry2Text, 1, entry2Bytes, f); + if (fclose(f)) returnValue->i = 0; + } + + free(temporary); + return 2; +} + int ExternalPathGetDefaultPrefix(ExecutionContext *context, Value *returnValue) { (void) returnValue; char *data = (char *) malloc(10000); diff --git a/util/start.script b/util/start.script index 311cb9c..eb75763 100644 --- a/util/start.script +++ b/util/start.script @@ -46,6 +46,7 @@ void Setup(bool forAutomation) { if forAutomation { assert FileWriteAll("bin/build_config.ini", "accepted_license=1\nautomated_build=1\n"); assert SystemShellExecute("bin/build get-toolchain"); + assert FileAppend("bin/build_config.ini", "\nautomated_build=1\n"); assert FileWriteAll("bin/commit.txt", StringSlice(StringSplitByCharacter(SystemShellEvaluate("git log"), "\n", true)[0], 8, 15)); } }