--- /tmp/bzip2-0.1pl2/bzip2.c	Sat Aug 30 00:32:15 1997
+++ /mnt/adfs/Hacking/bzip/c/bzip2	Sat Jan 17 10:57:48 1998
@@ -1,4 +1,3 @@
-
 /*-----------------------------------------------------------*/
 /*--- A block-sorting, lossless compressor        bzip2.c ---*/
 /*-----------------------------------------------------------*/
@@ -94,16 +93,20 @@
   Generic 32-bit Unix.
   Also works on 64-bit Unix boxes.
 --*/
-#define BZ_UNIX      1
+#define BZ_UNIX		0
 
 /*--
   Win32, as seen by Jacob Navia's excellent
   port of (Chris Fraser & David Hanson)'s excellent
   lcc compiler.
 --*/
-#define BZ_LCCWIN32  0
+#define BZ_LCCWIN32	0
 
+/*--
+  Acorn's RISC OS (currently requires unixlib & gcc)
+--*/
 
+#define BZ_RISCOS	1
 
 /*---------------------------------------------*/
 /*--
@@ -225,6 +228,48 @@
 
 #endif
 
+#if BZ_RISCOS
+   #define BZ_FILETYPE 0x16E
+
+   #include <sys/types.h>
+   #include <stdio.h>		/* required by tmpnam() */
+   #include <sys/os.h>		/* required by os_file() */
+   #include <utime.h>
+   #include <unistd.h>		/* can i narrow this down & remove it? */
+   #include <malloc.h>
+   #include <sys/stat.h>
+   #include <sys/times.h>
+
+   #define Int32   int
+   #define UInt32  unsigned int
+   #define Char    char
+   #define UChar   unsigned char
+   #define Int16   short
+   #define UInt16  unsigned short
+
+   #define PATH_SEP    '.'
+   #define MY_LSTAT    lstat
+   #define MY_S_IFREG  S_ISREG
+   #define MY_STAT     stat
+
+   #define APPEND_FILESPEC(root, name) \
+      root=snocString((root), (name))
+
+   #define SET_BINARY_MODE(fd) /**/
+
+   /*--
+      You should try very hard to persuade your C compiler
+      to inline the bits marked INLINE.  Otherwise bzip2 will
+      run rather slowly.  gcc version 2.x is recommended.
+   --*/
+   #ifdef __GNUC__
+      #define INLINE   inline
+      #define NORETURN __attribute__ ((noreturn))
+   #else
+      #define INLINE   /**/
+      #define NORETURN /**/
+   #endif
+#endif
 
 /*---------------------------------------------*/
 /*--
@@ -3276,10 +3321,16 @@
 /*---------------------------------------------*/
 Bool fileExists ( Char* name )
 {
+#ifdef BZ_RISCOS
+   int regs[6];
+   os_file( 17, name, regs );
+   return regs[0] & 1;
+#else
    FILE *tmp   = fopen ( name, "rb" );
    Bool exists = (tmp != NULL);
    if (tmp != NULL) fclose ( tmp );
    return exists;
+#endif
 }
 
 
@@ -3316,6 +3367,10 @@
    ERROR_IF_NOT_ZERO ( retVal );
    retVal = utime ( dstName, &uTimBuf );
    ERROR_IF_NOT_ZERO ( retVal );
+   #elif BZ_RISCOS
+   int regs [6];
+   os_file(17, srcName, regs);
+   os_file(1, dstName, regs);
    #endif
 }
 
@@ -3323,6 +3378,11 @@
 /*---------------------------------------------*/
 Bool endsInBz2 ( Char* name )
 {
+#ifdef BZ_RISCOS
+   int regs[6];
+   os_file(17, name, regs);
+   return (((regs[2] & 0x000fff00) >> 8) == BZ_FILETYPE);
+#else
    Int32 n = strlen ( name );
    if (n <= 4) return False;
    return
@@ -3330,6 +3390,7 @@
        name[n-3] == 'b' &&
        name[n-2] == 'z' &&
        name[n-1] == '2');
+#endif
 }
 
 
@@ -3354,12 +3415,19 @@
 
    switch (srcMode) {
       case SM_I2O: strcpy ( inName, "(stdin)" );
-                   strcpy ( outName, "(stdout)" ); break;
+                   strcpy ( outName, "(stdout)" );
+                   break;
       case SM_F2F: strcpy ( inName, name );
+#ifdef BZ_RISCOS
+		   tmpnam ( outName );
+#else
                    strcpy ( outName, name );
-                   strcat ( outName, ".bz2" ); break;
+                   strcat ( outName, ".bz2" );
+#endif
+		   break;
       case SM_F2O: strcpy ( inName, name );
-                   strcpy ( outName, "(stdout)" ); break;
+                   strcpy ( outName, "(stdout)" );
+                   break;
    }
 
    if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
@@ -3377,11 +3445,13 @@
                 progName, inName );
       return;
    }
+#ifndef BZ_RISCOS
    if ( srcMode != SM_I2O && notABogStandardFile ( inName )) {
       fprintf ( stderr, "%s: Input file %s is not a normal file, skipping.\n",
                 progName, inName );
       return;
    }
+#endif
    if ( srcMode == SM_F2F && fileExists ( outName ) ) {
       fprintf ( stderr, "%s: Output file %s already exists, skipping.\n",
                 progName, outName );
@@ -3459,6 +3529,14 @@
          IntNative retVal = remove ( inName );
          ERROR_IF_NOT_ZERO ( retVal );
       }
+#ifdef BZ_RISCOS
+      {
+         int regs[3];
+	 rename( outName, inName );
+	 regs[2] = BZ_FILETYPE;
+	 os_file( 18, inName, regs);
+      }
+#endif
    }
 }
 
@@ -3475,14 +3553,20 @@
 
    switch (srcMode) {
       case SM_I2O: strcpy ( inName, "(stdin)" );
-                   strcpy ( outName, "(stdout)" ); break;
+                   strcpy ( outName, "(stdout)" );
+                   break;
       case SM_F2F: strcpy ( inName, name );
+#ifdef BZ_RISCOS
+		   tmpnam( outName );
+#else
                    strcpy ( outName, name );
                    if (endsInBz2 ( outName ))
                       outName [ strlen ( outName ) - 4 ] = '\0';
+#endif
                    break;
       case SM_F2O: strcpy ( inName, name );
-                   strcpy ( outName, "(stdout)" ); break;
+                   strcpy ( outName, "(stdout)" );
+                   break;
    }
 
    if ( srcMode != SM_I2O && containsDubiousChars ( inName ) ) {
@@ -3501,11 +3585,13 @@
                 progName, inName );
       return;
    }
+#ifndef BZ_RISCOS
    if ( srcMode != SM_I2O && notABogStandardFile ( inName )) {
       fprintf ( stderr, "%s: Input file %s is not a normal file, skipping.\n",
                 progName, inName );
       return;
    }
+#endif
    if ( srcMode == SM_F2F && fileExists ( outName ) ) {
       fprintf ( stderr, "%s: Output file %s already exists, skipping.\n",
                 progName, outName );
@@ -3576,6 +3662,14 @@
             IntNative retVal = remove ( inName );
             ERROR_IF_NOT_ZERO ( retVal );
          }
+#ifdef BZ_RISCOS
+	 {
+	    int regs[3];
+	    rename( outName, inName );
+	    regs[2] = 0xffd;
+	    os_file( 18, inName, regs );
+	 }
+#endif
       }
    } else {
       if ( srcMode == SM_F2F ) {
@@ -3630,11 +3724,13 @@
                 progName, inName );
       return;
    }
+#ifndef BZ_RISCOS
    if ( srcMode != SM_I2O && notABogStandardFile ( inName )) {
       fprintf ( stderr, "%s: Input file %s is not a normal file, skipping.\n",
                 progName, inName );
       return;
    }
+#endif
 
    switch ( srcMode ) {
 
