[GRASS-dev] Re: gis.m crashes on zoom to map existing in more than one mapset

Michael Barton michael.barton at asu.edu
Thu Jan 4 15:35:18 EST 2007


Paul


On 1/4/07 9:42 AM, "Paul Kelly" <paul-grass at stjohnspoint.co.uk> wrote:

> Hello Michael
> 
> On Thu, 4 Jan 2007, Michael Barton wrote:
> 
>> On 1/4/07 8:47 AM, "Moritz Lennert" <mlennert at club.worldonline.be> wrote:
>> 
>> Moritz and Paul,
>> 
>> The following construction will trap errors in TclTk, but it doesn't help
>> this particular issue.
>> 
>>    if {![catch {open [concat "|g.region" "-ugp" $args] r} input]} {
>>        while {[gets $input line] >= 0} {
>>            regexp -nocase {^([a-z]+)=(.*)$} $line trash key value
>>            set parts($key) $value
>>        }
>> ....
>> 
>> If there if no error, "catch" returns 0 and the routine goes on.
>> If there is an error, "catch" returns a value >0 and the error message is
>> stored in the variable "input". Input can be printed to the terminal or to a
>> TclTk dialog if desired.
> 
> Try this instead:
>      if {![catch {open [concat "|g.region" "-ugp" $args "|&
> $env(GISBASE)/etc/grocat"] r} input]} {
>          while {[gets $input line] >= 0} {
>              if { [regexp -nocase {^([a-z]+)=(.*)$} $line trash key value] }
>              {
> set parts($key) $value
>              }
>          }

I can confirm that this works. What is grocat??

> 
> I am guessing that "catch" catches errors by seeing if anything is written
> to stderr - if a warning is written to stderr will it incorrectly catch it
> as an error? 

Yes, this is what seems to be happening. The program exits with the warning
printed to the terminal.

> I'm not sure, but merging stderr into stdout with the grocat
> program will stop anything being written to stderr so will stop this. This
> will work on Windows - in fact I wrote it specifically because the
> previous way it was done (see my recent changes to
> lib/gtcltk/gronsole.tcl) was Unix-specific - the grocat trick works on
> Unix and Windows.

OK. If you've tested this on Windows, then it should be OK. I'm just trying
not to do anything that will jeopardize a native Windows build.

> 
> Then within the while loop I've used an if to check the return value of
> regexp - there are only two possible values - 1 if it matches the line and
> 0 if it doesn't. So it won't match the Warning line, will return 0, and
> thus stops you trying to assign non-existent values to key and value.

OK. This works fine too. Thanks. After fixing stuff yesterday, I was
thinking it might be simpler to switch to

set key [string trim [lindex [split $line "="] 0]]

I wonder if this could be made to test in a similar way?

Thanks for your help.
Michael



> 
> Paul
> 

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics and Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton 




More information about the grass-dev mailing list