[GRASS-SVN] r47551 - in grass/trunk: include lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 11 06:35:16 EDT 2011
Author: martinl
Date: 2011-08-11 03:35:16 -0700 (Thu, 11 Aug 2011)
New Revision: 47551
Modified:
grass/trunk/include/gis.h
grass/trunk/include/gisdefs.h
grass/trunk/lib/gis/color_rules.c
grass/trunk/lib/gis/parser_standard_options.c
Log:
gislib: G_list_color_rules() and G_find_color_rule() added
new standard option G_OPT_M_COLR
Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h 2011-08-11 09:33:43 UTC (rev 47550)
+++ grass/trunk/include/gis.h 2011-08-11 10:35:16 UTC (rev 47551)
@@ -221,6 +221,7 @@
G_OPT_M_DATATYPE, /* datatype */
G_OPT_M_MAPSET, /* mapset */
G_OPT_M_EN, /* coordinates */
+ G_OPT_M_COLR, /* color rules */
} STD_OPT;
/* Message format */
Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h 2011-08-11 09:33:43 UTC (rev 47550)
+++ grass/trunk/include/gisdefs.h 2011-08-11 10:35:16 UTC (rev 47551)
@@ -126,8 +126,10 @@
void G_clicker(void);
/* color_rules.c */
-char *G_color_rules_list(void);
+char *G_color_rules_options(void);
char *G_color_rules_descriptions(void);
+void G_list_color_rules(FILE *);
+int G_find_color_rule(const char *);
/* color_str.c */
int G_num_standard_colors(void);
Modified: grass/trunk/lib/gis/color_rules.c
===================================================================
--- grass/trunk/lib/gis/color_rules.c 2011-08-11 09:33:43 UTC (rev 47550)
+++ grass/trunk/lib/gis/color_rules.c 2011-08-11 10:35:16 UTC (rev 47551)
@@ -1,7 +1,7 @@
/*!
\file lib/gis/color_tables.c
- \brief GIS Library - Color tables
+ \brief GIS Library - Color tables management subroutines
Taken from r.colors module.
@@ -14,7 +14,7 @@
#include <grass/gis.h>
#include <grass/glocale.h>
-static int scan_rules(char ***);
+static char **scan_rules(int *);
static int cmp(const void *, const void *);
/*!
@@ -22,7 +22,7 @@
\return allocated string buffer with options
*/
-char *G_color_rules_list(void)
+char *G_color_rules_options(void)
{
char *list, **rules;
const char *name;
@@ -32,7 +32,7 @@
list = NULL;
size = len = 0;
- nrules = scan_rules(&rules);
+ rules = scan_rules(&nrules);
for (i = 0; i < nrules; i++) {
name = rules[i];
@@ -64,10 +64,10 @@
{
char path[GPATH_MAX];
struct Key_Value *kv;
- int result_len, result_max, nrules;
+ int result_len, result_max;
char *result, **rules;
const char *name, *desc;
- int i, len;
+ int i, len, nrules;
result_len = 0;
result_max = 2000;
@@ -78,7 +78,7 @@
if (!kv)
return NULL;
- nrules = scan_rules(&rules);
+ rules = scan_rules(&nrules);
for (i = 0; i < nrules; i++) {
name = rules[i];
@@ -105,24 +105,24 @@
return result;
}
-int scan_rules(char ***rules)
+char **scan_rules(int *nrules)
{
- int nrules;
+ char **rules;
char path[GPATH_MAX];
G_snprintf(path, GPATH_MAX, "%s/etc/colors", G_gisbase());
- *rules = G__ls(path, &nrules);
+ rules = G__ls(path, nrules);
- *rules = G_realloc(*rules, (nrules + 3) * sizeof (const char *));
+ rules = G_realloc(rules, (*nrules + 3) * sizeof (const char *));
- (*rules)[nrules++] = G_store("random");
- (*rules)[nrules++] = G_store("grey.eq");
- (*rules)[nrules++] = G_store("grey.log");
+ rules[(*nrules)++] = G_store("random");
+ rules[(*nrules)++] = G_store("grey.eq");
+ rules[(*nrules)++] = G_store("grey.log");
- qsort(*rules, nrules, sizeof (char *), cmp);
+ qsort(rules, *nrules, sizeof (char *), cmp);
- return nrules;
+ return rules;
}
int cmp(const void *aa, const void *bb)
@@ -132,3 +132,41 @@
return strcmp(*a, *b);
}
+
+/*!
+ \brief Print color rules
+
+ \param out file where to print
+*/
+void G_list_color_rules(FILE *out)
+{
+ int i, nrules;
+ char **rules;
+
+ rules = scan_rules(&nrules);
+
+ for (i = 0; i < nrules; i++)
+ fprintf(out, "%s\n", rules[i]);
+}
+
+/*!
+ \brief Check if color rule is defined
+
+ \param name color rule name
+
+ \return 1 found
+ \return 0 not found
+*/
+int G_find_color_rule(const char *name)
+{
+ int i, nrules;
+ char **rules;
+
+ rules = scan_rules(&nrules);
+
+ for (i = 0; i < nrules; i++)
+ if (strcmp(name, rules[i]) == 0)
+ return 1;
+
+ return 0;
+}
Modified: grass/trunk/lib/gis/parser_standard_options.c
===================================================================
--- grass/trunk/lib/gis/parser_standard_options.c 2011-08-11 09:33:43 UTC (rev 47550)
+++ grass/trunk/lib/gis/parser_standard_options.c 2011-08-11 10:35:16 UTC (rev 47551)
@@ -82,12 +82,13 @@
- colors
- G_OPT_C_FG
- G_OPT_C_BG
-
+
- misc
- G_OPT_M_UNITS
- G_OPT_M_DATATYPE
- G_OPT_M_MAPSET
- G_OPT_M_EN
+ - G_OPT_M_COLR
\param opt type of Option struct to create
@@ -557,7 +558,17 @@
Opt->multiple = YES;
Opt->key_desc = "east,north";
Opt->description = _("Coordinates");
+ break;
+
+ case G_OPT_M_COLR:
+ Opt->key = "color";
+ Opt->key_desc = "style";
+ Opt->type = TYPE_STRING;
+ Opt->required = NO;
+ Opt->options = G_color_rules_options();
+ Opt->description = _("Name of color table");
+ Opt->descriptions = G_color_rules_descriptions();
}
-
+
return Opt;
}
More information about the grass-commit
mailing list