Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1 | /** |
| 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 | |
| 20 | typedef enum LYOUT_TYPE { |
| 21 | LYOUT_FD, /**< file descriptor */ |
| 22 | LYOUT_STREAM, /**< FILE stream */ |
Radek Krejci | 4a0ed4a | 2019-04-18 15:08:34 +0200 | [diff] [blame] | 23 | LYOUT_FDSTREAM, /**< FILE stream based on duplicated file descriptor */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 24 | LYOUT_MEMORY, /**< memory */ |
| 25 | LYOUT_CALLBACK /**< print via provided callback */ |
| 26 | } LYOUT_TYPE; |
| 27 | |
| 28 | struct lyout { |
| 29 | LYOUT_TYPE type; |
| 30 | union { |
| 31 | int fd; |
| 32 | FILE *f; |
| 33 | struct { |
| 34 | char *buf; |
| 35 | size_t len; |
| 36 | size_t size; |
| 37 | } mem; |
| 38 | struct { |
| 39 | ssize_t (*f)(void *arg, const void *buf, size_t count); |
| 40 | void *arg; |
| 41 | } clb; |
| 42 | } method; |
| 43 | |
| 44 | /* buffer for holes */ |
| 45 | char *buffered; |
| 46 | size_t buf_len; |
| 47 | size_t buf_size; |
| 48 | |
| 49 | /* hole counter */ |
| 50 | size_t hole_count; |
Radek Krejci | 897ad2e | 2019-04-29 16:43:07 +0200 | [diff] [blame] | 51 | |
| 52 | /* counter for printed bytes */ |
| 53 | size_t printed; |
| 54 | |
| 55 | /* libyang context for error logging */ |
| 56 | struct ly_ctx *ctx; |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 57 | LY_ERR status; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 60 | #define LYOUT_CHECK(LYOUT, ...) if (LYOUT->status) {return __VA_ARGS__;} |
| 61 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 62 | struct ext_substmt_info_s { |
| 63 | const char *name; |
| 64 | const char *arg; |
| 65 | int flags; |
| 66 | #define SUBST_FLAG_YIN 0x1 /**< has YIN element */ |
| 67 | #define SUBST_FLAG_ID 0x2 /**< the value is identifier -> no quotes */ |
| 68 | }; |
| 69 | |
| 70 | /* filled in printer.c */ |
| 71 | extern struct ext_substmt_info_s ext_substmt_info[]; |
| 72 | |
| 73 | |
| 74 | /** |
| 75 | * @brief |
| 76 | */ |
| 77 | LY_ERR yang_print_parsed(struct lyout *out, const struct lys_module *module); |
| 78 | |
| 79 | /** |
| 80 | * @brief |
| 81 | */ |
| 82 | LY_ERR yang_print_compiled(struct lyout *out, const struct lys_module *module); |
| 83 | |
| 84 | LY_ERR ly_print(struct lyout *out, const char *format, ...); |
| 85 | |
| 86 | void ly_print_flush(struct lyout *out); |
| 87 | |
| 88 | LY_ERR ly_write(struct lyout *out, const char *buf, size_t count); |
| 89 | |
| 90 | #endif /* LY_PRINTER_INTERNAL_H_ */ |