| Revision 210,
1.1 KB
checked in by xi, 7 years ago
(diff) |
|
Fix some leaks, segfaults and warnings.
|
| Line | |
|---|
| 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 | { |
|---|
| 10 | int number; |
|---|
| 11 | |
|---|
| 12 | if (argc < 2) { |
|---|
| 13 | printf("Usage: %s file1.yaml ...\n", argv[0]); |
|---|
| 14 | return 0; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 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; |
|---|
| 25 | |
|---|
| 26 | printf("[%d] Scanning '%s': ", number, argv[number]); |
|---|
| 27 | fflush(stdout); |
|---|
| 28 | |
|---|
| 29 | file = fopen(argv[number], "rb"); |
|---|
| 30 | assert(file); |
|---|
| 31 | |
|---|
| 32 | assert(yaml_parser_initialize(&parser)); |
|---|
| 33 | |
|---|
| 34 | yaml_parser_set_input_file(&parser, file); |
|---|
| 35 | |
|---|
| 36 | while (!done) |
|---|
| 37 | { |
|---|
| 38 | if (!yaml_parser_scan(&parser, &token)) { |
|---|
| 39 | error = 1; |
|---|
| 40 | break; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | done = (token.type == YAML_STREAM_END_TOKEN); |
|---|
| 44 | |
|---|
| 45 | yaml_token_delete(&token); |
|---|
| 46 | |
|---|
| 47 | count ++; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | yaml_parser_delete(&parser); |
|---|
| 51 | |
|---|
| 52 | assert(!fclose(file)); |
|---|
| 53 | |
|---|
| 54 | printf("%s (%d tokens)\n", (error ? "FAILURE" : "SUCCESS"), count); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | return 0; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.