home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / compress / zoosrc20.zoo / zoofilt.c < prev    next >
C/C++ Source or Header  |  1989-07-25  |  2KB  |  84 lines

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