comparison util.c @ 799:0b692b5d154b

Merge
author Michael Pavone <pavone@retrodev.com>
date Sun, 26 Jul 2015 13:25:31 -0700
parents bce97fc0bb8a 792be135d3af
children 3eced113081c
comparison
equal deleted inserted replaced
798:062a2199daf6 799:0b692b5d154b
6 6
7 #include <sys/types.h> 7 #include <sys/types.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
11 #include "blastem.h" //for headless global
12 #include "render.h" //for render_errorbox
13
11 char * alloc_concat(char * first, char * second) 14 char * alloc_concat(char * first, char * second)
12 { 15 {
13 int flen = strlen(first); 16 int flen = strlen(first);
14 int slen = strlen(second); 17 int slen = strlen(second);
15 char * ret = malloc(flen + slen + 1); 18 char * ret = malloc(flen + slen + 1);
82 static char * exe_str; 85 static char * exe_str;
83 86
84 void set_exe_str(char * str) 87 void set_exe_str(char * str)
85 { 88 {
86 exe_str = str; 89 exe_str = str;
90 }
91
92 void fatal_error(char *format, ...)
93 {
94 va_list args;
95 va_start(args, format);
96 if (!headless) {
97 //take a guess at the final size
98 size_t size = strlen(format) * 2;
99 char *buf = malloc(size);
100 size_t actual = vsnprintf(buf, size, format, args);
101 if (actual >= size) {
102 actual++;
103 free(buf);
104 buf = malloc(actual);
105 va_end(args);
106 va_start(args, format);
107 vsnprintf(buf, actual, format, args);
108 }
109 fputs(buf, stderr);
110 render_errorbox("Fatal Error", buf);
111 free(buf);
112 } else {
113 vfprintf(stderr, format, args);
114 }
115 va_end(args);
116 exit(1);
117 }
118
119 void warning(char *format, ...)
120 {
121 va_list args;
122 va_start(args, format);
123 #ifndef _WIN32
124 if (headless || (isatty(STDERR_FILENO) && isatty(STDIN_FILENO))) {
125 vfprintf(stderr, format, args);
126 } else {
127 #endif
128 size_t size = strlen(format) * 2;
129 char *buf = malloc(size);
130 size_t actual = vsnprintf(buf, size, format, args);
131 if (actual >= size) {
132 actual++;
133 free(buf);
134 buf = malloc(actual);
135 va_end(args);
136 va_start(args, format);
137 vsnprintf(buf, actual, format, args);
138 }
139 fputs(buf, stderr);
140 render_infobox("BlastEm Info", buf);
141 free(buf);
142 #ifndef _WIN32
143 }
144 #endif
145 va_end(args);
146 }
147
148 void info_message(char *format, ...)
149 {
150 va_list args;
151 va_start(args, format);
152 #ifndef _WIN32
153 if (headless || (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO))) {
154 vprintf(format, args);
155 } else {
156 #endif
157 size_t size = strlen(format) * 2;
158 char *buf = malloc(size);
159 size_t actual = vsnprintf(buf, size, format, args);
160 if (actual >= size) {
161 actual++;
162 free(buf);
163 buf = malloc(actual);
164 va_end(args);
165 va_start(args, format);
166 vsnprintf(buf, actual, format, args);
167 }
168 fputs(buf, stdout);
169 render_infobox("BlastEm Info", buf);
170 free(buf);
171 #ifndef _WIN32
172 }
173 #endif
174 va_end(args);
87 } 175 }
88 176
89 #ifdef _WIN32 177 #ifdef _WIN32
90 #include <windows.h> 178 #include <windows.h>
91 #include <shlobj.h> 179 #include <shlobj.h>