[GRASS5] Mac OS X Tcl fix and Startup Errors

Greetings,

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.

Here's the wrapper:

lsWrap:
     #!/bin/sh

     /bin/ls -1 $* | awk '{print "\"" $0 "\"" }' | sed s/\!/\\\\!/g

I suppose that it could be implemented inline, however I am not familiar enough with Tcl/Tk to make the attempt. It also seems that it's best to have it in one place.

I am also trying to fix these errors:
     Starting GRASS ...
     : 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;"

If I change stdout to stderr, everything looks normal:

     set GISDBASE='/Users/jeshua'; export GISDBASE;

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

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.

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

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?

I am also trying to fix the "console 1 bug" OS X Aqua Tcl/Tk 8.4.x bug, and thought I should get rid of all the errors/warnings first.

Thanks,

Jeshua Lacock __________________________
Programmer/Owner Phone: 760.935.4736
http://OpenOSX.com Fax: 760.935.4845
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

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
[snip]
  
  # Check for tcltk interface
  tcltk)
      eval `$WISH -file $TCLTKGRASSBASE/script/gis_set.tcl`
      
      case $? in
             1)
        # 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
[snip]

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

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

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

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@virgin.net>

On Tuesday, April 8, 2003, at 05:59 AM, Glynn Clements wrote:

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:

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.

The semi-colons appear to be the culprit.

Also. strangely, the line:
    puts stdout "exit"

Generates the message:
    : command not foundtc/Init.sh: exit

And yet, when I type in the shell "exit" <enter> everything works.

Any ideas?

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.

Yes, I was just making sure it was not garbled.

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.

Cool.

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:

[snip]

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.

Thanks.

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.

Hmm, I wonder if /bin/sh is failing to execute somewhere? I will attempt to trace the result.

Thanks again,

Jeshua Lacock __________________________
Programmer/Owner Phone: 760.935.4736
http://OpenOSX.com Fax: 760.935.4845
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_

Jeshua Lacock wrote:

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

The semi-colons appear to be the culprit.

Also. strangely, the line:
    puts stdout "exit"

Generates the message:
    : command not foundtc/Init.sh: exit

And yet, when I type in the shell "exit" <enter> everything works.

Any ideas?

No; you could try playing around with eval, e.g.

  eval `echo "exit"`

etc, but I'm not sure that it will achieve much (except, it may
confirm that the shell is broken).

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