Annotation of OpenXM_contrib/gnuplot/term/linux.trm, Revision 1.1.1.3
1.1 maekawa 1: /*
1.1.1.3 ! ohara 2: * $Id: linux.trm,v 1.8.2.3 2002/10/25 11:34:06 lhecking Exp $
1.1 maekawa 3: *
4: */
5:
6: /* GNUPLOT - linux.trm */
7:
8: /*[
9: * Copyright 1993, 1998
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: * SVGA up to 1024x768x256 for PC's running the Linux Operating System
43: * (also VGA 640x480x16, and SVGA 800x600x256)
44: *
45: * AUTHOR
46: * Scott Heavner (sdh@po.cwru.edu)
47: * based on original linux.trm by Tommy Frandsen (frandsen@diku.dk)
48: * patched by David J. Liu (liu@molecule.phri.nyu.edu)
49: * to increase perfomance and safety based on the features of SVGALib/GL.
50: * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
51: */
52:
53: /*
54: * Compile with Linux SVGAlib 0.95 currently maintained by
55: * Harm Hanemaayer (hhanemaa@cs.ruu.nl).
56: * supports Trident, Tseng, Cirrus, Oak and generic vga.
57: */
58:
59: #include "driver.h"
60:
61: #ifdef TERM_REGISTER
62: register_term(linux)
63: #endif
64:
65: #ifdef TERM_PROTO
66:
67: #define LINUX_VCHAR FNT5X9_VCHAR
68: #define LINUX_HCHAR FNT5X9_HCHAR
69: #define LINUX_VTIC 5
70: #define LINUX_HTIC 5
71: #define LINUX_XMAX 0 /* These two entries are just place holders. */
72: #define LINUX_YMAX 0 /* The actual values will be filled in init. */
73:
74: TERM_PUBLIC void LINUX_options __PROTO((void));
75: TERM_PUBLIC void LINUX_init __PROTO((void));
76: TERM_PUBLIC void LINUX_reset __PROTO((void));
77: TERM_PUBLIC void LINUX_text __PROTO((void));
78: TERM_PUBLIC void LINUX_graphics __PROTO((void));
79: TERM_PUBLIC void LINUX_linetype __PROTO((int linetype));
80: TERM_PUBLIC void LINUX_move __PROTO((unsigned int x, unsigned int y));
81: TERM_PUBLIC void LINUX_vector __PROTO((unsigned int x, unsigned int y));
82: TERM_PUBLIC int LINUX_text_angle __PROTO((int ang));
1.1.1.2 maekawa 83: TERM_PUBLIC void LINUX_put_text __PROTO((unsigned int x, unsigned int y, const char *str));
1.1 maekawa 84: TERM_PUBLIC void LINUX_suspend __PROTO((void));
85: TERM_PUBLIC void LINUX_resume __PROTO((void));
86:
87: #endif
88:
89: #ifdef TERM_BODY
90:
91: #define _STRING_H_
92: #include <vga.h>
93:
94: static int linux_vmode = G1024x768x256; /* default mode */
95: static int vgacolor[] = { 7, 8, 2, 3, 4, 5, 9, 14, 12, 15, 13, 10, 11, 1, 6 };
96: static int graphics_on = FALSE;
1.1.1.3 ! ohara 97: static vga_modeinfo *modeinfo;
1.1 maekawa 98: static int linux_startx, linux_starty, linux_lasty;
99: static int linux_angle;
1.1.1.3 ! ohara 100: int LINUX_graphics_allowed; /* also used in vgagl.trm */
1.1.1.2 maekawa 101: extern void drop_privilege();
102: extern void take_privilege();
1.1 maekawa 103:
1.1.1.3 ! ohara 104: typedef int (*linux_line_func_ptr) __PROTO((int x1, int y1, int x2, int y2));
1.1 maekawa 105:
106: static void LINUX_putc __PROTO((unsigned int x, unsigned int y, int c, int ang,
107: linux_line_func_ptr line_func));
108:
109: /* this function is called at the very beginning of main() to initialize
110: * the vgalib and to revoke suid privileges.
1.1.1.3 ! ohara 111: * /dev/console and /dev/tty\d and /dev/vc/\d are considered graphic terminals, all other
1.1 maekawa 112: * don't support the linux terminal */
113:
1.1.1.2 maekawa 114: void
115: LINUX_setup(void)
1.1 maekawa 116: {
117: char line[256];
118: FILE *pipe;
119:
120: LINUX_graphics_allowed = FALSE;
121:
122: if (geteuid() != 0)
123: return; /* if we aren't root, we cannot init graphics */
124:
125: if ((pipe = popen("/usr/bin/tty", "r")) != NULL) {
126: line[0] = 0;
127: fgets(line, 256, pipe);
128: pclose(pipe);
129: line[strlen(line) - 1] = '\0';
1.1.1.3 ! ohara 130: if (
! 131: strcmp(line, "/dev/console") == 0 ||
! 132:
! 133: ( ( strncmp(line, "/dev/tty", 8) == 0 || strncmp(line, "/dev/vc/", 8) == 0 )
! 134: && isdigit((unsigned char) line[8]))
! 135:
! 136: ) {
1.1 maekawa 137: LINUX_graphics_allowed = TRUE;
1.1.1.3 ! ohara 138: } else {
! 139: /* check for socket name as set for example by `screen' */
! 140: char* sty = getenv("STY");
! 141: if (sty) {
! 142: int n1, n2;
! 143: if (3 == sscanf(sty, "%d.tty%d.%s", &n1, &n2, line)) {
! 144: /* we could check here, if host is the
! 145: * same as gethostname() returns. */
! 146: LINUX_graphics_allowed = TRUE;
! 147: }
! 148: }
! 149: }
1.1 maekawa 150: }
151: if (LINUX_graphics_allowed) {
1.1.1.2 maekawa 152: take_privilege();
1.1 maekawa 153: vga_init();
1.1.1.2 maekawa 154: drop_privilege();
1.1 maekawa 155: } else {
156: /* err - shouldn't we give up root uid whatever happens ?
157: * or perhaps vga_init() does it ?
158: */
159: setuid(getuid());
160: }
161: }
162:
1.1.1.2 maekawa 163: TERM_PUBLIC
164: void LINUX_options()
1.1 maekawa 165: {
166: if (!LINUX_graphics_allowed) {
1.1.1.3 ! ohara 167: int_error("Linux terminal driver not available", NO_CARET);
1.1 maekawa 168: }
169: fprintf(stderr, "%s\n", vga_getmodename(linux_vmode));
170: }
171:
1.1.1.2 maekawa 172: TERM_PUBLIC
173: void LINUX_init()
1.1 maekawa 174: {
175: /* vga_init () has been moved to immediately after main () for security */
176: if (vga_getdefaultmode() != -1)
177: linux_vmode = vga_getdefaultmode();
178: /* get the default mode from GSVGAMODE, if available */
179: if (!vga_hasmode(linux_vmode))
180: linux_vmode = G640x480x16;
181: /* test default mode first */
182: if (!vga_hasmode(linux_vmode)) {
183: fputs("Error, unable to initiate graphics.\n", stderr);
184: return;
185: } /* this mode is the bottom line */
186: modeinfo = vga_getmodeinfo(linux_vmode);
187: term->xmax = modeinfo->width;
188: term->ymax = modeinfo->height;
189: linux_lasty = modeinfo->height - 1;
190: }
191:
1.1.1.2 maekawa 192: TERM_PUBLIC void
193: LINUX_reset()
1.1 maekawa 194: {
195: if (graphics_on) {
196: vga_setmode(TEXT);
197: graphics_on = FALSE;
198: }
199: }
200:
1.1.1.2 maekawa 201: TERM_PUBLIC void
202: LINUX_text()
1.1 maekawa 203: {
204: if (graphics_on) {
205: vga_getch();
206: vga_setmode(TEXT);
207: graphics_on = FALSE;
208: }
209: }
210:
1.1.1.2 maekawa 211: TERM_PUBLIC void
212: LINUX_graphics()
1.1 maekawa 213: {
214: if (!graphics_on) {
215: vga_setmode(linux_vmode);
216: graphics_on = TRUE;
217: }
218: }
219:
1.1.1.2 maekawa 220: TERM_PUBLIC void
221: LINUX_suspend()
1.1 maekawa 222: {
223: vga_flip();
224: }
225:
1.1.1.2 maekawa 226: TERM_PUBLIC void
227: LINUX_resume()
1.1 maekawa 228: {
229: vga_flip();
230: }
231:
1.1.1.2 maekawa 232: TERM_PUBLIC void
233: LINUX_linetype(linetype)
1.1 maekawa 234: int linetype;
235: {
236: if (linetype >= 13)
237: linetype %= 13;
238: vga_setcolor(vgacolor[linetype + 2]);
239: }
240:
1.1.1.2 maekawa 241: TERM_PUBLIC void
242: LINUX_move(x, y)
1.1 maekawa 243: unsigned int x;
244: unsigned int y;
245: {
246: linux_startx = x;
247: linux_starty = y;
248: }
249:
1.1.1.2 maekawa 250: TERM_PUBLIC void
251: LINUX_vector(x, y)
1.1 maekawa 252: unsigned int x;
253: unsigned int y;
254: {
255: vga_drawline(linux_startx, linux_lasty - linux_starty, x, linux_lasty - y);
256: linux_startx = x;
257: linux_starty = y;
258: }
259:
1.1.1.2 maekawa 260: TERM_PUBLIC int
261: LINUX_text_angle(ang)
1.1 maekawa 262: int ang;
263: {
264: linux_angle = ang;
265: return TRUE;
266: }
267:
1.1.1.2 maekawa 268: static void
269: LINUX_putc(x, y, c, ang, line_func)
1.1 maekawa 270: unsigned int x, y;
271: int c;
272: int ang;
273: linux_line_func_ptr line_func;
274: {
275: int i, j, k;
276: unsigned int pixelon;
277: i = (int) (c) - 32;
278: for (j = 0; j < FNT5X9_VBITS; j++) {
279: for (k = 0; k < FNT5X9_HBITS; k++) {
280: pixelon = (((unsigned int) (fnt5x9[i][j])) >> k & 1);
281: if (pixelon) {
282: switch (ang) {
283: case 0:
284: (*line_func) (x + k + 1, y - j, x + k + 1, y - j);
285: break;
286: case 1:
287: (*line_func) (x - j, y - k - 1, x - j, y - k - 1);
288: break;
289: }
290: }
291: }
292: }
293: }
294:
1.1.1.2 maekawa 295: TERM_PUBLIC void
296: LINUX_put_text(x, y, str)
1.1 maekawa 297: unsigned int x, y;
1.1.1.2 maekawa 298: const char *str;
1.1 maekawa 299: {
300: int i;
301: switch (linux_angle) {
302: case 0:
303: y -= LINUX_VCHAR / 2;
304: break;
305: case 1:
306: x += LINUX_VCHAR / 2;
307: break;
308: }
309: for (i = 0; str[i]; i++) {
310: LINUX_putc(x, linux_lasty - y, str[i], linux_angle, vga_drawline);
311: switch (linux_angle) {
312: case 0:
313: x += LINUX_HCHAR;
314: break;
315: case 1:
316: y += LINUX_HCHAR;
317: break;
318: }
319: }
320: }
321:
322: #endif
323:
324: #ifdef TERM_TABLE
325: TERM_TABLE_START(linux_driver)
326: "linux", "Linux PC with (s)vgalib",
327: LINUX_XMAX, LINUX_YMAX, LINUX_VCHAR, LINUX_HCHAR,
328: LINUX_VTIC, LINUX_HTIC, LINUX_options, LINUX_init, LINUX_reset,
329: LINUX_text, null_scale, LINUX_graphics, LINUX_move, LINUX_vector,
330: LINUX_linetype, LINUX_put_text, LINUX_text_angle,
331: null_justify_text, do_point, do_arrow, set_font_null,
332: 0, /* pointsize */
333: TERM_CAN_MULTIPLOT, LINUX_suspend, LINUX_resume
334: TERM_TABLE_END(linux_driver)
335: #undef LAST_TERM
336: #define LAST_TERM linux_driver
337: #endif
338:
339: #ifdef TERM_HELP
340: START_HELP(linux)
341: "1 linux",
342: "?commands set terminal linux",
343: "?set terminal linux",
344: "?set term linux",
345: "?terminal linux",
346: "?term linux",
347: "?linux",
348: " The `linux` driver has no additional options to specify. It looks at the",
349: " environment variable GSVGAMODE for the default mode; if not set, it uses",
350: " 1024x768x256 as default mode or, if that is not possible, 640x480x16",
351: " (standard VGA)."
352: END_HELP(linux)
353: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>