This is the first version to get near rings. It compiles,
authorGregory Minshall <minshall@ucbvax.Berkeley.EDU>
Sun, 11 Oct 1987 06:27:30 +0000 (22:27 -0800)
committerGregory Minshall <minshall@ucbvax.Berkeley.EDU>
Sun, 11 Oct 1987 06:27:30 +0000 (22:27 -0800)
but doesn't work.

SCCS-vsn: usr.bin/telnet/defines.h 1.2
SCCS-vsn: usr.bin/telnet/externs.h 1.3
SCCS-vsn: usr.bin/telnet/main.c 1.3
SCCS-vsn: usr.bin/telnet/commands.c 1.2
SCCS-vsn: usr.bin/telnet/network.c 1.3
SCCS-vsn: usr.bin/telnet/sys_bsd.c 1.3
SCCS-vsn: usr.bin/telnet/Makefile 1.5
SCCS-vsn: usr.bin/telnet/terminal.c 1.4
SCCS-vsn: usr.bin/telnet/utilities.c 1.2
SCCS-vsn: usr.bin/telnet/telnet.c 5.19
SCCS-vsn: usr.bin/telnet/ring.c 1.2
SCCS-vsn: usr.bin/telnet/ring.h 1.2

12 files changed:
usr/src/usr.bin/telnet/Makefile
usr/src/usr.bin/telnet/commands.c
usr/src/usr.bin/telnet/defines.h
usr/src/usr.bin/telnet/externs.h
usr/src/usr.bin/telnet/main.c
usr/src/usr.bin/telnet/network.c
usr/src/usr.bin/telnet/ring.c
usr/src/usr.bin/telnet/ring.h
usr/src/usr.bin/telnet/sys_bsd.c
usr/src/usr.bin/telnet/telnet.c
usr/src/usr.bin/telnet/terminal.c
usr/src/usr.bin/telnet/utilities.c

index 992138c..9f3205b 100644 (file)
@@ -3,9 +3,10 @@
 # All rights reserved.  The Berkeley software License Agreement
 # specifies the terms and conditions for redistribution.
 #
 # All rights reserved.  The Berkeley software License Agreement
 # specifies the terms and conditions for redistribution.
 #
-#      @(#)Makefile    1.4     (Berkeley)      %G%
+#      @(#)Makefile    1.5     (Berkeley)      %G%
 #
 CFLAGS=        -O
 #
 CFLAGS=        -O
+CFLAGS=        -g
 LIBC=  /lib/libc.a
 SRCS=  commands.c main.c network.c ring.c sys_bsd.c sys_dos.c \
        telnet.c terminal.c tn3270.c utilities.c
 LIBC=  /lib/libc.a
 SRCS=  commands.c main.c network.c ring.c sys_bsd.c sys_dos.c \
        telnet.c terminal.c tn3270.c utilities.c
index 16222d6..ff9ac61 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <arpa/telnet.h>
 
 
 #include <arpa/telnet.h>
 
+#include "ring.h"
+
 #include "externs.h"
 #include "defines.h"
 #include "types.h"
 #include "externs.h"
 #include "defines.h"
 #include "types.h"
@@ -1061,7 +1063,7 @@ tn(argc, argv)
     if (setjmp(peerdied) == 0)
        telnet();
     NetClose(net);
     if (setjmp(peerdied) == 0)
        telnet();
     NetClose(net);
-    ExitString(stderr, "Connection closed by foreign host.\n",1);
+    ExitString("Connection closed by foreign host.\n",1);
     /*NOTREACHED*/
 }
 
     /*NOTREACHED*/
 }
 
index 6d09474..9be754f 100644 (file)
@@ -2,25 +2,23 @@
 
 #if    !defined(TN3270)
 
 
 #if    !defined(TN3270)
 
-#define        ExitString(f,s,r)       { fprintf(f, s); exit(r); }
+#define        ExitString(s,r) { fprintf(stderr, s); exit(r); }
 #define        Exit(x)                 exit(x)
 #define        SetIn3270()
 
 #endif /* !defined(TN3270) */
 
 #define        Exit(x)                 exit(x)
 #define        SetIn3270()
 
 #endif /* !defined(TN3270) */
 
-#define        NETADD(c)       { *nfrontp++ = c; }
+#define        NETADD(c)       { *netoring.send = c; ring_added(&netoring, 1); }
 #define        NET2ADD(c1,c2)  { NETADD(c1); NETADD(c2); }
 #define        NET2ADD(c1,c2)  { NETADD(c1); NETADD(c2); }
-#define NETLOC()       (nfrontp)
-#define        NETMAX()        (netobuf+sizeof netobuf-1)
-#define        NETBYTES()      (nfrontp-nbackp)
-#define        NETROOM()       (NETMAX()-NETLOC()+1)
+#define        NETBYTES()      (ring_unsent_count(&netoring))
+#define        NETROOM()       (ring_empty_count(&netoring))
 
 
-#define        TTYADD(c)       { if (!(SYNCHing||flushout)) { *tfrontp++ = c; } }
-#define        TTYLOC()        (tfrontp)
-#define        TTYMAX()        (ttyobuf+sizeof ttyobuf-1)
-#define        TTYMIN()        (netobuf)
-#define        TTYBYTES()      (tfrontp-tbackp)
-#define        TTYROOM()       (TTYMAX()-TTYLOC()+1)
+#define        TTYADD(c)       if (!(SYNCHing||flushout)) { \
+                               *ttyoring.send = c; \
+                               ring_added(&ttyoring, 1); \
+                       }
+#define        TTYBYTES()      (ring_unsent_count(&ttyoring))
+#define        TTYROOM()       (ring_empty_count(&ttyoring))
 
 /*     Various modes */
 #define        MODE_LINE(m)    (modelist[m].modetype & LINE)
 
 /*     Various modes */
 #define        MODE_LINE(m)    (modelist[m].modetype & LINE)
index 712f9f4..eb70baf 100644 (file)
@@ -37,13 +37,7 @@ extern char
        myopts[],
        subbuffer[SUBBUFSIZE],
        *hostname,              /* Who are we connected to? */
        myopts[],
        subbuffer[SUBBUFSIZE],
        *hostname,              /* Who are we connected to? */
-       *prompt,                /* Prompt for command. */
-       *nfrontp,
-       *nbackp,
-       netobuf[2*BUFSIZ],
-       ttyobuf[2*BUFSIZ],
-       *tfrontp,
-       *tbackp;
+       *prompt;                /* Prompt for command. */
 
 extern FILE
        *NetTrace;              /* Where debugging output goes */
 
 extern FILE
        *NetTrace;              /* Where debugging output goes */
@@ -69,3 +63,11 @@ extern char
     termKillChar,
     termLiteralNextChar,
     termQuitChar;
     termKillChar,
     termLiteralNextChar,
     termQuitChar;
+
+/* Ring buffer structures which are shared */
+
+extern Ring
+       netoring,
+       netiring,
+       ttyoring,
+       ttyiring;
index 659d82d..1660c60 100644 (file)
@@ -1,3 +1,7 @@
+#include <sys/types.h>
+
+#include "ring.h"
+
 #include "externs.h"
 #include "defines.h"
 
 #include "externs.h"
 #include "defines.h"
 
index 95658a3..7310b75 100644 (file)
@@ -6,11 +6,13 @@
 
 #include <arpa/telnet.h>
 
 
 #include <arpa/telnet.h>
 
+#include "ring.h"
+
 #include "defines.h"
 #include "externs.h"
 
 #include "defines.h"
 #include "externs.h"
 
-char   netobuf[2*BUFSIZ], *nfrontp, *nbackp;
-static char    *neturg;                /* one past last byte of urgent data */
+Ring   netoring;
+char   netobuf[2*BUFSIZ];
 
 /*
  * Initialize internal network data structures.
 
 /*
  * Initialize internal network data structures.
@@ -18,7 +20,7 @@ static char   *neturg;                /* one past last byte of urgent data */
 
 init_network()
 {
 
 init_network()
 {
-    nfrontp = nbackp = netobuf;
+    ring_init(&netoring, netobuf, sizeof netobuf);
     NetTrace = stdout;
 }
 
     NetTrace = stdout;
 }
 
@@ -63,7 +65,7 @@ int   s;              /* socket number */
 void
 setneturg()
 {
 void
 setneturg()
 {
-    neturg = NETLOC()-1;       /* Some systems are off by one XXX */
+    ring_mark(&netoring);
 }
 
 
 }
 
 
@@ -82,11 +84,10 @@ netflush()
 {
     int n;
 
 {
     int n;
 
-    if ((n = nfrontp - nbackp) > 0) {
-       if (!neturg) {
-           n = send(net, nbackp, n, 0);        /* normal write */
+    if ((n = ring_unsent_consecutive(&netoring)) > 0) {
+       if (!ring_at_mark(&netoring)) {
+           n = send(net, netoring.send, n, 0); /* normal write */
        } else {
        } else {
-           n = neturg - nbackp;
            /*
             * In 4.2 (and 4.3) systems, there is some question about
             * what byte in a sendOOB operation is the "OOB" data.
            /*
             * In 4.2 (and 4.3) systems, there is some question about
             * what byte in a sendOOB operation is the "OOB" data.
@@ -95,11 +96,7 @@ netflush()
             * we really have more the TCP philosophy of urgent data
             * rather than the Unix philosophy of OOB data).
             */
             * we really have more the TCP philosophy of urgent data
             * rather than the Unix philosophy of OOB data).
             */
-           if (n > 1) {
-               n = send(net, nbackp, n-1, 0);  /* send URGENT all by itself */
-           } else {
-               n = send(net, nbackp, n, MSG_OOB);      /* URGENT data */
-           }
+           n = send(net, netoring.send, 1, MSG_OOB);/* URGENT data */
        }
     }
     if (n < 0) {
        }
     }
     if (n < 0) {
@@ -107,22 +104,16 @@ netflush()
            setcommandmode();
            perror(hostname);
            NetClose(net);
            setcommandmode();
            perror(hostname);
            NetClose(net);
-           neturg = 0;
+           ring_clear_mark(&netoring);
            longjmp(peerdied, -1);
            /*NOTREACHED*/
        }
        n = 0;
     }
     if (netdata && n) {
            longjmp(peerdied, -1);
            /*NOTREACHED*/
        }
        n = 0;
     }
     if (netdata && n) {
-       Dump('>', nbackp, n);
-    }
-    nbackp += n;
-    if (nbackp >= neturg) {
-       neturg = 0;
-    }
-    if (nbackp == nfrontp) {
-       nbackp = nfrontp = netobuf;
+       Dump('>', netoring.send, n);
     }
     }
+    ring_sent(&netoring, n);
     return n > 0;
 }
 \f
     return n > 0;
 }
 \f
@@ -166,6 +157,7 @@ char        *current;
        return current+2;
     }
 }
        return current+2;
     }
 }
+
 /*
  * netclear()
  *
 /*
  * netclear()
  *
@@ -186,6 +178,7 @@ char        *current;
 void
 netclear()
 {
 void
 netclear()
 {
+#if    0       /* XXX */
     register char *thisitem, *next;
     char *good;
 #define        wewant(p)       ((nfrontp > p) && ((*p&0xff) == IAC) && \
     register char *thisitem, *next;
     char *good;
 #define        wewant(p)       ((nfrontp > p) && ((*p&0xff) == IAC) && \
@@ -193,7 +186,7 @@ netclear()
 
     thisitem = netobuf;
 
 
     thisitem = netobuf;
 
-    while ((next = nextitem(thisitem)) <= nbackp) {
+    while ((next = nextitem(thisitem)) <= netobuf.send) {
        thisitem = next;
     }
 
        thisitem = next;
     }
 
@@ -201,7 +194,7 @@ netclear()
 
     good = netobuf;    /* where the good bytes go */
 
 
     good = netobuf;    /* where the good bytes go */
 
-    while (nfrontp > thisitem) {
+    while (netoring.add > thisitem) {
        if (wewant(thisitem)) {
            int length;
 
        if (wewant(thisitem)) {
            int length;
 
@@ -218,7 +211,44 @@ netclear()
        }
     }
 
        }
     }
 
-    nbackp = netobuf;
-    nfrontp = good;            /* next byte to be sent */
-    neturg = 0;
+#endif /* 0 */
+    ring_init(&netoring, netobuf, sizeof netobuf);
+}
+
+#include <varargs.h>
+
+void
+netoprint(va_alist)
+va_dcl
+{
+    va_list ap;
+    char buffer[100];          /* where things go */
+    char *ptr = buffer;
+    char *format;
+    int i;
+
+    va_start(ap);
+
+    format = va_arg(ap, char *);
+
+    while ((i = *format++) != 0) {
+       if (i == '%') {
+           i = *format++;
+           switch (i) {
+           case 'c':
+               i = va_arg(ap, char);
+               NETADD(i);
+               break;
+           case 0:
+               ExitString("netoprint: trailing %.\n", 1);
+               /*NOTREACHED*/
+           default:
+               ExitString("netoprint: unknown format character.\n", 1);
+               /*NOTREACHED*/
+           }
+       } else {
+           *ptr++ = i;
+       }
+    }
+    ring_add_data(&netoring, buffer, ptr-buffer);
 }
 }
index 509f914..8b5b643 100644 (file)
 
 /* Internal macros */
 
 
 /* Internal macros */
 
-#if    !defined(min)
-#define        min(a,b)        (((a)<(b))? (a):(b))
-#endif /* !defined(min) */
+#if    !defined(MIN)
+#define        MIN(a,b)        (((a)<(b))? (a):(b))
+#endif /* !defined(MIN) */
 
 
-#define        ring_subtract(d,a,b)    ((((int)(a))-((int)(b)) >= 0)? (a)-(b): (((a)-(b))+(d)->size))
+#define        ring_subtract(d,a,b)    ((((int)(a))-((int)(b)) >= 0)? \
+                                       (a)-(b): (((a)-(b))+(d)->size))
 
 #define        ring_increment(d,a,c)   (((a)+(c) < (d)->top)? \
                                        (a)+(c) : (((a)+(c))-(d)->size))
 
 #define        ring_increment(d,a,c)   (((a)+(c) < (d)->top)? \
                                        (a)+(c) : (((a)+(c))-(d)->size))
@@ -64,6 +65,21 @@ static u_long ring_clock = 0;
 
 /* Buffer state transition routines */
 
 
 /* Buffer state transition routines */
 
+ring_init(ring, buffer, count)
+Ring *ring;
+char *buffer;
+int count;
+{
+    memset((char *)ring, 0, sizeof *ring);
+
+    ring->size = count;
+
+    ring->add = ring->send = ring->ack = ring->bottom = buffer;
+
+    ring->top = ring->bottom+ring->size;
+
+    return 1;
+}
 
 /*
  * Add characters from current segment to ring buffer.
 
 /*
  * Add characters from current segment to ring buffer.
@@ -185,7 +201,7 @@ int count;
     int i;
 
     while (count) {
     int i;
 
     while (count) {
-       i = min(count, ring_empty_consecutive(ring));
+       i = MIN(count, ring_empty_consecutive(ring));
        memcpy(ring->add, buffer, i);
        ring_added(ring, i);
        count -= i;
        memcpy(ring->add, buffer, i);
        ring_added(ring, i);
        count -= i;
@@ -206,10 +222,32 @@ int count;
     int i;
 
     while (count) {
     int i;
 
     while (count) {
-       i = min(count, ring_unsent_consecutive(ring));
+       i = MIN(count, ring_unsent_consecutive(ring));
        memcpy(buffer, ring->send, i);
        ring_sent(ring, i);
        count -= i;
        buffer += i;
     }
 }
        memcpy(buffer, ring->send, i);
        ring_sent(ring, i);
        count -= i;
        buffer += i;
     }
 }
+
+/* Mark routines */
+
+/* XXX do something here */
+void
+ring_mark(ring)
+Ring *ring;
+{
+}
+
+int
+ring_at_mark(ring)
+Ring *ring;
+{
+    return 0;
+}
+
+void
+ring_clear_mark(ring)
+Ring *ring;
+{
+}
index fc8c9a0..7ed9123 100644 (file)
@@ -30,6 +30,10 @@ typedef struct {
 
 #if    defined(LINT_ARGS)
 
 
 #if    defined(LINT_ARGS)
 
+/* Initialization routine */
+extern int
+       ring_init(Ring *ring, char *buffer, int count);
+
 /* Data movement routines */
 extern void
        ring_add_data(Ring *ring, char *buffer, int count),
 /* Data movement routines */
 extern void
        ring_add_data(Ring *ring, char *buffer, int count),
index 7a51c13..e359f0d 100644 (file)
@@ -6,9 +6,12 @@
 #if    defined(unix)
 
 #include <sys/ioctl.h>
 #if    defined(unix)
 
 #include <sys/ioctl.h>
+#include <sys/types.h>
 #include <sys/time.h>
 #include <signal.h>
 
 #include <sys/time.h>
 #include <signal.h>
 
+#include "ring.h"
+
 #include "defines.h"
 #include "externs.h"
 #include "types.h"
 #include "defines.h"
 #include "externs.h"
 #include "types.h"
index a1312d1..37118d6 100644 (file)
@@ -8,47 +8,6 @@ static char copyright[] =
 static char sccsid[] = "@(#)telnet.c   1.2 (Berkeley) 9/25/87";
 #endif /* not lint */
 
 static char sccsid[] = "@(#)telnet.c   1.2 (Berkeley) 9/25/87";
 #endif /* not lint */
 
-/*
- * User telnet program, modified for use by tn3270.c.
- *
- * Many of the FUNCTIONAL changes in this newest version of TELNET
- * were suggested by Dave Borman of Cray Research, Inc.
- *
- * Other changes in the tn3270 side come from Alan Crosswell (Columbia),
- * Bob Braden (ISI), Steve Jacobson (Berkeley), and Cliff Frost (Berkeley).
- *
- * This code is common between telnet(1c) and tn3270(1c).  There are the
- * following defines used to generate the various versions:
- *
- *     TN3270          -       This is to be linked with tn3270.
- *
- *     NOT43           -       Allows the program to compile and run on
- *                             a 4.2BSD system.
- *
- *     PUTCHAR         -       Within tn3270, on a NOT43 system,
- *                             allows the use of the 4.3 curses
- *                             (greater speed updating the screen).
- *                             You need the 4.3 curses for this to work.
- *
- *     FD_SETSIZE      -       On whichever system, if this isn't defined,
- *                             we patch over the FD_SET, etc., macros with
- *                             some homebrewed ones.
- *
- *     SO_OOBINLINE    -       This is a socket option which we would like
- *                             to set to allow TCP urgent data to come
- *                             to us "inline".  This is NECESSARY for
- *                             CORRECT operation, and desireable for
- *                             simpler operation.
- *
- *     LNOFLSH         -       Detects the presence of the LNOFLSH bit
- *                             in the tty structure.
- *
- *     unix            -       Compiles in unix specific stuff.
- *
- *     MSDOS           -       Compiles in MSDOS specific stuff.
- *
- */
-
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/socket.h>
@@ -82,19 +41,15 @@ extern char *inet_ntoa();
 #include <string.h>
 #endif /* defined(unix) */
 
 #include <string.h>
 #endif /* defined(unix) */
 
+#include "ring.h"
+
 #include "defines.h"
 #include "externs.h"
 #include "types.h"
 #include "general.h"
 
 
 #include "defines.h"
 #include "externs.h"
 #include "types.h"
 #include "general.h"
 
 
-#if    !defined(TN3270)
-#define        ExitString(f,s,r)       { fprintf(f, s); exit(r); }
-#define        Exit(x)                 exit(x)
-#define        SetIn3270()
-
 void   setcommandmode(), command();    /* forward declarations */
 void   setcommandmode(), command();    /* forward declarations */
-#endif /* !defined(TN3270) */
 
 #ifndef        FD_SETSIZE
 /*
 
 #ifndef        FD_SETSIZE
 /*
@@ -315,8 +270,7 @@ willoption(option, reply)
                fmt = dont;
                break;
        }
                fmt = dont;
                break;
        }
-       sprintf(nfrontp, fmt, option);
-       nfrontp += sizeof (dont) - 2;
+       netoprint(fmt, option);
        if (reply)
                printoption(">SENT", fmt, option, reply);
        else
        if (reply)
                printoption(">SENT", fmt, option, reply);
        else
@@ -345,8 +299,7 @@ wontoption(option, reply)
        default:
                fmt = dont;
        }
        default:
                fmt = dont;
        }
-       sprintf(nfrontp, fmt, option);
-       nfrontp += sizeof (doopt) - 2;
+       netoprint(fmt, option);
        if (reply)
                printoption(">SENT", fmt, option, reply);
        else
        if (reply)
                printoption(">SENT", fmt, option, reply);
        else
@@ -380,8 +333,7 @@ dooption(option)
                fmt = wont;
                break;
        }
                fmt = wont;
                break;
        }
-       sprintf(nfrontp, fmt, option);
-       nfrontp += sizeof (doopt) - 2;
+       netoprint(fmt, option);
        printoption(">SENT", fmt, option, 0);
 }
 
        printoption(">SENT", fmt, option, 0);
 }
 
@@ -447,13 +399,12 @@ suboption()
                NumberColumns = 80;
                ScreenSize = NumberLines*NumberColumns;
                if ((MaxNumberLines*MaxNumberColumns) > MAXSCREENSIZE) {
                NumberColumns = 80;
                ScreenSize = NumberLines*NumberColumns;
                if ((MaxNumberLines*MaxNumberColumns) > MAXSCREENSIZE) {
-                   ExitString(stderr,
-                       "Programming error:  MAXSCREENSIZE too small.\n", 1);
+                   ExitString("Programming error:  MAXSCREENSIZE too small.\n",
+                                                                       1);
                    /*NOTREACHED*/
                }
                    /*NOTREACHED*/
                }
-               memcpy(nfrontp, sb_terminal, sizeof sb_terminal);
-               printsub(">", nfrontp+2, sizeof sb_terminal-2);
-               nfrontp += sizeof sb_terminal;
+               printsub(">", sb_terminal+2, sizeof sb_terminal-2);
+               ring_add_data(&netoring, sb_terminal, sizeof sb_terminal);
                return;
            }
 #endif /* defined(TN3270) */
                return;
            }
 #endif /* defined(TN3270) */
@@ -465,12 +416,12 @@ suboption()
            if ((len + 4+2) < NETROOM()) {
                strcpy(namebuf, name);
                upcase(namebuf);
            if ((len + 4+2) < NETROOM()) {
                strcpy(namebuf, name);
                upcase(namebuf);
-               sprintf(nfrontp, "%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
+               netoprint("%c%c%c%c%s%c%c", IAC, SB, TELOPT_TTYPE,
                                    TELQUAL_IS, namebuf, IAC, SE);
                                    TELQUAL_IS, namebuf, IAC, SE);
-               printsub(">", nfrontp+2, 4+strlen(namebuf)+2-2-2);
-               nfrontp += 4+strlen(namebuf)+2;
+               /* XXX */
+               /* printsub(">", nfrontp+2, 4+strlen(namebuf)+2-2-2); */
            } else {
            } else {
-               ExitString(stderr, "No room in buffer for terminal type.\n",
+               ExitString("No room in buffer for terminal type.\n",
                                                        1);
                /*NOTREACHED*/
            }
                                                        1);
                /*NOTREACHED*/
            }
@@ -700,8 +651,7 @@ telrcv()
            printoption(">RCVD", dont, c, myopts[c]);
            if (myopts[c]) {
                myopts[c] = 0;
            printoption(">RCVD", dont, c, myopts[c]);
            if (myopts[c]) {
                myopts[c] = 0;
-               sprintf(nfrontp, wont, c);
-               nfrontp += sizeof (wont) - 2;
+               netoprint(wont, c);
                flushline = 1;
                setconnmode();  /* set new tty mode (maybe) */
                printoption(">SENT", wont, c, 0);
                flushline = 1;
                setconnmode();  /* set new tty mode (maybe) */
                printoption(">SENT", wont, c, 0);
@@ -762,13 +712,12 @@ int returnCode;
 }
 
 void
 }
 
 void
-ExitString(file, string, returnCode)
-FILE *file;
+ExitString(string, returnCode)
 char *string;
 int returnCode;
 {
     SetForExit();
 char *string;
 int returnCode;
 {
     SetForExit();
-    fwrite(string, 1, strlen(string), file);
+    fwrite(string, 1, strlen(string), stderr);
     exit(returnCode);
 }
 
     exit(returnCode);
 }
 
index 51ef504..cbfd07a 100644 (file)
@@ -1,9 +1,13 @@
 #include <arpa/telnet.h>
 #include <arpa/telnet.h>
+#include <sys/types.h>
+
+#include "ring.h"
 
 #include "externs.h"
 #include "types.h"
 
 
 #include "externs.h"
 #include "types.h"
 
-char   ttyobuf[2*BUFSIZ], *tfrontp, *tbackp;
+Ring   ttyoring;
+char   ttyobuf[2*BUFSIZ];
 
 char
     termEofChar,
 
 char
     termEofChar,
@@ -20,7 +24,7 @@ char
 
 init_terminal()
 {
 
 init_terminal()
 {
-    tfrontp = tbackp = ttyobuf;
+    ring_init(&ttyoring, ttyobuf, sizeof ttyobuf);
     autoflush = TerminalAutoFlush();
 }
 
     autoflush = TerminalAutoFlush();
 }
 
@@ -39,19 +43,16 @@ int drop;
 {
     int n;
 
 {
     int n;
 
-    if ((n = tfrontp - tbackp) > 0) {
+    if ((n = ring_unsent_consecutive(&ttyoring)) > 0) {
        if (drop) {
            TerminalFlushOutput();
            /* we leave 'n' alone! */
        } else {
        if (drop) {
            TerminalFlushOutput();
            /* we leave 'n' alone! */
        } else {
-           n = TerminalWrite(tout, tbackp, n);
+           n = TerminalWrite(tout, ttyoring.send, n);
        }
     }
     if (n >= 0) {
        }
     }
     if (n >= 0) {
-       tbackp += n;
-       if (tbackp == tfrontp) {
-           tbackp = tfrontp = ttyobuf;
-       }
+       ring_sent(&ttyoring, n);
     }
     return n > 0;
 }
     }
     return n > 0;
 }
index 52091a0..5dbfd73 100644 (file)
@@ -1,8 +1,11 @@
 #define        TELOPTS
 #include <arpa/telnet.h>
 #define        TELOPTS
 #include <arpa/telnet.h>
+#include <sys/types.h>
 
 #include <ctype.h>
 
 
 #include <ctype.h>
 
+#include "ring.h"
+
 #include "externs.h"
 
 FILE   *NetTrace = 0;          /* Not in bss, since needs to stay */
 #include "externs.h"
 
 FILE   *NetTrace = 0;          /* Not in bss, since needs to stay */