[GRASS5] Mac OS X Tcl fix and Startup Errors

Glynn Clements glynn.clements at virgin.net
Tue Apr 8 08:59:20 EDT 2003

Jeshua Lacock wrote:

> Mac OS X allows the use of special/reserved characters in file names 
> such as the exclamation mark ("!") and the space character (" ").
> This was causing gis_set.tcl and other Tcl scripts to choke using the 
> native Aqua Tcl/Tk interface when encountering a file with illegal unix 
> characters.
> It turns out the most elegant solution I could come up with was to 
> create a wrapper for the "ls" command to escape the exclamation marks 
> and to wrap the filename in quotes to compensate for spaces and other 
> special characters.
> The wrapper is a shell script using awk and sed, and then I simply 
> changed occurrences of "ls -a" with "lsWrap -a" and so on. I can supply 
> patches if anyone is interested.

A better fix would be to just not use "ls", but to implement the
functionality in Tcl, using the "glob" command.

> I am also trying to fix these errors:
>      Starting GRASS ...
>      : command not foundtc/Init.sh:
>      : command not foundtc/Init.sh:
>      : command not foundtc/Init.sh:
> These errors are being caused by:
>      puts stdout "GISDBASE='$database'; export GISDBASE;"
>      puts stdout "LOCATION_NAME='$location'; export LOCATION_NAME;"
>      puts stdout "MAPSET='$mapset'; export MAPSET;"

Do you have any idea how is this code causing the above errors? I'm
not doubting that it is, but I can't see any possible mechanism.

> If I change stdout to stderr, everything looks normal:
>      set GISDBASE='/Users/jeshua'; export GISDBASE;

The strings aren't meant to be displayed on the terminal; they're
meant to be interpreted by Init.sh. Using stderr won't work.

> I don't get any errors when I remove the export part such as:
>      puts stdout "GISDBASE='$database'"

The export commands are unnecessary. So are the settings for GISDBASE
and MAPSET; only LOCATION_NAME (and the OLD_* variables a bit lower
down) are actually used by Init.sh.

> If I include the semicolon, I get the error:
>      : command not foundtc/Init.sh:
> I suppose this is a bug with the Aqua port of Tcl/Tk 8.4.2.

Or with the Mac's /bin/sh. In any case, you can remove the semicolon
and the export statement.

> What is the grass tcltk script trying to accomplish here? Just setting 
> the environment variables and exporting them?

It's returning the data back to the Init.sh script:

    case "$GRASS_GUI" in
	# Check for text interface
	# Check for tcltk interface
	    eval `$WISH -file $TCLTKGRASSBASE/script/gis_set.tcl`
	    case $? in
		    # The gis_set.tcl script printed an error message so wait
		    # for user to read it
		    echo "Error in Tcl/Tk startup. If necessary, please"
		    echo "report this error to the Grass developers."
		    echo "Switching to text mode now."
		    echo "Hit RETURN to continue..."
		    read ans

		    # These checks should not be necessary with real init stuff
		    if [ "$LOCATION_NAME" = "##NONE##" ] ; then
    	    		if [ $? != 0 ]; then
    	    		    echo "GISDBASE: $OLD_DB" > $GISRC
    	    		    echo "LOCATION_NAME: $OLD_LOC" >> $GISRC
    	    		    echo "MAPSET: $OLD_MAP" >> $GISRC

		    if [ "$LOCATION_NAME" = "##ERROR##" ] ; then
    	    		echo "The selected location is not a valid GRASS location"

		    echo "ERROR: Invalid return code from gis_set.tcl."
		    echo "Please advise GRASS developers of this error."

gis_set.tcl is meant to write some Bourne shell code to stdout, which
Init.sh then evaluates via a combination of backquotes ( `...` ) and
the "eval" command. Backquotes only capture stdout, not stderr.

> Also I am getting:
>      ERROR: Invalid return code from gis_set.tcl.
>      Please advise GRASS developers of this error.
>      Welcome to GRASS 5.0.1 (January 2003)
> The 'gis_set' result is 127. Everything seems to work fine, do you 
> think the error is anything to be concerned about?

Maybe; anything other than zero normally indicates some type of error. 
Init.sh should probably treat everything other than zero as an error
(i.e. use text mode instead; it certainly shouldn't just carry on
regardless). Of course, this would force you to fix whatever is
causing gis_set.tcl to return a non-zero exit code.

BTW, programs should avoid using code 127, as this is what system()
returns if it fails to execute /bin/sh; normally, system() returns the
program's exit code.

Glynn Clements <glynn.clements at virgin.net>

More information about the grass-dev mailing list