Xref: icaen comp.sys.apple2:49166 comp.binaries.apple2:4001
Path: icaen!news.uiowa.edu!hobbes.physics.uiowa.edu!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsm!cbnewsl!att-out!pacbell.com!charon.amdahl.com!amdahl!fadden
From: fadden@uts.amdahl.com (Andy McFadden)
Newsgroups: comp.sys.apple2,comp.binaries.apple2
Subject: NuLib v3.24
Message-ID: <66Fd03Ovc8uE00@amdahl.uts.amdahl.com>
Date: 12 Jan 93 01:09:17 GMT
Reply-To: fadden@amdahl.uts.amdahl.com (Andy McFadden)
Followup-To: comp.sys.apple2
Organization: Amdahl Corporation, Sunnyvale CA
Lines: 319

Here's a quick little patch to bring NuLib v3.23 up to v3.24.  Only major
change is better handling of MS-DOS filenames (converts them to xxxxxxxx.yyy
format; NuLib was choking on x.y.z stuff).

Well, actually there was a fix to the LZW decoder, but nobody's complained
about it yet, so it's not a major problem. :-)


--- nublu.c
*** nublu.c	Tue Sep  8 16:10:45 1992
--- ../nublu.c	Mon Jan 11 14:40:35 1993
***************
*** 92,103 ****
  	while ((fname[i] = buf[4+i]) != '\0')
  	    i++;
  	offset = 5+i;  /* how far into file is end of filename? */
  	if (verbose) { printf("(as %s)...", fname);  fflush(stdout); }
      }
  
!     len = strlen(fname);
      for (j = 0; j < len; j++)
  	fname[j] &= 0x7f;	/* clear hi bits */
  
      if (Exists(fname)) {
  	if (interact) {
--- 92,108 ----
  	while ((fname[i] = buf[4+i]) != '\0')
  	    i++;
  	offset = 5+i;  /* how far into file is end of filename? */
+ 	ConvFileName(fname);
  	if (verbose) { printf("(as %s)...", fname);  fflush(stdout); }
      }
  
!     ConvFileName(fname);	/* strip hi bits, adjust special chars, etc */
!     len = strlen(fname);	/* (no longer used?) */
! 
! #ifdef FUBAR
      for (j = 0; j < len; j++)
  	fname[j] &= 0x7f;	/* clear hi bits */
+ #endif
  
      if (Exists(fname)) {
  	if (interact) {

--- nucomp.c
*** nucomp.c	Tue Sep  8 16:10:52 1992
--- ../nucomp.c	Mon Dec 21 21:58:37 1992
***************
*** 333,341 ****
      long srcposn, dstposn;
      static char *procName = "u_compress";
  
!     if ((srcposn = lseek(srcfd, (off_t) 0, S_REL)) < 0)
  	Fatal("Bad posn lseek(1)", procName);
!     if ((dstposn = lseek(dstfd, (off_t) 0, S_REL)) < 0)
  	Fatal("Bad posn lseek(2)", procName);
  
      src2 = dup(srcfd);
--- 333,341 ----
      long srcposn, dstposn;
      static char *procName = "u_compress";
  
!     if ((srcposn = (long) lseek(srcfd, (off_t) 0, S_REL)) < 0)
  	Fatal("Bad posn lseek(1)", procName);
!     if ((dstposn = (long) lseek(dstfd, (off_t) 0, S_REL)) < 0)
  	Fatal("Bad posn lseek(2)", procName);
  
      src2 = dup(srcfd);
***************
*** 348,356 ****
          Fatal("can't fdopen() nustdout", procName);
      setvbuf(nustdin,xbuf,_IOFBF,XBUFSIZE);  /* make the buffers larger */
      setvbuf(nustdout,zbuf,_IOFBF,ZBUFSIZE);	/* (note setvbuf is a macro) */
!     if (fseek(nustdin, srcposn, S_ABS) < 0)	/* seek may not be needed */
  	Fatal("Bad stream posn lseek(1)", procName);
!     if (fseek(nustdout, dstposn, S_ABS) < 0)
  	Fatal("Bad stream posn lseek(2)", procName);
  
      oldbits = 0;	/* init for putcode() */
--- 348,356 ----
          Fatal("can't fdopen() nustdout", procName);
      setvbuf(nustdin,xbuf,_IOFBF,XBUFSIZE);  /* make the buffers larger */
      setvbuf(nustdout,zbuf,_IOFBF,ZBUFSIZE);	/* (note setvbuf is a macro) */
!     if (fseek(nustdin, (off_t)srcposn, S_ABS) < 0)	/* seek may not be needed */
  	Fatal("Bad stream posn lseek(1)", procName);
!     if (fseek(nustdout, (off_t)dstposn, S_ABS) < 0)
  	Fatal("Bad stream posn lseek(2)", procName);
  
      oldbits = 0;	/* init for putcode() */
***************
*** 687,695 ****
      long srcposn, dstposn;
      static char *procName = "u_decompress";
  
!     if ((srcposn = lseek(srcfd, (off_t) 0, S_REL)) < 0)
  	Fatal("Bad posn lseek(1)", procName);
!     if ((dstposn = lseek(dstfd, (off_t) 0, S_REL)) < 0)
  	Fatal("Bad posn lseek(2)", procName);
  
      src2 = dup(srcfd);
--- 687,695 ----
      long srcposn, dstposn;
      static char *procName = "u_decompress";
  
!     if ((srcposn = (long)lseek(srcfd, (off_t) 0, S_REL)) < 0)
  	Fatal("Bad posn lseek(1)", procName);
!     if ((dstposn = (long)lseek(dstfd, (off_t) 0, S_REL)) < 0)
  	Fatal("Bad posn lseek(2)", procName);
  
      src2 = dup(srcfd);
***************
*** 702,710 ****
          Fatal("can't fdopen() nustdout", procName);
      setvbuf(nustdin,zbuf,_IOFBF,ZBUFSIZE);  /* make the buffers larger */
      setvbuf(nustdout,xbuf,_IOFBF,XBUFSIZE); /* (note order diff from comp) */
!     if (fseek(nustdin, srcposn, S_ABS) < 0)	/* seek may not be needed */
  	Fatal("Bad stream posn lseek(1)", procName);
!     if (fseek(nustdout, dstposn, S_ABS) < 0)
  	Fatal("Bad stream posn lseek(2)", procName);
  
      /* Check the magic number */
--- 702,710 ----
          Fatal("can't fdopen() nustdout", procName);
      setvbuf(nustdin,zbuf,_IOFBF,ZBUFSIZE);  /* make the buffers larger */
      setvbuf(nustdout,xbuf,_IOFBF,XBUFSIZE); /* (note order diff from comp) */
!     if (fseek(nustdin, (off_t)srcposn, S_ABS) < 0)	/* seek may not be needed */
  	Fatal("Bad stream posn lseek(1)", procName);
!     if (fseek(nustdout, (off_t)dstposn, S_ABS) < 0)
  	Fatal("Bad stream posn lseek(2)", procName);
  
      /* Check the magic number */


--- nuext.c
*** nuext.c	Tue Sep  8 16:11:15 1992
--- ../nuext.c	Mon Jan 11 14:38:19 1993
***************
*** 87,93 ****
  #ifdef UNIX
  
      while (*str != '\0') {
! 	if ((*str > 127) || (*str < 0)) *str &= 0x7f;  /* clear hi bit */
  	if (*str == '/') *str = '.';
  	if (++idx > 255) { *str = '\0'; break; }	/* MAXNAMELEN? */
  	str++;
--- 87,93 ----
  #ifdef UNIX
  
      while (*str != '\0') {
! 	*str &= 0x7f;  /* clear hi bit */
  	if (*str == '/') *str = '.';
  	if (++idx > 255) { *str = '\0'; break; }	/* MAXNAMELEN? */
  	str++;
***************
*** 98,103 ****
--- 98,104 ----
  	"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.";
  
      /* assumes ProDOS limits, not GS/OS */
+     *str &= 0x7f;
      if ( ((*str < 'A') && (*str > 'Z'))  ||  ((*str < 'a') && (*str > 'z')) )
  	*str = 'X';  /* must start with alpha char */
      while (*str != '\0') {
***************
*** 107,120 ****
      }
  # endif /* APW */
  # ifdef MSDOS
      while (*str != '\0') {
!        if ((*str > 127) || (*str < 0)) *str &= 0x7f;  /* clear hi bit */
         if (*str == '/') *str = '_';
         if (*str == '\\') *str = '_';
         if (*str == '!') *str = '_';
         if (*str == ':') *str = '_';
         if (++idx > 255) { *str = '\0'; break; }
         str++;
      }
  # endif /* MSDOS */
  
--- 108,142 ----
      }
  # endif /* APW */
  # ifdef MSDOS
+     char *ostr = str, *prev_dot = NULL;
+ 
      while (*str != '\0') {
!        *str &= 0x7f;  /* clear hi bit */
         if (*str == '/') *str = '_';
         if (*str == '\\') *str = '_';
         if (*str == '!') *str = '_';
         if (*str == ':') *str = '_';
+        if (*str == '.') {
+ 	   if (prev_dot != NULL) *prev_dot = '_';
+ 	   prev_dot = str;
+ 	}
         if (++idx > 255) { *str = '\0'; break; }
         str++;
+     }
+     /* now limit the chars before the '.' to 8, and after to 3 */
+     /* (if no dot, cut it at 8) */
+     if (prev_dot == NULL) {
+ 	if (strlen(str) > 8) str[8] = '\0';
+     } else {
+ 	*prev_dot = '\0';
+ 	if (strlen(prev_dot+1) > 3) *(prev_dot+4) = '\0';
+ 	if (strlen(ostr) > 8) {
+ 	    *prev_dot = '.';
+ 	    while (*prev_dot)
+ 		*((ostr++) + 8) = *(prev_dot++);
+ 	    *((ostr++) + 8) = *(prev_dot++);
+ 	} else
+ 	    *prev_dot = '.';
      }
  # endif /* MSDOS */
  

--- numain.c
*** numain.c	Mon Dec  7 15:45:01 1992
--- ../numain.c	Mon Dec 21 21:52:50 1992
***************
*** 9,15 ****
  #endif
  
  static char *header =
!  "NuLib v3.23  December 1992  Freeware   Copyright 1989-92 By Andy McFadden";
  
  #include "nudefs.h"	/* system-dependent defines */
  #include <stdio.h>	/* standard I/O library */
--- 9,15 ----
  #endif
  
  static char *header =
!  "NuLib v3.24  Januray 1993  Freeware   Copyright 1989-93 By Andy McFadden";
  
  #include "nudefs.h"	/* system-dependent defines */
  #include <stdio.h>	/* standard I/O library */

--- nupak.c
*** nupak.c	Tue Sep  8 16:11:25 1992
--- ../nupak.c	Mon Dec 21 21:52:15 1992
***************
*** 349,356 ****
  	maxbits = 16;	/* global compress parameter */
  	if (verbose) { printf("compressing...");  fflush(stdout); }
  	/* packedSize set by compress() */
! 	srcposn = lseek(srcfd, (off_t) 0, S_REL);	/* save posn */
! 	dstposn = lseek(dstfd, (off_t) 0, S_REL);
  	if (u_compress(srcfd, dstfd, length) == OK) {
  	    /* compress succeeded */
  	    retval = 0x0005;
--- 349,356 ----
  	maxbits = 16;	/* global compress parameter */
  	if (verbose) { printf("compressing...");  fflush(stdout); }
  	/* packedSize set by compress() */
! 	srcposn = (long) lseek(srcfd, (off_t) 0, S_REL);	/* save posn */
! 	dstposn = (long) lseek(dstfd, (off_t) 0, S_REL);
  	if (u_compress(srcfd, dstfd, length) == OK) {
  	    /* compress succeeded */
  	    retval = 0x0005;


--- nushk.c
*** nushk.c	Mon Dec  7 15:47:49 1992
--- ../nushk.c	Mon Jan 11 14:33:04 1993
***************
*** 594,600 ****
  /*	0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,4 };*/
  	8,9,10,10,11,11,11,11,12,12,12,12,12,12,12,12,12 };
  
! static onebyt Stack[100];  /* simulated stack; should be <= 64 */
  static int out_bytes, stack_ptr, entry, at_bit, at_byte;
  static onebyt last_byte;  /* used in get_code */
  static int reset_fix;	/* fix problem unpacking certain LZW-II archives */
--- 594,600 ----
  /*	0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,4 };*/
  	8,9,10,10,11,11,11,11,12,12,12,12,12,12,12,12,12 };
  
! static onebyt *Stack;	/* simulated stack <= 64 for LZW-I, <= 4096 for II */
  static int out_bytes, stack_ptr, entry, at_bit, at_byte;
  static onebyt last_byte;  /* used in get_code */
  static int reset_fix;	/* fix problem unpacking certain LZW-II archives */
***************
*** 610,617 ****
  #ifdef DEBUG
  # define push(a_byte) \
      { \
! 	if (stack_ptr - Stack > 100) { \
! 	    printf("\n*** stack_ptr exceeded 100 in push() [%d]\n", \
  		(int) (stack_ptr - Stack));\
  	    exit (-1); \
  	} \
--- 610,617 ----
  #ifdef DEBUG
  # define push(a_byte) \
      { \
! 	if (stack_ptr - Stack > 4096) { \
! 	    printf("\n*** stack_ptr exceeded 4096 in push() [%d]\n", \
  		(int) (stack_ptr - Stack));\
  	    exit (-1); \
  	} \
***************
*** 891,896 ****
--- 891,899 ----
      fourbyt tmp4;  /* temporary 4-byte variable */
      int cc;
      static char *procName = "unpak_SHK";
+ 
+     if (Stack == NULL)
+ 	Stack = (onebyt *) Malloc(4096);
  
      type2 = use_type2;
  

--- END ---


-- 
fadden@uts.amdahl.com (Andy McFadden)
[ Above opinions are mine, Amdahl has nothing to do with them, etc, etc. ]