        .title  logical_lookup
;
;  Author     : Arne Vajhøj
;
;  Programmed : july/august 1994 by Arne Vajhøj
;
;  Purpose    : lookup all logicals in table
;
        .link   "sys$system:sys.stb"/selective_search
        .library "SYS$LIBRARY:LIB"
        $LNMSTRDEF
        .psect  $LOCAL quad,pic,con,lcl,noshr,noexe,wrt
dir:    .blkl   1
hash:   .blkl   1
tblnml: .blkw   1
tblnm:  .blkb   32
tbladr: .blkl   1
        .psect  $CODE quad,pic,con,lcl,shr,exe,nowrt
;
;  Entry : LOGICAL_LOOKUP ( LNM , LNML , NLNM , TABLE )
;
;  Functionality : Lookup all logicals in a specified logical name table
;
;  Arguments : LNM
;              logical name
;              fixed length chracter string passed by descriptor (array)
;              writeonly
;
;              LNML
;              length logical name
;              longword passed by reference (array)
;              writeonly
;
;              NLNM
;              number of logical names
;              longword passed by refrence
;              writeonly
;
;              TABLE
;              table to search for logicals
;              fixed length chracter string passed by descriptor
;              readonly
;
;  Priviliges required : CMEXEC     if table is in system-directory
;                                   (not in process-directory)
;
;  return codes : SS$_NORMAL       successfull
;                 SS$_NOPRIV       no CMEXEC privilige present
;                 SS$_IVLOGTAB     logicalname table not found
;
;
;
;  Bugs : Please mail bug-reports to ARNE@KO.HHS.DK (Arne Vajhøj).
;
;;VAX
        .entry  logical_lookup,^m<r2,r3,r4,r5>
;;VAX
;;AXP
;;logical_lookup:: .call_entry home_args=TRUE,max_args=4
;;AXP
        movl    B^16(ap),r0
        addw3   #1,(r0),tblnml
        movb    (r0),tblnm
        movc3   (r0),@B^4(r0),tblnm+1
        movl    @#LNM$AL_DIRTBL+4,r0    ; LNM$PROCESS_DIRECTORY
        movl    (r0),dir
        movl    @#LNM$AL_HASHTBL+4,r0
        movl    (r0),hash
        callg   (ap),G^logical_lookup2  ; user-mode call of lookup2
        cmpl    r0,#SS$_NORMAL
        bneq    100$
        ret
100$:   cmpl    r0,#SS$_IVLOGTAB
        bneq    200$
        movl    @#LNM$AL_DIRTBL,r0      ; LNM$SYSTEM_DIRECTORY
        movl    (r0),dir
        movl    @#LNM$AL_HASHTBL,r0
        movl    (r0),hash
        pushl   ap
        pushab  G^logical_lookup2
        calls   #2,G^SYS$CMEXEC         ; executive-mode call of lookup2
        cmpl    r0,#SS$_NORMAL
        bneq    200$
        ret
200$:   clrl    @B^12(ap)
        ret
        .entry  logical_lookup2,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
        movl    dir,r6                  ; address of logical-directory
        movl    B^LNMB$L_TABLE(r6),r6   ; address of logical-directory-header
        movl    B^LNMTH$L_CHILD(r6),r6  ; address of first logical-table
100$:   movl    B^LNMTH$L_NAME(r6),r7
;;VAX
        cmpc3   tblnml,B^LNMB$S_LNMBDEF-1(r7),tblnm ; test if table-name match
;;VAX
;;AXP
;;        cmpc3   B^LNMB$L_NAMELEN(r7),B^LNMB$T_NAME(r7),tblnm+1 ; test if table-name match
;;AXP
        tstl    r0
        beql    200$
        tstl    B^LNMTH$L_SIBLING(r6)   ; test if more tables
        beql    150$
        movl    B^LNMTH$L_SIBLING(r6),r6 ; goto next table
        brb     100$
150$:   clrl    @B^12(ap)               ; table not found so no logicals
        movl    #SS$_IVLOGTAB,r0
        ret
200$:   movl    r6,tbladr               ; address of logical-table-header
        movl    B^4(ap),r0
        movl    B^4(r0),r9              ; address of string-array
        movzwl  (r0),r10                ; size of string-array-elements
        movl    B^8(ap),r11             ; address of length-array
        clrl    @B^12(ap)               ; number of logicals
        movl    hash,r6                 ; address of hash-table
        movzwl  B^LNMHSH$W_SIZE(r6),r7  ; size of hash-table
        addl2   r6,r7                   ; end-address of hash-entries
        addl2   #LNMHSH$S_LNMHSHDEF,r6  ; start-address of hash-entries
300$:   cmpl    r6,r7                   ; test if finished
        bgeq    700$
        tstl    (r6)                    ; test if zero-entry
        beql    600$
        movl    (r6),r8                 ; address of logical-name-block
400$:   cmpl    B^LNMB$L_TABLE(r8),tbladr ; test if table match
        bneq    500$
;;VAX
        cvtbl   B^LNMB$S_LNMBDEF-1(r8),(r11) ; get length
        movc3   (r11),B^LNMB$S_LNMBDEF(r8),(r9) ; get string
;;VAX
;;AXP
;;        movl    B^LNMB$L_NAMELEN(r8),(r11) ; get length
;;        movc3   (r11),B^LNMB$T_NAME(r8),(r9) ; get string
;;AXP
        addl2   r10,r9
        addl2   #4,r11
        incl    @B^12(ap)
500$:   tstl    B^LNMB$L_FLINK(r8)      ; test if forward-link
        beql    600$
        movl    B^LNMB$L_FLINK(r8),r8   ; goto next in link
        brb     400$
600$:   addl2   #4,r6
        brb     300$
700$:   movl    #SS$_NORMAL,r0
        ret
        .end
