home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: DFÜ und Kommunikation / SOS-DFUE.ISO / programm / dos / utility / pccp076 / sfxtorfx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-12  |  2.5 KB  |  123 lines

  1. #include<stdio.h>
  2. #include<fcntl.h>
  3. #include<sys\types.h>
  4. #include<sys\stat.h>
  5.  
  6. #define BSIZ 2048
  7.  
  8. unsigned char putbuf[BSIZ], getbuf[BSIZ];
  9.  
  10. int infd, outfd, putptr, getptr, gettop;
  11.  
  12. putbyte(byte)
  13.     {
  14.     putbuf[putptr++]=byte;
  15.     if(putptr>=BSIZ)
  16.         if(write(outfd, putbuf, BSIZ)!=BSIZ)
  17.             {
  18.             printf("Write error.\n");
  19.             exit(10);
  20.             }
  21.         else
  22.             putptr=0;
  23.     }
  24.  
  25. unsigned char getbyte()
  26.     {
  27.     if(getptr>=gettop)
  28.         {
  29.         if((gettop=read(infd, getbuf, BSIZ))==-1)
  30.             {
  31.             printf("Read error.\n");
  32.             exit(11);
  33.             }
  34.         getptr=0;
  35.         }
  36.     return(getbuf[getptr++]);
  37.     }
  38.  
  39. putstr(str)
  40.     unsigned char *str;
  41.     {
  42.     char *cptr;
  43.     for(cptr=str;*cptr;cptr++)
  44.         putbyte(*cptr);
  45.     }
  46.  
  47. unsigned char bassack[256];
  48.  
  49. main(argc, argv)
  50.     int argc;
  51.     char **argv;
  52.     {
  53.     unsigned char c, otherc;
  54.     int page, i;
  55.     page=0;
  56.     if(argc!=3)
  57.         {
  58.         printf("USAGE: sfxtorfx <sfx file> <rfx file>\nInclude suffixes.\n\n");
  59.         exit(1);
  60.         }
  61.     if((infd=open(argv[1], O_RDONLY|O_BINARY))==-1)
  62.         {
  63.         printf("Error opening %s for read.\n", argv[1]);
  64.         exit(2);
  65.         }
  66.     if((outfd=open(argv[2], O_WRONLY|O_BINARY|O_CREAT|O_TRUNC, S_IWRITE))==-1)
  67.         {
  68.         printf("Error opening %s for write.\n", argv[2]);
  69.         exit(3);
  70.         }
  71.     for(i=0;i<256;++i)
  72.         for(bassack[i]=0,c=0x01,otherc=0x80;c;c<<=1,otherc>>=1)
  73.             if(c&i)
  74.                 bassack[i]|=otherc;
  75.     putptr=getptr=gettop=0;
  76.     putstr("\r\n+FCON\r\n\r\n+FTSI: \"PCCP SFXTORFX HACK  \"\r\n");
  77.     putstr("\r\n+FDCS: 1,3,0,2,0,0,0,0\r\n\r\nOK\r\n");
  78.     putstr("\r\n+FCFR\r\n\r\n+FDCS: 1,3,0,2,0,0,0,0\r\n");
  79.     putstr("\r\nCONNECT\r\n");
  80.     printf("Page %d...", ++page);
  81.     while(1)
  82.         {
  83.         if((c=getbyte())==0x10)
  84.             if((c=getbyte())==0x10)
  85.                 putbyte(0x08);
  86.             else if(c==0x03)
  87.                 {
  88.                 printf("\nPage %d...", ++page);
  89.                 putbyte(0x10);
  90.                 putbyte(0x03);
  91.                 putstr("\r\n+FPTS: 1,2219,0,0\r\n");
  92.                 putstr("\r\n+FET: 0\r\n");
  93.                 putstr("\r\nOK\r\n\r\n+FDR\r\n");
  94.                 putstr("\r\n+FDCS: 1,3,0,2,0,0,0,0\r\n");
  95.                 putstr("\r\nCONNECT\r\n");
  96.                 }
  97.             else if(c==0x04)
  98.                 break;
  99.             else
  100.                 {
  101.                 printf("Bogus shielded character hex %02x.\n", c);
  102.                 exit(20);
  103.                 }
  104.         else if(c==0x08)
  105.             {
  106.             putbyte(0x10);
  107.             putbyte(0x10);
  108.             }
  109.         else
  110.             putbyte(bassack[c]);
  111.         }
  112.     putbyte(0x10);
  113.     putbyte(0x03);
  114.     putstr("\r\n+FPTS: 1,2219,0,0\r\n");
  115.     putstr("\r\n+FET: 2\r\n\r\nOK\r\n\r\n+FHNG: 0\r\n\r\nOK\r\n");
  116.     if(putptr)
  117.         if(write(outfd, putbuf, putptr)!=putptr)
  118.             {
  119.             printf("Write error in flush.\n");
  120.             exit(13);
  121.             }
  122.     printf("\n\nAll done.\n");
  123.     }