<HTML>
<HEAD>
<TITLE>Re: [GRASS-dev] problem with r.colors on Mac</TITLE>
</HEAD>
<BODY>
<FONT FACE="Verdana, Helvetica, Arial"><SPAN STYLE='font-size:12.0px'><BR>
<BR>
<BR>
On 4/11/07 3:42 AM, "Glynn Clements" <glynn@gclements.plus.com> wrote:<BR>
<BR>
<FONT COLOR="#008000">>> If read is a problem, what is an alternative?<BR>
</FONT><FONT COLOR="#0000FF">> <BR>
> gets.<BR>
> <BR>
> Gronsole::output_to_gronsole is written on the assumption that it will<BR>
> get complete lines. Gronsole::readout tries to do this, but fails to<BR>
> allow for the fact that "read" may return arbitrary chunks of data<BR>
> (i.e. partial lines).<BR>
> <BR>
> If the stream is in non-blocking mode, gets will return an empty<BR>
> string if a complete line isn't available. The fblocked function can<BR>
> be used to distinguish this from the case where the process wrote a<BR>
> blank line. Also, after this case occurs, another readable event won't<BR>
> be generated for the stream until a complete line is available.<BR>
> <BR>
</FONT><FONT COLOR="#008000">>> I don't understand the<BR>
>> gronsole code very well (didn't write it), but I might be able to fix a<BR>
>> specific issue like this.<BR>
</FONT><FONT COLOR="#0000FF">> <BR>
> Gronsole::readout is the relevant function.<BR>
</FONT><BR>
Glynn,<BR>
<BR>
Now that I have cvs access again and could update, I tried to fix this. I changed Gronsole::readout as indicated below. Gronsole seems to work OK with the change, but the TckTk GUI still crashes when I run r.colors –e. It also seems to crash more often with other commands too. I’m guessing its the same cause. The change below does not seem to fix it, but I want to know if this is what you had in mind.<BR>
<BR>
##### ORIGINAL CODE #####<BR>
proc Gronsole::readout {path ci mark fh} {<BR>
set str [read $fh]<BR>
if {[string length $str] != 0} {<BR>
Gronsole::add_data_tag $path $ci out<BR>
}<BR>
set lines [split $str "\n"]<BR>
foreach line [lrange $lines 0 [expr [llength $lines] - 2]] {<BR>
Gronsole::output_to_gronsole $path $mark $ci [list cmd$ci cmd$ci-out] "$line\n"<BR>
}<BR>
set last [lindex $lines end]<BR>
if {$last != {}} {<BR>
Gronsole::output_to_gronsole $path $mark $ci [list cmd$ci cmd$ci-out] $last<BR>
}<BR>
$path.text see $mark<BR>
}<BR>
<BR>
##### REVISED CODE #####<BR>
proc Gronsole::readout {path ci mark fh} {<BR>
<BR>
# I left this first part in because it seems to simply make an output locale if there is something in $fh<BR>
<BR>
set str [read $fh]<BR>
if {[string length $str] != 0} {<BR>
Gronsole::add_data_tag $path $ci out<BR>
}<BR>
<BR>
# here I changed all the above code to use gets and read line by line rather than create line by line output with split<BR>
<BR>
while {[gets $fh line] >= 0} {<BR>
Gronsole::output_to_gronsole $path $mark $ci [list cmd$ci cmd$ci-out] "$line\n"<BR>
}<BR>
$path.text see $mark<BR>
}<BR>
<BR>
<BR>
Michael<BR>
__________________________________________<BR>
Michael Barton, Professor of Anthropology<BR>
School of Human Evolution & Social Change <BR>
Center for Social Dynamics & Complexity<BR>
Arizona State University<BR>
<BR>
phone: 480-965-6213<BR>
fax: 480-965-7671<BR>
www: <a href="http://www.public.asu.edu/~cmbarton">http://www.public.asu.edu/~cmbarton</a> <BR>
<BR>
</SPAN></FONT>
</BODY>
</HTML>