blob: 4d6128504609b422ff4567cba4fe05cc75773522 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_internal.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Internal structures and functions 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_INTERNAL_H_
16#define LY_PRINTER_INTERNAL_H_
17
18#include "printer_schema.h"
19
20typedef enum LYOUT_TYPE {
21 LYOUT_FD, /**< file descriptor */
22 LYOUT_STREAM, /**< FILE stream */
23 LYOUT_MEMORY, /**< memory */
24 LYOUT_CALLBACK /**< print via provided callback */
25} LYOUT_TYPE;
26
27struct lyout {
28 LYOUT_TYPE type;
29 union {
30 int fd;
31 FILE *f;
32 struct {
33 char *buf;
34 size_t len;
35 size_t size;
36 } mem;
37 struct {
38 ssize_t (*f)(void *arg, const void *buf, size_t count);
39 void *arg;
40 } clb;
41 } method;
42
43 /* buffer for holes */
44 char *buffered;
45 size_t buf_len;
46 size_t buf_size;
47
48 /* hole counter */
49 size_t hole_count;
50};
51
52struct ext_substmt_info_s {
53 const char *name;
54 const char *arg;
55 int flags;
56#define SUBST_FLAG_YIN 0x1 /**< has YIN element */
57#define SUBST_FLAG_ID 0x2 /**< the value is identifier -> no quotes */
58};
59
60/* filled in printer.c */
61extern struct ext_substmt_info_s ext_substmt_info[];
62
63
64/**
65 * @brief
66 */
67LY_ERR yang_print_parsed(struct lyout *out, const struct lys_module *module);
68
69/**
70 * @brief
71 */
72LY_ERR yang_print_compiled(struct lyout *out, const struct lys_module *module);
73
74LY_ERR ly_print(struct lyout *out, const char *format, ...);
75
76void ly_print_flush(struct lyout *out);
77
78LY_ERR ly_write(struct lyout *out, const char *buf, size_t count);
79
80#endif /* LY_PRINTER_INTERNAL_H_ */