Annotation of 43BSDTahoe/ucb/telnet/Source/terminal.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1988 Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted
        !             6:  * provided that this notice is preserved and that due credit is given
        !             7:  * to the University of California at Berkeley. The name of the University
        !             8:  * may not be used to endorse or promote products derived from this
        !             9:  * software without specific prior written permission. This software
        !            10:  * is provided ``as is'' without express or implied warranty.
        !            11:  */
        !            12: 
        !            13: #ifndef lint
        !            14: static char sccsid[] = "@(#)terminal.c 1.11 (Berkeley) 3/8/88";
        !            15: #endif /* not lint */
        !            16: 
        !            17: #include <arpa/telnet.h>
        !            18: #include <sys/types.h>
        !            19: 
        !            20: #include "ring.h"
        !            21: 
        !            22: #include "externs.h"
        !            23: #include "types.h"
        !            24: 
        !            25: Ring   ttyoring, ttyiring;
        !            26: char   ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ];
        !            27: 
        !            28: char
        !            29:     termEofChar,
        !            30:     termEraseChar,
        !            31:     termFlushChar,
        !            32:     termIntChar,
        !            33:     termKillChar,
        !            34:     termLiteralNextChar,
        !            35:     termQuitChar;
        !            36: 
        !            37: /*
        !            38:  * initialize the terminal data structures.
        !            39:  */
        !            40: 
        !            41: init_terminal()
        !            42: {
        !            43:     ring_init(&ttyoring, ttyobuf, sizeof ttyobuf);
        !            44:     ring_init(&ttyiring, ttyibuf, sizeof ttyibuf);
        !            45:     autoflush = TerminalAutoFlush();
        !            46: }
        !            47: 
        !            48: 
        !            49: /*
        !            50:  *             Send as much data as possible to the terminal.
        !            51:  *
        !            52:  *             The return value indicates whether we did any
        !            53:  *     useful work.
        !            54:  */
        !            55: 
        !            56: 
        !            57: int
        !            58: ttyflush(drop)
        !            59: int drop;
        !            60: {
        !            61:     register int n, n0, n1;
        !            62: 
        !            63:     n0 = ring_full_count(&ttyoring);
        !            64:     if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) {
        !            65:        if (drop) {
        !            66:            TerminalFlushOutput();
        !            67:            /* we leave 'n' alone! */
        !            68:        } else {
        !            69:            n = TerminalWrite(ttyoring.consume, n);
        !            70:        }
        !            71:     }
        !            72:     if (n > 0) {
        !            73:        /*
        !            74:         * If we wrote everything, and the full count is
        !            75:         * larger than what we wrote, then write the
        !            76:         * rest of the buffer.
        !            77:         */
        !            78:        if (n1 == n && n0 > n) {
        !            79:                n1 = n0 - n;
        !            80:                if (!drop)
        !            81:                        n1 = TerminalWrite(ttyoring.bottom, n1);
        !            82:                n += n1;
        !            83:        }
        !            84:        ring_consumed(&ttyoring, n);
        !            85:     }
        !            86:     return n > 0;
        !            87: }
        !            88: 
        !            89: 
        !            90: /*
        !            91:  * These routines decides on what the mode should be (based on the values
        !            92:  * of various global variables).
        !            93:  */
        !            94: 
        !            95: 
        !            96: int
        !            97: getconnmode()
        !            98: {
        !            99:     static char newmode[16] =
        !           100:                        { 4, 5, 3, 3, 2, 2, 1, 1, 6, 6, 6, 6, 6, 6, 6, 6 };
        !           101:     int modeindex = 0;
        !           102: 
        !           103:     if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) {
        !           104:        modeindex += 1;
        !           105:     }
        !           106:     if (hisopts[TELOPT_ECHO]) {
        !           107:        modeindex += 2;
        !           108:     }
        !           109:     if (hisopts[TELOPT_SGA]) {
        !           110:        modeindex += 4;
        !           111:     }
        !           112:     if (In3270) {
        !           113:        modeindex += 8;
        !           114:     }
        !           115:     return newmode[modeindex];
        !           116: }
        !           117: 
        !           118: void
        !           119: setconnmode()
        !           120: {
        !           121:     TerminalNewMode(getconnmode());
        !           122: }
        !           123: 
        !           124: 
        !           125: void
        !           126: setcommandmode()
        !           127: {
        !           128:     TerminalNewMode(0);
        !           129: }

unix.superglobalmegacorp.com

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