home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsc / computils / !CompUtils / Resources / Compress / cc / c / Example
Encoding:
Text File  |  1996-04-01  |  2.7 KB  |  100 lines

  1. #include "CompUtils:Compress.cc.h.Type6"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. #define IBUFF    (10*1024)
  6. #define    OBUFF    (25*1024)
  7.  
  8. #define INFILE "RAM:$.infile"
  9. #define OUTFILE "RAM:$.outfile"
  10.  
  11. main()
  12. {
  13.     FILE *in, *out;
  14.  
  15.     /* Set up I/O buffers */
  16.     Compress_6_SrcBufferPtr = malloc(IBUFF);
  17.     Compress_6_DestBufferPtr = malloc(OBUFF);
  18.     Compress_6_SrcLength = IBUFF;
  19.     Compress_6_DestLength = OBUFF;
  20.  
  21.     /* Claim workspace */
  22.     if (Compress_6_GlobalLength)
  23.         Compress_6_GlobalPtr = malloc(Compress_6_GlobalLength);
  24.  
  25.     /* NB - this program assumes no errors occur */
  26.  
  27.     /* Set up reason code and output flags */
  28.     Compress_6_ReasonCode = 0;
  29.     Compress_6_Flags = OUTPUT_LINEAR; /* All other flags are off */
  30.  
  31.     /* Open source file */
  32.     in = fopen(INFILE, "rb");
  33.     if (in==NULL)
  34.     {
  35.         printf("Can't open input file '%s'\n",INFILE);
  36.         exit(1);
  37.     }
  38.     /* Open destination file */
  39.     out = fopen(OUTFILE, "wb");
  40.     if (out==NULL)
  41.     {
  42.         fclose(in);
  43.         printf("Can't open output file '%s'\n",OUTFILE);
  44.         exit(1);
  45.     }
  46.  
  47.     /* Get sample length and sample period */
  48.     fseek(in, 0, SEEK_END);
  49.     fgetpos(in, &Compress_6_SampleLength);
  50.     Compress_6_SampleLength--;
  51.     fseek(in, 0, SEEK_SET);
  52.     fread(&Compress_6_SamplePeriod, 1, 1, in);
  53.  
  54.     puts("Starting...\n");
  55.  
  56.     while (Compress_6() != 0)
  57.     {
  58.         /* A non-zero reason code, so some action must be taken */
  59.         printf("Reason code: %d\n",Compress_6_ReasonCode);
  60.         switch (Compress_6_ReasonCode)
  61.         {
  62.             case SRC_EMPTY:
  63.                 /* Refill the source buffer */
  64.                 fread(Compress_6_SrcBufferPtr, 1, Compress_6_SrcLength, in);
  65.                 break;
  66.             case DEST_FULL:
  67.                 /* Output the destination buffer */
  68.                 fwrite(Compress_6_DestBufferPtr, 1, Compress_6_BytesWritten, out);
  69.                 break;
  70.             case SCAN_DONE:
  71.                 /* Claim the phase 2 workspace */
  72.                 if (Compress_6_Phase2Length)
  73.                     Compress_6_Phase2Ptr = malloc(Compress_6_Phase2Length);
  74.                 puts("Scanning phase done");
  75.  
  76.                 /* Fall through into NEXT_PASS */
  77.             case NEXT_PASS:
  78.                 /* Start again from the beginning */
  79.                 fseek(in, 1, SEEK_SET);
  80.                 puts("Next pass");
  81.                 break;
  82.             case CLAIM_WORK:
  83.                 /* Claim phase 1 workspace */
  84.                 if (Compress_6_Phase1Length)
  85.                     Compress_6_Phase1Ptr = malloc(Compress_6_Phase1Length);
  86.                 break;
  87.             default:
  88.                 fclose(in);
  89.                 fclose(out);
  90.                 printf("Unexpected reason code (%d)\n",Compress_6_ReasonCode);
  91.                 exit(1);
  92.  
  93.         }
  94.     }
  95.  
  96.     /* Tidy up and exit */
  97.     fclose(in);
  98.     fclose(out);
  99. }
  100.