10 #include <grass/gis.h>
13 static int read_colors(
const char *,
const char *,
const char *,
15 static int read_new_colors(FILE *,
struct Colors *);
16 static int read_old_colors(FILE *,
struct Colors *);
23 char buf[200], secondary[500], buf2[200], xname[512], xmapset[512];
26 sprintf(buf,
"%s/%s", G3D_DIRECTORY, xname);
27 sprintf(buf2,
"%s@%s", G3D_COLOR_ELEMENT, xmapset);
30 sprintf(buf,
"%s/%s", G3D_DIRECTORY, name);
31 sprintf(buf2,
"%s", G3D_COLOR_ELEMENT);
36 sprintf(secondary,
"%s/%s/%s",
37 G3D_DIRECTORY, G3D_COLOR2_DIRECTORY,
G_mapset());
49 char buf[512], buf2[200];
51 char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
52 struct FPRange drange;
58 if (strcmp(xmapset, mapset) != 0)
63 sprintf(buf,
"%s/%s/%s", G3D_DIRECTORY, G3D_COLOR2_DIRECTORY, mapset);
64 if (read_colors(buf, name,
G_mapset(), colors) >= 0)
74 sprintf(buf,
"%s/%s", G3D_DIRECTORY, name);
75 sprintf(buf2,
"%s", G3D_COLOR_ELEMENT);
79 switch (read_colors(buf, buf2, mapset, colors)) {
96 G_warning(
"color support for [%s] in mapset [%s] %s", name, mapset, err);
100 static int read_colors(
const char *element,
const char *
name,
101 const char *mapset,
struct Colors *colors)
114 if (fgets(buf,
sizeof buf, fd) ==
NULL) {
122 stat = read_new_colors(fd, colors);
126 stat = read_old_colors(fd, colors);
127 colors->version = -1;
145 static int read_new_colors(FILE * fd,
struct Colors *colors)
152 char word1[256], word2[256];
158 if (fgets(buf,
sizeof buf, fd) ==
NULL)
162 if (sscanf(buf + 1,
"%lf %lf", &val1, &val2) == 2)
166 while (fgets(buf,
sizeof buf, fd)) {
167 null = undef = fp_rule = 0;
169 n = sscanf(buf,
"%s %s", word1, word2);
173 if (sscanf(word1,
"shift:%lf", &shift) == 1
174 || (strcmp(word1,
"shift:") == 0 &&
175 sscanf(word2,
"%lf", &shift) == 1)) {
179 if (strcmp(word1,
"invert") == 0) {
183 if (strcmp(word1,
"%%") == 0) {
188 switch (sscanf(word1,
"nv:%d:%d:%d", &r1, &g1, &b1)) {
198 switch (sscanf(word1,
"*:%d:%d:%d", &r1, &g1, &b1)) {
208 switch (sscanf(word1,
"%ld:%d:%d:%d", &cat1, &r1, &g1, &b1)) {
215 if (sscanf(word1,
"%lf:%d:%d:%d", &val1, &r1, &g1, &b1) == 4)
217 else if (sscanf(word1,
"%lf:%d", &val1, &r1) == 2) {
225 switch (sscanf(word2,
"%ld:%d:%d:%d", &cat2, &r2, &g2, &b2)) {
236 if (sscanf(word2,
"%lf:%d:%d:%d", &val2, &r2, &g2, &b2) == 4) {
241 else if (sscanf(word2,
"%lf:%d", &val2, &r2) == 2) {
268 b1, (DCELL *) & val2, r2,
272 (CELL) cat2, r2, g2, b2, colors);
277 (DCELL *) & val2, r2, g2, b2,
281 (CELL) cat2, r2, g2, b2, colors);
290 static int read_old_colors(FILE * fd,
struct Colors *colors)
295 float red_f, grn_f, blu_f;
305 if (fgets(buf,
sizeof buf, fd) ==
NULL)
311 if (sscanf(buf + 1,
"%ld", &min) != 1)
323 while (fgets(buf,
sizeof buf, fd)) {
325 if (sscanf(buf,
"%f %f %f", &red_f, &grn_f, &blu_f) != 3)
333 switch (sscanf(buf,
"%d %d %d", &red, &grn, &blu)) {
355 colors->cmax = n - 1;
366 char element[512], buf[512], buf2[200];
367 char xname[512], xmapset[512];
372 if (strcmp(xmapset, mapset) != 0)
383 sprintf(element,
"%s/%s/%s", G3D_DIRECTORY, G3D_COLOR2_DIRECTORY, mapset);
384 if (strcmp(mapset,
G_mapset()) == 0) {
388 sprintf(buf,
"%s/%s", G3D_DIRECTORY, xname);
389 sprintf(buf2,
"%s@%s", G3D_COLOR_ELEMENT, xmapset);
392 sprintf(buf,
"%s/%s", G3D_DIRECTORY, name);
393 sprintf(buf2,
"%s", G3D_COLOR_ELEMENT);