home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume11 / gnuplot2 / part08 < prev    next >
Encoding:
Text File  |  1990-03-25  |  48.7 KB  |  1,817 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Pixar -- Marin County, California
  3. subject: v11i073: Gnuplot 2.0 - 8 of 14
  4. From: thaw@ucbvax.Berkeley.EDU@pixar.UUCP (Tom Williams)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 11, Issue 73
  8. Submitted-by: thaw@ucbvax.Berkeley.EDU@pixar.UUCP (Tom Williams)
  9. Archive-name: gnuplot2/part08
  10.  
  11. This is gnuplot.sh08
  12.  
  13. --- CUT HERE ---
  14. #! /bin/sh
  15. echo x - term.c
  16. sed 's/^X//' >term.c <<'*-*-END-of-term.c-*-*'
  17. X/* GNUPLOT - term.c */
  18. X/*
  19. X * Copyright (C) 1986, 1987, 1990   Thomas Williams, Colin Kelley
  20. X *
  21. X * Permission to use, copy, and distribute this software and its
  22. X * documentation for any purpose with or without fee is hereby granted, 
  23. X * provided that the above copyright notice appear in all copies and 
  24. X * that both that copyright notice and this permission notice appear 
  25. X * in supporting documentation.
  26. X *
  27. X * Permission to modify the software is granted, but not the right to
  28. X * distribute the modified code.  Modifications are to be distributed 
  29. X * as patches to released version.
  30. X *  
  31. X * This software  is provided "as is" without express or implied warranty.
  32. X * 
  33. X *
  34. X * AUTHORS
  35. X * 
  36. X *   Original Software:
  37. X *     Thomas Williams,  Colin Kelley.
  38. X * 
  39. X *   Gnuplot 2.0 additions:
  40. X *       Russell Lang, Dave Kotz, John Campbell.
  41. X * 
  42. X * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  43. X * 
  44. X */
  45. X
  46. X#include <stdio.h>
  47. X#include "plot.h"
  48. X
  49. X/* for use by all drivers */
  50. X#define sign(x) ((x) >= 0 ? 1 : -1)
  51. X#define abs(x) ((x) >= 0 ? (x) : -(x))
  52. X#define max(a,b) ((a) > (b) ? (a) : (b))
  53. X#define min(a,b) ((a) < (b) ? (a) : (b))
  54. X
  55. XBOOLEAN term_init;            /* true if terminal has been initialized */
  56. X
  57. Xextern FILE *outfile;
  58. Xextern char outstr[];
  59. Xextern BOOLEAN term_init;
  60. Xextern int term;
  61. Xextern float xsize, ysize;
  62. X
  63. Xextern char input_line[];
  64. Xextern struct lexical_unit token[];
  65. X
  66. Xextern BOOLEAN interactive;
  67. X
  68. X/*
  69. X * instead of <strings.h>
  70. X */
  71. Xextern char *strcpy();
  72. Xextern int strlen(), strcmp();
  73. X
  74. Xchar *getenv();
  75. X
  76. X#ifdef __TURBOC__
  77. Xchar *turboc_init();
  78. X#endif
  79. X
  80. X#ifdef vms
  81. X/* these are needed to sense a regis terminal and
  82. X * to do a SET TERM/NOWRAP */
  83. X#include <descrip.h>
  84. X#include <dvidef.h>
  85. X#include <iodef.h>
  86. X#include <ttdef.h>
  87. X#include <tt2def.h>
  88. Xstatic unsigned short   chan;
  89. Xstatic int  old_char_buf[3], new_char_buf[3];
  90. X$DESCRIPTOR(sysoutput_desc,"SYS$OUTPUT");
  91. Xchar *vms_init();
  92. X#endif
  93. X
  94. X
  95. X/* This is needed because the unixplot library only writes to stdout. */
  96. X#ifdef UNIXPLOT
  97. XFILE save_stdout;
  98. X#endif
  99. Xint unixplot=0;
  100. X
  101. X#define NICE_LINE        0
  102. X#define POINT_TYPES        6
  103. X
  104. X
  105. Xdo_point(x,y,number)
  106. Xint x,y;
  107. Xint number;
  108. X{
  109. Xregister int htic,vtic;
  110. Xregister struct termentry *t = &term_tbl[term];
  111. X
  112. X     if (number < 0) {        /* do dot */
  113. X        (*t->move)(x,y);
  114. X        (*t->vector)(x,y);
  115. X        return;
  116. X    }
  117. X
  118. X    number %= POINT_TYPES;
  119. X    htic = (t->h_tic/2);    /* should be in term_tbl[] in later version */
  120. X    vtic = (t->v_tic/2);    
  121. X
  122. X    switch(number) {
  123. X        case 0: /* do diamond */ 
  124. X                (*t->move)(x-htic,y);
  125. X                (*t->vector)(x,y-vtic);
  126. X                (*t->vector)(x+htic,y);
  127. X                (*t->vector)(x,y+vtic);
  128. X                (*t->vector)(x-htic,y);
  129. X                (*t->move)(x,y);
  130. X                (*t->vector)(x,y);
  131. X                break;
  132. X        case 1: /* do plus */ 
  133. X                (*t->move)(x-htic,y);
  134. X                (*t->vector)(x-htic,y);
  135. X                (*t->vector)(x+htic,y);
  136. X                (*t->move)(x,y-vtic);
  137. X                (*t->vector)(x,y-vtic);
  138. X                (*t->vector)(x,y+vtic);
  139. X                break;
  140. X        case 2: /* do box */ 
  141. X                (*t->move)(x-htic,y-vtic);
  142. X                (*t->vector)(x-htic,y-vtic);
  143. X                (*t->vector)(x+htic,y-vtic);
  144. X                (*t->vector)(x+htic,y+vtic);
  145. X                (*t->vector)(x-htic,y+vtic);
  146. X                (*t->vector)(x-htic,y-vtic);
  147. X                (*t->move)(x,y);
  148. X                (*t->vector)(x,y);
  149. X                break;
  150. X        case 3: /* do X */ 
  151. X                (*t->move)(x-htic,y-vtic);
  152. X                (*t->vector)(x-htic,y-vtic);
  153. X                (*t->vector)(x+htic,y+vtic);
  154. X                (*t->move)(x-htic,y+vtic);
  155. X                (*t->vector)(x-htic,y+vtic);
  156. X                (*t->vector)(x+htic,y-vtic);
  157. X                break;
  158. X        case 4: /* do triangle */ 
  159. X                (*t->move)(x,y+(4*vtic/3));
  160. X                (*t->vector)(x-(4*htic/3),y-(2*vtic/3));
  161. X                (*t->vector)(x+(4*htic/3),y-(2*vtic/3));
  162. X                (*t->vector)(x,y+(4*vtic/3));
  163. X                (*t->move)(x,y);
  164. X                (*t->vector)(x,y);
  165. X                break;
  166. X        case 5: /* do star */ 
  167. X                (*t->move)(x-htic,y);
  168. X                (*t->vector)(x-htic,y);
  169. X                (*t->vector)(x+htic,y);
  170. X                (*t->move)(x,y-vtic);
  171. X                (*t->vector)(x,y-vtic);
  172. X                (*t->vector)(x,y+vtic);
  173. X                (*t->move)(x-htic,y-vtic);
  174. X                (*t->vector)(x-htic,y-vtic);
  175. X                (*t->vector)(x+htic,y+vtic);
  176. X                (*t->move)(x-htic,y+vtic);
  177. X                (*t->vector)(x-htic,y+vtic);
  178. X                (*t->vector)(x+htic,y-vtic);
  179. X                break;
  180. X    }
  181. X}
  182. X
  183. X
  184. X/*
  185. X * general point routine
  186. X */
  187. Xline_and_point(x,y,number)
  188. Xint x,y,number;
  189. X{
  190. X    /* temporary(?) kludge to allow terminals with bad linetypes 
  191. X        to make nice marks */
  192. X
  193. X    (*term_tbl[term].linetype)(NICE_LINE);
  194. X    do_point(x,y,number);
  195. X}
  196. X
  197. X/* 
  198. X * general arrow routine
  199. X */
  200. X#define ROOT2 (1.41421)        /* sqrt of 2 */
  201. X
  202. Xdo_arrow(sx, sy, ex, ey)
  203. X    int sx,sy;            /* start point */
  204. X    int ex, ey;            /* end point (point of arrowhead) */
  205. X{
  206. X    register struct termentry *t = &term_tbl[term];
  207. X    int len = (t->h_tic + t->v_tic)/2; /* arrowhead size = avg of tic sizes */
  208. X    extern double sqrt();
  209. X
  210. X    /* draw the line for the arrow. That's easy. */
  211. X    (*t->move)(sx, sy);
  212. X    (*t->vector)(ex, ey);
  213. X
  214. X    /* now draw the arrow head. */
  215. X    /* we put the arrowhead marks at 45 degrees to line */
  216. X    if (sx == ex) {
  217. X       /* vertical line, special case */
  218. X       int delta = ((float)len / ROOT2 + 0.5);
  219. X       if (sy < ey)
  220. X        delta = -delta;    /* up arrow goes the other way */
  221. X       (*t->move)(ex - delta, ey + delta);
  222. X       (*t->vector)(ex,ey);
  223. X       (*t->vector)(ex + delta, ey + delta);
  224. X    } else {
  225. X       int dx = sx - ex;
  226. X       int dy = sy - ey;
  227. X       double coeff = len / sqrt(2.0*((double)dx*(double)dx 
  228. X                + (double)dy*(double)dy));
  229. X       int x,y;            /* one endpoint */
  230. X
  231. X       x = (int)( ex + (dx + dy) * coeff );
  232. X       y = (int)( ey + (dy - dx) * coeff );
  233. X       (*t->move)(x,y);
  234. X       (*t->vector)(ex,ey);
  235. X
  236. X       x = (int)( ex + (dx - dy) * coeff );
  237. X       y = (int)( ey + (dy + dx) * coeff );
  238. X       (*t->vector)(x,y);
  239. X    }
  240. X
  241. X}
  242. X
  243. X#ifdef PC
  244. X#ifndef __TURBOC__
  245. X#define FONT57
  246. X#endif
  247. X#endif
  248. X
  249. X#ifdef NEC
  250. X#ifndef EPSON
  251. X#define EPSON
  252. X#endif
  253. X#endif
  254. X
  255. X#ifdef PROPRINTER 
  256. X#ifndef EPSON
  257. X#define EPSON 
  258. X#endif
  259. X#endif
  260. X
  261. X#ifdef EPSON
  262. X#define FONT57
  263. X#endif
  264. X
  265. X#ifdef UNIXPC
  266. X#define FONT57
  267. X#endif
  268. X
  269. X#ifdef FONT57
  270. X#include "term/font5x7.trm"
  271. X#endif  /* FONT57  */
  272. X
  273. X
  274. X#ifdef PC            /* all PC types */
  275. X#include "term/pc.trm"
  276. X#endif
  277. X
  278. X/*
  279. X   all TEK types (TEK,BITGRAPH,KERMIT,SELANAR) are ifdef'd in tek.trm,
  280. X   but most require various TEK routines.  Hence TEK must be defined for
  281. X   the others to compile.
  282. X*/
  283. X#ifdef BITGRAPH
  284. X# ifndef TEK
  285. X#  define TEK
  286. X# endif
  287. X#endif
  288. X
  289. X#ifdef SELENAR
  290. X# ifndef TEK
  291. X#  define TEK
  292. X# endif
  293. X#endif
  294. X
  295. X#ifdef KERMIT
  296. X# ifndef TEK
  297. X#  define TEK
  298. X# endif
  299. X#endif
  300. X
  301. X#ifdef TEK            /* all TEK types, TEK, BBN, SELANAR, KERMIT */
  302. X#include "term/tek.trm"
  303. X#endif
  304. X
  305. X#ifdef EPSON        /* all bit map types, EPSON, NEC, PROPRINTER */
  306. X#include "term/epson.trm"
  307. X#endif
  308. X
  309. X#ifdef FIG                /* Fig 1.4FS Interactive graphics program */
  310. X#include "term/fig.trm"
  311. X#endif
  312. X
  313. X#ifdef IMAGEN        /* IMAGEN printer */
  314. X#include "term/imagen.trm"
  315. X#endif
  316. X
  317. X#ifdef EEPIC        /* EEPIC (LATEX) type */
  318. X#include "term/eepic.trm"
  319. X# ifndef LATEX
  320. X#  define LATEX
  321. X# endif
  322. X#endif
  323. X
  324. X#ifdef LATEX        /* LATEX type */
  325. X#include "term/latex.trm"
  326. X#endif
  327. X
  328. X#ifdef POSTSCRIPT    /* POSTSCRIPT type */
  329. X#include "term/post.trm"
  330. X#endif
  331. X
  332. X#ifdef HPLJET        /* hplaserjet */
  333. X#include "term/hpljet.trm"
  334. X#endif
  335. X
  336. X#ifdef UNIXPC     /* unix-PC  ATT 7300 or 3b1 machine */
  337. X#include "term/unixpc.trm"
  338. X#endif /* UNIXPC */
  339. X
  340. X#ifdef AED
  341. X#include "term/aed.trm"
  342. X#endif /* AED */
  343. X
  344. X#ifdef HP2648
  345. X/* also works for HP2647 */
  346. X#include "term/hp2648.trm"
  347. X#endif /* HP2648 */
  348. X
  349. X#ifdef HP26
  350. X#include "term/hp26.trm"
  351. X#endif /* HP26 */
  352. X
  353. X#ifdef HP75
  354. X#ifndef HPGL
  355. X#define HPGL
  356. X#endif
  357. X#endif
  358. X
  359. X/* HPGL - includes HP75 */
  360. X#ifdef HPGL
  361. X#include "term/hpgl.trm"
  362. X#endif /* HPGL */
  363. X
  364. X/* Roland DXY800A plotter driver by Martin Yii, eln557h@monu3.OZ 
  365. X    and Russell Lang, rjl@monu1.cc.monash.oz */
  366. X#ifdef DXY800A
  367. X#include "term/dxy.trm"
  368. X#endif /* DXY800A */
  369. X
  370. X#ifdef IRIS4D
  371. X#include "term/iris4d.trm"
  372. X#endif /* IRIS4D */
  373. X
  374. X#ifdef QMS
  375. X#include "term/qms.trm"
  376. X#endif /* QMS */
  377. X
  378. X#ifdef REGIS
  379. X#include "term/regis.trm"
  380. X#endif /* REGIS */
  381. X
  382. X#ifdef SUN
  383. X#include "term/sun.trm"
  384. X#endif /* SUN */
  385. X
  386. X#ifdef V384
  387. X#include "term/v384.trm"
  388. X#endif /* V384 */
  389. X
  390. X#ifdef UNIXPLOT
  391. X#include "term/unixplot.trm"
  392. X#endif /* UNIXPLOT */
  393. X
  394. X/* Dummy functions for unavailable features */
  395. X
  396. X/* change angle of text.  0 is horizontal left to right.
  397. X* 1 is vertical bottom to top (90 deg rotate)  
  398. X*/
  399. Xint null_text_angle()
  400. X{
  401. Xreturn FALSE ;    /* can't be done */
  402. X}
  403. X
  404. X/* change justification of text.  
  405. X * modes are LEFT (flush left), CENTRE (centred), RIGHT (flush right)
  406. X */
  407. Xint null_justify_text()
  408. X{
  409. Xreturn FALSE ;    /* can't be done */
  410. X}
  411. X
  412. X
  413. X/* Change scale of plot.
  414. X * Parameters are x,y scaling factors for this plot.
  415. X * Some terminals (eg latex) need to do scaling themselves.
  416. X */
  417. Xint null_scale()
  418. X{
  419. Xreturn FALSE ;    /* can't be done */
  420. X}
  421. X
  422. X
  423. XUNKNOWN_null()
  424. X{
  425. X}
  426. X
  427. X
  428. X/*
  429. X * term_tbl[] contains an entry for each terminal.  "unknown" must be the
  430. X *   first, since term is initialized to 0.
  431. X */
  432. Xstruct termentry term_tbl[] = {
  433. X    {"unknown", "Unknown terminal type - not a plotting device",
  434. X      100, 100, 1, 1,
  435. X      1, 1, UNKNOWN_null, UNKNOWN_null, 
  436. X      UNKNOWN_null, null_scale, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, 
  437. X      UNKNOWN_null, UNKNOWN_null, null_text_angle, 
  438. X      null_justify_text, UNKNOWN_null, UNKNOWN_null}
  439. X#ifdef PC
  440. X#ifdef __TURBOC__
  441. X
  442. X    ,{"egalib", "IBM PC/Clone with EGA graphics board",
  443. X       EGALIB_XMAX, EGALIB_YMAX, EGALIB_VCHAR, EGALIB_HCHAR,
  444. X       EGALIB_VTIC, EGALIB_HTIC, EGALIB_init, EGALIB_reset,
  445. X       EGALIB_text, null_scale, EGALIB_graphics, EGALIB_move, EGALIB_vector,
  446. X       EGALIB_linetype, EGALIB_put_text, EGALIB_text_angle, 
  447. X       EGALIB_justify_text, do_point, do_arrow}
  448. X
  449. X    ,{"vgalib", "IBM PC/Clone with VGA graphics board",
  450. X       VGA_XMAX, VGA_YMAX, VGA_VCHAR, VGA_HCHAR,
  451. X       VGA_VTIC, VGA_HTIC, VGA_init, VGA_reset,
  452. X       VGA_text, null_scale, VGA_graphics, VGA_move, VGA_vector,
  453. X       VGA_linetype, VGA_put_text, VGA_text_angle, 
  454. X       VGA_justify_text, do_point, do_arrow}
  455. X
  456. X    ,{"vgamono", "IBM PC/Clone with VGA Monochrome graphics board",
  457. X       VGA_XMAX, VGA_YMAX, VGA_VCHAR, VGA_HCHAR,
  458. X       VGA_VTIC, VGA_HTIC, VGA_init, VGA_reset,
  459. X       VGA_text, null_scale, VGA_graphics, VGA_move, VGA_vector,
  460. X       VGAMONO_linetype, VGA_put_text, VGA_text_angle, 
  461. X       VGA_justify_text, line_and_point, do_arrow}
  462. X
  463. X    ,{"mcga", "IBM PC/Clone with MCGA graphics board",
  464. X       MCGA_XMAX, MCGA_YMAX, MCGA_VCHAR, MCGA_HCHAR,
  465. X       MCGA_VTIC, MCGA_HTIC, MCGA_init, MCGA_reset,
  466. X       MCGA_text, null_scale, MCGA_graphics, MCGA_move, MCGA_vector,
  467. X       MCGA_linetype, MCGA_put_text, MCGA_text_angle, 
  468. X       MCGA_justify_text, line_and_point, do_arrow}
  469. X
  470. X    ,{"cga", "IBM PC/Clone with CGA graphics board",
  471. X       CGA_XMAX, CGA_YMAX, CGA_VCHAR, CGA_HCHAR,
  472. X       CGA_VTIC, CGA_HTIC, CGA_init, CGA_reset,
  473. X       CGA_text, null_scale, CGA_graphics, CGA_move, CGA_vector,
  474. X       CGA_linetype, CGA_put_text, MCGA_text_angle, 
  475. X       CGA_justify_text, line_and_point, do_arrow}
  476. X
  477. X    ,{"hercules", "IBM PC/Clone with Hercules graphics board",
  478. X       HERC_XMAX, HERC_YMAX, HERC_VCHAR, HERC_HCHAR,
  479. X       HERC_VTIC, HERC_HTIC, HERC_init, HERC_reset,
  480. X       HERC_text, null_scale, HERC_graphics, HERC_move, HERC_vector,
  481. X       HERC_linetype, HERC_put_text, MCGA_text_angle, 
  482. X       HERC_justify_text, line_and_point, do_arrow}
  483. X#else                    /* TURBO */
  484. X
  485. X    ,{"cga", "IBM PC/Clone with CGA graphics board",
  486. X       CGA_XMAX, CGA_YMAX, CGA_VCHAR, CGA_HCHAR,
  487. X       CGA_VTIC, CGA_HTIC, CGA_init, CGA_reset,
  488. X       CGA_text, null_scale, CGA_graphics, CGA_move, CGA_vector,
  489. X       CGA_linetype, CGA_put_text, CGA_text_angle, 
  490. X       null_justify_text, line_and_point, do_arrow}
  491. X
  492. X    ,{"egabios", "IBM PC/Clone with EGA graphics board (BIOS)",
  493. X       EGA_XMAX, EGA_YMAX, EGA_VCHAR, EGA_HCHAR,
  494. X       EGA_VTIC, EGA_HTIC, EGA_init, EGA_reset,
  495. X       EGA_text, null_scale, EGA_graphics, EGA_move, EGA_vector,
  496. X       EGA_linetype, EGA_put_text, EGA_text_angle, 
  497. X       null_justify_text, do_point, do_arrow}
  498. X
  499. X    ,{"vgabios", "IBM PC/Clone with VGA graphics board (BIOS)",
  500. X       VGA_XMAX, VGA_YMAX, VGA_VCHAR, VGA_HCHAR,
  501. X       VGA_VTIC, VGA_HTIC, VGA_init, VGA_reset,
  502. X       VGA_text, null_scale, VGA_graphics, VGA_move, VGA_vector,
  503. X       VGA_linetype, VGA_put_text, VGA_text_angle, 
  504. X       null_justify_text, do_point, do_arrow}
  505. X
  506. X#ifdef EGALIB
  507. X    ,{"egalib", "IBM PC/Clone with EGA graphics board (LIB)",
  508. X       EGALIB_XMAX, EGALIB_YMAX, EGALIB_VCHAR, EGALIB_HCHAR,
  509. X       EGALIB_VTIC, EGALIB_HTIC, EGALIB_init, EGALIB_reset,
  510. X       EGALIB_text, null_scale, EGALIB_graphics, EGALIB_move, EGALIB_vector,
  511. X       EGALIB_linetype, EGALIB_put_text, null_text_angle, 
  512. X       null_justify_text, do_point, do_arrow}
  513. X#endif
  514. X
  515. X#ifdef HERCULES
  516. X    ,{"hercules", "IBM PC/Clone with Hercules graphics board",
  517. X       HERC_XMAX, HERC_YMAX, HERC_VCHAR, HERC_HCHAR,
  518. X       HERC_VTIC, HERC_HTIC, HERC_init, HERC_reset,
  519. X       HERC_text, null_scale, HERC_graphics, HERC_move, HERC_vector,
  520. X       HERC_linetype, HERC_put_text, HERC_text_angle, 
  521. X       null_justify_text, line_and_point, do_arrow}
  522. X#endif                    /* HERCULES */
  523. X
  524. X#ifdef ATT6300
  525. X    ,{"att", "AT&T 6300 terminal ???",
  526. X       ATT_XMAX, ATT_YMAX, ATT_VCHAR, ATT_HCHAR,
  527. X       ATT_VTIC, ATT_HTIC, ATT_init, ATT_reset,
  528. X       ATT_text, null_scale, ATT_graphics, ATT_move, ATT_vector,
  529. X       ATT_linetype, ATT_put_text, ATT_text_angle, 
  530. X       null_justify_text, line_and_point, do_arrow}
  531. X#endif
  532. X
  533. X#ifdef CORONA
  534. X    ,{"corona325", "Corona graphics ???",
  535. X       COR_XMAX, COR_YMAX, COR_VCHAR, COR_HCHAR,
  536. X       COR_VTIC, COR_HTIC, COR_init, COR_reset,
  537. X       COR_text, null_scale, COR_graphics, COR_move, COR_vector,
  538. X       COR_linetype, COR_put_text, COR_text_angle, 
  539. X       null_justify_text, line_and_point, do_arrow}
  540. X#endif                    /* CORONA */
  541. X#endif                    /* TURBO */
  542. X#endif                    /* PC */
  543. X
  544. X#ifdef AED
  545. X    ,{"aed512", "AED 512 Terminal",
  546. X       AED5_XMAX, AED_YMAX, AED_VCHAR, AED_HCHAR,
  547. X       AED_VTIC, AED_HTIC, AED_init, AED_reset, 
  548. X       AED_text, null_scale, AED_graphics, AED_move, AED_vector, 
  549. X       AED_linetype, AED_put_text, null_text_angle, 
  550. X       null_justify_text, do_point, do_arrow}
  551. X    ,{"aed767", "AED 767 Terminal",
  552. X       AED_XMAX, AED_YMAX, AED_VCHAR, AED_HCHAR,
  553. X       AED_VTIC, AED_HTIC, AED_init, AED_reset, 
  554. X       AED_text, null_scale, AED_graphics, AED_move, AED_vector, 
  555. X       AED_linetype, AED_put_text, null_text_angle, 
  556. X       null_justify_text, do_point, do_arrow}
  557. X#endif
  558. X
  559. X#ifdef BITGRAPH
  560. X    ,{"bitgraph", "BBN Bitgraph Terminal",
  561. X       BG_XMAX,BG_YMAX,BG_VCHAR, BG_HCHAR, 
  562. X       BG_VTIC, BG_HTIC, BG_init, BG_reset, 
  563. X       BG_text, null_scale, BG_graphics, BG_move, BG_vector,
  564. X       BG_linetype, BG_put_text, null_text_angle, 
  565. X       null_justify_text, line_and_point, do_arrow}
  566. X#endif
  567. X
  568. X#ifdef DXY800A
  569. X    ,{"dxy800a", "Roland DXY800A plotter",
  570. X       DXY_XMAX, DXY_YMAX, DXY_VCHAR, DXY_HCHAR,
  571. X       DXY_VTIC, DXY_HTIC, DXY_init, DXY_reset,
  572. X       DXY_text, null_scale, DXY_graphics, DXY_move, DXY_vector,
  573. X       DXY_linetype, DXY_put_text, DXY_text_angle, 
  574. X       null_justify_text, do_point, do_arrow}
  575. X#endif
  576. X
  577. X#ifdef EPSON
  578. X    ,{"epson_lx800", "Epson LX-800, Star NL-10, NX-1000 and lots of others",
  579. X       EPSONXMAX, EPSONYMAX, EPSONVCHAR, EPSONHCHAR, 
  580. X       EPSONVTIC, EPSONHTIC, EPSONinit, EPSONreset, 
  581. X       EPSONtext, null_scale, EPSONgraphics, EPSONmove, EPSONvector, 
  582. X       EPSONlinetype, EPSONput_text, EPSON_text_angle, 
  583. X       null_justify_text, line_and_point, do_arrow}
  584. X#endif
  585. X
  586. X#ifdef FIG
  587. X    ,{"fig", "FIG graphics language: SunView or X graphics editor",
  588. X       FIG_XMAX, FIG_YMAX, FIG_VCHAR, FIG_HCHAR, 
  589. X       FIG_VTIC, FIG_HTIC, FIG_init, FIG_reset, 
  590. X       FIG_text, null_scale, FIG_graphics, FIG_move, FIG_vector, 
  591. X       FIG_linetype, FIG_put_text, FIG_text_angle, 
  592. X       FIG_justify_text, do_point, FIG_arrow}
  593. X#endif
  594. X
  595. X#ifdef HP26
  596. X    ,{"hp2623A", "HP2623A and maybe others",
  597. X       HP26_XMAX, HP26_YMAX, HP26_VCHAR, HP26_HCHAR,
  598. X       HP26_VTIC, HP26_HTIC, HP26_init, HP26_reset,
  599. X       HP26_text, null_scale, HP26_graphics, HP26_move, HP26_vector,
  600. X       HP26_linetype, HP26_put_text, null_text_angle, 
  601. X       null_justify_text, line_and_point, do_arrow}
  602. X#endif
  603. X
  604. X#ifdef HP2648
  605. X    ,{"hp2648", "HP2648 and HP2647",
  606. X       HP2648XMAX, HP2648YMAX, HP2648VCHAR, HP2648HCHAR, 
  607. X       HP2648VTIC, HP2648HTIC, HP2648init, HP2648reset, 
  608. X       HP2648text, null_scale, HP2648graphics, HP2648move, HP2648vector, 
  609. X       HP2648linetype, HP2648put_text, HP2648_text_angle, 
  610. X       null_justify_text, line_and_point, do_arrow}
  611. X#endif
  612. X
  613. X#ifdef HP75
  614. X    ,{"hp7580B", "HP7580, and probably other HPs (4 pens)",
  615. X       HPGL_XMAX, HPGL_YMAX, HPGL_VCHAR, HPGL_HCHAR,
  616. X       HPGL_VTIC, HPGL_HTIC, HPGL_init, HPGL_reset,
  617. X       HPGL_text, null_scale, HPGL_graphics, HPGL_move, HPGL_vector,
  618. X       HP75_linetype, HPGL_put_text, HPGL_text_angle, 
  619. X       null_justify_text, do_point, do_arrow}
  620. X#endif
  621. X
  622. X#ifdef HPGL
  623. X    ,{"hpgl", "HP7475 and (hopefully) lots of others (6 pens)",
  624. X       HPGL_XMAX, HPGL_YMAX, HPGL_VCHAR, HPGL_HCHAR,
  625. X       HPGL_VTIC, HPGL_HTIC, HPGL_init, HPGL_reset,
  626. X       HPGL_text, null_scale, HPGL_graphics, HPGL_move, HPGL_vector,
  627. X       HPGL_linetype, HPGL_put_text, HPGL_text_angle, 
  628. X       null_justify_text, do_point, do_arrow}
  629. X#endif
  630. X
  631. X#ifdef HPLJET
  632. X    ,{"laserjet1", "HP Laserjet, smallest size",
  633. X       HPLJETXMAX, HPLJETYMAX, HPLJET1VCHAR, HPLJET1HCHAR, 
  634. X       HPLJETVTIC, HPLJETHTIC, HPLJET1init, HPLJETreset, 
  635. X       HPLJETtext, null_scale, HPLJETgraphics, HPLJETmove, HPLJETvector,
  636. X       HPLJETlinetype, HPLJETput_text, null_text_angle, 
  637. X       null_justify_text, line_and_point, do_arrow}
  638. X    ,{"laserjet2", "HP Laserjet, medium size",
  639. X       HPLJETXMAX, HPLJETYMAX, HPLJET2VCHAR, HPLJET2HCHAR, 
  640. X       HPLJETVTIC, HPLJETHTIC, HPLJET2init, HPLJETreset, 
  641. X       HPLJETtext, null_scale, HPLJETgraphics, HPLJETmove, HPLJETvector,
  642. X       HPLJETlinetype, HPLJETput_text, null_text_angle, 
  643. X       null_justify_text, line_and_point, do_arrow}
  644. X    ,{"laserjet3", "HP Laserjet, largest size",
  645. X       HPLJETXMAX, HPLJETYMAX, HPLJET3VCHAR, HPLJET3HCHAR, 
  646. X       HPLJETVTIC, HPLJETHTIC, HPLJET3init, HPLJETreset, 
  647. X       HPLJETtext, null_scale, HPLJETgraphics, HPLJETmove, HPLJETvector, 
  648. X       HPLJETlinetype, HPLJETput_text, null_text_angle, 
  649. X       null_justify_text, line_and_point, do_arrow}
  650. X#endif
  651. X
  652. X#ifdef IMAGEN
  653. X    ,{"imagen", "Imagen laser printer",
  654. X       IMAGEN_XMAX, IMAGEN_YMAX, IMAGEN_VCHAR, IMAGEN_HCHAR, 
  655. X       IMAGEN_VTIC, IMAGEN_HTIC, IMAGEN_init, IMAGEN_reset, 
  656. X       IMAGEN_text, null_scale, IMAGEN_graphics, IMAGEN_move, 
  657. X       IMAGEN_vector, IMAGEN_linetype, IMAGEN_put_text, IMAGEN_text_angle,
  658. X       IMAGEN_justify_text, line_and_point, do_arrow}
  659. X#endif
  660. X
  661. X#ifdef IRIS4D
  662. X    ,{"iris4d", "Silicon Graphics IRIS 4D Series Computer",
  663. X       IRIS4D_XMAX, IRIS4D_YMAX, IRIS4D_VCHAR, IRIS4D_HCHAR, 
  664. X       IRIS4D_VTIC, IRIS4D_HTIC, IRIS4D_init, IRIS4D_reset, 
  665. X       IRIS4D_text, null_scale, IRIS4D_graphics, IRIS4D_move, IRIS4D_vector,
  666. X       IRIS4D_linetype, IRIS4D_put_text, null_text_angle, 
  667. X       null_justify_text, do_point, do_arrow}
  668. X#endif
  669. X
  670. X#ifdef KERMIT
  671. X    ,{"kc_tek40xx", "Kermit-MS tek40xx terminal emulator - color",
  672. X       TEK40XMAX,TEK40YMAX,TEK40VCHAR, KTEK40HCHAR, 
  673. X       TEK40VTIC, TEK40HTIC, TEK40init, KTEK40reset, 
  674. X       KTEK40Ctext, null_scale, KTEK40graphics, TEK40move, TEK40vector, 
  675. X       KTEK40Clinetype, TEK40put_text, null_text_angle, 
  676. X       null_justify_text, do_point, do_arrow}
  677. X    ,{"km_tek40xx", "Kermit-MS tek40xx terminal emulator - monochrome",
  678. X       TEK40XMAX,TEK40YMAX,TEK40VCHAR, KTEK40HCHAR, 
  679. X       TEK40VTIC, TEK40HTIC, TEK40init, KTEK40reset, 
  680. X       TEK40text, null_scale, KTEK40graphics, TEK40move, TEK40vector, 
  681. X       KTEK40Mlinetype, TEK40put_text, null_text_angle, 
  682. X       null_justify_text, line_and_point, do_arrow}
  683. X#endif
  684. X
  685. X#ifdef LATEX
  686. X    ,{"latex", "LaTeX picture environment",
  687. X       LATEX_XMAX, LATEX_YMAX, LATEX_VCHAR, LATEX_HCHAR, 
  688. X       LATEX_VTIC, LATEX_HTIC, LATEX_init, LATEX_reset, 
  689. X       LATEX_text, LATEX_scale, LATEX_graphics, LATEX_move, LATEX_vector, 
  690. X       LATEX_linetype, LATEX_put_text, LATEX_text_angle, 
  691. X       LATEX_justify_text, LATEX_point, LATEX_arrow}
  692. X#endif
  693. X
  694. X#ifdef EEPIC
  695. X    ,{"eepic", "EEPIC -- extended LaTeX picture environment",
  696. X       EEPIC_XMAX, EEPIC_YMAX, EEPIC_VCHAR, EEPIC_HCHAR, 
  697. X       EEPIC_VTIC, EEPIC_HTIC, EEPIC_init, EEPIC_reset, 
  698. X       EEPIC_text, EEPIC_scale, EEPIC_graphics, EEPIC_move, EEPIC_vector, 
  699. X       EEPIC_linetype, EEPIC_put_text, EEPIC_text_angle, 
  700. X       EEPIC_justify_text, EEPIC_point, EEPIC_arrow}
  701. X#endif
  702. X
  703. X#ifdef NEC
  704. X    ,{"nec_cp6m", "NEC printer CP6 Monochrome",
  705. X       NECXMAX, NECYMAX, NECVCHAR, NECHCHAR, 
  706. X       NECVTIC, NECHTIC, NECMinit, NECreset, 
  707. X       NECtext, null_scale, NECgraphics, NECmove, NECvector, 
  708. X       NECMlinetype, NECput_text, NEC_text_angle, 
  709. X       null_justify_text, line_and_point, do_arrow}
  710. X    ,{"nec_cp6c", "NEC printer CP6 Color",
  711. X       NECXMAX, NECYMAX, NECVCHAR, NECHCHAR, 
  712. X       NECVTIC, NECHTIC, NECCinit, NECreset, 
  713. X       NECtext, null_scale, NECgraphics, NECmove, NECvector, 
  714. X       NECClinetype, NECput_text, NEC_text_angle, 
  715. X       null_justify_text, do_point, do_arrow}
  716. X    ,{"nec_cp6d", "NEC printer CP6 Draft monochrome",
  717. X       NECXMAX, NECYMAX, NECVCHAR, NECHCHAR, 
  718. X       NECVTIC, NECHTIC, NECMinit, NECreset, 
  719. X       NECdraft_text, null_scale, NECgraphics, NECmove, NECvector, 
  720. X       NECMlinetype, NECput_text, NEC_text_angle, 
  721. X       null_justify_text, line_and_point, do_arrow}
  722. X#endif
  723. X
  724. X#ifdef POSTSCRIPT
  725. X    ,{"postscript", "Postscript graphics language, small characters",
  726. X       PS_XMAX, PS_YMAX, PS_VCHAR1, PS_HCHAR1, 
  727. X       PS_VTIC, PS_HTIC, PS1_init, PS_reset, 
  728. X       PS_text, null_scale, PS_graphics, PS_move, PS_vector, 
  729. X       PS_linetype, PS_put_text, PS_text_angle, 
  730. X       PS_justify_text, PS_point, do_arrow}
  731. X    ,{"psbig", "Postscript graphics language, big characters",
  732. X       PS_XMAX, PS_YMAX, PS_VCHAR2, PS_HCHAR2, 
  733. X       PS_VTIC, PS_HTIC, PS2_init, PS_reset, 
  734. X       PS_text, null_scale, PS_graphics, PS_move, PS_vector, 
  735. X       PS_linetype, PS_put_text, PS_text_angle, 
  736. X       PS_justify_text, PS_point, do_arrow}
  737. X    ,{"epsf1", "Encapsulated Postscript graphics language, small characters",
  738. X       PS_XMAX, PS_YMAX, PS_VCHAR1, PS_HCHAR1, 
  739. X       PS_VTIC, PS_HTIC, EPSF1_init, EPSF_reset, 
  740. X       EPSF_text, null_scale, EPSF_graphics, PS_move, PS_vector, 
  741. X       PS_linetype, PS_put_text, PS_text_angle, 
  742. X       PS_justify_text, PS_point, do_arrow}
  743. X    ,{"epsf2", "Encapsulated Postscript graphics language, big characters",
  744. X       PS_XMAX, PS_YMAX, PS_VCHAR2, PS_HCHAR2, 
  745. X       PS_VTIC, PS_HTIC, EPSF2_init, EPSF_reset, 
  746. X       EPSF_text, null_scale, EPSF_graphics, PS_move, PS_vector, 
  747. X       PS_linetype, PS_put_text, PS_text_angle, 
  748. X       PS_justify_text, PS_point, do_arrow}
  749. X#endif
  750. X
  751. X#ifdef PROPRINTER
  752. X    ,{"proprinter", "IBM Proprinter",
  753. X       EPSONXMAX, EPSONYMAX, EPSONVCHAR, EPSONHCHAR, 
  754. X       EPSONVTIC, EPSONHTIC, EPSONinit, EPSONreset, 
  755. X       PROPRINTERtext, null_scale, EPSONgraphics, EPSONmove, EPSONvector, 
  756. X       EPSONlinetype, EPSONput_text, EPSON_text_angle, 
  757. X       null_justify_text, line_and_point, do_arrow}
  758. X#endif
  759. X
  760. X#ifdef QMS
  761. X    ,{"qms", "QMS/QUIC Laser printer (also Talaris 1200 and others)",
  762. X       QMS_XMAX,QMS_YMAX, QMS_VCHAR, QMS_HCHAR, 
  763. X       QMS_VTIC, QMS_HTIC, QMS_init,QMS_reset, 
  764. X       QMS_text, null_scale, QMS_graphics, QMS_move, QMS_vector,
  765. X       QMS_linetype,QMS_put_text, null_text_angle, 
  766. X       null_justify_text, line_and_point, do_arrow}
  767. X#endif
  768. X
  769. X#ifdef REGIS
  770. X    ,{"regis", "REGIS graphics language",
  771. X       REGISXMAX, REGISYMAX, REGISVCHAR, REGISHCHAR, 
  772. X       REGISVTIC, REGISHTIC, REGISinit, REGISreset, 
  773. X       REGIStext, null_scale, REGISgraphics, REGISmove, REGISvector,
  774. X       REGISlinetype, REGISput_text, REGIStext_angle, 
  775. X       null_justify_text, line_and_point, do_arrow}
  776. X#endif
  777. X
  778. X
  779. X#ifdef SELANAR
  780. X    ,{"selanar", "Selanar",
  781. X       TEK40XMAX, TEK40YMAX, TEK40VCHAR, TEK40HCHAR, 
  782. X       TEK40VTIC, TEK40HTIC, SEL_init, SEL_reset, 
  783. X       SEL_text, null_scale, SEL_graphics, TEK40move, TEK40vector, 
  784. X       TEK40linetype, TEK40put_text, null_text_angle, 
  785. X       null_justify_text, line_and_point, do_arrow}
  786. X#endif
  787. X
  788. X#ifdef SUN
  789. X    ,{"sun", "SunView window system",
  790. X       SUN_XMAX, SUN_YMAX, SUN_VCHAR, SUN_HCHAR, 
  791. X       SUN_VTIC, SUN_HTIC, SUN_init, SUN_reset, 
  792. X       SUN_text, null_scale, SUN_graphics, SUN_move, SUN_vector,
  793. X       SUN_linetype, SUN_put_text, null_text_angle, 
  794. X       SUN_justify_text, line_and_point, do_arrow}
  795. X#endif
  796. X
  797. X#ifdef TEK
  798. X    ,{"tek40xx", "Tektronix 4010 and others; most TEK emulators",
  799. X       TEK40XMAX, TEK40YMAX, TEK40VCHAR, TEK40HCHAR, 
  800. X       TEK40VTIC, TEK40HTIC, TEK40init, TEK40reset, 
  801. X       TEK40text, null_scale, TEK40graphics, TEK40move, TEK40vector, 
  802. X       TEK40linetype, TEK40put_text, null_text_angle, 
  803. X       null_justify_text, line_and_point, do_arrow}
  804. X#endif
  805. X
  806. X#ifdef UNIXPLOT
  807. X    ,{"unixplot", "Unix plotting standard (see plot(1))",
  808. X       UP_XMAX, UP_YMAX, UP_VCHAR, UP_HCHAR, 
  809. X       UP_VTIC, UP_HTIC, UP_init, UP_reset, 
  810. X       UP_text, null_scale, UP_graphics, UP_move, UP_vector, 
  811. X       UP_linetype, UP_put_text, null_text_angle, 
  812. X       null_justify_text, line_and_point, do_arrow}
  813. X#endif
  814. X    
  815. X#ifdef UNIXPC
  816. X    ,{"unixpc", "AT&T 3b1 or AT&T 7300 Unix PC",
  817. X       uPC_XMAX, uPC_YMAX, uPC_VCHAR, uPC_HCHAR, 
  818. X       uPC_VTIC, uPC_HTIC, uPC_init, uPC_reset, 
  819. X       uPC_text, null_scale, uPC_graphics, uPC_move, uPC_vector,
  820. X       uPC_linetype, uPC_put_text, uPC_text_angle, 
  821. X       null_justify_text, line_and_point, do_arrow}
  822. X#endif
  823. X
  824. X#ifdef V384
  825. X    ,{"vx384", "Vectrix 384 and Tandy color printer",
  826. X       V384_XMAX, V384_YMAX, V384_VCHAR, V384_HCHAR, 
  827. X       V384_VTIC, V384_HTIC, V384_init, V384_reset, 
  828. X       V384_text, null_scale, V384_graphics, V384_move, V384_vector, 
  829. X       V384_linetype, V384_put_text, null_text_angle, 
  830. X       null_justify_text, do_point, do_arrow}
  831. X#endif
  832. X};
  833. X
  834. X#define TERMCOUNT (sizeof(term_tbl)/sizeof(struct termentry))
  835. X
  836. X
  837. Xlist_terms()
  838. X{
  839. Xregister int i;
  840. X
  841. X    fprintf(stderr,"\nAvailable terminal types:\n");
  842. X    for (i = 0; i < TERMCOUNT; i++)
  843. X        fprintf(stderr,"  %15s  %s\n",
  844. X               term_tbl[i].name, term_tbl[i].description);
  845. X    (void) putc('\n',stderr);
  846. X}
  847. X
  848. X
  849. X/* set_term: get terminal number from name on command line */
  850. X/* will change 'term' variable if successful */
  851. Xint                        /* term number */
  852. Xset_term(c_token)
  853. Xint c_token;
  854. X{
  855. X    register int t;
  856. X    char *input_name;
  857. X
  858. X    if (!token[c_token].is_token)
  859. X     int_error("terminal name expected",c_token);
  860. X    t = -1;
  861. X    input_name = input_line + token[c_token].start_index;
  862. X    t = change_term(input_name, token[c_token].length);
  863. X    if (t == -1)
  864. X     int_error("unknown terminal type; type just 'set terminal' for a list",
  865. X             c_token);
  866. X    if (t == -2)
  867. X     int_error("ambiguous terminal name; type just 'set terminal' for a list",
  868. X             c_token);
  869. X
  870. X    /* otherwise the type was changed */
  871. X
  872. X    return(t);
  873. X}
  874. X
  875. X/* change_term: get terminal number from name and set terminal type */
  876. X/* returns -1 if unknown, -2 if ambiguous, >=0 is terminal number */
  877. Xint
  878. Xchange_term(name, length)
  879. X    char *name;
  880. X    int length;
  881. X{
  882. X    int i, t = -1;
  883. X
  884. X    for (i = 0; i < TERMCOUNT; i++) {
  885. X       if (!strncmp(name,term_tbl[i].name,length)) {
  886. X          if (t != -1)
  887. X            return(-2);    /* ambiguous */
  888. X          t = i;
  889. X       }
  890. X    }
  891. X
  892. X    if (t == -1)            /* unknown */
  893. X     return(t);
  894. X
  895. X    /* Success: set terminal type now */
  896. X
  897. X    /* Special handling for unixplot term type */
  898. X    if (!strncmp("unixplot",name,sizeof(unixplot))) {
  899. X       UP_redirect (2);  /* Redirect actual stdout for unixplots */
  900. X    } else if (unixplot) {
  901. X       UP_redirect (3);  /* Put stdout back together again. */
  902. X    }
  903. X
  904. X    term = t;
  905. X    term_init = FALSE;
  906. X    name = term_tbl[term].name;
  907. X
  908. X    if (interactive)
  909. X     fprintf(stderr, "Terminal type set to '%s'\n", name);
  910. X
  911. X    return(t);
  912. X}
  913. X
  914. X/*
  915. X   Routine to detect what terminal is being used (or do anything else
  916. X   that would be nice).  One anticipated (or allowed for) side effect
  917. X   is that the global ``term'' may be set. 
  918. X   The environment variable GNUTERM is checked first; if that does
  919. X   not exist, then the terminal hardware is checked, if possible, 
  920. X   and finally, we can check $TERM for some kinds of terminals.
  921. X*/
  922. X/* thanks to osupyr!alden (Dave Alden) for the original GNUTERM code */
  923. Xinit_terminal()
  924. X{
  925. X    char *term_name = NULL;
  926. X    int t;
  927. X#ifdef SUN  /* turbo C doesn't like unused variables */
  928. X    char *term = NULL;        /* from TERM environment var */
  929. X#endif
  930. X    char *gnuterm = NULL;
  931. X
  932. X    /* GNUTERM environment variable is primary */
  933. X    gnuterm = getenv("GNUTERM");
  934. X    if (gnuterm != (char *)NULL)
  935. X     term_name = gnuterm;
  936. X    else {
  937. X#ifdef __TURBOC__
  938. X       term_name = turboc_init();
  939. X#endif
  940. X       
  941. X#ifdef vms
  942. X       term_name = vms_init();
  943. X#endif
  944. X       
  945. X#ifdef SUN
  946. X       term = getenv("TERM");    /* try $TERM */
  947. X       if (term_name == (char *)NULL
  948. X          && term != (char *)NULL && strcmp(term, "sun") == 0)
  949. X        term_name = "sun";
  950. X#endif /* sun */
  951. X
  952. X#ifdef UNIXPC
  953. X           if (iswind() == 0) {
  954. X              term_name = "unixpc";
  955. X           }
  956. X#endif /* unixpc */
  957. X    }
  958. X
  959. X    /* We have a name, try to set term type */
  960. X    if (term_name != NULL && *term_name != '\0') {
  961. X       t = change_term(term_name, strlen(term_name));
  962. X       if (t == -1)
  963. X        fprintf(stderr, "Unknown terminal name '%s'\n", term_name);
  964. X       else if (t == -2)
  965. X        fprintf(stderr, "Ambiguous terminal name '%s'\n", term_name);
  966. X       else                /* successful */
  967. X        ;
  968. X    }
  969. X}
  970. X
  971. X
  972. X#ifdef __TURBOC__
  973. Xchar *
  974. Xturboc_init()
  975. X{
  976. X  int g_driver,g_mode;
  977. X  char far *c1,*c2;
  978. X  char *term_name = NULL;
  979. X
  980. X/* Some of this code including BGI drivers is copyright Borland Intl. */
  981. X    g_driver=DETECT;
  982. X          get_path();
  983. X        initgraph(&g_driver,&g_mode,path);
  984. X        c1=getdrivername();
  985. X        c2=getmodename(g_mode);
  986. X          switch (g_driver){
  987. X            case -2: fprintf(stderr,"Graphics card not detected.\n");
  988. X                     break;
  989. X            case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  990. X                     break;
  991. X            case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  992. X                     break;
  993. X            case -5: fprintf(stderr,"Insufficient memory to load ",
  994. X                             "graphics driver.");
  995. X                     break;
  996. X            case 1 : term_name = "cga";
  997. X                     break;
  998. X            case 2 : term_name = "mcga";
  999. X                     break;
  1000. X            case 3 : 
  1001. X            case 4 : term_name = "egalib";
  1002. X                     break;
  1003. X            case 7 : term_name = "hercules";
  1004. X                     break;
  1005. X            case 9 : term_name = "vgalib";
  1006. X                     break;
  1007. X            }
  1008. X        closegraph();
  1009. X    fprintf(stderr,"\tTC Graphics, driver %s  mode %s\n",c1,c2);
  1010. X  return(term_name);
  1011. X}
  1012. X#endif /* __TURBOC__ */
  1013. X
  1014. X#ifdef vms
  1015. X/*
  1016. X * Determine if we have a regis terminal.  
  1017. X * and do a SET TERM/NOWRAP
  1018. X*/
  1019. Xchar *
  1020. Xvms_init()
  1021. X{
  1022. Xchar *term_str="tt:";
  1023. Xtypedef struct
  1024. X          {
  1025. X          short cond_value;
  1026. X          short count;
  1027. X          int info;
  1028. X          }  status_block;
  1029. Xtypedef struct
  1030. X          {
  1031. X          short buffer_len;
  1032. X          short item_code;
  1033. X          int buffer_addr;
  1034. X          int ret_len_addr;
  1035. X          }  item_desc;
  1036. Xstruct {
  1037. X    item_desc dev_type;
  1038. X      int terminator;
  1039. X   }  dvi_list;
  1040. X   int status, dev_type, zero=0;
  1041. X   char buffer[255];
  1042. X   $DESCRIPTOR(term_desc, term_str);
  1043. X
  1044. X/* This does the equivalent of a SET TERM/NOWRAP command */
  1045. X    int i;
  1046. X    sys$assign(&sysoutput_desc,&chan,0,0);
  1047. X    sys$qiow(0,chan,IO$_SENSEMODE,0,0,0,old_char_buf,12,0,0,0,0);
  1048. X    for (i = 0 ; i < 3 ; ++i) new_char_buf[i] = old_char_buf[i];
  1049. X    new_char_buf[1] &= ~(TT$M_WRAP);
  1050. X    sys$qiow(0,chan,IO$_SETMODE,0,0,0,new_char_buf,12,0,0,0,0);
  1051. X    sys$dassgn(chan);
  1052. X
  1053. X/* set up dvi item list */
  1054. X    dvi_list.dev_type.buffer_len = 4;
  1055. X    dvi_list.dev_type.item_code = DVI$_TT_REGIS;
  1056. X    dvi_list.dev_type.buffer_addr = &dev_type;
  1057. X    dvi_list.dev_type.ret_len_addr = 0;
  1058. X
  1059. X    dvi_list.terminator = 0;
  1060. X
  1061. X/* See what type of terminal we have. */
  1062. X    status = SYS$GETDVIW (0, 0, &term_desc, &dvi_list, 0, 0, 0, 0);
  1063. X    if ((status & 1) && dev_type) {
  1064. X        return("regis");
  1065. X    }
  1066. X     return(NULL);
  1067. X}
  1068. X
  1069. X
  1070. X
  1071. X/*
  1072. X *  vms_reset
  1073. X */
  1074. Xvms_reset()
  1075. X{
  1076. X    /* set wrap back to original state */
  1077. X    sys$assign(&sysoutput_desc,&chan,0,0);
  1078. X    sys$qiow(0,chan,IO$_SETMODE,0,0,0,old_char_buf,12,0,0,0,0);
  1079. X    sys$dassgn(chan);
  1080. X}
  1081. X#endif /* VMS */
  1082. X
  1083. X/*
  1084. X    This is always defined so we don't have to have command.c know if it
  1085. X    is there or not.
  1086. X*/
  1087. X#ifndef UNIXPLOT
  1088. XUP_redirect(caller) int caller; 
  1089. X{
  1090. X    caller = caller;    /* to stop Turbo C complaining 
  1091. X                         * about caller not being used */
  1092. X}
  1093. X#else
  1094. XUP_redirect (caller)
  1095. Xint caller;
  1096. X/*
  1097. X    Unixplot can't really write to outfile--it wants to write to stdout.
  1098. X    This is normally ok, but the original design of gnuplot gives us
  1099. X    little choice.  Originally users of unixplot had to anticipate
  1100. X    their needs and redirect all I/O to a file...  Not very gnuplot-like.
  1101. X
  1102. X    caller:  1 - called from SET OUTPUT "FOO.OUT"
  1103. X             2 - called from SET TERM UNIXPLOT
  1104. X             3 - called from SET TERM other
  1105. X             4 - called from SET OUTPUT
  1106. X*/
  1107. X{
  1108. X    switch (caller) {
  1109. X    case 1:
  1110. X    /* Don't save, just replace stdout w/outfile (save was already done). */
  1111. X        if (unixplot)
  1112. X            *(stdout) = *(outfile);  /* Copy FILE structure */
  1113. X    break;
  1114. X    case 2:
  1115. X        if (!unixplot) {
  1116. X            fflush(stdout);
  1117. X            save_stdout = *(stdout);
  1118. X            *(stdout) = *(outfile);  /* Copy FILE structure */
  1119. X            unixplot = 1;
  1120. X        }
  1121. X    break;
  1122. X    case 3:
  1123. X    /* New terminal in use--put stdout back to original. */
  1124. X        closepl();
  1125. X        fflush(stdout);
  1126. X        *(stdout) = save_stdout;  /* Copy FILE structure */
  1127. X        unixplot = 0;
  1128. X    break;
  1129. X    case 4:
  1130. X    /*  User really wants to go to normal output... */
  1131. X        if (unixplot) {
  1132. X            fflush(stdout);
  1133. X            *(stdout) = save_stdout;  /* Copy FILE structure */
  1134. X        }
  1135. X    break;
  1136. X    }
  1137. X}
  1138. X#endif
  1139. X
  1140. X
  1141. X/* test terminal by drawing border and text */
  1142. X/* called from command test */
  1143. Xtest_term()
  1144. X{
  1145. X    register struct termentry *t = &term_tbl[term];
  1146. X    char *str;
  1147. X    int x,y, xl,yl, i;
  1148. X    char label[MAX_ID_LEN];
  1149. X
  1150. X    if (!term_init) {
  1151. X       (*t->init)();
  1152. X       term_init = TRUE;
  1153. X    }
  1154. X    screen_ok = FALSE;
  1155. X    (*t->graphics)();
  1156. X    /* border linetype */
  1157. X    (*t->linetype)(-2);
  1158. X    (*t->move)(0,0);
  1159. X    (*t->vector)(t->xmax-1,0);
  1160. X    (*t->vector)(t->xmax-1,t->ymax-1);
  1161. X    (*t->vector)(0,t->ymax-1);
  1162. X    (*t->vector)(0,0);
  1163. X    (void) (*t->justify_text)(LEFT);
  1164. X    (*t->put_text)(t->h_char*5,t->ymax-t->v_char*3,"Terminal Test");
  1165. X    /* axis linetype */
  1166. X    (*t->linetype)(-1);
  1167. X    (*t->move)(t->xmax/2,0);
  1168. X    (*t->vector)(t->xmax/2,t->ymax-1);
  1169. X    (*t->move)(0,t->ymax/2);
  1170. X    (*t->vector)(t->xmax-1,t->ymax/2);
  1171. X    /* test width and height of characters */
  1172. X    (*t->linetype)(-2);
  1173. X    (*t->move)(  t->xmax/2-t->h_char*10,t->ymax/2+t->v_char/2);
  1174. X    (*t->vector)(t->xmax/2+t->h_char*10,t->ymax/2+t->v_char/2);
  1175. X    (*t->vector)(t->xmax/2+t->h_char*10,t->ymax/2-t->v_char/2);
  1176. X    (*t->vector)(t->xmax/2-t->h_char*10,t->ymax/2-t->v_char/2);
  1177. X    (*t->vector)(t->xmax/2-t->h_char*10,t->ymax/2+t->v_char/2);
  1178. X    (*t->put_text)(t->xmax/2-t->h_char*10,t->ymax/2,
  1179. X        "12345678901234567890");
  1180. X    /* test justification */
  1181. X    (void) (*t->justify_text)(LEFT);
  1182. X    (*t->put_text)(t->xmax/2,t->ymax/2+t->v_char*6,"left justified");
  1183. X    str = "centre+d text";
  1184. X    if ((*t->justify_text)(CENTRE))
  1185. X        (*t->put_text)(t->xmax/2,
  1186. X                t->ymax/2+t->v_char*5,str);
  1187. X    else
  1188. X        (*t->put_text)(t->xmax/2-strlen(str)*t->h_char/2,
  1189. X                t->ymax/2+t->v_char*5,str);
  1190. X    str = "right justified";
  1191. X    if ((*t->justify_text)(RIGHT))
  1192. X        (*t->put_text)(t->xmax/2,
  1193. X                t->ymax/2+t->v_char*4,str);
  1194. X    else
  1195. X        (*t->put_text)(t->xmax/2-strlen(str)*t->h_char,
  1196. X                t->ymax/2+t->v_char*4,str);
  1197. X    /* test text angle */
  1198. X    str = "rotated ce+ntred text";
  1199. X    if ((*t->text_angle)(1)) {
  1200. X        if ((*t->justify_text)(CENTRE))
  1201. X            (*t->put_text)(t->v_char,
  1202. X                t->ymax/2,str);
  1203. X        else
  1204. X            (*t->put_text)(t->v_char,
  1205. X                t->ymax/2-strlen(str)*t->h_char/2,str);
  1206. X    }
  1207. X    else {
  1208. X        (void) (*t->justify_text)(LEFT);
  1209. X        (*t->put_text)(t->h_char*2,t->ymax/2-t->v_char*2,"Can't rotate text");
  1210. X    }
  1211. X    (void) (*t->justify_text)(LEFT);
  1212. X    (void) (*t->text_angle)(0);
  1213. X    /* test tic size */
  1214. X    (*t->move)(t->xmax/2+t->h_tic*2,0);
  1215. X    (*t->vector)(t->xmax/2+t->h_tic*2,t->v_tic);
  1216. X    (*t->move)(t->xmax/2,t->v_tic*2);
  1217. X    (*t->vector)(t->xmax/2+t->h_tic,t->v_tic*2);
  1218. X    (*t->put_text)(t->xmax/2+t->h_tic*2,t->v_tic*2+t->v_char/2,"test tics");
  1219. X    /* test line and point types */
  1220. X    x = t->xmax - t->h_char*4 - t->h_tic*4;
  1221. X    y = t->ymax - t->v_char;
  1222. X    for ( i = -2; y > t->v_char; i++ ) {
  1223. X        (*t->linetype)(i);
  1224. X        (void) sprintf(label,"%d",i);
  1225. X        if ((*t->justify_text)(RIGHT))
  1226. X            (*t->put_text)(x,y,label);
  1227. X        else
  1228. X            (*t->put_text)(x-strlen(label)*t->h_char,y,label);
  1229. X        (*t->move)(x+t->h_char,y);
  1230. X        (*t->vector)(x+t->h_char*4,y);
  1231. X        if ( i >= -1 )
  1232. X            (*t->point)(x+t->h_char*4+t->h_tic*2,y,i);
  1233. X        y -= t->v_char;
  1234. X    }
  1235. X    /* test some arrows */
  1236. X    (*t->linetype)(0);
  1237. X    x = t->xmax/4;
  1238. X    y = t->ymax/4;
  1239. X    xl = t->h_tic*5;
  1240. X    yl = t->v_tic*5;
  1241. X    (*t->arrow)(x,y,x+xl,y);
  1242. X    (*t->arrow)(x,y,x+xl,y+yl);
  1243. X    (*t->arrow)(x,y,x,y+yl);
  1244. X    (*t->arrow)(x,y,x-xl,y+yl);
  1245. X    (*t->arrow)(x,y,x-xl,y);
  1246. X    (*t->arrow)(x,y,x-xl,y-yl);
  1247. X    (*t->arrow)(x,y,x,y-yl);
  1248. X    (*t->arrow)(x,y,x+xl,y-yl);
  1249. X    /* and back into text mode */
  1250. X    (*t->text)();
  1251. X}
  1252. *-*-END-of-term.c-*-*
  1253. echo x - util.c
  1254. sed 's/^X//' >util.c <<'*-*-END-of-util.c-*-*'
  1255. X/* GNUPLOT - util.c */
  1256. X/*
  1257. X * Copyright (C) 1986, 1987, 1990   Thomas Williams, Colin Kelley
  1258. X *
  1259. X * Permission to use, copy, and distribute this software and its
  1260. X * documentation for any purpose with or without fee is hereby granted, 
  1261. X * provided that the above copyright notice appear in all copies and 
  1262. X * that both that copyright notice and this permission notice appear 
  1263. X * in supporting documentation.
  1264. X *
  1265. X * Permission to modify the software is granted, but not the right to
  1266. X * distribute the modified code.  Modifications are to be distributed 
  1267. X * as patches to released version.
  1268. X *  
  1269. X * This software  is provided "as is" without express or implied warranty.
  1270. X * 
  1271. X *
  1272. X * AUTHORS
  1273. X * 
  1274. X *   Original Software:
  1275. X *     Thomas Williams,  Colin Kelley.
  1276. X * 
  1277. X *   Gnuplot 2.0 additions:
  1278. X *       Russell Lang, Dave Kotz, John Campbell.
  1279. X * 
  1280. X * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  1281. X * 
  1282. X */
  1283. X
  1284. X#include <ctype.h>
  1285. X#include <setjmp.h>
  1286. X#include <stdio.h>
  1287. X#include <errno.h>
  1288. X#include "plot.h"
  1289. X
  1290. XBOOLEAN screen_ok;
  1291. X    /* TRUE if command just typed; becomes FALSE whenever we
  1292. X        send some other output to screen.  If FALSE, the command line
  1293. X        will be echoed to the screen before the ^ error message. */
  1294. X
  1295. X#ifndef vms
  1296. X#ifndef __ZTC__
  1297. Xextern int errno;
  1298. Xextern int sys_nerr;
  1299. Xextern char *sys_errlist[];
  1300. X#endif
  1301. X#endif /* vms */
  1302. X
  1303. Xextern char input_line[];
  1304. Xextern struct lexical_unit token[];
  1305. Xextern jmp_buf env;    /* from plot.c */
  1306. Xextern int inline_num;        /* from command.c */
  1307. Xextern BOOLEAN interactive;    /* from plot.c */
  1308. Xextern char *infile_name;    /* from plot.c */
  1309. X
  1310. X/*
  1311. X * equals() compares string value of token number t_num with str[], and
  1312. X *   returns TRUE if they are identical.
  1313. X */
  1314. Xequals(t_num, str)
  1315. Xint t_num;
  1316. Xchar *str;
  1317. X{
  1318. Xregister int i;
  1319. X
  1320. X    if (!token[t_num].is_token)
  1321. X        return(FALSE);                /* must be a value--can't be equal */
  1322. X    for (i = 0; i < token[t_num].length; i++) {
  1323. X        if (input_line[token[t_num].start_index+i] != str[i])
  1324. X            return(FALSE);
  1325. X        }
  1326. X    /* now return TRUE if at end of str[], FALSE if not */
  1327. X    return(str[i] == '\0');
  1328. X}
  1329. X
  1330. X
  1331. X
  1332. X/*
  1333. X * almost_equals() compares string value of token number t_num with str[], and
  1334. X *   returns TRUE if they are identical up to the first $ in str[].
  1335. X */
  1336. Xalmost_equals(t_num, str)
  1337. Xint t_num;
  1338. Xchar *str;
  1339. X{
  1340. Xregister int i;
  1341. Xregister int after = 0;
  1342. Xregister start = token[t_num].start_index;
  1343. Xregister length = token[t_num].length;
  1344. X
  1345. X    if (!token[t_num].is_token)
  1346. X        return(FALSE);                /* must be a value--can't be equal */
  1347. X    for (i = 0; i < length + after; i++) {
  1348. X        if (str[i] != input_line[start + i]) {
  1349. X            if (str[i] != '$')
  1350. X                return(FALSE);
  1351. X            else {
  1352. X                after = 1;
  1353. X                start--;    /* back up token ptr */
  1354. X                }
  1355. X            }
  1356. X        }
  1357. X
  1358. X    /* i now beyond end of token string */
  1359. X
  1360. X    return(after || str[i] == '$' || str[i] == '\0');
  1361. X}
  1362. X
  1363. X
  1364. X
  1365. Xisstring(t_num)
  1366. Xint t_num;
  1367. X{
  1368. X    
  1369. X    return(token[t_num].is_token &&
  1370. X           (input_line[token[t_num].start_index] == '\'' ||
  1371. X           input_line[token[t_num].start_index] == '\"'));
  1372. X}
  1373. X
  1374. X
  1375. Xisnumber(t_num)
  1376. Xint t_num;
  1377. X{
  1378. X    return(!token[t_num].is_token);
  1379. X}
  1380. X
  1381. X
  1382. Xisletter(t_num)
  1383. Xint t_num;
  1384. X{
  1385. X    return(token[t_num].is_token &&
  1386. X            (isalpha(input_line[token[t_num].start_index])));
  1387. X}
  1388. X
  1389. X
  1390. X/*
  1391. X * is_definition() returns TRUE if the next tokens are of the form
  1392. X *   identifier =
  1393. X *        -or-
  1394. X *   identifier ( identifer ) =
  1395. X */
  1396. Xis_definition(t_num)
  1397. Xint t_num;
  1398. X{
  1399. X    return (isletter(t_num) &&
  1400. X            (equals(t_num+1,"=") ||            /* variable */
  1401. X            (equals(t_num+1,"(") &&        /* function */
  1402. X             isletter(t_num+2)   &&
  1403. X             equals(t_num+3,")") &&
  1404. X             equals(t_num+4,"=") )
  1405. X        ));
  1406. X}
  1407. X
  1408. X
  1409. X
  1410. X/*
  1411. X * copy_str() copies the string in token number t_num into str, appending
  1412. X *   a null.  No more than MAX_ID_LEN chars are copied.
  1413. X */
  1414. Xcopy_str(str, t_num)
  1415. Xchar str[];
  1416. Xint t_num;
  1417. X{
  1418. Xregister int i = 0;
  1419. Xregister int start = token[t_num].start_index;
  1420. Xregister int count;
  1421. X
  1422. X    if ((count = token[t_num].length) > MAX_ID_LEN)
  1423. X        count = MAX_ID_LEN;
  1424. X    do {
  1425. X        str[i++] = input_line[start++];
  1426. X        } while (i != count);
  1427. X    str[i] = '\0';
  1428. X}
  1429. X
  1430. X
  1431. X/*
  1432. X * quote_str() does the same thing as copy_str, except it ignores the
  1433. X *   quotes at both ends.  This seems redundant, but is done for
  1434. X *   efficency.
  1435. X */
  1436. Xquote_str(str, t_num)
  1437. Xchar str[];
  1438. Xint t_num;
  1439. X{
  1440. Xregister int i = 0;
  1441. Xregister int start = token[t_num].start_index + 1;
  1442. Xregister int count;
  1443. X
  1444. X    if ((count = token[t_num].length - 2) > MAX_ID_LEN)
  1445. X        count = MAX_ID_LEN;
  1446. X    if (count>0) {
  1447. X        do {
  1448. X            str[i++] = input_line[start++];
  1449. X            } while (i != count);
  1450. X    }
  1451. X    str[i] = '\0';
  1452. X}
  1453. X
  1454. X
  1455. X/*
  1456. X * quotel_str() does the same thing as quote_str, except it uses
  1457. X * MAX_LINE_LEN instead of MAX_ID_LEN. 
  1458. X */ 
  1459. Xquotel_str(str, t_num) 
  1460. Xchar str[]; 
  1461. Xint t_num; 
  1462. X{
  1463. Xregister int i = 0;
  1464. Xregister int start = token[t_num].start_index + 1;
  1465. Xregister int count;
  1466. X
  1467. X    if ((count = token[t_num].length - 2) > MAX_LINE_LEN)
  1468. X        count = MAX_LINE_LEN;
  1469. X    if (count>0) {
  1470. X        do {
  1471. X            str[i++] = input_line[start++];
  1472. X            } while (i != count);
  1473. X    }
  1474. X    str[i] = '\0';
  1475. X}
  1476. X
  1477. X
  1478. X/*
  1479. X *    capture() copies into str[] the part of input_line[] which lies between
  1480. X *    the begining of token[start] and end of token[end].
  1481. X */
  1482. Xcapture(str,start,end)
  1483. Xchar str[];
  1484. Xint start,end;
  1485. X{
  1486. Xregister int i,e;
  1487. X
  1488. X    e = token[end].start_index + token[end].length;
  1489. X    for (i = token[start].start_index; i < e && input_line[i] != '\0'; i++)
  1490. X        *str++ = input_line[i];
  1491. X    *str = '\0';
  1492. X}
  1493. X
  1494. X
  1495. X/*
  1496. X *    m_capture() is similar to capture(), but it mallocs storage for the
  1497. X *  string.
  1498. X */
  1499. Xm_capture(str,start,end)
  1500. Xchar **str;
  1501. Xint start,end;
  1502. X{
  1503. Xregister int i,e;
  1504. Xregister char *s;
  1505. X
  1506. X    if (*str)        /* previous pointer to malloc'd memory there */
  1507. X        free(*str);
  1508. X    e = token[end].start_index + token[end].length;
  1509. X    *str = alloc((unsigned int)(e - token[start].start_index + 1), "string");
  1510. X     s = *str;
  1511. X     for (i = token[start].start_index; i < e && input_line[i] != '\0'; i++)
  1512. X      *s++ = input_line[i];
  1513. X     *s = '\0';
  1514. X}
  1515. X
  1516. X
  1517. X/*
  1518. X *    m_quote_capture() is similar to m_capture(), but it removes
  1519. X    quotes from either end if the string.
  1520. X */
  1521. Xm_quote_capture(str,start,end)
  1522. Xchar **str;
  1523. Xint start,end;
  1524. X{
  1525. Xregister int i,e;
  1526. Xregister char *s;
  1527. X
  1528. X    if (*str)        /* previous pointer to malloc'd memory there */
  1529. X        free(*str);
  1530. X    e = token[end].start_index + token[end].length-1;
  1531. X    *str = alloc((unsigned int)(e - token[start].start_index + 1), "string");
  1532. X     s = *str;
  1533. X    for (i = token[start].start_index + 1; i < e && input_line[i] != '\0'; i++)
  1534. X     *s++ = input_line[i];
  1535. X    *s = '\0';
  1536. X}
  1537. X
  1538. X
  1539. Xconvert(val_ptr, t_num)
  1540. Xstruct value *val_ptr;
  1541. Xint t_num;
  1542. X{
  1543. X    *val_ptr = token[t_num].l_val;
  1544. X}
  1545. X
  1546. X
  1547. X
  1548. Xdisp_value(fp,val)
  1549. XFILE *fp;
  1550. Xstruct value *val;
  1551. X{
  1552. X        switch(val->type) {
  1553. X            case INT:
  1554. X                fprintf(fp,"%d",val->v.int_val);
  1555. X                break;
  1556. X            case CMPLX:
  1557. X                if (val->v.cmplx_val.imag != 0.0 )
  1558. X                    fprintf(fp,"{%g, %g}",
  1559. X                        val->v.cmplx_val.real,val->v.cmplx_val.imag);
  1560. X                else
  1561. X                    fprintf(fp,"%g", val->v.cmplx_val.real);
  1562. X                break;
  1563. X            default:
  1564. X                int_error("unknown type in disp_value()",NO_CARET);
  1565. X        }
  1566. X}
  1567. X
  1568. X
  1569. Xdouble
  1570. Xreal(val)        /* returns the real part of val */
  1571. Xstruct value *val;
  1572. X{
  1573. X    switch(val->type) {
  1574. X        case INT:
  1575. X            return((double) val->v.int_val);
  1576. X        case CMPLX:
  1577. X            return(val->v.cmplx_val.real);
  1578. X    }
  1579. X    int_error("unknown type in real()",NO_CARET);
  1580. X    /* NOTREACHED */
  1581. X}
  1582. X
  1583. X
  1584. Xdouble
  1585. Ximag(val)        /* returns the imag part of val */
  1586. Xstruct value *val;
  1587. X{
  1588. X    switch(val->type) {
  1589. X        case INT:
  1590. X            return(0.0);
  1591. X        case CMPLX:
  1592. X            return(val->v.cmplx_val.imag);
  1593. X    }
  1594. X    int_error("unknown type in real()",NO_CARET);
  1595. X    /* NOTREACHED */
  1596. X}
  1597. X
  1598. X
  1599. X
  1600. Xdouble
  1601. Xmagnitude(val)        /* returns the magnitude of val */
  1602. Xstruct value *val;
  1603. X{
  1604. X    double sqrt();
  1605. X
  1606. X    switch(val->type) {
  1607. X        case INT:
  1608. X            return((double) abs(val->v.int_val));
  1609. X        case CMPLX:
  1610. X            return(sqrt(val->v.cmplx_val.real*
  1611. X                    val->v.cmplx_val.real +
  1612. X                    val->v.cmplx_val.imag*
  1613. X                    val->v.cmplx_val.imag));
  1614. X    }
  1615. X    int_error("unknown type in magnitude()",NO_CARET);
  1616. X    /* NOTREACHED */
  1617. X}
  1618. X
  1619. X
  1620. X
  1621. Xdouble
  1622. Xangle(val)        /* returns the angle of val */
  1623. Xstruct value *val;
  1624. X{
  1625. X    double atan2();
  1626. X
  1627. X    switch(val->type) {
  1628. X        case INT:
  1629. X            return((val->v.int_val > 0) ? 0.0 : Pi);
  1630. X        case CMPLX:
  1631. X            if (val->v.cmplx_val.imag == 0.0) {
  1632. X                if (val->v.cmplx_val.real >= 0.0)
  1633. X                    return(0.0);
  1634. X                else
  1635. X                    return(Pi);
  1636. X            }
  1637. X            return(atan2(val->v.cmplx_val.imag,
  1638. X                     val->v.cmplx_val.real));
  1639. X    }
  1640. X    int_error("unknown type in angle()",NO_CARET);
  1641. X    /* NOTREACHED */
  1642. X}
  1643. X
  1644. X
  1645. Xstruct value *
  1646. Xcomplex(a,realpart,imagpart)
  1647. Xstruct value *a;
  1648. Xdouble realpart, imagpart;
  1649. X{
  1650. X    a->type = CMPLX;
  1651. X    a->v.cmplx_val.real = realpart;
  1652. X    a->v.cmplx_val.imag = imagpart;
  1653. X    return(a);
  1654. X}
  1655. X
  1656. X
  1657. Xstruct value *
  1658. Xinteger(a,i)
  1659. Xstruct value *a;
  1660. Xint i;
  1661. X{
  1662. X    a->type = INT;
  1663. X    a->v.int_val = i;
  1664. X    return(a);
  1665. X}
  1666. X
  1667. X
  1668. X
  1669. Xos_error(str,t_num)
  1670. Xchar str[];
  1671. Xint t_num;
  1672. X{
  1673. X#ifdef vms
  1674. Xstatic status[2] = {1, 0};        /* 1 is count of error msgs */
  1675. X#endif
  1676. X
  1677. Xregister int i;
  1678. X
  1679. X    /* reprint line if screen has been written to */
  1680. X
  1681. X    if (t_num != NO_CARET) {        /* put caret under error */
  1682. X        if (!screen_ok)
  1683. X            fprintf(stderr,"\n%s%s\n", PROMPT, input_line);
  1684. X
  1685. X        for (i = 0; i < sizeof(PROMPT) - 1; i++)
  1686. X            (void) putc(' ',stderr);
  1687. X        for (i = 0; i < token[t_num].start_index; i++) {
  1688. X            (void) putc((input_line[i] == '\t') ? '\t' : ' ',stderr);
  1689. X            }
  1690. X        (void) putc('^',stderr);
  1691. X        (void) putc('\n',stderr);
  1692. X    }
  1693. X
  1694. X    for (i = 0; i < sizeof(PROMPT) - 1; i++)
  1695. X        (void) putc(' ',stderr);
  1696. X    fprintf(stderr,"%s\n",str);
  1697. X
  1698. X    for (i = 0; i < sizeof(PROMPT) - 1; i++)
  1699. X        (void) putc(' ',stderr);
  1700. X     if (!interactive)
  1701. X      if (infile_name != NULL)
  1702. X        fprintf(stderr,"\"%s\", line %d: ", infile_name, inline_num);
  1703. X      else
  1704. X        fprintf(stderr,"line %d: ", inline_num);
  1705. X
  1706. X
  1707. X#ifdef vms
  1708. X    status[1] = vaxc$errno;
  1709. X    sys$putmsg(status);
  1710. X    (void) putc('\n',stderr);
  1711. X#else
  1712. X#ifdef __ZTC__
  1713. X    fprintf(stderr,"error number %d\n\n",errno);
  1714. X#else
  1715. X    if (errno >= sys_nerr)
  1716. X        fprintf(stderr, "unknown errno %d\n\n", errno);
  1717. X    else
  1718. X        fprintf(stderr,"(%s)\n\n",sys_errlist[errno]);
  1719. X#endif
  1720. X#endif
  1721. X
  1722. X    longjmp(env, TRUE);    /* bail out to command line */
  1723. X}
  1724. X
  1725. X
  1726. Xint_error(str,t_num)
  1727. Xchar str[];
  1728. Xint t_num;
  1729. X{
  1730. Xregister int i;
  1731. X
  1732. X    /* reprint line if screen has been written to */
  1733. X
  1734. X    if (t_num != NO_CARET) {        /* put caret under error */
  1735. X        if (!screen_ok)
  1736. X            fprintf(stderr,"\n%s%s\n", PROMPT, input_line);
  1737. X
  1738. X        for (i = 0; i < sizeof(PROMPT) - 1; i++)
  1739. X            (void) putc(' ',stderr);
  1740. X        for (i = 0; i < token[t_num].start_index; i++) {
  1741. X            (void) putc((input_line[i] == '\t') ? '\t' : ' ',stderr);
  1742. X            }
  1743. X        (void) putc('^',stderr);
  1744. X        (void) putc('\n',stderr);
  1745. X    }
  1746. X
  1747. X    for (i = 0; i < sizeof(PROMPT) - 1; i++)
  1748. X        (void) putc(' ',stderr);
  1749. X     if (!interactive)
  1750. X      if (infile_name != NULL)
  1751. X        fprintf(stderr,"\"%s\", line %d: ", infile_name, inline_num);
  1752. X      else
  1753. X        fprintf(stderr,"line %d: ", inline_num);
  1754. X     fprintf(stderr,"%s\n\n", str);
  1755. X
  1756. X    longjmp(env, TRUE);    /* bail out to command line */
  1757. X}
  1758. X
  1759. X/* Lower-case the given string (DFK) */
  1760. X/* Done in place. */
  1761. Xvoid
  1762. Xlower_case(s)
  1763. X     char *s;
  1764. X{
  1765. X  register char *p = s;
  1766. X
  1767. X  while (*p != '\0') {
  1768. X    if (isupper(*p))
  1769. X     *p = tolower(*p);
  1770. X    p++;
  1771. X  }
  1772. X}
  1773. X
  1774. X/* Squash spaces in the given string (DFK) */
  1775. X/* That is, reduce all multiple white-space chars to single spaces */
  1776. X/* Done in place. */
  1777. Xvoid
  1778. Xsquash_spaces(s)
  1779. X     char *s;
  1780. X{
  1781. X  register char *r = s;        /* reading point */
  1782. X  register char *w = s;        /* writing point */
  1783. X  BOOLEAN space = FALSE;        /* TRUE if we've already copied a space */
  1784. X
  1785. X  for (w = r = s; *r != '\0'; r++) {
  1786. X     if (isspace(*r)) {
  1787. X        /* white space; only copy if we haven't just copied a space */
  1788. X        if (!space) {
  1789. X            space = TRUE;
  1790. X            *w++ = ' ';
  1791. X        }                /* else ignore multiple spaces */
  1792. X     } else {
  1793. X        /* non-space character; copy it and clear flag */
  1794. X        *w++ = *r;
  1795. X        space = FALSE;
  1796. X     }
  1797. X  }
  1798. X  *w = '\0';                /* null terminate string */
  1799. X}
  1800. X
  1801. *-*-END-of-util.c-*-*
  1802. echo x - version.c
  1803. sed 's/^X//' >version.c <<'*-*-END-of-version.c-*-*'
  1804. Xchar version[] = "2.0";
  1805. Xchar patchlevel[] = "0";
  1806. Xchar date[] = "Wed Mar  7 22:18:59 EST 1990";
  1807. X
  1808. X/* override in Makefile */
  1809. X#ifndef CONTACT
  1810. X# define CONTACT "pixar!bug-gnuplot@sun.com";
  1811. X#endif
  1812. Xchar bug_email[] = CONTACT;
  1813. *-*-END-of-version.c-*-*
  1814. exit
  1815.  
  1816.  
  1817.