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