Add MessageBox error output on Windows
[mercenary-reloaded.git] / src / libsdl / print.c
1
2 #include <stdio.h>
3 #include <stdarg.h>
4 #include <SDL2/SDL_log.h>
5 #if defined(_WIN32)
6 #include <windows.h>
7 #endif
8
9 void __attribute__ ((format (printf, 1, 2))) _print_info(const char *format, ...)
10 {
11         va_list args;
12         va_start(args, format);
13
14         SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, format, args);
15
16         va_end(args);
17 }
18
19 void __attribute__ ((format (printf, 3, 4))) _print_error(const char *_file, int _line, const char *format, ...)
20 {
21         va_list args;
22         va_start(args, format);
23
24 #if defined(_WIN32)
25         char title[123], text[1234];
26         snprintf(title, sizeof(title), "Error in %s line %d:\n", _file, _line);
27         title[sizeof(title) - 1] = '\0';
28         vsnprintf(text, sizeof(text), format, args);
29         text[sizeof(text) - 1] = '\0';
30         MessageBox(NULL, text, title, MB_OK);
31 #else
32         SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "Error in %s line %d:\n", _file, _line);
33         SDL_LogMessageV(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, format, args);
34 #endif
35
36         va_end(args);
37 }
38