|
|
Joined: May 2008
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: May 2008
Posts: 127 |
How do I search though a specific INI file (let's say for example 'global.ini') for the specified value and return every item that contains that value? Example: global.ini contains this:
[general]
yellow=23
green=89
purple=23
orange=23
red=19 If I type !search 23, I want the script look inside global.ini and return all items with a value of '23'. So if I typed this, the script should return: Yellow Purple Orange Any help is appreciated. Thanks.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
Loop through the items using $ini and return their values using $readini.
-genius_at_work
|
|
|
|
Joined: May 2008
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: May 2008
Posts: 127 |
Could you give me an example? I'm not very experienced with loops. :P
|
|
|
|
Joined: May 2008
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: May 2008
Posts: 127 |
ehh, sorry to double post, but just to make sure we're clear, you do know I'm not interested in returning the values, but the name of the items, correct?
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
Example:
var %file = mydata.ini
var %sect = mysection
;---------------------
var %x, %i = 0, %ii = $ini(%file,%sect,0)
while (%i < %ii) {
inc %i
%x = $ini(%file,%sect,%i)
if ($readini(%file,%sect,%x) == $1) {
echo -a Matched $1 @ %x
}
}
Change %file and %sect to match your ini filename and ini section(topic). -genius_at_work
|
|
|
|
Joined: May 2008
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: May 2008
Posts: 127 |
There's people that are professional scriptors and then there's the ones who just friggin pwn at scripting, much like yourself. Thanks man, I really appreciate your help.
|
|
|
|
Joined: May 2008
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: May 2008
Posts: 127 |
Just one more thing...
Not always are there results. How do I add an else statement or something in this?
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
After the last } of the while loop, add this line:
if (%x == $null) { echo -a No Matches Found }
-genius_at_work
|
|
|
|
Joined: May 2008
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: May 2008
Posts: 127 |
I've tried many things and the things I tried ending up making it say 'no matches' when there ARE results and when there AREN'T results. But doing what you said...
while (%i < %ii) {
inc %i
%x = $ini(%file,%sect,%i)
if ($readini(%file,%sect,%x) == $2) { .notice $nick $cl %x }
}
if (%x == $null) { .notice $nick $cl No matches }
...doesn't work. If there ARE matches, it shows all matches and doesn't say "no matches". If there AREN'T matches, it doesn't show anything.
|
|
|
|
Joined: Oct 2005
Posts: 1,741
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,741 |
Try this:
var %file = mydata.ini
var %sect = mysection
;---------------------
var %x, %m = 0, %i = 0, %ii = $ini(%file,%sect,0)
while (%i < %ii) {
inc %i
%x = $ini(%file,%sect,%i)
if ($readini(%file,%sect,%x) == $1) {
%m = 1
echo -a Matched $1 @ %x
}
}
if (%m == 0) { echo -a No Matches Found }
-genius_at_work
|
|
|
|
Joined: May 2008
Posts: 127
Vogon poet
|
OP
Vogon poet
Joined: May 2008
Posts: 127 |
Yep, that worked. Thanks again.
|
|
|
|
|
|