|
@@ -7,6 +7,11 @@
|
|
|
|
|
|
#define KEY(x) (strcmp(key,x)==0)
|
|
|
|
|
|
+extern FILE *inputfd;
|
|
|
+extern int do_mapinfo;
|
|
|
+extern int do_vlegend;
|
|
|
+extern int ps_copies;
|
|
|
+
|
|
|
static char *help[] = {
|
|
|
"rast rastermap setcolor val_range(s) color",
|
|
|
"vpoints vector points map scalebar [f|s]",
|
|
@@ -26,14 +31,12 @@ static char *help[] = {
|
|
|
""
|
|
|
};
|
|
|
|
|
|
-void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
- int copies_set, int ps_copies, int can_reset_scale,
|
|
|
- struct scalebar *sb, int *do_mapinfo, int *do_vlegend,
|
|
|
- struct PS_group *grp)
|
|
|
+void read_instructions(int copies_set, int can_reset_scale)
|
|
|
{
|
|
|
int i;
|
|
|
int iflag;
|
|
|
- char name[GNAME_MAX], mapset[GMAPSET_MAX];
|
|
|
+ /* name can be fully qualified */
|
|
|
+ char name[GNAME_MAX + GMAPSET_MAX], mapset[GMAPSET_MAX];
|
|
|
char buf[1024];
|
|
|
|
|
|
iflag = 0;
|
|
@@ -44,8 +47,17 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
|
|
|
if (!input(1, buf, help)) {
|
|
|
if (!iflag) {
|
|
|
- if (G_getl2(buf, 12, inputfd))
|
|
|
- G_warning(_("Data exists after final 'end' instruction!"));
|
|
|
+ /* TODO: check also if instructions are piped in
|
|
|
+ * through stdin, not interactive */
|
|
|
+ if (inputfd != stdin) {
|
|
|
+ while (G_getl2(buf, 12, inputfd)) {
|
|
|
+ /* empty lines and comments are fine */
|
|
|
+ if (key_data(buf, &key, &data))
|
|
|
+ G_warning(_("Data exist after final 'end' instruction!"));
|
|
|
+ }
|
|
|
+ fclose(inputfd);
|
|
|
+ inputfd = stdin;
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
iflag = 0;
|
|
@@ -86,11 +98,11 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
|
|
|
n = sscanf(data, "%lf %lf %lf %lf", &x, &y, &w, &h);
|
|
|
if (n == 2 || n == 4) {
|
|
|
- PS->map_x_orig = x;
|
|
|
- PS->map_y_loc = y;
|
|
|
+ PS.map_x_orig = x;
|
|
|
+ PS.map_y_loc = y;
|
|
|
if (n == 4) {
|
|
|
- PS->map_width = w;
|
|
|
- PS->map_height = h;
|
|
|
+ PS.map_width = w;
|
|
|
+ PS.map_height = h;
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
@@ -122,7 +134,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
char colorbuf[100];
|
|
|
char catsbuf[100];
|
|
|
|
|
|
- if (PS->cell_fd < 0)
|
|
|
+ if (PS.cell_fd < 0)
|
|
|
error(key, data, _("no raster map selected yet"));
|
|
|
|
|
|
if (sscanf(data, "%s %[^\n]", catsbuf, colorbuf) == 2) {
|
|
@@ -131,11 +143,11 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
error(key, colorbuf, _("illegal color request"));
|
|
|
|
|
|
if (strncmp(catsbuf, "null", 4) == 0) {
|
|
|
- Rast_set_null_value_color(r, g, b, &(PS->colors));
|
|
|
+ Rast_set_null_value_color(r, g, b, &(PS.colors));
|
|
|
continue;
|
|
|
}
|
|
|
if (strncmp(catsbuf, "default", 7) == 0) {
|
|
|
- Rast_set_default_color(r, g, b, &(PS->colors));
|
|
|
+ Rast_set_default_color(r, g, b, &(PS.colors));
|
|
|
continue;
|
|
|
}
|
|
|
if ((count = parse_val_list(catsbuf, &val_list)) < 0)
|
|
@@ -145,7 +157,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
dmin = val_list[i];
|
|
|
dmax = val_list[i + 1];
|
|
|
Rast_add_d_color_rule(&dmin, r, g, b, &dmax, r, g, b,
|
|
|
- &(PS->colors));
|
|
|
+ &(PS.colors));
|
|
|
}
|
|
|
G_free(val_list);
|
|
|
}
|
|
@@ -153,21 +165,21 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
}
|
|
|
|
|
|
if (KEY("colortable")) {
|
|
|
- PS->do_colortable = 0;
|
|
|
+ PS.do_colortable = 0;
|
|
|
/*
|
|
|
- if (PS->cell_fd < 0)
|
|
|
+ if (PS.cell_fd < 0)
|
|
|
error(key, data, "no raster map selected yet");
|
|
|
else
|
|
|
*/
|
|
|
- PS->do_colortable = yesno(key, data);
|
|
|
- if (PS->do_colortable)
|
|
|
+ PS.do_colortable = yesno(key, data);
|
|
|
+ if (PS.do_colortable)
|
|
|
read_colortable();
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (KEY("border")) {
|
|
|
- PS->do_border = yesno(key, data);
|
|
|
- if (PS->do_border)
|
|
|
+ PS.do_border = yesno(key, data);
|
|
|
+ if (PS.do_border)
|
|
|
read_border();
|
|
|
continue;
|
|
|
}
|
|
@@ -178,11 +190,11 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
_("scalebar is not appropriate for this projection"));
|
|
|
gobble_input();
|
|
|
}
|
|
|
- PS->do_scalebar = 1;
|
|
|
- if (sscanf(data, "%s", sb->type) != 1)
|
|
|
- strcpy(sb->type, "f"); /* default to fancy scalebar */
|
|
|
+ PS.do_scalebar = 1;
|
|
|
+ if (sscanf(data, "%s", sb.type) != 1)
|
|
|
+ strcpy(sb.type, "f"); /* default to fancy scalebar */
|
|
|
read_scalebar();
|
|
|
- if (sb->length <= 0.) {
|
|
|
+ if (sb.length <= 0.) {
|
|
|
error(key, data, _("Bad scalebar length"));
|
|
|
gobble_input();
|
|
|
}
|
|
@@ -285,9 +297,9 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
if (!can_reset_scale)
|
|
|
continue;
|
|
|
if (check_scale(data))
|
|
|
- strcpy(PS->scaletext, data);
|
|
|
+ strcpy(PS.scaletext, data);
|
|
|
else {
|
|
|
- PS->scaletext[0] = 0;
|
|
|
+ PS.scaletext[0] = 0;
|
|
|
error(key, data, _("illegal scale request"));
|
|
|
}
|
|
|
continue;
|
|
@@ -301,24 +313,24 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
|
|
|
if (KEY("header")) {
|
|
|
read_header();
|
|
|
- PS->do_header = 1;
|
|
|
+ PS.do_header = 1;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (KEY("mapinfo")) {
|
|
|
read_info();
|
|
|
- *do_mapinfo = 1;
|
|
|
+ do_mapinfo = 1;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (KEY("vlegend")) {
|
|
|
read_vlegend();
|
|
|
- *do_vlegend = 1;
|
|
|
+ do_vlegend = 1;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (KEY("outline")) {
|
|
|
- if (PS->cell_fd < 0) {
|
|
|
+ if (PS.cell_fd < 0) {
|
|
|
error(key, data, _("no raster map selected yet"));
|
|
|
gobble_input();
|
|
|
}
|
|
@@ -336,15 +348,15 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
if (KEY("greyrast") || KEY("grayrast")) {
|
|
|
if (scan_gis("cell", "raster", key, data, name, mapset, 0))
|
|
|
read_cell(name, mapset);
|
|
|
- PS->grey = 1;
|
|
|
+ PS.grey = 1;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
if (KEY("group")) {
|
|
|
G_strip(data);
|
|
|
if (I_find_group(data)) {
|
|
|
- grp->group_name = G_store(data);
|
|
|
- grp->do_group = 1;
|
|
|
+ grp.group_name = G_store(data);
|
|
|
+ grp.do_group = 1;
|
|
|
read_group();
|
|
|
}
|
|
|
else
|
|
@@ -354,7 +366,7 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
|
|
|
if (KEY("rgb")) {
|
|
|
G_strip(data);
|
|
|
- grp->do_group = 1;
|
|
|
+ grp.do_group = 1;
|
|
|
read_rgb(key, data);
|
|
|
continue;
|
|
|
}
|
|
@@ -385,11 +397,11 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
}
|
|
|
|
|
|
if (KEY("grid")) {
|
|
|
- PS->grid = -1;
|
|
|
- PS->grid_numbers = 0;
|
|
|
- sscanf(data, "%d", &(PS->grid));
|
|
|
- if (PS->grid < 0) {
|
|
|
- PS->grid = 0;
|
|
|
+ PS.grid = -1;
|
|
|
+ PS.grid_numbers = 0;
|
|
|
+ sscanf(data, "%d", &(PS.grid));
|
|
|
+ if (PS.grid < 0) {
|
|
|
+ PS.grid = 0;
|
|
|
error(key, data, _("illegal grid spacing"));
|
|
|
gobble_input();
|
|
|
}
|
|
@@ -406,11 +418,11 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
}
|
|
|
/* if (G_projection() == PROJECTION_LL)
|
|
|
G_message(_("geogrid referenced to [???] ellipsoid")); */
|
|
|
- PS->geogrid = -1.;
|
|
|
- PS->geogrid_numbers = 0;
|
|
|
- sscanf(data, "%d %s", &(PS->geogrid), PS->geogridunit);
|
|
|
- if (PS->geogrid < 0) {
|
|
|
- PS->geogrid = 0;
|
|
|
+ PS.geogrid = -1.;
|
|
|
+ PS.geogrid_numbers = 0;
|
|
|
+ sscanf(data, "%d %s", &(PS.geogrid), PS.geogridunit);
|
|
|
+ if (PS.geogrid < 0) {
|
|
|
+ PS.geogrid = 0;
|
|
|
error(key, data, _("illegal geo-grid spacing"));
|
|
|
gobble_input();
|
|
|
}
|
|
@@ -420,11 +432,11 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
}
|
|
|
|
|
|
if (KEY("psfile")) {
|
|
|
- if (PS->num_psfiles >= MAX_PSFILES)
|
|
|
+ if (PS.num_psfiles >= MAX_PSFILES)
|
|
|
continue;
|
|
|
G_strip(data);
|
|
|
- PS->psfiles[PS->num_psfiles] = G_store(data);
|
|
|
- PS->num_psfiles++;
|
|
|
+ PS.psfiles[PS.num_psfiles] = G_store(data);
|
|
|
+ PS.num_psfiles++;
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -433,10 +445,10 @@ void read_instructions(FILE *inputfd, struct PS_data *PS,
|
|
|
|
|
|
ret = G_str_to_color(data, &r, &g, &b);
|
|
|
if (ret == 1) {
|
|
|
- PS->mask_r = r / 255.0;
|
|
|
- PS->mask_g = g / 255.0;
|
|
|
- PS->mask_b = b / 255.0;
|
|
|
- PS->mask_color = 1;
|
|
|
+ PS.mask_r = r / 255.0;
|
|
|
+ PS.mask_g = g / 255.0;
|
|
|
+ PS.mask_b = b / 255.0;
|
|
|
+ PS.mask_color = 1;
|
|
|
continue;
|
|
|
}
|
|
|
else if (ret == 2) { /* none */
|