home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_03 / term.c < prev    next >
Text File  |  1991-02-05  |  47KB  |  1,520 lines

  1. /* GNUPLOT - term.c */
  2. /*
  3.  * Copyright (C) 1986, 1987, 1990   Thomas Williams, Colin Kelley
  4.  *
  5.  * Permission to use, copy, and distribute this software and its
  6.  * documentation for any purpose with or without fee is hereby granted, 
  7.  * provided that the above copyright notice appear in all copies and 
  8.  * that both that copyright notice and this permission notice appear 
  9.  * in supporting documentation.
  10.  *
  11.  * Permission to modify the software is granted, but not the right to
  12.  * distribute the modified code.  Modifications are to be distributed 
  13.  * as patches to released version.
  14.  *  
  15.  * This software  is provided "as is" without express or implied warranty.
  16.  * 
  17.  *
  18.  * AUTHORS
  19.  * 
  20.  *   Original Software:
  21.  *     Thomas Williams,  Colin Kelley.
  22.  * 
  23.  *   Gnuplot 2.0 additions:
  24.  *       Russell Lang, Dave Kotz, John Campbell.
  25.  * 
  26.  * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
  27.  * 
  28.  */
  29.  
  30. #include <stdio.h>
  31. #include "plot.h"
  32. #include "setshow.h"
  33. #include "term.h"
  34. #include "bitmap.h"
  35.  
  36. /* for use by all drivers */
  37. #define sign(x) ((x) >= 0 ? 1 : -1)
  38. #define abs(x) ((x) >= 0 ? (x) : -(x))
  39. #define max(a,b) ((a) > (b) ? (a) : (b))
  40. #define min(a,b) ((a) < (b) ? (a) : (b))
  41.  
  42. BOOLEAN term_init;            /* true if terminal has been initialized */
  43.  
  44. extern FILE *outfile;
  45. extern char outstr[];
  46. extern BOOLEAN term_init;
  47. extern int term;
  48. extern float xsize, ysize;
  49.  
  50. extern char input_line[];
  51. extern struct lexical_unit token[];
  52.  
  53. extern BOOLEAN interactive;
  54.  
  55. /*
  56.  * instead of <strings.h>
  57.  */
  58. extern char *strcpy();
  59. extern int strlen(), strcmp();
  60.  
  61. char *getenv();
  62.  
  63. #ifdef __TURBOC__
  64. char *turboc_init();
  65. #endif
  66. #ifdef PC
  67. void reopen_binary();
  68. #endif
  69. #ifdef VMS
  70. char *vms_init();
  71. void vms_reset();
  72. void term_mode_tek();
  73. void term_mode_native();
  74. void term_pasthru();
  75. void term_nopasthru();
  76. void reopen_binary();
  77. void fflush_binary();
  78. #endif
  79.  
  80. /* This is needed because the unixplot library only writes to stdout. */
  81. #ifdef UNIXPLOT
  82. FILE save_stdout;
  83. #endif
  84. int unixplot=0;
  85.  
  86. #define NICE_LINE        0
  87. #define POINT_TYPES        6
  88.  
  89.  
  90. do_point(x,y,number)
  91. int x,y;
  92. int number;
  93. {
  94. register int htic,vtic;
  95. register struct termentry *t = &term_tbl[term];
  96.  
  97.      if (number < 0) {        /* do dot */
  98.         (*t->move)(x,y);
  99.         (*t->vector)(x,y);
  100.         return;
  101.     }
  102.  
  103.     number %= POINT_TYPES;
  104.     htic = (t->h_tic/2);    /* should be in term_tbl[] in later version */
  105.     vtic = (t->v_tic/2);    
  106.  
  107.     switch(number) {
  108.         case 0: /* do diamond */ 
  109.                 (*t->move)(x-htic,y);
  110.                 (*t->vector)(x,y-vtic);
  111.                 (*t->vector)(x+htic,y);
  112.                 (*t->vector)(x,y+vtic);
  113.                 (*t->vector)(x-htic,y);
  114.                 (*t->move)(x,y);
  115.                 (*t->vector)(x,y);
  116.                 break;
  117.         case 1: /* do plus */ 
  118.                 (*t->move)(x-htic,y);
  119.                 (*t->vector)(x-htic,y);
  120.                 (*t->vector)(x+htic,y);
  121.                 (*t->move)(x,y-vtic);
  122.                 (*t->vector)(x,y-vtic);
  123.                 (*t->vector)(x,y+vtic);
  124.                 break;
  125.         case 2: /* do box */ 
  126.                 (*t->move)(x-htic,y-vtic);
  127.                 (*t->vector)(x-htic,y-vtic);
  128.                 (*t->vector)(x+htic,y-vtic);
  129.                 (*t->vector)(x+htic,y+vtic);
  130.                 (*t->vector)(x-htic,y+vtic);
  131.                 (*t->vector)(x-htic,y-vtic);
  132.                 (*t->move)(x,y);
  133.                 (*t->vector)(x,y);
  134.                 break;
  135.         case 3: /* do X */ 
  136.                 (*t->move)(x-htic,y-vtic);
  137.                 (*t->vector)(x-htic,y-vtic);
  138.                 (*t->vector)(x+htic,y+vtic);
  139.                 (*t->move)(x-htic,y+vtic);
  140.                 (*t->vector)(x-htic,y+vtic);
  141.                 (*t->vector)(x+htic,y-vtic);
  142.                 break;
  143.         case 4: /* do triangle */ 
  144.                 (*t->move)(x,y+(4*vtic/3));
  145.                 (*t->vector)(x-(4*htic/3),y-(2*vtic/3));
  146.                 (*t->vector)(x+(4*htic/3),y-(2*vtic/3));
  147.                 (*t->vector)(x,y+(4*vtic/3));
  148.                 (*t->move)(x,y);
  149.                 (*t->vector)(x,y);
  150.                 break;
  151.         case 5: /* do star */ 
  152.                 (*t->move)(x-htic,y);
  153.                 (*t->vector)(x-htic,y);
  154.                 (*t->vector)(x+htic,y);
  155.                 (*t->move)(x,y-vtic);
  156.                 (*t->vector)(x,y-vtic);
  157.                 (*t->vector)(x,y+vtic);
  158.                 (*t->move)(x-htic,y-vtic);
  159.                 (*t->vector)(x-htic,y-vtic);
  160.                 (*t->vector)(x+htic,y+vtic);
  161.                 (*t->move)(x-htic,y+vtic);
  162.                 (*t->vector)(x-htic,y+vtic);
  163.                 (*t->vector)(x+htic,y-vtic);
  164.                 break;
  165.     }
  166. }
  167.  
  168.  
  169. /*
  170.  * general point routine
  171.  */
  172. line_and_point(x,y,number)
  173. int x,y,number;
  174. {
  175.     /* temporary(?) kludge to allow terminals with bad linetypes 
  176.         to make nice marks */
  177.  
  178.     (*term_tbl[term].linetype)(NICE_LINE);
  179.     do_point(x,y,number);
  180. }
  181.  
  182. /* 
  183.  * general arrow routine
  184.  */
  185. #define ROOT2 (1.41421)        /* sqrt of 2 */
  186.  
  187. do_arrow(sx, sy, ex, ey)
  188.     int sx,sy;            /* start point */
  189.     int ex, ey;            /* end point (point of arrowhead) */
  190. {
  191.     register struct termentry *t = &term_tbl[term];
  192.     int len = (t->h_tic + t->v_tic)/2; /* arrowhead size = avg of tic sizes */
  193.     extern double sqrt();
  194.  
  195.     /* draw the line for the arrow. That's easy. */
  196.     (*t->move)(sx, sy);
  197.     (*t->vector)(ex, ey);
  198.  
  199.     /* now draw the arrow head. */
  200.     /* we put the arrowhead marks at 45 degrees to line */
  201.     if (sx == ex) {
  202.        /* vertical line, special case */
  203.        int delta = ((float)len / ROOT2 + 0.5);
  204.        if (sy < ey)
  205.         delta = -delta;    /* up arrow goes the other way */
  206.        (*t->move)(ex - delta, ey + delta);
  207.        (*t->vector)(ex,ey);
  208.        (*t->vector)(ex + delta, ey + delta);
  209.     } else {
  210.        int dx = sx - ex;
  211.        int dy = sy - ey;
  212.        double coeff = len / sqrt(2.0*((double)dx*(double)dx 
  213.                 + (double)dy*(double)dy));
  214.        int x,y;            /* one endpoint */
  215.  
  216.        x = (int)( ex + (dx + dy) * coeff );
  217.        y = (int)( ey + (dy - dx) * coeff );
  218.        (*t->move)(x,y);
  219.        (*t->vector)(ex,ey);
  220.  
  221.        x = (int)( ex + (dx - dy) * coeff );
  222.        y = (int)( ey + (dy + dx) * coeff );
  223.        (*t->vector)(x,y);
  224.     }
  225.  
  226. }
  227.  
  228.  
  229. #ifdef PC            /* all PC types */
  230. #include "term/pc.trm"
  231. #endif
  232.  
  233. /*
  234.    all TEK types (TEK,BITGRAPH,KERMIT,VTTEK,SELANAR) are ifdef'd in tek.trm,
  235.    but most require various TEK routines.  Hence TEK must be defined for
  236.    the others to compile.
  237. */
  238. #ifdef BITGRAPH
  239. # ifndef TEK
  240. #  define TEK
  241. # endif
  242. #endif
  243.  
  244. #ifdef SELENAR
  245. # ifndef TEK
  246. #  define TEK
  247. # endif
  248. #endif
  249.  
  250. #ifdef KERMIT
  251. # ifndef TEK
  252. #  define TEK
  253. # endif
  254. #endif
  255.  
  256. #ifdef VTTEK
  257. # ifndef TEK
  258. #  define TEK
  259. # endif
  260. #endif
  261.  
  262. #ifdef T410X        /* Tektronix 4106, 4107, 4109 and 420x terminals */
  263. #include "term/t410x.trm"
  264. #endif
  265.  
  266. #ifdef TEK            /* all TEK types, TEK, BBN, SELANAR, KERMIT, VTTEK */
  267. #include "term/tek.trm"
  268. #endif
  269.  
  270. #ifdef EPSON    /* bit map types, EPSON, NEC, PROPRINTER, STAR Color */
  271. #include "term/epson.trm"
  272. #endif
  273.  
  274. #ifdef HPLJII        /* HP LaserJet II */
  275. #include "term/hpljii.trm"
  276. #endif
  277.  
  278. #ifdef FIG                /* Fig 1.4FS Interactive graphics program */
  279. #include "term/fig.trm"
  280. #endif
  281.  
  282. #ifdef IMAGEN        /* IMAGEN printer */
  283. #include "term/imagen.trm"
  284. #endif
  285.  
  286. #ifdef EEPIC        /* EEPIC (LATEX) type */
  287. #include "term/eepic.trm"
  288. # ifndef LATEX
  289. #  define LATEX
  290. # endif
  291. #endif
  292.  
  293. #ifdef EMTEX        /* EMTEX (LATEX for PC) type */
  294. # ifndef LATEX
  295. #  define LATEX
  296. # endif
  297. #endif
  298.  
  299. #ifdef LATEX        /* LATEX type */
  300. #include "term/latex.trm"
  301. #endif
  302.  
  303. #ifdef POSTSCRIPT    /* POSTSCRIPT type */
  304. #include "term/post.trm"
  305. #endif
  306.  
  307. #ifdef PRESCRIBE    /* PRESCRIBE type */
  308. #include "term/kyo.trm"
  309. #endif
  310.  
  311. #ifdef HPLJET        /* hplaserjet */
  312. #include "term/hpljet.trm"
  313. #endif
  314.  
  315. #ifdef UNIXPC     /* unix-PC  ATT 7300 or 3b1 machine */
  316. #include "term/unixpc.trm"
  317. #endif /* UNIXPC */
  318.  
  319. #ifdef AED
  320. #include "term/aed.trm"
  321. #endif /* AED */
  322.  
  323. #ifdef CGI
  324. #include "term/cgi.trm"
  325. #endif /* CGI */
  326.  
  327. #ifdef HP2648
  328. /* also works for HP2647 */
  329. #include "term/hp2648.trm"
  330. #endif /* HP2648 */
  331.  
  332. #ifdef HP26
  333. #include "term/hp26.trm"
  334. #endif /* HP26 */
  335.  
  336. #ifdef HP75
  337. #ifndef HPGL
  338. #define HPGL
  339. #endif
  340. #endif
  341.  
  342. /* HPGL - includes HP75 */
  343. #ifdef HPGL
  344. #include "term/hpgl.trm"
  345. #endif /* HPGL */
  346.  
  347. /* Roland DXY800A plotter driver by Martin Yii, eln557h@monu3.OZ 
  348.     and Russell Lang, rjl@monu1.cc.monash.oz */
  349. #ifdef DXY800A
  350. #include "term/dxy.trm"
  351. #endif /* DXY800A */
  352.  
  353. #ifdef IRIS4D
  354. #include "term/iris4d.trm"
  355. #endif /* IRIS4D */
  356.  
  357. #ifdef QMS
  358. #include "term/qms.trm"
  359. #endif /* QMS */
  360.  
  361. #ifdef REGIS
  362. #include "term/regis.trm"
  363. #endif /* REGIS */
  364.  
  365. #ifdef SUN
  366. #include "term/sun.trm"
  367. #endif /* SUN */
  368.  
  369. #ifdef V384
  370. #include "term/v384.trm"
  371. #endif /* V384 */
  372.  
  373. #ifdef UNIXPLOT
  374. #include "term/unixplot.trm"
  375. #endif /* UNIXPLOT */
  376.  
  377. #ifdef X11
  378. #include "term/x11.trm"
  379. #endif /* X11 */
  380.  
  381. /* Dummy functions for unavailable features */
  382.  
  383. /* change angle of text.  0 is horizontal left to right.
  384. * 1 is vertical bottom to top (90 deg rotate)  
  385. */
  386. int null_text_angle()
  387. {
  388. return FALSE ;    /* can't be done */
  389. }
  390.  
  391. /* change justification of text.  
  392.  * modes are LEFT (flush left), CENTRE (centred), RIGHT (flush right)
  393.  */
  394. int null_justify_text()
  395. {
  396. return FALSE ;    /* can't be done */
  397. }
  398.  
  399.  
  400. /* Change scale of plot.
  401.  * Parameters are x,y scaling factors for this plot.
  402.  * Some terminals (eg latex) need to do scaling themselves.
  403.  */
  404. int null_scale()
  405. {
  406. return FALSE ;    /* can't be done */
  407. }
  408.  
  409.  
  410. UNKNOWN_null()
  411. {
  412. }
  413.  
  414.  
  415. /*
  416.  * term_tbl[] contains an entry for each terminal.  "unknown" must be the
  417.  *   first, since term is initialized to 0.
  418.  */
  419. struct termentry term_tbl[] = {
  420.     {"unknown", "Unknown terminal type - not a plotting device",
  421.       100, 100, 1, 1,
  422.       1, 1, UNKNOWN_null, UNKNOWN_null, 
  423.       UNKNOWN_null, null_scale, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, 
  424.       UNKNOWN_null, UNKNOWN_null, null_text_angle, 
  425.       null_justify_text, UNKNOWN_null, UNKNOWN_null}
  426. #ifdef PC
  427. #ifdef __TURBOC__
  428.  
  429.     ,{"egalib", "IBM PC/Clone with EGA graphics board",
  430.        EGALIB_XMAX, EGALIB_YMAX, EGALIB_VCHAR, EGALIB_HCHAR,
  431.        EGALIB_VTIC, EGALIB_HTIC, EGALIB_init, EGALIB_reset,
  432.        EGALIB_text, null_scale, EGALIB_graphics, EGALIB_move, EGALIB_vector,
  433.        EGALIB_linetype, EGALIB_put_text, EGALIB_text_angle, 
  434.        EGALIB_justify_text, do_point, do_arrow}
  435.  
  436.     ,{"vgalib", "IBM PC/Clone with VGA graphics board",
  437.        VGA_XMAX, VGA_YMAX, VGA_VCHAR, VGA_HCHAR,
  438.        VGA_VTIC, VGA_HTIC, VGA_init, VGA_reset,
  439.        VGA_text, null_scale, VGA_graphics, VGA_move, VGA_vector,
  440.        VGA_linetype, VGA_put_text, VGA_text_angle, 
  441.        VGA_justify_text, do_point, do_arrow}
  442.  
  443.     ,{"vgamono", "IBM PC/Clone with VGA Monochrome graphics board",
  444.        VGA_XMAX, VGA_YMAX, VGA_VCHAR, VGA_HCHAR,
  445.        VGA_VTIC, VGA_HTIC, VGA_init, VGA_reset,
  446.        VGA_text, null_scale, VGA_graphics, VGA_move, VGA_vector,
  447.        VGAMONO_linetype, VGA_put_text, VGA_text_angle, 
  448.        VGA_justify_text, line_and_point, do_arrow}
  449.  
  450.     ,{"mcga", "IBM PC/Clone with MCGA graphics board",
  451.        MCGA_XMAX, MCGA_YMAX, MCGA_VCHAR, MCGA_HCHAR,
  452.        MCGA_VTIC, MCGA_HTIC, MCGA_init, MCGA_reset,
  453.        MCGA_text, null_scale, MCGA_graphics, MCGA_move, MCGA_vector,
  454.        MCGA_linetype, MCGA_put_text, MCGA_text_angle, 
  455.        MCGA_justify_text, line_and_point, do_arrow}
  456.  
  457.     ,{"cga", "IBM PC/Clone with CGA graphics board",
  458.        CGA_XMAX, CGA_YMAX, CGA_VCHAR, CGA_HCHAR,
  459.        CGA_VTIC, CGA_HTIC, CGA_init, CGA_reset,
  460.        CGA_text, null_scale, CGA_graphics, CGA_move, CGA_vector,
  461.        CGA_linetype, CGA_put_text, MCGA_text_angle, 
  462.        CGA_justify_text, line_and_point, do_arrow}
  463.  
  464.     ,{"hercules", "IBM PC/Clone with Hercules graphics board",
  465.        HERC_XMAX, HERC_YMAX, HERC_VCHAR, HERC_HCHAR,
  466.        HERC_VTIC, HERC_HTIC, HERC_init, HERC_reset,
  467.        HERC_text, null_scale, HERC_graphics, HERC_move, HERC_vector,
  468.        HERC_linetype, HERC_put_text, MCGA_text_angle, 
  469.        HERC_justify_text, line_and_point, do_arrow}
  470. #ifdef ATT6300
  471.     ,{"att", "IBM PC/Clone with AT&T 6300 graphics board",
  472.        ATT_XMAX, ATT_YMAX, ATT_VCHAR, ATT_HCHAR,
  473.        ATT_VTIC, ATT_HTIC, ATT_init, ATT_reset,
  474.        ATT_text, null_scale, ATT_graphics, ATT_move, ATT_vector,
  475.        ATT_linetype, ATT_put_text, ATT_text_angle, 
  476.        ATT_justify_text, line_and_point, do_arrow}
  477. #endif
  478. #else                    /* TURBO */
  479.  
  480.     ,{"cga", "IBM PC/Clone with CGA graphics board",
  481.        CGA_XMAX, CGA_YMAX, CGA_VCHAR, CGA_HCHAR,
  482.        CGA_VTIC, CGA_HTIC, CGA_init, CGA_reset,
  483.        CGA_text, null_scale, CGA_graphics, CGA_move, CGA_vector,
  484.        CGA_linetype, CGA_put_text, CGA_text_angle, 
  485.        null_justify_text, line_and_point, do_arrow}
  486.  
  487.     ,{"egabios", "IBM PC/Clone with EGA graphics board (BIOS)",
  488.        EGA_XMAX, EGA_YMAX, EGA_VCHAR, EGA_HCHAR,
  489.        EGA_VTIC, EGA_HTIC, EGA_init, EGA_reset,
  490.        EGA_text, null_scale, EGA_graphics, EGA_move, EGA_vector,
  491.        EGA_linetype, EGA_put_text, EGA_text_angle, 
  492.        null_justify_text, do_point, do_arrow}
  493.  
  494.     ,{"vgabios", "IBM PC/Clone with VGA graphics board (BIOS)",
  495.        VGA_XMAX, VGA_YMAX, VGA_VCHAR, VGA_HCHAR,
  496.        VGA_VTIC, VGA_HTIC, VGA_init, VGA_reset,
  497.        VGA_text, null_scale, VGA_graphics, VGA_move, VGA_vector,
  498.        VGA_linetype, VGA_put_text, VGA_text_angle, 
  499.        null_justify_text, do_point, do_arrow}
  500.  
  501. #ifdef EGALIB
  502.     ,{"egalib", "IBM PC/Clone with EGA graphics board (LIB)",
  503.        EGALIB_XMAX, EGALIB_YMAX, EGALIB_VCHAR, EGALIB_HCHAR,
  504.        EGALIB_VTIC, EGALIB_HTIC, EGALIB_init, EGALIB_reset,
  505.        EGALIB_text, null_scale, EGALIB_graphics, EGALIB_move, EGALIB_vector,
  506.        EGALIB_linetype, EGALIB_put_text, null_text_angle, 
  507.        null_justify_text, do_point, do_arrow}
  508. #endif
  509.  
  510. #ifdef HERCULES
  511.     ,{"hercules", "IBM PC/Clone with Hercules graphics board",
  512.        HERC_XMAX, HERC_YMAX, HERC_VCHAR, HERC_HCHAR,
  513.        HERC_VTIC, HERC_HTIC, HERC_init, HERC_reset,
  514.        HERC_text, null_scale, HERC_graphics, HERC_move, HERC_vector,
  515.        HERC_linetype, HERC_put_text, HERC_text_angle, 
  516.        null_justify_text, line_and_point, do_arrow}
  517. #endif                    /* HERCULES */
  518.  
  519. #ifdef ATT6300
  520.     ,{"att", "AT&T PC/6300 graphics",
  521.        ATT_XMAX, ATT_YMAX, ATT_VCHAR, ATT_HCHAR,
  522.        ATT_VTIC, ATT_HTIC, ATT_init, ATT_reset,
  523.        ATT_text, null_scale, ATT_graphics, ATT_move, ATT_vector,
  524.        ATT_linetype, ATT_put_text, ATT_text_angle, 
  525.        null_justify_text, line_and_point, do_arrow}
  526. #endif
  527.  
  528. #ifdef CORONA
  529.     ,{"corona325", "Corona graphics ???",
  530.        COR_XMAX, COR_YMAX, COR_VCHAR, COR_HCHAR,
  531.        COR_VTIC, COR_HTIC, COR_init, COR_reset,
  532.        COR_text, null_scale, COR_graphics, COR_move, COR_vector,
  533.        COR_linetype, COR_put_text, COR_text_angle, 
  534.        null_justify_text, line_and_point, do_arrow}
  535. #endif                    /* CORONA */
  536. #endif                    /* TURBO */
  537. #endif                    /* PC */
  538.  
  539. #ifdef AED
  540.     ,{"aed512", "AED 512 Terminal",
  541.        AED5_XMAX, AED_YMAX, AED_VCHAR, AED_HCHAR,
  542.        AED_VTIC, AED_HTIC, AED_init, AED_reset, 
  543.        AED_text, null_scale, AED_graphics, AED_move, AED_vector, 
  544.        AED_linetype, AED_put_text, null_text_angle, 
  545.        null_justify_text, do_point, do_arrow}
  546.     ,{"aed767", "AED 767 Terminal",
  547.        AED_XMAX, AED_YMAX, AED_VCHAR, AED_HCHAR,
  548.        AED_VTIC, AED_HTIC, AED_init, AED_reset, 
  549.        AED_text, null_scale, AED_graphics, AED_move, AED_vector, 
  550.        AED_linetype, AED_put_text, null_text_angle, 
  551.        null_justify_text, do_point, do_arrow}
  552. #endif
  553.  
  554. #ifdef BITGRAPH
  555.     ,{"bitgraph", "BBN Bitgraph Terminal",
  556.        BG_XMAX,BG_YMAX,BG_VCHAR, BG_HCHAR, 
  557.        BG_VTIC, BG_HTIC, BG_init, BG_reset, 
  558.        BG_text, null_scale, BG_graphics, BG_move, BG_vector,
  559.        BG_linetype, BG_put_text, null_text_angle, 
  560.        null_justify_text, line_and_point, do_arrow}
  561. #endif
  562.  
  563. #ifdef CGI
  564.     ,{"cgi", "SCO CGI drivers (requires CGIDISP or CGIPRNT env variable)",
  565.        CGI_XMAX, CGI_YMAX, 0, 0, 
  566.        CGI_VTIC, 0, CGI_init, CGI_reset, 
  567.        CGI_text, null_scale, CGI_graphics, CGI_move, CGI_vector, 
  568.        CGI_linetype, CGI_put_text, CGI_text_angle, 
  569.        CGI_justify_text, CGI_point, do_arrow}
  570.  
  571.     ,{"hcgi", "SCO CGI drivers (hardcopy, requires CGIPRNT env variable)",
  572.        CGI_XMAX, CGI_YMAX, 0, 0, 
  573.        CGI_VTIC, 0, HCGI_init, CGI_reset, 
  574.        CGI_text, null_scale, CGI_graphics, CGI_move, CGI_vector, 
  575.        CGI_linetype, CGI_put_text, CGI_text_angle, 
  576.        CGI_justify_text, CGI_point, do_arrow}
  577. #endif
  578.  
  579. #ifdef DXY800A
  580.     ,{"dxy800a", "Roland DXY800A plotter",
  581.        DXY_XMAX, DXY_YMAX, DXY_VCHAR, DXY_HCHAR,
  582.        DXY_VTIC, DXY_HTIC, DXY_init, DXY_reset,
  583.        DXY_text, null_scale, DXY_graphics, DXY_move, DXY_vector,
  584.        DXY_linetype, DXY_put_text, DXY_text_angle, 
  585.        null_justify_text, do_point, do_arrow}
  586. #endif
  587.  
  588. #ifdef EEPIC
  589.     ,{"eepic", "EEPIC -- extended LaTeX picture environment",
  590.        EEPIC_XMAX, EEPIC_YMAX, EEPIC_VCHAR, EEPIC_HCHAR, 
  591.        EEPIC_VTIC, EEPIC_HTIC, EEPIC_init, EEPIC_reset, 
  592.        EEPIC_text, EEPIC_scale, EEPIC_graphics, EEPIC_move, EEPIC_vector, 
  593.        EEPIC_linetype, EEPIC_put_text, EEPIC_text_angle, 
  594.        EEPIC_justify_text, EEPIC_point, EEPIC_arrow}
  595. #endif
  596.  
  597. #ifdef EMTEX
  598.    
  599.     ,{"emtex", "LATEX picture environment with emTeX specials",
  600.        LATEX_XMAX, LATEX_YMAX, LATEX_VCHAR, LATEX_HCHAR, 
  601.        LATEX_VTIC, LATEX_HTIC, EMTEX_init, EMTEX_reset, 
  602.        EMTEX_text, LATEX_scale, LATEX_graphics, LATEX_move, LATEX_vector, 
  603.        LATEX_linetype, LATEX_put_text, LATEX_text_angle, 
  604.        LATEX_justify_text, LATEX_point, LATEX_arrow}
  605. #endif
  606.  
  607. #ifdef EPS60
  608.     ,{"epson_60dpi", "Epson-style 60-dot per inch printers",
  609.        EPS60XMAX, EPS60YMAX, EPSONVCHAR, EPSONHCHAR,
  610.        EPSONVTIC, EPSONHTIC, EPSONinit, EPSONreset,
  611.        EPS60text, null_scale, EPS60graphics, EPSONmove, EPSONvector,
  612.        EPSONlinetype, EPSONput_text, EPSON_text_angle,
  613.        null_justify_text, do_point, do_arrow}
  614. #endif
  615.  
  616. #ifdef EPSON
  617.     ,{"epson_lx800", "Epson LX-800, Star NL-10, NX-1000, PROPRINTER ...",
  618.        EPSONXMAX, EPSONYMAX, EPSONVCHAR, EPSONHCHAR, 
  619.        EPSONVTIC, EPSONHTIC, EPSONinit, EPSONreset, 
  620.        EPSONtext, null_scale, EPSONgraphics, EPSONmove, EPSONvector, 
  621.        EPSONlinetype, EPSONput_text, EPSON_text_angle, 
  622.        null_justify_text, line_and_point, do_arrow}
  623. #endif
  624.  
  625. #ifdef FIG
  626.     ,{"fig", "FIG graphics language: SunView or X graphics editor",
  627.        FIG_XMAX, FIG_YMAX, FIG_VCHAR, FIG_HCHAR, 
  628.        FIG_VTIC, FIG_HTIC, FIG_init, FIG_reset, 
  629.        FIG_text, null_scale, FIG_graphics, FIG_move, FIG_vector, 
  630.        FIG_linetype, FIG_put_text, FIG_text_angle, 
  631.        FIG_justify_text, do_point, FIG_arrow}
  632. #endif
  633.  
  634. #ifdef HP26
  635.     ,{"hp2623A", "HP2623A and maybe others",
  636.        HP26_XMAX, HP26_YMAX, HP26_VCHAR, HP26_HCHAR,
  637.        HP26_VTIC, HP26_HTIC, HP26_init, HP26_reset,
  638.        HP26_text, null_scale, HP26_graphics, HP26_move, HP26_vector,
  639.        HP26_linetype, HP26_put_text, null_text_angle, 
  640.        null_justify_text, line_and_point, do_arrow}
  641. #endif
  642.  
  643. #ifdef HP2648
  644.     ,{"hp2648", "HP2648 and HP2647",
  645.        HP2648XMAX, HP2648YMAX, HP2648VCHAR, HP2648HCHAR, 
  646.        HP2648VTIC, HP2648HTIC, HP2648init, HP2648reset, 
  647.        HP2648text, null_scale, HP2648graphics, HP2648move, HP2648vector, 
  648.        HP2648linetype, HP2648put_text, HP2648_text_angle, 
  649.        null_justify_text, line_and_point, do_arrow}
  650. #endif
  651.  
  652. #ifdef HP75
  653.     ,{"hp7580B", "HP7580, and probably other HPs (4 pens)",
  654.        HPGL_XMAX, HPGL_YMAX, HPGL_VCHAR, HPGL_HCHAR,
  655.        HPGL_VTIC, HPGL_HTIC, HPGL_init, HPGL_reset,
  656.        HPGL_text, null_scale, HPGL_graphics, HPGL_move, HPGL_vector,
  657.        HP75_linetype, HPGL_put_text, HPGL_text_angle, 
  658.        null_justify_text, do_point, do_arrow}
  659. #endif
  660.  
  661. #ifdef HPGL
  662.     ,{"hpgl", "HP7475 and (hopefully) lots of others (6 pens)",
  663.        HPGL_XMAX, HPGL_YMAX, HPGL_VCHAR, HPGL_HCHAR,
  664.        HPGL_VTIC, HPGL_HTIC, HPGL_init, HPGL_reset,
  665.        HPGL_text, null_scale, HPGL_graphics, HPGL_move, HPGL_vector,
  666.        HPGL_linetype, HPGL_put_text, HPGL_text_angle, 
  667.        null_justify_text, do_point, do_arrow}
  668. #endif
  669.  
  670. #ifdef HPLJII
  671.     ,{"hpljii_300ppi", "HP Laserjet series II with 300 pixels per inch",
  672.        HPLJII_300PPI_XMAX, HPLJII_300PPI_YMAX, HPLJII_300PPI_VCHAR,
  673.        HPLJII_300PPI_HCHAR, HPLJII_300PPI_VTIC, HPLJII_300PPI_HTIC,
  674.        HPLJIIinit, HPLJIIreset, HPLJIItext, null_scale,
  675.        HPLJII_300PPIgraphics, HPLJIImove, HPLJIIvector, HPLJIIlinetype,
  676.        HPLJIIput_text, HPLJIItext_angle,  null_justify_text, line_and_point,
  677.        do_arrow}
  678.     ,{"hpljii_150ppi", "HP Laserjet series II with 150 pixels per inch",
  679.        HPLJII_150PPI_XMAX, HPLJII_150PPI_YMAX, HPLJII_150PPI_VCHAR,
  680.        HPLJII_150PPI_HCHAR, HPLJII_150PPI_VTIC, HPLJII_150PPI_HTIC,
  681.        HPLJIIinit, HPLJIIreset, HPLJIItext, null_scale,
  682.        HPLJII_150PPIgraphics, HPLJIImove, HPLJIIvector, HPLJIIlinetype,
  683.        HPLJIIput_text, HPLJIItext_angle, null_justify_text, line_and_point,
  684.        do_arrow}
  685.     ,{"hpljii_100ppi", "HP Laserjet series II with 100 pixels per inch",
  686.        HPLJII_100PPI_XMAX, HPLJII_100PPI_YMAX, HPLJII_100PPI_VCHAR,
  687.        HPLJII_100PPI_HCHAR, HPLJII_100PPI_VTIC, HPLJII_100PPI_HTIC,
  688.        HPLJIIinit, HPLJIIreset, HPLJIItext, null_scale,
  689.        HPLJII_100PPIgraphics, HPLJIImove, HPLJIIvector, HPLJIIlinetype,
  690.        HPLJIIput_text, HPLJIItext_angle, null_justify_text, line_and_point,
  691.        do_arrow}
  692.     ,{"hpljii_75ppi", "HP Laserjet series II with 75 pixels per inch",
  693.        HPLJII_75PPI_XMAX, HPLJII_75PPI_YMAX, HPLJII_75PPI_VCHAR,
  694.        HPLJII_75PPI_HCHAR, HPLJII_75PPI_VTIC, HPLJII_75PPI_HTIC,
  695.        HPLJIIinit, HPLJIIreset, HPLJIItext, null_scale,
  696.        HPLJII_75PPIgraphics, HPLJIImove, HPLJIIvector, HPLJIIlinetype,
  697.        HPLJIIput_text, HPLJIItext_angle, null_justify_text, line_and_point,
  698.        do_arrow}
  699. #endif
  700.  
  701. #ifdef IMAGEN
  702.     ,{"imagen", "Imagen laser printer",
  703.        IMAGEN_XMAX, IMAGEN_YMAX, IMAGEN_VCHAR, IMAGEN_HCHAR, 
  704.        IMAGEN_VTIC, IMAGEN_HTIC, IMAGEN_init, IMAGEN_reset, 
  705.        IMAGEN_text, null_scale, IMAGEN_graphics, IMAGEN_move, 
  706.        IMAGEN_vector, IMAGEN_linetype, IMAGEN_put_text, IMAGEN_text_angle,
  707.        IMAGEN_justify_text, line_and_point, do_arrow}
  708. #endif
  709.  
  710. #ifdef IRIS4D
  711.     ,{"iris4d", "Silicon Graphics IRIS 4D Series Computer",
  712.        IRIS4D_XMAX, IRIS4D_YMAX, IRIS4D_VCHAR, IRIS4D_HCHAR, 
  713.        IRIS4D_VTIC, IRIS4D_HTIC, IRIS4D_init, IRIS4D_reset, 
  714.        IRIS4D_text, null_scale, IRIS4D_graphics, IRIS4D_move, IRIS4D_vector,
  715.        IRIS4D_linetype, IRIS4D_put_text, null_text_angle, 
  716.        null_justify_text, do_point, do_arrow}
  717. #endif
  718.  
  719. #ifdef KERMIT
  720.     ,{"kc_tek40xx", "Kermit-MS tek40xx terminal emulator - color",
  721.        TEK40XMAX,TEK40YMAX,TEK40VCHAR, KTEK40HCHAR, 
  722.        TEK40VTIC, TEK40HTIC, TEK40init, KTEK40reset, 
  723.        KTEK40Ctext, null_scale, KTEK40graphics, TEK40move, TEK40vector, 
  724.        KTEK40Clinetype, TEK40put_text, null_text_angle, 
  725.        null_justify_text, do_point, do_arrow}
  726.     ,{"km_tek40xx", "Kermit-MS tek40xx terminal emulator - monochrome",
  727.        TEK40XMAX,TEK40YMAX,TEK40VCHAR, KTEK40HCHAR, 
  728.        TEK40VTIC, TEK40HTIC, TEK40init, KTEK40reset, 
  729.        TEK40text, null_scale, KTEK40graphics, TEK40move, TEK40vector, 
  730.        KTEK40Mlinetype, TEK40put_text, null_text_angle, 
  731.        null_justify_text, line_and_point, do_arrow}
  732. #endif
  733.  
  734. #ifdef LATEX
  735.     ,{"latex", "LaTeX picture environment",
  736.        LATEX_XMAX, LATEX_YMAX, LATEX_VCHAR, LATEX_HCHAR, 
  737.        LATEX_VTIC, LATEX_HTIC, LATEX_init, LATEX_reset, 
  738.        LATEX_text, LATEX_scale, LATEX_graphics, LATEX_move, LATEX_vector, 
  739.        LATEX_linetype, LATEX_put_text, LATEX_text_angle, 
  740.        LATEX_justify_text, LATEX_point, LATEX_arrow}
  741. #endif
  742.  
  743. #ifdef NEC
  744.     ,{"nec_cp6m", "NEC printer CP6, Epson LQ-800 Monochrome",
  745.        NECXMAX, NECYMAX, NECVCHAR, NECHCHAR, 
  746.        NECVTIC, NECHTIC, NECinit, NECreset, 
  747.        NECtext, null_scale, NECMgraphics, NECmove, NECvector, 
  748.        NECMlinetype, NECput_text, NEC_text_angle, 
  749.        null_justify_text, line_and_point, do_arrow}
  750.     ,{"nec_cp6c", "NEC printer CP6 Color",
  751.        NECXMAX, NECYMAX, NECVCHAR, NECHCHAR, 
  752.        NECVTIC, NECHTIC, NECinit, NECreset, 
  753.        NECtext, null_scale, NECCgraphics, NECmove, NECvector, 
  754.        NECClinetype, NECput_text, NEC_text_angle, 
  755.        null_justify_text, do_point, do_arrow}
  756.     ,{"nec_cp6d", "NEC printer CP6, Epson LQ-800 Draft monochrome",
  757.        NECXMAX, NECYMAX, NECVCHAR, NECHCHAR, 
  758.        NECVTIC, NECHTIC, NECinit, NECreset, 
  759.        NECdraft_text, null_scale, NECMgraphics, NECmove, NECvector, 
  760.        NECMlinetype, NECput_text, NEC_text_angle, 
  761.        null_justify_text, line_and_point, do_arrow}
  762. #endif
  763.  
  764. #ifdef POSTSCRIPT
  765.     ,{"postscript", "Postscript graphics language, small characters",
  766.        PS_XMAX, PS_YMAX, PS_VCHAR1, PS_HCHAR1, 
  767.        PS_VTIC, PS_HTIC, PS1_init, PS_reset, 
  768.        PS_text, null_scale, PS_graphics, PS_move, PS_vector, 
  769.        PS_linetype, PS_put_text, PS_text_angle, 
  770.        PS_justify_text, PS_point, do_arrow}
  771.     ,{"psbig", "Postscript graphics language, big characters",
  772.        PS_XMAX, PS_YMAX, PS_VCHAR2, PS_HCHAR2, 
  773.        PS_VTIC, PS_HTIC, PS2_init, PS_reset, 
  774.        PS_text, null_scale, PS_graphics, PS_move, PS_vector, 
  775.        PS_linetype, PS_put_text, PS_text_angle, 
  776.        PS_justify_text, PS_point, do_arrow}
  777.     ,{"epsf1", "Encapsulated Postscript graphics language, small characters",
  778.        PS_XMAX, PS_YMAX, PS_VCHAR1, PS_HCHAR1, 
  779.        PS_VTIC, PS_HTIC, EPSF1_init, EPSF_reset, 
  780.        EPSF_text, null_scale, EPSF_graphics, PS_move, PS_vector, 
  781.        PS_linetype, PS_put_text, PS_text_angle, 
  782.        PS_justify_text, PS_point, do_arrow}
  783.     ,{"epsf2", "Encapsulated Postscript graphics language, big characters",
  784.        PS_XMAX, PS_YMAX, PS_VCHAR2, PS_HCHAR2, 
  785.        PS_VTIC, PS_HTIC, EPSF2_init, EPSF_reset, 
  786.        EPSF_text, null_scale, EPSF_graphics, PS_move, PS_vector, 
  787.        PS_linetype, PS_put_text, PS_text_angle, 
  788.        PS_justify_text, PS_point, do_arrow}
  789. #endif
  790.  
  791. #ifdef PRESCRIBE
  792.     ,{"prescribe", "Prescribe - for the Kyocera Laser Printer",
  793.     PRE_XMAX, PRE_YMAX, PRE_VCHAR, PRE_HCHAR, 
  794.     PRE_VTIC, PRE_HTIC, PRE_init, PRE_reset, 
  795.     PRE_text, null_scale, PRE_graphics, PRE_move, PRE_vector, 
  796.     PRE_linetype, PRE_put_text, null_text_angle, 
  797.     PRE_justify_text, line_and_point, do_arrow}
  798.     ,{"kyo", "Kyocera Laser Printer with Courier font",
  799.     PRE_XMAX, PRE_YMAX, KYO_VCHAR, KYO_HCHAR, 
  800.     PRE_VTIC, PRE_HTIC, KYO_init, PRE_reset, 
  801.     PRE_text, null_scale, PRE_graphics, PRE_move, PRE_vector, 
  802.     PRE_linetype, PRE_put_text, null_text_angle, 
  803.     PRE_justify_text, line_and_point, do_arrow}
  804. #endif /* PRESCRIBE */
  805.  
  806. #ifdef QMS
  807.     ,{"qms", "QMS/QUIC Laser printer (also Talaris 1200 and others)",
  808.        QMS_XMAX,QMS_YMAX, QMS_VCHAR, QMS_HCHAR, 
  809.        QMS_VTIC, QMS_HTIC, QMS_init,QMS_reset, 
  810.        QMS_text, null_scale, QMS_graphics, QMS_move, QMS_vector,
  811.        QMS_linetype,QMS_put_text, null_text_angle, 
  812.        null_justify_text, line_and_point, do_arrow}
  813. #endif
  814.  
  815. #ifdef REGIS
  816.     ,{"regis", "REGIS graphics language",
  817.        REGISXMAX, REGISYMAX, REGISVCHAR, REGISHCHAR, 
  818.        REGISVTIC, REGISHTIC, REGISinit, REGISreset, 
  819.        REGIStext, null_scale, REGISgraphics, REGISmove, REGISvector,
  820.        REGISlinetype, REGISput_text, REGIStext_angle, 
  821.        null_justify_text, line_and_point, do_arrow}
  822. #endif
  823.  
  824.  
  825. #ifdef SELANAR
  826.     ,{"selanar", "Selanar",
  827.        TEK40XMAX, TEK40YMAX, TEK40VCHAR, TEK40HCHAR, 
  828.        TEK40VTIC, TEK40HTIC, SEL_init, SEL_reset, 
  829.        SEL_text, null_scale, SEL_graphics, TEK40move, TEK40vector, 
  830.        TEK40linetype, TEK40put_text, null_text_angle, 
  831.        null_justify_text, line_and_point, do_arrow}
  832. #endif
  833.  
  834. #ifdef STARC
  835.     ,{"starc", "Star Color Printer",
  836.        STARCXMAX, STARCYMAX, STARCVCHAR, STARCHCHAR, 
  837.        STARCVTIC, STARCHTIC, STARCinit, STARCreset, 
  838.        STARCtext, null_scale, STARCgraphics, STARCmove, STARCvector, 
  839.        STARClinetype, STARCput_text, STARC_text_angle, 
  840.        null_justify_text, line_and_point, do_arrow}
  841. #endif
  842.  
  843. #ifdef SUN
  844.     ,{"sun", "SunView window system",
  845.        SUN_XMAX, SUN_YMAX, SUN_VCHAR, SUN_HCHAR, 
  846.        SUN_VTIC, SUN_HTIC, SUN_init, SUN_reset, 
  847.        SUN_text, null_scale, SUN_graphics, SUN_move, SUN_vector,
  848.        SUN_linetype, SUN_put_text, null_text_angle, 
  849.        SUN_justify_text, line_and_point, do_arrow}
  850. #endif
  851.  
  852. #ifdef TANDY60
  853.     ,{"tandy_60dpi", "Tandy DMP-130 series 60-dot per inch graphics",
  854.        EPS60XMAX, EPS60YMAX, EPSONVCHAR, EPSONHCHAR,
  855.        EPSONVTIC, EPSONHTIC, EPSONinit, EPSONreset,
  856.        TANDY60text, null_scale, EPS60graphics, EPSONmove, EPSONvector,
  857.        EPSONlinetype, EPSONput_text, EPSON_text_angle,
  858.        null_justify_text, do_point, do_arrow}
  859. #endif
  860.  
  861. #ifdef T410X
  862.     ,{"tek410x", "Tektronix 4106, 4107, 4109 and 420X terminals",
  863.        T410XXMAX, T410XYMAX, T410XVCHAR, T410XHCHAR, 
  864.        T410XVTIC, T410XHTIC, T410X_init, T410X_reset, 
  865.        T410X_text, null_scale, T410X_graphics, T410X_move, T410X_vector, 
  866.        T410X_linetype, T410X_put_text, T410X_text_angle, 
  867.        null_justify_text, T410X_point, do_arrow}
  868. #endif
  869.  
  870. #ifdef TEK
  871.     ,{"tek40xx", "Tektronix 4010 and others; most TEK emulators",
  872.        TEK40XMAX, TEK40YMAX, TEK40VCHAR, TEK40HCHAR, 
  873.        TEK40VTIC, TEK40HTIC, TEK40init, TEK40reset, 
  874.        TEK40text, null_scale, TEK40graphics, TEK40move, TEK40vector, 
  875.        TEK40linetype, TEK40put_text, null_text_angle, 
  876.        null_justify_text, line_and_point, do_arrow}
  877. #endif
  878.  
  879. #ifdef UNIXPLOT
  880.     ,{"unixplot", "Unix plotting standard (see plot(1))",
  881.        UP_XMAX, UP_YMAX, UP_VCHAR, UP_HCHAR, 
  882.        UP_VTIC, UP_HTIC, UP_init, UP_reset, 
  883.        UP_text, null_scale, UP_graphics, UP_move, UP_vector, 
  884.        UP_linetype, UP_put_text, null_text_angle, 
  885.        null_justify_text, line_and_point, do_arrow}
  886. #endif
  887.     
  888. #ifdef UNIXPC
  889.     ,{"unixpc", "AT&T 3b1 or AT&T 7300 Unix PC",
  890.        uPC_XMAX, uPC_YMAX, uPC_VCHAR, uPC_HCHAR, 
  891.        uPC_VTIC, uPC_HTIC, uPC_init, uPC_reset, 
  892.        uPC_text, null_scale, uPC_graphics, uPC_move, uPC_vector,
  893.        uPC_linetype, uPC_put_text, uPC_text_angle, 
  894.        null_justify_text, line_and_point, do_arrow}
  895. #endif
  896.  
  897. #ifdef V384
  898.     ,{"vx384", "Vectrix 384 and Tandy color printer",
  899.        V384_XMAX, V384_YMAX, V384_VCHAR, V384_HCHAR, 
  900.        V384_VTIC, V384_HTIC, V384_init, V384_reset, 
  901.        V384_text, null_scale, V384_graphics, V384_move, V384_vector, 
  902.        V384_linetype, V384_put_text, null_text_angle, 
  903.        null_justify_text, do_point, do_arrow}
  904. #endif
  905.  
  906. #ifdef VTTEK
  907.     ,{"vttek", "VT-like tek40xx terminal emulator",
  908.        TEK40XMAX,TEK40YMAX,TEK40VCHAR, TEK40HCHAR,
  909.        TEK40VTIC, TEK40HTIC, VTTEK40init, VTTEK40reset,
  910.        TEK40text, null_scale, TEK40graphics, TEK40move, TEK40vector,
  911.        VTTEK40linetype, VTTEK40put_text, null_text_angle,
  912.        null_justify_text, line_and_point, do_arrow}
  913. #endif
  914.  
  915. #ifdef X11
  916.     ,{"x11", "X11 Window System",
  917.        X11_XMAX, X11_YMAX, X11_VCHAR, X11_HCHAR, 
  918.        X11_VTIC, X11_HTIC, X11_init, X11_reset, 
  919.        X11_text, null_scale, X11_graphics, X11_move, X11_vector, 
  920.        X11_linetype, X11_put_text, null_text_angle, 
  921.        X11_justify_text, line_and_point, do_arrow}
  922.     ,{"X11", "X11 Window System - multi-color points",
  923.        X11_XMAX, X11_YMAX, X11_VCHAR, X11_HCHAR, 
  924.        X11_VTIC, X11_HTIC, X11_init, X11_reset, 
  925.        X11_text, null_scale, X11_graphics, X11_move, X11_vector, 
  926.        X11_linetype, X11_put_text, null_text_angle, 
  927.        X11_justify_text, do_point, do_arrow}
  928. #endif
  929. };
  930.  
  931. #define TERMCOUNT (sizeof(term_tbl)/sizeof(struct termentry))
  932.  
  933.  
  934. list_terms()
  935. {
  936. register int i;
  937.  
  938.     fprintf(stderr,"\nAvailable terminal types:\n");
  939.     for (i = 0; i < TERMCOUNT; i++)
  940.         fprintf(stderr,"  %15s  %s\n",
  941.                term_tbl[i].name, term_tbl[i].description);
  942.     (void) putc('\n',stderr);
  943. }
  944.  
  945.  
  946. /* set_term: get terminal number from name on command line */
  947. /* will change 'term' variable if successful */
  948. int                        /* term number */
  949. set_term(c_token)
  950. int c_token;
  951. {
  952.     register int t;
  953.     char *input_name;
  954.  
  955.     if (!token[c_token].is_token)
  956.      int_error("terminal name expected",c_token);
  957.     t = -1;
  958.     input_name = input_line + token[c_token].start_index;
  959.     t = change_term(input_name, token[c_token].length);
  960.     if (t == -1)
  961.      int_error("unknown terminal type; type just 'set terminal' for a list",
  962.              c_token);
  963.     if (t == -2)
  964.      int_error("ambiguous terminal name; type just 'set terminal' for a list",
  965.              c_token);
  966.  
  967.     /* otherwise the type was changed */
  968.  
  969.     return(t);
  970. }
  971.  
  972. /* change_term: get terminal number from name and set terminal type */
  973. /* returns -1 if unknown, -2 if ambiguous, >=0 is terminal number */
  974. int
  975. change_term(name, length)
  976.     char *name;
  977.     int length;
  978. {
  979.     int i, t = -1;
  980.  
  981.     for (i = 0; i < TERMCOUNT; i++) {
  982.        if (!strncmp(name,term_tbl[i].name,length)) {
  983.           if (t != -1)
  984.             return(-2);    /* ambiguous */
  985.           t = i;
  986.        }
  987.     }
  988.  
  989.     if (t == -1)            /* unknown */
  990.      return(t);
  991.  
  992.     /* Success: set terminal type now */
  993.  
  994.     /* Special handling for unixplot term type */
  995.     if (!strncmp("unixplot",name,sizeof(unixplot))) {
  996.        UP_redirect (2);  /* Redirect actual stdout for unixplots */
  997.     } else if (unixplot) {
  998.        UP_redirect (3);  /* Put stdout back together again. */
  999.     }
  1000.  
  1001.     term = t;
  1002.     term_init = FALSE;
  1003.     name = term_tbl[term].name;
  1004.  
  1005.     if (interactive)
  1006.      fprintf(stderr, "Terminal type set to '%s'\n", name);
  1007.  
  1008.     return(t);
  1009. }
  1010.  
  1011. /*
  1012.    Routine to detect what terminal is being used (or do anything else
  1013.    that would be nice).  One anticipated (or allowed for) side effect
  1014.    is that the global ``term'' may be set. 
  1015.    The environment variable GNUTERM is checked first; if that does
  1016.    not exist, then the terminal hardware is checked, if possible, 
  1017.    and finally, we can check $TERM for some kinds of terminals.
  1018. */
  1019. /* thanks to osupyr!alden (Dave Alden) for the original GNUTERM code */
  1020. init_terminal()
  1021. {
  1022.     char *term_name = NULL;
  1023.     int t;
  1024.     char *term = NULL;        /* from TERM environment var */
  1025. #ifdef X11
  1026.     char *display = NULL;
  1027. #endif
  1028.     char *gnuterm = NULL;
  1029.  
  1030.     /* GNUTERM environment variable is primary */
  1031.     gnuterm = getenv("GNUTERM");
  1032.     if (gnuterm != (char *)NULL)
  1033.      term_name = gnuterm;
  1034.     else {
  1035. #ifdef __TURBOC__
  1036.        term_name = turboc_init();
  1037.        term = (char *)NULL; /* shut up turbo C */
  1038. #endif
  1039.        
  1040. #ifdef vms
  1041.        term_name = vms_init();
  1042. #endif
  1043.        
  1044. #ifdef SUN
  1045.        term = getenv("TERM");    /* try $TERM */
  1046.        if (term_name == (char *)NULL
  1047.           && term != (char *)NULL && strcmp(term, "sun") == 0)
  1048.         term_name = "sun";
  1049. #endif /* sun */
  1050.  
  1051. #ifdef X11
  1052.        term = getenv("TERM");    /* try $TERM */
  1053.        if (term_name == (char *)NULL
  1054.           && term != (char *)NULL && strcmp(term, "xterm") == 0)
  1055.         term_name = "x11";
  1056.        display = getenv("DISPLAY");
  1057.        if (term_name == (char *)NULL && display != (char *)NULL)
  1058.         term_name = "x11";
  1059. #endif /* x11 */
  1060.  
  1061. #ifdef UNIXPC
  1062.            if (iswind() == 0) {
  1063.               term_name = "unixpc";
  1064.            }
  1065. #endif /* unixpc */
  1066.  
  1067. #ifdef CGI
  1068.        if (getenv("CGIDISP") || getenv("CGIPRNT"))
  1069.          term_name = "cgi";
  1070. #endif /*CGI */
  1071.     }
  1072.  
  1073.     /* We have a name, try to set term type */
  1074.     if (term_name != NULL && *term_name != '\0') {
  1075.        t = change_term(term_name, strlen(term_name));
  1076.        if (t == -1)
  1077.         fprintf(stderr, "Unknown terminal name '%s'\n", term_name);
  1078.        else if (t == -2)
  1079.         fprintf(stderr, "Ambiguous terminal name '%s'\n", term_name);
  1080.        else                /* successful */
  1081.         ;
  1082.     }
  1083. }
  1084.  
  1085.  
  1086. #ifdef __TURBOC__
  1087. char *
  1088. turboc_init()
  1089. {
  1090.   int g_driver,g_mode;
  1091.   char far *c1,*c2;
  1092.   char *term_name = NULL;
  1093.  
  1094. /* Some of this code including BGI drivers is copyright Borland Intl. */
  1095.     g_driver=DETECT;
  1096.           get_path();
  1097.         initgraph(&g_driver,&g_mode,path);
  1098.         c1=getdrivername();
  1099.         c2=getmodename(g_mode);
  1100.           switch (g_driver){
  1101.             case -2: fprintf(stderr,"Graphics card not detected.\n");
  1102.                      break;
  1103.             case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  1104.                      break;
  1105.             case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  1106.                      break;
  1107.             case -5: fprintf(stderr,"Insufficient memory to load ",
  1108.                              "graphics driver.");
  1109.                      break;
  1110.             case 1 : term_name = "cga";
  1111.                      break;
  1112.             case 2 : term_name = "mcga";
  1113.                      break;
  1114.             case 3 : 
  1115.             case 4 : term_name = "egalib";
  1116.                      break;
  1117.             case 7 : term_name = "hercules";
  1118.                      break;
  1119.             case 8 : term_name = "att";
  1120.                      break;
  1121.             case 9 : term_name = "vgalib";
  1122.                      break;
  1123.             }
  1124.         closegraph();
  1125.     fprintf(stderr,"\tTC Graphics, driver %s  mode %s\n",c1,c2);
  1126.   return(term_name);
  1127. }
  1128. #endif /* __TURBOC__ */
  1129.  
  1130. /*
  1131.     This is always defined so we don't have to have command.c know if it
  1132.     is there or not.
  1133. */
  1134. #ifndef UNIXPLOT
  1135. UP_redirect(caller) int caller; 
  1136. {
  1137.     caller = caller;    /* to stop Turbo C complaining 
  1138.                          * about caller not being used */
  1139. }
  1140. #else
  1141. UP_redirect (caller)
  1142. int caller;
  1143. /*
  1144.     Unixplot can't really write to outfile--it wants to write to stdout.
  1145.     This is normally ok, but the original design of gnuplot gives us
  1146.     little choice.  Originally users of unixplot had to anticipate
  1147.     their needs and redirect all I/O to a file...  Not very gnuplot-like.
  1148.  
  1149.     caller:  1 - called from SET OUTPUT "FOO.OUT"
  1150.              2 - called from SET TERM UNIXPLOT
  1151.              3 - called from SET TERM other
  1152.              4 - called from SET OUTPUT
  1153. */
  1154. {
  1155.     switch (caller) {
  1156.     case 1:
  1157.     /* Don't save, just replace stdout w/outfile (save was already done). */
  1158.         if (unixplot)
  1159.             *(stdout) = *(outfile);  /* Copy FILE structure */
  1160.     break;
  1161.     case 2:
  1162.         if (!unixplot) {
  1163.             fflush(stdout);
  1164.             save_stdout = *(stdout);
  1165.             *(stdout) = *(outfile);  /* Copy FILE structure */
  1166.             unixplot = 1;
  1167.         }
  1168.     break;
  1169.     case 3:
  1170.     /* New terminal in use--put stdout back to original. */
  1171.         closepl();
  1172.         fflush(stdout);
  1173.         *(stdout) = save_stdout;  /* Copy FILE structure */
  1174.         unixplot = 0;
  1175.     break;
  1176.     case 4:
  1177.     /*  User really wants to go to normal output... */
  1178.         if (unixplot) {
  1179.             fflush(stdout);
  1180.             *(stdout) = save_stdout;  /* Copy FILE structure */
  1181.         }
  1182.     break;
  1183.     }
  1184. }
  1185. #endif
  1186.  
  1187.  
  1188. /* test terminal by drawing border and text */
  1189. /* called from command test */
  1190. test_term()
  1191. {
  1192.     register struct termentry *t = &term_tbl[term];
  1193.     char *str;
  1194.     int x,y, xl,yl, i;
  1195.     unsigned int xmax, ymax;
  1196.     char label[MAX_ID_LEN];
  1197.  
  1198.     if (!term_init) {
  1199.        (*t->init)();
  1200.        term_init = TRUE;
  1201.     }
  1202.     screen_ok = FALSE;
  1203.     (void)(*t->scale)(xsize, ysize);
  1204.     xmax = (unsigned int)(t->xmax * xsize);
  1205.     ymax = (unsigned int)(t->ymax * ysize);
  1206.     (*t->graphics)();
  1207.     /* border linetype */
  1208.     (*t->linetype)(-2);
  1209.     (*t->move)(0,0);
  1210.     (*t->vector)(xmax-1,0);
  1211.     (*t->vector)(xmax-1,ymax-1);
  1212.     (*t->vector)(0,ymax-1);
  1213.     (*t->vector)(0,0);
  1214.     (void) (*t->justify_text)(LEFT);
  1215.     (*t->put_text)(t->h_char*5,ymax-t->v_char*3,"Terminal Test");
  1216.     /* axis linetype */
  1217.     (*t->linetype)(-1);
  1218.     (*t->move)(xmax/2,0);
  1219.     (*t->vector)(xmax/2,ymax-1);
  1220.     (*t->move)(0,ymax/2);
  1221.     (*t->vector)(xmax-1,ymax/2);
  1222.     /* test width and height of characters */
  1223.     (*t->linetype)(-2);
  1224.     (*t->move)(  xmax/2-t->h_char*10,ymax/2+t->v_char/2);
  1225.     (*t->vector)(xmax/2+t->h_char*10,ymax/2+t->v_char/2);
  1226.     (*t->vector)(xmax/2+t->h_char*10,ymax/2-t->v_char/2);
  1227.     (*t->vector)(xmax/2-t->h_char*10,ymax/2-t->v_char/2);
  1228.     (*t->vector)(xmax/2-t->h_char*10,ymax/2+t->v_char/2);
  1229.     (*t->put_text)(xmax/2-t->h_char*10,ymax/2,
  1230.         "12345678901234567890");
  1231.     /* test justification */
  1232.     (void) (*t->justify_text)(LEFT);
  1233.     (*t->put_text)(xmax/2,ymax/2+t->v_char*6,"left justified");
  1234.     str = "centre+d text";
  1235.     if ((*t->justify_text)(CENTRE))
  1236.         (*t->put_text)(xmax/2,
  1237.                 ymax/2+t->v_char*5,str);
  1238.     else
  1239.         (*t->put_text)(xmax/2-strlen(str)*t->h_char/2,
  1240.                 ymax/2+t->v_char*5,str);
  1241.     str = "right justified";
  1242.     if ((*t->justify_text)(RIGHT))
  1243.         (*t->put_text)(xmax/2,
  1244.                 ymax/2+t->v_char*4,str);
  1245.     else
  1246.         (*t->put_text)(xmax/2-strlen(str)*t->h_char,
  1247.                 ymax/2+t->v_char*4,str);
  1248.     /* test text angle */
  1249.     str = "rotated ce+ntred text";
  1250.     if ((*t->text_angle)(1)) {
  1251.         if ((*t->justify_text)(CENTRE))
  1252.             (*t->put_text)(t->v_char,
  1253.                 ymax/2,str);
  1254.         else
  1255.             (*t->put_text)(t->v_char,
  1256.                 ymax/2-strlen(str)*t->h_char/2,str);
  1257.     }
  1258.     else {
  1259.         (void) (*t->justify_text)(LEFT);
  1260.         (*t->put_text)(t->h_char*2,ymax/2-t->v_char*2,"Can't rotate text");
  1261.     }
  1262.     (void) (*t->justify_text)(LEFT);
  1263.     (void) (*t->text_angle)(0);
  1264.     /* test tic size */
  1265.     (*t->move)(xmax/2+t->h_tic*2,0);
  1266.     (*t->vector)(xmax/2+t->h_tic*2,t->v_tic);
  1267.     (*t->move)(xmax/2,t->v_tic*2);
  1268.     (*t->vector)(xmax/2+t->h_tic,t->v_tic*2);
  1269.     (*t->put_text)(xmax/2+t->h_tic*2,t->v_tic*2+t->v_char/2,"test tics");
  1270.     /* test line and point types */
  1271.     x = xmax - t->h_char*4 - t->h_tic*4;
  1272.     y = ymax - t->v_char;
  1273.     for ( i = -2; y > t->v_char; i++ ) {
  1274.         (*t->linetype)(i);
  1275.         (void) sprintf(label,"%d",i);
  1276.         if ((*t->justify_text)(RIGHT))
  1277.             (*t->put_text)(x,y,label);
  1278.         else
  1279.             (*t->put_text)(x-strlen(label)*t->h_char,y,label);
  1280.         (*t->move)(x+t->h_char,y);
  1281.         (*t->vector)(x+t->h_char*4,y);
  1282.         if ( i >= -1 )
  1283.             (*t->point)(x+t->h_char*4+t->h_tic*2,y,i);
  1284.         y -= t->v_char;
  1285.     }
  1286.     /* test some arrows */
  1287.     (*t->linetype)(0);
  1288.     x = xmax/4;
  1289.     y = ymax/4;
  1290.     xl = t->h_tic*5;
  1291.     yl = t->v_tic*5;
  1292.     (*t->arrow)(x,y,x+xl,y);
  1293.     (*t->arrow)(x,y,x+xl,y+yl);
  1294.     (*t->arrow)(x,y,x,y+yl);
  1295.     (*t->arrow)(x,y,x-xl,y+yl);
  1296.     (*t->arrow)(x,y,x-xl,y);
  1297.     (*t->arrow)(x,y,x-xl,y-yl);
  1298.     (*t->arrow)(x,y,x,y-yl);
  1299.     (*t->arrow)(x,y,x+xl,y-yl);
  1300.     /* and back into text mode */
  1301.     (*t->text)();
  1302. }
  1303.  
  1304.  
  1305. #ifdef PC
  1306. /* output for some terminal types must be binary to stop non Unix computers
  1307.    changing \n to \r\n. 
  1308.    If the output is not STDOUT, the following code reopens outfile 
  1309.    with binary mode. */
  1310. void
  1311. reopen_binary()
  1312. {
  1313. char filename[MAX_ID_LEN+1];
  1314.  
  1315.     if (strcmp(outstr,"STDOUT")) {
  1316.         (void) fclose(outfile);
  1317.         (void) strcpy(filename,outstr+1);    /* remove quotes */
  1318.         filename[strlen(filename)-1] = '\0';
  1319.         if ( (outfile = fopen(filename,"wb")) == (FILE *)NULL ) {
  1320.             if ( (outfile = fopen(filename,"w")) == (FILE *)NULL ) {
  1321.                 os_error("cannot reopen file with binary type; output unknown",
  1322.                     NO_CARET);
  1323.             } 
  1324.             else {
  1325.     os_error("cannot reopen file with binary type; output reset to ascii", 
  1326.                     NO_CARET);
  1327.             }
  1328.         }
  1329.     }
  1330. }
  1331. #endif
  1332.  
  1333. #ifdef VMS
  1334. /* these are needed to modify terminal characteristics */
  1335. #include <descrip.h>
  1336. #include <iodef.h>
  1337. #include <ttdef.h>
  1338. #include <tt2def.h>
  1339. #include <dcdef.h>
  1340. #include <ssdef.h>
  1341. #include <stat.h>
  1342. #include <fab.h>
  1343. static unsigned short   chan;
  1344. static int  old_char_buf[3], cur_char_buf[3];
  1345. $DESCRIPTOR(sysoutput_desc,"SYS$OUTPUT");
  1346.  
  1347. char *vms_init()
  1348. /*
  1349.  * Determine if we have a regis terminal
  1350.  * and save terminal characteristics
  1351. */
  1352. {
  1353.    /* Save terminal characteristics in old_char_buf and
  1354.    initialise cur_char_buf to current settings. */
  1355.    int i;
  1356.    sys$assign(&sysoutput_desc,&chan,0,0);
  1357.    sys$qiow(0,chan,IO$_SENSEMODE,0,0,0,old_char_buf,12,0,0,0,0);
  1358.    for (i = 0 ; i < 3 ; ++i) cur_char_buf[i] = old_char_buf[i];
  1359.    sys$dassgn(chan);
  1360.  
  1361.    /* Test if terminal is regis */
  1362.    if ((cur_char_buf[2] & TT2$M_REGIS) == TT2$M_REGIS) return("regis");
  1363.    return(NULL);
  1364. }
  1365.  
  1366. void
  1367. vms_reset()
  1368. /* set terminal to original state */
  1369. {
  1370.    int i;
  1371.    sys$assign(&sysoutput_desc,&chan,0,0);
  1372.    sys$qiow(0,chan,IO$_SETMODE,0,0,0,old_char_buf,12,0,0,0,0);
  1373.    for (i = 0 ; i < 3 ; ++i) cur_char_buf[i] = old_char_buf[i];
  1374.    sys$dassgn(chan);
  1375. }
  1376.  
  1377. void
  1378. term_mode_tek()
  1379. /* set terminal mode to tektronix */
  1380. {
  1381.    long status;
  1382.    if (outfile != stdout) return; /* don't modify if not stdout */
  1383.    sys$assign(&sysoutput_desc,&chan,0,0);
  1384.    cur_char_buf[0] = 0x004A0000 | DC$_TERM | (TT$_TEK401X<<8);
  1385.    cur_char_buf[1] = (cur_char_buf[1] & 0x00FFFFFF) | 0x18000000;
  1386.  
  1387.    cur_char_buf[1] &= ~TT$M_CRFILL;
  1388.    cur_char_buf[1] &= ~TT$M_ESCAPE;
  1389.    cur_char_buf[1] &= ~TT$M_HALFDUP;
  1390.    cur_char_buf[1] &= ~TT$M_LFFILL;
  1391.    cur_char_buf[1] &= ~TT$M_MECHFORM;
  1392.    cur_char_buf[1] &= ~TT$M_NOBRDCST;
  1393.    cur_char_buf[1] &= ~TT$M_NOECHO;
  1394.    cur_char_buf[1] &= ~TT$M_READSYNC;
  1395.    cur_char_buf[1] &= ~TT$M_REMOTE;
  1396.    cur_char_buf[1] |= TT$M_LOWER;
  1397.    cur_char_buf[1] |= TT$M_TTSYNC;
  1398.    cur_char_buf[1] |= TT$M_WRAP;
  1399.    cur_char_buf[1] &= ~TT$M_EIGHTBIT;
  1400.    cur_char_buf[1] &= ~TT$M_MECHTAB;
  1401.    cur_char_buf[1] &= ~TT$M_SCOPE;
  1402.    cur_char_buf[1] |= TT$M_HOSTSYNC;
  1403.  
  1404.    cur_char_buf[2] &= ~TT2$M_APP_KEYPAD;
  1405.    cur_char_buf[2] &= ~TT2$M_BLOCK;
  1406.    cur_char_buf[2] &= ~TT2$M_DECCRT3;
  1407.    cur_char_buf[2] &= ~TT2$M_LOCALECHO;
  1408.    cur_char_buf[2] &= ~TT2$M_PASTHRU;
  1409.    cur_char_buf[2] &= ~TT2$M_REGIS;
  1410.    cur_char_buf[2] &= ~TT2$M_SIXEL;
  1411.    cur_char_buf[2] |= TT2$M_BRDCSTMBX;
  1412.    cur_char_buf[2] |= TT2$M_EDITING;
  1413.    cur_char_buf[2] |= TT2$M_INSERT;
  1414.    cur_char_buf[2] |= TT2$M_PRINTER;
  1415.    cur_char_buf[2] &= ~TT2$M_ANSICRT;
  1416.    cur_char_buf[2] &= ~TT2$M_AVO;
  1417.    cur_char_buf[2] &= ~TT2$M_DECCRT;
  1418.    cur_char_buf[2] &= ~TT2$M_DECCRT2;
  1419.    cur_char_buf[2] &= ~TT2$M_DRCS;
  1420.    cur_char_buf[2] &= ~TT2$M_EDIT;
  1421.    cur_char_buf[2] |= TT2$M_FALLBACK;
  1422.  
  1423.    status = sys$qiow(0,chan,IO$_SETMODE,0,0,0,cur_char_buf,12,0,0,0,0);
  1424.    if (status == SS$_BADPARAM) {
  1425.       /* terminal fallback utility not installed on system */
  1426.       cur_char_buf[2] &= ~TT2$M_FALLBACK;
  1427.       sys$qiow(0,chan,IO$_SETMODE,0,0,0,cur_char_buf,12,0,0,0,0);
  1428.    }
  1429.    else {
  1430.       if (status != SS$_NORMAL)
  1431.          lib$signal(status,0,0);
  1432.    }
  1433.    sys$dassgn(chan);
  1434. }
  1435.  
  1436. void
  1437. term_mode_native()
  1438. /* set terminal mode back to native */
  1439. {
  1440.    int i;
  1441.    if (outfile != stdout) return; /* don't modify if not stdout */
  1442.    sys$assign(&sysoutput_desc,&chan,0,0);
  1443.    sys$qiow(0,chan,IO$_SETMODE,0,0,0,old_char_buf,12,0,0,0,0);
  1444.    for (i = 0 ; i < 3 ; ++i) cur_char_buf[i] = old_char_buf[i];
  1445.    sys$dassgn(chan);
  1446. }
  1447.  
  1448. void
  1449. term_pasthru()
  1450. /* set terminal mode pasthru */
  1451. {
  1452.    if (outfile != stdout) return; /* don't modify if not stdout */
  1453.    sys$assign(&sysoutput_desc,&chan,0,0);
  1454.    cur_char_buf[2] |= TT2$M_PASTHRU;
  1455.    sys$qiow(0,chan,IO$_SETMODE,0,0,0,cur_char_buf,12,0,0,0,0);
  1456.    sys$dassgn(chan);
  1457. }
  1458.  
  1459. void
  1460. term_nopasthru()
  1461. /* set terminal mode nopasthru */
  1462. {
  1463.    if (outfile != stdout) return; /* don't modify if not stdout */
  1464.    sys$assign(&sysoutput_desc,&chan,0,0);
  1465.    cur_char_buf[2] &= ~TT2$M_PASTHRU;
  1466.    sys$qiow(0,chan,IO$_SETMODE,0,0,0,cur_char_buf,12,0,0,0,0);
  1467.    sys$dassgn(chan);
  1468. }
  1469.  
  1470. void
  1471. reopen_binary()
  1472. /* close the file outfile outfile and reopen it with binary type
  1473.    if not already done or outfile == stdout */
  1474. {
  1475.    stat_t stat_buf;
  1476.    char filename[MAX_ID_LEN+1];
  1477.    if (outfile != stdout) { /* don't modify if not stdout */
  1478.       if (!fstat(fileno(outfile),&stat_buf)) {
  1479.          if (stat_buf.st_fab_rfm != FAB$C_FIX) {
  1480.             /* modify only if not already done */
  1481.             (void) fclose(outfile);
  1482.             (void) strcpy(filename,outstr+1);   /* remove quotes */
  1483.             filename[strlen(filename)-1] = '\0';
  1484.             (void) delete(filename);
  1485.             if ((outfile = fopen(filename,"wb","rfm=fix","bls=512","mrs=512"))
  1486.                 == (FILE *)NULL ) {
  1487.                if ( (outfile = fopen(filename,"w")) == (FILE *)NULL ) {
  1488.                  os_error("cannot reopen file with binary type; output unknown",
  1489.                            NO_CARET);
  1490.                }
  1491.                else {
  1492.           os_error("cannot reopen file with binary type; output reset to ascii",
  1493.                            NO_CARET);
  1494.                }
  1495.             }
  1496.          }
  1497.       }
  1498.       else{
  1499.          os_error("cannot reopen file with binary type; output remains ascii",
  1500.                   NO_CARET);
  1501.       }
  1502.    }
  1503. }
  1504.  
  1505. void
  1506. fflush_binary()
  1507. {
  1508.    typedef short int INT16;     /* signed 16-bit integers */
  1509.    register INT16 k;            /* loop index */
  1510.    if (outfile != stdout) {
  1511.        /* Stupid VMS fflush() raises error and loses last data block
  1512.           unless it is full for a fixed-length record binary file.
  1513.           Pad it here with NULL characters. */
  1514.        for (k = (INT16)((*outfile)->_cnt); k > 0; --k)
  1515.           putc('\0',outfile);
  1516.        fflush(outfile);
  1517.    }
  1518. }
  1519. #endif
  1520.