Hello everyone,
I'm sure about 99% this is a bug. In the help file, we can read :
Quote:
In PureBasic, a recurrence is fully supported for the procedures and any procedure can call it itself
...
You have to set the type after Procedure and use the ProcedureReturn keyword at any moment inside the procedure.
So if it's the case we should be able to use a ProcedureReturn to stop a procedure and return a value or string event if the procedure call it's self. But it's not the case with the following example.
Code:
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Project name : Recursivity Bug
; File Name : Recursivity Bug.pb
; File version: 1.0.0
; Programming : OK
; Programmed by : Guimauve
; Date : 27-05-2012
; Last Update : 27-05-2012
; PureBasic code : 4.61 x64
; Platform : Linux Mint 12 x64
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Notes :
;
; The "FindFile()" original code has been created by dige
; and extended + updated for PB 4.00 by Andre
; Date: 03. February 2005
;
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Procedure.s FindFile(Directory.s, FileName.s)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
PathSep.s = "\"
CompilerCase #PB_OS_Linux
PathSep.s = "/"
CompilerCase #PB_OS_MacOS
PathSep.s = "/"
CompilerEndSelect
If Right(Directory, 1) <> PathSep
Directory + PathSep
EndIf
Debug "THE CURRENT FOLDER : " + Directory
DirectoryHandle = ExamineDirectory( #PB_Any, Directory, "*.*" )
If DirectoryHandle <> 0
While NextDirectoryEntry(DirectoryHandle)
EntryName.s = DirectoryEntryName(DirectoryHandle)
If Left(EntryName, 1) <> "."
Select DirectoryEntryType(DirectoryHandle)
Case #PB_DirectoryEntry_File
If EntryName = FileName
Debug "FOUND IN : " + Directory
; Apparently this ProcedureReturn do absolutely nothing.
; The procedure should stop at this point and return the
; "Directory" string.
ProcedureReturn Directory
EndIf
Case #PB_DirectoryEntry_Directory
Debug "THE NEXT FOLDER : " + Directory + EntryName + PathSep
FindFile(Directory + EntryName, FileName)
EndSelect
EndIf
Wend
EndIf
ProcedureReturn "NOT FOUND"
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< !!! WARNING - THE FOLLOWING PROCEDURE IS NOT RELATED - WARNING !!! <<<<<
; <<<<< !!! WARNING - TO THE BUG DEMONSTRATION CODE. IS JUST - WARNING !!! <<<<<
; <<<<< !!! WARNING - BECAUSE I'M TOO LAZY TO PUT THE CODE - WARNING !!! <<<<<
; <<<<< !!! WARNING - DIRECTLY INSIDE THIS DEMONSTRATION. - WARNING !!! <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Procedure.b BuiltPathDirectory(Path.s)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
PathSep.s = "\"
CompilerCase #PB_OS_Linux
PathSep.s = "/"
CompilerCase #PB_OS_MacOS
PathSep.s = "/"
CompilerEndSelect
DirectoryQty = CountString(Path, PathSep) + 1
For Index = 1 To DirectoryQty
Directory.s = Directory + StringField(Path, Index, PathSep) + PathSep
If FileSize(Directory) = -1
CreateDirectory(Directory)
EndIf
Next
If FileSize(Directory) = -2
Success.b = #True
Else
Success = #False
EndIf
ProcedureReturn Success
EndProcedure
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< !!! WARNING - TESTING CODE !!! <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; Here we set a valid path in two parts, we want
; to start the search far away from the file.
Path.s = GetHomeDirectory() + "Test Folder/"
FullPath.s = Path + "SubFolder/SubSubFolder/"
; Here we set the filename
FileName.s = "A simple text file.txt"
; Here we built an existing path
If BuiltPathDirectory(FullPath)
; we create a basic text file for testing
If CreateFile(0, FullPath + FileName)
WriteStringN(0, "This is a simple test !")
WriteStringN(0, "Apparently, the recursive procedure don't work properly !")
CloseFile(0)
EndIf
; Then we try to find where the file is to test
; the FindFile() function.
Debug "; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
Debug "; FindFile() should return : " + FullPath
Debug ""
Debug FindFile(Path, FileName)
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<
; <<<<< END OF FILE <<<<<
; <<<<<<<<<<<<<<<<<<<<<<<
Debugger wrote:
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; FindFile() should return : /home/guimauve/Test Folder/SubFolder/SubSubFolder/
THE CURRENT FOLDER : /home/guimauve/Test Folder/
THE NEXT FOLDER : /home/guimauve/Test Folder/SubFolder/
THE CURRENT FOLDER : /home/guimauve/Test Folder/SubFolder/
THE NEXT FOLDER : /home/guimauve/Test Folder/SubFolder/SubSubFolder/
THE CURRENT FOLDER : /home/guimauve/Test Folder/SubFolder/SubSubFolder/
FOUND IN : /home/guimauve/Test Folder/SubFolder/SubSubFolder/
NOT FOUND
Best regards.
Guimauve