[GRASSLIST:4425] Re: bug fixes for tcltkgrass for GRASS 5.3

Glynn Clements glynn.clements at virgin.net
Tue Sep 28 21:40:17 EDT 2004


Michael Barton wrote:

> Previously these things all worked (except for r.resamp.rst, which is new
> since I finished the menus late last Spring). I am guessing that changes to
> the grass parser modules implemented over the summer have caused some of the
> tcltkgrass modules in 5.3 to fail now.
> 
> To the list in general, it seems that a command with a flag will no longer
> parse correctly in the tcltkgrass modules for 5.3. The odd thing is that
> other arguments (at least one that I tried) do seem to parse OK. In a number
> of cases, the flags were included with the command as a convenience.
> 
> I can add them as user options in the modules affected (I don't remember
> which or how many at the moment), but does anyone have a clue why these are
> not parsing now? The format is:
> 
> interface_build {
>     {s.to.vect -p} 0
>     {Converts a GRASS sites map to a GRASS vector map.}
>     {entry input {Name of input site list:} 0 sites}
>     {entry output {Name of new vector file:} 0 vector}
>     {entry cat {String field in site_list to use in vector file
> (default=1):} 0 ""}
> }
> 
> It seems that the command string in brackets {s.to.vect -p} ought to parse
> OK. Quoting it seems redundant. Any thoughts?

I suspect that something is using "list" instead of "concat", e.g.:

	% set cmd {s.to.vect -p}
	% set arg foo
	% foreach word [list $cmd $arg] {puts $word}
	s.to.vect -p
	foo
	% foreach word [concat $cmd $arg] {puts $word}
	s.to.vect
	-p
	foo

Were there some changes made to deal with arguments which contain
spaces? That could explain it.

In order for commands with arguments in the module description to
work, the command (lindex $description 0) needs to be treated as a
list. But in order for arguments with spaces to work, they must be
treated as a single word.

E.g.:

	% set cmd {s.to.vect -p}
	% set arg {foo bar}
	% foreach word [list $cmd $arg] {puts $word}
	s.to.vect -p
	foo bar
	% foreach word [concat $cmd $arg] {puts $word}
	s.to.vect
	-p
	foo
	bar

The first is wrong, because it doesn't split the command. The second
is wrong because it splits the argument. You need to use concat but
"wrap" the argument:

	% foreach word [concat $cmd [list $arg]] {puts $word}
	s.to.vect
	-p
	foo bar

However, the 5.3 tcltkgrass is so complex that I'm not even going to
try to figure out what needs to be changed where. Also, essentially
the same problem can occur in lots of different ways (e.g. lappend,
append, eval, subst "$foo $bar", etc).

It's an inherent consequence of the fact that, in Tcl, everything is a
string (a list of strings is simultaneously both a string and a list
of strings).

Also, the use of variables whose values are variable names tends to
result in incomprehensible code; unfortunately, the 5.3 version of
tcltkgrass does a lot of that.

-- 
Glynn Clements <glynn.clements at virgin.net>




More information about the grass-user mailing list