; $readallini(<file>,[line])
; [line] can be:
; - a positive integer to return data of that line counting top-bottom
; - a negative integer to return data of that line counting bottom-top
; - 0 to return the total number of lines
; - nothing to return data of a random line
alias readallini {
; any lines in <file>
if ($lines($1)) {
; filter to a tempfile, exclude lines starting with "[" and blank lines
filter -ffcxg $qt($1) readallini.tmp ^\[|^$
; any lines remaining
if ($filtered) {
; second parameter is 0: return total
if ($2 == 0) { return $filtered }
; no or invalid second parameter: return random
elseif ($2 !isnum) { return $gettok($read(readallini.tmp,n),2-,61) }
; second parameter is a positive number: return that line
elseif ($2 > 0) { return $gettok($read(readallini.tmp,n,$v1),2-,61) }
; second parameter is a negativenumber: return that-last line
elseif ($calc($filtered + $2 +1) > 0) { return $gettok($read(readallini.tmp,n,$v1),2-,61) }
}
}
}