Initial release of Maemo 5 port of gnuplot
[gnuplot] / term / regis.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: regis.trm,v 1.15 2006/07/21 02:35:48 sfeam Exp $
3  *
4  */
5
6 /* GNUPLOT - regis.trm */
7
8 /*[
9  * Copyright 1990 - 1993, 1998, 2004
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.c.
40  *
41  * This terminal driver supports:
42  *  REGIS devices
43  *
44  * AUTHORS
45  *  Colin Kelley, Thomas Williams
46  *
47  * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
48  *
49  */
50
51 #include "driver.h"
52
53 #ifdef TERM_REGISTER
54 register_term(regis)
55 #endif
56
57
58 #ifdef TERM_PROTO
59 TERM_PUBLIC void REGIS_init __PROTO((void));
60 TERM_PUBLIC void REGIS_graphics __PROTO((void));
61 TERM_PUBLIC void REGIS_init __PROTO((void));
62 TERM_PUBLIC void REGIS_graphics __PROTO((void));
63 TERM_PUBLIC void REGIS_text __PROTO((void));
64 TERM_PUBLIC void REGIS_linetype __PROTO((int linetype));
65 TERM_PUBLIC void REGIS_move __PROTO((unsigned int x, unsigned int y));
66 TERM_PUBLIC void REGIS_vector __PROTO((unsigned int x, unsigned int y));
67 TERM_PUBLIC void REGIS_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
68 TERM_PUBLIC int REGIS_text_angle __PROTO((int ang));
69 TERM_PUBLIC void REGIS_reset __PROTO((void));
70 TERM_PUBLIC void REGIS_options __PROTO((void));
71
72 #define REGISXMAX 800
73 #define REGISYMAX 440
74
75 #define REGISXLAST (REGISXMAX - 1)
76 #define REGISYLAST (REGISYMAX - 1)
77
78 #define REGISVCHAR              20
79 #define REGISHCHAR              9
80 #define REGISVTIC               8
81 #define REGISHTIC               6
82
83 /* is defined in plot.h
84 #define TRUE 1
85 #define FALSE 0
86 */
87 #endif
88
89
90
91 #ifndef TERM_PROTO_ONLY
92 #ifdef TERM_BODY
93
94 static int REGIS16color = FALSE;
95
96 static int REGISang = 0;
97
98 TERM_PUBLIC void
99 REGIS_init()
100 {
101     fputs("\033[r\033[24;1H", gpoutfile);
102     /*     1     2
103      * 1. reset scrolling region
104      * 2. locate cursor on bottom line
105      */
106 }
107
108
109 /* thanks to calmasd!dko (Dan O'Neill) for adding S(E) for vt125s */
110 TERM_PUBLIC void
111 REGIS_graphics()
112 {
113     fputs("\033[2J\033P1pS(C0)S(E)T(A0)\n", gpoutfile);
114     /*     1      2      3    4   5
115      * 1. clear screen
116      * 2. enter ReGIS graphics
117      * 3. turn off graphics diamond cursor
118      * 4. clear graphics screen
119      * 5. character set option.
120      */
121     (void) REGIS_text_angle(0); /* select text size and angle */
122 }
123
124
125 TERM_PUBLIC void
126 REGIS_text()
127 {
128     fputs("\033\\\033[24;1H", gpoutfile);
129     /*     1    2
130      * 1. Leave ReGIS graphics mode
131      * 2. locate cursor on last line of screen
132      */
133 }
134
135
136 TERM_PUBLIC void
137 REGIS_linetype(int linetype)
138 {
139     /* This will change color in order G,R,B,G-dot,R-dot,B-dot */
140
141     static int in_16_map[15 + 2] = { 7, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
142     static int lt_16_map[15 + 2] = { 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
143     static int in_map[9 + 2] = { 2, 2, 3, 2, 1, 3, 2, 1, 3, 2, 1 };
144     static int lt_map[9 + 2] = { 1, 4, 1, 1, 1, 4, 4, 4, 6, 6, 6 };
145
146     if (linetype < -2)
147         linetype = LT_BLACK;
148
149     if (!REGIS16color) {
150         if (linetype >= 9)
151             linetype %= 9;
152         fprintf(gpoutfile, "W(I%d)\n", in_map[linetype + 2]);
153         fprintf(gpoutfile, "W(P%d)\n", lt_map[linetype + 2]);
154     } else {
155         if (linetype >= 15)
156             linetype %= 15;
157         fprintf(gpoutfile, "W(I%d)\n", in_16_map[linetype + 2]);
158         fprintf(gpoutfile, "W(P%d)\n", lt_16_map[linetype + 2]);
159     }
160 }
161
162
163
164 /*
165 ** The \n was added in the functions below (and above) in order to not cause
166 ** a buffer overflow in devices that can't deal with long line lengths.
167 ** The DEC vt-340 doesn't need this, but Reflection 4, a vt-340 emulator
168 ** for PC's under MS-DOS and Microsoft Windows does need it.
169 ** Also needed for DECterm, a vt-340 emulator for use with Motif 1.0
170 ** on Open/VMS.
171 ** NGB 9/13/93
172 */
173
174 TERM_PUBLIC void
175 REGIS_move(unsigned int x, unsigned int y)
176 {
177     fprintf(gpoutfile, "P[%d,%d]\n", x, REGISYLAST - y);
178 }
179
180
181 TERM_PUBLIC void
182 REGIS_vector(unsigned int x, unsigned int y)
183 {
184     fprintf(gpoutfile, "v[]v[%d,%d]\n", x, REGISYLAST - y);
185     /* the initial v[] is needed to get the first pixel plotted */
186 }
187
188
189 /* put_text and text_angle by rjl */
190 TERM_PUBLIC void
191 REGIS_put_text(unsigned int x, unsigned int y, const char *str)
192 {
193     if (REGISang == 1)
194         REGIS_move(x - REGISVCHAR / 2 - 1, y);
195     else
196         REGIS_move(x, y + REGISVCHAR / 2 - 1);
197     (void) putc('T', gpoutfile);
198     (void) putc('\'', gpoutfile);
199     while (*str) {
200         (void) putc(*str, gpoutfile);
201         if (*str == '\'')
202             (void) putc('\'', gpoutfile);       /* send out another one */
203         str++;
204     }
205     (void) putc('\'', gpoutfile);
206     (void) putc('\n', gpoutfile);
207 }
208
209
210 TERM_PUBLIC int
211 REGIS_text_angle(int ang)
212 {
213     REGISang = (ang ? 1 : 0);
214     if (REGISang == 1)
215         fputs("T(D90,S1)\n", gpoutfile);
216     else
217         fputs("T(D0,S1)\n", gpoutfile);
218     return TRUE;
219 }
220
221
222 TERM_PUBLIC void
223 REGIS_reset()
224 {
225     fputs("\033[2J\033[24;1H", gpoutfile);
226 }
227
228 TERM_PUBLIC void
229 REGIS_options()
230 {
231     int i = 0;
232     struct value a;
233
234     if (!END_OF_COMMAND) {
235         i = (int) real(const_express(&a));
236     }
237     REGIS16color = (i == 16);
238     sprintf(term_options, "%s", REGIS16color ? "16" : "4");
239 }
240
241 #endif
242
243
244 #ifdef TERM_TABLE
245 TERM_TABLE_START(regis_driver)
246     "regis", "REGIS graphics language",
247     REGISXMAX, REGISYMAX, REGISVCHAR, REGISHCHAR,
248     REGISVTIC, REGISHTIC, REGIS_options, REGIS_init, REGIS_reset,
249     REGIS_text, null_scale, REGIS_graphics, REGIS_move, REGIS_vector,
250     REGIS_linetype, REGIS_put_text, REGIS_text_angle,
251     null_justify_text, line_and_point, do_arrow, set_font_null
252 TERM_TABLE_END(regis_driver)
253
254 #undef LAST_TERM
255 #define LAST_TERM regis_driver
256 #endif
257 #endif /* TERM_PROTO_ONLY */
258
259 #ifdef TERM_HELP
260 START_HELP(regis)
261 "1 regis",
262 "?commands set terminal regis",
263 "?set terminal regis",
264 "?set term regis",
265 "?terminal regis",
266 "?term regis",
267 "?regis",
268 " The `regis` terminal device generates output in the REGIS graphics language.",
269 " It has the option of using 4 (the default) or 16 colors.",
270 "",
271 " Syntax:",
272 "       set terminal regis {4 | 16}"
273 END_HELP(regis)
274 #endif