|
@@ -183,160 +183,12 @@ int edit_colors(int argc, char **argv, int type, const char *maptype,
|
|
|
|
|
|
if (flag.l->answer) {
|
|
|
G_list_color_rules(stdout);
|
|
|
+
|
|
|
return EXIT_SUCCESS;
|
|
|
}
|
|
|
|
|
|
if (flag.d->answer) {
|
|
|
- char path[GPATH_MAX];
|
|
|
- FILE *fp;
|
|
|
- int ncolors;
|
|
|
- struct colordesc *colordesc;
|
|
|
- char **cnames;
|
|
|
-
|
|
|
- /* load color rules */
|
|
|
- G_snprintf(path, GPATH_MAX, "%s/etc/colors", G_gisbase());
|
|
|
-
|
|
|
- ncolors = 0;
|
|
|
- cnames = G_ls2(path, &ncolors);
|
|
|
- colordesc = G_malloc(ncolors * sizeof(struct colordesc));
|
|
|
- for (i = 0; i < ncolors; i++) {
|
|
|
- char buf[1024];
|
|
|
- double rmin, rmax;
|
|
|
- int first;
|
|
|
- int cisperc;
|
|
|
-
|
|
|
- colordesc[i].name = G_store(cnames[i]);
|
|
|
- colordesc[i].desc = NULL;
|
|
|
-
|
|
|
- /* open color rule file */
|
|
|
- G_snprintf(path, GPATH_MAX, "%s/etc/colors/%s", G_gisbase(),
|
|
|
- colordesc[i].name);
|
|
|
- fp = fopen(path, "r");
|
|
|
- if (!fp)
|
|
|
- G_fatal_error(_("Unable to open color rule"));
|
|
|
-
|
|
|
- /* scan all lines */
|
|
|
- first = 1;
|
|
|
- rmin = rmax = 0;
|
|
|
- cisperc = 0;
|
|
|
- while (G_getl2(buf, sizeof(buf), fp)) {
|
|
|
- char value[80], color[80];
|
|
|
- double x;
|
|
|
- char c;
|
|
|
-
|
|
|
- G_strip(buf);
|
|
|
-
|
|
|
- if (*buf == '\0')
|
|
|
- continue;
|
|
|
- if (*buf == '#')
|
|
|
- continue;
|
|
|
-
|
|
|
- if (sscanf(buf, "%s %[^\n]", value, color) != 2)
|
|
|
- continue;
|
|
|
-
|
|
|
- if (G_strcasecmp(value, "default") == 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (G_strcasecmp(value, "nv") == 0) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (sscanf(value, "%lf%c", &x, &c) == 2 && c == '%') {
|
|
|
- cisperc = 1;
|
|
|
- break;
|
|
|
- }
|
|
|
- if (sscanf(value, "%lf", &x) == 1) {
|
|
|
- if (first) {
|
|
|
- first = 0;
|
|
|
- rmin = rmax = x;
|
|
|
- }
|
|
|
- else {
|
|
|
- if (rmin > x)
|
|
|
- rmin = x;
|
|
|
- if (rmax < x)
|
|
|
- rmax = x;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- fclose(fp);
|
|
|
-
|
|
|
- if (cisperc)
|
|
|
- colordesc[i].type = G_store(_("relative, percent of map range"));
|
|
|
- else {
|
|
|
- G_snprintf(buf, sizeof(buf) - 1, _("absolute, %g to %g"), rmin, rmax);
|
|
|
- colordesc[i].type = G_store(buf);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- qsort(colordesc, ncolors, sizeof(struct colordesc), cmp_clrname);
|
|
|
-
|
|
|
- /* load color descriptions */
|
|
|
- G_snprintf(path, GPATH_MAX, "%s/etc/colors.desc", G_gisbase());
|
|
|
- fp = fopen(path, "r");
|
|
|
- if (!fp)
|
|
|
- G_fatal_error(_("Unable to open color descriptions"));
|
|
|
-
|
|
|
- for (;;) {
|
|
|
- char buf[1024];
|
|
|
- char tok_buf[1024];
|
|
|
- char *cname, *cdesc;
|
|
|
- int ntokens;
|
|
|
- char **tokens;
|
|
|
- struct colordesc csearch, *cfound;
|
|
|
-
|
|
|
- if (!G_getl2(buf, sizeof(buf), fp))
|
|
|
- break;
|
|
|
- strcpy(tok_buf, buf);
|
|
|
- tokens = G_tokenize(tok_buf, ":");
|
|
|
- ntokens = G_number_of_tokens(tokens);
|
|
|
- if (ntokens != 2)
|
|
|
- continue;
|
|
|
-
|
|
|
- cname = G_chop(tokens[0]);
|
|
|
- cdesc = G_chop(tokens[1]);
|
|
|
-
|
|
|
- csearch.name = cname;
|
|
|
- cfound = bsearch(&csearch, colordesc, ncolors,
|
|
|
- sizeof(struct colordesc), cmp_clrname);
|
|
|
-
|
|
|
- if (cfound) {
|
|
|
- cfound->desc = G_store(cdesc);
|
|
|
- }
|
|
|
- G_free_tokens(tokens);
|
|
|
- }
|
|
|
- fclose(fp);
|
|
|
-
|
|
|
- if (opt.colr->answer) {
|
|
|
- struct colordesc csearch, *cfound;
|
|
|
-
|
|
|
- csearch.name = opt.colr->answer;
|
|
|
- cfound = bsearch(&csearch, colordesc, ncolors,
|
|
|
- sizeof(struct colordesc), cmp_clrname);
|
|
|
-
|
|
|
- if (cfound) {
|
|
|
- if (cfound->desc) {
|
|
|
- fprintf(stdout, "%s: %s (%s)\n", cfound->name,
|
|
|
- cfound->desc, cfound->type);
|
|
|
- }
|
|
|
- else {
|
|
|
- fprintf(stdout, "%s: (%s)\n", cfound->name,
|
|
|
- cfound->type);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- for (i = 0; i < ncolors; i++) {
|
|
|
- if (colordesc[i].desc) {
|
|
|
- fprintf(stdout, "%s: %s (%s)\n", colordesc[i].name,
|
|
|
- colordesc[i].desc, colordesc[i].type);
|
|
|
- }
|
|
|
- else {
|
|
|
- fprintf(stdout, "%s: (%s)\n", colordesc[i].name,
|
|
|
- colordesc[i].type);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ G_list_color_rules_description_type(stdout, opt.colr->answer);
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
}
|