13 #define MAX_LINE_WIDTH 128
15 void strlwr (char * str)
17 while (*str) {*str = tolower (*str); str++; }
20 int filelength (int fd)
23 if (fstat (fd, &buf) == -1)
29 unsigned long _beginthread (void (*pfuncStart)(void *), unsigned unStackSize, void* pArgList)
41 void OutputDebugString (const char *str)
43 fprintf(stderr, "OutputDebugString: %s\n", str);
51 void _splitpath (const char *path, char *drive, char *dir, char *fname, char *ext)
56 /* fs2 only uses fname */
58 const char *ls = strrchr(path, '/');
60 ls++; // move past '/'
65 const char *lp = strrchr(path, '.');
67 lp = ls + strlen(ls); // move to the end
71 if (dist > (_MAX_FNAME-1))
74 strncpy(fname, ls, dist);
75 fname[dist] = 0; // add null, just in case
79 int MulDiv(int a, int b, int c)
81 /* slow long long version */
82 __extension__ long long aa = a;
83 __extension__ long long bb = b;
84 __extension__ long long cc = c;
86 __extension__ long long dd = aa * bb;
87 __extension__ long long ee = dd / cc;
112 static RAM *RamTable;
115 void vm_free(void* ptr, char *file, int line)
118 fprintf(stderr, "FREE: %s:%d addr = %p\n", file, line, ptr);
120 RAM *item = RamTable;
121 RAM **mark = &RamTable;
123 while (item != NULL) {
124 if (item->addr == ptr) {
135 mark = &(item->next);
140 fprintf(stderr, "ERROR: vm_free caught invalid free: addr = %p, file = %s/%d\n", ptr, file, line);
146 void *vm_malloc(int size, char *file, int line)
149 fprintf(stderr, "MALLOC: %s:%d %d bytes\n", file, line, size);
151 RAM *next = (RAM *)malloc(sizeof(RAM));
153 next->addr = malloc(size);
158 next->next = RamTable;
167 char *vm_strdup(char const* str, char *file, int line)
170 fprintf(stderr, "STRDUP: %s:%d\n", file, line);
172 RAM *next = (RAM *)malloc(sizeof(RAM));
174 next->addr = strdup(str);
175 next->size = strlen(str)+1;
179 next->next = RamTable;
182 return (char *)next->addr;
193 fprintf(stderr, "\nDumping allocated memory:\n");
197 fprintf(stderr, "%d: file: %s:%d: addr:%p size:%d\n", i, ptr->file, ptr->line, ptr->addr, ptr->size);
203 fprintf(stderr, "\nTotal of %d left-over bytes from %d allocations\n", mem, i);
207 void windebug_memwatch_init()
212 /* error message debugging junk */
213 int Log_debug_output_to_file = 0;
215 void load_filter_info(void)
220 void outwnd_printf(char* id, char* format, ...)
222 char tmp[MAX_LINE_WIDTH*4];
225 va_start (args, format);
226 vsprintf (tmp, format, args);
228 fprintf (stderr, "%s: %s\n", id, tmp);
231 void outwnd_printf2(char* format, ...)
233 char tmp[MAX_LINE_WIDTH*4];
236 va_start (args, format);
237 vsprintf (tmp, format, args);
239 fprintf (stderr, "General: %s", tmp);
247 void Warning( char * filename, int line, char * format, ... )
249 char tmp[MAX_LINE_WIDTH*4];
252 va_start (args, format);
253 vsprintf (tmp, format, args);
255 fprintf (stderr, "Warning: (%s:%d): %s\n", filename, line, tmp);
258 void Error( char * filename, int line, char * format, ... )
260 char tmp[MAX_LINE_WIDTH*4];
263 va_start (args, format);
264 vsprintf (tmp, format, args);
266 fprintf (stderr, "Error: (%s:%d): %s\n", filename, line, tmp);
270 void WinAssert(char * text,char *filename, int line)
272 fprintf (stderr, "Assertion: (%s:%d) %s\n", filename, line, text);