| Revision 265,
1.4 KB
checked in by xi, 5 years ago
(diff) |
|
Fixed bugs and updated tests.
|
| Line | |
|---|
| 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 | |
|---|
| 11 | int |
|---|
| 12 | main(int argc, char *argv[]) |
|---|
| 13 | { |
|---|
| 14 | int idx; |
|---|
| 15 | |
|---|
| 16 | if (argc < 2) { |
|---|
| 17 | printf("Usage: %s file1.yaml ...\n", argv[0]); |
|---|
| 18 | return 0; |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | for (idx = 1; idx < argc; idx ++) |
|---|
| 22 | { |
|---|
| 23 | FILE *file; |
|---|
| 24 | yaml_parser_t *parser; |
|---|
| 25 | yaml_event_t event; |
|---|
| 26 | int failed = 0; |
|---|
| 27 | int count = 0; |
|---|
| 28 | |
|---|
| 29 | printf("[%d] Parsing '%s': ", idx, argv[idx]); |
|---|
| 30 | fflush(stdout); |
|---|
| 31 | |
|---|
| 32 | file = fopen(argv[idx], "rb"); |
|---|
| 33 | assert(file); |
|---|
| 34 | |
|---|
| 35 | parser = yaml_parser_new(); |
|---|
| 36 | assert(parser); |
|---|
| 37 | |
|---|
| 38 | yaml_parser_set_file_reader(parser, file); |
|---|
| 39 | |
|---|
| 40 | while (1) |
|---|
| 41 | { |
|---|
| 42 | if (!yaml_parser_parse_event(parser, &event)) { |
|---|
| 43 | failed = 1; |
|---|
| 44 | break; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | if (event.type == YAML_NO_EVENT) |
|---|
| 48 | break; |
|---|
| 49 | |
|---|
| 50 | yaml_event_destroy(&event); |
|---|
| 51 | |
|---|
| 52 | count ++; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | if (!failed) { |
|---|
| 56 | printf("SUCCESS (%d tokens)\n", count); |
|---|
| 57 | } |
|---|
| 58 | else { |
|---|
| 59 | yaml_error_t error; |
|---|
| 60 | char message[256]; |
|---|
| 61 | yaml_parser_get_error(parser, &error); |
|---|
| 62 | yaml_error_message(&error, message, 256); |
|---|
| 63 | printf("FAILURE (%d events)\n -> %s\n", count, message); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | yaml_parser_delete(parser); |
|---|
| 67 | |
|---|
| 68 | fclose(file); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | return 0; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.