[GRASS-dev] g.rename consolidation

Martin Landa landa.martin at gmail.com
Fri Feb 23 05:24:27 EST 2007


Hi,

2007/2/22, Glynn Clements <glynn at gclements.plus.com>:
>
> Martin Landa wrote:
>
> > > There needs to be a new function for messages which allows specifying
> > > the verbosity level.
> > >
> > > Rather than individual modules having to do:
> > >
> > >         if (G_verbose() >= level)
> > >                 G_message(...);
> > >
> > > they would do e.g.:
> > >
> > >         G_message_ex(level, ...);
> > >
> > > The new function would check the verbosity level.
> > >
> > > The current mechanism is just making the code messy.
> >
> > OK, it would be also useful to have G_message_no_nl() which does not
> > print new-line character at the of the message. I am not sure how to
> > derive these functions from the existing G_message() fn. Is there any
> > way how to redirect variadic parameters. E.g.:
> >
> > void foo (char *text, ...);
> > void foo1 (char *text, ...);
> >
> > void foo (char *text) {
> >     foo1 (?)
> > }
>
> You would need a version of the callee which takes a va_list as a
> parameter, and I'm not sure whether there's any portable way to write
> such functions.

OK,

/*!
 * \fn void G_message_ex (char *msg,...)
 *
 * \brief Print a message to stderr only on the given verbosity level or greater
 *
 * The output format depends on enviroment variable GRASS_MESSAGE_FORMAT
 *
 * \param level verbosity level
*/
void G_message_ex (int level, char *msg,...)
{
    char buffer[2000];  /* G_asprintf does not work */
    va_list ap;

    va_start(ap, msg);
    vsprintf(buffer,msg,ap);
    va_end(ap);

    if (G_verbose() >= level) {
	print_error (buffer,MSG);
    }
}

anyway is not nice way. Duplicate the code. Last time I have tried to
write G_message_no_line() I had similar problem.

Martin

-- 
Martin Landa <landa.martin at gmail.com> * http://gama.fsv.cvut.cz/~landa *




More information about the grass-dev mailing list