# $Header: /home/cvsroot/tcldb/wisql/Tlib/changeElem,v 1.1.1.1 1996/10/12 02:26:26 de Exp $
# tcl procs saved on Tue Sep 05 09:32:19 PDT 1995

proc changeElem {old new arrN size} {
#
#	procedure changes array element position from old to new
#


	upvar #0 $arrN arr


#	we pass the effective legit size of the array, not its literal
#	size -- these arrays could have blank (ignore) cells on the end

	set al $size
	set rl [array size arr]

	if {$old == $new} {
		return
	}

	set shuffle 0
	if {$old > $new} {
		set start 0
		set end $al
		set inc 1
	} else {
		set start [expr {$al - 1}]
		set end -1
		set inc -1
	}

	loop i $start $end $inc {
		if {$i == $new} {
			set was $arr($i)
			set arr($i) $arr($old)
			set shuffle 1
			continue
		}
		if {$i == $old} {
			set arr($i) $was
			set shuffle 0
			continue
		}
		if {$shuffle} {
			set temp $arr($i)
			set arr($i) $was
			set was $temp
		}
	}

}

