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

  1. /*
  2. MAIN.C   Main program of recursive Grep.
  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. int    max_files      =  1000 ;
  14. BOOL   B_FileOnly     =  FALSE ;
  15. BOOL   B_EmptyReport  =  FALSE ;
  16. BOOL   B_Statistics   =  TRUE  ;
  17. BOOL   B_AnyCase      =  FALSE ;
  18. int    N_Files        =  0  ;
  19. int    N_Hits         =  0  ;
  20. int    N_Lines        =  0  ;
  21. int    N_Direc        =  0  ;
  22.  
  23. int  main  ( int ac , char **av)
  24. {
  25.   char    *cp   ;
  26.   char    *CharPattern  ;    
  27.   char    BaseDir[MAX_DIR_NAME] ;
  28.   char    StartFile[MAX_FILE_NAME] ;
  29.   
  30.   if( (comline(ac,av,"HELP") != 0 ) || !(--ac) )
  31.   {
  32.     HelpInformation();
  33.     return 1 ;
  34.   }
  35.   
  36.   CharPattern    =   *++av ;               /* First parameter is a pattern*/
  37.   cp     =   *(av+1);       
  38.   if( !(--ac) || *cp == '-' || *cp == '/') 
  39.   strcpy(BaseDir,"$.*") ;             /* Default no second path parameter */
  40.   else
  41.   {
  42.     strcpy(BaseDir,*++av) ;  
  43.     --ac ;                                          /*  claim a parameter */
  44.   }
  45.   
  46.   if( ac )
  47.   {
  48.     if( ( cp = comline(ac,av,"N") ) != 0 )max_files     = atoi(cp) ;    
  49.     if( comline(ac,av,"F" ) )             B_FileOnly    = TRUE ;   
  50.     if( comline(ac,av,"E"  ) )            B_EmptyReport = TRUE ;
  51.     if( comline(ac,av,"X"  ) )            B_Statistics  = FALSE ;
  52.     if( comline(ac,av,"A"  ) )            B_AnyCase     = TRUE  ;
  53.   }
  54.   
  55.   if( (cp = strrchr(BaseDir , '.') ) != 0 )  
  56.   {
  57. /*
  58.  peel the file name off the end of the directory path
  59. */
  60.     *cp  =   '\0'  ;                              /* Terminate Dir String. */
  61.     strcpy(StartFile,++cp) ;
  62.   }
  63.   else  
  64.   strcpy(StartFile,"*" ) ;
  65.   
  66.   if( B_AnyCase)   strupper(CharPattern) ;
  67. /*
  68.         the file name bit of the path should follow.
  69.         it can be a wild-card (name with a '*' at the end)
  70. */
  71.   if( FileTree(CharPattern, BaseDir,StartFile) )
  72.   {
  73.     fprintf(stderr,"**Tree Search Error.\n")  ;
  74.     return TRUE   ;
  75.   }
  76.   SummaryReport() ;      
  77.   return 0 ;
  78. }
  79.  
  80.  
  81.