[BACK]Return to linux.trm CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot / term

Annotation of OpenXM_contrib/gnuplot/term/linux.trm, Revision 1.1.1.1

1.1       maekawa     1: /*
                      2:  * $Id: linux.trm,v 1.21 1998/06/18 14:59:20 ddenholm Exp $
                      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));
                     83: TERM_PUBLIC void LINUX_put_text __PROTO((unsigned int x, unsigned int y, char *str));
                     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;
                     97: vga_modeinfo *modeinfo;
                     98: static int linux_startx, linux_starty, linux_lasty;
                     99: static int linux_angle;
                    100: int LINUX_graphics_allowed;
                    101:
                    102: typedef (*linux_line_func_ptr) __PROTO((int x1, int y1, int x2, int y2));
                    103:
                    104: static void LINUX_putc __PROTO((unsigned int x, unsigned int y, int c, int ang,
                    105:                                linux_line_func_ptr line_func));
                    106:
                    107: /* this function is called at the very beginning of main() to initialize
                    108:  *  the vgalib and to revoke suid privileges.
                    109:  * /dev/console and /dev/tty\d are considered graphic terminals, all other
                    110:  * don't support the linux terminal */
                    111:
                    112: void LINUX_setup(void)
                    113: {
                    114:     char line[256];
                    115:     FILE *pipe;
                    116:
                    117:     LINUX_graphics_allowed = FALSE;
                    118:
                    119:     if (geteuid() != 0)
                    120:        return;                 /* if we aren't root, we cannot init graphics */
                    121:
                    122:     if ((pipe = popen("/usr/bin/tty", "r")) != NULL) {
                    123:        line[0] = 0;
                    124:        fgets(line, 256, pipe);
                    125:        pclose(pipe);
                    126:        line[strlen(line) - 1] = '\0';
                    127:        if (strcmp(line, "/dev/console") == 0 ||
                    128:            (strncmp(line, "/dev/tty", 8) == 0 && isdigit(line[8])))
                    129:            LINUX_graphics_allowed = TRUE;
                    130:     }
                    131:     if (LINUX_graphics_allowed) {
                    132:        vga_init();
                    133:     } else {
                    134:        /* err - shouldn't we give up root uid whatever happens ?
                    135:         * or perhaps vga_init() does it ?
                    136:         */
                    137:        setuid(getuid());
                    138:     }
                    139: }
                    140:
                    141: TERM_PUBLIC void LINUX_options()
                    142: {
                    143:     if (!LINUX_graphics_allowed) {
                    144:        int_error("Linux terminal driver not available", NO_CARET);
                    145:     }
                    146:     fprintf(stderr, "%s\n", vga_getmodename(linux_vmode));
                    147: }
                    148:
                    149: TERM_PUBLIC void LINUX_init()
                    150: {
                    151:     /* vga_init () has been moved to immediately after main () for security */
                    152:     if (vga_getdefaultmode() != -1)
                    153:        linux_vmode = vga_getdefaultmode();
                    154:     /* get the default mode from GSVGAMODE, if available */
                    155:     if (!vga_hasmode(linux_vmode))
                    156:        linux_vmode = G640x480x16;
                    157:     /* test default mode first */
                    158:     if (!vga_hasmode(linux_vmode)) {
                    159:        fputs("Error, unable to initiate graphics.\n", stderr);
                    160:        return;
                    161:     }                          /* this mode is the bottom line */
                    162:     modeinfo = vga_getmodeinfo(linux_vmode);
                    163:     term->xmax = modeinfo->width;
                    164:     term->ymax = modeinfo->height;
                    165:     linux_lasty = modeinfo->height - 1;
                    166: }
                    167:
                    168: TERM_PUBLIC void LINUX_reset()
                    169: {
                    170:     if (graphics_on) {
                    171:        vga_setmode(TEXT);
                    172:        graphics_on = FALSE;
                    173:     }
                    174: }
                    175:
                    176: TERM_PUBLIC void LINUX_text()
                    177: {
                    178:     if (graphics_on) {
                    179:        vga_getch();
                    180:        vga_setmode(TEXT);
                    181:        graphics_on = FALSE;
                    182:     }
                    183: }
                    184:
                    185: TERM_PUBLIC void LINUX_graphics()
                    186: {
                    187:     if (!graphics_on) {
                    188:        vga_setmode(linux_vmode);
                    189:        graphics_on = TRUE;
                    190:     }
                    191: }
                    192:
                    193: TERM_PUBLIC void LINUX_suspend()
                    194: {
                    195:     vga_flip();
                    196: }
                    197:
                    198: TERM_PUBLIC void LINUX_resume()
                    199: {
                    200:     vga_flip();
                    201: }
                    202:
                    203: TERM_PUBLIC void LINUX_linetype(linetype)
                    204: int linetype;
                    205: {
                    206:     if (linetype >= 13)
                    207:        linetype %= 13;
                    208:     vga_setcolor(vgacolor[linetype + 2]);
                    209: }
                    210:
                    211: TERM_PUBLIC void LINUX_move(x, y)
                    212: unsigned int x;
                    213: unsigned int y;
                    214: {
                    215:     linux_startx = x;
                    216:     linux_starty = y;
                    217: }
                    218:
                    219: TERM_PUBLIC void LINUX_vector(x, y)
                    220: unsigned int x;
                    221: unsigned int y;
                    222: {
                    223:     vga_drawline(linux_startx, linux_lasty - linux_starty, x, linux_lasty - y);
                    224:     linux_startx = x;
                    225:     linux_starty = y;
                    226: }
                    227:
                    228: TERM_PUBLIC int LINUX_text_angle(ang)
                    229: int ang;
                    230: {
                    231:     linux_angle = ang;
                    232:     return TRUE;
                    233: }
                    234:
                    235: static void LINUX_putc(x, y, c, ang, line_func)
                    236: unsigned int x, y;
                    237: int c;
                    238: int ang;
                    239: linux_line_func_ptr line_func;
                    240: {
                    241:     int i, j, k;
                    242:     unsigned int pixelon;
                    243:     i = (int) (c) - 32;
                    244:     for (j = 0; j < FNT5X9_VBITS; j++) {
                    245:        for (k = 0; k < FNT5X9_HBITS; k++) {
                    246:            pixelon = (((unsigned int) (fnt5x9[i][j])) >> k & 1);
                    247:            if (pixelon) {
                    248:                switch (ang) {
                    249:                case 0:
                    250:                    (*line_func) (x + k + 1, y - j, x + k + 1, y - j);
                    251:                    break;
                    252:                case 1:
                    253:                    (*line_func) (x - j, y - k - 1, x - j, y - k - 1);
                    254:                    break;
                    255:                }
                    256:            }
                    257:        }
                    258:     }
                    259: }
                    260:
                    261: TERM_PUBLIC void LINUX_put_text(x, y, str)
                    262: unsigned int x, y;
                    263: char *str;
                    264: {
                    265:     int i;
                    266:     switch (linux_angle) {
                    267:     case 0:
                    268:        y -= LINUX_VCHAR / 2;
                    269:        break;
                    270:     case 1:
                    271:        x += LINUX_VCHAR / 2;
                    272:        break;
                    273:     }
                    274:     for (i = 0; str[i]; i++) {
                    275:        LINUX_putc(x, linux_lasty - y, str[i], linux_angle, vga_drawline);
                    276:        switch (linux_angle) {
                    277:        case 0:
                    278:            x += LINUX_HCHAR;
                    279:            break;
                    280:        case 1:
                    281:            y += LINUX_HCHAR;
                    282:            break;
                    283:        }
                    284:     }
                    285: }
                    286:
                    287: #endif
                    288:
                    289: #ifdef TERM_TABLE
                    290: TERM_TABLE_START(linux_driver)
                    291:     "linux", "Linux PC with (s)vgalib",
                    292:     LINUX_XMAX, LINUX_YMAX, LINUX_VCHAR, LINUX_HCHAR,
                    293:     LINUX_VTIC, LINUX_HTIC, LINUX_options, LINUX_init, LINUX_reset,
                    294:     LINUX_text, null_scale, LINUX_graphics, LINUX_move, LINUX_vector,
                    295:     LINUX_linetype, LINUX_put_text, LINUX_text_angle,
                    296:     null_justify_text, do_point, do_arrow, set_font_null,
                    297:     0,                         /* pointsize */
                    298:     TERM_CAN_MULTIPLOT, LINUX_suspend, LINUX_resume
                    299: TERM_TABLE_END(linux_driver)
                    300: #undef LAST_TERM
                    301: #define LAST_TERM linux_driver
                    302: #endif
                    303:
                    304: #ifdef TERM_HELP
                    305: START_HELP(linux)
                    306: "1 linux",
                    307: "?commands set terminal linux",
                    308: "?set terminal linux",
                    309: "?set term linux",
                    310: "?terminal linux",
                    311: "?term linux",
                    312: "?linux",
                    313: " The `linux` driver has no additional options to specify.  It looks at the",
                    314: " environment variable GSVGAMODE for the default mode; if not set, it uses",
                    315: " 1024x768x256 as default mode or, if that is not possible, 640x480x16",
                    316: " (standard VGA)."
                    317: END_HELP(linux)
                    318: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>