LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
Mitch_Peplow

Preserve .ini File Comments Formatting

Status: New

I use .ini files for alot of my configuration setups and like to add comments after the key value for future reference and clarity.

 

The problem is that if you write to the .ini file, all comments formatting (i.e. white space) is removed resulting in a .ini file that looks like a bomb has gone off in it. 

 

Below is a snapshot of before and after the write for clarity:

 

 

 Before.PNG

 

 

After.PNG

 

 

Ive spoken to tech support and they confirmed that due to the nature of how the VIs are written this is the default behaviour. For clarity and full understanding I have included their response below:

 

 

I've been looking through the source code for the config file vi's and I've found where the tabs are disappearing. During the open config file function, the existing keys are parsed. This includes trimming any whitespace, which is why all your neatly aligned columns with tabs are disappearing, in the general case.

This can be overcome by modifying the file. The config files are all found in <LabVIEW>/vi.lib/Utility/config.llb/NI_LVConfig.lvlib.

In this library you will need to modify "Parse Key Value Pair.vi". Remove the "trim whitespace" function in the false case, which is currently removing whitespace before the comment. This will lead to all the whitespace remaining.

However, this will only work for keys which are not edited. When you write a key, this all changes. At the low level, the "Add Key.vi" is doing the formatting of the key. In here, you can see in the true>true>true case that there is space added between value and comment, which simply reformats the key to have 4 space characters before the comment. You could change this space constant to tab constant (maybe just have 3 of them), which would preserve most of what you are intending to keep. It will be slightly subject to the length of text affecting the tab alignment. If you need to sort this, you could use a bit of code which reads the string length and decides how many tabs to insert.

 

 

This method will work, however it is laborious and time consuming. For me personally it would be a great addition if there were a boolean control that allowed me to set whether to preserve the original formatting or not (True by default). You could even argue that there is no need to have the option to turn it on/off, simply preserve the original format by default then edit the original document after if you so wish.

 

Any comments or thoughts on this would be appreciated.

 

Regards

 

Mitch

 

5 Comments
SnowMule
Active Participant

 

Drives me nuts.

It's the main reason I don't put comments in the INI file, when sometimes it really should have something.

PaulG.
Active Participant

Very old complaint that comes up from time to time. I use ini files extensively and would greatly appreciate being able to use comments. Doesn't look like this will be resolved or improved any time soon. I've just accepted the usefulness of ini files without being able to make comments. Smiley Sad

PaulG.

LabVIEW versions 5.0 - 2020

“All programmers are optimists”
― Frederick P. Brooks Jr.
johnsold
Knight of NI

Why not add a Read with Comments VI which would read the config file with the current formatting and create a new human-readable file (or display) with nicely spaced formatting? This would allow those who want a human-readable version to have it without requiring changes in several existing low-level subVIs.

 

 

NickNZ
Member

One time I was dumping binary data to a key in the ini file. (I didn't want/need it human modifiable) - hence reading it back sometimes caused errors as the binary data happened to have a bytes that corresponeded to white space at the start or end...took me a while to figure out that white space was being trimmed, I solved it by wrapping the writes and reads with quotes.  (This was with LabVIEW 7.1 when they were still VIs). 

 

d.w.b
Member

The INI file specification was originally created by Microsoft for Windows configuration profiles. The comment character is only a semicolon. Under the WinAPI's GetPrivateProfileString's dialect, comments must occur on lines by themselves. I insist that LabVIEW INI files be compatible with this. Any deviation should be controlled by optional inputs.