]> git.ozlabs.org Git - ppp.git/commitdiff
added echo patch
authorPaul Mackerras <paulus@samba.org>
Wed, 26 Jun 1996 00:51:06 +0000 (00:51 +0000)
committerPaul Mackerras <paulus@samba.org>
Wed, 26 Jun 1996 00:51:06 +0000 (00:51 +0000)
chat/chat.8
chat/chat.c

index c227e79bd2eaab9d8b879ddf54177fe2232ab3a8..c3028d45e17045911b3570a66bb74b864045be28 100644 (file)
@@ -1,6 +1,6 @@
 .\" -*- nroff -*-
 .\" manual page [] for chat 1.8
-.\" $Id: chat.8,v 1.3 1995/12/18 03:32:45 paulus Exp $
+.\" $Id: chat.8,v 1.4 1996/06/26 00:51:05 paulus Exp $
 .\" SH section heading
 .\" SS subsection heading
 .\" LP paragraph
@@ -43,6 +43,12 @@ Set the file for output of the report strings. If you use the keyword
 option is not used and you still use \fIREPORT\fR keywords, the
 \fIstderr\fR file is used for the report strings.
 .TP
+.B -e
+Start with the echo option turned on. Echoing may also be turned on
+or off at specific points in the chat script by using the \fIECHO\fR
+keyword. When echoing is enabled, all output from the modem is echoed
+to \fIstderr\fR.
+.TP
 .B -v
 Request that the \fIchat\fR script be executed in a verbose mode. The
 \fIchat\fR program will then log all text received from the modem and
@@ -164,6 +170,34 @@ ATDT5551212 to dial the telephone. The expected string is
 of the script is executed. In addition the program will write to the
 expect-file the string "CONNECT" plus any characters which follow it
 such as the connection rate.
+.SH ECHO
+The echo options controls whether the output from the modem is echoed
+to \fIstderr\fR. This option may be set with the \fI-e\fR option, but
+it can also be controlled by the \fIECHO\fR keyword. The "expect-send"
+pair \fIECHO\fR \fION\fR enables echoing, and \fIECHO\fR \fIOFF\fR
+disables it. With this keyword you can select which parts of the
+conversation should be visible. For instance, with the following
+script:
+.IP
+ABORT   'BUSY'
+.br
+ABORT   'NO CARIER'
+.br
+''      ATZ
+.br
+OK\\r\\n  ATD1234567
+.br
+\\r\\n    \\c
+.br
+ECHO    ON
+.br
+CONNECT \\c
+.br
+ogin:   account
+.LP
+all output resulting from modem configuration and dialing is not visible,
+but starting with the \fICONNECT\fR (or \fIBUSY\fR) message, everything
+will be echoed.
 .SH TIMEOUT
 The initial timeout value is 45 seconds. This may be changed using the \fB-t\fR
 parameter.
index e74fdfa539c1a430035a5171494e42ab30625508..115ab2d8bdcbba115d25ad4b93cde0b491c2ead3 100644 (file)
@@ -21,6 +21,9 @@
  *      Added -r "report file" switch & REPORT keyword.
  *              Robert Geer <bgeer@xmission.com>
  *
+ *     Added -e "echo" switch & ECHO keyword
+ *             Dick Streefland <dicks@tasking.nl>
+ *
  *     The original author is:
  *
  *             Karl Fox <karl@MorningStar.Com>
@@ -31,7 +34,7 @@
  *
  */
 
-static char rcsid[] = "$Id: chat.c,v 1.11 1996/05/28 00:57:08 paulus Exp $";
+static char rcsid[] = "$Id: chat.c,v 1.12 1996/06/26 00:51:06 paulus Exp $";
 
 #include <stdio.h>
 #include <time.h>
@@ -92,6 +95,7 @@ char *program_name;
 #define        MAX_REPORTS             50
 #define        DEFAULT_CHAT_TIMEOUT    45
 
+int echo          = 0;
 int verbose       = 0;
 int Verbose       = 0;
 int quiet         = 0;
@@ -120,7 +124,7 @@ struct termios saved_tty_parameters;
 
 char *abort_string[MAX_ABORTS], *fail_reason = (char *)0,
        fail_buffer[50];
-int n_aborts = 0, abort_next = 0, timeout_next = 0;
+int n_aborts = 0, abort_next = 0, timeout_next = 0, echo_next = 0;
 
 char *report_string[MAX_REPORTS] ;
 char  report_buffer[50] ;
@@ -140,6 +144,7 @@ SIGTYPE sighup __P((int signo));
 void unalarm __P((void));
 void init __P((void));
 void set_tty_parameters __P((void));
+void echo_stderr __P((int));
 void break_sequence __P((void));
 void terminate __P((int status));
 void do_file __P((char *chat_file));
@@ -196,6 +201,10 @@ char **argv;
         {
        switch (option)
            {
+           case 'e':
+               ++echo;
+               break;
+
            case 'v':
                ++verbose;
                break;
@@ -302,6 +311,25 @@ char **argv;
                }
            }
        }
+/*
+ * Allow the last of the report string to be gathered before we terminate.
+ */
+    while (report_gathering)
+        {
+       int c;
+       c = get_char();
+       if (!iscntrl (c))
+           {
+           int rep_len = strlen (report_buffer);
+           report_buffer[rep_len]     = c;
+           report_buffer[rep_len + 1] = '\0';
+           }
+       else
+           {
+           report_gathering = 0;
+           fprintf (report_fp, "chat:  %s\n", report_buffer);
+           }
+        }
 
     terminate(0);
     }
@@ -402,7 +430,7 @@ char *chat_file;
 void usage()
     {
     fprintf(stderr, "\
-Usage: %s [-v] [-t timeout] [-r report-file] {-f chat-file | chat-script}\n",
+Usage: %s [-e] [-v] [-t timeout] [-r report-file] {-f chat-file | chat-script}\n",
            program_name);
     exit(1);
     }
@@ -578,6 +606,7 @@ void break_sequence()
 void terminate(status)
 int status;
     {
+    echo_stderr(-1);
     if (report_file != (char *) 0 && report_fp != (FILE *) NULL)
         {
        if (verbose)
@@ -764,50 +793,56 @@ int sending;
 char *expect_strtok (s, term)
 char *s, *term;
     {
-    static char *str        = "";
-    static int escape_flag = 0;
+    static  char *str   = "";
+    int            escape_flag = 0;
     char   *result;
 /*
  * If a string was specified then do initial processing.
  */
     if (s)
        {
-       str         = s;
-       escape_flag = 0;
+       str = s;
        }
+/*
+ * If this is the escape flag then reset it and ignore the character.
+ */
+    if (*str)
+        {
+       result = str;
+        }
+    else
+        {
+       result = (char *) 0;
+        }
 
-    result = (char *) 0;
     while (*str)
        {
-/*
- * Look for the terminator sequence.
- * If the escape flag is set then this character is not the terminator.
- * We assume that term does not contain the backslash character.
- */
-       if (escape_flag || strchr (term, *str) == (char *) 0)
+       if (escape_flag)
            {
-           if (result == (char *) 0)
-               {
-               result = str;
-               }
-
-           if (escape_flag || *str == '\\')
-               {
-               escape_flag = !escape_flag;
-               }
+           escape_flag = 0;
+           ++str;
+           continue;
+           }
 
+       if (*str == '\\')
+           {
            ++str;
+           escape_flag = 1;
            continue;
            }
 /*
- * This is the terminator. If we have a string then this is the end of the
- * scan operation.
+ * If this is not in the termination string, continue.
  */
-       *str++ = '\0';
-       if (result)
+       if (strchr (term, *str) == (char *) 0)
            {
-           break;
+           ++str;
+           continue;
            }
+/*
+ * This is the terminator. Mark the end of the string and stop.
+ */
+       *str++ = '\0';
+       break;
        }
     return (result);
     }
@@ -839,6 +874,12 @@ char *s;
        ++timeout_next;
        return;
        }
+
+    if (strcmp(s, "ECHO") == 0)
+       {
+       ++echo_next;
+       return;
+       }
 /*
  * Fetch the expect and reply string.
  */
@@ -924,6 +965,12 @@ int c;
 void chat_send (s)
 register char *s;
     {
+    if (echo_next)
+       {
+       echo_next = 0;
+       echo = (strcmp(s, "ON") == 0);
+       return;
+       }
     if (abort_next)
         {
        char *s1;
@@ -1193,6 +1240,37 @@ register char *s;
     return (1);
     }
 
+/*
+ *     Echo a character to stderr.
+ *     When called with -1, a '\n' character is generated when
+ *     the cursor is not at the beginning of a line.
+ */
+void echo_stderr(n)
+int n;
+    {
+       static int need_lf;
+       char *s;
+
+       switch (n)
+           {
+       case '\r':              /* ignore '\r' */
+           break;
+       case -1:
+           if (need_lf == 0)
+               break;
+           /* fall through */
+       case '\n':
+           write(2, "\n", 1);
+           need_lf = 0;
+           break;
+       default:
+           s = character(n);
+           write(2, s, strlen(s));
+           need_lf = 1;
+           break;
+           }
+    }
+
 /*
  *     'Wait for' this string to appear on this file descriptor.
  */
@@ -1246,6 +1324,10 @@ register char *string;
        {
        int n, abort_len, report_len;
 
+       if (echo)
+           {
+           echo_stderr(c);
+           }
        if (verbose)
            {
            if (c == '\n')