home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 1 / APDL_PD1A.iso / program / assembler / tasm / GREP / C / valid < prev   
Encoding:
Text File  |  1992-03-04  |  2.1 KB  |  75 lines

  1. /*
  2. valid.C   Search a file for a text string.
  3. R.J.P.    9-5/90
  4. */
  5.  
  6. #include       <stdio.h>
  7. #include       <string.h>
  8. #include       <stdlib.h>
  9. #include       <kernel.h>
  10. #include       <swis.h>
  11. #include       "grep.h"
  12.  
  13. char *ValidObject(char *CharPattern , char *path , char *fnB )
  14. {/*0*/
  15.  
  16.   _kernel_swi_regs    KI  ;
  17.   _kernel_swi_regs    KO  ;
  18.   _kernel_oserror    *KE  ;
  19.   int    Fatt        ;           
  20. /*
  21.         Finds the directory information on the given file.
  22.         and determines the type.
  23.         If no file can be found, give up and return.
  24.         If the file given is a directory, then recurse .
  25.         Otherwise, find if the file is a Machine code dump
  26.         by looking at the load address which has the top 3 
  27.         3 nibbles set to 0xfff if it is not.
  28. */
  29.   KI.r[0]  =  5  ;                  /* Using File$Path  */
  30.   KI.r[1]  =  (int)path  ;          /* R1 points to object name */
  31.   if( (KE = _kernel_swi( OS_File , &KI , &KO ) ) != 0 )
  32.   {
  33.     fprintf(stderr,"OS_File Error : %d\n%s\n",KE->errnum,KE->errmess) ;
  34.     return 0  ;
  35.   }
  36.   if( !KO.r[0] )
  37.   {
  38.     fprintf(stderr,"**Find error : %s\n" , path ) ;
  39.     return( 0 ) ;
  40.   }
  41.   
  42.   if( KO.r[0] == 2 )                  /*  It's Directory..... */
  43.   {
  44.     ++N_Direc ;
  45.     FileTree(CharPattern,path,fnB)  ; /*  Recurse   */
  46.     return 0 ;                        /*  Flag no file search on return.*/
  47.   }
  48.   
  49.   if( KO.r[0] != 1 )                  /*  Unknown........ */
  50.   return 0 ;
  51. /*  
  52.         Ok .. It's a File .......
  53.         Decode Load Address to find if Date-Stamped....                     
  54.         Load address should be    0xfffIIIId   bottom bit is part
  55.         of the 5-byte date field .
  56. */
  57.   ++N_Files  ;
  58.   if( ( ( KO.r[2] >> 20) & 0xfff)  != 0xfff  )
  59.   return 0   ;                                        /* It's a Dump.... */
  60.  
  61.   Fatt  =   (KO.r[2] >> 8) & 0xfff   ;      
  62.   switch( Fatt )
  63.   {
  64. case  TEXT_TYPE:          return("Text" ) ;
  65. case  DATA_TYPE:          return("Data" ) ;
  66. case  COMMAND_TYPE:       return("Cmd." ) ;
  67. case  OBEY_TYPE:          return("Obey" ) ;
  68. case  PRINT_TYPE:         return("Prt." ) ;
  69. default:                  break;
  70.   }
  71.   return 0 ;
  72. }/*0*/
  73.  
  74.  
  75.