home *** CD-ROM | disk | FTP | other *** search
- ; Function to check whether a pathname is already
- ; defined in the environment path string.
- ; A brute force method is used for searching.
- ; Returns pointer to start of string if match is found.
- ; Returns null pointer if not.
- ; char *findNstr(char *source, char *dest);
- ; For Turbo C 2.0, small/tiny model.
- ; Written and tested with Turbo Assembler 1.0
- ; By Goh King Hwa, 20 Dec 1989.
-
- ; Various usage of registers
- ; SI : index into source (environment path string)
- ; DI : index into dest (pathname)
- ; BX : points to end of dest
- ; DX : marks the beginning of a match
- ; AX, CX : scrap registers
-
- _TEXT segment byte public 'CODE'
- assume cs:_TEXT
- _findNstr proc near
- push bp
- mov bp,sp
- push si
- push di
-
- mov ax,ds
- mov es,ax ;move DS to ES
- cld ;auto-increment mode
-
- findEnd: ;find end of near string
- mov cx,-1 ;set for maximum count
- mov di,[bp+6]
- xor al,al ;zero AL
- repnz scasb ;repeat until EOS
- mov bx,di ;end of dest string save in BX
-
- mov di,[bp+6] ;DI points to dest string
- mov si,[bp+4] ;SI points to source string
-
- cmp byte ptr [si],0
- je notfound ;null source string, exit
- cmp byte ptr [di],0
- je notfound ;null dest string, exit
-
- search:
- lodsb ;get one character from source string
- or al,al ;end of string?
- jz notfound ;end of far string encountered
-
- cmp al,[di] ;did first character match?
- jne search ;yes, continue checking
- match:
- mov dx,si ;save marker
- inc di ;point to second character
- mov cx,-1 ;set for maximum count
- repz cmpsb ;until the first non-matching character
- cmp bx,di ;check against end of string
- jbe found ;if BX <= DI, string matches
- ja Contd1 ;did not match
- Contd:
- mov bx,cx ;restore our old BX
- Contd1:
- mov si,dx ;restore SI
- mov di,[bp+6] ;reset DI
- jmp short search ;continue search
- found:
- mov cx,bx ;save BX (pointer to EOS dest)
- mov bx,dx
- dec bx ;actual starting of string match
- dec bx ;go back one more character
- cmp byte ptr [bx], ';' ;make sure the character in front
- je found1 ;is a ';' or '='.
- cmp byte ptr [bx], '='
- jne Contd
- found1:
- mov bx,si
- dec bx ;last character that stop the comparison
- cmp byte ptr [bx], ';' ;was it a ';' character?
- je pathFound
- cmp cx,di ;did we reach the end of source?
- jae Contd ;becos last match would be comparing
- ;2 zeros which should overshoot the
- ;EOS we've found by at least one byte
- pathFound:
- mov ax,dx ;restore old DI
- dec ax ;this should be the correct starting address
- jmp short exit
- notfound:
- xor ax,ax ;return zero
- exit:
- pop di
- pop si
- pop bp
- ret
- _findNstr endp
- _TEXT ends
-
- public _findNstr
- end
-