summaryrefslogtreecommitdiff
path: root/src/reader.c
blob: 787f785db12e0fe0d9b155cda5518c2144fc4241 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53

#define RAW_BUFFER_SIZE 16384
#define BUFFER_SIZE (RAW_BUFFER_SIZE*2) /* Should be enough for decoding 
                                           the whole raw buffer. */

/*
 * Ensure that the buffer contains at least length characters.
 * Return 1 on success, 0 on failure.
 */

int
yaml_parser_update_reader(yaml_parser_t *parser, size_t length)
{
    /* If the EOF flag is set, do nothing. */

    if (parser->eof)
        return 1;

    /* First, let us check that the buffers are allocated. */

    if (!parser->buffer) {
        parser->buffer = yaml_malloc(BUFFER_SIZE);
        if (!parser->buffer) {
            parser->error = YAML_MEMORY_ERROR;
            return 0;
        }
        parser->buffer_size = BUFFER_SIZE;
        parser->buffer_pointer = parser->buffer;
        parser->buffer_length = 0;
    }

    if (!parser->raw_buffer) {
        parser->raw_buffer = yaml_malloc(RAW_BUFFER_SIZE);
        if (!parser->raw_buffer) {
            parser->error = YAML_MEMORY_ERROR;
            return 0;
        }
        parser->raw_buffer_size = RAW_BUFFER_SIZE;
    }

    /* Next, determine the input encoding. */

    if (!parser->encoding) {
        if (!yaml_parser_determine_encoding(parser))
            return 0;
    }

    /* more... */

}