www.pudn.com > ASYNC13.rar > WAITFOR.C


/* A module of ASYNCx.LIB version 1.02 */ 
 
#include  
#include  
#include "asyncdef.h" 
 
/************************************************************* 
 Wait for the string pointed to by s to be received on the 
 specified port. Wait for up to between t and t+1 18ths of a 
 second for the string to arrive. If mode is 0, the string 
 must match exactly. If the mode is 1, the case of the 
 received string may vary from that of the string s points to. 
 *************************************************************/ 
int a_waitfor(ASYNC *p,char *s,int t,int mode) 
{unsigned long t0,far *t1; 
 char c,*cp; 
 if (p) 
  {cp=s; 
   t1=(unsigned long far *)MK_FP(0x40,0x6c); 
   t0=*t1; 
   while(*cp && (*t1)-t0<=(unsigned long)t) 
     if (a_icount(p))    /* a character is available from the port       */ 
      {c=a_getc(p);      /* read the character                           */ 
       if (mode)         /* the case of the character does not matter    */ 
         if (toupper(*cp)==toupper(c)) /* this is the right character    */ 
           cp++;         /* point cp to the next character to look for   */ 
         else            /* this is not the right character              */ 
           cp=s;         /* start cp back at the beginning of the string */ 
       else              /* the case of the character does matter        */ 
         if (*cp==c)     /* this is the character I was looking for      */ 
           cp++;         /* point cp to the next character to look for   */ 
         else            /* this is not the right character              */ 
           cp=s;         /* start cp back at the beginning of the string */ 
      } 
   return (int)(*cp);    /* return 0 if the string was found             */ 
  } 
 return -1; 
} /* end of a_waitfor(p,s,t,mode) */