[GRASS-dev] r.timestamp script style output wish

hi,

I would like to add a -g flag to r.timestamp for shell script style
output plus another
-n flag for numerical month output (only with -g to avoid timestamp
order confusion):

Original:
  r.timestamp mymap
  26 Jan 2010

Desired:
  r.timestamp -g -n mymap
  day=26
  month=1
  year=2010

The problem is that r.timestamp uses
G__write_timestamp(stdout, &ts);

which is defined as:

lib/gis/timestamp.c
int G__write_timestamp(FILE * fd, const struct TimeStamp *ts)
{
    char buf[1024];

    if (G_format_timestamp(ts, buf) < 0)
        return -1;
    fprintf(fd, "%s\n", buf);
    return 0;
}

Since it prints into stdout and prints directly in the libgis function I have no
idea how to hijack the output in order to apply G_str_replace() for
the month-name
to month-number replacement etc.

How could -g and -n be implemented?

Markus

Markus wrote:

I would like to add a -g flag to r.timestamp for shell
script style output plus another
-n flag for numerical month output (only with -g to avoid
timestamp order confusion):

...

The problem is that r.timestamp uses
G__write_timestamp(stdout, &ts);

...

Since it prints into stdout and prints directly in the
libgis function I have no idea how to hijack the output in
order to apply G_str_replace() for the month-name to
month-number replacement etc.

How could -g and -n be implemented?

add a new
G__write_timestamp2(FILE *, const struct TimeStamp *,
                     int shell_style, int numeric)

then apply booleans at runtime?

Hamish

On Wed, Oct 6, 2010 at 11:43 AM, Hamish <hamish_b@yahoo.com> wrote:

Markus wrote:

I would like to add a -g flag to r.timestamp for shell
script style output plus another
-n flag for numerical month output (only with -g to avoid
timestamp order confusion):

...

The problem is that r.timestamp uses
G__write_timestamp(stdout, &ts);

...

Since it prints into stdout and prints directly in the
libgis function I have no idea how to hijack the output in
order to apply G_str_replace() for the month-name to
month-number replacement etc.

How could -g and -n be implemented?

add a new
G__write_timestamp2(FILE *, const struct TimeStamp *,
int shell_style, int numeric)

then apply booleans at runtime?

Maybe yes but I still would not know how to hijack the output of
G__write_timestamp[2]().

Markus

Markus Neteler wrote:

>> How could -g and -n be implemented?

Hamish:

> add a new
> G__write_timestamp2(FILE *, const struct TimeStamp *,
> int shell_style, int numeric)
>
> then apply booleans at runtime?

Maybe yes but I still would not know how to hijack the
output of G__write_timestamp[2]().

the point is that you wouldn't have to. G__write_timestamp2()
could do the alpha->int internally and render it in the way you
wanted up front.

Hamish