home *** CD-ROM | disk | FTP | other *** search
- /*
- TREE.C Test Version.
- R.J.P. 9-5/90
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <kernel.h>
- #include <swis.h>
- #include "GREP.h"
-
- BOOL FileTree(char *CharPattern, char *dir , char *fn )
- {/*0*/
-
- _kernel_swi_regs KI ;
- _kernel_swi_regs KO ;
- _kernel_oserror *KE ;
- char *cp , *dbu ;
- int memsize ;
-
- memsize = MAX_FILE_NAME * (max_files+1) ;
- if( (dbu = (char *)malloc(memsize) ),dbu==0 )
- {
- fprintf(stderr,"**Tree :Out of Memory\n") ;
- return(4) ;
- }
- /*
- Use OS_GBPB call #9 to get the file-names in the current
- directory. These are loaded into dbu as a set of strings
- separated by null bytes.
- */
- KI.r[0] = 9 ;
- KI.r[1] = (int)dir ;
- KI.r[2] = (int)dbu ;
- KI.r[3] = max_files ;
- KI.r[4] = 0 ; /* No limit on items to Get. */
- KI.r[5] = memsize ; /* Maximum storage available. */
- KI.r[6] = (int)fn ;
- if( (KE = _kernel_swi( OS_GBPB , &KI , &KO ) ) != 0 )
- {
- fprintf(stderr,"OS_GBPB Error : %d\n%s\n",KE->errnum,KE->errmess) ;
- free(dbu) ;
- return 3 ;
- }
-
- if( !KO.r[3] )
- {
- if(B_EmptyReport)
- printf("**No files Found [%s.%s].\n",dir,fn ) ;
- free(dbu) ;
- return 5 ;
- }
- /*
- Recover the unused space in this directory file buffer.
- use the worst case file-name length in each case to work
- out the maximum space that could have been used.
- */
- if( ( cp = (char *)realloc(dbu,KO.r[3]*MAX_FILE_NAME),cp==0 )
- || cp != dbu )
- {
- fprintf(stderr,"Tree : Reallocate Failed.\n" ) ;
- free(dbu) ;
- return 7 ;
- }
-
- cp = dbu ;
- while( KO.r[3]-- )
- {
- SearchFile(CharPattern,dir,cp,fn) ;
- cp += strlen(cp)+1 ;
- }
- free(dbu) ;
- return FALSE ;
- }
-
-
-