[GRASS-dev] C syntax and the use of underscore ('_')

Hi,

In r.univar_main.c, there are a number of string assignments similar to this:

param.percentile->description =
_(“Percentile to calculate (requires extended statistics flag)”);

I am not familiar with the ‘_’ syntax as it is being used here before the opening ‘(’.

The Eclipse editor complains about syntax.

Anyone know what is happening here?

Regards,

Rob Parsons

Raleigh NC

On Sun, Aug 2, 2015 at 6:42 PM, Rob Parsons <jrobparsons@gmail.com> wrote:

Hi,

In r.univar_main.c, there are a number of string assignments similar to
this:

param.percentile->description =
    _("Percentile to calculate (requires extended statistics flag)");

I am not familiar with the '_' syntax as it is being used here before the
opening '('.

These are the gettext macros used for the indication of strings (user
messages) to be translated.
Background info:
http://grass.osgeo.org/development/translations/
and especially
http://grasswiki.osgeo.org/wiki/GRASS_messages_translation

I have added some more hints now here:
http://grasswiki.osgeo.org/wiki/GRASS_messages_translation#Updating_messages_in_the_source_code

The Eclipse editor complains about syntax.

Anyone know what is happening here?

I suppose that the Eclipse editor needs to be configured properly for
that (no idea how since I am not familiar with it). Perhaps others
know here?

In any case, the macro need to remain.

best,
Markus

* Markus Neteler <neteler@osgeo.org> [2015-08-02 19:55:46 +0200]:

On Sun, Aug 2, 2015 at 6:42 PM, Rob Parsons <jrobparsons@gmail.com> wrote:
> Hi,
>
> In r.univar_main.c, there are a number of string assignments similar to
> this:
>
>
> param.percentile->description =
> _("Percentile to calculate (requires extended statistics flag)");
>
>
> I am not familiar with the '_' syntax as it is being used here before the
> opening '('.

These are the gettext macros used for the indication of strings (user
messages) to be translated.
Background info:
http://grass.osgeo.org/development/translations/
and especially
http://grasswiki.osgeo.org/wiki/GRASS_messages_translation

Is this relevant to python (scripts) as well?

Nikos

I have added some more hints now here:
http://grasswiki.osgeo.org/wiki/GRASS_messages_translation#Updating_messages_in_the_source_code

> The Eclipse editor complains about syntax.
>
> Anyone know what is happening here?

I suppose that the Eclipse editor needs to be configured properly for
that (no idea how since I am not familiar with it). Perhaps others
know here?

In any case, the macro need to remain.

best,
Markus
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

--
Nikos Alexandris | Remote Sensing Scientist, Dr
Themidos 3, 42100, Trikala, Greece
GPG Key Fingerprint 6F9D4506F3CA28380974D31A9053534B693C4FB3

On Sun, Aug 2, 2015 at 10:25 PM, Nikos Alexandris
<nik@nikosalexandris.net> wrote:
...

Is this relevant to python (scripts) as well?

Yes, e.g.

[neteler@oboe r.unpack]$ grep message *
r.unpack.py: grass.message(_('Raster map <{name}>
unpacked'.format(name=map_name)))

I added a hint here:
http://grasswiki.osgeo.org/wiki/GRASS_messages_translation#Python_programming_language

Markus

Some examples on _() and n_() use are in locale/README file.
https://svn.osgeo.org/grass/grass/trunk/locale/README

2015-08-03 0:32 GMT+03:00 Markus Neteler <neteler@osgeo.org>:

On Sun, Aug 2, 2015 at 10:25 PM, Nikos Alexandris
<nik@nikosalexandris.net> wrote:
...

Is this relevant to python (scripts) as well?

Yes, e.g.

[neteler@oboe r.unpack]$ grep message *
r.unpack.py: grass.message(_('Raster map <{name}>
unpacked'.format(name=map_name)))

I added a hint here:
http://grasswiki.osgeo.org/wiki/GRASS_messages_translation#Python_programming_language

Markus
_______________________________________________
grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

Telling Eclipse that the C dialect is c99 (-std=c99) solved the problem. The macro is now recognized.

On Aug 3, 2015 4:00 AM, “Maris Nartiss” <maris.gis@gmail.com> wrote:

Some examples on () and n() use are in locale/README file.
https://svn.osgeo.org/grass/grass/trunk/locale/README

2015-08-03 0:32 GMT+03:00 Markus Neteler <neteler@osgeo.org>:

On Sun, Aug 2, 2015 at 10:25 PM, Nikos Alexandris
<nik@nikosalexandris.net> wrote:

Is this relevant to python (scripts) as well?

Yes, e.g.

[neteler@oboe r.unpack]$ grep message *
r.unpack.py: grass.message(_(‘Raster map <{name}>
unpacked’.format(name=map_name)))

I added a hint here:
http://grasswiki.osgeo.org/wiki/GRASS_messages_translation#Python_programming_language

Markus


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev


grass-dev mailing list
grass-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-dev

On Mon, Aug 3, 2015 at 2:26 PM, Rob Parsons <jrobparsons@gmail.com> wrote:

Telling Eclipse that the C dialect is c99 (-std=c99) solved the problem. The
macro is now recognized.

Excellent. Please consider to update the page
http://grasswiki.osgeo.org/wiki/Eclipse

in order to help others with the hint(s) which easily get lost in the
email archive.

Markus

Ok.

I am getting smarter.

Forget what I said about using the -std=c99 option to get Eclipse to recognize the _() macro. The syntax error being reported by the Eclipse editor (CDT parser) is caused be the definition of PACKAGE on the gcc command line.

-DPACKAGE="“grassmods”"

Eclipse invokes the GRASS ‘make default’ tool and builds the system or module with no problem. The Eclipse parser/indexer builds its database of symbols and cross-references by scanning all the C/C++ source code, Python scripts and make output.

It learns that the value of PACKAGE is the string:

"“grassmods”"

This value is OK when building the system or module because the build is performed within a MSYS shell.

The Eclipse editor and CDT parser likes this value:

“grassmods”

I am not suggesting any kind of change. The _() macro works. I can successfully compile and from within Eclipse. The ‘syntax error’ is more of a nuisance than anything else. Maybe I can figure out how to tell Eclipse to ignore this syntax.

Eclipse 4.5 Mars for GRASS development on Windows 7 is working very well. I can browse, build, run, debug GRASS C/C+ modules and Python scripts.

I will document this on the wiki.

Rob Parsons

Raleigh NC

···

On Mon, Aug 3, 2015 at 8:57 AM, Markus Neteler <neteler@osgeo.org> wrote:

On Mon, Aug 3, 2015 at 2:26 PM, Rob Parsons <jrobparsons@gmail.com> wrote:

Telling Eclipse that the C dialect is c99 (-std=c99) solved the problem. The
macro is now recognized.

Excellent. Please consider to update the page
http://grasswiki.osgeo.org/wiki/Eclipse

in order to help others with the hint(s) which easily get lost in the
email archive.

Markus