Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file printer.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief Printers for libyang |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 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 |
Michal Vasko | 8de098c | 2016-02-26 10:00:25 +0100 | [diff] [blame^] | 11 | * |
Radek Krejci | 54f6fb3 | 2016-02-24 12:56:39 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef LY_PRINTER_H_ |
| 16 | #define LY_PRINTER_H_ |
| 17 | |
| 18 | #include "libyang.h" |
| 19 | #include "tree_schema.h" |
| 20 | #include "tree_internal.h" |
| 21 | |
| 22 | typedef enum LYOUT_TYPE { |
| 23 | LYOUT_FD, /**< file descriptor */ |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 24 | LYOUT_STREAM, /**< FILE stream */ |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 25 | LYOUT_MEMORY, /**< memory */ |
Radek Krejci | 6140e4e | 2015-10-09 15:50:55 +0200 | [diff] [blame] | 26 | LYOUT_CALLBACK /**< print via provided callback */ |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 27 | } LYOUT_TYPE; |
| 28 | |
| 29 | struct lyout { |
| 30 | LYOUT_TYPE type; |
| 31 | union { |
| 32 | int fd; |
| 33 | FILE *f; |
Radek Krejci | 50929eb | 2015-10-09 18:14:15 +0200 | [diff] [blame] | 34 | struct { |
Radek Krejci | 2fa0fc1 | 2015-10-14 18:14:29 +0200 | [diff] [blame] | 35 | char *buf; |
| 36 | size_t len; |
| 37 | size_t size; |
| 38 | } mem; |
| 39 | struct { |
Radek Krejci | 50929eb | 2015-10-09 18:14:15 +0200 | [diff] [blame] | 40 | ssize_t (*f)(void *arg, const void *buf, size_t count); |
| 41 | void *arg; |
| 42 | } clb; |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 43 | } method; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * @brief Generic printer, replacement for printf() / write() / etc |
| 48 | */ |
| 49 | int ly_print(struct lyout *out, const char *format, ...); |
| 50 | int ly_write(struct lyout *out, const char *buf, size_t count); |
| 51 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 52 | int yang_print_model(struct lyout *out, const struct lys_module *module); |
Michal Vasko | a63ca34 | 2016-02-05 14:29:19 +0100 | [diff] [blame] | 53 | int yin_print_model(struct lyout *out, const struct lys_module *module); |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 54 | int tree_print_model(struct lyout *out, const struct lys_module *module); |
| 55 | int info_print_model(struct lyout *out, const struct lys_module *module, const char *target_node); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 56 | |
Radek Krejci | 5044be3 | 2016-01-18 17:05:51 +0100 | [diff] [blame] | 57 | int json_print_data(struct lyout *out, const struct lyd_node *root, int options); |
| 58 | int xml_print_data(struct lyout *out, const struct lyd_node *root, int format, int options); |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 59 | |
Radek Krejci | 998a750 | 2015-10-26 15:54:33 +0100 | [diff] [blame] | 60 | /* 0 - same, 1 - different */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 61 | int nscmp(const struct lyd_node *node1, const struct lyd_node *node2); |
Radek Krejci | 998a750 | 2015-10-26 15:54:33 +0100 | [diff] [blame] | 62 | |
Radek Krejci | 76b0790 | 2015-10-09 09:11:25 +0200 | [diff] [blame] | 63 | #endif /* LY_PRINTER_H_ */ |