这个函数的作用?
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 <= len) return oneread(s- >op,s- >fd,buf,len);//估计为:如果s中已经处理的数据不足,则从s->fd中去数据到buf中
r = substdio_feed(s); if (r <= 0) return r;//
return getthis(s,buf,len); //重新从s中取数据到buf中.
}
//这个函数的用途是从s->x中最多取len个字节的数据到buf中,如果s->x中的数据不足,则取剩余的数据;并更新s中的相关计算.
//s->p的值的应该为s->x中还有多少数据未处理.
//s->n的值应该为s->x中已经有多少数据被处理.
//s->x为存放待处理的数据
//r为拷贝了几个字节.
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;
}
//用op函数对fd,buf,len三个参数进行操作.返回操作.估计相当于从fd中取len个数据到buf中,和read(fd,buf,len)类似.
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;
}
}