| 1 | /* |
| 2 | * Copyright (C) 2021 EfficiOS Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Prettyfi a xml input from stdin to stddout. |
| 10 | * This allows a more human friendly format for xml testing when problems occur. |
| 11 | */ |
| 12 | |
| 13 | #include "common.hpp" |
| 14 | |
| 15 | #include <libxml/parser.h> |
| 16 | #include <unistd.h> |
| 17 | |
| 18 | int main() |
| 19 | { |
| 20 | xmlDocPtr doc = NULL; |
| 21 | |
| 22 | /* Init libxml. */ |
| 23 | xmlInitParser(); |
| 24 | |
| 25 | { |
| 26 | xml_parser_ctx_uptr parserCtx{ xmlNewParserCtxt() }; |
| 27 | |
| 28 | /* Parse the XML document from stdin. */ |
| 29 | doc = xmlCtxtReadFd( |
| 30 | parserCtx.get(), STDIN_FILENO, nullptr, nullptr, XML_PARSE_NOBLANKS); |
| 31 | if (!doc) { |
| 32 | fprintf(stderr, "ERR parsing: xml input invalid"); |
| 33 | return -1; |
| 34 | } |
| 35 | |
| 36 | xmlDocFormatDump(stdout, doc, 1); |
| 37 | |
| 38 | xmlFreeDoc(doc); |
| 39 | } |
| 40 | |
| 41 | /* Shutdown libxml. */ |
| 42 | xmlCleanupParser(); |
| 43 | |
| 44 | return 0; |
| 45 | } |