24 static struct colorinfo *get_colorinfo(
int *);
25 static void free_colorinfo(
struct colorinfo *,
int);
27 static int cmp_clrname(
const void *a,
const void *
b)
29 struct colorinfo *
ca = (
struct colorinfo *)a;
30 struct colorinfo *cb = (
struct colorinfo *)
b;
32 return (strcmp(
ca->name, cb->name));
44 int size, len, nrules;
46 struct colorinfo *colorinfo;
51 colorinfo = get_colorinfo(&nrules);
53 for (i = 0; i < nrules; i++) {
54 name = colorinfo[i].name;
57 if (size < len + n + 2) {
69 free_colorinfo(colorinfo, nrules);
81 int result_len, result_max;
83 const char *
name, *desc;
85 struct colorinfo *colorinfo;
91 colorinfo = get_colorinfo(&nrules);
93 for (i = 0; i < nrules; i++) {
94 name = colorinfo[i].name;
95 desc = colorinfo[i].desc;
98 desc =
_(
"no description");
102 len = strlen(
name) + strlen(desc) + 2;
103 if (result_len + len >= result_max) {
104 result_max = result_len + len + 1000;
108 sprintf(result + result_len,
"%s;%s;",
name, desc);
112 free_colorinfo(colorinfo, nrules);
127 struct colorinfo *colorinfo;
128 const char *
name, *desc, *type;
129 int result_len, result_max;
132 colorinfo = get_colorinfo(&nrules);
138 for (i = 0; i < nrules; i++) {
139 name = colorinfo[i].name;
140 desc = colorinfo[i].desc;
141 type = colorinfo[i].type;
144 len = strlen(
name) + strlen(desc) + strlen(type) + 5;
145 if (result_len + len >= result_max) {
146 result_max = result_len + len + 1000;
150 sprintf(result + result_len,
"%s;%s [%s];",
name, desc, type);
154 len = strlen(
name) + strlen(type) + 5;
155 if (result_len + len >= result_max) {
156 result_max = result_len + len + 1000;
160 sprintf(result + result_len,
"%s; [%s];",
name, type);
165 free_colorinfo(colorinfo, nrules);
178 struct colorinfo *colorinfo;
180 colorinfo = get_colorinfo(&nrules);
182 for (i = 0; i < nrules; i++)
183 fprintf(out,
"%s\n", colorinfo[i].
name);
185 free_colorinfo(colorinfo, nrules);
201 struct colorinfo *colorinfo, csearch, *cfound;
203 colorinfo = get_colorinfo(&nrules);
208 cfound = bsearch(&csearch, colorinfo, nrules,
sizeof(
struct colorinfo),
213 fprintf(out,
"%s: %s [%s]\n", cfound->name, cfound->desc,
217 fprintf(out,
"%s: [%s]\n", cfound->name, cfound->type);
222 if (cfound ==
NULL) {
223 for (i = 0; i < nrules; i++) {
224 if (colorinfo[i].desc) {
225 fprintf(out,
"%s: %s [%s]\n", colorinfo[i].
name,
226 colorinfo[i].desc, colorinfo[i].type);
229 fprintf(out,
"%s: [%s]\n", colorinfo[i].
name,
235 free_colorinfo(colorinfo, nrules);
249 struct colorinfo *colorinfo, csearch;
251 colorinfo = get_colorinfo(&nrules);
253 csearch.name = (
char *)
name;
254 result = (bsearch(&csearch, colorinfo, nrules,
sizeof(
struct colorinfo),
255 cmp_clrname) !=
NULL);
257 free_colorinfo(colorinfo, nrules);
262 struct colorinfo *get_colorinfo(
int *nrules)
267 struct colorinfo *colorinfo;
276 colorinfo =
G_malloc(*nrules *
sizeof(
struct colorinfo));
277 for (i = 0; i < *nrules - 3; i++) {
283 colorinfo[i].name =
G_store(cnames[i]);
284 colorinfo[i].desc =
NULL;
289 fp = fopen(
path,
"r");
297 while (
G_getl2(buf,
sizeof(buf), fp)) {
298 char value[80], color[80];
309 if (sscanf(buf,
"%s %[^\n]", value, color) != 2)
320 if (sscanf(value,
"%lf%c", &
x, &c) == 2 && c ==
'%') {
324 if (sscanf(value,
"%lf", &
x) == 1) {
340 colorinfo[i].type =
G_store(
_(
"range: map values"));
342 snprintf(buf,
sizeof(buf) - 1,
_(
"range: %g to %g"), rmin, rmax);
343 colorinfo[i].type =
G_store(buf);
349 colorinfo[*nrules - 3].name =
G_store(
"random");
350 colorinfo[*nrules - 3].desc =
NULL;
351 colorinfo[*nrules - 3].type =
G_store(
_(
"range: map values"));
353 colorinfo[*nrules - 2].name =
G_store(
"grey.eq");
354 colorinfo[*nrules - 2].desc =
NULL;
355 colorinfo[*nrules - 2].type =
G_store(
_(
"range: map values"));
357 colorinfo[*nrules - 1].name =
G_store(
"grey.log");
358 colorinfo[*nrules - 1].desc =
NULL;
359 colorinfo[*nrules - 1].type =
G_store(
_(
"range: map values"));
361 qsort(colorinfo, *nrules,
sizeof(
struct colorinfo), cmp_clrname);
365 fp = fopen(
path,
"r");
375 struct colorinfo csearch, *cfound;
377 if (!
G_getl2(buf,
sizeof(buf), fp))
385 cname =
G_chop(tokens[0]);
386 cdesc =
G_chop(tokens[1]);
388 csearch.name = cname;
389 cfound = bsearch(&csearch, colorinfo, *nrules,
sizeof(
struct colorinfo),
402 void free_colorinfo(
struct colorinfo *colorinfo,
int nrules)
406 for (i = 0; i < nrules; i++) {
407 if (colorinfo[i].
name)
409 if (colorinfo[i].desc)
410 G_free(colorinfo[i].desc);
411 if (colorinfo[i].type)
412 G_free(colorinfo[i].type);
int G_getl2(char *, int, FILE *)
Gets a line of text from a file of any pedigree.
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_free_tokens(char **)
Free memory allocated to tokens.
char ** G_ls2(const char *, int *)
Stores a sorted directory listing in an array.
void G_strip(char *)
Removes all leading and trailing white space from string.
int G_number_of_tokens(char **)
Return number of tokens.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
const char * G_gisbase(void)
Get full path name of the top level module directory.
char * G_chop(char *)
Chop leading and trailing white spaces.
char * G_store(const char *)
Copy string to allocated memory.
char ** G_tokenize(const char *, const char *)
Tokenize string.
char * G_color_rules_options(void)
Get list of color rules for Option->options.
void G_list_color_rules(FILE *out)
Print color rules.
char * G_color_rules_description_type(void)
Get color rules description for Option->descriptions.
void G_list_color_rules_description_type(FILE *out, char *name)
Print color rules with description and type.
int G_find_color_rule(const char *name)
Check if color rule is defined.
char * G_color_rules_descriptions(void)
Get color rules description for Option->descriptions.