static int expect_str(char *str, int fn) { static char rdvec[MR]; char *rp = rdvec; int kr, c; char nextch; *rp = 0; CDEBUG(4, "expect: (%s", ""); for (c = 0; (kr = str[c]) != 0; c++) if (kr < 040) { /*EMPTY*/ CDEBUG(4, "^%c", kr | 0100); } else { /*EMPTY*/ CDEBUG(4, "%c", kr); } CDEBUG(4, ")\n%s", ""); if (EQUALS(str, "\"\"")) { CDEBUG(4, "got it\n%s", ""); return (0); } if (*str == '\0') return (0); if (setjmp(Sjbuf)) return (FAIL); (void) signal(SIGALRM, alarmtr); (void) alarm(expecttime); while (notin(str, rdvec)) { errno = 0; kr = (*Read)(fn, &nextch, 1); if (kr <= 0) { (void) alarm(0); CDEBUG(4, "lost line errno - %d\n", errno); logent("LOGIN", "LOST LINE"); return (FAIL); } c = nextch & 0177; CDEBUG(4, "%s", c < 040 ? "^" : ""); CDEBUG(4, "%c", c < 040 ? c | 0100 : c); if ((*rp = nextch & 0177) != NULLCHAR) rp++; if (rp >= rdvec + MR) { CDEBUG(4, "enough already\n%s", ""); (void) alarm(0); return (FAIL); } *rp = NULLCHAR; } (void) alarm(0); CDEBUG(4, "got it\n%s", ""); return (0); }
static int expect(char *cp) { char buf[300]; char *rp = buf; int timeout = 30, online = 0; if (strcmp(cp, "\"\"") == 0) return (1); *rp = 0; /* * If we are waiting for the Vadic to complete * dialing and get a connection, allow more time * Unfortunately, the Vadic times out 24 seconds after * the last digit is dialed */ online = strcmp(cp, "ON LINE") == 0; if (online) timeout = number(value(DIALTIMEOUT)); signal(SIGALRM, alarmtr); if (setjmp(Sjbuf)) return (0); alarm(timeout); while (notin(cp, buf) && rp < buf + sizeof (buf) - 1) { if (online && notin("FAILED CALL", buf) == 0) return (0); if (read(FD, rp, 1) < 0) { alarm(0); return (0); } if (*rp &= 0177) rp++; *rp = '\0'; } alarm(0); return (1); }
void cgoto(void) { int i, j, s; int npos, curpos, n; int tryit; uint8_t tch[NCH]; int tst[NCH]; uint8_t *q; /* generate initial state, for each start condition */ Bprint(&fout,"int yyvstop[] = {\n0,\n"); while(stnum < 2 || stnum/2 < sptr){ for(i = 0; i<tptr; i++) tmpstat[i] = 0; count = 0; if(tptr > 0)first(tptr-1); add(state,stnum); # ifdef DEBUG if(debug){ if(stnum > 1) print("%s:\n",sname[stnum/2]); pstate(stnum); } # endif stnum++; } stnum--; /* even stnum = might not be at line begin */ /* odd stnum = must be at line begin */ /* even states can occur anywhere, odd states only at line begin */ for(s = 0; s <= stnum; s++){ tryit = FALSE; cpackflg[s] = FALSE; sfall[s] = -1; acompute(s); for(i=0;i<NCH;i++) symbol[i] = 0; npos = *state[s]; for(i = 1; i<=npos; i++){ curpos = *(state[s]+i); if(name[curpos] < NCH) symbol[name[curpos]] = TRUE; else switch(name[curpos]){ case RCCL: tryit = TRUE; q = ptr[curpos]; while(*q){ for(j=1;j<NCH;j++) if(cindex[j] == *q) symbol[j] = TRUE; q++; } break; case RSTR: symbol[right[curpos]] = TRUE; break; # ifdef DEBUG case RNULLS: case FINAL: case S1FINAL: case S2FINAL: break; default: warning("bad switch cgoto %d state %d",curpos,s); break; # endif } } # ifdef DEBUG if(debug){ print("State %d transitions on:\n\t",s); charc = 0; for(i = 1; i<NCH; i++){ if(symbol[i]) allprint(i); if(charc > LINESIZE){ charc = 0; print("\n\t"); } } print("\n"); } # endif /* for each char, calculate next state */ n = 0; for(i = 1; i<NCH; i++){ if(symbol[i]){ nextstate(s,i); /* executed for each state, transition pair */ xstate = notin(stnum); if(xstate == -2) warning("bad state %d %o",s,i); else if(xstate == -1){ if(stnum >= nstates) error("Too many states %s",(nstates == NSTATES ? "\nTry using %n num":"")); add(state,++stnum); # ifdef DEBUG if(debug)pstate(stnum); # endif tch[n] = i; tst[n++] = stnum; } else { /* xstate >= 0 ==> state exists */ tch[n] = i; tst[n++] = xstate; } } } tch[n] = 0; tst[n] = -1; /* pack transitions into permanent array */ if(n > 0) packtrans(s,tch,tst,n,tryit); else gotof[s] = -1; } Bprint(&fout,"0};\n"); }