Jump to content

Need AutoIt's ini format


Recommended Posts

Yeah, the topic explains it pretty well. Since there is no official ini format for every file I'd like to know how exactly Autoit is handling it to imitate it for my or espacially the _IniRead(Section(Names)|ToArray) functions which most likely use RegExp (or should use RegExp if it wouldn't fail for _IniReadSectionFromString; see the thread for more information). That's why I'm requesting the ini syntax AutoIt uses in the first place; the best would be as RegExp but this is not that important.

Wikipedia; Cloanto

How are comments recognized? Just from the start of a line or also after a key/section? Is "#" also accepted? Are "[A,B,C]", "key1, key2=value1" or "key=value1, value2, value3" supported? Is 'key_with_string="I have blanks"' allowed or can you use white space characters in section names or keys? I never saw any of that and did not try it myself yet but an official statement or even a good one would be really nice.

Thanks in advance.

PS: I would've used the Developer Chat forum but it's not allowed for new users to post there; also it's not allowed to edit posts after a few hours which is pretty annoying since I would like to edit my UDF post but I guess it can't be helped.

Link to comment
Share on other sites

By doing a little testing with the Ini functions, which I suggest to you to do it yourself next time.

comments are preceeded by ";" and must start a line

section names are surrounded by "[" and "]"

keys are formatted like so "Key1=value1",

Section names, keys and values can have spaces in them as well as quotes.

##### Edit #####

I almost forgot, any text that isn't formatted as a Section name (i.e. [section Name]), or key definition (i.e. Key=) will be ignored if it's on a line by itself so it works as a comment without having to use the semi-colon. The semi-colon is useful to comment out a line in an ini file that you don't want to be read by the program but you don't want to necessarily delete the line.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

To be quite honest, there's no such thing as an INI comment. If you were to mark the line, it just won't match the request anymore.

IniRead("file.ini", "section", "key")

and say you have

[section]

;key=value

It doesn't return ";key" because it doesn't match "key".

Also, I may be misremembering IniRead.

Edited by Richard Robertson
Link to comment
Share on other sites

AutoIt doesn't recognize ";" as a comment? If I were to use IniReadSection, it won't show the "commented" line in the array either, so I assumed it was just seeing it as a comment. Good to know.

Either way, the result is the same, they're both ignored and the line doesn't have to be deleted to be ignored because of the semi-colon.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

So, here are my results:

[normsection]
key1.1=value1
key1.2=value2 with spaces <- fully recognized
key1.3 with spaces=value3 <- fully recognized
key1.4="value4 with spaces and"" <- fully recognized
[section with spaces]
key2.1=value1
; comment, highlighted from SciTE <- not recognized
# also highlighted from SciTe and also invalid <- not recognized
; [commented_section] <- not recognized
# [commented_section2] <- not recognized
[section3] ; comment after sectionname <- correctly recognized
key3.1=value1
;key3.2=value2 with key directly after ; <- not recognized
# key3.3=value2 with key after # and blank <- fully recognized
[section4,section5]; <- fully recognized
key4&5.1=value1

[normsection2_after_empty_line]; <- recognized
key6.1=value1 ; comment after value <- fully recognized
key6.1.5=value1.5 # comment2 after value <- fully recognized
key6.2, key6.3=value2 for multiple keys <- fully recognized
key6.4=value3, value4, value5 <- fully recognized

key6.5=value6 with key after empty line <- fully recognized
0000(([ <- not recognized
key6.6=value7 with key after invalid line <- fully recognized
key6    .7   =  value after '    =  ' <- fully recognized without leading or ending white spaces (\t, blank)
[key6.8]=value8 with key using [] <- recognized as section "key6.8"
key6.9=value9
[key6.10=value10 with key using [ ; <- fully recognized as section, can have an ending [
key6.11=value11

    [section_after_white_spaces] <- fully recognized, ";" not needed, everything after the first] is skipped
    key7.1=value1 with key after white spaces <- fully recognized

#include <Array.au3>

$snames = IniReadSectionNames("test.ini")
If @error Then
    ConsoleWrite("! IniReadSectionNames @error code:" & @error & @CRLF)
    Exit
EndIf
_ArrayDisplay($snames)

For $i = 1 To $snames[0]
    $section = IniReadSection("test.ini", $snames[$i])
    If @error Then
        ConsoleWrite("! IniReadSection @error code:" & @error & @CRLF)
        ContinueLoop
    EndIf
    $res = _ArraySearch($section, @TAB, 0, 0, 0, 1, 1, 0)
    If $res > -1 Then ConsoleWrite("--- Found a Tabstop in" & $res & "[0] : " & $section[$res][0] & @CRLF)
    $res = _ArraySearch($section, @TAB, 0, 0, 0, 1, 1, 0)
    If $res > -1 Then ConsoleWrite("--- Found a Tabstop in" & $res & "[1] : " & $section[$res][1] & @CRLF)

    _ArrayDisplay($section, $snames[$i])
Next

I commented every line in the ini that is not the usual syntax "[section]\r\nkey=value".

;

  • is recognized as comment and does make the whole ine invalid - sections and keys.
  • is not recognized after or in values.

A section

  • is recognized if the line starts with an [.
  • may have leading \t or blanks.
  • does not need to be closed with a ], the whole line will be read as sectionname.
  • may have "[" inside, even at the end of the line.
  • ignores every single character after it is closed with a "]".

A key

  • is recognized if the line starts with # <- # may not be used as comment.
  • may have leading or ending \t or blanks.
  • is recognized "as it is". "key6.2, key6.3=value2 for multiple keys" will result in "key6.2, key6.3" and "value2 for multiple keys"

A value

  • may have leading \t or blanks.
  • is recognized "as it is". 'key1.4="value4 with spaces and"' will result in '"value4 with spaces and"', 'key1.2=value2 with spaces' in 'value2 with spaces'

Every other line that does not match "(?<=\r\n)(?<!\s*;)\s*(.*?)=(.*)" or "(?<=\r\n|\A)(?<!\s*;)\s*\[([^\]]*)\]?" is simply ignored. Those RegEx are not testet but should show the procedure after what I've tested.

Edited by FichteFoll
Link to comment
Share on other sites

Also, keep in mind that any "Undocumented Features" that you try to take advantage of now may not be carried forward into future versions.

Link to comment
Share on other sites

Running code and looking at the results to build a replica is reverse engineering.

Wouldn't it be more like testing undocumented features so that the documentation can be improved? I don't see how using a function, as its intended to be used, and figuring out what works and what doesn't could be "reverse engineering" anything.

If the Ini file format had a real standard then it wouldn't be a question, if the help file for the Ini... functions explained what works and what doesn't it wouldn't be a question.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Then someone needs to enhance the help file so that there's no need to "reverse engineer" how it works because right now, it's a bit lacking in regards to how the ini file can be formatted and read by the functions.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • 7 months later...

To be quite honest, there's no such thing as an INI comment. If you were to mark the line, it just won't match the request anymore.

Wrong. Lines beginning with a semicolon are indeed comments and should be IGNORED entirely. Value names can NOT start with a semicolon for this reason.

This is from the Win3.1 or Win95 Resource Kit Manual. I'll see if I can find the exact page number when I get a chance. :graduated:

.

Link to comment
Share on other sites

Be careful about how you test this. What you are doing is actually reverse engineering which is against the license for AutoIt.

He's observing behavior without disassembling or doing anything against the terms of the license. This is not against the license.

.

Link to comment
Share on other sites

Any good reason for ressurecting old threads?

Apparently I did this to a few threads yesterday, my apologies. I was on a crummy connection and the pages weren't loading with correct formatting let alone always showing timestamps. I see the date now; I'll be more careful in the future. :graduated: Edited by Unsigned

.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...