home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Multimed / Multimed.zip / lbraplay.zip / MAIN.C < prev    next >
C/C++ Source or Header  |  1999-04-22  |  2KB  |  87 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. void ra144(FILE *fdo,FILE *fd,FILE *fdl);
  4. void ra288(FILE *fdo,FILE *fd,FILE *fdl);
  5.  
  6. int main(int ac, char **av)
  7. {
  8.    static unsigned char in[256];
  9.    FILE *fdl,*fd,*fdo=NULL;
  10.  
  11.    fdl=stdout;
  12.    if ((ac == 3)||(ac==2)) {
  13.       if (strcmp(av[1],"-")) {
  14.          fd=fopen(av[1],"rb");
  15.          if(fd==0) {
  16.             fprintf(stderr,"file not found %s",av[1]);
  17.             exit(1);
  18.             }
  19.          }
  20.       else fd=stdin;
  21.       if (ac==3) {
  22.          if (strcmp(av[2],"-")) {
  23.             fdo=fopen(av[2],"wb");
  24.             if (!fdo) {
  25.                fprintf(stderr,"Can't open output file %s",av[2]);
  26.                exit(1);
  27.                }
  28.             }
  29.          else {
  30.             fdo=stdout;
  31.             fdl=stderr;
  32.             }
  33.          }
  34.       }
  35.    else {
  36.       fprintf(stderr,"Usage: RAPlay {infile|-} [outfile|-]");
  37.       exit(1);
  38.       }
  39.  
  40.    fread(in,6,1,fd);
  41.    if(!strncmp(in,".ra",3) &&in[3]==0xfd && in[4]==0) {
  42.         if (in[5]==3)
  43.       {
  44.              fprintf(fdl,"recognized format: 14.4kbaud file\n");
  45.             ra144(fdo,fd,fdl);
  46.       }
  47.         else if (in[5]==4)
  48.       {
  49.             long pos,l;
  50.             unsigned char sig2[12];
  51.             fread(sig2,12,1,fd);
  52.             fread(in,4,1,fd);
  53.           pos=(in[0]<<24|in[1]<<16|in[2]<<8|in[3])+0x10;
  54.             fread(in,0x16,1,fd);
  55.             if (!strncmp(sig2+2,".ra4",4) && in[4] == 0 || in[5] == 0x26
  56.                     && in[0x12] == 0 && in[0x13] == 12 && in[0x14] == 0 && in[0x15] == 0xe4) {
  57.                  fprintf(fdl,"recognized format: 28.8kbaud file\n");
  58.                         pos-=6+12+4+0x16;
  59.                         while (pos>0) {
  60.                            if (pos>256) l=256; else l=pos;
  61.                            fread(in,l,1,fd);
  62.                            pos-=l;
  63.                            }
  64.             ra288(fdo,fd,fdl);
  65.             }
  66.             else {
  67.                  fprintf(stderr,"recognized format: 28.8kbaud, unrecognized file parameters");
  68.                 exit(1);
  69.             }
  70.       }
  71.       else {
  72.              fprintf(stderr,"RA file format version %d not supported",in[5]);
  73.             exit(1);
  74.         }
  75.     }
  76.     else if (!strncmp(in,".RMF",4)) {
  77.         fprintf(stderr,"Real media files (RMF) not currently supported");
  78.         exit(1);
  79.     }
  80.     else {
  81.         fprintf(stderr,"unrecognized file format");
  82.         exit(1);
  83.     }
  84.     fprintf(fdl,"\nDecoding done");
  85.     return 0;
  86. }
  87.