FreeOrion

Forums for the FreeOrion project
It is currently Sat Dec 16, 2017 1:16 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Mon Mar 21, 2016 9:08 pm 
Offline
Programmer

Joined: Sun Feb 14, 2016 12:08 am
Posts: 359
Currently a lot of unused macros are included when parsing certain script files.
These files should include any macros they need, without concern of what those files might also include.

e.g.
An entry uses macros A_1 and B_1. It includes files A.macros and B.macros
A.macros has a couple of macros that use macro B_2, and should include B.macros
Other entries also use A_1 or B_1, but not always both.

For more concrete examples:
species.macros is a good example of macros that rely on each other.
Most of the tech entries are examples of loading a much larger list of macros for a single macro (TECH_COST_MULTIPLIER).

I've created a PR that initially does the following:
* Limit the #include statement to only include a file once.
* Replace any base path (a leading '/') with default/ (specifically, GetResourceDir() ).
* Allow a leading asterisk wildcard in the filename

I omitted adding a separate #include_once and limited the other options to keep from a need to parse the files multiple times.
If there is a method to have both #include and #include_once, without needing to pre-process, the logic escaped me.

The base path was redirected since absolute paths should never be used, and any traversal beyond default/ would potentially fail if the resource directory is changed.

The wildcard is probably the most controversial bit. I wanted to give a method for including a specific batch of files, but a separate directive leads me to need multiple passes.
Full wildcard support would add more complexity for what I felt would be seldom used. e.g. How many times would #include "asteroid??_small.txt" be needed, a sub-directory could just as easily be created for those files and use #include "asteroids/*_small.txt" if a batch inclusion was desired.

_________________
Any content posted should be considered licensed GNU GPL 2.0 and/or CC-BY-SA 3.0 as appropriate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group