diff options
Diffstat (limited to 'src/util.cc')
| -rw-r--r-- | src/util.cc | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc new file mode 100644 index 0000000..f2ebc48 --- /dev/null +++ b/src/util.cc @@ -0,0 +1,42 @@ +#include "util.hh" + +static void (*ErrorFunction)(const char *Text) = NULL; +static void (*PrintFunction)(int Level, const char *Text) = NULL; + +void SetErrorFunction(TErrorFunction *Function){ + ErrorFunction = Function; +} + +void SetPrintFunction(TPrintFunction *Function){ + PrintFunction = Function; +} + +void error(char *Text, ...){ + char s[1024]; + + va_list ap; + va_start(ap, Text); + vsnprintf(s, sizeof(s), Text, ap); + va_end(ap); + + if(ErrorFunction){ + ErrorFunction(s); + }else{ + printf("%s", s); + } +} + +void print(int Level, char *Text, ...){ + char s[1024]; + + va_list ap; + va_start(ap, Text); + vsnprintf(s, sizeof(s), Text, ap); + va_end(ap); + + if(PrintFunction){ + PrintFunction(Level, s); + }else{ + printf("%s", s); + } +} |
