User forums > Using Code::Blocks

custom variable string: loading .cbp converts slash to backslash

(1/3) > >>

J.:
The custom variable LEX_OUTPUT reasonably defined in the .cbp file (see xml snip below) is converted to  '| gawk -f .\FlexOutput.awk >' where the required slash is annoyingly replaced by a backslash in the build options view and when running a build. A nasty workaround is to edit the custom variable every time when the project is newly loaded.  ???

How can the conversion be avoided - or is this a bug (happy to file a bug if pointed to where to report it)?

Living on Win10 with CB16.01 (Jan 25, 2016).

Thanks,
J.


--- Code: ---<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Build>
<Environment>
<Variable name="LEX_OUTPUT" value="| gawk -f ./FlexOutput.awk &gt;" />
</Environment>
</Build>
</Project>
</CodeBlocks_project_file>
--- End code ---

oBFusCATed:
I think you can use the macro $TO_UNIX_PATH{} around the path.
See here http://wiki.codeblocks.org/index.php/Variable_expansion#Build_in_functions_for_path_conversion

J.:
Thanks, this does not work unfortunately:
--- Code: ---<Variable name="LEX_OUTPUT" value="| gawk -f $TO_UNIX_PATH{.\FlexOutput.awk} &gt;" />
--- End code ---
which is what you suggested translates upon a build to
--- Code: ---... | gawk -f {.\FlexOutput.awk} > ...
--- End code ---
, i.e. $TO_UNIX_PATH is dropped without any impact, but leaving the curly brackets in place.

I checked that - in contrast to functions '$F{}' - variables '$V()' are correctly expanded.

... or am I missing something here?  ::)

oBFusCATed:
Can you share a minimal sample project that demonstrate this problem?

J.:
First of all, apologies for this rather lengthy posting! After digging a bit deeper into this issue, here some thoughts on custom variables defined in the build option section Custom Variables:


* Slashes and backslashes in custom variables

* Slashes and backslashes are properly saved as such in the project file .cbp. [EDIT: I just noted that CB insists on converting slashes to backslashes in .cbp files]
* Slashes are confusingly displayed as backslashes in the overview of custom variables and in their edit window once the project is opened by CB. [EDIT: supposingly because when parsing the project file CB applies the slash to backslash conversion]
* Slashes are converted to backslashes for internal use of the custom variables, unless they are manually edited and changed to slashes again; then these newly edited slashes are temporarily used as such  - and not converted to backslashes - until the end of the CB session. Reopening the CB project welcomes the user with all slashes converted to backslashes again.  ::)
* Path macros like $TO_UNIX_PATH{} (pointed to http://wiki.codeblocks.org/index.php/Variable_expansion#Build_in_functions_for_path_conversion by ObFusCATed - thanks again!)

* These macros appear to simply replace - in strings placed into the argument in curly brackets - slashes by backslashes and vice versa as requested regardless whether the string is a valid path or not.
* The macros work perfectly fine - in, e.g., pre/post build steps - when applied to custom variables.
* Macros are not expanded as part of a custom variable definition! It appears that when parsing a custom variable variables CB tries to expand expressions of the form $VAR. If $VAR is not defined, then it is expanded by a void string. This is what I saw and described above when a custom variable of the from $TO_UNIX_PATH{bla} is expanded to {bla}, since the variable $TO_UNIX_PATH does not exist (I am guessing here). (*)
Solution to my very issue:

* The variable LEX_OUTPUT is fed into a pre-compiler directive (deriving a .c file from another file) where the path defined in this custom variable is required to be a UNIX path. 
* The slash/backslash conversion must not be defined on the level of custom variables.
* Add the slash/backslash conversion to the required format to the pre-compiler string.
Potential CB enhancements:

* removing the automatic conversion of slashes to backslashes in variables in project files and upon opening a CB project
* refining the parsing of (custom) variables to allow for direct expansion of macros (see (*) above).

--- Quote from: oBFusCATed on April 13, 2017, 08:52:21 pm ---Can you share a minimal sample project that demonstrate this problem?

--- End quote ---
Happy to share a minimal example if still needed. Please give me a shout if so and I'll will create one.

Please note that I am living on Win10 with CB16.01.

Navigation

[0] Message Index

[#] Next page

Go to full version