home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / archiver / compres2 / compress.h < prev    next >
C/C++ Source or Header  |  1993-07-07  |  27KB  |  800 lines

  1. /*@H************************ < COMPRESS HEADER > ****************************
  2. *   $@(#) compress.c,v 4.3 88/12/26 08:00:00 don Release ^                  *
  3. *                                                                           *
  4. *   compress : compress.h <global defines, etc>                             *
  5. *                                                                           *
  6. *   port by  : Donald J. Gloistein                                          *
  7. *                                                                           *
  8. *   Source, Documentation, Object Code:                                     *
  9. *   released to Public Domain.  This code is based on code as documented    *
  10. *   below in release notes.                                                 *
  11. *                                                                           *
  12. *---------------------------  Module Description  --------------------------*
  13. *   THIS HEADER CONTAINS MUCH IMPLEMENTATION INFORMATION AND ASSUMPTIONS    *
  14. *   PLEASE PRINT IT OUT AND READ IT BEFORE COMPILING CODE FOR YOURSELF      *
  15. *                                                                           *
  16. *   This header supports a number of compiler defines and predefines.       *
  17. *   Rather than explain all of them, please print the header and read the   *
  18. *   notes. Also the unix and xenix makefiles are commented for the          *
  19. *   various options. There continues to have a lot of Dos specific info in  *
  20. *   the header. This is to help on 16 bit Msdos machines to get their       *
  21. *   compiler to work properly. I make no appology for that, as this port    *
  22. *   began as a way to implement 16 bit compress on a segmented MsDos machine*
  23. *                                                                           *
  24. *   However, for Unix and Xenix, all you should have to define is -DXENIX   *
  25. *   or -DUNIX and compile. There may be a problem with whether your library *
  26. *   supports alloc() or malloc(), but there is a define for that, also.     *
  27. *                                                                           *
  28. *   This header can be maintained to keep up with the different compilers   *
  29. *   and systems. As distributed in don Release, the files will compile with *
  30. *   no changes under Microsoft version 5.1 C compiler, and Xenix C compiler *
  31. *   which is the Microsoft version 4 ported. If you are going to bind the   *
  32. *   code for use in MsDos and OS/2 machines, then you must uncomment the    *
  33. *   #define BIND in this header. Otherwise, this distribution of source     *
  34. *   detect Msdos and Xenix predefines from the compiler and adjust.         *
  35. *                                                                           *
  36. *--------------------------- Implementation Notes --------------------------*
  37. *                                                                           *
  38. *   compiled with : compress.fns                                            *
  39. *
  40. *   NOTE!!!  Defaults of this code now are completely Unix, even for the    *
  41. *            msdos ports.  That means that the program works as a filter,   *
  42. *            and will just sit there waiting for input from stdin if you    *
  43. *            issue just the command name. You must use -h or -? to get the  *
  44. *            full help screen now. Also, it will unlink (kill) as a default *
  45. *            on successful compression and decompression. That means the    *
  46. *            source file will be erased.                                    *
  47. *            These defaults are changed with the FILTER and KEEPFLAG        *
  48. *            defines.                                                       *
  49. *                                                                           *
  50. *   NOTE!!!  Compiler predefines were taken out of the compress.h header.   *
  51. *            You must either specify them on compile or uncomment the       *
  52. *            compiler define in this header. Compiling without doing these  *
  53. *            will result in a program that does unspecified actions.        *
  54. *   problems:                                                               *
  55. *            The inpath and outpath is a bit kludged. It should work okay.  *
  56. *            Let me know if you have problems, especially under Unix.       *
  57. *                                                                           *
  58. *   CAUTION: The bound version will run on Dos 2.x, but you must use the    *
  59. *            name compress.exe.  If you rename the file, it will not run    *
  60. *            The unbound version will run on Dos 2.x with the name changed  *
  61. *            but due to the dos version, will not detect its own name.      *
  62. *                                                                           *
  63. *   CAUTION: Non MsDos users. You must modify the _MAX_PATH defines for     *
  64. *            your operating system if it is different from the assumed      *
  65. *            standard.                                                      *
  66. *                                                                           *
  67. *   CAUTION: I have used a number of defines to make it possible to compile *
  68. *            properly under a number of bit sizes and adjust for the memory *
  69. *            allocation scheme needed. If you do not use a dos system,      *
  70. *            PLEASE pay attention to the defines for MAXSEG_64 and the one  *
  71. *            called SMALLMODEL. The SMALLMODEL define is set in the header  *
  72. *            but if you don't have a compiler that triggers the MAXSEG_64   *
  73. *            define, you may end up with bad pointers. Becareful.           *
  74. *                                                                           *
  75. *   Header for files using version 4 compress routines define MAIN          *
  76. *   in the file with defining instance of the global variables.             *
  77. *   There are a number of compilers for MsDos and Unix/Xenix.               *
  78. *   So the user must define the actions required.                           *
  79. *                                                                           *
  80. *                                                                           *
  81. *   Defines:  This header file contains most of the system wide defines.    *
  82. *             the purpose for this was to consolodate compiler differences  *
  83. *             into one area that is easily changed.                         *
  84. *                                                                           *
  85. *   define MAXBITS= if you want a different maximum bits. 16 bits will now  *
  86. *   run in about 400K of memory.                                            *
  87. *   define BIND if you are going to use Microsoft bind.exe program on the   *
  88. *   executable.                                                             *
  89. *                                                                           *
  90. *   define MSDOS if you are compiling under MsDos or PcDos and your compiler*
  91. *   does not predefine it.                                                  *
  92. *                                                                           *
  93. *     Initials ---- Name ---------------------------------                  *
  94. *      DjG          Donald J. Gloistein, current port to MsDos 16 bit       *
  95. *                   Plus many others, see rev.hst file for full list        *
  96. *      LvR          Lyle V. Rains, many thanks for improved implementation  *
  97. *                   of the compression and decompression routines.          *
  98. *************************************************************************@H*/
  99.  
  100. #ifndef FALSE            /* let's get some sense to this */
  101. #define FALSE 0
  102. #define TRUE !FALSE
  103. #endif
  104.  
  105.  
  106.  
  107. #ifdef UNIX
  108. #define NPROTO
  109. #define COMP40           /* take this out for a little more speed */
  110. #ifdef ALLOC
  111. char *alloc();
  112. #define ALLOCATE(x,y)   alloc((unsigned int)x*y)
  113. #else
  114. char *malloc();
  115. #define ALLOCATE(x,y)   malloc((unsigned int)x*y)
  116. #endif
  117. #define FREEIT(ptr)     free(ptr)
  118. #define setbinary(fp)
  119. #define NO_SETVBUF      /* most don't support setvbuf() function */
  120. #endif
  121.  
  122.             /* NOTE: This program will not work on the */
  123.             /* IBM/PC version of MINIX due to the small */
  124.             /* memory model restrictions.  There is no */
  125.             /* such thing as a FAR pointer in MINIX-PC */
  126. #ifdef MINIX        /* Unix V7 clone for Atari ST */
  127. #define    strchr    index
  128. #define    strrchr    rindex
  129. #define DFLTBITS 13    /* compatible with original MINIX compress, max=16 */
  130. #ifndef KEEPFLAG
  131. #define    KEEPFLAG 1    /* compatible with original MINIX compress */
  132.             /* may be redefined from the Makefile if desired */
  133. #endif
  134. #ifndef VERBOSE
  135. #define    VERBOSE TRUE    /* compatible with original MINIX compress */
  136.             /* may be redefined from the Makefile if desired */
  137. #endif
  138. #define NPROTO
  139. #define SIGTYPE int    /* MINIX defines this as pointer to int */
  140.             /* for the return from a signal         */
  141. #endif
  142.  
  143.                           /* Microsoft C compiler  v 4.0-5.1 */
  144.                           /* MSC is defined in makefile.msc        */
  145. #ifdef MSC
  146. #define FAR far        
  147. #define MAXSEG_64K
  148. #define NO_REVSEARCH
  149. #define CONST const
  150. #define ALLOCTYPE void
  151. #ifdef M_I86SM
  152. #define SMALLMODEL        /* compiled in small model */
  153. #endif
  154. #define setbinary(fp)    setmode(fileno((fp)), O_BINARY)
  155. #endif
  156.  
  157.                           /* Mark Williams C for Atari ST (V3.0.5) */
  158.                           /* MWC is defined in makefile.mwc        */
  159. #ifdef MWC
  160. #define MSDOS
  161. #define NOSIGNAL
  162. #define DFLTBITS 14
  163. #define NPROTO
  164. /* #define MAXSEG_64K */  /* use this if your compiler has a problem with */
  165.                           /* indexing arrays larger than 64k              */
  166. #define NO_SETVBUF
  167. #define NO_REVSEARCH
  168. #define ALLOCATE(x,y)   lcalloc((unsigned long)(x),((unsigned long)(unsigned)(y)))
  169. #define FREEIT(ptr)     free(ptr)
  170. #define setbinary(fp)    ((fp)->_ff &= ~_FASCII)
  171. #endif
  172.  
  173.                           /* Sozobon or Alcyon (4.14) C for Atari ST */
  174.                           /* used with the dLibs standard library    */
  175. #ifdef ALCYON
  176. #define    SOZOBON    1
  177. #endif
  178. #ifdef SOZOBON
  179. #define MSDOS
  180. #define NOSIGNAL
  181. #define DFLTBITS 14
  182. #define NPROTO
  183. /* #define MAXSEG_64K */  /* use this if your compiler has a problem with */
  184.                           /* indexing arrays larger than 64k              */
  185. #define ALLOCATE(x,y)   lalloc((unsigned long)(x) * ((unsigned long)(y)))
  186. #define FREEIT(ptr)     free(ptr)
  187. #define setbinary(fp)    ((fp)->_flag |= _IOBIN)
  188. #define    FILTER    FALSE
  189. #endif
  190.  
  191.                           /* Gnu C compiler for Atari TOS           */
  192.                           /* __GNUC_TOS__ is defined in makefile    */
  193. #ifdef __GNUC_TOS__
  194. #define MSDOS        /* follow MSDOS file naming conventions */
  195. #define NOSIGNAL    /* do not undef this, bombs (i dont know why!) */
  196. #define CONST const
  197. #define ALLOCTYPE void
  198. #define DFLTBITS 16
  199.                           /* indexing arrays larger than 64k              */
  200. #define ALLOCATE(x,y)   calloc((size_t)(x),(size_t)(y))
  201. #define FREEIT(ptr)     free(ptr)
  202. #define setbinary(fp)    ((fp)->_flag |= _IOBIN)
  203. #endif /* __GNUC_TOS__ */
  204.  
  205.  
  206. #ifdef __ZTC__                 /* Zortech compiler           */
  207. #define setbinary(fp)    ((fp)->_flag&=~_IOTRAN)
  208. #define NO_REVSEARCH
  209. #define CONST const
  210. #define MAXSEG_64K
  211. #endif
  212.  
  213. #ifdef XENIX
  214. #define setbinary(fp)
  215. #define FAR far
  216. #define CONST
  217. #define SIGTYPE int           /* xenix defines this as pointer to int */
  218.                               /* for the return from a signal         */
  219. #ifdef M_I286
  220. #define MAXSEG_64K
  221. #endif
  222. #define NO_SETVBUF            /* evidently xenix chokes on the large buff*/
  223. #endif                        /* really needs to be fine tuned           */
  224.  
  225. #ifdef MCH_AMIGA
  226. #define CONST
  227. #define MAXSEG_64K             /* Manx C compiler limitation */
  228. #define NO_SETVBUF
  229. #endif
  230.  
  231. #ifdef vms
  232. #define NO_SETVBUF
  233. #endif
  234.  
  235. #ifdef __TURBOC__
  236. #define MSDOS
  237. #define MAXSEG_64
  238. #define NO_REVSEARCH
  239. #ifdef __SMALL__
  240. #define SMALLMODEL
  241. #endif
  242. #define CONST const
  243. #define FAR             far
  244. #define setbinary(fp)   setmode(fileno((fp)), O_BINARY)
  245. #endif
  246.  
  247. /* FILTER  if you want the program to operate as a unix type filter */
  248. /*  if not defined TRUE, then issuing command without parameters will */
  249. /*  print a usage and help information                              */
  250. /*  Use -DFILTER=0 to deactivate filter operation                   */
  251. #ifndef FILTER
  252. #define FILTER  TRUE
  253. #endif
  254.  
  255. /* KEEPFLAG determines the default action on successful completion */
  256. /* Unix convention is FALSE (erase input file)                     */
  257. /* Use -DKEEPFLAG=1 to keep files as default or change here        */
  258. /* if you don't set it before here and you are compiling the debug */
  259. /* version, then files will be kept.                               */
  260.  
  261. #ifndef KEEPFLAG
  262. #ifdef NDEBUG
  263. #define KEEPFLAG FALSE
  264. #else
  265. #define KEEPFLAG TRUE
  266. #endif
  267. #endif
  268.  
  269.  
  270. /* Does your compiler support extended prototyping?  */
  271. /* Uncomment the following if your compiler does not.*/
  272. /* support full prototyping, such as:                */
  273. /*      char *emalloc(unsigned,int);                 */
  274. /* if defined it will use the following:             */
  275. /*      char *emalloc();                             */
  276. /* #define NPROTO */
  277.  
  278. /* putting the include files in one location */
  279.  
  280. #include <ctype.h>
  281.  
  282. #ifdef MINIX
  283. #define    assert(x)
  284. extern char *index(), *rindex(), *strcat(), *strcpy(), *strncat(), *strncpy();
  285. #else
  286. #include <assert.h>
  287. #include <string.h>
  288. #endif
  289.  
  290. #ifndef NOSIGNAL
  291. #include <signal.h>
  292. #endif
  293.  
  294. #ifdef MWC
  295. #include <stdlib.h>
  296. #include <types.h>
  297. #include <stat.h>
  298. #else
  299. #ifdef SOZOBON
  300. #include <stdio.h>
  301. #include <stat.h>
  302. #include <limits.h>
  303. #include <malloc.h>
  304. #include <errno.h>
  305. #else
  306. #ifdef __GNUC_TOS__
  307. #include <stddef.h>
  308. #include <stdlib.h>
  309. #include <stdio.h>
  310. #include <types.h>
  311. #include <stat.h>
  312. #include <errno.h>
  313. #include <unixlib.h>
  314. #include <memory.h>
  315. #include <fcntl.h>
  316. #include <limits.h>
  317. #include <time.h>
  318. #else
  319. #include <sys/types.h>
  320. #include <sys/stat.h>
  321. #endif
  322. #endif
  323. #endif
  324.  
  325. #ifdef M_XENIX
  326. #include <fcntl.h>
  327. #endif
  328.  
  329.  
  330. #ifdef MSC
  331. #include <stdlib.h>
  332. #include <io.h>
  333. #include <sys/utime.h>
  334. #include <fcntl.h>
  335. #include <limits.h>
  336. #endif
  337.  
  338. #ifdef __TURBOC__
  339. #include <stdlib.h>
  340. #include <io.h>
  341. #include <fcntl.h>
  342. #include <limits.h>
  343. #endif
  344.  
  345. #ifndef NOSIGNAL
  346. #ifndef SIGTYPE
  347. #define SIGTYPE void
  348. #endif
  349. #ifndef SIG_ERR
  350. #define SIG_ERR (SIGTYPE(*)())-1
  351. #endif
  352. #endif
  353.  
  354. /* This is for Microsoft C v5.1 to compile and be bound  */
  355. /* for use with os/2.  Also if compiled just for os/2    */
  356. /* The signal function is different between protected    */
  357. /* and real mode.                                        */
  358.  
  359. /* #define BIND */
  360.  
  361. #ifdef INCL_DOSPROCESS
  362. #define ISOS2 TRUE
  363. #endif
  364.  
  365. #ifdef BIND
  366. #define ISOS2 TRUE
  367. #endif
  368.  
  369. /*  The following is defined in MSC 5.1 stdlib.h
  370.     Replace with appropriate values for your system.
  371.     These values are used for MSDos system.
  372. */
  373. #ifndef _MAX_PATH
  374. #define _MAX_PATH  144      /* max. length of full pathname       */
  375. #define _MAX_DRIVE   3      /* max. length of drive component     */
  376. #define _MAX_DIR   130      /* max. length of path component      */
  377. #define _MAX_FNAME   9      /* max. length of file name component */
  378. #define _MAX_EXT     5      /* max. length of extension component */
  379. #endif
  380.  
  381. /* the following tells the system that the maximum segment is 64k */
  382. /* if your compiler is not one of these and has this limitation   */
  383. /* Because of this, this code should compile with minimum porting */
  384. /* in the COMPUSI.XEN module to most unix systems.                */
  385. /* This is also used to keep array indexing to 16 bit integer     */
  386. /* if not predefined in compiler implementation, you must define  */
  387. /* it separately if applicable to your compiler/system            */
  388. /* #define MAXSEG_64K                                             */
  389.  
  390. /* put this in if you are compiling in small code */
  391. /* model and your compiler does not predefine it  */
  392. /* this is for CPU' with 64k segment limitation.  */
  393. /* Use this define for small code, it is used by  */
  394. /* the header to decide on value for NEARHEAP     */
  395. /* #define SMALLMODEL */
  396.  
  397. /* does your system use far pointers ? if you want it enabled keep this */
  398. /* if you have segment limit and compile in larger than 13 bits         */
  399. /* then you will have to use compact or large model if your compiler    */
  400. /* does not support far pointer keyword.                                */
  401.  
  402. #ifndef FAR
  403. #define FAR
  404. #endif
  405.  
  406. /* What type does the alloc() function return, char or void? */
  407.  
  408. #ifndef ALLOCTYPE
  409. #define ALLOCTYPE char
  410. #endif
  411.  
  412. /* If you use compusi.dos and your computer supports the unix */
  413. /* file links and the link code is set properly in the stat() */
  414. /* then define the following:                                 */
  415. /* #define USE_LINKS */
  416.  
  417. /* Does your run time library support the ANSI functions for:*/
  418.  
  419. /* reverse string set search?  strrpbrk() if so:             */
  420. /*#define NO_REVSEARCH*//* dos module uses this function. */
  421. /* #define NO_REVSEARCH */
  422.  
  423. /* Does your library include strrchr()? If not define this:  */
  424. /*#define NO_STRRCHR*//* unix/xenix module uses this function*/
  425.  
  426. /* Does your library include strchr()? If not define this:   */
  427. /*#define NO_STRCHR*//* dos module uses this function.       */
  428.  
  429. /* definition for const key word if supported */
  430. #ifndef CONST
  431. #define CONST
  432. #endif
  433.  
  434.  
  435. /*  And now for some typedefs */
  436. typedef unsigned short CODE;
  437. typedef unsigned char UCHAR;
  438. typedef unsigned int HASH;
  439. typedef int FLAG;
  440.  
  441.   /* 
  442.    * You can define the value of MAXBITS to be anything betweeen MINBITS
  443.    * and MAXMAXBITS.  This is will determine the maximum memory you will
  444.    * use and how the tables will be handled.  I recommend you just leave
  445.    * it at MAXMAXBITS, because you can define DFLTBITS in compiling the
  446.    * module COMPRESS.C to set the default, and you can vary the number
  447.    * of bits at runtime by using the -b switch.
  448.    */
  449.  
  450.    /*
  451.    * The only reason to change MAXBITS is if you absolutely must have
  452.    * faster performance. If you specify 14 bits, the tables will not
  453.    * be split; at 13 bits, you can fit in the MSDOS small memory model
  454.    * and allocate tables in near heap.
  455.    * This value is available to other modules through the variable maxbits.
  456.    */
  457.  
  458. #define INITBITS    9
  459. #define MINBITS     12
  460. #define MAXMAXBITS  16
  461.  
  462. #ifndef MAXBITS
  463. #define MAXBITS    MAXMAXBITS
  464. #endif
  465.  
  466. #if (MAXBITS > MAXMAXBITS)
  467. #undef MAXBITS
  468. #define MAXBITS    MAXMAXBITS
  469. #endif
  470.  
  471. #if (MAXBITS < MINBITS)
  472. #undef MAXBITS
  473. #define MAXBITS  MINBITS
  474. #endif
  475.  
  476.   /* You should define DFLTBITS to be the default compression code
  477.    * bit length you desire on your system.
  478.    * (I define mine in the compiler command line in my Makefile.LvR)
  479.    * (I leave mine alone and keep to the maximum. DjG)
  480.    */
  481.  
  482. #ifndef DFLTBITS
  483. #define DFLTBITS MAXBITS
  484. #endif
  485. #if (DFLTBITS < MINBITS)
  486. #undef DFLTBITS
  487. #define DFLTBITS MINBITS
  488. #endif
  489. #if (DFLTBITS > MAXBITS)
  490. #undef DFLTBITS
  491. #define DFLTBITS MAXBITS
  492. #endif
  493.  
  494. /* THIS IS TO COMPILE A 13 BIT MODEL IN SMALL MEMORY AND NEAR HEAP */
  495. /* AS SET UP IT WILL WORK WITH MICROSOFT C COMPILER                */
  496.  
  497. #if (MAXBITS < 14)
  498. #ifdef SMALLMODEL
  499. #define NEARHEAP TRUE
  500. #undef FAR
  501. #define FAR
  502. #endif
  503. #endif
  504.  
  505. /* correcting for different types of pointer arithmatic */
  506. /* probably won't have to change it                     */
  507. #define NULLPTR(type)   ((type FAR *) NULL)
  508.  
  509.  
  510. /* in making this program portable the following allocation and          */
  511. /* free functions are called, with the following parameters:             */
  512. /*        ALLOCTYPE FAR *emalloc(unsigned int x, int y)                  */
  513. /*                 void  efree(ALLOCTYPE FAR *ptr)                       */
  514. /* you must define the allocation function and the free function         */
  515. /* keep in mind that the casts must be correct for your compiler         */
  516. /* NOTE these are the two functions to change for allocating pointers to */
  517. /* far data space if you are not using Microsoft C v.5.1                 */
  518. /* Consult your compiler manual and find the low level function that     */
  519. /* returns a far pointer when compiled in the small model.               */
  520. /* if your compiler does not support that, you will have to compile with */
  521. /* a model that defaults to far pointers to data (compact or large model)*/
  522. /* HERE ARE SOME SAMPLE PREDEFINED ONES                                  */
  523.  
  524. #ifdef MSC
  525. #include <malloc.h>
  526. #ifdef NEARHEAP
  527. #define ALLOCATE(x,y)   malloc((size_t)((x)*(y)))
  528. #define FREEIT(ptr)     free((ptr))
  529. #else
  530. #define ALLOCATE(x,y)   _fmalloc((size_t)((x)*(y)))
  531. #define FREEIT(ptr)     _ffree((ptr))
  532. #endif
  533. #endif
  534.  
  535. #ifdef HUGE
  536. #include <malloc.h>
  537. #define ALLOCATE(x,y)   halloc((long)(x),(size_t)(y))
  538. #define FREEIT(ptr)     hfree(ptr)
  539. #endif
  540.  
  541. #ifdef __TURBOC__
  542. #include <alloc.h>
  543. #ifdef NEARHEAP
  544. #define ALLOCATE(x,y)  malloc((unsigned int)((x)*(y)))
  545. #define FREEIT(x)      free(x)
  546. #else
  547. #define ALLOCATE(x,y)  farmalloc((unsigned long)((x)*(y)))
  548. #define FREEIT(x)    farfree(x)
  549. #endif
  550. #endif
  551.  
  552. /* default allocation function, in segmented addressing, must return */
  553. /* a far pointer or compile with far pointer data as default         */
  554. #ifndef ALLOCATE
  555. #include <malloc.h>
  556. #define ALLOCATE(x,y)   malloc((unsigned int)x*y)
  557. #define FREEIT(ptr)     free((ptr))
  558. #endif
  559.  
  560.  
  561. # ifdef MAXSEG_64K
  562. #   if  MAXBITS > 14
  563. #       define SPLIT_HT   TRUE
  564. #   else
  565. #       define SPLIT_HT   0
  566. #   endif
  567. # else
  568. #   define SPLIT_HT   0
  569. # endif
  570.  
  571. # ifdef MAXSEG_64K
  572. #   if  MAXBITS > 15
  573. #       define SPLIT_PFX   TRUE
  574. #   else
  575. #       define SPLIT_PFX   0
  576. #   endif
  577. # else
  578. #   define SPLIT_PFX   0
  579. # endif
  580.  
  581. #ifndef BUFSIZ
  582. #define BUFSIZ 512
  583. #endif
  584.  
  585. #ifdef NO_SETBUF
  586. #define NO_SETVBUF
  587. #endif
  588.  
  589. #ifdef NO_SETVBUF
  590. #   ifndef NO_SETBUF
  591. #       define setvbuf(fp,buf,mode,size) setbuf((fp),(buf))
  592. #       define ZBUFSIZE BUFSIZ
  593. #       define XBUFSIZE BUFSIZ
  594. #   else
  595. #       define setvbuf(fp,buf,mode,size)
  596. #       define ZBUFSIZE (1)
  597. #       define XBUFSIZE (1)
  598. #   endif
  599. #else
  600. #   ifdef NEARHEAP
  601. #       define XBUFSIZE    (0xC00)
  602. #       define ZBUFSIZE    (0x1800)
  603. #   else
  604. #       define XBUFSIZE    (0x3000)      /* 12k bytes */
  605. #       define ZBUFSIZE    (0x6000)      /* 24k bytes */
  606. #   endif
  607. #endif
  608.  
  609. #define UNUSED      ((CODE)0)   /* Indicates hash table value unused    */
  610. #define CLEAR       ((CODE)256) /* Code requesting table to be cleared  */
  611. #define FIRSTFREE ((CODE)(CLEAR+1))/* First free code for token encoding */
  612. #define MAXTOKLEN   512         /* Max chars in token; size of buffer   */
  613. #define OK          0           /* Result codes from functions:         */
  614. #ifdef vms
  615. #define ERROR       0x10000004  /* General unspecified error            */
  616. #define NORMAL      1           /* No error                             */
  617. #define unlink(x)   remove(x)
  618. #else
  619. #    define NORMAL      0
  620. #    ifdef ERROR
  621. #        if (ERROR == NORMAL)
  622. #            define ERROR   1    /* force redefine if (ERROR == NORMAL)  */
  623. #        endif
  624. #    else
  625. #        define ERROR       1
  626. #    endif
  627. #endif
  628. #define SIGNAL_ERROR -1         /*   signal function error              */
  629. #define NOMEM       2           /*   Ran out of memory                  */
  630. #define TOKTOOBIG   3           /*   Token longer than MAXTOKLEN chars  */
  631. #define READERR     4           /*   I/O error on input                 */
  632. #define WRITEERR    5           /*   I/O error on output                */
  633. #define INFILEBAD   6           /*   Infile not in compressed format    */
  634. #define CODEBAD     7           /*   Infile contained a bad token code  */
  635. #define TABLEBAD    8           /*   The tables got corrupted (!)       */
  636. #define NOSAVING    9           /*   no saving in file size             */
  637. #define NOTOPENED  10           /*   output file couldn't be opened     */
  638. #define YES         1
  639. #define NO          0
  640.  
  641.  
  642. #include "compress.fns"
  643.  
  644. /* defines opening mode for files */
  645. /* and suffixes for compressed file */
  646.  
  647. #ifdef MSDOS
  648. #define WRITE_FILE_TYPE "wb"
  649. #define READ_FILE_TYPE "rb"
  650. #define SUFFIX "Z"
  651. #else
  652. #ifdef vms
  653. #define SUFFIX "_Z"
  654. #define WRITE_FILE_TYPE "wb"
  655. #define READ_FILE_TYPE "rb"
  656. #else
  657. #define WRITE_FILE_TYPE "w"
  658. #define READ_FILE_TYPE "r"
  659. #define SUFFIX ".Z"
  660. #endif
  661. #endif
  662.  
  663.  
  664. /* The VERBOSE flag defines the default value of the verbose variable */
  665. /* If it's not already defined, we set it to FALSE here since most */
  666. /* systems set the default that way.  -Dal */
  667. #ifndef VERBOSE
  668. #define    VERBOSE    FALSE
  669. #endif
  670.  
  671.  
  672. /* Defines for third byte of header */
  673. #define BIT_MASK    0x1f
  674. #define BLOCK_MASK  0x80
  675. /* Masks 0x40 and 0x20 are free.  I think 0x20 should mean that there is
  676.    a fourth header byte (for expansion).
  677. */
  678.  
  679.  
  680. #define CHECK_GAP 10000L     /* ratio check interval */
  681.  
  682. #ifdef MAIN
  683. UCHAR magic_header[] = { 0x1F,0x9D };  /* 1F 9D */
  684.  
  685. char rcs_ident[] = "@(#) compress,v 4.3 88/12/26 08:00:00 don Release $";
  686.  
  687. #ifdef MWC
  688. long _stksize = 20000L;     /* set MWC's stack to 20,000 */
  689. #ifdef MWC_NAME           /* if defined in makefile set _cmdname for */
  690. char _cmdname[]=MWC_NAME;   /* compress,zcat,uncomp check for desktop and */
  691. #endif                      /* dumb shells */
  692. #endif
  693. #ifdef SOZOBON
  694. long _STKSIZ = 20000L;        /* set runtime stack to 20,000 bytes */
  695. #ifndef CMDNAME
  696. #define    CMDNAME "compress"
  697. #endif
  698. char _cmdname[]=CMDNAME;    /* force command name */
  699. #endif
  700.  
  701. #ifdef __GNUC_TOS__
  702. long _stksize = 20000L;     /* set GNU's stack to 20,000 */
  703. char _cmdname[]="compress";   /* compress,zcat,uncomp check for desktop and */
  704. #endif                      /* dumb shells */
  705.  
  706. int overwrite = 0;          /* Do not overwrite unless given -f flag */
  707. int maxbits = DFLTBITS;     /* user settable max # bits/code */
  708.  
  709. int exit_stat = 0;
  710. int keep = KEEPFLAG;            /* True = don't kill file */
  711. int keep_error = FALSE;     /* True = keep output file even if error exist */
  712. char *prog_name;
  713. char ifname[_MAX_DIR];
  714. char inpath[_MAX_DIR];
  715. char ofname [_MAX_DIR];
  716. char outpath[_MAX_DIR];
  717. int is_list = FALSE;            /* flag for file parameters */
  718. char endchar[1];
  719. char xbuf[XBUFSIZE];
  720. char zbuf[ZBUFSIZE];
  721. #ifdef MSDOS
  722. char separator[] = "\\";
  723. #else
  724. char separator[] = "/";
  725. #endif
  726. int nomagic = FALSE;  /* Use a 3-byte magic number header, unless old file */
  727. int zcat_flg = FALSE; /* Write output on stdout, suppress messages */
  728. int quiet = !VERBOSE; /* don't tell me about compression */
  729. /*
  730.  * block compression parameters -- after all codes are used up,
  731.  * and compression rate changes, start over.
  732.  */
  733. int block_compress = BLOCK_MASK;
  734. #ifdef COMP40
  735. long int ratio = 0L;
  736. long checkpoint = CHECK_GAP;
  737. #endif
  738.  
  739. /* force the overwrite */
  740. int force = 0;
  741.  
  742. #ifndef NDEBUG
  743. int verbose = VERBOSE;
  744. int debug = FALSE;
  745. #endif /* !NDEBUG */
  746.  
  747. #ifndef NOSIGNAL
  748. SIGTYPE (*bgnd_flag)();
  749. #endif
  750.  
  751. int do_decomp = FALSE;
  752.  
  753. #else               /* not defining instance */
  754.  
  755. extern UCHAR magic_header[];
  756. extern char rcs_ident[];
  757. #ifdef MWC
  758. extern long _stksize;
  759. #endif
  760. #ifdef __GNUC_TOS__
  761. extern long _stksize;
  762. #endif
  763. extern int overwrite;
  764. extern int maxbits;
  765.  
  766.  
  767. extern int exit_stat;
  768. extern int keep;
  769. extern int keep_error;
  770. extern char *prog_name;
  771. extern char inpath[];
  772. extern char outpath[];
  773. extern int is_list;
  774. extern char endchar[];
  775. extern char xbuf[];
  776. extern char zbuf[];
  777. extern char ifname[];
  778. extern char ofname[];
  779. extern char separator[];
  780. extern int nomagic;
  781. extern int zcat_flg;
  782. extern int quiet;
  783. extern int block_compress;
  784. #ifdef COMP40
  785. extern long int ratio;
  786. extern long checkpoint;
  787. #endif
  788. extern int force;
  789.  
  790. #ifndef NDEBUG
  791. extern int verbose;
  792. extern int debug;
  793. #endif /* !NDEBUG */
  794.  
  795. #ifndef NOSIGNAL
  796. extern SIGTYPE (*bgnd_flag)();
  797. #endif
  798. extern int do_decomp;
  799. #endif
  800.