/* > memalloc.h

 * SJ Middleton, 1993

 * Consistent interface to memory claim/free routines.

 */

#ifndef __memalloc_h
# define __memalloc_h

#ifndef BOOL
# define BOOL int
#endif
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif

#ifndef __size_t
#define __size_t 1
typedef unsigned int size_t;   /* from <stddef.h> */
#endif


typedef void **mem_ptr;

/* ----------------------- mem_allocfn --------------------------
 *
 * Description: Allocate or reallocate some memory.
 * Parameters:  mem_ptr anchor -- address of pointer to store
 *                              size_t nbytes -- size store should be when call returns.
 * Returns:             TRUE of store was (re)allocated successfully.
 *                              FALSE if memory couldn't be allocated in which case *anchor
 *                              should be unchanged.
 * Notes:               If *anchor == NULL then nbytes are allocated
 *                              If *anchor != NULL then the store is reallocated to by nbytes in size.
 */

typedef BOOL (*mem_allocfn)(mem_ptr anchor, size_t nbytes);

/* ----------------------- mem_freefn --------------------------
 *
 * Description: Deallocate some memory.
 * Parameters:  mem_ptr anchor -- address of pointer to store
 * Returns:             void
 * Notes:               If *anchor == NULL then do nothing
 *                              If *anchor != NULL then deallocate store and write NULL
 *                              into *anchor.
 */

typedef void (*mem_freefn)(mem_ptr anchor);

/* ------------------------------------------------------------------------------ */

/* set error status - if TRUE then will call werr and quit */

extern void alloc_error(BOOL give);

/* register name for next buffer to be allocated (for d_alloc and debugging) */

extern void alloc_nextiscalled(const char *name);

/* register max size for next buffer to be allocated (for d_alloc) */

extern void alloc_nextmaxsize(int maxsize);

/* ------------------------------------------------------------------------------ */

/* From f_alloc.c - uses flex library */

extern BOOL f_alloc(mem_ptr anchor, size_t nbytes);
extern void f_free(mem_ptr anchor);

/* From c_alloc.c - uses Clib functions */

extern BOOL c_alloc(mem_ptr anchor, size_t nbytes);
extern void c_free(mem_ptr anchor);

/* From m_alloc.c - uses OS_Module */

extern BOOL m_alloc(mem_ptr anchor, size_t nbytes);
extern void m_free(mem_ptr anchor);

/* From d_alloc.c - uses OS_DynamicArea */

extern BOOL d_alloc(mem_ptr anchor, size_t nbytes);
extern void d_free(mem_ptr anchor);
extern BOOL dynamicarea_init(void);

/* From h_alloc.c - uses heap.c functions */

extern BOOL h_alloc(void **anchor, size_t nbytes);
extern void h_free(void **anchor);

/* From code_alloc.c - you decide what to use
 * defaults to c_alloc, c_free
 */

extern BOOL code_alloc(void **anchor, size_t nbytes);
extern void code_free(void **anchor);
extern void code_RegisterMemFns(mem_allocfn allocfn, mem_freefn freefn);

/* ------------------------------------------------------------------------------ */

#endif

/* eof memalloc.h */

