1 | /*
|
---|
2 | * $Source: /tmp_mnt/n/fs/grad1/jsp/src/jgraph/RCS/edit.c,v $
|
---|
3 | * $Revision: 8.3 $
|
---|
4 | * $Date: 92/11/30 11:42:12 $
|
---|
5 | * $Author: jsp $
|
---|
6 | */
|
---|
7 |
|
---|
8 |
|
---|
9 | #include <stdio.h>
|
---|
10 | #include <string.h>
|
---|
11 |
|
---|
12 | #include "jgraph.h"
|
---|
13 |
|
---|
14 | #define MAX(a,b) ((a > b) ? a : b)
|
---|
15 | #define MIN(a,b) ((a < b) ? a : b)
|
---|
16 |
|
---|
17 | void edit_label(Label l)
|
---|
18 | {
|
---|
19 | char *txt, inp_str[80];
|
---|
20 | float f;
|
---|
21 | int i;
|
---|
22 |
|
---|
23 | while ( getstring(inp_str) ) {
|
---|
24 | if (strcmp(inp_str, ":") == 0) {
|
---|
25 | if ((txt = getlabel()) == CNULL) return;
|
---|
26 | l->label = txt;
|
---|
27 | } else if (strcmp(inp_str, "x") == 0) {
|
---|
28 | if (!getfloat(&f)) rejecttoken(); else l->x = f;
|
---|
29 | } else if (strcmp(inp_str, "y") == 0) {
|
---|
30 | if (!getfloat(&f)) rejecttoken(); else l->y = f;
|
---|
31 | } else if (strcmp(inp_str, "fontsize") == 0) {
|
---|
32 | if (!getfloat(&f)) rejecttoken(); else l->fontsize = f;
|
---|
33 | } else if (strcmp(inp_str, "linesep") == 0) {
|
---|
34 | if (!getfloat(&f)) rejecttoken(); else l->linesep = f;
|
---|
35 | } else if (strcmp(inp_str, "hjl") == 0) {
|
---|
36 | l->hj = 'l';
|
---|
37 | } else if (strcmp(inp_str, "hjc") == 0) {
|
---|
38 | l->hj = 'c';
|
---|
39 | } else if (strcmp(inp_str, "hjr") == 0) {
|
---|
40 | l->hj = 'r';
|
---|
41 | } else if (strcmp(inp_str, "vjc") == 0) {
|
---|
42 | l->vj = 'c';
|
---|
43 | } else if (strcmp(inp_str, "vjt") == 0) {
|
---|
44 | l->vj = 't';
|
---|
45 | } else if (strcmp(inp_str, "vjb") == 0) {
|
---|
46 | l->vj = 'b';
|
---|
47 | } else if (strcmp(inp_str, "font") == 0) {
|
---|
48 | if (!getstring(inp_str)) return;
|
---|
49 | txt = (char *) malloc (sizeof(char)*strlen(inp_str)+2);
|
---|
50 | strcpy(txt, inp_str);
|
---|
51 | l->font = txt;
|
---|
52 | } else if (strcmp(inp_str, "rotate") == 0) {
|
---|
53 | if (!getfloat(&f)) rejecttoken(); else l->rotate = f;
|
---|
54 | } else if (strcmp(inp_str, "lgray") == 0) {
|
---|
55 | if (!getfloat(&f)) rejecttoken(); else {
|
---|
56 | l->graytype = 'g';
|
---|
57 | l->gray[0] = f;
|
---|
58 | }
|
---|
59 | } else if (strcmp(inp_str, "lcolor") == 0) {
|
---|
60 | l->graytype = 'c';
|
---|
61 | for( i = 0 ; i < 3 ; i++ ) {
|
---|
62 | if(!getfloat(&f)) {
|
---|
63 | rejecttoken();
|
---|
64 | l->graytype = 'n';
|
---|
65 | break ;
|
---|
66 | } else l->gray[i] = f ;
|
---|
67 | }
|
---|
68 | } else {
|
---|
69 | rejecttoken();
|
---|
70 | return;
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | void copy_curve(Curve c1, Curve c2) /* Copies curve c2 to c1 */
|
---|
76 | {
|
---|
77 | Flist f, newf;
|
---|
78 | Point p, newp;
|
---|
79 |
|
---|
80 | copy_label(c1->l, c2->l);
|
---|
81 | copy_label(c1->lmark, c2->lmark);
|
---|
82 | c1->l->label = CNULL;
|
---|
83 | c1->clip = c2->clip;
|
---|
84 | for (f = first(c2->gen_linetype);
|
---|
85 | f != nil(c2->gen_linetype);
|
---|
86 | f = next(f)) {
|
---|
87 | newf = (Flist) get_node(c1->gen_linetype);
|
---|
88 | newf->f = f->f;
|
---|
89 | insert(newf, c1->gen_linetype);
|
---|
90 | }
|
---|
91 | c1->pattern = c2->pattern;
|
---|
92 | c1->apattern = c2->apattern;
|
---|
93 | c1->ppattern = c2->ppattern;
|
---|
94 | c1->parg = c2->parg;
|
---|
95 | c1->aparg = c2->aparg;
|
---|
96 | c1->pparg = c2->pparg;
|
---|
97 | c1->marktype = c2->marktype;
|
---|
98 | c1->linetype = c2->linetype;
|
---|
99 | c1->linethick = c2->linethick;
|
---|
100 | c1->marksize[0] = c2->marksize[0];
|
---|
101 | c1->marksize[1] = c2->marksize[1];
|
---|
102 | c1->mrotate = c2->mrotate;
|
---|
103 | for (p = first(c2->general_marks);
|
---|
104 | p != nil(c2->general_marks);
|
---|
105 | p = next(p)) {
|
---|
106 | newp = (Point) get_node(c1->general_marks);
|
---|
107 | newp->x = p->x;
|
---|
108 | newp->y = p->y;
|
---|
109 | insert(newp, c1->general_marks);
|
---|
110 | }
|
---|
111 | c1->graytype = c2->graytype;
|
---|
112 | c1->gray[0] = c2->gray[0];
|
---|
113 | c1->gray[1] = c2->gray[1];
|
---|
114 | c1->gray[2] = c2->gray[2];
|
---|
115 | c1->filltype = c2->filltype;
|
---|
116 | c1->fill[0] = c2->fill[0];
|
---|
117 | c1->fill[1] = c2->fill[1];
|
---|
118 | c1->fill[2] = c2->fill[2];
|
---|
119 | c1->poly = c2->poly;
|
---|
120 | c1->pfilltype = c2->pfilltype;
|
---|
121 | c1->pfill[0] = c2->pfill[0];
|
---|
122 | c1->pfill[1] = c2->pfill[1];
|
---|
123 | c1->pfill[2] = c2->pfill[2];
|
---|
124 | c1->afilltype = c2->afilltype;
|
---|
125 | c1->afill[0] = c2->afill[0];
|
---|
126 | c1->afill[1] = c2->afill[1];
|
---|
127 | c1->afill[2] = c2->afill[2];
|
---|
128 | c1->postscript = c2->postscript;
|
---|
129 | c1->postfile = c2->postfile;
|
---|
130 | c1->eps = c2->eps;
|
---|
131 | c1->rarrow = c2->rarrow;
|
---|
132 | c1->larrow = c2->larrow;
|
---|
133 | c1->rarrows = c2->rarrows;
|
---|
134 | c1->larrows = c2->larrows;
|
---|
135 | c1->asize[0] = c2->asize[0];
|
---|
136 | c1->asize[1] = c2->asize[1];
|
---|
137 | c1->bezier = c2->bezier;
|
---|
138 | }
|
---|
139 |
|
---|
140 | void copy_label(Label l1, Label l2) /* Copies label l2 to l1 */
|
---|
141 | {
|
---|
142 | l1->label = l2->label;
|
---|
143 | l1->x = l2->x;
|
---|
144 | l1->y = l2->y;
|
---|
145 | l1->rotate = l2->rotate;
|
---|
146 | l1->font = l2->font;
|
---|
147 | l1->fontsize = l2->fontsize;
|
---|
148 | l1->hj = l2->hj;
|
---|
149 | l1->vj = l2->vj;
|
---|
150 | l1->graytype = l2->graytype;
|
---|
151 | l1->gray[0] = l2->gray[0];
|
---|
152 | l1->gray[1] = l2->gray[1];
|
---|
153 | l1->gray[2] = l2->gray[2];
|
---|
154 | l1->linesep = l2->linesep;
|
---|
155 | }
|
---|
156 |
|
---|
157 | void copy_axis(Axis a1, Axis a2) /* Copies axis a2 to a1 */
|
---|
158 | {
|
---|
159 | copy_label(a1->label, a2->label);
|
---|
160 | copy_label(a1->hl, a2->hl);
|
---|
161 | a1->max = a2->max;
|
---|
162 | a1->min = a2->min;
|
---|
163 | a1->pmax = a2->pmax;
|
---|
164 | a1->pmin = a2->pmin;
|
---|
165 | a1->size = a2->size;
|
---|
166 | a1->hash_interval = a2->hash_interval;
|
---|
167 | a1->hash_start = a2->hash_start;
|
---|
168 | a1->log_base = a2->log_base;
|
---|
169 | a1->draw_hash_marks_at = a2->draw_hash_marks_at;
|
---|
170 | a1->draw_hash_labels_at = a2->draw_hash_labels_at;
|
---|
171 | a1->draw_at = a2->draw_at;
|
---|
172 | a1->draw_hash_labels = a2->draw_hash_labels;
|
---|
173 | a1->draw_axis_line = a2->draw_axis_line;
|
---|
174 | a1->draw_hash_marks = a2->draw_hash_marks;
|
---|
175 | a1->draw_axis_label = a2->draw_axis_label;
|
---|
176 | a1->auto_hash_labels = a2->auto_hash_labels;
|
---|
177 | a1->auto_hash_marks = a2->auto_hash_marks;
|
---|
178 | a1->minor_hashes = a2->minor_hashes;
|
---|
179 | a1->hash_scale = a2->hash_scale;
|
---|
180 | a1->hash_format = a2->hash_format;
|
---|
181 | a1->graytype = a2->graytype;
|
---|
182 | a1->gray[0] = a2->gray[0];
|
---|
183 | a1->gray[1] = a2->gray[1];
|
---|
184 | a1->gray[2] = a2->gray[2];
|
---|
185 | a1->mgr_graytype = a2->mgr_graytype;
|
---|
186 | a1->mgr_gray[0] = a2->mgr_gray[0];
|
---|
187 | a1->mgr_gray[1] = a2->mgr_gray[1];
|
---|
188 | a1->mgr_gray[2] = a2->mgr_gray[2];
|
---|
189 | a1->gr_graytype = a2->gr_graytype;
|
---|
190 | a1->gr_gray[0] = a2->gr_gray[0];
|
---|
191 | a1->gr_gray[1] = a2->gr_gray[1];
|
---|
192 | a1->gr_gray[2] = a2->gr_gray[2];
|
---|
193 | a1->grid_lines = a2->grid_lines;
|
---|
194 | a1->mgrid_lines = a2->mgrid_lines;
|
---|
195 | a1->precision = a2->precision;
|
---|
196 | a1->start_given = a2->start_given;
|
---|
197 | a1->is_lg = a2->is_lg;
|
---|
198 | a1->is_x = a2->is_x;
|
---|
199 | }
|
---|
200 |
|
---|
201 | Curve do_copy_curve(Graph g, Graphs gs, Graphs all_gs)
|
---|
202 | {
|
---|
203 | Curve lastc, newc;
|
---|
204 | Graph oldg;
|
---|
205 | Graphs oldgs;
|
---|
206 | int num;
|
---|
207 |
|
---|
208 | if (!getint(&num)) {
|
---|
209 | rejecttoken();
|
---|
210 | oldg = g;
|
---|
211 | oldgs = gs;
|
---|
212 | while(gs != nil(all_gs)) {
|
---|
213 | if (gs != oldgs) g = last(gs->g);
|
---|
214 | while(g != nil(gs->g)) {
|
---|
215 | if (first(g->curves) == nil(g->curves)) g = prev(g);
|
---|
216 | else {
|
---|
217 | lastc = last(g->curves);
|
---|
218 | if (first(oldg->curves) == nil(oldg->curves))
|
---|
219 | newc = new_curve(oldg->curves, 0);
|
---|
220 | else newc = new_curve(oldg->curves, last(oldg->curves)->num + 1);
|
---|
221 | copy_curve(newc, lastc);
|
---|
222 | return newc;
|
---|
223 | }
|
---|
224 | }
|
---|
225 | gs = prev(gs);
|
---|
226 | }
|
---|
227 | error_header();
|
---|
228 | fprintf(stderr, "Cannot perform copycurve on first curve\n");
|
---|
229 | exit(1);
|
---|
230 | } else {
|
---|
231 | if (first(g->curves) == nil(g->curves))
|
---|
232 | newc = new_curve(g->curves, 0);
|
---|
233 | else newc = new_curve(g->curves, last(g->curves)->num + 1);
|
---|
234 | lastc = g->curves;
|
---|
235 | while(1) {
|
---|
236 | lastc = prev(lastc);
|
---|
237 | if (lastc == nil(g->curves) || lastc->num < num) {
|
---|
238 | error_header();
|
---|
239 | fprintf(stderr, "copycurve: curve #%d not found\n", num);
|
---|
240 | exit(1);
|
---|
241 | }
|
---|
242 | if (lastc->num == num) {
|
---|
243 | copy_curve(newc, lastc);
|
---|
244 | return newc;
|
---|
245 | }
|
---|
246 | }
|
---|
247 | }
|
---|
248 | return newc; /* To shut lint up */
|
---|
249 | }
|
---|
250 |
|
---|
251 | Label do_copy_string(Graph g, Graphs gs, Graphs all_gs)
|
---|
252 | {
|
---|
253 | String lastl, newl;
|
---|
254 | Graph oldg;
|
---|
255 | Graphs oldgs;
|
---|
256 | int num;
|
---|
257 |
|
---|
258 | if (!getint(&num)) {
|
---|
259 | rejecttoken();
|
---|
260 | oldgs = gs;
|
---|
261 | oldg = g;
|
---|
262 | while(gs != nil(all_gs)) {
|
---|
263 | if (gs != oldgs) g = last(gs->g);
|
---|
264 | while(g != nil(gs->g)) {
|
---|
265 | if (first(g->strings) == nil(g->strings)) g = prev(g);
|
---|
266 | else {
|
---|
267 | lastl = last(g->strings);
|
---|
268 | if (first(oldg->strings) == nil(oldg->strings))
|
---|
269 | newl = new_string(oldg->strings, 0);
|
---|
270 | else newl = new_string(oldg->strings, last(oldg->strings)->num + 1);
|
---|
271 | copy_label(newl->s, lastl->s);
|
---|
272 | return newl->s;
|
---|
273 | }
|
---|
274 | }
|
---|
275 | gs = prev(gs);
|
---|
276 | }
|
---|
277 | error_header();
|
---|
278 | fprintf(stderr, "Cannot perform copystring on first string\n");
|
---|
279 | exit(1);
|
---|
280 | return newl->s; /* To shut lint up */
|
---|
281 | } else {
|
---|
282 | if (first(g->strings) == nil(g->strings))
|
---|
283 | newl = new_string(g->strings, 0);
|
---|
284 | else newl = new_string(g->strings, last(g->strings)->num + 1);
|
---|
285 | lastl = g->strings;
|
---|
286 | while(1) {
|
---|
287 | lastl = prev(lastl);
|
---|
288 | if (lastl == nil(g->strings) || lastl->num < num) {
|
---|
289 | error_header();
|
---|
290 | fprintf(stderr, "copystring: string #%d not found\n", num);
|
---|
291 | exit(1);
|
---|
292 | }
|
---|
293 | if (lastl->num == num) {
|
---|
294 | copy_label(newl->s, lastl->s);
|
---|
295 | return newl->s;
|
---|
296 | }
|
---|
297 | }
|
---|
298 | }
|
---|
299 | }
|
---|
300 |
|
---|
301 | Graph last_graph(Graph g, Graphs gs, Graphs all_gs)
|
---|
302 | {
|
---|
303 | Graph lastg;
|
---|
304 |
|
---|
305 |
|
---|
306 | lastg = prev(g);
|
---|
307 | while(lastg == nil(gs->g)) {
|
---|
308 | if (prev(gs) == nil(all_gs)) {
|
---|
309 | error_header();
|
---|
310 | fprintf(stderr, "First graph cannot inherit axes\n");
|
---|
311 | exit(1);
|
---|
312 | } else {
|
---|
313 | gs = prev(gs);
|
---|
314 | lastg = last(gs->g);
|
---|
315 | }
|
---|
316 | }
|
---|
317 | return lastg;
|
---|
318 | }
|
---|
319 |
|
---|
320 | void copy_legend(Legend l1, Legend l2)
|
---|
321 | {
|
---|
322 | l1->linelength = l2->linelength;
|
---|
323 | l1->linebreak = l2->linebreak;
|
---|
324 | l1->midspace = l2->midspace;
|
---|
325 | l1->type = l2->type;
|
---|
326 | copy_label(l1->l, l2->l);
|
---|
327 | }
|
---|
328 |
|
---|
329 | void inherit_axes(Graph g, Graph lastg)
|
---|
330 | {
|
---|
331 | char *s;
|
---|
332 | copy_axis(g->x_axis, lastg->x_axis);
|
---|
333 | copy_axis(g->y_axis, lastg->y_axis);
|
---|
334 | g->x_translate = lastg->x_translate;
|
---|
335 | g->y_translate = lastg->y_translate;
|
---|
336 | g->clip = lastg->clip;
|
---|
337 | g->border = lastg->border;
|
---|
338 | copy_legend(g->legend, lastg->legend);
|
---|
339 | s = g->title->label;
|
---|
340 | copy_label(g->title, lastg->title);
|
---|
341 | g->title->label = s;
|
---|
342 | }
|
---|
343 |
|
---|
344 | void getpattern(char *inp_str, char *key, char *p, float *a)
|
---|
345 | {
|
---|
346 | int i;
|
---|
347 | float f;
|
---|
348 |
|
---|
349 | if (!getstring(inp_str)) return;
|
---|
350 | for (i = 0; i < NPATTERNS; i++) {
|
---|
351 | if (strcmp(inp_str, PATTERNS[i]) == 0) {
|
---|
352 | *p = PTYPES[i];
|
---|
353 | if (getfloat(&f)) {
|
---|
354 | *a = f;
|
---|
355 | } else {
|
---|
356 | rejecttoken();
|
---|
357 | }
|
---|
358 | i = NPATTERNS + 1;
|
---|
359 | }
|
---|
360 | }
|
---|
361 | if (i == NPATTERNS) {
|
---|
362 | error_header(); fprintf(stderr, "Bad %s: %s\n", key, inp_str);
|
---|
363 | error_header(); fprintf(stderr, " Valid %ss are:", key);
|
---|
364 | for (i = 0; i < NPATTERNS; i++) fprintf(stderr, " %s", PATTERNS[i]);
|
---|
365 | fprintf(stderr, "\n");
|
---|
366 | exit(1);
|
---|
367 | }
|
---|
368 | return;
|
---|
369 | }
|
---|
370 |
|
---|
371 | void edit_curve(Curve c, Graph g)
|
---|
372 | {
|
---|
373 | char inp_str[256], *txt;
|
---|
374 | float x, y, f, e1, e2;
|
---|
375 | float xh, yh, xl, yl;
|
---|
376 | Point p, p1, p2;
|
---|
377 | Flist fl;
|
---|
378 | FILE *fi;
|
---|
379 | int i;
|
---|
380 | char e;
|
---|
381 |
|
---|
382 | while ( getstring(inp_str) ) {
|
---|
383 | if (strcmp(inp_str, "y_epts") == 0 ||
|
---|
384 | strcmp(inp_str, "pts") == 0 ||
|
---|
385 | strcmp(inp_str, "x_epts") == 0) {
|
---|
386 | e = inp_str[0];
|
---|
387 | while (getfloat(&x)) {
|
---|
388 | if (e == 'p') {
|
---|
389 | if (!getfloat(&y)) {
|
---|
390 | error_header();
|
---|
391 | fprintf(stderr, "Reading Points, no y value for x=%f\n", x);
|
---|
392 | exit(1);
|
---|
393 | }
|
---|
394 | } else {
|
---|
395 | if (!getfloat(&y) || !getfloat(&e1) || !getfloat(&e2)) {
|
---|
396 | error_header();
|
---|
397 | fprintf(stderr,
|
---|
398 | "Reading %s, need 4 values per data point\n", inp_str);
|
---|
399 | exit(1);
|
---|
400 | }
|
---|
401 | }
|
---|
402 | p = (Point) get_node(c->pts);
|
---|
403 | p->x = x;
|
---|
404 | p->y = y;
|
---|
405 | p->e = e;
|
---|
406 | insert(p, c->pts);
|
---|
407 | c->npts++;
|
---|
408 | if (e == 'x') {
|
---|
409 | p1 = (Point) get_node(c->xepts);
|
---|
410 | p1->x = e1;
|
---|
411 | p1->y = y;
|
---|
412 | p2 = (Point) get_node(c->xepts);
|
---|
413 | p2->x = e2;
|
---|
414 | p2->y = y;
|
---|
415 | insert(p1, c->xepts);
|
---|
416 | insert(p2, c->xepts);
|
---|
417 | xh = MAX(e1, e2); xh = MAX(xh, x);
|
---|
418 | xl = MIN(e1, e2); xl = MIN(xl, x);
|
---|
419 | yh = y; yl = y;
|
---|
420 | } else if (e == 'y') {
|
---|
421 | p1 = (Point) get_node(c->yepts);
|
---|
422 | p1->y = e1;
|
---|
423 | p1->x = x;
|
---|
424 | p2 = (Point) get_node(c->yepts);
|
---|
425 | p2->y = e2;
|
---|
426 | p2->x = x;
|
---|
427 | insert(p1, c->yepts);
|
---|
428 | insert(p2, c->yepts);
|
---|
429 | yh = MAX(e1, e2); yh = MAX(yh, y);
|
---|
430 | yl = MIN(e1, e2); yl = MIN(yl, y);
|
---|
431 | xh = x; xl = x;
|
---|
432 | } else {
|
---|
433 | xh = x; xl = x; yh = y; yl = y;
|
---|
434 | }
|
---|
435 | if (g->x_axis->pmax == FSIG) {
|
---|
436 | g->x_axis->pmax = xh;
|
---|
437 | g->x_axis->pmin = xl;
|
---|
438 | g->y_axis->pmax = yh;
|
---|
439 | g->y_axis->pmin = yl;
|
---|
440 | } else {
|
---|
441 | g->x_axis->pmax = MAX(g->x_axis->pmax, xh);
|
---|
442 | g->x_axis->pmin = MIN(g->x_axis->pmin, xl);
|
---|
443 | g->y_axis->pmax = MAX(g->y_axis->pmax, yh);
|
---|
444 | g->y_axis->pmin = MIN(g->y_axis->pmin, yl);
|
---|
445 | }
|
---|
446 | }
|
---|
447 | rejecttoken();
|
---|
448 |
|
---|
449 | } else if (strcmp(inp_str, "label") == 0) {
|
---|
450 | edit_label(c->l);
|
---|
451 | } else if (strcmp(inp_str, "marksize") == 0) {
|
---|
452 | if (!getfloat(&f)) rejecttoken();
|
---|
453 | else {
|
---|
454 | c->marksize[0] = f;
|
---|
455 | if (!getfloat(&f)) rejecttoken();
|
---|
456 | else c->marksize[1] = f;
|
---|
457 | }
|
---|
458 | } else if (strcmp(inp_str, "gmarks") == 0) {
|
---|
459 | while (getfloat(&x)) {
|
---|
460 | if (!getfloat(&y)) {
|
---|
461 | error_header();
|
---|
462 | fprintf(stderr, "Reading GMarks, no y value for x=%f\n", x);
|
---|
463 | exit(1);
|
---|
464 | }
|
---|
465 | p = (Point) get_node(c->general_marks);
|
---|
466 | p->x = x;
|
---|
467 | p->y = y;
|
---|
468 | insert(p, c->general_marks);
|
---|
469 | }
|
---|
470 | rejecttoken();
|
---|
471 | } else if (strcmp(inp_str, "pfill") == 0) {
|
---|
472 | if (!getfloat(&f)) rejecttoken(); else {
|
---|
473 | /* grey fill */
|
---|
474 | c->pfilltype = 'g';
|
---|
475 | c->pfill[0] = f;
|
---|
476 | }
|
---|
477 | } else if (strcmp(inp_str, "pcfill") == 0) {
|
---|
478 | /* color fill */
|
---|
479 | c->pfilltype = 'c';
|
---|
480 | for( i = 0 ; i < 3 ; i++ ) {
|
---|
481 | if(!getfloat(&f)) {
|
---|
482 | rejecttoken();
|
---|
483 | c->pfilltype = 'n';
|
---|
484 | break ;
|
---|
485 | } else c->pfill[i] = f ;
|
---|
486 | }
|
---|
487 | } else if (strcmp(inp_str, "fill") == 0) {
|
---|
488 | if (!getfloat(&f)) rejecttoken(); else {
|
---|
489 | /* grey fill */
|
---|
490 | c->filltype = 'g';
|
---|
491 | c->fill[0] = f;
|
---|
492 | }
|
---|
493 | } else if (strcmp(inp_str, "cfill") == 0) {
|
---|
494 | /* color fill */
|
---|
495 | c->filltype = 'c';
|
---|
496 | for( i = 0 ; i < 3 ; i++ ) {
|
---|
497 | if(!getfloat(&f)) {
|
---|
498 | rejecttoken();
|
---|
499 | c->filltype = 'n';
|
---|
500 | break ;
|
---|
501 | } else c->fill[i] = f ;
|
---|
502 | }
|
---|
503 | } else if (strcmp(inp_str, "afill") == 0) {
|
---|
504 | if (!getfloat(&f)) rejecttoken(); else {
|
---|
505 | c->afilltype = 'g';
|
---|
506 | c->afill[0] = f;
|
---|
507 | }
|
---|
508 | } else if (strcmp(inp_str, "acfill") == 0) {
|
---|
509 | c->afilltype = 'c';
|
---|
510 | for( i = 0 ; i < 3 ; i++ ) {
|
---|
511 | if(!getfloat(&f)) {
|
---|
512 | rejecttoken();
|
---|
513 | c->afilltype = 'n';
|
---|
514 | break ;
|
---|
515 | } else c->afill[i] = f ;
|
---|
516 | }
|
---|
517 | } else if (strcmp(inp_str, "marktype") == 0) {
|
---|
518 | if (!getstring(inp_str)) return;
|
---|
519 | for (i = 0; i < NMARKTYPES && strcmp(inp_str, MARKTYPESTRS[i]) != 0; i++) ;
|
---|
520 | if (i == NMARKTYPES) {
|
---|
521 | error_header(); fprintf(stderr, "Bad mark: %s\n", inp_str);
|
---|
522 | fprintf(stderr, " Valid marks are:");
|
---|
523 | for (i = 0; i < NMARKTYPES; i++) {
|
---|
524 | fprintf(stderr, " %s", MARKTYPESTRS[i]);
|
---|
525 | }
|
---|
526 | fprintf(stderr, "\n");
|
---|
527 | exit(1);
|
---|
528 | } else {
|
---|
529 | c->marktype = MARKTYPES[i];
|
---|
530 | if (c->marktype == 'l') edit_label(c->lmark);
|
---|
531 | }
|
---|
532 | } else if (strcmp(inp_str, "glines") == 0) {
|
---|
533 | while (getfloat(&f)) {
|
---|
534 | fl = (Flist) get_node (c->gen_linetype);
|
---|
535 | fl->f = f;
|
---|
536 | insert(fl, c->gen_linetype);
|
---|
537 | }
|
---|
538 | rejecttoken();
|
---|
539 | } else if (strcmp(inp_str, "pattern") == 0) {
|
---|
540 | getpattern(inp_str, "pattern", &(c->pattern), &(c->parg));
|
---|
541 | } else if (strcmp(inp_str, "apattern") == 0) {
|
---|
542 | getpattern(inp_str, "apattern", &(c->apattern), &(c->aparg));
|
---|
543 | } else if (strcmp(inp_str, "ppattern") == 0) {
|
---|
544 | getpattern(inp_str, "ppattern", &(c->ppattern), &(c->pparg));
|
---|
545 |
|
---|
546 | } else if (strcmp(inp_str, "linetype") == 0) {
|
---|
547 | if (!getstring(inp_str)) return;
|
---|
548 | if (strcmp(inp_str, "none") == 0) c->linetype = '0';
|
---|
549 | else if (strcmp(inp_str, "solid") == 0) c->linetype = 's';
|
---|
550 | else if (strcmp(inp_str, "dotted") == 0) c->linetype = '.';
|
---|
551 | else if (strcmp(inp_str, "dashed") == 0) c->linetype = '-';
|
---|
552 | else if (strcmp(inp_str, "longdash") == 0) c->linetype = 'l';
|
---|
553 | else if (strcmp(inp_str, "dotdash") == 0) c->linetype = 'd';
|
---|
554 | else if (strcmp(inp_str, "dotdotdash") == 0) c->linetype = 'D';
|
---|
555 | else if (strcmp(inp_str, "dotdotdashdash") == 0) c->linetype = '2';
|
---|
556 | else if (strcmp(inp_str, "general") == 0) c->linetype = 'g';
|
---|
557 | else {
|
---|
558 | error_header(); fprintf(stderr, "Bad line type: %s\n", inp_str);
|
---|
559 | error_header(); fprintf(stderr, " Valid marks are %s\n",
|
---|
560 | "solid, dotted, dashed, longdash, dotdash,");
|
---|
561 | error_header(); fprintf(stderr, " %s.\n",
|
---|
562 | "dotdotdash, dotdotdashdash, none");
|
---|
563 | exit(1);
|
---|
564 | }
|
---|
565 | } else if (strcmp(inp_str, "linethickness") == 0) {
|
---|
566 | if (!getfloat(&f)) rejecttoken(); else c->linethick = f;
|
---|
567 | } else if (strcmp(inp_str, "gray") == 0) {
|
---|
568 | if (!getfloat(&f)) rejecttoken(); else {
|
---|
569 | c->graytype = 'g';
|
---|
570 | c->gray[0] = f;
|
---|
571 | }
|
---|
572 | } else if (strcmp(inp_str, "color") == 0) {
|
---|
573 | c->graytype = 'c';
|
---|
574 | for( i = 0 ; i < 3 ; i++ ) {
|
---|
575 | if(!getfloat(&f)) {
|
---|
576 | rejecttoken();
|
---|
577 | c->graytype = 'n';
|
---|
578 | break ;
|
---|
579 | } else c->gray[i] = f ;
|
---|
580 | }
|
---|
581 | } else if (strcmp(inp_str, "mrotate") == 0) {
|
---|
582 | if (!getfloat(&f)) rejecttoken(); else {
|
---|
583 | c->mrotate = f;
|
---|
584 | }
|
---|
585 | } else if (strcmp(inp_str, "eps") == 0) {
|
---|
586 | if (!getstring(inp_str)) {
|
---|
587 | error_header();
|
---|
588 | fprintf(stderr, "eps token must be followed by an %s\n",
|
---|
589 | "encapsulated postscript file\n");
|
---|
590 | exit(1);
|
---|
591 | }
|
---|
592 | c->marktype = 'E';
|
---|
593 | c->eps = (char *) malloc ((strlen(inp_str)+1)*sizeof(char));
|
---|
594 | strcpy(c->eps, inp_str);
|
---|
595 | fi = fopen(c->eps, "r");
|
---|
596 | if (fi == NULL) {
|
---|
597 | error_header();
|
---|
598 | fprintf(stderr, "couldn't open eps file '%s'\n", c->eps);
|
---|
599 | exit(1);
|
---|
600 | }
|
---|
601 | fclose(fi);
|
---|
602 | } else if (strcmp(inp_str, "postscript") == 0) {
|
---|
603 | if (!getstring(inp_str)) return;
|
---|
604 | c->marktype = 'p';
|
---|
605 | if (strcmp(inp_str, ":") == 0) {
|
---|
606 | c->postfile = 0;
|
---|
607 | if ((txt = getmultiline()) == CNULL) return;
|
---|
608 | c->postscript = txt;
|
---|
609 | } else {
|
---|
610 | c->postfile = 1;
|
---|
611 | c->postscript = (char *) malloc ((strlen(inp_str)+1)*sizeof(char));
|
---|
612 | strcpy(c->postscript, inp_str);
|
---|
613 | fi = fopen(c->postscript, "r");
|
---|
614 | if (fi == NULL) {
|
---|
615 | error_header();
|
---|
616 | fprintf(stderr, "couldn't open postscript file '%s'\n",
|
---|
617 | c->postscript);
|
---|
618 | exit(1);
|
---|
619 | }
|
---|
620 | fclose(fi);
|
---|
621 | }
|
---|
622 | } else if (strcmp(inp_str, "poly") == 0) {
|
---|
623 | c->poly = 1;
|
---|
624 | } else if (strcmp(inp_str, "nopoly") == 0) {
|
---|
625 | c->poly = 0;
|
---|
626 | } else if (strcmp(inp_str, "larrow") == 0) {
|
---|
627 | c->larrow = 1;
|
---|
628 | } else if (strcmp(inp_str, "nolarrow") == 0) {
|
---|
629 | c->larrow = 0;
|
---|
630 | } else if (strcmp(inp_str, "rarrow") == 0) {
|
---|
631 | c->rarrow = 1;
|
---|
632 | } else if (strcmp(inp_str, "norarrow") == 0) {
|
---|
633 | c->rarrow = 0;
|
---|
634 | } else if (strcmp(inp_str, "larrows") == 0) {
|
---|
635 | c->larrows = 1;
|
---|
636 | } else if (strcmp(inp_str, "nolarrows") == 0) {
|
---|
637 | c->larrows = 0;
|
---|
638 | } else if (strcmp(inp_str, "rarrows") == 0) {
|
---|
639 | c->rarrows = 1;
|
---|
640 | } else if (strcmp(inp_str, "norarrows") == 0) {
|
---|
641 | c->rarrows = 0;
|
---|
642 | } else if (strcmp(inp_str, "bezier") == 0) {
|
---|
643 | c->bezier = 1;
|
---|
644 | } else if (strcmp(inp_str, "nobezier") == 0) {
|
---|
645 | c->bezier = 0;
|
---|
646 | } else if (strcmp(inp_str, "asize") == 0) {
|
---|
647 | if (!getfloat(&f)) rejecttoken();
|
---|
648 | else {
|
---|
649 | c->asize[0] = f;
|
---|
650 | if (!getfloat(&f)) rejecttoken();
|
---|
651 | else c->asize[1] = f;
|
---|
652 | }
|
---|
653 | } else if (strcmp(inp_str, "clip") == 0) {
|
---|
654 | c->clip = 1;
|
---|
655 | } else if (strcmp(inp_str, "noclip") == 0) {
|
---|
656 | c->clip = 0;
|
---|
657 | } else {
|
---|
658 | rejecttoken();
|
---|
659 | return;
|
---|
660 | }
|
---|
661 | }
|
---|
662 | }
|
---|
663 |
|
---|
664 | void edit_hash_label(Axis a)
|
---|
665 | {
|
---|
666 | float at, f;
|
---|
667 | char *s;
|
---|
668 | char inp_str[256];
|
---|
669 | String st;
|
---|
670 | int done;
|
---|
671 |
|
---|
672 | s = CNULL;
|
---|
673 |
|
---|
674 | at = (first(a->hash_lines) == nil(a->hash_lines)) ? FSIG
|
---|
675 | : first(a->hash_lines)->loc;
|
---|
676 | while(1) {
|
---|
677 | done = 0;
|
---|
678 | if (getstring(inp_str)) {
|
---|
679 | if (strcmp(inp_str, ":") == 0) {
|
---|
680 | if ((s = getlabel()) == CNULL) return;
|
---|
681 | } else if (strcmp(inp_str, "at") == 0) {
|
---|
682 | if (getfloat(&f)) {
|
---|
683 | at = f;
|
---|
684 | } else {
|
---|
685 | rejecttoken();
|
---|
686 | done = 1;
|
---|
687 | }
|
---|
688 | } else {
|
---|
689 | rejecttoken();
|
---|
690 | done = 1;
|
---|
691 | }
|
---|
692 | } else {
|
---|
693 | done = 1;
|
---|
694 | }
|
---|
695 | if (done) {
|
---|
696 | if (s == CNULL) return;
|
---|
697 | if (at == FSIG) {
|
---|
698 | error_header();
|
---|
699 | fprintf(stderr,
|
---|
700 | "hash_label either needs \"at\" or an associated \"hash_at\"\n");
|
---|
701 | exit(1);
|
---|
702 | }
|
---|
703 | st = (String) get_node(a->hash_labels);
|
---|
704 | st->s = new_label();
|
---|
705 | st->s->label = s;
|
---|
706 | st->s->x = at;
|
---|
707 | st->s->y = at;
|
---|
708 | insert(st, a->hash_labels);
|
---|
709 | return;
|
---|
710 | }
|
---|
711 | }
|
---|
712 | }
|
---|
713 |
|
---|
714 | void edit_axis(Axis a)
|
---|
715 | {
|
---|
716 | char inp_str[256];
|
---|
717 | float f;
|
---|
718 | int i;
|
---|
719 | Hash h;
|
---|
720 |
|
---|
721 | while ( getstring(inp_str) ) {
|
---|
722 |
|
---|
723 | if (strcmp(inp_str, "size") == 0) {
|
---|
724 | if ( getfloat(&f)) a->size = f; else rejecttoken();
|
---|
725 | } else if (strcmp(inp_str, "max") == 0) {
|
---|
726 | if ( getfloat(&f)) a->max = f; else rejecttoken();
|
---|
727 | } else if (strcmp(inp_str, "min") == 0) {
|
---|
728 | if ( getfloat(&f)) a->min = f; else rejecttoken();
|
---|
729 | } else if (strcmp(inp_str, "hash") == 0) {
|
---|
730 | if ( getfloat(&f)) a->hash_interval = f; else rejecttoken();
|
---|
731 | } else if (strcmp(inp_str, "shash") == 0) {
|
---|
732 | if ( getfloat(&f)) {
|
---|
733 | a->hash_start = f;
|
---|
734 | a->start_given = 1;
|
---|
735 | }
|
---|
736 | else rejecttoken();
|
---|
737 | } else if (strcmp(inp_str, "mhash") == 0) {
|
---|
738 | if (getint(&i)) a->minor_hashes = i; else rejecttoken();
|
---|
739 | } else if (strcmp(inp_str, "precision") == 0) {
|
---|
740 | if (getint(&i)) a->precision = i; else rejecttoken();
|
---|
741 | } else if (strcmp(inp_str, "label") == 0) {
|
---|
742 | edit_label(a->label);
|
---|
743 | } else if (strcmp(inp_str, "hash_format") == 0) {
|
---|
744 | if (!getstring(inp_str)) return;
|
---|
745 | if (strcmp(inp_str, "g") == 0) {
|
---|
746 | a->hash_format = 'g';
|
---|
747 | } else if (strcmp(inp_str, "G") == 0) {
|
---|
748 | a->hash_format = 'G';
|
---|
749 | } else if (strcmp(inp_str, "E") == 0) {
|
---|
750 | a->hash_format = 'E';
|
---|
751 | } else if (strcmp(inp_str, "e") == 0) {
|
---|
752 | a->hash_format = 'e';
|
---|
753 | } else if (strcmp(inp_str, "f") == 0) {
|
---|
754 | a->hash_format = 'f';
|
---|
755 | } else {
|
---|
756 | error_header();
|
---|
757 | fprintf(stderr, "Invalid hash_style %s. Must be f, g, G, e or E\n",
|
---|
758 | inp_str);
|
---|
759 | exit(1);
|
---|
760 | }
|
---|
761 | } else if (strcmp(inp_str, "hash_labels") == 0) {
|
---|
762 | edit_label(a->hl);
|
---|
763 | } else if (strcmp(inp_str, "log_base") == 0) {
|
---|
764 | if (getfloat(&f)) {
|
---|
765 | if (f <= 1.0) {
|
---|
766 | error_header();
|
---|
767 | fprintf(stderr, "\"log_base %f\": log_base must be > 1.0\n", f);
|
---|
768 | exit(1);
|
---|
769 | } else a->log_base = f;
|
---|
770 | } else rejecttoken();
|
---|
771 | } else if (strcmp(inp_str, "draw_at") == 0) {
|
---|
772 | if ( getfloat(&f)) a->draw_at = f; else rejecttoken();
|
---|
773 | } else if (strcmp(inp_str, "log") == 0) {
|
---|
774 | a->is_lg = 1;
|
---|
775 | } else if (strcmp(inp_str, "linear") == 0) {
|
---|
776 | a->is_lg = 0;
|
---|
777 | } else if (strcmp(inp_str, "nodraw") == 0) {
|
---|
778 | a->draw_hash_labels = 0;
|
---|
779 | a->draw_axis_line = 0;
|
---|
780 | a->draw_hash_marks = 0;
|
---|
781 | a->draw_axis_label = 0;
|
---|
782 | } else if (strcmp(inp_str, "draw") == 0) {
|
---|
783 | a->draw_hash_labels = 1;
|
---|
784 | a->draw_axis_line = 1;
|
---|
785 | a->draw_hash_marks = 1;
|
---|
786 | a->draw_axis_label = 1;
|
---|
787 | } else if (strcmp(inp_str, "hash_at") == 0 ||
|
---|
788 | strcmp(inp_str, "mhash_at") == 0) {
|
---|
789 | if (getfloat(&f)) {
|
---|
790 | h = (Hash) get_node (a->hash_lines);
|
---|
791 | h->loc = f;
|
---|
792 | h->major = (inp_str[0] == 'h');
|
---|
793 | h->size = h->major ? HASH_SIZE : MHASH_SIZE;
|
---|
794 | insert(h, a->hash_lines);
|
---|
795 | } else rejecttoken();
|
---|
796 | } else if (strcmp(inp_str, "hash_label") == 0) {
|
---|
797 | edit_hash_label(a);
|
---|
798 | } else if (strcmp(inp_str, "hash_scale") == 0) {
|
---|
799 | if ( getfloat(&f)) a->hash_scale = f; else rejecttoken();
|
---|
800 | } else if (strcmp(inp_str, "auto_hash_marks") == 0) {
|
---|
801 | a->auto_hash_marks = 1;
|
---|
802 | } else if (strcmp(inp_str, "no_auto_hash_marks") == 0) {
|
---|
803 | a->auto_hash_marks = 0;
|
---|
804 | } else if (strcmp(inp_str, "auto_hash_labels") == 0) {
|
---|
805 | a->auto_hash_labels = 1;
|
---|
806 | } else if (strcmp(inp_str, "no_auto_hash_labels") == 0) {
|
---|
807 | a->auto_hash_labels = 0;
|
---|
808 | } else if (strcmp(inp_str, "draw_hash_labels_at") == 0) {
|
---|
809 | if (getfloat(&f)) a->draw_hash_labels_at = f; else rejecttoken();
|
---|
810 | } else if (strcmp(inp_str, "draw_hash_marks_at") == 0) {
|
---|
811 | if (getfloat(&f)) a->draw_hash_marks_at = f; else rejecttoken();
|
---|
812 | } else if (strcmp(inp_str, "no_draw_hash_labels") == 0) {
|
---|
813 | a->draw_hash_labels = 0;
|
---|
814 | } else if (strcmp(inp_str, "draw_hash_labels") == 0) {
|
---|
815 | a->draw_hash_labels = 1;
|
---|
816 | } else if (strcmp(inp_str, "no_draw_axis_line") == 0) {
|
---|
817 | a->draw_axis_line = 0;
|
---|
818 | } else if (strcmp(inp_str, "draw_axis_line") == 0) {
|
---|
819 | a->draw_axis_line = 1;
|
---|
820 | } else if (strcmp(inp_str, "no_draw_axis") == 0) {
|
---|
821 | a->draw_axis_line = 0;
|
---|
822 | } else if (strcmp(inp_str, "draw_axis") == 0) {
|
---|
823 | a->draw_axis_line = 1;
|
---|
824 | } else if (strcmp(inp_str, "no_draw_hash_marks") == 0) {
|
---|
825 | a->draw_hash_marks = 0;
|
---|
826 | } else if (strcmp(inp_str, "draw_hash_marks") == 0) {
|
---|
827 | a->draw_hash_marks = 1;
|
---|
828 | } else if (strcmp(inp_str, "no_draw_axis_label") == 0) {
|
---|
829 | a->draw_axis_label = 0;
|
---|
830 | } else if (strcmp(inp_str, "draw_axis_label") == 0) {
|
---|
831 | a->draw_axis_label = 1;
|
---|
832 | } else if (strcmp(inp_str, "no_grid_lines") == 0) {
|
---|
833 | a->grid_lines = 0;
|
---|
834 | } else if (strcmp(inp_str, "grid_lines") == 0) {
|
---|
835 | a->grid_lines = 1;
|
---|
836 | } else if (strcmp(inp_str, "no_mgrid_lines") == 0) {
|
---|
837 | a->mgrid_lines = 0;
|
---|
838 | } else if (strcmp(inp_str, "mgrid_lines") == 0) {
|
---|
839 | a->mgrid_lines = 1;
|
---|
840 | } else if (strcmp(inp_str, "gray") == 0) {
|
---|
841 | if (!getfloat(&f)) rejecttoken(); else {
|
---|
842 | a->graytype = 'g';
|
---|
843 | a->gray[0] = f;
|
---|
844 | }
|
---|
845 | } else if (strcmp(inp_str, "color") == 0) {
|
---|
846 | a->graytype = 'c';
|
---|
847 | for( i = 0 ; i < 3 ; i++ ) {
|
---|
848 | if(!getfloat(&f)) {
|
---|
849 | rejecttoken();
|
---|
850 | a->graytype = 'n';
|
---|
851 | break ;
|
---|
852 | } else a->gray[i] = f ;
|
---|
853 | }
|
---|
854 | } else if (strcmp(inp_str, "grid_gray") == 0) {
|
---|
855 | if (!getfloat(&f)) rejecttoken(); else {
|
---|
856 | a->gr_graytype = 'g';
|
---|
857 | a->gr_gray[0] = f;
|
---|
858 | }
|
---|
859 | } else if (strcmp(inp_str, "grid_color") == 0) {
|
---|
860 | a->gr_graytype = 'c';
|
---|
861 | for( i = 0 ; i < 3 ; i++ ) {
|
---|
862 | if(!getfloat(&f)) {
|
---|
863 | rejecttoken();
|
---|
864 | a->gr_graytype = 'n';
|
---|
865 | break ;
|
---|
866 | } else a->gr_gray[i] = f ;
|
---|
867 | }
|
---|
868 | } else if (strcmp(inp_str, "mgrid_gray") == 0) {
|
---|
869 | if (!getfloat(&f)) rejecttoken(); else {
|
---|
870 | a->mgr_graytype = 'g';
|
---|
871 | a->mgr_gray[0] = f;
|
---|
872 | }
|
---|
873 | } else if (strcmp(inp_str, "mgrid_color") == 0) {
|
---|
874 | a->mgr_graytype = 'c';
|
---|
875 | for( i = 0 ; i < 3 ; i++ ) {
|
---|
876 | if(!getfloat(&f)) {
|
---|
877 | rejecttoken();
|
---|
878 | a->mgr_graytype = 'n';
|
---|
879 | break ;
|
---|
880 | } else a->mgr_gray[i] = f ;
|
---|
881 | }
|
---|
882 | } else {
|
---|
883 | rejecttoken();
|
---|
884 | return;
|
---|
885 | }
|
---|
886 | }
|
---|
887 | }
|
---|
888 |
|
---|
889 | void edit_legend(Legend l)
|
---|
890 | {
|
---|
891 | char inp_str[256];
|
---|
892 | float f;
|
---|
893 |
|
---|
894 | while ( getstring(inp_str) ) {
|
---|
895 | if (strcmp(inp_str, "x") == 0) {
|
---|
896 | if (!getfloat(&f)) rejecttoken();
|
---|
897 | else {
|
---|
898 | l->l->x = f;
|
---|
899 | l->l->hj = 'l';
|
---|
900 | l->l->vj = 't';
|
---|
901 | l->type = 'u';
|
---|
902 | }
|
---|
903 | } else if (strcmp(inp_str, "y") == 0) {
|
---|
904 | if (!getfloat(&f)) rejecttoken();
|
---|
905 | else {
|
---|
906 | l->l->y = f;
|
---|
907 | l->l->hj = 'l';
|
---|
908 | l->l->vj = 't';
|
---|
909 | l->type = 'u';
|
---|
910 | }
|
---|
911 | } else if (strcmp(inp_str, "right") == 0 ||
|
---|
912 | strcmp(inp_str, "on") == 0) {
|
---|
913 | l->type = 'u';
|
---|
914 | l->l->y = FSIG;
|
---|
915 | l->l->x = FSIG;
|
---|
916 | l->l->hj = 'l';
|
---|
917 | l->l->vj = 'c';
|
---|
918 | } else if (strcmp(inp_str, "left") == 0) {
|
---|
919 | l->type = 'u';
|
---|
920 | l->l->y = FSIG;
|
---|
921 | l->l->x = FSIG;
|
---|
922 | l->l->hj = 'r';
|
---|
923 | l->l->vj = 'c';
|
---|
924 | } else if (strcmp(inp_str, "off") == 0) {
|
---|
925 | l->type = 'n';
|
---|
926 | } else if (strcmp(inp_str, "top") == 0) {
|
---|
927 | l->type = 'u';
|
---|
928 | l->l->y = FSIG;
|
---|
929 | l->l->x = FSIG;
|
---|
930 | l->l->hj = 'l';
|
---|
931 | l->l->vj = 'b';
|
---|
932 | } else if (strcmp(inp_str, "bottom") == 0) {
|
---|
933 | l->type = 'u';
|
---|
934 | l->l->y = FSIG;
|
---|
935 | l->l->x = FSIG;
|
---|
936 | l->l->hj = 'l';
|
---|
937 | l->l->vj = 't';
|
---|
938 | } else if (strcmp(inp_str, "custom") == 0) {
|
---|
939 | l->type = 'c';
|
---|
940 | } else if (strcmp(inp_str, "linelength") == 0) {
|
---|
941 | if (!getfloat(&f)) rejecttoken(); else l->linelength = f;
|
---|
942 | } else if (strcmp(inp_str, "linebreak") == 0) {
|
---|
943 | if (!getfloat(&f)) rejecttoken(); else l->linebreak = f;
|
---|
944 | } else if (strcmp(inp_str, "midspace") == 0) {
|
---|
945 | if (!getfloat(&f)) rejecttoken(); else l->midspace = f;
|
---|
946 | } else if (strcmp(inp_str, "defaults") == 0) {
|
---|
947 | edit_label(l->l);
|
---|
948 | } else {
|
---|
949 | rejecttoken();
|
---|
950 | return;
|
---|
951 | }
|
---|
952 | }
|
---|
953 | }
|
---|
954 |
|
---|
955 | void edit_graph(Graph g, Graphs gs, Graphs all_gs)
|
---|
956 | {
|
---|
957 | char inp_str[80];
|
---|
958 | int num;
|
---|
959 | String s;
|
---|
960 | float f;
|
---|
961 |
|
---|
962 | while ( getstring(inp_str) ) {
|
---|
963 | if (strcmp(inp_str, "xaxis") == 0)
|
---|
964 | edit_axis(g->x_axis);
|
---|
965 | else if (strcmp(inp_str, "yaxis") == 0)
|
---|
966 | edit_axis(g->y_axis);
|
---|
967 | else if (strcmp(inp_str, "curve") == 0) {
|
---|
968 | if (!getint(&num)) {
|
---|
969 | error_header(); fprintf(stderr, "\"curve\" not followed by number\n");
|
---|
970 | exit(1);
|
---|
971 | }
|
---|
972 | edit_curve(get_curve(g->curves, num), g);
|
---|
973 | } else if (strcmp(inp_str, "newcurve") == 0) {
|
---|
974 | if (first(g->curves) == nil(g->curves))
|
---|
975 | edit_curve(new_curve(g->curves, 0), g);
|
---|
976 | else edit_curve(new_curve(g->curves, last(g->curves)->num + 1), g);
|
---|
977 | } else if (strcmp(inp_str, "copycurve") == 0) {
|
---|
978 | edit_curve(do_copy_curve(g, gs, all_gs), g);
|
---|
979 | } else if (strcmp(inp_str, "newline") == 0) {
|
---|
980 | if (first(g->curves) == nil(g->curves))
|
---|
981 | edit_curve(new_line(g->curves, 0), g);
|
---|
982 | else edit_curve(new_line(g->curves, last(g->curves)->num + 1), g);
|
---|
983 | } else if (strcmp(inp_str, "title") == 0) {
|
---|
984 | edit_label(g->title);
|
---|
985 | } else if (strcmp(inp_str, "legend") == 0) {
|
---|
986 | edit_legend(g->legend);
|
---|
987 | } else if (strcmp(inp_str, "x_translate") == 0) {
|
---|
988 | if (!getfloat(&f)) rejecttoken(); else g->x_translate = f;
|
---|
989 | } else if (strcmp(inp_str, "y_translate") == 0) {
|
---|
990 | if (!getfloat(&f)) rejecttoken(); else g->y_translate = f;
|
---|
991 | } else if (strcmp(inp_str, "string") == 0) {
|
---|
992 | if (!getint(&num)) {
|
---|
993 | error_header(); fprintf(stderr, "\"string\" not followed by number\n");
|
---|
994 | exit(1);
|
---|
995 | }
|
---|
996 | s = get_string(g->strings, num);
|
---|
997 | edit_label(s->s);
|
---|
998 | } else if (strcmp(inp_str, "newstring") == 0) {
|
---|
999 | if (first(g->strings) == nil(g->strings))
|
---|
1000 | s = new_string(g->strings, 0);
|
---|
1001 | else s = new_string(g->strings, last(g->strings)->num + 1);
|
---|
1002 | edit_label(s->s);
|
---|
1003 | } else if (strcmp(inp_str, "copystring") == 0 ||
|
---|
1004 | strcmp(inp_str, "copyline") == 0) {
|
---|
1005 | edit_label(do_copy_string(g, gs, all_gs));
|
---|
1006 | } else if (strcmp(inp_str, "inherit_axes") == 0) {
|
---|
1007 | inherit_axes(g, last_graph(g, gs, all_gs));
|
---|
1008 | } else if (strcmp(inp_str, "Y") == 0) {
|
---|
1009 | if (!getfloat(&f)) rejecttoken(); else gs->height = f;
|
---|
1010 | } else if (strcmp(inp_str, "X") == 0) {
|
---|
1011 | if (!getfloat(&f)) rejecttoken(); else gs->width = f;
|
---|
1012 | } else if (strcmp(inp_str, "border") == 0) {
|
---|
1013 | g->border = 1;
|
---|
1014 | } else if (strcmp(inp_str, "noborder") == 0) {
|
---|
1015 | g->border = 0;
|
---|
1016 | } else if (strcmp(inp_str, "clip") == 0) {
|
---|
1017 | g->clip = 1;
|
---|
1018 | } else if (strcmp(inp_str, "noclip") == 0) {
|
---|
1019 | g->clip = 0;
|
---|
1020 | } else {
|
---|
1021 | rejecttoken();
|
---|
1022 | return;
|
---|
1023 | }
|
---|
1024 | }
|
---|
1025 | }
|
---|
1026 |
|
---|
1027 | void edit_graphs(Graphs gs)
|
---|
1028 | {
|
---|
1029 | Graphs the_g;
|
---|
1030 | Graph g, tmp_g;
|
---|
1031 | char inp_str[80];
|
---|
1032 | float f;
|
---|
1033 | int num, i, ok, j;
|
---|
1034 |
|
---|
1035 | the_g = first(gs);
|
---|
1036 | while ( getstring(inp_str) ) {
|
---|
1037 | if (strcmp(inp_str, "graph") == 0) {
|
---|
1038 | if (!getint(&num)) {
|
---|
1039 | error_header(); fprintf(stderr, "\"graph\" not followed by number\n");
|
---|
1040 | exit(1);
|
---|
1041 | }
|
---|
1042 | edit_graph(get_graph(the_g->g, num), the_g, gs);
|
---|
1043 | } else if (strcmp(inp_str, "newgraph") == 0) {
|
---|
1044 | if (first(the_g->g) == nil(the_g->g))
|
---|
1045 | edit_graph(new_graph(the_g->g, 0), the_g, gs);
|
---|
1046 | else edit_graph(new_graph(the_g->g, last(the_g->g)->num + 1), the_g, gs);
|
---|
1047 | } else if (strcmp(inp_str, "copygraph") == 0) {
|
---|
1048 | if (first(the_g->g) == nil(the_g->g))
|
---|
1049 | g = new_graph(the_g->g, 0);
|
---|
1050 | else g = new_graph(the_g->g, last(the_g->g)->num + 1);
|
---|
1051 | if (!getint(&num)) {
|
---|
1052 | rejecttoken();
|
---|
1053 | inherit_axes(g, last_graph(g, the_g, gs));
|
---|
1054 | } else {
|
---|
1055 | ok = 0;
|
---|
1056 | tmp_g = the_g->g;
|
---|
1057 | while(!ok) {
|
---|
1058 | tmp_g = prev(tmp_g);
|
---|
1059 | if (tmp_g == nil(the_g->g) || tmp_g->num < num) {
|
---|
1060 | error_header();
|
---|
1061 | fprintf(stderr, "copygraph: no graph #%d\n", num);
|
---|
1062 | exit(1);
|
---|
1063 | }
|
---|
1064 | ok = (tmp_g->num == num);
|
---|
1065 | }
|
---|
1066 | inherit_axes(g, tmp_g);
|
---|
1067 | }
|
---|
1068 | edit_graph(g, the_g, gs);
|
---|
1069 | } else if (strcmp(inp_str, "Y") == 0) {
|
---|
1070 | if (!getfloat(&f)) rejecttoken(); else the_g->height = f;
|
---|
1071 | } else if (strcmp(inp_str, "X") == 0) {
|
---|
1072 | if (!getfloat(&f)) rejecttoken(); else the_g->width = f;
|
---|
1073 | } else if (strcmp(inp_str, "newpage") == 0) {
|
---|
1074 | new_graphs(gs);
|
---|
1075 | the_g = last(gs);
|
---|
1076 | } else if (strcmp(inp_str, "bbox") == 0) {
|
---|
1077 | for (i = 0; i < 4; i++) {
|
---|
1078 | if (!getint(&j)) {
|
---|
1079 | error_header();
|
---|
1080 | fprintf(stderr, "Bbox definition must have four integers\n");
|
---|
1081 | exit(1);
|
---|
1082 | } else {
|
---|
1083 | the_g->bb[i] = j;
|
---|
1084 | }
|
---|
1085 | }
|
---|
1086 | } else if (strcmp(inp_str, "preamble") == 0) {
|
---|
1087 | if (!getstring(inp_str)) return;
|
---|
1088 | if (strcmp(inp_str, ":") != 0) {
|
---|
1089 | the_g->prefile = 1;
|
---|
1090 | the_g->preamble = (char *) malloc (sizeof(char)*(strlen(inp_str)+1));
|
---|
1091 | strcpy(the_g->preamble, inp_str);
|
---|
1092 | } else {
|
---|
1093 | the_g->prefile = 0;
|
---|
1094 | the_g->preamble = getmultiline();
|
---|
1095 | if (the_g->preamble == CNULL) return;
|
---|
1096 | }
|
---|
1097 | } else if (strcmp(inp_str, "epilogue") == 0) {
|
---|
1098 | if (!getstring(inp_str)) return;
|
---|
1099 | if (strcmp(inp_str, ":") != 0) {
|
---|
1100 | the_g->epifile = 1;
|
---|
1101 | the_g->epilogue = (char *) malloc (sizeof(char)*(strlen(inp_str)+1));
|
---|
1102 | strcpy(the_g->epilogue, inp_str);
|
---|
1103 | } else {
|
---|
1104 | the_g->epifile = 0;
|
---|
1105 | the_g->epilogue = getmultiline();
|
---|
1106 | if (the_g->epilogue == CNULL) return;
|
---|
1107 | }
|
---|
1108 | } else {
|
---|
1109 | error_header(); fprintf(stderr, "Bad token: %s\n", inp_str);
|
---|
1110 | exit(1);
|
---|
1111 | }
|
---|
1112 | }
|
---|
1113 | }
|
---|