#include #include #include #include extern jmp_buf Sjbuf; extern int Debug; extern int (*cdf)(); int login_retries; /* how many attempts to log in */ int first_attempt; /* is this the first time we're trying? */ snd_brk() /* send a BREAK to the rs232 port */ { dobreak(1); nap(500L); dobreak(0); } patwait(patt, timeout) /* wait for "patt" to come in from modem */ char *patt; { register int len, i, c; register char buf[128]; int strcmp(), stricmp(); register int (*compare)(); printmsg(10, "expect(%s)", patt); compare = strcmp; while (1) if (strncmp(patt, "\\i", 2) == 0) { compare = stricmp; patt += 2; } else if (strncmp(patt, "\\d", 2) == 0) { patt += 2; for (c=0; isdigit(*patt); patt++) c = (c*10) + (*patt - '0'); timeout = (c < 0) ? 10 : c; } else if (strncmp(patt, "\\RETRY", 6) == 0) { patt += 6; for (c=0; isdigit(*patt); patt++) c = (c*10) + (*patt - '0'); if (first_attempt) login_retries= (c<=0) ? 1 : c; } else break; len = strlen(patt)-1; if (len == 0) { do { if ((c = receive(timeout)) < 0) return 0; c &= 0x7f; if (Debug) putc(c, stderr); if (!(*cdf)()) longjmp(Sjbuf, 1); } while (c != *patt); } else if (len > 0 && strcmp(patt, "\"\"") != 0) { buf[1+len] = 0; do { for(i=0; i 0); if (p) { printmsg(1, "patwait (%s) failed\n", p); return 0; } return 1; } /* login */ fpatwait(msg) char *msg; { char *strchr(); register char *p; repat: if (p = strchr(msg,'-')) *p++ = 0; if (patwait(msg,10)) return 1; else if (msg=p) { if (p=strchr(msg,'-')) *p++ = 0; sendthing(msg); if (msg=p) goto repat; } if (!(*cdf)()) longjmp(Sjbuf, 1); return 0; } sendthing(p) register char *p; { int brkcnt; int cr_at_end = 1; int tmp; printmsg(10, "send(%s)", p); if (strncmp(p,"BREAK",5) == 0) { p += 5; if (isdigit(*p)) { brkcnt = 0; do { brkcnt = (brkcnt*10) + (*p++ - '0'); } while (isdigit(*p)); } else brkcnt = 3; while (brkcnt-- > 0) snd_brk(); } else if (strcmp(p,"EOT") == 0) { ttyout(4); } else if (strncmp(p, "PAUSE", 5) == 0) { p += 5; if (isdigit(*p)) { brkcnt = 0; do { brkcnt = (brkcnt*10) + (*p++ - '0'); } while (isdigit(*p)); } else brkcnt = 5; sleep(brkcnt); } while (*p) { if (*p == '\\' && p[1]) { switch (*++p) { case 'c': cr_at_end = 0; break; case 'd': sleep(1); break; case 'F': flush(); break; case 's': ttyout(' '); break; case 'b': snd_brk(); break; case 'r': ttyout('\r'); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': tmp = 0; do { tmp = (tmp*10) + (*p++ - '0'); } while (isdigit(*p)); ttyout(tmp); --p; break; default: ttyout(*p); } ++p; } else ttyout(*p++); nap(50L); } if (cr_at_end) ttyout('\r'); }