3
#include <grass/colors.h>
4
#include <grass/imagery.h>
5
#include <grass/glocale.h>
6
#include "local_proto.h"
8
#define KEY(x) (strcmp(key,x)==0)
11
extern int do_mapinfo;
12
extern int do_vlegend;
15
static char *help[] = {
16
"cell rastermap rast rastermap",
17
"raster rastermap group imagery group",
18
"greyrast greyscale rastermap grayrast grayscale rastermap",
19
"rgb 3 rastermaps for RGB setcolor val_range(s) color",
20
"vpoints vector points map scalebar [f|s]",
21
"vlines vector lines map paper [a4|a3|us-letter|...]",
22
"vareas vector areas map maploc x y [width height]",
23
"labels labelfile text east north text",
24
"region regionfile line east north east north",
25
"grid spacing point east north",
26
"geogrid spacing header header text",
27
"colortable [y|n] vlegend vector legend",
28
"comments [unix-file] psfile PostScript include file",
29
"read unix-file eps Encapsulated PostScript file",
30
"border [y|n] mapinfo map information",
31
"window region definition region region definition",
32
"maskcolor MASK color",
33
"rectangle east north east north",
34
"scale 1:#|# inches|# panels|1 inch = # miles",
35
"outline map composition outline",
36
"copies number of copies",
40
void read_instructions(int copies_set, int can_reset_scale)
44
/* name can be fully qualified */
45
char name[GNAME_MAX + GMAPSET_MAX], mapset[GMAPSET_MAX];
54
if (!input(1, buf, help)) {
56
/* TODO: check also if instructions are piped in
57
* through stdin, not interactive */
58
if (inputfd != stdin) {
59
while (G_getl2(buf, 12, inputfd)) {
60
/* empty lines and comments are fine */
61
if (key_data(buf, &key, &data))
62
G_warning(_("Data exist after final 'end' instruction!"));
72
if (!key_data(buf, &key, &data))
79
if (sscanf(data, "%s", name) != 1) {
80
error(key, data, _("no file specified"));
83
else if ((inputfd = fopen(name, "r")) == NULL) {
84
error(key, data, _("unable to open"));
93
if (strlen(data) > 0) {
105
n = sscanf(data, "%lf %lf %lf %lf", &x, &y, &w, &h);
106
if (n == 2 || n == 4) {
115
error(key, data, _("illegal maploc request"));
126
n = sscanf(data, "%d", &copies);
127
if (n != 1 || copies < 1 || copies > 20) {
129
error(key, data, _("illegal copies request"));
135
if (KEY("setcolor")) {
144
error(key, data, _("no raster map selected yet"));
146
if (sscanf(data, "%s %[^\n]", catsbuf, colorbuf) == 2) {
147
ret = G_str_to_color(colorbuf, &r, &g, &b);
149
error(key, colorbuf, _("illegal color request"));
151
if (strncmp(catsbuf, "null", 4) == 0) {
152
Rast_set_null_value_color(r, g, b, &(PS.colors));
155
if (strncmp(catsbuf, "default", 7) == 0) {
156
Rast_set_default_color(r, g, b, &(PS.colors));
159
if ((count = parse_val_list(catsbuf, &val_list)) < 0)
160
error(key, data, _("illegal value list"));
162
for (i = 0; i < count; i += 2) {
164
dmax = val_list[i + 1];
165
Rast_add_d_color_rule(&dmin, r, g, b, &dmax, r, g, b,
173
if (KEY("colortable")) {
174
PS.do_colortable = 0;
177
error(key, data, "no raster map selected yet");
180
PS.do_colortable = yesno(key, data);
181
if (PS.do_colortable)
187
PS.do_border = yesno(key, data);
193
if (KEY("scalebar")) {
194
if (G_projection() == PROJECTION_LL) {
196
_("scalebar is not appropriate for this projection"));
200
if (sscanf(data, "%s", sb.type) != 1)
201
strcpy(sb.type, "f"); /* default to fancy scalebar */
203
if (sb.length <= 0.) {
204
error(key, data, _("Bad scalebar length"));
212
char east[50], north[50];
215
if (sscanf(data, "%s %s %[^\n]", east, north, text) == 3
216
&& (scan_easting(east, &e) && scan_northing(north, &n)))
217
read_text(east, north, text);
220
error(key, data, _("illegal text request"));
227
char east[50], north[50];
229
if (sscanf(data, "%s %s", east, north) == 2
230
&& (scan_easting(east, &e) && scan_northing(north, &n)))
234
error(key, data, _("illegal point request"));
241
char east[50], north[50];
243
if (sscanf(data, "%s %s", east, north) == 2
244
&& (scan_easting(east, &e) && scan_northing(north, &n)))
248
error(key, data, _("illegal eps request"));
254
char east1[50], north1[50];
255
char east2[50], north2[50];
256
double e1, n1, e2, n2;
258
if (sscanf(data, "%s %s %s %s", east1, north1, east2, north2) == 4
259
&& (scan_easting(east1, &e1) && scan_easting(east2, &e2)
260
&& scan_northing(north1, &n1) &&
261
scan_northing(north2, &n2)))
262
read_line(e1, n1, e2, n2);
265
error(key, data, _("illegal line request"));
270
if (KEY("rectangle")) {
271
char east1[50], north1[50];
272
char east2[50], north2[50];
273
double e1, n1, e2, n2;
275
if (sscanf(data, "%s %s %s %s", east1, north1, east2, north2) == 4
276
&& (scan_easting(east1, &e1) && scan_easting(east2, &e2)
277
&& scan_northing(north1, &n1) &&
278
scan_northing(north2, &n2)))
279
read_rectangle(e1, n1, e2, n2);
282
error(key, data, _("illegal rectangle request"));
287
if (KEY("comments")) {
288
switch (sscanf(data, "%s %s", name, mapset)) {
293
error(key, data, _("illegal comments request"));
303
if (!can_reset_scale)
305
if (check_scale(data))
306
strcpy(PS.scaletext, data);
309
error(key, data, _("illegal scale request"));
315
if (scan_gis("paint/labels", "label", key, data, name, mapset, 1))
316
read_labels(name, mapset);
326
if (KEY("mapinfo")) {
332
if (KEY("vlegend")) {
338
if (KEY("outline")) {
339
if (PS.cell_fd < 0) {
340
error(key, data, _("no raster map selected yet"));
348
if (KEY("cell") || KEY("rast") || KEY("raster")) {
349
if (scan_gis("cell", "raster", key, data, name, mapset, 0))
350
read_cell(name, mapset);
354
if (KEY("greyrast") || KEY("grayrast")) {
355
if (scan_gis("cell", "raster", key, data, name, mapset, 0))
356
read_cell(name, mapset);
363
if (I_find_group(data)) {
364
grp.group_name = G_store(data);
369
error(key, data, _("group not found"));
380
if (KEY("vpoints")) {
381
if (scan_gis("vector", "vector", key, data, name, mapset, 1))
382
read_vpoints(name, mapset);
387
if (scan_gis("vector", "vector", key, data, name, mapset, 1))
388
read_vlines(name, mapset);
393
if (scan_gis("vector", "vector", key, data, name, mapset, 1))
394
read_vareas(name, mapset);
398
if (KEY("window") || KEY("region")) {
399
if (scan_gis("windows", "region definition", key, data, name,
401
read_wind(name, mapset);
408
sscanf(data, "%d", &(PS.grid));
411
error(key, data, _("illegal grid spacing"));
419
if (KEY("geogrid")) {
420
if (G_projection() == PROJECTION_XY) {
422
_("geogrid is not available for this projection"));
425
/* if (G_projection() == PROJECTION_LL)
426
G_message(_("geogrid referenced to [???] ellipsoid")); */
428
PS.geogrid_numbers = 0;
429
sscanf(data, "%d %s", &(PS.geogrid), PS.geogridunit);
430
if (PS.geogrid < 0) {
432
error(key, data, _("illegal geo-grid spacing"));
441
if (PS.num_psfiles >= MAX_PSFILES)
444
PS.psfiles[PS.num_psfiles] = G_store(data);
449
if (KEY("maskcolor")) {
452
ret = G_str_to_color(data, &r, &g, &b);
454
PS.mask_r = r / 255.0;
455
PS.mask_g = g / 255.0;
456
PS.mask_b = b / 255.0;
460
else if (ret == 2) { /* none */
464
error(key, data, _("illegal color request"));
469
error(key, "", _("illegal request"));