Author Topic: getting list of just source files (*.c) for a tool parameter  (Read 1716 times)

Offline trailstrider

  • Single posting newcomer
  • *
  • Posts: 3
getting list of just source files (*.c) for a tool parameter
« 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

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12911
    • Travis build status
Re: getting list of just source files (*.c) for a tool parameter
« Reply #1 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
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline trailstrider

  • Single posting newcomer
  • *
  • Posts: 3
Re: getting list of just source files (*.c) for a tool parameter
« Reply #2 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12911
    • Travis build status
Re: getting list of just source files (*.c) for a tool parameter
« Reply #3 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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline trailstrider

  • Single posting newcomer
  • *
  • Posts: 3
Re: getting list of just source files (*.c) for a tool parameter
« Reply #4 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: [Select]
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() [email protected]" ";
}

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?

Offline LETARTARE

  • Regular
  • ***
  • Posts: 435
  • L'ami de l'homme.The friend of man.
Re: getting list of just source files (*.c) for a tool parameter
« Reply #5 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
And here the sources with explanatory: https://sourceforge.net/projects/wxtranslate
I just try with 'svn1816' , it works well .

Maybe this will help.

Best regards.

CB-rev12240, plugins : QtPregen-2.7.3-sdk240
1-Win7 Business Pack1 64bits : wx-3.1.4, gcc-8.1.0,
2-Vista Business Pack2 32bits : wx-3.1.4, gcc-8.1.0
3-OpenSuse-15.1-Leap 64bits : wx-3.03, gcc-7.5.
=> !! The messages are translated by Deepl !!