25 #include <grass/gis.h>
26 #include <grass/glocale.h>
29 static int read_colors(
const char *,
const char *,
const char *,
31 static int read_new_colors(FILE *,
struct Colors *);
32 static int read_old_colors(FILE *,
struct Colors *);
67 char xname[GNAME_MAX];
69 struct FPRange drange;
84 sprintf(buf,
"colr2/%s", mapset);
85 if (read_colors(buf, name,
G_mapset(), colors) >= 0)
89 switch (read_colors(
"colr", name, mapset, colors)) {
116 G_warning(_(
"color support for [%s] in mapset [%s] %s"), name, mapset,
121 static int read_colors(
const char *element,
const char *
name,
122 const char *mapset,
struct Colors *colors)
135 if (fgets(buf,
sizeof buf, fd) ==
NULL) {
143 stat = read_new_colors(fd, colors);
147 stat = read_old_colors(fd, colors);
148 colors->version = -1;
168 static int read_new_colors(FILE * fd,
struct Colors *colors)
175 char word1[256], word2[256];
181 if (fgets(buf,
sizeof buf, fd) ==
NULL)
185 if (sscanf(buf + 1,
"%lf %lf", &val1, &val2) == 2)
189 while (fgets(buf,
sizeof buf, fd)) {
190 null = undef = fp_rule = 0;
192 n = sscanf(buf,
"%s %s", word1, word2);
196 if (sscanf(word1,
"shift:%lf", &shift) == 1
197 || (strcmp(word1,
"shift:") == 0 &&
198 sscanf(word2,
"%lf", &shift) == 1)) {
202 if (strcmp(word1,
"invert") == 0) {
206 if (strcmp(word1,
"%%") == 0) {
211 switch (sscanf(word1,
"nv:%d:%d:%d", &r1, &g1, &b1)) {
221 switch (sscanf(word1,
"*:%d:%d:%d", &r1, &g1, &b1)) {
231 switch (sscanf(word1,
"%ld:%d:%d:%d", &cat1, &r1, &g1, &b1)) {
238 if (sscanf(word1,
"%lf:%d:%d:%d", &val1, &r1, &g1, &b1) == 4)
240 else if (sscanf(word1,
"%lf:%d", &val1, &r1) == 2) {
248 switch (sscanf(word2,
"%ld:%d:%d:%d", &cat2, &r2, &g2, &b2)) {
259 if (sscanf(word2,
"%lf:%d:%d:%d", &val2, &r2, &g2, &b2) == 4) {
264 else if (sscanf(word2,
"%lf:%d", &val2, &r2) == 2) {
291 b1, (DCELL *) & val2, r2,
295 (CELL) cat2, r2, g2, b2, colors);
300 (DCELL *) & val2, r2, g2, b2,
304 (CELL) cat2, r2, g2, b2, colors);
313 static int read_old_colors(FILE * fd,
struct Colors *colors)
318 float red_f, grn_f, blu_f;
328 if (fgets(buf,
sizeof buf, fd) ==
NULL)
334 if (sscanf(buf + 1,
"%ld", &min) != 1)
346 while (fgets(buf,
sizeof buf, fd)) {
348 if (sscanf(buf,
"%f %f %f", &red_f, &grn_f, &blu_f) != 3)
356 switch (sscanf(buf,
"%d %d %d", &red, &grn, &blu)) {
378 colors->cmax = n - 1;
398 colors->is_float = 1;