| 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 <common/scope-exit.hpp> |
| 16 | |
| 17 | #include <iostream> |
| 18 | #include <libxml/parser.h> |
| 19 | #include <unistd.h> |
| 20 | |
| 21 | namespace ll = lttng::libxml; |
| 22 | |
| 23 | int main() |
| 24 | { |
| 25 | const ll::global_parser_context global_parser_context; |
| 26 | const ll::parser_ctx_uptr parserCtx{ xmlNewParserCtxt() }; |
| 27 | |
| 28 | /* Parse the XML document from stdin. */ |
| 29 | const ll::doc_uptr doc{ xmlCtxtReadFd( |
| 30 | parserCtx.get(), STDIN_FILENO, nullptr, nullptr, XML_PARSE_NOBLANKS) }; |
| 31 | if (!doc) { |
| 32 | std::cerr << "Error: invalid XML input on stdin\n"; |
| 33 | return -1; |
| 34 | } |
| 35 | |
| 36 | xmlDocFormatDump(stdout, doc.get(), 1); |
| 37 | |
| 38 | return 0; |
| 39 | } |