XIncludeFile and IncludeFile to search local directory first

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

XIncludeFile and IncludeFile to search local directory first

Post by Mistrel »

I would like to see the XIncludeFile and IncludeFile functions search the directory local to the currently included file first before searching the directory local to the file passed to the compiler.

Trond provided a trick to do this by adding another line but I believe this behavior should be built into these functions. I see no tangible benefit to for these functions to search only the compile file directory.

http://www.purebasic.fr/english/viewtopic.php?p=268111
http://www.purebasic.fr/english/viewtopic.php?t=30504
Little John
Addict
Addict
Posts: 4773
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Post by Little John »

+1

Regards, Little John
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: XIncludeFile and IncludeFile to search local directory f

Post by PB »

I don't understand the request. I have files in the same folder as my source
and they're all included just fine like this:

Code: Select all

IncludeFile "Name.pb"
What am I misunderstanding?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

IncludeFile and XIncludeFile only work with files relative to the main source file passed to the PB compiler (%COMPILEFILE).

All files should work like this by default and only if the file is not found check the directory relative to the main source file:

Code: Select all

IncludeFile(#PB_Compiler_File+"\..\"+"Include.pb")
XIncludeFile(#PB_Compiler_File+"\..\"+"Include.pb")
DarkDragon
Addict
Addict
Posts: 2344
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Post by DarkDragon »

+2
bye,
Daniel
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Post by STARGÅTE »

IncludePath is your frind,

so you can, select your directory und move relativ there
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: XIncludeFile and IncludeFile to search local directory f

Post by luis »

And yet I hope to see this added,

Every time I have to do something like:

Code: Select all

IncludePath #PB_Compiler_FilePath
XIncludeFile "..\MyFile.pb"
XIncludeFile "..\MyFile2.pb"
XIncludeFile "..\..\MyFile3.pb"
IncludePath "."
or

Code: Select all

XIncludeFile #PB_Compiler_FilePath + "..\MyFile.pb"
XIncludeFile #PB_Compiler_FilePath + "..\MyFile2.pb"
XIncludeFile #PB_Compiler_FilePath + "..\..\MyFile3.pb"
when a

XIncludeFileRelative "..\file.ext"

could make everyone happy.

I don't really see why it was done this way in the first place. It's really counter-intuitive IMHO and make difficult create something you can move to another path or share with anyone (unless you use consistently the tricks mentioned above).

It's something minor since you can fix this way, but adding the command would require really... nothing I guess, so a request is understandable.


Thanks.
"Have you tried turning it off and on again ?"
A little PureBasic review
Zach
Addict
Addict
Posts: 1675
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: XIncludeFile and IncludeFile to search local directory f

Post by Zach »

I have no problem backing out of my source directory and going into another using XincludeFile.... Nor do I have a problem navigating deeper into my source directory.. I maintain a "includes" directory where I place common reused code files, so I don't have to move things around, etc.. I thought that was just plain good practice.

What exactly is the benefit here? I have to agree I'm not understanding the request.
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: XIncludeFile and IncludeFile to search local directory f

Post by luis »

The links listed in this thread already explains it, but anyway:

Code: Select all

c:\dira\dirb\includes
	
	c:\dira\dirb\includes\math\
		math1.pb
		math2.pb
	
	c:\dira\dirb\includes\support\
		support1.pb
		support2.pb

	c:\dira\dirb\includes\graph\
		graph1.pb
		graph2.pb
	
In your program's main include:

xincludefile "c:\dira\dirb\includes\math\math1.pb"
xincludefile "c:\dira\dirb\includes\graph\graph1.pb"

If math1.pb needs to include support1.pb I would like to be able to do (inside math1.pb obviously):

xincludefile "..\support\support1.pb"

Would be nice (and logical) and it will make your include tree easily moveable from place to place and shareable with other people.

But this DOES NOT WORK, because all paths are relative to the main program file.

Same thing if math1.pb tries to include math2.pb by simply using:

xincludefile "math2.pb"

They are both in the same dir, but no sir, because the path it's still relative to the main including file.

IMHO this is really flawed.


[EDIT: THIS REQUEST HAS BEEN IMPLEMENTED]
Last edited by luis on Fri Feb 01, 2019 12:30 pm, edited 3 times in total.
"Have you tried turning it off and on again ?"
A little PureBasic review
Zach
Addict
Addict
Posts: 1675
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: XIncludeFile and IncludeFile to search local directory f

Post by Zach »

Ah.. I see what you mean, now.
Post Reply