www.pudn.com > ASYNC13.rar > GETS.C
/* A module of ASYNCx.LIB version 1.02 */ #include#include #include "asyncdef.h" /*************************************************************** Get a string from the input buffer of the async port associated with p. Read up to n-1 characters from the port or until a '\r' character is reached. Store the string into the buffer pointed to by s. Spend a maximum of t+1 eighteenths of a second waiting for this string to arrive. If at least one character is successfully received into the string, return the address of the string. If no characters have been read into the string at the end of between t and t+1 eighteenths of a second, return NULL. ***************************************************************/ char *a_gets(char *s,int n,ASYNC *p,int t) {unsigned long t0; /* regulate the time spent in this function */ unsigned long far *t1; word count; /* keeps track of how many bytes have been read */ int eof; /* TRUE only if no characters are received */ char *orgs; /* remembers where we're putting the data */ if (p==NULL) return NULL; t1=(unsigned long far *)MK_FP(0x40,0x6c); /* t1 -> system clock */ t0=*t1; /* t0 = time at the beginning of this function */ count=1; eof=1; /* assume that no characters have will be received */ orgs=s; do {if (p->ibufhead!=p->ibuftail) {eof=0; if ((*s=a_getc(p))!=0) /* add only non-null characters to the string */ {if (*s=='\n') /* ignore '\n' characters */ continue; if (*s=='\r') /* '\r' terminates input */ break; else {s++; count++; } } } } while((*t1)-t0<=(unsigned long)t && count