home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_01 / cgi.trm < prev    next >
Text File  |  1991-02-05  |  5KB  |  228 lines

  1. /* GNUPLOT - cgi.trm */
  2. /*
  3.  * Copyright (C) 1990 Ronald Florence
  4.  *
  5.  * Permission is hereby granted for unlimited non-commercial
  6.  * use of this code, on condition that the copyright
  7.  * notices are left intact and any modifications to the source
  8.  * code are noted as such.  No warranty of any kind is implied
  9.  * or granted for this material.
  10.  *
  11.  * This file is included by ../term.c.
  12.  *
  13.  * This terminal driver supports SCO CGI drivers
  14.  *
  15.  * AUTHOR
  16.  *   Ronald Florence <ron@mlfarm.com>
  17.  */
  18.  
  19. #ifdef VGA_MONO
  20. static short rgb[16][3] = {
  21.   0,    0,      0,      /* Black        */
  22.   1000,    1000,    1000,    /* White    */
  23.   800,    800,    0,    /* Red        */
  24.   0,    600,    0,    /* Green    */
  25.   0,    800,    800,    /* Blue        */
  26.   1000,    1000,    400,    /* Yellow    */
  27.   0,    600,    600,    /* Cyan        */
  28.   600,    600,    600,    /* Magenta    */
  29.   800,    800,    0,    /* Brown    */
  30.   600,    600,    600,    /* Lt. Grey    */
  31.   400,    600,    400,    /* Dark Grey    */
  32.   400,    600,    1000,    /* Lt. Blue    */
  33.   400,    1000,    400,    /* Lt Green    */
  34.   400,    1000,    1000,    /* Lt Cyan    */
  35.   1000,    600,    400,    /* Lt Red    */
  36.   600,    600,    1000    /* Lt Magenta    */
  37. };
  38. #endif
  39.  
  40. #define CGI_XMAX    32767
  41. #define CGI_YMAX    32767
  42. #define CGI_VTIC    (CGI_YMAX / 75)
  43. #define CGI_HTIC    term_tbl[term].h_tic
  44. #define CGI_VCHAR    term_tbl[term].v_char
  45. #define CGI_HCHAR    term_tbl[term].h_char
  46. #define CRT        (gout[45] == 0)
  47. #define CGICOLORS    gout[13]
  48. #define CGILINES    gout[6]
  49. #define CGIROTATES    gout[36]
  50. #define CGITEXTALIGN    gout[48]
  51.  
  52. static short gout[66];
  53. static short cgidev;
  54. static short vect[4];
  55. static short gin[19] = {
  56.  0,    /* default aspect ratio */
  57.  1,    /* solid line */
  58.  1,    /* line color */
  59.  1,    /* marker type . */
  60.  1,    /* marker color */
  61.  1,    /* graphics text font */
  62.  1,    /* graphics text color */
  63.  0,    /* fill interior style */
  64.  0,    /* fill style index */
  65.  1,    /* fill color index */
  66.  1     /* prompt for paper changes */
  67.  };
  68.  
  69. char    *cgidriver, *getenv();
  70.  
  71.  
  72. CGI_init()
  73. {
  74.   if (getenv(cgidriver = "CGIDISP") == NULL)
  75.     HCGI_init();
  76. }
  77.  
  78.  
  79. HCGI_init()
  80. {
  81.   if (getenv(cgidriver = "CGIPRNT") == NULL)
  82.     int_error("no CGI driver", NO_CARET);
  83. }
  84.  
  85.  
  86. CGI_graphics()
  87. {
  88.   int    i, aspect;
  89.   char *s;
  90.   short font_cap[9];
  91.   char    err_str[80];
  92.  
  93.   if ( (s=getenv("ASPECT")) != NULL && (aspect=atoi(s)) >= 0 && aspect <= 3 )
  94.     gin[0] = aspect;
  95.   for (i = 0; cgidriver[i]; i++) 
  96.     gin[11+i] = cgidriver[i];
  97.   gin[18] = ' ';
  98.  
  99.   if (v_opnwk(gin, &cgidev, gout) < 0) 
  100.     {
  101.       sprintf(err_str, "CGI error %d opening %s", -vq_error(), cgidriver);
  102.       int_error(err_str, NO_CARET);
  103.     }
  104.   vqt_representation(cgidev, 9, font_cap);
  105.   CGI_VCHAR = font_cap[8] * 3 / 2;
  106.   CGI_HCHAR = font_cap[7];
  107.   CGI_HTIC = CGI_VTIC * ((double) gout[1] / (double) gout[4]) / 
  108.             ((double) gout[0] / (double) gout[3]);
  109. #ifdef VGA_MONO
  110.   if (CGICOLORS > 2)
  111.     vsc_table(cgidev, 0, CGICOLORS, rgb);
  112. #endif
  113. }
  114.  
  115.  
  116. CGI_text()
  117. {
  118.   if (CRT)  
  119.     {
  120.       short ptin[2];
  121.       char  strin[2];
  122.       
  123.       ptin[0] = 0;
  124.       ptin[1] = 0;
  125.       vrq_string(cgidev, 1, 0, ptin, strin);
  126.     }
  127.   v_clswk(cgidev);
  128. }
  129.  
  130.  
  131. CGI_reset()
  132. {
  133. }
  134.  
  135.  
  136. CGI_move(x, y)
  137.      int x, y;
  138. {
  139.   vect[0] = x;
  140.   vect[1] = y;
  141. }
  142.  
  143. CGI_vector(x, y)
  144.      int x, y;
  145. {
  146.   vect[2] = x;
  147.   vect[3] = y;
  148.   v_pline(cgidev, 2, vect);
  149.   vect[0] = x;
  150.   vect[1] = y;
  151. }
  152.  
  153.  
  154. CGI_linetype(linetype)
  155.      int linetype;
  156. {
  157.   short lcolor;
  158.  
  159.   if (CGICOLORS > 2) 
  160.     {
  161.       lcolor = (linetype + 2) % CGICOLORS + 1;
  162.       vsl_color(cgidev, lcolor);
  163.       vsm_color(cgidev, lcolor);
  164.     }
  165.   vsl_type(cgidev, (linetype < 1) ? 1 : (linetype % CGILINES) + 1);
  166. }
  167.  
  168.  
  169. CGI_put_text(x, y, str)
  170. int x, y;
  171. char *str;
  172. {
  173.   v_gtext(cgidev, (short) x, (short) y, str);
  174. }
  175.  
  176.  
  177. CGI_text_angle(ang)
  178. int    ang;
  179. {
  180.   if (!CGIROTATES)
  181.     return FALSE;
  182.                 /* angles are 1/10 degree ccw */
  183.   vst_rotation(cgidev, (ang) ? 900 : 0);
  184.   return TRUE;
  185. }
  186.  
  187.  
  188. CGI_justify_text(mode)
  189. enum JUSTIFY mode;
  190. {
  191.   short hor_in, hor_out, vert_out;
  192.  
  193.   if (!CGITEXTALIGN)
  194.     return FALSE;
  195.  
  196.   switch (mode)
  197.     {
  198.     case LEFT:   hor_in = 0; break;
  199.     case CENTRE: hor_in = 1; break;
  200.     case RIGHT:  hor_in = 2; break;
  201.     }
  202.   vst_alignment(cgidev, hor_in, 1, &hor_out, &vert_out); 
  203.   return TRUE;
  204. }
  205.  
  206.  
  207. #define POINT_TYPES 6
  208.  
  209. CGI_point(x,y,num)
  210.      int x, y, num;
  211. {
  212.   short  point[2];
  213.   static short cgimarker[POINT_TYPES] = {1, 2, 6, 4, 5, 3};
  214.                           /* .  +  <> [] X  * */
  215.   if (num < 0)
  216.     {
  217.       CGI_move(x, y);
  218.       CGI_vector(x, y);
  219.     }
  220.   else
  221.     {
  222.       vsm_type(cgidev, cgimarker[num % POINT_TYPES]);
  223.       point[0] = x;
  224.       point[1] = y;
  225.       v_pmarker(cgidev, 1, point);
  226.     }
  227. }
  228.