AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Class] IniFile 0.6.6 - Object-oriented INI file handling
Goto page Previous  1, 2, 3  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
bmcclure



Joined: 24 Nov 2007
Posts: 774

PostPosted: Tue Mar 03, 2009 8:59 pm    Post subject: Reply with quote

Version 0.6.0 posted with all the changes we discussed. Most of them are included in the IniFile_test.ahk example now as well.

Let me know what you think, or if you see any errors I missed Smile

New attributes:
headerComments under IniFile

New functions:
-IniFile_getComment
-IniFile_setComment
-IniFile_getHeaderComment
-IniFile_setHeaderComment
-IniFile_addHeaderComment
-IniFile_removeHeaderComment
-IniFile_loadFromVar
-IniFile_reload
-IniFile_reloadFromVar

Some functions have been overloaded with additional functionality. They should work exactly like before if you don't do anything differently, however.

Note that you can avoid calling the SortOptions parameter in every function by specifying you always want the file sorted:
Code:
IniFile_setAutoSort(File, true)
IniFile_setSortOptions(File, "U") ; or whatever you want to use


You can do the same to set ignoreComments, ignoreBlankLines, splitComments (split them to their own lines), quoteValues, etc. and it is handled automatically where appropriate. You can always (usually) override these defaults by using extra parameters in the function calls, where they are appropriate.
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Wed Mar 04, 2009 3:45 am    Post subject: Reply with quote

Looks good. Nice additions, can't wait to try them out.

I always use null ("") to mean an error (like removing an item from an empty Vector). I use 0 when zero (like an index) is returned. Also, I use 0 to mean the function was not successful (but not due to an error). For example, when destroying an object, it returns false (0) to indicate the object still exists (i.e. not ready to delete); whereas it returns null if the object is NULL (0 or blank), to indicate the error.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Wed Mar 04, 2009 4:07 am    Post subject: Reply with quote

Observation: I see a value for duplicate keys, but it doesn't look like it is ever used.

Edit:
Not sure if it would cause problems, but for IniFile_loadFromVar (and IniFile_reLoadFromVar), you might want <data> to be ByRef. Since loadFromVar should be passing a variable, it means that large amounts of data don't need to be copied first, because the value is ByRef. However, this only is possible if data will ALWAYS be a variable.

Edit2:
Bug report. In IniFile_clear, you should be clearing the sections - you currently set it to zero (destroying the sections Vector)

This fixes it:

Code:
IniFile_clear(IniFileObject) {
    IniFile_setData(IniFileObject, "")
    if sections := IniFile_getSections(IniFileObject)
        Vector_clear(sections)

    IniFIle_setLoaded(IniFileObject, 0)
   
    return true
}

_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
bmcclure



Joined: 24 Nov 2007
Posts: 774

PostPosted: Wed Mar 04, 2009 6:17 am    Post subject: Reply with quote

Still working on duplicate keys, I sort of forgot to include that in the release and have been busy with the DOM library.

I'll try to get that in place tomorrow.

In the meantime, I've changed data (and its reference in the reloadFromVar function) to ByRef, removed the extra call you messaged me about, and changed IniFile_clear() to clear the vector to fix the bug you found.

Thanks as usual!

Edit New version uploaded with the fixes.
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
animeaime



Joined: 04 Nov 2008
Posts: 1045

PostPosted: Wed Mar 04, 2009 6:18 am    Post subject: Reply with quote

No rush, thanks for your great work.
_________________
As always, if you have any further questions, don't hesitate to ask.

Add OOP to your scripts via the Class Library. Check out my scripts.
Back to top
View user's profile Send private message Send e-mail
bmcclure



Joined: 24 Nov 2007
Posts: 774

PostPosted: Sat Mar 07, 2009 11:40 pm    Post subject: Reply with quote

New version (0.6.5) posted. Updating first topic.

1. Implemented changes in OOP Library V2, meaning:
- IniFiles, IniSections, and IniFields are all cloneable
- IniFiles, IniSections, and IniFields are all comparable

2. Fixed HeaderComment code to account for a change to the Vector class.

3. When a function has a problem, it now returns "" (null) instead of 0 (false)
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 774

PostPosted: Sun Mar 08, 2009 4:09 pm    Post subject: Reply with quote

re-uploaded a new, very minor release, 0.6.6.

I had previously only used 4-bits per byte when setting bit flags, meaning I was using twice the amount of space I needed to for storing boolean values. (thanks, animeaime!)

I have now shortened IniFile objects from 23 bytes to 22 Smile
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 774

PostPosted: Sun Mar 08, 2009 5:19 pm    Post subject: Reply with quote

I also fixed the Clone function to utilize a feature I was unaware of in the Class library to clean up the Settings-only IniFile clone operation.

It's such a minor change that I didn't update the version number, but feel free to grab the new release from the first post if you plan to utilize IniFile cloning.
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 774

PostPosted: Thu May 28, 2009 7:15 am    Post subject: Reply with quote

I'm starting to create an IniFileI interface to define what an IniFile class should be. Before I get too far, I want to check with anyone who has used this library, or any of the available Ini libraries:

Do you like the current function names in this library? Do you use the provided aliases to match Titan's functions, or do you access my functions directly?

if I'm going to make a change to the methods, I'd like to do it before releasing the interface if possible.
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
Mystiq



Joined: 08 Jan 2007
Posts: 83

PostPosted: Thu Jun 11, 2009 11:39 am    Post subject: Reply with quote

Am i correct that in the current release none of the duplicate keys removal options work? If so, any news on when it might get added?

Also i'd like to say thanks Exclamation
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 774

PostPosted: Thu Jun 11, 2009 2:40 pm    Post subject: Reply with quote

There are options (duplicateSections and duplicateKeys) you can set on the IniFile object to choose whether or not you want to allow duplicates in your IniFile.

After you create your IniFile object, use the following:

Code:
IniFile_setDuplicateSections(IniFileObject, true)
IniFile_setDuplicateKeys(IniFileObject, true)


This will allow both types of duplicates. By default duplicates are not allowed.

If it isn't working properly, I can take a look at it today.

Thanks.
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Sun Oct 11, 2009 8:06 pm    Post subject: Reply with quote

When a value contains a ';' (semicolon), IniFile_read stops reading the value after the semicolon. Even suffixing a break ("`") before the semicolon fails to allow IniFile_read to read the complete line.

Here's my data:
task_notes=Execute following via Tivoli on all servers in environment:`ncd /var/spool/cron/crontabs`;for file in *`; do if [ -f $file ]`; then lines=`grep -v '^#'`n$file | grep -v '^$'|wc -l | sed 's/ //g'``;if [ "$lines" = "0" ]`; then crontab -r $file`;fi`;f`ni`;done`n

Here's my code:
Code:
task_notes := IniFile_read(File, "crq", "task_notes")
MsgBox,,read from file,%task_notes%


This is what MsgBox shows:
Code:
Execute following via Tivoli on all servers in environment:`ncd /var/spool/cron/crontabs`


Is there a workaround?
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 774

PostPosted: Mon Oct 12, 2009 2:20 am    Post subject: Reply with quote

This was built surrounding the recognized INI file "standards" (basically non-existent) stating that a semicolon indicates the start of a comment and everything after it should be ignored (see http://en.wikipedia.org/wiki/INI_file).

However you're right, some sort of escape sequence should be supported so that semicolons can be used within actual content.

I've been heavily focused on my C# apps and libraries lately, but will make it a point to touch up this INI library and allow escape sequences for characters with meanings.
_________________
Ben

My Trac projects
My Wiki
[Broken] - My music
Back to top
View user's profile Send private message
ghee22



Joined: 04 Jul 2009
Posts: 36

PostPosted: Mon Oct 12, 2009 1:48 pm    Post subject: Reply with quote

bmcclure wrote:
This was built surrounding the recognized INI file "standards" (basically non-existent) stating that a semicolon indicates the start of a comment and everything after it should be ignored (see http://en.wikipedia.org/wiki/INI_file).

However you're right, some sort of escape sequence should be supported so that semicolons can be used within actual content.

I've been heavily focused on my C# apps and libraries lately, but will make it a point to touch up this INI library and allow escape sequences for characters with meanings.


Thanks for underlying reason. What I did was use accent characters as a replacement for semicolons. Since the code I wrote will never be localized, I was not restricted by them. However, I do not recommend this solution if one plans to localize their code in the future.

Here's my code:
Code:
String_multiline_to_save(ByRef target)
{
   global
   StringReplace, target, target, `n ,``n,  All
   StringReplace, target, target, `;, ¿ , All
   Return
}

String_multiline_to_load(ByRef target, var_name)
{
   global
   target := IniFile_read(File, "crq", var_name)
   ;MsgBox,,read from file,%target%
   StringReplace, target, target, ``n, `n , All
   ;MsgBox,,replaced newlines,%target%
   StringReplace, target, target, ¿, `; , All
   ;MsgBox,,replaced semicolons,%target%
   Return
}
Back to top
View user's profile Send private message
kenn



Joined: 11 Oct 2010
Posts: 288

PostPosted: Tue Jan 11, 2011 8:20 pm    Post subject: Reply with quote

download link is dead Sad
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group