home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / modinfo.zip / src / MODINFO.C < prev    next >
Text File  |  1993-05-10  |  4KB  |  144 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.     struct SampleInfo
  5.     {
  6.     char Name[22];
  7.     int Len;
  8.     short FineTune;
  9.     short Vol;
  10.     int RepStart;
  11.     int RepLen;
  12.     } Sample[31];
  13.  
  14.     short SongLen;
  15.     short Dummy;
  16.     int SongPos[127];
  17.     char ModSig[5];
  18.  
  19.     char Use[]="\nUsage:  modinfo <modname.mod>\n"
  20.            "This will give you more info than you will ever want\n"
  21.            "about a .mod file -- best to redirect to a file or a\n"
  22.            "utility like \"more.\"\n\nWritten by Captain Sarcastic.\n"
  23.            "kkoller@nyx.cs.du.edu\n";
  24.  
  25.     char Head[]="\nModInfo 1.0a by Captain Sarcastic\n"
  26.             "Generates ProTracker Module Information\n"
  27.             "This program has no choice--it is doinkware\n"
  28.             "   [a.k.a. FreeWare, PD, do what ya want...]\n\n";
  29.  
  30.     char Protracker[]="ProTracker 1.1";
  31.  
  32. int main(int argc,char *argv[])
  33. {
  34.     FILE *fp;
  35.     int outloop,loop,er;
  36.     char temphi,templo;
  37.     char modname[21];
  38.     int RepStart, RepLen;
  39.     char ModType[20];
  40.  
  41.     if (argc < 2)
  42.     {
  43.     fprintf(stderr,"%s",Use);
  44.     return(5);
  45.     }
  46.  
  47.     fprintf(stdout,"%s",Head);
  48.  
  49.     fp = fopen(argv[1],"rb");
  50.  
  51.     if (fp==NULL)
  52.       {
  53.       fprintf(stderr,"\nFile <%s> not found, or some other file error.",argv[1]);
  54.       return(5);
  55.       } /* endif */
  56.  
  57.     for(loop=0;loop<20;loop++)
  58.      {  modname[loop] = fgetc(fp); }
  59.      modname[20] = 0;
  60.  
  61.     for (outloop=0;outloop<31;outloop++)
  62.     {
  63.       for(loop=0;loop<22;loop++)
  64.        {
  65.        Sample[outloop].Name[loop] = fgetc(fp);
  66.        }
  67.        temphi=fgetc(fp);templo=fgetc(fp);
  68.        Sample[outloop].Len=temphi*256+templo;
  69.        Sample[outloop].FineTune = fgetc(fp);
  70.        Sample[outloop].Vol = fgetc(fp);
  71.        temphi=fgetc(fp);templo=fgetc(fp);
  72.        Sample[outloop].RepStart = temphi*256+templo;
  73.        temphi=fgetc(fp);templo=fgetc(fp);
  74.        Sample[outloop].RepLen = temphi*256+templo;
  75.     }
  76.     SongLen = fgetc(fp);
  77.     Dummy = fgetc(fp);
  78.     for(outloop=0;outloop<128;outloop++)
  79.       {
  80.       SongPos[outloop] = fgetc(fp);
  81.       } /* end for */
  82.     for(outloop=0;outloop<4;outloop++)
  83.       {
  84.       ModSig[outloop]=fgetc(fp);
  85.       } /* end for */
  86.       ModSig[4]=0;
  87.  
  88.     fclose(fp);
  89.  
  90.     if ( (ModSig[0]=='M')&&(ModSig[2]=='K') )
  91.      {
  92.      strcpy(ModType,Protracker);
  93.      }
  94.     else
  95.      {
  96.      fprintf(stderr,"\n<%s> is not a protracker module.\n",argv[1]);
  97.      return(5);
  98.      }
  99.  
  100.     fprintf(stdout,"\nModule name  = \"%s\"\n",modname);
  101.     fprintf(stdout,"Module Type  = %s\n",ModType);
  102.     fprintf(stdout,"Song Length  = %d (%02x hex)\n",SongLen,SongLen);
  103.     fprintf(stdout,"Pattern(s)   =");
  104.     for (outloop=0;outloop<SongLen;outloop+=8)
  105.       {
  106.       for (loop=0;loop<8;loop++)
  107.        {
  108.        if ( (outloop+loop) < SongLen)
  109.        fprintf(stdout," %02x",SongPos[outloop+loop]);
  110.        }
  111.       fprintf(stdout,"\n              ");
  112.       }
  113.  
  114.     for (loop=0;loop<31;loop++)
  115.     {
  116.       fprintf(stdout,"\nSample %d ",loop+1);
  117.       if (Sample[loop].Len==0)
  118.        { fprintf(stdout,"-- empty");
  119.          fprintf(stdout,"\nText   : \"%s\"\n",Sample[loop].Name);
  120.        } /* endif */
  121.       else
  122.        {
  123.        fprintf(stdout,"\nName   : \"%s\"\n",Sample[loop].Name);
  124.        fprintf(stdout,"Length : %d bytes (%04x hex)\n"
  125.         ,Sample[loop].Len, Sample[loop].Len);
  126.        fprintf(stdout,"Volume : %d (%02x hex)\n"
  127.         ,Sample[loop].Vol, Sample[loop].Vol);
  128.        RepStart = Sample[loop].RepStart;
  129.        RepLen   = Sample[loop].RepLen;
  130.  
  131.        if (! ( (RepStart==0) && ((RepLen==1)||(RepLen==0)) ) )
  132.         {
  133.          fprintf(stdout,"Repeat Info\n");
  134.          fprintf(stdout,"Start  : %d (%04x hex)\n",RepStart,RepStart);
  135.          fprintf(stdout,"Length : %d (%04x hex)\n",RepLen  ,RepLen  );
  136.         } /* endif */
  137.       } /* end else */
  138.     } /* end for (loop++) */
  139.  
  140. return(0);
  141. } /* end main() */
  142.  
  143.  
  144.