Page 1 of 2

getkey - content of a whole section?

Posted: 04 Mar 2015 15:35
by highend
I'm unsure if this worked in the past but iirc it was possible to get the full content of section via:

Code: Select all

$content = getkey(, "General", "<come .ini file>");
With:

Code: Select all

[General]
Reserved=0
Broken=1
Test=0
Where $content became:

Code: Select all

Reserved=0
Broken=1
Test=0
Am I wrong or can anybody confirm this?

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 15:44
by bdeshi
BTW,these days, a list of keys are still returned, but without values, and separated by null, which terminates any text output prematurely.

Code: Select all

::$content = getkey(, "Settings", <xyini>); $keys = replace($content,chr(00),<crlf>); text $content; text hexdump($content); text $keys;
ed: the same is true for sections. If section parameter is empty, all existing sections are returned null-separated.

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 15:54
by admin
Correct. The behavior can be read up here (although not really detailed): https://msdn.microsoft.com/en-us/librar ... 85%29.aspx
(XY just wraps this function).

I also think this has been different in earlier Windows versions. Hm.

Kind of funny that again we have a case where NULLs are returned and the output is mostly eaten by the Windows edit box. I'm slowly getting softer with regard to auto-patching the output in such cases... :whistle:

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 16:29
by admin
I got a short coding attack and did this (next beta v14.80.0239):

Code: Select all

    ' 20150304: returns a list of all key=value pairs in Section, separated by Separator
    ' syntax: getkeyvaluelist(Section, [INIfile], [Separator=CRLF])
    ' example: text getkeyvaluelist("General");
Still waiting for the documenting attack. Till then it will be undocumented.

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 16:38
by bdeshi
What about a list of Sections?

ed. maybe rename it to getini():

Code: Select all

    getini()
    Returns a list of all keys in Section or a list of sections,separated by Separator.
    Optionally with values or child keys respectively.
    syntax: getini([Section], [INIfile], [Separator=CRLF], [return terseness flag])
    example:
    text getini("General");
    //returns all keys only in General section of <xyini>
    text getini("General",,,1);
    //returns the same but with values as key=value
    text getini(,,,);
    //returns all sections in <xyini>
    text getini(,,,1);
    //returns the same but with child keys as section<tab>keys<tab>keys
ed2. or maybe getsectionlist() :lol:

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 16:59
by admin
What about a list of Sections?
Good.

terseness?
Overkill.

getsectionlist()?
Yep, better.

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 17:23
by TheQwerty
I think you guys are just making this too complicated and complex...

GetKey can already do the list of sections.

Unless you mean doing:

Code: Select all

$kvPairs = getkeyvaluelist('General|Settings'); // Get all key=values in General & Settings sections
But there's no decent way of distinguishing keys from each section with this unless it also prefixes the sections to the key names. Frankly, none of this is difficult to achieve with a foreach loop so I don't see the point in making this a more complicated function.

It's not like the inspiration to document this thing will come any easier if there is more to explain. :P


I'd much prefer the time be spent on things we cannot easily accomplish - like reading and changing the in memory values that correspond to XY's INI file. Those things requiring saving the settings, modifying them, and then restarting XY are a major PITA. ;)

EDIT: Actually scratch that... I want NEED user functions!

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 18:16
by bdeshi
simplest solution: add a separator parameter to getkey()
Key values can be retrieved easily from keylist. No need for additional SCs.

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 18:18
by admin
Indeed, GetKey can do it. So I just leave it all as it is now.

No need for a can worms ATM.

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 18:30
by bdeshi
admin wrote:Indeed, GetKey can do it. So I just leave it all as it is now.
a separator? nice to skip an extra step of replace(getkey(),chr(00),<crlf>)

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 18:48
by admin
SammaySarkar wrote:
admin wrote:Indeed, GetKey can do it. So I just leave it all as it is now.
a separator? nice to skip an extra step of replace(getkey(),chr(00),<crlf>)
Ah, okay. In that case getSectionList() is the better name indeed.

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 19:03
by bdeshi
eh (sorry!), but actually in that case that extra replace() seems better and simpler than new SCs... :whistle:

Re: getkey - content of a whole section?

Posted: 04 Mar 2015 19:06
by admin
You can go the replace way if you want. My coding attack is over, I feel better, there won't be any docs, so case closed I suppose. :)

Re: getkey - content of a whole section?

Posted: 05 Mar 2015 15:09
by admin
2 examples (v14.80.0239) to finish this little excercise:

Code: Select all

text getsectionlist("General");
text getsectionlist();

Re: getkey - content of a whole section?

Posted: 05 Mar 2015 15:20
by bdeshi
another Secret for future newbies to find, at any case. :wink:
At the risk of beating a dead horse: y'know, returning keys without values could've been a choice.... keys can have huge huge values.... : whistle :