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) {
65 memcpy(&list[len], name, n + 1);
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,
209 sizeof(
struct colorinfo), cmp_clrname);
213 fprintf(out,
"%s: %s [%s]\n", cfound->name,
214 cfound->desc, cfound->type);
217 fprintf(out,
"%s: [%s]\n", cfound->name,
223 if (cfound ==
NULL) {
224 for (i = 0; i < nrules; i++) {
225 if (colorinfo[i].desc) {
226 fprintf(out,
"%s: %s [%s]\n", colorinfo[i].name,
227 colorinfo[i].desc, colorinfo[i].type);
230 fprintf(out,
"%s: [%s]\n", colorinfo[i].name,
236 free_colorinfo(colorinfo, nrules);
250 struct colorinfo *colorinfo, csearch;
252 colorinfo = get_colorinfo(&nrules);
254 csearch.name = (
char *)name;
255 result = (bsearch(&csearch, colorinfo, nrules,
256 sizeof(
struct colorinfo), cmp_clrname) !=
NULL);
258 free_colorinfo(colorinfo, nrules);
263 struct colorinfo *get_colorinfo(
int *nrules)
268 struct colorinfo *colorinfo;
275 cnames =
G_ls2(path, nrules);
277 colorinfo =
G_malloc(*nrules *
sizeof(
struct colorinfo));
278 for (i = 0; i < *nrules - 3; i++) {
284 colorinfo[i].name =
G_store(cnames[i]);
285 colorinfo[i].desc =
NULL;
290 fp = fopen(path,
"r");
298 while (
G_getl2(buf,
sizeof(buf), fp)) {
299 char value[80], color[80];
310 if (sscanf(buf,
"%s %[^\n]", value, color) != 2)
321 if (sscanf(value,
"%lf%c", &x, &c) == 2 && c ==
'%') {
325 if (sscanf(value,
"%lf", &x) == 1) {
341 colorinfo[i].type =
G_store(
_(
"range: map values"));
343 G_snprintf(buf,
sizeof(buf) - 1,
_(
"range: %g to %g"), rmin, rmax);
344 colorinfo[i].type =
G_store(buf);
350 colorinfo[*nrules - 3].name =
G_store(
"random");
351 colorinfo[*nrules - 3].desc =
NULL;
352 colorinfo[*nrules - 3].type =
G_store(
_(
"range: map values"));
354 colorinfo[*nrules - 2].name =
G_store(
"grey.eq");
355 colorinfo[*nrules - 2].desc =
NULL;
356 colorinfo[*nrules - 2].type =
G_store(
_(
"range: map values"));
358 colorinfo[*nrules - 1].name =
G_store(
"grey.log");
359 colorinfo[*nrules - 1].desc =
NULL;
360 colorinfo[*nrules - 1].type =
G_store(
_(
"range: map values"));
362 qsort(colorinfo, *nrules,
sizeof(
struct colorinfo), cmp_clrname);
366 fp = fopen(path,
"r");
376 struct colorinfo csearch, *cfound;
378 if (!
G_getl2(buf,
sizeof(buf), fp))
380 strcpy(tok_buf, buf);
386 cname =
G_chop(tokens[0]);
387 cdesc =
G_chop(tokens[1]);
389 csearch.name = cname;
390 cfound = bsearch(&csearch, colorinfo, *nrules,
391 sizeof(
struct colorinfo), cmp_clrname);
403 void free_colorinfo(
struct colorinfo *colorinfo,
int nrules)
407 for (i = 0; i < nrules; i++) {
408 if (colorinfo[i].
name)
409 G_free(colorinfo[i].name);
410 if (colorinfo[i].desc)
411 G_free(colorinfo[i].desc);
412 if (colorinfo[i].type)
413 G_free(colorinfo[i].type);
int G_getl2(char *, int, FILE *)
Gets a line of text from a file of any pedigree.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_find_color_rule(const char *name)
Check if color rule is defined.
void G_free(void *)
Free allocated memory.
void G_list_color_rules(FILE *out)
Print color rules.
void G_strip(char *)
Removes all leading and trailing white space from string.
char ** G_ls2(const char *, int *)
Stores a sorted directory listing in an array.
char ** G_tokenize(const char *, const char *)
Tokenize string.
char * G_color_rules_description_type(void)
Get color rules description for Option->descriptions.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
void G_list_color_rules_description_type(FILE *out, char *name)
Print color rules with description and type.
int G_number_of_tokens(char **)
Return number of tokens.
char * G_chop(char *)
Chop leading and trailing white spaces.
int G_snprintf(char *, size_t, const char *,...) __attribute__((format(printf
const char * G_gisbase(void)
Get full path name of the top level module directory.
void G_free_tokens(char **)
Free memory allocated to tokens.
char * G_color_rules_descriptions(void)
Get color rules description for Option->descriptions.
char * G_color_rules_options(void)
Get list of color rules for Option->options.
char * G_store(const char *)
Copy string to allocated memory.