home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / EXPFILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  1.4 KB  |  73 lines

  1. /*
  2. ** expfile.c
  3. ** contains: expfile()
  4. */
  5.  
  6. #include <stdio.h>
  7. #include "gfuncts.h"
  8.  
  9.  
  10. #ifdef    AZTEC
  11. #define READOPENSTR    "r"
  12. #define WRITEOPENSTR    "w"
  13. #else
  14. #define READOPENSTR    "rb"
  15. #define WRITEOPENSTR    "wb"
  16. #endif
  17.  
  18. /*
  19. **  int
  20. ** expfile(char *inputname,char *outputname)
  21. **
  22. ** ARGUMENT(s)
  23. **    inputname    -    Null terminated string for source path & filename.
  24. **    outputname    -    Null terminated string for destination path & filename.
  25. **
  26. **
  27. ** DESCRIPTION
  28. **  "Un-compresses" a file previously compressed with compfile().
  29. **
  30. ** RETURNS
  31. **    0 = successful or CANTOPENFILE
  32. **
  33. ** AUTHOR
  34. **  "" Mon 09-Jan-1989 15:27:26
  35. **   Copyright (C)1989-1990 Greenleaf Software Inc. All Rights Reserved.
  36. **
  37. ** MODIFICATIONS
  38. **
  39. */
  40. int GF_CONV expfile(inputname,outputname)
  41. char *inputname,*outputname;
  42. {
  43.     FILE *inhandle;
  44.     FILE *outhandle;
  45.     unsigned short runcount;
  46.     int inputchar,prevchar;
  47.  
  48.     if((inhandle=fopen(inputname,READOPENSTR))==(FILE *)0)
  49.         return(CANTOPENFILE);
  50.     if((outhandle=fopen(outputname,WRITEOPENSTR))==(FILE *)0) {
  51.         fclose(inhandle);
  52.         return(CANTOPENFILE);
  53.     }
  54.     runcount=0;
  55.     while((inputchar=fgetc(inhandle))!=-1) {
  56.         if(inputchar!=COMPMARK) {
  57.             fputc(inputchar,outhandle);
  58.             prevchar=inputchar;
  59.         } else {
  60.             runcount=fgetc(inhandle);
  61.             if(!runcount)
  62.                 fputc(COMPMARK,outhandle);
  63.             else {
  64.                 while(--runcount)
  65.                     fputc(prevchar,outhandle);
  66.             }
  67.         }
  68.     }
  69.     fclose(inhandle);
  70.     fclose(outhandle);
  71.     return(0);
  72. }
  73.