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

Annotation of OpenXM_contrib/gnuplot/term/pc.trm, Revision 1.1

1.1     ! maekawa     1: /*
        !             2:  * $Id: pc.trm,v 1.20 1998/06/18 14:59:22 ddenholm Exp $
        !             3:  *
        !             4:  */
        !             5:
        !             6: /* GNUPLOT - pc.trm */
        !             7:
        !             8: /*[
        !             9:  * Copyright 1990 - 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:  *  Under Microsoft C
        !            43:  *      cga, egabios, egalib, vgabios, hercules, corona325, att
        !            44:  *  Under Turboc C
        !            45:  *      cga, ega/vga, vgamono, svga, mcga, hercules, att
        !            46:  *  Under Watcom C
        !            47:  *      cga, ega/vga, vgamono, svga, mcga, hercules, ???
        !            48:  *
        !            49:  * AUTHORS
        !            50:  *  Colin Kelley, Thomas Williams, William Wilson, Russell Lang
        !            51:  *  modified by David J. Liu (liu@csb.yale.edu) for version 3.6
        !            52:  *
        !            53:  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
        !            54:  *
        !            55:  * Because only one compiler is used to generate gnuplot.exe
        !            56:  * and the type of the single graphics board is auto-detected,
        !            57:  * we can combine all these parts into one terminal type: PC
        !            58:  * and let the computer take care of the rest.  -- DJL
        !            59:  *
        !            60:  * Since I don't have MicroSoft C, I assume it would define MSC.
        !            61:  * Please correct it if you are using MS C.  Thank you.  -- DJL
        !            62:  *
        !            63:  */
        !            64:
        !            65: /*
        !            66:  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
        !            67:  */
        !            68:
        !            69: #include "driver.h"
        !            70:
        !            71: #ifdef TERM_REGISTER
        !            72: register_term(dospc)
        !            73: #endif
        !            74:
        !            75: #ifdef TERM_PROTO
        !            76: TERM_PUBLIC void PC_text __PROTO((void));
        !            77: TERM_PUBLIC void PC_reset __PROTO((void));
        !            78: TERM_PUBLIC void PC_init __PROTO((void));
        !            79: TERM_PUBLIC void PC_graphics __PROTO((void));
        !            80: TERM_PUBLIC void PC_linetype __PROTO((int linetype));
        !            81: TERM_PUBLIC void PC_move __PROTO((int x, int y));
        !            82: TERM_PUBLIC void PC_vector __PROTO((int x, int y));
        !            83: TERM_PUBLIC void PC_put_text __PROTO((int x, int y, char *str));
        !            84: TERM_PUBLIC int PC_text_angle __PROTO((int ang));
        !            85: TERM_PUBLIC int PC_justify_text __PROTO((enum JUSTIFY ang));
        !            86:
        !            87: #define PC_HCHAR FNT5X9_HCHAR
        !            88: #define PC_VCHAR FNT5X9_VCHAR
        !            89: #define PC_HTIC 5
        !            90: #define PC_VTIC 4
        !            91: #define PC_XMAX 100            /* These two entries are just place holders. */
        !            92: #define PC_YMAX 100            /* The actual values will be found in init.  */
        !            93: #endif /* TERM_PROTO */
        !            94:
        !            95: #ifndef TERM_PROTO_ONLY
        !            96: #ifdef TERM_BODY
        !            97:
        !            98: #ifdef __TURBOC__
        !            99: static int huge detect_svga __PROTO((void));
        !           100: #endif /* __TURBOC__ */
        !           101:
        !           102: #include <string.h>
        !           103: #include <stdlib.h>
        !           104: #ifdef __TURBOC__
        !           105: #include <graphics.h>
        !           106: #include <conio.h>
        !           107: #include <dos.h>
        !           108: #endif /* __TURBOC__ */
        !           109: #ifdef __WATCOMC__
        !           110: #include <graph.h>
        !           111: #endif /* WATCOMC */
        !           112: #ifdef MSC
        !           113: #include "mcega.h"
        !           114: #endif /* MSC */
        !           115:
        !           116: static int pattern[] ={ 0xffff, 0x0f0f, 0xffff, 0xaaaa, 0x3333, 0x3f3f, 0x0f0f };
        !           117: static int vga_color[] ={ 7, 8, 2, 3, 4, 5, 9, 14, 12, 15, 13, 10, 11, 1, 6 };
        !           118:
        !           119: static int pc_driver, pc_mode;
        !           120: static int graphics_on = FALSE, pc_graphics = FALSE;
        !           121: static int startx, starty, pc_lastx, pc_lasty, pc_colors;
        !           122: static int pc_angle, pc_hjustify, pc_vjustify, pc_text_size, pc_text_dir, pc_corscreen = -1;
        !           123:
        !           124:
        !           125: #ifdef __TURBOC__
        !           126: extern int far _Cdecl SVGA_driver_far[];
        !           127: #endif /* __TURBOC__ */
        !           128:
        !           129: #ifdef __WATCOMC__
        !           130: enum {
        !           131:     HORIZ_DIR, VERT_DIR
        !           132: };
        !           133: static void _settextang(ang)
        !           134: int ang;
        !           135: {
        !           136:     if (ang == HORIZ_DIR) {
        !           137:        _settextorient(1, 0);
        !           138:     } else {
        !           139:        _settextorient(0, 1);
        !           140:     }
        !           141: }
        !           142: #endif /* WATCOMC */
        !           143:
        !           144: static int huge detect_svga(void)
        !           145: {
        !           146:     return 0;                  /* the default mode, just a place holder */
        !           147: }
        !           148:
        !           149: void PC_setup()
        !           150: {                              /* called from the beginning of main() */
        !           151:     int i, t, x, y;
        !           152:     char pc_modename[9];
        !           153: #ifdef __WATCOMC__
        !           154:     struct videoconfig VC;
        !           155: #endif /* WATCOMC */
        !           156:
        !           157:     /* First link all BRI dribers, then detect the display card. */
        !           158:     /* If environment PCTRM is set, try initiate the card/mode.  */
        !           159:
        !           160:     /* special instruction on mode */
        !           161:     safe_strncpy(pc_modename, getenv("PCTRM"), 8);
        !           162:
        !           163: #ifdef __TURBOC__
        !           164:     /* Some of this code including BGI drivers are copyright Borland Intl. */
        !           165:     registerfarbgidriver(EGAVGA_driver_far);
        !           166:     registerfarbgidriver(CGA_driver_far);
        !           167:     registerfarbgidriver(Herc_driver_far);
        !           168:     registerfarbgidriver(ATT_driver_far);
        !           169:     registerfarbgidriver(PC3270_driver_far);
        !           170:     pc_driver = DETECT;
        !           171:     detectgraph(&pc_driver, &pc_mode);
        !           172:     if (graphresult()) {
        !           173:        fputs("Unable to initialize graphics.\n", stderr);
        !           174:        return;
        !           175:     }
        !           176: #ifdef BGI_NAME
        !           177: /* the highest standard pc_driver value, see graphics.h */
        !           178: #define LAST_BGI 10
        !           179: /* the last mode of the SVGA.BGI */
        !           180: #define LAST_SVGA_MODE 6
        !           181:     /* test SVGA if we have VGA */
        !           182:     if ((pc_driver == VGA) && (pc_modename[0] == 'S')) {
        !           183:        installuserdriver(BGI_NAME, &detect_svga);
        !           184:        registerfarbgidriver(SVGA_driver_far);
        !           185:        pc_driver = DETECT;
        !           186:        initgraph(&pc_driver, &pc_mode, "");
        !           187:         /* The following code, which is independent of the actual SVGA.BGI
        !           188:         * used, tries to find a mode of width defined in the environment
        !           189:         * variable PCTRM */
        !           190:        if (pc_driver > LAST_BGI) {     /* success */
        !           191:            sscanf(pc_modename, "S%d", &t);
        !           192:            switch (t) {
        !           193:            case 800:
        !           194:                break;          /* S800  */
        !           195:            case 1024:
        !           196:                break;          /* S1024 */
        !           197:            case 1280:
        !           198:                break;          /* S1280 */
        !           199:            default:
        !           200:                t = 640;        /* 640x480 */
        !           201:            }
        !           202:            for (i = 0; i <= LAST_SVGA_MODE; i++) {
        !           203:                setgraphmode(i);
        !           204:                if ((getmaxx() + 1 == t) && (getmaxcolor() > 14))
        !           205:                    pc_mode = i;
        !           206:            }
        !           207:            setgraphmode(pc_mode);
        !           208:            if (graphresult()) {        /* error, go back to VGA */
        !           209:                pc_driver = VGA;
        !           210:                pc_mode = 4;
        !           211:            }
        !           212:        }
        !           213:     }                          /* SVGA tested */
        !           214:     if (pc_driver <= LAST_BGI)
        !           215: #endif /* BGI_NAME */
        !           216:        initgraph(&pc_driver, &pc_mode, "");
        !           217:     pc_colors = getmaxcolor() + 1;
        !           218:     pc_lastx = getmaxx();
        !           219:     pc_lasty = getmaxy();
        !           220:     restorecrtmode();
        !           221:     clrscr();
        !           222: #endif /* __TURBOC__ */
        !           223: #ifdef __WATCOMC__
        !           224:     _getvideoconfig(&VC);
        !           225:     if ((pc_driver = VC.adapter) == 0) {
        !           226:        fprintf(stderr, "Unable to initialize graphics.\n");
        !           227:        return;
        !           228:     }
        !           229:     switch (pc_driver = VC.adapter) {
        !           230:     case _HERCULES:
        !           231:        pc_mode = _HERCMONO;
        !           232:        break;
        !           233:     case _CGA:
        !           234:        pc_mode = _HRESBW;
        !           235:        break;
        !           236:     case _MCGA:
        !           237:        pc_mode = _MRES256COLOR;
        !           238:        break;
        !           239:     case _EGA:
        !           240:        pc_mode = (VC.monitor == _MONO ? _ERESCOLOR : _ERESNOCOLOR);
        !           241:        break;
        !           242:     case _VGA:
        !           243:        pc_mode = _VRES16COLOR;
        !           244:        break;
        !           245:     case _SVGA:
        !           246:        if (pc_modename[0] == 'S') {    /* test SVGA resolution */
        !           247:            sscanf(pc_modename, "S%d", &t);
        !           248:            switch (t) {
        !           249:            case 800:
        !           250:                pc_mode = _SVRES256COLOR;
        !           251:                break;          /* S800  */
        !           252:            case 1024:
        !           253:                pc_mode = _XRES256COLOR;
        !           254:                break;          /* S1024 */
        !           255:            case 1280:
        !           256:                pc_mode = _XRES256COLOR + 2;
        !           257:                break;          /* S1280 */
        !           258:                /* Someone help me, who knows, how a newer Watcom calls that */
        !           259:            default:
        !           260:                t = 640;
        !           261:                pc_mode = _VRES256COLOR;        /* 640x480 */
        !           262:            }
        !           263:            while (_setvideomode(pc_mode) == 0)
        !           264:                pc_mode--;
        !           265:        }
        !           266:        break;
        !           267:     default:
        !           268:        fputs("Unable to initialize graphics.\n", stderr);
        !           269:        return;
        !           270:     }
        !           271:     _setvideomode(pc_mode);
        !           272:     _getvideoconfig(&VC);
        !           273:     pc_lastx = VC.numxpixels - 1;
        !           274:     pc_lasty = VC.numypixels - 1;
        !           275:     pc_colors = VC.numcolors;
        !           276:     _setvideomode(_DEFAULTMODE);
        !           277: #endif /* WATCOMC */
        !           278:     x = pc_lastx + 1;
        !           279:     y = pc_lasty + 1;
        !           280:     fprintf(stderr, "\tScreen of %d x %d pixels and %d colors.\n",
        !           281:            x, y, pc_colors);
        !           282:     pc_graphics = TRUE;
        !           283: }
        !           284:
        !           285: TERM_PUBLIC void PC_init()
        !           286: {
        !           287:     char *pathp;
        !           288: #ifdef __WATCOMC__
        !           289:     struct _fontinfo fi;
        !           290: #endif
        !           291:
        !           292:     if (!pc_graphics) {
        !           293:        fputs("Unable to initialize graphics.\n", stderr);
        !           294:        term = 0;
        !           295:        return;
        !           296:     }
        !           297:     /* Double the tic/font sizes. */
        !           298:     pc_text_size = (pc_lasty > 590) ? 2 : 1;
        !           299:     term->h_char = PC_HCHAR;
        !           300:     term->v_char = PC_VCHAR;
        !           301:     term->h_tic = PC_HTIC * pc_text_size;
        !           302:     term->v_tic = PC_VTIC * pc_text_size;
        !           303:     term->xmax = pc_lastx + 1;
        !           304:     term->ymax = pc_lasty + 1;
        !           305: #ifdef __TURBOC__
        !           306:     setgraphmode(pc_mode);
        !           307:     settextstyle(DEFAULT_FONT, HORIZ_DIR, pc_text_size);
        !           308:     settextjustify(pc_hjustify, pc_vjustify);
        !           309:     term->h_char = textheight("X");    /* overriding the default */
        !           310:     term->v_char = textwidth("X");     /* overriding the default */
        !           311: #endif /* __TURBOC__ */
        !           312: #ifdef __WATCOMC__
        !           313:     _setvideomode(pc_mode);
        !           314:     _settextang(HORIZ_DIR);
        !           315:     _settextalign(pc_hjustify, pc_vjustify);
        !           316:     _setcharsize(pc_text_size * PC_HCHAR, pc_text_size * PC_VCHAR);
        !           317:     _getfontinfo(&fi);
        !           318:     term->h_char = fi.avgwidth;
        !           319:     term->v_char = fi.pixheight * 1.5;
        !           320: #endif /* WATCOMC */
        !           321: #ifdef MSC
        !           322: #endif /* MSC */
        !           323: }
        !           324:
        !           325: TERM_PUBLIC void PC_graphics()
        !           326: {
        !           327:     graphics_on = TRUE;
        !           328: #ifdef __TURBOC__
        !           329:     setgraphmode(pc_mode);
        !           330: #endif /* __TURBOC__ */
        !           331: #ifdef __WATCOMC__
        !           332:     _setvideomode(pc_mode);
        !           333: #endif /* WATCOMC */
        !           334: #ifdef MSC
        !           335:     if (pc_corscreen == -1)
        !           336:        Vmode(18);              /* VGA */
        !           337:     else {
        !           338:        grinit(corscreen);
        !           339:        grandtx();
        !           340:     }                          /* corolla */
        !           341: #endif /* MSC */
        !           342: }
        !           343:
        !           344: TERM_PUBLIC void PC_linetype(linetype)
        !           345: {
        !           346:     if (pc_colors > 14) {      /* 16 or more colors */
        !           347:        if (linetype >= 13)
        !           348:            linetype %= 13;
        !           349: #ifdef __TURBOC__
        !           350:        setcolor(vga_color[linetype + 2]);
        !           351: #endif /* __TURBOC__ */
        !           352: #ifdef __WATCOMC__
        !           353:        _setcolor(vga_color[linetype + 2]);
        !           354: #endif /* WATCOMC */
        !           355: #ifdef MSC
        !           356: #endif /* MSC */
        !           357:     } else {                   /* MONO */
        !           358:        if (linetype >= 5)
        !           359:            linetype %= 5;
        !           360: #ifdef __TURBOC__
        !           361:        setlinestyle(4, pattern[linetype + 2], 1);
        !           362: #endif /* __TURBOC__ */
        !           363: #ifdef __WATCOMC__
        !           364:        _setlinestyle(pattern[linetype + 2]);
        !           365: #endif /* WATCOMC */
        !           366: #ifdef MSC
        !           367:        if (pc_corscreen != -1)
        !           368:            Cor_mask(pattern[linetype + 2]);
        !           369: #endif /* MSC */
        !           370:     }
        !           371: }
        !           372:
        !           373: TERM_PUBLIC void PC_move(x, y)
        !           374: int x, y;
        !           375: {
        !           376: #ifdef __TURBOC__
        !           377:     moveto(x, pc_lasty - y);
        !           378: #endif /* __TURBOC__ */
        !           379: #ifdef __WATCOMC__
        !           380:     _moveto(x, pc_lasty - y);
        !           381: #endif /* WATCOMC */
        !           382: #ifdef MSC
        !           383: #endif /* MSC */
        !           384:     startx = x;
        !           385:     starty = y;
        !           386: }
        !           387:
        !           388: TERM_PUBLIC void PC_vector(x, y)
        !           389: int x, y;
        !           390: {
        !           391: #ifdef __TURBOC__
        !           392:     lineto(x, pc_lasty - y);
        !           393: #endif /* __TURBOC__ */
        !           394: #ifdef __WATCOMC__
        !           395:     _lineto(x, pc_lasty - y);
        !           396: #endif /* WATCOMC */
        !           397: #ifdef MSC
        !           398:     if (pc_corscreen != -1)
        !           399:        Cor_line(startx, COR_YLAST - starty, x, COR_YLAST - y);
        !           400: #endif /* MSC */
        !           401:     startx = x;
        !           402:     starty = y;
        !           403: }
        !           404:
        !           405: TERM_PUBLIC void PC_reset()
        !           406: {
        !           407:     graphics_on = FALSE;
        !           408: #ifdef __TURBOC__
        !           409:     restorecrtmode();
        !           410:     clrscr();
        !           411: #endif /* __TURBOC__ */
        !           412: #ifdef __WATCOMC__
        !           413:     _setvideomode(_DEFAULTMODE);
        !           414: #endif /* WATCOMC */
        !           415: #ifdef MSC
        !           416:     Vmode(3);
        !           417: #endif /* MSC */
        !           418: }
        !           419:
        !           420: TERM_PUBLIC void PC_text()
        !           421: {
        !           422:     if (graphics_on) {
        !           423:        graphics_on = FALSE;
        !           424:        (void) getch();
        !           425: #ifdef __TURBOC__
        !           426:        restorecrtmode();
        !           427:        clrscr();
        !           428: #endif /* __TURBOC__ */
        !           429: #ifdef __WATCOMC__
        !           430:        _setvideomode(_DEFAULTMODE);
        !           431: #endif /* WATCOMC */
        !           432: #ifdef MSC
        !           433:        if (pc_corscreen != -1) {
        !           434:            grreset();
        !           435:            txonly();
        !           436:        }
        !           437:        Vmode(3);
        !           438: #endif /* MSC */
        !           439:     }
        !           440: }
        !           441:
        !           442: TERM_PUBLIC int PC_text_angle(ang)
        !           443: int ang;
        !           444: {
        !           445:     switch (ang) {
        !           446:     case 0:
        !           447:        pc_text_dir = HORIZ_DIR;
        !           448:        break;
        !           449:     case 1:
        !           450:        pc_text_dir = VERT_DIR;
        !           451:        break;
        !           452:     }
        !           453:     return TRUE;
        !           454: }
        !           455:
        !           456: TERM_PUBLIC int PC_justify_text(just)
        !           457: enum JUSTIFY just;
        !           458: {
        !           459: #if defined(__TURBOC__)
        !           460:     switch (just) {
        !           461:     case LEFT:
        !           462:        pc_hjustify = LEFT_TEXT;
        !           463:        pc_vjustify = CENTER_TEXT;
        !           464:        break;
        !           465:     case CENTRE:
        !           466:        pc_hjustify = CENTER_TEXT;
        !           467:        pc_vjustify = CENTER_TEXT;
        !           468:        break;
        !           469:     case RIGHT:
        !           470:        pc_hjustify = RIGHT_TEXT;
        !           471:        pc_vjustify = CENTER_TEXT;
        !           472:        break;
        !           473:     }
        !           474:     settextjustify(pc_hjustify, pc_vjustify);
        !           475:     return 1;
        !           476: #elif defined(__WATCOMC__)
        !           477:     switch (just) {
        !           478:     case LEFT:
        !           479:        pc_hjustify = _LEFT;
        !           480:        pc_vjustify = _HALF;
        !           481:        break;
        !           482:     case CENTRE:
        !           483:        pc_hjustify = _CENTER;
        !           484:        pc_vjustify = _HALF;
        !           485:        break;
        !           486:     case RIGHT:
        !           487:        pc_hjustify = _RIGHT;
        !           488:        pc_vjustify = _HALF;
        !           489:        break;
        !           490:     }
        !           491:     _settextalign(pc_hjustify, pc_vjustify);
        !           492:     return 1;
        !           493: #else
        !           494:     return (just == LEFT);
        !           495: #endif
        !           496: }
        !           497:
        !           498: TERM_PUBLIC void PC_put_text(x, y, str)
        !           499: int x, y;
        !           500: char *str;
        !           501: {
        !           502: #ifdef __TURBOC__
        !           503:     settextstyle(DEFAULT_FONT, pc_text_dir, pc_text_size);
        !           504:     settextjustify(pc_hjustify, pc_vjustify);
        !           505:     outtextxy(x, pc_lasty - y, str);
        !           506: #endif /* __TURBOC__ */
        !           507: #ifdef __WATCOMC__
        !           508:     _setcharsize(pc_text_size * PC_VCHAR, pc_text_size * PC_HCHAR);
        !           509:     _settextang(pc_text_dir);
        !           510:     _settextalign(pc_hjustify, pc_vjustify);
        !           511:     _grtext(x, pc_lasty - y, str);
        !           512: #endif /* WATCOMC */
        !           513: #ifdef MSC
        !           514: #endif /* MSC */
        !           515: }
        !           516:
        !           517: #endif /* TERM_BODY */
        !           518:
        !           519: #ifdef TERM_TABLE
        !           520:
        !           521: TERM_TABLE_START(dospc_driver)
        !           522:     "dospc", "IBM PC/Clone running DOS",
        !           523:     PC_XMAX, PC_YMAX, PC_VCHAR, PC_HCHAR,
        !           524:     PC_VTIC, PC_HTIC, options_null, PC_init, PC_reset,
        !           525:     PC_text, null_scale, PC_graphics, PC_move, PC_vector,
        !           526:     PC_linetype, PC_put_text, PC_text_angle,
        !           527:     PC_justify_text, line_and_point, do_arrow, set_font_null
        !           528: TERM_TABLE_END(pc_driver)
        !           529:
        !           530: #undef LAST_TERM
        !           531: #define LAST_TERM dospc_driver
        !           532:
        !           533: #endif /* TERM_TABLE */
        !           534: #endif /* TERM_PROTO_ONLY */
        !           535:
        !           536: #ifdef TERM_HELP
        !           537: START_HELP(dospc)
        !           538: "1 dospc",
        !           539: "?commands set terminal dospc",
        !           540: "?set terminal dospc",
        !           541: "?set term dospc",
        !           542: "?terminal dospc",
        !           543: "?term dospc",
        !           544: "?dospc",
        !           545: " The `dospc` terminal driver supports PCs with arbitrary graphics boards, which",
        !           546: " will be automatically detected.  It should be used only if you are not using",
        !           547: " the gcc or Zortec C/C++ compilers."
        !           548: END_HELP(dospc)
        !           549: #endif /* TERM_HELP */

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