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

Paul Kelly paul-grass at stjohnspoint.co.uk
Thu Jan 4 11:42:22 EST 2007


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 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? 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.

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.

Paul




More information about the grass-dev mailing list