/* tailor.h -- target dependent definitions

   Copyright (C) 1997-1999, 2002, 2006, 2009-2016 Free Software Foundation,
   Inc.
   Copyright (C) 1992-1993 Jean-loup Gailly

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */

/* The target dependent definitions should be defined here only.
 * The target dependent functions should be defined in tailor.c.
 */

#if defined(__MSDOS__) && !defined(MSDOS)
#  define MSDOS
#endif

#if defined(__OS2__) && !defined(OS2)
#  define OS2
#endif

#if defined(OS2) && defined(MSDOS) /* MS C under OS/2 */
#  undef MSDOS
#endif

#ifdef MSDOS
#  ifdef __GNUC__
     /* DJGPP on MS-DOS. */
#    define near
#    ifndef HAVE_DIRENT_H
#      define HAVE_DIRENT_H
#    endif
#    ifndef HAVE_LIMITS_H
#      define HAVE_LIMITS_H
#    endif
#    ifndef HAVE_UNISTD_H
#      define HAVE_UNISTD_H
#    endif
#    define fcalloc(items,size) malloc((size_t)(items)*(size_t)(size))
#    define fcfree(ptr) free(ptr)
#    ifdef __DJGPP__
       /* DJGPP version 2.x or later supports long file names on Windows.  */
#      include <fcntl.h>
#      define LONG_FILE_NAMES
#      define HAVE_LONG_FILE_NAMES(f)  (_use_lfn(f))
#      define MAX_PATH_LEN             PATH_MAX
#      define MAX_EXT_CHARS            3
#      define MAX_SUFFIX               30
#      define OS_CODE                  (HAVE_LONG_FILE_NAMES(ifname) ? 0x0e : 0x00)
#      define NO_FSTAT
#      define PART_SEP              "._- "
       /* Function definition in tailor.c */
       void make_valid_dosw32_name(char *name);
#      define MAKE_LEGAL_NAME(name) make_valid_dosw32_name(name)
#    else /* DJGPP version 1.x */
       /* The DJGPP 1.09 stat() function must be upgraded before gzip will
        * fully work.
        */
#      define MAX_PATH_LEN  128
#      define NO_MULTIPLE_DOTS
#      define MAX_EXT_CHARS 3
#      define Z_SUFFIX "z"
#      define OS_CODE            0x00
#    endif
#  endif /* __GNUC__ */
#  define PATH_SEP2 '\\'
#  define PATH_SEP3 ':'
#  define PROTO
#  ifndef STDC_HEADERS
#    define STDC_HEADERS
#  endif
#  define casemap(c) tolow(c) /* Force file names to lower case */
#  include <io.h>
#  include <unistd.h>
   /* Do not ever switch console input into binary mode, even if
      they've said --force.  Doing so will attempt to read from
      the console with no echo and no way to signal EOF or even
      interrupt the program (since special characters like ^Z and ^C
      are not special in binary mode).  For all practical purposes,
      a program which does that, wedges the machine.
      If both stdin and stdout are the console device, don't switch
      stdout into binary mode either, since that will switch the
      console device into raw mode, with the same consequences as
      described above.  */
#  define SET_BINARY_MODE(fd) \
     {if (!isatty(fd) || (force && !isatty(fileno(stdin)))) setmode(fd, O_BINARY);}
#  if !defined(NO_ASM) && !defined(ASMV)
#    define ASMV
#  endif
#else /* !MSDOS */
#  define near
#endif

#ifdef OS2
#  define PATH_SEP2 '\\'
#  define PATH_SEP3 ':'
#  define MAX_PATH_LEN  260
#  ifdef OS2FAT
#    define NO_MULTIPLE_DOTS
#    define MAX_EXT_CHARS 3
#    define Z_SUFFIX "z"
#    define casemap(c) tolow(c)
#  endif
#  define STDC_HEADERS
#  define UNLINK_READONLY_BUG
#  include <io.h>
#  define OS_CODE  0x06
#  define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
#  ifdef _MSC_VER
#    define HAVE_SYS_UTIME_H
#    define MAXSEG_64K
#    undef near
#    define near _near
#  endif
#  ifdef __EMX__
#    define HAVE_SYS_UTIME_H
#    define EXPAND(argc,argv) \
       {_response(&argc, &argv); _wildcard(&argc, &argv);}
#  endif
#  ifdef __BORLANDC__
#    define HAVE_UTIME_H
#  endif
#  ifdef __ZTC__
#    define NO_DIR 1
#    include <dos.h>
#    define EXPAND(argc,argv) \
       {response_expand(&argc, &argv);}
#  endif
#endif

#ifdef WIN32 /* Windows NT */
#  define HAVE_SYS_UTIME_H
#  define PATH_SEP2 '\\'
#  define PATH_SEP3 ':'
#  define MAX_PATH_LEN  260
#  define STDC_HEADERS
#  define SET_BINARY_MODE(fd) setmode(fd, O_BINARY)
#  define UNLINK_READONLY_BUG
#  include <io.h>
#  include <malloc.h>
#  ifdef NTFAT
#    define NO_MULTIPLE_DOTS
#    define MAX_EXT_CHARS 3
#    define Z_SUFFIX "z"
#    define casemap(c) tolow(c) /* Force file names to lower case */
#  endif
#  define OS_CODE  0x0b
#endif

#ifndef MSDOS
#  ifdef MAXSEG_64K
#    define fcalloc(items,size) calloc((items),(size))
#  else
#    define fcalloc(items,size) malloc((size_t)(items)*(size_t)(size))
#  endif
#  define fcfree(ptr) free(ptr)
#endif

#if defined(VAXC) || defined(VMS)
#  define PATH_SEP ']'
#  define PATH_SEP2 ':'
#  define SUFFIX_SEP ';'
#  define NO_MULTIPLE_DOTS
#  define NO_SIZE_CHECK
#  define Z_SUFFIX "-gz"
#  define RECORD_IO 1
#  define casemap(c) tolow(c)
#  define OS_CODE  0x02
#  define OPTIONS_VAR "GZIP_OPT"
#  define STDC_HEADERS
#  define EXPAND(argc,argv) vms_expand_args(&argc,&argv);
#  include <file.h>
#  define unlink delete
#  ifdef VAXC
#    include <unixio.h>
#  endif
#endif

#ifdef AMIGA
#  define PATH_SEP2 ':'
#  define STDC_HEADERS
#  define OS_CODE  0x01
#  define ASMV
#  ifdef __GNUC__
#    define HAVE_CHOWN
#    define HAVE_LSTAT
#  else /* SASC */
#    define HAVE_SYS_DIR_H
#    include <fcntl.h> /* for read() and write() */
#    define direct dirent
     extern void _expand_args(int *argc, char ***argv);
#    define EXPAND(argc,argv) _expand_args(&argc,&argv);
#  endif
#endif

#if defined(ATARI) || defined(atarist)
#  define ASMV
#  define OS_CODE  0x05
#  ifdef TOSFS
#    define PATH_SEP2 '\\'
#    define PATH_SEP3 ':'
#    define MAX_PATH_LEN  128
#    define NO_MULTIPLE_DOTS
#    define MAX_EXT_CHARS 3
#    define Z_SUFFIX "z"
#    define casemap(c) tolow(c) /* Force file names to lower case */
#  endif
#endif

#ifdef TOPS20
#  define OS_CODE  0x0a
#endif

#ifndef SIGPIPE
# define SIGPIPE 0
#endif


        /* Common defaults */

#ifndef OS_CODE
#  define OS_CODE  0x03  /* assume Unix */
#endif

#ifndef PATH_SEP
#  define PATH_SEP '/'
#endif

#ifndef casemap
#  define casemap(c) (c)
#endif

#ifndef OPTIONS_VAR
#  define OPTIONS_VAR "GZIP"
#endif

#ifndef Z_SUFFIX
#  define Z_SUFFIX ".gz"
#endif

#ifdef MAX_EXT_CHARS
#  ifndef MAX_SUFFIX
#    define MAX_SUFFIX  MAX_EXT_CHARS
#  endif
#else
#  define LONG_FILE_NAMES
#endif

#ifndef MAKE_LEGAL_NAME
#  ifdef NO_MULTIPLE_DOTS
#    define MAKE_LEGAL_NAME(name)   make_simple_name(name)
#  else
#    define MAKE_LEGAL_NAME(name)
#  endif
#endif

#ifndef MIN_PART
#  define MIN_PART 3
   /* keep at least MIN_PART chars between dots in a file name. */
#endif

#ifndef EXPAND
#  define EXPAND(argc,argv)
#endif

#ifndef RECORD_IO
#  define RECORD_IO 0
#endif

#ifndef SET_BINARY_MODE
#  define SET_BINARY_MODE(fd)
#endif
