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 

INI Library - ultra fast in-memory data mining function set
Goto page Previous  1, 2, 3, 4  Next
 
Post new topic   This topic is locked: you cannot edit posts or make replies.    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
ScottMattes



Joined: 21 May 2007
Posts: 165
Location: USA

PostPosted: Wed Sep 03, 2008 12:40 pm    Post subject: Reply with quote

haichen wrote:
May be a Bracket Error in YOUR Code.


haichen,
Good guess, but removing the "]" from the "*.ini]" did not resolve the problem, I still get the same error.

toralf,
Don't you know that as soon as the doc it written it becomes obsolete? The code reads "ini_MoveKey(ByRef var, from, to, key, copy = false) {"
_________________
-------------
Scott Mattes

My small, and slowly growing, collection of scripts.
Back to top
View user's profile Send private message Visit poster's website
Titan



Joined: 11 Aug 2004
Posts: 5042
Location: /b/

PostPosted: Wed Sep 03, 2008 1:03 pm    Post subject: Reply with quote

Hi scottmattes, I think I found the problem:

Code:

; test ini library

FileSelectFile, my_ini_name, , , Prompt, *.ini]

rc := ini_Load(my_ini_contents, my_ini_name)
if rc = 0
{
  msgbox, my_ini_name=%my_ini_name% contents`n`n%my_ini_contents%
}
else
  msgbox, failed to load
} <-- this shouldn't be here (else block doesn't have opening {)

Maybe this was what haichen was referring to Wink
_________________
Chat (IRC)PlusNetScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ScottMattes



Joined: 21 May 2007
Posts: 165
Location: USA

PostPosted: Wed Sep 03, 2008 1:35 pm    Post subject: Reply with quote

Titan,
Right you are! I saw the ] and focused on that.

Is it just me, or does the error reported seem 'wrong'? Like, I guess that I am wondering why ahk didn't raise an error before getting to the ini.ahk code.

O well, thank you for finding my error for me.
_________________
-------------
Scott Mattes

My small, and slowly growing, collection of scripts.
Back to top
View user's profile Send private message Visit poster's website
haichen



Joined: 05 Feb 2007
Posts: 178
Location: Osnabrück, Germany

PostPosted: Wed Sep 03, 2008 3:46 pm    Post subject: Reply with quote

Quote:
Maybe this was what haichen was referring to Wink

I often make such mistakes when I work with Includes. Sorry of being a bit short.
Back to top
View user's profile Send private message
Coryf88



Joined: 01 Dec 2008
Posts: 1

PostPosted: Mon Dec 01, 2008 8:42 pm    Post subject: Reply with quote

Ran into a problem with _ini_(un)escape. One of my values contained \r, which resulted in it being converted to a carriage return. A simple fix would be to modify the escaped version of "`r" and "`n" to something like "{INI_CARRIAGE_RETURN}" and "{INI_NEWLINE}".

It also looks like ini_Save isn't escaping properly.

Code:
ini_Load(LoadedINI, "[Section]`nKey = \\\\We\Shall\Rock\N\Roll\All\Night\!\\\\")
MsgBox % "Key value is """ . ini_Read(LoadedINI, "Section", "Key") . """."
ini_Write(LoadedINI, "Section", "Key", "\\We\Shall\Rock\N\Roll\All\Night\!\\")
MsgBox % "Key value is """ . ini_Read(LoadedINI, "Section", "Key") . """ after ini_Write."
MsgBox % "INI will be saved as """ . ini_Save(LoadedINI) . """."
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 766

PostPosted: Sat Feb 28, 2009 10:09 am    Post subject: Reply with quote

I can't get ini_Save to work, and I've found some issues (some of which have already been stated).

Line 442:
Code:
_at = %A_LoopField%


Should be:
Code:
_at = %A_AutoTrim%


Line 451:
Code:
StringReplace, ls, ls, %s%`n


%s% is a blank variable at the start of the loop, so you're removing all newlines of the section list on loop pass 1 and doing nothing for the other passes, as far as I can tell. I think this line should be moved up above 451:
Code:
s := SubStr(l, 2, -2), x := InStr(ls, s . "`n"), z := ini_GetKeys(var, s)


Finally, as another user stated, %file% is not defined when you use it at the end of the function. %src% used to contain the filename, but was overwritten at the beginning with the file contents. Before it's overwritten, you need to add:
Code:
file := src


Testing to see if additional changes are needed to get it working...

Update: Definitely still not working. The Save function looks like a mess! I hope the other functions are sound, as I hope to be able to use this library when I figure out the save function.
_________________
Ben

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



Joined: 13 Dec 2006
Posts: 104

PostPosted: Sat Feb 28, 2009 6:03 pm    Post subject: Re: INI Library - ultra fast in-memory data mining function Reply with quote

Titan wrote:
Best of all the script is performance enhanced with only string functions used for parsing content (no regex!), unlike all the other similar scripts you can find on the forum.


Is that RegEx really so slow compare to string functions ?
Back to top
View user's profile Send private message
bmcclure



Joined: 24 Nov 2007
Posts: 766

PostPosted: Sat Feb 28, 2009 11:16 pm    Post subject: Re: INI Library - ultra fast in-memory data mining function Reply with quote

Smurth wrote:
Is that RegEx really so slow compare to string functions ?


In general, no. Compared to string functions, generally yes. Kind of a speed vs. convenience trade-off.
_________________
Ben

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





PostPosted: Tue Mar 10, 2009 6:26 pm    Post subject: ini_Save is not working Reply with quote

I also found that the ini_Save functionality is not working.

When someone (maybe even me) fixes this problem, please post the code. The ini library is really fast and I would like to be able to write to file.

Thanks
Back to top
bmcclure



Joined: 24 Nov 2007
Posts: 766

PostPosted: Tue Mar 10, 2009 6:32 pm    Post subject: Reply with quote

I don't know exactly how the speed compares, but if you can't figure this out,
you might want to try my IniFile class also in these forums which I created because
this library had some unresolved issues. Initial reports indicate it's pretty fast and
all functions work.
_________________
Ben

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





PostPosted: Tue Mar 10, 2009 6:51 pm    Post subject: Found the problem Reply with quote

The ini_Save works fine. You will notice that at the bottom Titan uses
%file% . This is empty. So you just need to create a copy of the file uptop before any changes happen. Viola you got a working program.

Very Happy

And it is much faster than other routines purely because it stores the ini file in memory. So unless you're ini file is really small it wont be worth using it.
Back to top
bmcclure



Joined: 24 Nov 2007
Posts: 766

PostPosted: Wed Mar 11, 2009 12:38 am    Post subject: Reply with quote

Ini_save doesn't work for me in Vista 64-bit, even when populating the %file% variable properly in the function. You'll notice in my posts above there are several other code errors I found, but even when I fixed them it still did not work for me.

My IniFile class is object-oriented, and also stores the Ini file in memory for ultra-fast access, FYI. It parses the whole file into sections and fields (separated by key, value, and comment) when opening it, so it doesn't have to parse the file when you actually run your operations on it. And the save function works, and I don't believe there are errors or omissions in the current code.

So if you can't get this to work, as I couldn't, and because this doesn't seem to be supported anymore (or currently, at least), feel free to give my library a try here.

I even created function aliases in my library so that you can use almost the exact same syntax you use with the Ini_ library, but with IniFile_ before it.

You can also use both at the same time, because I changed the name to IniFile for mine. So feel free to compare and share your results. I've tried to cater to fans of this library, since I'm a fan of this library.
_________________
Ben

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



Joined: 15 Apr 2009
Posts: 75
Location: Italy

PostPosted: Sun Apr 26, 2009 9:21 pm    Post subject: Re: Found the problem Reply with quote

Boontjie wrote:
The ini_Save works fine. You will notice that at the bottom Titan uses
%file% . This is empty.

....


I still dont get it why it works like this

Code:
   c := ini_Save(AppParms)
   FileDelete %MainIniFile%
   FileAppend, %c%, %MainIniFile%


while it doesn't like this (even though I guess that's the intended most common usage):

Code:
   c := ini_Save(AppParms,MainIniFile)


although the last lines in the invoked function look exactly like those in the working example

Code:
   If src_file = 1
   {
      FileDelete, %file%
      FileAppend, %d%, %file%
      Return, !ErrorLevel
   }


src_file is = 1, %file% contains exactly the same value as per the working example (that is a correctly placed existing ini file, it aint empty Boontjie...).
testing ErrorLevel (via OutputDebugger) both after the attempted deletion and file append show a failure on both commands

Code:
   If src_file = 1
   {
      FileDelete, %file%
      OD_Err1 = ErrorLevel
      FileAppend, %d%, %file%
      OD_Err2 = ErrorLevel
      OutputDebug %OD_Err1% %OD_Err2%

      Return, !ErrorLevel

   }


Question
Back to top
View user's profile Send private message AIM Address
UncleScrooge



Joined: 15 Apr 2009
Posts: 75
Location: Italy

PostPosted: Thu Nov 26, 2009 7:02 pm    Post subject: Reply with quote

Unfortunately this library doesnt work.
Or at least I cant make it working
Aside the objections above:

you cant have a key containing C:\remainder or C:\nicholas as value because \r and \n will be escaped/unescaped with funny results.

I found also:

if my code tries to write an empty string in a key, the key and values of the immedialy subsequent one will be deleted and lost

If a section gets vacated of keys the entire section is deleted...

I gave up and switched to the old fashioned ahk directives
It was nice (and fast, veeery fas!!) to handle INI in memory with no disk access.
I doubt that this should still be included in the Wiki catalogue.
_________________
Intel Centrino @ 2.8GHz
4 GB RAM
WIN XP SP3
Back to top
View user's profile Send private message AIM Address
UncleScrooge



Joined: 15 Apr 2009
Posts: 75
Location: Italy

PostPosted: Fri Nov 27, 2009 5:46 pm    Post subject: Reply with quote

Found the bug in ini_Write function
Line 95 and 97 (contained in ini_Write) are:
Code:

95   p += StrLen(f) + 1
97   StringLeft, d1, var, p - 1

if one passes an empty string to write in the key that "+1" at the end of the line 95 gets the following StringGetPos call to set the string trimming right at the end of the following key
so a section like this
[SOMESECTION]
Key1=somevalues1
key2=somevalues2

after a manipulation like
Code:

ini_Write(MyIniRef, "SOMESECTION", "Key1", newVal)

where newVal is an empty string (I want to keep the key but with no value set) becomes:
[SOMESECTION]
Key1=

WHAT?!! IVE LOST Key2 WHICH WASNT EVEN MEANT TO BE TOUCHED!!
yep.
Ive changed the above lines into
Code:

95   p += StrLen(f)
97   StringLeft, d1, var, p

and now it looks like it's working fine, at least for my usage.
I've also made (see bmcclure and Coryf88 posts above) these other changes in the Titan's original code:
Code:

431b   file := src                                    ;line added in ini_Save
440   _at = %A_AutoTrim%                              ;line changed in ini_Save
;##############
571   StringReplace, val, val, `r, {I_C_R}, All       ;lines changed in
572   StringReplace, val, val, `n, {I_L_F}, All       ;_ini_escape
;##############
578   StringReplace, val, val, {I_C_R}, `r, All       ;lines changed in
579   StringReplace, val, val, {I_L_F}, `n, All       ;_ini_unescape

again it works for my own usage wich is limited to load, read, write, delete and save. dunno abt the rest.
_________________
Intel Centrino @ 2.8GHz
4 GB RAM
WIN XP SP3
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3, 4  Next
Page 3 of 4

 
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