home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / boo / ufuboo.c < prev   
C/C++ Source or Header  |  2020-01-01  |  2KB  |  76 lines

  1. /*
  2.  * This program is used to unpack the UniFLEX kermit BOO files.
  3.  */
  4.  
  5. #include <stdio.h>
  6.  
  7. #define fixchr(x) ((x) -'0')
  8. #define NULLCHR fixchr('~')
  9.  
  10. main(argc,argv)
  11. int argc;
  12. char **argv;
  13. {
  14.    decode("ufksup.boo");
  15.    decode("ufkrmt.boo");
  16. }
  17.  
  18. decode(infile)
  19. char *infile;
  20. {
  21.    char inline[100],
  22.         outline[200];
  23.    char outfile[100];
  24.    int f;
  25.    FILE *ifp, *ofp;
  26.  
  27.    if ((ifp = fopen(infile,"r")) == NULL)
  28.    {
  29.       printf("%s not found.\n",infile);
  30.       exit(1);
  31.    }
  32.  
  33.    fgets(outfile,100,ifp);               /* get output file name */
  34.    outfile[strlen(outfile)-1] = '\0';
  35.  
  36.    if ((ofp = fopen(outfile,"w")) == NULL)
  37.    {
  38.       printf("could not open %s\n",outfile);
  39.       exit(0);
  40.    }
  41.    printf("%s ==> %s\n",infile,outfile); /* announce our intentions */
  42.    while(fgets(inline,100,ifp) != NULL)
  43.    {
  44.       int index = 0,
  45.           outindex = 0;
  46.  
  47.       while (index < strlen(inline) && inline[index] != '\n' &&
  48.            inline[index] != '\r')       /* end of line? */
  49.       if (fixchr(inline[index]) == NULLCHR)
  50.       {                                 /* null compress char... */
  51.          int rptcnt;
  52.          int i;
  53.  
  54.          rptcnt = fixchr(inline[++index]); /* get repeat count */
  55.          for (i = 0; i < rptcnt; i++)   /* output the nulls */
  56.             putc('\0',ofp);
  57.          index++;                       /* pass the count field */
  58.       }
  59.       else
  60.       {                                 /* a quad to decode... */
  61.          int a, b, c ,d;
  62.  
  63.          a = fixchr(inline[index++]);
  64.          b = fixchr(inline[index++]);
  65.          c = fixchr(inline[index++]);
  66.          d = fixchr(inline[index++]);
  67.                                         /* output the bytes */
  68.          putc(((a * 4) + (b / 16)) & 255,ofp);
  69.          putc(((b * 16) + (c / 4)) & 255,ofp);
  70.          putc(((c * 64) + d) & 255,ofp);
  71.       }
  72.    }
  73.    fclose(ofp);                         /* Close the files */
  74.    fclose(ifp);
  75. }
  76.