While working on my soon to be released snippet, I saw the need to be able to reference topics and/or items by wildmatch... so without further ado, I present you $wini! :_)
It's kind of like $ini, although slightly different.
see code for usage, example follows here.
say we have the following ini file (C:\things.ini):
[animals]
cat=meow
dog=woof
cow=moo
$wini(C:\animals.ini, animals, *o*)
returns '2'
$wini(C:\animals.ini, animals, *o*, 1)
returns 'dog'
I hope that's clear enough, feel free to ask for clarification ;_)
;; takes the following input:
;; $1 = ini file
;; $2 = catagory
;; $3 = item
;; $4 = Nth match to return. if item isn't specified, this becomes $3. for this reason
;; you most likely cannot match on numbers :(
alias wini {
var %file $1
var %cat $2
if ($3 != $null) {
if ($3 !isnum) {
echo -s no number given: $3
var %item $3
if ($4 != $null) {
echo -s number given: $4
var %return $4
}
}
else {
echo -s number given: $3
var %return $3
}
}
echo -s input is: $1-
var %count 1
var %total $iif(%item == $null, $ini(%file, 0), $ini(%file, %cat, 0))
echo -a total: %total
while (%count <= %total) {
var %current $iif(%item == $null, $ini(%file, %count), $ini(%file, %cat, %count))
echo -a current: %current
if ($iif(%item == $null, %cat, %item) iswm %current) {
echo -a wildmatch!
var %result $addtok(%result, %current, 32)
}
inc %count
}
if (%return != $null) {
return $gettok(%result, %return, 32)
}
else {
return $numtok(%result, 32)
}
}