/*

    File:    utils.c
    Author:  Graham Toal
    Purpose: Portability library

Description:

    This is a cut-down version of my portability header-file.
    We cater here only for Unix and Risc OS (the latter being
    my development environment).

*/

#define DEFAULT_DAWG "dict.dwg"
#define EXT_CHAR '.'

#ifdef SYS_RISCOS
#undef DEFAULT_DAWG
#define DEFAULT_DAWG "run:dict-dwg"
#undef EXT_CHAR
#define EXT_CHAR '-'
#endif

#define READ_TEXT "r"
#define WRITE_TEXT "w"
#define WRITE_BIN "wb"
#define READ_BIN "rb"


/* system configuration */

#if defined(STDLIBS) || defined(COMPILER_MICROSOFT)
#include <stdlib.h>  /* for malloc, free & exit */
#else /* Doesn't know <stdlib.h> */
#ifndef size_t       /* Doesn't work if size_t was typedef'd */
#define size_t int   /* And if an int isn't big enough we're in trouble! */
extern void *malloc(size_t bytes);
extern void exit(int rc);
#endif
#endif /* not <stdlib.h> */

#ifdef COMPILER_MICROSOFT
#include <malloc.h>
#define MALLOC(x,s) halloc((long)(x),(size_t)(s))
#define Malloc(x,s) malloc((x)*(s))
#define FREE(x) hfree(x)
#define Free(x) free(x)
#else /* Not MICROSOFT */
#define MALLOC(x,s) malloc((size_t)((x)*(s)))
#define Malloc(x,s) malloc((x)*(s))
#define FREE(x) free(x)
#define Free(x) free(x)
#endif /* Not Microsoft */

/*
                     Error handling

     At the moment we'll just go for OK / NOT OK.  Later we should
   fix all exit's to use a specific code symbol (eg EXIT_MALLOCFAIL)
   but this has to be done system by system.  Whenever a new one is
   added, a default should be set up (as 0?)
 */

#define EXIT_OK       (0)     /* Generic success              */
#define EXIT_ERROR    (1)     /* Generic failure             */


#define DELETE(filename) unlink(filename)
#ifdef __STDC__
#undef DELETE
#define DELETE(filename) remove(filename)
#endif

#define RANGECHECK(idx,max) (idx)
