[BACK]Return to terminal.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / telnet

Annotation of src/usr.bin/telnet/terminal.c, Revision 1.2

1.2     ! niklas      1: /*     $OpenBSD$       */
        !             2: /*     $NetBSD: terminal.c,v 1.5 1996/02/28 21:04:17 thorpej Exp $     */
        !             3:
1.1       deraadt     4: /*
                      5:  * Copyright (c) 1988, 1990, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by the University of
                     19:  *     California, Berkeley and its contributors.
                     20:  * 4. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  */
                     36:
                     37: #ifndef lint
1.2     ! niklas     38: #if 0
        !            39: static char sccsid[] = "@(#)terminal.c 8.2 (Berkeley) 2/16/95";
        !            40: static char rcsid[] = "$NetBSD: terminal.c,v 1.5 1996/02/28 21:04:17 thorpej Exp $";
        !            41: #else
        !            42: static char rcsid[] = "$OpenBSD$";
        !            43: #endif
1.1       deraadt    44: #endif /* not lint */
                     45:
                     46: #include <arpa/telnet.h>
                     47: #include <sys/types.h>
                     48:
                     49: #include "ring.h"
                     50:
                     51: #include "externs.h"
                     52: #include "types.h"
                     53:
                     54: Ring           ttyoring, ttyiring;
                     55: unsigned char  ttyobuf[2*BUFSIZ], ttyibuf[BUFSIZ];
                     56:
                     57: int termdata;                  /* Debugging flag */
                     58:
                     59: #ifdef USE_TERMIO
                     60: # ifndef VDISCARD
                     61: cc_t termFlushChar;
                     62: # endif
                     63: # ifndef VLNEXT
                     64: cc_t termLiteralNextChar;
                     65: # endif
                     66: # ifndef VSUSP
                     67: cc_t termSuspChar;
                     68: # endif
                     69: # ifndef VWERASE
                     70: cc_t termWerasChar;
                     71: # endif
                     72: # ifndef VREPRINT
                     73: cc_t termRprntChar;
                     74: # endif
                     75: # ifndef VSTART
                     76: cc_t termStartChar;
                     77: # endif
                     78: # ifndef VSTOP
                     79: cc_t termStopChar;
                     80: # endif
                     81: # ifndef VEOL
                     82: cc_t termForw1Char;
                     83: # endif
                     84: # ifndef VEOL2
                     85: cc_t termForw2Char;
                     86: # endif
                     87: # ifndef VSTATUS
                     88: cc_t termAytChar;
                     89: # endif
                     90: #else
                     91: cc_t termForw2Char;
                     92: cc_t termAytChar;
                     93: #endif
                     94:
                     95: /*
                     96:  * initialize the terminal data structures.
                     97:  */
                     98:
                     99:     void
                    100: init_terminal()
                    101: {
                    102:     if (ring_init(&ttyoring, ttyobuf, sizeof ttyobuf) != 1) {
                    103:        exit(1);
                    104:     }
                    105:     if (ring_init(&ttyiring, ttyibuf, sizeof ttyibuf) != 1) {
                    106:        exit(1);
                    107:     }
                    108:     autoflush = TerminalAutoFlush();
                    109: }
                    110:
                    111:
                    112: /*
                    113:  *             Send as much data as possible to the terminal.
                    114:  *
                    115:  *             Return value:
                    116:  *                     -1: No useful work done, data waiting to go out.
                    117:  *                      0: No data was waiting, so nothing was done.
                    118:  *                      1: All waiting data was written out.
                    119:  *                      n: All data - n was written out.
                    120:  */
                    121:
                    122:
                    123:     int
                    124: ttyflush(drop)
                    125:     int drop;
                    126: {
                    127:     register int n, n0, n1;
                    128:
                    129:     n0 = ring_full_count(&ttyoring);
                    130:     if ((n1 = n = ring_full_consecutive(&ttyoring)) > 0) {
                    131:        if (drop) {
                    132:            TerminalFlushOutput();
                    133:            /* we leave 'n' alone! */
                    134:        } else {
                    135:            n = TerminalWrite(ttyoring.consume, n);
                    136:        }
                    137:     }
                    138:     if (n > 0) {
                    139:        if (termdata && n) {
                    140:            Dump('>', ttyoring.consume, n);
                    141:        }
                    142:        /*
                    143:         * If we wrote everything, and the full count is
                    144:         * larger than what we wrote, then write the
                    145:         * rest of the buffer.
                    146:         */
                    147:        if (n1 == n && n0 > n) {
                    148:                n1 = n0 - n;
                    149:                if (!drop)
                    150:                        n1 = TerminalWrite(ttyoring.bottom, n1);
1.2     ! niklas    151:                if (n1 > 0)
        !           152:                        n += n1;
1.1       deraadt   153:        }
                    154:        ring_consumed(&ttyoring, n);
                    155:     }
                    156:     if (n < 0)
                    157:        return -1;
                    158:     if (n == n0) {
                    159:        if (n0)
                    160:            return -1;
                    161:        return 0;
                    162:     }
                    163:     return n0 - n + 1;
                    164: }
                    165:
                    166: 
                    167: /*
                    168:  * These routines decides on what the mode should be (based on the values
                    169:  * of various global variables).
                    170:  */
                    171:
                    172:
                    173:     int
                    174: getconnmode()
                    175: {
                    176:     extern int linemode;
                    177:     int mode = 0;
                    178: #ifdef KLUDGELINEMODE
                    179:     extern int kludgelinemode;
                    180: #endif
                    181:
                    182:     if (In3270)
                    183:        return(MODE_FLOW);
                    184:
                    185:     if (my_want_state_is_dont(TELOPT_ECHO))
                    186:        mode |= MODE_ECHO;
                    187:
                    188:     if (localflow)
                    189:        mode |= MODE_FLOW;
                    190:
                    191:     if (my_want_state_is_will(TELOPT_BINARY))
                    192:        mode |= MODE_INBIN;
                    193:
                    194:     if (his_want_state_is_will(TELOPT_BINARY))
                    195:        mode |= MODE_OUTBIN;
                    196:
                    197: #ifdef KLUDGELINEMODE
                    198:     if (kludgelinemode) {
                    199:        if (my_want_state_is_dont(TELOPT_SGA)) {
                    200:            mode |= (MODE_TRAPSIG|MODE_EDIT);
                    201:            if (dontlecho && (clocks.echotoggle > clocks.modenegotiated)) {
                    202:                mode &= ~MODE_ECHO;
                    203:            }
                    204:        }
                    205:        return(mode);
                    206:     }
                    207: #endif
                    208:     if (my_want_state_is_will(TELOPT_LINEMODE))
                    209:        mode |= linemode;
                    210:     return(mode);
                    211: }
                    212:
                    213:     void
                    214: setconnmode(force)
                    215:     int force;
                    216: {
                    217:     register int newmode;
                    218:
                    219:     newmode = getconnmode()|(force?MODE_FORCE:0);
                    220:
                    221:     TerminalNewMode(newmode);
                    222:
                    223:
                    224: }
                    225:
                    226:
                    227:     void
                    228: setcommandmode()
                    229: {
                    230:     TerminalNewMode(-1);
                    231: }