home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / snip0693.zip / NAME2HDL.ASM < prev    next >
Assembly Source File  |  1993-03-13  |  5KB  |  180 lines

  1. ;_____________________________________________________________________________
  2. ;
  3. ;           Author: Terry Carmen
  4. ; Released to the Public Domain 3/11/1993
  5. ;_____________________________________________________________________________
  6. ;
  7. ;
  8. ;     Program Name:   name2hdl.asm
  9. ;        $Revision:   1.1  $
  10. ;            $Date:   11 Mar 1993 13:47:20  $
  11. ;
  12. ;
  13. ;
  14. ; Revision History:
  15. ;             $Log:   E:/logfiles/shoptrak/name2hdl.asv  $
  16. ;
  17. ;     Rev 1.1   11 Mar 1993 13:47:20
  18. ;  Improved comments and released to PD
  19. ;
  20. ;     Rev 1.0   12 Dec 1992  2:18:06
  21. ;  Initial Revision
  22. ;
  23. ;_____________________________________________________________________________
  24.  
  25.  
  26. ;Clipper callable function to return the handle when given the filename.
  27. ; This function uses no Clipper internals and gets the handle information
  28. ; from DOSs Job File Table
  29.  
  30. ; Note that it is unaware of paths, and you will confuse it if you have
  31. ; the same filename open in multiple directories at the same time.
  32. ; This shouldn't be a big problem
  33.  
  34. ;  usage:   cName:="CUST    DBF"
  35. ;           nHandle:=name2hdl(cName)
  36.  
  37. ;  note that the name ;must; be exactly 11 characters wide, and contain
  38. ;  no punctuation, and have the filename flush left and the
  39. ;  extention flush right.
  40.  
  41. ; assemble with TASM /mx /w2 name2hdl
  42.  
  43.  
  44. public name2hdl
  45.  
  46. extrn   __parc:far
  47. extrn   __parinfo:far
  48. extrn   __parclen:far
  49. extrn   __retni:far
  50. extrn   __ret:far
  51.  
  52. assume cs:_prog, ds:nothing, es:nothing
  53.  
  54. dgroup  group   datasg
  55. datasg  segment public  para 'DATA'
  56.  
  57.         namebuff   db 11 dup (' ')
  58.  
  59. datasg ends
  60.  
  61. _prog segment 'CODE'
  62.  
  63. name2hdl proc    far
  64.  
  65.         push    bp
  66.         mov     bp,sp
  67.         push    ds
  68.         push    es
  69.         push    si
  70.         push    di
  71.  
  72.         mov     ax, 0
  73.         push    ax
  74.         call    __parinfo           ; how many params?
  75.         add     sp,2
  76.         cmp     al,1                ; should be 1
  77.         jne     @@bad_exit          ; if not, we're out of here..
  78.  
  79.  
  80.         mov     ax, 1               ; check the type
  81.         push    ax
  82.         call    __parinfo
  83.         add     sp,2
  84.         and     ax,1                ; is it a string?
  85.         cmp     ax, 1
  86.         jne     @@bad_exit          ; if not, we're out of here..
  87.  
  88.         mov     ax, 1
  89.         push    ax
  90.         call    __parclen           ; how big is the string?
  91.         add     sp,2
  92.         cmp     ax, 11
  93.         jne     @@bad_exit
  94.  
  95.         mov     ax, 1
  96.         push    ax
  97.         call    __parc              ; where is the string?
  98.         add     sp,2                ; address in DX:AX
  99.  
  100.         mov     ds, dx              ; point ds:si to Clipper's string
  101.         mov     si, ax
  102.  
  103.         mov     ax, seg datasg       ; point es: to our buffer
  104.         mov     es, ax
  105.  
  106.         cld
  107.         mov     al, ' '
  108.         mov     cx, 11
  109.         mov     di, offset namebuff
  110.         rep stosb         ; al -> es:di   clear our buffer
  111.  
  112.         mov     cx, 11
  113.         mov     di, offset namebuff
  114.         rep movsb         ; ds:si -> es:di copy string to our buffer
  115.  
  116.         mov     bx,0                ; start with handle 1
  117.  
  118. @@next_handle:
  119.  
  120.         inc     bx
  121.         push    bx
  122.         mov     ah,12h              ; get JFT number
  123.         mov     al,20h              ; ES:DI will point to JFT
  124.         int     2Fh                 ; byte pointed at has SFT number
  125.         jc      @@bad_exit
  126.  
  127.         xor     bh,bh                   ; BX must contain SFT
  128.         mov     bl, byte ptr es:[di]    ; for this call
  129.         mov     ah,12h                  ; get SFT table for this file
  130.         mov     al,16h                  ; return address of SFT in ES:DI
  131.         int     2fh
  132.  
  133.         add     di,20h                  ; point es:[di] to file name in SFT
  134.  
  135.  
  136.         mov     ax, seg namebuff       ; point ds:si to our buffer
  137.         mov     ds, ax
  138.         mov     si, offset namebuff
  139.         mov     cx, 11
  140.  
  141.         cld
  142.         mov cx, 11                      ; 11 byte filename
  143.         rep cmpsb                       ; compare ds:si -> es:di
  144.         je @@good_exit
  145.  
  146.         pop bx                          ; because we pushed it at the top
  147.                                         ; of the loop
  148.         jmp short @@next_handle
  149.  
  150.  
  151. @@bad_exit:
  152.  
  153.        pop   bx ; because we pushed it at the top of the loop
  154.        call __ret                  ; return NIL
  155.        jmp short @@pop_regs
  156.  
  157.  
  158.  @@good_exit:                      ; we already pushed BX in the
  159.                                    ; top of the loop
  160.    mov    ax, seg dgroup           ; point ds to Clipper's dataseg
  161.    mov    ds, ax                   ; so it doesn't get all confused
  162.    call __retni                    ; send the data back to Clipper
  163.    add    sp,2                     ; fix the stack
  164.  
  165. @@pop_regs:
  166.  
  167.        pop    di
  168.        pop    si
  169.        pop    es
  170.        pop    ds
  171.        pop    bp
  172.        Ret
  173.  
  174. name2hdl endp
  175. ends
  176. end
  177.  
  178.  
  179. ;****************end of source code***********************
  180.