[GRASS5] White spaces support

Hi,

I have commited some changes to CVS to support white space
to some extend.

GRASS:/tmp/grass data > g.gisenv
GISDBASE=/tmp/grass data
LOCATION_NAME=rmapcalcUTM
MAPSET=PERMANENT
MONITOR=x0
GRASS_GUI=text

GRASS:/tmp/grass data > pwd
/tmp/grass data
GRASS:/tmp/grass data > l
total 4
drwxr-xr-x 3 neteler ssi 4096 Feb 27 16:12 rmapcalcUTM
GRASS:/tmp/grass data >

It's possible to start GRASS now with white spaces.

Hope that it doesn't break anything,
but the changes are just variable quoting in the start shell
scripts.

Markus

On Thu, Feb 27, 2003 at 04:26:31PM +0100, Markus Neteler wrote:

Hi,

I have commited some changes to CVS to support white space
to some extend.

GRASS:/tmp/grass data > g.gisenv
GISDBASE=/tmp/grass data
LOCATION_NAME=rmapcalcUTM
MAPSET=PERMANENT
MONITOR=x0
GRASS_GUI=text

GRASS:/tmp/grass data > pwd
/tmp/grass data
GRASS:/tmp/grass data > l
total 4
drwxr-xr-x 3 neteler ssi 4096 Feb 27 16:12 rmapcalcUTM
GRASS:/tmp/grass data >

It's possible to start GRASS now with white spaces.

A followup: Further changes to the startup scripts
are committed. Now also

grass5 "grass data/rmapcalcUTM/PERMANENT/"
             
works.
This update was a bit more tricky. I have changed:
src/general/init/grass.src
src/general/init/init.sh

and tried hopefully most possible combinations.

TODO:
- Missing (and left to a tcl expert) is an update of
  src/tcltkgrass/main/gis_set.tcl

  to fix white space problem when starting
  grass5 -tcltk
  in a directory, where subdirectory name(s) contain white space.
- fix for g.list
- maybe other modules.

Markus

Markus Neteler wrote:

I have commited some changes to CVS to support white space
to some extend.

GRASS:/tmp/grass data > g.gisenv
GISDBASE=/tmp/grass data
LOCATION_NAME=rmapcalcUTM
MAPSET=PERMANENT
MONITOR=x0
GRASS_GUI=text

GRASS:/tmp/grass data > pwd
/tmp/grass data
GRASS:/tmp/grass data > l
total 4
drwxr-xr-x 3 neteler ssi 4096 Feb 27 16:12 rmapcalcUTM
GRASS:/tmp/grass data >

It's possible to start GRASS now with white spaces.

But is it possible to use it? If it isn't, it might be better if GRASS
simply refused to start.

Also, in most of the cases where users have had problems due to
whitespace, the problem has been due to their home directory rather
than GISDBASE. This is arguably a more serious problem, as the user
can choose where to put GISDBASE, but they don't necessarily get to
choose their home directory.

Hope that it doesn't break anything,
but the changes are just variable quoting in the start shell
scripts.

I suspect that many shell[1] scripts will be broken for similar
reasons. Similarly for anything which passes to system() or popen()
any filenames which are within GISDBASE.

For system() etc, use single quotes, e.g. change:

  sprintf(buff, "command %s", filename); system(buff);
to:
  sprintf(buff, "command '%s'", filename); system(buff);

This should handle any filename except one which contains a single
quote character (which is pretty unlikely). Ultimately, use of
system() should be eliminated.

[1] Tcl/Tk mostly[2] avoids the problem, as it performs tokenisation
(splitting the string into words) before it expands variables; when a
variable is expanded to its value, the result remains a single token
even if it contains whitespace.

[2] However, using a variable within a double-quoted string which is
subsequently tokenised (e.g. eval "...", open "|...") will have the
same problem.

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

On Thu, Feb 27, 2003 at 08:39:15PM +0000, Glynn Clements wrote:

Markus Neteler wrote:

> I have commited some changes to CVS to support white space
> to some extend.
>
> GRASS:/tmp/grass data > g.gisenv
> GISDBASE=/tmp/grass data
> LOCATION_NAME=rmapcalcUTM
> MAPSET=PERMANENT
> MONITOR=x0
> GRASS_GUI=text
>
> GRASS:/tmp/grass data > pwd
> /tmp/grass data
> GRASS:/tmp/grass data > l
> total 4
> drwxr-xr-x 3 neteler ssi 4096 Feb 27 16:12 rmapcalcUTM
> GRASS:/tmp/grass data >
>
> It's possible to start GRASS now with white spaces.

But is it possible to use it? If it isn't, it might be better if GRASS
simply refused to start.

I tried some modules which worked well (except g.list).
Only if we try that we can find out what's missing.

Also, in most of the cases where users have had problems due to
whitespace, the problem has been due to their home directory rather
than GISDBASE. This is arguably a more serious problem, as the user
can choose where to put GISDBASE, but they don't necessarily get to
choose their home directory.

Right. Perhaps someone with Cygwin installed could try it again
and report where it fails (if).

> Hope that it doesn't break anything,
> but the changes are just variable quoting in the start shell
> scripts.

I suspect that many shell[1] scripts will be broken for similar
reasons. Similarly for anything which passes to system() or popen()
any filenames which are within GISDBASE.

For system() etc, use single quotes, e.g. change:

  sprintf(buff, "command %s", filename); system(buff);
to:
  sprintf(buff, "command '%s'", filename); system(buff);

Ok.

This should handle any filename except one which contains a single
quote character (which is pretty unlikely). Ultimately, use of
system() should be eliminated.

Yes. We could issue that for 5.1, while migrating code into the 5.1
repository.
There are maybe 5 system calls in 5.1 currently.
Recommendations are welcome.

[1] Tcl/Tk mostly[2] avoids the problem, as it performs tokenisation
(splitting the string into words) before it expands variables; when a
variable is expanded to its value, the result remains a single token
even if it contains whitespace.

[2] However, using a variable within a double-quoted string which is
subsequently tokenised (e.g. eval "...", open "|...") will have the
same problem.

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

This was just a first step (a favor for the MS-Win world).

Markus

On Thu, Feb 27, 2003 at 08:39:15PM +0000, Glynn Clements wrote:
[...]

Also, in most of the cases where users have had problems due to
whitespace, the problem has been due to their home directory rather
than GISDBASE. This is arguably a more serious problem, as the user
can choose where to put GISDBASE, but they don't necessarily get to
choose their home directory.

Now I have tried with spaces in the /home/user dir/ and fixed
the lister and r.info. The main problem, as you stated earlier,
are all the [G_]system() calls.

g.list works now, d.mon as well (also d.rast etc).

Any Windows tester may update again and try.

Markus