blob: 613e7686b1cb9ab55dff9eb912149aa58abfb782 [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
Radek Krejcie7b95092019-05-15 11:03:07 +020018#include <stdio.h>
Radek Krejcid3ca0632019-04-16 16:54:54 +020019#include <unistd.h>
20
Radek Krejcie7b95092019-05-15 11:03:07 +020021#include "tree_schema.h"
22
Radek Krejcid3ca0632019-04-16 16:54:54 +020023/**
24 * @brief Print schema tree in the specified format into a memory block.
25 * It is up to caller to free the returned string by free().
26 *
27 * @param[out] strp Pointer to store the resulting dump.
28 * @param[in] module Schema tree to print.
29 * @param[in] format Schema output format.
30 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
31 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020032 * @return Number of printed bytes in case of success.
33 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020034 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020035ssize_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 +020036
37/**
38 * @brief Print schema tree in the specified format into a file descriptor.
39 *
40 * @param[in] module Schema tree to print.
41 * @param[in] fd File descriptor where to print the data.
42 * @param[in] format Schema output format.
43 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE format.
44 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020045 * @return Number of printed bytes in case of success.
46 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020047 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020048ssize_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 +020049
50/**
51 * @brief Print schema tree in the specified format into a file stream.
52 *
53 * @param[in] module Schema tree to print.
54 * @param[in] f File stream where to print the schema.
55 * @param[in] format Schema output format.
56 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
57 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020058 * @return Number of printed bytes in case of success.
59 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020060 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020061ssize_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 +020062
63/**
64 * @brief Print schema tree in the specified format into a file.
65 *
66 * @param[in] path File where to print the schema.
67 * @param[in] module Schema tree to print.
68 * @param[in] format Schema output format.
69 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
70 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020071 * @return Number of printed bytes in case of success.
72 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020073 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020074ssize_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 +020075
76/**
77 * @brief Print schema tree in the specified format using a provided callback.
78 *
79 * @param[in] module Schema tree to print.
80 * @param[in] writeclb Callback function to write the data (see write(1)).
81 * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback.
82 * @param[in] format Schema output format.
83 * @param[in] line_length Maximum characters to be printed on a line, 0 for unlimited. Only for #LYS_OUT_TREE printer.
84 * @param[in] options Schema output options (see @ref schemaprinterflags).
Radek Krejci897ad2e2019-04-29 16:43:07 +020085 * @return Number of printed bytes in case of success.
86 * @return Negative value failure (absolute value corresponds to LY_ERR values).
Radek Krejcid3ca0632019-04-16 16:54:54 +020087 */
Radek Krejci897ad2e2019-04-29 16:43:07 +020088ssize_t lys_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
Radek Krejcid3ca0632019-04-16 16:54:54 +020089 const struct lys_module *module, LYS_OUTFORMAT format, int line_length, int options);
90
91#endif /* LY_PRINTER_SCHEMA_H_ */