[GRASS-dev] howto rewrite r.colors using G_message and G_warning
glynn at gclements.plus.com
Wed Sep 27 11:43:51 EDT 2006
Jachym Cepicky wrote:
> i tryed to rewrite r.colors so it uses G_message && G_warning where ever
> it seemed better, then fprinfs
> i used it also for printing of warnings, when colors are set via rules.
> in error.c print_error() uses G_sleep(5) which makes the module sleep
> about 5 seconds when the warning is printed out:
> echo "1 233:233:443"|r.colors map=pokus color=rules --q
> WARNING: R:G:B value(s) out of range [0..255]: 233:233:443
> (5 seconds )
> WARNING: rule is not added
> (another 5 seconds )
> Is there a way, how to omit this sleeping function or is usage of
> G_warning on this place in general wrong approach?
IMHO, the sleep() should just be discarded. It makes no sense for
non-interactive modules (which constitute the vast majority), and not
much sense for interactive modules.
My guess is that it was added for a specific case, probably a curses
application where the warning would get erased from the screen
BTW, beeping assumes that the terminal supports it, and uses \x07 for
that purpose. This isn't guaranteed; my default terminal is XEmacs'
shell-mode, which just dumps everything in the buffer, so a "beep" is
just a "^G" in the buffer.
OTOH, that's still small fry compared to G_percent():
glynn at cerise:cvs $ r.mapcalc 'map1=col()'
0%^H^H^H^H^H 11%^H^H^H^H^H 22%^H^H^H^H^H 33%^H^H^H^H^H ....
In theory, you should write any control codes except \n to the
terminal unless the terminal's termpcap/terminfo entry tells you to.
However, linking everything against libtermcap/libtinfo/libncurses
(*if* you can figure out which is the right one to use) just for this
purpose is a rather heavyweight solution.
> patch is attached, not yet in cvs, please test
> Index: main.c
FWIW, it's preferable to generate patches from the top of the GRASS
> RCS file: /grassrepository/grass6/raster/r.colors/main.c,v
> retrieving revision 2.8
> diff -u -r2.8 main.c
> --- main.c 15 Sep 2006 06:51:55 -0000 2.8
> +++ main.c 27 Sep 2006 09:15:22 -0000
> @@ -174,7 +174,7 @@
> "ryg;red through yellow to green colors;"
> "random;random color table;"
> "wave;color wave;"
> - "rules;create new color table by rules";
> + "rules;create new color table by rules (input via keyboard or stdin)";
This is unnecessary, IMHO.
Other than that, it seems fine.
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev