[GRASS-dev] lib/gis/*.c: Extra calls to sprintf () just before G_warning ()

Glynn Clements glynn at gclements.plus.com
Mon Mar 23 13:04:49 EDT 2009


Ivan Shmakov wrote:

> 	There's no need to use sprintf () along with G_warning (), since
> 	the latter is already capable of the printf ()-style formatting.
> 
> 	Also, the following are /not/ equivalent fragments of code:
> 
>    G_warning (FMT, <arguments...>);
> 
>    sprintf (s, FMT, <arguments...>);
>    G_warning (s);
> 
> 	Instead, the former is equivalent to the following:
> 
>    sprintf (s, FMT, <arguments...>);
>    G_warning ("%s", s);
> 
> 	While the latter behaves differently should any percent signs
> 	(`%') be put into `s' as a result of sprintf ().
> 
> 	Hopefully, the following patch will resolve the issue.

The above is an artifact of printf-style formatting having been
retrofitted to G_warning() etc. Unsurprisingly, no-one went to the
trouble of fixing every single usage at that time ;)

> 	* the code like the following could bring all the sorts of woe
> 	  upon the heads of unsuspecting translators (this issue may
> 	  deserve a mention on Trac.)
> 
> --cut--
> 	    sprintf(buf,
> 		    _("Unable to read header file for raster map <%s@%s>."),
> 		    name, mapset);
> 	    tail = buf + strlen(buf);
> 	    sprintf(tail, _(" It is a reclass of raster map <%s@%s> "),
> 		    real_name, real_mapset);
> 	    tail = buf + strlen(buf);
> 	    if (!G_find_cell(real_name, real_mapset))
> 		sprintf(tail, _("which is missing."));
> 	    else
> 		sprintf(tail, _("whose header file can't be opened."));
> 	    G_warning ("%s", buf);
> 	    return -1;
> --cut--

Please fix this, e.g.:

	G_warning(
		!G_find_cell(real_name, real_mapset)
		? _("Unable to read header file for raster map <%s@%s>. It is a reclass of raster map <%s@%s> which is missing.")
		: _("Unable to read header file for raster map <%s@%s>. It is a reclass of raster map <%s@%s> whose header file can't be opened."),
		name, mapset);

I don't think that mentioning it on Trac is particularly helpful, as
no-one will find it unless they're specifically looking for it, in
which case they probably already know. But it's worth mentioning here,
and probably on the Wiki (if it isn't already):

The translation macro _(...) must be applied to entire messages, not
fragments. Code such as the above needs to be fixed to have the entire
message as a single string before it can be internationalised.

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


More information about the grass-dev mailing list