home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume31 / jgraph / part03 < prev    next >
Encoding:
Text File  |  1992-07-13  |  53.8 KB  |  1,822 lines

  1. Newsgroups: comp.sources.misc
  2. From: jsp@Princeton.EDU (James Plank)
  3. Subject:  v31i033:  jgraph - A filter for plotting postscript graphs v8.0, Part03/07
  4. Message-ID: <1992Jul14.151608.10377@sparky.imd.sterling.com>
  5. X-Md4-Signature: bb2ffa7ca9e27296075d716a079bb5b0
  6. Date: Tue, 14 Jul 1992 15:16:08 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jsp@Princeton.EDU (James Plank)
  10. Posting-number: Volume 31, Issue 33
  11. Archive-name: jgraph/part03
  12. Environment: UNIX, VMS, postscript
  13. Supersedes: jgraph: Volume 16, Issue 20
  14.  
  15. #! /bin/sh
  16. # This is a shell archive.  Remove anything before this line, then feed it
  17. # into a shell via "sh file" or similar.  To overwrite existing files,
  18. # type "sh file -c".
  19. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  20. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  21. # Contents:  draw.c edit.c prio_list.h
  22. # Wrapped by kent@sparky on Sun Jul 12 20:04:02 1992
  23. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  24. echo If this archive is complete, you will see the following message:
  25. echo '          "shar: End of archive 3 (of 7)."'
  26. if test -f 'draw.c' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'draw.c'\"
  28. else
  29.   echo shar: Extracting \"'draw.c'\" \(18554 characters\)
  30.   sed "s/^X//" >'draw.c' <<'END_OF_FILE'
  31. X/* 
  32. X * $Source: /n/fs/vd/jsp/src/jgraph/RCS/draw.c,v $
  33. X * $Revision: 8.0 $
  34. X * $Date: 92/07/03 14:15:39 $
  35. X * $Author: jsp $
  36. X */
  37. X
  38. X#include "jgraph.h"
  39. X#include <stdio.h>
  40. X#include <math.h>
  41. X
  42. Xstatic char real_eof = EOF;
  43. X
  44. Xfloat ctop(val, axis)
  45. Xfloat val;
  46. XAxis axis;
  47. X{
  48. X  if (axis->is_lg) {
  49. X    if (val <= 0.0) {
  50. X      error_header();
  51. X      fprintf(stderr, 
  52. X              "Value of %f is at negative infinity with logrhythmic %c axis\n", 
  53. X              val, (axis->is_x) ? 'x' : 'y'); 
  54. X       exit(1);
  55. X    }
  56. X    return (log(val) / axis->logfactor - axis->logmin) * axis->factor;
  57. X  } else {
  58. X    return (val - axis->min) * axis->factor;
  59. X  }
  60. X}
  61. X
  62. Xfloat disttop(val, axis)
  63. Xfloat val;
  64. XAxis axis;
  65. X{
  66. X  if (axis->is_lg) {
  67. X    return FCPI * val;
  68. X  } else {
  69. X    return (val) * axis->factor;
  70. X  }
  71. X}
  72. X
  73. Xfloat intop(val)
  74. Xfloat val;
  75. X{
  76. X  return FCPI * val;
  77. X}
  78. X
  79. X#define MAXIMUM(a,b) ((a > b) ? a : b)
  80. X
  81. Xdraw_axis(a, other)
  82. XAxis a, other;
  83. X{
  84. X  char orientation;
  85. X  Hash h;
  86. X  String s;
  87. X
  88. X  orientation = (a->is_x) ? 'x' : 'y';
  89. X  setlinewidth(1.0);
  90. X  comment("Drawing Axis");
  91. X  if (a->grid_lines) {
  92. X    comment("Drawing Grid lines");
  93. X    gsave();
  94. X    setgray(a->gr_graytype, a->gr_gray);
  95. X    for (h = first(a->hash_lines); h != nil(a->hash_lines); h = next(h)) {
  96. X      if (h->major) {
  97. X        printline(h->loc, 0.0, h->loc, other->psize, orientation);
  98. X      }
  99. X    }
  100. X    grestore();
  101. X  }
  102. X  if (a->mgrid_lines) {
  103. X    comment("Drawing Minor Grid lines");
  104. X    gsave();
  105. X    setgray(a->mgr_graytype, a->mgr_gray);
  106. X    for (h = first(a->hash_lines); h != nil(a->hash_lines); h = next(h)) {
  107. X      if (!h->major) {
  108. X        printline(h->loc, 0.0, h->loc, other->psize, orientation);
  109. X      }
  110. X    }
  111. X    grestore();
  112. X  }
  113. X  gsave();
  114. X  setgray(a->graytype, a->gray);
  115. X  if (a->draw_axis_line) {
  116. X    printline(0.0, a->draw_at, a->psize, a->draw_at, orientation);
  117. X  }
  118. X  if (a->draw_hash_marks) {
  119. X    comment("Drawing Hash Marks");
  120. X    for (h = first(a->hash_lines); h != nil(a->hash_lines); h = next(h)) {
  121. X      printline(h->loc, a->draw_hash_marks_at, h->loc, 
  122. X                a->draw_hash_marks_at + (h->size * a->hash_scale), 
  123. X                orientation);
  124. X    }
  125. X  }
  126. X  if (a->draw_hash_labels) {
  127. X    comment("Drawing Hash Labels");
  128. X    for (s = first(a->hash_labels); s != nil(a->hash_labels); s = next(s)) {
  129. X      a->hl->label = s->s->label;
  130. X      if (a->is_x) {
  131. X        a->hl->x = s->s->x;
  132. X      } else {
  133. X        a->hl->y = s->s->y;
  134. X      }
  135. X      draw_label(a->hl);
  136. X    }
  137. X  }
  138. X  if (a->draw_axis_label) {
  139. X    comment("Drawing Axis Label");
  140. X    draw_label(a->label);
  141. X  }
  142. X  grestore();
  143. X  printf("\n");
  144. X}
  145. X
  146. X
  147. Xdraw_label(l)
  148. XLabel l;
  149. X{
  150. X  if (l->label == CNULL) return;
  151. X  comment(l->label);
  152. X  print_label(l);
  153. X}
  154. X
  155. Xset_clip(g)
  156. XGraph g;
  157. X{
  158. X  comment("Setting Clip");
  159. X  printf("newpath\n");
  160. X  printf(" 0 0 moveto 0 %f lineto %f %f lineto %f 0 lineto\n",
  161. X           g->y_axis->psize, g->x_axis->psize,
  162. X           g->y_axis->psize, g->x_axis->psize);
  163. X  printf("  closepath clip newpath\n");
  164. X}
  165. X
  166. Xdraw_curves(g)
  167. XGraph g;
  168. X{
  169. X  Curve c;
  170. X
  171. X  gsave();
  172. X  printf("\n");
  173. X  if (g->clip) set_clip(g);
  174. X  for(c = first(g->curves); c != nil(g->curves); c = next(c)) {
  175. X    draw_curve(c, g);
  176. X  }
  177. X  grestore();
  178. X  printf("\n");
  179. X}
  180. X
  181. Xdraw_curve(c, g)
  182. XCurve c;
  183. XGraph g;
  184. X{
  185. X  Point p, px, py;
  186. X  int i, j;
  187. X  float this_x, this_y, last_x, last_y, x, y;
  188. X
  189. X  gsave();
  190. X  setgray(c->graytype, c->gray);
  191. X  if (c->clip) set_clip(g);
  192. X  if (first(c->xepts) != nil(c->xepts) ||
  193. X      first(c->yepts) != nil(c->yepts)) {
  194. X    comment("Drawing Epts");
  195. X    px = first(c->xepts);
  196. X    py = first(c->yepts);
  197. X    setlinewidth(c->linethick);
  198. X    setlinestyle('s', (Flist)0);
  199. X    for (p = first(c->pts); p != nil(c->pts); p = next(p)) {
  200. X      if (p->e == 'x') {
  201. X        x = ctop(p->x, g->x_axis);
  202. X        y = ctop(p->y, g->y_axis);
  203. X        print_ebar(x, y, ctop(px->x, g->x_axis), c->marksize[1]/2.0, 'x');
  204. X        px = next(px);
  205. X        print_ebar(x, y, ctop(px->x, g->x_axis), c->marksize[1]/2.0, 'x');
  206. X        px = next(px);
  207. X      } else if (p->e == 'y') {
  208. X        x = ctop(p->x, g->x_axis);
  209. X        y = ctop(p->y, g->y_axis);
  210. X        print_ebar(y, x, ctop(py->y, g->y_axis), c->marksize[0]/2.0, 'y');
  211. X        py = next(py);
  212. X        print_ebar(y, x, ctop(py->y, g->y_axis), c->marksize[0]/2.0, 'y');
  213. X        py = next(py);
  214. X      }
  215. X    }
  216. X  }
  217. X
  218. X  comment("Drawing Curve");
  219. X  if (c->linetype != '0' || c->poly) {
  220. X    if (c->bezier) {
  221. X      i = 0;
  222. X      j = 0;
  223. X      if (c->poly) printf("newpath ");
  224. X      for (p = first(c->pts); p != nil(c->pts); p = next(p)) {
  225. X        if (j == 0 && i == 0) {
  226. X          start_line(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis), c);
  227. X          j++;
  228. X        } else if (i != 0) {
  229. X          bezier_control(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis));
  230. X        } else {
  231. X          bezier_end(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis));
  232. X          j++;
  233. X        }
  234. X        if (!c->poly && j == 30 && i == 0) {
  235. X          end_line();
  236. X          p = prev(p);
  237. X          j = 0;
  238. X          i = 0;
  239. X        } else i = (i + 1) % 3;
  240. X      }
  241. X      if (j != 0) {
  242. X        if (c->poly) {
  243. X          printf("closepath ");
  244. X          setfill(c->pfilltype, c->pfill);
  245. X        }
  246. X        end_line();
  247. X      }
  248. X    } else {
  249. X      i = 0;
  250. X      if (c->poly) printf("newpath ");
  251. X      for (p = first(c->pts);
  252. X           p != nil(c->pts);
  253. X           p = next(p)) {
  254. X        if (i == 0) {
  255. X          start_line(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis), c);
  256. X        } else {
  257. X          cont_line(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis));
  258. X        } 
  259. X        if (!c->poly && i == 100 && next(p)) {
  260. X          end_line();
  261. X          p = prev(p);
  262. X          i = 0;
  263. X        } else i++;
  264. X      }
  265. X      if (i != 0) {
  266. X        if (c->poly) {
  267. X          printf("closepath ");
  268. X          setfill(c->pfilltype, c->pfill);
  269. X        }
  270. X        end_line();
  271. X      }
  272. X    }
  273. X  }
  274. X  comment("Drawing Curve points");
  275. X  i = 0;
  276. X  for (p = first(c->pts);
  277. X       p != nil(c->pts);
  278. X       p = next(p)) {
  279. X    this_x = ctop(p->x, g->x_axis);
  280. X    this_y = ctop(p->y, g->y_axis);
  281. X    if (!c->bezier || i == 0) draw_mark(this_x, this_y, c, g);
  282. X    if (p != first(c->pts)) {
  283. X      if (c->rarrows || (c->rarrow && p == last(c->pts))) {
  284. X        if (!c->bezier || i == 0) 
  285. X          draw_arrow(this_x, this_y, last_x, last_y, c);
  286. X      }
  287. X      if (c->larrows || (c->larrow && prev(p) == first(c->pts))) {
  288. X        if (!c->bezier || i == 1) 
  289. X          draw_arrow(last_x, last_y, this_x, this_y, c);
  290. X      }
  291. X    }
  292. X    last_x = this_x;  
  293. X    last_y = this_y;  
  294. X    i = (i + 1) % 3;
  295. X  }
  296. X  grestore();
  297. X  printf("\n");
  298. X}
  299. X
  300. Xdraw_mark(x, y, c, g)
  301. Xfloat x, y;
  302. XCurve c;
  303. XGraph g;
  304. X{
  305. X  Point p;
  306. X  float ms0, ms1;
  307. X  int i, j;
  308. X  FILE *f;
  309. X  char ch;
  310. X
  311. X  if (c->marktype == 'n') return;
  312. X  ms0 = c->marksize[0] / 2.0;
  313. X  ms1 = c->marksize[1] / 2.0;
  314. X
  315. X  gsave();
  316. X  printf(" %f %f translate %f rotate\n", x, y, c->mrotate);
  317. X
  318. X  switch (c->marktype) {
  319. X    case 'n': break;
  320. X    case 'p': if (c->postscript == CNULL) break;
  321. X              printf("%f %f scale\n", ms0, ms1);
  322. X              if (!c->postfile) {
  323. X                printf("%s\n", c->postscript);
  324. X              } else {
  325. X                f = fopen(c->postscript, "r");
  326. X                if (f == NULL) {
  327. X                fprintf(stderr, 
  328. X                        "Error: postscript file %s couldn't be opened\n",
  329. X                        c->postscript);
  330. X                  exit(1);
  331. X                }
  332. X                for (ch = getc(f); ch != real_eof; ch = getc(f)) putchar(ch);
  333. X                putchar('\n');
  334. X                fclose(f);
  335. X              }
  336. X              break;
  337. X    case 'c': printline(-ms0, 0.0, ms0, 0.0, 'x');
  338. X              printline(-ms1, 0.0, ms1, 0.0, 'y');
  339. X              break;
  340. X    case 'b': start_poly(-ms0, -ms1);
  341. X              cont_poly(ms0, -ms1);
  342. X              cont_poly(ms0, ms1);
  343. X              cont_poly(-ms0, ms1);
  344. X              end_poly(c->filltype, c->fill);
  345. X              break;
  346. X    case 'd': start_poly(-ms0, 0.0);
  347. X              cont_poly(0.0, -ms1);
  348. X              cont_poly(ms0, 0.0);
  349. X              cont_poly(0.0, ms1);
  350. X              end_poly(c->filltype, c->fill);
  351. X              break;
  352. X    case 'g': p = first(c->general_marks);
  353. X              if (p == nil(c->general_marks)) break;
  354. X              if (next(p) == nil(c->general_marks)) break;
  355. X              start_poly(p->x*ms0, p->y*ms1);
  356. X              for(p = next(p); p != nil(c->general_marks); p = next(p))
  357. X                cont_poly(p->x*ms0, p->y*ms1);
  358. X              end_poly(c->filltype, c->fill);
  359. X              break;
  360. X    case 'G': i = 0;
  361. X              for (p = first(c->general_marks);
  362. X                   p != nil(c->general_marks);
  363. X                   p = next(p)) {
  364. X                if (i == 0) {
  365. X                  printf("%f %f moveto ", p->x*ms0, p->y*ms1);
  366. X                } else {
  367. X                  printf("%f %f lineto\n", p->x*ms0, p->y*ms1);
  368. X                }
  369. X                if (i == 100) {
  370. X                  printf("stroke\n");
  371. X                  p = prev(p);
  372. X                  i = 0;
  373. X                } else i++;
  374. X              }
  375. X              if (i != 0) printf("stroke\n");
  376. X              break;
  377. X    case 'B': i = 0;
  378. X              j = 0;
  379. X              for (p = first(c->general_marks);
  380. X                   p != nil(c->general_marks);
  381. X                   p = next(p)) {
  382. X                if (j == 0 && i == 0) {
  383. X                  printf("%f %f moveto ", p->x*ms0, p->y*ms1);
  384. X                  j++;
  385. X                } else if (i != 0) {
  386. X                  printf("%f %f ", p->x*ms0, p->y*ms1);
  387. X                } else {
  388. X                  printf("%f %f curveto\n", p->x*ms0, p->y*ms1);
  389. X                  j++;
  390. X                }
  391. X                if (j == 30 && i == 0) {
  392. X                  printf(" stroke\n");
  393. X                  p = prev(p);
  394. X                  j = 0;
  395. X                  i = 0;
  396. X                } else i = (i + 1) % 3;
  397. X              }
  398. X              if (j != 0) printf(" stroke\n");
  399. X              if (! ((i == 1) || (i == 0 && j == 0))) {
  400. X                fprintf(stderr, "Error: curve %d, %s\n", c->num,
  401. X                        "wrong number of points for bezier marktype\n");
  402. X                exit(1);
  403. X              }
  404. X              break;
  405. X
  406. X    case 'Z': i = 0;
  407. X              j = 0;
  408. X              for (p = first(c->general_marks);
  409. X                   p != nil(c->general_marks);
  410. X                   p = next(p)) {
  411. X                if (i == 0 && j == 0) {
  412. X                  printf("newpath %f %f moveto ", p->x*ms0, p->y*ms1);
  413. X                  j++;
  414. X                } else if (i != 0) {
  415. X                  printf("%f %f ", p->x*ms0, p->y*ms1);
  416. X                } else {
  417. X                  printf("%f %f curveto\n", p->x*ms0, p->y*ms1);
  418. X                }
  419. X                i = (i + 1) % 3;
  420. X              }
  421. X              printf("closepath ");
  422. X              setfill(c->filltype, c->fill);
  423. X              printf("stroke\n");
  424. X
  425. X              if (i != 1) {
  426. X                fprintf(stderr, "Error: curve %d, %s\n", c->num,
  427. X                        "wrong number of points for bezier marktype\n");
  428. X                exit(1);
  429. X              }
  430. X              break;
  431. X
  432. X    case 'x': printline(-ms0, -ms1, ms0, ms1, 'x');
  433. X              printline(-ms0, ms1, ms0, -ms1, 'x');
  434. X              break;
  435. X    case 'o': printellipse(0.0, 0.0, ms0, ms0, c->filltype, c->fill);
  436. X              break;
  437. X    case 'e': printellipse(0.0, 0.0, ms0, ms1, c->filltype, c->fill);
  438. X              break;
  439. X    case 't': start_poly(ms0, -ms1);
  440. X              cont_poly(0.0, ms1);
  441. X              cont_poly(-ms0, -ms1);
  442. X              end_poly(c->filltype, c->fill);
  443. X              break;
  444. X    case 'X': start_poly(ms0, 0.0);
  445. X              cont_poly(-ms0, 0.0);
  446. X              cont_poly(-ms0, g->x_axis->draw_at - y);
  447. X              cont_poly(ms0, g->x_axis->draw_at - y);
  448. X              end_poly(c->filltype, c->fill);
  449. X              break;
  450. X    case 'Y': start_poly(0.0, ms1);
  451. X              cont_poly(0.0, -ms1);
  452. X              cont_poly(g->y_axis->draw_at - x, -ms1);
  453. X              cont_poly(g->y_axis->draw_at - x, ms1);
  454. X              end_poly(c->filltype, c->fill);
  455. X              break;
  456. X    case 'l': draw_label(c->lmark);
  457. X              break;
  458. X    default: error_header(); 
  459. X             fprintf(stderr, "Unknown mark: %c\n", c->marktype);
  460. X             break;
  461. X  }
  462. X  grestore();
  463. X}
  464. X
  465. Xdraw_arrow(x1, y1, x2, y2, c)
  466. Xfloat x1, y1, x2, y2;
  467. XCurve c;
  468. X{
  469. X  float dx, dy;
  470. X  float ms0;
  471. X  float theta, ct, st;
  472. X  
  473. X  
  474. X  if (c->marktype == 'o') {
  475. X    dx = x1 - x2;
  476. X    dy = y1 - y2;
  477. X    if (dx == 0.0 && dy == 0.0) return;
  478. X
  479. X    ms0 = c->marksize[0] / 2.0;
  480. X    if (dx == 0.0) theta = asin(1.0); else theta = atan(dy/dx);
  481. X    if (theta < 0.0) theta = -theta;
  482. X    ct = cos(theta)*ms0;
  483. X    st = sin(theta)*ms0;
  484. X    x1 = x1 + ct*(dx > 0.0 ? -1.0 : 1.0);
  485. X    y1 = y1 + st*(dy > 0.0 ? -1.0 : 1.0);
  486. X
  487. X    if ( ((x1 - x2 > 0) != (dx > 0)) || 
  488. X         ((y1 - y2 > 0) != (dy > 0)) ) return;
  489. X  }
  490. X
  491. X  dx = x1 - x2;
  492. X  dy = y1 - y2;
  493. X  if (dx == 0.0 && dy == 0.0) return;
  494. X
  495. X  gsave();
  496. X  printf("%f %f translate %f %f atan rotate\n", x1, y1, dy, dx);
  497. X  start_poly(0.0, 0.0);
  498. X  cont_poly(-(c->asize[0]), (c->asize[1]));
  499. X  cont_poly(-(c->asize[0]), -(c->asize[1]));
  500. X  end_poly(c->afilltype, c->afill);
  501. X  grestore();
  502. X  printf("\n");
  503. X}
  504. X
  505. Xdraw_legend(g)
  506. XGraph g;
  507. X{
  508. X  Curve c;
  509. X  Legend l;
  510. X  float x, y;
  511. X  char tmpmktype;
  512. X
  513. X  l = g->legend;
  514. X  comment("Drawing legend");
  515. X  if (l->type == 'n' || l->anylines < 0) return;
  516. X  gsave();
  517. X  if (l->type == 'u') {
  518. X    printf("%f %f translate %f rotate\n", l->l->x, l->l->y, l->l->rotate);
  519. X  }
  520. X  for (c = first(g->curves); c != nil(g->curves); c = next(c)) {
  521. X    if (c->l->label != CNULL) {
  522. X      gsave();
  523. X      setgray(c->graytype, c->gray);
  524. X      y = (c->l->ymax + c->l->ymin) / 2.0;
  525. X      if (l->anylines) {
  526. X        if (c->linetype != '0' && l->linelength != 0) {
  527. X          if (l->type == 'c' && c->l->hj == 'r') {
  528. X            x = c->l->x + l->midspace;
  529. X          } else {
  530. X            x = c->l->x - l->midspace - l->linelength;
  531. X          }
  532. X          start_line(x, y, c); 
  533. X          cont_line(x+l->linelength, y);
  534. X          end_line();
  535. X        }
  536. X        tmpmktype = c->marktype;
  537. X        c->marktype = 'n';
  538. X        if (c->larrows || c->larrow) draw_arrow(x, y, x+l->linelength, y, c);
  539. X        if (c->rarrows || c->rarrow) draw_arrow(x+l->linelength, y, x, y, c);
  540. X        c->marktype = tmpmktype;
  541. X        if (l->type == 'c' && c->l->hj == 'r') {
  542. X          x = c->l->x + l->midspace + l->linelength / 2.0;
  543. X        } else {
  544. X          x = c->l->x - l->midspace - l->linelength / 2.0;
  545. X        }
  546. X      } else if (l->type == 'c' && c->l->hj == 'r') {
  547. X        x = c->l->x + l->midspace;
  548. X      } else {
  549. X        x = c->l->x - l->midspace;
  550. X      }
  551. X      if (c->marktype == 'X' || c->marktype == 'Y') {
  552. X        char old;
  553. X        old = c->marktype;
  554. X        c->marktype = 'b'; 
  555. X        draw_mark(x, y, c, g); 
  556. X        c->marktype = old;
  557. X      } else {
  558. X        draw_mark(x, y, c, g);
  559. X      }
  560. X      grestore();
  561. X      printf("\n");
  562. X      draw_label(c->l);
  563. X    }
  564. X  }
  565. X  grestore();
  566. X  printf("\n");
  567. X}
  568. X
  569. Xdraw_strings(g)
  570. XGraph g;
  571. X{
  572. X  String s;
  573. X
  574. X  comment("Drawing strings");
  575. X  for (s = first(g->strings); s != nil(g->strings); s = next(s))
  576. X    draw_label(s->s);
  577. X}
  578. X
  579. Xdraw_graph(g)
  580. XGraph g;
  581. X{
  582. X  comment("Drawing New Graph");
  583. X  printf("%f %f translate\n", g->x_translate, g->y_translate);
  584. X  if (g->border) {
  585. X    printline(0.0, 0.0, 0.0, g->y_axis->psize, 'x');
  586. X    printline(0.0, 0.0, 0.0, g->x_axis->psize, 'y');
  587. X    printline(g->x_axis->psize, 0.0, g->x_axis->psize, g->y_axis->psize, 'x');
  588. X    printline(g->y_axis->psize, 0.0, g->y_axis->psize, g->x_axis->psize, 'y');
  589. X  }
  590. X  draw_axis(g->x_axis, g->y_axis);
  591. X  draw_axis(g->y_axis, g->x_axis);
  592. X  draw_label(g->title);
  593. X  draw_curves(g);
  594. X  draw_legend(g);
  595. X  draw_strings(g);
  596. X  printf("%f %f translate\n", - g->x_translate, - g->y_translate);
  597. X
  598. X}
  599. X
  600. Xdraw_graphs(gs, pp, landscape)
  601. XGraphs gs;
  602. Xint pp;
  603. Xint landscape;
  604. X{
  605. X  Graphs gs_p;
  606. X  Graph g;
  607. X
  608. X  for (gs_p = first(gs); gs_p != nil(gs); gs_p = next(gs_p)) {
  609. X    draw_header(gs_p, pp, landscape);
  610. X    for (g = first(gs_p->g); g != nil(gs_p->g); g = next(g)) {
  611. X      draw_graph(g);
  612. X    }
  613. X    draw_footer(gs_p, pp);
  614. X  }
  615. X}
  616. X
  617. Xdraw_header(gs, pp, landscape)
  618. XGraphs gs;
  619. Xint pp;
  620. Xint landscape;
  621. X{
  622. X  FILE *f;
  623. X  char c;
  624. X
  625. X  printf("%%!PS-Adobe-2.0 EPSF-1.2\n");
  626. X  printf("%%%%Pages: 0\n");
  627. X  if (landscape) {
  628. X    printf("%%%%BoundingBox: %f %f %f %f\n", gs->bb[1], gs->bb[0], 
  629. X            gs->bb[3], gs->bb[2]);
  630. X  } else {
  631. X    printf("%%%%BoundingBox: %f %f %f %f\n", gs->bb[0], gs->bb[1], 
  632. X            gs->bb[2], gs->bb[3]);
  633. X  }
  634. X
  635. X  printf("%%%%EndComments\n");
  636. X  printf("/$F2psDict 32 dict def $F2psDict begin\t$F2psDict /mtrx matrix put\n");
  637. X  printf("/DrawEllipse {\t/endangle exch def\t/startangle exch def");
  638. X  printf("\t/yrad exch def\t/xrad exch def\t/y exch def\t/x exch def");
  639. X  printf("\t/savematrix mtrx currentmatrix def");
  640. X  printf("\tx y translate xrad yrad scale 0 0 1 startangle endangle arc");
  641. X  printf("\tsavematrix setmatrix\t} def\n");
  642. X  printf("\tend\t/$F2psBegin {$F2psDict begin /$F2psEnteredState save def} def");
  643. X  printf("\t/$F2psEnd\n");
  644. X  printf("{$F2psEnteredState restore end} def\t%%%%EndProlog\n");
  645. X  printf("$F2psBegin\n");
  646. X  if (landscape) {
  647. X    printf("-90 rotate\n");
  648. X  }
  649. X  if (pp) {
  650. X    if (landscape) {
  651. X      printf("%f 0 translate\n", -(11.0 * FCPI));
  652. X      printf("%f %f translate\n",
  653. X        (((11.0 * FCPI) - gs->width) / 2.0) - gs->bb[0],     
  654. X        (((8.5 * FCPI) - gs->height) / 2.0) - gs->bb[1]);     
  655. X    } else {
  656. X      printf("%f %f translate\n",
  657. X        (((8.5 * FCPI) - gs->width) / 2.0) - gs->bb[0],     
  658. X        (((11.0 * FCPI) - gs->height) / 2.0) - gs->bb[1]);     
  659. X    }
  660. X  } else if (landscape) {
  661. X    printf("%f 0 translate\n", -gs->bb[2] - gs->bb[0]);
  662. X  }
  663. X  printf("1 setlinecap 1 setlinejoin\n");
  664. X  printf("0.700 setlinewidth\n");
  665. X  printf("0.00 setgray\n");
  666. X  gsave();
  667. X  setfont("Times-Roman", 9.00);
  668. X  if (gs->preamble != CNULL) {
  669. X    if (gs->prefile) {
  670. X      f = fopen(gs->preamble, "r");
  671. X      if (f == NULL) {
  672. X        fprintf(stderr, "Error: preamble file %s couldn't be opened\n",
  673. X                gs->preamble);
  674. X        exit(1);
  675. X      }
  676. X      for (c = getc(f); c != real_eof; c = getc(f)) putchar(c);
  677. X      putchar('\n');
  678. X      fclose(f);
  679. X    } else {
  680. X      printf("%s\n", gs->preamble);
  681. X    }
  682. X  }
  683. X}
  684. X
  685. Xdraw_footer(gs, pp)
  686. XGraphs gs;
  687. Xint pp;
  688. X{
  689. X  FILE *f;
  690. X  char c;
  691. X
  692. X  if (gs->epilogue != CNULL) {
  693. X    if (gs->epifile) {
  694. X      f = fopen(gs->epilogue, "r");
  695. X      if (f == NULL) {
  696. X        fprintf(stderr, "Error: epilogue file %s couldn't be opened\n",
  697. X                gs->epilogue);
  698. X        exit(1);
  699. X      }
  700. X      for (c = getc(f); c != real_eof; c = getc(f)) putchar(c);
  701. X      putchar('\n');
  702. X      fclose(f);
  703. X    } else {
  704. X      printf("%s\n", gs->epilogue);
  705. X    }
  706. X  }
  707. X  printf("$F2psEnd\n");
  708. X  grestore();
  709. X  if (pp) printf("showpage\n"); else printf("\n");
  710. X}
  711. X
  712. END_OF_FILE
  713.   if test 18554 -ne `wc -c <'draw.c'`; then
  714.     echo shar: \"'draw.c'\" unpacked with wrong size!
  715.   fi
  716.   # end of 'draw.c'
  717. fi
  718. if test -f 'edit.c' -a "${1}" != "-c" ; then 
  719.   echo shar: Will not clobber existing file \"'edit.c'\"
  720. else
  721.   echo shar: Extracting \"'edit.c'\" \(31446 characters\)
  722.   sed "s/^X//" >'edit.c' <<'END_OF_FILE'
  723. X/* 
  724. X * $Source: /n/fs/vd/jsp/src/jgraph/RCS/edit.c,v $
  725. X * $Revision: 8.0 $
  726. X * $Date: 92/07/03 14:15:40 $
  727. X * $Author: jsp $
  728. X */
  729. X
  730. X
  731. X#include <stdio.h>
  732. X
  733. X#include "jgraph.h"
  734. X
  735. X#define MAX(a,b) ((a > b) ? a : b)
  736. X#define MIN(a,b) ((a < b) ? a : b)
  737. X
  738. Xedit_label(l)
  739. XLabel l;
  740. X{
  741. X  char *txt, inp_str[80];
  742. X  float f;
  743. X  int i;
  744. X
  745. X  while ( getstring(inp_str) ) {
  746. X    if (strcmp(inp_str, ":") == 0) {
  747. X      if ((txt = getlabel()) == CNULL) return;
  748. X      l->label = txt;
  749. X    } else if (strcmp(inp_str, "x") == 0) {
  750. X      if (!getfloat(&f)) rejecttoken(); else l->x = f;
  751. X    } else if (strcmp(inp_str, "y") == 0) {
  752. X      if (!getfloat(&f)) rejecttoken(); else l->y = f;
  753. X    } else if (strcmp(inp_str, "fontsize") == 0) {
  754. X      if (!getfloat(&f)) rejecttoken(); else l->fontsize = f;
  755. X    } else if (strcmp(inp_str, "linesep") == 0) {
  756. X      if (!getfloat(&f)) rejecttoken(); else l->linesep = f;
  757. X    } else if (strcmp(inp_str, "hjl") == 0) {
  758. X      l->hj = 'l';
  759. X    } else if (strcmp(inp_str, "hjc") == 0) {
  760. X      l->hj = 'c';
  761. X    } else if (strcmp(inp_str, "hjr") == 0) {
  762. X      l->hj = 'r';
  763. X    } else if (strcmp(inp_str, "vjc") == 0) {
  764. X      l->vj = 'c';
  765. X    } else if (strcmp(inp_str, "vjt") == 0) {
  766. X      l->vj = 't';
  767. X    } else if (strcmp(inp_str, "vjb") == 0) {
  768. X      l->vj = 'b';
  769. X    } else if (strcmp(inp_str, "font") == 0) {
  770. X      if (!getstring(inp_str)) return;
  771. X      txt = (char *) malloc (sizeof(char)*strlen(inp_str)+2);
  772. X      strcpy(txt, inp_str);
  773. X      l->font = txt;
  774. X    } else if (strcmp(inp_str, "rotate") == 0) {
  775. X      if (!getfloat(&f)) rejecttoken(); else l->rotate = f;
  776. X    } else if (strcmp(inp_str, "lgray") == 0) {
  777. X        if (!getfloat(&f)) rejecttoken(); else {
  778. X          l->graytype = 'g';
  779. X          l->gray[0] = f;
  780. X        }
  781. X    } else if (strcmp(inp_str, "lcolor") == 0) {
  782. X        l->graytype = 'c';
  783. X        for( i = 0 ; i < 3 ; i++ )  {
  784. X          if(!getfloat(&f)) {
  785. X            rejecttoken();
  786. X            l->graytype = 'n';
  787. X            break ;
  788. X          } else l->gray[i] = f ;
  789. X        }
  790. X    } else {
  791. X      rejecttoken();
  792. X      return;
  793. X    }
  794. X  }
  795. X}
  796. X
  797. Xcopy_curve(c1, c2) /* Copies curve c2 to c1 */
  798. XCurve c1, c2;
  799. X{
  800. X  Flist f, newf;
  801. X  Point p, newp;
  802. X
  803. X  copy_label(c1->l, c2->l);
  804. X  copy_label(c1->lmark, c2->lmark);
  805. X  c1->l->label = CNULL;
  806. X  c1->clip = c2->clip;
  807. X  for (f = first(c2->gen_linetype); 
  808. X       f != nil(c2->gen_linetype); 
  809. X       f = next(f)) {
  810. X    newf = (Flist) get_node(c1->gen_linetype);
  811. X    newf->f = f->f;
  812. X    insert(newf, c1->gen_linetype);
  813. X  }
  814. X  c1->marktype = c2->marktype;
  815. X  c1->linetype = c2->linetype;
  816. X  c1->linethick = c2->linethick;
  817. X  c1->marksize[0] = c2->marksize[0];
  818. X  c1->marksize[1] = c2->marksize[1];
  819. X  c1->mrotate = c2->mrotate;
  820. X  for (p = first(c2->general_marks); 
  821. X       p != nil(c2->general_marks); 
  822. X       p = next(p)) {
  823. X    newp = (Point) get_node(c1->general_marks);
  824. X    newp->x = p->x;
  825. X    newp->y = p->y;
  826. X    insert(newp, c1->general_marks);
  827. X  }
  828. X  c1->graytype = c2->graytype;
  829. X  c1->gray[0] = c2->gray[0];
  830. X  c1->gray[1] = c2->gray[1];
  831. X  c1->gray[2] = c2->gray[2];
  832. X  c1->filltype = c2->filltype;
  833. X  c1->fill[0] = c2->fill[0];
  834. X  c1->fill[1] = c2->fill[1];
  835. X  c1->fill[2] = c2->fill[2];
  836. X  c1->poly = c2->poly;
  837. X  c1->pfilltype = c2->pfilltype;
  838. X  c1->pfill[0] = c2->pfill[0];
  839. X  c1->pfill[1] = c2->pfill[1];
  840. X  c1->pfill[2] = c2->pfill[2];
  841. X  c1->afilltype = c2->afilltype;
  842. X  c1->afill[0] = c2->afill[0];
  843. X  c1->afill[1] = c2->afill[1];
  844. X  c1->afill[2] = c2->afill[2];
  845. X  c1->postscript = c2->postscript;
  846. X  c1->postfile = c2->postfile;
  847. X  c1->rarrow = c2->rarrows;
  848. X  c1->larrow = c2->larrows;
  849. X  c1->rarrows = c2->rarrows;
  850. X  c1->larrows = c2->larrows;
  851. X  c1->asize[0] = c2->asize[0];
  852. X  c1->asize[1] = c2->asize[1];
  853. X  c1->bezier = c2->bezier;
  854. X}
  855. X
  856. Xcopy_label(l1, l2) /* Copies label l2 to l1 */
  857. XLabel l1, l2;
  858. X{
  859. X  l1->label = l2->label;
  860. X  l1->x = l2->x;
  861. X  l1->y = l2->y;
  862. X  l1->rotate = l2->rotate;
  863. X  l1->font = l2->font;
  864. X  l1->fontsize = l2->fontsize;
  865. X  l1->hj = l2->hj;
  866. X  l1->vj = l2->vj;
  867. X  l1->graytype = l2->graytype;
  868. X  l1->gray[0] = l2->gray[0];
  869. X  l1->gray[1] = l2->gray[1];
  870. X  l1->gray[2] = l2->gray[2];
  871. X  l1->linesep = l2->linesep;
  872. X}
  873. X
  874. Xcopy_axis(a1, a2) /* Copies axis a2 to a1 */
  875. XAxis a1, a2;
  876. X{
  877. X  copy_label(a1->label, a2->label);
  878. X  copy_label(a1->hl, a2->hl);
  879. X  a1->max = a2->max;
  880. X  a1->min = a2->min;
  881. X  a1->pmax = a2->pmax;
  882. X  a1->pmin = a2->pmin;
  883. X  a1->size = a2->size;
  884. X  a1->hash_interval = a2->hash_interval;
  885. X  a1->hash_start = a2->hash_start;
  886. X  a1->log_base = a2->log_base;
  887. X  a1->draw_hash_marks_at = a2->draw_hash_marks_at;
  888. X  a1->draw_hash_labels_at = a2->draw_hash_labels_at;
  889. X  a1->draw_at = a2->draw_at;
  890. X  a1->draw_hash_labels = a2->draw_hash_labels;
  891. X  a1->draw_axis_line = a2->draw_axis_line;
  892. X  a1->draw_hash_marks = a2->draw_hash_marks;
  893. X  a1->draw_axis_label = a2->draw_axis_label;
  894. X  a1->auto_hash_labels = a2->auto_hash_labels;
  895. X  a1->auto_hash_marks = a2->auto_hash_marks;
  896. X  a1->minor_hashes = a2->minor_hashes;
  897. X  a1->hash_scale = a2->hash_scale;
  898. X  a1->graytype = a2->graytype;
  899. X  a1->gray[0] = a2->gray[0];
  900. X  a1->gray[1] = a2->gray[1];
  901. X  a1->gray[2] = a2->gray[2];
  902. X  a1->mgr_graytype = a2->mgr_graytype;
  903. X  a1->mgr_gray[0] = a2->mgr_gray[0];
  904. X  a1->mgr_gray[1] = a2->mgr_gray[1];
  905. X  a1->mgr_gray[2] = a2->mgr_gray[2];
  906. X  a1->gr_graytype = a2->gr_graytype;
  907. X  a1->gr_gray[0] = a2->gr_gray[0];
  908. X  a1->gr_gray[1] = a2->gr_gray[1];
  909. X  a1->gr_gray[2] = a2->gr_gray[2];
  910. X  a1->grid_lines = a2->grid_lines;
  911. X  a1->mgrid_lines = a2->mgrid_lines;
  912. X  a1->precision = a2->precision;
  913. X  a1->start_given = a2->start_given;
  914. X  a1->is_lg = a2->is_lg;
  915. X  a1->is_x = a2->is_x;
  916. X}
  917. X
  918. XCurve do_copy_curve(g, gs, all_gs)
  919. XGraph g;
  920. XGraphs gs;
  921. XGraphs all_gs;
  922. X{
  923. X  Curve lastc, newc;
  924. X  Graph oldg;
  925. X  Graphs oldgs;
  926. X  int num;
  927. X
  928. X  if (!getint(&num)) {
  929. X    rejecttoken();
  930. X    oldg = g;
  931. X    oldgs = gs;
  932. X    while(gs != nil(all_gs)) {
  933. X      if (gs != oldgs) g = last(gs->g);
  934. X      while(g != nil(gs->g)) {
  935. X        if (first(g->curves) == nil(g->curves)) g = prev(g);
  936. X        else {
  937. X          lastc = last(g->curves);
  938. X          if (first(oldg->curves) == nil(oldg->curves))
  939. X            newc = new_curve(oldg->curves, 0);
  940. X          else newc = new_curve(oldg->curves, last(oldg->curves)->num + 1);
  941. X          copy_curve(newc, lastc);
  942. X          return newc;
  943. X        }
  944. X      }
  945. X      gs = prev(gs);
  946. X    }
  947. X    error_header(); 
  948. X    fprintf(stderr, "Cannot perform copycurve on first curve\n");
  949. X    exit(1);
  950. X  } else {
  951. X    if (first(g->curves) == nil(g->curves))
  952. X      newc = new_curve(g->curves, 0);
  953. X    else newc = new_curve(g->curves, last(g->curves)->num + 1);
  954. X    lastc = g->curves; 
  955. X    while(1) {
  956. X      lastc = prev(lastc);
  957. X      if (lastc == nil(g->curves) || lastc->num < num) {
  958. X        error_header(); 
  959. X        fprintf(stderr, "copycurve: curve #%d not found\n", num);
  960. X        exit(1);
  961. X      }
  962. X      if (lastc->num == num) {
  963. X        copy_curve(newc, lastc);
  964. X        return newc;
  965. X      }
  966. X    }
  967. X  }
  968. X  return newc; /* To shut lint up */
  969. X}
  970. X
  971. XLabel do_copy_string(g, gs, all_gs)
  972. XGraph g;
  973. XGraphs gs;
  974. XGraphs all_gs;
  975. X{
  976. X  String lastl, newl;
  977. X  Graph oldg;
  978. X  Graphs oldgs;
  979. X  int num;
  980. X
  981. X  if (!getint(&num)) {
  982. X    rejecttoken();
  983. X    oldgs = gs;
  984. X    oldg = g;
  985. X    while(gs != nil(all_gs)) {
  986. X      if (gs != oldgs) g = last(gs->g);
  987. X      while(g != nil(gs->g)) {
  988. X        if (first(g->strings) == nil(g->strings)) g = prev(g);
  989. X        else {
  990. X          lastl = last(g->strings);
  991. X          if (first(oldg->strings) == nil(oldg->strings))
  992. X            newl = new_string(oldg->strings, 0);
  993. X          else newl = new_string(oldg->strings, last(oldg->strings)->num + 1);
  994. X          copy_label(newl->s, lastl->s);
  995. X          return newl->s;
  996. X        }
  997. X      }
  998. X      gs = prev(gs);
  999. X    }
  1000. X    error_header(); 
  1001. X    fprintf(stderr, "Cannot perform copystring on first string\n");
  1002. X    exit(1);
  1003. X    return newl->s; /* To shut lint up */
  1004. X  } else {
  1005. X    if (first(g->strings) == nil(g->strings))
  1006. X      newl = new_string(g->strings, 0);
  1007. X    else newl = new_string(g->strings, last(g->strings)->num + 1);
  1008. X    lastl = g->strings; 
  1009. X    while(1) {
  1010. X      lastl = prev(lastl);
  1011. X      if (lastl == nil(g->strings) || lastl->num < num) {
  1012. X        error_header(); 
  1013. X        fprintf(stderr, "copystring: string #%d not found\n", num);
  1014. X        exit(1);
  1015. X      }
  1016. X      if (lastl->num == num) {
  1017. X        copy_label(newl->s, lastl->s);
  1018. X        return newl->s;
  1019. X      }
  1020. X    }
  1021. X  }
  1022. X}
  1023. X
  1024. XGraph last_graph(g, gs, all_gs)
  1025. XGraph g;
  1026. XGraphs gs;
  1027. XGraphs all_gs;
  1028. X{
  1029. X  Graph lastg;
  1030. X
  1031. X
  1032. X  lastg = prev(g);
  1033. X  while(lastg == nil(gs->g)) {
  1034. X    if (prev(gs) == nil(all_gs)) {
  1035. X      error_header(); 
  1036. X      fprintf(stderr, "First graph cannot inherit axes\n");
  1037. X      exit(1);
  1038. X    } else {
  1039. X      gs = prev(gs);
  1040. X      lastg = last(gs->g);
  1041. X    }
  1042. X  }
  1043. X  return lastg;
  1044. X}
  1045. X
  1046. Xcopy_legend(l1, l2)
  1047. XLegend l1, l2;
  1048. X{
  1049. X  l1->linelength = l2->linelength;
  1050. X  l1->linebreak = l2->linebreak;
  1051. X  l1->midspace = l2->midspace;
  1052. X  l1->type = l2->type;
  1053. X  copy_label(l1->l, l2->l);
  1054. X}
  1055. X
  1056. Xinherit_axes(g, lastg)
  1057. XGraph g;
  1058. XGraph lastg;
  1059. X{
  1060. X  char *s;
  1061. X  copy_axis(g->x_axis, lastg->x_axis);
  1062. X  copy_axis(g->y_axis, lastg->y_axis);
  1063. X  g->x_translate = lastg->x_translate;
  1064. X  g->y_translate = lastg->y_translate;
  1065. X  g->clip = lastg->clip;
  1066. X  g->border = lastg->border;
  1067. X  copy_legend(g->legend, lastg->legend);
  1068. X  s = g->title->label;
  1069. X  copy_label(g->title, lastg->title);
  1070. X  g->title->label = s;
  1071. X}
  1072. X
  1073. Xedit_curve(c, g)
  1074. XCurve c;
  1075. XGraph g;
  1076. X{
  1077. X  char inp_str[256], *txt;
  1078. X  float x, y, f, e1, e2;
  1079. X  float xh, yh, xl, yl;
  1080. X  Point p, p1, p2;
  1081. X  Flist fl;
  1082. X  int i;
  1083. X  char e;
  1084. X
  1085. X  while ( getstring(inp_str) ) {
  1086. X    if (strcmp(inp_str, "y_epts") == 0 ||
  1087. X        strcmp(inp_str, "pts") == 0    ||
  1088. X        strcmp(inp_str, "x_epts") == 0) {
  1089. X      e = inp_str[0];
  1090. X      while (getfloat(&x)) {
  1091. X        if (e == 'p') {
  1092. X          if (!getfloat(&y)) {
  1093. X            error_header(); 
  1094. X            fprintf(stderr, "Reading Points, no y value for x=%f\n", x);
  1095. X            exit(1);
  1096. X          }
  1097. X        } else {
  1098. X          if (!getfloat(&y) || !getfloat(&e1) || !getfloat(&e2)) {
  1099. X            error_header();
  1100. X              fprintf(stderr, 
  1101. X                      "Reading %s, need 4 values per data point\n", inp_str);
  1102. X              exit(1);
  1103. X          }
  1104. X        }
  1105. X        p = (Point) get_node(c->pts);
  1106. X        p->x = x;
  1107. X        p->y = y;
  1108. X        p->e = e;
  1109. X    insert(p, c->pts);
  1110. X        c->npts++;
  1111. X        if (e == 'x') {
  1112. X          p1 = (Point) get_node(c->xepts);
  1113. X          p1->x = e1;
  1114. X          p1->y = y;
  1115. X          p2 = (Point) get_node(c->xepts);
  1116. X          p2->x = e2;
  1117. X          p2->y = y;
  1118. X      insert(p1, c->xepts);
  1119. X      insert(p2, c->xepts);
  1120. X          xh = MAX(e1, e2); xh = MAX(xh, x);
  1121. X          xl = MIN(e1, e2); xl = MIN(xl, x);
  1122. X          yh = y; yl = y;
  1123. X        } else if (e == 'y') {
  1124. X          p1 = (Point) get_node(c->yepts);
  1125. X          p1->y = e1;
  1126. X          p1->x = x;
  1127. X          p2 = (Point) get_node(c->yepts);
  1128. X          p2->y = e2;
  1129. X          p2->x = x;
  1130. X      insert(p1, c->yepts);
  1131. X      insert(p2, c->yepts);
  1132. X          yh = MAX(e1, e2); yh = MAX(yh, y);
  1133. X          yl = MIN(e1, e2); yl = MIN(yl, y);
  1134. X          xh = x; xl = x;
  1135. X        } else {
  1136. X          xh = x; xl = x; yh = y; yl = y;
  1137. X        }
  1138. X        if (g->x_axis->pmax == FSIG) {
  1139. X          g->x_axis->pmax = xh;
  1140. X          g->x_axis->pmin = xl;
  1141. X          g->y_axis->pmax = yh;
  1142. X          g->y_axis->pmin = yl;
  1143. X        } else {
  1144. X          g->x_axis->pmax = MAX(g->x_axis->pmax, xh);
  1145. X          g->x_axis->pmin = MIN(g->x_axis->pmin, xl);
  1146. X          g->y_axis->pmax = MAX(g->y_axis->pmax, yh);
  1147. X          g->y_axis->pmin = MIN(g->y_axis->pmin, yl);
  1148. X        }
  1149. X      }
  1150. X      rejecttoken();
  1151. X
  1152. X    } else if (strcmp(inp_str, "label") == 0) {
  1153. X      edit_label(c->l);
  1154. X    } else if (strcmp(inp_str, "marksize") == 0) {
  1155. X      if (!getfloat(&f)) rejecttoken(); 
  1156. X      else {
  1157. X        c->marksize[0] = f;
  1158. X        if (!getfloat(&f)) rejecttoken(); 
  1159. X        else c->marksize[1] = f;
  1160. X      }
  1161. X    } else if (strcmp(inp_str, "gmarks") == 0) {
  1162. X      while (getfloat(&x)) {
  1163. X        if (!getfloat(&y)) {
  1164. X          error_header(); 
  1165. X          fprintf(stderr, "Reading GMarks, no y value for x=%f\n", x);
  1166. X          exit(1);
  1167. X        }
  1168. X        p =  (Point) get_node(c->general_marks);
  1169. X        p->x = x;
  1170. X        p->y = y;
  1171. X        insert(p, c->general_marks);
  1172. X      }
  1173. X      rejecttoken();
  1174. X    } else if (strcmp(inp_str, "pfill") == 0) {
  1175. X        if (!getfloat(&f)) rejecttoken(); else {
  1176. X          /* grey fill */
  1177. X          c->pfilltype = 'g';
  1178. X          c->pfill[0] = f;
  1179. X        }
  1180. X    } else if (strcmp(inp_str, "pcfill") == 0) {
  1181. X         /* color fill */
  1182. X        c->pfilltype = 'c';
  1183. X        for( i = 0 ; i < 3 ; i++ )  {
  1184. X          if(!getfloat(&f)) {
  1185. X            rejecttoken();
  1186. X            c->pfilltype = 'n';
  1187. X            break ;
  1188. X          } else c->pfill[i] = f ;
  1189. X        }
  1190. X    } else if (strcmp(inp_str, "fill") == 0) {
  1191. X        if (!getfloat(&f)) rejecttoken(); else {
  1192. X          /* grey fill */
  1193. X          c->filltype = 'g';
  1194. X          c->fill[0] = f;
  1195. X        }
  1196. X    } else if (strcmp(inp_str, "cfill") == 0) {
  1197. X         /* color fill */
  1198. X        c->filltype = 'c';
  1199. X        for( i = 0 ; i < 3 ; i++ )  {
  1200. X          if(!getfloat(&f)) {
  1201. X            rejecttoken();
  1202. X            c->filltype = 'n';
  1203. X            break ;
  1204. X          } else c->fill[i] = f ;
  1205. X        }
  1206. X    } else if (strcmp(inp_str, "afill") == 0) {
  1207. X    if (!getfloat(&f)) rejecttoken(); else {
  1208. X      c->afilltype = 'g';
  1209. X          c->afill[0] = f;
  1210. X    }
  1211. X    } else if (strcmp(inp_str, "acfill") == 0) {
  1212. X    c->afilltype = 'c';
  1213. X    for( i = 0 ; i < 3 ; i++ )  {
  1214. X      if(!getfloat(&f)) { 
  1215. X        rejecttoken(); 
  1216. X         c->afilltype = 'n';
  1217. X            break ;
  1218. X      } else c->afill[i] = f ;
  1219. X    }
  1220. X    } else if (strcmp(inp_str, "marktype") == 0) {
  1221. X      if (!getstring(inp_str)) return;
  1222. X      for (i = 0; i < NMARKTYPES && strcmp(inp_str, MARKTYPESTRS[i]) != 0; i++) ;
  1223. X      if (i == NMARKTYPES) {
  1224. X        error_header(); fprintf(stderr, "Bad mark: %s\n", inp_str);
  1225. X        fprintf(stderr, "             Valid marks are:");
  1226. X        for (i = 0; i < NMARKTYPES; i++) {
  1227. X          fprintf(stderr, " %s", MARKTYPESTRS[i]);
  1228. X        }
  1229. X        fprintf(stderr, "\n");
  1230. X        exit(1);
  1231. X      } else {
  1232. X        c->marktype = MARKTYPES[i];
  1233. X        if (c->marktype == 'l') edit_label(c->lmark);
  1234. X      }
  1235. X    } else if (strcmp(inp_str, "glines") == 0) {
  1236. X      while (getfloat(&f)) {
  1237. X        fl = (Flist) get_node (c->gen_linetype);
  1238. X        fl->f = f;
  1239. X        insert(fl, c->gen_linetype);
  1240. X      } 
  1241. X      rejecttoken();
  1242. X    } else if (strcmp(inp_str, "linetype") == 0) {
  1243. X      if (!getstring(inp_str)) return;
  1244. X      if (strcmp(inp_str, "none") == 0) c->linetype = '0';
  1245. X      else if (strcmp(inp_str, "solid") == 0) c->linetype = 's';
  1246. X      else if (strcmp(inp_str, "dotted") == 0) c->linetype = '.';
  1247. X      else if (strcmp(inp_str, "dashed") == 0) c->linetype = '-';
  1248. X      else if (strcmp(inp_str, "longdash") == 0) c->linetype = 'l';
  1249. X      else if (strcmp(inp_str, "dotdash") == 0) c->linetype = 'd';
  1250. X      else if (strcmp(inp_str, "dotdotdash") == 0) c->linetype = 'D';
  1251. X      else if (strcmp(inp_str, "dotdotdashdash") == 0) c->linetype = '2';
  1252. X      else if (strcmp(inp_str, "general") == 0) c->linetype = 'g';
  1253. X      else {
  1254. X        error_header(); fprintf(stderr, "Bad line type: %s\n", inp_str);
  1255. X        error_header(); fprintf(stderr, "             Valid marks are %s\n", 
  1256. X          "solid, dotted, dashed, longdash, dotdash,"); 
  1257. X        error_header(); fprintf(stderr, "             %s.\n", 
  1258. X          "dotdotdash, dotdotdashdash, none");
  1259. X        exit(1);
  1260. X      }
  1261. X    } else if (strcmp(inp_str, "linethickness") == 0) {
  1262. X      if (!getfloat(&f)) rejecttoken(); else c->linethick = f;
  1263. X    } else if (strcmp(inp_str, "gray") == 0) {
  1264. X        if (!getfloat(&f)) rejecttoken(); else {
  1265. X          c->graytype = 'g';
  1266. X          c->gray[0] = f;
  1267. X        }
  1268. X    } else if (strcmp(inp_str, "color") == 0) {
  1269. X        c->graytype = 'c';
  1270. X        for( i = 0 ; i < 3 ; i++ )  {
  1271. X          if(!getfloat(&f)) {
  1272. X            rejecttoken();
  1273. X            c->graytype = 'n';
  1274. X            break ;
  1275. X          } else c->gray[i] = f ;
  1276. X        }
  1277. X    } else if (strcmp(inp_str, "mrotate") == 0) {
  1278. X      if (!getfloat(&f)) rejecttoken(); else {
  1279. X        c->mrotate = f;
  1280. X      }
  1281. X    } else if (strcmp(inp_str, "postscript") == 0) {
  1282. X      c->marktype = 'p';
  1283. X      if (!getstring(inp_str)) return;
  1284. X      if (strcmp(inp_str, ":") == 0) {
  1285. X        c->postfile = 0;
  1286. X        if ((txt = getmultiline()) == CNULL) return;
  1287. X        c->postscript = txt;
  1288. X      } else {
  1289. X        c->postfile = 1;
  1290. X        c->postscript = (char *) malloc ((strlen(inp_str)+1)*sizeof(char));
  1291. X        strcpy(c->postscript, inp_str);
  1292. X      }
  1293. X    } else if (strcmp(inp_str, "poly") == 0) {
  1294. X      c->poly = 1;
  1295. X    } else if (strcmp(inp_str, "nopoly") == 0) {
  1296. X      c->poly = 0;
  1297. X    } else if (strcmp(inp_str, "larrow") == 0) {
  1298. X      c->larrow = 1;
  1299. X    } else if (strcmp(inp_str, "nolarrow") == 0) {
  1300. X      c->larrow = 0;
  1301. X    } else if (strcmp(inp_str, "rarrow") == 0) {
  1302. X      c->rarrow = 1;
  1303. X    } else if (strcmp(inp_str, "norarrow") == 0) {
  1304. X      c->rarrow = 0;
  1305. X    } else if (strcmp(inp_str, "larrows") == 0) {
  1306. X      c->larrows = 1;
  1307. X    } else if (strcmp(inp_str, "nolarrows") == 0) {
  1308. X      c->larrows = 0;
  1309. X    } else if (strcmp(inp_str, "rarrows") == 0) {
  1310. X      c->rarrows = 1;
  1311. X    } else if (strcmp(inp_str, "norarrows") == 0) {
  1312. X      c->rarrows = 0;
  1313. X    } else if (strcmp(inp_str, "bezier") == 0) {
  1314. X      c->bezier = 1;
  1315. X    } else if (strcmp(inp_str, "nobezier") == 0) {
  1316. X      c->bezier = 0;
  1317. X    } else if (strcmp(inp_str, "asize") == 0) {
  1318. X      if (!getfloat(&f)) rejecttoken(); 
  1319. X      else {
  1320. X        c->asize[0] = f;
  1321. X        if (!getfloat(&f)) rejecttoken(); 
  1322. X        else c->asize[1] = f;
  1323. X      }
  1324. X    } else if (strcmp(inp_str, "clip") == 0) {
  1325. X      c->clip = 1;
  1326. X    } else if (strcmp(inp_str, "noclip") == 0) {
  1327. X      c->clip = 0;
  1328. X    } else {
  1329. X      rejecttoken();
  1330. X      return;
  1331. X    }
  1332. X  }
  1333. X}
  1334. X
  1335. Xedit_hash_label(a)
  1336. XAxis a;
  1337. X{
  1338. X  float at, f;
  1339. X  char *s;
  1340. X  char inp_str[256];
  1341. X  String st;
  1342. X
  1343. X  s = CNULL;
  1344. X
  1345. X  at = (first(a->hash_lines) == nil(a->hash_lines)) ? FSIG
  1346. X          : first(a->hash_lines)->loc;
  1347. X  while (getstring(inp_str)) {
  1348. X    if (strcmp(inp_str, ":") == 0) {
  1349. X      if ((s = getlabel()) == CNULL) return;
  1350. X    } else if (strcmp(inp_str, "at") == 0) {
  1351. X      if (getfloat(&f)) at = f; else rejecttoken();
  1352. X    } else {
  1353. X      rejecttoken();
  1354. X      if (s == CNULL) return;
  1355. X      if (at == FSIG) {
  1356. X        error_header();
  1357. X        fprintf(stderr, 
  1358. X          "hash_label either needs \"at\" or an associated \"hash_at\"\n");
  1359. X        exit(1);
  1360. X      }
  1361. X      st = (String) get_node(a->hash_labels);
  1362. X      st->s = new_label();
  1363. X      st->s->label = s;
  1364. X      st->s->x = at;
  1365. X      st->s->y = at;
  1366. X      insert(st, a->hash_labels);
  1367. X      return;
  1368. X    }
  1369. X  }
  1370. X}
  1371. X
  1372. Xedit_axis(a)
  1373. XAxis a;
  1374. X{
  1375. X  char inp_str[256];
  1376. X  float f;
  1377. X  int i;
  1378. X  Hash h;
  1379. X
  1380. X  while ( getstring(inp_str) ) {
  1381. X
  1382. X    if (strcmp(inp_str, "size") == 0) {
  1383. X      if ( getfloat(&f)) a->size = f; else rejecttoken();
  1384. X    } else if (strcmp(inp_str, "max") == 0) {
  1385. X      if ( getfloat(&f)) a->max = f; else rejecttoken();
  1386. X    } else if (strcmp(inp_str, "min") == 0) {
  1387. X      if ( getfloat(&f)) a->min = f; else rejecttoken();
  1388. X    } else if (strcmp(inp_str, "hash") == 0) {
  1389. X      if ( getfloat(&f)) a->hash_interval = f; else rejecttoken();
  1390. X    } else if (strcmp(inp_str, "shash") == 0) {
  1391. X      if ( getfloat(&f)) {
  1392. X        a->hash_start = f;
  1393. X        a->start_given = 1;
  1394. X        } 
  1395. X      else rejecttoken();
  1396. X    } else if (strcmp(inp_str, "mhash") == 0) {
  1397. X      if (getint(&i)) a->minor_hashes = i; else rejecttoken();
  1398. X    } else if (strcmp(inp_str, "precision") == 0) {
  1399. X      if (getint(&i)) a->precision = i; else rejecttoken();
  1400. X    } else if (strcmp(inp_str, "label") == 0) {
  1401. X      edit_label(a->label);
  1402. X    } else if (strcmp(inp_str, "hash_labels") == 0) {
  1403. X      edit_label(a->hl);
  1404. X    } else if (strcmp(inp_str, "log_base") == 0) {
  1405. X      if (getfloat(&f)) {
  1406. X        if (f <= 1.0) {
  1407. X          error_header();
  1408. X          fprintf(stderr, "\"log_base %f\": log_base must be > 1.0\n", f);
  1409. X          exit(1);
  1410. X        } else a->log_base = f; 
  1411. X      } else rejecttoken();
  1412. X    } else if (strcmp(inp_str, "draw_at") == 0) {
  1413. X      if ( getfloat(&f)) a->draw_at = f; else rejecttoken();
  1414. X    } else if (strcmp(inp_str, "log") == 0) {
  1415. X      a->is_lg = 1;
  1416. X    } else if (strcmp(inp_str, "linear") == 0) {
  1417. X      a->is_lg = 0;
  1418. X    } else if (strcmp(inp_str, "nodraw") == 0) {
  1419. X      a->draw_hash_labels = 0;
  1420. X      a->draw_axis_line = 0;
  1421. X      a->draw_hash_marks = 0;
  1422. X      a->draw_axis_label = 0;
  1423. X    } else if (strcmp(inp_str, "draw") == 0) {
  1424. X      a->draw_hash_labels = 1;
  1425. X      a->draw_axis_line = 1;
  1426. X      a->draw_hash_marks = 1;
  1427. X      a->draw_axis_label = 1;
  1428. X    } else if (strcmp(inp_str, "hash_at") == 0 ||
  1429. X               strcmp(inp_str, "mhash_at") == 0) {
  1430. X      if (getfloat(&f)) {
  1431. X        h = (Hash) get_node (a->hash_lines);
  1432. X        h->loc = f;
  1433. X        h->major = (inp_str[0] == 'h');
  1434. X        h->size = h->major ? HASH_SIZE : MHASH_SIZE;
  1435. X        insert(h, a->hash_lines);
  1436. X      } else rejecttoken();
  1437. X    } else if (strcmp(inp_str, "hash_label") == 0) {
  1438. X      edit_hash_label(a);       
  1439. X    } else if (strcmp(inp_str, "hash_scale") == 0) {
  1440. X      if ( getfloat(&f)) a->hash_scale = f; else rejecttoken();
  1441. X    } else if (strcmp(inp_str, "auto_hash_marks") == 0) {
  1442. X      a->auto_hash_marks = 1;
  1443. X    } else if (strcmp(inp_str, "no_auto_hash_marks") == 0) {
  1444. X      a->auto_hash_marks = 0;
  1445. X    } else if (strcmp(inp_str, "auto_hash_labels") == 0) {
  1446. X      a->auto_hash_labels = 1;
  1447. X    } else if (strcmp(inp_str, "no_auto_hash_labels") == 0) {
  1448. X      a->auto_hash_labels = 0;
  1449. X    } else if (strcmp(inp_str, "draw_hash_labels_at") == 0) {
  1450. X      if (getfloat(&f)) a->draw_hash_labels_at = f; else rejecttoken();
  1451. X    } else if (strcmp(inp_str, "draw_hash_marks_at") == 0) {
  1452. X      if (getfloat(&f)) a->draw_hash_marks_at = f; else rejecttoken();
  1453. X    } else if (strcmp(inp_str, "no_draw_hash_labels") == 0) {
  1454. X      a->draw_hash_labels = 0;
  1455. X    } else if (strcmp(inp_str, "draw_hash_labels") == 0) {
  1456. X      a->draw_hash_labels = 1;
  1457. X    } else if (strcmp(inp_str, "no_draw_axis_line") == 0) {
  1458. X      a->draw_axis_line = 0;
  1459. X    } else if (strcmp(inp_str, "draw_axis_line") == 0) {
  1460. X      a->draw_axis_line = 1;
  1461. X    } else if (strcmp(inp_str, "no_draw_axis") == 0) {
  1462. X      a->draw_axis_line = 0;
  1463. X    } else if (strcmp(inp_str, "draw_axis") == 0) {
  1464. X      a->draw_axis_line = 1;
  1465. X    } else if (strcmp(inp_str, "no_draw_hash_marks") == 0) {
  1466. X      a->draw_hash_marks = 0;
  1467. X    } else if (strcmp(inp_str, "draw_hash_marks") == 0) {
  1468. X      a->draw_hash_marks = 1;
  1469. X    } else if (strcmp(inp_str, "no_draw_axis_label") == 0) {
  1470. X      a->draw_axis_label = 0;
  1471. X    } else if (strcmp(inp_str, "draw_axis_label") == 0) {
  1472. X      a->draw_axis_label = 1;
  1473. X    } else if (strcmp(inp_str, "no_grid_lines") == 0) {
  1474. X      a->grid_lines = 0;
  1475. X    } else if (strcmp(inp_str, "grid_lines") == 0) {
  1476. X      a->grid_lines = 1;
  1477. X    } else if (strcmp(inp_str, "no_mgrid_lines") == 0) {
  1478. X      a->mgrid_lines = 0;
  1479. X    } else if (strcmp(inp_str, "mgrid_lines") == 0) {
  1480. X      a->mgrid_lines = 1;
  1481. X    } else if (strcmp(inp_str, "gray") == 0) {
  1482. X      if (!getfloat(&f)) rejecttoken(); else {
  1483. X        a->graytype = 'g';
  1484. X        a->gray[0] = f;
  1485. X      }
  1486. X    } else if (strcmp(inp_str, "color") == 0) {
  1487. X      a->graytype = 'c';
  1488. X      for( i = 0 ; i < 3 ; i++ )  {
  1489. X        if(!getfloat(&f)) {
  1490. X          rejecttoken();
  1491. X          a->graytype = 'n';
  1492. X          break ;
  1493. X        } else a->gray[i] = f ;
  1494. X      }
  1495. X    } else if (strcmp(inp_str, "grid_gray") == 0) {
  1496. X      if (!getfloat(&f)) rejecttoken(); else {
  1497. X        a->gr_graytype = 'g';
  1498. X        a->gr_gray[0] = f;
  1499. X      }
  1500. X    } else if (strcmp(inp_str, "grid_color") == 0) {
  1501. X      a->gr_graytype = 'c';
  1502. X      for( i = 0 ; i < 3 ; i++ )  {
  1503. X        if(!getfloat(&f)) {
  1504. X          rejecttoken();
  1505. X          a->gr_graytype = 'n';
  1506. X          break ;
  1507. X        } else a->gr_gray[i] = f ;
  1508. X      }
  1509. X    } else if (strcmp(inp_str, "mgrid_gray") == 0) {
  1510. X      if (!getfloat(&f)) rejecttoken(); else {
  1511. X        a->mgr_graytype = 'g';
  1512. X        a->mgr_gray[0] = f;
  1513. X      }
  1514. X    } else if (strcmp(inp_str, "mgrid_color") == 0) {
  1515. X      a->mgr_graytype = 'c';
  1516. X      for( i = 0 ; i < 3 ; i++ )  {
  1517. X        if(!getfloat(&f)) {
  1518. X          rejecttoken();
  1519. X          a->mgr_graytype = 'n';
  1520. X          break ;
  1521. X        } else a->mgr_gray[i] = f ;
  1522. X      }
  1523. X    } else {
  1524. X      rejecttoken(); 
  1525. X      return;
  1526. X    }
  1527. X  }
  1528. X}
  1529. X
  1530. Xedit_legend(l)
  1531. XLegend l;
  1532. X{
  1533. X  char inp_str[256];
  1534. X  float f;
  1535. X
  1536. X  while ( getstring(inp_str) ) {
  1537. X    if (strcmp(inp_str, "x") == 0) {
  1538. X      if (!getfloat(&f)) rejecttoken(); 
  1539. X      else {
  1540. X        l->l->x = f; 
  1541. X        l->l->hj = 'l';
  1542. X        l->l->vj = 't';
  1543. X        l->type = 'u';
  1544. X      }
  1545. X    } else if (strcmp(inp_str, "y") == 0) {
  1546. X      if (!getfloat(&f)) rejecttoken(); 
  1547. X      else {
  1548. X        l->l->y = f; 
  1549. X        l->l->hj = 'l';
  1550. X        l->l->vj = 't';
  1551. X        l->type = 'u';
  1552. X      }
  1553. X    } else if (strcmp(inp_str, "right") == 0 ||
  1554. X               strcmp(inp_str, "on") == 0) {
  1555. X      l->type = 'u';
  1556. X      l->l->y = FSIG; 
  1557. X      l->l->x = FSIG; 
  1558. X      l->l->hj = 'l';
  1559. X      l->l->vj = 'c';
  1560. X    } else if (strcmp(inp_str, "left") == 0) {
  1561. X      l->type = 'u';
  1562. X      l->l->y = FSIG; 
  1563. X      l->l->x = FSIG; 
  1564. X      l->l->hj = 'r';
  1565. X      l->l->vj = 'c';
  1566. X    } else if (strcmp(inp_str, "off") == 0) {
  1567. X      l->type = 'n';
  1568. X    } else if (strcmp(inp_str, "top") == 0) {
  1569. X      l->type = 'u';
  1570. X      l->l->y = FSIG; 
  1571. X      l->l->x = FSIG; 
  1572. X      l->l->hj = 'l';
  1573. X      l->l->vj = 'b';
  1574. X    } else if (strcmp(inp_str, "bottom") == 0) {
  1575. X      l->type = 'u';
  1576. X      l->l->y = FSIG; 
  1577. X      l->l->x = FSIG; 
  1578. X      l->l->hj = 'l';
  1579. X      l->l->vj = 't';
  1580. X    } else if (strcmp(inp_str, "custom") == 0) {
  1581. X      l->type = 'c';
  1582. X    } else if (strcmp(inp_str, "linelength") == 0) {
  1583. X      if (!getfloat(&f)) rejecttoken(); else l->linelength = f;
  1584. X    } else if (strcmp(inp_str, "linebreak") == 0) {
  1585. X      if (!getfloat(&f)) rejecttoken(); else l->linebreak = f;
  1586. X    } else if (strcmp(inp_str, "midspace") == 0) {
  1587. X      if (!getfloat(&f)) rejecttoken(); else l->midspace = f;
  1588. X    } else if (strcmp(inp_str, "defaults") == 0) {
  1589. X      edit_label(l->l);
  1590. X    } else {
  1591. X      rejecttoken();
  1592. X      return;
  1593. X    }
  1594. X  }
  1595. X}
  1596. X
  1597. Xedit_graph(g, gs, all_gs)
  1598. XGraph g;
  1599. XGraphs gs;
  1600. XGraphs all_gs;
  1601. X{
  1602. X  char inp_str[80];
  1603. X  int num;
  1604. X  String s;
  1605. X  float f;
  1606. X
  1607. X  while ( getstring(inp_str) ) {
  1608. X    if (strcmp(inp_str, "xaxis") == 0)
  1609. X      edit_axis(g->x_axis);
  1610. X    else if (strcmp(inp_str, "yaxis") == 0)
  1611. X      edit_axis(g->y_axis);
  1612. X    else if (strcmp(inp_str, "curve") == 0) {
  1613. X      if (!getint(&num)) {
  1614. X        error_header(); fprintf(stderr, "\"curve\" not followed by number\n");
  1615. X        exit(1);
  1616. X      }
  1617. X      edit_curve(get_curve(g->curves, num), g);
  1618. X    } else if (strcmp(inp_str, "newcurve") == 0) {
  1619. X      if (first(g->curves) == nil(g->curves))
  1620. X        edit_curve(new_curve(g->curves, 0), g);
  1621. X      else edit_curve(new_curve(g->curves, last(g->curves)->num + 1), g);
  1622. X    } else if (strcmp(inp_str, "copycurve") == 0) {
  1623. X      edit_curve(do_copy_curve(g, gs, all_gs), g);
  1624. X    } else if (strcmp(inp_str, "newline") == 0) {
  1625. X      if (first(g->curves) == nil(g->curves))
  1626. X        edit_curve(new_line(g->curves, 0), g);
  1627. X      else edit_curve(new_line(g->curves, last(g->curves)->num + 1), g);
  1628. X    } else if (strcmp(inp_str, "title") == 0) {
  1629. X      edit_label(g->title);
  1630. X    } else if (strcmp(inp_str, "legend") == 0) {
  1631. X      edit_legend(g->legend);
  1632. X    } else if (strcmp(inp_str, "x_translate") == 0) {
  1633. X      if (!getfloat(&f)) rejecttoken(); else g->x_translate = f;
  1634. X    } else if (strcmp(inp_str, "y_translate") == 0) {
  1635. X      if (!getfloat(&f)) rejecttoken(); else g->y_translate = f;
  1636. X    } else if (strcmp(inp_str, "string") == 0) {
  1637. X      if (!getint(&num)) {
  1638. X        error_header(); fprintf(stderr, "\"string\" not followed by number\n");
  1639. X        exit(1);
  1640. X      }
  1641. X      s = get_string(g->strings, num);
  1642. X      edit_label(s->s);
  1643. X    } else if (strcmp(inp_str, "newstring") == 0) {
  1644. X      if (first(g->strings) == nil(g->strings))
  1645. X        s = new_string(g->strings, 0);
  1646. X      else s = new_string(g->strings, last(g->strings)->num + 1);
  1647. X      edit_label(s->s);
  1648. X    } else if (strcmp(inp_str, "copystring") == 0 ||
  1649. X               strcmp(inp_str, "copyline") == 0) {
  1650. X      edit_label(do_copy_string(g, gs, all_gs));
  1651. X    } else if (strcmp(inp_str, "inherit_axes") == 0) {
  1652. X      inherit_axes(g, last_graph(g, gs, all_gs));
  1653. X    } else if (strcmp(inp_str, "Y") == 0) {
  1654. X      if (!getfloat(&f)) rejecttoken(); else gs->height = f;
  1655. X    } else if (strcmp(inp_str, "X") == 0) {
  1656. X      if (!getfloat(&f)) rejecttoken(); else gs->width = f;
  1657. X    } else if (strcmp(inp_str, "border") == 0) {
  1658. X      g->border = 1;
  1659. X    } else if (strcmp(inp_str, "noborder") == 0) {
  1660. X      g->border = 0;
  1661. X    } else if (strcmp(inp_str, "clip") == 0) {
  1662. X      g->clip = 1;
  1663. X    } else if (strcmp(inp_str, "noclip") == 0) {
  1664. X      g->clip = 0;
  1665. X    } else {
  1666. X      rejecttoken();
  1667. X      return;
  1668. X    } 
  1669. X  }
  1670. X}
  1671. X
  1672. Xedit_graphs(gs)
  1673. XGraphs gs;
  1674. X{
  1675. X  Graphs the_g;
  1676. X  Graph g, tmp_g;
  1677. X  char inp_str[80];
  1678. X  float f;
  1679. X  int num, i, ok;
  1680. X
  1681. X  the_g = first(gs);
  1682. X  while ( getstring(inp_str) ) {
  1683. X    if (strcmp(inp_str, "graph") == 0) {
  1684. X      if (!getint(&num)) {
  1685. X        error_header(); fprintf(stderr, "\"graph\" not followed by number\n");
  1686. X        exit(1);
  1687. X      }
  1688. X      edit_graph(get_graph(the_g->g, num), the_g, gs);
  1689. X    } else if (strcmp(inp_str, "newgraph") == 0) {
  1690. X      if (first(the_g->g) == nil(the_g->g))
  1691. X        edit_graph(new_graph(the_g->g, 0), the_g, gs);
  1692. X      else edit_graph(new_graph(the_g->g, last(the_g->g)->num + 1), the_g, gs);
  1693. X    } else if (strcmp(inp_str, "copygraph") == 0) {
  1694. X      if (first(the_g->g) == nil(the_g->g))
  1695. X        g = new_graph(the_g->g, 0);
  1696. X      else g = new_graph(the_g->g, last(the_g->g)->num + 1);
  1697. X      if (!getint(&num)) {
  1698. X        rejecttoken();
  1699. X        inherit_axes(g, last_graph(g, the_g, gs));
  1700. X      } else {
  1701. X        ok = 0;
  1702. X        tmp_g = the_g->g;
  1703. X        while(!ok) {
  1704. X          tmp_g = prev(tmp_g);
  1705. X          if (tmp_g == nil(the_g->g) || tmp_g->num < num) {
  1706. X            error_header();
  1707. X            fprintf(stderr, "copygraph: no graph #%d\n", num);
  1708. X            exit(1);
  1709. X          }
  1710. X          ok = (tmp_g->num == num);
  1711. X        }
  1712. X        inherit_axes(g, tmp_g);
  1713. X      }
  1714. X      edit_graph(g, the_g, gs);
  1715. X    } else if (strcmp(inp_str, "Y") == 0) {
  1716. X      if (!getfloat(&f)) rejecttoken(); else the_g->height = f;
  1717. X    } else if (strcmp(inp_str, "X") == 0) {
  1718. X      if (!getfloat(&f)) rejecttoken(); else the_g->width = f;
  1719. X    } else if (strcmp(inp_str, "newpage") == 0) {
  1720. X      new_graphs(gs);
  1721. X      the_g = last(gs);
  1722. X    } else if (strcmp(inp_str, "bbox") == 0) {
  1723. X      for (i = 0; i < 4; i++) {
  1724. X        if (!getfloat(&f)) {
  1725. X          error_header();
  1726. X          fprintf(stderr, "Bbox definition must have four numbers\n");
  1727. X          exit(1);
  1728. X        } else {
  1729. X          the_g->bb[i] = f;
  1730. X        }
  1731. X      }
  1732. X    } else if (strcmp(inp_str, "preamble") == 0) {
  1733. X      if (!getstring(inp_str)) return;
  1734. X      if (strcmp(inp_str, ":") != 0) {
  1735. X        the_g->prefile = 1;
  1736. X        the_g->preamble = (char *) malloc (sizeof(char)*(strlen(inp_str)+1));
  1737. X        strcpy(the_g->preamble, inp_str);
  1738. X      } else {
  1739. X        the_g->prefile = 0;
  1740. X        the_g->preamble = getmultiline();
  1741. X        if (the_g->preamble == CNULL) return;
  1742. X      }
  1743. X    } else if (strcmp(inp_str, "epilogue") == 0) {
  1744. X      if (!getstring(inp_str)) return;
  1745. X      if (strcmp(inp_str, ":") != 0) {
  1746. X        the_g->epifile = 1;
  1747. X        the_g->epilogue = (char *) malloc (sizeof(char)*(strlen(inp_str)+1));
  1748. X        strcpy(the_g->epilogue, inp_str);
  1749. X      } else {
  1750. X        the_g->epifile = 0;
  1751. X        the_g->epilogue = getmultiline();
  1752. X        if (the_g->epilogue == CNULL) return;
  1753. X      }
  1754. X    } else {
  1755. X      error_header(); fprintf(stderr, "Bad token: %s\n", inp_str);
  1756. X      exit(1);
  1757. X    } 
  1758. X  }
  1759. X}
  1760. END_OF_FILE
  1761.   if test 31446 -ne `wc -c <'edit.c'`; then
  1762.     echo shar: \"'edit.c'\" unpacked with wrong size!
  1763.   fi
  1764.   # end of 'edit.c'
  1765. fi
  1766. if test -f 'prio_list.h' -a "${1}" != "-c" ; then 
  1767.   echo shar: Will not clobber existing file \"'prio_list.h'\"
  1768. else
  1769.   echo shar: Extracting \"'prio_list.h'\" \(789 characters\)
  1770.   sed "s/^X//" >'prio_list.h' <<'END_OF_FILE'
  1771. X/* 
  1772. X * $Source: /n/fs/vd/jsp/src/jgraph/RCS/prio_list.h,v $
  1773. X * $Revision: 8.0 $
  1774. X * $Date: 92/07/03 14:16:08 $
  1775. X * $Author: jsp $
  1776. X */
  1777. X
  1778. X/* Priority lists are just like normal lists of list.h and list.c, except
  1779. X * that their third field is a (int) prioriy.  The routines of list.c should all
  1780. X * be used except for insert, because it will always put an item at the 
  1781. X * end of a list.  Instead, use prio_insert, which will put the item
  1782. X * into its proper place in the list.  The last argument of prio_insert should
  1783. X * be TRUE if the list is to be kept in descending order; it should be FALSE
  1784. X * for ascending order.
  1785. X
  1786. X * Priority list should be:
  1787. X
  1788. Xstruct prio_list {
  1789. X  struct prio_list *flink;
  1790. X  struct prio_list *blink;
  1791. X  int prio;
  1792. X  ...
  1793. X  }
  1794. X
  1795. X*/
  1796. X
  1797. X/* void prio_insert(node, list, descending); */
  1798. X
  1799. END_OF_FILE
  1800.   if test 789 -ne `wc -c <'prio_list.h'`; then
  1801.     echo shar: \"'prio_list.h'\" unpacked with wrong size!
  1802.   fi
  1803.   # end of 'prio_list.h'
  1804. fi
  1805. echo shar: End of archive 3 \(of 7\).
  1806. cp /dev/null ark3isdone
  1807. MISSING=""
  1808. for I in 1 2 3 4 5 6 7 ; do
  1809.     if test ! -f ark${I}isdone ; then
  1810.     MISSING="${MISSING} ${I}"
  1811.     fi
  1812. done
  1813. if test "${MISSING}" = "" ; then
  1814.     echo You have unpacked all 7 archives.
  1815.     rm -f ark[1-9]isdone
  1816. else
  1817.     echo You still must unpack the following archives:
  1818.     echo "        " ${MISSING}
  1819. fi
  1820. exit 0
  1821. exit 0 # Just in case...
  1822.