compress.h

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 811 行 · 第 1/2 页

H
811
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


/*@H************************ < COMPRESS HEADER > ****************************
*   $@(#) compress.c,v 4.3 88/12/26 08:00:00 don Release ^                  *
*                                                                           *
*   compress : compress.h <global defines, etc>                             *
*                                                                           *
*   port by  : Donald J. Gloistein                                          *
*                                                                           *
*   Source, Documentation, Object Code:                                     *
*   released to Public Domain.  This code is based on code as documented    *
*   below in release notes.                                                 *
*                                                                           *
*---------------------------  Module Description  --------------------------*
*   THIS HEADER CONTAINS MUCH IMPLEMENTATION INFORMATION AND ASSUMPTIONS    *
*   PLEASE PRINT IT OUT AND READ IT BEFORE COMPILING CODE FOR YOURSELF      *
*                                                                           *
*   This header supports a number of compiler defines and predefines.       *
*   Rather than explain all of them, please print the header and read the   *
*   notes. Also the unix and xenix makefiles are commented for the          *
*   various options. There continues to have a lot of Dos specific info in  *
*   the header. This is to help on 16 bit Msdos machines to get their       *
*   compiler to work properly. I make no appology for that, as this port    *
*   began as a way to implement 16 bit compress on a segmented MsDos machine*
*                                                                           *
*   However, for Unix and Xenix, all you should have to define is -DXENIX   *
*   or -DUNIX and compile. There may be a problem with whether your library *
*   supports alloc() or malloc(), but there is a define for that, also.     *
*                                                                           *
*   This header can be maintained to keep up with the different compilers   *
*   and systems. As distributed in don Release, the files will compile with *
*   no changes under Microsoft version 5.1 C compiler, and Xenix C compiler *
*   which is the Microsoft version 4 ported. If you are going to bind the   *
*   code for use in MsDos and OS/2 machines, then you must uncomment the    *
*   #define BIND in this header. Otherwise, this distribution of source     *
*   detect Msdos and Xenix predefines from the compiler and adjust.         *
*                                                                           *
*--------------------------- Implementation Notes --------------------------*
*                                                                           *
*   compiled with : compress.fns                                            *
*
*   NOTE!!!  Defaults of this code now are completely Unix, even for the    *
*            msdos ports.  That means that the program works as a filter,   *
*            and will just sit there waiting for input from stdin if you    *
*            issue just the command name. You must use -h or -? to get the  *
*            full help screen now. Also, it will unlink (kill) as a default *
*            on successful compression and decompression. That means the    *
*            source file will be erased.                                    *
*            These defaults are changed with the FILTER and KEEPFLAG        *
*            defines.                                                       *
*                                                                           *
*   NOTE!!!  Compiler predefines were taken out of the compress.h header.   *
*            You must either specify them on compile or uncomment the       *
*            compiler define in this header. Compiling without doing these  *
*            will result in a program that does unspecified actions.        *
*   problems:                                                               *
*            The inpath and outpath is a bit kludged. It should work okay.  *
*            Let me know if you have problems, especially under Unix.       *
*                                                                           *
*   CAUTION: The bound version will run on Dos 2.x, but you must use the    *
*            name compress.exe.  If you rename the file, it will not run    *
*            The unbound version will run on Dos 2.x with the name changed  *
*            but due to the dos version, will not detect its own name.      *
*                                                                           *
*   CAUTION: Non MsDos users. You must modify the _MAX_PATH defines for     *
*            your operating system if it is different from the assumed      *
*            standard.                                                      *
*                                                                           *
*   CAUTION: I have used a number of defines to make it possible to compile *
*            properly under a number of bit sizes and adjust for the memory *
*            allocation scheme needed. If you do not use a dos system,      *
*            PLEASE pay attention to the defines for MAXSEG_64 and the one  *
*            called SMALLMODEL. The SMALLMODEL define is set in the header  *
*            but if you don't have a compiler that triggers the MAXSEG_64   *
*            define, you may end up with bad pointers. Becareful.           *
*                                                                           *
*   Header for files using version 4 compress routines define MAIN          *
*   in the file with defining instance of the global variables.             *
*   There are a number of compilers for MsDos and Unix/Xenix.               *
*   So the user must define the actions required.                           *
*                                                                           *
*                                                                           *
*   Defines:  This header file contains most of the system wide defines.    *
*             the purpose for this was to consolodate compiler differences  *
*             into one area that is easily changed.                         *
*                                                                           *
*   define MAXBITS= if you want a different maximum bits. 16 bits will now  *
*   run in about 400K of memory.                                            *
*   define BIND if you are going to use Microsoft bind.exe program on the   *
*   executable.                                                             *
*                                                                           *
*   define MSDOS if you are compiling under MsDos or PcDos and your compiler*
*   does not predefine it.                                                  *
*                                                                           *
*     Initials ---- Name ---------------------------------                  *
*      DjG          Donald J. Gloistein, current port to MsDos 16 bit       *
*                   Plus many others, see rev.hst file for full list        *
*      LvR          Lyle V. Rains, many thanks for improved implementation  *
*                   of the compression and decompression routines.          *
*************************************************************************@H*/

#ifndef FALSE            /* let's get some sense to this */
#define FALSE 0
#define TRUE !FALSE
#endif



#ifdef UNIX
#define NPROTO
#define COMP40           /* take this out for a little more speed */
#ifdef ALLOC
char *alloc();
#define ALLOCATE(x,y)   alloc((unsigned int)x*y)
#else
char *malloc();
#define ALLOCATE(x,y)   malloc((unsigned int)x*y)
#endif
#define FREEIT(ptr)     free(ptr)
#define setbinary(fp)
#define NO_SETVBUF      /* most don't support setvbuf() function */
#endif

                        /* NOTE: This program will not work on the */
                        /* IBM/PC version of MINIX due to the small */
                        /* memory model restrictions.  There is no */
                        /* such thing as a FAR pointer in MINIX-PC */
#ifdef MINIX            /* Unix V7 clone for Atari ST */
#define strchr  index
#define strrchr rindex
#define DFLTBITS 13     /* compatible with original MINIX compress, max=16 */
#ifndef KEEPFLAG
#define KEEPFLAG 1      /* compatible with original MINIX compress */
                        /* may be redefined from the Makefile if desired */
#endif
#ifndef VERBOSE
#define VERBOSE TRUE    /* compatible with original MINIX compress */
                        /* may be redefined from the Makefile if desired */
#endif
#define NPROTO
#define SIGTYPE int     /* MINIX defines this as pointer to int */
                        /* for the return from a signal         */
#endif

                          /* Microsoft C compiler  v 4.0-5.1 */
                          /* MSC is defined in makefile.msc        */
#ifdef MSC
#define FAR far
#define MAXSEG_64K
#define NO_REVSEARCH
#define CONST const
#define ALLOCTYPE void
#ifdef M_I86SM
#define SMALLMODEL        /* compiled in small model */
#endif
#define setbinary(fp)    setmode(fileno((fp)), O_BINARY)
#endif

                          /* Mark Williams C for Atari ST (V3.0.5) */
                          /* MWC is defined in makefile.mwc        */
#ifdef MWC
#define MSDOS
#define NOSIGNAL
#define DFLTBITS 14
#define NPROTO
/* #define MAXSEG_64K */  /* use this if your compiler has a problem with */
                          /* indexing arrays larger than 64k              */
#define NO_SETVBUF
#define NO_REVSEARCH
#define ALLOCATE(x,y)   lcalloc((unsigned long)(x),((unsigned long)(unsigned)(y)))
#define FREEIT(ptr)     free(ptr)
#define setbinary(fp)    ((fp)->_ff &= ~_FASCII)
#endif

                          /* Sozobon or Alcyon (4.14) C for Atari ST */
                          /* used with the dLibs standard library    */
#ifdef ALCYON
#define SOZOBON 1
#endif
#ifdef SOZOBON
#define MSDOS
#define NOSIGNAL
#define DFLTBITS 14
#define NPROTO
/* #define MAXSEG_64K */  /* use this if your compiler has a problem with */
                          /* indexing arrays larger than 64k              */
#define ALLOCATE(x,y)   lalloc((unsigned long)(x) * ((unsigned long)(y)))
#define FREEIT(ptr)     free(ptr)
#define setbinary(fp)    ((fp)->_flag |= _IOBIN)
#define FILTER  FALSE
#endif


#ifdef __ZTC__                 /* Zortech compiler           */
#define setbinary(fp)    ((fp)->_flag&=~_IOTRAN)
#define NO_REVSEARCH
#define CONST const
#define MAXSEG_64K
#endif

#ifdef XENIX
#define setbinary(fp)
#define FAR far
#define CONST
#define SIGTYPE int           /* xenix defines this as pointer to int */
                              /* for the return from a signal         */
#ifdef M_I286
#define MAXSEG_64K
#endif
#define NO_SETVBUF            /* evidently xenix chokes on the large buff*/
#endif                        /* really needs to be fine tuned           */

#ifdef MCH_AMIGA
#define CONST
#define MAXSEG_64K             /* Manx C compiler limitation */
#define NO_SETVBUF
#endif

#ifdef vms
#define NO_SETVBUF
#endif

#ifdef __TURBOC__
#define MSDOS
#define MAXSEG_64
#define NO_REVSEARCH
#ifdef __SMALL__
#define SMALLMODEL
#endif
#define CONST const
#define FAR             far
#define setbinary(fp)   setmode(fileno((fp)), O_BINARY)
#endif

#ifdef __WATCOMC__
#ifndef MSDOS
 #define MSDOS
#endif
#define NO_REVSEARCH
#define CONST const
#include <unistd.h>
#include <stdlib.h>
#if defined(__OS_qnx__) || defined(__OS_qnx16__)
 #include <utime.h>
#else
 #include <sys/utime.h>
#endif
#endif

/* FILTER  if you want the program to operate as a unix type filter */
/*  if not defined TRUE, then issuing command without parameters will */
/*  print a usage and help information                              */
/*  Use -DFILTER=0 to deactivate filter operation                   */
#ifndef FILTER
#define FILTER  TRUE
#endif

/* KEEPFLAG determines the default action on successful completion */
/* Unix convention is FALSE (erase input file)                     */
/* Use -DKEEPFLAG=1 to keep files as default or change here        */
/* if you don't set it before here and you are compiling the debug */
/* version, then files will be kept.                               */

#ifndef KEEPFLAG
#ifdef NDEBUG
#define KEEPFLAG FALSE
#else
#define KEEPFLAG TRUE
#endif
#endif


/* Does your compiler support extended prototyping?  */
/* Uncomment the following if your compiler does not.*/
/* support full prototyping, such as:                */
/*      char *emalloc(unsigned,int);                 */
/* if defined it will use the following:             */
/*      char *emalloc();                             */
/* #define NPROTO */

/* putting the include files in one location */

#include <ctype.h>

#ifdef MINIX
#define assert(x)
extern char *index(), *rindex(), *strcat(), *strcpy(), *strncat(), *strncpy();
#else
#include <assert.h>
#include <string.h>
#endif

#ifndef NOSIGNAL
#include <signal.h>
#endif

#ifdef MWC
#include <stdlib.h>
#include <types.h>
#include <stat.h>
#else
#ifdef SOZOBON
#include <stdio.h>
#include <stat.h>
#include <limits.h>
#include <malloc.h>
#include <errno.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif
#endif

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


#ifdef MSC
#include <stdlib.h>
#include <io.h>
#include <sys/utime.h>
#include <fcntl.h>
#include <limits.h>
#endif

#ifdef __TURBOC__
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <limits.h>
#endif

#ifndef NOSIGNAL
#ifndef SIGTYPE
#define SIGTYPE void
#endif
#ifndef SIG_ERR
#define SIG_ERR (SIGTYPE(*)())-1
#endif
#endif

/* This is for Microsoft C v5.1 to compile and be bound  */
/* for use with os/2.  Also if compiled just for os/2    */
/* The signal function is different between protected    */
/* and real mode.                                        */

/* #define BIND */

#ifdef INCL_DOSPROCESS
#define ISOS2 TRUE
#endif

#ifdef BIND
#define ISOS2 TRUE
#endif

/*  The following is defined in MSC 5.1 stdlib.h
    Replace with appropriate values for your system.
    These values are used for MSDos system.
*/
#ifndef _MAX_PATH
#define _MAX_PATH  144      /* max. length of full pathname       */
#define _MAX_DRIVE   3      /* max. length of drive component     */
#define _MAX_DIR   130      /* max. length of path component      */
#define _MAX_FNAME   9      /* max. length of file name component */
#define _MAX_EXT     5      /* max. length of extension component */
#endif

/* the following tells the system that the maximum segment is 64k */
/* if your compiler is not one of these and has this limitation   */
/* Because of this, this code should compile with minimum porting */
/* in the COMPUSI.XEN module to most unix systems.                */
/* This is also used to keep array indexing to 16 bit integer     */
/* if not predefined in compiler implementation, you must define  */
/* it separately if applicable to your compiler/system            */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?