[GRASS-dev] fprintf in raster modules converted to G_message

Hallo,
after some time, I hope, I (with help of Soeren and others) managed to
convert (hopefuly) all fprintf(stderr functions to G_message, G_warning
and G_fatal_error

Most of the messages were also prepared for localisation, using _()
macro.

Actually, there are few modules, which are a bit complicated and I'm not
able to find or distinguish between module outputs and module messages
(e.g. new r.li modules).
And sorry, my C-knowledge are poor and my C++-knowledge are sub-zero -
r.terraflow is one big unknown. If anybody could fix it, would be cool.

So, please test the r.* modules, check their verbosity level or just try
to think, if some message is really necessary or if it could be removed.

Next step could be update of vlib, and all v.* modules so that they
react on --v/--q flags.

I would also like to grep -r -i "not found" * and replace it for
standard message (maybe defined in gis.h?), that "File not found".

Thanks for your testing, hints and help. I hope, no module is broken
now.

Jachym
--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub
-----------------------------------------
OFFICE:
Department of Geoinformation Technologies
Zemedelska 3
613 00, Brno
Czech Republick
e-mail: xcepicky@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

Hi,

last night I was cleaning up GRASS translation and found GRASS error
messages very inconsistent.
I.e. "Map not found" can be as "[%s] - map not found", "Map '%s' not
found", "Map <%s> not found", "Map <%s@%s> not found" etc.
It would be realy nice to set up some common error messages for usage
in code like:
G_err_rnf(map,mapset) -> "Raster map <%s@%s> was not found." etc. for
most common error messages like "Raster not found", "Vector not
found", "Could not write to raster" etc.
It would make translators life more easy and improve usability - one
type of error, one message in all places for that error.

Just my 0.002 cents (equals 0.002 dollars by Verizon)
Maris.

2006/12/7, Jachym Cepicky <jachym.cepicky@centrum.cz>:

I would also like to grep -r -i "not found" * and replace it for
standard message (maybe defined in gis.h?), that "File not found".

Thanks for your testing, hints and help. I hope, no module is broken
now.

Jachym
--
Jachym Cepicky

On Sat, 2006-12-09 at 17:11 +0200, Maris Nartiss wrote:

Hi,

last night I was cleaning up GRASS translation and found GRASS error
messages very inconsistent.
I.e. "Map not found" can be as "[%s] - map not found", "Map '%s' not
found", "Map <%s> not found", "Map <%s@%s> not found" etc.
It would be realy nice to set up some common error messages for usage
in code like:
G_err_rnf(map,mapset) -> "Raster map <%s@%s> was not found." etc. for
most common error messages like "Raster not found", "Vector not
found", "Could not write to raster" etc.
It would make translators life more easy and improve usability - one
type of error, one message in all places for that error.

I've thought about this, too, but have other priorities. :frowning:

The best idea I can come up with is a sparse series of macros for the
most common messages:

#define MSG_RASTER_OPEN_FILE "Unable to find raster [%s]"
#define MSG_RASTER_OPEN_FILE_MAPSET "Unable to find raster <%s@%s>"
#define MSG_RASTER_WRITE_FILE "Unable to write to raster [%s]"
...

This is the madness to my method:
MSG -> to be used with messaging functions (G_warning()/G_fatal_error())
RASTER -> operating on
OPEN -> operation
WRITE -> another operation
FILE -> argument
MAPSET -> argument

Everything after the operation are arguments for "easy" recognition of
what to pass in.

Then use the message functions:
G_fatal_error (MSG_RASTER_OPEN_FILE, raster_map);

Okay, we now have a standard set of messages, but now locale macros need
to be dealt with. There's a few ways to deal with it, but none of them
seem trivial to me.

I can see this quickly becoming unwieldy, too. Others may have better
ideas.

Just my 0.002 cents (equals 0.002 dollars by Verizon)
Maris.

Apparently, 5th grade math isn't a requirement for management. :wink:

--
Brad Douglas <rez touchofmadness com> KB8UYR/6
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785

Maris Nartiss wrote:

last night I was cleaning up GRASS translation and found GRASS error
messages very inconsistent.

In the past when adding i18n macros to modules I have used this method:

#search for messages already in use:
grass-src$ cd raster
raster$ grep -rI -A5 G_find_cell2 * | grep fatal

this gives a list of messages already used for that function (here
G_find_cell2()), then I just reuse the nicest message from that list
(prefer "raster map" to "cell file", <%s> brackets around map names,
square brackets around values (invalid color [%s]), etc).

A centralized list would be a nice idea, but I would modify Brad's macro
names,

-MSG_*
+ERR_MSG_*
+WRN_MSG_*

(and formalize usage of <> vs , etc)

Brad:

Okay, we now have a standard set of messages, but now locale macros
need to be dealt with. There's a few ways to deal with it, but none
of them seem trivial to me.

#define ERRMSG_RASTER_OPEN_FILE _("Unable to find raster map <%s>")
#define ERRMSG_RASTER_OPEN_FILE_MAPSET _("Unable to find raster map <%s@%s>")
#define ERRMSG_RASTER_WRITE_FILE _("Unable to write to raster map <%s>")
...

?
but these should probably live in a .h file, and would #include <glocale.h>
at the top of that enough to get them translated at run time? (I assume not?)

Hamish

Maris Nartiss wrote:

last night I was cleaning up GRASS translation and found GRASS error
messages very inconsistent.

another point re. rationalized error messages. Sometimes a module uses
the same fn call for two different maps, and the error messages are
slightly different (e.g. "<%s> base map not found" and "<%s> cover map
not found"). In that case it is best to keep the existing (cleaned)
error messages. Similar to the use of G_define_option() versus
G_define_standard_option().

[but slightly different, with G_define_standard_option() you can follow
it with e.g. a single change, e.g. opt->description="text"]

Hamish

hallo,

I greped-out list of "not found" messages used in grass raster modules

grep -r -i "not found" */*.c |grep \"| sed "s/.*\"\(.*\)\".*/\1/g"

Basicly, there are following slightly different messages:

messages with mostly with G_program_name(), some_map->answer
-----------------------------------------------------------
    %s: %s - raster map not found
    %s: <%s> raster file not found
    cell file [%s] not found
    vector map <%s> not found
    %s: <%s> not found
    %s: <%s> reference map not found
    %s: <%s> cellfile not found
    ...

messages with only some_map->answer
-----------------------------------
    %s - map not found
    %s - map not found
    <%s> raster file not found
    Input file [%s] not found.
    File not found: %s
    Terrain raster map <%s> not found!
    Raster map [%s] not found
    %s: base raster map not found
    %s: cover raster map not found
    Raster map or group [%s] not found
    Cell file [%s] not found\n
    Raster map [%s] not found
    ...

messages with special meaing of raster/vector map
-------------------------------------------------
    3dview file <%s> not found
    Old 3dview file. Region not found in <%s> in <%s>
    elevin cell file <%s> not found
    aspin cell file <%s> not found
    slopein cell file <%s> not found
    linkein cell file <%s> not found
    albedo cell file <%s> not found
    latin cell file <%s> not found
    coefbh cell file <%s> not found
    coefdh cell file <%s> not found
    Raster file [%s] not found
    contour cell file [%s] not found\n
    ...

My suggestion is:

Index: include/glocale.h

RCS file: /grassrepository/grass6/include/glocale.h,v
retrieving revision 2.2
diff -u -r2.2 glocale.h
--- include/glocale.h 26 Nov 2006 21:32:36 -0000 2.2
+++ include/glocale.h 13 Dec 2006 18:51:56 -0000
@@ -1,6 +1,11 @@
#ifndef GRASS_GLOCALE_H
#define GRASS_GLOCALE_H

+#define ERRMSG_RASTER_OPEN_FILE _("Unable to find raster map <%s>")
+#define ERRMSG_VECTOR_OPEN_FILE _("Unable to find vector map <%s>")
+#define ERRMSG_ASCII_OPEN_FILE _("Unable to find ASCII file <%s>")
+#define ERRMSG_OTHER_OPEN_FILE _("Unable to find file <%s>")
+
#include <grass/config.h>

extern char * G_gettext(const char *, const char *);
@@ -11,6 +16,7 @@
#else
#define _(str) (str)
#endif
+

#endif

There could come other messages during the time, but this four ERRMSG could cover all
"not found" messages listed above.

What do you think?

Thanks

Jachym

On Mon, Dec 11, 2006 at 04:41:26PM +1300, Hamish wrote:

Maris Nartiss wrote:
> last night I was cleaning up GRASS translation and found GRASS error
> messages very inconsistent.

In the past when adding i18n macros to modules I have used this method:

#search for messages already in use:
grass-src$ cd raster
raster$ grep -rI -A5 G_find_cell2 * | grep fatal

this gives a list of messages already used for that function (here
G_find_cell2()), then I just reuse the nicest message from that list
(prefer "raster map" to "cell file", <%s> brackets around map names,
square brackets around values (invalid color [%s]), etc).

A centralized list would be a nice idea, but I would modify Brad's macro
names,

-MSG_*
+ERR_MSG_*
+WRN_MSG_*

(and formalize usage of <> vs , etc)

Brad:
> Okay, we now have a standard set of messages, but now locale macros
> need to be dealt with. There's a few ways to deal with it, but none
> of them seem trivial to me.

#define ERRMSG_RASTER_OPEN_FILE _("Unable to find raster map <%s>")
#define ERRMSG_RASTER_OPEN_FILE_MAPSET _("Unable to find raster map <%s@%s>")
#define ERRMSG_RASTER_WRITE_FILE _("Unable to write to raster map <%s>")
...

?
but these should probably live in a .h file, and would #include <glocale.h>
at the top of that enough to get them translated at run time? (I assume not?)

Hamish

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub
-----------------------------------------
OFFICE:
Department of Geoinformation Technologies
Zemedelska 3
613 00, Brno
Czech Republick
e-mail: xcepicky@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

On Mon, 2006-12-11 at 16:41 +1300, Hamish wrote:

Maris Nartiss wrote:
> last night I was cleaning up GRASS translation and found GRASS error
> messages very inconsistent.

In the past when adding i18n macros to modules I have used this method:

#search for messages already in use:
grass-src$ cd raster
raster$ grep -rI -A5 G_find_cell2 * | grep fatal

this gives a list of messages already used for that function (here
G_find_cell2()), then I just reuse the nicest message from that list
(prefer "raster map" to "cell file", <%s> brackets around map names,
square brackets around values (invalid color [%s]), etc).

A centralized list would be a nice idea, but I would modify Brad's macro
names,

-MSG_*
+ERR_MSG_*
+WRN_MSG_*

(and formalize usage of <> vs , etc)

Brad:
> Okay, we now have a standard set of messages, but now locale macros
> need to be dealt with. There's a few ways to deal with it, but none
> of them seem trivial to me.

#define ERRMSG_RASTER_OPEN_FILE _("Unable to find raster map <%s>")
#define ERRMSG_RASTER_OPEN_FILE_MAPSET _("Unable to find raster map <%s@%s>")
#define ERRMSG_RASTER_WRITE_FILE _("Unable to write to raster map <%s>")
...

?
but these should probably live in a .h file, and would #include <glocale.h>
at the top of that enough to get them translated at run time? (I assume not?)

What I meant by "not exactly trivial" is that the above will *require*
locale support. Two conditional copies of the same thing to accommodate
with and without locale is ugly...even worse is definitions in two
separate files (glocale.h and another non-locale header).

I have no elegant answer.

--
Brad Douglas <rez touchofmadness com> KB8UYR/6
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785

Jachym Cepicky wrote:

My suggestion is:

Index: include/glocale.h

RCS file: /grassrepository/grass6/include/glocale.h,v
retrieving revision 2.2
diff -u -r2.2 glocale.h
--- include/glocale.h 26 Nov 2006 21:32:36 -0000 2.2
+++ include/glocale.h 13 Dec 2006 18:51:56 -0000
@@ -1,6 +1,11 @@
#ifndef GRASS_GLOCALE_H
#define GRASS_GLOCALE_H

+#define ERRMSG_RASTER_OPEN_FILE _("Unable to find raster map <%s>")
+#define ERRMSG_VECTOR_OPEN_FILE _("Unable to find vector map <%s>")
+#define ERRMSG_ASCII_OPEN_FILE _("Unable to find ASCII file <%s>")
+#define ERRMSG_OTHER_OPEN_FILE _("Unable to find file <%s>")

Will that hardcode whatever language GRASS was built with as the
only translation it can use for those messages? Or will the _(macros)
survive the build process and be processed normally at run-time?

Hamish

Hamish wrote:

> My suggestion is:
>
> Index: include/glocale.h
> ===================================================================
> RCS file: /grassrepository/grass6/include/glocale.h,v
> retrieving revision 2.2
> diff -u -r2.2 glocale.h
> --- include/glocale.h 26 Nov 2006 21:32:36 -0000 2.2
> +++ include/glocale.h 13 Dec 2006 18:51:56 -0000
> @@ -1,6 +1,11 @@
> #ifndef GRASS_GLOCALE_H
> #define GRASS_GLOCALE_H
>
> +#define ERRMSG_RASTER_OPEN_FILE _("Unable to find raster map <%s>")
> +#define ERRMSG_VECTOR_OPEN_FILE _("Unable to find vector map <%s>")
> +#define ERRMSG_ASCII_OPEN_FILE _("Unable to find ASCII file <%s>")
> +#define ERRMSG_OTHER_OPEN_FILE _("Unable to find file <%s>")

Will that hardcode whatever language GRASS was built with as the
only translation it can use for those messages? Or will the _(macros)
survive the build process and be processed normally at run-time?

Macros are substituted by the preprocessor, so there's no difference
between:

  G_fatal_error(ERRMSG_RASTER_OPEN_FILE, mapname);
and:
  G_fatal_error(_("Unable to find raster map <%s>"), mapname);

so far as the resulting object file is concerned.

In either case, the code which is actually compiled will be either:

  G_fatal_error(("Unable to find raster map <%s>"), mapname);
or:
  G_fatal_error(G_gettext(PACKAGE,("Unable to find raster map <%s>")), mapname);

depending upon whether I18N is enabled (in the latter case, PACKAGE
will have been expanded to either "grasslibs" or "grassmods").

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

hi,
I tryed this patch for glocale.h, which sets standard messages, which
should be used in all grass modules.

it worked for r.average quite well, but when I updated .po files, new
messages did not appear.

could someone tell me, how to add glocale.h to list of files, which are
searched trough by running "make pot" ?

thanks

Jachym

On Thu, Dec 14, 2006 at 10:55:31AM +0000, Glynn Clements wrote:

Hamish wrote:

> > My suggestion is:
> >
> > Index: include/glocale.h
> > ===================================================================
> > RCS file: /grassrepository/grass6/include/glocale.h,v
> > retrieving revision 2.2
> > diff -u -r2.2 glocale.h
> > --- include/glocale.h 26 Nov 2006 21:32:36 -0000 2.2
> > +++ include/glocale.h 13 Dec 2006 18:51:56 -0000
> > @@ -1,6 +1,11 @@
> > #ifndef GRASS_GLOCALE_H
> > #define GRASS_GLOCALE_H
> >
> > +#define ERRMSG_RASTER_OPEN_FILE _("Unable to find raster map <%s>")
> > +#define ERRMSG_VECTOR_OPEN_FILE _("Unable to find vector map <%s>")
> > +#define ERRMSG_ASCII_OPEN_FILE _("Unable to find ASCII file <%s>")
> > +#define ERRMSG_OTHER_OPEN_FILE _("Unable to find file <%s>")
>
>
> Will that hardcode whatever language GRASS was built with as the
> only translation it can use for those messages? Or will the _(macros)
> survive the build process and be processed normally at run-time?

Macros are substituted by the preprocessor, so there's no difference
between:

  G_fatal_error(ERRMSG_RASTER_OPEN_FILE, mapname);
and:
  G_fatal_error(_("Unable to find raster map <%s>"), mapname);

so far as the resulting object file is concerned.

In either case, the code which is actually compiled will be either:

  G_fatal_error(("Unable to find raster map <%s>"), mapname);
or:
  G_fatal_error(G_gettext(PACKAGE,("Unable to find raster map <%s>")), mapname);

depending upon whether I18N is enabled (in the latter case, PACKAGE
will have been expanded to either "grasslibs" or "grassmods").

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

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub
-----------------------------------------
OFFICE:
Department of Geoinformation Technologies
Zemedelska 3
613 00, Brno
Czech Republick
e-mail: xcepicky@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514

On Sat, 23 Dec 2006, Jachym Cepicky wrote:

hi,
I tryed this patch for glocale.h, which sets standard messages, which
should be used in all grass modules.

FWIW I don't like this idea, as it means (IIUC) that you can't grep for error messages in source files. Makes debugging a pain and is something that really annoys me with other software packages that do something similar. I don't see any advantage in using these macros over simply changing non-standard text strings to whichever ones we decide are standard?

it worked for r.average quite well, but when I updated .po files, new
messages did not appear.

But are they not old messages - they are already used in other modules? But I don't know how the translation stuff works??

Paul

could someone tell me, how to add glocale.h to list of files, which are
searched trough by running "make pot" ?

thanks

Jachym

On Thu, Dec 14, 2006 at 10:55:31AM +0000, Glynn Clements wrote:

Hamish wrote:

My suggestion is:

Index: include/glocale.h

RCS file: /grassrepository/grass6/include/glocale.h,v
retrieving revision 2.2
diff -u -r2.2 glocale.h
--- include/glocale.h 26 Nov 2006 21:32:36 -0000 2.2
+++ include/glocale.h 13 Dec 2006 18:51:56 -0000
@@ -1,6 +1,11 @@
#ifndef GRASS_GLOCALE_H
#define GRASS_GLOCALE_H

+#define ERRMSG_RASTER_OPEN_FILE _("Unable to find raster map <%s>")
+#define ERRMSG_VECTOR_OPEN_FILE _("Unable to find vector map <%s>")
+#define ERRMSG_ASCII_OPEN_FILE _("Unable to find ASCII file <%s>")
+#define ERRMSG_OTHER_OPEN_FILE _("Unable to find file <%s>")

Will that hardcode whatever language GRASS was built with as the
only translation it can use for those messages? Or will the _(macros)
survive the build process and be processed normally at run-time?

Macros are substituted by the preprocessor, so there's no difference
between:

  G_fatal_error(ERRMSG_RASTER_OPEN_FILE, mapname);
and:
  G_fatal_error(_("Unable to find raster map <%s>"), mapname);

so far as the resulting object file is concerned.

In either case, the code which is actually compiled will be either:

  G_fatal_error(("Unable to find raster map <%s>"), mapname);
or:
  G_fatal_error(G_gettext(PACKAGE,("Unable to find raster map <%s>")), mapname);

depending upon whether I18N is enabled (in the latter case, PACKAGE
will have been expanded to either "grasslibs" or "grassmods").

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

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

--
Jachym Cepicky
e-mail: jachym.cepicky@centrum.cz
URL: http://les-ejk.cz
GPG: http://www.les-ejk.cz/pgp/jachym_cepicky-gpg.pub
-----------------------------------------
OFFICE:
Department of Geoinformation Technologies
Zemedelska 3
613 00, Brno
Czech Republick
e-mail: xcepicky@node.mendelu.cz
URL: http://mapserver.mendelu.cz
Tel.: +420 545 134 514