source: trunk/Jgraph/edit.c@ 418

Last change on this file since 418 was 418, checked in by Nicholas Riley, 16 years ago

Jgraph 8.3 from http://www.cs.utk.edu/~plank/plank/jgraph/jgraph.tar.gz

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