|
Last change
on this file since 1355 was
898,
checked in by hartmans, 17 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.2 KB
|
| Rev | Line | |
|---|
| [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 | |
|---|
| 11 | int |
|---|
| 12 | main(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_document_t document; |
|---|
| 26 | int done = 0; |
|---|
| 27 | int count = 0; |
|---|
| 28 | int error = 0; |
|---|
| 29 | |
|---|
| 30 | printf("[%d] Loading '%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_load(&parser, &document)) { |
|---|
| 43 | error = 1; |
|---|
| 44 | break; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | done = (!yaml_document_get_root_node(&document)); |
|---|
| 48 | |
|---|
| 49 | yaml_document_delete(&document); |
|---|
| 50 | |
|---|
| 51 | if (!done) count ++; |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | yaml_parser_delete(&parser); |
|---|
| 55 | |
|---|
| 56 | assert(!fclose(file)); |
|---|
| 57 | |
|---|
| 58 | printf("%s (%d documents)\n", (error ? "FAILURE" : "SUCCESS"), count); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | return 0; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.