proc trf_place {y x val fmt {brk 0} {nl {}} {hdr {}}} {
# $Header: /home/cvsroot/tcldb/ucodb/Tlib/trf_place,v 1.1.1.1 1996/10/12 01:08:27 de Exp $

	global trf_wid trf_len trf_sav trf_pag trf_lin
	global trf_arr trf_blk trf_fp trf_pnf trf_pnx trf_pny trf_pnn

#	puts stderr "enter trf_place with args col $x line $y val $val fmt $fmt brk $brk nl? $nl hdr? $hdr"

#	trf_wid:  width of page in char
#	trf_len:	 length of page in lines
#	trf_pag:  current page counter
#	trf_lin:  current line counter
#	trf_sav:  list of lines to preserve (save) across page breaks
#	trf_arr:  an array of lines making up a page in progress
#	trf_blk:  the line at which a block of data began which cannot
#		 contain a page break


#	puts stderr "Call trf_place..."

	if {$nl == "+"} {
		incr trf_lin
	}

	if {$y == "."} {
		set y $trf_lin
	} else {
		if {$y > $trf_len} {
#			puts stderr "WARNING, text placed at line $y will force a new page"
		}
		set trf_lin $y
	}

#	puts stderr "  y is really $y"

	if {$hdr != ""} {
		lappend trf_sav $y
		set trf_sav [lrmdups $trf_sav]
		if {$val == "PNO"} {
			set trf_pnf($trf_pnn) $fmt
			set trf_pnx($trf_pnn) $x
			set trf_pny($trf_pnn) $y
			set val $trf_pag
			incr trf_pnn
		}
	} else {
		if {[lsearch $trf_sav $y] >= 0} {
#			puts stderr "  Data $val hdr $hdr would be at $y, $x in a protected line! New page!"
			set y [expr $trf_len + 1]
		}
	}

	if {$y > $trf_len} {
#		puts stderr "  next y ($y) is greater than $trf_len NEW PAGE"
		if {$trf_blk} {
			trf_saveb 
		}
		trf_print
		trf_init
		if {$trf_blk} {
                        trf_restoreb
		}
		set y $trf_lin
#		puts stderr "  new y on new page is $y"
	}

	if {$brk > 0} {
#		puts stderr "  breaking line to $brk chars"
		set sa [strFold $val $brk]
		set fl " [llength $sa]"
#		puts stderr "  produced $fl lines"
	} else {
		set fl ""
		eval set sa \{\{$val\}\}
	}
#
# you have to sanity check y position within the loop as well (sigh)
#
	foreach v $sa {

	if {$hdr == ""} {
	if {[lsearch $trf_sav $y] >= 0} {
#		puts stderr "  Data $val hdr $hdr would be at $y, $x in a protected line! New page!"
		set y [expr $trf_len + 1]
	}
	}
	if {$y > $trf_len} {
#		puts stderr "    next y ($y) is greater than $trf_len NEW PAGE"
		if {$trf_blk} {
			trf_saveb 
		}
		trf_print
		trf_init
		if {$trf_blk} {
                        trf_restoreb
		}
		set y $trf_lin
#		puts stderr "new y on new page is $y"
	}

#	puts stderr "  place value $v"

#	put formatted data in right place in requested line
	set line $trf_arr($y)
	
	set newl1 ""
	if {$x > 0} {
	set newl1 [crange $line 0 [expr $x - 1]]
	}

	set newl2 "[format $fmt $v]"
	set vlen [clength $newl2]

	if {[expr $x + $vlen] > $trf_wid} {
#		puts stderr "WARNING, page $trf_pag line $y, text $newl2 placed at $x exceeds margin"
	}

	set newl3 [crange $line [expr $x + $vlen] end]

	set line "$newl1$newl2$newl3"

	set trf_arr($y) "$line"

	incr y

	}

	set trf_lin [expr $y - 1]
	return "$trf_lin$fl"

}
