source: trunk/packages/libyaml/tests/run-scanner.c @ 906

Last change on this file since 906 was 898, checked in by hartmans, 16 years ago

Add pyyaml and libyaml packages
backported from lenny.
There is discussion about how these should go in the repository; these are added in this form
in order to make forward progress.

File size: 1.1 KB
RevLine 
[898]1#include <yaml.h>
2
3#include <stdlib.h>
4#include <stdio.h>
5
6#ifdef NDEBUG
7#undef NDEBUG
8#endif
9#include <assert.h>
10
11int
12main(int argc, char *argv[])
13{
14    int number;
15
16    if (argc < 2) {
17        printf("Usage: %s file1.yaml ...\n", argv[0]);
18        return 0;
19    }
20
21    for (number = 1; number < argc; number ++)
22    {
23        FILE *file;
24        yaml_parser_t parser;
25        yaml_token_t token;
26        int done = 0;
27        int count = 0;
28        int error = 0;
29
30        printf("[%d] Scanning '%s': ", number, argv[number]);
31        fflush(stdout);
32
33        file = fopen(argv[number], "rb");
34        assert(file);
35
36        assert(yaml_parser_initialize(&parser));
37
38        yaml_parser_set_input_file(&parser, file);
39
40        while (!done)
41        {
42            if (!yaml_parser_scan(&parser, &token)) {
43                error = 1;
44                break;
45            }
46
47            done = (token.type == YAML_STREAM_END_TOKEN);
48
49            yaml_token_delete(&token);
50
51            count ++;
52        }
53
54        yaml_parser_delete(&parser);
55
56        assert(!fclose(file));
57
58        printf("%s (%d tokens)\n", (error ? "FAILURE" : "SUCCESS"), count);
59    }
60
61    return 0;
62}
63
Note: See TracBrowser for help on using the repository browser.