[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.2

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

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