summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2015-07-26 13:25:31 -0700
committerMichael Pavone <pavone@retrodev.com>2015-07-26 13:25:31 -0700
commit3372e57c62e3ff5f93c5541ef5b969229d132463 (patch)
treedf1a91e13ebef01d2ad636bd940c7e514a6919ff /util.c
parent4755aa94deb0a8fb90bf74033d370e9370d69ca2 (diff)
parentbee8b42029900ca034675c54d98813a61ca4407a (diff)
Merge
Diffstat (limited to 'util.c')
-rw-r--r--util.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/util.c b/util.c
index 9722d3e..76b0e14 100644
--- a/util.c
+++ b/util.c
@@ -8,6 +8,9 @@
#include <sys/stat.h>
#include <unistd.h>
+#include "blastem.h" //for headless global
+#include "render.h" //for render_errorbox
+
char * alloc_concat(char * first, char * second)
{
int flen = strlen(first);
@@ -86,6 +89,91 @@ void set_exe_str(char * str)
exe_str = str;
}
+void fatal_error(char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ if (!headless) {
+ //take a guess at the final size
+ size_t size = strlen(format) * 2;
+ char *buf = malloc(size);
+ size_t actual = vsnprintf(buf, size, format, args);
+ if (actual >= size) {
+ actual++;
+ free(buf);
+ buf = malloc(actual);
+ va_end(args);
+ va_start(args, format);
+ vsnprintf(buf, actual, format, args);
+ }
+ fputs(buf, stderr);
+ render_errorbox("Fatal Error", buf);
+ free(buf);
+ } else {
+ vfprintf(stderr, format, args);
+ }
+ va_end(args);
+ exit(1);
+}
+
+void warning(char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+#ifndef _WIN32
+ if (headless || (isatty(STDERR_FILENO) && isatty(STDIN_FILENO))) {
+ vfprintf(stderr, format, args);
+ } else {
+#endif
+ size_t size = strlen(format) * 2;
+ char *buf = malloc(size);
+ size_t actual = vsnprintf(buf, size, format, args);
+ if (actual >= size) {
+ actual++;
+ free(buf);
+ buf = malloc(actual);
+ va_end(args);
+ va_start(args, format);
+ vsnprintf(buf, actual, format, args);
+ }
+ fputs(buf, stderr);
+ render_infobox("BlastEm Info", buf);
+ free(buf);
+#ifndef _WIN32
+ }
+#endif
+ va_end(args);
+}
+
+void info_message(char *format, ...)
+{
+ va_list args;
+ va_start(args, format);
+#ifndef _WIN32
+ if (headless || (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO))) {
+ vprintf(format, args);
+ } else {
+#endif
+ size_t size = strlen(format) * 2;
+ char *buf = malloc(size);
+ size_t actual = vsnprintf(buf, size, format, args);
+ if (actual >= size) {
+ actual++;
+ free(buf);
+ buf = malloc(actual);
+ va_end(args);
+ va_start(args, format);
+ vsnprintf(buf, actual, format, args);
+ }
+ fputs(buf, stdout);
+ render_infobox("BlastEm Info", buf);
+ free(buf);
+#ifndef _WIN32
+ }
+#endif
+ va_end(args);
+}
+
#ifdef _WIN32
#include <windows.h>
#include <shlobj.h>