home *** CD-ROM | disk | FTP | other *** search
- /*
- MAIN.C Main program of recursive Grep.
- R.J.P. 9-5/90
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <kernel.h>
- #include <swis.h>
- #include "grep.h"
-
- int max_files = 1000 ;
- BOOL B_FileOnly = FALSE ;
- BOOL B_EmptyReport = FALSE ;
- BOOL B_Statistics = TRUE ;
- BOOL B_AnyCase = FALSE ;
- int N_Files = 0 ;
- int N_Hits = 0 ;
- int N_Lines = 0 ;
- int N_Direc = 0 ;
-
- int main ( int ac , char **av)
- {
- char *cp ;
- char *CharPattern ;
- char BaseDir[MAX_DIR_NAME] ;
- char StartFile[MAX_FILE_NAME] ;
-
- if( (comline(ac,av,"HELP") != 0 ) || !(--ac) )
- {
- HelpInformation();
- return 1 ;
- }
-
- CharPattern = *++av ; /* First parameter is a pattern*/
- cp = *(av+1);
- if( !(--ac) || *cp == '-' || *cp == '/')
- strcpy(BaseDir,"$.*") ; /* Default no second path parameter */
- else
- {
- strcpy(BaseDir,*++av) ;
- --ac ; /* claim a parameter */
- }
-
- if( ac )
- {
- if( ( cp = comline(ac,av,"N") ) != 0 )max_files = atoi(cp) ;
- if( comline(ac,av,"F" ) ) B_FileOnly = TRUE ;
- if( comline(ac,av,"E" ) ) B_EmptyReport = TRUE ;
- if( comline(ac,av,"X" ) ) B_Statistics = FALSE ;
- if( comline(ac,av,"A" ) ) B_AnyCase = TRUE ;
- }
-
- if( (cp = strrchr(BaseDir , '.') ) != 0 )
- {
- /*
- peel the file name off the end of the directory path
- */
- *cp = '\0' ; /* Terminate Dir String. */
- strcpy(StartFile,++cp) ;
- }
- else
- strcpy(StartFile,"*" ) ;
-
- if( B_AnyCase) strupper(CharPattern) ;
- /*
- the file name bit of the path should follow.
- it can be a wild-card (name with a '*' at the end)
- */
- if( FileTree(CharPattern, BaseDir,StartFile) )
- {
- fprintf(stderr,"**Tree Search Error.\n") ;
- return TRUE ;
- }
- SummaryReport() ;
- return 0 ;
- }
-
-
-