From 5cfe00df82a69f44187b1cd77fe3d6865cf3425f Mon Sep 17 00:00:00 2001 From: fusion32 Date: Tue, 1 Jul 2025 09:26:06 -0300 Subject: `reader.cc` --- src/utils.cc | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src/utils.cc') diff --git a/src/utils.cc b/src/utils.cc index 4a3523b..11aa048 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -2,8 +2,9 @@ #include -static void (*ErrorFunction)(const char *Text) = NULL; -static void (*PrintFunction)(int Level, const char *Text) = NULL; +static TErrorFunction *ErrorFunction; +static TPrintFunction *PrintFunction; +static char StandardLogFile[4096]; void SetErrorFunction(TErrorFunction *Function){ ErrorFunction = Function; @@ -13,6 +14,36 @@ void SetPrintFunction(TPrintFunction *Function){ PrintFunction = Function; } +void SetStandardLogFile(const char *FileName){ + strcpy(StandardLogFile, FileName); +} + +void SilentHandler(const char *Text){ + // no-op +} + +void SilentHandler(int Level, const char *Text){ + // no-op +} + +void LogFileHandler(const char *Text){ + if(StandardLogFile[0] == 0){ + return; + } + + FILE *File = fopen(StandardLogFile, "at"); + if(File != NULL){ + fprintf(File, "%s", Text); + if(fclose(File) != 0){ + error("LogfileHandler: Fehler %d beim Schließen der Datei.\n", errno); + } + } +} + +void LogFileHandler(int Level, const char *Text){ + LogFileHandler(Text); +} + void error(const char *Text, ...){ char s[1024]; -- cgit v1.2.3