News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Path traversing algorithm

Started by drhowarddrfine, November 18, 2006, 02:21:56 AM

Previous topic - Next topic

drhowarddrfine

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.

ecube

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



lingo


drhowarddrfine

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