home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / varia / pgp / pgpamiga / source / zipup.c < prev    next >
C/C++ Source or Header  |  1996-11-08  |  3KB  |  108 lines

  1. /*
  2.  
  3.  Copyright (C) 1990,1991 Mark Adler, Richard B. Wales, and Jean-loup Gailly.
  4.  Permission is granted to any individual or institution to use, copy, or
  5.  redistribute this software so long as all of the original files are included
  6.  unmodified, that it is not sold for profit, and that this copyright notice
  7.  is retained.
  8.  
  9. */
  10.  
  11. /*
  12.  *  zipup.c by Mark Adler. Includes modifications by Jean-loup Gailly.
  13.  */
  14.  
  15. #define NOCPYRT         /* this is not a main module */
  16. #include <ctype.h>
  17. #include <fcntl.h>
  18. #include "zip.h"
  19. #include "zrevisio.h"
  20.  
  21. /* Use the raw functions for MSDOS and Unix to save on buffer space.
  22.    They're not used for VMS since it doesn't work (raw is weird on VMS).
  23.    (This sort of stuff belongs in fileio.c, but oh well.) */
  24. #ifdef VMS
  25.    typedef FILE *ftype;
  26. #  define fhow FOPR
  27. #  define fbad NULL
  28. #  define zopen(n,p) fopen(n,p)
  29. #  define zread(f,b,n) fread(b,1,n,f)
  30. #  define zclose(f) fclose(f)
  31. #  define zerr(f) ferror(f)
  32. #  define zrew(f) rewind(f)
  33. #  define zstdin stdin
  34. #else /* !VMS */
  35. #  ifdef MSDOS
  36. #    include <io.h>
  37. #    include <fcntl.h>
  38. #    define fhow (O_RDONLY|O_BINARY)
  39. #  else /* !MSDOS */
  40. #ifndef AMIGA
  41.      long lseek();
  42. #endif /* AMIGA */
  43. #    define fhow 0
  44. #  endif /* ?MSDOS */
  45.    typedef int ftype;
  46. #  define fbad (-1)
  47. #  define zopen(n,p) open(n,p)
  48. #  define zread(f,b,n) read(f,b,n)
  49. #  define zclose(f) close(f)
  50. #  define zerr(f) (k==(extent)(-1L))
  51. #  define zrew(f) lseek(f,0L,0)
  52. #  define zstdin 0
  53. #endif /* ?VMS */
  54.  
  55. /* Local data */
  56.  
  57. local ftype ifile;        /* file to compress */
  58.  
  59. void lm_free(void);
  60. void ct_free(void);
  61.  
  62. int zipup(FILE *inFile, FILE *y)
  63. /* Compress the file fileName and write it to the file *y. Return an error
  64.    code in the ZE_ class.  Also, update tempzn by the number of bytes written. */
  65. /* ??? Does not yet handle non-seekable y */
  66. {
  67.   int m;                /* method for this entry */
  68.   long q = -1L;            /* size returned by filetime */
  69.   ush att;                /* internal file attributes (dummy only) */
  70.   ush flg;                /* gp compresion flags (dummy only) */
  71.  
  72.     /* Set input file and find its size */
  73. #ifdef VMS
  74.     ifile = inFile;
  75.     fseek(ifile, 0L, SEEK_END);
  76.     q = ftell(ifile);
  77.     fseek(ifile, 0L, SEEK_SET);
  78. #else
  79.     ifile = fileno( inFile );
  80.     q = lseek(ifile, 0L, SEEK_END);
  81.     lseek(ifile, 0L, SEEK_SET);
  82. #endif /* VMS */
  83.  
  84.     m = (q == 0) ? STORE : DEFLATE;
  85.  
  86.   if (m == DEFLATE) {
  87.      bi_init(y);
  88.          att = (ush) UNKNOWN;
  89.      ct_init(&att, &m);
  90.      lm_init(level, &flg);
  91.      /* s = */ deflate();
  92.   }
  93.   lm_free();
  94.   ct_free();
  95.  
  96.   return(0);
  97. }
  98.  
  99. int read_buf(buf, size)
  100.   char far *buf;
  101.   unsigned size;
  102. /* Read a new buffer from the current input file, and update the crc and
  103.  * input file size.
  104.  * IN assertion: size >= 2 (for end-of-line translation) */
  105. {
  106.   return ((int) (zread(ifile, buf, size)));
  107. }
  108.