BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.bin / telnet / utilities.c
index 6ca5ecd..06d08a4 100644 (file)
@@ -2,11 +2,37 @@
  * Copyright (c) 1988, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
  * Copyright (c) 1988, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)utilities.c        8.1 (Berkeley) %G%";
+static char sccsid[] = "@(#)utilities.c        8.3 (Berkeley) 5/30/95";
 #endif /* not lint */
 
 #define        TELOPTS
 #endif /* not lint */
 
 #define        TELOPTS
@@ -177,10 +203,12 @@ printoption(direction, cmd, option)
                } else
                    fprintf(NetTrace, "%s %d %d", direction, cmd, option);
        }
                } else
                    fprintf(NetTrace, "%s %d %d", direction, cmd, option);
        }
-       if (NetTrace == stdout)
+       if (NetTrace == stdout) {
            fprintf(NetTrace, "\r\n");
            fprintf(NetTrace, "\r\n");
-       else
+           fflush(NetTrace);
+       } else {
            fprintf(NetTrace, "\n");
            fprintf(NetTrace, "\n");
+       }
        return;
 }
 
        return;
 }
 
@@ -302,7 +330,9 @@ printsub(direction, pointer, length)
            length -= 2;
        }
        if (length < 1) {
            length -= 2;
        }
        if (length < 1) {
-           fprintf(NetTrace, "(Empty suboption???)");
+           fprintf(NetTrace, "(Empty suboption??\?)");
+           if (NetTrace == stdout)
+               fflush(NetTrace);
            return;
        }
        switch (pointer[0]) {
            return;
        }
        switch (pointer[0]) {
@@ -324,7 +354,7 @@ printsub(direction, pointer, length)
        case TELOPT_TSPEED:
            fprintf(NetTrace, "TERMINAL-SPEED");
            if (length < 2) {
        case TELOPT_TSPEED:
            fprintf(NetTrace, "TERMINAL-SPEED");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -346,7 +376,7 @@ printsub(direction, pointer, length)
        case TELOPT_LFLOW:
            fprintf(NetTrace, "TOGGLE-FLOW-CONTROL");
            if (length < 2) {
        case TELOPT_LFLOW:
            fprintf(NetTrace, "TOGGLE-FLOW-CONTROL");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -368,7 +398,7 @@ printsub(direction, pointer, length)
        case TELOPT_NAWS:
            fprintf(NetTrace, "NAWS");
            if (length < 2) {
        case TELOPT_NAWS:
            fprintf(NetTrace, "NAWS");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            if (length == 2) {
                break;
            }
            if (length == 2) {
@@ -393,7 +423,7 @@ printsub(direction, pointer, length)
        case TELOPT_AUTHENTICATION:
            fprintf(NetTrace, "AUTHENTICATION");
            if (length < 2) {
        case TELOPT_AUTHENTICATION:
            fprintf(NetTrace, "AUTHENTICATION");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -406,7 +436,7 @@ printsub(direction, pointer, length)
                else
                    fprintf(NetTrace, "%d ", pointer[2]);
                if (length < 3) {
                else
                    fprintf(NetTrace, "%d ", pointer[2]);
                if (length < 3) {
-                   fprintf(NetTrace, "(partial suboption???)");
+                   fprintf(NetTrace, "(partial suboption??\?)");
                    break;
                }
                fprintf(NetTrace, "%s|%s",
                    break;
                }
                fprintf(NetTrace, "%s|%s",
@@ -428,7 +458,7 @@ printsub(direction, pointer, length)
                    else
                        fprintf(NetTrace, "%d ", pointer[i]);
                    if (++i >= length) {
                    else
                        fprintf(NetTrace, "%d ", pointer[i]);
                    if (++i >= length) {
-                       fprintf(NetTrace, "(partial suboption???)");
+                       fprintf(NetTrace, "(partial suboption??\?)");
                        break;
                    }
                    fprintf(NetTrace, "%s|%s ",
                        break;
                    }
                    fprintf(NetTrace, "%s|%s ",
@@ -460,7 +490,7 @@ printsub(direction, pointer, length)
        case TELOPT_ENCRYPT:
            fprintf(NetTrace, "ENCRYPT");
            if (length < 2) {
        case TELOPT_ENCRYPT:
            fprintf(NetTrace, "ENCRYPT");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -485,7 +515,7 @@ printsub(direction, pointer, length)
                fprintf(NetTrace, " %s ", (pointer[1] == ENCRYPT_IS) ?
                                                        "IS" : "REPLY");
                if (length < 3) {
                fprintf(NetTrace, " %s ", (pointer[1] == ENCRYPT_IS) ?
                                                        "IS" : "REPLY");
                if (length < 3) {
-                   fprintf(NetTrace, " (partial suboption???)");
+                   fprintf(NetTrace, " (partial suboption??\?)");
                    break;
                }
                if (ENCTYPE_NAME_OK(pointer[2]))
                    break;
                }
                if (ENCTYPE_NAME_OK(pointer[2]))
@@ -530,7 +560,7 @@ printsub(direction, pointer, length)
        case TELOPT_LINEMODE:
            fprintf(NetTrace, "LINEMODE ");
            if (length < 2) {
        case TELOPT_LINEMODE:
            fprintf(NetTrace, "LINEMODE ");
            if (length < 2) {
-               fprintf(NetTrace, " (empty suboption???)");
+               fprintf(NetTrace, " (empty suboption??\?)");
                break;
            }
            switch (pointer[1]) {
                break;
            }
            switch (pointer[1]) {
@@ -547,7 +577,7 @@ printsub(direction, pointer, length)
                fprintf(NetTrace, "DONT ");
            common:
                if (length < 3) {
                fprintf(NetTrace, "DONT ");
            common:
                if (length < 3) {
-                   fprintf(NetTrace, "(no option???)");
+                   fprintf(NetTrace, "(no option??\?)");
                    break;
                }
                switch (pointer[2]) {
                    break;
                }
                switch (pointer[2]) {
@@ -563,7 +593,7 @@ printsub(direction, pointer, length)
                    break;
                }
                break;
                    break;
                }
                break;
-               
+
            case LM_SLC:
                fprintf(NetTrace, "SLC");
                for (i = 2; i < length - 2; i += 3) {
            case LM_SLC:
                fprintf(NetTrace, "SLC");
                for (i = 2; i < length - 2; i += 3) {
@@ -600,7 +630,7 @@ printsub(direction, pointer, length)
            case LM_MODE:
                fprintf(NetTrace, "MODE ");
                if (length < 3) {
            case LM_MODE:
                fprintf(NetTrace, "MODE ");
                if (length < 3) {
-                   fprintf(NetTrace, "(no mode???)");
+                   fprintf(NetTrace, "(no mode??\?)");
                    break;
                }
                {
                    break;
                }
                {
@@ -695,7 +725,7 @@ printsub(direction, pointer, length)
                            fprintf(NetTrace, "\n");
 
                        break;
                            fprintf(NetTrace, "\n");
 
                        break;
-                               
+
                    default:
                        fprintf(NetTrace, " %d", pointer[i]);
                        break;
                    default:
                        fprintf(NetTrace, " %d", pointer[i]);
                        break;
@@ -721,8 +751,14 @@ printsub(direction, pointer, length)
            }
            break;
 
            }
            break;
 
-       case TELOPT_ENVIRON:
-           fprintf(NetTrace, "ENVIRON ");
+       case TELOPT_NEW_ENVIRON:
+           fprintf(NetTrace, "NEW-ENVIRON ");
+#ifdef OLD_ENVIRON
+           goto env_common1;
+       case TELOPT_OLD_ENVIRON:
+           fprintf(NetTrace, "OLD-ENVIRON");
+       env_common1:
+#endif
            switch (pointer[1]) {
            case TELQUAL_IS:
                fprintf(NetTrace, "IS ");
            switch (pointer[1]) {
            case TELQUAL_IS:
                fprintf(NetTrace, "IS ");
@@ -735,28 +771,40 @@ printsub(direction, pointer, length)
            env_common:
                {
                    register int noquote = 2;
            env_common:
                {
                    register int noquote = 2;
-#ifdef ENV_HACK
-                   extern int env_var, env_value;
+#if defined(ENV_HACK) && defined(OLD_ENVIRON)
+                   extern int old_env_var, old_env_value;
 #endif
                    for (i = 2; i < length; i++ ) {
                        switch (pointer[i]) {
 #endif
                    for (i = 2; i < length; i++ ) {
                        switch (pointer[i]) {
-                       case ENV_VAR:
-#ifdef ENV_HACK
-                           if (env_var == ENV_VALUE)
-                               fprintf(NetTrace, "\" (VALUE) " + noquote);
-                           else
-#endif
-                           fprintf(NetTrace, "\" VAR " + noquote);
+                       case NEW_ENV_VALUE:
+#ifdef OLD_ENVIRON
+                    /* case NEW_ENV_OVAR: */
+                           if (pointer[0] == TELOPT_OLD_ENVIRON) {
+# ifdef        ENV_HACK
+                               if (old_env_var == OLD_ENV_VALUE)
+                                   fprintf(NetTrace, "\" (VALUE) " + noquote);
+                               else
+# endif
+                                   fprintf(NetTrace, "\" VAR " + noquote);
+                           } else
+#endif /* OLD_ENVIRON */
+                               fprintf(NetTrace, "\" VALUE " + noquote);
                            noquote = 2;
                            break;
 
                            noquote = 2;
                            break;
 
-                       case ENV_VALUE:
-#ifdef ENV_HACK
-                           if (env_value == ENV_VAR)
-                               fprintf(NetTrace, "\" (VAR) " + noquote);
-                           else
-#endif
-                           fprintf(NetTrace, "\" VALUE " + noquote);
+                       case NEW_ENV_VAR:
+#ifdef OLD_ENVIRON
+                    /* case OLD_ENV_VALUE: */
+                           if (pointer[0] == TELOPT_OLD_ENVIRON) {
+# ifdef        ENV_HACK
+                               if (old_env_value == OLD_ENV_VAR)
+                                   fprintf(NetTrace, "\" (VAR) " + noquote);
+                               else
+# endif
+                                   fprintf(NetTrace, "\" VALUE " + noquote);
+                           } else
+#endif /* OLD_ENVIRON */
+                               fprintf(NetTrace, "\" VAR " + noquote);
                            noquote = 2;
                            break;
 
                            noquote = 2;
                            break;
 
@@ -808,6 +856,8 @@ printsub(direction, pointer, length)
            else
                fprintf(NetTrace, "\n");
        }
            else
                fprintf(NetTrace, "\n");
        }
+       if (NetTrace == stdout)
+           fflush(NetTrace);
     }
 }
 
     }
 }