[GRASS-dev] db.execute: ".execute" suffix missing in man page

Hi,

In Firefox and Lynx browsers the ".execute" part of
"db.execute" is missing above the module description. It
also not there in "man db.execute" output.

Applies to current 6.3 CVS and checkouts few weeks old. In
6.2 it's OK though.

See a copy/paste:

---
NAME

   db - Executes any SQL statement.

KEYWORDS

   database, SQL

SYNOPSIS

   db
   db help
   db [-i] [input=name] [driver=name] [database=name]
[--verbose] [--quiet]
---

Does anybody confirm?

Maciek

Maciej Sieczka wrote:

In Firefox and Lynx browsers the ".execute" part of
"db.execute" is missing above the module description. It
also not there in "man db.execute" output.

G_basename

Does anybody confirm?

Confirm:

  $ db.execute --help
  
  ...
  
  Usage:
   db [-i] [input=name] [driver=name] [database=name] [--verbose]
     [--quiet]

G_parser() does:

  G_basename(tmp_name, "exe");

G_basename() is described thus:

* \fn char * G_basename (char *filename, const char *desired_ext)
*
* \brief Truncates filename to the base part (before the last '.')
* if it matches the extension, otherwise leaves it unchanged.

But it actually only checks if the specified extension is a prefix of
the actual extension rather than a complete match.

Suggested fix (untested):

char * G_basename(char *filename, const char *desired_ext)
{
    /* Find the last . in the filename */
    char *dot = strrchr(filename, '.');

    if (dot && G_strcasecmp(dot + 1, desired_ext) == 0)
       *dot = '\0';

    return filename;
}

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

On Wed, 10 Oct 2007, Glynn Clements wrote:

Maciej Sieczka wrote:

In Firefox and Lynx browsers the ".execute" part of
"db.execute" is missing above the module description. It
also not there in "man db.execute" output.

[...]

G_parser() does:

  G_basename(tmp_name, "exe");

Oops - that was an oversight on my part.

G_basename() is described thus:

* \fn char * G_basename (char *filename, const char *desired_ext)
*
* \brief Truncates filename to the base part (before the last '.')
* if it matches the extension, otherwise leaves it unchanged.

But it actually only checks if the specified extension is a prefix of
the actual extension rather than a complete match.

The reason for that was so that e.g. "tif" can match .tif and .tiff and other usage cases like that. The original usage for G_basename() was checking the output filename for r.out.tiff so it could decide if it should add an extension or not.

Suggested fix (untested):

char * G_basename(char *filename, const char *desired_ext)
{
   /* Find the last . in the filename */
   char *dot = strrchr(filename, '.');

   if (dot && G_strcasecmp(dot + 1, desired_ext) == 0)
      *dot = '\0';

   return filename;
}

That would break the way it is used in r.out.tiff in some circumstances. I'm thinking it might be easier to conditionalise its use in G_parser() and G_set_program_name() on __MINGW32__ as its only purpose there is to strip out the .exe executable extension on Windows?

Maybe there should be two functions though. Or maybe stripping out the .exe is quite simple and it doesn't need to use G_basename()?

If noone else has fixed this yet I'll try and get to it fairly soon.

Paul

Paul Kelly wrote:

>> In Firefox and Lynx browsers the ".execute" part of
>> "db.execute" is missing above the module description. It
>> also not there in "man db.execute" output.
>
[...]
> G_parser() does:
>
> G_basename(tmp_name, "exe");

Oops - that was an oversight on my part.

> G_basename() is described thus:
>
> * \fn char * G_basename (char *filename, const char *desired_ext)
> *
> * \brief Truncates filename to the base part (before the last '.')
> * if it matches the extension, otherwise leaves it unchanged.
>
> But it actually only checks if the specified extension is a prefix of
> the actual extension rather than a complete match.

The reason for that was so that e.g. "tif" can match .tif and .tiff and
other usage cases like that. The original usage for G_basename() was
checking the output filename for r.out.tiff so it could decide if it
should add an extension or not.

> Suggested fix (untested):
>
> char * G_basename(char *filename, const char *desired_ext)
> {
> /* Find the last . in the filename */
> char *dot = strrchr(filename, '.');
>
> if (dot && G_strcasecmp(dot + 1, desired_ext) == 0)
> *dot = '\0';
>
> return filename;
> }

That would break the way it is used in r.out.tiff in some circumstances.
I'm thinking it might be easier to conditionalise its use in G_parser()
and G_set_program_name() on __MINGW32__ as its only purpose there is to
strip out the .exe executable extension on Windows?

Maybe there should be two functions though. Or maybe stripping out the
.exe is quite simple and it doesn't need to use G_basename()?

If noone else has fixed this yet I'll try and get to it fairly soon.

I suggest fixing G_basename() as above; the current behaviour is
counter-intuitive and undesirable in most cases.

r.out.tiff should check for .tif and .tiff separately. This isn't just
a matter of being able to use G_basename() for other purposes.
r.out.tiff shouldn't treat anything other than .tif or .tiff (modulo
case) as a TIFF extension; cf. "area.around.Tifton_GA".

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

On Wed, 24 Oct 2007, Glynn Clements wrote:

[...]

Suggested fix (untested):

char * G_basename(char *filename, const char *desired_ext)
{
   /* Find the last . in the filename */
   char *dot = strrchr(filename, '.');

   if (dot && G_strcasecmp(dot + 1, desired_ext) == 0)
      *dot = '\0';

   return filename;
}

That would break the way it is used in r.out.tiff in some circumstances.
I'm thinking it might be easier to conditionalise its use in G_parser()
and G_set_program_name() on __MINGW32__ as its only purpose there is to
strip out the .exe executable extension on Windows?

Maybe there should be two functions though. Or maybe stripping out the
.exe is quite simple and it doesn't need to use G_basename()?

If noone else has fixed this yet I'll try and get to it fairly soon.

I suggest fixing G_basename() as above; the current behaviour is
counter-intuitive and undesirable in most cases.

r.out.tiff should check for .tif and .tiff separately. This isn't just
a matter of being able to use G_basename() for other purposes.
r.out.tiff shouldn't treat anything other than .tif or .tiff (modulo
case) as a TIFF extension; cf. "area.around.Tifton_GA".

I agree; have committed changes to G_basename() and r.out.tiff accordingly. Hopefully the db.execute problem should be fixed now.

Paul

Paul Kelly wrote:

I agree; have committed changes to G_basename() and r.out.tiff
accordingly. Hopefully the db.execute problem should be fixed now.

Paul

db.execute's manual looks OK now. Thanks.

Maciek