summaryrefslogtreecommitdiff
path: root/chat
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>1999-05-12 06:13:22 +0000
committerPaul Mackerras <paulus@samba.org>1999-05-12 06:13:22 +0000
commita6f2276a5e205ec00e611391a5899fceca773c4f (patch)
treefbe33c5ec5b607033c448bc22739c71da5714c63 /chat
parent10eadbc0231e7cd7a6a1ce05d8182dcb5a1d252b (diff)
downloadppp-a6f2276a5e205ec00e611391a5899fceca773c4f.tar.gz
Add @filename syntax for the send string
Diffstat (limited to 'chat')
-rw-r--r--chat/chat.812
-rw-r--r--chat/chat.c44
2 files changed, 54 insertions, 2 deletions
diff --git a/chat/chat.8 b/chat/chat.8
index 2612d67..7d4ad5f 100644
--- a/chat/chat.8
+++ b/chat/chat.8
@@ -1,6 +1,6 @@
.\" -*- nroff -*-
.\" manual page [] for chat 1.8
-.\" $Id: chat.8,v 1.7 1998/02/04 01:35:49 paulus Exp $
+.\" $Id: chat.8,v 1.8 1999/05/12 06:13:22 paulus Exp $
.\" SH section heading
.\" SS subsection heading
.\" LP paragraph
@@ -153,6 +153,16 @@ character, you would have to write something like this:
\'# ' logout
.LP
+.SH SENDING DATA FROM A FILE
+If the string to send starts with an at sign (@), the rest of the
+string is taken to be the name of a file to read to get the string to
+send. If the last character of the data read is a newline, it is
+removed. The file can be a named pipe (or fifo) instead of a regular
+file. This provides a way for \fBchat\fR to communicate with another
+program, for example, a program to prompt the user and receive a
+password typed in.
+.LP
+
.SH ABORT STRINGS
Many modems will report the status of the call as a string. These
strings may be \fBCONNECTED\fR or \fBNO CARRIER\fR or \fBBUSY\fR. It
diff --git a/chat/chat.c b/chat/chat.c
index 5ce1336..1f362a2 100644
--- a/chat/chat.c
+++ b/chat/chat.c
@@ -14,6 +14,9 @@
* This software is in the public domain.
*
* -----------------
+ * 12-May-99 added a feature to read data to be sent from a file,
+ * if the send string starts with @. Idea from gpk <gpk@onramp.net>.
+ *
* added -T and -U option and \T and \U substitution to pass a phone
* number into chat script. Two are needed for some ISDN TA applications.
* Keith Dart <kdart@cisco.com>
@@ -78,7 +81,7 @@
*/
#ifndef lint
-static char rcsid[] = "$Id: chat.c,v 1.20 1999/03/31 12:28:16 paulus Exp $";
+static char rcsid[] = "$Id: chat.c,v 1.21 1999/05/12 06:13:22 paulus Exp $";
#endif
#include <stdio.h>
@@ -971,6 +974,8 @@ int c;
void chat_send (s)
register char *s;
{
+ char file_data[STR_LEN];
+
if (say_next) {
say_next = 0;
s = clean(s,0);
@@ -1109,6 +1114,43 @@ register char *s;
return;
}
+ /*
+ * The syntax @filename means read the string to send from the
+ * file `filename'.
+ */
+ if (s[0] == '@') {
+ /* skip the @ and any following white-space */
+ char *fn = s;
+ while (*++fn == ' ' || *fn == '\t')
+ ;
+
+ if (*fn != 0) {
+ FILE *f;
+ int n = 0;
+
+ /* open the file and read until STR_LEN-1 bytes or end-of-file */
+ f = fopen(fn, "r");
+ if (f == NULL)
+ fatal(1, "%s -- open failed: %m", fn);
+ while (n < STR_LEN - 1) {
+ int nr = fread(&file_data[n], 1, STR_LEN - 1 - n, f);
+ if (nr < 0)
+ fatal(1, "%s -- read error", fn);
+ if (nr == 0)
+ break;
+ n += nr;
+ }
+ fclose(f);
+
+ /* use the string we got as the string to send,
+ but trim off the final newline if any. */
+ if (n > 0 && file_data[n-1] == '\n')
+ --n;
+ file_data[n] = 0;
+ s = file_data;
+ }
+ }
+
if (strcmp(s, "EOT") == 0)
s = "^D\\c";
else if (strcmp(s, "BREAK") == 0)