fehQlibs 26
Qlibs
Loading...
Searching...
No Matches
getln.c
Go to the documentation of this file.
1#include "byte.h"
2#include "getln.h"
3
11int getln(buffer *b,stralloc *sa,int *match,int sep)
12{
13 char *cont;
14 unsigned int clen;
15
16 if (getln2(b,sa,&cont,&clen,sep) == -1) return -1;
17 if (!clen) { *match = 0; return 0; }
18 if (!stralloc_catb(sa,cont,clen)) return -1;
19 *match = 1;
20 return 0;
21}
22
23int getln2(buffer *b,stralloc *sa,char **cont,unsigned int *clen,int sep)
24{
25 char *x;
26 unsigned int i;
27 int n;
28
29 if (!stralloc_ready(sa,0)) return -1;
30 sa->len = 0;
31
32 for (;;) {
33 n = buffer_feed(b);
34 if (n < 0) return -1;
35 if (n == 0) { *clen = 0; return 0; }
36 x = buffer_PEEK(b);
37 i = byte_chr(x,n,sep);
38 if (i < n) { buffer_SEEK(b,*clen = i + 1); *cont = x; return 0; }
39 if (!stralloc_readyplus(sa,n)) return -1;
40 i = sa->len;
41 sa->len = i + buffer_get(b,sa->s + i,n);
42 }
43}
int getln2(buffer *b, stralloc *sa, char **cont, unsigned int *clen, int sep)
Definition: getln.c:23
int getln(buffer *b, stralloc *sa, int *match, int sep)
Definition: getln.c:11
int buffer_get(buffer *, char *, size_t)
Definition: buffer.c:121
int buffer_feed(buffer *)
Definition: buffer.c:97
#define buffer_SEEK(s, len)
Definition: buffer.h:43
#define buffer_PEEK(s)
Definition: buffer.h:42
unsigned int byte_chr(char *, unsigned int, int)
Definition: byte.c:9
int stralloc_catb(stralloc *, const char *, unsigned int)
Definition: stralloc.c:26
int stralloc_ready(stralloc *sa, size_t len)
Definition: stralloc.c:47
int stralloc_readyplus(stralloc *sa, size_t len)
Definition: stralloc.c:61
Definition: buffer.h:5
size_t len
Definition: stralloc.h:19
char * s
Definition: stralloc.h:18