Annotation of researchv9/X11/src/X.V11R1/clients/xterm/Tekproc.c, revision 1.1

1.1     ! root        1: /*
        !             2:  *     $Source: /orpheus/u1/X11/clients/xterm/RCS/Tekproc.c,v $
        !             3:  *     $Header: Tekproc.c,v 1.5 87/09/10 17:19:46 swick Exp $
        !             4:  */
        !             5: 
        !             6: 
        !             7: #include <X11/copyright.h>
        !             8: 
        !             9: /*
        !            10:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
        !            11:  *
        !            12:  *                         All Rights Reserved
        !            13:  *
        !            14:  * Permission to use, copy, modify, and distribute this software and its
        !            15:  * documentation for any purpose and without fee is hereby granted,
        !            16:  * provided that the above copyright notice appear in all copies and that
        !            17:  * both that copyright notice and this permission notice appear in
        !            18:  * supporting documentation, and that the name of Digital Equipment
        !            19:  * Corporation not be used in advertising or publicity pertaining to
        !            20:  * distribution of the software without specific, written prior permission.
        !            21:  *
        !            22:  *
        !            23:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            24:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            25:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            26:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            27:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            28:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            29:  * SOFTWARE.
        !            30:  */
        !            31: 
        !            32: /* Tekproc.c */
        !            33: 
        !            34: #include <X11/Xlib.h>
        !            35: #include <X11/Intrinsic.h>
        !            36: #include <X11/Xatom.h>
        !            37: #include <X11/Xutil.h>
        !            38: #include "ptyx.h"
        !            39: #include "Tekparse.h"
        !            40: #include <stdio.h>
        !            41: #include <sgtty.h>
        !            42: #include <ctype.h>
        !            43: #include <errno.h>
        !            44: #include <setjmp.h>
        !            45: #include <sys/file.h>
        !            46: #include <sys/time.h>
        !            47: #include <pwd.h>
        !            48: #include <strings.h>
        !            49: #include "data.h"
        !            50: #include "error.h"
        !            51: #ifdef MODEMENU
        !            52: #include "menu.h"
        !            53: #endif MODEMENU
        !            54: 
        !            55: extern void exit();
        !            56: extern long time();
        !            57: 
        !            58: /* ||| Temp stuff till I make this work again */
        !            59: char *fore_color;
        !            60: char *back_color;
        !            61: char *curs_color;
        !            62: 
        !            63: #define TekColormap DefaultColormap( screen->display, \
        !            64:                                    DefaultScreen(screen->display) )
        !            65: 
        !            66: /* Tek defines */
        !            67: 
        !            68: #define        BEL             07
        !            69: #define        CANCEL          030
        !            70: #define        DOTDASHEDLINE   2
        !            71: #define        DOTTEDLINE      1
        !            72: #define        EAST            01
        !            73: #define        ETX             03
        !            74: #define        LARGEFONT       0
        !            75: #define        LARGEFONTNAME   "9x15"
        !            76: #define        LINEMASK        07
        !            77: #define        LONGDASHEDLINE  4
        !            78: #define        MARGIN1         0
        !            79: #define        MARGIN2         1
        !            80: #define MAX_PTS                150
        !            81: #define MAX_VTX                300
        !            82: #define        NAK             025
        !            83: #define        NORTH           04
        !            84: #define        PENDOWN         1
        !            85: #define        PENUP           0
        !            86: #define        SHORTDASHEDLINE 3
        !            87: #define        SMALLFONT       3
        !            88: #define        SMALLFONTNAME   "5x7"
        !            89: #define        SOLIDLINE       0
        !            90: #define        SOUTH           010
        !            91: #define        TEKBOTTOMPAD    23
        !            92: #define        TEKDEFHEIGHT    565
        !            93: #define        TEKDEFWIDTH     750
        !            94: #define        TEKHEIGHT       3072
        !            95: #define        TEKHOME         ((TekChar[screen->page.fontsize].nlines - 1)\
        !            96:                         * TekChar[screen->page.fontsize].vsize)
        !            97: #define        TEKMINHEIGHT    452
        !            98: #define        TEKMINWIDTH     600
        !            99: #define        TEKPAD          57
        !           100: #define        TEKTOPPAD       34
        !           101: #define        TEKWIDTH        4096
        !           102: #define        TEXT_BUF_SIZE   256
        !           103: #define        THREEFONT       2
        !           104: #define        THREEFONTNAME   "8x13"
        !           105: #define        TWOFONT         1
        !           106: #define        TWOFONTNAME     "fixed"
        !           107: #define        WEST            02
        !           108: 
        !           109: #define        TekMove(x,y)    screen->cur_X = x; screen->cur_Y = y
        !           110: #define        input()         Tinput()
        !           111: #define        unput(c)        *Tpushback++ = c
        !           112: 
        !           113: #ifndef lint
        !           114: static char rcs_id[] = "$Header: Tekproc.c,v 1.5 87/09/10 17:19:46 swick Exp $";
        !           115: #endif lint
        !           116: 
        !           117: static XPoint *T_box[TEKNUMFONTS] = {
        !           118:        T_boxlarge,
        !           119:        T_box2,
        !           120:        T_box3,
        !           121:        T_boxsmall,
        !           122: };
        !           123: static struct Tek_Char {
        !           124:        int hsize;      /* in Tek units */
        !           125:        int vsize;      /* in Tek units */
        !           126:        int charsperline;
        !           127:        int nlines;
        !           128: } TekChar[TEKNUMFONTS] = {
        !           129:        {56, 88, 74, 35},       /* large */
        !           130:        {51, 82, 81, 38},       /* #2 */
        !           131:        {34, 53, 121, 58},      /* #3 */
        !           132:        {31, 48, 133, 64},      /* small */
        !           133: };
        !           134: 
        !           135: static int *curstate;
        !           136: static Cursor GINcursor;
        !           137: static XSegment *line_pt;
        !           138: static int nplot;
        !           139: static TekLink Tek0;
        !           140: static jmp_buf Tekjump;
        !           141: static TekLink *TekRecord;
        !           142: static XSegment *Tline;
        !           143: static int *Tparsestate;
        !           144: 
        !           145: extern int Talptable[];
        !           146: extern int Tbestable[];
        !           147: extern int Tbyptable[];
        !           148: extern int Tesctable[];
        !           149: extern int Tipltable[];
        !           150: extern int Tplttable[];
        !           151: extern int Tpttable[];
        !           152: extern int Tspttable[];
        !           153: 
        !           154: /* event handlers */
        !           155: extern HandleKeyPressed();
        !           156: extern EventDoNothing();
        !           157: extern HandleEnterWindow();
        !           158: extern HandleLeaveWindow();
        !           159: extern HandleFocusChange();
        !           160: extern TekButtonPressed();
        !           161: 
        !           162: 
        !           163: Tekparse()
        !           164: {
        !           165:        register TScreen *screen = &term.screen;
        !           166:        register int c, x, y;
        !           167:        char ch;
        !           168:        int arg;
        !           169:        int Tinput();
        !           170: 
        !           171:        for( ; ; )
        !           172:                switch(Tparsestate[c = input()]) {
        !           173:                 case CASE_REPORT:
        !           174:                        /* report address */
        !           175:                        if(screen->TekGIN) {
        !           176:                                TekGINoff();
        !           177:                                TekEnqMouse(0);
        !           178:                        } else {
        !           179:                                c = 064;        /* has hard copy unit */
        !           180:                                if(screen->margin == MARGIN2)
        !           181:                                        c |= 02;
        !           182:                                TekEnq(c, screen->cur_X, screen->cur_Y);
        !           183:                        }
        !           184:                        TekRecord->ptr[-1] = NAK; /* remove from recording */
        !           185:                        Tparsestate = curstate;
        !           186:                        break;
        !           187: 
        !           188:                 case CASE_VT_MODE:
        !           189:                        /* special return to vt102 mode */
        !           190:                        Tparsestate = curstate;
        !           191:                        TekRecord->ptr[-1] = NAK; /* remove from recording */
        !           192:                        if(screen->logging) {
        !           193:                                FlushLog(screen);
        !           194:                                screen->logstart = buffer;
        !           195:                        }
        !           196:                        return;
        !           197: 
        !           198:                 case CASE_SPT_STATE:
        !           199:                        /* Enter Special Point Plot mode */
        !           200:                        if(screen->TekGIN)
        !           201:                                TekGINoff();
        !           202:                        Tparsestate = curstate = Tspttable;
        !           203:                        break;
        !           204: 
        !           205:                 case CASE_GIN:
        !           206:                        /* Do Tek GIN mode */
        !           207:                        screen->TekGIN = &TekRecord->ptr[-1];
        !           208:                                /* Set cross-hair cursor raster array */
        !           209:                        if(GINcursor = make_tcross(
        !           210:                            screen->mousecolor,
        !           211:                            screen->background))
        !           212:                                XDefineCursor(
        !           213:                                    screen->display,
        !           214:                                    TWindow(screen),
        !           215:                                    GINcursor);
        !           216:                        Tparsestate = Tbyptable;        /* Bypass mode */
        !           217:                        break;
        !           218: 
        !           219:                 case CASE_BEL:
        !           220:                        /* BEL */
        !           221:                        if(screen->TekGIN)
        !           222:                                TekGINoff();
        !           223:                        if(!TekRefresh)
        !           224:                                Bell();
        !           225:                        Tparsestate = curstate; /* clear bypass condition */
        !           226:                        break;
        !           227: 
        !           228:                 case CASE_BS:
        !           229:                        /* BS */
        !           230:                        if(screen->TekGIN)
        !           231:                                TekGINoff();
        !           232:                        Tparsestate = curstate; /* clear bypass condition */
        !           233:                        TCursorBack();
        !           234:                        break;
        !           235: 
        !           236:                 case CASE_PT_STATE:
        !           237:                        /* Enter Tek Point Plot mode */
        !           238:                        if(screen->TekGIN)
        !           239:                                TekGINoff();
        !           240:                        Tparsestate = curstate = Tpttable;
        !           241:                        break;
        !           242: 
        !           243:                 case CASE_PLT_STATE:
        !           244:                        /* Enter Tek Plot mode */
        !           245:                        if(screen->TekGIN)
        !           246:                                TekGINoff();
        !           247:                        Tparsestate = curstate = Tplttable;
        !           248:                        if((c = input()) == BEL)
        !           249:                                screen->pen = PENDOWN;
        !           250:                        else {
        !           251:                                unput(c);
        !           252:                                screen->pen = PENUP;
        !           253:                        }
        !           254:                        break;
        !           255: 
        !           256:                 case CASE_TAB:
        !           257:                        /* HT */
        !           258:                        if(screen->TekGIN)
        !           259:                                TekGINoff();
        !           260:                        Tparsestate = curstate; /* clear bypass condition */
        !           261:                        TCursorForward();
        !           262:                        break;
        !           263: 
        !           264:                 case CASE_IPL_STATE:
        !           265:                        /* Enter Tek Incremental Plot mode */
        !           266:                        if(screen->TekGIN)
        !           267:                                TekGINoff();
        !           268:                        Tparsestate = curstate = Tipltable;
        !           269:                        break;
        !           270: 
        !           271:                 case CASE_ALP_STATE:
        !           272:                        /* Enter Tek Alpha mode from any other mode */
        !           273:                        if(screen->TekGIN)
        !           274:                                TekGINoff();
        !           275:                        /* if in one of graphics states, move alpha cursor */
        !           276:                        if(nplot > 0)   /* flush line Tbuffer */
        !           277:                                TekFlush();
        !           278:                        Tparsestate = curstate = Talptable;
        !           279:                        break;
        !           280: 
        !           281:                 case CASE_UP:
        !           282:                        /* cursor up */
        !           283:                        if(screen->TekGIN)
        !           284:                                TekGINoff();
        !           285:                        Tparsestate = curstate; /* clear bypass condition */
        !           286:                        TCursorUp();
        !           287:                        break;
        !           288: 
        !           289:                 case CASE_COPY:
        !           290:                        /* make copy */
        !           291:                        if(screen->TekGIN)
        !           292:                                TekGINoff();
        !           293:                        TekCopy();
        !           294:                        TekRecord->ptr[-1] = NAK; /* remove from recording */
        !           295:                        Tparsestate = curstate; /* clear bypass condition */
        !           296:                        break;
        !           297: 
        !           298:                 case CASE_PAGE:
        !           299:                        /* Page Function */
        !           300:                        if(screen->TekGIN)
        !           301:                                TekGINoff();
        !           302:                        TekPage();      /* clear bypass condition */
        !           303:                        break;
        !           304: 
        !           305:                 case CASE_BES_STATE:
        !           306:                        /* Byp: an escape char */
        !           307:                        Tparsestate = Tbestable;
        !           308:                        break;
        !           309: 
        !           310:                 case CASE_BYP_STATE:
        !           311:                        /* set bypass condition */
        !           312:                        Tparsestate = Tbyptable;
        !           313:                        break;
        !           314: 
        !           315:                 case CASE_IGNORE:
        !           316:                        /* Esc: totally ignore CR, ESC, LF, ~ */
        !           317:                        break;
        !           318: 
        !           319:                 case CASE_ASCII:
        !           320:                        /* Select ASCII char set */
        !           321:                        /* ignore for now */
        !           322:                        Tparsestate = curstate;
        !           323:                        break;
        !           324: 
        !           325:                 case CASE_APL:
        !           326:                        /* Select APL char set */
        !           327:                        /* ignore for now */
        !           328:                        Tparsestate = curstate;
        !           329:                        break;
        !           330: 
        !           331:                 case CASE_CHAR_SIZE:
        !           332:                        /* character size selector */
        !           333:                        screen->cur.fontsize = c & 03;
        !           334:                        Tparsestate = curstate;
        !           335:                        break;
        !           336: 
        !           337:                 case CASE_BEAM_VEC:
        !           338:                        /* beam and vector selector */
        !           339:                        /* only line types */
        !           340:                        if((c &= LINEMASK) != screen->cur.linetype) {
        !           341:                                if(nplot > 0)
        !           342:                                        TekFlush();
        !           343:                                screen->cur.linetype = c;
        !           344:                        }
        !           345:                        Tparsestate = curstate;
        !           346:                        break;
        !           347: 
        !           348:                 case CASE_CURSTATE:
        !           349:                        Tparsestate = curstate;
        !           350:                        break;
        !           351: 
        !           352:                 case CASE_PENUP:
        !           353:                        /* Ipl: penup */
        !           354:                        screen->pen = PENUP;
        !           355:                        break;
        !           356: 
        !           357:                 case CASE_PENDOWN:
        !           358:                        /* Ipl: pendown */
        !           359:                        screen->pen = PENDOWN;
        !           360:                        break;
        !           361: 
        !           362:                 case CASE_IPL_POINT:
        !           363:                        /* Ipl: point */
        !           364:                        x = screen->cur_X;
        !           365:                        y = screen->cur_Y;
        !           366:                        if(c & NORTH)
        !           367:                                y++;
        !           368:                        else if(c & SOUTH)
        !           369:                                y--;
        !           370:                        if(c & EAST)
        !           371:                                x++;
        !           372:                        else if(c & WEST)
        !           373:                                x--;
        !           374:                        if(screen->pen == PENDOWN)
        !           375:                                TekDraw(x, y);
        !           376:                        else
        !           377:                                TekMove(x, y);
        !           378:                        break;
        !           379: 
        !           380:                 case CASE_PLT_VEC:
        !           381:                        /* Plt: vector */
        !           382:                        unput(c);
        !           383:                        if(getpoint()) {
        !           384:                                if(screen->pen == PENDOWN)
        !           385:                                        TekDraw(screen->cur.x, screen->cur.y);
        !           386:                                else
        !           387:                                        TekMove(screen->cur.x, screen->cur.y);
        !           388:                                screen->pen = PENDOWN;
        !           389:                        }
        !           390:                        break;
        !           391: 
        !           392:                 case CASE_PT_POINT:
        !           393:                        /* Pt: point */
        !           394:                        unput(c);
        !           395:                        if(getpoint()) {
        !           396:                                TekMove(screen->cur.x, screen->cur.y);
        !           397:                                TekDraw(screen->cur.x, screen->cur.y);
        !           398:                        }
        !           399:                        break;
        !           400: 
        !           401:                 case CASE_SPT_POINT:
        !           402:                        /* Spt: point */
        !           403:                        /* ignore intensity character in c */
        !           404:                        if(getpoint()) {
        !           405:                                TekMove(screen->cur.x, screen->cur.y);
        !           406:                                TekDraw(screen->cur.x, screen->cur.y);
        !           407:                        }
        !           408:                        break;
        !           409: 
        !           410:                 case CASE_CR:
        !           411:                        /* CR */
        !           412:                        if(screen->TekGIN)
        !           413:                                TekGINoff();
        !           414:                        if(nplot > 0)   /* flush line Tbuffer */
        !           415:                                TekFlush();
        !           416:                        screen->cur_X = screen->margin == MARGIN1 ? 0 :
        !           417:                         TEKWIDTH / 2;
        !           418:                        Tparsestate = curstate = Talptable;
        !           419:                        break;
        !           420: 
        !           421:                 case CASE_ESC_STATE:
        !           422:                        /* ESC */
        !           423:                        Tparsestate = Tesctable;
        !           424:                        break;
        !           425: 
        !           426:                 case CASE_LF:
        !           427:                        /* LF */
        !           428:                        if(screen->TekGIN)
        !           429:                                TekGINoff();
        !           430:                        TCursorDown();
        !           431:                        if(!TekRefresh && (screen->display->qlen > 0 ||
        !           432:                         (ioctl(screen->display->fd, FIONREAD, (char *)&arg), arg) > 0))
        !           433:                                xevents();
        !           434:                        break;
        !           435: 
        !           436:                 case CASE_SP:
        !           437:                        /* SP */
        !           438:                        TCursorForward();
        !           439:                        break;
        !           440: 
        !           441:                 case CASE_PRINT:
        !           442:                        /* printable character */
        !           443:                        ch = c;
        !           444:                        c = screen->cur.fontsize;
        !           445: 
        !           446:                        XDrawString(
        !           447:                            screen->display,
        !           448:                            TWindow(screen), 
        !           449:                            screen->TnormalGC,
        !           450:                            (int)(screen->cur_X * TekScale(screen)) + screen->border,
        !           451:                            (int)((TEKHEIGHT + TEKTOPPAD - screen->cur_Y) * TekScale(screen)) + screen->border - screen->tobaseline[c],
        !           452:                            &ch,
        !           453:                            1);
        !           454:                        TCursorForward();
        !           455:                        break;
        !           456:                 case CASE_OSC:
        !           457:                        /* do osc escape */
        !           458:                        do_osc(Tinput);
        !           459:                        Tparsestate = curstate;
        !           460:                        break;
        !           461:                }
        !           462: }
        !           463: 
        !           464: static int rcnt;
        !           465: static char *rptr;
        !           466: static int Tselect_mask;
        !           467: 
        !           468: Tinput()
        !           469: {
        !           470:        register TScreen *screen = &term.screen;
        !           471:        register char *cp;
        !           472:        register int i;
        !           473:        register TekLink *tek;
        !           474:        extern char *malloc();
        !           475: 
        !           476:        if(Tpushback > Tpushb)
        !           477:                return(*--Tpushback);
        !           478:        if(TekRefresh) {
        !           479:                if(rcnt-- > 0)
        !           480:                        return(*rptr++);
        !           481:                if(tek = TekRefresh->next) {
        !           482:                        TekRefresh = tek;
        !           483:                        rcnt = tek->count - 1;
        !           484:                        rptr = tek->data;
        !           485:                        return(*rptr++);
        !           486:                }
        !           487:                TekRefresh = (TekLink *)0;
        !           488:                longjmp(Tekjump, 1);
        !           489:        }
        !           490: again:
        !           491:        if(Tbcnt-- <= 0) {
        !           492:                if(nplot > 0)   /* flush line Tbuffer */
        !           493:                        TekFlush();
        !           494:                Tselect_mask = pty_mask;        /* force a read */
        !           495:                for( ; ; ) {
        !           496:                        if(Tselect_mask & pty_mask) {
        !           497:                                if(screen->logging)
        !           498:                                        FlushLog(screen);
        !           499:                                if((Tbcnt = read(screen->respond,
        !           500:                                 Tbptr = Tbuffer, BUF_SIZE)) < 0) {
        !           501:                                        if(errno == EIO && am_slave)
        !           502:                                                exit(0);
        !           503:                                        else if(errno != EWOULDBLOCK)
        !           504:                                                Panic(
        !           505:                                 "Tinput:read returned unexpected error (%d)\n",
        !           506:                                                 errno);
        !           507:                                } else if(Tbcnt == 0)
        !           508:                                        Panic("input: read returned zero\n", 0);
        !           509:                                else {
        !           510:                                        /* strip parity bit */
        !           511:                                        for(i = Tbcnt, cp = Tbptr ; i > 0 ; i--)
        !           512:                                                *cp++ &= CHAR;
        !           513:                                        break;
        !           514:                                }
        !           515:                        }
        !           516:                        if (Ttoggled && curstate == Talptable) {
        !           517:                                TCursorToggle(TOGGLE);
        !           518:                                Ttoggled = FALSE;
        !           519:                        }
        !           520:                        if(QLength(screen->display))
        !           521:                                Tselect_mask = X_mask;
        !           522:                        else {
        !           523:                                XFlush(screen->display);
        !           524:                                Tselect_mask = Select_mask;
        !           525:                                if((i = select(max_plus1, &Tselect_mask,
        !           526:                                        (int *)NULL, (int *)NULL,
        !           527:                                        (struct timeval *)NULL)) < 0){
        !           528:                                        if (errno != EINTR)
        !           529:                                                SysError(ERROR_TSELECT);
        !           530:                                        continue;
        !           531:                                }
        !           532:                        }
        !           533:                        if(Tselect_mask & X_mask) {
        !           534:                                xevents();
        !           535:                                if(Tbcnt > 0)
        !           536:                                        goto again;
        !           537:                        }
        !           538:                }
        !           539:                Tbcnt--;
        !           540:                if (!Ttoggled && curstate == Talptable) {
        !           541:                        TCursorToggle(TOGGLE);
        !           542:                        Ttoggled = TRUE;
        !           543:                }
        !           544:        }
        !           545:        if((tek = TekRecord)->count >= TEK_LINK_BLOCK_SIZE) {
        !           546:                if((TekRecord = tek->next = (TekLink *)malloc(sizeof(TekLink)))
        !           547:                 == (TekLink *)0)
        !           548:                        Panic("Tinput: malloc error (%d)\n", errno);
        !           549:                tek = tek->next;
        !           550:                tek->next = (TekLink *)0;
        !           551:                tek->count = 0;
        !           552:                tek->ptr = tek->data;
        !           553:        }
        !           554:        tek->count++;
        !           555:        return(*tek->ptr++ = *Tbptr++);
        !           556: }
        !           557: 
        !           558: TekExpose(rep)
        !           559: register XExposeEvent *rep;
        !           560: {
        !           561:        register TScreen *screen = &term.screen;
        !           562:        register int border = 2 * screen->border;
        !           563:        register double d;
        !           564: 
        !           565:        if(rep) {
        !           566:                if (rep->width != (TWidth(screen) + border) || rep->height !=
        !           567:                 (THeight(screen) + border)) {
        !           568:                        XClearWindow(screen->display, TWindow(screen));
        !           569:                        TWidth(screen) = rep->width - border;
        !           570:                        THeight(screen) = rep->height - border;
        !           571:                        TekScale(screen) = (double)TWidth(screen) /
        !           572:                         (TEKWIDTH + TEKPAD);
        !           573:                        if((d = (double)THeight(screen) / (TEKHEIGHT +
        !           574:                         TEKTOPPAD + TEKBOTTOMPAD)) < TekScale(screen))
        !           575:                                TekScale(screen) = d;
        !           576:                        TFullWidth(screen) = rep->width;
        !           577:                        TFullHeight(screen) = rep->height;
        !           578: 
        !           579:                } else if(TFullHeight(screen) != rep->height)
        !           580:                        TFullHeight(screen) = rep->height;
        !           581:                else if(!Ttoggled)
        !           582:                        TCursorToggle(CLEAR);
        !           583:        }
        !           584:        Ttoggled = TRUE;
        !           585:        Tpushback = Tpushb;
        !           586:        screen->cur_X = 0;
        !           587:        screen->cur_Y = TEKHOME;
        !           588:        screen->cur = screen->page;
        !           589:        screen->margin = MARGIN1;
        !           590:        if(screen->TekGIN) {
        !           591:                screen->TekGIN = NULL;
        !           592:                TekGINoff();
        !           593:        }
        !           594:        TekRefresh = &Tek0;
        !           595:        rptr = TekRefresh->data;
        !           596:        rcnt = TekRefresh->count;
        !           597:        Tparsestate = curstate = Talptable;
        !           598:        if(!screen->waitrefresh)
        !           599:                dorefresh();
        !           600: }
        !           601: 
        !           602: dorefresh()
        !           603: {
        !           604:        register TScreen *screen = &term.screen;
        !           605:        register Cursor cur;
        !           606: 
        !           607:        XDefineCursor(screen->display, TWindow(screen), 
        !           608:         cur = make_wait(screen->mousecolor, screen->background));
        !           609:        XFlush(screen->display);
        !           610:        if(!setjmp(Tekjump))
        !           611:                Tekparse();
        !           612:        XDefineCursor(screen->display, TWindow(screen), 
        !           613:         (screen->TekGIN && GINcursor) ? GINcursor : screen->arrow);
        !           614:        XFreeCursor(screen->display, cur);
        !           615: }
        !           616: 
        !           617: TekPage()
        !           618: {
        !           619:        register TScreen *screen = &term.screen;
        !           620:        register TekLink *tek, *tek2;
        !           621: 
        !           622:        XClearWindow(screen->display, TWindow(screen));
        !           623:        screen->cur_X = 0;
        !           624:        screen->cur_Y = TEKHOME;
        !           625:        screen->margin = MARGIN1;
        !           626:        screen->page = screen->cur;
        !           627:        if(screen->TekGIN)
        !           628:                TekGINoff();
        !           629:        tek = TekRecord = &Tek0;
        !           630:        tek->count = 0;
        !           631:        tek->ptr = tek->data;
        !           632:        if(tek = tek->next)
        !           633:                do {
        !           634:                        tek2 = tek->next;
        !           635:                        free((char *)tek);
        !           636:                } while(tek = tek2);
        !           637:        TekRecord->next = (TekLink *)0;
        !           638:        TekRefresh = (TekLink *)0;
        !           639:        Ttoggled = TRUE;
        !           640:        Tparsestate = curstate = Talptable;     /* Tek Alpha mode */
        !           641: }
        !           642: 
        !           643: #define        EXTRABITS       017
        !           644: #define        FIVEBITS        037
        !           645: #define        HIBITS          (FIVEBITS << SHIFTHI)
        !           646: #define        LOBITS          (FIVEBITS << SHIFTLO)
        !           647: #define        SHIFTHI         7
        !           648: #define        SHIFTLO         2
        !           649: #define        TWOBITS         03
        !           650: 
        !           651: getpoint()
        !           652: {
        !           653:        register int c, x, y, e, lo_y = 0;
        !           654:        register TScreen *screen = &term.screen;
        !           655: 
        !           656:        x = screen->cur.x;
        !           657:        y = screen->cur.y;
        !           658:        for( ; ; ) {
        !           659:                if((c = input()) < ' ') {       /* control character */
        !           660:                        unput(c);
        !           661:                        return(0);
        !           662:                }
        !           663:                if(c < '@') {   /* Hi X or Hi Y */
        !           664:                        if(lo_y) {      /* seen a Lo Y, so this must be Hi X */
        !           665:                                x &= ~HIBITS;
        !           666:                                x |= (c & FIVEBITS) << SHIFTHI;
        !           667:                                continue;
        !           668:                        }
        !           669:                        /* else Hi Y */
        !           670:                        y &= ~HIBITS;
        !           671:                        y |= (c & FIVEBITS) << SHIFTHI;
        !           672:                        continue;
        !           673:                }
        !           674:                if(c < '`') {   /* Lo X */
        !           675:                        x &= ~LOBITS;
        !           676:                        x |= (c & FIVEBITS) << SHIFTLO;
        !           677:                        screen->cur.x = x;
        !           678:                        screen->cur.y = y;
        !           679:                        return(1);      /* OK */
        !           680:                }
        !           681:                /* else Lo Y */
        !           682:                if(lo_y) {      /* seen a Lo Y, so other must be extra bits */
        !           683:                        e = (y >> SHIFTLO) & EXTRABITS;
        !           684:                        x &= ~TWOBITS;
        !           685:                        x |= e & TWOBITS;
        !           686:                        y &= ~TWOBITS;
        !           687:                        y |= (e >> SHIFTLO) & TWOBITS;
        !           688:                }
        !           689:                y &= ~LOBITS;
        !           690:                y |= (c & FIVEBITS) << SHIFTLO;
        !           691:                lo_y++;
        !           692:        }
        !           693: }
        !           694: 
        !           695: TCursorBack()
        !           696: {
        !           697:        register TScreen *screen = &term.screen;
        !           698:        register struct Tek_Char *t;
        !           699:        register int x, l;
        !           700: 
        !           701:        x = ( screen->cur_X -=
        !           702:                (t = &TekChar[screen->cur.fontsize])->hsize
        !           703:            );
        !           704: 
        !           705:        if(screen->margin == MARGIN1 && x < 0 || screen->margin == MARGIN2
        !           706:         && x < TEKWIDTH / 2) {
        !           707:                if((l = (screen->cur_Y + (t->vsize - 1)) / t->vsize + 1) >=
        !           708:                 t->nlines) {
        !           709:                        screen->margin = !screen->margin;
        !           710:                        l = 0;
        !           711:                }
        !           712:                screen->cur_Y = l * t->vsize;
        !           713:                screen->cur_X = (t->charsperline - 1) * t->hsize;
        !           714:        }
        !           715: }
        !           716: 
        !           717: TCursorForward()
        !           718: {
        !           719:        register TScreen *screen = &term.screen;
        !           720:        register struct Tek_Char *t;
        !           721:        register int l;
        !           722: 
        !           723:        if( ( screen->cur_X +=
        !           724:                ( t = &TekChar[screen->cur.fontsize])->hsize
        !           725:            ) > TEKWIDTH
        !           726:          ) {
        !           727:                if((l = screen->cur_Y / t->vsize - 1) < 0) {
        !           728:                        screen->margin = !screen->margin;
        !           729:                        l = t->nlines - 1;
        !           730:                }
        !           731:                screen->cur_Y = l * t->vsize;
        !           732:                screen->cur_X = screen->margin == MARGIN1 ? 0 : TEKWIDTH / 2;
        !           733:        }
        !           734: }
        !           735: 
        !           736: TCursorUp()
        !           737: {
        !           738:        register TScreen *screen = &term.screen;
        !           739:        register struct Tek_Char *t;
        !           740:        register int l;
        !           741: 
        !           742:        t = &TekChar[screen->cur.fontsize];
        !           743: 
        !           744:        if((l = (screen->cur_Y + (t->vsize - 1)) / t->vsize + 1) >= t->nlines) {
        !           745:                l = 0;
        !           746:                if((screen->margin = !screen->margin) != MARGIN1) {
        !           747:                        if(screen->cur_X < TEKWIDTH / 2)
        !           748:                                screen->cur_X += TEKWIDTH / 2;
        !           749:                } else if(screen->cur_X >= TEKWIDTH / 2)
        !           750:                        screen->cur_X -= TEKWIDTH / 2;
        !           751:        }
        !           752:        screen->cur_Y = l * t->vsize;
        !           753: }
        !           754: 
        !           755: TCursorDown()
        !           756: {
        !           757:        register TScreen *screen = &term.screen;
        !           758:        register struct Tek_Char *t;
        !           759:        register int l;
        !           760: 
        !           761:        t = &TekChar[screen->cur.fontsize];
        !           762: 
        !           763:        if((l = screen->cur_Y / t->vsize - 1) < 0) {
        !           764:                l = t->nlines - 1;
        !           765:                if((screen->margin = !screen->margin) != MARGIN1) {
        !           766:                        if(screen->cur_X < TEKWIDTH / 2)
        !           767:                                screen->cur_X += TEKWIDTH / 2;
        !           768:                } else if(screen->cur_X >= TEKWIDTH / 2)
        !           769:                        screen->cur_X -= TEKWIDTH / 2;
        !           770:        }
        !           771:        screen->cur_Y = l * t->vsize;
        !           772: }
        !           773: 
        !           774: TekDraw (x, y)
        !           775: int x, y;
        !           776: {
        !           777:        register TScreen *screen = &term.screen;
        !           778: 
        !           779:        if(nplot == 0 || T_lastx != screen->cur_X || T_lasty != screen->cur_Y) {
        !           780:                /*
        !           781:                 * We flush on each unconnected line segment if the line
        !           782:                 * type is not solid.  This solves a bug in X when drawing
        !           783:                 * points while the line type is not solid.
        !           784:                 */
        !           785:                if(nplot > 0 && screen->cur.linetype != SOLIDLINE)
        !           786:                        TekFlush();
        !           787:        }
        !           788:        AddToDraw(screen->cur_X, screen->cur_Y, x, y);
        !           789:        T_lastx = screen->cur_X = x;
        !           790:        T_lasty = screen->cur_Y = y;
        !           791: }
        !           792: 
        !           793: AddToDraw(x1, y1, x2, y2)
        !           794: int x1, y1, x2, y2;
        !           795: {
        !           796:        register TScreen *screen = &term.screen;
        !           797:        register XSegment *lp;
        !           798: 
        !           799:        if(nplot >= MAX_PTS) {
        !           800:                TekFlush();
        !           801:        }
        !           802:        lp = line_pt++;
        !           803:        lp->x1 = x1 = x1 * TekScale(screen) + screen->border;
        !           804:        lp->y1 = y1 = (TEKHEIGHT + TEKTOPPAD - y1) * TekScale(screen) +
        !           805:         screen->border;
        !           806:        lp->x2 = x2 = x2 * TekScale(screen) + screen->border;
        !           807:        lp->y2 = y2 = (TEKHEIGHT + TEKTOPPAD - y2) * TekScale(screen) +
        !           808:         screen->border;
        !           809:        nplot++;
        !           810: }
        !           811: 
        !           812: TekFlush ()
        !           813: {
        !           814:        register TScreen *screen = &term.screen;
        !           815: 
        !           816:        XDrawSegments(screen->display, TWindow(screen), 
        !           817:                ((screen->cur.linetype == SOLIDLINE)?  screen->TnormalGC :
        !           818:                 screen->linepat[screen->cur.linetype - 1]),
        !           819:                 Tline, nplot);
        !           820:        nplot = 0;
        !           821:        line_pt = Tline;
        !           822: }
        !           823: 
        !           824: TekGINoff()
        !           825: {
        !           826:        register TScreen *screen = &term.screen;
        !           827:        
        !           828:        XDefineCursor(screen->display, TWindow(screen), screen->arrow);
        !           829:        if(GINcursor)
        !           830:                XFreeCursor(screen->display, GINcursor);
        !           831:        if(screen->TekGIN) {
        !           832:                *screen->TekGIN = CANCEL;       /* modify recording */
        !           833:                screen->TekGIN = NULL;
        !           834:        }
        !           835: }
        !           836: 
        !           837: TekEnqMouse(c)
        !           838: int c;
        !           839: {
        !           840:        register TScreen *screen = &term.screen;
        !           841:        int mousex, mousey, winx, winy;
        !           842:        unsigned int mask; /* XQueryPointer */
        !           843:        Window root, subw;
        !           844: 
        !           845:        XQueryPointer(
        !           846:            screen->display, TWindow(screen), 
        !           847:            &root, &subw,
        !           848:            &mousex, &mousey,
        !           849:            &winx, &winy,
        !           850:            &mask);
        !           851:        if((mousex = (mousex - screen->border) / TekScale(screen)) < 0)
        !           852:                mousex = 0;
        !           853:        else if(mousex >= TEKWIDTH)
        !           854:                mousex = TEKWIDTH - 1;
        !           855:        if((mousey = TEKHEIGHT + TEKTOPPAD - (mousey - screen->border) /
        !           856:             TekScale(screen)) < 0)
        !           857:                mousey = 0;
        !           858:        else if(mousey >= TEKHEIGHT)
        !           859:                mousey = TEKHEIGHT - 1;
        !           860:        TekEnq(c, mousex, mousey);
        !           861: }
        !           862: 
        !           863: TekEnq (status, x, y)
        !           864: int status;
        !           865: register int x, y;
        !           866: {
        !           867:        register TScreen *screen = &term.screen;
        !           868:        int pty = screen->respond;
        !           869:        char cplot [5];
        !           870: 
        !           871:        /* Translate x and y to Tektronix code */
        !           872:        cplot[1] = 040 | ((x >> SHIFTHI) & FIVEBITS);
        !           873:        cplot[2] = 040 | ((x >> SHIFTLO) & FIVEBITS);
        !           874:        cplot[3] = 040 | ((y >> SHIFTHI) & FIVEBITS);
        !           875:        cplot[4] = 040 | ((y >> SHIFTLO) & FIVEBITS);
        !           876:        if(cplot[0] = status)
        !           877:                write (pty, cplot, 5);
        !           878:        else
        !           879:                write (pty, &cplot[1], 4);
        !           880: }
        !           881: 
        !           882: TekRun()
        !           883: {
        !           884:        register TScreen *screen = &term.screen;
        !           885:        register int i;
        !           886:        
        !           887:        if(!TWindow(screen) && !TekInit()) {
        !           888:                if(VWindow(screen)) {
        !           889:                        screen->TekEmu = FALSE;
        !           890:                        return;
        !           891:                }
        !           892:                Exit(ERROR_TINIT);
        !           893:        }
        !           894:        if(!screen->Tshow) {
        !           895:                screen->Tshow = TRUE;
        !           896:                XMapRaised(screen->display, TWindow(screen));
        !           897:        } else
        !           898:                XRaiseWindow(screen->display, TWindow(screen));
        !           899:        if(screen->select)
        !           900:                TekSelect();
        !           901:        if (L_flag > 0) {
        !           902:                XWarpPointer (screen->display, None, TWindow(screen),
        !           903:                            0, 0, 0, 0,
        !           904:                            TFullWidth(screen) >> 1, TFullHeight(screen) >> 1);
        !           905:                L_flag = -1;
        !           906:        }
        !           907:        Tpushback = Tpushb;
        !           908:        Tbptr = Tbuffer;
        !           909:        for(i = Tbcnt = bcnt ; i > 0 ; i--)
        !           910:                *Tbptr++ = *bptr++;
        !           911:        Tbptr = Tbuffer;
        !           912:        Ttoggled = TRUE;
        !           913:        if(!setjmp(Tekend))
        !           914:                Tekparse();
        !           915:        if(!Ttoggled) {
        !           916:                TCursorToggle(TOGGLE);
        !           917:                Ttoggled = TRUE;
        !           918:        }
        !           919:        screen->TekEmu = FALSE;
        !           920:        TekUnselect();
        !           921: }
        !           922: 
        !           923: #define DOTTED_LENGTH 2
        !           924: #define DOT_DASHED_LENGTH 4
        !           925: #define SHORT_DASHED_LENGTH 2
        !           926: #define LONG_DASHED_LENGTH 2
        !           927: 
        !           928: static int dash_length[TEKNUMLINES] = {
        !           929:        DOTTED_LENGTH,
        !           930:        DOT_DASHED_LENGTH,
        !           931:        SHORT_DASHED_LENGTH,
        !           932:        LONG_DASHED_LENGTH,
        !           933: };
        !           934: 
        !           935: static unsigned char dotted[DOTTED_LENGTH] = {3, 1};
        !           936: static unsigned char dot_dashed[DOT_DASHED_LENGTH] = {3, 4, 3, 1};
        !           937: static unsigned char short_dashed[SHORT_DASHED_LENGTH] = {4, 4};
        !           938: static unsigned char long_dashed[LONG_DASHED_LENGTH] = {4, 7};
        !           939: 
        !           940: static unsigned char *dashes[TEKNUMLINES] = {
        !           941:        dotted,
        !           942:        dot_dashed,
        !           943:        short_dashed,
        !           944:        long_dashed,
        !           945: };
        !           946: 
        !           947: 
        !           948: 
        !           949: /*ARGSUSED*/
        !           950: XtEventReturnCode TekExposeWindow(event, eventdata)
        !           951: register XEvent *event;
        !           952: caddr_t eventdata;
        !           953: {
        !           954:        register TScreen *screen = &term.screen;
        !           955: #ifdef DEBUG
        !           956:        if(debug)
        !           957:                fputs("ExposeWindow Tek\n", stderr);
        !           958: #endif DEBUG
        !           959:        if(!screen->Tshow) {
        !           960:                screen->Tshow = TRUE;
        !           961:                reselectwindow(screen);
        !           962:        }
        !           963:        TekExpose((XExposeEvent *) event);
        !           964: 
        !           965:        return (XteventHandled);
        !           966: }
        !           967: 
        !           968: /*ARGSUSED*/
        !           969: XtEventReturnCode TekUnmapWindow(event, eventdata)
        !           970: XEvent *event;
        !           971: caddr_t eventdata;
        !           972: {
        !           973:        register TScreen *screen = &term.screen;
        !           974: 
        !           975:        if (event->type != UnmapNotify) return(XteventNotHandled);
        !           976: 
        !           977: #ifdef DEBUG
        !           978:        if(debug)
        !           979:                fputs("UnmapWindow Tek\n", stderr);
        !           980: #endif DEBUG
        !           981:        screen->Tshow = FALSE;
        !           982: /*     if(screen->show) {
        !           983:                screen->show = FALSE;
        !           984:                XUnmapWindow(screen->display, screen->fullVwin.window );
        !           985:                SyncUnmap( screen->fullVwin.window, WINDOWEVENTS );
        !           986:        }
        !           987: */
        !           988:        reselectwindow(screen);
        !           989:        return (XteventHandled);
        !           990: }
        !           991: 
        !           992: 
        !           993: TekInit()
        !           994: {
        !           995:        register TScreen *screen = &term.screen;
        !           996:        register int i;
        !           997:        register TekLink *tek;
        !           998:        register double d;
        !           999:        register int border = 2 * screen->border;
        !          1000:        XColor cdef;
        !          1001:        int pixels[2];
        !          1002:        static short Tfailed;
        !          1003:        int x, y, rootx, rooty, pr;
        !          1004:        Window win, root;
        !          1005:        unsigned int mask; /* XQueryPointer */
        !          1006:        XGCValues gcv;
        !          1007:        int winX, winY, width, height;
        !          1008:        XSizeHints sizehints;
        !          1009:        XSetWindowAttributes attr;
        !          1010:        char Tdefault[32];
        !          1011:        extern char *malloc();
        !          1012: 
        !          1013:        if(Tfailed)
        !          1014:                return(0);
        !          1015:        if (!(screen->Tfont[SMALLFONT] = XLoadQueryFont(screen->display, SMALLFONTNAME))) {
        !          1016:            fprintf(stderr, "%s: Could not get font %s; using server default\n",
        !          1017:                    xterm_name, SMALLFONTNAME);
        !          1018:            screen->Tfont[SMALLFONT] =
        !          1019:              XQueryFont(screen->display,
        !          1020:                         DefaultGC(screen->display,
        !          1021:                                   DefaultScreen(screen->display)
        !          1022:                                   )->gid
        !          1023:                         );
        !          1024:            TEKgcFontMask = 0;
        !          1025:        }
        !          1026:        if((Tbuffer = (char *)malloc(BUF_SIZE)) == NULL ||
        !          1027:         (Tpushb = (char *)malloc(10)) == NULL ||
        !          1028:         (Tline = (XSegment *)malloc(MAX_VTX * sizeof(XSegment))) == NULL) {
        !          1029:                fprintf(stderr, "%s: Not enough core for Tek mode\n",
        !          1030:                 xterm_name);
        !          1031:                goto mallocfailed;
        !          1032:        }
        !          1033: 
        !          1034:        screen->xorplane = 1;
        !          1035:        screen->Tbackground = XtDefaultBGPixel;
        !          1036:        screen->Tforeground = XtDefaultFGPixel;
        !          1037:        screen->Tcursorcolor = XtDefaultFGPixel;
        !          1038: 
        !          1039:        if (DisplayCells(screen->display, DefaultScreen(screen->display)) > 2
        !          1040:            && (fore_color || back_color || curs_color)) {
        !          1041:                if (curs_color &&
        !          1042:                    XParseColor(screen->display, TekColormap, curs_color, &cdef)) {
        !          1043:                        if(XAllocColorCells(
        !          1044:                            screen->display,
        !          1045:                            TekColormap,
        !          1046:                            0, 
        !          1047:                            &screen->xorplane, 1,
        !          1048:                            pixels, 2)) {
        !          1049:                                screen->cellsused = TRUE;
        !          1050:                                screen->colorcells[2] = cdef;
        !          1051:                                screen->Tbackground = pixels[0];
        !          1052:                                screen->Tforeground = pixels[1];
        !          1053: 
        !          1054:                                screen->Tcursorcolor = screen->Tbackground |
        !          1055:                                 screen->xorplane;
        !          1056:                                screen->Tcolor |= C_CURSOR;
        !          1057:                                screen->planeused = TRUE;
        !          1058:                        }
        !          1059:                } else if (XAllocColorCells(
        !          1060:                    screen->display,
        !          1061:                    TekColormap, 0, 
        !          1062:                    &screen->xorplane, 1, &screen->Tbackground, 1)) {
        !          1063:                        screen->Tforeground = screen->Tbackground |
        !          1064:                         screen->xorplane;
        !          1065:                        screen->Tcursorcolor = screen->Tforeground;
        !          1066:                        screen->planeused = TRUE;
        !          1067:                }
        !          1068:                if (screen->Tbackground != XtDefaultBGPixel) {
        !          1069:                        if (back_color == NULL ||
        !          1070:                                !XParseColor(screen->display,
        !          1071:                                 TekColormap,
        !          1072:                                 back_color, &cdef)) {
        !          1073:                                cdef.pixel = XtDefaultBGPixel;
        !          1074:                                XQueryColor(screen->display, TekColormap, &cdef);
        !          1075:                                screen->Tcolor |= C_BACKGROUND;
        !          1076:                        }
        !          1077:                        cdef.pixel = screen->Tbackground;
        !          1078:                        XStoreColor(screen->display, TekColormap, &cdef);
        !          1079:                        if(screen->cellsused) {
        !          1080:                                screen->colorcells[0] = cdef;
        !          1081:                                cdef.pixel = screen->Tforeground |
        !          1082:                                        screen->xorplane;
        !          1083:                                XStoreColor(screen->display, TekColormap,&cdef);
        !          1084:                        }
        !          1085:                        if (fore_color == NULL ||
        !          1086:                                !XParseColor(screen->display,
        !          1087:                                 TekColormap,
        !          1088:                                 fore_color, &cdef)) {
        !          1089:                                cdef.pixel = XtDefaultFGPixel;
        !          1090:                                XQueryColor(screen->display, TekColormap, &cdef);
        !          1091:                                screen->Tcolor |= C_FOREGROUND;
        !          1092:                        }
        !          1093:                        cdef.pixel = screen->Tforeground;
        !          1094:                        XStoreColor(screen->display, TekColormap, &cdef);
        !          1095:                        if(screen->cellsused) {
        !          1096:                                screen->colorcells[1] = cdef;
        !          1097:                                cdef.pixel = screen->Tcursorcolor;
        !          1098:                                XStoreColor(screen->display, TekColormap, &cdef);
        !          1099:                        }
        !          1100:                }
        !          1101:        }
        !          1102:        
        !          1103:        if (T_geometry == NULL) {
        !          1104:          sprintf(Tdefault, "=%dx%d",
        !          1105:            TEKDEFWIDTH + border, TEKDEFHEIGHT + border);
        !          1106:          T_geometry = Tdefault;
        !          1107:        }
        !          1108: 
        !          1109:        winX = 1;
        !          1110:        winY = 1;
        !          1111:        width = TEKDEFWIDTH + border;
        !          1112:        height = TEKDEFHEIGHT + border;
        !          1113:        
        !          1114:        pr = XParseGeometry(T_geometry, &winX, &winY, &width, &height);
        !          1115:          if ((pr & XValue) && (XNegative&pr))
        !          1116:           winX += DisplayWidth(screen->display, DefaultScreen(screen->display))                        - width;
        !          1117:         if ((pr & YValue) && (YNegative&pr))
        !          1118:           winY += DisplayHeight(screen->display, DefaultScreen(screen->display))                        - height;
        !          1119:   
        !          1120:        /* set up size hints */
        !          1121:        sizehints.min_width = TEKMINWIDTH + border;
        !          1122:        sizehints.min_height = TEKMINHEIGHT + border;
        !          1123:        sizehints.width_inc = 1;
        !          1124:        sizehints.height_inc = 1;
        !          1125:        sizehints.flags = PMinSize|PResizeInc;
        !          1126:         if ((XValue&pr) && (YValue&pr))
        !          1127:           sizehints.flags |= USPosition;
        !          1128:         else sizehints.flags |= PPosition;
        !          1129:         sizehints.width = width;
        !          1130:         sizehints.height = height;
        !          1131:         if ((WidthValue&pr) && (HeightValue&pr))
        !          1132:           sizehints.flags |= USSize;
        !          1133:         else sizehints.flags |= PSize;
        !          1134: 
        !          1135:        attr.border_pixmap = screen->graybordertile;
        !          1136:        attr.win_gravity = NorthWestGravity;
        !          1137:        attr.background_pixel = screen->Tbackground;
        !          1138:        if((TWindow(screen) = XCreateWindow(
        !          1139:            screen->display,
        !          1140:            DefaultRootWindow(screen->display), 
        !          1141:            winX, winY, width, height, screen->borderwidth,
        !          1142:            DefaultDepth(screen->display, DefaultScreen(screen->display)),
        !          1143:            CopyFromParent, CopyFromParent,
        !          1144:            CWBorderPixmap|CWBackPixel|CWWinGravity, &attr)) == NULL) {
        !          1145:                fprintf(stderr, "%s: Can't create Tek window\n", xterm_name);
        !          1146:                free((char *)Tline);
        !          1147: mallocfailed:
        !          1148:                if(Tpushb)
        !          1149:                        free((char *)Tpushb);
        !          1150:                if(Tbuffer)
        !          1151:                        free((char *)Tbuffer);
        !          1152:                XFreeFont(screen->display, screen->Tfont[SMALLFONT]);
        !          1153: fontfailed:
        !          1154:                Tfailed = TRUE;
        !          1155:                return(FALSE);
        !          1156:        }
        !          1157:         /* crock to make configure notifies get through */
        !          1158:         XtMakeMaster(screen->display, TWindow(screen));
        !          1159: 
        !          1160:        XSetNormalHints (screen->display, TWindow(screen), &sizehints);
        !          1161: 
        !          1162:        XtSetEventHandler(screen->display, TWindow(screen), 
        !          1163:         (XtEventHandler) HandleEnterWindow, EnterWindowMask, (caddr_t)NULL);
        !          1164:        XtSetEventHandler(screen->display, TWindow(screen), 
        !          1165:         (XtEventHandler) HandleLeaveWindow, LeaveWindowMask, (caddr_t)NULL);
        !          1166:        XtSetEventHandler(screen->display, TWindow(screen), 
        !          1167:         (XtEventHandler) HandleFocusChange, FocusChangeMask, (caddr_t)NULL);
        !          1168:        XtSetEventHandler(screen->display, TWindow(screen), 
        !          1169:         (XtEventHandler) TekButtonPressed, ButtonPressMask, (caddr_t)NULL);
        !          1170:        XtSetEventHandler(screen->display, TWindow(screen), 
        !          1171:         (XtEventHandler) EventDoNothing, ButtonReleaseMask, (caddr_t)NULL);
        !          1172:        XtSetEventHandler(screen->display, TWindow(screen), 
        !          1173:         (XtEventHandler) TekExposeWindow, ExposureMask, (caddr_t)NULL);
        !          1174:        XtSetEventHandler(screen->display, TWindow(screen), 
        !          1175:         (XtEventHandler) TekUnmapWindow, StructureNotifyMask, (caddr_t)NULL);
        !          1176:        XtSetEventHandler(screen->display, TWindow(screen), 
        !          1177:         (XtEventHandler) HandleKeyPressed, KeyPressMask, (caddr_t)NULL);
        !          1178: 
        !          1179:        screen->Tbox = T_box;
        !          1180: 
        !          1181:        TFullWidth(screen) = width;
        !          1182:        TFullHeight(screen) = height;
        !          1183:        TWidth(screen) = width - border;
        !          1184:        THeight(screen) = height - border;
        !          1185:        TekScale(screen) = (double)TWidth(screen)
        !          1186:                                    / (TEKWIDTH + TEKPAD);
        !          1187:        if((d = (double)THeight(screen) / (TEKHEIGHT + TEKTOPPAD +
        !          1188:         TEKBOTTOMPAD)) < TekScale(screen))
        !          1189:                TekScale(screen) = d;
        !          1190: 
        !          1191: 
        !          1192:        screen->tobaseline[SMALLFONT] = screen->Tfont[SMALLFONT]->ascent;
        !          1193: 
        !          1194:        if (!(screen->Tfont[THREEFONT] = XLoadQueryFont(screen->display, THREEFONTNAME)))
        !          1195:                screen->Tfont[THREEFONT] = screen->Tfont[SMALLFONT];
        !          1196:        screen->tobaseline[THREEFONT] = screen->Tfont[THREEFONT]->ascent;
        !          1197: 
        !          1198:        if (!(screen->Tfont[TWOFONT] = XLoadQueryFont(screen->display, TWOFONTNAME)))
        !          1199:                screen->Tfont[TWOFONT] = screen->Tfont[THREEFONT];
        !          1200:        screen->tobaseline[TWOFONT] = screen->Tfont[TWOFONT]->ascent;
        !          1201: 
        !          1202:        if (!(screen->Tfont[LARGEFONT] = XLoadQueryFont(screen->display, LARGEFONTNAME)))
        !          1203:                screen->Tfont[LARGEFONT] = screen->Tfont[TWOFONT];
        !          1204:        screen->tobaseline[LARGEFONT] = screen->Tfont[LARGEFONT]->ascent;
        !          1205: 
        !          1206:        gcv.graphics_exposures = TRUE;  /* default */
        !          1207:        gcv.font = screen->Tfont[screen->cur.fontsize]->fid;
        !          1208:        gcv.foreground = screen->Tforeground;
        !          1209:        gcv.background = screen->Tbackground;
        !          1210:        screen->TnormalGC = XCreateGC(
        !          1211:            screen->display, TWindow(screen), 
        !          1212:            TEKgcFontMask+GCGraphicsExposures+GCForeground+GCBackground, &gcv);
        !          1213: 
        !          1214:        gcv.foreground = screen->Tcursorcolor;
        !          1215:        gcv.background = screen->Tbackground;
        !          1216:        gcv.function = GXinvert;
        !          1217:        gcv.plane_mask = screen->xorplane;
        !          1218:        screen->TcursorGC = XCreateGC(screen->display, TWindow(screen), 
        !          1219:         GCFunction+GCPlaneMask+GCForeground+GCBackground , &gcv);
        !          1220: 
        !          1221:        if(term.flags & REVERSE_VIDEO) {
        !          1222:                TekReverseVideo(screen);
        !          1223:        } else
        !          1224:                TekBackground(screen);
        !          1225: 
        !          1226:        gcv.foreground = screen->Tforeground;
        !          1227:        gcv.line_style = LineOnOffDash;
        !          1228:        for(i = 0 ; i < TEKNUMLINES ; i++) {
        !          1229:                screen->linepat[i] = XCreateGC(
        !          1230:                    screen->display, TWindow(screen),
        !          1231:                    GCForeground+GCLineStyle, &gcv); 
        !          1232:                XSetDashes(screen->display, screen->linepat[i], 0,
        !          1233:                 dashes[i], dash_length[i]);
        !          1234:        }
        !          1235:        screen->margin = MARGIN1;               /* Margin 1             */
        !          1236:        screen->cur.fontsize = LARGEFONT;       /* set large font       */
        !          1237:        screen->TekGIN = FALSE;                 /* GIN off              */
        !          1238: 
        !          1239: 
        !          1240:        XDefineCursor(screen->display, TWindow(screen), screen->curs );
        !          1241:        if((screen->Ticonname = malloc((unsigned) screen->iconnamelen + 7)) == NULL)
        !          1242:                Error(ERROR_TWINNAME);
        !          1243:        strcpy(screen->Ticonname, screen->iconname);
        !          1244:        strcat(screen->Ticonname, "(Tek) ");
        !          1245:        screen->Ticonnamelen = strlen(screen->Ticonname);
        !          1246:        if((screen->Ttitlename = malloc((unsigned) screen->titlenamelen + 7)) == NULL)
        !          1247:                Error(ERROR_TWINNAME);
        !          1248:        strcpy(screen->Ttitlename, screen->titlename);
        !          1249:        strcat(screen->Ttitlename, "(Tek) ");
        !          1250:        screen->Ttitlenamelen = strlen(screen->Ttitlename);
        !          1251:        XStoreName (screen->display, TWindow(screen), screen->Ttitlename);
        !          1252:        XChangeProperty(screen->display, TWindow(screen), XA_WM_ICON_NAME,
        !          1253:          XA_STRING, 8, PropModeReplace, (unsigned char *)screen->Ticonname,
        !          1254:          screen->Ticonnamelen);
        !          1255: 
        !          1256: 
        !          1257:        tek = TekRecord = &Tek0;
        !          1258:        tek->next = (TekLink *)0;
        !          1259:        tek->count = 0;
        !          1260:        tek->ptr = tek->data;
        !          1261:        Tpushback = Tpushb;
        !          1262:        screen->cur_X = 0;
        !          1263:        screen->cur_Y = TEKHOME;
        !          1264:        line_pt = Tline;
        !          1265:        Ttoggled = TRUE;
        !          1266:        return(TRUE);
        !          1267: }
        !          1268: 
        !          1269: TekReverseVideo(screen)
        !          1270: register TScreen *screen;
        !          1271: {
        !          1272:        register int flag, i;
        !          1273:        XGCValues gcv;
        !          1274:         
        !          1275: 
        !          1276:        i = screen->Tbackground;
        !          1277:        screen->Tbackground = screen->Tforeground;
        !          1278:        screen->Tforeground = i;
        !          1279:        screen->Tcolor = (screen->Tcolor & ~C_FBMASK) | switchfb[screen->Tcolor
        !          1280:         & C_FBMASK];
        !          1281:        
        !          1282:        XSetForeground(screen->display, screen->TnormalGC, 
        !          1283:         screen->Tforeground);
        !          1284:        XSetBackground(screen->display, screen->TnormalGC, 
        !          1285:         screen->Tbackground);
        !          1286: 
        !          1287:        for(i = 0 ; i < TEKNUMLINES ; i++) {
        !          1288:                XSetForeground(screen->display, screen->linepat[i], 
        !          1289:                 screen->Tforeground);
        !          1290:        }
        !          1291: 
        !          1292:        if(screen->cellsused) {
        !          1293:                flag = (term.flags & REVERSE_VIDEO) != 0;
        !          1294:                screen->Tcursorcolor = screen->Tbackground | screen->xorplane;
        !          1295:                i = screen->select ? 2 : !flag;
        !          1296:                screen->colorcells[i].pixel = screen->Tcursorcolor;
        !          1297:                XStoreColor(screen->display, TekColormap, &screen->colorcells[i]);
        !          1298:                screen->colorcells[flag].pixel = screen->Tforeground |
        !          1299:                 screen->xorplane;
        !          1300:                XStoreColor(screen->display, TekColormap, &screen->colorcells[flag]);
        !          1301:        } else
        !          1302:                screen->Tcursorcolor = screen->Tforeground;
        !          1303: 
        !          1304:        gcv.foreground = screen->Tcursorcolor;
        !          1305:        gcv.background = screen->Tbackground;
        !          1306:        XChangeGC(screen->display, screen->TcursorGC, 
        !          1307:          GCForeground+GCBackground, &gcv);
        !          1308: 
        !          1309:        TekBackground(screen);
        !          1310: }
        !          1311: 
        !          1312: TekBackground(screen)
        !          1313: register TScreen *screen;
        !          1314: {
        !          1315:        if(TWindow(screen))
        !          1316:                XSetWindowBackground(screen->display, TWindow(screen), 
        !          1317:                 screen->Tbackground);
        !          1318: }
        !          1319: 
        !          1320: /*
        !          1321:  * Toggles cursor on or off at cursor position in screen.
        !          1322:  */
        !          1323: TCursorToggle(toggle)
        !          1324: int toggle;
        !          1325: {
        !          1326:        register TScreen *screen = &term.screen;
        !          1327:        register int c, x, y;
        !          1328:        register T_fontsize *Tf;
        !          1329: 
        !          1330:        c = screen->cur.fontsize;
        !          1331:        Tf = &Tfontsize[c];
        !          1332: 
        !          1333:        x = (screen->cur_X * TekScale(screen)) + screen->border;
        !          1334:        y = ((TEKHEIGHT + TEKTOPPAD - screen->cur_Y) * TekScale(screen)) +
        !          1335:         screen->border + screen->tobaseline[c] - 2*(unsigned) Tf->Theight;
        !          1336:        if (toggle) {
        !          1337:           if (screen->select) 
        !          1338:                XFillRectangle(
        !          1339:                    screen->display, TWindow(screen), screen->TcursorGC,
        !          1340:                    x, y,
        !          1341:                    (unsigned) Tf->Twidth, (unsigned) Tf->Theight);
        !          1342:          else { /* fix to use different GC! */
        !          1343:                  screen->Tbox[c]->x = x;
        !          1344:                  screen->Tbox[c]->y = y ;
        !          1345:                  XDrawLines(screen->display, TWindow(screen), 
        !          1346:                    screen->TcursorGC,
        !          1347:                    screen->Tbox[c], NBOX, CoordModePrevious);
        !          1348:           }
        !          1349:        } else {
        !          1350:           if (screen->select) 
        !          1351:                XClearArea(screen->display, TWindow(screen), x, y,
        !          1352:                    (unsigned) Tf->Twidth, (unsigned) Tf->Theight, FALSE);
        !          1353:           else { 
        !          1354:                  screen->Tbox[c]->x = x;
        !          1355:                  screen->Tbox[c]->y = y ;
        !          1356:                  XDrawLines(screen->display, TWindow(screen), 
        !          1357:                    screen->TcursorGC,
        !          1358:                    screen->Tbox[c], NBOX, CoordModePrevious);
        !          1359:           }
        !          1360:        }
        !          1361: }
        !          1362: 
        !          1363: TekSelect()
        !          1364: {
        !          1365:        register TScreen *screen = &term.screen;
        !          1366: 
        !          1367:        XSetWindowBorder(screen->display, TWindow(screen), screen->bordercolor);
        !          1368: }
        !          1369: 
        !          1370: TekUnselect()
        !          1371: {
        !          1372:        register TScreen *screen = &term.screen;
        !          1373: 
        !          1374:        XSetWindowBorderPixmap(screen->display, TWindow(screen), screen->graybordertile);
        !          1375: }
        !          1376: 
        !          1377: TekCopy()
        !          1378: {
        !          1379:        register TekLink *Tp;
        !          1380:        register int fd;
        !          1381:        register TScreen *screen = &term.screen;
        !          1382:        register struct tm *tp;
        !          1383:        long l;
        !          1384:        char buf[32];
        !          1385: 
        !          1386:        /* for login windows, check that a user has logged in */
        !          1387:        if(L_flag && !checklogin()) {
        !          1388:                Bell();
        !          1389:                return;
        !          1390:        }
        !          1391:        time(&l);
        !          1392:        tp = localtime(&l);
        !          1393:        sprintf(buf, "COPY%02d-%02d-%02d.%02d:%02d:%02d", tp->tm_year,
        !          1394:         tp->tm_mon, tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec);
        !          1395:        if(access(buf, F_OK) >= 0) {    /* file exists */
        !          1396:                if(access(buf, W_OK) < 0) {
        !          1397:                        Bell();
        !          1398:                        return;
        !          1399:                }
        !          1400:        } else if(access(".", W_OK) < 0) {      /* can't write in directory */
        !          1401:                Bell();
        !          1402:                return;
        !          1403:        }
        !          1404:        if((fd = open(buf, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) {
        !          1405:                Bell();
        !          1406:                return;
        !          1407:        }
        !          1408:        chown(buf, screen->uid, screen->gid);
        !          1409:        sprintf(buf, "\033%c\033%c", screen->page.fontsize + '8',
        !          1410:         screen->page.linetype + '`');
        !          1411:        write(fd, buf, 4);
        !          1412:        Tp = &Tek0; 
        !          1413:        do
        !          1414:                write(fd, (char *)Tp->data, Tp->count);
        !          1415:        while(Tp = Tp->next);
        !          1416:        close(fd);
        !          1417: }
        !          1418: 
        !          1419: #ifdef MODEMENU
        !          1420: /*
        !          1421:  * TMENU_LARGE through TMENU_SMALL must be first, as they must be the same
        !          1422:  * as the font size values LARGEFONT through SMALLFONT
        !          1423:  */
        !          1424: #define        TMENU_LARGE     0
        !          1425: #define        TMENU_NUM2      (TMENU_LARGE+1)
        !          1426: #define        TMENU_NUM3      (TMENU_NUM2+1)
        !          1427: #define        TMENU_SMALL     (TMENU_NUM3+1)
        !          1428: #define        TMENU_VTWIN     (TMENU_SMALL+1)
        !          1429: #define        TMENU_LINE      (TMENU_VTWIN+1)
        !          1430: #define        TMENU_PAGE      (TMENU_LINE+1)
        !          1431: #define        TMENU_RESET     (TMENU_PAGE+1)
        !          1432: #define        TMENU_COPY      (TMENU_RESET+1)
        !          1433: #define        TMENU_VTMODE    (TMENU_COPY+1)
        !          1434: #define        TMENU_HIDETEK   (TMENU_VTMODE+1)
        !          1435: 
        !          1436: static char *Ttext[] = {
        !          1437:        "Large Characters",
        !          1438:        "#2 Size Characters",
        !          1439:        "#3 Size Characters",
        !          1440:        "Small Characters",
        !          1441:        "VT Window Showing",
        !          1442:        "-",
        !          1443:        "PAGE",
        !          1444:        "RESET",
        !          1445:        "COPY",
        !          1446:        "Select VT Mode",
        !          1447:        "Hide Tek Window",
        !          1448:        0,
        !          1449: };
        !          1450: 
        !          1451: static Tmodes curmodes;
        !          1452: static int Tsize;
        !          1453: 
        !          1454: Menu *Tsetupmenu(menu)
        !          1455: register Menu **menu;
        !          1456: {
        !          1457:        register TScreen *screen = &term.screen;
        !          1458:        register char **cp;
        !          1459:        register int size = screen->cur.fontsize;
        !          1460:        register int kflags = term.keyboard.flags;
        !          1461: 
        !          1462:        curmodes = screen->cur;
        !          1463:        if (*menu == NULL) {
        !          1464:                if ((*menu = NewMenu("Tektronix", re_verse)) == NULL)
        !          1465:                        return(NULL);
        !          1466:                for(cp = Ttext ; *cp ; cp++)
        !          1467:                        AddMenuItem(*menu, *cp);
        !          1468:                CheckItem(*menu, size);
        !          1469: /*             if(vshow = screen->show)
        !          1470:                        CheckItem(*menu, TMENU_VTWIN);
        !          1471:                else
        !          1472:                        DisableItem(*menu, TMENU_HIDETEK);
        !          1473: */
        !          1474:                DisableItem(*menu, TMENU_LINE);
        !          1475:                Tsize = size;
        !          1476:                return(*menu);
        !          1477:        }
        !          1478:        if (Tsize != size) {
        !          1479:                UncheckItem(*menu, Tsize);
        !          1480:                CheckItem(*menu, Tsize = size);
        !          1481:        }
        !          1482: /*     if(vshow != screen->show) {
        !          1483:                SetItemCheck(*menu, TMENU_VTWIN, (vshow = screen->show));
        !          1484:                SetItemDisable(*menu, TMENU_HIDETEK, !vshow);
        !          1485:        }
        !          1486: */
        !          1487:        return(*menu);
        !          1488: }
        !          1489: 
        !          1490: static char *changesize[] = {
        !          1491:        "\0338",
        !          1492:        "\0339",
        !          1493:        "\033:",
        !          1494:        "\033;",
        !          1495: };
        !          1496: 
        !          1497: Tdomenufunc(item)
        !          1498: int item;
        !          1499: {
        !          1500:        register TScreen *screen = &term.screen;
        !          1501:        register char *tp;
        !          1502:        register char *fp;
        !          1503:        Window win;
        !          1504:        int x, y;
        !          1505: 
        !          1506:        switch (item) {
        !          1507:        case TMENU_LARGE:
        !          1508:        case TMENU_NUM2:
        !          1509:        case TMENU_NUM3:
        !          1510:        case TMENU_SMALL:
        !          1511:                if(!Ttoggled) {
        !          1512:                        TCursorToggle(TOGGLE);
        !          1513:                        Ttoggled = TRUE;
        !          1514:                }
        !          1515:                if(Tbcnt < 0)
        !          1516:                        Tbcnt = 0;
        !          1517:                for(fp = changesize[item], tp = &Tbptr[Tbcnt] ; *fp ; ) {
        !          1518:                        *tp++ = *fp++;
        !          1519:                        Tbcnt++;
        !          1520:                }
        !          1521:                break;
        !          1522: 
        !          1523:        case TMENU_RESET:
        !          1524:                bzero((char *)&curmodes, sizeof(Tmodes));
        !          1525:                        /* drop through */
        !          1526:        case TMENU_PAGE:
        !          1527:                TekRefresh = (TekLink *)0;
        !          1528:                screen->cur = curmodes;
        !          1529:                TekPage();
        !          1530:                screen->cur_X = 0;
        !          1531:                screen->cur_Y = TEKHOME;
        !          1532:                break;
        !          1533: 
        !          1534:        case TMENU_COPY:
        !          1535:                TekCopy();
        !          1536:                break;
        !          1537: 
        !          1538:        case TMENU_HIDETEK:
        !          1539:                screen->Tshow = FALSE;
        !          1540:                XUnmapWindow(screen->display, TWindow(screen));
        !          1541:                SyncUnmap(TWindow(screen), TWINDOWEVENTS);
        !          1542:                reselectwindow(screen);
        !          1543:                TekRefresh = (TekLink *)0;
        !          1544:                        /* drop through */
        !          1545:        case TMENU_VTMODE:
        !          1546:                if(TekRefresh)
        !          1547:                        dorefresh();
        !          1548:                if(screen->TekEmu) {
        !          1549:                        if(screen->logging) {
        !          1550:                                FlushLog(screen);
        !          1551:                                screen->logstart = buffer;
        !          1552:                        }
        !          1553:                        longjmp(Tekend, 1);
        !          1554:                } else
        !          1555:                        XRaiseWindow(screen->display, VWindow(screen));
        !          1556:                break;
        !          1557: 
        !          1558:        case TMENU_VTWIN:
        !          1559: /*             if(screen->show = !screen->show) {
        !          1560:                        if(VWindow(screen) || VTInit()) {
        !          1561:                                XMapWindow(screen->display, VWindow(screen));
        !          1562:                                screen->show = TRUE;
        !          1563:                        }
        !          1564:                } else {
        !          1565:                        screen->show = FALSE;
        !          1566:                        XUnmapWindow(screen->display, VWindow(screen));
        !          1567:                        SyncUnmap(VWindow(screen), WINDOWEVENTS);
        !          1568:                        if(!screen->TekEmu) {
        !          1569:                                if(TekRefresh)
        !          1570:                                        dorefresh();
        !          1571:                                if(screen->logging) {
        !          1572:                                        FlushLog(screen);
        !          1573:                                        screen->logstart = Tbuffer;
        !          1574:                                }
        !          1575:                                screen->TekEmu = TRUE;
        !          1576:                                longjmp(VTend, 1);
        !          1577:                        }
        !          1578:                }
        !          1579: */
        !          1580:                reselectwindow(screen);
        !          1581:                break;
        !          1582:        }
        !          1583:        if(TekRefresh)
        !          1584:                dorefresh();
        !          1585: }
        !          1586: #endif MODEMENU
        !          1587: 
        !          1588: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.