/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\
* |_o_o|\\ Copyright (c) 1989 The Software Distillery.                    *
* |. o.| ||          All Rights Reserved                                  *
* | .  | ||          Written by Doug Walker                               *
* | o  | ||          The Software Distillery                              *
* |  . |//           235 Trillingham Lane                                 *
* ======             Cary, NC 27513                                       *
*                    BBS:(919)-471-6436                                   *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef D_MEMWATCH_H
#define D_MEMWATCH_H

/* Flags for MWInit */
#define MWF_NOCHECK   0x00000000 /* (compatibility - do not use)         */
#define MWF_NOLOG     0x00000002 /* No debug messages                    */
#define MWF_CHECK     0x00000004 /* Check mem whenever mem rtns called   */
#define MWF_NOFREE    0x00000008 /* Don't free nonfreed memory           */
#define MWF_NOFTRASH  0x00000010 /* Don't trash memory upon free         */
#define MWF_NOATRASH  0x00000020 /* Don't trash memory upon alloc        */
#define MWF_NOFKEEP   0x00000040 /* Don't keep memory after free         */
#define MWF_MALLOCWRN 0x00000080 /* Warn about malloc'd mem not freed    */
#define MWF_SERIAL    0x00000100 /* Use serial port for output           */

#define MWF_ACTIVE   0x80000000 /* PRIVATE - MemWatch is active          */
#define MWF_ERROR    0x40000000 /* PRIVATE - Error discovered, terminate */

/* Flags to tell MWReport how much to report */
#define MWR_NONE 0   /* Don't report anything; just return    */
#define MWR_SUM  1   /* Report current and total usage        */
#define MWR_FULL 2   /* Report on all outstanding allocations */

#if MWDEBUG

#include <exec/types.h>

#ifdef free
#undef free
#endif

#define AllocMem(size,flags) MWAllocMem(size, flags, 0, __FILE__, __LINE__)
#define FreeMem(mem,size)    MWFreeMem(mem, size, 0, __FILE__, __LINE__)
#define malloc(size)         MWAllocMem(size, 0, 1, __FILE__, __LINE__)
#define calloc(nelt,esize)   MWAllocMem((nelt)*(esize), MEMF_CLEAR, 1, \
                                        __FILE__, __LINE__)
#define realloc(mem,size)    MWrealloc(mem,size,__FILE__,__LINE__)
#define free(mem)            MWFreeMem(mem, -1, 1, __FILE__, __LINE__)

void MWInit      (LONG, LONG, char *);
void MWTerm      (void);
void *MWAllocMem (long, long, long, char *, long);
void MWFreeMem   (void *, long, long, char *, long);
void MWCheck     (void);
void MWReport    (char *, long);
void MWLimit     (LONG, LONG);
void *MWrealloc  (void *, long, char *, long);

extern unsigned long  __MWFlags;
extern char *__MWLogName;

#else /* MWDEBUG */

/* No memory debugging - make everything go away */

#define MWInit(a,b,c)
#define MWTerm()
#define MWCheck()
#define MWReport(a,b)
#define MWLimit(a,b)

#endif /* MWDEBUG */
#endif /* D_MEMWATCH_H */
