home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 17 / af017.adf / search.c < prev    next >
C/C++ Source or Header  |  1978-01-21  |  5KB  |  177 lines

  1. /* --------------------------------------------------------------------- */
  2. /* Amiga IFF/SMF Search Utility: PAUL OVERAA             September 90    */
  3. /* --------------------------------------------------------------------- */
  4.  
  5. /* includes */
  6.  
  7. #include <exec/types.h>
  8. #include <exec/memory.h>
  9. #include <libraries/dos.h>
  10. #include <libraries/dosextens.h>
  11.  
  12. /* prototypes */
  13.  
  14. void CreateLevel(TEXT *imported_path); /* prototypes */
  15. void FileCheck(TEXT *filename);
  16.  
  17. /* defines */
  18.  
  19. #define MakeID(a,b,c,d)  ( (LONG) (a)<<24L | (LONG) (b)<<16L | (c)<<8 | (d) )
  20. #define  FIB_SIZE  (LONG)(sizeof(struct FileInfoBlock)) 
  21. #define  ID_FORM MakeID('F','O','R','M')
  22. #define  ID_SMF  MakeID('M','T','h','d')
  23. #define BUFFERSIZE 12
  24.  
  25. /* some globals */
  26.  
  27. UBYTE buffer[12]; /* some space for partial file load */
  28.  
  29. UBYTE global_error=0; /* NON-ZERO values indicates error conditions... */
  30.  
  31. TEXT *error[6] = {
  32.                  "Amiga Format IFF/SMF SEARCH Utility (Paul Overaa 1990)... \n\n", 
  33.                  "Format... search <device>\n",
  34.                  "Device not found \n",
  35.                  "Sorry, not enough memory to continue\n",
  36.                  "Integrity error occured during searching \n"
  37.         };
  38.  
  39. /* --------------------------------------------------------------------- */
  40.  
  41. main(int argc, TEXT *argv[])
  42.  
  43. {
  44.  
  45. printf(error[0]); /* sign on message */
  46.  
  47. if (argc!=2) {printf(error[1]);}
  48.    
  49.   else { 
  50.         
  51.         CreateLevel(argv[1]);
  52.  
  53.         if(global_error) {printf(error[global_error]);}
  54.  
  55.        }
  56.         
  57. } /* logical end of program */
  58.  
  59.  
  60. /* --------------------------------------------------------------------- */
  61.  
  62. void CreateLevel(TEXT *imported_path)
  63.  
  64. {
  65.  
  66. TEXT   exported_path[300];
  67.  
  68. struct FileLock *FrameLock_p,*Lock(); 
  69. struct FileInfoBlock *fib_p;
  70.  
  71.   if(FrameLock_p=Lock(imported_path,ACCESS_READ))
  72.  
  73.          {
  74.  
  75.           if (fib_p=(struct FileInfoBlock *)AllocMem(FIB_SIZE,MEMF_PUBLIC))
  76.  
  77.                {
  78.  
  79.                  if(Examine(FrameLock_p,fib_p))
  80.  
  81.                      {
  82.  
  83.                       while(ExNext(FrameLock_p,fib_p))
  84.  
  85.                          {
  86.  
  87.                          strcpy(exported_path,imported_path); /* copy name */
  88.  
  89.                          if(exported_path[strlen(exported_path)-1]!=':') 
  90.  
  91.                              {strcat(exported_path,"/");}
  92.  
  93.                          strcat(exported_path,fib_p->fib_FileName);
  94.  
  95.                          if(fib_p->fib_DirEntryType<0) 
  96.  
  97.                              { /* FILE FOUND SO LOOK AT IT */
  98.              
  99.                               FileCheck(exported_path);
  100.  
  101.                               }
  102.  
  103.                                else { /* SET UP A NEW FRAME */
  104.             
  105.                                      CreateLevel(exported_path);
  106.             
  107.                                      }
  108.  
  109.                          }  
  110.  
  111.                      }  else {global_error=4;} /* Examine() failed */
  112.  
  113.                FreeMem(fib_p,FIB_SIZE);
  114.  
  115.                } else {global_error=3;} /* AllocMem() failed */
  116.  
  117.           UnLock(FrameLock_p);
  118.  
  119.      } else {global_error=2;} /* Lock() failed */
  120.  
  121. }
  122.  
  123. /* --------------------------------------------------------------------- */
  124.  
  125. void FileCheck(TEXT *filename)
  126.  
  127. {
  128.     
  129. struct FileHandle *fh;
  130. LONG   length;
  131.  
  132. if (fh=(struct FileHandle *)Open(filename, MODE_OLDFILE))
  133.  
  134.                {
  135.  
  136.                 length=Read(fh,buffer,BUFFERSIZE);
  137.  
  138.                 if(length==BUFFERSIZE)
  139.  
  140.                      { /* check for SMF or FORM identifiers */
  141.  
  142.                      if(*((LONG *)buffer)==ID_SMF) 
  143.                          
  144.                           { 
  145.                           
  146.                            printf("MIDI File: %s\n",filename); 
  147.                          
  148.                           }
  149.  
  150.                      else { 
  151.                          
  152.                            if(*((LONG *)buffer)==ID_FORM) 
  153.                          
  154.                               { 
  155.                                 
  156.                                printf("IFF ");
  157.                                printf("%c", *(buffer+8));
  158.                                printf("%c", *(buffer+9));
  159.                                printf("%c", *(buffer+10));
  160.                                printf("%c:  ", *(buffer+11));
  161.                                printf("%s\n", filename); 
  162.                           
  163.                               }
  164.  
  165.                           }
  166.                      
  167.                      } 
  168.  
  169.                 Close(fh);
  170.          
  171.                 }
  172.  
  173. }
  174.  
  175. /* --------------------------------------------------------------------- */
  176.  
  177.