proc write_config_file {array_var file} {
    upvar $array_var av
    
    set fp [open $file w]
    foreach index [array names av] {
	puts $fp "$index = $av($index)"
    }
    close $fp
    
    return 1
}

# use first file in filelist as configuration file.  This allows
# users to migrate the names of config files

proc read_config_file {array_var filelist} {
    upvar $array_var av
    
    foreach file $filelist {
	if [file exists $file] {
	    set fp [open $file r]
	    while ![eof $fp] {
		set numb [gets $fp line]
		if {$numb < 0} break;
		
		# skip comments and blank lines
		
		if {($line == "") || ([string index $line 0] == "\#")} continue
		
		# split the line at equal and require that there be
		# a list of 2 entries
		
		set bline [split $line =]
		if {[llength $bline] != 2} continue
		
		set index [string trim [lindex $bline 0]]
		set av($index) [string trim [lindex $bline 1]]
	    }
	    close $fp
	    return 1
	}
    }
    return 0
}
