[GRASS-dev] problem with r.colors on Mac

Glynn Clements glynn at gclements.plus.com
Tue Apr 17 15:09:19 EDT 2007


Michael Barton wrote:

> >> # here I changed all the above code to use gets and read line by line rather
> >> than create line by line output with split
> >> 
> >>     while {[gets $fh line] >= 0} {
> > 
> > This test will never be true; the preceding "read" will have consumed
> > all available data, leaving none for the "gets".
> 
> On 4/17/07 8:35 AM, "Glynn Clements" <glynn at gclements.plus.com> wrote:
> 
> >>     if {[string length $str] != 0} {
> >>         Gronsole::add_data_tag $path $ci out
> >>     }
> 
> So do I just get rid of this if clause?

No, get rid of the "read" call. E.g. (untested):

proc Gronsole::readout {path ci mark fh} {

	set lines {}

	while {[gets $fh line] >= 0} {
		lappend lines $line
	}

	if {[length $lines] != 0} {
		Gronsole::add_data_tag $path $ci out
	}

	foreach line [lrange $lines 0 [expr [llength $lines] - 2]] {
		Gronsole::output_to_gronsole $path $mark $ci [list cmd$ci cmd$ci-out] "$line\n"
	}
	set last [lindex $lines end]
	if {$last != {}} {
		Gronsole::output_to_gronsole $path $mark $ci [list cmd$ci cmd$ci-out] $last
	}
	$path.text see $mark
}

Although, I'm not entirely sure why it's necessary to omit the newline
from the last entry; maybe that was due to the use of "read". Try:

proc Gronsole::readout {path ci mark fh} {

	set lines {}

	while {[gets $fh line] >= 0} {
		lappend lines $line
	}

	if {[length $lines] != 0} {
		Gronsole::add_data_tag $path $ci out
	}

	foreach line $lines {
		Gronsole::output_to_gronsole $path $mark $ci [list cmd$ci cmd$ci-out] "$line\n"
	}

	$path.text see $mark
}

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list