/*
 *                            S Y S T E M . H
 *
 *  Header file for EXPAND, a file maintenance utility to decompress files;
 *  compatible with the public domain COMPRESS utility (Rev. 4) by
 *  Spencer W. Thomas, et al.
 *
 *  This file contains definitions which may need to change for different
 *  systems and compilers.
 *-----------------------------------------------------------------------
 *  Author: Lyle V. Rains
 *-----------------------------------------------------------------------
 *  Revision History:
 */

#define YES         1
#define NO          0


#ifdef __MSDOS__
/* Turbo C */
# define MSDOS
#endif

#ifdef M_XENIX
# define CONST
# define FNAME_MONOCASE   NO
#endif

#ifdef MCH_AMIGA
# define CONST
# define PATHDELIM        ":/"
# define MAXNAMELEN       30
#endif

#ifndef CONST
# define CONST const
#endif

#ifndef FNAME_MONOCASE
# define FNAME_MONOCASE   YES
#endif

#ifndef PATHDELIM
# define PATHDELIM        "/"
#endif

#ifndef MAXNAMELEN
# define MAXNAMELEN       14
#endif

#ifdef EXPAND

  /* System dependencies in EXPAND.C and EXPAND.H */

  /* Machines/compilers with maximum 64k bytes per data object */

# ifdef MSDOS
/* Brain damaged CPU */
#   define MAXSEG_64K
# endif

# ifdef MCH_AMIGA
/* Manx C compiler has 64k-byte limit on objects */
#   define MAXSEG_64K
# endif

# ifdef M_I286
/* Xenix compiled for 286 */
#   define MAXSEG_64K
# endif

  /* 
   * You can define the value of MAXBITS to be anything betweeen INITBITS
   * and MAXMAXBITS.  This is will determine the maximum memory you will
   * use and how the tables will be handled.  I recommend you just leave
   * it at MAXMAXBITS.  The only reason to mess with this value is
   * if you absolutely must have faster performance.  If you specify
   * 15 bits, the pfx[] will not be split; at 14 bits, you can fit in
   * the MSDOS small memory model and allocate tables in near heap.
   * This value is available to other modules through the variable Maxbits.
   */

# ifndef MAXBITS
#   define MAXBITS    MAXMAXBITS
# endif
# if (MAXBITS > MAXMAXBITS)
#   undef MAXBITS
#   define MAXBITS    MAXMAXBITS
# endif
# if (MAXBITS < INITBITS)
#   undef MAXBITS
#   define MAXBITS    INITBITS
# endif

# define SPLIT_PFX  NO
# ifdef MAXSEG_64K
#   if (MAXBITS > 15)
#     undef SPLIT_PFX
#     define SPLIT_PFX  YES
#   endif
# endif

# ifdef MSC
#   if (MAXBITS > 14)
      /* MSC hack to use small memory model with explicit far pointers */
#     define FAR far
#     include <malloc.h>
#     define malloc(x)  _fmalloc(x)
#     define free(x)    _ffree(x)
#   else
#     include <stdlib.h>
#   endif
# endif

# ifdef __TURBOC__
#   if (MAXBITS > 14)
      /* Turbo C hack to use small memory model with explicit far pointers */
#     define FAR far
#     include <alloc.h>
#     define malloc(x)  farmalloc((unsigned long)x)
#     define free(x)    farfree(x)
#     define FAR far
#   else
#     include <stdlib.h>
#   endif
# endif

# ifdef __ZTC__
#   include <stdlib.h>
# endif

# ifdef MWC
#   include <stdlib.h>
#   define ALLOCTYPE  char
#   define MALLOCARG  unsigned long
#   define malloc(x)  lmalloc((MALLOCARG)(x))
# endif

# ifdef M_XENIX
#   include <malloc.h>
# endif

# ifdef MCH_AMIGA
#   define ALLOCTYPE char
    ALLOCTYPE * malloc();
# endif

# ifdef vms
#   include <stdlib.h>
# endif

  /* What pointer type does malloc() return?
   * What argument type does it take?
   */
# ifndef ALLOCTYPE
#   define ALLOCTYPE  void
# endif
# ifndef FAR
#   define FAR
# endif
# ifndef MALLOCARG
#   define MALLOCARG  unsigned int
# endif

#endif


#ifdef MAIN

  /* System dependencies in MAIN.C and MAIN.H */

# define FILTER     NO          /* Default action with no arguments     */
# define KILL       NO          /* Default delete action on input file  */

  /* You should define DFLTBITS to be the default compression code
   * bit length you desire on your system.
   * (I define mine in the compiler command line in my Makefile.)
   */

# define SW         '-'         /* Command line switch prefix character */
# define TO         '='         /* Command line output file prefix char */

# ifdef vms
#   define NORMAL   1           /* Normal return value for program      */
#   define ERROR    0x10000004  /* Error return value for program       */
#   define unlink   remove
# else
#   define NORMAL   0           /* Normal return value for program      */
#   define ERROR    1           /* Error return value for program       */
# endif

# define NAMEBUFSIZ 128         /* Size of filename buffer (with path)  */


# ifdef MWC
#   define NOSETVBUF
# endif

# ifdef vms
#   define NOSETVBUF
# endif

# ifdef MCH_AMIGA
#   define NOSETVBUF
# endif


# ifdef NOSETVBUF               /* No setvbuf() function                */
#   define setvbuf(fp, buf, mode, size)
#   define ZBUFSIZE (1)
#   define XBUFSIZE (1)
# else
#   define ZBUFSIZE (0x1400)    /* Bigger buffers for faster I/O        */
#   define XBUFSIZE (0xC00)
# endif

# ifdef MSC
#   include <fcntl.h>           /*   These are needed for setmode(),    */
#   include <io.h>              /*   used in the setbinary() macro.     */
#   define setbinary(fp)    setmode(fileno(fp), O_BINARY)
# endif

# ifdef __TURBOC__
#   include <fcntl.h>           /*   These are needed for setmode(),    */
#   include <io.h>              /*   used in the setbinary() macro.     */
#   define setbinary(fp)    setmode(fileno(fp), O_BINARY)
# endif

# ifdef __ZTC__
#   define setbinary(fp)    ((fp)->_flag&=~_IOTRAN)
# endif

# ifdef MWC
#   define setbinary(fp)    ((fp)->_ff &= ~_FASCII)
# endif

# ifndef setbinary
    /* Assume file access is always binary  */
#   define setbinary(fp)
# endif

#endif


#ifdef MSDOS
# define MSDOS_FNAMES
#endif

#ifdef MWC
# define MSDOS_FNAMES
#endif


/* Default suffix for compressed file   */
#ifdef MSDOS_FNAMES
# define ZSUFFIX    "Z"
#endif

#ifdef vms
# define ZSUFFIX    "_Z"
#endif

#ifndef ZSUFFIX
# define ZSUFFIX    ".Z"
#endif


#ifdef SYSTEM
# include <string.h>
# if FNAME_MONOCASE
#   include <ctype.h>
#   define CASE   tolower
# else
#   define CASE
# endif
#endif


/*
 * Externally visible objects in SYSTEM.C
 *    int to_xname(char *inname);
 *    void to_zname(char *inname);
 *    extern int eprintf(char *format, ...);
 *    extern int debug;
 */
int to_xname();
void to_zname();
extern int eprintf();

#ifndef DEBUGOUT
# define DEBUGOUT   1           /* Enable debug info output             */
#endif

#if DEBUGOUT
  extern int debug;
# define DBG(msg) (debug && eprintf msg)
#else
# define DBG(msg)
#endif

#define errexit(msg, exitval) (eprintf msg, exit(exitval))
