The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: drhowarddrfine on November 18, 2006, 02:21:56 AM

Title: Path traversing algorithm
Post by: drhowarddrfine on November 18, 2006, 02:21:56 AM
I'm looking for an algorithm or description of a method for following a path name to determine an executable file.  This would be used for dynamically creating web pages.  So if the web site is www.example.com/page1/page2/mywebpage, the server would provide me with this part: /page1/page2/mywebpage.  But there could be mywebpage2 or /page1/universal/page1, etc.  So the executable file would be the last name in the path, such as mywebpage or page1, etc.  The problem is traversing to the last name and jumping out if none of the pathnames along the way are valid.
Title: Re: Path traversing algorithm
Post by: ecube on November 18, 2006, 04:54:24 AM
I just wrote this, it works if the end of the path ends with / or not. Should be pretty fast have nothing to compare it to really :)



  .386
      .model flat, stdcall
      option casemap :none   ; case sensitive

      include \masm32\include\windows.inc
      include \masm32\include\kernel32.inc
      includelib \masm32\lib\kernel32.lib
       include \masm32\include\user32.inc
      includelib \masm32\lib\user32.lib
     include \masm32\macros\macros.asm

FindTheEnd proto :DWORD,:DWORD

.data
testx db "/page1/page2/mywebpage/",0

.data?
mybuf db 500 dup(?)

.code
start:

invoke FindTheEnd,addr testx,addr mybuf
invoke MessageBox,0,addr mybuf,addr testx,MB_OK
invoke ExitProcess,0


FindTheEnd proc iData:DWORD,oBuf:DWORd
mov edi, dword ptr [esp+8]
mov esi, dword ptr [esp+12]
mov ecx, dword ptr [esp+16]
@@:
inc edi
cmp byte ptr [edi],0
jne @B
dec edi
@@:
dec edi
cmp byte ptr[edi],'/'
jne @B
inc edi
@@:
cmp byte ptr[edi],'/'
je @F
mov al,byte ptr[edi]
inc edi
mov [esi], al
inc esi
test al,al
jne @B
@@:
ret
FindTheEnd endp

end start


Title: Re: Path traversing algorithm
Post by: lingo on November 18, 2006, 02:32:15 PM
E^cube,

You can use my faster FileNameFromPath proc:
http://www.masm32.com/board/index.php?topic=4195.msg31495#msg3149 

Regards,
Lingo
Title: Re: Path traversing algorithm
Post by: drhowarddrfine on November 18, 2006, 04:22:24 PM
Thanks cube but the harder part is finding and calling the executable.  I think the link lingo gave had some pretty good stuff I didn't find when searching.  Thanks. :U