mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2003
Posts: 42
Demarko Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Sep 2003
Posts: 42
Hi all,

I have a .ini file in the following format:

Code:
[Alpha]
entry=empty
key=123
more=less

[Beta]
entry=window
pass=123

[Gamma]
key=123
password=123

Those entries are not fixed, so I dont know the sections names and I do not know if or what keys go with each of the existing section. That being said I want to get the following two functions.

First, I'd like to read the existing sections from the given file with something like:
Quote:
/getsection (or /getsection file.ini)

which will return something (a String) like Found sections: Alpha Beta Gamma

Once I know the sections, the second and last step is to get the entries by something like
Quote:
/getentry Beta
which should return the following two lines:
Code:
entry=window
pass=123


Unfortunately my knowledge about the mirc coding syntax is terrible, so any solution is welcome.
Thanks in advance! smile

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
You can loop through ini files using $ini combined with $readini to get proper values.
Use the help files to know how to use them
example:
Code:
var %i 1
var %length $ini(inifile.ini,section,0)
while (%i < %length) {
var %item $ini(inifile.ini,section,%i)
var %value $readini(inifile.ini,section,%item)
echo -ag Value of Nr: %i is %value and the item is called %item
}
Not sure if that's exactly what you're looking for. But I guess you'll figure it out from reference. There's also support for wildcards using $ini


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Sep 2003
Posts: 42
Demarko Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Sep 2003
Posts: 42
This looks like something I could start on with... it will probably solve the /getentry value thing.
But still I dont know what sections are available. In your code snippet section is fixed.

How can I get the available sections from a given file. That would be what I meant with /getsection command above.
confused

Joined: Dec 2013
Posts: 779
N
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
If you read the help files of $ini, you could see that you can simply use
Code:
$ini(file.ini,0)
to return the full number of sections in that inifile.
Example:
Code:
var %i 1
while (%i <= $ini(file.ini,0) {
var %section $ini(file.ini,%i)
echo -a Section $chr(32) $+ %i $+ : %section
inc %i
}
You can then loop through the sections items the same way by using $ini(file.ini,%section,0) etc


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Joined: Sep 2003
Posts: 42
Demarko Offline OP
Ameglian cow
OP Offline
Ameglian cow
Joined: Sep 2003
Posts: 42
Ok, that looks like it could work. I gonna try it later. I'll be back if I should fail crazy

Thank you Nillen smile


Link Copied to Clipboard