21#include <grass/symbol.h>
22#include <grass/glocale.h>
24static char key[100], data[500];
37 G_debug(3,
" get_key_data(): %s", buf);
53 G_debug(3,
" key = %s data = %s", key, data);
62 p = (SYMBOL *)G_malloc(
sizeof(SYMBOL));
73 if (s->count == s->alloc) {
76 (SYMBPART **)G_realloc(s->part, s->alloc *
sizeof(SYMBPART *));
78 s->part[s->count] = p;
88 p = (SYMBPART *)G_malloc(
sizeof(SYMBPART));
93 p->color.color = S_COL_DEFAULT;
94 p->fcolor.color = S_COL_DEFAULT;
101 if (p->count == p->alloc) {
104 (SYMBCHAIN **)G_realloc(p->chain, p->alloc *
sizeof(SYMBCHAIN *));
106 p->chain[p->count] = s;
116 p = (SYMBCHAIN *)G_malloc(
sizeof(SYMBCHAIN));
130 if (s->count == s->alloc) {
132 s->elem = (SYMBEL **)G_realloc(s->elem, s->alloc *
sizeof(SYMBEL *));
134 s->elem[s->count] = e;
144 p = (SYMBEL *)G_malloc(
sizeof(SYMBEL));
146 p->coor.line.count = 0;
147 p->coor.line.alloc = 0;
148 p->coor.line.x =
NULL;
149 p->coor.line.y =
NULL;
156 if (el->coor.line.count == el->coor.line.alloc) {
157 el->coor.line.alloc += 10;
158 el->coor.line.x = (
double *)G_realloc(
159 el->coor.line.x, el->coor.line.alloc *
sizeof(
double));
160 el->coor.line.y = (
double *)G_realloc(
161 el->coor.line.y, el->coor.line.alloc *
sizeof(
double));
163 el->coor.line.x[el->coor.line.count] =
x;
164 el->coor.line.y[el->coor.line.count] = y;
165 el->coor.line.count++;
169SYMBEL *
new_arc(
double x,
double y,
double r,
double a1,
double a2,
int c)
173 p = (SYMBEL *)G_malloc(
sizeof(SYMBEL));
175 p->coor.arc.clock = c;
192 while (
G_getl2(buf, 500, fp) != 0) {
196 if ((buf[0] ==
'#') || (buf[0] ==
'\0'))
201 if (strcmp(key,
"END") == 0) {
206 if (sscanf(buf,
"%lf %lf", &
x, &y) != 2) {
207 G_warning(_(
"Cannot read symbol line coordinates: %s"), buf);
216SYMBOL *
err(FILE *fp, SYMBOL *s,
char *msg)
235 char group[500],
name[500], buf[2001], buf2[2048];
238 double x, y, x2, y2, rad, ang1, ang2;
249 G_debug(3,
"S_read(): sname = %s", sname);
253 strcpy(group, sname);
254 c = strchr(group,
'/');
256 G_warning(_(
"Incorrect symbol name: '%s' (should be: group/name or "
257 "group/name@mapset)"),
266 G_debug(3,
" group: '%s' name: '%s'", group,
name);
269 sprintf(buf,
"symbol/%s", group);
276 sprintf(buf,
"%s/etc/symbol/%s",
G_gisbase(), sname);
277 fp = fopen(buf,
"r");
281 G_warning(_(
"Cannot find/open symbol: '%s'"), sname);
291 while (
G_getl2(buf, 2000, fp) != 0) {
296 if ((buf[0] ==
'#') || (buf[0] ==
'\0'))
301 if (strcmp(key,
"VERSION") == 0) {
302 if (strcmp(data,
"1.0") != 0) {
303 sprintf(buf,
"Wrong symbol version: '%s'", data);
304 return (
err(fp, symb, buf));
307 else if (strcmp(key,
"BOX") == 0) {
308 if (sscanf(data,
"%lf %lf %lf %lf", &
x, &y, &x2, &y2) != 4) {
309 sprintf(buf,
"Incorrect box definition: '%s'", data);
310 return (
err(fp, symb, buf));
312 symb->xscale = 1 / (x2 -
x);
313 symb->yscale = 1 / (y2 - y);
314 if (x2 -
x > y2 - y) {
315 symb->scale = symb->xscale;
318 symb->scale = symb->yscale;
321 else if (strcmp(key,
"STRING") == 0) {
330 else if (strcmp(key,
"POLYGON") == 0) {
336 else if (strcmp(key,
"RING") == 0) {
342 else if (strcmp(key,
"LINE") == 0) {
348 else if (strcmp(key,
"ARC") == 0) {
350 ret = sscanf(data,
"%lf %lf %lf %lf %lf %c", &
x, &y, &rad, &ang1,
353 sprintf(buf2,
"Incorrect arc definition: '%s'", buf);
354 return (
err(fp, symb, buf2));
356 if (ret == 6 && (clock ==
'c' || clock ==
'C'))
360 elem =
new_arc(
x, y, rad, ang1, ang2, i);
363 else if (strcmp(key,
"END") == 0) {
379 else if (strcmp(key,
"COLOR") == 0) {
381 part->color.color = S_COL_NONE;
383 else if (sscanf(data,
"%d %d %d", &
r, &
g, &
b) == 3) {
384 if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
385 G_warning(_(
"Incorrect symbol color: '%s', using default."),
391 part->color.color = S_COL_DEFINED;
398 G_debug(4,
" color [%d %d %d] = [%.3f %.3f %.3f]",
r,
g,
b,
403 G_warning(_(
"Incorrect symbol color: '%s', using default."),
407 else if (strcmp(key,
"FCOLOR") == 0) {
409 part->fcolor.color = S_COL_NONE;
411 else if (sscanf(data,
"%d %d %d", &
r, &
g, &
b) == 3) {
412 if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255)
413 G_warning(_(
"Incorrect symbol color: '%s', using default."),
419 part->fcolor.color = S_COL_DEFINED;
423 part->fcolor.fr = fr;
424 part->fcolor.fg = fg;
425 part->fcolor.fb = fb;
426 G_debug(4,
" color [%d %d %d] = [%.3f %.3f %.3f]",
r,
g,
b,
431 G_warning(_(
"Incorrect symbol color: '%s', using default."),
436 sprintf(buf2,
"Unknown keyword in symbol: '%s'", buf);
437 return (
err(fp, symb, buf2));
444 G_debug(3,
"Number of parts: %d", symb->count);
445 for (i = 0; i < symb->count; i++) {
446 part = symb->part[i];
447 G_debug(4,
" Part %d: type: %d number of chains: %d", i, part->type,
449 G_debug(4,
" color: %d: fcolor: %d", part->color.color,
451 for (j = 0; j < part->count; j++) {
452 chain = part->chain[j];
453 G_debug(4,
" Chain %d: number of elements: %d", j, chain->count);
454 for (k = 0; k < chain->count; k++) {
455 elem = chain->elem[k];
456 G_debug(4,
" Element %d: type: %d", k, elem->type);
457 if (elem->type == S_LINE) {
458 G_debug(4,
" Number of points %d",
459 elem->coor.line.count);
460 for (
l = 0;
l < elem->coor.line.count;
l++) {
461 G_debug(4,
" x, y: %f %f", elem->coor.line.x[
l],
462 elem->coor.line.y[
l]);
466 G_debug(4,
" arc r = %f", elem->coor.arc.r);
void G_free(void *buf)
Free allocated memory.
int G_debug(int level, const char *msg,...)
Print debugging message.
const char * G_find_file(const char *element, char *name, const char *mapset)
Searches for a file from the mapset search list or in a specified mapset.
int G_getl2(char *buf, int n, FILE *fd)
Gets a line of text from a file of any pedigree.
void G_warning(const char *msg,...)
Print a warning message to stderr.
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
const char * G_gisbase(void)
Get full path name of the top level module directory.
char * G_chop(char *line)
Chop leading and trailing white spaces.
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
void get_key_data(char *buf)
SYMBCHAIN * new_chain(void)
SYMBPART * new_part(int type)
SYMBEL * new_arc(double x, double y, double r, double a1, double a2, int c)
void add_part(SYMBOL *s, SYMBPART *p)
void add_chain(SYMBPART *p, SYMBCHAIN *s)
void read_coor(FILE *fp, SYMBEL *e)
SYMBOL * new_symbol(void)
SYMBOL * S_read(const char *sname)
void add_point(SYMBEL *el, double x, double y)
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
void add_element(SYMBCHAIN *s, SYMBEL *e)