Annotation of 43BSDReno/usr.bin/telnet/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 provided
        !             6:  * that: (1) source distributions retain this entire copyright notice and
        !             7:  * comment, and (2) distributions including binaries display the following
        !             8:  * acknowledgement:  ``This product includes software developed by the
        !             9:  * University of California, Berkeley and its contributors'' in the
        !            10:  * documentation or other materials provided with the distribution and in
        !            11:  * all advertising materials mentioning features or use of this software.
        !            12:  * Neither the name of the University nor the names of its contributors may
        !            13:  * be used to endorse or promote products derived from this software without
        !            14:  * specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: static char sccsid[] = "@(#)terminal.c 1.21 (Berkeley) 6/28/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: #include <arpa/telnet.h>
        !            25: #include <sys/types.h>
        !            26: 
        !            27: #include "ring.h"
        !            28: 
        !            29: #include "externs.h"
        !            30: #include "types.h"
        !            31: 
        !            32: Ring   ttyoring, ttyiring;
        !            33: char   ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ];
        !            34: 
        !            35: int termdata;                  /* Debugging flag */
        !            36: 
        !            37: #ifdef USE_TERMIO
        !            38: # ifndef VFLUSHO
        !            39: cc_t termFlushChar;
        !            40: # endif
        !            41: # ifndef VLNEXT
        !            42: cc_t termLiteralNextChar;
        !            43: # endif
        !            44: # ifndef VSUSP
        !            45: cc_t termSuspChar;
        !            46: # endif
        !            47: # ifndef VWERASE
        !            48: cc_t termWerasChar;
        !            49: # endif
        !            50: # ifndef VREPRINT
        !            51: cc_t termRprntChar;
        !            52: # endif
        !            53: # ifndef VSTART
        !            54: cc_t termStartChar;
        !            55: # endif
        !            56: # ifndef VSTOP
        !            57: cc_t termStopChar;
        !            58: # endif
        !            59: # ifndef VEOL
        !            60: cc_t termForw1Char;
        !            61: # endif
        !            62: # ifndef VEOL2
        !            63: cc_t termForw2Char;
        !            64: # endif
        !            65: #else
        !            66: cc_t termForw2Char;
        !            67: #endif
        !            68: 
        !            69: /*
        !            70:  * initialize the terminal data structures.
        !            71:  */
        !            72: 
        !            73: init_terminal()
        !            74: {
        !            75:     if (ring_init(&ttyoring, ttyobuf, sizeof ttyobuf) != 1) {
        !            76:        exit(1);
        !            77:     }
        !            78:     if (ring_init(&ttyiring, ttyibuf, sizeof ttyibuf) != 1) {
        !            79:        exit(1);
        !            80:     }
        !            81:     autoflush = TerminalAutoFlush();
        !            82: }
        !            83: 
        !            84: 
        !            85: /*
        !            86:  *             Send as much data as possible to the terminal.
        !            87:  *
        !            88:  *             Return value:
        !            89:  *                     -1: No useful work done, data waiting to go out.
        !            90:  *                      0: No data was waiting, so nothing was done.
        !            91:  *                      1: All waiting data was written out.
        !            92:  *                      n: All data - n was written out.
        !            93:  */
        !            94: 
        !            95: 
        !            96: int
        !            97: ttyflush(drop)
        !            98: int drop;
        !            99: {
        !           100:     register int n, n0, n1;
        !           101: 
        !           102:     n0 = ring_full_count(&ttyoring);
        !           103:     if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) {
        !           104:        if (drop) {
        !           105:            TerminalFlushOutput();
        !           106:            /* we leave 'n' alone! */
        !           107:        } else {
        !           108:            n = TerminalWrite(ttyoring.consume, n);
        !           109:        }
        !           110:     }
        !           111:     if (n > 0) {
        !           112:        if (termdata && n) {
        !           113:            Dump('>', ttyoring.consume, n);
        !           114:        }
        !           115:        /*
        !           116:         * If we wrote everything, and the full count is
        !           117:         * larger than what we wrote, then write the
        !           118:         * rest of the buffer.
        !           119:         */
        !           120:        if (n1 == n && n0 > n) {
        !           121:                n1 = n0 - n;
        !           122:                if (!drop)
        !           123:                        n1 = TerminalWrite(ttyoring.bottom, n1);
        !           124:                n += n1;
        !           125:        }
        !           126:        ring_consumed(&ttyoring, n);
        !           127:     }
        !           128:     if (n < 0)
        !           129:        return -1;
        !           130:     if (n == n0) {
        !           131:        if (n0)
        !           132:            return -1;
        !           133:        return 0;
        !           134:     }
        !           135:     return n0 - n + 1;
        !           136: }
        !           137: 
        !           138: 
        !           139: /*
        !           140:  * These routines decides on what the mode should be (based on the values
        !           141:  * of various global variables).
        !           142:  */
        !           143: 
        !           144: 
        !           145: int
        !           146: getconnmode()
        !           147: {
        !           148:     extern int linemode;
        !           149:     int mode = 0;
        !           150: #ifdef KLUDGELINEMODE
        !           151:     extern int kludgelinemode;
        !           152: #endif
        !           153: 
        !           154:     if (In3270)
        !           155:        return(MODE_FLOW);
        !           156: 
        !           157:     if (my_want_state_is_dont(TELOPT_ECHO))
        !           158:        mode |= MODE_ECHO;
        !           159: 
        !           160:     if (localflow)
        !           161:        mode |= MODE_FLOW;
        !           162: 
        !           163:     if (my_want_state_is_will(TELOPT_BINARY))
        !           164:        mode |= MODE_INBIN;
        !           165: 
        !           166:     if (his_want_state_is_will(TELOPT_BINARY))
        !           167:        mode |= MODE_OUTBIN;
        !           168: 
        !           169: #ifdef KLUDGELINEMODE
        !           170:     if (kludgelinemode) {
        !           171:        if (my_want_state_is_dont(TELOPT_SGA)) {
        !           172:            mode |= (MODE_TRAPSIG|MODE_EDIT);
        !           173:            if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) {
        !           174:                mode &= ~MODE_ECHO;
        !           175:            }
        !           176:        }
        !           177:        return(mode);
        !           178:     }
        !           179: #endif
        !           180:     if (my_want_state_is_will(TELOPT_LINEMODE))
        !           181:        mode |= linemode;
        !           182:     return(mode);
        !           183: }
        !           184: 
        !           185: void
        !           186: setconnmode(force)
        !           187: {
        !           188:     TerminalNewMode(getconnmode()|(force?MODE_FORCE:0));
        !           189: }
        !           190: 
        !           191: 
        !           192: void
        !           193: setcommandmode()
        !           194: {
        !           195:     TerminalNewMode(-1);
        !           196: }

unix.superglobalmegacorp.com

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