home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / DOS_HELP / XP.ZIP / FINDNSTR.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-12-20  |  3.6 KB  |  100 lines

  1. ; Function to check whether a pathname is already
  2. ; defined in the environment path string.
  3. ; A brute force method is used for searching.
  4. ; Returns pointer to start of string if match is found.
  5. ; Returns null pointer if not.
  6. ;       char *findNstr(char *source, char *dest);
  7. ; For Turbo C 2.0, small/tiny model.
  8. ; Written and tested with Turbo Assembler 1.0
  9. ; By Goh King Hwa, 20 Dec 1989.
  10.  
  11. ; Various usage of registers
  12. ;    SI : index into source (environment path string)
  13. ;    DI : index into dest   (pathname)
  14. ;    BX : points to end of dest
  15. ;    DX : marks the beginning of a match
  16. ;    AX, CX : scrap registers
  17.  
  18. _TEXT   segment byte public 'CODE'
  19.         assume  cs:_TEXT
  20. _findNstr        proc    near
  21.     push    bp
  22.     mov    bp,sp
  23.         push    si
  24.         push    di
  25.  
  26.         mov     ax,ds
  27.         mov     es,ax           ;move DS to ES
  28.         cld                     ;auto-increment mode
  29.  
  30. findEnd:                        ;find end of near string
  31.         mov     cx,-1           ;set for maximum count
  32.         mov     di,[bp+6]
  33.         xor     al,al           ;zero AL
  34.         repnz   scasb           ;repeat until EOS
  35.         mov     bx,di           ;end of dest string save in BX
  36.  
  37.         mov     di,[bp+6]       ;DI points to dest string
  38.         mov     si,[bp+4]       ;SI points to source string
  39.  
  40.         cmp     byte ptr [si],0
  41.         je      notfound        ;null source string, exit
  42.         cmp     byte ptr [di],0
  43.         je      notfound        ;null dest string, exit
  44.  
  45. search:
  46.         lodsb                   ;get one character from source string
  47.         or      al,al           ;end of string?
  48.         jz      notfound        ;end of far string encountered
  49.  
  50.         cmp     al,[di]         ;did first character match?
  51.         jne     search          ;yes, continue checking
  52. match:
  53.         mov     dx,si           ;save marker
  54.         inc     di              ;point to second character
  55.         mov     cx,-1           ;set for maximum count
  56.         repz    cmpsb           ;until the first non-matching character
  57.         cmp     bx,di           ;check against end of string
  58.         jbe     found           ;if BX <= DI, string matches
  59.         ja      Contd1          ;did not match
  60. Contd:
  61.         mov     bx,cx           ;restore our old BX
  62. Contd1:
  63.         mov     si,dx           ;restore SI
  64.         mov     di,[bp+6]       ;reset DI
  65.         jmp     short search    ;continue search
  66. found:
  67.         mov     cx,bx           ;save BX (pointer to EOS dest)
  68.         mov     bx,dx
  69.         dec     bx              ;actual starting of string match
  70.         dec     bx              ;go back one more character
  71.         cmp     byte ptr [bx], ';'      ;make sure the character in front
  72.         je      found1                  ;is a ';' or '='.
  73.         cmp     byte ptr [bx], '='
  74.         jne     Contd
  75. found1:
  76.         mov     bx,si
  77.         dec     bx              ;last character that stop the comparison
  78.         cmp     byte ptr [bx], ';'      ;was it a ';' character?
  79.         je      pathFound
  80.         cmp     cx,di           ;did we reach the end of source?
  81.         jae     Contd           ;becos last match would be comparing
  82.                                 ;2 zeros which should overshoot the
  83.                                 ;EOS we've found by at least one byte
  84. pathFound:
  85.         mov     ax,dx           ;restore old DI
  86.         dec     ax              ;this should be the correct starting address
  87.         jmp     short exit
  88. notfound:
  89.         xor     ax,ax           ;return zero
  90. exit:
  91.         pop     di
  92.         pop     si
  93.     pop    bp
  94.     ret    
  95. _findNstr        endp
  96. _TEXT    ends
  97.  
  98.         public  _findNstr
  99.     end
  100.