User forums > Using Code::Blocks
getting list of just source files (*.c) for a tool parameter
trailstrider:
Hi-
The ${ALL_PROJECT_FILES} variable expansion is just that... Everything. I can't seem to find a builtin variable that would be appropriate for only selecting the files in the my Sources folder, which is essentially all the *.c in the project. Also, i'm looking at adding a test directory for unit test harnesses and am likely going to want to be able to select those separately also for passing to a tool. Am i correct in assuming that I can use [[ ]] script expansion to get what i need since there doesnt seem to be a variable expansion builtin for this? Also, i cant seem to get variable expansion working quite right either...
Perhaps im just being an idiot, but the documentation isnt helping in this case either.
Thanks
oBFusCATed:
Yes, you can use scripting to achieve your goal.
Check these pages:
http://wiki.codeblocks.org/index.php/Variable_expansion
http://wiki.codeblocks.org/index.php/Scripting_commands
You can test your scripts in the View -> Script console
trailstrider:
Any hints on where to start for getting that list as efficiently as possible? Perhaps even a way to automate creating a variable for that list that is accessible to the tools?
As an aside, I did try to go down the scripting route last night, but am looking for some help on what calls are going to be most fruitful. I had opened the scripting console, and tested with just the one in the documentation:
[[ print(GetProjectManager().GetActiveProject().GetTitle()); ]]
I ran it without the [[ and ]], so just print(print(GetProjectManager().GetActiveProject().GetTitle());
It didn't work. That was last night. I noticed my machine was getting very sluggish from having left Code::Blocks running for a couple days, so i suspected a memory leak and closed it.
This morning, I tried again and its working all of a sudden. I'll report that bug later, and maybe run some Polyspace on the source code for Code::Blocks later to see if i can track any issues down which are more specific. For now, just trying to get the list of source files i need to pass to a tool. Glad that the script console will work for me, when i was concerned it wouldn't.
oBFusCATed:
--- Quote from: trailstrider on April 21, 2016, 02:46:48 pm ---Perhaps even a way to automate creating a variable for that list that is accessible to the tools?
--- End quote ---
This is only possible if you modify the internals of codeblocks.
trailstrider:
Good to know. Just to be clear, there is no way to run a script in one place, and export the variables so that they are available to the Tools? Trying to put an entire script in a single call is pretty messy/hacky.
Regardless, any hints on the script calls i'll need? So far, it appears something like this...
--- Code: ---fc = GetProjectManager.GetActiveProject().GetFilesCount();
file_string = @""; //init empty string
// would prefer to use the squirrel foreach here, but then, if i could get the full list of files directly, i wouldnt have to do this anyway!
for(i=0;i<fc;i+=1)
{
file_string += GetProjectManager.GetActiveProject().GetFile(i).relativeToCommonTopLevelPath() +@" ";
}
--- End code ---
but its not working in the console since it keeps complaining about TABLE indexes not existing... i think because the script console is stuck in a funky state. in the local scope, there is only a 'this' variable, which is a table... and its not letting me define any local variables because im stuck in a table apparently?
Navigation
[0] Message Index
[#] Next page
Go to full version