blob: 7ad615446181a261634b133fbfa932f9512c6c48 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_schema.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Schema printers for libyang
5 *
6 * Copyright (c) 2015-2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_PRINTER_SCHEMA_H_
16#define LY_PRINTER_SCHEMA_H_
17
18#include <unistd.h>
19
20/**
21 * @brief Print schema tree in the specified format into a memory block.
22 * It is up to caller to free the returned string by free().
23 *
24 * @param[out] strp Pointer to store the resulting dump.
25 * @param[in] module Schema tree to print.
26 * @param[in] format Schema output format.
27 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
28 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020029 * @return Number of printed bytes in case of success.
30 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020031 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020032ssize_t lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020033
34/**
35 * @brief Print schema tree in the specified format into a file descriptor.
36 *
37 * @param[in] module Schema tree to print.
38 * @param[in] fd File descriptor where to print the data.
39 * @param[in] format Schema output format.
40 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE format.
41 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020042 * @return Number of printed bytes in case of success.
43 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020044 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020045ssize_t lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020046
47/**
48 * @brief Print schema tree in the specified format into a file stream.
49 *
50 * @param[in] module Schema tree to print.
51 * @param[in] f File stream where to print the schema.
52 * @param[in] format Schema output format.
53 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
54 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020055 * @return Number of printed bytes in case of success.
56 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020057 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020058ssize_t lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020059
60/**
61 * @brief Print schema tree in the specified format into a file.
62 *
63 * @param[in] path File where to print the schema.
64 * @param[in] module Schema tree to print.
65 * @param[in] format Schema output format.
66 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
67 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020068 * @return Number of printed bytes in case of success.
69 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020070 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020071ssize_t lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
Radek Krejcid3ca0632019-04-16 16:54:54 +020072
73/**
74 * @brief Print schema tree in the specified format using a provided callback.
75 *
76 * @param[in] module Schema tree to print.
77 * @param[in] writeclb Callback function to write the data (see write(1)).
78 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
79 * @param[in] format Schema output format.
80 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
81 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020082 * @return Number of printed bytes in case of success.
83 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020084 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020085ssize_t lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
Radek Krejcid3ca0632019-04-16 16:54:54 +020086 const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
87
88#endif /* LY_PRINTER_SCHEMA_H_ */