Initial release of Maemo 5 port of gnuplot
[gnuplot] / term / iris4d.trm
1 /* Hello, Emacs, this is -*-C-*-
2  * $Id: iris4d.trm,v 1.15 2006/07/21 02:35:47 sfeam Exp $
3  *
4  */
5
6 /* GNUPLOT - iris4d.trm */
7
8 /*[
9  * Copyright 1990 - 1993, 1998, 2004   Thomas Williams, Colin Kelley
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  *   IRIS terminals
43  *
44  * AUTHORS
45  *   John H. Merritt
46  *           (Applied Research Corporation) 7/1/89
47  *           INTERNET: merritt@iris613.gsfc.nasa.gov
48  *
49  * send your comments or suggestions to (gnuplot-info@lists.sourceforge.net).
50  *
51  */
52 /*
53  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
54  */
55
56 #include "driver.h"
57
58 #ifdef TERM_REGISTER
59 register_term(iris4d)
60 #endif
61
62 #ifdef TERM_PROTO
63 TERM_PUBLIC void IRIS4D_options __PROTO((void));
64 TERM_PUBLIC void IRIS4D_init __PROTO((void));
65 TERM_PUBLIC void IRIS4D_graphics __PROTO((void));
66 TERM_PUBLIC void IRIS4D_text __PROTO((void));
67 TERM_PUBLIC void IRIS4D_linetype __PROTO((int linetype));
68 TERM_PUBLIC void IRIS4D_move __PROTO((unsigned int x, unsigned int y));
69 TERM_PUBLIC void IRIS4D_vector __PROTO((unsigned int x, unsigned int y));
70 TERM_PUBLIC void IRIS4D_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
71 TERM_PUBLIC void IRIS4D_reset __PROTO((void));
72 #define IRIS4D_XMAX 1024
73 #define IRIS4D_YMAX 1024
74 #define IRIS4D_VCHAR (IRIS4D_YMAX/30)
75 #define IRIS4D_HCHAR (IRIS4D_XMAX/72)
76 #define IRIS4D_VTIC (IRIS4D_YMAX/80)
77 #define IRIS4D_HTIC (IRIS4D_XMAX/80)
78 #endif /* TERM_PROTO */
79
80 #ifndef TERM_PROTO_ONLY
81 #ifdef TERM_BODY
82 void IRIS4D_cmove __PROTO((unsigned int x, unsigned int y));
83 #include <gl.h>
84
85 /* plot.c */
86 extern const char *user_homedir;
87
88 #define IRIS4DRC    ".gnuplot_iris4d"
89
90 #define IRIS4D_XLAST (IRIS4D_XMAX - 1)
91 #define IRIS4D_YLAST (IRIS4D_YMAX - 1)
92
93 static short colors24bits[][3] =
94 {
95     {85, 85, 85},               /* 0. BACK GROUND ( DARKGRAY ) */
96     {0, 0, 0},                  /* 1. BLACK */
97     {170, 0, 170},              /* 2. MAGENTA */
98     {85, 255, 255},             /* 3. LIGHTCYAN */
99     {170, 0, 0},                /* 4. RED */
100     {0, 170, 0},                /* 5. GREEN */
101     {255, 85, 255},             /* 6. LIGHTMAGENTA */
102     {255, 255, 85},             /* 7. YELLOW */
103     {255, 85, 85},              /* 8. LIGHTRED */
104     {85, 255, 85},              /* 9. LIGHTGREEN */
105     {0, 170, 170},              /* 10. CYAN */
106     {170, 170, 0},              /* 11. BROWN */
107 };
108 #define COLOR24_SIZE (sizeof(colors24bits) / (sizeof(short) * 3))
109
110 static iris24bits = FALSE;
111
112 #define IRIS4D_BACKGROUND       0
113 #define IRIS4D_BLACK            1
114 #define IRIS4D_MAGENTA          2
115 #define IRIS4D_LIGHTCYAN        3
116 #define IRIS4D_RED              4
117 #define IRIS4D_GREEN            5
118 #define IRIS4D_LIGHTMAGENTA     6
119 #define IRIS4D_YELLOW           7
120 #define IRIS4D_LIGHTRED         8
121 #define IRIS4D_LIGHTGREEN       9
122 #define IRIS4D_CYAN             10
123 #define IRIS4D_BROWN            11
124
125 TERM_PUBLIC void
126 IRIS4D_options()
127 {
128     int i = 0;
129     struct value a;
130
131     if (!END_OF_COMMAND) {
132         i = (int) real(const_express(&a));
133     }
134     iris24bits = (i == 24);
135
136     sprintf(term_options, "%s", iris24bits ? "24" : "8");
137 }
138
139 TERM_PUBLIC void
140 IRIS4D_init()
141 {
142     int i;
143     char line[80];
144     char *irisinitfile = NULL;
145     FILE *f = NULL:
146
147     irisinitfile = (char *) gp_alloc (( user_homedir ? strlen(user_homedir) : 0 )+1+strlen(IRIS4DRC)+1, "irisinitfile");
148
149     foreground();
150     winopen("Gnuplot");
151     if (iris24bits) {
152         RGBmode();
153         gconfig();
154     }
155
156 #ifdef NOCWDRC
157     /* inhibit check of init file in current directory for security reasons */
158 #else
159     f = fopen(IRIS4DRC, "r");
160 #endif
161     if (!f) {
162         if (user_homedir) {
163             strcpy (irisinitfile, user_homedir);
164             PATH_CONCAT(irisinitfile,IRIS4DRC);
165             f = fopen (irisinitfile, "r");
166         }
167     }
168
169     if (f) {
170         int c1, c2, c3;
171         for (i = 0; i < COLOR24_SIZE; i++) {
172             if (fgets(line, 79, f) == NULL ||
173                 sscanf(line, "%d %d %d", &c1, &c2, &c3) != 3)
174                 int_error(NO_CARET, "Iris4d color file terminated prematurely or wrong format.\n");
175             colors24bits[i][0] = c1;
176             colors24bits[i][1] = c2;
177             colors24bits[i][2] = c3;
178         }
179
180         fclose(f);
181     }
182     deflinestyle(1, 0x3FFF);    /* long dash */
183     deflinestyle(2, 0x5555);    /* dotted */
184     deflinestyle(3, 0x3333);    /* short dash */
185     deflinestyle(4, 0xB5AD);    /* dotdashed */
186     deflinestyle(5, 0x0F0F);    /* dashed */
187     deflinestyle(6, 0xBBBB);    /* dotdashed */
188     deflinestyle(7, 0x3F3F);    /* mid-long dash */
189     deflinestyle(8, 0x7777);    /* mid-long dash */
190
191     return;
192 }
193
194 TERM_PUBLIC void
195 IRIS4D_graphics()
196 {
197     reshapeviewport();
198     ortho2((Coord) 0, (Coord) IRIS4D_XMAX, (Coord) 0, (Coord) IRIS4D_YMAX);
199     if (iris24bits)
200         RGBcolor(colors24bits[IRIS4D_BACKGROUND][0],
201                  colors24bits[IRIS4D_BACKGROUND][1],
202                  colors24bits[IRIS4D_BACKGROUND][2]);
203     else
204         color(WHITE);
205
206     clear();
207
208     return;
209 }
210
211 TERM_PUBLIC void
212 IRIS4D_text()
213 {
214     gflush();                   /* flush buffer */
215     return;                     /* enter text from another window!!! */
216 }
217
218 TERM_PUBLIC void IRIS4D_linetype(int linetype)
219 {
220     static int pen_color_24[11] =
221     {
222         IRIS4D_BLACK,           /* reserved for border and numbers */
223         IRIS4D_MAGENTA,         /* reserved for axis traces */
224         IRIS4D_LIGHTCYAN,
225         IRIS4D_RED,
226         IRIS4D_GREEN,
227         IRIS4D_LIGHTMAGENTA,
228         IRIS4D_YELLOW,
229         IRIS4D_LIGHTRED,
230         IRIS4D_LIGHTGREEN,
231         IRIS4D_CYAN,
232         IRIS4D_BROWN,
233     };
234     static int pen_color[8] = { 0, 1, 4, 5, 6, 1, 2, 4 };
235
236     if (linetype < -2)
237         linetype = LT_BLACK;
238
239     if (iris24bits) {
240         int pencolor = pen_color_24[linetype < 0 ? linetype + 2 : linetype % 9 + 2];
241
242         RGBcolor(colors24bits[pencolor][0],
243                  colors24bits[pencolor][1],
244                  colors24bits[pencolor][2]);
245         /* Make all lines solid (linestyle 0) upto to the ninth. If more than
246          * 9 colors are needed, start to use the different line styles (1 to 8).
247          */
248         setlinestyle(linetype < 9 ? 0 : (linetype + 2) % 8 + 1);
249     } else {
250         linetype = (linetype+2) % 8;
251         color((Colorindex) pen_color[linetype]);
252         setlinestyle(linetype);
253     }
254     return;
255 }
256
257 TERM_PUBLIC void
258 IRIS4D_move(unsigned int x, unsigned int y)
259 {
260     move2i(x, y);
261     return;
262 }
263
264 void
265 IRIS4D_cmove(unsigned int x, unsigned int y)
266 {
267     cmov2i(x, y);
268     return;
269 }
270
271 TERM_PUBLIC void
272 IRIS4D_vector(unsigned int x, unsigned int y)
273 {
274     draw2i(x, y);
275     return;
276 }
277
278
279 TERM_PUBLIC void
280 IRIS4D_put_text(unsigned int x, unsigned int y, const char *str)
281 {
282     IRIS4D_cmove(x, y - IRIS4D_VCHAR / 2);
283     charstr(str);
284     return;
285 }
286
287
288 TERM_PUBLIC void
289 IRIS4D_reset()
290 {
291     return;
292 }
293
294 #endif /* TERM_BODY */
295
296 #ifdef TERM_TABLE
297
298 TERM_TABLE_START(iris4d_driver)
299     "iris4d", "Silicon Graphics IRIS 4D Series Computer",
300     IRIS4D_XMAX, IRIS4D_YMAX, IRIS4D_VCHAR, IRIS4D_HCHAR,
301     IRIS4D_VTIC, IRIS4D_HTIC, IRIS4D_options, IRIS4D_init, IRIS4D_reset,
302     IRIS4D_text, null_scale, IRIS4D_graphics, IRIS4D_move, IRIS4D_vector,
303     IRIS4D_linetype, IRIS4D_put_text, null_text_angle,
304     null_justify_text, do_point, do_arrow, set_font_null
305 TERM_TABLE_END(iris4d_driver)
306
307 #undef LAST_TERM
308 #define LAST_TERM iris4d_driver
309
310 #endif /* TERM_TABLE */
311 #endif /* TERM_PROTO_ONLY */
312
313 #ifdef TERM_HELP
314 START_HELP(iris4d)
315 "1 iris4d",
316 "?commands set terminal iris4d",
317 "?set terminal iris4d",
318 "?set term iris4d",
319 "?terminal iris4d",
320 "?term iris4d",
321 "?iris4d",
322 " The `iris4d` terminal driver supports Silicon Graphics IRIS 4D computers.",
323 " Its only option is 8- or 24-bit color depth.  The default is 8.",
324 "",
325 " Syntax:",
326 "       set terminal iris4d {8 | 24}",
327 "",
328 " The color depth is not really a choice -- the value appropriate for the",
329 " hardware should be selected.",
330 "",
331 " When using 24-bit mode, the colors can be directly specified via the file",
332 " .gnuplot_iris4d that is searched in the current directory and then in the",
333 " home directory specified by the HOME environment variable.  This file holds",
334 " RGB values for the background, border, labels and nine plotting colors, in",
335 " that order.  For example, here is a file containing the default colors:",
336 "",
337 "       85   85   85     Background   (dark gray)",
338 "       0    0    0      Boundary     (black)",
339 "       170  0    170    Labeling     (magenta)",
340 "       85   255  255    Plot Color 1 (light cyan)",
341 "       170  0    0      Plot Color 2 (red)",
342 "       0    170  0      Plot Color 3 (green)",
343 "       255  85   255    Plot Color 4 (light magenta)",
344 "       255  255  85     Plot Color 5 (yellow)",
345 "       255  85   85     Plot Color 6 (light red)",
346 "       85   255  85     Plot Color 7 (light green)",
347 "       0    170  170    Plot Color 8 (cyan)",
348 "       170  170  0      Plot Color 9 (brown)",
349 "",
350 " This file must have exactly 12 lines of RGB triples.  No empty lines are",
351 " allowed, and anything after the third number on a line is ignored."
352 END_HELP(iris4d)
353 #endif /* TERM_TABLE */