X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=chat%2Fchat.c;h=1f362a2e2aedd88b89d85778474abbdb019435a6;hb=bbaa125b02eedc3133a7db1618adc6b76474bab9;hp=90dcc5be837cac3787c77d9fc5fe66c1bd858699;hpb=39f685ec9a552874cd02b511bbf84b3912b1058b;p=ppp.git diff --git a/chat/chat.c b/chat/chat.c index 90dcc5b..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 . + * * 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 @@ -78,7 +81,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: chat.c,v 1.18 1998/02/04 01:35:49 paulus Exp $"; +static char rcsid[] = "$Id: chat.c,v 1.21 1999/05/12 06:13:22 paulus Exp $"; #endif #include @@ -606,6 +609,11 @@ void break_sequence() void terminate(status) int status; { + static int terminating = 0; + + if (terminating) + exit(status); + terminating = 1; echo_stderr(-1); if (report_file != (char *) 0 && report_fp != (FILE *) NULL) { /* @@ -966,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); @@ -1104,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) @@ -1414,6 +1461,16 @@ register char *string; return (0); } +/* + * Gross kludge to handle Solaris versions >= 2.6 having usleep. + */ +#ifdef SOL2 +#include +#if MAXUID > 65536 /* then this is Solaris 2.6 or later */ +#undef NO_USLEEP +#endif +#endif /* SOL2 */ + #ifdef NO_USLEEP #include #include