|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @file printer.h
|
|
Packit |
8fb591 |
* @author Radek Krejci <rkrejci@cesnet.cz>
|
|
Packit |
8fb591 |
* @brief Printers for libyang
|
|
Packit |
8fb591 |
*
|
|
Packit |
8fb591 |
* Copyright (c) 2015 CESNET, z.s.p.o.
|
|
Packit |
8fb591 |
*
|
|
Packit |
8fb591 |
* This source code is licensed under BSD 3-Clause License (the "License").
|
|
Packit |
8fb591 |
* You may not use this file except in compliance with the License.
|
|
Packit |
8fb591 |
* You may obtain a copy of the License at
|
|
Packit |
8fb591 |
*
|
|
Packit |
8fb591 |
* https://opensource.org/licenses/BSD-3-Clause
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
#ifndef LY_PRINTER_H_
|
|
Packit |
8fb591 |
#define LY_PRINTER_H_
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
#include "libyang.h"
|
|
Packit |
8fb591 |
#include "tree_schema.h"
|
|
Packit |
8fb591 |
#include "tree_internal.h"
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
typedef enum LYOUT_TYPE {
|
|
Packit |
8fb591 |
LYOUT_FD, /**< file descriptor */
|
|
Packit |
8fb591 |
LYOUT_STREAM, /**< FILE stream */
|
|
Packit |
8fb591 |
LYOUT_MEMORY, /**< memory */
|
|
Packit |
8fb591 |
LYOUT_CALLBACK /**< print via provided callback */
|
|
Packit |
8fb591 |
} LYOUT_TYPE;
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
struct lyout {
|
|
Packit |
8fb591 |
LYOUT_TYPE type;
|
|
Packit |
8fb591 |
union {
|
|
Packit |
8fb591 |
int fd;
|
|
Packit |
8fb591 |
FILE *f;
|
|
Packit |
8fb591 |
struct {
|
|
Packit |
8fb591 |
char *buf;
|
|
Packit |
8fb591 |
size_t len;
|
|
Packit |
8fb591 |
size_t size;
|
|
Packit |
8fb591 |
} mem;
|
|
Packit |
8fb591 |
struct {
|
|
Packit |
8fb591 |
ssize_t (*f)(void *arg, const void *buf, size_t count);
|
|
Packit |
8fb591 |
void *arg;
|
|
Packit |
8fb591 |
} clb;
|
|
Packit |
8fb591 |
} method;
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* buffer for holes */
|
|
Packit |
8fb591 |
char *buffered;
|
|
Packit |
8fb591 |
size_t buf_len;
|
|
Packit |
8fb591 |
size_t buf_size;
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* hole counter */
|
|
Packit |
8fb591 |
size_t hole_count;
|
|
Packit |
8fb591 |
};
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
struct ext_substmt_info_s {
|
|
Packit |
8fb591 |
const char *name;
|
|
Packit |
8fb591 |
const char *arg;
|
|
Packit |
8fb591 |
int flags;
|
|
Packit |
8fb591 |
#define SUBST_FLAG_YIN 0x1 /**< has YIN element */
|
|
Packit |
8fb591 |
#define SUBST_FLAG_ID 0x2 /**< the value is identifier -> no quotes */
|
|
Packit |
8fb591 |
};
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* filled in printer.c */
|
|
Packit |
8fb591 |
extern struct ext_substmt_info_s ext_substmt_info[];
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* @brief Generic printer, replacement for printf() / write() / etc
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
int ly_print(struct lyout *out, const char *format, ...);
|
|
Packit |
8fb591 |
void ly_print_flush(struct lyout *out);
|
|
Packit |
8fb591 |
int ly_write(struct lyout *out, const char *buf, size_t count);
|
|
Packit |
8fb591 |
int ly_write_skip(struct lyout *out, size_t count, size_t *position);
|
|
Packit |
8fb591 |
int ly_write_skipped(struct lyout *out, size_t position, const char *buf, size_t count);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* prefix_kind: 0 - print import prefixes for foreign features, 1 - print module names, 2 - print prefixes (tree printer), 3 - print module names including revisions (JSONS printer) */
|
|
Packit |
8fb591 |
int ly_print_iffeature(struct lyout *out, const struct lys_module *module, struct lys_iffeature *expr, int prefix_kind);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int yang_print_model(struct lyout *out, const struct lys_module *module);
|
|
Packit |
8fb591 |
int yin_print_model(struct lyout *out, const struct lys_module *module);
|
|
Packit |
8fb591 |
int tree_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path, int line_length, int options);
|
|
Packit |
8fb591 |
int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path);
|
|
Packit |
8fb591 |
int jsons_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int json_print_data(struct lyout *out, const struct lyd_node *root, int options);
|
|
Packit |
8fb591 |
int xml_print_data(struct lyout *out, const struct lyd_node *root, int options);
|
|
Packit |
8fb591 |
int xml_print_node(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options);
|
|
Packit |
8fb591 |
int lyb_print_data(struct lyout *out, const struct lyd_node *root, int options);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
int lys_print_target(struct lyout *out, const struct lys_module *module, const char *target_schema_path,
|
|
Packit |
8fb591 |
void (*clb_print_typedef)(struct lyout*, const struct lys_tpdf*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_identity)(struct lyout*, const struct lys_ident*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_feature)(struct lyout*, const struct lys_feature*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_type)(struct lyout*, const struct lys_type*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_grouping)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_container)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_choice)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_leaf)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_leaflist)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_list)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_anydata)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_case)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_notif)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_rpc)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_action)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_input)(struct lyout*, const struct lys_node*, int*),
|
|
Packit |
8fb591 |
void (*clb_print_output)(struct lyout*, const struct lys_node*, int*));
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/**
|
|
Packit |
8fb591 |
* get know if the node is supposed to be printed according to the specified with-default mode
|
|
Packit |
8fb591 |
* return 1 - print, 0 - do not print
|
|
Packit |
8fb591 |
*/
|
|
Packit |
8fb591 |
int lyd_wd_toprint(const struct lyd_node *node, int options);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
/* 0 - same, 1 - different */
|
|
Packit |
8fb591 |
int nscmp(const struct lyd_node *node1, const struct lyd_node *node2);
|
|
Packit |
8fb591 |
|
|
Packit |
8fb591 |
#endif /* LY_PRINTER_H_ */
|