Finding commented out ini line in position relative to others in section

Hey everyone, if you have time to review this please let me know if my relevance can be improved. It’s working but I have a feeling it could be written better (i.e. run faster).

I am dealing with a vendor limitation where if a commented out item exists in a certain ini section, their software stops reading the section instead of just skipping the comment. :face_with_symbols_over_mouth: So I need to check all our systems to find out where this situation exists.

So these situations are ok:

[DataPath]
Item1=\\Device1\c\test\data
Item2=\\Device2\c\test\data
Item3=\\Device3\c\test\data
Item4=\\Device4\c\test\data
;Item5=\\Device5\c\test\data

[DataPath]
Item1=\\Device1\c\test\data
Item2=\\Device2\c\test\data
Item3=\\Device3\c\test\data
;Item4=\\Device4\c\test\data
;Item5=\\Device5\c\test\data

But this is not and would result in items 3-5 getting “lost”:

[DataPath]
Item1=\\Device1\c\test\data
;Item2=\\Device2\c\test\data
Item3=\\Device3\c\test\data
Item4=\\Device4\c\test\data
Item5=\\Device5\c\test\data

This is what I have so far:

q: /*Is the last commented out device string after the Device1 line *and* before the last uncommented device line?*/((tuple string item 0 of it as integer > tuple string item 1 of it as integer) and (tuple string item 0 of it as integer < tuple string item 2 of it as integer)) of (concatenation ", " of ((/*Commented out DeviceX*/maximum of line numbers of lines whose (it contains case insensitive regex ";Item\d{1,}=\\\\Device\d{1,}\\c\\test\\data$") of it as string | "0"; /*Device1*/line number of line whose (it contains case insensitive regex "Item1=\\\\Device\d{1,}\\c\\test\\data$") of it as string | "0"; /*DeviceX*/maximum of line numbers of lines whose (it contains case insensitive regex "Item\d{1,}=\\\\Device\d{1,}\\c\\test\\data$") of it as string | "0") of file "C:\Temp\Test.ini")) | False
A: True
T: 4.537 ms
I: singular boolean

You can assume that Device1 will be present and uncommented, and that are no two digit devices (e.g. Device10).

Thanks in advance for any help.

1 Like

Are there other sections in the .ini that we care about? Otherwise maybe something like the following - i dont have a debugger handy and haven’t tested though. True if there is a non-comment line anywhere after a comment line.

maximum of line numbers of lines whose (it as trimmed string !="" and it does not start with ";") of it > minimum of line numbers of lines whose (it as trimmed string starts with ";") of it) of file "whatever"

Also check a long discussion at RFE: better INI inspectors / parsing with regular expressions as workaround

Not sure how a comment line appears in ‘variables of file’ output though

Thanks Jason. Unfortunately there are many other sections in this ini that may have comments as well, I just simplified the test case for the forum post. I did check out the variables of file inspector but it didn’t seem to really improve things.

And to answer your question, a comment when using variables of file has no special handling - the semicolon is at the beginning of the value part of the string as expected. But that inspector has come in very handy in other situations I have been in.

Shoot, I came up with something that works yesterday at home and got sidetracked, forgot to post it. Will try to recreate if I get some free time today, otherwise will post tonight.

It used variables of file, trimming to following text of firsts "[Section]." of preceding text of firsts "=" of variables of ..., then concatenated them with “|”, then looked at substrings separated by |

Ok I think I have something working.

// Acceptable file
q: lines of file "c:\temp\test\file1.ini"
A: [Section1]
A: var1=val1
A: [DataPath]
A: Item1=\\Device1\c\test\data
A: Item2=\\Device2\c\test\data
A: Item3=\\Device3\c\test\data
A: ;Item4=\\Device4\c\test\data
A: ;Item5=\\Device5\c\test\data
A: [Section2]
A: var2=val2
T: 0.453 ms
I: plural file line

q: variables of file "c:\temp\test\file1.ini"
A: [Section1].var1=val1
A: [DataPath].Item1=\\Device1\c\test\data
A: [DataPath].Item2=\\Device2\c\test\data
A: [DataPath].Item3=\\Device3\c\test\data
A: [DataPath].;Item4=\\Device4\c\test\data
A: [DataPath].;Item5=\\Device5\c\test\data
A: [Section2].var2=val2
T: 0.303 ms
I: plural string

q: preceding texts of firsts "=" of following texts of firsts "[DataPath]." of variables of file "c:\temp\test\file1.ini"
A: Item1
A: Item2
A: Item3
A: ;Item4
A: ;Item5
T: 0.480 ms
I: plural substring

q: (it, following text of it) of substrings separated by "|" of concatenation "|" of preceding texts of firsts "=" of following texts of firsts "[DataPath]." of variables of file "c:\temp\test\file1.ini"
A: Item1, |Item2|Item3|;Item4|;Item5
A: Item2, |Item3|;Item4|;Item5
A: Item3, |;Item4|;Item5
A: ;Item4, |;Item5
A: ;Item5, 
T: 0.625 ms
I: plural ( substring, substring )

// Good file returns 'false'
q: exists it whose (it starts with ";" and exists (substrings separated by "|" of following text of it) whose (it != "" and it does not start with ";")) of substrings separated by "|" of concatenation "|" of preceding texts of firsts "=" of following texts of firsts "[DataPath]." of variables of file "c:\temp\test\file1.ini"
A: False
T: 0.561 ms
I: singular boolean

// bad file
q: lines of file "c:\temp\test\file2.ini"
A: [Section1]
A: var1=val1
A: [DataPath]
A: Item1=\\Device1\c\test\data
A: Item2=\\Device2\c\test\data
A: Item3=\\Device3\c\test\data
A: ;Item4=\\Device4\c\test\data
A: ;Item5=\\Device5\c\test\data
A: Item6=\\Device6\c\test\data
A: [Section2]
A: var2=val2
T: 0.498 ms
I: plural file line

// Bad file returns 'true'
q: exists it whose (it starts with ";" and exists (substrings separated by "|" of following text of it) whose (it != "" and it does not start with ";")) of substrings separated by "|" of concatenation "|" of preceding texts of firsts "=" of following texts of firsts "[DataPath]." of variables of file "c:\temp\test\file2.ini"
A: True
T: 0.617 ms
I: singular boolean
2 Likes

Thanks Jason, that is a lot cleaner than my attempt. I appreciate the help!