1 ; SCCSID = @(#)search.asm 1.1 85/04/10
2 TITLE SEARCH
- Directory scan system calls
7 ; Directory search system calls. These will be passed direct text of the
8 ; pathname from the user. They will need to be passed through the macro
9 ; expander prior to being sent through the low-level stuff. I/O specs are
10 ; defined in DISPATCH. The system calls are:
13 ; $Dir_Search_First written
14 ; $Dir_Search_Next written
19 ; Modification history:
21 ; Created: ARR 4 April 1983
26 ; get the appropriate segment definitions
30 CODE SEGMENT BYTE PUBLIC 'CODE'
31 ASSUME
SS:DOSGroup
,CS:DOSGroup
48 I_need Fastopenflg
,BYTE
49 I_need DOS34_FLAG
,WORD
52 ; DS:DX Points to unopenned FCB
54 ; Directory is searched for first matching entry and the directory
55 ; entry is loaded at the disk transfer address
57 ; AL = -1 if no entries matched, otherwise 0
59 procedure $DIR_SEARCH_FIRST
,NEAR
60 ASSUME
CS:DOSGroup
,DS:NOTHING
,ES:NOTHING
,SS:DOSGroup
62 MOV WORD PTR [THISFCB
],DX
63 MOV WORD PTR [THISFCB
+2],DS
65 CMP BYTE PTR [SI],0FFH
67 ADD SI,7 ; Point to drive select byte
69 SaveReg
<[SI]> ; Save original drive byte for later
70 Context
ES ; get es to address DOSGroup
71 MOV DI,OFFSET DOSGroup
:OpenBuf
; appropriate buffer
72 invoke TransFCB
; convert the FCB, set SATTRIB EXTFCB
73 JNC SearchIt
; no error, go and look
74 RestoreReg
<BX> ; Clean stack
78 transfer FCB_Ret_Err
; error
81 Context
DS ; get ready for search
82 SaveReg
<<WORD PTR [DMAAdd
]>, <WORD PTR [DMAAdd
+2]>>
83 MOV WORD PTR [DMAAdd
],OFFSET DOSGroup
:SEARCHBUF
84 MOV WORD PTR [DMAAdd
+2],DS
85 invoke GET_FAST_SEARCH
; search
86 RestoreReg
<<WORD PTR [DMAAdd
+2]>, <WORD PTR [DMAAdd
]>>
87 JNC SearchSet
; no error, transfer info
88 RestoreReg
<BX> ; Clean stack
95 ; The search was successful (or the search-next). We store the information
96 ; into the user's FCB for continuation.
99 MOV SI,OFFSET DOSGroup
:SEARCHBUF
100 LES DI,[THISFCB
] ; point to the FCB
103 ADD DI,7 ; Point past the extension
105 RestoreReg
<BX> ; Get original drive byte
111 LODSB ; Get correct search contin drive byte
112 XCHG AL,BL ; Search byte to BL, user byte to AL
114 ; STOSB ; Store the correct "user" drive byte
115 ; at the start of the search info
117 REP MOVSW ; Rest of search cont info, SI -> entry
118 XCHG AL,BL ; User drive byte back to BL, search
120 STOSB ; Search contin drive byte at end of
133 MOV AL,BL ; User Drive byte
136 MOVSW ; 2/13/KK ;AN000;
137 CMP BYTE PTR ES:[DI-2],5 ; 2/13/KK ;AN000;
138 JNZ NOTKTRAN
; 2/13/KK ;AN000;
139 MOV BYTE PTR ES:[DI-2],0E5H ; 2/13/KK ;AN000;
140 NOTKTRAN: ; 2/13/KK ;AN000;
141 MOV CX,15 ; 2/13/KK ;AN000;
143 MOV CX,16 ; 32 / 2 words of dir entry ;AN000;
148 EndProc $DIR_SEARCH_FIRST
151 ; DS:DX points to unopenned FCB returned by $DIR_SEARCH_FIRST
153 ; Directory is searched for the next matching entry and the directory
154 ; entry is loaded at the disk transfer address
156 ; AL = -1 if no entries matched, otherwise 0
158 procedure $DIR_SEARCH_NEXT
,NEAR
159 ASSUME
CS:DOSGroup
,DS:NOTHING
,ES:NOTHING
,SS:DOSGroup
161 MOV WORD PTR [THISFCB
],DX
162 MOV WORD PTR [THISFCB
+2],DS
166 MOV DI,OFFSET DOSGroup
:SEARCHBUF
168 CMP BYTE PTR [SI],0FFH
175 LODSB ; Get original user drive byte
176 SaveReg
<AX> ; Put it on stack
177 MOV AL,[SI+20] ; Get correct search contin drive byte
178 STOSB ; Put in correct place
180 REP MOVSW ; Transfer in rest of search contin info
182 SaveReg
<<WORD PTR [DMAAdd
]>, <WORD PTR [DMAAdd
+2]>>
183 MOV WORD PTR [DMAAdd
],OFFSET DOSGroup
:SEARCHBUF
184 MOV WORD PTR [DMAAdd
+2],DS
185 invoke DOS_SEARCH_NEXT
; Find it
186 RestoreReg
<<WORD PTR [DMAAdd
+2]>, <WORD PTR [DMAAdd
]>>
188 JMP SearchSet
; Ok set return
194 ADD DI,7 ; Point past the extension
196 RestoreReg
<BX> ; Get original drive byte
197 MOV ES:[DI],BL ; Store the correct "user" drive byte
200 ; error code is in AX
204 EndProc $DIR_SEARCH_NEXT
211 ; ; DMA address has datablock
214 ; AX = error_path_not_found
215 ; = error_no_more_files
217 procedure $FIND_FIRST
,NEAR
218 ASSUME
CS:DOSGroup
,DS:NOTHING
,ES:NOTHING
,SS:DOSGroup
220 MOV SI,DX ; get name in appropriate place
221 MOV [SATTRIB
],CL ; Search attribute to correct loc
222 MOV DI,OFFSET DOSGroup
:OpenBuf
; appropriate buffer
223 invoke TransPathSet
; convert the path
224 JNC Find_it
; no error, go and look
226 error error_path_not_found
; error and map into one.
229 SaveReg
<<WORD PTR [DMAAdd
]>, <WORD PTR [DMAAdd
+2]>>
230 MOV WORD PTR [DMAAdd
],OFFSET DOSGroup
:SEARCHBUF
231 MOV WORD PTR [DMAAdd
+2],DS
232 invoke GET_FAST_SEARCH
; search
233 RestoreReg
<<WORD PTR [DMAAdd
+2]>, <WORD PTR [DMAAdd
]>>
234 JNC FindSet
; no error, transfer info
238 MOV SI,OFFSET DOSGroup
:SEARCHBUF
242 PUSH SI ; Save pointer to start of entry
249 INC SI ; Skip dir_first
250 MOVSW ; dir_size (2 words)
252 POP SI ; Point back to dir_name
254 PUSH DI ; XXXX save dest name 2/13/KK ;AN000;
255 CALL PackName
;AN000;
256 POP DI ; XXXX Recover dest name 2/13/KK ;AN000;
257 CMP BYTE PTR ES:[DI],05H ; XXXX Need fix? 2/13/KK ;AN000;
258 JNZ FNXXX
; XXXX No 2/13/KK ;AN000;
259 MOV BYTE PTR ES:[DI],0E5H ; XXXX Yes, Fix 2/13/KK ;AN000;
260 FNXXX: ; 2/13/KK ;AN000;
264 transfer Sys_Ret_OK
; bye with no errors
267 procedure $FIND_NEXT
,NEAR
268 ASSUME
CS:DOSGroup
,DS:NOTHING
,ES:NOTHING
,SS:DOSGroup
271 ; ; dma points at area returned by find_first
274 ; ; next entry is at dma
277 ; AX = error_no_more_files
280 MOV DI,OFFSET DOSGroup
:SEARCHBUF
283 REP MOVSB ; Put the search continuation info
285 Context
DS ; get ready for search
286 SaveReg
<<WORD PTR [DMAAdd
]>, <WORD PTR [DMAAdd
+2]>>
287 MOV WORD PTR [DMAAdd
],OFFSET DOSGroup
:SEARCHBUF
288 MOV WORD PTR [DMAAdd
+2],DS
289 invoke DOS_SEARCH_NEXT
; Find it
290 RestoreReg
<<WORD PTR [DMAAdd
+2]>, <WORD PTR [DMAAdd
]>>
291 JNC FindSet
; No error, set info
296 Break <PackName
- convert
file names
from FCB to ASCIZ
>
298 ; PackName - transfer a file name from DS:SI to ES:DI and convert it to
301 ; Input: DS:SI points to an 11 character FCB or dir entry name
302 ; ES:DI points to a destination area (13 bytes)
303 ; Output: Above pointers advanced
304 ; Registers modified: SI,DI,CX,AL
305 Procedure PackName
,NEAR
306 ASSUME
CS:DOSGroup
,DS:NOTHING
,ES:NOTHING
,SS:DOSGroup
307 MOV CX,8 ; Pack the name
308 REP MOVSB ; Move all of it
310 CMP BYTE PTR ES:[DI-1]," "
312 DEC DI ; Back up over trailing space
317 CMP WORD PTR [SI],(" " SHL 8) OR " "
318 JNZ got_ext
; Some chars in extension
319 CMP BYTE PTR [SI+2]," "
320 JZ find_done
; No extension
327 CMP BYTE PTR ES:[DI-1]," "
329 DEC DI ; Back up over trailing space
333 STOSB ; NUL terminate
337 procedure GET_FAST_SEARCH
,NEAR
338 ASSUME
DS:NOTHING
,ES:NOTHING
340 OR [DOS34_FLAG
],SEARCH_FASTOPEN
;FO.trigger fastopen ;AN000;
341 invoke DOS_SEARCH_FIRST
344 EndProc GET_FAST_SEARCH