--- np2/common/_memory.c 2003/10/16 17:57:10 1.1 +++ np2/common/_memory.c 2005/02/15 18:42:20 1.4 @@ -1,12 +1,26 @@ #include "compiler.h" -#include "dosio.h" #define MEMTBLMAX 256 #define HDLTBLMAX 256 + #if defined(MEMTRACE) +#include "strres.h" +#include "dosio.h" + +#if defined(MACOS) +#define CRLITERAL "\r" +#define CRCONST str_cr +#elif defined(X11) || defined(SLZAURUS) +#define CRLITERAL "\n" +#define CRCONST str_lf +#else +#define CRLITERAL "\r\n" +#define CRCONST str_crlf +#endif + typedef struct { void *hdl; UINT size; @@ -21,13 +35,15 @@ typedef struct { static _MEMTBL memtbl[MEMTBLMAX]; static _HDLTBL hdltbl[HDLTBLMAX]; -static const char memstr[] = \ - "Handle Size Name\r\n" \ - "--------------------------------------------\r\n"; - -static const char hdlstr[] = \ - "Handle Name\r\n" \ - "-------------------------------------\r\n"; +static const OEMCHAR str_memhdr[] = \ + "Handle Size Name" CRLITERAL \ + "--------------------------------------------" CRLITERAL; + +static const OEMCHAR str_hdlhdr[] = \ + "Handle Name" CRLITERAL \ + "-------------------------------------" CRLITERAL; + +static const OEMCHAR str_memused[] = "memused: %d" CRLITERAL; void _meminit(void) { @@ -69,7 +85,7 @@ void _memfree(void *hdl) { } } -void _handle_append(void *hdl, const char *name) { +void _handle_append(void *hdl, const OEMCHAR *name) { int i; @@ -77,7 +93,7 @@ void _handle_append(void *hdl, const cha for (i=0; i>3] |= (BYTE)0x80 >> (i & 7); + memusebit[i>>3] |= (UINT8)(0x80 >> (i & 7)); memuses++; } } for (i=0; i>3] |= (BYTE)0x80 >> (i & 7); + hdlusebit[i>>3] |= (UINT8)(0x80 >> (i & 7)); hdluses++; } } fh = file_create_c(filename); if (fh != FILEH_INVALID) { - SPRINTF(work, "memused: %d\r\n", memuses); - file_write(fh, work, strlen(work)); + OEMSPRINTF(work, OEMTEXT("memused: %d\r\n"), memuses); + file_write(fh, work, OEMSTRLEN(work)); if (memuses) { - file_write(fh, memstr, strlen(memstr)); + file_write(fh, str_memhdr, OEMSTRLEN(str_memhdr)); for (i=0; i>3] << (i & 7)) & 0x80) { - SPRINTF(work, "%08lx %10u %s\r\n", + OEMSPRINTF(work, OEMTEXT("%08lx %10u %s\r\n"), (long)memtbl[i].hdl, memtbl[i].size, memtbl[i].name); - file_write(fh, work, strlen(work)); + file_write(fh, work, OEMSTRLEN(work)); } } - file_write(fh, "\r\n", 2); + file_write(fh, CRCONST, OEMSTRLEN(CRCONST)); } - SPRINTF(work, "hdlused: %d\r\n", hdluses); - file_write(fh, work, strlen(work)); + OEMSPRINTF(work, "hdlused: %d\r\n", hdluses); + file_write(fh, work, OEMSTRLEN(work)); if (hdluses) { - file_write(fh, hdlstr, strlen(hdlstr)); + file_write(fh, str_hdlhdr, OEMSTRLEN(str_hdlhdr)); for (i=0; i>3] << (i & 7)) & 0x80) { - SPRINTF(work, "%08lx %s\r\n", + OEMSPRINTF(work, "%08lx %s\r\n", (long)hdltbl[i].hdl, hdltbl[i].name); - file_write(fh, work, strlen(work)); + file_write(fh, work, OEMSTRLEN(work)); } } - file_write(fh, "\r\n", 2); + file_write(fh, CRCONST, strlen(CRCONST)); } file_close(fh); } @@ -160,8 +176,9 @@ typedef struct { UINT size; } _MEMTBL; - UINT usedmemory; BOOL chgmemory; + UINT usedmemory; + static _MEMTBL memtbl[MEMTBLMAX]; void _meminit(void) {