~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to ps/ps.map/r_instructions.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <string.h>
 
2
 
 
3
#include <grass/colors.h>
 
4
#include <grass/imagery.h>
 
5
#include <grass/glocale.h>
 
6
#include "local_proto.h"
 
7
 
 
8
#define KEY(x) (strcmp(key,x)==0)
 
9
 
 
10
extern FILE *inputfd;
 
11
extern int do_mapinfo;
 
12
extern int do_vlegend;
 
13
extern int ps_copies;
 
14
 
 
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",
 
37
    ""
 
38
};
 
39
 
 
40
void read_instructions(int copies_set, int can_reset_scale)
 
41
{
 
42
    int i;
 
43
    int iflag;
 
44
    /* name can be fully qualified */
 
45
    char name[GNAME_MAX + GMAPSET_MAX], mapset[GMAPSET_MAX];
 
46
    char buf[1024];
 
47
 
 
48
    iflag = 0;
 
49
    
 
50
    while (1) {
 
51
        char *key;
 
52
        char *data;
 
53
 
 
54
        if (!input(1, buf, help)) {
 
55
            if (!iflag) {
 
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!"));
 
63
                    }
 
64
                    fclose(inputfd);
 
65
                    inputfd = stdin;
 
66
                }
 
67
                break;
 
68
            }
 
69
            iflag = 0;
 
70
            continue;
 
71
        }
 
72
        if (!key_data(buf, &key, &data))
 
73
            continue;
 
74
 
 
75
        if (KEY("read")) {
 
76
            if (inputfd != stdin)
 
77
                fclose(inputfd);
 
78
 
 
79
            if (sscanf(data, "%s", name) != 1) {
 
80
                error(key, data, _("no file specified"));
 
81
                inputfd = stdin;
 
82
            }
 
83
            else if ((inputfd = fopen(name, "r")) == NULL) {
 
84
                error(key, data, _("unable to open"));
 
85
                inputfd = stdin;
 
86
            }
 
87
            else
 
88
                iflag = 1;
 
89
            continue;
 
90
        }
 
91
 
 
92
        if (KEY("paper")) {
 
93
            if (strlen(data) > 0) {
 
94
                set_paper(data);
 
95
            }
 
96
            read_paper();
 
97
 
 
98
            continue;
 
99
        }
 
100
        
 
101
        if (KEY("maploc")) {
 
102
            int n;
 
103
            double x, y, w, h;
 
104
 
 
105
            n = sscanf(data, "%lf %lf %lf %lf", &x, &y, &w, &h);
 
106
            if (n == 2 || n == 4) {
 
107
                PS.map_x_orig = x;
 
108
                PS.map_y_loc = y;
 
109
                if (n == 4) {
 
110
                    PS.map_width = w;
 
111
                    PS.map_height = h;
 
112
                }
 
113
            }
 
114
            else {
 
115
                error(key, data, _("illegal maploc request"));
 
116
                gobble_input();
 
117
            }
 
118
            continue;
 
119
        }
 
120
 
 
121
        if (KEY("copies")) {
 
122
            int n, copies;
 
123
 
 
124
            if (copies_set)
 
125
                continue;
 
126
            n = sscanf(data, "%d", &copies);
 
127
            if (n != 1 || copies < 1 || copies > 20) {
 
128
                ps_copies = 1;
 
129
                error(key, data, _("illegal copies request"));
 
130
            }
 
131
            ps_copies = copies;
 
132
            continue;
 
133
        }
 
134
 
 
135
        if (KEY("setcolor")) {
 
136
            int ret, r, g, b;
 
137
            int count;
 
138
            DCELL *val_list;
 
139
            DCELL dmin, dmax;
 
140
            char colorbuf[100];
 
141
            char catsbuf[100];
 
142
 
 
143
            if (PS.cell_fd < 0)
 
144
                error(key, data, _("no raster map selected yet"));
 
145
 
 
146
            if (sscanf(data, "%s %[^\n]", catsbuf, colorbuf) == 2) {
 
147
                ret = G_str_to_color(colorbuf, &r, &g, &b);
 
148
                if (ret != 1)
 
149
                    error(key, colorbuf, _("illegal color request")); 
 
150
 
 
151
                if (strncmp(catsbuf, "null", 4) == 0) {
 
152
                    Rast_set_null_value_color(r, g, b, &(PS.colors));
 
153
                    continue;
 
154
                }
 
155
                if (strncmp(catsbuf, "default", 7) == 0) {
 
156
                    Rast_set_default_color(r, g, b, &(PS.colors));
 
157
                    continue;
 
158
                }
 
159
                if ((count = parse_val_list(catsbuf, &val_list)) < 0)
 
160
                    error(key, data, _("illegal value list"));
 
161
 
 
162
                for (i = 0; i < count; i += 2) {
 
163
                    dmin = val_list[i];
 
164
                    dmax = val_list[i + 1];
 
165
                    Rast_add_d_color_rule(&dmin, r, g, b, &dmax, r, g, b,
 
166
                                          &(PS.colors));
 
167
                }
 
168
                G_free(val_list);
 
169
            }
 
170
            continue;
 
171
        }
 
172
 
 
173
        if (KEY("colortable")) {
 
174
            PS.do_colortable = 0;
 
175
            /*
 
176
               if (PS.cell_fd < 0)
 
177
               error(key, data, "no raster map selected yet");
 
178
               else
 
179
             */
 
180
            PS.do_colortable = yesno(key, data);
 
181
            if (PS.do_colortable)
 
182
                read_colortable();
 
183
            continue;
 
184
        }
 
185
 
 
186
        if (KEY("border")) {
 
187
            PS.do_border = yesno(key, data);
 
188
            if (PS.do_border)
 
189
                read_border();
 
190
            continue;
 
191
        }
 
192
 
 
193
        if (KEY("scalebar")) {
 
194
            if (G_projection() == PROJECTION_LL) {
 
195
                error(key, data,
 
196
                      _("scalebar is not appropriate for this projection"));
 
197
                gobble_input();
 
198
            }
 
199
            PS.do_scalebar = 1;
 
200
            if (sscanf(data, "%s", sb.type) != 1)
 
201
                strcpy(sb.type, "f");   /* default to fancy scalebar */
 
202
            read_scalebar();
 
203
            if (sb.length <= 0.) {
 
204
                error(key, data, _("Bad scalebar length"));
 
205
                gobble_input();
 
206
            }
 
207
            continue;
 
208
        }
 
209
 
 
210
        if (KEY("text")) {
 
211
            double e, n;
 
212
            char east[50], north[50];
 
213
            char text[1024];
 
214
 
 
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);
 
218
            else {
 
219
                gobble_input();
 
220
                error(key, data, _("illegal text request"));
 
221
            }
 
222
            continue;
 
223
        }
 
224
 
 
225
        if (KEY("point")) {
 
226
            double e, n;
 
227
            char east[50], north[50];
 
228
 
 
229
            if (sscanf(data, "%s %s", east, north) == 2
 
230
                && (scan_easting(east, &e) && scan_northing(north, &n)))
 
231
                read_point(e, n);
 
232
            else {
 
233
                gobble_input();
 
234
                error(key, data, _("illegal point request"));
 
235
            }
 
236
            continue;
 
237
        }
 
238
 
 
239
        if (KEY("eps")) {
 
240
            double e, n;
 
241
            char east[50], north[50];
 
242
 
 
243
            if (sscanf(data, "%s %s", east, north) == 2
 
244
                && (scan_easting(east, &e) && scan_northing(north, &n)))
 
245
                read_eps(e, n);
 
246
            else {
 
247
                gobble_input();
 
248
                error(key, data, _("illegal eps request"));
 
249
            }
 
250
            continue;
 
251
        }
 
252
 
 
253
        if (KEY("line")) {
 
254
            char east1[50], north1[50];
 
255
            char east2[50], north2[50];
 
256
            double e1, n1, e2, n2;
 
257
 
 
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);
 
263
            else {
 
264
                gobble_input();
 
265
                error(key, data, _("illegal line request"));
 
266
            }
 
267
            continue;
 
268
        }
 
269
 
 
270
        if (KEY("rectangle")) {
 
271
            char east1[50], north1[50];
 
272
            char east2[50], north2[50];
 
273
            double e1, n1, e2, n2;
 
274
 
 
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);
 
280
            else {
 
281
                gobble_input();
 
282
                error(key, data, _("illegal rectangle request"));
 
283
            }
 
284
            continue;
 
285
        }
 
286
 
 
287
        if (KEY("comments")) {
 
288
            switch (sscanf(data, "%s %s", name, mapset)) {
 
289
            case 1:
 
290
                read_comment(name);
 
291
                break;
 
292
            case 2:
 
293
                error(key, data, _("illegal comments request"));
 
294
                break;
 
295
            default:
 
296
                read_comment("");
 
297
                break;
 
298
            }
 
299
            continue;
 
300
        }
 
301
 
 
302
        if (KEY("scale")) {
 
303
            if (!can_reset_scale)
 
304
                continue;
 
305
            if (check_scale(data))
 
306
                strcpy(PS.scaletext, data);
 
307
            else {
 
308
                PS.scaletext[0] = 0;
 
309
                error(key, data, _("illegal scale request"));
 
310
            }
 
311
            continue;
 
312
        }
 
313
 
 
314
        if (KEY("labels")) {
 
315
            if (scan_gis("paint/labels", "label", key, data, name, mapset, 1))
 
316
                read_labels(name, mapset);
 
317
            continue;
 
318
        }
 
319
 
 
320
        if (KEY("header")) {
 
321
            read_header();
 
322
            PS.do_header = 1;
 
323
            continue;
 
324
        }
 
325
 
 
326
        if (KEY("mapinfo")) {
 
327
            read_info();
 
328
            do_mapinfo = 1;
 
329
            continue;
 
330
        }
 
331
 
 
332
        if (KEY("vlegend")) {
 
333
            read_vlegend();
 
334
            do_vlegend = 1;
 
335
            continue;
 
336
        }
 
337
 
 
338
        if (KEY("outline")) {
 
339
            if (PS.cell_fd < 0) {
 
340
                error(key, data, _("no raster map selected yet"));
 
341
                gobble_input();
 
342
            }
 
343
            else
 
344
                read_outline();
 
345
            continue;
 
346
        }
 
347
 
 
348
        if (KEY("cell") || KEY("rast") || KEY("raster")) {
 
349
            if (scan_gis("cell", "raster", key, data, name, mapset, 0))
 
350
                read_cell(name, mapset);
 
351
            continue;
 
352
        }
 
353
 
 
354
        if (KEY("greyrast") || KEY("grayrast")) {
 
355
            if (scan_gis("cell", "raster", key, data, name, mapset, 0))
 
356
                read_cell(name, mapset);
 
357
            PS.grey = 1;
 
358
            continue;
 
359
        }
 
360
 
 
361
        if (KEY("group")) {
 
362
            G_strip(data);
 
363
            if (I_find_group(data)) {
 
364
                grp.group_name = G_store(data);
 
365
                grp.do_group = 1;
 
366
                read_group();
 
367
            }
 
368
            else
 
369
                error(key, data, _("group not found"));
 
370
            continue;
 
371
        }
 
372
 
 
373
        if (KEY("rgb")) {
 
374
            G_strip(data);
 
375
            grp.do_group = 1;
 
376
            read_rgb(key, data);
 
377
            continue;
 
378
        }
 
379
 
 
380
        if (KEY("vpoints")) {
 
381
            if (scan_gis("vector", "vector", key, data, name, mapset, 1))
 
382
                read_vpoints(name, mapset);
 
383
            continue;
 
384
        }
 
385
 
 
386
        if (KEY("vlines")) {
 
387
            if (scan_gis("vector", "vector", key, data, name, mapset, 1))
 
388
                read_vlines(name, mapset);
 
389
            continue;
 
390
        }
 
391
 
 
392
        if (KEY("vareas")) {
 
393
            if (scan_gis("vector", "vector", key, data, name, mapset, 1))
 
394
                read_vareas(name, mapset);
 
395
            continue;
 
396
        }
 
397
 
 
398
        if (KEY("window") || KEY("region")) {
 
399
            if (scan_gis("windows", "region definition", key, data, name,
 
400
                         mapset, 1))
 
401
                read_wind(name, mapset);
 
402
            continue;
 
403
        }
 
404
 
 
405
        if (KEY("grid")) {
 
406
            PS.grid = -1;
 
407
            PS.grid_numbers = 0;
 
408
            sscanf(data, "%d", &(PS.grid));
 
409
            if (PS.grid < 0) {
 
410
                PS.grid = 0;
 
411
                error(key, data, _("illegal grid spacing"));
 
412
                gobble_input();
 
413
            }
 
414
            else
 
415
                getgrid();
 
416
            continue;
 
417
        }
 
418
 
 
419
        if (KEY("geogrid")) {
 
420
            if (G_projection() == PROJECTION_XY) {
 
421
                error(key, data,
 
422
                      _("geogrid is not available for this projection"));
 
423
                gobble_input();
 
424
            }
 
425
            /*          if (G_projection() == PROJECTION_LL)
 
426
               G_message(_("geogrid referenced to [???] ellipsoid"));  */
 
427
            PS.geogrid = -1.;
 
428
            PS.geogrid_numbers = 0;
 
429
            sscanf(data, "%d %s", &(PS.geogrid), PS.geogridunit);
 
430
            if (PS.geogrid < 0) {
 
431
                PS.geogrid = 0;
 
432
                error(key, data, _("illegal geo-grid spacing"));
 
433
                gobble_input();
 
434
            }
 
435
            else
 
436
                getgeogrid();
 
437
            continue;
 
438
        }
 
439
 
 
440
        if (KEY("psfile")) {
 
441
            if (PS.num_psfiles >= MAX_PSFILES)
 
442
                continue;
 
443
            G_strip(data);
 
444
            PS.psfiles[PS.num_psfiles] = G_store(data);
 
445
            PS.num_psfiles++;
 
446
            continue;
 
447
        }
 
448
 
 
449
        if (KEY("maskcolor")) {
 
450
            int ret, r, g, b;
 
451
 
 
452
            ret = G_str_to_color(data, &r, &g, &b);
 
453
            if (ret == 1) {
 
454
                PS.mask_r = r / 255.0;
 
455
                PS.mask_g = g / 255.0;
 
456
                PS.mask_b = b / 255.0;
 
457
                PS.mask_color = 1;
 
458
                continue;
 
459
            }
 
460
            else if (ret == 2) {        /* none */
 
461
                continue;
 
462
            }
 
463
            else {
 
464
                error(key, data, _("illegal color request"));
 
465
            }
 
466
        }
 
467
 
 
468
        if (*key)
 
469
            error(key, "", _("illegal request"));
 
470
    }
 
471
}