Source

libyaml / tests / run-parser.c

#include <yaml.h>

#include <stdlib.h>
#include <stdio.h>

#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>

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

    if (argc < 2) {
        printf("Usage: %s file1.yaml ...\n", argv[0]);
        return 0;
    }

    for (idx = 1; idx < argc; idx ++)
    {
        FILE *file;
        yaml_parser_t *parser;
        yaml_event_t event;
        int failed = 0;
        int count = 0;

        printf("[%d] Parsing '%s': ", idx, argv[idx]);
        fflush(stdout);

        file = fopen(argv[idx], "rb");
        assert(file);

        parser = yaml_parser_new();
        assert(parser);

        yaml_parser_set_file_reader(parser, file);

        while (1)
        {
            if (!yaml_parser_parse_event(parser, &event)) {
                failed = 1;
                break;
            }

            if (event.type == YAML_NO_EVENT)
                break;

            yaml_event_destroy(&event);

            count ++;
        }

        if (!failed) {
            printf("SUCCESS (%d tokens)\n", count);
        }
        else {
            yaml_error_t error;
            char message[256];
            yaml_parser_get_error(parser, &error);
            yaml_error_message(&error, message, 256);
            printf("FAILURE (%d events)\n -> %s\n", count, message);
        }

        yaml_parser_delete(parser);

        fclose(file);
    }

    return 0;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.