BSD 4_4_Lite2 release
[unix-history] / usr / src / usr.bin / telnet / utilities.c
index 1280d19..06d08a4 100644 (file)
@@ -32,7 +32,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)utilities.c        8.1 (Berkeley) 6/6/93";
+static char sccsid[] = "@(#)utilities.c        8.3 (Berkeley) 5/30/95";
 #endif /* not lint */
 
 #define        TELOPTS
 #endif /* not lint */
 
 #define        TELOPTS
@@ -203,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;
 }
 
@@ -328,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]) {
@@ -350,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]) {
@@ -372,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]) {
@@ -394,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) {
@@ -419,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]) {
@@ -432,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",
@@ -454,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 ",
@@ -486,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]) {
@@ -511,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]))
@@ -556,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]) {
@@ -573,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]) {
@@ -589,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) {
@@ -626,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;
                }
                {
@@ -721,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;
@@ -747,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 ");
@@ -761,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;
 
@@ -834,6 +856,8 @@ printsub(direction, pointer, length)
            else
                fprintf(NetTrace, "\n");
        }
            else
                fprintf(NetTrace, "\n");
        }
+       if (NetTrace == stdout)
+           fflush(NetTrace);
     }
 }
 
     }
 }