Jump to content

Comments in Configuration Files


Recommended Posts

Hi,

i'm thinking about a solution to write a comment on each line in a config file. I know there is no explicit standard for comments in a line but there are some usual solutions.....

[info]

Project=test #[Project name....]

Date=2007_09_27 #[YYYY_MM_DD]

Is there a chance to implement comments like that in the line of each entry?

Thanks

Claude

Link to comment

I'm fairly sure there isn't a mechanism for commenting in the config file VIs, but since everything is pure G, you could create your own copy and implement it yourself, if you really want it.

Another option is to add comments as separate lines near the lines they're commenting on.

Link to comment

QUOTE(dwisti @ Oct 1 2007, 02:18 PM)

Per "LabVIEW for Everyone", there is no standard method for .ini files in LabVIEW. It's nice that they told me this, but did not tell me actually how to enter comments. I needed to comment the section titles and so I just tried a few things. Turns out, you can just put text after the "]" of you section title and it will be ignored. I don't know how to comment keys, though, becasue I did not require this. Hope this helps. Below is a sample of my .ini file with section header, comment, and a few keys...

[65] A

a = 0

b = 122880

c = 7680

Link to comment

QUOTE(EdDeWitt @ Oct 1 2007, 03:09 PM)

Per "LabVIEW for Everyone", there is no standard method for .ini files in LabVIEW. It's nice that they told me this, but did not tell me actually how to enter comments. I needed to comment the section titles and so I just tried a few things. Turns out, you can just put text after the "]" of you section title and it will be ignored. I don't know how to comment keys, though, becasue I did not require this. Hope this helps. Below is a sample of my .ini file with section header, comment, and a few keys...

[65] A

a = 0

b = 122880

c = 7680

Not just LabVIEW for everyone!!! There isn't any standard at all and the only defacto standard is what Windows invented for ini files and as far as Windows is concerned there are no comments in an ini file. The fact that there are lines that contain some data that is never queried with a GetPrivateProfileString is all that makes them comments. Similarly SetPrivateProfileString does not really give you any functionality to add comments to an ini file.

As per Windows a section is enclosed between brackets and what comes behind is not read and a ini token has a name that starts a line and a value that follows the equal sign. The value can be a quoted string if it must contain line breaks but otherwise it goes to the end of the line.

One could of course devise various variants on this and restrict above limit to request double quoted strings for anything that contains line breaks AND spaces and stop reading a token value as soon as there is a non quoted space but that is not how Windows invented it. The Configuration functions already do some non-Windows stuff by escaping special characters and normalizing paths in order to be platform independant.

If you want to change above behaviour it is fairly easy to modify the Configuration file VI's to do so as they are clearly structured and build up. They do the double quoting already for strings containing spaces but at least in 8.2.1 is a bug in that respect where the quoting is skipped if the section did not yet exist when adding a new key.

Extending the configuration VIs to allow adding comments programmatically will however by a much more involved task. It's one thing to just ignore some data and a completely different one to add infrastructure to support it.

Rolf Kalbermatter

Link to comment
QUOTE(rolfk @ Oct 3 2007, 08:15 AM)
Not just LabVIEW for everyone!!! There isn't any standard at all and the only defacto standard is what Windows invented for ini files and as far as Windows is concerned there are no comments in an ini file. The fact that there are lines that contain some data that is never queried with a GetPrivateProfileString is all that makes them comments. Similarly SetPrivateProfileString does not really give you any functionality to add comments to an ini file.
Hello,Rolf, I think you are making things too complicated here. Microsoft themselves introduced the semicolon (;) as comment symbol, so although it's not a standard as in ISO or IEEE I don't think there can be too much discussion about how you should place comments in an ini file. Note NI calls them config files, I guess to stay out of MS's water. My experience with config files and the routines I have developed a couple of years back, is that it is possible to enhance the functionality and speed greatly over NI's routines. To prevent messing up the file layout, I am modifying only the value part and keep the rest of the text unmodified, and don't reconstruct the section by collecting keys and values. I insert new keys at the beginning of a new line (after the last written entry or at the end, depending on whether somethings was already written). These are simple measures to retain comments.Other useful improvements could be to write entire sections (so you can store other kinds of data). That way, you can store 1D or 2D arrays of DBL/I32/string in a transparant way in a section.JorisPS yeah that smiley should have been a semicolon
Link to comment

QUOTE(robijn @ Oct 3 2007, 03:49 AM)

Hello,Rolf, I think you are making things too complicated here. Microsoft themselves introduced the semicolon ( ;) as comment symbol, so although it's not a standard as in ISO or IEEE I don't think there can be too much discussion about how you should place comments in an ini file. Note NI calls them config files, I guess to stay out of MS's water. My experience with config files and the routines I have developed a couple of years back, is that it is possible to enhance the functionality and speed greatly over NI's routines. To prevent messing up the file layout, I am modifying only the value part and keep the rest of the text unmodified, and don't reconstruct the section by collecting keys and values. I insert new keys at the beginning of a new line (after the last written entry or at the end, depending on whether somethings was already written). These are simple measures to retain comments.Other useful improvements could be to write entire sections (so you can store other kinds of data). That way, you can store 1D or 2D arrays of DBL/I32/string in a transparant way in a section.JorisPS yeah that smiley should have been a semicolon

What I meant is that the WinAPI to deal with ini files has no clean means of dealing with comments.

Adding them is impossible through the API and ignoring them is very limited.

Only lines starting with a semicolon will be ignored at all by recent Windows versions.

But for a line

myToken=YES; This is a comment

querying myToken will return "YES; This is a comment"

Definitely not what the OP wanted!

The same funcionality and more than what Windows has can be already done with the Configuration functions. The only drawback with those functions is that they disturb the layout of ini files sometimes (but not the functionality). And all I can say to that is that INI files are not really meant to be read by humans and definitely not by non-programmers. That is one reason why MS moved it into the registry where the presentation of data is left to an application (regedit) instead of having it embedded in the data.

Rolf Kalbermatter

Link to comment

Hello readers,

Thanks for all the hints and tips! I'm a real fan of OpenG vis so i decided to create a new vi for this challenge to add a comment to each line. As long as i use only Clusters for ini files this solution works for me. I'm still struggling a bit with recusive vi's under Labview but it works ,-)

Simply put this vi after each read_section_Clusterogtk.vi and set the comment symbol.... Thats it!

Please let me know if there is something wrong...

Claude

Okay,

there is a little problem with the enum data type. This problem only can be solveted within the OpenG vi. If we think this is a good extension for all OpenG users, this will be the way to go...... just a little fix as always ;-)

Link to comment
  • 14 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.