     1                                  ;	SCCSID = @(#)isearch.asm	1.1 85/04/10
     2                                  ;TITLE	DOS_SEARCH - Internal SEARCH calls for MS-DOS
     3                                  ;NAME	DOS_SEARCH
     4                                  ; Low level routines for doing local and NET directory searches
     5                                  ;
     6                                  ;   DOS_SEARCH_FIRST
     7                                  ;   DOS_SEARCH_NEXT
     8                                  ;   RENAME_NEXT
     9                                  ;
    10                                  ;   Revision history:
    11                                  ;
    12                                  ;	Created: ARR 30 March 1983
    13                                  ;	A000	version 4.00  Jan. 1988
    14                                  ;	A001	PTM 3564 -- serach for fastopen
    15                                  
    16                                  ;
    17                                  ; get the appropriate segment definitions
    18                                  ;
    19                                  [list -]
    19          ******************       warning: redefining multi-line macro `struc' [-w+pp-macro-redef-multi]
    14                              <4> [list -]
    14                              <3> [list -]
     3                              <2> 
     4                              <2> addsection DOSSTART, align=16 PUBLIC class=DOSSTART
     5                              <2> ; (no prior section) ; DOSSTART		ENDS
     6                              <2> 
     7                              <2> addsection DOSSTARTJUMP, align=1 PUBLIC class=START
     8                              <2> ; (no prior section) ; DOSSTARTJUMP		ENDS
     9                              <2> 
    10                              <2> addsection CONSTANTS, align=2 PUBLIC class=CONST
    11                              <2> ; (no prior section) ; CONSTANTS	ENDS
    12                              <2> 
    13                              <2> addsection DATA, align=2 PUBLIC class=DATA
    14                              <2> ; (no prior section) ; DATA		ENDS
    15                              <2> 
    16                              <2> addsection TABLE, align=2 PUBLIC class=TABLE
    17                              <2> ; (no prior section) ; TABLE		ENDS
    18                              <2> 
    19                              <2> addsection DOSDATATABLE, align=2 PUBLIC class=DOSDATACODE
    20                              <2> ; (no prior section) ; DOSDATATABLE		ENDS
    21                              <2> 
    22                              <2> addsection DOSDATACODE, align=1 PUBLIC class=DOSDATACODE
    23                              <2> ; (no prior section) ; DOSDATACODE		ENDS
    24                              <2> 
    25                              <2> addsection DOSBIODATA, align=2 PUBLIC class=DOSBIODATA
    26                              <2> 
    27                              <2> addsection LAST, align=16 PUBLIC class=LAST
    28                              <2> ; (no prior section) ; LAST		ENDS
    29                              <2> 
    30                              <2> group DOSGROUP DOSSTART DOSSTARTJUMP CONSTANTS DATA TABLE DOSDATATABLE DOSDATACODE DOSBIODATA LAST
     8                              <1> 
     9                              <1> %include "dcodeseg.nas"
     1                              <2> 
     2                              <2> %ifndef DCODESEGNAS
     3                              <2> %assign DCODESEGNAS 1
     4                              <2> 
     5                              <2> section DOSCODETABLE align=2 PUBLIC class=DOSCODE
     6                              <2> ; (no prior section) ; DOSCODETABLE		ENDS
     7                              <2> section DOSCODECODE align=1 PUBLIC class=DOSCODE
     8                              <2> ; (no prior section) ; DOSCODECODE		ENDS
     9                              <2> section DOSBIOCODE align=2 PUBLIC class=DOSCODE
    10                              <2> section BIOCODE	align=2 PUBLIC class=DOSCODE
    11                              <2> 
    12                              <2> %ifnidni DOSENTRYGROUP, DOSCODEGROUP
    13                              <2>  group DOSCODEGROUP DOSCODETABLE DOSCODECODE DOSBIOCODE BIOCODE
    14                              <2> %endif
    15                              <2> 
    16                              <2> %endif
    10                              <1> 
    11                              <1> section LAST
    12                              <1> ; (no prior section) ; LAST		ENDS
    21                                  
    22                                  [list +]
    23                                  section DOSCODECODE
    24                                  [list -]
    24          ******************       warning: out: ... for DOS Version 4.00 ... [-w+user]
    24          ******************       warning: out: BPB.INC... [-w+user]
    24          ******************       warning: out: ... CLONE version build switch on ... [-w+user]
    24          ******************       warning: out: DEVSYM.INC... [-w+user]
    33                                  
    34                                  %iassign Installed TRUE
    35                                  
    36                                  	i_need	NoSetDir,BYTE
    37                                  	i_need	Creating,BYTE
    38                                  	i_need	THISCDS,DWORD
    39                                  	i_need	CURBUF,DWORD
    40                                  	i_need	DMAADD,DWORD
    41                                  	i_need	DummyCDS,128
    42                                  	i_need	THISDPB,DWORD
    43                                  	i_need	THISDRV,BYTE
    44                                  	i_need	NAME1,BYTE
    45                                  	i_need	ATTRIB,BYTE
    46                                  	i_need	DIRSTART,WORD
    47                                  	i_need	LASTENT,WORD
    48                                  	i_need	FOUND_DEV,BYTE
    49                                  	I_need	WFP_Start,WORD
    50                                  	i_need	EXTERR_LOCUS,BYTE
    51                                  	i_need	FastopenFlg,BYTE
    52                                  	I_need	DOS34_FLAG,WORD
    53                                  
    54                                   assume nocheck, ss:DOSGROUP
    55                                  
    56                                  ; Inputs:
    57                                  ;	[WFP_START] Points to WFP string ("d:/" must be first 3 chars, NUL
    58                                  ;		terminated)
    59                                  ;	[CURR_DIR_END] Points to end of Current dir part of string
    60                                  ;		( = -1 if current dir not involved, else
    61                                  ;		 Points to first char after last "/" of current dir part)
    62                                  ;	[THISCDS] Points to CDS being used
    63                                  ;		(Low word = -1 if NUL CDS (Net direct request))
    64                                  ;	[SATTRIB] Is attribute of search, determines what files can be found
    65                                  ;	[DMAADD] Points to 53 byte buffer
    66                                  ; Function:
    67                                  ;	Initiate a search for the given file spec
    68                                  ; Outputs:
    69                                  ;	CARRY CLEAR
    70                                  ;	    The 53 bytes ot DMAADD are filled in as follows:
    71                                  ;
    72                                  ;	LOCAL
    73                                  ;	    Drive Byte (A=1, B=2, ...) High bit clear
    74                                  ;		NEVER STORE DRIVE BYTE AFTER  found_it
    75                                  ;	    11 byte search name with Meta chars in it
    76                                  ;	    Search Attribute Byte, attribute of search
    77                                  ;	    WORD LastEnt value
    78                                  ;	    WORD DirStart
    79                                  ;	    4 byte pad
    80                                  ;	    32 bytes of the directory entry found
    81                                  ;	NET
    82                                  ;	    21 bytes First byte has high bit set
    83                                  ;	    32 bytes of the directory entry found
    84                                  ;
    85                                  ;	CARRY SET
    86                                  ;	    AX = error code
    87                                  ;		error_no_more_files
    88                                  ;			No match for this file
    89                                  ;		error_path_not_found
    90                                  ;			Bad path (not in curr dir part if present)
    91                                  ;		error_bad_curr_dir
    92                                  ;			Bad path in current directory part of path
    93                                  ; DS preserved, others destroyed
    94                                  
    95                                  	procedure   DOS_SEARCH_FIRST,NEAR
    95          ******************       warning: proc DOS_SEARCH_FIRST... [-w+user]
    96                                  	DOSAssume   CS,<DS>,"DOS_Search_First"
    97                                  	ASSUME	ES:NOTHING
    98                                  
    99 00000000 C43E[0000]              	LES	DI,[THISCDS]
   100 00000004 83FFFF                  	CMP	DI,-1
   101 00000007 7506                    	JNZ	TEST_RE_NET
   102                                  %IFN Installed
   103                                  	transfer NET_SEQ_SEARCH_FIRST
   104                                  %ELSE
   105                                  multNET equ MultNET	; NASM port equate
   106 00000009 B81911                  	MOV	AX,(multNET << 8) | 25
   107 0000000C CD2F                    	INT	2FH
   108 0000000E C3                      	return
   109                                  %ENDIF
   110                                  
   111                                  TEST_RE_NET:
   112 0000000F 26F745430080            	TEST	word [ES:DI + curdir_flags],curdir_isnet
   113 00000015 7406                    	JZ	LOCAL_SEARCH_FIRST
   114                                  %IFN Installed
   115                                  	transfer NET_SEARCH_FIRST
   116                                  %ELSE
   117 00000017 B81B11                  	MOV	AX,(multNET << 8) | 27
   118 0000001A CD2F                    	INT	2FH
   119 0000001C C3                      	return
   120                                  %ENDIF
   121                                  
   122                                  LOCAL_SEARCH_FIRST:
   123 0000001D E8(0000)                	EnterCrit   critDisk
   124 00000020 F706[0000]0004          	TEST	word [DOS34_FLAG],SEARCH_FASTOPEN  ;AN000;
   125 00000026 7405                    	JZ	NOFN			      ;AN000;
   126                                  FastOpenflg equ FastopenFlg	; NASM port label
   127                                  Fastopen_Set equ FastOpen_Set	; NASM port equate
   128 00000028 800E[0000]01            	OR	byte [FastOpenflg],Fastopen_Set    ;AN000;
   129                                  NOFN:					      ;AN000;
   130 0000002D C606[0000]01            	MOV	byte [NoSetDir],1		; if we find a dir, don't change to it
   131 00000032 E84301                  	CALL	CHECK_QUESTION		;AN000;;FO. is '?' in path
   132 00000035 7305                    	JNC	norm_getpath		;AN000;;FO. no
   133 00000037 8026[0000]80            	AND	byte [FastOpenflg],Fast_yes	;AN000;;FO. reset fastopen
   134                                  norm_getpath:
   135 0000003C E8(0000)                	invoke	GetPath
   136                                  getdone:
   137 0000003F 7319                    	JNC	find_check_dev
   138 00000041 7512                    	JNZ	bad_path
   139 00000043 08C9                    	OR	CL,CL
   140 00000045 740E                    	JZ	bad_path
   141                                  find_no_more:
   142 00000047 B81200                  	MOV	AX,error_no_more_files
   143                                  BadBye:
   144 0000004A 368026[0000]80          	AND	byte [ss:FastOpenflg],Fast_yes  ;AN000;;FO. reset fastopen
   145                                  
   146 00000050 F9                      	STC
   147 00000051 E8(0000)                	LeaveCrit   critDisk
   148 00000054 C3                      	return
   149                                  
   150                                  bad_path:
   151 00000055 B80300                  	MOV	AX,error_path_not_found
   152 00000058 EBF0                    	JMP	BadBye
   153                                  
   154                                  find_check_dev:
   155 0000005A 08E4                    	OR	AH,AH
   156 0000005C 790A                    	JNS	found_entry
   157                                  LastEnt equ LASTENT	; NASM port label
   158 0000005E C706[0000]FFFF          	MOV	word [LastEnt],-1		; Cause DOS_SEARCH_NEXT to fail
   159                                  Found_Dev equ FOUND_DEV	; NASM port label
   160 00000064 FE06[0000]              	INC	byte [Found_Dev]		; Tell DOS_RENAME we found a device
   161                                  found_entry:
   162                                  ;
   163                                  ; We set the physical drive byte here Instead of after found_it; Doing
   164                                  ; a search-next may not have wfp_start set correctly
   165                                  ;
   166 00000068 C43E[0000]              	LES	DI,[DMAADD]
   167 0000006C 8B36[0000]              	MOV	SI,[WFP_Start]		; get pointer to beginning
   168 00000070 AC                      	LODSB
   169 00000071 2C40                    	SUB	AL,'A'-1                ; logical drive
   170 00000073 AA                      	STOSB				; High bit not set (local)
   171                                  found_it:
   172 00000074 C43E[0000]              	LES	DI,[DMAADD]
   173                                   assume es:nothing
   174 00000078 47                      	INC	DI
   175 00000079 1E                      	PUSH	DS			;FO.;AN001; save ds
   176                                  Fastopenflg equ FastopenFlg	; NASM port label
   177 0000007A F606[0000]10            	TEST	byte [Fastopenflg],Set_For_Search	  ;FO.;AN001; from fastopen
   178 0000007F 7408                    	JZ	notfast 			  ;FO.;AN001;
   179 00000081 89DE                    	MOV	SI,BX				  ;FO.;AN001;
   180 00000083 8E1E[0200]              	MOV	DS,WORD PTR [CURBUF+2]		  ;FO.;AN001;
   181                                   assume ds:nothing
   182 00000087 EB03                    	JMP	SHORT movmov			  ;FO.;AN001;
   183                                  
   184                                  
   185                                  notfast:
   186 00000089 BE[0000]                	MOV	SI,OFFSET NAME1 wrt DOSGROUP; find_buf 2 = formatted name
   187                                  movmov:
   188                                   assume ds:nothing
   189                                  ; Special E5 code
   190 0000008C A4                      	MOVSB
   191 0000008D 26807DFF05              	CMP	BYTE PTR [ES:DI-1],5
   192 00000092 7505                    	JNZ	NOTKANJB
   193 00000094 26C645FFE5              	MOV	BYTE PTR [ES:DI-1],0E5H
   194                                  NOTKANJB:
   195                                  
   196 00000099 B90A00                  	MOV	CX,10
   197 0000009C F3A4                    	REP	MOVSB
   198 0000009E 1F                      	POP	DS			;FO.;AN001; restore ds
   199                                   assume ds:DOSGROUP
   200                                  
   201                                  Attrib equ ATTRIB	; NASM port label
   202 0000009F A0[0000]                	MOV	AL,[Attrib]
   203 000000A2 AA                      	STOSB
   204 000000A3 50                      	PUSH	AX			; Save AH device info
   205 000000A4 A1[0000]                	MOV	AX,[LastEnt]
   206 000000A7 AB                      	STOSW
   207                                  DirStart equ DIRSTART	; NASM port label
   208 000000A8 A1[0000]                	MOV	AX,[DirStart]
   209 000000AB AB                      	STOSW
   210                                  ; 4 bytes of 21 byte cont structure left for NET stuff
   211 000000AC 83C704                  	ADD	DI,4
   212 000000AF 58                      	POP	AX			; Recover AH device info
   213 000000B0 08E4                    	OR	AH,AH
   214 000000B2 781B                    	JS	DOSREL			; Device entry is DOSGROUP relative
   215 000000B4 833E[0000]FF            	CMP	WORD PTR [CURBUF],-1
   216 000000B9 7510                    	JNZ	OKSTORE
   217                                  FastOPenFlg equ FastopenFlg	; NASM port label
   218 000000BB F606[0000]10            	TEST	byte [FastOPenFlg],Set_For_Search ;AN000;;FO. from fastopen and is good
   219 000000C0 7509                    	JNZ	OKSTORE 		     ;AN000;;FO.
   220                                  
   221                                  
   222                                  
   223                                  	; The user has specified the root directory itself, rather than some
   224                                  	; contents of it. We can't "find" that.
   225 000000C2 26C745F8FFFF            	MOV	WORD PTR [ES:DI-8],-1	; Cause DOS_SEARCH_NEXT to fail by
   226                                  					;   stuffing a -1 at Lastent
   227 000000C8 E97CFF                  	JMP	find_no_more
   228                                  
   229                                  OKSTORE:
   230 000000CB 8E1E[0200]              	MOV	DS,WORD PTR [CURBUF+2]
   231                                  ASSUME	DS:NOTHING
   232                                  DOSREL:
   233 000000CF 89DE                    	MOV	SI,BX			; SI-> start of entry
   234                                  
   235                                  ; NOTE: DOS_RENAME depends on BX not being altered after this point
   236                                  
   237 000000D1 B92000                  	MOV	CX,dir_entry_struc_size
   238                                  ;;;;; 7/29/86
   239 000000D4 89F8                    	MOV	AX,DI			; save the 1st byte addr
   240 000000D6 F3A4                    	REP	MOVSB
   241 000000D8 89C7                    	MOV	DI,AX			; restore 1st byte addr
   242 000000DA 26803D05                	CMP	BYTE PTR [ES:DI],05H	; special char check
   243 000000DE 7504                    	JNZ	NO05
   244 000000E0 26C605E5                	MOV	BYTE PTR [ES:DI],0E5H	; convert it back to E5
   245                                  NO05:
   246                                  
   247                                  ;;;;; 7/29/86
   248 000000E4 161F                    	context DS
   249 000000E6 8026[0000]80            	AND	byte [FastOpenflg],Fast_yes  ;AN000;;FO. reset fastopen
   250 000000EB F8                      	CLC
   251 000000EC E8(0000)                	LeaveCrit   critDisk
   252 000000EF C3                      	return
   253                                  
   254                                  EndProc DOS_SEARCH_FIRST
   255                                  
   256                                  BREAK <DOS_SEARCH_NEXT - scan for subsequent matches>
   257                                  
   258                                  ; Inputs:
   259                                  ;	[DMAADD] Points to 53 byte buffer returned by DOS_SEARCH_FIRST
   260                                  ;	    (only first 21 bytes must have valid information)
   261                                  ; Function:
   262                                  ;	Look for subsequent matches
   263                                  ; Outputs:
   264                                  ;	CARRY CLEAR
   265                                  ;	    The 53 bytes at DMAADD are updated for next call
   266                                  ;		(see DOS_SEARCH_FIRST)
   267                                  ;	CARRY SET
   268                                  ;	    AX = error code
   269                                  ;		error_no_more_files
   270                                  ;			No more files to find
   271                                  ; DS preserved, others destroyed
   272                                  
   273                                  	procedure   DOS_SEARCH_NEXT,NEAR
   273          ******************       warning: proc DOS_SEARCH_NEXT... [-w+user]
   274                                  	DOSAssume   CS,<DS>,"DOS_Search_Next"
   275                                  	ASSUME	ES:NOTHING
   276                                  
   277 000000F0 C43E[0000]              	LES	DI,[DMAADD]
   278 000000F4 268A05                  	MOV	AL,[ES:DI]
   279 000000F7 A880                    	TEST	AL,80H			; Test for NET
   280 000000F9 7406                    	JZ	LOCAL_SEARCH_NEXT
   281                                  %IFN Installed
   282                                  	transfer NET_SEARCH_NEXT
   283                                  %ELSE
   284 000000FB B81C11                  	MOV	AX,(multNET << 8) | 28
   285 000000FE CD2F                    	INT	2FH
   286 00000100 C3                      	return
   287                                  %ENDIF
   288                                  
   289                                  LOCAL_SEARCH_NEXT:
   290                                  ;AL is drive A=1
   291 00000101 C606[0000]02            	MOV	byte [EXTERR_LOCUS],errLOC_Disk
   292 00000106 E8(0000)                	EnterCrit   critDisk
   293                                  ThisCDS equ THISCDS	; NASM port label
   294 00000109 C706[0000][0000]        	MOV	WORD [ThisCDS],OFFSET DummyCDS wrt DOSGROUP
   295 0000010F 8C1E[0200]              	MOV	WORD PTR [ThisCDS+2], ds
   296 00000113 0440                    	ADD	AL,'A'-1
   297 00000115 E8(0000)                	invoke	InitCDS
   298                                  
   299                                  ;	invoke	GetThisDrv		; Set CDS pointer
   300                                  
   301 00000118 7236                    	JC	No_files		; Bogus drive letter
   302 0000011A C43E[0000]              	LES	DI,[THISCDS]		; Get CDS pointer
   303 0000011E 26C46D45                	LES	BP,[ES:DI + curdir_devptr]; Get DPB pointer
   304 00000122 E8(0000)                	invoke	GOTDPB			; [THISDPB] = ES:BP
   305                                  
   306 00000125 268A4600                	mov	AL,[ES:BP + dpb_drive]
   307                                  ThisDrv equ THISDRV	; NASM port label
   308 00000129 A2[0000]                	mov	[ThisDrv],AL
   309                                  
   310                                  CREATING equ Creating	; NASM port label
   311 0000012C C706[0000]00E5          	MOV	WORD PTR [CREATING],0E500H
   312 00000132 C606[0000]01            	MOV	byte [NoSetDir],1		; if we find a dir, don't change to it
   313 00000137 C536[0000]              	LDS	SI,[DMAADD]
   314                                  ASSUME	DS:NOTHING
   315 0000013B AC                      	LODSB				; Drive Byte
   316                                  
   317                                  ;	DEC	AL
   318                                  ;	MOV	[THISDRV],AL
   319                                  
   320                                  	entry	RENAME_NEXT		; Entry used by DOS_RENAME
   321                                  
   322 0000013C 1607                    	context ES			; THIS BLOWS ES:BP POINTER TO DPB
   323 0000013E BF[0000]                	MOV	DI,OFFSET NAME1 wrt DOSGROUP
   324 00000141 B90B00                  	MOV	CX,11
   325 00000144 F3A4                    	REP	MOVSB			; Search name
   326 00000146 AC                      	LODSB				; Attribute
   327 00000147 36A2[0000]              	MOV	[ss:ATTRIB],AL
   328 0000014B AD                      	LODSW				; LastEnt
   329 0000014C 09C0                    	OR	AX,AX
   330 0000014E 7903                    	JNS	cont_load
   331                                  No_files:
   332 00000150 E9F4FE                  	JMP	find_no_more
   333                                  
   334                                  cont_load:
   335 00000153 50                      	PUSH	AX			; Save LastEnt
   336 00000154 AD                      	LODSW				; DirStart
   337 00000155 89C3                    	MOV	BX,AX
   338 00000157 161F                    	context DS
   339 00000159 C42E[0000]              	LES	BP,[THISDPB]		; Recover ES:BP
   340 0000015D E8(0000)                	invoke	SetDirSrch
   341 00000160 7303                    	JNC	SEARCH_GOON
   342 00000162 58                      	POP	AX			; Clean stack
   343 00000163 EBEB                    	JMP	No_files
   344                                  
   345                                  SEARCH_GOON:
   346 00000165 E8(0000)                	invoke	StartSrch
   347 00000168 58                      	POP	AX
   348 00000169 E8(0000)                	invoke	GetEnt
   349 0000016C 72E2                    	JC	No_files
   350 0000016E E8(0000)                	invoke	NextEnt
   351 00000171 72DD                    	JC	No_files
   352 00000173 30E4                    	XOR	AH,AH			; If Search_Next, can't be a DEV
   353 00000175 E9FCFE                  	JMP	found_it
   354                                  
   355                                  EndProc DOS_SEARCH_NEXT
   356                                  
   357                                  
   358                                  ;Input: [WFP_START]= pointer to final path
   359                                  ;Function: check '?' char
   360                                  ;Output: carry clear, if no '?'
   361                                  ;	 carry set, if '?' exists
   362                                  
   363                                  	procedure   CHECK_QUESTION,NEAR ;AN000;
   363          ******************       warning: proc CHECK_QUESTION... [-w+user]
   364                                  	ASSUME	ES:NOTHING,DS:NOTHING	;AN000;
   365                                  
   366 00000178 16                      	PUSH	ss			;AN000;;FO.
   367 00000179 1F                      	POP	DS			;AN000;;FO. ds:si -> final path
   368                                   assume ds:DOSGROUP
   369                                  WFP_START equ WFP_Start	; NASM port label
   370 0000017A 8B36[0000]              	MOV	SI,[WFP_START]		;AN000;;FO.
   371                                  getnext:				;AN000;
   372 0000017E AC                      	LODSB				;AN000;;FO. get char
   373 0000017F 84C0                    	test	AL,AL			;AN000;;FO. is it null
   374 00000181 7405                    	JZ	NO_Question		;AN000;;FO. yes --> (NC)
   375 00000183 3C3F                    	CMP	AL,'?'                  ;AN000;;FO. is '?'
   376 00000185 75F7                    	JNZ	getnext 		;AN000;;FO. no
   377 00000187 F9                      	STC				;AN000;;FO.
   378                                  NO_Question:				;AN000;
   379 00000188 C3                      	return				;AN000;;FO.
   380                                  
   381                                  EndProc CHECK_QUESTION			;AN000;
   382                                  
   383                                      END
