Author Topic: Convert backslashes to slashes in tools configuration  (Read 3945 times)

Offline Bluescreen2001

  • Single posting newcomer
  • *
  • Posts: 3
Convert backslashes to slashes in tools configuration
« 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.

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Re: Convert backslashes to slashes in tools configuration
« Reply #1 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);]]
« Last Edit: February 23, 2017, 02:00:06 am by BlueHazzard »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: Convert backslashes to slashes in tools configuration
« Reply #2 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}
(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 Bluescreen2001

  • Single posting newcomer
  • *
  • Posts: 3
Re: Convert backslashes to slashes in tools configuration
« Reply #3 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!  :)


Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3352
Re: Convert backslashes to slashes in tools configuration
« Reply #4 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