int read_labels(char *name, char *mapset) { char fullname[GNAME_MAX + 2 * GMAPSET_MAX + 4]; char buf[1024]; char *key, *data; sprintf(fullname, "%s in %s", name, mapset); if (labels.count >= MAXLABELS) { error(fullname, "", "no more label files allowed"); return 0; } labels.name[labels.count] = G_store(name); labels.mapset[labels.count] = G_store(mapset); while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("font")) { get_font(data); labels.font[labels.count] = G_store(data); continue; } error(key, "", "illegal request (labels)"); } labels.count++; return 1; }
int read_outline(void) { char buf[1024]; char ch, *key, *data; PSCOLOR color; int ret, r, g, b; PS.outline_width = 1.; set_color(&color, 0, 0, 0); while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&color, r, g, b); else if (ret == 2) /* i.e. "none" */ /* unset_color(&color); */ error(key, data, _("Unsupported color request")); else error(key, data, _("illegal color request")); continue; } if (KEY("width")) { PS.outline_width = -1.; ch = ' '; if (sscanf(data, "%lf%c", &(PS.outline_width), &ch) < 1 || PS.outline_width < 0.) { PS.outline_width = 1.; error(key, data, _("illegal width request")); } if (ch == 'i') PS.outline_width = PS.outline_width * 72.; continue; } error(key, data, _("illegal outline sub-request")); } PS.outline_color = color; PS.do_outline = 1; return 0; }
int read_info(void) { char buf[1024]; char *key, *data; int fontsize; double x, y; int r, g, b, ret; PSCOLOR color, bgcolor, border; fontsize = 0; set_color(&color, 0, 0, 0); set_color(&bgcolor, 255, 255, 255); unset_color(&border); x = y = 0.0; while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("where")) { if (sscanf(data, "%lf %lf", &x, &y) != 2) { x = y = 0.0; error(key, data, _("illegal where request")); } else continue; } if (KEY("fontsize")) { fontsize = atoi(data); if (fontsize < 4 || fontsize > 50) fontsize = 0; continue; } if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&color, r, g, b); else if (ret == 2) /* i.e. "none" */ /* unset_color(&color); */ error(key, data, _("Unsupported color request")); else error(key, data, _("illegal color request")); continue; } if (KEY("background")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&bgcolor, r, g, b); else if (ret == 2) /* i.e. "none" */ unset_color(&bgcolor); else error(key, data, _("illegal bgcolor request")); continue; } if (KEY("border")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&border, r, g, b); else if (ret == 2) /* i.e. "none" */ unset_color(&border); else error(key, data, _("illegal border color request")); continue; } if (KEY("font")) { get_font(data); m_info.font = G_store(data); continue; } error(key, data, _("illegal mapinfo sub-request")); } m_info.x = x; m_info.y = y; m_info.color = color; m_info.bgcolor = bgcolor; m_info.border = border; if (fontsize) m_info.fontsize = fontsize; return 0; }
int read_vpoints(char *name, char *mapset) { char fullname[100]; char buf[1024]; char *key, *data; double width, size, scale, rotate; int itmp, vec; int r, g, b; int ret; struct Map_info Map; vector_alloc(); /* allocate space */ sprintf(fullname, "%s in %s", name, mapset); Vect_set_open_level(2); Vect_set_fatal_error(GV_FATAL_PRINT); if (2 > Vect_open_old(&Map, name, mapset)) { error(fullname, "", "can't open vector map"); gobble_input(); return 0; } Vect_close(&Map); vec = vector.count; vector.layer[vec].type = VPOINTS; vector.layer[vec].name = G_store(name); vector.layer[vec].mapset = G_store(mapset); vector.layer[vec].ltype = GV_POINT; vector.layer[vec].masked = 0; vector.layer[vec].field = 1; vector.layer[vec].cats = NULL; vector.layer[vec].where = NULL; vector.layer[vec].width = 1.; set_color(&(vector.layer[vec].color), 0, 0, 0); set_color(&(vector.layer[vec].fcolor), 255, 0, 0); vector.layer[vec].rgbcol = NULL; vector.layer[vec].label = NULL; vector.layer[vec].lpos = -1; vector.layer[vec].symbol = G_store("basic/diamond"); vector.layer[vec].size = 6.0; vector.layer[vec].sizecol = NULL; vector.layer[vec].scale = 1.0; vector.layer[vec].rotate = 0.0; vector.layer[vec].rotcol = NULL; vector.layer[vec].epstype = 0; while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("masked")) { vector.layer[vec].masked = yesno(key, data); if (vector.layer[vec].masked) PS.mask_needed = 1; continue; } if (KEY("type")) { G_strip(data); vector.layer[vec].ltype = 0; if (strstr(data, "point")) vector.layer[vec].ltype |= GV_POINT; if (strstr(data, "centroid")) vector.layer[vec].ltype |= GV_CENTROID; continue; } if (KEY("layer")) { G_strip(data); vector.layer[vec].field = atoi(data); continue; } if (KEY("cats")) { G_strip(data); vector.layer[vec].cats = G_store(data); continue; } if (KEY("where")) { G_strip(data); vector.layer[vec].where = G_store(data); continue; } if (KEY("width")) { width = -1.; *mapset = 0; if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) { width = 1.; error(key, data, "illegal width (vpoints)"); continue; } if (mapset[0] == 'i') width = width / 72.; vector.layer[vec].width = width; continue; } if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&(vector.layer[vec].color), r, g, b); else if (ret == 2) unset_color(&(vector.layer[vec].color)); else error(key, data, "illegal color request"); continue; } if (KEY("fcolor")) { /* fill color */ ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&(vector.layer[vec].fcolor), r, g, b); else if (ret == 2) unset_color(&(vector.layer[vec].fcolor)); else error(key, data, "illegal color request (vpoints)"); continue; } if (KEY("rgbcolumn")) { G_strip(data); vector.layer[vec].rgbcol = G_store(data); continue; } if (KEY("label")) { /* map legend label */ G_strip(data); vector.layer[vec].label = G_store(data); continue; } if (KEY("lpos")) { if (sscanf(data, "%d", &itmp) < 1 || itmp < 0) { itmp = -1; error(key, data, "illegal lpos"); continue; } vector.layer[vec].lpos = itmp; continue; } if (KEY("symbol")) { /* TODO: test here if isymbol exists */ vector.layer[vec].symbol = G_store(data); continue; } if (KEY("eps")) { char *cc; G_chop(data); vector.layer[vec].epspre = G_store(data); /* epstype: 0 - no eps, 1 - common eps, 2 - eps for each category */ vector.layer[vec].epstype = 1; /* find dynamic filename by cat number character */ /* pre is filename before the $, suf is filename after the $ */ cc = (char *)strchr(vector.layer[vec].epspre, '$'); if (cc != NULL) { *cc = '\0'; vector.layer[vec].epssuf = G_store(cc + sizeof(char)); vector.layer[vec].epstype = 2; G_debug(2, "epstype=%d, pre=[%s], suf=[%s]", vector.layer[vec].epstype, vector.layer[vec].epspre, vector.layer[vec].epssuf); } else { G_debug(2, "epstype=%d, eps file=[%s]", vector.layer[vec].epstype, vector.layer[vec].epspre); } continue; } if (KEY("size")) { if (sscanf(data, "%lf", &size) != 1 || size <= 0.0) { size = 1.0; error(key, data, "illegal size request (vpoints)"); } vector.layer[vec].size = size; continue; } /* GRASS 6.3: sizecol renamed to sizecolumn remove sizecol test and the warning in GRASS7 */ if (KEY("sizecol")) { G_warning(_("The mapping instruction <%s> will be renamed to <%s> " "in future versions of GRASS. Please use <%s> instead."), "sizecol", "sizecolumn", "sizecolumn"); } if (KEY("sizecol") || KEY("sizecolumn")) { G_strip(data); vector.layer[vec].sizecol = G_store(data); continue; } if (KEY("scale")) { if (sscanf(data, "%lf", &scale) != 1 || scale <= 0.0) { scale = 1.0; error(key, data, "illegal scale request (vpoints)"); } vector.layer[vec].scale = scale; continue; } if (KEY("rotate")) { if (sscanf(data, "%lf", &rotate) != 1) { rotate = 0.0; error(key, data, "illegal rotation request (vpoints)"); } vector.layer[vec].rotate = rotate; continue; } if (KEY("rotatecolumn")) { G_strip(data); vector.layer[vec].rotcol = G_store(data); continue; } error(key, "", "illegal request (vpoints)"); } vector.count++; return 1; }
int read_scalebar(void) { char buf[1024]; char *key, *data; char ch; /* struct defined in decorate.h */ sb.segment = 4; /* four segments */ sb.numbers = 1; /* label each segment */ sb.font = G_store("Helvetica"); sb.fontsize = 8; sb.color = BLACK; /* TODO: multi-color */ sb.width = 1.; sb.length = -1.; sb.height = 0.1; /* default height in inches */ sb.x = PS.page_width / 2.; sb.y = 2.; sb.bgcolor = 1; /* TODO: multi-color */ sb.units = SB_UNITS_AUTO; /* default to automatic based on value in PROJ_UNITS */ while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("where")) { if (sscanf(data, "%lf %lf", &sb.x, &sb.y) != 2) { error(key, data, "illegal where request"); } else continue; } if (KEY("height")) { if (sscanf(data, "%lf", &sb.height) != 1 || sb.height <= 0.) { error(key, data, "illegal height request"); } else continue; } if (KEY("length")) { if (sscanf(data, "%lf", &sb.length) != 1 || sb.length <= 0.) { error(key, data, "illegal length request"); } else continue; } if (KEY("units")) { G_strip(data); if (strcmp(data, "auto") == 0) { sb.units = SB_UNITS_AUTO; continue; } else if (G_projection() == PROJECTION_XY) { error(key, data, "Earth units not available in simple XY location"); } else if (strcmp(data, "meters") == 0) { sb.units = SB_UNITS_METERS; continue; } else if (strcmp(data, "kilometers") == 0 || strcmp(data, "km") == 0) { sb.units = SB_UNITS_KM; continue; } else if (strcmp(data, "feet") == 0) { sb.units = SB_UNITS_FEET; continue; } else if (strcmp(data, "miles") == 0) { sb.units = SB_UNITS_MILES; continue; } else if (strcmp(data, "nautmiles") == 0 || strcmp(data, "nm") == 0) { sb.units = SB_UNITS_NMILES; continue; } else error(key, data, "illegal units request"); } if (KEY("segment")) { if (sscanf(data, "%d", &sb.segment) != 1 || sb.segment <= 0) { error(key, data, "illegal segment request"); } else continue; } if (KEY("numbers")) { if (sscanf(data, "%d", &sb.numbers) != 1 || sb.numbers <= 0) { error(key, data, "illegal numbers request"); } else continue; } if (KEY("font")) { get_font(data); G_free(sb.font); sb.font = G_store(data); continue; } if (KEY("fontsize")) { if (sscanf(data, "%d", &sb.fontsize) != 1 || sb.fontsize <= 0) { error(key, data, "illegal fontsize request"); } else continue; } if (KEY("color")) { sb.color = get_color_number(data); if (sb.color < 0) { sb.color = BLACK; error(key, data, "illegal color request"); } continue; } if (KEY("background")) { sb.bgcolor = yesno(key, data); continue; } if (KEY("width")) { sb.width = -1.; ch = ' '; if ((sscanf(data, "%lf%c", &sb.width, &ch) < 1) || (sb.width < 0.)) { sb.width = 1.; error(key, data, "illegal grid width request"); } if (ch == 'i') sb.width = sb.width * 72.0; continue; } error(key, data, "illegal request (scalebar)"); } return 0; }
int read_header(void) { char buf[1024]; char *key, *data; int fontsize; PSCOLOR color; int ret, r, g, b; fontsize = 0; set_color(&color, 0, 0, 0); while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("none")) { PS.do_header = 0; continue; } if (KEY("file")) { G_strip(data); hdr.fp = fopen(data, "r"); if (hdr.fp != NULL) hdr.file = G_store(data); continue; } if (KEY("fontsize")) { fontsize = atoi(data); if (fontsize < 4 || fontsize > 50) fontsize = 0; continue; } if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&color, r, g, b); else if (ret == 2) /* i.e. "none" */ /* unset_color(&color); */ error(key, data, _("Unsupported color request")); else error(key, data, _("illegal color request")); continue; } if (KEY("font")) { get_font(data); hdr.font = G_store(data); continue; } error(key, data, _("illegal header sub-request")); } hdr.color = color; if (fontsize) hdr.fontsize = fontsize; return 0; }
int read_text(char *east, char *north, char *text) { PSCOLOR color, hcolor, background, border; int r, g, b; int ret; int xoffset; int yoffset; float size; int fontsize; double width; double hwidth; double rotate; int xref, yref; int opaque; char t1[128]; char buf[1024]; char *key, *data; FILE *fd; char fontname[128]; set_color(&color, 0, 0, 0); /* black */ unset_color(&hcolor); unset_color(&background); unset_color(&border); opaque = TRUE; size = 0.0; fontsize = 0; xoffset = 0; yoffset = 0; width = 1.; hwidth = 0.; rotate = 0.0; xref = CENTER; yref = CENTER; G_strcpy(fontname, "Helvetica"); while (*text == ' ' || *text == '\t') text++; if (*text == '\\') text++; if (*text == 0) { error("text", "", "no text given"); gobble_input(); return 0; } while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("font")) { get_font(data); strcpy(fontname, data); continue; } if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&color, r, g, b); else if (ret == 2) error(key, data, "primary color cannot be \"none\""); else error(key, data, "illegal color request"); continue; } if (KEY("hcolor")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&hcolor, r, g, b); else if (ret == 2) unset_color(&hcolor); else error(key, data, "illegal hcolor request"); if (color_none(&hcolor) || hwidth <= 0.) hwidth = 0.; continue; } if (KEY("background")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&background, r, g, b); else if (ret == 2) { unset_color(&background); opaque = FALSE; } else error(key, data, "illegal background color request"); continue; } if (KEY("border")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&border, r, g, b); else if (ret == 2) unset_color(&border); else error(key, data, "illegal border color request"); continue; } if (KEY("opaque")) { opaque = yesno(key, data); continue; } if (KEY("width")) { width = -1.; *t1 = 0; if (sscanf(data, "%lf%1s", &width, t1) < 1 || width < 0.) { width = 1.; error(key, data, "illegal width request"); } if (t1 && t1[0] == 'i') width = width / 72.0; continue; } if (KEY("hwidth")) { hwidth = -1.; *t1 = 0; if (sscanf(data, "%lf%1s", &hwidth, t1) < 1 || hwidth < 0.) { hwidth = 0.; error(key, data, "illegal width request"); } if (t1 && t1[0] == 'i') hwidth = hwidth / 72.0; continue; } if (KEY("size")) { double x; if (!scan_resolution(data, &x)) { size = 0.0; error(key, data, "illegal size request"); } else size = x; continue; } if (KEY("fontsize")) { if (sscanf(data, "%d", &fontsize) != 1 || fontsize <= 0) { error(key, data, "illegal fontsize request"); } else continue; } if (KEY("xoffset")) { *t1 = 0; if (sscanf(data, "%d%1s", &xoffset, t1) != 1 || *t1) { xoffset = 0; error(key, data, "illegal request (text)"); } continue; } if (KEY("yoffset")) { *t1 = 0; if (sscanf(data, "%d%1s", &yoffset, t1) != 1 || *t1) { yoffset = 0; error(key, data, "illegal request (text)"); } continue; } if (KEY("rotate")) { if (sscanf(data, "%lf", &rotate) != 1) { rotate = 0.0; error(key, data, "illegal rotate request"); } continue; } if (KEY("ref")) { if (!scan_ref(data, &xref, &yref)) { xref = CENTER; yref = CENTER; error(key, data, "illegal ref request"); } continue; } error(key, data, "illegal request (text)"); } /* if file doesn't exist create it and close it */ if (labels.other == NULL) { labels.other = G_tempfile(); if ((fd = fopen(labels.other, "w")) != NULL) fclose(fd); } /* open file in append mode */ fd = fopen(labels.other, "a"); if (fd == NULL) { error("misc labels file", "", "can't open"); return 1; } /* write the file */ fprintf(fd, "font: %s\n", fontname); fprintf(fd, "east: %s\n", east); fprintf(fd, "north: %s\n", north); fprintf(fd, "xoffset: %d\n", xoffset); fprintf(fd, "yoffset: %d\n", yoffset); fprintf(fd, "width: %f\n", width); fprintf(fd, "hwidth: %f\n", hwidth); fprintf(fd, "size: %f\n", size); fprintf(fd, "fontsize: %d\n", fontsize); fprintf(fd, "opaque: %s\n", opaque ? "yes" : "no"); if (rotate != 0) fprintf(fd, "rotate: %f\n", rotate); fprintf(fd, "color: "); if (!color_none(&color)) fprintf(fd, "%d:%d:%d\n", color.r, color.g, color.b); else fprintf(fd, "black\n"); fprintf(fd, "hcolor: "); if (!color_none(&hcolor)) fprintf(fd, "%d:%d:%d\n", hcolor.r, hcolor.g, hcolor.b); else fprintf(fd, "none\n"); fprintf(fd, "background: "); if (!color_none(&background)) fprintf(fd, "%d:%d:%d\n", background.r, background.g, background.b); else fprintf(fd, "none\n"); fprintf(fd, "border: "); if (!color_none(&border)) fprintf(fd, "%d:%d:%d\n", border.r, border.g, border.b); else fprintf(fd, "none\n"); fprintf(fd, "ref: "); switch (yref) { case UPPER: fprintf(fd, "upper"); break; case LOWER: fprintf(fd, "lower"); break; case CENTER: fprintf(fd, "center"); break; } switch (xref) { case LEFT: fprintf(fd, " left"); break; case RIGHT: fprintf(fd, " right"); break; case CENTER: fprintf(fd, "%s", (xref == CENTER) ? "" : " center"); break; } fprintf(fd, "\n"); fprintf(fd, "text:%s\n\n", text); fclose(fd); return 0; }
int read_point(double e, double n) { char buf[1024], symb[1024]; int r, g, b; int color_R, color_G, color_B; int fcolor_R, fcolor_G, fcolor_B; int ret; double size, width, rotate; int have_icon; char ch; char *key, *data; int masked; static char *help[] = { "color color", "fcolor fill color", "symbol group/symbol", "size #", "width #", "rotate #", "masked [y|n]", "" }; size = 6.0; width = -1.0; /* default is proportionate to symbol size */ rotate = 0.0; have_icon = 0; masked = 0; color_R = color_G = color_B = 0; fcolor_R = fcolor_G = fcolor_B = 128; while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("masked")) { masked = yesno(key, data); if (masked) PS.mask_needed = 1; continue; } if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) { color_R = r; color_G = g; color_B = b; } else if (ret == 2) /* i.e. "none" */ color_R = color_G = color_B = -1; else error(key, data, "illegal color request"); continue; } if (KEY("fcolor")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) { fcolor_R = r; fcolor_G = g; fcolor_B = b; } else if (ret == 2) /* i.e. "none" */ fcolor_R = fcolor_G = fcolor_B = -1; else error(key, data, "illegal color request"); continue; } if (KEY("symbol")) { /* TODO: check if exists */ strcpy(symb, data); continue; } if (KEY("size")) { if (sscanf(data, "%lf", &size) != 1 || size <= 0.0) { size = 1.0; error(key, data, "illegal size request"); } continue; } if (KEY("width")) { ch = ' '; if (sscanf(data, "%lf%c", &width, &ch) < 1 || width < 0.) { width = 1.; error(key, data, "illegal width request"); } if (ch == 'i') width = width * 72.; continue; } if (KEY("rotate")) { if (sscanf(data, "%lf", &rotate) != 1) { rotate = 0.0; error(key, data, "illegal rotate request"); } continue; } error(key, data, "illegal point request"); } sprintf(buf, "P %d %f %f %d %d %d %d %d %d %f %f %s %.2f", masked, e, n, color_R, color_G, color_B, fcolor_R, fcolor_G, fcolor_B, size, rotate, symb, width); add_to_plfile(buf); return 0; }
int read_rectangle(double e1, double n1, double e2, double n2) { char buf[300]; int r, g, b; int color_R, color_G, color_B; int fcolor_R, fcolor_G, fcolor_B; int ret; double width; int masked; char ch, *key, *data; static char *help[] = { "color color", "fcolor fill color", "width #", "masked [y|n]", "" }; width = 1.; masked = 0; color_R = color_G = color_B = 0; fcolor_R = fcolor_G = fcolor_B = -1; /* not filled by default */ while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("masked")) { masked = yesno(key, data); if (masked) PS.mask_needed = 1; continue; } if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) { color_R = r; color_G = g; color_B = b; } else if (ret == 2) /* i.e. "none" */ color_R = color_G = color_B = -1; else error(key, data, "illegal color request"); continue; } if (KEY("fcolor")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) { fcolor_R = r; fcolor_G = g; fcolor_B = b; } else if (ret == 2) /* i.e. "none" */ fcolor_R = fcolor_G = fcolor_B = -1; else error(key, data, "illegal color request"); continue; } if (KEY("width")) { ch = ' '; if (sscanf(data, "%lf%c", &width, &ch) < 1 || width < 0.) { width = 1.; error(key, data, "illegal width request"); } if (ch == 'i') width = width * 72.; continue; } error(key, data, "illegal rectangle request"); } sprintf(buf, "R %d %f %f %f %f %d %d %d %d %d %d %.2f", masked, e1, n1, e2, n2, color_R, color_G, color_B, fcolor_R, fcolor_G, fcolor_B, width); add_to_plfile(buf); return 0; }
int read_eps(double e, double n) { char buf[1024], eps_file[GPATH_MAX]; char *eps; double scale, rotate; int have_eps; char *key, *data; int masked; FILE *fp; static char *help[] = { "epsfile EPS file", "scale #", "rotate #", "masked [y|n]", "" }; scale = 1.0; rotate = 0.0; have_eps = 0; masked = 0; while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("masked")) { masked = yesno(key, data); if (masked) PS.mask_needed = 1; continue; } if (KEY("epsfile")) { G_chop(data); /* expand "$GISBASE" if present */ if (strncmp(data, "$GISBASE", 8) != 0) strcpy(eps_file, data); else { strcpy(eps_file, G_gisbase()); data += 8; strcat(eps_file, data); } eps = G_store(eps_file); /* test if file is accessible */ if ((fp = fopen(eps, "r")) == NULL) error(key, data, _("Can't open eps file")); have_eps = 1; fclose(fp); continue; } if (KEY("scale")) { if (sscanf(data, "%lf", &scale) != 1 || scale <= 0.0) { scale = 1.0; error(key, data, "illegal scale request"); } continue; } if (KEY("rotate")) { if (sscanf(data, "%lf", &rotate) != 1) { rotate = 0.0; error(key, data, "illegal rotate request"); } continue; } error(key, data, "illegal eps request"); } if (have_eps) { sprintf(buf, "E %d %f %f %f %f %s", masked, e, n, scale, rotate, eps); } add_to_plfile(buf); return 0; }
int read_vlines(char *name, char *mapset) { char fullname[GNAME_MAX]; char buf[1024]; char *key, *data, *dp; double width; int itmp, vec; int r, g, b; int ret; struct Map_info Map; vector_alloc(); /* allocate space */ sprintf(fullname, "%s in %s", name, mapset); Vect_set_open_level(2); Vect_set_fatal_error(GV_FATAL_PRINT); if (2 > Vect_open_old(&Map, name, mapset)) { error(fullname, "", "can't open vector map"); gobble_input(); return 0; } Vect_close(&Map); vec = vector.count; vector.layer[vec].type = VLINES; vector.layer[vec].name = G_store(name); vector.layer[vec].mapset = G_store(mapset); vector.layer[vec].ltype = GV_LINE; vector.layer[vec].masked = 0; vector.layer[vec].field = 1; vector.layer[vec].cats = NULL; vector.layer[vec].where = NULL; vector.layer[vec].width = 1.; vector.layer[vec].cwidth = 0.; vector.layer[vec].offset = 0.; vector.layer[vec].coffset = 0.; set_color(&(vector.layer[vec].color), 0, 0, 0); vector.layer[vec].rgbcol = NULL; vector.layer[vec].linestyle = NULL; vector.layer[vec].linecap = LINECAP_BUTT; vector.layer[vec].ref = LINE_REF_CENTER; vector.layer[vec].hwidth = 0.; unset_color(&(vector.layer[vec].hcolor)); vector.layer[vec].label = NULL; vector.layer[vec].lpos = -1; vector.layer[vec].pwidth = 1.; while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("masked")) { vector.layer[vec].masked = yesno(key, data); if (vector.layer[vec].masked) PS.mask_needed = 1; continue; } if (KEY("type")) { G_strip(data); vector.layer[vec].ltype = 0; if (strstr(data, "line")) vector.layer[vec].ltype |= GV_LINE; if (strstr(data, "boundary")) vector.layer[vec].ltype |= GV_BOUNDARY; continue; } if (KEY("layer")) { G_strip(data); vector.layer[vec].field = atoi(data); continue; } if (KEY("cats")) { G_strip(data); vector.layer[vec].cats = G_store(data); continue; } if (KEY("where")) { G_strip(data); vector.layer[vec].where = G_store(data); continue; } if (KEY("style")) { G_strip(data); if (strcmp(data, "solid") == 0) { vector.layer[vec].linestyle = NULL; continue; } else if (strcmp(data, "dashed") == 0) { vector.layer[vec].linestyle = G_store("000000111"); continue; } else if (strcmp(data, "dotted") == 0) { vector.layer[vec].linestyle = G_store("100000"); continue; } else if (strcmp(data, "dashdotted") == 0) { vector.layer[vec].linestyle = G_store("000000111011111"); continue; } for (dp = data; *dp; dp++) if (*dp < '0' || *dp > '9') break; if (*dp != 0 || dp == data) { error(key, data, "illegal line style (vlines)"); continue; } vector.layer[vec].linestyle = G_store(data); continue; } if (KEY("linecap")) { G_strip(data); if (strcmp(data, "butt") == 0) { vector.layer[vec].linecap = LINECAP_BUTT; continue; } else if (strcmp(data, "round") == 0) { vector.layer[vec].linecap = LINECAP_ROUND; continue; } else if (strcmp(data, "extended_butt") == 0) { vector.layer[vec].linecap = LINECAP_EXTBUTT; continue; } else error(key, data, "illegal line cap (vlines)"); continue; } if (KEY("width")) { width = -1.; *mapset = 0; if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) { width = 1.; error(key, data, "illegal width (vlines)"); continue; } if (mapset[0] == 'i') width = width / 72.; vector.layer[vec].width = width; continue; } if (KEY("cwidth")) { width = -1.; *mapset = 0; if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) { width = 1.; error(key, data, "illegal cwidth (vlines)"); continue; } if (mapset[0] == 'i') width = width / 72.; vector.layer[vec].cwidth = width; continue; } if (KEY("offset")) { *mapset = 0; if (sscanf(data, "%lf%s", &width, mapset) < 1) { width = 0.; error(key, data, "illegal offset (vlines)"); continue; } if (mapset[0] == 'i') width = width / 72.; vector.layer[vec].offset = width; continue; } if (KEY("coffset")) { *mapset = 0; if (sscanf(data, "%lf%s", &width, mapset) < 1) { width = 0.; error(key, data, "illegal coffset (vlines)"); continue; } if (mapset[0] == 'i') width = width / 72.; vector.layer[vec].coffset = width; continue; } if (KEY("hwidth")) { width = -1.; if (sscanf(data, "%lf%s", &width, mapset) < 1 || width < 0.) { width = 0.; error(key, data, "illegal hwidth (vlines)"); continue; } if (mapset[0] == 'i') width = width / 72.; vector.layer[vec].hwidth = width; continue; } if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&(vector.layer[vec].color), r, g, b); else if (ret == 2) unset_color(&(vector.layer[vec].color)); else error(key, data, "illegal color request (vlines)"); continue; } if (KEY("rgbcolumn")) { G_strip(data); vector.layer[vec].rgbcol = G_store(data); continue; } if (KEY("hcolor")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&(vector.layer[vec].hcolor), r, g, b); else if (ret == 2) unset_color(&(vector.layer[vec].hcolor)); else error(key, data, "illegal hcolor request (vlines)"); continue; } if (KEY("label")) { /* map legend label */ G_strip(data); vector.layer[vec].label = G_store(data); continue; } if (KEY("lpos")) { if (sscanf(data, "%d", &itmp) < 1 || itmp < 0) { itmp = -1; error(key, data, "illegal lpos (vlines)"); continue; } vector.layer[vec].lpos = itmp; continue; } if (KEY("ref")) { G_strip(data); if (strcmp(data, "left") == 0) { vector.layer[vec].ref = LINE_REF_LEFT; continue; } if (strcmp(data, "right") == 0) { vector.layer[vec].ref = LINE_REF_RIGHT; continue; } error(key, data, "illegal ref request (vlines)"); continue; } if (KEY("scale")) { G_strip(data); vector.layer[vec].scale = atof(data); continue; } error(key, "", "illegal request (vlines)"); } vector.count++; return 1; }
int read_border(void) { char buf[1024]; char *key, *data; double width; char ch; int r, g, b; double color_R, color_G, color_B; int ret; static char *help[] = { "color name", "width #", "" }; G_debug(1, "Reading border settings .."); width = 1.; color_R = color_G = color_B = 0.; while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) { color_R = r / 255.; color_G = g / 255.; color_B = b / 255.; } else if (ret == 2) /* i.e. "none" */ color_R = color_G = color_B = -1.; else error(key, data, "illegal border color request"); continue; } if (KEY("width")) { ch = ' '; if (sscanf(data, "%lf%c", &width, &ch) < 1 || width < 0.) { width = 1.; error(key, data, "illegal border width request"); } /* if asked for in inches */ if (ch == 'i') width = width * 72.; continue; } error(key, data, "illegal border sub-request"); } brd.R = color_R; brd.G = color_G; brd.B = color_B; brd.width = width; return 0; }
int getgrid(void) { int spacing; int fontsize = PS_FONT_DEFAULT_SIZE; int ret, r, g, b; char temp[30]; char buf[1024]; char ch, *key, *data; PSCOLOR color, text_color; PS.grid_font = G_store("Helvetica"); PS.grid_fontsize = 0; PS.grid_numbers = 0; PS.grid_cross = 0.; PS.grid_width = 0.25; set_color(&color, 0, 0, 0); set_color(&text_color, 0, 0, 0); while (input(2, buf, help)) { if (!key_data(buf, &key, &data)) continue; if (KEY("color")) { ret = G_str_to_color(data, &r, &g, &b); if (ret == 1) set_color(&color, r, g, b); else if (ret == 2) /* i.e. "none" */ /* unset_color(&color); */ error(key, data, _("Unsupported color request")); else error(key, data, _("illegal color request")); continue; } if (KEY("numbers")) { spacing = -1; if (strlen(data) == 0) { spacing = 1; set_color(&text_color, 0, 0, 0); } switch (sscanf(data, "%d %[^\n]", &spacing, temp)) { case 1: set_color(&text_color, 0, 0, 0); break; case 2: ret = G_str_to_color(temp, &r, &g, &b); if (ret == 1) set_color(&text_color, r, g, b); else if (ret == 2) /* i.e. "none" */ error(key, data, _("Unsupported color request")); else error(key, data, _("illegal color request")); if (ret < 1) spacing = -1; break; } if (spacing < 0) error(key, data, _("illegal numbers request")); else { PS.grid_numbers = spacing; PS.grid_numbers_color = text_color; } continue; } if (KEY("cross")) { PS.grid_cross = atof(data); continue; } if (KEY("fontsize")) { fontsize = atoi(data); if (fontsize < PS_FONT_MIN_SIZE || fontsize > PS_FONT_MAX_SIZE) fontsize = PS_FONT_DEFAULT_SIZE; continue; } if (KEY("font")) { get_font(data); PS.grid_font = G_store(data); continue; } if (KEY("width")) { PS.grid_width = -1.; ch = ' '; if ((sscanf(data, "%lf%c", &PS.grid_width, &ch) < 1) || (PS.grid_width < 0.)) { PS.grid_width = 1.; error(key, data, _("illegal grid width request")); } if (ch == 'i') PS.grid_width = PS.grid_width * 72.0; continue; } error(key, data, _("illegal request (grid)")); } PS.grid_fontsize = fontsize; PS.grid_color = color; return 0; }