File: printer.h

package info (click to toggle)
libyang 0.16.105-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 14,544 kB
  • sloc: ansic: 96,743; xml: 9,300; cpp: 5,023; python: 1,637; java: 1,448; lex: 281; sh: 158; makefile: 72
file content (116 lines) | stat: -rw-r--r-- 5,052 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
 * @file printer.h
 * @author Radek Krejci <rkrejci@cesnet.cz>
 * @brief Printers for libyang
 *
 * Copyright (c) 2015 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#ifndef LY_PRINTER_H_
#define LY_PRINTER_H_

#include "libyang.h"
#include "tree_schema.h"
#include "tree_internal.h"

typedef enum LYOUT_TYPE {
    LYOUT_FD,          /**< file descriptor */
    LYOUT_STREAM,      /**< FILE stream */
    LYOUT_MEMORY,      /**< memory */
    LYOUT_CALLBACK     /**< print via provided callback */
} LYOUT_TYPE;

struct lyout {
    LYOUT_TYPE type;
    union {
        int fd;
        FILE *f;
        struct {
            char *buf;
            size_t len;
            size_t size;
        } mem;
        struct {
            ssize_t (*f)(void *arg, const void *buf, size_t count);
            void *arg;
        } clb;
    } method;

    /* buffer for holes */
    char *buffered;
    size_t buf_len;
    size_t buf_size;

    /* hole counter */
    size_t hole_count;
};

struct ext_substmt_info_s {
    const char *name;
    const char *arg;
    int flags;
#define SUBST_FLAG_YIN 0x1 /**< has YIN element */
#define SUBST_FLAG_ID 0x2  /**< the value is identifier -> no quotes */
};

/* filled in printer.c */
extern struct ext_substmt_info_s ext_substmt_info[];

/**
 * @brief Generic printer, replacement for printf() / write() / etc
 */
int ly_print(struct lyout *out, const char *format, ...);
void ly_print_flush(struct lyout *out);
int ly_write(struct lyout *out, const char *buf, size_t count);
int ly_write_skip(struct lyout *out, size_t count, size_t *position);
int ly_write_skipped(struct lyout *out, size_t position, const char *buf, size_t count);

/* 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) */
int ly_print_iffeature(struct lyout *out, const struct lys_module *module, struct lys_iffeature *expr, int prefix_kind);

int yang_print_model(struct lyout *out, const struct lys_module *module);
int yin_print_model(struct lyout *out, const struct lys_module *module);
int tree_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path, int line_length, int options);
int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path);
int jsons_print_model(struct lyout *out, const struct lys_module *module, const char *target_schema_path);

int json_print_data(struct lyout *out, const struct lyd_node *root, int options);
int xml_print_data(struct lyout *out, const struct lyd_node *root, int options);
int xml_print_node(struct lyout *out, int level, const struct lyd_node *node, int toplevel, int options);
int lyb_print_data(struct lyout *out, const struct lyd_node *root, int options);

int lys_print_target(struct lyout *out, const struct lys_module *module, const char *target_schema_path,
                     void (*clb_print_typedef)(struct lyout*, const struct lys_tpdf*, int*),
                     void (*clb_print_identity)(struct lyout*, const struct lys_ident*, int*),
                     void (*clb_print_feature)(struct lyout*, const struct lys_feature*, int*),
                     void (*clb_print_type)(struct lyout*, const struct lys_type*, int*),
                     void (*clb_print_grouping)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_container)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_choice)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_leaf)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_leaflist)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_list)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_anydata)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_case)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_notif)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_rpc)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_action)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_input)(struct lyout*, const struct lys_node*, int*),
                     void (*clb_print_output)(struct lyout*, const struct lys_node*, int*));

/**
 * get know if the node is supposed to be printed according to the specified with-default mode
 * return 1 - print, 0 - do not print
 */
int lyd_wd_toprint(const struct lyd_node *node, int options);

/* 0 - same, 1 - different */
int nscmp(const struct lyd_node *node1, const struct lyd_node *node2);

#endif /* LY_PRINTER_H_ */