Descent3/mac/MACONLY.CPP

119 lines
2.4 KiB
C++
Raw Normal View History

2024-04-16 03:43:29 +00:00
#include <stdarg.h>
#include <math.h>
#include <ctype.h>
#include "debug.h"
#include "mem.h"
#include "ddio.h"
2024-04-16 18:56:40 +00:00
// void atexit(void *proc)
2024-04-16 03:43:29 +00:00
//{
// mprintf((2, "atexit\n"));
//}
2024-04-16 18:56:40 +00:00
int stricmp(const char *s1, const char *s2) {
char c1, c2;
while (1) {
c1 = tolower(*s1++);
c2 = tolower(*s2++);
if (c1 < c2)
return -1;
if (c1 > c2)
return 1;
if (c1 == 0)
return 0;
}
2024-04-16 03:43:29 +00:00
}
2024-04-16 18:56:40 +00:00
int strnicmp(const char *s1, const char *s2, int n) {
int i;
char c1, c2;
for (i = 0; i < n; i++) {
c1 = tolower(*s1++);
c2 = tolower(*s2++);
if (c1 < c2)
return -1;
if (c1 > c2)
return 1;
if (!c1)
return 0;
}
return 0;
2024-04-16 03:43:29 +00:00
}
2024-04-16 18:56:40 +00:00
void Sleep(int millis) {
longlong start = timer_GetMSTime();
while (timer_GetMSTime() - start < millis)
;
2024-04-16 03:43:29 +00:00
}
#define USE_MALLOC
2024-04-16 18:56:40 +00:00
void HeapFree(HANDLE heap, int dummy, void *mptr) {
if (mptr)
2024-04-16 03:43:29 +00:00
#ifdef USE_MALLOC
2024-04-16 18:56:40 +00:00
free(mptr);
2024-04-16 03:43:29 +00:00
#else
2024-04-16 18:56:40 +00:00
DisposePtr((char *)mptr);
2024-04-16 03:43:29 +00:00
#endif
}
2024-04-16 18:56:40 +00:00
void *HeapAlloc(HANDLE heap, int dummy, int size) {
if (size <= 0)
return NULL;
#ifdef USE_MALLOC
return malloc(size);
2024-04-16 03:43:29 +00:00
#else
2024-04-16 18:56:40 +00:00
return NewPtr(size);
2024-04-16 03:43:29 +00:00
#endif
}
2024-04-16 18:56:40 +00:00
void *HeapReAlloc(HANDLE heap, int dummy, void *oldblock, int size) {
if (size <= 0)
return NULL;
2024-04-16 03:43:29 +00:00
#ifdef USE_MALLOC
2024-04-16 18:56:40 +00:00
return (realloc(oldblock, size));
2024-04-16 03:43:29 +00:00
#else
2024-04-16 18:56:40 +00:00
SetPtrSize((char *)oldblock, size);
return (oldblock);
2024-04-16 03:43:29 +00:00
#endif
}
2024-04-16 18:56:40 +00:00
void GlobalFree(void *mptr) {
if (mptr)
mem_free(mptr);
2024-04-16 03:43:29 +00:00
}
2024-04-16 18:56:40 +00:00
void *GlobalAlloc(int flags, int size) {
if (size <= 0)
return NULL;
return mem_malloc(size);
2024-04-16 03:43:29 +00:00
}
2024-04-16 18:56:40 +00:00
void *GlobalLock(HGLOBAL hMem) { return hMem; }
char *strupr(char *string) {
while (string && *string) {
*string = toupper(*string);
string++;
}
return string;
2024-04-16 03:43:29 +00:00
}
2024-04-16 18:56:40 +00:00
char *itoa(int value, char *string, int radix) {
if (radix == 10) {
sprintf(string, "%d", value);
} else if (radix == 16) {
sprintf(string, "%x", value);
} else {
DebugStr("\p!!!!!!!!!!!!!!!WARNING CALLING itoa WITHOUT 10 or 16 RADIX!!!!!!!!!!!!!!!!!!!!!!");
sprintf(string, "%d", value);
}
return string;
2024-04-16 03:43:29 +00:00
}
void Debug_ConsoleRedirectMessages(int virtual_window, int physical_window) {}
int debug_level = 2;
2024-04-16 18:56:40 +00:00
void Debug_ConsolePrintf(int n, char *format, ...) {
if (n >= debug_level) {
va_list args;
va_start(args, format);
vprintf(format, args);
va_end(args);
}
return;
2024-04-16 03:43:29 +00:00
}