source: libyaml/trunk/tests/run-parser.c @ 208

Revision 208, 789 bytes checked in by xi, 8 years ago (diff)

Refactor internal and external API.

RevLine 
[208]1#include <yaml.h>
2
3#include <stdlib.h>
4#include <stdio.h>
5#include <assert.h>
6
7int
8main(int argc, char *argv[])
9{
10    FILE *file;
11    yaml_parser_t parser;
12    yaml_event_t event;
13    int done = 0;
14    int count = 0;
15
16    if (argc != 2) {
17        printf("Usage: %s file.yaml\n", argv[0]);
18        return 0;
19    }
20    file = fopen(argv[1], "rb");
21    assert(file);
22
23    assert(yaml_parser_initialize(&parser));
24
25    yaml_parser_set_input_file(&parser, file);
26
27    while (!done)
28    {
29        assert(yaml_parser_parse(&parser, &event));
30
31        done = (event.type == YAML_STREAM_END_EVENT);
32
33        yaml_event_delete(&event);
34
35        count ++;
36    }
37
38    yaml_parser_delete(&parser);
39
40    fclose(file);
41
42    printf("Parsing the file '%s': %d events\n", argv[1], count);
43
44    return 0;
45}
46
Note: See TracBrowser for help on using the repository browser.