]> git.ozlabs.org Git - ppp.git/commitdiff
Mods from Al Longyear and Robert Geer to add REPORT stuff.
authorPaul Mackerras <paulus@samba.org>
Mon, 12 Jun 1995 11:24:15 +0000 (11:24 +0000)
committerPaul Mackerras <paulus@samba.org>
Mon, 12 Jun 1995 11:24:15 +0000 (11:24 +0000)
chat/Makefile.linux
chat/chat.8
chat/chat.c

index d46583fbb05f5445bc5ad595da2e7c3f43550764..d1a663902ed42bf60c05443761c9cb8b3596c337 100644 (file)
@@ -1,14 +1,13 @@
-#      $Id: Makefile.linux,v 1.1 1995/04/28 05:26:48 paulus Exp $
+#      $Id: Makefile.linux,v 1.2 1995/06/12 11:24:12 paulus Exp $
 
 BINDIR=/usr/etc
 
 CDEF1= -DTERMIOS                       # Use the termios structure
 CDEF2= -DPIDSTRING                     # I like ascii pid values
 
 BINDIR=/usr/etc
 
 CDEF1= -DTERMIOS                       # Use the termios structure
 CDEF2= -DPIDSTRING                     # I like ascii pid values
-CDEF3= -DLOCK_DIR=\"/usr/spool/uucp\"  # Directory for lock file
-CDEF4= -DSIGTYPE=void                  # Standard definition
-CDEF5= -UNO_SLEEP                      # Use the usleep function
-CDEF6= -DFNDELAY=O_NDELAY              # Old name value
-CDEFS= $(CDEF1) $(CDEF2) $(CDEF3) $(CDEF4) $(CDEF5) $(CDEF6)
+CDEF3= -DSIGTYPE=void                  # Standard definition
+CDEF4= -UNO_SLEEP                      # Use the usleep function
+CDEF5= -DFNDELAY=O_NDELAY              # Old name value
+CDEFS= $(CDEF1) $(CDEF2) $(CDEF3) $(CDEF4) $(CDEF5)
 
 CFLAGS=        -O2 -N $(CDEFS)
 
 
 CFLAGS=        -O2 -N $(CDEFS)
 
index 93eb8a6abf8b826fba9ea119e7e3cea3048dfeef..c70eb70cff16aaf0ff81d52631c6ec77345cd154 100644 (file)
@@ -1,12 +1,12 @@
 .\" -*- nroff -*-
 .\" manual page [] for chat 1.8
 .\" -*- nroff -*-
 .\" manual page [] for chat 1.8
-.\" $Id: chat.8,v 1.1 1995/04/28 05:27:25 paulus Exp $
+.\" $Id: chat.8,v 1.2 1995/06/12 11:24:14 paulus Exp $
 .\" SH section heading
 .\" SS subsection heading
 .\" LP paragraph
 .\" IP indented paragraph
 .\" TP hanging label
 .\" SH section heading
 .\" SS subsection heading
 .\" LP paragraph
 .\" IP indented paragraph
 .\" TP hanging label
-.TH CHAT 8 "17 April 1994" "Chat Version 1.8"
+.TH CHAT 8 "5 May 1995" "Chat Version 1.9"
 .SH NAME
 chat \- Automated conversational script with a modem
 .SH SYNOPSIS
 .SH NAME
 chat \- Automated conversational script with a modem
 .SH SYNOPSIS
@@ -30,25 +30,6 @@ have read access to the file. Multiple lines are permitted in the
 file. Space or horizontal tab characters should be used to separate
 the strings.
 .TP
 file. Space or horizontal tab characters should be used to separate
 the strings.
 .TP
-.B -l \fI<lock file>
-Perform the UUCP style locking using the indicated lock file.
-.IP
-If the file could not be created then the \fIchat\fR program will
-fail. The lock file will be deleted only if the \fIchat\fR program
-fails to perform the script for any reason. If the script is
-successful the lock file will be left on the disk. It is expected that
-the lock file will be deleted when the \fIpppd\fR process no longer
-wishes to use the serial device.
-.IP
-The use of a lock file with 
-.I chat
-and 
-\fIpppd\fR\'s
-.I lock
-option should not be used at the same time. They are mutually
-exclusive options and will cause one or the other program to fail to
-achieve the required lock if you use both.
-.TP
 .B -t \fI<timeout>
 Set the timeout for the expected string to be received. If the string
 is not received within the time limit then the reply string is not
 .B -t \fI<timeout>
 Set the timeout for the expected string to be received. If the string
 is not received within the time limit then the reply string is not
@@ -56,6 +37,12 @@ sent. An alternate reply may be sent or the script will fail if there
 is no alternate reply string. A failed script will cause the
 \fIchat\fR program to terminate with a non-zero error code.
 .TP
 is no alternate reply string. A failed script will cause the
 \fIchat\fR program to terminate with a non-zero error code.
 .TP
+.B -r \fI<report file>
+Set the file for output of the report strings. If you use the keyword
+\fIREPORT\fR, the resulting strings are written to this file. If this
+option is not used and you still use \fIREPORT\fR keywords, the
+\fIstderr\fR file is used for the report strings.
+.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
 .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
@@ -80,9 +67,9 @@ allotted, it is to send a break sequence to the remote and then expect the
 string "ogin:". If the first "ogin:" is received then the break sequence is
 not generated.
 .LP
 string "ogin:". If the first "ogin:" is received then the break sequence is
 not generated.
 .LP
-Once it received the login prompt the \fIchat\fR program will send the string ppp
-and then expect the prompt "ssword:". When it receives the prompt for the
-password, it will send the password hello2u2.
+Once it received the login prompt the \fIchat\fR program will send the
+string ppp and then expect the prompt "ssword:". When it receives the
+prompt for the password, it will send the password hello2u2.
 .LP
 A carriage return is normally sent following the reply string. It is not
 expected in the "expect" string unless it is specifically requested by using
 .LP
 A carriage return is normally sent following the reply string. It is not
 expected in the "expect" string unless it is specifically requested by using
@@ -141,6 +128,32 @@ character sequence. The script will then fail because it found a match to
 the abort string. If it received the string \fINO CARRIER\fR, it will abort
 for the same reason. Either string may be received. Either string will
 terminate the \fIchat\fR script.
 the abort string. If it received the string \fINO CARRIER\fR, it will abort
 for the same reason. Either string may be received. Either string will
 terminate the \fIchat\fR script.
+
+.SH REPORT STRINGS
+A \fBreport\fR string is similar to the ABORT string. The difference
+is that the strings, and all characters to the next control character
+such as a carriage return, are written to the report file.
+.LP
+The report strings may be used to isolate the transmission rate of the
+modem's connect string and return the value to the chat user. The
+analysis of the report string logic occurs in conjunction with the
+other string processing such as looking for the expect string. The use
+of the same string for a report and abort sequence is probably not
+very useful, however, it is possible.
+.LP
+The report strings to no change the completion code of the program.
+.LP
+These "report" strings may be specified in the script using the \fIREPORT\fR
+sequence. It is written in the script as in the following example:
+.IP
+REPORT CONNECT ABORT BUSY '' ATDT5551212 CONNECT '' ogin: account
+.LP
+This sequence will expect nothing; and then send the string
+ATDT5551212 to dial the telephone. The expected string is
+\fICONNECT\fR. If the string \fICONNECT\fR is received the remainder
+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 TIMEOUT
 The initial timeout value is 45 seconds. This may be changed using the \fB-t\fR
 parameter.
 .SH TIMEOUT
 The initial timeout value is 45 seconds. This may be changed using the \fB-t\fR
 parameter.
@@ -240,10 +253,55 @@ character.
 Substitute the sequence with the control character represented by C.
 For example, the character DC1 (17) is shown as \^^Q.
 .I (some characters are not valid in expect.)
 Substitute the sequence with the control character represented by C.
 For example, the character DC1 (17) is shown as \^^Q.
 .I (some characters are not valid in expect.)
+.SH TERMINATION CODES
+The \fIchat\fR program will terminate with the following completion
+codes.
+.TP
+.B 0
+The normal termination of the program. This indicates that the script
+was executed without error to the normal conclusion.
+.TP
+.B 1
+One or more of the parameters are invalid or an expect string was too
+large for the internal buffers. This indicates that the program as not
+properly executed.
+.TP
+.B 2
+An error occurred during the execution of the program. This may be due
+to a read or write operation failing for some reason or chat receiving
+a signal such as SIGINT.
+.TP
+.B 3
+A timeout event occurred when there was an \fIexpect\fR string without
+having a "-subsend" string. This may mean that you did not program the
+script correctly for the condition or that some unexpected event has
+occurred and the expected string could not be found.
+.TP
+.B 4
+The first string marked as an \fIABORT\fR condition occurred.
+.TP
+.B 5
+The second string marked as an \fIABORT\fR condition occurred.
+.TP
+.B 6
+The third string marked as an \fIABORT\fR condition occurred.
+.TP
+.B 7
+The fourth string marked as an \fIABORT\fR condition occurred.
+.TP
+.B ...
+The other termination codes are also strings marked as an \fIABORT\fR
+condition.
+.LP
+Using the termination code, it is possible to determine which event
+terminated the script. It is possible to decide if the string "BUSY"
+was received from the modem as opposed to "NO DIAL TONE". While the
+first event may be retried, the second will probably have little
+chance of succeeding during a retry.
 .SH SEE ALSO
 Additional information about \fIchat\fR scripts may be found with UUCP
 .SH SEE ALSO
 Additional information about \fIchat\fR scripts may be found with UUCP
-documentation. The \fIchat\fR script was taken from the ideas proposed by the
-scripts used by the \fIuucico\fR program.
+documentation. The \fIchat\fR script was taken from the ideas proposed
+by the scripts used by the \fIuucico\fR program.
 .LP
 uucico(1), uucp(1)
 .SH COPYRIGHT
 .LP
 uucico(1), uucp(1)
 .SH COPYRIGHT
index b8bbda8e02763f399e2ca8a3c2c7deaf92903515..f7aaabf1a30050d66130078c018a6d469b0b265c 100644 (file)
@@ -2,6 +2,15 @@
  *     Chat -- a program for automatic session establishment (i.e. dial
  *             the phone and log in).
  *
  *     Chat -- a program for automatic session establishment (i.e. dial
  *             the phone and log in).
  *
+ * Standard termination codes:
+ *  0 - successful completion of the script
+ *  1 - invalid argument, expect string too large, etc.
+ *  2 - error on an I/O operation or fatal error condtion.
+ *  3 - timeout waiting for a simple string.
+ *  4 - the first string declared as "ABORT"
+ *  5 - the second string declared as "ABORT"
+ *  6 - ... and so on for successive ABORT strings.
+ *
  *     This software is in the public domain.
  *
  *     Please send all bug reports, requests for information, etc. to:
  *     This software is in the public domain.
  *
  *     Please send all bug reports, requests for information, etc. to:
@@ -9,6 +18,9 @@
  *             Al Longyear (longyear@netcom.com)
  *             (I was the last person to change this code.)
  *
  *             Al Longyear (longyear@netcom.com)
  *             (I was the last person to change this code.)
  *
+ *      Added -r "report file" switch & REPORT keyword.
+ *              Robert Geer <bgeer@xmission.com>
+ *
  *     The original author is:
  *
  *             Karl Fox <karl@MorningStar.Com>
  *     The original author is:
  *
  *             Karl Fox <karl@MorningStar.Com>
  *             1760 Zollinger Road
  *             Columbus, OH  43221
  *             (614)451-1883
  *             1760 Zollinger Road
  *             Columbus, OH  43221
  *             (614)451-1883
+ *
  */
 
  */
 
-static char rcsid[] = "$Id: chat.c,v 1.8 1995/05/19 04:19:29 paulus Exp $";
+static char rcsid[] = "$Id: chat.c,v 1.9 1995/06/12 11:24:15 paulus Exp $";
 
 #include <stdio.h>
 
 #include <stdio.h>
+#include <time.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <errno.h>
@@ -57,7 +71,7 @@ static char rcsid[] = "$Id: chat.c,v 1.8 1995/05/19 04:19:29 paulus Exp $";
 #endif
 
 #ifndef O_NONBLOCK
 #endif
 
 #ifndef O_NONBLOCK
-#define O_NONBLOCK     FNDELAY
+#define O_NONBLOCK     O_NDELAY
 #endif
 
 /*************** Micro getopt() *********************************************/
 #endif
 
 /*************** Micro getopt() *********************************************/
@@ -75,19 +89,31 @@ static int _O = 0;          /* Internal state */
 char *program_name;
 
 #define        MAX_ABORTS              50
 char *program_name;
 
 #define        MAX_ABORTS              50
+#define        MAX_REPORTS             50
 #define        DEFAULT_CHAT_TIMEOUT    45
 
 #define        DEFAULT_CHAT_TIMEOUT    45
 
-int verbose = 0;
-int quiet = 0;
-char *lock_file = (char *)0;
-char *chat_file = (char *)0;
-int timeout = DEFAULT_CHAT_TIMEOUT;
+int verbose       = 0;
+int quiet         = 0;
+int report        = 0;
+int exit_code     = 0;
+FILE* report_fp   = (FILE *) 0;
+char *report_file = (char *) 0;
+char *chat_file   = (char *) 0;
+int timeout       = DEFAULT_CHAT_TIMEOUT;
 
 int have_tty_parameters = 0;
 
 int have_tty_parameters = 0;
+
 #ifdef TERMIO
 #ifdef TERMIO
+#define term_parms struct termio
+#define get_term_param(param) ioctl(0, TCGETA, param)
+#define set_term_param(param) ioctl(0, TCSETA, param)
 struct termio saved_tty_parameters;
 #endif
 struct termio saved_tty_parameters;
 #endif
+
 #ifdef TERMIOS
 #ifdef TERMIOS
+#define term_parms struct termios
+#define get_term_param(param) tcgetattr(0, param)
+#define set_term_param(param) tcsetattr(0, TCSANOW, param)
 struct termios saved_tty_parameters;
 #endif
 
 struct termios saved_tty_parameters;
 #endif
 
@@ -95,6 +121,10 @@ char *abort_string[MAX_ABORTS], *fail_reason = (char *)0,
        fail_buffer[50];
 int n_aborts = 0, abort_next = 0, timeout_next = 0;
 
        fail_buffer[50];
 int n_aborts = 0, abort_next = 0, timeout_next = 0;
 
+char *report_string[MAX_REPORTS] ;
+char  report_buffer[50] ;
+int n_reports = 0, report_next = 0, report_gathering = 0 ; 
+
 void *dup_mem __P((void *b, size_t c));
 void *copy_of __P((char *s));
 void usage __P((void));
 void *dup_mem __P((void *b, size_t c));
 void *copy_of __P((char *s));
 void usage __P((void));
@@ -131,7 +161,9 @@ size_t c;
     {
     void *ans = malloc (c);
     if (!ans)
     {
     void *ans = malloc (c);
     if (!ans)
+        {
        fatal ("memory error!\n");
        fatal ("memory error!\n");
+        }
     memcpy (ans, b, c);
     return ans;
     }
     memcpy (ans, b, c);
     return ans;
     }
@@ -143,7 +175,7 @@ char *s;
     }
 
 /*
     }
 
 /*
- *     chat [ -v ] [ -t timeout ] [ -f chat-file ] \
+ *     chat [ -v ] [ -t timeout ] [ -f chat-file ] [ -r report-file ] \
  *             [...[[expect[-say[-expect...]] say expect[-say[-expect]] ...]]]
  *
  *     Perform a UUCP-dialer-like chat script on stdin and stdout.
  *             [...[[expect[-say[-expect...]] say expect[-say[-expect]] ...]]]
  *
  *     Perform a UUCP-dialer-like chat script on stdin and stdout.
@@ -157,8 +189,10 @@ char **argv;
     char *arg;
 
     program_name = *argv;
     char *arg;
 
     program_name = *argv;
+    tzset();
 
     while (option = OPTION(argc, argv))
 
     while (option = OPTION(argc, argv))
+        {
        switch (option)
            {
            case 'v':
        switch (option)
            {
            case 'v':
@@ -167,42 +201,74 @@ char **argv;
 
            case 'f':
                if (arg = OPTARG(argc, argv))
 
            case 'f':
                if (arg = OPTARG(argc, argv))
+                   {
                    chat_file = copy_of(arg);
                    chat_file = copy_of(arg);
+                   }
                else
                else
+                   {
                    usage();
                    usage();
-
-               break;
-
-           case 'l':
-               if (arg = OPTARG(argc, argv))
-                   lock_file = copy_of(arg);
-               else
-                   usage();
-
+                   }
                break;
 
            case 't':
                if (arg = OPTARG(argc, argv))
                break;
 
            case 't':
                if (arg = OPTARG(argc, argv))
+                   {
                    timeout = atoi(arg);
                    timeout = atoi(arg);
+                   }
                else
                else
+                   {
                    usage();
                    usage();
+                   }
+               break;
 
 
+           case 'r':
+               arg = OPTARG (argc, argv);
+               if (arg)
+                   {
+                   if (report_fp != NULL)
+                       {
+                       fclose (report_fp);
+                       }
+                   report_file = copy_of (arg);
+                   report_fp   = fopen (report_file, "a");
+                   if (report_fp != NULL)
+                       {
+                       if (verbose)
+                           {
+                           fprintf (report_fp, "Opening \"%s\"...\n",
+                                    report_file);
+                           }
+                       report = 1;
+                       }
+                   }
                break;
 
            default:
                usage();
                break;
 
            default:
                usage();
+               break;
            }
            }
+      }
+/*
+ * Default the report file to the stderr location
+ */
+    if (report_fp == NULL)
+        {
+       report_fp = stderr;
+        }
 
 #ifdef ultrix
     openlog("chat", LOG_PID);
 #else
     openlog("chat", LOG_PID | LOG_NDELAY, LOG_LOCAL2);
 
 
 #ifdef ultrix
     openlog("chat", LOG_PID);
 #else
     openlog("chat", LOG_PID | LOG_NDELAY, LOG_LOCAL2);
 
-    if (verbose) {
+    if (verbose)
+        {
        setlogmask(LOG_UPTO(LOG_INFO));
        setlogmask(LOG_UPTO(LOG_INFO));
-    } else {
+        }
+    else
+        {
        setlogmask(LOG_UPTO(LOG_WARNING));
        setlogmask(LOG_UPTO(LOG_WARNING));
-    }
+        }
 #endif
 
     init();
 #endif
 
     init();
@@ -211,9 +277,13 @@ char **argv;
        {
        arg = ARG(argc, argv);
        if (arg != NULL)
        {
        arg = ARG(argc, argv);
        if (arg != NULL)
+           {
            usage();
            usage();
+           }
        else
        else
+           {
            do_file (chat_file);
            do_file (chat_file);
+           }
        }
     else
        {
        }
     else
        {
@@ -222,7 +292,9 @@ char **argv;
            chat_expect(arg);
 
            if (arg = ARG(argc, argv))
            chat_expect(arg);
 
            if (arg = ARG(argc, argv))
+               {
                chat_send(arg);
                chat_send(arg);
+               }
            }
        }
 
            }
        }
 
@@ -241,7 +313,8 @@ char *chat_file;
     char buf [STR_LEN];
     FILE *cfp;
 
     char buf [STR_LEN];
     FILE *cfp;
 
-    if ((cfp = fopen (chat_file, "r")) == NULL)
+    cfp = fopen (chat_file, "r");
+    if (cfp == NULL)
        {
        syslog (LOG_ERR, "%s -- open failed: %m", chat_file);
        terminate (1);
        {
        syslog (LOG_ERR, "%s -- open failed: %m", chat_file);
        terminate (1);
@@ -254,7 +327,9 @@ char *chat_file;
        {
        sp = strchr (buf, '\n');
        if (sp)
        {
        sp = strchr (buf, '\n');
        if (sp)
+           {
            *sp = '\0';
            *sp = '\0';
+           }
 
        linect++;
        sp = buf;
 
        linect++;
        sp = buf;
@@ -280,19 +355,27 @@ char *chat_file;
                        }
                    
                    if (*sp++ == '\\')
                        }
                    
                    if (*sp++ == '\\')
+                       {
                        if (*sp != '\0')
                        if (*sp != '\0')
+                           {
                            ++sp;
                            ++sp;
+                           }
+                       }
                    }
                }
            else
                {
                arg = sp;
                while (*sp != '\0' && *sp != ' ' && *sp != '\t')
                    }
                }
            else
                {
                arg = sp;
                while (*sp != '\0' && *sp != ' ' && *sp != '\t')
+                   {
                    ++sp;
                    ++sp;
+                   }
                }
 
            if (*sp != '\0')
                }
 
            if (*sp != '\0')
+               {
                *sp++ = '\0';
                *sp++ = '\0';
+               }
 
            if (sendflg)
                {
 
            if (sendflg)
                {
@@ -314,7 +397,7 @@ char *chat_file;
 void usage()
     {
     fprintf(stderr, "\
 void usage()
     {
     fprintf(stderr, "\
-Usage: %s [-v] [-t timeout] {-f chat-file || chat-script}\n",
+Usage: %s [-v] [-t timeout] [-r report-file] {-f chat-file | chat-script}\n",
            program_name);
     exit(1);
     }
            program_name);
     exit(1);
     }
@@ -360,7 +443,7 @@ void fatal (msg)
 const char *msg;
     {
     syslog(LOG_ERR, "%s", msg);
 const char *msg;
     {
     syslog(LOG_ERR, "%s", msg);
-    terminate(1);
+    terminate(2);
     }
 
 /*
     }
 
 /*
@@ -372,7 +455,7 @@ void sysfatal (msg)
 const char *msg;
     {
     syslog(LOG_ERR, "%s: %m", msg);
 const char *msg;
     {
     syslog(LOG_ERR, "%s: %m", msg);
-    terminate(1);
+    terminate(2);
     }
 
 int alarmed = 0;
     }
 
 int alarmed = 0;
@@ -388,10 +471,16 @@ int signo;
 
     logflush();
     if ((flags = fcntl(0, F_GETFL, 0)) == -1)
 
     logflush();
     if ((flags = fcntl(0, F_GETFL, 0)) == -1)
+        {
        sysfatal("Can't get file mode flags on stdin");
        sysfatal("Can't get file mode flags on stdin");
+        }
     else
     else
+        {
        if (fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1)
        if (fcntl(0, F_SETFL, flags | O_NONBLOCK) == -1)
+           {
            sysfatal("Can't set file mode flags on stdin");
            sysfatal("Can't set file mode flags on stdin");
+           }
+        }
 
     if (verbose)
        {
 
     if (verbose)
        {
@@ -404,10 +493,16 @@ void unalarm()
     int flags;
 
     if ((flags = fcntl(0, F_GETFL, 0)) == -1)
     int flags;
 
     if ((flags = fcntl(0, F_GETFL, 0)) == -1)
+        {
        sysfatal("Can't get file mode flags on stdin");
        sysfatal("Can't get file mode flags on stdin");
+        }
     else
     else
+        {
        if (fcntl(0, F_SETFL, flags & ~O_NONBLOCK) == -1)
        if (fcntl(0, F_SETFL, flags & ~O_NONBLOCK) == -1)
+           {
            sysfatal("Can't set file mode flags on stdin");
            sysfatal("Can't set file mode flags on stdin");
+           }
+        }
     }
 
 SIGTYPE sigint(signo)
     }
 
 SIGTYPE sigint(signo)
@@ -442,36 +537,29 @@ void init()
 
 void set_tty_parameters()
     {
 
 void set_tty_parameters()
     {
-#ifdef TERMIO
-    struct termio t;
+#if defined(get_term_param)
+    term_parms t;
 
 
-    if (ioctl(0, TCGETA, &t) < 0)
+    if (get_term_param (&t) < 0)
+        {
        sysfatal("Can't get terminal parameters");
        sysfatal("Can't get terminal parameters");
-#endif
-#ifdef TERMIOS
-    struct termios t;
-
-    if (tcgetattr(0, &t) < 0)
-       sysfatal("Can't get terminal parameters");
-#endif
+        }
 
     saved_tty_parameters = t;
 
     saved_tty_parameters = t;
-    have_tty_parameters = 1;
-
-    t.c_iflag |= IGNBRK | ISTRIP | IGNPAR;
-    t.c_oflag  = 0;
-    t.c_lflag  = 0;
-    t.c_cc[VERASE] = t.c_cc[VKILL] = 0;
-    t.c_cc[VMIN] = 1;
-    t.c_cc[VTIME] = 0;
-
-#ifdef TERMIO
-    if (ioctl(0, TCSETA, &t) < 0)
-       sysfatal("Can't set terminal parameters");
-#endif
-#ifdef TERMIOS
-    if (tcsetattr(0, TCSANOW, &t) < 0)
+    have_tty_parameters  = 1;
+
+    t.c_iflag     |= IGNBRK | ISTRIP | IGNPAR;
+    t.c_oflag      = 0;
+    t.c_lflag      = 0;
+    t.c_cc[VERASE] =
+    t.c_cc[VKILL]  = 0;
+    t.c_cc[VMIN]   = 1;
+    t.c_cc[VTIME]  = 0;
+
+    if (set_term_param (&t) < 0)
+        {
        sysfatal("Can't set terminal parameters");
        sysfatal("Can't set terminal parameters");
+        }
 #endif
     }
 
 #endif
     }
 
@@ -485,17 +573,27 @@ void break_sequence()
 void terminate(status)
 int status;
     {
 void terminate(status)
 int status;
     {
-    if (have_tty_parameters &&
-#ifdef TERMIO
-        ioctl(0, TCSETA, &saved_tty_parameters) < 0
-#endif
-#ifdef TERMIOS
-       tcsetattr(0, TCSANOW, &saved_tty_parameters) < 0
-#endif
-       ) {
-       syslog(LOG_ERR, "Can't restore terminal parameters: %m");
-       exit(1);
+    if (report_file != (char *) 0 && report_fp != (FILE *) NULL)
+        {
+       if (verbose)
+           {
+           fprintf (report_fp, "Closing \"%s\".\n", report_file);
+           }
+       fclose (report_fp);
+       report_fp = (FILE*) NULL;
         }
         }
+
+#if defined(get_term_param)
+    if (have_tty_parameters)
+        {
+       if (set_term_param (&saved_tty_parameters) < 0)
+           {
+           syslog(LOG_ERR, "Can't restore terminal parameters: %m");
+           exit(1);
+           }
+        }
+#endif
+
     exit(status);
     }
 
     exit(status);
     }
 
@@ -525,7 +623,9 @@ int sending;
                }
            cur_chr &= 0x1F;
            if (cur_chr != 0)
                }
            cur_chr &= 0x1F;
            if (cur_chr != 0)
+               {
                *s1++ = cur_chr;
                *s1++ = cur_chr;
+               }
            continue;
            }
 
            continue;
            }
 
@@ -554,9 +654,13 @@ int sending;
 
        case 'c':
            if (sending && *s == '\0')
 
        case 'c':
            if (sending && *s == '\0')
+               {
                add_return = 0;
                add_return = 0;
+               }
            else
            else
+               {
                *s1++ = cur_chr;
                *s1++ = cur_chr;
+               }
            break;
 
        case '\\':
            break;
 
        case '\\':
@@ -564,7 +668,9 @@ int sending;
        case 'p':
        case 'd':
            if (sending)
        case 'p':
        case 'd':
            if (sending)
+               {
                *s1++ = '\\';
                *s1++ = '\\';
+               }
 
            *s1++ = cur_chr;
            break;
 
            *s1++ = cur_chr;
            break;
@@ -596,7 +702,9 @@ int sending;
                *s1++ = '\0';
                }
            else
                *s1++ = '\0';
                }
            else
+               {
                *s1++ = 'N';
                *s1++ = 'N';
+               }
            break;
            
        default:
            break;
            
        default:
@@ -617,21 +725,27 @@ int sending;
                if (cur_chr != 0 || sending)
                    {
                    if (sending && (cur_chr == '\\' || cur_chr == 0))
                if (cur_chr != 0 || sending)
                    {
                    if (sending && (cur_chr == '\\' || cur_chr == 0))
+                       {
                        *s1++ = '\\';
                        *s1++ = '\\';
+                       }
                    *s1++ = cur_chr;
                    }
                break;
                }
 
            if (sending)
                    *s1++ = cur_chr;
                    }
                break;
                }
 
            if (sending)
+               {
                *s1++ = '\\';
                *s1++ = '\\';
+               }
            *s1++ = cur_chr;
            break;
            }
        }
 
     if (add_return)
            *s1++ = cur_chr;
            break;
            }
        }
 
     if (add_return)
+        {
        *s1++ = '\r';
        *s1++ = '\r';
+        }
 
     *s1++ = '\0'; /* guarantee closure */
     *s1++ = '\0'; /* terminate the string */
 
     *s1++ = '\0'; /* guarantee closure */
     *s1++ = '\0'; /* terminate the string */
@@ -650,6 +764,12 @@ register char *s;
        return;
        }
 
        return;
        }
 
+    if (strcmp(s, "REPORT") == 0)
+       {
+       ++report_next;
+       return;
+       }
+
     if (strcmp(s, "TIMEOUT") == 0)
        {
        ++timeout_next;
     if (strcmp(s, "TIMEOUT") == 0)
        {
        ++timeout_next;
@@ -661,24 +781,38 @@ register char *s;
        register char *hyphen;
 
        for (hyphen = s; *hyphen; ++hyphen)
        register char *hyphen;
 
        for (hyphen = s; *hyphen; ++hyphen)
+           {
            if (*hyphen == '-')
            if (*hyphen == '-')
+               {
                if (hyphen == s || hyphen[-1] != '\\')
                if (hyphen == s || hyphen[-1] != '\\')
+                   {
                    break;
                    break;
+                   }
+               }
+           }
        
        if (*hyphen == '-')
            {
            *hyphen = '\0';
 
            if (get_string(s))
        
        if (*hyphen == '-')
            {
            *hyphen = '\0';
 
            if (get_string(s))
+               {
                return;
                return;
+               }
            else
                {
                s = hyphen + 1;
 
                for (hyphen = s; *hyphen; ++hyphen)
            else
                {
                s = hyphen + 1;
 
                for (hyphen = s; *hyphen; ++hyphen)
+                   {
                    if (*hyphen == '-')
                    if (*hyphen == '-')
+                       {
                        if (hyphen == s || hyphen[-1] != '\\')
                        if (hyphen == s || hyphen[-1] != '\\')
+                           {
                            break;
                            break;
+                           }
+                       }
+                   }
 
                if (*hyphen == '-')
                    {
 
                if (*hyphen == '-')
                    {
@@ -695,17 +829,25 @@ register char *s;
                }
            }
        else
                }
            }
        else
+           {
            if (get_string(s))
            if (get_string(s))
+               {
                return;
                return;
+               }
            else
                {
                if (fail_reason)
            else
                {
                if (fail_reason)
+                   {
                    syslog(LOG_INFO, "Failed (%s)", fail_reason);
                    syslog(LOG_INFO, "Failed (%s)", fail_reason);
+                   }
                else
                else
+                   {
                    syslog(LOG_INFO, "Failed");
                    syslog(LOG_INFO, "Failed");
+                   }
 
 
-               terminate(1);
+               terminate(exit_code);
                }
                }
+           }
        }
     }
 
        }
     }
 
@@ -719,12 +861,20 @@ int c;
     c &= 0x7F;
 
     if (c < 32)
     c &= 0x7F;
 
     if (c < 32)
+        {
        sprintf(string, "%s^%c", meta, (int)c + '@');
        sprintf(string, "%s^%c", meta, (int)c + '@');
+        }
     else
     else
+        {
        if (c == 127)
        if (c == 127)
+           {
            sprintf(string, "%s^?", meta);
            sprintf(string, "%s^?", meta);
+           }
        else
        else
+           {
            sprintf(string, "%s%c", meta, c);
            sprintf(string, "%s%c", meta, c);
+           }
+        }
 
     return (string);
     }
 
     return (string);
     }
@@ -736,16 +886,18 @@ void chat_send (s)
 register char *s;
     {
     if (abort_next)
 register char *s;
     {
     if (abort_next)
-       {
+        {
        char *s1;
        char *s1;
-
+       
        abort_next = 0;
        abort_next = 0;
-
+       
        if (n_aborts >= MAX_ABORTS)
        if (n_aborts >= MAX_ABORTS)
+           {
            fatal("Too many ABORT strings");
            fatal("Too many ABORT strings");
-
+           }
+       
        s1 = clean(s, 0);
        s1 = clean(s, 0);
-
+       
        if (strlen(s1) > strlen(s)
            || strlen(s1) + 1 > sizeof(fail_buffer))
            {
        if (strlen(s1) > strlen(s)
            || strlen(s1) + 1 > sizeof(fail_buffer))
            {
@@ -760,38 +912,83 @@ register char *s;
            logf("abort on (");
 
            for (s1 = s; *s1; ++s1)
            logf("abort on (");
 
            for (s1 = s; *s1; ++s1)
+               {
                logf(character(*s1));
                logf(character(*s1));
+               }
 
            logf(")\n");
            }
 
            logf(")\n");
            }
+       return;
        }
        }
-    else
-       if (timeout_next)
+
+    if (report_next)
+        {
+       char *s1;
+       
+       report_next = 0;
+       if (n_reports >= MAX_REPORTS)
            {
            {
-           timeout_next = 0;
-           timeout = atoi(s);
+           fatal("Too many REPORT strings");
+           }
+       
+       s1 = clean(s, 0);
+       
+       if (strlen(s1) > strlen(s) || strlen(s1) > sizeof fail_buffer - 1)
+           {
+           syslog(LOG_WARNING, "Illegal or too-long REPORT string ('%s')", s);
+           die();
+           }
+       
+       report_string[n_reports++] = s1;
+       
+       if (verbose)
+           {
+           logf("report (");
+           s1 = s;
+           while (*s1)
+               {
+               logf(character(*s1));
+               ++s1;
+               }
+           logf(")\n");
+           }
+       return;
+        }
 
 
-           if (timeout <= 0)
-               timeout = DEFAULT_CHAT_TIMEOUT;
+    if (timeout_next)
+        {
+       timeout_next = 0;
+       timeout = atoi(s);
+       
+       if (timeout <= 0)
+           {
+           timeout = DEFAULT_CHAT_TIMEOUT;
+           }
 
 
-           if (verbose)
-               {
-               syslog(LOG_INFO, "timeout set to %d seconds", timeout);
-               }
+       if (verbose)
+           {
+           syslog(LOG_INFO, "timeout set to %d seconds", timeout);
            }
            }
-       else
+       return;
+        }
+
+    if (strcmp(s, "EOT") == 0)
+        {
+       s = "^D\\c";
+        }
+    else
+        {
+       if (strcmp(s, "BREAK") == 0)
            {
            {
-           if (strcmp(s, "EOT") == 0)
-               s = "^D\\c";
-           else
-               if (strcmp(s, "BREAK") == 0)
-                   s = "\\K\\c";
-           if ( ! put_string(s))
-               {
-               syslog(LOG_INFO, "Failed");
-               terminate(1);
-               }
+           s = "\\K\\c";
            }
            }
+        }
+
+    if (!put_string(s))
+        {
+       syslog(LOG_INFO, "Failed");
+       terminate(1);
+        }
     }
 
 int get_char()
     }
 
 int get_char()
@@ -802,23 +999,29 @@ int get_char()
     status = read(0, &c, 1);
 
     switch (status)
     status = read(0, &c, 1);
 
     switch (status)
-       {
-       case 1:
-           return ((int)c & 0x7F);
-
-       default:
-           syslog(LOG_WARNING, "warning: read() on stdin returned %d",
-                  status);
+        {
+    case 1:
+       return ((int)c & 0x7F);
 
 
-       case -1:
-           if ((status = fcntl(0, F_GETFL, 0)) == -1)
-               sysfatal("Can't get file mode flags on stdin");
-           else
-               if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
-                   sysfatal("Can't set file mode flags on stdin");
+    default:
+       syslog(LOG_WARNING, "warning: read() on stdin returned %d",
+              status);
 
 
-           return (-1);
-       }
+    case -1:
+       if ((status = fcntl(0, F_GETFL, 0)) == -1)
+           {
+           sysfatal("Can't get file mode flags on stdin");
+           }
+       else
+           {
+           if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
+               {
+               sysfatal("Can't set file mode flags on stdin");
+               }
+           }
+       
+       return (-1);
+        }
     }
 
 int put_char(c)
     }
 
 int put_char(c)
@@ -832,23 +1035,29 @@ int c;
     status = write(1, &ch, 1);
 
     switch (status)
     status = write(1, &ch, 1);
 
     switch (status)
-       {
-       case 1:
-           return (0);
-
-       default:
-           syslog(LOG_WARNING, "warning: write() on stdout returned %d",
-                  status);
-
-       case -1:
-           if ((status = fcntl(0, F_GETFL, 0)) == -1)
-               sysfatal("Can't get file mode flags on stdin");
-           else
-               if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
-                   sysfatal("Can't set file mode flags on stdin");
-
-           return (-1);
-       }
+        {
+    case 1:
+       return (0);
+       
+    default:
+       syslog(LOG_WARNING, "warning: write() on stdout returned %d",
+              status);
+       
+    case -1:
+       if ((status = fcntl(0, F_GETFL, 0)) == -1)
+           {
+           sysfatal("Can't get file mode flags on stdin");
+           }
+       else
+           {
+           if (fcntl(0, F_SETFL, status & ~O_NONBLOCK) == -1)
+               {
+               sysfatal("Can't set file mode flags on stdin");
+               }
+           }
+       
+       return (-1);
+        }
     }
 
 int write_char (c)
     }
 
 int write_char (c)
@@ -858,14 +1067,19 @@ int c;
        {
        extern int errno;
 
        {
        extern int errno;
 
-       alarm(0); alarmed = 0;
+       alarm(0);
+       alarmed = 0;
 
        if (verbose)
            {
            if (errno == EINTR || errno == EWOULDBLOCK)
 
        if (verbose)
            {
            if (errno == EINTR || errno == EWOULDBLOCK)
+               {
                syslog(LOG_INFO, " -- write timed out");
                syslog(LOG_INFO, " -- write timed out");
+               }
            else
            else
+               {
                syslog(LOG_INFO, " -- write failed: %m");
                syslog(LOG_INFO, " -- write failed: %m");
+               }
            }
        return (0);
        }
            }
        return (0);
        }
@@ -882,13 +1096,17 @@ register char *s;
        logf("send (");
 
        if (quiet)
        logf("send (");
 
        if (quiet)
+           {
            logf("??????");
            logf("??????");
+           }
        else
            {
            register char *s1 = s;
 
            for (s1 = s; *s1; ++s1)
        else
            {
            register char *s1 = s;
 
            for (s1 = s; *s1; ++s1)
+               {
                logf(character(*s1));
                logf(character(*s1));
+               }
            }
 
        logf(")\n");
            }
 
        logf(")\n");
@@ -903,7 +1121,9 @@ register char *s;
        if (c != '\\')
            {
            if (!write_char (c))
        if (c != '\\')
            {
            if (!write_char (c))
+               {
                return 0;
                return 0;
+               }
            continue;
            }
 
            continue;
            }
 
@@ -919,7 +1139,7 @@ register char *s;
            break;
 
        case 'p':
            break;
 
        case 'p':
-           usleep(10000); /* 1/100th of a second. */
+           usleep(10000);      /* 1/100th of a second (arg is microseconds) */
            break;
 
        default:
            break;
 
        default:
@@ -956,7 +1176,9 @@ register char *string;
        logf("expect (");
 
        for (s1 = string; *s1; ++s1)
        logf("expect (");
 
        for (s1 = string; *s1; ++s1)
+           {
            logf(character(*s1));
            logf(character(*s1));
+           }
 
        logf(")\n");
        }
 
        logf(")\n");
        }
@@ -964,6 +1186,7 @@ register char *string;
     if (len > STR_LEN)
        {
        syslog(LOG_INFO, "expect string is too long");
     if (len > STR_LEN)
        {
        syslog(LOG_INFO, "expect string is too long");
+       exit_code = 1;
        return 0;
        }
 
        return 0;
        }
 
@@ -977,18 +1200,23 @@ register char *string;
        return (1);
        }
 
        return (1);
        }
 
-    alarm(timeout); alarmed = 0;
+    alarm(timeout);
+    alarmed = 0;
 
     while ( ! alarmed && (c = get_char()) >= 0)
        {
 
     while ( ! alarmed && (c = get_char()) >= 0)
        {
-       int n, abort_len;
+       int n, abort_len, report_len;
 
        if (verbose)
            {
            if (c == '\n')
 
        if (verbose)
            {
            if (c == '\n')
+               {
                logf("\n");
                logf("\n");
+               }
            else
            else
+               {
                logf(character(c));
                logf(character(c));
+               }
            }
 
        *s++ = c;
            }
 
        *s++ = c;
@@ -1002,32 +1230,74 @@ register char *string;
                logf(" -- got it\n");
                }
 
                logf(" -- got it\n");
                }
 
-           alarm(0); alarmed = 0;
+           alarm(0);
+           alarmed = 0;
            return (1);
            }
 
        for (n = 0; n < n_aborts; ++n)
            return (1);
            }
 
        for (n = 0; n < n_aborts; ++n)
+           {
            if (s - temp >= (abort_len = strlen(abort_string[n])) &&
                strncmp(s - abort_len, abort_string[n], abort_len) == 0)
            if (s - temp >= (abort_len = strlen(abort_string[n])) &&
                strncmp(s - abort_len, abort_string[n], abort_len) == 0)
-               {
+               {
                if (verbose)
                    {
                    logf(" -- failed\n");
                    }
                if (verbose)
                    {
                    logf(" -- failed\n");
                    }
-
-               alarm(0); alarmed = 0;
+               
+               alarm(0);
+               alarmed = 0;
+               exit_code = n + 4;
                strcpy(fail_reason = fail_buffer, abort_string[n]);
                return (0);
                strcpy(fail_reason = fail_buffer, abort_string[n]);
                return (0);
-               }
+               }
+           }
+
+       if (!report_gathering)
+           {
+           for (n = 0; n < n_reports; ++n)
+               {
+               if ((report_string[n] != (char*) NULL) &&
+                   s - temp >= (report_len = strlen(report_string[n])) &&
+                   strncmp(s - report_len, report_string[n], report_len) == 0)
+                   {
+                   time_t time_now   = time ((time_t*) NULL);
+                   struct tm* tm_now = localtime (&time_now);
+
+                   strftime (report_buffer, 20, "%b %d %H:%M:%S ", tm_now);
+                   strcat (report_buffer, report_string[n]);
+
+                   report_string[n] = (char *) NULL;
+                   report_gathering = 1;
+                   break;
+                   }
+               }
+           }
+       else
+           {
+           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);
+               }
+           }
 
        if (s >= end)
            {
 
        if (s >= end)
            {
-           strncpy(temp, s - minlen, minlen);
+           strncpy (temp, s - minlen, minlen);
            s = temp + minlen;
            }
 
        if (alarmed && verbose)
            s = temp + minlen;
            }
 
        if (alarmed && verbose)
+           {
            syslog(LOG_WARNING, "warning: alarm synchronization problem");
            syslog(LOG_WARNING, "warning: alarm synchronization problem");
+           }
        }
 
     alarm(0);
        }
 
     alarm(0);
@@ -1035,7 +1305,9 @@ register char *string;
     if (verbose && printed)
        {
        if (alarmed)
     if (verbose && printed)
        {
        if (alarmed)
+           {
            logf(" -- read timed out\n");
            logf(" -- read timed out\n");
+           }
        else
            {
            logflush();
        else
            {
            logflush();
@@ -1043,7 +1315,8 @@ register char *string;
            }
        }
 
            }
        }
 
-    alarmed = 0;
+    exit_code = 3;
+    alarmed   = 0;
     return (0);
     }
 
     return (0);
     }
 
@@ -1063,12 +1336,12 @@ usleep( usec )                            /* returns 0 if ok, else -1 */
     long               usec;           /* delay in microseconds */
 {
     static struct                      /* `timeval' */
     long               usec;           /* delay in microseconds */
 {
     static struct                      /* `timeval' */
-       {
-           long        tv_sec;         /* seconds */
-           long        tv_usec;        /* microsecs */
-       }   delay;          /* _select() timeout */
+        {
+       long    tv_sec;         /* seconds */
+       long    tv_usec;        /* microsecs */
+        } delay;           /* _select() timeout */
 
 
-    delay.tv_sec = usec / 1000000L;
+    delay.tv_sec  = usec / 1000000L;
     delay.tv_usec = usec % 1000000L;
 
     return select( 0, (long *)0, (long *)0, (long *)0, &delay );
     delay.tv_usec = usec % 1000000L;
 
     return select( 0, (long *)0, (long *)0, (long *)0, &delay );