#
# QCad
# (c) Q Solutions 1998
#
#
#
# List processing routines
#


# listFind item list - returns position of item(.*) within list
# listGet item list - returns list matching item(.*) from list
# listPut item list value - replace list matching item(.*) with item(value)
# inList item list  - returns 1 /0 if exact item is in list
# listDel item list - removes the item(.*) from the list
# listOpt item list - returns option from tk configure type list

proc listFind { item list } { return [lsearch -glob $list $item\(*] }

proc listGet { item list } {

	set p [listFind $item $list]
 	if { $p == -1} { return "" }
	regsub {(.+[(])(.*)([)])} [lindex $list $p] {\2} val
	return $val
}

proc listPut { item list value } {

	set p [listFind $item $list]
 	if { $p == -1} { return [lappend list $item\($value)]  }
	regsub {(.+[(])(.*)([)])} [lindex $list $p] "\\1$value\\3" val
	return [lreplace $list $p $p $val]
}

proc listDel { item list } {

	set p [listFind $item $list]
 	if { $p == -1} { return $list  }
	return [lreplace $list $p $p]
}


proc inList { item list } { return [expr [lsearch -exact $list $item] != -1] }



proc listOpt { item list } {

	set p [lsearch -exact $list $item]
	if { $p == -1 } { return "" }
	return [lrange $list $p [expr $p +1]]
}




