home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / DISKE.ASM < prev    next >
Assembly Source File  |  1994-12-18  |  4KB  |  175 lines

  1.     page    66,132
  2. ;******************************** DISKE.ASM  *********************************
  3.  
  4.         public    walk_path
  5.  
  6. LIBSEG           segment byte public "LIB"
  7.         assume cs:LIBSEG , ds:nothing
  8.  
  9. ;----------------------------------------------------------------------------
  10. .xlist
  11.     include  mac.inc
  12.     extrn    expand_filename:far
  13. .list
  14. ;----------------------------------------------------------------------------
  15. LocalAlloc    equ    2ch        ;size of DTA for stack allocation
  16.  
  17. filename    db    128 dup (0)
  18. UpOneLevel    db    "..",0
  19. FileMask    db    13 dup (0)
  20. process        label    dword
  21. process_offset    dw    0
  22. process_seg    dw    0
  23.  
  24. comment 
  25. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  DISK   )
  26. ;walk_path - compress data block
  27. ;
  28. ; inputs:  ds:si = pointer to asciiz file mask
  29. ;          ax    = pointer to processing for each file match.
  30. ;                  This must be a FAR routine with same CS as calling
  31. ;                  program.
  32. ;          cx    = file attributes to match.
  33. ;                  0000 - match normal data files
  34. ;                  0001 - find read only files
  35. ;                  0002 - find hidden files
  36. ;                  0004 - find system files and directories
  37. ;                  0008 - find volume labels
  38. ;                  0010 - walk subdirectories also
  39. ;
  40. ;                  note: attributes may be combined in some cases.
  41. ;
  42. ; output:  The feed proceedure is called with:  es:di = ptr to file found.
  43. ;          The file name found is fully quailfied and includes drive.
  44. ;          The current directory is where the match file was found.
  45. ;
  46. ;          After all files are processed walk_path exits with all regiseters
  47. ;          restored.
  48. ;
  49. ; note:  The path walk starts with the current directory and includes each
  50. ;        subdirectory found.
  51. ;* * * * * * * * * * * * * *
  52. 
  53. walk_path         proc     far
  54.     apush    ax,bx,cx,dx,si,di,bp,ds,es
  55.     mov    bp,sp
  56.     mov    cs:process_offset,ax
  57.     mov    ax,word ptr [bp+20]        ;get callers cs
  58.     mov    cs:process_seg,ax
  59. ;
  60. ; copy file mask from ds:si to cs:FileMask
  61. ;
  62.     cld
  63.     push    cs
  64.     pop    es
  65.     mov    di,offset FileMask
  66. wp_lp1:
  67.     lodsb
  68.     stosb
  69.     test    al,al
  70.     jnz    wp_lp1
  71.     push    cs
  72.     pop    ds
  73.     call    recursive_walk
  74.     apop    es,ds,bp,di,si,dx,cx,bx,ax
  75.         retf
  76. walk_path         endp
  77. ;
  78. ;--------------------------------------------------------------------------
  79. ; recursive_walk - walk till out of files/directories.
  80. ;  inputs:  ds,es = our code/data segment
  81. ;           FileMask =  match mask in asciiz form.
  82. ;           Process  =  far ptr to processing routine           
  83. ;
  84. recursive_walk:
  85.     push    bp
  86.         mov     ah,2Fh                  ;Get DTA address
  87.         int     21h
  88.         push    bx                      ;Save it on the stack
  89.         push    es
  90.         sub     sp,LocalAlloc           ;Allocate stack space
  91.         mov     bp,sp                   ;Stack pointer in BP
  92.         push    ss
  93.         pop    ds
  94.         mov     ah,1Ah                  ;Change DTA to location
  95.         mov     dx,bp                   ;on the stack
  96.         int     21h
  97. ;
  98.     mov    ah,4eh            ;DOS function (find first)    
  99. rs_loop:                ;mov cx,10h ;attribute = files & dir's
  100.     mov    dx,offset FileMask
  101.     push    cs
  102.     pop    ds
  103.     int    21h
  104.     jc    exit            ;jmp if end of this dir
  105.     cmp    byte ptr [bp+1eh],'.'    ;check if directory header
  106.     je    tail            ;jmp if header file
  107.     test    byte ptr [bp+15h],10h    ;check if directory entry
  108.     jz    file_fnd        ;jmp if not dir, and is file
  109. ;
  110. ; we have encountered a directory, switch to it and look for files
  111. ;
  112.     mov    ah,3bh
  113.     mov    dx,bp
  114.     add    dx,30
  115.     push    ss
  116.     pop    ds    
  117.     int    21h    
  118.  
  119.     push    bp
  120.     call    recursive_walk
  121.     pop    bp
  122. ;
  123. ; we are back from directory processing, restore origional dir.
  124. ;
  125.     mov    ah,3bh
  126.     mov    dx,offset UpOneLevel
  127.     push    cs
  128.     pop    ds
  129.     int    21h
  130.     jmp    tail
  131. ;
  132. ; we have found a file the caller wants to process
  133. ;
  134. file_fnd:
  135.     mov    si,bp
  136.     add    si,30
  137.     push    ss
  138.     pop    ds
  139.  
  140.     push    cs
  141.     pop    es    
  142.     mov    di,offset filename
  143. move_it:
  144.     lodsb
  145.     stosb
  146.     cmp    al,0
  147.     jne    move_it
  148.  
  149.     mov    si,offset filename
  150.     push    es
  151.     pop    ds
  152.     call    expand_filename
  153.     mov    di,si
  154.  
  155.     call    process
  156.  
  157. tail:    mov    ah,4fh
  158.     jmp    rs_loop    
  159. ;
  160. ; restore origional DTA from stack.
  161. ;
  162. exit:    add    sp,LocalAlloc    ;deallocate stack space
  163.     
  164.     mov    bx,ds
  165.     mov    ah,1ah        ;restore previous DTA
  166.     pop    ds
  167.     pop    dx
  168.     int    21h
  169.     mov    ds,bx
  170.     pop    bp
  171.     ret
  172.     
  173.     
  174. LIBSEG    ENDS
  175. ;;    end