home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zoo21-2.zip / source / zoofilt.c < prev    next >
C/C++ Source or Header  |  1992-09-20  |  2KB  |  90 lines

  1. /* derived from: zoofilt.c 1.8 88/01/30 23:47:05 */
  2.  
  3. #ifndef LINT
  4. static char sccsid[]="@(#) $Id: zoofilt.c,v 1.5 91/07/09 01:54:15 dhesi Exp $";
  5. #endif
  6.  
  7. /*
  8. (C) Copyright 1988 Rahul Dhesi -- All rights reserved
  9. (C) Copyright 1991 Rahul Dhesi -- All rights reserved
  10.  
  11. Filter mode -- compress or decompress standard input and write
  12. to standard output.
  13. */
  14.  
  15. #include "options.h"
  16.  
  17. #ifdef FILTER
  18.  
  19. #include "zoo.h"
  20. #include "zooio.h"
  21. #include "errors.i"
  22. #include "zoofns.h"
  23.  
  24. /* action */
  25. #define COMPRESS        0
  26. #define UNCOMPRESS    1
  27.  
  28. #define FTAG    ((unsigned int) 0x5a32)    /* magic number */
  29.  
  30. extern unsigned int crccode;
  31.  
  32. int rdint PARMS((unsigned int *));    /* read an unsigned int */
  33. int wrint PARMS((unsigned int));    /* write an unsigned int */
  34.  
  35. /* global variable used to pass two bytes (CRC value) back from lzd to here */
  36. unsigned int filt_lzd_word;
  37.  
  38. void zoofilt (option)
  39. char *option;
  40. {
  41.     int choice;                                            /* what to do -- [de]compress */
  42.     unsigned int filetag;                            /* tag stored in input */
  43.     int stat1, stat2, stat3;                        /* status codes */
  44.     int use_lzh = 0;                                    /* use lzh instead */
  45.     extern lzc(), lzh_encode();                    /* possible encoders */
  46.     extern lzd(), lzh_decode();                    /* and decoders */
  47.  
  48.     while (*++option) {
  49.         switch (*option) {
  50.             case 'c':    choice = COMPRESS;    break;
  51.             case 'u':    choice = UNCOMPRESS;  break;
  52.             case 'h':    use_lzh = 1; break;
  53.             default:
  54.                        prterror ('f', inv_option, *option);    /* fatal error -- abort */
  55.                 }
  56.     }
  57.  
  58.         MODE_BIN(stdin);
  59.         MODE_BIN(stdout);
  60.     crccode = 0;    /* needed whether compressing or uncompressing */
  61.  
  62.     switch (choice) {
  63.         case COMPRESS:
  64.             stat1 = wrint (FTAG);
  65.             stat2 = (use_lzh ? lzh_encode : lzc) (STDIN, STDOUT);
  66.             stat3 = wrint (crccode);
  67.             if (stat1 == 0 && stat2 == 0 && stat3 == 0)
  68.                 zooexit (0);
  69.             else {
  70.                 fprintf (stderr, "Zoo: FATAL: Compression error.\n");
  71.                 zooexit (1);
  72.             }
  73.             break;
  74.         case UNCOMPRESS:
  75.             stat1 = rdint (&filetag);
  76.             if (stat1 != 0 || filetag != FTAG)
  77.                 zooexit (1);
  78.             stat2 = (use_lzh ? lzh_decode : lzd) (STDIN, STDOUT);
  79.             if (stat2 == 0 && filt_lzd_word == crccode)
  80.                 zooexit (0);
  81.             else {
  82.                 fprintf (stderr, "Zoo: FATAL: Uncompression error.\n");
  83.                 zooexit (1);
  84.             }
  85.             break;
  86.     }
  87. } /* zoofilt */
  88.  
  89. #endif /* FILTER */
  90.