Snippet that reads from an ini based on wildcards. Also returns a list of matched items alternatively.
; ------------------------------------------------------
; $readiniwm()
; Returns the Nth item wildmatch you receive from an ini topic.
; $readiniwm(<file>,<topic>,<params>,[N])
; Since $readiniwm uses iswm to check the params, you can use a wildcard (e.g *d* would return all matches equal to *d*)
; [N] is optional:
; Returns the Nth wm in the generated list.
; If there isn't a Nth wildmatch, it will just return the list of all wildmatches.
; Alternatively, you can just use $readiniwm(<file>,<topic>,<params>) to return all matching items.
; Here is an example:
; $readinwm($mircini,dirs,*d*):
; Returned logdir midis
; Here is how the ini file looked:
; [dirs]
; logdir=logs
; waves=sounds
; midis=sounds
; mp3s=sounds
; wmas=sounds
; oggs=sounds
; ^ So it obviously matched the d in logdir and the d in midis
; Now if we used:
; $readiniwm($mircini,dirs,*d*,1):
; it would return logs
; because it returned the first wildmatch (logdir) and read the ini item from there.
; ------------------------------------------------------
alias readiniwm {
if ($3) {
if (($isfile($1)) && ($ini($1,$2))) {
var %x = 1, %n = storeini.temphash
if ($hget(%n)) hfree %n
while ($ini($1,$2,%x)) {
if ($3 iswm $v1) hadd -m %n $ini($1,$2,%x)
inc %x
}
if ($hget(%n,1).item) {
return $iif($4 && $hget(%n,$4).item, $&
$readini($1,$2,$hget(%n,$4).item), $&
$hget(%n,0).item)
}
return $false
}
else $err($!readiniwm: invalid parameters)
}
else $err($!readiniwm: insufficient parameters)
}
alias -l err {
if (!$1-) return $false
echo $+(-,ac,$iif($prop,t)) info $1-
halt
}