home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsc / computils / !CompUtils / Resources / Expand / cc / c / Example
Encoding:
Text File  |  1995-07-31  |  1.8 KB  |  75 lines

  1. #include "CompUtils:Expand.cc.h.Universal"
  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.     Expand_SrcBufferPtr = malloc(IBUFF);
  17.     Expand_DestBufferPtr = malloc(OBUFF);
  18.     Expand_SrcLength = IBUFF;
  19.     Expand_DestLength = OBUFF;
  20.  
  21.     /* Set up reason code and output flags */
  22.     Expand_ReasonCode = 0;
  23.     Expand_OutputFlags = OUTPUT_LINEAR; /* All other flags are off */
  24.  
  25.     /* Open source file */
  26.     in = fopen(INFILE, "rb");
  27.     if (in==NULL)
  28.     {
  29.         printf("Can't open input file '%s'\n",INFILE);
  30.         exit(1);
  31.     }
  32.     /* Open destination file */
  33.     out = fopen(OUTFILE, "wb");
  34.     if (out==NULL)
  35.     {
  36.         fclose(in);
  37.         printf("Can't open output file '%s'\n",OUTFILE);
  38.         exit(1);
  39.     }
  40.  
  41.     puts("Starting...\n");
  42.  
  43.     while (Expand() != 0)
  44.     {
  45.         /* A non-zero reason code, so some action must be taken */
  46.         printf("Reason code: %d\n",Expand_ReasonCode);
  47.         switch (Expand_ReasonCode)
  48.         {
  49.             case SRC_EMPTY:
  50.                 /* Refill the source buffer */
  51.                 fread(Expand_SrcBufferPtr, 1, Expand_SrcLength, in);
  52.                 break;
  53.             case DEST_FULL:
  54.                 /* Output the destination buffer */
  55.                 fwrite(Expand_DestBufferPtr, 1, Expand_BytesWritten, out);
  56.                 break;
  57.             case INIT_DONE:
  58.                 /* Write the sample period - it's an Armadeus file */
  59.                 fwrite(&Expand_SamplePeriod, 1, 1, out);
  60.                 printf("File format: Type %d\n",Expand_FileFormat);
  61.                 break;
  62.             default:
  63.                 fclose(in);
  64.                 fclose(out);
  65.                 printf("Unexpected reason code (%d)\n",Expand_ReasonCode);
  66.                 exit(1);
  67.  
  68.         }
  69.     }
  70.  
  71.     /* Tidy up and exit */
  72.     fclose(in);
  73.     fclose(out);
  74. }
  75.