home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / ASM / ALIB30B / DISK9.ASM < prev    next >
Assembly Source File  |  1994-10-15  |  7KB  |  249 lines

  1.     page    66,132
  2. ;******************************** DISK9.ASM  *********************************
  3.  
  4. LIBSEG           segment byte public "LIB"
  5.         assume cs:LIBSEG , ds:nothing
  6.  
  7. ;----------------------------------------------------------------------------
  8. .xlist
  9.     include  mac.inc
  10.     include  common.inc
  11. .list
  12. ;----------------------------------------------------------------------------
  13.     extrn    dos_mem_allocate:far
  14.     extrn    dos_mem_release:far
  15. comment 
  16. ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(  DISK   )
  17. EXPAND_FILENAME - Expand a file string to the full path including drive.
  18. ;                 This is useful for user entered data which needs to
  19. ;                 be made consistient for processing.  See DECODE_FILENAME.
  20. ;
  21. ; inputs:    DS:[SI] pointing to a filename; the filename may contain
  22. ;                    drive specification and/or complete or partial path name.
  23. ;                    Drive specification and path name not required.
  24. ;                    Path string is terminated with a zero (null) character.
  25. ;                    
  26. ; outputs:  if no carry then,
  27. ;            DS:[SI] pointing to the full DRIVESPEC:\PATH\FILENAME
  28. ;            CX = length of full filename
  29. ;           if carry is set then filename is bad
  30. ;
  31. ; Note:  The file name is expanded and will overwrite the file name input.
  32. ;        Thus, the file name which is input needs to be in a buffer area
  33. ;        which will accomodate the expansion.       
  34. ;* * * * * * * * * * * * * *
  35. 
  36. expand_struc    struc
  37.  restore_drv        DB    0
  38.  restore_pth1           DB      ?        ;'\'
  39.  restore_pth2        DW    60 dup (?)
  40.  
  41.  tmp_target_path    db    64 dup (?)
  42.  
  43.  tested_path            db      ?,?,?        ;'x:\'
  44.              DB    64 dup (?)
  45.  
  46.  in_path        db    60 dup (?)    ;local copy of input data
  47.  in_path_ptr        dw    0        ;ptr to input data
  48.  
  49.  uin_path_ptr        DW    0        ;ptr to callers path info
  50.  uin_path_seg        dw    0        ;callers seg
  51. expand_struc    ends
  52. ;------------------------
  53.  
  54.     public    EXPAND_FILENAME
  55. EXPAND_FILENAME    PROC    FAR
  56.    apush   ax,bx,dx,si,di,bp,ds,es
  57. ;
  58. ; allocate memory for work area
  59. ;   
  60.    mov     dx,0
  61.    mov     ax,size expand_struc +1
  62.    call    DOS_MEM_ALLOCATE    ;returns area (es:0) if no carry
  63.    jc      ef_exit2        ;jmp if memory not available
  64. ;
  65. ; setup our memory area
  66. ;
  67.     mov    es:[uin_path_ptr],si
  68.     mov    es:[uin_path_seg],ds
  69.     mov    es:[restore_pth1],'\'
  70.     mov    word ptr es:[tested_path+1],'\:'
  71.     mov    word ptr es:in_path_ptr,offset in_path
  72. ;
  73. ; move users string into our memory area
  74. ;
  75.     mov    cx,-1
  76.     mov    di,offset in_path
  77. ef_lp1:    lodsb
  78.     stosb
  79.     inc    cx
  80.     cmp    al,0
  81.     jne    ef_lp1        ;loop till input copied to our memory
  82.    CLD
  83.    MOV     BX,ES
  84.    MOV     DS,BX
  85.    MOV     BP,CX
  86. ;
  87. ; save current path information
  88. ;   
  89.    MOV       AH,19h        ;current drive to AL
  90.    INT     21h
  91.    MOV     byte ptr ds:[restore_drv],AL
  92.    mov     SI,offset restore_pth2
  93.    MOV       AH,47h        ;current directory -> ds:si
  94.    MOV     DL,00
  95.    INT     21h
  96. ;
  97. ; check if drive was specified
  98. ;   
  99.    MOV     DI,word ptr ds:[in_path_ptr]
  100.    MOV     CX,BP        ;get length of in-path
  101.    CMP     CX,+02
  102.    JL      ef_sav_dir1        ;jmp if no drive was specified
  103.    CMP     BYTE PTR [DI+01],3Ah      ; ':'
  104.    JNZ     ef_sav_dir1        ;jmp if no drive was specified
  105.    MOV       DL,[DI]        ;get in-path drive letter
  106.    OR      DL,' '               ;force lower case
  107.    SUB     DL,'a'               ;  & convert to drive#
  108.    MOV       AH,0Eh        ;select in-path drive
  109.    INT     21h
  110. ;
  111. ; verify drive was selected (legal)
  112. ;   
  113.    MOV       AH,19h        ;current drive -> al
  114.    INT     21h
  115.    CMP       DL,AL        ;check if drive change occured
  116.    JZ       ef_drv_fnd        ;jmp if legal drive specified
  117.    JMP       ef_err_exit        ;illegal drive specified
  118. ef_drv_fnd:
  119.    ADD       DI,+02        ;move past in-path drive
  120.    SUB       CX,+02        ;decrement in-path length
  121. ;
  122. ; save current directory again for this new drive
  123. ;   
  124. ef_sav_dir1:
  125.    mov     SI,offset restore_pth2
  126.    MOV       AH,47h        ;current directory -> ds:si
  127.    MOV     DL,00
  128.    INT     21h
  129. ;
  130. ; extract path portion of file name
  131. ;   
  132.    PUSH    DI
  133.    MOV     AL,5Ch    ; '\'
  134. ef_more_ck:
  135.    MOV     word ptr ds:[in_path_ptr],DI
  136.    MOV     BP,CX
  137.    JCXZ    ef_last_slash        ;jmp if no in-path found
  138.    REPNZ   SCASB                ;scan for '\'
  139.    JZ      ef_more_ck           ;jmp if '\' path start found
  140. ef_last_slash:
  141.    POP       SI            ;get in-path ptr
  142. ;
  143. ; copy path to local buffer and put zero at end
  144. ;   
  145.    mov       DI,offset tmp_target_path    ;get tmp_target_path ptr
  146.    MOV     CX,word ptr ds:[in_path_ptr]
  147.    SUB     CX,SI                ;compute length of string to first in-path '\'
  148.    JZ       ef_bld_tested        ;jmp if null path
  149.    CMP     CX,+01
  150.    JZ       ef_bld_target        ;jmp if root dir
  151.    DEC     CX                   ;discard last '\'
  152. ;
  153. ; move path portion of string
  154. ;   
  155. ef_bld_target:
  156.    REPZ    MOVSB
  157.    XOR     AL,AL
  158.    STOSB                ;put zero at end of path string
  159. ;
  160. ; switch to target path
  161. ;   
  162.    mov       DX,offset tmp_target_path
  163.    MOV       AH,3Bh        ;set current dir -> ds:dx
  164.    INT     21h
  165.    JB       ef_err_exit
  166. ;
  167. ; Now, start building the tested path string from the current location
  168. ;   
  169. ef_bld_tested:
  170.    MOV       AH,19h        ;current drive -> al
  171.    INT     21h
  172.    ADD     AL,41h
  173.    MOV     byte ptr ds:[tested_path],AL
  174.    MOV     DL,00
  175.    mov     SI,offset tested_path+3
  176.    MOV       AH,47h        ;current dir to ds:si
  177.    INT     21h
  178.    JB       ef_err_exit
  179.    mov     DI,offset tested_path+3
  180. ;
  181. ; check if this is the root directory
  182. ;   
  183.    CMP     BYTE PTR [DI],00
  184.    JZ      ef_add_fname        ;jmp if this is root dir
  185.    XOR     AL,AL
  186.    MOV     CX,0FFFFh
  187.    REPNZ   SCASB
  188.    MOV     BYTE PTR [DI-01],5Ch      ; '\'
  189. ;
  190. ; append the filename to drive & path
  191. ;   
  192. ef_add_fname:
  193.    MOV     SI,word ptr ds:[in_path_ptr]
  194. ;
  195. ; check if this is a directory alias, '..' or '.'
  196. ;   
  197.    CMP     BYTE PTR [SI],2Eh     ; '.'
  198.    JZ       ef_err_exit             ;jmp if alias directory entry
  199.    MOV     CX,BP
  200.    REPZ    MOVSB
  201.    MOV     AL,CL
  202.    STOSB
  203.    mov     SI,offset tested_path
  204.    MOV     AX,DI
  205.    SUB     AX,SI
  206.    CLC
  207.    JMP     ef_restore_path
  208. ef_err_exit:
  209.    STC
  210. ef_restore_path:
  211.    PUSHF
  212.    PUSH    AX            ;save length of new path
  213. ;
  214. ; restore the origional directory
  215. ;   
  216.    MOV     DX,OFFSET restore_pth1
  217.    MOV       AH,3Bh        ;set current dir to ds:dx
  218.    INT     21h
  219. ;
  220. ; restore the origional drive
  221. ;   
  222.    MOV     DL,byte ptr ds:[restore_drv]
  223.    MOV       AH,0Eh        ;set current drive
  224.    INT     21h
  225. ;
  226. ; move new path to users buffer
  227. ;
  228.    pop     cx
  229.    push    cx
  230.    les     di,dword ptr ds:uin_path_ptr
  231.    mov     si,offset tested_path
  232.    rep     movsb
  233. ;
  234. ; release memory buffers
  235. ;
  236.    push    ds
  237.    pop     es
  238.    call    DOS_MEM_RELEASE
  239.       
  240.    POP     CX            ;get length of path
  241.    POPF
  242. ef_exit2:   
  243.    APOP    ES,DS,BP,DI,SI,DX,BX,AX
  244.    RETF
  245. EXPAND_FILENAME    ENDP
  246.  
  247. LIBSEG    ENDS
  248.     end
  249.