alias readyml {
if (!$1) || (!$2) { echo -a 10* ERROR incorrect parameters: $eval($readyml(filename, section [,N]),0) | halt }
if (!$exists($1)) { echo -a 10* ERROR file does not exist: $1 | halt }
var %s $read($1,ntw,$+($2,:)), %r $readn
if (!%s) { echo -a 10* ERROR section does not exist: $2 | halt }
if ($readyml_section($1,%r)) {
if ($3 != $null) {
if ($3 == 0) return $hget(yml_sect,0).item
if ($3 > 0) {
if ($3 > $hget(yml_sect,0).item) { echo -a 10* ERROR there are items in the section: $v2 | halt }
return $hget(yml_sect,$3)
}
}
else { var %i 1 | while (%i <= $hget(yml_sect,0).item) { echo -a $hget(yml_sect,%i) | inc %i } | halt }
}
}
alias -l readyml_section {
.hfree -sw yml_sect | var %p $1, %r $2, %n 1
while ($true) {
var %c $calc(%r + %n), %i $read(%p,%c)
if ($right(%i,1) == :) || (%i == $null) || (%c > $lines(%p)) { return $true }
if ($left(%i,1) == -) .hadd -m yml_sect %n %i
inc %n
}
}