Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 1 | #include <stdio.h> |
Lawrence Tang | 368e0b4 | 2022-07-07 14:31:06 +0100 | [diff] [blame] | 2 | #include "../cper-parse.h" |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 3 | #include "json.h" |
Lawrence Tang | 8a2d737 | 2022-07-12 16:44:49 +0100 | [diff] [blame] | 4 | #include "../json-schema.h" |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 5 | |
| 6 | int main(int argc, char* argv[]) { |
Lawrence Tang | f0f9557 | 2022-07-07 16:56:22 +0100 | [diff] [blame] | 7 | |
| 8 | //Get a handle for the log file. |
| 9 | FILE* cper_file = fopen(argv[1], "r"); |
| 10 | if (cper_file == NULL) { |
| 11 | printf("Could not open CPER record, file handle returned null."); |
| 12 | return -1; |
| 13 | } |
| 14 | |
| 15 | json_object* ir = cper_to_ir(cper_file); |
| 16 | fclose(cper_file); |
| 17 | |
Lawrence Tang | 8a2d737 | 2022-07-12 16:44:49 +0100 | [diff] [blame] | 18 | const char* json_output = json_object_to_json_string(ir); |
| 19 | printf("\n%s\n", json_output); |
| 20 | |
| 21 | //Test JSON validator. |
| 22 | if (argc >= 3) |
| 23 | { |
| 24 | printf("Validating output with specification %s...\n", argv[2]); |
Lawrence Tang | 8f793ac | 2022-07-13 10:17:09 +0100 | [diff] [blame] | 25 | validate_schema_debug_enable(); |
| 26 | char* error_message = malloc(JSON_ERROR_MSG_MAX_LEN); |
Lawrence Tang | 8a2d737 | 2022-07-12 16:44:49 +0100 | [diff] [blame] | 27 | if (!validate_schema_from_file(argv[2], ir, error_message)) |
| 28 | { |
| 29 | printf("Validation failed: %s\n", error_message); |
| 30 | } |
| 31 | else |
| 32 | { |
| 33 | printf("Validation passed!\n"); |
| 34 | } |
| 35 | } |
Lawrence Tang | 1b0b00e | 2022-07-05 10:33:10 +0100 | [diff] [blame] | 36 | } |