Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Bluescreen2001 on February 22, 2017, 08:04:45 pm

Title: Convert backslashes to slashes in tools configuration
Post by: Bluescreen2001 on February 22, 2017, 08:04:45 pm
Hi

I am using Code::Block on Windows for ARM development. I flash my controllers using OOCD. This tool wants it's pathnames with forward slashes even on windows. If I use some variables in the tool configuration Code::Blocks inserts the pathnames with backslashes like normal on windows.
Lets say I want to give the full path to my target output file. I try it this way:

$(PROJECT_DIR)$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_FILENAME)

This expands to:
D:\Entwickl\WinARM\Projects\Blink\default\Blink.elf

It's a typical Windows path like expected. But I need a Linux-like path with forward slashes:
D:/Entwickl/WinARM/Projects/Blink/default/Blink.elf

1. Is there any way to convert the variables to this "linux-like" syntax, may some kind of script or special syntax?
As I noted Code::Blocks accepts a varity of forms of variables like     
    $VARIABLE
    $(VARIABLE)
    ${VARIABLE}
    %VARIABLE%
Maybe it would be nice to interpret them slightly different like $VARIABLE = use forward slashes %VARIABLE% = use backslashes or something. And maybe adding a special character befor the variable name to signal a full path, like this: $_VARIABLE
What do you think about that?

2. Is there an easier way to get the full path of a target output file like as linking all these variable together.

BTW.: it is very helpful that the configurate tools dialog shows examples of the variables, but they are outdated.
Title: Re: Convert backslashes to slashes in tools configuration
Post by: BlueHazzard on February 23, 2017, 01:50:25 am
How the h*** does the program read from the filesys?

Anyway  here is a solution for your problem. It is probably not the nicest, but hey it works ;)

You can add this lane in the ToolsPlus plugin
Code
 YOURCOMMAND [[local test = ReplaceMacros(_T("$(PROJECT_DIR)$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_FILENAME)")); test.Replace(_T("\\"),_T("/")); print(test);]]

greetings

[EDIT:] you can shrink it to:
Code
 YOURCOMMAND [[local test = ReplaceMacros(_T("$(PROJECT_DIR)$(TARGET_OUTPUT_FILE)")); test.Replace(_T("\\"),_T("/")); print(test);]]
Title: Re: Convert backslashes to slashes in tools configuration
Post by: oBFusCATed on February 23, 2017, 09:42:42 am
There should be a bit easier way to do it with this:
Code
$TO_UNIX_PATH{\test\test\test}
Title: Re: Convert backslashes to slashes in tools configuration
Post by: Bluescreen2001 on February 27, 2017, 09:13:40 pm
Sorry for the late answer. I missed the forum's notification somehow.

Both versions does as desired. Thank you very much!  :)

Title: Re: Convert backslashes to slashes in tools configuration
Post by: BlueHazzard on February 27, 2017, 10:02:53 pm
I have updated the wiki, because i also didn't knew that this functions existed
http://wiki.codeblocks.org/index.php/Variable_expansion#Build_in_functions_for_path_conversion