#
# Commands to eval an nlv-keys.cfg file
#
set param(NOSET) "-"
set param(parse,set) "-"

###########################################################

proc groupalias { alias names } {
  global param

  if { $param(parse,set) != $param(NOSET) } {
    puts "Groupalias $alias must be in global space; ignored"
    return
  }
  set param(cfg,groupalias,$alias) $names
}

###########################################################

proc eventset { name options } {
  global param

  if { $param(parse,set) != $param(NOSET) } {
    puts "Set $name must be in global space; ignored"
    return
  }
  set vis [string range $name 0 0]
  set nm  [string range $name 1 end]
  if { ($vis != "+" && $vis != "-") || [string length $nm] < 1 } {
    puts "Invalid set name $name ; ignored"
    return 1
  } 
  set param(cfg,set,$nm) $vis
  set param(parse,set) $nm
  foreach option $options {
    if { [eval $option] != 0 } {
      puts "Error evaluating event set $nm option: $option"
      return 1
    }
  }
  set param(parse,set) $param(NOSET)
}

###########################################################

proc type { t } {
  global param
  set s $param(parse,set)
  set param(cfg,$s,type) $t
  return 0
}

###########################################################

proc id { t } {
  global param
  set s $param(parse,set)
  set param(cfg,$s,id) $t
  return 0
}

###########################################################

proc group { t } {
  global param
  set s $param(parse,set)
  set param(cfg,$s,group) $t
  return 0
}

###########################################################

proc val { fld min max } {
  global param
  set s $param(parse,set)
  set param(cfg,$s,val) [list $fld $min $max]
  return 0
}

###########################################################

proc annotate { t } {
  global param
  set s $param(parse,set)
  set param(cfg,$s,annotate) $t
  return 0
}

###########################################################

proc rotateclients { t } {
  global param
  set s $param(parse,set)
  set param(cfg,$s,rotateclients) $t
  return 0
}

###########################################################

proc events { elist } {
  global param
  set s $param(parse,set)
  foreach e $elist {
    set vis [string range $e 0 0]
    set evt [string range $e 1 end]
    if { ($vis != "+" && $vis != "-") || [string length $evt] < 1 } {
      puts "Invalid event name $evt in set $s ; ignored"
    } 
    set param(cfg,$s,events) $elist
  }
  return 0
}

source "./nlv-keys.cfg"
