home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d386 / xlispstat.lha / XLispStat / src3.lzh / UNIX / term.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-30  |  5.3 KB  |  255 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 "gnuplot.h"
  17. #include <stdio.h>
  18. #include "xlisp.h"
  19. extern LVAL s_stdout, s_unbound;
  20. static LVAL s_plotout = NIL;
  21.  
  22. LOCAL LVAL get_plot_stream()
  23. {
  24.   LVAL stream;
  25.  
  26.   if (s_plotout == NIL) {
  27.     s_plotout = xlenter("*PLOT-OUTPUT*");
  28.     if (getvalue(s_plotout) == s_unbound) 
  29.       setvalue(s_plotout, getvalue(s_stdout));
  30.   }
  31.  
  32.   stream = getvalue(s_plotout);
  33.   if (! streamp(stream) && ! ustreamp(stream)) xlerror("not a stream", stream);
  34.  
  35.   return(stream);
  36. }
  37.  
  38. extern struct termentry term_tbl[];
  39. int term = 1;  /* gives tek */
  40.  
  41. #define NICE_LINE        0
  42. #define POINT_TYPES        6
  43.  
  44. do_point(x,y,number)
  45.      int x,y;
  46.      int number;
  47. {
  48.   register int htic,vtic;
  49.   register struct termentry *t;
  50.  
  51.   number %= POINT_TYPES;
  52.   t = &term_tbl[term];
  53.   htic = (t->h_tic/2);    /* should be in term_tbl[] in later version */
  54.   vtic = (t->v_tic/2);    
  55.  
  56.   if ( x < t->h_tic || y < t->v_tic || x >= t->xmax-t->h_tic ||
  57.       y >= t->ymax-t->v_tic ) 
  58.     return;        /* add clipping in later version maybe */
  59.  
  60.   switch(number) {
  61.   case 0: /* do diamond */ 
  62.     (*t->move)(x-htic,y);
  63.     (*t->vector)(x,y-vtic);
  64.     (*t->vector)(x+htic,y);
  65.     (*t->vector)(x,y+vtic);
  66.     (*t->vector)(x-htic,y);
  67.     (*t->move)(x,y);
  68.     (*t->vector)(x,y);
  69.     break;
  70.   case 1: /* do plus */ 
  71.     (*t->move)(x-htic,y);
  72.     (*t->vector)(x-htic,y);
  73.     (*t->vector)(x+htic,y);
  74.     (*t->move)(x,y-vtic);
  75.     (*t->vector)(x,y-vtic);
  76.     (*t->vector)(x,y+vtic);
  77.     break;
  78.   case 2: /* do box */ 
  79.     (*t->move)(x-htic,y-vtic);
  80.     (*t->vector)(x+htic,y-vtic);
  81.     (*t->vector)(x+htic,y+vtic);
  82.     (*t->vector)(x-htic,y+vtic);
  83.     (*t->vector)(x-htic,y-vtic);
  84.     (*t->move)(x,y);
  85.     (*t->vector)(x,y);
  86.     break;
  87.   case 3: /* do X */ 
  88.     (*t->move)(x-htic,y-vtic);
  89.     (*t->vector)(x-htic,y-vtic);
  90.     (*t->vector)(x+htic,y+vtic);
  91.     (*t->move)(x-htic,y+vtic);
  92.     (*t->vector)(x-htic,y+vtic);
  93.     (*t->vector)(x+htic,y-vtic);
  94.     break;
  95.   case 4: /* do triangle */ 
  96.     (*t->move)(x,y+(4*vtic/3));
  97.     (*t->vector)(x-(4*htic/3),y-(2*vtic/3));
  98.     (*t->vector)(x+(4*htic/3),y-(2*vtic/3));
  99.     (*t->vector)(x,y+(4*vtic/3));
  100.     (*t->move)(x,y);
  101.     (*t->vector)(x,y);
  102.     break;
  103.   case 5: /* do star */ 
  104.     (*t->move)(x-htic,y);
  105.     (*t->vector)(x-htic,y);
  106.     (*t->vector)(x+htic,y);
  107.     (*t->move)(x,y-vtic);
  108.     (*t->vector)(x,y-vtic);
  109.     (*t->vector)(x,y+vtic);
  110.     (*t->move)(x-htic,y-vtic);
  111.     (*t->vector)(x-htic,y-vtic);
  112.     (*t->vector)(x+htic,y+vtic);
  113.     (*t->move)(x-htic,y+vtic);
  114.     (*t->vector)(x-htic,y+vtic);
  115.     (*t->vector)(x+htic,y-vtic);
  116.     break;
  117.   }
  118. }
  119.  
  120. /*
  121.  * general point routine
  122.  */
  123. line_and_point(x,y,number)
  124.      int x,y,number;
  125. {
  126.   /* temporary(?) kludge to allow terminals with bad linetypes 
  127.      to make nice marks */
  128.   
  129.   (*term_tbl[term].linetype)(NICE_LINE);
  130.   do_point(x,y,number);
  131. }
  132.  
  133.  
  134. #define TEK40XMAX 1024
  135. #define TEK40YMAX 780
  136.  
  137. #define TEK40XLAST (TEK40XMAX - 1)
  138. #define TEK40YLAST (TEK40YMAX - 1)
  139.  
  140. #define TEK40VCHAR        25
  141. #define TEK40HCHAR        14
  142. #define TEK40VTIC        11
  143. #define TEK40HTIC        11    
  144.  
  145. #define HX 0x20        /* bit pattern to OR over 5-bit data */
  146. #define HY 0x20
  147. #define LX 0x40
  148. #define LY 0x60
  149.  
  150. #define LOWER5 31
  151. #define UPPER5 (31<<5)
  152.  
  153.  
  154.   TEK40init()
  155. {
  156. }
  157.  
  158.  
  159. TEK40graphics()
  160. {
  161.   xlputstr(get_plot_stream(), "\033\014");
  162.   /*                   1
  163.                1. clear screen
  164.                */
  165.   return(0);
  166. }
  167.  
  168.  
  169. TEK40text()
  170. {
  171.   TEK40move(0,12);
  172.   xlputstr(get_plot_stream(), "\037");
  173.   /*                   1
  174.                1. into alphanumerics
  175.                */
  176. }
  177.  
  178.  
  179. TEK40linetype(linetype)
  180.      int linetype;
  181. {
  182. }
  183.  
  184.  
  185. TEK40move(x,y)
  186.      unsigned int x,y;
  187. {
  188.   xlputc(get_plot_stream(), '\035');    /* into graphics */
  189.   TEK40vector(x,y);
  190. }
  191.  
  192.  
  193. TEK40vector(x,y)
  194.      unsigned int x,y;
  195. {
  196.   xlputc(get_plot_stream(), (HY | (y & UPPER5)>>5));
  197.   xlputc(get_plot_stream(), (LY | (y & LOWER5)));
  198.   xlputc(get_plot_stream(), (HX | (x & UPPER5)>>5));
  199.   xlputc(get_plot_stream(), (LX | (x & LOWER5)));
  200. }
  201.  
  202.  
  203. TEK40lrput_text(row,str)
  204.      unsigned int row;
  205.      char str[];
  206. {
  207.   TEK40move(TEK40XMAX - TEK40HTIC - TEK40HCHAR*(strlen(str)+1),
  208.         TEK40VTIC + TEK40VCHAR*(row+1));
  209.   xlputc(get_plot_stream(), '\037');
  210.   xlputstr(get_plot_stream(), str);
  211.   xlputc(get_plot_stream(), '\n');
  212. }
  213.  
  214.  
  215. TEK40ulput_text(row,str)
  216.      unsigned int row;
  217.      char str[];
  218. {
  219.   TEK40move(TEK40HTIC, TEK40YMAX - TEK40VTIC - TEK40VCHAR*(row+1));
  220.   xlputc(get_plot_stream(), '\037');
  221.   xlputstr(get_plot_stream(), str);
  222.   xlputc(get_plot_stream(), '\n');
  223. }
  224.  
  225.  
  226. TEK40reset()
  227. {
  228. }
  229.  
  230.  
  231.  
  232. UNKNOWN_null()
  233. {
  234. }
  235.  
  236.  
  237. /*
  238.  * term_tbl[] contains an entry for each terminal.  "unknown" must be the
  239.  *   first, since term is initialized to 0.
  240.  */
  241. struct termentry term_tbl[] = {
  242.   {"unknown", 100, 100, 1, 1, 1, 1, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null,
  243.      UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null, UNKNOWN_null,
  244.      UNKNOWN_null, UNKNOWN_null},
  245.   {"tek40xx",TEK40XMAX,TEK40YMAX,TEK40VCHAR, TEK40HCHAR, TEK40VTIC, 
  246.       TEK40HTIC, TEK40init, TEK40reset, TEK40text, TEK40graphics, 
  247.       TEK40move, TEK40vector, TEK40linetype, TEK40lrput_text,
  248.       TEK40ulput_text, line_and_point}
  249.   
  250. };
  251.  
  252. #define TERMCOUNT 2
  253.  
  254.  
  255.