[GRASS-dev] Re: [GRASS-SVN] r46717 - grass/branches/releasebranch_6_4/scripts/v.build.all

On Wed, Jun 15, 2011 at 4:53 PM, <svn_grass@osgeo.org> wrote:

Author: mmetz
Date: 2011-06-15 07:53:21 -0700 (Wed, 15 Jun 2011)
New Revision: 46717

Modified:
grass/branches/releasebranch_6_4/scripts/v.build.all/v.build.all
Log:
message is now a required parameter for g.message

Modified: grass/branches/releasebranch_6_4/scripts/v.build.all/v.build.all

--- grass/branches/releasebranch_6_4/scripts/v.build.all/v.build.all 2011-06-15 14:13:34 UTC (rev 46716)
+++ grass/branches/releasebranch_6_4/scripts/v.build.all/v.build.all 2011-06-15 14:53:21 UTC (rev 46717)
@@ -38,7 +38,7 @@
do
g.message "Build topology for vector '${VECT}@${MAPSET}'"
CMD="v.build map=${VECT}@${MAPSET}"
- g.message "$CMD"
+ g.message message="$CMD"
$CMD
done

... is this a needed change?

cd scripts/
grep g.message */* | grep -v '=' | wc -l
726

Most are without this parameter...

Just surprised :slight_smile:
Markus

MMetz:

> CMD="v.build map=${VECT}@${MAPSET}"
> - g.message "$CMD"
> + g.message message="$CMD"
> $CMD
> done

MNeteler:

... is this a needed change?

...

Most are without this parameter...

Needed in this case because the string contains a '=', which
confuses the parser.

Hamish

ps- those curly brackets do nothing..

On Tue, Jun 28, 2011 at 1:05 AM, Hamish <hamish_b@yahoo.com> wrote:

MMetz:

> CMD="v.build map=${VECT}@${MAPSET}"
> - g.message "$CMD"
> + g.message message="$CMD"
> $CMD
> done

MNeteler:

... is this a needed change?

...

Most are without this parameter...

Needed in this case because the string contains a '=', which
confuses the parser.

.. and resulted in a fatal error

Hamish

ps- those curly brackets do nothing..

also no harm

Markus M

Hamish wrote:

> > CMD="v.build map=${VECT}@${MAPSET}"
> > - g.message "$CMD"
> > + g.message message="$CMD"
> > $CMD
> > done
MNeteler:
> ... is this a needed change?
...
> Most are without this parameter...

Needed in this case because the string contains a '=', which
confuses the parser.

That should really be fixed in the parser. Even in 6.x, an option name
cannot contain a space.

In 6.x, the test for whether an argument is an option finds the first
'=' in the string and checks that the immediately preceding character
is alphanumeric.

  static int is_option(const char *string)
  {
      const char *p = strchr(string, '=');
  
      if (!p)
    return 0;
      if (p == string)
    return 0;
      p--;
      if (!strchr("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", *p))
    return 0;
  
      return 1;
  }

In 7.0, the test uses strspn() to find the length of the prefix
consisting entirely of (lower-case) alphanumeric characters and
underscores, then checks that the following character is an '=' and
that the prefix doesn't begin or end with an underscore:

  static int is_option(const char *string)
  {
      int n = strspn(string, "abcdefghijklmnopqrstuvwxyz0123456789_");
  
      return n > 0 && string[n] == '=' && string[0] != '_' && string[n-1] != '_';
  }

It would be simple to back-port the 7.0 version to 6.x. Compatibility
requires adding the upper-case characters, which are allowed in option
names in 6.x (e.g. r.terraflow's STREAM_DIR= option). Technically, the
check for a leading underscore should be removed, but I'm not sure
that actually matters.

--
Glynn Clements <glynn@gclements.plus.com>

> > > CMD="v.build map=${VECT}@${MAPSET}"
> > > - g.message "$CMD"
> > > + g.message message="$CMD"

Hamish:

> Needed in this case because the string contains a '=',
> which confuses the parser.

Glynn:

That should really be fixed in the parser. Even in 6.x, an
option name cannot contain a space.

it's more general than that, e.g. this would need the option=
to be specified:
   g.message message="minimum=[$min]"

as the short-cut version will fail:
   g.message "minimum=[$min]"

so in those cases just don't use the short-cut.
not a big problem & not really the parser's fault.

Hamish

Hamish wrote:

> > > > CMD="v.build map=${VECT}@${MAPSET}"
> > > > - g.message "$CMD"
> > > > + g.message message="$CMD"
Hamish:
> > Needed in this case because the string contains a '=',
> > which confuses the parser.
Glynn:
> That should really be fixed in the parser. Even in 6.x, an
> option name cannot contain a space.

it's more general than that, e.g. this would need the option=
to be specified:
   g.message message="minimum=[$min]"

as the short-cut version will fail:
   g.message "minimum=[$min]"

That's unavoidable. If an option value begins with a sequence of
alphanumerics followed immediately by an "=", the option name must be
given.

Similarly, if the option value can be arbitrary text, the option name
must be given both to avoid this issue and to correctly handle the
case where the value starts with a dash.

But none of this changes the fact that the parser failing on e.g.

  g.message "v.build map=..."

is a bug, caused by the option=value test using a crude heuristic
(only checking the character immediately prior to the first "="), when
a correct test would actually require less code.

In the above case, the first (and only) argument cannot possibly be an
option=value argument due to the space in the portion before the "=".

--
Glynn Clements <glynn@gclements.plus.com>