Changed russian description a little bit
[gnuplot] / term / cgi.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: cgi.trm,v 1.14 2006/07/21 02:35:45 sfeam Exp $
3  *
4  */
5
6 /* GNUPLOT - cgi.trm */
7
8 /*[
9  * Copyright (C) 1990 - 1993 Ronald Florence
10  *
11  * Permission to use, copy, and distribute this software and its
12  * documentation for any purpose with or without fee is hereby granted,
13  * provided that the above copyright notice appear in all copies and
14  * that both that copyright notice and this permission notice appear
15  * in supporting documentation.
16  *
17  * Permission to modify the software is granted, but not the right to
18  * distribute the complete modified source code.  Modifications are to
19  * be distributed as patches to the released version.  Permission to
20  * distribute binaries produced by compiling modified sources is granted,
21  * provided you
22  *   1. distribute the corresponding source modifications from the
23  *    released version in the form of a patch file along with the binaries,
24  *   2. add special version identification to distinguish your version
25  *    in addition to the base release version number,
26  *   3. provide your name and address as the primary contact for the
27  *    support of your modified version, and
28  *   4. retain our contact information in regard to use of the base
29  *    software.
30  * Permission to distribute the released version of the source code along
31  * with corresponding source modifications in the form of a patch file is
32  * granted with same provisions 2 through 4 for binary distributions.
33  *
34  * This software is provided "as is" without express or implied warranty
35  * to the extent permitted by applicable law.
36 ]*/
37
38 /*
39  * This file is included by ../term.h.
40  *
41  * This terminal driver supports SCO CGI drivers
42  *
43  * AUTHOR
44  *   Ronald Florence <ron@18james.com>
45  */
46
47 /*
48  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
49  */
50
51 #include "driver.h"
52
53 #ifdef TERM_REGISTER
54 register_term(cgi)
55 register_term(hcgi)
56 #endif
57
58 #ifdef TERM_PROTO
59 TERM_PUBLIC void CGI_init __PROTO((void));
60 TERM_PUBLIC void HCGI_init __PROTO((void));
61 TERM_PUBLIC void CGI_graphics __PROTO((void));
62 TERM_PUBLIC void CGI_text __PROTO((void));
63 TERM_PUBLIC void CGI_reset __PROTO((void));
64 TERM_PUBLIC void CGI_move __PROTO((unsigned int x, unsigned int y));
65 TERM_PUBLIC void CGI_vector __PROTO((unsigned int x, unsigned int y));
66 TERM_PUBLIC void CGI_linetype __PROTO((int linetype));
67 TERM_PUBLIC void CGI_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
68 TERM_PUBLIC int CGI_text_angle __PROTO((int ang));
69 TERM_PUBLIC int CGI_justify_text __PROTO((enum JUSTIFY mode));
70 TERM_PUBLIC void CGI_point __PROTO((unsigned int x, unsigned int y, int num));
71 #define CGI_XMAX        32767
72 #define CGI_YMAX        32767
73 #define CGI_VTIC        (CGI_YMAX / 75)
74 #define CGI_HTIC        term->h_tic
75 #define CGI_VCHAR       term->v_char
76 #define CGI_HCHAR       term->h_char
77 #endif
78
79 #ifndef TERM_PROTO_ONLY
80 #ifdef TERM_BODY
81
82 #ifdef VGA_MONO
83 static short rgb[16][3] =
84 {
85     0, 0, 0,                    /* Black        */
86     1000, 1000, 1000,           /* White        */
87     800, 800, 0,                /* Red          */
88     0, 600, 0,                  /* Green        */
89     0, 800, 800,                /* Blue         */
90     1000, 1000, 400,            /* Yellow       */
91     0, 600, 600,                /* Cyan         */
92     600, 600, 600,              /* Magenta      */
93     800, 800, 0,                /* Brown        */
94     600, 600, 600,              /* Lt. Grey     */
95     400, 600, 400,              /* Dark Grey    */
96     400, 600, 1000,             /* Lt. Blue     */
97     400, 1000, 400,             /* Lt Green     */
98     400, 1000, 1000,            /* Lt Cyan      */
99     1000, 600, 400,             /* Lt Red       */
100     600, 600, 1000              /* Lt Magenta   */
101 };
102 #endif
103
104 #define CRT             (gout[45] == 0)
105 #define CGICOLORS       gout[13]
106 #define CGILINES        gout[6]
107 #define CGIROTATES      gout[36]
108 #define CGITEXTALIGN    gout[48]
109
110 static short gout[66];
111 static short cgidev;
112 static short vect[4];
113 static short gin[19] =
114 {
115     0,                          /* default aspect ratio */
116     1,                          /* solid line */
117     1,                          /* line color */
118     1,                          /* marker type . */
119     1,                          /* marker color */
120     1,                          /* graphics text font */
121     1,                          /* graphics text color */
122     0,                          /* fill interior style */
123     0,                          /* fill style index */
124     1,                          /* fill color index */
125     1                           /* prompt for paper changes */
126 };
127
128 char *cgidriver, *getenv();
129
130
131 TERM_PUBLIC void
132 CGI_init()
133 {
134     if (getenv(cgidriver = "CGIDISP") == NULL)
135         HCGI_init();
136 }
137
138
139 TERM_PUBLIC void
140 HCGI_init()
141 {
142     if (getenv(cgidriver = "CGIPRNT") == NULL)
143         int_error(NO_CARET, "no CGI driver");
144 }
145
146
147 TERM_PUBLIC void
148 CGI_graphics()
149 {
150     int i, aspect;
151     char *s;
152     short font_cap[9];
153
154     if ((s = getenv("ASPECT")) != NULL && (aspect = atoi(s)) >= 0 && aspect <= 3)
155         gin[0] = aspect;
156     for (i = 0; cgidriver[i]; i++)
157         gin[11 + i] = cgidriver[i];
158     gin[18] = ' ';
159
160     if (v_opnwk(gin, &cgidev, gout) < 0) {
161         int_error(NO_CARET, "CGI error %d opening %s", -vq_error(), cgidriver);
162     }
163     vqt_representation(cgidev, 9, font_cap);
164     CGI_VCHAR = font_cap[8] * 3 / 2;
165     CGI_HCHAR = font_cap[7];
166     CGI_HTIC = CGI_VTIC * ((double) gout[1] / (double) gout[4]) /
167         ((double) gout[0] / (double) gout[3]);
168 #ifdef VGA_MONO
169     if (CGICOLORS > 2)
170         vsc_table(cgidev, 0, CGICOLORS, rgb);
171 #endif
172 }
173
174
175 TERM_PUBLIC void
176 CGI_text()
177 {
178     if (CRT) {
179         short ptin[2];
180         char strin[2];
181
182         ptin[0] = 0;
183         ptin[1] = 0;
184         vrq_string(cgidev, 1, 0, ptin, strin);
185     }
186     v_clswk(cgidev);
187 }
188
189
190 TERM_PUBLIC void
191 CGI_reset()
192 {
193 }
194
195
196 TERM_PUBLIC void
197 CGI_move(unsigned int x, unsigned int y)
198 {
199     vect[0] = x;
200     vect[1] = y;
201 }
202
203 TERM_PUBLIC void
204 CGI_vector(unsigned int x, unsigned int y)
205 {
206     vect[2] = x;
207     vect[3] = y;
208     v_pline(cgidev, 2, vect);
209     vect[0] = x;
210     vect[1] = y;
211 }
212
213
214 TERM_PUBLIC void
215 CGI_linetype(int linetype)
216 {
217     short lcolor;
218
219     if (CGICOLORS > 2) {
220         lcolor = (linetype + 2) % CGICOLORS + 1;
221         vsl_color(cgidev, lcolor);
222         vsm_color(cgidev, lcolor);
223     }
224     vsl_type(cgidev, (linetype < 1) ? 1 : (linetype % CGILINES) + 1);
225 }
226
227
228 TERM_PUBLIC void
229 CGI_put_text(unsigned int x, unsigned int y, const char *str)
230 {
231     v_gtext(cgidev, (short) x, (short) y, str);
232 }
233
234
235 TERM_PUBLIC int
236 CGI_text_angle(int ang)
237 {
238     if (!CGIROTATES)
239         return FALSE;
240     /* angles are 1/10 degree ccw */
241     vst_rotation(cgidev, (ang) ? 900 : 0);
242     return TRUE;
243 }
244
245
246 TERM_PUBLIC int
247 CGI_justify_text(enum JUSTIFY mode)
248 {
249     short hor_in, hor_out, vert_out;
250
251     if (!CGITEXTALIGN)
252         return FALSE;
253
254     switch (mode) {
255     case LEFT:
256         hor_in = 0;
257         break;
258     case CENTRE:
259         hor_in = 1;
260         break;
261     case RIGHT:
262         hor_in = 2;
263         break;
264     }
265     vst_alignment(cgidev, hor_in, 1, &hor_out, &vert_out);
266     return TRUE;
267 }
268
269
270 #define POINT_TYPES 6
271
272 TERM_PUBLIC void
273 CGI_point(unsigned int x, unsigned y, int num)
274 {
275     short point[2];
276     static short cgimarker[POINT_TYPES] = { 1, 2, 6, 4, 5, 3 };
277     /* .  +  <> [] X  * */
278     if (num < 0) {
279         CGI_move(x, y);
280         CGI_vector(x, y);
281     } else {
282         vsm_type(cgidev, cgimarker[num % POINT_TYPES]);
283         point[0] = x;
284         point[1] = y;
285         v_pmarker(cgidev, 1, point);
286     }
287 }
288
289 #endif /* TERM_BODY */
290
291 #ifdef TERM_TABLE
292
293 TERM_TABLE_START(cgi_driver)
294     "cgi", "SCO CGI drivers (requires CGIDISP or CGIPRNT env variable)",
295     CGI_XMAX, CGI_YMAX, 0, 0,
296     CGI_VTIC, 0, options_null, CGI_init, CGI_reset,
297     CGI_text, null_scale, CGI_graphics, CGI_move, CGI_vector,
298     CGI_linetype, CGI_put_text, CGI_text_angle,
299     CGI_justify_text, CGI_point, do_arrow, set_font_null
300 TERM_TABLE_END(cgi_driver)
301
302 #undef LAST_TERM
303 #define LAST_TERM cgi_driver
304
305 TERM_TABLE_START(hcgi_driver)
306     "hcgi", "SCO CGI drivers (hardcopy, requires CGIPRNT env variable)",
307     CGI_XMAX, CGI_YMAX, 0, 0,
308     CGI_VTIC, 0, options_null, HCGI_init, CGI_reset,
309     CGI_text, null_scale, CGI_graphics, CGI_move, CGI_vector,
310     CGI_linetype, CGI_put_text, CGI_text_angle,
311     CGI_justify_text, CGI_point, do_arrow, set_font_null
312 TERM_TABLE_END(hcgi_driver)
313
314 #undef LAST_TERM
315 #define LAST_TERM hcgi_driver
316
317 #endif /* TERM_TABLE */
318 #endif /* TERM_PROTO_ONLY */
319
320 #ifdef TERM_HELP
321 START_HELP(cgi)
322 "1 cgi",
323 "?commands set terminal cgi",
324 "?set terminal cgi",
325 "?set term cgi",
326 "?terminal cgi",
327 "?term cgi",
328 "?cgi",
329 "?commands set terminal hcgi",
330 "?set terminal hcgi",
331 "?set term hcgi",
332 "?terminal hcgi",
333 "?term hcgi",
334 "?hcgi",
335 " The `cgi` and `hcgi` terminal drivers support SCO CGI drivers.  `hcgi` is for",
336 " printers; the environment variable CGIPRNT must be set.  `cgi` may be used",
337 " for either a display or hardcopy; if the environment variable CGIDISP is set,",
338 " then that display is used.  Otherwise CGIPRNT is used.",
339 "",
340 " These terminals have no options."
341 END_HELP(cgi)
342 #endif