这个函数的作用?
int getln2(ss,sa,cont,clen,sep)
register substdio *ss;
register stralloc *sa;
/*@out@*/char **cont;
/*@out@*/unsigned int *clen;
int sep;
{
register char *x;
register unsigned int i;
int n;
if (!stralloc_ready(sa,0)) return -1; //stralloc_ready函数为sa分配空间
sa->len = 0;
for (;;) {
n = substdio_feed(ss); //使ss中有可读字节
if (n < 0) return -1;
if (n == 0) { *clen = 0; return 0; }
x = substdio_PEEK(ss); //宏,相当于 x = ( (ss)->x + (ss)->n )
i = byte_chr(x,n,sep); //在x开头往后查找n个字符直到找到sep
if (i < n) { substdio_SEEK(ss,*clen = i + 1); *cont = x; return 0; }
//#define substdio_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) )
if (!stralloc_readyplus(sa,n)) return -1; //应该是为sa中某个char*成员分配n个字符空间
i = sa->len;
sa->len = i + substdio_get(ss,sa->s + i,n);
}
}
-----------------------下面是一些相关函数 我还没看懂如果能顺便一起给解决再好不过了-------------------
int substdio_get(s,buf,len)
register substdio *s;
register char *buf;
register int len;
{
register int r;
if (s->p > 0) return getthis(s,buf,len);
if (s->n <= len) return oneread(s->op,s->fd,buf,len);
r = substdio_feed(s); if (r <= 0) return r;
return getthis(s,buf,len);
}
static int getthis(s,buf,len)
register substdio *s;
register char *buf;
register int len;
{
register int r;
register int q;
r = s->p;
q = r - len;
if (q > 0) { r = len; s->p = q; } else s->p = 0;
byte_copy(buf,r,s->x + s->n); //从s->x + s->n中拷贝r个字符到buf中
s->n += r;
return r;
}
static int oneread(op,fd,buf,len)
register int (*op)();
register int fd;
register char *buf;
register int len;
{
register int r;
for (;;) {
r = op(fd,buf,len);
if (r == -1) if (errno == error_intr) continue;
return r;
}
}
------解决方案--------------------信息不完整...
------解决方案--------------------int getln2(ss,sa,cont,clen,sep)
register substdio *ss;
register stralloc *sa;
/*@out@*/char **cont;
/*@out@*/unsigned int *clen;
int sep;
{
register char *x;
register unsigned int i;
int n;
if (!stralloc_ready(sa,0)) return -1; //stralloc_ready函数为sa分配空间
sa- >len = 0;
for (;;) {
n = substdio_feed(ss); //使ss中有可读字节
if (n < 0) return -1;
if (n == 0) { *clen = 0; return 0; }
x = substdio_PEEK(ss); //宏,相当于 x = ( (ss)- >x + (ss)- >n )
i = byte_chr(x,n,sep); //在x开头往后查找n个字符直到找到sep
if (i < n) { substdio_SEEK(ss,*clen = i + 1); *cont = x; return 0; }
//#define substdio_SEEK(s,len) ( ( (s)- >p -= (len) ) , ( (s)- >n += (len) ) )
if (!stralloc_readyplus(sa,n)) return -1; //应该是为sa中某个char*成员分配n个字符空间
i = sa- >len;
sa- >len = i + substdio_get(ss,sa- >s + i,n); //此处估计为把ss中的数据拷贝到sa->s中的相应位置,并更新其状态计数.
}
}
-----------------------下面是一些相关函数 我还没看懂如果能顺便一起给解决再好不过了-------------------
int substdio_get(s,buf,len)
register substdio *s;
register char *buf;
register int len;
{
register int r;
if (s- >p > 0) return getthis(s,buf,len); //如果s中有数据未处理,这从s->x中拷贝数据到buf中,
if (s- >n <