From 24fa1e5285ac83ece1025eed81fae214aec1cb5a Mon Sep 17 00:00:00 2001 From: Nishant Bansal Date: Fri, 1 Nov 2024 15:36:04 +0530 Subject: [PATCH] Add a standard parser option for color formatting Signed-off-by: Nishant Bansal --- include/grass/gis.h | 5 +++-- lib/gis/parser_standard_options.c | 15 +++++++++++++++ raster/r.colors.out/raster3d_main.c | 18 +----------------- raster/r.colors.out/raster_main.c | 17 +---------------- 4 files changed, 20 insertions(+), 35 deletions(-) diff --git a/include/grass/gis.h b/include/grass/gis.h index c032b40de06..48b792c2ae4 100644 --- a/include/grass/gis.h +++ b/include/grass/gis.h @@ -316,8 +316,9 @@ typedef enum { G_OPT_F_OUTPUT, /*!< new output file */ G_OPT_F_SEP, /*!< data field separator */ - G_OPT_C, /*!< color */ - G_OPT_CN, /*!< color or none */ + G_OPT_C, /*!< color */ + G_OPT_CN, /*!< color or none */ + G_OPT_C_FORMAT, /*!< set color format to rgb,hex,hsv or xterm */ G_OPT_M_UNITS, /*!< units */ G_OPT_M_DATATYPE, /*!< datatype */ diff --git a/lib/gis/parser_standard_options.c b/lib/gis/parser_standard_options.c index 5c3da23c7bf..f4464f4d06c 100644 --- a/lib/gis/parser_standard_options.c +++ b/lib/gis/parser_standard_options.c @@ -652,6 +652,21 @@ struct Option *G_define_standard_option(int opt) Opt->description = _("Either a standard color name, R:G:B triplet, or \"none\""); break; + case G_OPT_C_FORMAT: + Opt->key = "color_format"; + Opt->type = TYPE_STRING; + Opt->key_desc = "name"; + Opt->required = YES; + Opt->multiple = NO; + Opt->answer = "xterm"; + Opt->options = "rgb,hex,hsv,xterm"; + Opt->label = _("Color format"); + Opt->description = _("Color format for output values."); + G_asprintf( + (char **)&(Opt->descriptions), "rgb;%s;hex;%s;hsv;%s;xterm;%s", + _("output color in RGB format"), _("output color in HEX format"), + _("output color in HSV format"), _("output color in XTERM format")); + break; /* misc */ diff --git a/raster/r.colors.out/raster3d_main.c b/raster/r.colors.out/raster3d_main.c index ffb9026fbbd..9744941aaa7 100644 --- a/raster/r.colors.out/raster3d_main.c +++ b/raster/r.colors.out/raster3d_main.c @@ -63,23 +63,7 @@ int main(int argc, char **argv) opt.format = G_define_standard_option(G_OPT_F_FORMAT); opt.format->guisection = _("Print"); - opt.color_format = G_define_option(); - opt.color_format->key = "color_format"; - opt.color_format->type = TYPE_STRING; - opt.color_format->key_desc = "name"; - opt.color_format->required = YES; - opt.color_format->multiple = NO; - opt.color_format->answer = "xterm"; - opt.color_format->options = "rgb,hex,hsv,xterm"; - opt.color_format->label = _("Color format"); - opt.color_format->description = - _("Color format output for raster3d values."); - char *desc = NULL; - G_asprintf(&desc, "rgb;%s;hex;%s;hsv;%s;xterm;%s", - _("output color in RGB format"), _("output color in HEX format"), - _("output color in HSV format"), - _("output color in XTERM format")); - opt.color_format->descriptions = desc; + opt.color_format = G_define_standard_option(G_OPT_C_FORMAT); opt.color_format->guisection = _("Color"); flag.p = G_define_flag(); diff --git a/raster/r.colors.out/raster_main.c b/raster/r.colors.out/raster_main.c index 1809114c325..505a82ba578 100644 --- a/raster/r.colors.out/raster_main.c +++ b/raster/r.colors.out/raster_main.c @@ -62,22 +62,7 @@ int main(int argc, char **argv) opt.format = G_define_standard_option(G_OPT_F_FORMAT); opt.format->guisection = _("Print"); - opt.color_format = G_define_option(); - opt.color_format->key = "color_format"; - opt.color_format->type = TYPE_STRING; - opt.color_format->key_desc = "name"; - opt.color_format->required = YES; - opt.color_format->multiple = NO; - opt.color_format->answer = "xterm"; - opt.color_format->options = "rgb,hex,hsv,xterm"; - opt.color_format->label = _("Color format"); - opt.color_format->description = _("Color format output for raster values."); - char *desc = NULL; - G_asprintf(&desc, "rgb;%s;hex;%s;hsv;%s;xterm;%s", - _("output color in RGB format"), _("output color in HEX format"), - _("output color in HSV format"), - _("output color in XTERM format")); - opt.color_format->descriptions = desc; + opt.color_format = G_define_standard_option(G_OPT_C_FORMAT); opt.color_format->guisection = _("Color"); flag.p = G_define_flag();