compress for uport

Dominick Samperi samperi at mancol.UUCP
Fri Feb 19 01:08:41 AEST 1988


The following patches for compress 4.0 will fix it for Microport's
System V/286. All but one of the patches are John Rupley's (thanks
John!). I had to add one patch (in the form of a type cast) to fix
a problem that came up when large files were compressed (usually
resulting in a Bus error). 

To apply the patches, change directory to the directory containing
compress.c (Version 4.0, as distributed), and type:
patch < file-containing-this-article. Here patch is Larry Walls
patch program. (No need to delete the headers from this article.)


*** compress4.0/compress.c	Sun Aug  9 13:18:18 1987
--- compress.c	Thu Feb 18 08:27:17 1988
***************
*** 1,6
  /* 
   * Compress - data compression program 
   */
  #define	min(a,b)	((a>b) ? b : a)
  
  /*

--- 1,34 -----
  /* 
   * Compress - data compression program 
   */
+ 
+ /*  Changes for sysV/286 - by John Rupley 12/5/87
+ *
+ *	cc -Ml ... ( UPORT_16 is defined below, for 16 bit compress)
+ *
+ *	John's original patches did not include the cast to long
+ *       that appears on line 803 below, and this led to problems
+ *       when large files were compressed. This patch was added by
+ *       Dominick Samperi, 2/18/88.
+ *
+ *
+ *
+ *
+ *
+ *
+ */
+ 
+ #define UPORT_16
+ 
+ #ifdef UPORT
+ #define BITS 13
+ #endif
+ 
+ #ifdef UPORT_16
+ #define BITS 16
+ #define XENIX_16
+ #define min(a,b)	(((long)a>(long)b) ? (long)b : (long)a)
+ #else
  #define	min(a,b)	((a>b) ? b : a)
  #endif
  
***************
*** 2,7
   * Compress - data compression program 
   */
  #define	min(a,b)	((a>b) ? b : a)
  
  /*
   * machine variants which require cc -Dmachine:  pdp11, z8000, pcxt

--- 30,36 -----
  #define min(a,b)	(((long)a>(long)b) ? (long)b : (long)a)
  #else
  #define	min(a,b)	((a>b) ? b : a)
+ #endif
  
  /*
   * machine variants which require cc -Dmachine:  pdp11, z8000, pcxt
***************
*** 71,76
  # endif BITS
  #endif /* PBITS */
  
  #if BITS == 16
  # define HSIZE	69001		/* 95% occupancy */
  #endif

--- 100,106 -----
  # endif BITS
  #endif /* PBITS */
  
+ 
  #if BITS == 16
  # define HSIZE	69001L		/* 95% occupancy */
  #endif
***************
*** 72,78
  #endif /* PBITS */
  
  #if BITS == 16
! # define HSIZE	69001		/* 95% occupancy */
  #endif
  #if BITS == 15
  # define HSIZE	35023		/* 94% occupancy */

--- 102,108 -----
  
  
  #if BITS == 16
! # define HSIZE	69001L		/* 95% occupancy */
  #endif
  #if BITS == 15
  # define HSIZE	35023L		/* 94% occupancy */
***************
*** 75,81
  # define HSIZE	69001		/* 95% occupancy */
  #endif
  #if BITS == 15
! # define HSIZE	35023		/* 94% occupancy */
  #endif
  #if BITS == 14
  # define HSIZE	18013		/* 91% occupancy */

--- 105,111 -----
  # define HSIZE	69001L		/* 95% occupancy */
  #endif
  #if BITS == 15
! # define HSIZE	35023L		/* 94% occupancy */
  #endif
  #if BITS == 14
  # define HSIZE	18013L		/* 91% occupancy */
***************
*** 78,84
  # define HSIZE	35023		/* 94% occupancy */
  #endif
  #if BITS == 14
! # define HSIZE	18013		/* 91% occupancy */
  #endif
  #if BITS == 13
  # define HSIZE	9001		/* 91% occupancy */

--- 108,114 -----
  # define HSIZE	35023L		/* 94% occupancy */
  #endif
  #if BITS == 14
! # define HSIZE	18013L		/* 91% occupancy */
  #endif
  #if BITS == 13
  # define HSIZE	9001L		/* 91% occupancy */
***************
*** 81,87
  # define HSIZE	18013		/* 91% occupancy */
  #endif
  #if BITS == 13
! # define HSIZE	9001		/* 91% occupancy */
  #endif
  #if BITS <= 12
  # define HSIZE	5003		/* 80% occupancy */

--- 111,117 -----
  # define HSIZE	18013L		/* 91% occupancy */
  #endif
  #if BITS == 13
! # define HSIZE	9001L		/* 91% occupancy */
  #endif
  #if BITS <= 12
  # define HSIZE	5003L		/* 80% occupancy */
***************
*** 84,90
  # define HSIZE	9001		/* 91% occupancy */
  #endif
  #if BITS <= 12
! # define HSIZE	5003		/* 80% occupancy */
  #endif
  
  #ifdef M_XENIX			/* Stupid compiler can't handle arrays with */

--- 114,120 -----
  # define HSIZE	9001L		/* 91% occupancy */
  #endif
  #if BITS <= 12
! # define HSIZE	5003L		/* 80% occupancy */
  #endif
  
  #ifdef M_XENIX			/* Stupid compiler can't handle arrays with */
***************
*** 263,269
  int n_bits;				/* number of bits/code */
  int maxbits = BITS;			/* user settable max # bits/code */
  code_int maxcode;			/* maximum code, given n_bits */
! code_int maxmaxcode = 1 << BITS;	/* should NEVER generate this code */
  #ifdef COMPATIBLE		/* But wrong! */
  # define MAXCODE(n_bits)	(1 << (n_bits) - 1)
  #else

--- 293,299 -----
  int n_bits;				/* number of bits/code */
  int maxbits = BITS;			/* user settable max # bits/code */
  code_int maxcode;			/* maximum code, given n_bits */
! code_int maxmaxcode = 1L << BITS;	/* should NEVER generate this code */
  #ifdef COMPATIBLE		/* But wrong! */
  # define MAXCODE(n_bits)	(1L << (n_bits) - 1)
  #else
***************
*** 265,271
  code_int maxcode;			/* maximum code, given n_bits */
  code_int maxmaxcode = 1 << BITS;	/* should NEVER generate this code */
  #ifdef COMPATIBLE		/* But wrong! */
! # define MAXCODE(n_bits)	(1 << (n_bits) - 1)
  #else
  # define MAXCODE(n_bits)	((1 << (n_bits)) - 1)
  #endif /* COMPATIBLE */

--- 295,301 -----
  code_int maxcode;			/* maximum code, given n_bits */
  code_int maxmaxcode = 1L << BITS;	/* should NEVER generate this code */
  #ifdef COMPATIBLE		/* But wrong! */
! # define MAXCODE(n_bits)	(1L << (n_bits) - 1)
  #else
  # define MAXCODE(n_bits)	((1L << (n_bits)) - 1)
  #endif /* COMPATIBLE */
***************
*** 267,273
  #ifdef COMPATIBLE		/* But wrong! */
  # define MAXCODE(n_bits)	(1 << (n_bits) - 1)
  #else
! # define MAXCODE(n_bits)	((1 << (n_bits)) - 1)
  #endif /* COMPATIBLE */
  
  #ifdef XENIX_16

--- 297,303 -----
  #ifdef COMPATIBLE		/* But wrong! */
  # define MAXCODE(n_bits)	(1L << (n_bits) - 1)
  #else
! # define MAXCODE(n_bits)	((1L << (n_bits)) - 1)
  #endif /* COMPATIBLE */
  
  #ifdef XENIX_16
***************
*** 279,285
  count_int htab5[8192];
  count_int htab6[8192];
  count_int htab7[8192];
! count_int htab8[HSIZE-65536];
  count_int * htab[9] = {
  	htab0, htab1, htab2, htab3, htab4, htab5, htab6, htab7, htab8 };
  

--- 309,315 -----
  count_int htab5[8192];
  count_int htab6[8192];
  count_int htab7[8192];
! count_int htab8[HSIZE-65536L];
  count_int * htab[9] = {
  	htab0, htab1, htab2, htab3, htab4, htab5, htab6, htab7, htab8 };
  
***************
*** 283,288
  count_int * htab[9] = {
  	htab0, htab1, htab2, htab3, htab4, htab5, htab6, htab7, htab8 };
  
  #define htabof(i)	(htab[(i) >> 13][(i) & 0x1fff])
  unsigned short code0tab[16384];
  unsigned short code1tab[16384];

--- 313,321 -----
  count_int * htab[9] = {
  	htab0, htab1, htab2, htab3, htab4, htab5, htab6, htab7, htab8 };
  
+ #ifdef UPORT_16
+ #define htabof(i)	(htab[((long)i) >> 13][((long)i) & 0x1fff])
+ #else
  #define htabof(i)	(htab[(i) >> 13][(i) & 0x1fff])
  #endif
  
***************
*** 284,289
  	htab0, htab1, htab2, htab3, htab4, htab5, htab6, htab7, htab8 };
  
  #define htabof(i)	(htab[(i) >> 13][(i) & 0x1fff])
  unsigned short code0tab[16384];
  unsigned short code1tab[16384];
  unsigned short code2tab[16384];

--- 317,324 -----
  #define htabof(i)	(htab[((long)i) >> 13][((long)i) & 0x1fff])
  #else
  #define htabof(i)	(htab[(i) >> 13][(i) & 0x1fff])
+ #endif
+ 
  unsigned short code0tab[16384];
  unsigned short code1tab[16384];
  unsigned short code2tab[16384];
***************
*** 292,297
  unsigned short * codetab[5] = {
  	code0tab, code1tab, code2tab, code3tab, code4tab };
  
  #define codetabof(i)	(codetab[(i) >> 14][(i) & 0x3fff])
  
  #else	/* Normal machine */

--- 327,335 -----
  unsigned short * codetab[5] = {
  	code0tab, code1tab, code2tab, code3tab, code4tab };
  
+ #ifdef UPORT_16
+ #define codetabof(i)	(codetab[((long)i) >> 14][((long)i) & 0x3fff])
+ #else
  #define codetabof(i)	(codetab[(i) >> 14][(i) & 0x3fff])
  #endif
  
***************
*** 293,298
  	code0tab, code1tab, code2tab, code3tab, code4tab };
  
  #define codetabof(i)	(codetab[(i) >> 14][(i) & 0x3fff])
  
  #else	/* Normal machine */
  count_int htab [HSIZE];

--- 331,337 -----
  #define codetabof(i)	(codetab[((long)i) >> 14][((long)i) & 0x3fff])
  #else
  #define codetabof(i)	(codetab[(i) >> 14][(i) & 0x3fff])
+ #endif
  
  #else	/* Normal machine */
  count_int htab [HSIZE];
***************
*** 314,319
  
  #define tab_prefixof(i)	codetabof(i)
  #ifdef XENIX_16
  # define tab_suffixof(i)	((char_type *)htab[(i)>>15])[(i) & 0x7fff]
  # define de_stack		((char_type *)(htab2))
  #else	/* Normal machine */

--- 353,361 -----
  
  #define tab_prefixof(i)	codetabof(i)
  #ifdef XENIX_16
+ #ifdef UPORT_16
+ #define  tab_suffixof(i)  ((char_type *)htab[((long)i)>>15])[((long)i) & 0x7fff]
+ #else
  # define tab_suffixof(i)	((char_type *)htab[(i)>>15])[(i) & 0x7fff]
  #endif
  # define de_stack		((char_type *)(htab2))
***************
*** 315,320
  #define tab_prefixof(i)	codetabof(i)
  #ifdef XENIX_16
  # define tab_suffixof(i)	((char_type *)htab[(i)>>15])[(i) & 0x7fff]
  # define de_stack		((char_type *)(htab2))
  #else	/* Normal machine */
  # define tab_suffixof(i)	((char_type *)(htab))[i]

--- 357,363 -----
  #define  tab_suffixof(i)  ((char_type *)htab[((long)i)>>15])[((long)i) & 0x7fff]
  #else
  # define tab_suffixof(i)	((char_type *)htab[(i)>>15])[(i) & 0x7fff]
+ #endif
  # define de_stack		((char_type *)(htab2))
  #else	/* Normal machine */
  # define tab_suffixof(i)	((char_type *)(htab))[i]
***************
*** 520,526
  
      if(maxbits < INIT_BITS) maxbits = INIT_BITS;
      if (maxbits > BITS) maxbits = BITS;
!     maxmaxcode = 1 << maxbits;
  
      if (*filelist != NULL) {
  	for (fileptr = filelist; *fileptr; fileptr++) {

--- 563,569 -----
  
      if(maxbits < INIT_BITS) maxbits = INIT_BITS;
      if (maxbits > BITS) maxbits = BITS;
!     maxmaxcode = 1L << maxbits;
  
      if (*filelist != NULL) {
  	for (fileptr = filelist; *fileptr; fileptr++) {
***************
*** 548,554
  		    maxbits = getchar();	/* set -b from file */
  		    block_compress = maxbits & BLOCK_MASK;
  		    maxbits &= BIT_MASK;
! 		    maxmaxcode = 1 << maxbits;
  		    if(maxbits > BITS) {
  			fprintf(stderr,
  			"%s: compressed with %d bits, can only handle %d bits\n",

--- 591,597 -----
  		    maxbits = getchar();	/* set -b from file */
  		    block_compress = maxbits & BLOCK_MASK;
  		    maxbits &= BIT_MASK;
! 		    maxmaxcode = 1L << maxbits;
  		    if(maxbits > BITS) {
  			fprintf(stderr,
  			"%s: compressed with %d bits, can only handle %d bits\n",
***************
*** 577,583
  		 * serve as upper bounds on the number of output codes. 
  		 */
  		hsize = HSIZE;
! 		if ( fsize < (1 << 12) )
  		    hsize = min ( 5003, HSIZE );
  		else if ( fsize < (1 << 13) )
  		    hsize = min ( 9001, HSIZE );

--- 620,626 -----
  		 * serve as upper bounds on the number of output codes. 
  		 */
  		hsize = HSIZE;
! 		if ( fsize < (1L << 12) )
  		    hsize = min ( 5003, HSIZE );
  		else if ( fsize < (1L << 13) )
  		    hsize = min ( 9001, HSIZE );
***************
*** 579,585
  		hsize = HSIZE;
  		if ( fsize < (1 << 12) )
  		    hsize = min ( 5003, HSIZE );
! 		else if ( fsize < (1 << 13) )
  		    hsize = min ( 9001, HSIZE );
  		else if ( fsize < (1 << 14) )
  		    hsize = min ( 18013, HSIZE );

--- 622,628 -----
  		hsize = HSIZE;
  		if ( fsize < (1L << 12) )
  		    hsize = min ( 5003, HSIZE );
! 		else if ( fsize < (1L << 13) )
  		    hsize = min ( 9001, HSIZE );
  		else if ( fsize < (1L << 14) )
  		    hsize = min ( 18013, HSIZE );
***************
*** 581,587
  		    hsize = min ( 5003, HSIZE );
  		else if ( fsize < (1 << 13) )
  		    hsize = min ( 9001, HSIZE );
! 		else if ( fsize < (1 << 14) )
  		    hsize = min ( 18013, HSIZE );
  		else if ( fsize < (1 << 15) )
  		    hsize = min ( 35023, HSIZE );

--- 624,630 -----
  		    hsize = min ( 5003, HSIZE );
  		else if ( fsize < (1L << 13) )
  		    hsize = min ( 9001, HSIZE );
! 		else if ( fsize < (1L << 14) )
  		    hsize = min ( 18013, HSIZE );
  		else if ( fsize < (1L << 15) )
  		    hsize = min ( 35023, HSIZE );
***************
*** 583,589
  		    hsize = min ( 9001, HSIZE );
  		else if ( fsize < (1 << 14) )
  		    hsize = min ( 18013, HSIZE );
! 		else if ( fsize < (1 << 15) )
  		    hsize = min ( 35023, HSIZE );
  		else if ( fsize < 47000 )
  		    hsize = min ( 50021, HSIZE );

--- 626,632 -----
  		    hsize = min ( 9001, HSIZE );
  		else if ( fsize < (1L << 14) )
  		    hsize = min ( 18013, HSIZE );
! 		else if ( fsize < (1L << 15) )
  		    hsize = min ( 35023, HSIZE );
  		else if ( fsize < 47000 )
  		    hsize = min ( 50021, HSIZE );
***************
*** 666,672
  		maxbits = getchar();	/* set -b from file */
  		block_compress = maxbits & BLOCK_MASK;
  		maxbits &= BIT_MASK;
! 		maxmaxcode = 1 << maxbits;
  		fsize = 100000;		/* assume stdin large for USERMEM */
  		if(maxbits > BITS) {
  			fprintf(stderr,

--- 709,715 -----
  		maxbits = getchar();	/* set -b from file */
  		block_compress = maxbits & BLOCK_MASK;
  		maxbits &= BIT_MASK;
! 		maxmaxcode = 1L << maxbits;
  		fsize = 100000;		/* assume stdin large for USERMEM */
  		if(maxbits > BITS) {
  			fprintf(stderr,
***************
*** 757,763
  #endif
  	in_count++;
  	fcode = (long) (((long) c << maxbits) + ent);
!  	i = ((c << hshift) ^ ent);	/* xor hashing */
  
  	if ( htabof (i) == fcode ) {
  	    ent = codetabof (i);

--- 800,807 -----
  #endif
  	in_count++;
  	fcode = (long) (((long) c << maxbits) + ent);
!  	i = (((long) c << hshift) ^ ent);	/* xor hashing */
! 	/*      ^ Rupley forgot this cast, resulting in i < 0. */	
  
  	if ( htabof (i) == fcode ) {
  	    ent = codetabof (i);
***************
*** 1177,1183
      exit( 0 );
  }
  
! code_int sorttab[1<<BITS];	/* sorted pointers into htab */
  
  dump_tab()	/* dump string table */
  {

--- 1221,1227 -----
      exit( 0 );
  }
  
! code_int sorttab[1L<<BITS];	/* sorted pointers into htab */
  
  dump_tab()	/* dump string table */
  {
***************
*** 1181,1186
  
  dump_tab()	/* dump string table */
  {
      register int i, first;
      register ent;
  #define STACK_SIZE	15000

--- 1225,1234 -----
  
  dump_tab()	/* dump string table */
  {
+ #ifdef UPORT_16
+     long i, first ;
+     long ent ;
+ #else
      register int i, first;
      register ent;
  #endif
***************
*** 1183,1188
  {
      register int i, first;
      register ent;
  #define STACK_SIZE	15000
      int stack_top = STACK_SIZE;
      register c;

--- 1231,1237 -----
  #else
      register int i, first;
      register ent;
+ #endif
  #define STACK_SIZE	15000
      int stack_top = STACK_SIZE;
      register c;
***************
*** 1202,1208
  		de_stack[--stack_top] = '"';
  		stack_top = in_stack((htabof(sorttab[i])>>maxbits)&0xff, 
                                       stack_top);
! 		for(ent=htabof(sorttab[i]) & ((1<<maxbits)-1);
  		    ent > 256;
  		    ent=htabof(sorttab[ent]) & ((1<<maxbits)-1)) {
  			stack_top = in_stack(htabof(sorttab[ent]) >> maxbits,

--- 1251,1257 -----
  		de_stack[--stack_top] = '"';
  		stack_top = in_stack((htabof(sorttab[i])>>maxbits)&0xff, 
                                       stack_top);
! 		for(ent=htabof(sorttab[i]) & ((1L<<maxbits)-1);
  		    ent > 256;
  		    ent=htabof(sorttab[ent]) & ((1L<<maxbits)-1)) {
  			stack_top = in_stack(htabof(sorttab[ent]) >> maxbits,
***************
*** 1204,1210
                                       stack_top);
  		for(ent=htabof(sorttab[i]) & ((1<<maxbits)-1);
  		    ent > 256;
! 		    ent=htabof(sorttab[ent]) & ((1<<maxbits)-1)) {
  			stack_top = in_stack(htabof(sorttab[ent]) >> maxbits,
  						stack_top);
  		}

--- 1253,1259 -----
                                       stack_top);
  		for(ent=htabof(sorttab[i]) & ((1L<<maxbits)-1);
  		    ent > 256;
! 		    ent=htabof(sorttab[ent]) & ((1L<<maxbits)-1)) {
  			stack_top = in_stack(htabof(sorttab[ent]) >> maxbits,
  						stack_top);
  		}
***************
*** 1460,1465
  version()
  {
  	fprintf(stderr, "%s\n", rcs_ident);
  	fprintf(stderr, "Options: ");
  #ifdef vax
  	fprintf(stderr, "vax, ");

--- 1509,1515 -----
  version()
  {
  	fprintf(stderr, "%s\n", rcs_ident);
+ 	fprintf(stderr, "\tModified for Microport SysV/286, 12/5/87\n") ;
  	fprintf(stderr, "Options: ");
  #ifdef vax
  	fprintf(stderr, "vax, ");
***************
*** 1471,1476
  	fprintf(stderr, "SIGNED_COMPARE_SLOW, ");
  #endif
  #ifdef XENIX_16
  	fprintf(stderr, "XENIX_16, ");
  #endif
  #ifdef COMPATIBLE

--- 1521,1529 -----
  	fprintf(stderr, "SIGNED_COMPARE_SLOW, ");
  #endif
  #ifdef XENIX_16
+ #ifdef UPORT_16
+ 	fprintf(stderr, "UPORT_16, ") ;
+ #else
  	fprintf(stderr, "XENIX_16, ");
  #endif
  #endif
***************
*** 1472,1477
  #endif
  #ifdef XENIX_16
  	fprintf(stderr, "XENIX_16, ");
  #endif
  #ifdef COMPATIBLE
  	fprintf(stderr, "COMPATIBLE, ");

--- 1525,1531 -----
  	fprintf(stderr, "UPORT_16, ") ;
  #else
  	fprintf(stderr, "XENIX_16, ");
+ #endif
  #endif
  #ifdef COMPATIBLE
  	fprintf(stderr, "COMPATIBLE, ");
-- 
Dominick Samperi, Manhattan College, NYC
    manhat!samperi at NYU.EDU           ihnp4!rutgers!nyu.edu!manhat!samperi
    philabs!cmcl2!manhat!samperi     ihnp4!rutgers!hombre!samperi
              (^ that's an ell)      uunet!swlabs!mancol!samperi



More information about the Comp.unix.microport mailing list