| 1 | #include "substdio.h" |
| 2 | #include "stralloc.h" |
| 3 | #include "byte.h" |
| 4 | #include "getln.h" |
| 5 | |
| 6 | int getln2(ss,sa,cont,clen,sep) |
| 7 | register substdio *ss; |
| 8 | register stralloc *sa; |
| 9 | /*@out@*/char **cont; |
| 10 | /*@out@*/unsigned int *clen; |
| 11 | int sep; |
| 12 | { |
| 13 | register char *x; |
| 14 | register unsigned int i; |
| 15 | int n; |
| 16 | |
| 17 | if (!stralloc_ready(sa,0)) return -1; |
| 18 | sa->len = 0; |
| 19 | |
| 20 | for (;;) { |
| 21 | n = substdio_feed(ss); |
| 22 | if (n < 0) return -1; |
| 23 | if (n == 0) { *clen = 0; return 0; } |
| 24 | x = substdio_PEEK(ss); |
| 25 | i = byte_chr(x,n,sep); |
| 26 | if (i < n) { substdio_SEEK(ss,*clen = i + 1); *cont = x; return 0; } |
| 27 | if (!stralloc_readyplus(sa,n)) return -1; |
| 28 | i = sa->len; |
| 29 | sa->len = i + substdio_get(ss,sa->s + i,n); |
| 30 | } |
| 31 | } |