Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: trailstrider on April 21, 2016, 06:00:25 am

Title: getting list of just source files (*.c) for a tool parameter
Post by: trailstrider on April 21, 2016, 06:00:25 am
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
Title: Re: getting list of just source files (*.c) for a tool parameter
Post by: oBFusCATed on April 21, 2016, 08:03:21 am
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
Title: Re: getting list of just source files (*.c) for a tool parameter
Post by: trailstrider on April 21, 2016, 02:46:48 pm
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.
Title: Re: getting list of just source files (*.c) for a tool parameter
Post by: oBFusCATed on April 21, 2016, 06:46:11 pm
Perhaps even a way to automate creating a variable for that list that is accessible to the tools?
This is only possible if you modify the internals of codeblocks.
Title: Re: getting list of just source files (*.c) for a tool parameter
Post by: trailstrider on April 27, 2016, 06:48:45 pm
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() +@" ";
}

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?
Title: Re: getting list of just source files (*.c) for a tool parameter
Post by: LETARTARE on April 27, 2016, 07:21:34 pm
Hello,
I wrote a script plugin 'squirrel' to translate the projects  'Code::Block' which comes with a script ' tools.script ' which will list the files of a project .
Here the discussion forum :http://forums.codeblocks.org/index.php/topic,18223.msg137602.html#msg137602 (http://forums.codeblocks.org/index.php/topic,18223.msg137602.html#msg137602)
And here the sources with explanatory: https://sourceforge.net/projects/wxtranslate (https://sourceforge.net/projects/wxtranslate)
I just try with 'svn1816' , it works well .

Maybe this will help.

Best regards.