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

  1. /*
  2. TREE.C   Test Version.
  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. BOOL FileTree(char *CharPattern, char *dir , char *fn )
  14. {/*0*/
  15.  
  16.   _kernel_swi_regs    KI  ;
  17.   _kernel_swi_regs    KO  ;
  18.   _kernel_oserror    *KE  ;
  19.   char               *cp  , *dbu  ;    
  20.   int                memsize ;
  21.   
  22.   memsize  =   MAX_FILE_NAME * (max_files+1) ;
  23.   if( (dbu  =  (char *)malloc(memsize) ),dbu==0 )
  24.   {
  25.     fprintf(stderr,"**Tree :Out of Memory\n") ;
  26.     return(4) ;
  27.   }
  28. /*
  29.          Use  OS_GBPB  call #9 to get the file-names in the current
  30. directory.  These are loaded into dbu as a set of strings
  31. separated by null bytes.
  32. */
  33.   KI.r[0]  =  9  ;
  34.   KI.r[1]  =  (int)dir  ;
  35.   KI.r[2]  =  (int)dbu  ;
  36.   KI.r[3]  =  max_files ;
  37.   KI.r[4]  =  0  ;               /* No limit on items to Get. */
  38.   KI.r[5]  =  memsize   ;        /* Maximum storage available. */
  39.   KI.r[6]  =  (int)fn  ;
  40.   if( (KE  = _kernel_swi( OS_GBPB , &KI , &KO ) ) != 0 )
  41.   {
  42.     fprintf(stderr,"OS_GBPB Error : %d\n%s\n",KE->errnum,KE->errmess) ;
  43.     free(dbu) ;
  44.     return 3 ;
  45.   }
  46.   
  47.   if( !KO.r[3] )
  48.   {
  49.     if(B_EmptyReport)
  50.     printf("**No files Found [%s.%s].\n",dir,fn ) ;
  51.     free(dbu) ;
  52.     return  5 ; 
  53.   }
  54. /*
  55.         Recover the unused space in this directory file buffer.
  56.         use the worst case file-name length in each case to work
  57.         out the maximum space that could have been used.
  58. */
  59.   if( ( cp = (char *)realloc(dbu,KO.r[3]*MAX_FILE_NAME),cp==0 )
  60.       || cp != dbu  )
  61.   {
  62.     fprintf(stderr,"Tree : Reallocate Failed.\n" ) ;
  63.     free(dbu) ;
  64.     return  7  ;
  65.   }
  66.   
  67.   cp   =  dbu ;
  68.   while( KO.r[3]-- )
  69.   {
  70.     SearchFile(CharPattern,dir,cp,fn) ;
  71.     cp += strlen(cp)+1 ;
  72.   }
  73.   free(dbu) ;
  74.   return  FALSE ;
  75. }
  76.  
  77.  
  78.