home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / source / shark.lzh / compress.h < prev    next >
C/C++ Source or Header  |  1990-11-12  |  23KB  |  809 lines

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