here are the two main functions:
you can see in the ini_read proc where i unset itm. any thoughts on this?proc ini_read {inifile section item} {
set item [lindex $item 0]
if {[lindex $inifile 0] == "" || [lindex $section 0] == "" || [lindex $item 0] == ""} { return "\;" }
if {![file exists $inifile]} { return "\;" }
set fileo [open $inifile r]
set sect ""
while {![eof $fileo]} {
set rline [gets $fileo]
set rline [string trim $rline]
if {$rline != "" || [string index $rline 0] != "\;"} {
if {[string index $rline 0] == "\[" && [string index $rline [expr [string length $rline] - 1]] == "\]"} {
set sect [string range $rline 1 [expr [string length $rline] - 2]]
} elseif {[string tolower $sect] == [string tolower $section]} {
set im [string tolower [string range $rline 0 [expr [string first = $rline] - 1]]]
set va [string range $rline [expr [string first = $rline] + 1] end]
set itm(${im}) $va
}
}
}
if {[array names itm [string tolower $item]] == ""} { return "\;" }
set rtrn [set itm([string tolower $item])]
array unset itm
close $fileo
return $rtrn
}
proc ini_write {inifile section item value} {
set section [lindex [string tolower $section] 0]
if {[lindex $inifile 0] == "" || [lindex $section 0] == "" || [lindex $item 0] == ""} { return 0 }
if {![file exists $inifile] || [file size $inifile] == 0} {
set filew [open $inifile w]
puts $filew "\[$section\]"
puts $filew "[string tolower $item]=$value"
close $filew; return 1
}
set fileo [open $inifile r]
set cursect ""; set sect ""
while {![eof $fileo]} {
set rline [string trim [gets $fileo]]
if {$rline != "" || [string index $rline 0] != "\;"} {
if {[string index $rline 0] == "\[" && [string index $rline [expr [string length $rline] - 1]] == "\]"} {
set cursect [string tolower [string range $rline 1 [expr [string length $rline] - 2]]]
lappend sect $cursect
} {
set im [string tolower [string range $rline 0 [expr [string first = $rline] - 1]]]
set vl [string range $rline [expr [string first = $rline] + 1] end]
lappend [join "ini $cursect" ""]($im) $vl
}
}
}
close $fileo; unset fileo
if {[lsearch $sect $section] == -1} { lappend sect $section }
set [join "ini $section" ""]([string tolower $item]) $value
set fileo [open $inifile w]
foreach sct $sect {
puts $fileo "\[$sct\]"
foreach ite [array names [join "ini $sct" ""]] {
set ite [lindex $ite 0]
set valu [set [join "ini $sct" ""]($ite)]
if {$ite != ""} {
puts $fileo "$ite=[join $valu]"
}
}
puts $fileo ""
}
close $fileo
return 1
}
looks like the tabs aren't showing. here's the link:
http://www.egghelp.org/files/tcl/inidb042.tgz
thanks