home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / newc_dev / fileid12.lha / FileID.c < prev    next >
C/C++ Source or Header  |  1990-11-25  |  18KB  |  783 lines

  1. /**************************************************
  2.  *
  3.  * FileID.c
  4.  *
  5.  *    Identify picture/IFF file
  6.  *      and give info about it.
  7.  *
  8.  *    Copyright(c), 1990 Lloyd B. Eldred
  9.  *                     & Fredrick R Homan
  10.  **************************************************/
  11. #include <stdio.h>
  12. #include <math.h>
  13.  
  14. typedef unsigned char UBYTE;     /* 8 bits unsigned */
  15. typedef unsigned short UWORD;    /* 16 bits unsigned */
  16. typedef short WORD;         /* 16 bits signed */
  17. typedef long LONG;               /* 32 bits signed */
  18.  
  19. #define GIF 1
  20. #define IFF 2
  21. #define ANIM 3
  22. #define HIRES 0x8000
  23. #define LACE 0x4
  24. #define HAM 0x800
  25. #define HALFBRITE 0x80
  26. #define TRUE 1
  27. #define FALSE 0
  28.  
  29. void main(argc, argv)
  30. char **argv;
  31. {
  32.     FILE *picfile;
  33.     char buf[256],buf2[256];
  34.    char *filename; 
  35.     int type,width,height,color,i,planes,start,start2,start3,camg,offset;
  36.     UBYTE c,c1,c2,c3,c4,gct,cr,sf,bci,p;
  37.     long vpmode,volume,dt;
  38.     UWORD sps,tempo,par;
  39.     WORD numframes;
  40.     unsigned long reltime;
  41.     LONG size,makelong(char,char,char,char);
  42.    UBYTE VERBOSE, TERSE,COMMENT;
  43.    int cfind(char * , int , char * , int);
  44.    int cfindws(char * , int , char * , int, int);
  45.    void Gif_PlainText(FILE *, UBYTE),Gif_Application(FILE *, UBYTE),
  46.       Gif_Comment(FILE *, UBYTE),Gif_Image(FILE *, UBYTE),
  47.       Gif_Graphic(FILE *, UBYTE),fi_getc(FILE *,char *),
  48.       fi_exit();
  49.    float ar,tempo2;
  50.    
  51.       if ((argc < 2) | (argc > 3)) {
  52.         printf(
  53.         "FileID -- File IDentifier. V 1.20\n"
  54.       "Copyright (c) 1990, Lloyd B. Eldred and Fredrick R Homan.\n"
  55.         "Gives information about GIF and IFF files\n"
  56.         "Usage: FileID [-flag] filename\n"
  57.       "Valid flags: -c : Give GIF89a included comments only\n"
  58.       "             -t : terse mode, gives one line output\n"
  59.       "             -v : verbose mode, gives lots of extra GIF information\n");
  60.         fi_exit();
  61.     }
  62.    
  63.    COMMENT = FALSE;
  64.    VERBOSE = FALSE;
  65.    TERSE = FALSE;
  66.    filename = argv[1];
  67.    
  68.    c1 = argv[1][0];
  69.    c2 = argv[1][1];
  70.    if(c1 == '-'){
  71.       if(c2 == 'v' || c2 == 'V'){
  72.           VERBOSE=TRUE;
  73.           if(argc == 3) filename = argv[2];
  74.           else{
  75.              printf("No file specified\n");
  76.              fi_exit();
  77.              }
  78.        }
  79.        else if(c2 == 't' || c2 == 'T'){
  80.           TERSE=TRUE;
  81.           if(argc == 3) filename = argv[2];
  82.           else{
  83.              printf("No file specified\n");
  84.              fi_exit();
  85.              }
  86.        }
  87.        else if(c2 == 'c' || c2 == 'C'){
  88.           COMMENT=TRUE;
  89.           if(argc == 3) filename = argv[2];
  90.           else{
  91.              printf("No file specified\n");
  92.              fi_exit();
  93.              }
  94.        } 
  95.        else{
  96.             printf("Invalid flag -%c\n",c2);
  97.             fi_exit();
  98.        }
  99.       }   
  100.       
  101.     if ((picfile = fopen(filename, "rb")) == NULL) {
  102.             perror(filename);
  103.             fi_exit();
  104.            }
  105.  
  106.   
  107.     /* search for header line */
  108.     for (;;) {
  109.         if (fread(buf, sizeof(buf), 1,picfile) != 1) {
  110.             fprintf(stderr, "Unrecognized filetype\n");
  111.             fclose(picfile);
  112.             fi_exit();
  113.         }
  114.         start = cfind(buf,sizeof(buf),"GIF",3);
  115.         if (start != -1){
  116.             type=GIF;
  117.             break;
  118.         }
  119.         
  120.         start = cfind(buf,sizeof(buf),"FORM",4);
  121.         if (start != -1){
  122.             type=IFF;
  123.             break;
  124.         }
  125.         
  126.         start = cfind(buf,sizeof(buf),"CAT ",4);
  127.         if (start != -1){
  128.             type=IFF;
  129.             break;
  130.         }
  131.  
  132.         start = cfind(buf,sizeof(buf),"LIST",4);
  133.         if (start != -1){
  134.             type=IFF;
  135.             break;
  136.         }
  137.  
  138.  
  139.             
  140.     }
  141.     
  142.     fclose(picfile);
  143.  
  144. /********************************************************************/
  145. /*                          GIF analysis                            */
  146. /********************************************************************/
  147.     
  148.     if(type == GIF){
  149.  
  150.         if(start != 0){
  151.             printf("Padding encountered at the beginning of the file.\n" 
  152.                 "Some viewers may not like this file.\n");
  153.            start2 = cfindws(buf,sizeof(buf),"GIF",3,128);
  154.            if (start2 != -1){
  155.                printf("Macintosh resource fork found. Recommend using"
  156.                 " StripGif to remove the header.\n");
  157.             start=start2;
  158.          }
  159.       }
  160.  
  161.          c1 = buf[start+3];
  162.         c2 = buf[start+4];
  163.         c3 = buf[start+5];
  164.  
  165.         if(!TERSE){
  166.          printf("GIF -- Version %c%c%c:",c1,c2,c3);
  167.            if( c1 != '8' || (c2 != '7' && c2 != '9') || c3 != 'a'){
  168.               printf(" non recognized version, the following are guesses");
  169.             }
  170.             if (COMMENT) printf("\n");
  171.          if(!COMMENT) printf("\n  Image Header\n");
  172.       }
  173.       else printf("GIF%c%c%c",c1,c2,c3);
  174.          
  175.         c1 = buf[start+6];
  176.         c2 = buf[start+7];
  177.         c3 = buf[start+8];
  178.         c4 = buf[start+9];
  179.         c  = buf[start+10];
  180.       bci= buf[start+11];
  181.       p= buf[start+12];
  182.             
  183.   /* Expand Logical Screen Descriptor packed fields */
  184.       gct = (UBYTE)(c & 0x80);
  185.       cr =  (UBYTE)(c & 0x70)>>4;
  186.       cr++;
  187.       sf =  (UBYTE)(c & 0x08);
  188.         planes = (int)(c & 0x7) + 1;
  189.       par=(UWORD)p+15;
  190.  
  191.       ar = par/64.0;
  192.          
  193.       if(VERBOSE){
  194.          if(gct && !sf)
  195.            printf("    Global Color Table Flag set (table unsorted)\n");
  196.          if(gct && sf)
  197.            printf("    Global Color Table Flag set (table sorted)\n");
  198.          printf("    Color resolution: %d bits of RG&B per palette color\n",
  199.                cr);
  200.          if(gct)
  201.             printf("    Background color is color number %d\n",bci);
  202.          if(!p)
  203.             printf("    No pixel aspect ratio information given.\n");
  204.          else
  205.             printf("    Aspect ratio (pixel's width/height) is %g\n",ar);
  206.       }
  207.       
  208.         color=1;
  209.         
  210.         for(i=0; i<planes ; i++)
  211.           color = color * 2;
  212.         
  213.         width=c1 + 256 * c2;
  214.         
  215.         height=c3 + 256 * c4;
  216.         
  217.         if(!TERSE && !COMMENT) 
  218.                  printf("    Width : %5d\n"
  219.                           "    Height: %5d\n"
  220.                           "    Colors: %5d\n",width,height,color);
  221.                         
  222.       if(TERSE) printf(" %5d %5d %5d\n",width,height,color);              
  223.         
  224.       /* 
  225.        *Done with logical screen descriptor, continue
  226.        * only if user has selected verbose mode
  227.        */
  228.    if(!VERBOSE && !COMMENT) fi_exit();
  229.    
  230.    offset=start+13;
  231.    
  232.    if(gct){ /* if Global Color Table, skip it... */
  233.       offset += 3 * color; 
  234.       }
  235.    
  236.     if ((picfile = fopen(filename, "rb")) == NULL) {
  237.             perror(filename);
  238.             fi_exit();
  239.            }
  240.    if (fseek(picfile,offset,1) == -1){
  241.          printf(" Unexpected end of file. (1)\n");  
  242.          fclose(picfile);
  243.          fi_exit();
  244.       }
  245.    
  246.    for(;;){
  247.    
  248.       fi_getc(picfile,&c1);
  249.       
  250.       switch(c1){
  251.          case 0x2c:
  252.             Gif_Image(picfile,!COMMENT);
  253.             break;
  254.          
  255.          case 0x21:
  256.             if (!COMMENT) printf("  Extension:");
  257.             fi_getc(picfile,&c2);
  258.             
  259.             if(c2 == 0xf9) Gif_Graphic(picfile,!COMMENT);
  260.             if(c2 == 0xfe) {
  261.              if (!COMMENT) printf("Comment\n");
  262.              Gif_Comment(picfile,1);
  263.             }
  264.             if(c2 == 0x01) Gif_PlainText(picfile,!COMMENT);
  265.             if(c2 == 0xff) Gif_Application(picfile,!COMMENT);
  266.  
  267.             break;
  268.               
  269.          case 0x3b:
  270.             printf("  Normal End of GIF reached.\n");               
  271.             fclose(picfile);
  272.             fi_exit();
  273.             break;
  274. /***/            
  275.          default:
  276.             printf("  Unknown block type: (Label 0x%x)\n",c1);
  277.             fclose(picfile);
  278.             fi_exit();
  279.             break;
  280.          
  281.          } /* end of switch */
  282.  
  283.    } /* end of for(;;) */
  284.  
  285.    
  286.     } /* End of GIF analysis section */
  287.  
  288. /********************************************************************/
  289. /*                          IFF analysis                            */
  290. /********************************************************************/
  291.  
  292.     if(type == IFF){
  293.         printf(" IFF file:");
  294.  
  295. /* ILBM analysis */
  296.  
  297.         start3 = cfind(buf,sizeof(buf),"ANIM",4);
  298.         if (start3 != -1){
  299.             printf(" ANIM (Cel Animation)\n");
  300.             type = ANIM;
  301.             start = cfind(buf,sizeof(buf),"ILBM",4);
  302.             if(start != -1 && start < sizeof(buf) + 5){
  303.                 c1 = buf[start-4];
  304.                 c2 = buf[start-3];
  305.                 c3 = buf[start-2];
  306.                 c4 = buf[start-1];
  307.                 size = makelong(c1,c2,c3,c4);
  308.                 if ((picfile = fopen(filename, "rb")) == NULL) {
  309.                     perror(argv[1]);
  310.                     fi_exit();
  311.                 }
  312.                 if(fseek(picfile,(long)(start+size),0)
  313.                     == -1){
  314.                     printf(" Can't find animation info. (fseek past end of file)\n");
  315.                     fi_exit();
  316.                 }
  317.             if (fread(buf2, sizeof(buf2), 1,picfile) != 1) {
  318.                 fprintf(stderr, 
  319.                     " Can't find animation info. (fread past end of file)\n");
  320.                 }
  321.                 
  322.             }
  323.             start = cfind(buf2,sizeof(buf2),"ANHD",4);
  324.             if(start != -1 && start < sizeof(buf2) - 25){
  325.                 c1 = buf2[start+8];
  326.                 c2 = buf2[start+9];
  327.                 c3 = buf2[start+23];
  328.                 c4 = buf2[start+24];
  329.                 
  330.                 c = buf2[start+25];
  331.  
  332.                 printf("   Compression Mode      :");
  333.                 if(c1 == 0) printf(" None\n");
  334.                 if(c1 == 1) printf(" XOR ILBM mode\n");
  335.                 if(c1 == 2) printf(" Long Delta mode\n");
  336.                 if(c1 == 3) printf(" Short Delta mode\n");
  337.                 if(c1 == 4) printf(
  338.                     " Gen. short/long Delta mode\n");
  339.                 if(c1 == 5) printf(
  340.                     " Byte Vertical Delta mode\n");
  341.                 if(c1 == 'J') printf(
  342.                     " Eric Graham's technique\n");
  343.             
  344.                 reltime = (unsigned long)
  345.                     makelong(c2,c3,c4,c);
  346.                 printf("   Frame timing (jiffies): %d\n"
  347.                     ,reltime);
  348.                 printf("   (1 jiffy=1/60 sec)\n");
  349.             }
  350.             else
  351.                 printf(
  352.                 " Can't find animation information. (Can't find ANHD)\n");
  353.         }
  354.         start = -1;
  355.         if(type != ANIM){
  356.             start = cfind(buf,sizeof(buf),"ILBM",4);
  357.             if(start != -1)
  358.                 printf(
  359.                 " ILBM (Picture: InterLeaved Bit Map)\n");
  360.             start2 = cfind(buf,sizeof(buf),"ACBM",4);
  361.             if(start2 != -1)
  362.                 printf(
  363.                 " ACBM (Picture: Amiga Contiguous Bit Map)\n");
  364.         }
  365.             
  366.         if (start != -1 || start2 != -1 || start3 != -1){
  367.             start = cfind(buf,sizeof(buf),"BMHD",4);
  368.             
  369.             if(start == -1){
  370.                 printf(" Color information not found\n");
  371.                 fi_exit();
  372.             }
  373.             
  374.             
  375.             if(start > (sizeof(buf)-12)){
  376.                 printf(
  377.                 " Incomplete color information found\n");
  378.                 fi_exit();
  379.             }
  380.             c1 = buf[start+8];
  381.             c2 = buf[start+9];
  382.             c3 = buf[start+10];
  383.             c4 = buf[start+11];
  384.             c  = buf[start+16];
  385.  
  386.             width = (int)c2 + (int)(c1<<8);
  387.             height= (int)c4 + (int)(c3<<8);
  388.                         
  389.             planes=(int)c;
  390.             color=1;
  391.             for(i=0; i<planes ; i++)
  392.                   color = color * 2;
  393.   /* HAM or Extra Half Bright? */
  394.   /* Search for CAMG block */
  395.             camg=0;
  396.             start = cfind(buf,sizeof(buf),"CAMG",4);
  397.                             
  398.             if(start != -1) { /* check vpmode flag */
  399.                 camg=1;
  400.                 c1 = buf[start+8];
  401.                 c2 = buf[start+9];
  402.                 c3 = buf[start+10];
  403.                 c4 = buf[start+11]; 
  404.                 vpmode = makelong(c1,c2,c3,c4);
  405.  
  406.                 if(vpmode & HAM) /* HAM flag */
  407.                         color = 4096;
  408.             } /* end if(start != -1) */
  409.                      
  410.             printf("   Width : %5d",width);
  411.             if(camg == 1 && (vpmode & HIRES))
  412.                 printf("  Hi-Res");
  413.             printf("\n");
  414.             
  415.             printf("   Height: %5d",height);
  416.             if(camg == 1 && (vpmode & LACE))
  417.                 printf("  Interlaced");
  418.             printf("\n");
  419.                         
  420.             printf("   Colors: %5d",color);
  421.             if(camg == 1 && (vpmode & HAM))
  422.                 printf("  HAM");
  423.             if(camg == 1 && (vpmode & HALFBRITE))
  424.                 printf("  Extra-Halfbright");
  425.             printf("\n");
  426.             fi_exit();
  427.             
  428.         } /* end if ILBM */
  429.         
  430. /* check for other IFF file types */
  431.  
  432.         start = cfind(buf,sizeof(buf),"FTXT",4);
  433.         if (start != -1){
  434.             printf(" FTXT (Formatted Text)\n");
  435.             fi_exit();
  436.         }
  437.         
  438.         start = cfind(buf,sizeof(buf),"SMUS",4);
  439.         if (start != -1){
  440.             printf(" SMUS (Simple MUsical Score)\n");
  441.             start = cfind(buf,sizeof(buf),"SHDR",4);
  442.             if (start == -1 || start > sizeof(buf) - 11){
  443.                 printf(" Can't read music info.\n");
  444.                 fi_exit();
  445.             }
  446.             c1 = buf[start+8];
  447.             c2 = buf[start+9];
  448.             
  449.             tempo = (UWORD)c2 + (UWORD)(c1<<8);
  450.  
  451.          tempo2 = tempo/128.0; 
  452.                         
  453.             c3 = buf[start+10];
  454.  
  455.             volume = ((int)c3 * 100)/127;
  456.  
  457.             c = buf[start+11];
  458.             
  459.             printf("   Tempo  (1/4 notes/min): %g\n",tempo2);
  460.             printf("   Volume (percent)      : %d\n",volume);
  461.             printf("   Tracks                : %d\n",(int)c);
  462.           
  463.          fi_exit();
  464.         }
  465.         
  466.         start = cfind(buf,sizeof(buf),"8SVX",4);
  467.         if (start != -1){
  468.             printf(" 8SVX (8-Bit Sample Voice)\n");
  469.             start = cfind(buf,sizeof(buf),"VHDR",4);
  470.             if (start == -1 || start > sizeof(buf)-27){
  471.                 printf(" Can't read voice info\n");
  472.                 fi_exit();
  473.             }
  474.             c1 = buf[start+20];
  475.             c2 = buf[start+21];
  476.             
  477.             sps = (UWORD)c2 + (UWORD)(c1<<8);
  478.             
  479.             c1 = buf[start+24];
  480.             c2 = buf[start+25];
  481.             c3 = buf[start+26];
  482.             c4 = buf[start+27];
  483.             
  484.             volume = makelong(c1,c2,c3,c4);
  485.             volume = (volume * 100) / 65536;
  486.             printf("   Samples per second: %d\n",sps);
  487.             printf("   Volume (percent)  : %d\n",volume);
  488.             
  489.             fi_exit();
  490.         }
  491.  
  492.         start = cfind(buf,sizeof(buf),"AIFF",4);
  493.         if (start != -1){
  494.             printf(" AIFF (Apple Audio IFF)\n");
  495.             fi_exit();
  496.         }
  497.  
  498.         start = cfind(buf,sizeof(buf),"ANBM",4);
  499.         if (start != -1){
  500.             printf(" ANBM (Animated bitmap -- Deluxe Video)\n");
  501.             start = cfind(buf,sizeof(buf),"FSQN",4);
  502.             if(start == -1 || start > sizeof(buf) - 13 ){
  503.                 printf(" Can't read animation info\n");
  504.                 fi_exit();
  505.             }
  506.             c1 = buf[start+8];
  507.             c2 = buf[start+9];
  508.             
  509.             numframes = (WORD)c2 + (WORD)(c1<<8);
  510.             
  511.             c1 = buf[start+10];
  512.             c2 = buf[start+11];
  513.             c3 = buf[start+12];
  514.             c4 = buf[start+13];
  515.             
  516.             dt = makelong(c1,c2,c3,c4);
  517.             
  518.             printf("   Number of Frames              : %d\n",
  519.                 numframes);
  520.             printf("   Time between frames (jiffies) : %d\n",
  521.                 dt);
  522.             printf("   (1 jiffy=1/60 sec)\n");
  523.             
  524.             fi_exit();
  525.         }
  526.  
  527.         start = cfind(buf,sizeof(buf),"BANK",4);
  528.         if (start != -1){
  529.             printf(" BANK (SoundQuest MIDI data-dump)\n");
  530.             fi_exit();
  531.         }
  532.  
  533.         start = cfind(buf,sizeof(buf),"HEAD",4);
  534.         if (start != -1){
  535.             printf(" HEAD (Flow Idea Processor form)\n");
  536.             fi_exit();
  537.         }
  538.  
  539.         start = cfind(buf,sizeof(buf),"MIDI",4);
  540.         if (start != -1){
  541.             printf(" MIDI\n");
  542.             fi_exit();
  543.         }
  544.  
  545.         start = cfind(buf,sizeof(buf),"PGTB",4);
  546.         if (start != -1){
  547.             printf(" PGTB (ProGram TraceBack diagnostic dump image)\n");
  548.             fi_exit();
  549.         }
  550.  
  551.         start = cfind(buf,sizeof(buf),"SYTH",4);
  552.         if (start != -1){
  553.             printf(" SYTH (SoundQuest Master Librarian file)\n");
  554.             fi_exit();
  555.         }
  556.  
  557.         start = cfind(buf,sizeof(buf),"WORD",4);
  558.         if (start != -1){
  559.             printf(" WORD (ProWrite data file)\n");
  560.             fi_exit();
  561.         }
  562.         
  563.         start = cfind(buf,sizeof(buf),"C100",4);
  564.         if (start != -1){
  565.             printf(" C100 (Cloanto Italia, private word processing form)\n");
  566.             fi_exit();
  567.         }
  568.  
  569.         start = cfind(buf,sizeof(buf),"PDEF",4);
  570.         if (start != -1){
  571.             printf(" PDEF (Deluxe Print page definition)\n");
  572.             fi_exit();
  573.         }
  574.  
  575.         start = cfind(buf,sizeof(buf),"SHAK",4);
  576.         if (start != -1){
  577.             printf(" SHAK (Shakespeare data file)\n");
  578.             fi_exit();
  579.         }
  580.  
  581.         start = cfind(buf,sizeof(buf),"VDEO",4);
  582.         if (start != -1){
  583.             printf(" VDEO (Deluxe Video file)\n");
  584.             fi_exit();
  585.         }
  586.  
  587.         start = cfind(buf,sizeof(buf),"SAMP",4);
  588.         if (start != -1){
  589.             printf(" SAMP (Sound Sample)\n");
  590.             fi_exit();
  591.         }
  592.  
  593.         start = cfind(buf,sizeof(buf),"TDDD",4);
  594.         if (start != -1){
  595.             printf(" TDDD (Turbo Silver file)\n");
  596.             fi_exit();
  597.         }
  598.  
  599.         start = cfind(buf,sizeof(buf),"SC3D",4);
  600.         if (start != -1){
  601.             printf(" SC3D (Sculpt 3-D file)\n");
  602.             fi_exit();
  603.         }
  604.  
  605.         start = cfind(buf,sizeof(buf),"TEXT",4);
  606.         if (start != -1){
  607.             printf(" TEXT (unformatted ASCII text)\n");
  608.             fi_exit();
  609.         }
  610.  
  611.         start = cfind(buf,sizeof(buf),"FNTR",4);
  612.         if (start != -1){
  613.             printf(" FNTR (Raster Font)\n");
  614.             fi_exit();
  615.         }
  616.  
  617.         start = cfind(buf,sizeof(buf),"FNTV",4);
  618.         if (start != -1){
  619.             printf(" FNTV (Vector Font)\n");
  620.             fi_exit();
  621.         }
  622.  
  623.         start = cfind(buf,sizeof(buf),"GSCR",4);
  624.         if (start != -1){
  625.             printf(" GSCR (General-use musical SCoRe)\n");
  626.             fi_exit();
  627.         }
  628.         
  629.         start = cfind(buf,sizeof(buf),"PICS",4);
  630.         if (start != -1){
  631.             printf(" PICS (Macintosh picture)\n");
  632.             fi_exit();
  633.         }
  634.  
  635.         start = cfind(buf,sizeof(buf),"PLBM",4);
  636.         if (start != -1){
  637.             printf(" PLBM (Obsolete)\n");
  638.             fi_exit();
  639.         }
  640.  
  641.         start = cfind(buf,sizeof(buf),"USCR",4);
  642.         if (start != -1){
  643.             printf(" USCR (Uhura Sound software musical score)\n");
  644.             fi_exit();
  645.         }
  646.  
  647.         start = cfind(buf,sizeof(buf),"UVOX",4);
  648.         if (start != -1){
  649.             printf(" UVOX (Uhura Sound software Macintosh Voice)\n");
  650.             fi_exit();
  651.         }
  652.  
  653.         start = cfind(buf,sizeof(buf),"CLIP",4);
  654.         if (start != -1){
  655.             printf(" CLIP (Clipboard data)\n");
  656.             fi_exit();
  657.         }
  658.  
  659.         start = cfind(buf,sizeof(buf),"ARC ",4);
  660.         if (start != -1){
  661.             printf(" ARC  (Archive form)\n");
  662.             fi_exit();
  663.         }
  664.  
  665.         start = cfind(buf,sizeof(buf),"ATXT",4);
  666.         if (start != -1){
  667.             printf(" ATXT\n");
  668.             fi_exit();
  669.         }
  670.  
  671.         start = cfind(buf,sizeof(buf),"PTXT",4);
  672.         if (start != -1){
  673.             printf(" PTXT\n");
  674.             fi_exit();
  675.         }
  676.  
  677.         start = cfind(buf,sizeof(buf),"RGBX",4);
  678.         if (start != -1){
  679.             printf(" RGBX\n");
  680.             fi_exit();
  681.         }
  682.  
  683.         start = cfind(buf,sizeof(buf),"CDAT",4);
  684.         if (start != -1){
  685.             printf(" CDAT\n");
  686.             fi_exit();
  687.         }
  688.  
  689.         start = cfind(buf,sizeof(buf),"MSMP",4);
  690.         if (start != -1){
  691.             printf(" MSMP\n");
  692.             fi_exit();
  693.         }
  694.  
  695.         start = cfind(buf,sizeof(buf),"FIGR",4);
  696.         if (start != -1){
  697.             printf(" FIGR\n");
  698.             fi_exit();
  699.         }
  700.  
  701.         start = cfind(buf,sizeof(buf),"MOVI",4);
  702.         if (start != -1){
  703.             printf(" MOVI\n");
  704.             fi_exit();
  705.         }
  706.  
  707.         printf(" Unknown type\n");
  708.  
  709.     } /* End of IFF code */
  710.     
  711. } /* end of main() */
  712.  
  713. int cfind(buffer,blength,string,slength)
  714. char *buffer;
  715. char *string;
  716. int blength,slength;
  717. {
  718.     int i,start;
  719.     int found;
  720.     
  721.     start = 0;
  722.     
  723.     while(start < (blength-slength)){
  724.         found = 1;
  725.         
  726.         for(i=0;i<slength;i++)
  727.             if(buffer[start+i] != string[i]){
  728.                 found = 0;
  729.                 break;
  730.             }
  731.         
  732.         if(found == 1) return(start);
  733.         
  734.         start++;
  735.     }
  736.     
  737.     return(-1);  /* string not found */
  738.         
  739. } /* end of cfind() */    
  740.  
  741. int cfindws(buffer,blength,string,slength,init)
  742. char *buffer;
  743. char *string;
  744. int blength,slength,init;
  745. {
  746.     int i,start;
  747.     int found;
  748.     
  749.     start = init;
  750.     
  751.     while(start < (blength-slength)){
  752.         found = 1;
  753.         
  754.         for(i=0;i<slength;i++)
  755.             if(buffer[start+i] != string[i]){
  756.                 found = 0;
  757.                 break;
  758.             }
  759.         
  760.         if(found == 1) return(start);
  761.         
  762.         start++;
  763.     }
  764.     
  765.     return(-1);  /* string not found */
  766.         
  767. } /* end of cfindws() */    
  768.  
  769. LONG makelong(c1,c2,c3,c4)
  770. char c1,c2,c3,c4;
  771. {
  772.     LONG value;
  773.     
  774.     value = (LONG)c4 + (LONG)(c3<<8) + (LONG)(c2<<16) + (LONG)(c1<<24);
  775.     
  776.     return(value);
  777.     
  778. } /* end of makelong() */
  779.  
  780. void fi_exit()
  781. {
  782.    exit(0);
  783. }