home *** CD-ROM | disk | FTP | other *** search
- ;unsigned short seek_subdirectory(dir_name,st_element,tree_array);
- ; char *tree_array,*dir_name;
- ; unsigned short st_element;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
- EXTRN _tree_array_size:word
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _seek_subdirectory
- _seek_subdirectory proc near
- push bp ;
- mov bp,sp ;
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;
- mov _error_code,3 ;3 = DirName wrong size
- cmp _memory_model,2 ;data near or far?
- jb L0 ;
- les di,dword ptr[bp+4] ;ES:DI pts to DirName
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L00 ;
- L0: mov ax,ds ;ES = DS
- mov es,ax ;
- mov di,[bp+4] ;NEAR case
- L00: sub cx,cx ;
- push di ;find string length...
- L000: cmp byte ptr es:[di],0 ;end of string?
- je L1 ;
- inc di ;forward ptr
- inc cx ;inc strg length counter
- jmp short L000 ;
- L1: pop di ;back to start of string
- jcxz L8 ;quit if string is null
- cmp cl,12 ;longer than 12 chars?
- ja L8 ;quit if so
- mov si,di ;keep a copy of startpoint
- inc cx ;last byte (null) must match too
- mov dx,cx ;copy of DirName length
- dec _error_code ;2 = StElement out of range
- L2: cmp byte ptr es:[di],97 ;compare to 'a'
- jb L3 ;jump ahead if below
- cmp byte ptr es:[di],122 ;compare to 'z'
- ja L3 ;jump ahead if above
- sub byte ptr es:[di],32 ;make upper case
- L3: inc di ;forward pointer
- loop L2 ;go do next char
- mov di,si ;point ES:DI back to string descriptor
- mov ax,[bp+6] ;fetch StartElement
- or ax,ax ;test for 0
- jz L8 ;quit if zero
- mov bx,_tree_array_size ;getch _tree_array_size
- cmp ax,bx ;in range?
- ja L8 ;quit if not
- dec _error_code ;1 = no match found
- dec ax ;count from 0 to figure offset
- sub bx,ax ;number elements to check
- mov cl,21 ;bytes per record
- mul cl ;figure offset
- cmp _memory_model,2 ;data near or far?
- jb L4 ;
- lds si,dword ptr[bp+8] ;DS:SI pts to array
- jmp short L5 ;
- L4: mov si,[bp+8] ;
- L5: add si,21 ;start from first array element
- add si,ax ;now DS:SI pts to element
- cld ;direction forward
- L6: push di ;save pointer start points
- push si ;
- mov cx,dx ;DirName length
- repe cmpsb ;compare the strings
- pop si ;restore start points
- pop di ;
- jz L7 ;match found
- dec bx ;dec element counter
- jz L8 ;quit if all elements compared
- add si,21 ;forward to next element name
- jmp short L6 ;loop
- L7: pop ds ;found it
- mov _error_code,0 ;0 = match found
- mov ax,_tree_array_size ;calculate match offset
- sub ax,bx ;
- inc ax ;
- jmp short L9 ;go quit
- L8: pop ds ;out of elements, didn't find
- sub ax,ax ;return 0 as position
- L9: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _seek_subdirectory endp
- _TEXT ENDS
- END