summaryrefslogtreecommitdiffstats
path: root/test-bufferq.c
blob: 05fc35bad135fafac38a758c30a0940b59074d2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "bufferq.h"

int main(int argc, char *argv[]) {

    sa_bufferq_t q;

    sa_bufferq_init(&q, 1, 1);

    sa_bufferq_push(&q, 0, "{AAAAAAAA}", 10, 0, SA_SEEK_RELATIVE);
    sa_bufferq_push(&q, 0, "<BBBBBBBB>", 10, 5, SA_SEEK_RELATIVE);
    sa_bufferq_push(&q, 0, "[CCCC]", 6, -18, SA_SEEK_RELATIVE);
    sa_bufferq_push(&q, 0, "(DDDD)", 6, -3, SA_SEEK_ABSOLUTE);
    sa_bufferq_push(&q, 0, "XXX", 3, 10, SA_SEEK_RELATIVE_END);
    sa_bufferq_push(&q, 0, "YYYYY", 5, -4, SA_SEEK_RELATIVE);

    for (;;) {
        void *b[1];
        size_t size;
        
        sa_bufferq_get(&q, b, &size);

        if (size == 0)
            break;

        printf("Got %u bytes: ", size);
        if (b[0])
            fwrite(b[0], size, 1, stdout);
        else
            printf("empty");

        printf("\n");

        sa_bufferq_drop(&q, size);
    }
    
    sa_bufferq_done(&q);

    return 0;
}