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

  1. Newsgroups: comp.sources.misc
  2. From: jsp@Princeton.EDU (James Plank)
  3. Subject:  v31i036:  jgraph - A filter for plotting postscript graphs v8.0, Part06/07
  4. Message-ID: <1992Jul14.151945.11202@sparky.imd.sterling.com>
  5. X-Md4-Signature: 8896463471b40d917bf6e5c91dd6ee60
  6. Date: Tue, 14 Jul 1992 15:19:45 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: jsp@Princeton.EDU (James Plank)
  10. Posting-number: Volume 31, Issue 36
  11. Archive-name: jgraph/part06
  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:  descrip.mms jgraph.c jgraph.h jmalloc.c printline.c show.c
  22. #   token.c
  23. # Wrapped by kent@sparky on Sun Jul 12 20:04:04 1992
  24. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  25. echo If this archive is complete, you will see the following message:
  26. echo '          "shar: End of archive 6 (of 7)."'
  27. if test -f 'descrip.mms' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'descrip.mms'\"
  29. else
  30.   echo shar: Extracting \"'descrip.mms'\" \(1241 characters\)
  31.   sed "s/^X//" >'descrip.mms' <<'END_OF_FILE'
  32. X# VMS MMS makefile
  33. X#
  34. X# In the link you will get a warning because of the multiple definition
  35. X# of exit(). This may be ignored; in order to get MMS completing without
  36. X# trouble you will have to call MMS as follows:
  37. X#    $ MMS/IGNORE
  38. X#
  39. X.ifdef DEBUG
  40. XCFLAGS=/INCLUDE=(SYS$DISK:[],SYS$SHARE:)/noopt/debug
  41. XLFLAGS=/debug
  42. X.else
  43. XCFLAGS=/INCLUDE=(SYS$DISK:[],SYS$SHARE:)
  44. XLFLAGS=
  45. X.endif
  46. X
  47. XOBJS = draw.obj, \
  48. X        edit.obj, \
  49. X        jgraph.obj, \
  50. X        list.obj, \
  51. X        printline.obj, \
  52. X        prio_list.obj, \
  53. X        process.obj, \
  54. X        show.obj, \
  55. X        token.obj, \
  56. X        exit.obj
  57. X
  58. Xall :    jgraph.exe
  59. X    ! done
  60. X
  61. X# Do not link against the shareable image VAXCRTL.EXE, or you will
  62. X# miss the reference to the local exit() routine.
  63. X# EXIT will be reported as being multiply defined - ignore that.
  64. Xjgraph.exe : $(OBJS)
  65. X    link $(LFLAGS) /exe=jgraph $(OBJS),sys$library:vaxcrtl/libr
  66. X
  67. X###
  68. Xdraw.obj :    draw.c jgraph.h list.h prio_list.h
  69. Xedit.obj :    edit.c jgraph.h list.h prio_list.h
  70. Xjgraph.obj :    jgraph.c jgraph.h list.h prio_list.h
  71. Xlist.obj :    list.c list.h
  72. Xprintline.obj :    printline.c jgraph.h list.h prio_list.h
  73. Xprio_list.obj :    prio_list.c list.h prio_list.h
  74. Xprocess.obj :    process.c jgraph.h list.h prio_list.h
  75. Xshow.obj :    show.c jgraph.h list.h prio_list.h
  76. Xtoken.obj :    token.c list.h
  77. Xexit.obj :    exit.c
  78. END_OF_FILE
  79.   if test 1241 -ne `wc -c <'descrip.mms'`; then
  80.     echo shar: \"'descrip.mms'\" unpacked with wrong size!
  81.   fi
  82.   # end of 'descrip.mms'
  83. fi
  84. if test -f 'jgraph.c' -a "${1}" != "-c" ; then 
  85.   echo shar: Will not clobber existing file \"'jgraph.c'\"
  86. else
  87.   echo shar: Extracting \"'jgraph.c'\" \(7360 characters\)
  88.   sed "s/^X//" >'jgraph.c' <<'END_OF_FILE'
  89. X/* 
  90. X * $Source: /n/fs/vd/jsp/src/jgraph/RCS/jgraph.c,v $
  91. X * $Revision: 8.0 $
  92. X * $Date: 92/07/03 14:15:54 $
  93. X * $Author: jsp $
  94. X */
  95. X
  96. X#include <stdio.h>
  97. X
  98. X#ifdef VMS 
  99. X#include <redexp.VMS>
  100. Xextern FILE *IOSTREAM;    /* for token.c, q.v. -hdd */
  101. X#endif
  102. X
  103. X#include "jgraph.h"
  104. X
  105. Xint NMARKTYPES = 16;
  106. Xint NORMALMARKTYPES = 6;
  107. X
  108. Xchar *MARKTYPESTRS[] = { "circle", "box", "diamond", "triangle", "x", "cross", 
  109. X                         "ellipse", "general", "general_nf", "general_bez",
  110. X                         "general_bez_nf", "postscript", 
  111. X                         "xbar", "ybar", "none", "text"};
  112. Xchar MARKTYPES[] = {     'o',      'b',   'd',       't',        'x', 'c', 
  113. X             'e',       'g',       'G',          'Z',
  114. X                         'B',              'p',          
  115. X                         'X',    'Y',    'n',    'l' };
  116. X
  117. XLabel new_label()
  118. X{
  119. X  Label l;
  120. X  int i;
  121. X
  122. X  l = (Label) malloc (sizeof(struct label));
  123. X  l->label = CNULL;
  124. X  l->hj = 'c';
  125. X  l->vj = 'b';
  126. X  l->font = "Times-Roman";
  127. X  l->fontsize = 9.0;
  128. X  l->rotate = 0;
  129. X  l->graytype = 'n';
  130. X  for (i = 0; i < 3; i++) l->gray[i] = 0.0;
  131. X  l->linesep = FSIG;
  132. X
  133. X  return l;
  134. X}
  135. X
  136. X
  137. XCurve new_curve(c, num)
  138. XCurve c;
  139. Xint num;
  140. X{
  141. X  Curve new_c;
  142. X  int i;
  143. X
  144. X  new_c = (Curve) get_node(c);
  145. X  new_c->num = num;
  146. X  new_c->l = new_label();
  147. X  new_c->l->vj = 't';
  148. X  new_c->lmark = new_label();
  149. X  new_c->lmark->hj = 'c';
  150. X  new_c->lmark->vj = 'c';
  151. X  new_c->clip = 0;
  152. X  new_c->graytype = 'n';
  153. X  for (i = 0; i < 3; i++) new_c->gray[i] = 0.0;
  154. X  new_c->afilltype = 'g';
  155. X  for (i = 0; i < 3; i++) new_c->afill[i] = 0.0;
  156. X  new_c->pts = (Point) make_list(sizeof(struct point));
  157. X  new_c->yepts = (Point) make_list(sizeof(struct point));
  158. X  new_c->xepts = (Point) make_list(sizeof(struct point));
  159. X  new_c->npts = 0;
  160. X  new_c->gen_linetype = (Flist) make_list(sizeof(struct flist));
  161. X  new_c->marktype = MARKTYPES[num % NORMALMARKTYPES];
  162. X  new_c->linetype = '0';
  163. X  new_c->linethick = 1.0;
  164. X  new_c->marksize[0] = FSIG;
  165. X  new_c->marksize[1] = FSIG;
  166. X  new_c->mrotate = 0.0;
  167. X  new_c->general_marks = (Point) make_list(sizeof(struct point));
  168. X  new_c->filltype = 'n';
  169. X  for (i = 0; i < 3; i++) new_c->fill[i] = 0.0;
  170. X  new_c->pfilltype = 'n';
  171. X  for (i = 0; i < 3; i++) new_c->pfill[i] = 0.0;
  172. X  new_c->poly = 0;
  173. X  new_c->rarrow = 0;
  174. X  new_c->larrow = 0;
  175. X  new_c->rarrows = 0;
  176. X  new_c->larrows = 0;
  177. X  new_c->asize[0] = FSIG;
  178. X  new_c->asize[1] = FSIG;
  179. X  new_c->bezier = 0;
  180. X  new_c->postscript = CNULL;
  181. X  new_c->postfile = 0;
  182. X  prio_insert(new_c, c, 0);
  183. X  return new_c;
  184. X}
  185. X
  186. XCurve new_line(c, num)
  187. XCurve c;
  188. Xint num;
  189. X{
  190. X  Curve new_c;
  191. X  new_c = new_curve(c, num);
  192. X  new_c->linetype = 's';
  193. X  new_c->marktype = 'n';
  194. X  return new_c;
  195. X}
  196. X
  197. X
  198. XCurve get_curve(c, num)
  199. XCurve c;
  200. Xint num;
  201. X{
  202. X  Curve new_c;
  203. X  for(new_c = last(c); new_c != nil(c) && new_c->num > num; new_c = prev(new_c));
  204. X  if (new_c == nil(c) || new_c->num < num) return new_curve(c, num);
  205. X  return new_c;
  206. X}
  207. X
  208. XAxis new_axis(is_x)
  209. Xint is_x;
  210. X{
  211. X  int i;
  212. X  Axis a;
  213. X
  214. X  a = (Axis) malloc (sizeof(struct axis));
  215. X  a->label = new_label();
  216. X  a->label->x = FSIG;
  217. X  a->label->y = FSIG;
  218. X  a->label->font = "Times-Bold";
  219. X  a->label->fontsize = 10.0;
  220. X  a->label->rotate = FSIG;
  221. X  a->label->hj = '0';
  222. X  a->label->vj = '0';
  223. X  a->size = 3.0;
  224. X  a->max = FSIG;
  225. X  a->min = FSIG;
  226. X  a->pmax = FSIG;
  227. X  a->pmin = FSIG;
  228. X  a->hash_interval = -1.0;
  229. X  a->log_base = 10.0;
  230. X  a->minor_hashes = -1;
  231. X  a->precision = -1;
  232. X  a->hl = new_label();
  233. X  a->hl->label = "";
  234. X  a->hl->font = "Times-Roman";
  235. X  a->hl->fontsize = 9.0;
  236. X  a->hl->rotate = 0.0;
  237. X  a->hl->hj = '0';
  238. X  a->hl->vj = '0';
  239. X  a->draw_at = FSIG;
  240. X  a->draw_hash_marks_at = FSIG;
  241. X  a->draw_hash_labels_at = FSIG;
  242. X  a->draw_hash_labels = 1;
  243. X  a->draw_axis_line = 1;
  244. X  a->draw_hash_marks = 1;
  245. X  a->draw_axis_label = 1;
  246. X  a->auto_hash_labels = 1;
  247. X  a->auto_hash_marks = 1;
  248. X  a->start_given = 0;
  249. X  a->hash_scale = -1.0;
  250. X  a->grid_lines = 0;
  251. X  a->mgrid_lines = 0;
  252. X  a->graytype = 'n';
  253. X  for (i = 0; i < 3; i++) a->gray[i] = 0.0;
  254. X  a->gr_graytype = '0';
  255. X  for (i = 0; i < 3; i++) a->gr_gray[i] = 0.0;
  256. X  a->mgr_graytype = '0';
  257. X  for (i = 0; i < 3; i++) a->mgr_gray[i] = 0.0;
  258. X  a->is_x = is_x;
  259. X  a->is_lg = 0;
  260. X  a->hash_labels = (String) make_list (sizeof(struct string));
  261. X  a->hash_lines = (Hash) make_list (sizeof(struct hash));
  262. X  return a;
  263. X}
  264. X
  265. XLegend new_legend()
  266. X{
  267. X  Legend l;
  268. X  l = (Legend) malloc (sizeof(struct legend));
  269. X  l->linelength = FSIG;
  270. X  l->linebreak = FSIG;
  271. X  l->midspace = FSIG;
  272. X  l->type = 'u';
  273. X  l->l = new_label();
  274. X  l->l->label = "";
  275. X  l->l->hj = 'l';
  276. X  l->l->vj = 'c';
  277. X  l->l->x = FSIG;
  278. X  l->l->y = FSIG;
  279. X  return l;
  280. X}
  281. X
  282. XLabel new_title()
  283. X{
  284. X  Label t;
  285. X
  286. X  t = new_label();
  287. X  t->x = FSIG;
  288. X  t->y = FSIG;
  289. X  t->rotate = 0.0;
  290. X  t->hj = 'c';
  291. X  t->vj = 't';
  292. X  t->fontsize = 12.0;
  293. X  return t;
  294. X}
  295. X
  296. XString new_string(s, num)
  297. XString s;
  298. Xint num;
  299. X{
  300. X  String new_s;
  301. X
  302. X  new_s = (String) get_node(s);
  303. X  new_s->num = num;
  304. X  new_s->s = new_label();
  305. X  prio_insert(new_s, s, 0);
  306. X  return new_s;
  307. X}
  308. X
  309. XString get_string(s, num)
  310. XString s;
  311. Xint num;
  312. X{
  313. X  String new_s;
  314. X  for(new_s = last(s); new_s != nil(s) && new_s->num > num; new_s = prev(new_s));
  315. X  if (new_s == nil(s) || new_s->num < num) return new_string(s, num);
  316. X  return new_s;
  317. X}
  318. X
  319. X/*
  320. XDefault new_default()
  321. X{
  322. X  Default new_d;
  323. X  new_d = (Default) malloc (sizeof(default));
  324. X  new_d->rotate = FSIG;
  325. X  new_d->fontsize = FSIG;
  326. X  new_d->general_marks = GMNULL;
  327. X  new_d->fill = FSIG;
  328. X  new_d->linethick = FSIG;
  329. X  new_d->font = CNULL;
  330. X  new_d->hj = '!';
  331. X  new_d->vj = '!';
  332. X  new_d->marktype = '!';
  333. X  new_d->linetype = '!';
  334. X  new_d->marksize[0] = FSIG;
  335. X  new_d->marksize[1] = FSIG;
  336. X}
  337. X*/
  338. X  
  339. XGraph new_graph(gs, num)
  340. XGraph gs;
  341. Xint num;
  342. X{
  343. X  Graph g;
  344. X
  345. X  g = (Graph) get_node(gs);
  346. X  g->num = num;
  347. X  g->xminval = 0.0;
  348. X  g->yminval = 0.0;
  349. X  g->xmaxval = 0.0;
  350. X  g->ymaxval = 0.0;
  351. X  g->x_axis = new_axis(1);
  352. X  g->y_axis = new_axis(0);
  353. X  g->x_translate = 0.0;
  354. X  g->y_translate = 0.0;
  355. X  g->curves = (Curve) make_list(sizeof(struct curve));
  356. X  g->strings = (String) make_list(sizeof(struct string));
  357. X  g->title = new_title();
  358. X  g->clip = 0;
  359. X  g->border = 0;
  360. X  g->legend = new_legend();
  361. X/*  g->def = new_default(); */
  362. X  prio_insert(g, gs, 0);
  363. X  return g;
  364. X}
  365. X
  366. XGraph get_graph(g, num)
  367. XGraph g;
  368. Xint num;
  369. X{
  370. X  Graph new_g;
  371. X  for(new_g = last(g); new_g != nil(g) && new_g->num > num; new_g = prev(new_g));
  372. X  if (new_g == nil(g) || new_g->num < num) return new_graph(g, num);
  373. X  return new_g;
  374. X}
  375. X
  376. Xnew_graphs(gs)
  377. XGraphs gs;
  378. X{
  379. X  Graphs newg;
  380. X
  381. X  newg = (Graphs) get_node(gs);
  382. X  newg->g = (Graph) make_list(sizeof(struct graph));
  383. X  newg->height = 0.0;
  384. X  newg->width = 0.0;
  385. X  newg->bb[0] = FSIG; newg->bb[1] = FSIG;
  386. X  newg->bb[2] = FSIG; newg->bb[3] = FSIG;
  387. X  newg->preamble = CNULL;
  388. X  newg->epilogue = CNULL;
  389. X  newg->prefile = 0;
  390. X  newg->epifile = 0;
  391. X  insert(newg, gs);
  392. X}
  393. X
  394. Xmain(argc, argv)
  395. Xint argc;
  396. Xchar **argv;
  397. X{
  398. X  Graphs gs;
  399. X  int i;
  400. X  int show, pp;
  401. X  int landscape;
  402. X  int comments;
  403. X
  404. X#ifdef VMS 
  405. X  IOSTREAM = stdin;    /* for token.c -hdd */
  406. X#endif
  407. X  show = 0;
  408. X  pp = 0;
  409. X  comments = 0;
  410. X  landscape = 0;
  411. X
  412. X  for (i = 1; i < argc; i++) {
  413. X    if (strcmp(argv[i], "-p") == 0) show = 1;
  414. X    else if (strcmp(argv[i], "-comments") == 0) comments = 1;
  415. X    else if (strcmp(argv[i], "-P") == 0) pp = 1;
  416. X    else if (strcmp(argv[i], "-L") == 0) landscape = 1;
  417. X  }
  418. X  gs = (Graphs) make_list(sizeof(struct graphs));
  419. X  set_comment(comments);
  420. X  new_graphs(gs);
  421. X  edit_graphs(gs);
  422. X  process_graphs(gs);
  423. X  if (show) show_graphs(gs); else draw_graphs(gs, pp, landscape);
  424. X  exit(0);
  425. X  return 0;
  426. X}
  427. X
  428. X
  429. END_OF_FILE
  430.   if test 7360 -ne `wc -c <'jgraph.c'`; then
  431.     echo shar: \"'jgraph.c'\" unpacked with wrong size!
  432.   fi
  433.   # end of 'jgraph.c'
  434. fi
  435. if test -f 'jgraph.h' -a "${1}" != "-c" ; then 
  436.   echo shar: Will not clobber existing file \"'jgraph.h'\"
  437. else
  438.   echo shar: Extracting \"'jgraph.h'\" \(3993 characters\)
  439.   sed "s/^X//" >'jgraph.h' <<'END_OF_FILE'
  440. X/* 
  441. X * $Source: /n/fs/vd/jsp/src/jgraph/RCS/jgraph.h,v $
  442. X * $Revision: 8.0 $
  443. X * $Date: 92/07/03 14:15:58 $
  444. X * $Author: jsp $
  445. X */
  446. X
  447. X#include "list.h"
  448. X#include "prio_list.h"
  449. X#ifdef LCC
  450. X#include <stdlib.h>
  451. X#endif
  452. X
  453. X#define PPI 120
  454. X#define FPPI 120.0
  455. X#define CPI 72.0
  456. X#define FCPI 72.0
  457. X#define CNULL ((char *)0)
  458. X#define GMNULL ((Point)0)
  459. X#define FSIG -10010.0
  460. X#define HASH_SIZE 5.0
  461. X#define MHASH_SIZE 2.0
  462. X
  463. Xtypedef struct point {
  464. X  struct point *flink;
  465. X  struct point *blink;
  466. X  float x;
  467. X  float y;
  468. X  char e;          /* 'x' for x_ebars, 'y' for y_ebars, 'p' for neither */
  469. X} *Point;
  470. X
  471. Xtypedef struct flist {
  472. X  struct flist *flink;
  473. X  struct flist *blink;
  474. X  float f;
  475. X} *Flist;
  476. X
  477. Xtypedef struct label {
  478. X  char *label;
  479. X  float x;
  480. X  float y;
  481. X  float rotate;
  482. X  char *font;
  483. X  float fontsize;
  484. X  char hj;
  485. X  char vj;
  486. X  float gray[3];
  487. X  char graytype;
  488. X  float linesep;
  489. X  float xmin;
  490. X  float xmax;
  491. X  float ymin;
  492. X  float ymax;
  493. X  int nlines;
  494. X} *Label;
  495. X
  496. Xtypedef struct curve {
  497. X  struct curve *flink;
  498. X  struct curve *blink;
  499. X  int num;
  500. X  Label l;
  501. X  Label lmark;
  502. X  Point pts;
  503. X  Point yepts;
  504. X  Point xepts;
  505. X  int npts;
  506. X  Point general_marks;
  507. X  float marksize[2];
  508. X  float fill[3];
  509. X  float gray[3];
  510. X  float afill[3];
  511. X  float pfill[3];
  512. X  float linethick;
  513. X  float mrotate;
  514. X  Flist gen_linetype;
  515. X  char graytype ;
  516. X  char filltype ;
  517. X  char afilltype;
  518. X  char pfilltype;
  519. X  char marktype;
  520. X  char linetype;
  521. X  char *postscript;
  522. X  int postfile;
  523. X  int rarrow;
  524. X  int larrow;
  525. X  int rarrows;
  526. X  int larrows;
  527. X  int bezier;
  528. X  int poly;
  529. X  float asize[2];
  530. X  int clip;
  531. X} *Curve;
  532. X
  533. Xtypedef struct string {
  534. X  struct string *flink;
  535. X  struct string *blink;
  536. X  int num;
  537. X  Label s;
  538. X} *String;
  539. X
  540. Xtypedef struct hash {
  541. X  struct hash *flink;
  542. X  struct hash *blink;
  543. X  float loc;
  544. X  float size;
  545. X  int major;
  546. X} *Hash;
  547. X
  548. Xtypedef struct deflt {
  549. X  float rotate;
  550. X  float fontsize;
  551. X  Point general_marks;
  552. X  float fill;
  553. X  float linethick;
  554. X  float marksize[2];
  555. X  char *font;
  556. X  char hj;
  557. X  char vj;
  558. X  char marktype;
  559. X} *Default;
  560. X  
  561. Xtypedef struct axis {
  562. X  Label label;
  563. X  Label hl;
  564. X  float max;
  565. X  float min;
  566. X  float pmax;
  567. X  float pmin;
  568. X  float logmin;
  569. X  float logfactor;
  570. X  float size;
  571. X  float psize;
  572. X  float factor;
  573. X  float hash_interval;
  574. X  float hash_start;
  575. X  float hash_scale;
  576. X  float log_base;
  577. X  float draw_hash_marks_at;
  578. X  float draw_hash_labels_at;
  579. X  float draw_at;
  580. X  float gray[3];
  581. X  char graytype;
  582. X  float gr_gray[3];
  583. X  char gr_graytype;
  584. X  float mgr_gray[3];
  585. X  char mgr_graytype;
  586. X  int grid_lines;
  587. X  int mgrid_lines;
  588. X  int draw_hash_labels;
  589. X  int draw_axis_line;
  590. X  int draw_hash_marks;
  591. X  int draw_axis_label;
  592. X  int auto_hash_labels;
  593. X  int auto_hash_marks;
  594. X  int minor_hashes;
  595. X  int precision;
  596. X  int start_given;
  597. X  String hash_labels;
  598. X  Hash hash_lines;
  599. X  int is_x;
  600. X  int is_lg;
  601. X} *Axis;
  602. X
  603. Xtypedef struct legend {
  604. X  float linelength;
  605. X  float linebreak;
  606. X  int anylines;
  607. X  float midspace;
  608. X  char type; /* 'n' = off, 'u' = userdefined (use Label), 'c' = custom */
  609. X  Label l;
  610. X} *Legend;
  611. X
  612. Xtypedef struct graph {
  613. X  struct graph *flink;
  614. X  struct graph *blink;
  615. X  int num;
  616. X  float xminval;
  617. X  float yminval;
  618. X  float xmaxval;
  619. X  float ymaxval;
  620. X  float x_translate;
  621. X  float y_translate;
  622. X  Axis x_axis;
  623. X  Axis y_axis;
  624. X  Curve curves;
  625. X  Legend legend;
  626. X  String strings;
  627. X  Label title;
  628. X  int clip;
  629. X  int border;
  630. X  Default def;
  631. X} *Graph;
  632. X
  633. Xtypedef struct graphs {
  634. X  struct graphs *flink;
  635. X  struct graphs *blink;
  636. X  Graph g;
  637. X  float height;
  638. X  float width;
  639. X  float bb[4]; /* Bounding box */
  640. X  char *preamble; 
  641. X  char *epilogue; 
  642. X  int prefile;
  643. X  int epifile;
  644. X} *Graphs;
  645. X
  646. Xextern float ctop();
  647. Xextern float disttop();
  648. Xextern float intop();
  649. Xextern float ptoc();
  650. Xextern float ptodist();
  651. X
  652. Xextern char *getlabel();
  653. Xextern char *getmultiline();
  654. X
  655. X/* Stuff defined in jgraph.c */
  656. X
  657. Xextern Curve new_line();
  658. Xextern Curve new_curve();
  659. Xextern Curve get_curve();
  660. Xextern Graph new_graph();
  661. Xextern Graph get_graph();
  662. Xextern String new_string();
  663. Xextern String get_string();
  664. Xextern Label new_label();
  665. Xextern char *MARKTYPESTRS[];
  666. Xextern char MARKTYPES[];
  667. Xextern int NMARKTYPES;
  668. Xextern int NORMALMARKTYPES;
  669. END_OF_FILE
  670.   if test 3993 -ne `wc -c <'jgraph.h'`; then
  671.     echo shar: \"'jgraph.h'\" unpacked with wrong size!
  672.   fi
  673.   # end of 'jgraph.h'
  674. fi
  675. if test -f 'jmalloc.c' -a "${1}" != "-c" ; then 
  676.   echo shar: Will not clobber existing file \"'jmalloc.c'\"
  677. else
  678.   echo shar: Extracting \"'jmalloc.c'\" \(11525 characters\)
  679.   sed "s/^X//" >'jmalloc.c' <<'END_OF_FILE'
  680. X#include <stdio.h>
  681. X#include <malloc.h>
  682. X
  683. X/* Each memory block has 8 extra 32-bit values associated with it.  If malloc
  684. X   returns the pointer p to you, the state really looks like:
  685. X
  686. Xjmal(p)------>  |------------------------------------------------------------|
  687. X                | flink (next malloc block in absolute order)                |
  688. X                |------------------------------------------------------------|
  689. X                | blink (prev malloc block in absolute order)                |
  690. X                |------------------------------------------------------------|
  691. X                | nextfree (next free malloc block - no particular order)    |
  692. X                |------------------------------------------------------------|
  693. X                | prevfree (next free malloc block - no particular order)    |
  694. X                |------------------------------------------------------------|
  695. X                | size (size of memory allocated)                            |
  696. X                |------------------------------------------------------------|
  697. X                | cs2 (pointer to the second checksum, which is right after  |
  698. X                |   the mem block)                                           |
  699. X                |------------------------------------------------------------|
  700. X                | cs (checksum right before mem block.  used to determine if |
  701. X                |   there is an error of writing around the memory block)    |
  702. Xp------------>  |------------------------------------------------------------|
  703. X                | space: the memory block                                    |
  704. X                |                  ...                                       |
  705. X                |                  ...                                       |
  706. X                |------------------------------------------------------------|
  707. X            | the second checksum                                        |
  708. X                |------------------------------------------------------------|
  709. X*/
  710. X
  711. X
  712. Xtypedef struct jmalloc {
  713. X  struct jmalloc *flink;
  714. X  struct jmalloc *blink;
  715. X  struct jmalloc *nextfree;
  716. X  struct jmalloc *prevfree;
  717. X  int size;
  718. X  int *cs2;
  719. X  int cs;
  720. X  char *space;
  721. X} *Jmalloc;
  722. X
  723. X#define JMSZ (sizeof(struct jmalloc))
  724. X#define PTSZ (sizeof(char *))  /* Also assuming its > sizeof int */
  725. X#define CHUNK_SIZE (16384 - JMSZ)    /* 16K */
  726. X#define MASK 0x17826a9b
  727. X#define JNULL ((Jmalloc) 0)
  728. X
  729. Xstatic struct jmalloc j_head;
  730. Xstatic Jmalloc memlist;
  731. Xstatic int nfree = 0;
  732. Xstatic int nblocks = 0;
  733. Xstatic int init = 0;
  734. Xstatic Jmalloc start;
  735. Xstatic int free_called = 0;
  736. Xstatic int malloc_called = 0;
  737. Xstatic int used_mem = 0;
  738. Xstatic int free_mem = 0;
  739. Xstatic int used_blocks = 0;
  740. Xstatic int free_blocks = 0;
  741. X
  742. X#define cksum(p) (((int) &(p->cs)) - 1)
  743. X#define jloc(l) ((char *) (&l->space))
  744. X#define jmal(l) ((Jmalloc) (((char *)l) - JMSZ + PTSZ))
  745. X#define isfree(l) (l->nextfree != JNULL)
  746. X
  747. X#define do_init() \
  748. X  if (!init) {\
  749. X    memlist = &j_head;\
  750. X    memlist->flink = memlist;\
  751. X    memlist->blink = memlist;\
  752. X    memlist->nextfree = memlist;\
  753. X    memlist->prevfree = memlist;\
  754. X    memlist->size = 0;\
  755. X    memlist->cs = cksum(memlist);\
  756. X    memlist->cs2 = &memlist->cs;\
  757. X    memlist->space = (char *) 0;\
  758. X    start = memlist;\
  759. X    init = 1;\
  760. X  }
  761. X
  762. Xdump_core()
  763. X{
  764. X  memlist->space[0] = 0;
  765. X}
  766. X
  767. Xchar *set_used(l)
  768. XJmalloc l;
  769. X{
  770. X  start = l->nextfree;
  771. X  l->prevfree->nextfree = l->nextfree;
  772. X  l->nextfree->prevfree = l->prevfree;
  773. X  l->prevfree = JNULL;
  774. X  l->nextfree = JNULL;
  775. X  used_mem += l->size;
  776. X  free_mem -= l->size;
  777. X  used_blocks++;
  778. X  free_blocks--;
  779. X
  780. X  return jloc(l);
  781. X}
  782. X
  783. Xvoid *malloc(size)
  784. Xint size;
  785. X{
  786. X  int redo;
  787. X  int done;
  788. X  Jmalloc l;
  789. X  char *tmp;
  790. X  Jmalloc newl;
  791. X  int newsize;
  792. X  
  793. X  do_init();
  794. X  malloc_called++;
  795. X  if (size <= 0) {
  796. X    fprintf(stderr, "Error: Malloc(%d) called\n", size);
  797. X    /* Dump core */
  798. X    dump_core();
  799. X  }
  800. X    
  801. X  if (size % PTSZ != 0) size += PTSZ - (size % PTSZ);
  802. X
  803. X  done = 0;
  804. X  l = start;
  805. X  while(!done) {
  806. X    if (l->size >= size) {
  807. X      done = 1;
  808. X      redo = 0;
  809. X    } else {
  810. X      l = l->nextfree;
  811. X      done = (l == start);
  812. X      redo = done;
  813. X    } 
  814. X  }
  815. X      
  816. X  if (redo) {
  817. X    if (size > CHUNK_SIZE) 
  818. X      newsize = size + JMSZ; 
  819. X      else newsize = CHUNK_SIZE + JMSZ;
  820. X    newl = (Jmalloc) sbrk(newsize);
  821. X    while (newl == (Jmalloc) -1 && newsize > size + JMSZ) {
  822. X      newsize /= 2;
  823. X      if (newsize < size + JMSZ) newsize = size + JMSZ;
  824. X      newl = (Jmalloc) sbrk(newsize);
  825. X    }
  826. X      
  827. X    if (newl == (Jmalloc) -1) {
  828. X/*       fprintf(stderr, "Jmalloc: out of memory\n"); */
  829. X/*       fprintf(stderr, "Used bytes = %d, Free bytes = %d\n",  */
  830. X/*               used_mem, free_mem); */
  831. X/*       fprintf(stderr, "Trying to get %d bytes (chunk of %d)\n",  */
  832. X/*               size, newsize); */
  833. X      return NULL;
  834. X    }
  835. X    newl->flink = memlist;
  836. X    newl->blink = memlist->blink;
  837. X    newl->flink->blink = newl;
  838. X    newl->blink->flink = newl;
  839. X    newl->nextfree = memlist;
  840. X    newl->prevfree = memlist->prevfree;
  841. X    newl->nextfree->prevfree = newl;
  842. X    newl->prevfree->nextfree = newl;
  843. X    newl->size = ((char *) sbrk(0)) - jloc(newl) - PTSZ;
  844. X    free_mem += newl->size;
  845. X    newl->cs = cksum(newl);
  846. X    newl->cs2 = ((int *) (jloc(newl) + newl->size));
  847. X    *(newl->cs2) = cksum(newl);
  848. X    if(newl->size < size) {
  849. X      fprintf(stderr, "Newl->size(%d) < size(%d)\n", newl->size, size);
  850. X      exit(1);
  851. X    }
  852. X    free_blocks++;
  853. X    l = newl;
  854. X  } 
  855. X
  856. X  if (l->size - size < JMSZ) {
  857. X    return set_used(l);
  858. X  } else {
  859. X    tmp = jloc(l);
  860. X    newl = (Jmalloc) (tmp + size + PTSZ);
  861. X    newl->flink = l->flink;
  862. X    newl->blink = l;
  863. X    newl->flink->blink = newl;
  864. X    newl->blink->flink = newl;
  865. X    newl->nextfree = l->nextfree;
  866. X    newl->prevfree = l;
  867. X    newl->nextfree->prevfree = newl;
  868. X    newl->prevfree->nextfree = newl;
  869. X    newl->size = l->size - size - JMSZ;
  870. X    newl->cs = cksum(newl);
  871. X    newl->cs2 = (int *) (jloc(newl) + newl->size);
  872. X    *(newl->cs2) = cksum(newl);
  873. X    free_mem += size + newl->size - l->size;
  874. X    free_blocks++;
  875. X    l->size = size;
  876. X    l->cs2 = ((int *) (jloc(l) + l->size));
  877. X    *(l->cs2) = cksum(l);
  878. X    return set_used(l);
  879. X  }
  880. X}
  881. X
  882. Xjmalloc_print_mem()
  883. X{
  884. X  Jmalloc l;
  885. X  int done;
  886. X  char *bufs[100];
  887. X  int sizes[100];
  888. X  int mc;
  889. X  int fc;
  890. X  int i, j;
  891. X
  892. X  do_init();
  893. X  mc = malloc_called;
  894. X  fc = free_called;
  895. X  if (jmal(jloc(memlist)) != memlist) {
  896. X    fprintf(stderr, "TROUBLE: memlist=0x%x, jmal(jloc(memlist))=0x%x)\n",
  897. X            memlist, jmal(jloc(memlist)));
  898. X    exit(1);
  899. X  }
  900. X  done = 0;
  901. X  l = start;
  902. X  i = 0;
  903. X  while (!done) {
  904. X    if (cksum(l) != l->cs) {
  905. X      printf("Memory location 0x%x corrupted\n", jloc(l));
  906. X      exit(1);
  907. X    } else if (cksum(l) != *(l->cs2)) {
  908. X      printf("Memory location 0x%x corrupted\n", jloc(l));
  909. X      exit(1);
  910. X    }
  911. X    
  912. X    bufs[i] = jloc(l);
  913. X    sizes[i] = l->size;
  914. X    if (l->nextfree == 0) sizes[i] = -sizes[i];
  915. X    i++;
  916. X    l = l->flink;
  917. X    done = ((l == start) || i >= 100);
  918. X  }
  919. X  printf("Malloc called %d times\n", mc);
  920. X  printf("Free called %d times\n", fc);
  921. X  for (j = 0; j < i; j++) {
  922. X    printf("Loc = 0x%x, size = %d, free = %d\n", bufs[j], 
  923. X           (sizes[j] > 0) ? sizes[j] : -sizes[j], (sizes[j] >= 0));
  924. X  }
  925. X}
  926. X
  927. Xjmalloc_check_mem()
  928. X{
  929. X  Jmalloc l;
  930. X  int done;
  931. X
  932. X  done = 0;
  933. X
  934. X  l = start;
  935. X
  936. X  while (!done) {
  937. X    if (cksum(l) != l->cs) {
  938. X      fprintf(stderr, "Memory chunk violated: 0x%x: %s 0x%x.  %s 0x%x\n", 
  939. X              jloc(l), "Checksum 1 is ", l->cs, "It should be", cksum(l));
  940. X      dump_core();
  941. X    } else if (cksum(l) != *(l->cs2)) {
  942. X      fprintf(stderr, "Memory chunk violated: 0x%x: %s 0x%x.  %s 0x%x\n", 
  943. X              jloc(l), "Checksum 2 is ", *(l->cs2), "It should be", cksum(l));
  944. X      dump_core();
  945. X    }
  946. X    l = l->flink;
  947. X    done = (l == start);
  948. X  }
  949. X}
  950. X
  951. X  
  952. Xvoid free(loc)
  953. Xchar *loc;
  954. X{
  955. X  Jmalloc l;
  956. X  Jmalloc pl, nl;
  957. X
  958. X  do_init();
  959. X  free_called++;
  960. X  l = jmal(loc); 
  961. X
  962. X  if (cksum(l) != l->cs) {
  963. X    fprintf(stderr, "Error on free: memory chunk violated: 0x%x\n", loc);
  964. X    dump_core();
  965. X  } else if (cksum(l) != *(l->cs2)) {
  966. X    fprintf(stderr, "Error on free: memory chunk violated: 0x%x\n", loc);
  967. X    dump_core();
  968. X  }
  969. X
  970. X  used_mem -= l->size;
  971. X  free_mem += l->size;
  972. X  free_blocks++;
  973. X  used_blocks--;
  974. X
  975. X  pl = l->blink;
  976. X  nl = l->flink;
  977. X  if (isfree(pl) && (jloc(pl)+pl->size + PTSZ == (char *) l)) {
  978. X    free_mem += JMSZ;
  979. X    pl->size += l->size + JMSZ;
  980. X    pl->flink = nl;
  981. X    pl->flink->blink = pl;
  982. X    l = pl;
  983. X    free_blocks--;
  984. X  } else {
  985. X    l->prevfree = start;
  986. X    l->nextfree = start->nextfree;
  987. X    l->nextfree->prevfree = l;
  988. X    l->prevfree->nextfree = l;
  989. X  }
  990. X
  991. X  if (isfree(nl) && jloc(l)+l->size + PTSZ == (char *) nl) {
  992. X    free_mem += JMSZ;
  993. X    l->size += nl->size + JMSZ;
  994. X    l->flink = nl->flink;
  995. X    l->flink->blink = l;
  996. X    free_blocks--;
  997. X    nl->nextfree->prevfree = nl->prevfree;
  998. X    nl->prevfree->nextfree = nl->nextfree;
  999. X  }
  1000. X  start = l;
  1001. X}
  1002. X
  1003. Xvoid *realloc(loc, size)
  1004. Xchar *loc;
  1005. Xint size;
  1006. X{
  1007. X  Jmalloc l;
  1008. X  Jmalloc l2, nl;
  1009. X  char *loc2;
  1010. X  int i;
  1011. X  Jmalloc newl;
  1012. X
  1013. X
  1014. X  do_init();
  1015. X
  1016. X  if (size <= 0) {
  1017. X    fprintf(stderr, "Error: Malloc(%d) called\n", size);
  1018. X    /* Dump core */
  1019. X    dump_core();
  1020. X  }
  1021. X    
  1022. X  if (size % PTSZ != 0) size += PTSZ - (size % PTSZ);
  1023. X
  1024. X  l = jmal(loc); 
  1025. X
  1026. X  if (cksum(l) != l->cs) {
  1027. X    fprintf(stderr, "Error on realloc: memory chunk violated: 0x%x\n", loc);
  1028. X    dump_core();
  1029. X  } else if (cksum(l) != *(l->cs2)) {
  1030. X    fprintf(stderr, "Error on realloc: memory chunk violated: 0x%x\n", loc);
  1031. X    dump_core();
  1032. X  }
  1033. X
  1034. X  if (size < l->size) {
  1035. X    if (l->size - size < JMSZ + 4) return loc;
  1036. X    newl = (Jmalloc) (loc + size + PTSZ);
  1037. X    newl->flink = l->flink;
  1038. X    newl->blink = l;
  1039. X    newl->flink->blink = newl;
  1040. X    newl->blink->flink = newl;
  1041. X    newl->nextfree = start->nextfree;
  1042. X    newl->prevfree = start;
  1043. X    newl->nextfree->prevfree = newl;
  1044. X    newl->prevfree->nextfree = newl;
  1045. X    newl->size = l->size - size - JMSZ;
  1046. X    newl->cs = cksum(newl);
  1047. X    newl->cs2 = (int *) (jloc(newl) + newl->size);
  1048. X    *(newl->cs2) = cksum(newl);
  1049. X    used_mem += size - l->size;
  1050. X    free_mem += newl->size;
  1051. X    free_blocks++;
  1052. X    l->size = size;
  1053. X    l->cs2 = ((int *) (jloc(l) + l->size));
  1054. X    *(l->cs2) = cksum(l);
  1055. X    start = newl;
  1056. X    return loc;
  1057. X  }
  1058. X
  1059. X
  1060. X  nl = l->flink;
  1061. X
  1062. X  if (isfree(nl) && (jloc(l)+l->size + PTSZ == (char *) nl) &&
  1063. X      l->size + JMSZ + nl->size >= size) {
  1064. X    start = nl;
  1065. X    i = size - l->size - JMSZ;
  1066. X    if (i < 0) i = 4;
  1067. X    loc2 = malloc(i);
  1068. X    l2 = jmal(loc2);
  1069. X    if (l2 != nl) {
  1070. X      fprintf(stderr, "Realloc internal error: l2 != nl\n");
  1071. X      dump_core();
  1072. X    }
  1073. X
  1074. X    nl->flink->blink = nl->blink;
  1075. X    nl->blink->flink = nl->flink;
  1076. X    free_mem -= nl->size;
  1077. X    used_mem += nl->size + JMSZ;
  1078. X    free_blocks--;
  1079. X    l->size += nl->size + JMSZ;
  1080. X    l->cs2 = ((int *) (jloc(l) + l->size));
  1081. X    *(l->cs2) = cksum(l);
  1082. X    return loc;
  1083. X  } else {
  1084. X    loc2 = malloc(size);
  1085. X    for (i = 0; i < l->size; i++) loc2[i] = loc[i];
  1086. X    free(loc);
  1087. X    return loc2;
  1088. X  }
  1089. X}
  1090. X
  1091. Xchar *calloc(nelem, elsize)
  1092. Xint nelem, elsize;
  1093. X{
  1094. X  int *iptr;
  1095. X  char *ptr;
  1096. X  int sz;
  1097. X  int i;
  1098. X
  1099. X  sz = nelem*elsize;
  1100. X  ptr = malloc(sz);
  1101. X  iptr = (int *) ptr;
  1102. X  
  1103. X  for (i = 0; i < sz/sizeof(int); i++) iptr[i] = 0;
  1104. X  for (i = i * sizeof(int); i < sz; i++) ptr[i] = 0;
  1105. X  return ptr;
  1106. X}
  1107. X
  1108. Xint mallopt(cmd, value)
  1109. Xint cmd, value;
  1110. X{
  1111. X  fprintf(stderr, "Mallopt is not defined...\n");
  1112. X  exit(1);
  1113. X}
  1114. X
  1115. X
  1116. Xjmalloc_usage()
  1117. X{
  1118. X  fprintf(stderr, "Jmalloc: %d %s %d block%s. %d %s %d block%s\n",
  1119. X                    used_mem, "bytes used in", used_blocks, 
  1120. X                    (used_blocks == 1) ? "" : "s", 
  1121. X                    free_mem, "bytes free in", free_blocks,
  1122. X                    (free_blocks == 1) ? "" : "s");
  1123. X}
  1124. END_OF_FILE
  1125.   if test 11525 -ne `wc -c <'jmalloc.c'`; then
  1126.     echo shar: \"'jmalloc.c'\" unpacked with wrong size!
  1127.   fi
  1128.   # end of 'jmalloc.c'
  1129. fi
  1130. if test -f 'printline.c' -a "${1}" != "-c" ; then 
  1131.   echo shar: Will not clobber existing file \"'printline.c'\"
  1132. else
  1133.   echo shar: Extracting \"'printline.c'\" \(6292 characters\)
  1134.   sed "s/^X//" >'printline.c' <<'END_OF_FILE'
  1135. X/* 
  1136. X * $Source: /n/fs/vd/jsp/src/jgraph/RCS/printline.c,v $
  1137. X * $Revision: 8.0 $
  1138. X * $Date: 92/07/03 14:16:05 $
  1139. X * $Author: jsp $
  1140. X */
  1141. X
  1142. X#include "jgraph.h"
  1143. X#include <stdio.h>
  1144. X
  1145. X#define LINEWIDTHFACTOR 0.700
  1146. X#define MAX(a, b) ((a > b) ? (a) : (b))
  1147. X
  1148. Xtypedef struct fontlist {
  1149. X  struct fontlist *flink;
  1150. X  struct fontlist *blink;
  1151. X  int level;
  1152. X  float s;
  1153. X  char *f;
  1154. X} *Fontlist;
  1155. X
  1156. Xstatic Fontlist Jgraph_fonts;
  1157. Xstatic int Jgraph_gsave_level = -100;
  1158. Xstatic int Jgraph_comment;
  1159. X
  1160. Xgsave()
  1161. X{
  1162. X  if (Jgraph_gsave_level == -100) {
  1163. X    Jgraph_gsave_level = 0;
  1164. X    Jgraph_fonts = (Fontlist) make_list(sizeof(struct fontlist));
  1165. X  } 
  1166. X  Jgraph_gsave_level++;
  1167. X  printf(" gsave ");
  1168. X}
  1169. X
  1170. Xgrestore()
  1171. X{
  1172. X  Fontlist l;
  1173. X
  1174. X  if (last(Jgraph_fonts) != nil(Jgraph_fonts)) {
  1175. X    l = last(Jgraph_fonts);
  1176. X    if (l->level == Jgraph_gsave_level) {
  1177. X      delete_item(l);
  1178. X      free_node(l, Jgraph_fonts);
  1179. X    }
  1180. X  }
  1181. X  Jgraph_gsave_level--;
  1182. X  printf(" grestore ");
  1183. X}
  1184. X
  1185. Xsetfont(f, s)
  1186. Xchar *f;
  1187. Xfloat s;
  1188. X{
  1189. X  Fontlist l;
  1190. X  int ins;
  1191. X
  1192. X  if (last(Jgraph_fonts) != nil(Jgraph_fonts)) {
  1193. X    l = last(Jgraph_fonts);
  1194. X    ins = (strcmp(l->f, f) != 0 || s != l->s);
  1195. X    if (ins) {
  1196. X      delete_item(l);
  1197. X      free_node(l, Jgraph_fonts);
  1198. X    }
  1199. X  } else {
  1200. X    ins = 1;
  1201. X  }
  1202. X  if (ins) {
  1203. X    l = (Fontlist) get_node(Jgraph_fonts);
  1204. X    l->level = Jgraph_gsave_level;
  1205. X    l->s = s;
  1206. X    l->f = f;
  1207. X    insert(l, Jgraph_fonts);
  1208. X    printf("/%s findfont %f scalefont setfont\n", f, s);
  1209. X  }
  1210. X}
  1211. X  
  1212. Xsetfill( t, f)
  1213. Xchar t ;
  1214. Xfloat f[] ;
  1215. X{
  1216. X    if ( t == 'g' )  {
  1217. X       if( f[0] >= 0.0 ) printf("gsave %f setgray fill grestore ", f[0] );
  1218. X    } else if ( t == 'c' )  {
  1219. X       printf("gsave %f %f %f setrgbcolor fill grestore ", f[0], f[1], f[2] );
  1220. X    } else {
  1221. X       printf("fill ");
  1222. X    }
  1223. X}
  1224. X
  1225. Xsetgray( t, f)
  1226. Xchar t ;
  1227. Xfloat f[] ;
  1228. X{
  1229. X    if ( t == 'g' )  {
  1230. X       if( f[0] >= 0.0 ) printf("%f setgray\n", f[0] );
  1231. X    } else if ( t == 'c' )  {
  1232. X       printf("%f %f %f setrgbcolor\n", f[0], f[1], f[2] );
  1233. X    }
  1234. X}
  1235. X
  1236. Xprintline(x1, y1,x2, y2, orientation)
  1237. Xfloat x1, y1, x2, y2;
  1238. Xchar orientation;
  1239. X{
  1240. X  if (orientation == 'x') 
  1241. X    printf("newpath %f %f moveto %f %f lineto stroke\n",
  1242. X          x1, y1, x2, y2);
  1243. X  else
  1244. X    printf("newpath %f %f moveto %f %f lineto stroke\n",
  1245. X          y1, x1, y2, x2);
  1246. X} 
  1247. X
  1248. Xprint_ebar(x1, y1, x2, ms, orientation)
  1249. Xfloat x1, y1, x2, ms;
  1250. Xchar orientation;
  1251. X{
  1252. X  printline(x1, y1, x2, y1, orientation);
  1253. X  printline(x2, y1-ms, x2, y1+ms, orientation);
  1254. X}
  1255. X
  1256. Xstart_line(x1, y1, c)
  1257. Xfloat x1, y1;
  1258. XCurve c;
  1259. X{
  1260. X  setlinewidth(c->linethick);
  1261. X  setlinestyle(c->linetype, c->gen_linetype);
  1262. X  printf("%f %f moveto ", x1, y1);
  1263. X}
  1264. X
  1265. Xcont_line(x1, y1)
  1266. Xfloat x1, y1;
  1267. X{
  1268. X  printf("  %f %f lineto\n", x1, y1);
  1269. X}
  1270. X
  1271. Xend_line()
  1272. X{
  1273. X  printf("stroke\n");
  1274. X  setlinewidth(1.0);
  1275. X  setlinestyle('s', (Flist) 0);
  1276. X
  1277. X}
  1278. X
  1279. Xbezier_control(x1, y1)
  1280. Xfloat x1, y1;
  1281. X{
  1282. X  printf("  %f %f ", x1, y1);
  1283. X}
  1284. X
  1285. Xbezier_end(x1, y1)
  1286. Xfloat x1, y1;
  1287. X{
  1288. X  printf("  %f %f curveto\n", x1, y1);
  1289. X}
  1290. X
  1291. X
  1292. Xstart_poly(x1, y1)
  1293. Xfloat x1, y1;
  1294. X{
  1295. X  printf("newpath %f %f moveto ", x1, y1);
  1296. X}
  1297. X
  1298. Xcont_poly(x1, y1)
  1299. Xfloat x1, y1;
  1300. X{
  1301. X  printf("  %f %f lineto\n", x1, y1);
  1302. X}
  1303. X
  1304. Xend_poly(ftype, fill)
  1305. Xchar  ftype ;
  1306. Xfloat fill[];
  1307. X{
  1308. X  printf("closepath ");
  1309. X  setfill( ftype, fill );
  1310. X  printf("stroke\n");
  1311. X}
  1312. X
  1313. Xprintellipse(x, y, radius1, radius2, ftype, fill)
  1314. Xchar ftype ;
  1315. Xfloat x, y, radius1, radius2, fill[];
  1316. X{
  1317. X  printf("newpath %f %f %f %f 0 360 DrawEllipse ", x, y, radius1, radius2);
  1318. X  setfill( ftype, fill );
  1319. X  printf("stroke\n");
  1320. X}
  1321. X
  1322. Xset_comment(c)
  1323. Xint c;
  1324. X{
  1325. X  Jgraph_comment = c;
  1326. X}
  1327. X
  1328. Xcomment(s)
  1329. Xchar *s;
  1330. X{
  1331. X  if (Jgraph_comment) printf("%% %s\n", s);
  1332. X}
  1333. X
  1334. Xprintline_c(x1, y1, x2, y2, g)
  1335. Xfloat x1, y1, x2, y2;
  1336. XGraph g;
  1337. X{
  1338. X  printline(ctop(x1, g->x_axis), ctop(y1, g->y_axis),
  1339. X            ctop(x2, g->x_axis), ctop(y2, g->y_axis), 'x');
  1340. X}
  1341. X
  1342. Xprint_label(l)
  1343. XLabel l;
  1344. X{
  1345. X  int f, i, nlines;
  1346. X  float fnl;
  1347. X  char *s;
  1348. X
  1349. X  if (l->label == CNULL) return;
  1350. X
  1351. X  nlines = 0;
  1352. X  for (i = 0; l->label[i] != '\0'; i++) {
  1353. X    if (l->label[i] == '\n') {
  1354. X      l->label[i] = '\0';
  1355. X      nlines++;
  1356. X    }
  1357. X  }
  1358. X  fnl = (float) nlines;
  1359. X
  1360. X  setfont(l->font, l->fontsize);
  1361. X  printf("gsave %f %f translate %f rotate\n", l->x, l->y, l->rotate);
  1362. X  if (l->graytype == 'g') {
  1363. X    printf("  %f setgray\n", l->gray[0]);
  1364. X  } else if (l->graytype == 'c') {
  1365. X    printf("  %f %f %f setrgbcolor\n", l->gray[0], l->gray[1], 
  1366. X           l->gray[2]);
  1367. X  }
  1368. X
  1369. X  if (l->vj == 'b') {
  1370. X    printf("0 %f translate ", fnl * (l->fontsize + l->linesep) * FCPI / FPPI);
  1371. X  } else if (l->vj == 'c') {
  1372. X    if (nlines % 2 == 0) {
  1373. X      printf("0 %f translate ", 
  1374. X             (fnl/2.0*(l->fontsize + l->linesep) - l->fontsize/2.0)
  1375. X              * FCPI / FPPI);
  1376. X    } else {
  1377. X      printf("0 %f translate ", 
  1378. X             ((fnl-1.0)/2.0*(l->fontsize + l->linesep) + l->linesep/2.0)
  1379. X              * FCPI / FPPI);
  1380. X    }
  1381. X  } else {
  1382. X    printf("0 %f translate ", -l->fontsize * FCPI / FPPI);
  1383. X  }
  1384. X
  1385. X  s = l->label;
  1386. X  for (i = 0; i <= nlines; i++) {
  1387. X    printf("(%s) dup stringwidth pop ", s);
  1388. X    if (l->hj == 'c') {
  1389. X      printf("2 div neg 0 moveto\n");
  1390. X    } else if (l->hj == 'r') {
  1391. X      printf("neg 0 moveto\n");
  1392. X    } else {
  1393. X      printf("pop 0 0 moveto\n");
  1394. X    }
  1395. X    /* I would put string blanking in here if I had the time... */
  1396. X    if (i != nlines) {
  1397. X      f = strlen(s);
  1398. X      s[f] = '\n';
  1399. X      s = &(s[f+1]);
  1400. X      printf("show 0 %f translate\n", 
  1401. X              - (l->fontsize + l->linesep) * FCPI / FPPI);
  1402. X    } else {
  1403. X      printf("show\n");
  1404. X    }
  1405. X  }
  1406. X  printf("grestore\n");
  1407. X}
  1408. X
  1409. Xsetlinewidth(size)
  1410. Xfloat size;
  1411. X{
  1412. X  printf("%f setlinewidth\n", size * LINEWIDTHFACTOR);
  1413. X}
  1414. X
  1415. Xsetlinestyle(style, glist)
  1416. Xchar style;
  1417. XFlist glist;
  1418. X{
  1419. X  Flist fl;
  1420. X
  1421. X  switch(style) {
  1422. X    case '0': printf("\t[0 2] setdash\n"); break;
  1423. X    case 's': printf("\t[] 0 setdash\n"); break;
  1424. X    case '.': printf("\t [1 3.200000] 0 setdash\n"); break;
  1425. X    case '-': printf("\t [4.00000] 0 setdash\n"); break;
  1426. X    case 'l': printf("\t [7 2] 0 setdash\n"); break;
  1427. X    case 'd': printf("\t [5 3 1 3] 0 setdash\n"); break;
  1428. X    case 'D': printf("\t [5 3 1 2 1 3] 0 setdash\n"); break;
  1429. X    case '2': printf("\t [5 3 5 3 1 2 1 3] 0 setdash\n"); break;
  1430. X    case 'g': 
  1431. X      printf("\t [");
  1432. X      for (fl = first(glist); fl != nil(glist); fl = next(fl))
  1433. X        printf("%f ", fl->f);
  1434. X      printf("] 0 setdash\n");
  1435. X      break;
  1436. X    default: fprintf(stderr, "Error: Unknown line type: %c\n", style);
  1437. X             exit(1);
  1438. X             break;
  1439. X  }
  1440. X}
  1441. X
  1442. END_OF_FILE
  1443.   if test 6292 -ne `wc -c <'printline.c'`; then
  1444.     echo shar: \"'printline.c'\" unpacked with wrong size!
  1445.   fi
  1446.   # end of 'printline.c'
  1447. fi
  1448. if test -f 'show.c' -a "${1}" != "-c" ; then 
  1449.   echo shar: Will not clobber existing file \"'show.c'\"
  1450. else
  1451.   echo shar: Extracting \"'show.c'\" \(11318 characters\)
  1452.   sed "s/^X//" >'show.c' <<'END_OF_FILE'
  1453. X/* 
  1454. X * $Source: /n/fs/vd/jsp/src/jgraph/RCS/show.c,v $
  1455. X * $Revision: 8.0 $
  1456. X * $Date: 92/07/03 14:16:15 $
  1457. X * $Author: jsp $
  1458. X */ 
  1459. X
  1460. X#include <stdio.h>
  1461. X#include <math.h>
  1462. X#include "jgraph.h"
  1463. X
  1464. Xstatic spaces(nsp)
  1465. Xint nsp;
  1466. X{
  1467. X  while(nsp-- > 0) putchar(' ');
  1468. X}
  1469. X
  1470. Xfloat ptoin(p)
  1471. Xfloat p;
  1472. X{
  1473. X  return p / FCPI;
  1474. X}
  1475. X
  1476. Xfloat ptoc(p, a)
  1477. Xfloat p;
  1478. XAxis a;
  1479. X{
  1480. X  if (a->is_lg) {
  1481. X    return (float) exp((p / a->factor + a->logmin) * a->logfactor);
  1482. X  } else {
  1483. X    return (p / a->factor) + a->min;
  1484. X  }
  1485. X}
  1486. X
  1487. Xfloat ptodist(p, a)
  1488. Xfloat p;
  1489. XAxis a;
  1490. X{
  1491. X  if (a->is_lg) {
  1492. X    return p  / FCPI;
  1493. X  } else {
  1494. X    return (p / a->factor);
  1495. X  }
  1496. X}
  1497. X
  1498. Xstatic show_mltiline(s)
  1499. Xchar *s;
  1500. X{
  1501. X  int i;
  1502. X
  1503. X  if (s != CNULL) {
  1504. X    for (i = 0; s[i] != '\0'; i++) {
  1505. X      if (s[i] == '\n') putchar('\\');
  1506. X      putchar(s[i]);
  1507. X    }
  1508. X  }
  1509. X  putchar('\n');
  1510. X}
  1511. X
  1512. Xshow_string(s)
  1513. Xchar *s;
  1514. X{
  1515. X  int i;
  1516. X
  1517. X  if (s != CNULL) {
  1518. X    printf(": ");
  1519. X    for (i = 0; s[i] != '\0'; i++) {
  1520. X      if (s[i] == '\n') putchar('\\');
  1521. X      if (s[i] == '\\') i++;
  1522. X      putchar(s[i]);
  1523. X    }
  1524. X  }
  1525. X  putchar('\n');
  1526. X}
  1527. X    
  1528. X   
  1529. Xshow_label(l, nsp, g)
  1530. XLabel l;
  1531. Xint nsp;
  1532. XGraph g;
  1533. X{
  1534. X  spaces(nsp); 
  1535. X  show_string(l->label);
  1536. X  spaces(nsp); printf("x %f ", ptoc(l->x, g->x_axis));
  1537. X               printf("y %f\n", ptoc(l->y, g->y_axis));
  1538. X  spaces(nsp); printf("hj%c vj%c ", l->hj, l->vj);
  1539. X               printf("rotate %f\n", l->rotate);
  1540. X  spaces(nsp); printf("font %s ", l->font);
  1541. X               printf("fontsize %f ", l->fontsize);
  1542. X           printf("linesep %f\n", l->linesep);
  1543. X  if (l->graytype == 'g') {
  1544. X    spaces(nsp);
  1545. X    printf("lgray %f\n", l->gray[0]);
  1546. X  } else if (l->graytype == 'c') {
  1547. X    spaces(nsp);
  1548. X    printf("lcolor %f %f %f\n", l->gray[0], l->gray[1], l->gray[2]);
  1549. X  }
  1550. X  return;
  1551. X}
  1552. X
  1553. Xshow_lmark(l, nsp, g)
  1554. XLabel l;
  1555. Xint nsp;
  1556. XGraph g;
  1557. X{
  1558. X  spaces(nsp); show_string(l->label);
  1559. X  spaces(nsp); printf("x %f ", ptodist(l->x, g->x_axis));
  1560. X               printf("y %f\n", ptodist(l->y, g->y_axis));
  1561. X  spaces(nsp); printf("hj%c vj%c ", l->hj, l->vj);
  1562. X               printf("rotate %f\n", l->rotate);
  1563. X  spaces(nsp); printf("font %s ", l->font);
  1564. X               printf("fontsize %f\n", l->fontsize);
  1565. X  return;
  1566. X}
  1567. X
  1568. Xshow_curve(c, nsp, g)
  1569. XCurve c;
  1570. Xint nsp;
  1571. XGraph g;
  1572. X{
  1573. X  Point p;
  1574. X  Point px;
  1575. X  Point py;
  1576. X  int i;
  1577. X  Flist fl;
  1578. X
  1579. X  if (c->l->label != CNULL) {
  1580. X    spaces(nsp); printf("label\n");
  1581. X    spaces(nsp+2);
  1582. X    printf("(* unless <legend custom>, this label\'s x\'s and y\'s will be ignored *)\n");
  1583. X    show_label(c->l, nsp+2, g);
  1584. X  }
  1585. X  
  1586. X  px = first(c->xepts);
  1587. X  py = first(c->yepts);
  1588. X  for(p = first(c->pts); p != nil(c->pts); p = next(p)) {
  1589. X    if (p->e == 'p') {
  1590. X      spaces(nsp); printf("pts %f %f\n", p->x, p->y);
  1591. X    } else if (p->e == 'x') {
  1592. X      spaces(nsp); 
  1593. X      printf("x_epts %f %f %f %f\n", p->x, p->y, px->x, next(px)->x);
  1594. X      px = next(next(px));
  1595. X    } else if (p->e == 'y') {
  1596. X      spaces(nsp); 
  1597. X      printf("y_epts %f %f %f %f\n", p->y, p->y, py->y, next(py)->y);
  1598. X      py = next(next(py));
  1599. X    } else {
  1600. X      fprintf(stderr, "Internal error: p->e == %c\n", p->e);
  1601. X      exit(1);
  1602. X    }
  1603. X  }
  1604. X  if (c->postscript != CNULL) {
  1605. X    spaces(nsp);
  1606. X    printf("postscript ");
  1607. X    if (!c->postfile) printf(": ");
  1608. X    show_mltiline(c->postscript);
  1609. X  }
  1610. X  spaces(nsp); printf("marktype ");
  1611. X  for (i = 0; i < NMARKTYPES && c->marktype != MARKTYPES[i]; i++) ;
  1612. X  if (i == NMARKTYPES) {
  1613. X    error_header();
  1614. X    fprintf(stderr, "Unknown mark type %c\n", c->marktype);
  1615. X    exit(1);
  1616. X  } else printf("%s ", MARKTYPESTRS[i]);
  1617. X  if (c->marktype == 'l') {
  1618. X    show_lmark(c->lmark, nsp+2, g);
  1619. X    spaces(nsp);
  1620. X  }
  1621. X  printf("marksize %f %f ", ptodist(c->marksize[0], g->x_axis), 
  1622. X                            ptodist(c->marksize[1], g->y_axis));
  1623. X  printf("mrotate %f ", c->mrotate);
  1624. X  if (c->filltype == 'g') {
  1625. X     printf("fill %f\n", c->fill[0] );
  1626. X  } else if (c->filltype == 'c')  {
  1627. X     printf("cfill %f %f %f\n", c->fill[0], c->fill[1], c->fill[2] );
  1628. X  }
  1629. X  if (first(c->general_marks) != c->general_marks) {
  1630. X    spaces(nsp); printf("gmarks");
  1631. X    for(p = first(c->general_marks); p != nil(c->general_marks); p = next(p))
  1632. X      printf(" %f %f ", p->x, p->y);
  1633. X  }
  1634. X  printf("\n");
  1635. X  spaces(nsp);
  1636. X  if(!c->poly) printf("no"); printf("poly ");
  1637. X  if (c->pfilltype == 'g') {
  1638. X     printf("pfill %f", c->pfill[0] );
  1639. X  } else if (c->pfilltype == 'c')  {
  1640. X     printf("pcfill %f %f %f", c->pfill[0], c->pfill[1], c->pfill[2] );
  1641. X  }
  1642. X  printf("\n");
  1643. X  
  1644. X  spaces(nsp); printf("linetype ");
  1645. X  if (c->linetype == '0')  printf("none ");
  1646. X  else if (c->linetype == 's') printf("solid ");
  1647. X  else if (c->linetype == '.') printf("dotted ");
  1648. X  else if (c->linetype == '-') printf("dashed ");
  1649. X  else if (c->linetype == 'l') printf("longdash ");
  1650. X  else if (c->linetype == 'd') printf("dotdash ");
  1651. X  else if (c->linetype == 'D') printf("dotdotdash ");
  1652. X  else if (c->linetype == '2') printf("dotdotdashdash ");
  1653. X  else if (c->linetype == 'g') {
  1654. X    printf("general\n");
  1655. X    spaces(nsp+2);
  1656. X    printf("glines "); 
  1657. X    i = 0;
  1658. X    for (fl = first(c->gen_linetype); fl != nil(c->gen_linetype); 
  1659. X                                      fl = next(fl)) {
  1660. X      if (i == 6) {
  1661. X        printf("\n");
  1662. X        spaces(nsp + 9);
  1663. X        i = 0;
  1664. X      }
  1665. X      printf("%f ", fl->f);
  1666. X      i++;
  1667. X    }
  1668. X    printf("\n");
  1669. X    spaces(nsp);
  1670. X  }
  1671. X  printf("linethickness %f\n", c->linethick);
  1672. X  spaces(nsp); 
  1673. X  if (c->graytype == 'g') {
  1674. X    printf("gray %f ", c->gray[0]);
  1675. X  } else if (c->graytype == 'c') {
  1676. X    printf("color %f %f %f ", c->gray[0], c->gray[1], c->gray[2]);
  1677. X  }
  1678. X  if(!c->clip) printf("no"); printf("clip\n");
  1679. X  spaces(nsp); 
  1680. X  if(!c->rarrow) printf("no"); printf("rarrow ");
  1681. X  if(!c->larrow) printf("no"); printf("larrow ");
  1682. X  if(!c->rarrows) printf("no"); printf("rarrows ");
  1683. X  if(!c->larrows) printf("no"); printf("larrows ");
  1684. X  if (c->afilltype == 'g') {
  1685. X     printf("afill %f\n", c->afill[0] );
  1686. X  } else if (c->afilltype == 'c')  {
  1687. X     printf("acfill %f %f %f\n", c->afill[0], c->afill[1], c->afill[2] );
  1688. X  }
  1689. X  spaces(nsp);
  1690. X  if(!c->bezier) printf("no"); printf("bezier ");
  1691. X  printf("asize %f %f\n", ptodist(c->asize[0], g->x_axis), 
  1692. X                          ptodist(c->asize[1], g->y_axis) * 2.0);
  1693. X}
  1694. X
  1695. Xshow_axis(a, nsp, g)
  1696. XAxis a;
  1697. Xint nsp;
  1698. XGraph g;
  1699. X{
  1700. X  Axis other;
  1701. X  Hash h;
  1702. X  String s;
  1703. X
  1704. X  if (a->is_x) other = g->y_axis; else other = g->x_axis;
  1705. X  spaces(nsp); printf("size %f\n", a->size);
  1706. X  spaces(nsp); printf("min %f max %f %s\n", a->min, a->max,
  1707. X                      (a->is_lg) ? "log" : "linear");
  1708. X  if (!(a->draw_hash_labels || a->draw_axis_line ||
  1709. X        a->draw_hash_marks || a->draw_axis_label)) {
  1710. X    spaces(nsp);
  1711. X    printf("nodraw\n");
  1712. X    return;
  1713. X  }
  1714. X  spaces(nsp); printf("draw_at %f\n", ptoc(a->draw_at, other));
  1715. X  if (a->label->label != CNULL) {
  1716. X    spaces(nsp); printf("label\n");
  1717. X    show_label(a->label, nsp+2, g);
  1718. X  }
  1719. X  spaces(nsp); 
  1720. X  printf("%sdraw_hash_labels\n", (a->draw_hash_labels) ? "" : "no_");
  1721. X  spaces(nsp); 
  1722. X  printf("%sdraw_axis_line\n", (a->draw_axis_line) ? "" : "no_");
  1723. X  spaces(nsp); 
  1724. X  printf("%sdraw_hash_marks\n", (a->draw_hash_marks) ? "" : "no_");
  1725. X  spaces(nsp); 
  1726. X  printf("%sgrid_lines\n", (a->grid_lines) ? "" : "no_");
  1727. X  spaces(nsp); 
  1728. X  printf("%smgrid_lines\n", (a->mgrid_lines) ? "" : "no_");
  1729. X  spaces(nsp); 
  1730. X  printf("%sdraw_axis_label\n", (a->draw_axis_label) ? "" : "no_");
  1731. X  spaces(nsp); 
  1732. X  if (a->graytype == 'g') {
  1733. X    printf("gray %f\n", a->gray[0]);
  1734. X  } else if (a->graytype == 'c') {
  1735. X    printf("color %f %f %f\n", a->gray[0], a->gray[1], a->gray[2]);
  1736. X  }
  1737. X  spaces(nsp); 
  1738. X  if (a->gr_graytype == 'g') {
  1739. X    printf("gr_gray %f ", a->gr_gray[0]);
  1740. X  } else if (a->gr_graytype == 'c') {
  1741. X    printf("color %f %f %f ", a->gr_gray[0], a->gr_gray[1], a->gr_gray[2]);
  1742. X  }
  1743. X  if (a->mgr_graytype == 'g') {
  1744. X    printf("mgr_gray %f\n", a->mgr_gray[0]);
  1745. X  } else if (a->mgr_graytype == 'c') {
  1746. X    printf("color %f %f %f\n", a->mgr_gray[0], a->mgr_gray[1], a->mgr_gray[2]);
  1747. X  }
  1748. X
  1749. X  spaces(nsp);
  1750. X
  1751. X  printf("(* The real settings for generating auto_hash_labels:\n");
  1752. X  spaces(nsp+5);
  1753. X  printf("%sauto_hash_marks ", (a->auto_hash_marks) ? "" : "no_");
  1754. X  printf("%sauto_hash_labels\n", (a->auto_hash_labels) ? "" : "no_");
  1755. X  spaces(nsp+5); printf("hash %f shash %f mhash %d\n", a->hash_interval, 
  1756. X                       a->hash_start, a->minor_hashes);
  1757. X  spaces(nsp+5);
  1758. X  if (a->is_lg) {
  1759. X    printf("log_base %f ", a->log_base);
  1760. X  }
  1761. X  printf("hash_scale %f ", a->hash_scale);
  1762. X  printf("precision %d\n", a->precision);
  1763. X  spaces(nsp+3);
  1764. X  printf("The following are explicit and implicit hash marks and labels *)\n");
  1765. X  
  1766. X  spaces(nsp); 
  1767. X  printf("hash 0 draw_hash_marks_at %f draw_hash_labels_at %f\n",
  1768. X         ptoc(a->draw_hash_marks_at, other), 
  1769. X         ptoc(a->draw_hash_labels_at, other));
  1770. X  spaces(nsp); printf("hash_labels (* The :, x, and y values are ignored *)\n");
  1771. X  show_label(a->hl, nsp + 2, g);
  1772. X  
  1773. X  for (h = first(a->hash_lines); h != nil(a->hash_lines); h = next(h)) {
  1774. X    spaces(nsp);
  1775. X    printf("%s %f\n", ((h->size == HASH_SIZE) ? "hash_at" : "mhash_at"),
  1776. X           ptoc(h->loc, a));
  1777. X  }
  1778. X  for (s = first(a->hash_labels); s != nil(a->hash_labels); s = next(s)) {
  1779. X    spaces(nsp);
  1780. X    printf("hash_label at %f ", ptoc(s->s->x, a));
  1781. X    show_string(s->s->label);
  1782. X  }
  1783. X}
  1784. X
  1785. Xshow_legend(l, nsp, g)
  1786. XLegend l;
  1787. Xint nsp;
  1788. XGraph g;
  1789. X{
  1790. X  if (l->type == 'c') {
  1791. X    spaces(nsp); printf("custom\n");
  1792. X  } else if (l->type == 'n') {
  1793. X    spaces(nsp); printf("off\n");
  1794. X  }
  1795. X
  1796. X  spaces(nsp); printf("linelength %f linebreak %f midspace %f\n",
  1797. X     ptodist(l->linelength, g->x_axis), ptodist(l->linebreak, g->y_axis),
  1798. X     ptodist(l->midspace, g->x_axis));
  1799. X  if (l->type == 'u') {
  1800. X    spaces(nsp); printf("defaults");
  1801. X    show_label(l->l, nsp+2, g);
  1802. X  }
  1803. X}
  1804. X
  1805. Xshow_graph(g, nsp)
  1806. XGraph g;
  1807. Xint nsp;
  1808. X{
  1809. X
  1810. X  Curve c;
  1811. X  String s;    
  1812. X  spaces(nsp); printf("x_translate %f y_translate %f\n", 
  1813. X                       ptoin(g->x_translate), ptoin(g->y_translate));
  1814. X  spaces(nsp); printf("xaxis\n"); show_axis(g->x_axis, nsp+2, g);
  1815. X  spaces(nsp); printf("yaxis\n"); show_axis(g->y_axis, nsp+2, g);
  1816. X  spaces(nsp); if(!g->clip) printf("no"); printf("clip ");
  1817. X               if(!g->border) printf("no"); printf("border\n");
  1818. X  for (c = first(g->curves); c != nil(g->curves); c = next(c)) {
  1819. X    spaces(nsp);
  1820. X    printf("curve %d\n", c->num);
  1821. X    show_curve(c, nsp+2, g);
  1822. X  }
  1823. X  spaces(nsp); printf("legend\n");
  1824. X  show_legend(g->legend, nsp+2, g);
  1825. X  if (g->title->label != CNULL) {
  1826. X    spaces(nsp);
  1827. X    printf("title\n");
  1828. X    show_label(g->title, nsp+2, g);
  1829. X  }
  1830. X  for (s = first(g->strings); s != nil(g->strings); s = next(s)) {
  1831. X    spaces(nsp);
  1832. X    printf("string %d\n", s->num);
  1833. X    show_label(s->s, nsp+2, g);
  1834. X  }
  1835. X}
  1836. X
  1837. Xshow_graphs(gs)
  1838. XGraphs gs;
  1839. X{
  1840. X  Graphs the_g;
  1841. X  Graph g;
  1842. X  char started;
  1843. X  int i;
  1844. X
  1845. X  started = 0;
  1846. X  for (the_g = first(gs); the_g != nil(gs); the_g = next(the_g)) {
  1847. X    if (started) printf("\nnewpage\n");
  1848. X    started = 1;
  1849. X    printf("X %f Y %f\n", ptoin(the_g->width), ptoin(the_g->height));
  1850. X    if (the_g->preamble != CNULL) {
  1851. X      printf("preamble ");
  1852. X      if (!the_g->prefile) printf(": ");
  1853. X      show_mltiline(the_g->preamble);
  1854. X    }
  1855. X    if (the_g->epilogue != CNULL) {
  1856. X      printf("epilogue ");
  1857. X      if (!the_g->epifile) printf(": ");
  1858. X      show_mltiline(the_g->epilogue);
  1859. X    }
  1860. X    printf("bbox"); 
  1861. X    for (i = 0; i < 4; i++) printf(" %f", the_g->bb[i]);
  1862. X    printf("\n");
  1863. X    for (g = first(the_g->g); g != nil(the_g->g); g = next(g)) {
  1864. X      printf("graph %d\n", g->num);
  1865. X      show_graph(g, 2);
  1866. X    }
  1867. X  }
  1868. X}
  1869. X
  1870. X
  1871. END_OF_FILE
  1872.   if test 11318 -ne `wc -c <'show.c'`; then
  1873.     echo shar: \"'show.c'\" unpacked with wrong size!
  1874.   fi
  1875.   # end of 'show.c'
  1876. fi
  1877. if test -f 'token.c' -a "${1}" != "-c" ; then 
  1878.   echo shar: Will not clobber existing file \"'token.c'\"
  1879. else
  1880.   echo shar: Extracting \"'token.c'\" \(7542 characters\)
  1881.   sed "s/^X//" >'token.c' <<'END_OF_FILE'
  1882. X/* 
  1883. X * $Source: /n/fs/vd/jsp/src/jgraph/RCS/token.c,v $
  1884. X * $Revision: 8.0 $
  1885. X * $Date: 92/07/03 14:16:17 $
  1886. X * $Author: jsp $
  1887. X */
  1888. X
  1889. X#include <math.h>
  1890. X#ifdef LCC
  1891. X#include <stdlib.h>
  1892. X#endif
  1893. X/* On VMS, math.h does not have a definition for atof. Grrr. */
  1894. X#ifdef VMS 
  1895. X#include <stdlib.h>
  1896. X#endif
  1897. X#include <stdio.h>
  1898. X
  1899. X#include "list.h"
  1900. X
  1901. X#define CNULL ((char *)0)
  1902. X
  1903. Xtypedef struct iostack {
  1904. X  struct iostack *flink;
  1905. X  struct iostack *blink;
  1906. X  char *filename;
  1907. X  FILE *stream;
  1908. X  int oldcharvalid;
  1909. X  char oldchar;
  1910. X  char pipe;
  1911. X  int line;
  1912. X} *Iostack;
  1913. X
  1914. Xstatic char INPUT[1000];
  1915. Xstatic int getnew = 1;
  1916. Xstatic char oldchar = '\0';
  1917. Xstatic oldcharvalid = 0;
  1918. Xstatic char pipe = 0;
  1919. Xstatic int eof = 0;
  1920. Xstatic int init = 0;
  1921. Xstatic Iostack stack;
  1922. Xstatic char real_eof = EOF;
  1923. X
  1924. X#ifndef VMS 
  1925. Xstatic FILE *IOSTREAM = stdin;
  1926. X#else
  1927. XFILE *IOSTREAM; /* VMS cannot initialize streams, init in jgraph.c -hdd */
  1928. X#endif
  1929. Xstatic char FILENAME[300];
  1930. Xstatic int line = 1;
  1931. X
  1932. X#define iostackinit() {\
  1933. X                        if (init == 0) {\
  1934. X                          strcpy(FILENAME, "<stdin>"); \
  1935. X                          stack = (Iostack) make_list(sizeof(struct iostack)); \
  1936. X                          init = 1; }}
  1937. X
  1938. X#ifdef VMS
  1939. X/* On VMS, there are no popen() and pclose(), so we provide dummies here. */
  1940. XFILE *popen(command, type)
  1941. Xchar *command, *type;
  1942. X{
  1943. X    return(NULL);
  1944. X}
  1945. Xint pclose(stream)
  1946. XFILE *stream;
  1947. X{
  1948. X    return(-1);
  1949. X}
  1950. X#endif /*VMS*/
  1951. X
  1952. Xerror_header()
  1953. X{
  1954. X  iostackinit();
  1955. X  fprintf(stderr, "%s,%d: ", FILENAME, line);
  1956. X}
  1957. X  
  1958. Xint gettokenchar()
  1959. X{
  1960. X  if (oldcharvalid == 0) oldchar = getc(IOSTREAM);
  1961. X  oldcharvalid = 0;
  1962. X  if (oldchar == '\n') line++;
  1963. X  return oldchar;
  1964. X}
  1965. X
  1966. Xungettokenchar()
  1967. X{
  1968. X  oldcharvalid = 1;
  1969. X  if (oldchar == '\n') line--;
  1970. X}
  1971. X
  1972. Xint gettoken(s)
  1973. Xchar *s;
  1974. X{
  1975. X  int i;
  1976. X  char c;
  1977. X
  1978. X  for (c = gettokenchar(); 
  1979. X       c == ' ' || c == '\t' || c == '\n';
  1980. X       c = gettokenchar()) ;
  1981. X  for (i = 0;
  1982. X       c != real_eof && c != ' ' && c != '\t' && c != '\n';
  1983. X       c = gettokenchar()) {
  1984. X    s[i++] = c;
  1985. X  }
  1986. X  s[i] = '\0';
  1987. X  ungettokenchar();
  1988. X  return i;
  1989. X}
  1990. X
  1991. Xget_comment()
  1992. X{
  1993. X  if (eof) return;
  1994. X  while (1) {
  1995. X    if (gettoken(INPUT) == 0) return;
  1996. X    else if (strcmp(INPUT, "(*") == 0)
  1997. X      get_comment();
  1998. X    else if (strcmp(INPUT, "*)") == 0) 
  1999. X      return;
  2000. X  }
  2001. X}
  2002. X
  2003. Xstatic int iostackempty()
  2004. X{
  2005. X  iostackinit();
  2006. X  return (first(stack) == nil(stack));
  2007. X}
  2008. X
  2009. Xstatic push_iostack(p)
  2010. Xint p;
  2011. X{
  2012. X  Iostack n;
  2013. X
  2014. X  iostackinit();
  2015. X  n = (Iostack) get_node(stack);
  2016. X  n->stream = IOSTREAM;
  2017. X  n->filename = (char *) malloc (sizeof(char)*(strlen(FILENAME)+2));
  2018. X  n->oldchar = oldchar;
  2019. X  n->oldcharvalid = oldcharvalid;
  2020. X  n->pipe = pipe;
  2021. X  n->line = line;
  2022. X  strcpy(n->filename, FILENAME);
  2023. X  insert(n, stack);
  2024. X  if (p) {
  2025. X    IOSTREAM = (FILE *) popen(INPUT, "r");
  2026. X  } else {
  2027. X    IOSTREAM = fopen(INPUT, "r");
  2028. X  }
  2029. X  pipe = p;
  2030. X  line = 1;
  2031. X  if (IOSTREAM == NULL) {
  2032. X    error_header();
  2033. X    fprintf(stderr, "Include file \"%s\" does not exist\n", INPUT);
  2034. X    exit(1);
  2035. X  }
  2036. X  strcpy(FILENAME, INPUT);
  2037. X}
  2038. X
  2039. Xstatic pop_iostack()
  2040. X{
  2041. X  Iostack n;
  2042. X
  2043. X/*  error_header();
  2044. X  fprintf(stderr, "\nCalled pop_io_stack.  Pipe = %d\n", pipe); */
  2045. X  fflush(IOSTREAM);
  2046. X  iostackinit();
  2047. X  if (pipe) {
  2048. X    if (pclose(IOSTREAM)) {
  2049. X      /*error_header();
  2050. X      fprintf(stderr, "\n\nPipe returned a non-zero error code.\n");
  2051. X      exit(1); */
  2052. X    }
  2053. X  } else {
  2054. X    fclose(IOSTREAM);
  2055. X  }
  2056. X  n = last(stack);
  2057. X  IOSTREAM = n->stream;
  2058. X  strcpy(FILENAME, n->filename);
  2059. X/*  free(n->filename); */
  2060. X  pipe = n->pipe;
  2061. X  line = n->line;
  2062. X  oldchar = n->oldchar;
  2063. X  oldcharvalid = n->oldcharvalid;
  2064. X  delete_item(n);
  2065. X  free_node(n, stack);
  2066. X}
  2067. X
  2068. Xstatic nexttoken()
  2069. X{
  2070. X  if (eof) return;
  2071. X  if (getnew) {
  2072. X    while (1) {
  2073. X      if (gettoken(INPUT) == 0) {
  2074. X        iostackinit();
  2075. X        if (iostackempty()) {
  2076. X          eof = 1;
  2077. X          getnew = 0;
  2078. X          return;
  2079. X        } else {
  2080. X          pop_iostack();
  2081. X        }
  2082. X      } else if (strcmp(INPUT, "(*") == 0) {
  2083. X        get_comment();
  2084. X      } else if (strcmp(INPUT, "include") == 0) {
  2085. X        if (gettoken(INPUT) == 0) {
  2086. X          error_header();
  2087. X          fprintf(stderr, "Empty include statement\n");
  2088. X          exit(1);
  2089. X        } else {
  2090. X          push_iostack(0);
  2091. X        }
  2092. X      } else if (strcmp(INPUT, "shell") == 0) {
  2093. X#ifdef VMS 
  2094. X        fprintf(stderr, "No shell option on VMS, sorry.\n");
  2095. X        exit(1);
  2096. X#endif /*VMS*/    
  2097. X        if (gettoken(INPUT) == 0 || strcmp(INPUT, ":") != 0) {
  2098. X          error_header();
  2099. X          fprintf(stderr, "'shell' must be followed by ':'\n");
  2100. X          exit(1);
  2101. X        } 
  2102. X        if (getsystemstring() == 0) {
  2103. X          fprintf(stderr, "Empty shell statement\n");
  2104. X          exit(1);
  2105. X        }
  2106. X        push_iostack(1);
  2107. X      } else {
  2108. X        getnew = 1;
  2109. X        return;
  2110. X      }
  2111. X    }
  2112. X  }
  2113. X  getnew = 1;
  2114. X  return;
  2115. X}
  2116. X
  2117. Xint getstring(s)
  2118. Xchar *s;
  2119. X{
  2120. X  nexttoken();
  2121. X  if (eof) return 0;
  2122. X  strcpy(s, INPUT);
  2123. X  return 1;
  2124. X}
  2125. X
  2126. Xint getint(i)
  2127. Xint *i;
  2128. X{
  2129. X  int j;
  2130. X
  2131. X  nexttoken();
  2132. X  if (eof) return 0;
  2133. X  *i = atoi(INPUT);
  2134. X  if (*i == 0) {
  2135. X    for (j = 0; INPUT[j] != '\0'; j++)
  2136. X      if (INPUT[j] != '0') return 0;
  2137. X  }
  2138. X  return 1;
  2139. X}
  2140. X
  2141. Xint getfloat(f)
  2142. Xfloat *f;
  2143. X{
  2144. X  int j;
  2145. X
  2146. X  nexttoken();
  2147. X  if (eof) return 0;
  2148. X  *f = (float) atof(INPUT);
  2149. X  if (*f == 0.0) {
  2150. X    for (j = 0; INPUT[j] == '-'; j++);
  2151. X    while (INPUT[j] == '0') j++;
  2152. X    if (INPUT[j] == '.') j++;
  2153. X    while (INPUT[j] == '0') j++;
  2154. X    if (INPUT[j] == 'e' || INPUT[j] == 'E') {
  2155. X      j++;
  2156. X      if (INPUT[j] == '+' || INPUT[j] == '-') j++;
  2157. X      while (INPUT[j] == '0') j++;
  2158. X    }
  2159. X    return (INPUT[j] == '\0');
  2160. X  } else return 1;
  2161. X}
  2162. X
  2163. Xstatic char *new_printable_text(s)
  2164. Xchar *s;
  2165. X{
  2166. X  char *new_s;
  2167. X  int to_pad, i, j;
  2168. X
  2169. X  to_pad = 0;
  2170. X  for (i = 0; s[i] != '\0'; i++) {
  2171. X    if (s[i] == '\\' || s[i] == ')' || s[i] == '(') {
  2172. X       to_pad++;
  2173. X    }
  2174. X  }
  2175. X
  2176. X  j = sizeof(char) * (i + to_pad + 2);
  2177. X  if ((j % 8) != 0) j += 8 - j % 8;
  2178. X  new_s = (char *) malloc (j);
  2179. X  j = 0;
  2180. X  for (i = 0; s[i] != '\0'; i++) {
  2181. X    if (s[i] == '\\' || s[i] == ')' || s[i] == '(') {
  2182. X      new_s[j++] = '\\';
  2183. X    }
  2184. X    new_s[j++] = s[i];
  2185. X  }
  2186. X  new_s[j] = '\0';        /* added: tie off -hdd */
  2187. X  return new_s;
  2188. X}
  2189. X
  2190. Xchar *getmultiline()
  2191. X{
  2192. X  char c;
  2193. X  int i, j, done, len, started;
  2194. X  char *out_str;
  2195. X
  2196. X  if (getnew == 0) return CNULL;
  2197. X  
  2198. X  c = gettokenchar();
  2199. X  if (c == real_eof) {
  2200. X    ungettokenchar();
  2201. X    return CNULL;
  2202. X  }
  2203. X  done = 0;
  2204. X  started = 0;
  2205. X  while (!done) {
  2206. X    i = 0;
  2207. X    for (c = gettokenchar(); c != real_eof && c != '\n';  c = gettokenchar()) {
  2208. X      INPUT[i++] = c;
  2209. X    }
  2210. X    INPUT[i] = '\0';
  2211. X    if (!started) {
  2212. X      out_str = (char *) malloc (sizeof(char)*(i+1));
  2213. X      strcpy(out_str, INPUT);
  2214. X      len = i;
  2215. X      started = 1;
  2216. X    } else {
  2217. X      out_str = (char *) realloc(out_str, (len + i + 3) * sizeof(char));
  2218. X      sprintf(&(out_str[len]), "\n%s", INPUT);
  2219. X      len += i+1;
  2220. X    }
  2221. X    if (c == '\n' && len != 0 && out_str[len-1] == '\\') {
  2222. X      len--;
  2223. X    } else {
  2224. X      done = 1;
  2225. X    }
  2226. X  }
  2227. X  ungettokenchar();
  2228. X  return out_str;
  2229. X}
  2230. X
  2231. Xchar *getlabel()
  2232. X{
  2233. X  char c;
  2234. X  char *txt, *new;
  2235. X  int i;
  2236. X
  2237. X  txt = getmultiline();
  2238. X  if (txt == CNULL) return CNULL;
  2239. X  new = new_printable_text(txt);
  2240. X  free(txt);
  2241. X  return new;
  2242. X}
  2243. X
  2244. Xint getsystemstring()
  2245. X{
  2246. X  char c;
  2247. X  int i;
  2248. X  int done;
  2249. X
  2250. X  if (getnew == 0) return 0;
  2251. X  
  2252. X  c = gettokenchar();
  2253. X  if (c == real_eof) {
  2254. X    ungettokenchar();
  2255. X    return 0;
  2256. X  }
  2257. X  i = 0;
  2258. X  done = 0;
  2259. X  while (!done) {
  2260. X    for (c = gettokenchar(); c != real_eof && c != '\n';  c = gettokenchar()) {
  2261. X      INPUT[i++] = c;
  2262. X    }
  2263. X    if (c == '\n' && i > 0 && INPUT[i-1] == '\\') {
  2264. X      INPUT[i++] = '\n';
  2265. X    } else {
  2266. X      done = 1;
  2267. X    }
  2268. X  }
  2269. X  ungettokenchar();
  2270. X  INPUT[i] = '\0';
  2271. X  return 1;
  2272. X}
  2273. X
  2274. Xrejecttoken()
  2275. X{
  2276. X  getnew = 0;
  2277. X}
  2278. END_OF_FILE
  2279.   if test 7542 -ne `wc -c <'token.c'`; then
  2280.     echo shar: \"'token.c'\" unpacked with wrong size!
  2281.   fi
  2282.   # end of 'token.c'
  2283. fi
  2284. echo shar: End of archive 6 \(of 7\).
  2285. cp /dev/null ark6isdone
  2286. MISSING=""
  2287. for I in 1 2 3 4 5 6 7 ; do
  2288.     if test ! -f ark${I}isdone ; then
  2289.     MISSING="${MISSING} ${I}"
  2290.     fi
  2291. done
  2292. if test "${MISSING}" = "" ; then
  2293.     echo You have unpacked all 7 archives.
  2294.     rm -f ark[1-9]isdone
  2295. else
  2296.     echo You still must unpack the following archives:
  2297.     echo "        " ${MISSING}
  2298. fi
  2299. exit 0
  2300. exit 0 # Just in case...
  2301.