home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume8 / gnuplot1.10A / part04 / term.c < prev   
Encoding:
C/C++ Source or Header  |  1989-09-09  |  19.0 KB  |  776 lines

  1. /*
  2.  *
  3.  *    G N U P L O T  --  term.c
  4.  *
  5.  *  Copyright (C) 1986, 1987  Colin Kelley, Thomas Williams
  6.  *
  7.  *  You may use this code as you wish if credit is given and this message
  8.  *  is retained.
  9.  *
  10.  *  Please e-mail any useful additions to vu-vlsi!plot so they may be
  11.  *  included in later releases.
  12.  *
  13.  *  This file should be edited with 4-column tabs!  (:set ts=4 sw=4 in vi)
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include "plot.h"
  18.  
  19. char *getenv();
  20.  
  21. extern FILE *outfile;
  22. extern BOOLEAN term_init;
  23. extern int term;
  24.  
  25. extern char input_line[];
  26. extern struct lexical_unit token[];
  27. extern struct termentry term_tbl[];
  28.  
  29. /* This is needed because the unixplot library only writes to stdout. */
  30. FILE save_stdout;
  31. int unixplot=0;
  32.  
  33. #define NICE_LINE        0
  34. #define POINT_TYPES        6
  35.  
  36.  
  37. do_point(x,y,number)
  38. int x,y;
  39. int number;
  40. {
  41. register int htic,vtic;
  42. register struct termentry *t;
  43.  
  44.     number %= POINT_TYPES;
  45.     t = &term_tbl[term];
  46.     htic = (t->h_tic/2);    /* should be in term_tbl[] in later version */
  47.     vtic = (t->v_tic/2);    
  48.  
  49.     if ( x < t->h_tic || y < t->v_tic || x >= t->xmax-t->h_tic ||
  50.         y >= t->ymax-t->v_tic ) 
  51.         return;                /* add clipping in later version maybe */
  52.  
  53.     switch(number) {
  54.         case 0: /* do diamond */ 
  55.                 (*t->move)(x-htic,y);
  56.                 (*t->vector)(x,y-vtic);
  57.                 (*t->vector)(x+htic,y);
  58.                 (*t->vector)(x,y+vtic);
  59.                 (*t->vector)(x-htic,y);
  60.                 (*t->move)(x,y);
  61.                 (*t->vector)(x,y);
  62.                 break;
  63.         case 1: /* do plus */ 
  64.                 (*t->move)(x-htic,y);
  65.                 (*t->vector)(x-htic,y);
  66.                 (*t->vector)(x+htic,y);
  67.                 (*t->move)(x,y-vtic);
  68.                 (*t->vector)(x,y-vtic);
  69.                 (*t->vector)(x,y+vtic);
  70.                 break;
  71.         case 2: /* do box */ 
  72.                 (*t->move)(x-htic,y-vtic);
  73.                 (*t->vector)(x+htic,y-vtic);
  74.                 (*t->vector)(x+htic,y+vtic);
  75.                 (*t->vector)(x-htic,y+vtic);
  76.                 (*t->vector)(x-htic,y-vtic);
  77.                 (*t->move)(x,y);
  78.                 (*t->vector)(x,y);
  79.                 break;
  80.         case 3: /* do X */ 
  81.                 (*t->move)(x-htic,y-vtic);
  82.                 (*t->vector)(x-htic,y-vtic);
  83.                 (*t->vector)(x+htic,y+vtic);
  84.                 (*t->move)(x-htic,y+vtic);
  85.                 (*t->vector)(x-htic,y+vtic);
  86.                 (*t->vector)(x+htic,y-vtic);
  87.                 break;
  88.         case 4: /* do triangle */ 
  89.                 (*t->move)(x,y+(4*vtic/3));
  90.                 (*t->vector)(x-(4*htic/3),y-(2*vtic/3));
  91.                 (*t->vector)(x+(4*htic/3),y-(2*vtic/3));
  92.                 (*t->vector)(x,y+(4*vtic/3));
  93.                 (*t->move)(x,y);
  94.                 (*t->vector)(x,y);
  95.                 break;
  96.         case 5: /* do star */ 
  97.                 (*t->move)(x-htic,y);
  98.                 (*t->vector)(x-htic,y);
  99.                 (*t->vector)(x+htic,y);
  100.                 (*t->move)(x,y-vtic);
  101.                 (*t->vector)(x,y-vtic);
  102.                 (*t->vector)(x,y+vtic);
  103.                 (*t->move)(x-htic,y-vtic);
  104.                 (*t->vector)(x-htic,y-vtic);
  105.                 (*t->vector)(x+htic,y+vtic);
  106.                 (*t->move)(x-htic,y+vtic);
  107.                 (*t->vector)(x-htic,y+vtic);
  108.                 (*t->vector)(x+htic,y-vtic);
  109.                 break;
  110.     }
  111. }
  112.  
  113.  
  114. /*
  115.  * general point routine
  116.  */
  117. line_and_point(x,y,number)
  118. int x,y,number;
  119. {
  120.     /* temporary(?) kludge to allow terminals with bad linetypes 
  121.         to make nice marks */
  122.  
  123.     (*term_tbl[term].linetype)(NICE_LINE);
  124.     do_point(x,y,number);
  125. }
  126.  
  127.  
  128. #ifdef HPLJET
  129. #define RASTER
  130. #endif /* HPLJET */
  131.  
  132. #ifdef RASTER
  133. /*
  134. ** General raster plotting routines.
  135. ** Raster routines written and copyrighted 1987 by
  136. ** Jyrki Yli-Nokari (jty@intrin.UUCP)
  137. ** Intrinsic, Ltd.
  138. ** 
  139. ** You may use this code for anything you like as long as
  140. ** you are not selling it and the credit is given and
  141. ** this message retained.
  142. **
  143. ** The plotting area is defined as a huge raster.
  144. ** The raster is stored in a dynamically allocated pixel array r_p
  145. **
  146. ** The raster is allocated (and initialized to zero) with
  147. ** r_makeraster(xsize, ysize)
  148. ** and freed with r_freeraster()
  149. **
  150. ** Valid (unsigned) coordinates range from zero to (xsize-1,ysize-1)
  151. **
  152. ** Plotting is done via r_move(x, y) and r_draw(x, y, value) functions,
  153. ** where the point (x,y) is the target to go from the current point
  154. ** and value is the value (of type pixel) to be stored in every pixel.
  155. **
  156. ** Internally all plotting goes through r_setpixel(x, y, val).
  157. ** If you want different plotting styles (like OR, XOR...), use "value"
  158. ** in r_draw() to mark different styles and change r_setpixel() accordingly.
  159. */
  160.  
  161. #define IN(i,size)    ((unsigned)i < (unsigned)size)
  162. typedef char pixel;    /* the type of one pixel in raster */
  163. typedef pixel *raster[];    /* the raster */
  164.  
  165. static raster *r_p;    /* global pointer to raster */
  166. static unsigned r_currx, r_curry;    /* the current coordinates */
  167. static unsigned r_xsize, r_ysize;    /* the size of the raster */
  168.  
  169. char *calloc();
  170. void free();
  171.  
  172. /*
  173. ** set pixel (x, y, val) to value val (this can be 1/0 or a color number).
  174. */
  175. void
  176. r_setpixel(x, y, val)
  177. unsigned x, y;
  178. pixel val;
  179. {
  180.     if (IN(x, r_xsize) && IN(y, r_ysize)) {
  181.         *(((*r_p)[y]) + x) = val;
  182.     }
  183. #ifdef RASTERDEBUG
  184.     else {
  185.         fprintf(stderr, "Warning: setpixel(%d, %d, %d) out of bounds\n", x, y, val);
  186.     }
  187. #endif
  188. }
  189.  
  190. /*
  191. ** get pixel (x,y) value
  192. */
  193. pixel
  194. r_getpixel(x, y)
  195. unsigned x, y;
  196. {
  197.     if (IN(x, r_xsize) && IN(y, r_ysize)) {
  198.         return *(((*r_p)[y]) + x);
  199.     } else {
  200. #ifdef RASTERDEBUG
  201.         fprintf(stderr, "Warning: getpixel(%d,%d) out of bounds\n", x, y);
  202. #endif
  203.         return 0;
  204.     }
  205. }
  206.  
  207. /*
  208. ** allocate the raster
  209. */
  210. void
  211. r_makeraster(x, y)
  212. unsigned x, y;
  213. {
  214.     register unsigned j;
  215.     
  216.     /* allocate row pointers */
  217.     if ((r_p = (raster *)calloc(y, sizeof(pixel *))) == (raster *)0) {
  218.         fprintf(stderr, "Raster buffer allocation failure\n");
  219.         exit(1);
  220.     }
  221.     for (j = 0; j < y; j++) {
  222.         if (((*r_p)[j] = (pixel *)calloc(x, sizeof(pixel))) == (pixel *)0) {
  223.             fprintf(stderr, "Raster buffer allocation failure\n");
  224.             exit(1);
  225.         }
  226.     }
  227.     r_xsize = x; r_ysize = y;
  228.     r_currx = r_curry = 0;
  229. }
  230.     
  231. /*
  232. ** plot a line from (x0,y0) to (x1,y1) with color val.
  233. */
  234. void
  235. r_plot(x0, y0, x1, y1, val)
  236. unsigned x0, y0, x1, y1;
  237. pixel val;
  238. {
  239.     unsigned hx, hy, i;
  240.     int e, dx, dy;
  241.  
  242.     hx = abs((int)(x1 - x0));
  243.     hy = abs((int)(y1 - y0));
  244.     dx = (x1 > x0) ? 1 : -1;
  245.     dy = (y1 > y0) ? 1 : -1;
  246.     
  247.     if (hx > hy) {
  248.         /*
  249.         ** loop over x-axis
  250.         */
  251.         e = hy + hy - hx;
  252.         for (i = 0; i <= hx; i++) {
  253.             r_setpixel(x0, y0, val);
  254.             if (e > 0) {
  255.                 y0 += dy;
  256.                 e += hy + hy - hx - hx;
  257.             } else {
  258.                 e += hy + hy;
  259.             }
  260.             x0 += dx;
  261.         }
  262.     } else {
  263.         /*
  264.         ** loop over y-axis
  265.         */
  266.         e = hx + hx - hy;
  267.         for (i = 0; i <= hy; i++) {
  268.             r_setpixel(x0, y0, val);
  269.             if (e > 0) {
  270.                 x0 += dx;
  271.                 e += hx + hx - hy - hy;
  272.             } else {
  273.                 e += hx + hx;
  274.             }
  275.             y0 += dy;
  276.         }
  277.     }
  278. }
  279.  
  280. /*
  281. ** move to (x,y)
  282. */
  283. void
  284. r_move(x, y)
  285. unsigned x, y;
  286. {
  287.     r_currx = x;
  288.     r_curry = y;
  289. }
  290.  
  291. /*
  292. ** draw to (x,y) with color val
  293. ** (move pen down)
  294. */
  295. void
  296. r_draw(x, y, val)
  297. unsigned x, y;
  298. pixel val;
  299. {
  300.     r_plot(r_currx, r_curry, x, y, val);
  301.     r_currx = x;
  302.     r_curry = y;
  303. }
  304.  
  305. /*
  306. ** free the allocated raster
  307. */
  308. void
  309. r_freeraster()
  310. {
  311.     int y;
  312.  
  313.     for (y = 0; y < r_ysize; y++) {
  314.         free((char *)(*r_p)[y]);
  315.     }
  316.     free((char *)r_p);
  317. }
  318. #endif /* RASTER */
  319.  
  320. #ifdef HPLJET
  321. #include "hpljet.trm"
  322. #endif /* HPLJET */
  323.  
  324. #ifdef PC
  325. #include "pc.trm"
  326. #endif /* PC */
  327.  
  328. #ifdef AED
  329. #include "aed.trm"
  330. #endif /* AED */
  331.  
  332. #ifdef BITGRAPH
  333. #include "bitgraph.trm"
  334. #endif /* BITGRAPH */
  335.  
  336. #ifdef HP26
  337. #include "hp26.trm"
  338. #endif /* HP26 */
  339.  
  340. #ifdef HP75
  341. #include "hp75.trm"
  342. #endif /* HP75 */
  343.  
  344. #ifdef IRIS4D
  345. #include "iris4d.trm"
  346. #endif /* IRIS4D */
  347.  
  348. #ifdef POSTSCRIPT
  349. #include "postscpt.trm"
  350. #endif /* POSTSCRIPT */
  351.  
  352.  
  353. #ifdef QMS
  354. #include "qms.trm"
  355. #endif /* QMS */
  356.  
  357.  
  358. #ifdef REGIS
  359. #include "regis.trm"
  360. #endif /* REGIS */
  361.  
  362.  
  363. #ifdef SELANAR
  364. #include "selanar.trm"
  365. #endif /* SELANAR */
  366.  
  367.  
  368. #ifdef TEK
  369. #include "tek.trm"
  370. #endif /* TEK */
  371.  
  372.  
  373. #ifdef V384
  374. #include "v384.trm"
  375. #endif /* V384 */
  376.  
  377.  
  378. #ifdef UNIXPLOT
  379. /*
  380.    Unixplot library writes to stdout.  A fix was put in place by
  381.    ..!arizona!naucse!jdc to let set term and set output redirect
  382.    stdout.  All other terminals write to outfile.
  383. */
  384. #include "unixplot.trm"
  385. #endif /* UNIXPLOT */
  386.  
  387. #ifdef UNIXPC     /* unix-PC  ATT 7300 or 3b1 machine */
  388. #include "unixpc.trm"
  389. #endif /* UNIXPC */
  390.  
  391.  
  392. UNKNOWN_null()
  393. {
  394. }
  395.  
  396.  
  397. /*
  398.  * term_tbl[] contains an entry for each terminal.  "unknown" must be the
  399.  *   first, since term is initialized to 0.
  400.  */
  401. struct termentry term_tbl[] = {
  402.     {"unknown", 100, 100, 1, 1, 1, 1, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null,
  403.     UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null,
  404.     UNKNOWN_null, UNKNOWN_null}
  405. #ifdef HPLJET
  406.     ,{"laserjet1",HPLJETXMAX,HPLJETYMAX,HPLJET1VCHAR, HPLJET1HCHAR, HPLJETVTIC,
  407.         HPLJETHTIC, HPLJET1init,HPLJETreset, HPLJETtext, HPLJETgraphics, 
  408.         HPLJETmove, HPLJETvector,HPLJETlinetype,HPLJETlrput_text,
  409.         HPLJETulput_text, line_and_point}
  410.     ,{"laserjet2",HPLJETXMAX,HPLJETYMAX,HPLJET2VCHAR, HPLJET2HCHAR, HPLJETVTIC, 
  411.         HPLJETHTIC, HPLJET2init,HPLJETreset, HPLJETtext, HPLJETgraphics, 
  412.         HPLJETmove, HPLJETvector,HPLJETlinetype,HPLJETlrput_text,
  413.         HPLJETulput_text, line_and_point}
  414.     ,{"laserjet3",HPLJETXMAX,HPLJETYMAX,HPLJET3VCHAR, HPLJET3HCHAR, HPLJETVTIC, 
  415.         HPLJETHTIC, HPLJET3init,HPLJETreset, HPLJETtext, HPLJETgraphics, 
  416.         HPLJETmove, HPLJETvector,HPLJETlinetype,HPLJETlrput_text,
  417.         HPLJETulput_text, line_and_point}
  418. #endif
  419.  
  420. #ifdef PC
  421. #ifdef __TURBOC__
  422.  
  423.     ,{"egalib", EGALIB_XMAX, EGALIB_YMAX, EGALIB_VCHAR, EGALIB_HCHAR,
  424.         EGALIB_VTIC, EGALIB_HTIC, EGALIB_init, EGALIB_reset,
  425.         EGALIB_text, EGALIB_graphics, EGALIB_move, EGALIB_vector,
  426.         EGALIB_linetype, EGALIB_lrput_text, EGALIB_ulput_text, line_and_point}
  427.  
  428.     ,{"vgalib", VGA_XMAX, VGA_YMAX, VGA_VCHAR, VGA_HCHAR,
  429.         VGA_VTIC, VGA_HTIC, VGA_init, VGA_reset,
  430.         VGA_text, VGA_graphics, VGA_move, VGA_vector,
  431.         VGA_linetype, VGA_lrput_text, VGA_ulput_text, line_and_point}
  432.  
  433.     ,{"vgamono", VGA_XMAX, VGA_YMAX, VGA_VCHAR, VGA_HCHAR,
  434.         VGA_VTIC, VGA_HTIC, VGA_init, VGA_reset,
  435.         VGA_text, VGA_graphics, VGA_move, VGA_vector,
  436.         VGAMONO_linetype, VGA_lrput_text, VGA_ulput_text, line_and_point}
  437.  
  438.     ,{"mcga", MCGA_XMAX, MCGA_YMAX, MCGA_VCHAR, MCGA_HCHAR,
  439.         MCGA_VTIC, MCGA_HTIC, MCGA_init, MCGA_reset,
  440.         MCGA_text, MCGA_graphics, MCGA_move, MCGA_vector,
  441.         MCGA_linetype, MCGA_lrput_text, MCGA_ulput_text, line_and_point}
  442.  
  443.     ,{"cga", CGA_XMAX, CGA_YMAX, CGA_VCHAR, CGA_HCHAR,
  444.         CGA_VTIC, CGA_HTIC, CGA_init, CGA_reset,
  445.         CGA_text, CGA_graphics, CGA_move, CGA_vector,
  446.         CGA_linetype, CGA_lrput_text, CGA_ulput_text, line_and_point}
  447.  
  448.     ,{"hercules", HERC_XMAX, HERC_YMAX, HERC_VCHAR, HERC_HCHAR,
  449.         HERC_VTIC, HERC_HTIC, HERC_init, HERC_reset,
  450.         HERC_text, HERC_graphics, HERC_move, HERC_vector,
  451.         HERC_linetype, HERC_lrput_text, HERC_ulput_text, line_and_point}
  452.  
  453. #else
  454.     ,{"cga", CGA_XMAX, CGA_YMAX, CGA_VCHAR, CGA_HCHAR,
  455.         CGA_VTIC, CGA_HTIC, CGA_init, CGA_reset,
  456.         CGA_text, CGA_graphics, CGA_move, CGA_vector,
  457.         CGA_linetype, CGA_lrput_text, CGA_ulput_text, line_and_point}
  458.  
  459.     ,{"egabios", EGA_XMAX, EGA_YMAX, EGA_VCHAR, EGA_HCHAR,
  460.         EGA_VTIC, EGA_HTIC, EGA_init, EGA_reset,
  461.         EGA_text, EGA_graphics, EGA_move, EGA_vector,
  462.         EGA_linetype, EGA_lrput_text, EGA_ulput_text, do_point}
  463.  
  464. #ifdef EGALIB
  465.     ,{"egalib", EGALIB_XMAX, EGALIB_YMAX, EGALIB_VCHAR, EGALIB_HCHAR,
  466.         EGALIB_VTIC, EGALIB_HTIC, EGALIB_init, EGALIB_reset,
  467.         EGALIB_text, EGALIB_graphics, EGALIB_move, EGALIB_vector,
  468.         EGALIB_linetype, EGALIB_lrput_text, EGALIB_ulput_text, do_point}
  469. #endif
  470.  
  471. #ifdef HERCULES
  472.     ,{"hercules", HERC_XMAX, HERC_YMAX, HERC_VCHAR, HERC_HCHAR,
  473.         HERC_VTIC, HERC_HTIC, HERC_init, HERC_reset,
  474.         HERC_text, HERC_graphics, HERC_move, HERC_vector,
  475.         HERC_linetype, HERC_lrput_text, HERC_ulput_text, line_and_point}
  476. #endif /* HERCULES */
  477.  
  478. #ifdef ATT6300
  479.     ,{"att", ATT_XMAX, ATT_YMAX, ATT_VCHAR, ATT_HCHAR,
  480.         ATT_VTIC, ATT_HTIC, ATT_init, ATT_reset,
  481.         ATT_text, ATT_graphics, ATT_move, ATT_vector,
  482.         ATT_linetype, ATT_lrput_text, ATT_ulput_text, line_and_point}
  483. #endif
  484.  
  485. #ifdef CORONA
  486.     ,{"corona325", COR_XMAX, COR_YMAX, COR_VCHAR, COR_HCHAR,
  487.         COR_VTIC, COR_HTIC, COR_init, COR_reset,
  488.         COR_text, COR_graphics, COR_move, COR_vector,
  489.         COR_linetype, COR_lrput_text, COR_ulput_text, line_and_point}
  490. #endif /* CORONA */
  491. #endif /* TURBOC */
  492. #endif /* PC */
  493.  
  494. #ifdef AED
  495.     ,{"aed512", AED5_XMAX, AED_YMAX, AED_VCHAR, AED_HCHAR,
  496.         AED_VTIC, AED_HTIC, AED_init, AED_reset, 
  497.         AED_text, AED_graphics, AED_move, AED_vector, 
  498.         AED_linetype, AED5_lrput_text, AED_ulput_text, do_point}
  499.     ,{"aed767", AED_XMAX, AED_YMAX, AED_VCHAR, AED_HCHAR,
  500.         AED_VTIC, AED_HTIC, AED_init, AED_reset, 
  501.         AED_text, AED_graphics, AED_move, AED_vector, 
  502.         AED_linetype, AED_lrput_text, AED_ulput_text, do_point}
  503. #endif
  504.  
  505. #ifdef UNIXPC
  506.     ,{"unixpc",uPC_XMAX,uPC_YMAX,uPC_VCHAR, uPC_HCHAR, uPC_VTIC, 
  507.         uPC_HTIC, uPC_init,uPC_reset, uPC_text, uPC_graphics, 
  508.         uPC_move, uPC_vector,uPC_linetype,uPC_lrput_text,
  509.         uPC_ulput_text, line_and_point}
  510. #endif
  511.  
  512. #ifdef BITGRAPH
  513.     ,{"bitgraph",BG_XMAX,BG_YMAX,BG_VCHAR, BG_HCHAR, BG_VTIC, 
  514.         BG_HTIC, BG_init,BG_reset, BG_text, BG_graphics, 
  515.         BG_move, BG_vector,BG_linetype,BG_lrput_text,
  516.         BG_ulput_text, line_and_point}
  517. #endif
  518.  
  519. #ifdef HP26
  520.     ,{"hp2623A",HP26_XMAX,HP26_YMAX, HP26_VCHAR, HP26_HCHAR,HP26_VTIC,HP26_HTIC,
  521.         HP26_init,HP26_reset,HP26_text, HP26_graphics, HP26_move, HP26_vector,
  522.         HP26_linetype, HP26_lrput_text, HP26_ulput_text, line_and_point}
  523. #endif
  524.  
  525. #ifdef HP75
  526.     ,{"hp7580B",HP75_XMAX,HP75_YMAX, HP75_VCHAR, HP75_HCHAR,HP75_VTIC,HP75_HTIC,
  527.         HP75_init,HP75_reset,HP75_text, HP75_graphics, HP75_move, HP75_vector,
  528.         HP75_linetype, HP75_lrput_text, HP75_ulput_text, do_point}
  529. #endif
  530.  
  531. #ifdef IRIS4D
  532.     ,{"iris4d", IRIS4D_XMAX, IRIS4D_YMAX, IRIS4D_VCHAR,
  533.         IRIS4D_HCHAR, IRIS4D_VTIC, IRIS4D_HTIC,
  534.         IRIS4D_init, IRIS4D_reset, IRIS4D_text,
  535.         IRIS4D_graphics, IRIS4D_move, IRIS4D_vector,
  536.         IRIS4D_linetype, IRIS4D_lrput_text, IRIS4D_ulput_text,
  537.         do_point}
  538. #endif
  539.  
  540. #ifdef POSTSCRIPT
  541.     ,{"postscript", PS_XMAX, PS_YMAX, PS_VCHAR, PS_HCHAR, PS_VTIC, PS_HTIC,
  542.         PS_init, PS_reset, PS_text, PS_graphics, PS_move, PS_vector,
  543.         PS_linetype, PS_lrput_text, PS_ulput_text, line_and_point}
  544. #endif
  545.  
  546. #ifdef QMS
  547.     ,{"qms",QMS_XMAX,QMS_YMAX, QMS_VCHAR, QMS_HCHAR, QMS_VTIC, QMS_HTIC,
  548.         QMS_init,QMS_reset, QMS_text, QMS_graphics, QMS_move, QMS_vector,
  549.         QMS_linetype,QMS_lrput_text,QMS_ulput_text,line_and_point}
  550. #endif
  551.  
  552. #ifdef REGIS
  553.     ,{"regis", REGISXMAX, REGISYMAX, REGISVCHAR, REGISHCHAR, REGISVTIC,
  554.         REGISHTIC, REGISinit, REGISreset, REGIStext, REGISgraphics,
  555.         REGISmove,REGISvector,REGISlinetype, REGISlrput_text, REGISulput_text,
  556.         line_and_point}
  557. #endif
  558.  
  559.  
  560. #ifdef SELANAR
  561.     ,{"selanar",TEK40XMAX,TEK40YMAX,TEK40VCHAR, TEK40HCHAR, TEK40VTIC, 
  562.         TEK40HTIC, SEL_init, SEL_reset, SEL_text, SEL_graphics, 
  563.         TEK40move, TEK40vector, TEK40linetype, TEK40lrput_text,
  564.         TEK40ulput_text, line_and_point}
  565. #endif
  566.  
  567. #ifdef TEK
  568.     ,{"tek40xx",TEK40XMAX,TEK40YMAX,TEK40VCHAR, TEK40HCHAR, TEK40VTIC, 
  569.         TEK40HTIC, TEK40init, TEK40reset, TEK40text, TEK40graphics, 
  570.         TEK40move, TEK40vector, TEK40linetype, TEK40lrput_text,
  571.         TEK40ulput_text, line_and_point}
  572. #endif
  573.  
  574. #ifdef UNIXPLOT
  575.     ,{"unixplot", UP_XMAX, UP_YMAX, UP_VCHAR, UP_HCHAR, UP_VTIC, UP_HTIC,
  576.         UP_init, UP_reset, UP_text, UP_graphics, UP_move, UP_vector,
  577.         UP_linetype, UP_lrput_text, UP_ulput_text, line_and_point}
  578. #endif
  579.  
  580. #ifdef V384
  581.     ,{"vx384", V384_XMAX, V384_YMAX, V384_VCHAR, V384_HCHAR, V384_VTIC,
  582.         V384_HTIC, V384_init, V384_reset, V384_text, V384_graphics,
  583.         V384_move, V384_vector, V384_linetype, V384_lrput_text,
  584.         V384_ulput_text, do_point}
  585. #endif
  586.     };
  587.  
  588. #define TERMCOUNT (sizeof(term_tbl)/sizeof(struct termentry))
  589.  
  590.  
  591. list_terms()
  592. {
  593. register int i;
  594.  
  595.     fprintf(stderr,"\navailable terminals types:\n");
  596.     for (i = 0; i < TERMCOUNT; i++)
  597.         fprintf(stderr,"\t%s\n",term_tbl[i].name);
  598.     (void) putc('\n',stderr);
  599. }
  600.  
  601.  
  602. set_term(c_token)
  603. int c_token;
  604. {
  605. register int i,t;
  606.  
  607.     if (!token[c_token].is_token)
  608.         int_error("terminal name expected",c_token);
  609.     t = -1;
  610.  
  611.     for (i = 0; i < TERMCOUNT; i++) {
  612.            if (!strncmp(input_line + token[c_token].start_index,term_tbl[i].name,
  613.             token[c_token].length)) {
  614.             if (t != -1)
  615.                 int_error("ambiguous terminal name",c_token);
  616.             t = i;
  617.         }
  618.     }
  619.     if (t == -1)
  620.         int_error("unknown terminal type; type just 'set terminal' for a list",
  621.             c_token);
  622.     else if (!strncmp("unixplot",term_tbl[t].name,sizeof(unixplot))) {
  623.         UP_redirect (2);  /* Redirect actual stdout for unixplots */
  624.     }
  625.     else if (unixplot) {
  626.         UP_redirect (3);  /* Put stdout back together again. */
  627.     }
  628.     term_init = FALSE;
  629.     return(t);
  630. }
  631.  
  632.  
  633. /*
  634.    Routine to detect what terminal is being used (or do anything else
  635.    that would be nice).  One anticipated (or allowed for) side effect
  636.    is that the global ``term'' may be set.
  637. */
  638. init()
  639. {
  640. char *term_name = NULL;
  641. int t = -1, i;
  642. #ifdef __TURBOC__
  643.   int g_driver,g_mode;
  644.   char far *c1,*c2;
  645.  
  646. /* Some of this code including BGI drivers is copyright Borland Intl. */
  647.     g_driver=DETECT;
  648.           get_path();
  649.         initgraph(&g_driver,&g_mode,path);
  650.         c1=getdrivername();
  651.         c2=getmodename(g_mode);
  652.           switch (g_driver){
  653.             case -2: fprintf(stderr,"Graphics card not detected.\n");
  654.                      break;
  655.             case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  656.                      break;
  657.             case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  658.                      break;
  659.             case -5: fprintf(stderr,"Insufficient memory to load ",
  660.                              "graphics driver.");
  661.                      break;
  662.             }
  663.         closegraph();
  664.     fprintf(stderr,"\tTC Graphics, driver %s  mode %s\n",c1,c2);
  665. #endif
  666. #ifdef VMS
  667. /*
  668.    Determine if we have a regis terminal.  If not use TERM 
  669.    (tek40xx) as default.
  670. */
  671. #include <descrip>
  672. #include <dvidef>
  673.  
  674. extern int term;
  675. char *term_str="tt:";
  676. typedef struct
  677.           {
  678.           short cond_value;
  679.           short count;
  680.           int info;
  681.           }  status_block;
  682. typedef struct
  683.           {
  684.           short buffer_len;
  685.           short item_code;
  686.           int buffer_addr;
  687.           int ret_len_addr;
  688.           }  item_desc;
  689. struct {
  690.     item_desc dev_type;
  691.       int terminator;
  692.    }  dvi_list;
  693.    int status, dev_type, zero=0;
  694.    char buffer[255];
  695.    $DESCRIPTOR(term_desc, term_str);
  696.  
  697. /* set up dvi item list */
  698.     dvi_list.dev_type.buffer_len = 4;
  699.     dvi_list.dev_type.item_code = DVI$_TT_REGIS;
  700.     dvi_list.dev_type.buffer_addr = &dev_type;
  701.     dvi_list.dev_type.ret_len_addr = 0;
  702.  
  703.     dvi_list.terminator = 0;
  704.  
  705. /* See what type of terminal we have. */
  706.     status = SYS$GETDVIW (0, 0, &term_desc, &dvi_list, 0, 0, 0, 0);
  707.     if ((status & 1) && dev_type) {
  708.         term_name = "regis";
  709.     }
  710. #endif
  711.     if (term_name != NULL) {
  712.     /* We have a name to set! */
  713.         for (i = 0; i < TERMCOUNT; i++) {
  714.                if (!strncmp("regis",term_tbl[i].name,5)) {
  715.                 t = i;
  716.             }
  717.         }
  718.         if (t != -1)
  719.             term = t;
  720.     }
  721. }
  722.  
  723.  
  724. /*
  725.     This is always defined so we don't have to have command.c know if it
  726.     is there or not.
  727. */
  728. #ifndef UNIXPLOT
  729. UP_redirect(caller) int caller; {}
  730. #else
  731. UP_redirect (caller)
  732. int caller;
  733. /*
  734.     Unixplot can't really write to outfile--it wants to write to stdout.
  735.     This is normally ok, but the original design of gnuplot gives us
  736.     little choice.  Originally users of unixplot had to anticipate
  737.     their needs and redirect all I/O to a file...  Not very gnuplot-like.
  738.  
  739.     caller:  1 - called from SET OUTPUT "FOO.OUT"
  740.              2 - called from SET TERM UNIXPLOT
  741.              3 - called from SET TERM other
  742.              4 - called from SET OUTPUT
  743. */
  744. {
  745.     switch (caller) {
  746.     case 1:
  747.     /* Don't save, just replace stdout w/outfile (save was already done). */
  748.         if (unixplot)
  749.             *(stdout) = *(outfile);  /* Copy FILE structure */
  750.     break;
  751.     case 2:
  752.         if (!unixplot) {
  753.             fflush(stdout);
  754.             save_stdout = *(stdout);
  755.             *(stdout) = *(outfile);  /* Copy FILE structure */
  756.             unixplot = 1;
  757.         }
  758.     break;
  759.     case 3:
  760.     /* New terminal in use--put stdout back to original. */
  761.         closepl();
  762.         fflush(stdout);
  763.         *(stdout) = save_stdout;  /* Copy FILE structure */
  764.         unixplot = 0;
  765.     break;
  766.     case 4:
  767.     /*  User really wants to go to normal output... */
  768.         if (unixplot) {
  769.             fflush(stdout);
  770.             *(stdout) = save_stdout;  /* Copy FILE structure */
  771.         }
  772.     break;
  773.     }
  774. }
  775. #endif
  776.