AutoHotkey Community

It is currently May 26th, 2012, 6:32 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: March 3rd, 2009, 9:59 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
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 :)

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2009, 4:45 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2009, 5:07 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2009, 7:17 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2009, 7:18 am 
Offline

Joined: November 4th, 2008, 9:23 am
Posts: 1045
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2009, 12:40 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2009, 5:09 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
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 :)

_________________
Ben

My Trac projects
My Wiki
[Broken] - My music


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 8th, 2009, 6:19 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2009, 8:15 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 11th, 2009, 12:39 pm 
Offline

Joined: January 8th, 2007, 1:14 pm
Posts: 83
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 :!:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 11th, 2009, 3:40 pm 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 11th, 2009, 9:06 pm 
Offline

Joined: July 4th, 2009, 6:53 pm
Posts: 36
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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2009, 3:20 am 
Offline

Joined: November 24th, 2007, 9:07 pm
Posts: 774
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2009, 2:48 pm 
Offline

Joined: July 4th, 2009, 6:53 pm
Posts: 36
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 11th, 2011, 9:20 pm 
Offline

Joined: October 11th, 2010, 12:30 pm
Posts: 406
download link is dead :(


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group