<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, &quot;Glynn Clements&quot; &lt;glynn@gclements.plus.com&gt; wrote:<BR>
<BR>
<FONT COLOR="#008000">&gt;&gt; If read is a problem, what is an alternative?<BR>
</FONT><FONT COLOR="#0000FF">&gt; <BR>
&gt; gets.<BR>
&gt; <BR>
&gt; Gronsole::output_to_gronsole is written on the assumption that it will<BR>
&gt; get complete lines. Gronsole::readout tries to do this, but fails to<BR>
&gt; allow for the fact that &quot;read&quot; may return arbitrary chunks of data<BR>
&gt; (i.e. partial lines).<BR>
&gt; <BR>
&gt; If the stream is in non-blocking mode, gets will return an empty<BR>
&gt; string if a complete line isn't available. The fblocked function can<BR>
&gt; be used to distinguish this from the case where the process wrote a<BR>
&gt; blank line. Also, after this case occurs, another readable event won't<BR>
&gt; be generated for the stream until a complete line is available.<BR>
&gt; <BR>
</FONT><FONT COLOR="#008000">&gt;&gt; I don't understand the<BR>
&gt;&gt; gronsole code very well (didn't write it), but I might be able to fix a<BR>
&gt;&gt; specific issue like this.<BR>
</FONT><FONT COLOR="#0000FF">&gt; <BR>
&gt; 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 &#8211;e. It also seems to crash more often with other commands too. I&#8217;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>
&nbsp;&nbsp;&nbsp;&nbsp;set str [read $fh]<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if {[string length $str] != 0} {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gronsole::add_data_tag $path $ci out<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;set lines [split $str &quot;\n&quot;]<BR>
&nbsp;&nbsp;&nbsp;&nbsp;foreach line [lrange $lines 0 [expr [llength $lines] - 2]] {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gronsole::output_to_gronsole $path $mark $ci [list cmd$ci cmd$ci-out] &quot;$line\n&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;set last [lindex $lines end]<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if {$last != {}} {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gronsole::output_to_gronsole $path $mark $ci [list cmd$ci cmd$ci-out] $last<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;$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>
&nbsp;&nbsp;&nbsp;&nbsp;set str [read $fh]<BR>
&nbsp;&nbsp;&nbsp;&nbsp;if {[string length $str] != 0} {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gronsole::add_data_tag $path $ci out<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;<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>
&nbsp;&nbsp;&nbsp;&nbsp;while {[gets $fh line] &gt;= 0} {<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gronsole::output_to_gronsole $path $mark $ci [list cmd$ci cmd$ci-out] &quot;$line\n&quot;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;}<BR>
&nbsp;&nbsp;&nbsp;&nbsp;$path.text see $mark<BR>
}<BR>
<BR>
<BR>
Michael<BR>
__________________________________________<BR>
Michael Barton, Professor of Anthropology<BR>
School of Human Evolution &amp; Social Change &nbsp;&nbsp;&nbsp;<BR>
Center for Social Dynamics &amp; 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>