flat assembler
Message board for the users of flat assembler.

 Index > Main > include directive behavior
Author
aaro

Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
I tried to organize one of my projects in multiple files in multiple directories when i discovered that if i for example have structure like this:
Code:
Project folder:
test.asm
sub folder:
test2.asm
test2.inc
;in test.asm:
include 'sub folder\test2.asm'
;in sub folder\test2.asm:
include 'test2.inc'


It won't include 'test2.inc' because it tries to find 'test2.inc' in same folder that has the main source file. I think it would be better to make include work so it would include files relative to current file instead of main source file. Comments, please. Or mayby someone knows how to implement this with macros?
17 Nov 2003, 17:22
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Wouldnt it be better to refer to current idea with '.'. SO to do what you want you could just use
Code:
include '.\test2.inc'

Maybe not '.', it could be problem with OS, but some special symbol, or pseudo-environment variable (like %CurrentFile%).
17 Nov 2003, 18:13
aaro

Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
In my opinion it should be includes default behavior but something like %CurrentDir% would also do so i could have macro that works like i want.
19 Nov 2003, 13:04
pelaillo
Missing in inaction

Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo
It is useful indeed, and not only for includes but for all directory references in fasm (file and load directives).
It could be a fasm directive to indicate reference at current preprocessed file path.
AFAIK it cannot be done with only macros (until Privalov proves me wrong )

The result could be similar to the time directive (%T) that Privalov is including in new release:

%T - compile time
%D - current parsed file directory
%F - current parsed file name
19 Nov 2003, 16:26
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
didnt you mean current preprocessed? (not current parsed)
20 Nov 2003, 19:12
aaro

Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
If you Privalov see this, would it be difficult to add something like %D to fasm? I would really appreciate it, i'm trying to create macros for somekind of module system and i have structured my projects like this:
Code:
ProjectDir:
main.asm
main.inc
foobar.asm
Module1:
main.asm
main.inc
foo.asm
bar.asm
SubModule:
main.asm
main.inc
Module2:
main.asm
main.inc

22 Nov 2003, 16:36
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
aaro: why .inc files? You compile to OBJ files and link then? If you just include everything into one file and assemble then i dont see reason for separate .inc files. And if not, why do you need %D then?

do not take this as offense, i was just wondering why you use them
23 Nov 2003, 14:21
Vortex

Joined: 17 Jun 2003
Posts: 318
Vortex
vid,

The main feature of Fasm is that it can produce executables without the usage of object files,in another way,you don't have to use an external linker. Naturally,depending on the project, one can select the classical method based on creating obj files.

_________________
Code it... That's all...
23 Nov 2003, 14:54
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7992
Location: Kraków, Poland
Tomasz Grysztar
I have designed very interesting macro solution (fasm 1.49.9.2 or higher is needed, as it uses the concatenations of quoted strings, which was not enabled in earlier versions):
Code:
macro incdir dirpath,filename
{
macro rstincdir .% inc_dir fix cur_dir %.
cur_dir fix cur_dir # '\' # dirpath
}

macro endinc
{
rstincdir
purge rstincdir
}

macro defincl
{
macro incl filename
.%
defincl
INCLUDE inc_dir .. '\' .. filename
purge incl
%.
}

include fix incl
inc_dir fix cur_dir
cur_dir fix '.'
.% fix {
%. fix }
.. fix __
__ fix #
defincl    

Here's an example of usage:
Code:
include 'foobar.inc'    ; includes .\foobar.inc

incdir 'module1'
include 'foo.inc'     ; includes module1\foo.inc
include 'bar.inc'     ; includes module1\bar.inc
endinc    

and file "module1\foo.inc" may contain something like:
Code:
include 'subfoo.inc'    ; includes module1\subfoo.inc

incdir 'submod1'
include 'x.inc'       ; includes module1\submod1\x.inc
endinc    
23 Nov 2003, 18:47
aaro

Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Privalov: Thank you VERY mutch! Just what i needed.

vid: I like the ability in fasm to assemble without linking and i use separate .inc/.asm files just to organise my code. With these macros i can now have my modules in sub dirs under my project dir and if i need that module in some other project i just copy the sub dir in the new project folder. Then if i need to change something in my module it won't break my old code.
23 Nov 2003, 21:23
vid
Verbosity in development

Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
vortex: i know, i was just asking him which method he uses

aaro: i use modules too (for reusuability, but i never reused anything, i rather rewrite it better). But in assermbly there's not separate declaration and definition like in C, and i only break my module file when they are is too big to maintain.
But, of course, code as you like.
24 Nov 2003, 05:48
aaro

Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Privalov, is it possible to get these macros work with paths outside the project dir? Now i have to use old include with paths like: '%include%\win32a.inc' and incl with others(commented line 'include fix incl'). Not very importan(i can live with it) but it would be nice if it worked with those too. I can't think way to accomplish this, but it wouldn't be first time you show me how to go around these obstacles.
And in macro 'incdir' there is paramater called 'filename' witch is never used, probably some leftover from previous version, just to inform you.
27 Nov 2003, 02:27
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7992
Location: Kraków, Poland
Tomasz Grysztar
You can try such little modified version:
Code:
macro incdir dirpath
{
macro rstincdir .% inc_dir fix cur_dir %.
cur_dir fix cur_dir # dirpath
}

macro endinc
{
rstincdir
purge rstincdir
}

macro defincl
{
macro incl filename
.%
defincl
INCLUDE inc_dir .. filename
purge incl
%.
}

include fix incl
inc_dir fix cur_dir
cur_dir fix ''
.% fix {
%. fix }
.. fix __
__ fix #
defincl    

It should allow normal include use, and the only difference is that you should include path separator at the end of path for "incdir" macro, like:
Code:
incdir 'module1\'
include 'foo.inc'
include 'bar.inc'
endinc    
27 Nov 2003, 15:33
aaro

Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Won't work in modules(incdir has been called). I can't think any other solution to this but to somehow compare start of file name with '%include%' and '\' but i don't think that's possible.. I hope i'm mistaken.
27 Nov 2003, 17:36
Tomasz Grysztar

Joined: 16 Jun 2003
Posts: 7992
Location: Kraków, Poland
Tomasz Grysztar
Do you mean that you need to do use %include%-like includes in the submodules? Indeed, that would be harder. But you can always use the uppercase INCLUDE for such purpose (or: Include) - it will invoke the original one, not macro.
27 Nov 2003, 17:59
aaro

Joined: 21 Jun 2003
Posts: 107
Location: hel.fi
aaro
Yes that's what i meant. Harder, but not impossible?
But it's good enought allready, i'll use INCLUDE when i want normal behavior. Thank you.
27 Nov 2003, 19:53
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum