13 // use system versions of this stuff in here rather than the vm_* versions
19 #define MAX_LINE_WIDTH 128
21 void strlwr (char * str)
23 while (*str) {*str = tolower (*str); str++; }
26 void strupr (char * str)
28 while (*str) {*str = toupper (*str); str++; }
31 int filelength (int fd)
34 if (fstat (fd, &buf) == -1)
40 unsigned long _beginthread (void (*pfuncStart)(void *), unsigned unStackSize, void* pArgList)
50 // ughh, SDL_Delay causes a slowdown on Tiger for some reason and though I hate
51 // doing this, even the few Apple examples I've seen do this over what SDL_Delay does.
52 uint then = SDL_GetTicks() + mili;
54 while ( then > SDL_GetTicks() );
56 SDL_Delay( long(mili) );
60 void OutputDebugString (const char *str)
62 fprintf(stderr, "OutputDebugString: %s\n", str);
70 // make specified directory, recursively
71 // NOTE: since this is for use with CFILE this code assumes that there will be a trailing '/'
72 // or a trailing filename. any directory name not followed by a '/' will be considered a file
73 int _mkdir(const char *path)
75 int status = 1; // if we don't ever call mkdir() to update this then assume we are in error
76 char *c, tmp_path[MAX_PATH] = { 0 };
78 strncpy(tmp_path, path, MAX_PATH-1);
88 status = mkdir(tmp_path, 0700);
93 if (status && (m_error != EEXIST) ) {
94 Warning(__FILE__, __LINE__, "Cannot mkdir %s: %s", tmp_path, strerror(m_error));
105 void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
110 /* fs2 only uses fname */
112 const char *ls = strrchr(path, '/');
114 ls++; // move past '/'
119 const char *lp = strrchr(path, '.');
121 lp = ls + strlen(ls); // move to the end
125 if (dist > (_MAX_FNAME-1))
128 strncpy(fname, ls, dist);
129 fname[dist] = 0; // add null, just in case
133 int MulDiv(int a, int b, int c)
135 /* slow long long version */
136 __extension__ long long aa = a;
137 __extension__ long long bb = b;
138 __extension__ long long cc = c;
140 __extension__ long long dd = aa * bb;
141 __extension__ long long ee = dd / cc;
166 static RAM *RamTable;
170 void vm_free(void* ptr, const char *file, int line)
172 void vm_free(void* ptr)
176 fprintf(stderr, "FREE: %s:%d addr = %p\n", file, line, ptr);
178 RAM *item = RamTable;
179 RAM **mark = &RamTable;
181 while (item != NULL) {
182 if (item->addr == ptr) {
193 mark = &(item->next);
198 fprintf(stderr, "ERROR: vm_free caught invalid free: addr = %p, file = %s/%d\n", ptr, file, line);
205 void *vm_malloc(int size, const char *file, int line)
207 void *vm_malloc(int size)
211 fprintf(stderr, "MALLOC: %s:%d %d bytes\n", file, line, size);
213 RAM *next = (RAM *)malloc(sizeof(RAM));
215 next->addr = malloc(size);
220 next->next = RamTable;
230 char *vm_strdup(char const* str, const char *file, int line)
232 char *vm_strdup(char const* str)
236 fprintf(stderr, "STRDUP: %s:%d\n", file, line);
238 RAM *next = (RAM *)malloc(sizeof(RAM));
240 next->addr = strdup(str);
241 next->size = strlen(str)+1;
245 next->next = RamTable;
248 return (char *)next->addr;
259 fprintf(stderr, "\nDumping allocated memory:\n");
263 fprintf(stderr, "%d: file: %s:%d: addr:%p size:%d\n", i, ptr->file, ptr->line, ptr->addr, ptr->size);
269 fprintf(stderr, "\nTotal of %d left-over bytes from %d allocations\n", mem, i);
273 void windebug_memwatch_init()
278 /* error message debugging junk */
280 int Log_debug_output_to_file = 0;
282 void load_filter_info(void)
287 void outwnd_printf(char* id, char* format, ...)
289 char tmp[MAX_LINE_WIDTH*4];
292 va_start (args, format);
293 vsprintf (tmp, format, args);
295 fprintf (stderr, "%s: %s\n", id, tmp);
298 void outwnd_printf2(char* format, ...)
300 char tmp[MAX_LINE_WIDTH*4];
303 va_start (args, format);
304 vsprintf (tmp, format, args);
306 fprintf (stderr, "General: %s", tmp);
315 extern void gr_force_windowed();
317 void Warning( const char * filename, int line, const char * format, ... )
319 char tmp[MAX_LINE_WIDTH*4] = { 0 };
320 char tmp2[MAX_LINE_WIDTH*4] = { 0 };
323 va_start(args, format);
324 vsnprintf(tmp, sizeof(tmp), format, args);
326 // fprintf (stderr, "Warning: (%s:%d): %s\n", filename, line, tmp);
327 snprintf(tmp2, sizeof(tmp2), "Warning: %s\n\nFile:%s\nLine: %d", tmp, filename, line);
331 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, "Warning!", tmp2, NULL);
334 void Error( const char * filename, int line, const char * format, ... )
336 char tmp[MAX_LINE_WIDTH*4] = { 0 };
337 char tmp2[MAX_LINE_WIDTH*4] = { 0 };
340 va_start (args, format);
341 vsnprintf (tmp, sizeof(tmp), format, args);
343 // fprintf (stderr, "Error: (%s:%d): %s\n", filename, line, tmp);
344 snprintf(tmp2, sizeof(tmp2), "Error: %s\n\nFile:%s\nLine: %d", tmp, filename, line);
348 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error!", tmp2, NULL);
353 void WinAssert(const char * text, const char *filename, int line)
355 fprintf (stderr, "Assertion: (%s:%d) %s\n", filename, line, text);