Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file printer_yang.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 5 | * @brief YANG printer |
| 6 | * |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2022 CESNET, z.s.p.o. |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 16 | #define _GNU_SOURCE |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 17 | |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 18 | #include <assert.h> |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 19 | #include <inttypes.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 24 | #include <sys/types.h> |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 25 | |
Radek Krejci | aa45bda | 2020-07-20 07:43:38 +0200 | [diff] [blame] | 26 | #include "compat.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 27 | #include "log.h" |
Michal Vasko | 8f702ee | 2024-02-20 15:44:24 +0100 | [diff] [blame] | 28 | #include "ly_common.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 29 | #include "out.h" |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 30 | #include "out_internal.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 31 | #include "plugins_exts.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 32 | #include "plugins_types.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 33 | #include "printer_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 34 | #include "printer_schema.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 35 | #include "tree.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 36 | #include "tree_data.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 37 | #include "tree_schema.h" |
| 38 | #include "tree_schema_internal.h" |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 39 | #include "xpath.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 40 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 41 | /** |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 42 | * @brief Types of the YANG printers |
| 43 | */ |
| 44 | enum lys_ypr_schema_type { |
| 45 | LYS_YPR_PARSED, /**< YANG printer of the parsed schema */ |
| 46 | LYS_YPR_COMPILED /**< YANG printer of the compiled schema */ |
| 47 | }; |
| 48 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 49 | enum lys_ypr_text_flags { |
| 50 | LYS_YPR_TEXT_SINGLELINE = 0x01, /**< print 'text' on the same line as 'name' */ |
| 51 | LYS_YPR_TEXT_SINGLEQUOTED = 0x02 /**< do not encode 'text' and print it in single quotes */ |
| 52 | }; |
| 53 | |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 54 | #define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */ |
| 55 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 56 | #define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; } |
| 57 | #define YPR_EXTRA_LINE_PRINT(PCTX) \ |
| 58 | if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \ |
| 59 | (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \ |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 60 | if (DO_FORMAT) { \ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 61 | ly_print_((PCTX)->out, "\n"); \ |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 62 | } \ |
| 63 | } |
| 64 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 65 | #define YPR_IS_LYS_SINGLEQUOTED(FLAGS) (((FLAGS) & LYS_SINGLEQUOTED) ? 1 : 0) |
| 66 | |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 67 | /** |
| 68 | * @brief Compiled YANG printer context |
| 69 | * |
| 70 | * Note that the YANG extensions API provides getter to the members for the extension plugins. |
| 71 | */ |
| 72 | struct lys_ypr_ctx { |
| 73 | union { |
| 74 | struct { |
| 75 | struct ly_out *out; /**< output specification */ |
| 76 | uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */ |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 77 | uint16_t flags; /**< internal flags for use by printer */ |
Radek Krejci | f8d7f9a | 2021-03-10 14:32:36 +0100 | [diff] [blame] | 78 | uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */ |
| 79 | const struct lys_module *module; /**< schema to print */ |
| 80 | }; |
| 81 | struct lyspr_ctx printer_ctx; |
| 82 | }; |
| 83 | |
| 84 | /* YANG printer specific members */ |
| 85 | enum lys_ypr_schema_type schema; /**< type of the schema to print */ |
| 86 | }; |
| 87 | |
| 88 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 89 | * @brief Print the given text as content of a double quoted YANG string, |
| 90 | * including encoding characters that have special meanings. The quotation marks |
| 91 | * are not printed. |
| 92 | * |
| 93 | * Follows RFC 7950, section 6.1.3. |
| 94 | * |
| 95 | * @param[in] out Output specification. |
| 96 | * @param[in] text String to be printed. |
Radek Krejci | f56e2a4 | 2019-09-09 14:15:25 +0200 | [diff] [blame] | 97 | * @param[in] len Length of the string from @p text to be printed. In case of -1, |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 98 | * the @p text is printed completely as a NULL-terminated string. |
| 99 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 100 | static void |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 101 | ypr_encode(struct ly_out *out, const char *text, ssize_t len) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 102 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 103 | size_t i, start_len; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 104 | const char *start; |
| 105 | char special = 0; |
| 106 | |
| 107 | if (!len) { |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | if (len < 0) { |
| 112 | len = strlen(text); |
| 113 | } |
| 114 | |
| 115 | start = text; |
| 116 | start_len = 0; |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 117 | for (i = 0; i < (size_t)len; ++i) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 118 | switch (text[i]) { |
| 119 | case '\n': |
| 120 | case '\t': |
| 121 | case '\"': |
| 122 | case '\\': |
| 123 | special = text[i]; |
| 124 | break; |
| 125 | default: |
| 126 | ++start_len; |
| 127 | break; |
| 128 | } |
| 129 | |
| 130 | if (special) { |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 131 | ly_write_(out, start, start_len); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 132 | switch (special) { |
| 133 | case '\n': |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 134 | ly_write_(out, "\\n", 2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 135 | break; |
| 136 | case '\t': |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 137 | ly_write_(out, "\\t", 2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 138 | break; |
| 139 | case '\"': |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 140 | ly_write_(out, "\\\"", 2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 141 | break; |
| 142 | case '\\': |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 143 | ly_write_(out, "\\\\", 2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 144 | break; |
| 145 | } |
| 146 | |
| 147 | start += start_len + 1; |
| 148 | start_len = 0; |
| 149 | |
| 150 | special = 0; |
| 151 | } |
| 152 | } |
| 153 | |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 154 | ly_write_(out, start, start_len); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static void |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 158 | ypr_open(struct ly_out *out, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 159 | { |
| 160 | if (flag && !*flag) { |
| 161 | *flag = 1; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 162 | ly_print_(out, " {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
| 166 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 167 | ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 168 | { |
| 169 | if (flag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 170 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 171 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 172 | ly_print_(pctx->out, ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
| 176 | static void |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 177 | ypr_text(struct lys_ypr_ctx *pctx, const char *name, const char *text, enum lys_ypr_text_flags flags) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 178 | { |
| 179 | const char *s, *t; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 180 | char quot; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 181 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 182 | if (flags & LYS_YPR_TEXT_SINGLEQUOTED) { |
| 183 | quot = '\''; |
| 184 | } else { |
| 185 | quot = '\"'; |
| 186 | } |
| 187 | |
| 188 | if (flags & LYS_YPR_TEXT_SINGLELINE) { |
| 189 | ly_print_(pctx->out, "%*s%s %c", INDENT, name, quot); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 190 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 191 | ly_print_(pctx->out, "%*s%s\n", INDENT, name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 192 | LEVEL++; |
| 193 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 194 | ly_print_(pctx->out, "%*s%c", INDENT, quot); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 195 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 196 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 197 | t = text; |
| 198 | while ((s = strchr(t, '\n'))) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 199 | if (flags & LYS_YPR_TEXT_SINGLEQUOTED) { |
| 200 | ly_print_(pctx->out, "%.*s", (int)(s - t), t); |
| 201 | } else { |
| 202 | ypr_encode(pctx->out, t, s - t); |
| 203 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 204 | ly_print_(pctx->out, "\n"); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 205 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 206 | t = s + 1; |
| 207 | if (*t != '\n') { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 208 | ly_print_(pctx->out, "%*s ", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 212 | if (flags & LYS_YPR_TEXT_SINGLEQUOTED) { |
| 213 | ly_print_(pctx->out, "%s", t); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 214 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 215 | ypr_encode(pctx->out, t, strlen(t)); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 216 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 217 | ly_print_(pctx->out, "%c", quot); |
| 218 | if (!(flags & LYS_YPR_TEXT_SINGLELINE)) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 219 | LEVEL--; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 224 | yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 225 | { |
| 226 | struct lysp_stmt *childstmt; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 227 | uint16_t tflags = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 228 | |
| 229 | if (stmt->arg) { |
| 230 | if (stmt->flags) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 231 | if (stmt->flags & LYS_SINGLEQUOTED) { |
| 232 | tflags |= LYS_YPR_TEXT_SINGLEQUOTED; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 233 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 234 | ypr_text(pctx, stmt->stmt, stmt->arg, tflags); |
| 235 | ly_print_(pctx->out, "%s", stmt->child ? " {\n" : ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 236 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 237 | ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 238 | } |
| 239 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 240 | ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | if (stmt->child) { |
| 244 | LEVEL++; |
| 245 | LY_LIST_FOR(stmt->child, childstmt) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 246 | yprp_stmt(pctx, childstmt); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 247 | } |
| 248 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 249 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 253 | static void |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 254 | yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
| 255 | struct lysp_ext_instance *ext, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 256 | { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 257 | struct lysp_stmt *stmt; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 258 | ly_bool child_presence; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 259 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 260 | if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) { |
| 261 | return; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 262 | } |
Radek Krejci | 85ac831 | 2021-03-03 20:21:33 +0100 | [diff] [blame] | 263 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 264 | ypr_open(pctx->out, flag); |
| 265 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 266 | if (ext->def->argname) { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 267 | ly_print_(pctx->out, "%*s%s \"", INDENT, ext->name); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 268 | ypr_encode(pctx->out, ext->argument, -1); |
| 269 | ly_print_(pctx->out, "\""); |
| 270 | } else { |
| 271 | ly_print_(pctx->out, "%*s%s", INDENT, ext->name); |
| 272 | } |
| 273 | |
| 274 | child_presence = 0; |
| 275 | LEVEL++; |
| 276 | LY_LIST_FOR(ext->child, stmt) { |
| 277 | if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) { |
Radek Krejci | f56e2a4 | 2019-09-09 14:15:25 +0200 | [diff] [blame] | 278 | continue; |
| 279 | } |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 280 | if (!child_presence) { |
| 281 | ly_print_(pctx->out, " {\n"); |
| 282 | child_presence = 1; |
Radek Krejci | f56e2a4 | 2019-09-09 14:15:25 +0200 | [diff] [blame] | 283 | } |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 284 | yprp_stmt(pctx, stmt); |
| 285 | } |
| 286 | LEVEL--; |
| 287 | if (child_presence) { |
| 288 | ly_print_(pctx->out, "%*s}\n", INDENT); |
| 289 | } else { |
| 290 | ly_print_(pctx->out, ";\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 294 | static void |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 295 | yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
| 296 | struct lysp_ext_instance *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 297 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 298 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 299 | |
| 300 | LY_ARRAY_FOR(exts, u) { |
aPiecek | 6cf1d16 | 2023-11-08 16:07:00 +0100 | [diff] [blame] | 301 | if (exts[u].flags & LYS_INTERNAL) { |
| 302 | continue; |
| 303 | } |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 304 | yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag); |
| 305 | } |
| 306 | } |
| 307 | |
aPiecek | 6cf1d16 | 2023-11-08 16:07:00 +0100 | [diff] [blame] | 308 | static ly_bool |
| 309 | yprp_extension_has_printable_instances(struct lysp_ext_instance *exts) |
| 310 | { |
| 311 | LY_ARRAY_COUNT_TYPE u; |
| 312 | |
| 313 | LY_ARRAY_FOR(exts, u) { |
| 314 | if (!(exts[u].flags & LYS_INTERNAL)) { |
| 315 | return 1; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 322 | static void |
| 323 | yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
| 324 | struct lysc_ext_instance *exts, ly_bool *flag) |
| 325 | { |
| 326 | LY_ARRAY_COUNT_TYPE u; |
| 327 | ly_bool inner_flag; |
| 328 | |
| 329 | LY_ARRAY_FOR(exts, u) { |
| 330 | if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) { |
| 331 | return; |
| 332 | } |
| 333 | |
| 334 | ypr_open(pctx->out, flag); |
| 335 | if (exts[u].argument) { |
| 336 | ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name); |
| 337 | ypr_encode(pctx->out, exts[u].argument, -1); |
| 338 | ly_print_(pctx->out, "\""); |
| 339 | } else { |
| 340 | ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name); |
| 341 | } |
| 342 | |
| 343 | LEVEL++; |
| 344 | inner_flag = 0; |
| 345 | yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag); |
| 346 | |
Michal Vasko | 941e056 | 2022-10-18 10:35:00 +0200 | [diff] [blame] | 347 | if (exts[u].def->plugin && exts[u].def->plugin->printer_info) { |
| 348 | exts[u].def->plugin->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | LEVEL--; |
| 352 | ypr_close(pctx, inner_flag); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | static void |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 357 | ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, |
| 358 | ly_bool singlequoted, void *exts) |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 359 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 360 | ly_bool extflag = 0; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 361 | uint16_t flags = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 362 | |
| 363 | if (!text) { |
| 364 | /* nothing to print */ |
| 365 | return; |
| 366 | } |
| 367 | |
Michal Vasko | b872d0f | 2022-12-08 09:36:54 +0100 | [diff] [blame] | 368 | if (lys_stmt_flags(substmt) & LY_STMT_FLAG_ID) { |
| 369 | ly_print_(pctx->out, "%*s%s %s", INDENT, lys_stmt_str(substmt), text); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 370 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 371 | if (!(lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN)) { |
| 372 | flags |= LYS_YPR_TEXT_SINGLELINE; |
| 373 | } |
| 374 | if (singlequoted) { |
| 375 | flags |= LYS_YPR_TEXT_SINGLEQUOTED; |
| 376 | } |
| 377 | ypr_text(pctx, lys_stmt_str(substmt), text, flags); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 381 | if (pctx->schema == LYS_YPR_PARSED) { |
| 382 | yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag); |
| 383 | } else { |
| 384 | yprc_extension_instances(pctx, substmt, substmt_index, exts, &extflag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 385 | } |
| 386 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 387 | ypr_close(pctx, extflag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | static void |
Michal Vasko | 9a9e4e7 | 2022-03-21 10:05:11 +0100 | [diff] [blame] | 391 | ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 392 | unsigned long attr_value, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 393 | { |
| 394 | char *str; |
| 395 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 396 | if (asprintf(&str, "%lu", attr_value) == -1) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 397 | LOGMEM(pctx->module->ctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 398 | return; |
| 399 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 400 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 401 | ypr_substmt(pctx, substmt, substmt_index, str, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 402 | free(str); |
| 403 | } |
| 404 | |
| 405 | static void |
Michal Vasko | 2bf4af4 | 2023-01-04 12:08:38 +0100 | [diff] [blame] | 406 | ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, long attr_value, |
Michal Vasko | 9a9e4e7 | 2022-03-21 10:05:11 +0100 | [diff] [blame] | 407 | ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 408 | { |
| 409 | char *str; |
| 410 | |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 411 | if (asprintf(&str, "%ld", attr_value) == -1) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 412 | LOGMEM(pctx->module->ctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 413 | return; |
| 414 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 415 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 416 | ypr_substmt(pctx, substmt, substmt_index, str, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 417 | free(str); |
| 418 | } |
| 419 | |
| 420 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 421 | yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 422 | { |
| 423 | if (rev->dsc || rev->ref || rev->exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 424 | ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 425 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 426 | yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 427 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, 0, rev->exts); |
| 428 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, 0, rev->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 429 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 430 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 431 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 432 | ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
| 436 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 437 | ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 438 | { |
| 439 | if (flags & LYS_MAND_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 440 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 441 | ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
| 445 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 446 | ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 447 | { |
| 448 | if (flags & LYS_CONFIG_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 449 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 450 | ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
| 454 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 455 | ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 456 | { |
| 457 | const char *status = NULL; |
| 458 | |
| 459 | if (flags & LYS_STATUS_CURR) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 460 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 461 | status = "current"; |
| 462 | } else if (flags & LYS_STATUS_DEPRC) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 463 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 464 | status = "deprecated"; |
| 465 | } else if (flags & LYS_STATUS_OBSLT) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 466 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 467 | status = "obsolete"; |
| 468 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 469 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 470 | ypr_substmt(pctx, LY_STMT_STATUS, 0, status, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 474 | ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 475 | { |
| 476 | if (dsc) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 477 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 478 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | |
| 482 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 483 | ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 484 | { |
| 485 | if (ref) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 486 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 487 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, 0, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
| 491 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 492 | yprp_iffeatures(struct lys_ypr_ctx *pctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 493 | { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 494 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 495 | ly_bool extflag; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 496 | uint16_t flags; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 497 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 498 | LY_ARRAY_FOR(iffs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 499 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 500 | extflag = 0; |
| 501 | |
Michal Vasko | 659f8fa | 2024-02-27 15:20:34 +0100 | [diff] [blame] | 502 | flags = LYS_YPR_TEXT_SINGLELINE | ((iffs[u].flags & LYS_SINGLEQUOTED) ? LYS_YPR_TEXT_SINGLEQUOTED : 0); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 503 | ypr_text(pctx, "if-feature", iffs[u].str, flags); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 504 | |
| 505 | /* extensions */ |
| 506 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 507 | yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 508 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 509 | ypr_close(pctx, extflag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 514 | yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 515 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 516 | ly_bool flag = 0, flag2 = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 517 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 518 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 519 | ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 520 | LEVEL++; |
| 521 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 522 | yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 523 | |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 524 | if (ext->argname) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 525 | ypr_open(pctx->out, &flag); |
| 526 | ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname); |
Radek Krejci | 38d2e9f | 2019-09-09 10:31:51 +0200 | [diff] [blame] | 527 | LEVEL++; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 528 | if (ext->exts) { |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 529 | u = -1; |
Radek Krejci | fc596f9 | 2021-02-26 22:40:26 +0100 | [diff] [blame] | 530 | while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) { |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 531 | yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 532 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 533 | } |
| 534 | if ((ext->flags & LYS_YINELEM_MASK) || |
Radek Krejci | fc596f9 | 2021-02-26 22:40:26 +0100 | [diff] [blame] | 535 | (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 536 | ypr_open(pctx->out, &flag2); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 537 | ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", 0, ext->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 538 | } |
Radek Krejci | 38d2e9f | 2019-09-09 10:31:51 +0200 | [diff] [blame] | 539 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 540 | ypr_close(pctx, flag2); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 541 | } |
| 542 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 543 | ypr_status(pctx, ext->flags, ext->exts, &flag); |
| 544 | ypr_description(pctx, ext->dsc, ext->exts, &flag); |
| 545 | ypr_reference(pctx, ext->ref, ext->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 546 | |
| 547 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 548 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 552 | yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 553 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 554 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 555 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 556 | ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 557 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 558 | yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 559 | yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag); |
| 560 | ypr_status(pctx, feat->flags, feat->exts, &flag); |
| 561 | ypr_description(pctx, feat->dsc, feat->exts, &flag); |
| 562 | ypr_reference(pctx, feat->ref, feat->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 563 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 564 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 568 | yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 569 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 570 | ly_bool flag = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 571 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 572 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 573 | ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 574 | LEVEL++; |
| 575 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 576 | yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 577 | yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 578 | |
| 579 | LY_ARRAY_FOR(ident->bases, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 580 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 581 | ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], 0, ident->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 582 | } |
| 583 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 584 | ypr_status(pctx, ident->flags, ident->exts, &flag); |
| 585 | ypr_description(pctx, ident->dsc, ident->exts, &flag); |
| 586 | ypr_reference(pctx, ident->ref, ident->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 587 | |
| 588 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 589 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 593 | yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 594 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 595 | ly_bool flag = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 596 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 597 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 598 | ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 599 | LEVEL++; |
| 600 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 601 | yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 602 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 603 | ypr_open(pctx->out, &flag); |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 604 | if (lys_identity_iffeature_value(ident) == LY_ENOT) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 605 | ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name); |
aPiecek | f4a0a19 | 2021-08-03 15:14:17 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 608 | LY_ARRAY_FOR(ident->derived, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 609 | if (pctx->module != ident->derived[u]->module) { |
| 610 | ly_print_(pctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 611 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 612 | ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 616 | ypr_status(pctx, ident->flags, ident->exts, &flag); |
| 617 | ypr_description(pctx, ident->dsc, ident->exts, &flag); |
| 618 | ypr_reference(pctx, ident->ref, ident->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 619 | |
| 620 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 621 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 625 | yprp_restr(struct lys_ypr_ctx *pctx, const struct lysp_restr *restr, enum ly_stmt stmt, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 626 | { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 627 | ly_bool inner_flag = 0; |
Michal Vasko | 9a9e4e7 | 2022-03-21 10:05:11 +0100 | [diff] [blame] | 628 | const char *text; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 629 | uint16_t flags = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 630 | |
| 631 | if (!restr) { |
| 632 | return; |
| 633 | } |
| 634 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 635 | ypr_open(pctx->out, flag); |
Michal Vasko | 9a9e4e7 | 2022-03-21 10:05:11 +0100 | [diff] [blame] | 636 | text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ? |
| 637 | restr->arg.str : restr->arg.str + 1; |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 638 | if (!strchr(text, '\n')) { |
| 639 | flags |= LYS_YPR_TEXT_SINGLELINE; |
| 640 | } |
| 641 | if (restr->arg.flags & LYS_SINGLEQUOTED) { |
| 642 | flags |= LYS_YPR_TEXT_SINGLEQUOTED; |
| 643 | } |
| 644 | ypr_text(pctx, lyplg_ext_stmt2str(stmt), text, flags); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 645 | |
| 646 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 647 | yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag); |
Radek Krejci | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 648 | if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 649 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 650 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 651 | ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 652 | } |
| 653 | if (restr->emsg) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 654 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 655 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, 0, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 656 | } |
| 657 | if (restr->eapptag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 658 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 659 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, 0, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 660 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 661 | ypr_description(pctx, restr->dsc, restr->exts, &inner_flag); |
| 662 | ypr_reference(pctx, restr->ref, restr->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 663 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 664 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 665 | ypr_close(pctx, inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 669 | yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 670 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 671 | ly_bool inner_flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 672 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 673 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 674 | ypr_text(pctx, "must", must->cond->expr, LYS_YPR_TEXT_SINGLELINE); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 675 | |
| 676 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 677 | yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 678 | if (must->emsg) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 679 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 680 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, 0, must->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 681 | } |
| 682 | if (must->eapptag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 683 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 684 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, 0, must->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 685 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 686 | ypr_description(pctx, must->dsc, must->exts, &inner_flag); |
| 687 | ypr_reference(pctx, must->ref, must->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 688 | |
| 689 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 690 | ypr_close(pctx, inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 691 | } |
| 692 | |
| 693 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 694 | yprc_range(struct lys_ypr_ctx *pctx, const struct lysc_range *range, LY_DATA_TYPE basetype, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 695 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 696 | ly_bool inner_flag = 0; |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 697 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 698 | |
Radek Krejci | 334ccc7 | 2019-06-12 13:49:29 +0200 | [diff] [blame] | 699 | if (!range) { |
| 700 | return; |
| 701 | } |
| 702 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 703 | ypr_open(pctx->out, flag); |
| 704 | ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 705 | LY_ARRAY_FOR(range->parts, u) { |
| 706 | if (u > 0) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 707 | ly_print_(pctx->out, " | "); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 708 | } |
| 709 | if (range->parts[u].max_64 == range->parts[u].min_64) { |
| 710 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 711 | ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 712 | } else { /* signed values */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 713 | ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 714 | } |
| 715 | } else { |
| 716 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 717 | ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 718 | } else { /* signed values */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 719 | ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 720 | } |
| 721 | } |
| 722 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 723 | ly_print_(pctx->out, "\""); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 724 | |
| 725 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 726 | yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 727 | if (range->emsg) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 728 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 729 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, 0, range->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 730 | } |
| 731 | if (range->eapptag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 732 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 733 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, 0, range->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 734 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 735 | ypr_description(pctx, range->dsc, range->exts, &inner_flag); |
| 736 | ypr_reference(pctx, range->ref, range->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 737 | |
| 738 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 739 | ypr_close(pctx, inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 743 | yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 744 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 745 | ly_bool inner_flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 746 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 747 | ypr_open(pctx->out, flag); |
| 748 | ly_print_(pctx->out, "%*spattern \"", INDENT); |
| 749 | ypr_encode(pctx->out, pattern->expr, -1); |
| 750 | ly_print_(pctx->out, "\""); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 751 | |
| 752 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 753 | yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 754 | if (pattern->inverted) { |
| 755 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 756 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 757 | ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, pattern->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 758 | } |
| 759 | if (pattern->emsg) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 760 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 761 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, 0, pattern->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 762 | } |
| 763 | if (pattern->eapptag) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 764 | ypr_open(pctx->out, &inner_flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 765 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, 0, pattern->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 766 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 767 | ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag); |
| 768 | ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 769 | |
| 770 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 771 | ypr_close(pctx, inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | static void |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 775 | yprc_bits_enum(struct lys_ypr_ctx *pctx, const struct lysc_type_bitenum_item *items, LY_DATA_TYPE basetype, ly_bool *flag) |
| 776 | { |
| 777 | LY_ARRAY_COUNT_TYPE u; |
| 778 | const struct lysc_type_bitenum_item *item; |
| 779 | ly_bool inner_flag; |
| 780 | |
| 781 | assert((basetype == LY_TYPE_BITS) || (basetype == LY_TYPE_ENUM)); |
| 782 | |
| 783 | LY_ARRAY_FOR(items, u) { |
| 784 | item = &items[u]; |
| 785 | inner_flag = 0; |
| 786 | |
| 787 | ypr_open(pctx->out, flag); |
| 788 | ly_print_(pctx->out, "%*s%s \"", INDENT, basetype == LY_TYPE_BITS ? "bit" : "enum"); |
| 789 | ypr_encode(pctx->out, item->name, -1); |
| 790 | ly_print_(pctx->out, "\""); |
| 791 | LEVEL++; |
| 792 | if (basetype == LY_TYPE_BITS) { |
| 793 | yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag); |
| 794 | ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag); |
| 795 | } else { /* LY_TYPE_ENUM */ |
| 796 | yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag); |
| 797 | ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag); |
| 798 | } |
| 799 | ypr_status(pctx, item->flags, item->exts, &inner_flag); |
| 800 | ypr_description(pctx, item->dsc, item->exts, &inner_flag); |
| 801 | ypr_reference(pctx, item->ref, item->exts, &inner_flag); |
| 802 | LEVEL--; |
| 803 | ypr_close(pctx, inner_flag); |
| 804 | } |
| 805 | } |
| 806 | |
| 807 | static void |
| 808 | yprp_when(struct lys_ypr_ctx *pctx, const struct lysp_when *when, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 809 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 810 | ly_bool inner_flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 811 | |
| 812 | if (!when) { |
| 813 | return; |
| 814 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 815 | ypr_open(pctx->out, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 816 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 817 | ypr_text(pctx, "when", when->cond, LYS_YPR_TEXT_SINGLELINE); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 818 | |
| 819 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 820 | yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 821 | ypr_description(pctx, when->dsc, when->exts, &inner_flag); |
| 822 | ypr_reference(pctx, when->ref, when->exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 823 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 824 | ypr_close(pctx, inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | static void |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 828 | yprc_when(struct lys_ypr_ctx *pctx, const struct lysc_when *when, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 829 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 830 | ly_bool inner_flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 831 | |
| 832 | if (!when) { |
| 833 | return; |
| 834 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 835 | ypr_open(pctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 836 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 837 | ypr_text(pctx, "when", when->cond->expr, LYS_YPR_TEXT_SINGLELINE); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 838 | |
| 839 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 840 | yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 841 | ypr_description(pctx, when->dsc, when->exts, &inner_flag); |
| 842 | ypr_reference(pctx, when->ref, when->exts, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 843 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 844 | ypr_close(pctx, inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | static void |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 848 | yprp_bits_enum(struct lys_ypr_ctx *pctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 849 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 850 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 851 | ly_bool inner_flag; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 852 | |
| 853 | LY_ARRAY_FOR(items, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 854 | ypr_open(pctx->out, flag); |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 855 | if (type == LY_TYPE_BITS) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 856 | ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name); |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 857 | } else { /* LY_TYPE_ENUM */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 858 | ly_print_(pctx->out, "%*senum \"", INDENT); |
| 859 | ypr_encode(pctx->out, items[u].name, -1); |
| 860 | ly_print_(pctx->out, "\""); |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 861 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 862 | inner_flag = 0; |
| 863 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 864 | yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 865 | yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 866 | if (items[u].flags & LYS_SET_VALUE) { |
| 867 | if (type == LY_TYPE_BITS) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 868 | ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 869 | } else { /* LY_TYPE_ENUM */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 870 | ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 871 | } |
| 872 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 873 | ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag); |
| 874 | ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag); |
| 875 | ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 876 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 877 | ypr_close(pctx, inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | |
| 881 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 882 | yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 883 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 884 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 885 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 886 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 887 | ly_print_(pctx->out, "%*stype %s", INDENT, type->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 888 | LEVEL++; |
| 889 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 890 | yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 891 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 892 | yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag); |
| 893 | yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 894 | LY_ARRAY_FOR(type->patterns, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 895 | yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 896 | } |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 897 | yprp_bits_enum(pctx, type->bits, LY_TYPE_BITS, &flag); |
| 898 | yprp_bits_enum(pctx, type->enums, LY_TYPE_ENUM, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 899 | |
| 900 | if (type->path) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 901 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 902 | ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, 0, type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 903 | } |
| 904 | if (type->flags & LYS_SET_REQINST) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 905 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 906 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", 0, type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 907 | } |
| 908 | if (type->flags & LYS_SET_FRDIGITS) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 909 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 910 | } |
| 911 | LY_ARRAY_FOR(type->bases, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 912 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 913 | ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], 0, type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 914 | } |
| 915 | LY_ARRAY_FOR(type->types, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 916 | ypr_open(pctx->out, &flag); |
| 917 | yprp_type(pctx, &type->types[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 921 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 925 | yprc_dflt_value(struct lys_ypr_ctx *pctx, const struct ly_ctx *ly_pctx, const struct lyd_value *value, |
Radek Krejci | 224d4b4 | 2021-04-23 13:54:59 +0200 | [diff] [blame] | 926 | struct lysc_ext_instance *exts) |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 927 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 928 | ly_bool dynamic; |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 929 | const char *str; |
| 930 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 931 | str = value->realtype->plugin->print(ly_pctx, value, LY_VALUE_JSON, NULL, &dynamic, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 932 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, str, 0, exts); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 933 | if (dynamic) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 934 | free((void *)str); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 935 | } |
| 936 | } |
| 937 | |
| 938 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 939 | yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 940 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 941 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 942 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 943 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 944 | ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype)); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 945 | LEVEL++; |
| 946 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 947 | yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 948 | |
Michal Vasko | 2bb55bc | 2020-08-05 13:27:04 +0200 | [diff] [blame] | 949 | switch (type->basetype) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 950 | case LY_TYPE_BINARY: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 951 | struct lysc_type_bin *bin = (struct lysc_type_bin *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 952 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 953 | yprc_range(pctx, bin->length, type->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 954 | break; |
| 955 | } |
| 956 | case LY_TYPE_UINT8: |
| 957 | case LY_TYPE_UINT16: |
| 958 | case LY_TYPE_UINT32: |
| 959 | case LY_TYPE_UINT64: |
| 960 | case LY_TYPE_INT8: |
| 961 | case LY_TYPE_INT16: |
| 962 | case LY_TYPE_INT32: |
| 963 | case LY_TYPE_INT64: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 964 | struct lysc_type_num *num = (struct lysc_type_num *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 965 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 966 | yprc_range(pctx, num->range, type->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 967 | break; |
| 968 | } |
| 969 | case LY_TYPE_STRING: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 970 | struct lysc_type_str *str = (struct lysc_type_str *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 971 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 972 | yprc_range(pctx, str->length, type->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 973 | LY_ARRAY_FOR(str->patterns, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 974 | yprc_pattern(pctx, str->patterns[u], &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 975 | } |
| 976 | break; |
| 977 | } |
| 978 | case LY_TYPE_BITS: |
| 979 | case LY_TYPE_ENUM: { |
| 980 | /* bits and enums structures are compatible */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 981 | struct lysc_type_bits *bits = (struct lysc_type_bits *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 982 | |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 983 | yprc_bits_enum(pctx, bits->bits, type->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 984 | break; |
| 985 | } |
| 986 | case LY_TYPE_BOOL: |
| 987 | case LY_TYPE_EMPTY: |
| 988 | /* nothing to do */ |
| 989 | break; |
| 990 | case LY_TYPE_DEC64: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 991 | struct lysc_type_dec *dec = (struct lysc_type_dec *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 992 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 993 | ypr_open(pctx->out, &flag); |
| 994 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag); |
| 995 | yprc_range(pctx, dec->range, dec->basetype, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 996 | break; |
| 997 | } |
| 998 | case LY_TYPE_IDENT: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 999 | struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1000 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1001 | LY_ARRAY_FOR(ident->bases, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1002 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1003 | ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, 0, type->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1004 | } |
| 1005 | break; |
| 1006 | } |
| 1007 | case LY_TYPE_INST: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1008 | struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1009 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1010 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1011 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", 0, inst->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1012 | break; |
| 1013 | } |
| 1014 | case LY_TYPE_LEAFREF: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1015 | struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1016 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1017 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1018 | ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, 0, lr->exts); |
| 1019 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", 0, lr->exts); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1020 | yprc_type(pctx, lr->realtype); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1021 | break; |
| 1022 | } |
| 1023 | case LY_TYPE_UNION: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1024 | struct lysc_type_union *un = (struct lysc_type_union *)type; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1025 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1026 | LY_ARRAY_FOR(un->types, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1027 | ypr_open(pctx->out, &flag); |
| 1028 | yprc_type(pctx, un->types[u]); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1029 | } |
| 1030 | break; |
| 1031 | } |
| 1032 | default: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1033 | LOGINT(pctx->module->ctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
| 1036 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1037 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1041 | yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1042 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1043 | ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1044 | LEVEL++; |
| 1045 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1046 | yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1047 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1048 | yprp_type(pctx, &tpdf->type); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1049 | |
| 1050 | if (tpdf->units) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1051 | ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, 0, tpdf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1052 | } |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1053 | if (tpdf->dflt.str) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1054 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, YPR_IS_LYS_SINGLEQUOTED(tpdf->dflt.flags), tpdf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1055 | } |
| 1056 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1057 | ypr_status(pctx, tpdf->flags, tpdf->exts, NULL); |
| 1058 | ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL); |
| 1059 | ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1060 | |
| 1061 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1062 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1063 | } |
| 1064 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1065 | static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node); |
| 1066 | static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node); |
| 1067 | static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action); |
| 1068 | static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1069 | |
| 1070 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1071 | yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1072 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1073 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1074 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1075 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1076 | struct lysp_node_action *action; |
| 1077 | struct lysp_node_notif *notif; |
| 1078 | struct lysp_node_grp *subgrp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1079 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1080 | ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1081 | LEVEL++; |
| 1082 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1083 | yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1084 | ypr_status(pctx, grp->flags, grp->exts, &flag); |
| 1085 | ypr_description(pctx, grp->dsc, grp->exts, &flag); |
| 1086 | ypr_reference(pctx, grp->ref, grp->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1087 | |
| 1088 | LY_ARRAY_FOR(grp->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1089 | ypr_open(pctx->out, &flag); |
| 1090 | yprp_typedef(pctx, &grp->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1091 | } |
| 1092 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1093 | LY_LIST_FOR(grp->groupings, subgrp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1094 | ypr_open(pctx->out, &flag); |
| 1095 | yprp_grouping(pctx, subgrp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1096 | } |
| 1097 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1098 | LY_LIST_FOR(grp->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1099 | ypr_open(pctx->out, &flag); |
| 1100 | yprp_node(pctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1101 | } |
| 1102 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1103 | LY_LIST_FOR(grp->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1104 | ypr_open(pctx->out, &flag); |
| 1105 | yprp_action(pctx, action); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | LY_LIST_FOR(grp->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1109 | ypr_open(pctx->out, &flag); |
| 1110 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1114 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1118 | yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1119 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1120 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1121 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1122 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1123 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1124 | if (!inout->child) { |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1125 | /* no children */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1126 | return; |
| 1127 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1128 | ypr_open(pctx->out, flag); |
| 1129 | YPR_EXTRA_LINE_PRINT(pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1130 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1131 | ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1132 | LEVEL++; |
| 1133 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1134 | yprp_extension_instances(pctx, LY_STMT_MUST, 0, inout->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1135 | LY_ARRAY_FOR(inout->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1136 | yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1137 | } |
| 1138 | LY_ARRAY_FOR(inout->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1139 | yprp_typedef(pctx, &inout->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1140 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1141 | LY_LIST_FOR(inout->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1142 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1143 | } |
| 1144 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1145 | LY_LIST_FOR(inout->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1146 | yprp_node(pctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1150 | ypr_close(pctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1154 | yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1155 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1156 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1157 | struct lysc_node *data; |
| 1158 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1159 | if (!inout->child) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1160 | /* input/output is empty */ |
| 1161 | return; |
| 1162 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1163 | ypr_open(pctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1164 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1165 | ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1166 | LEVEL++; |
| 1167 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1168 | yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1169 | LY_ARRAY_FOR(inout->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1170 | yprc_must(pctx, &inout->musts[u], NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1171 | } |
| 1172 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1173 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1174 | LY_LIST_FOR(inout->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1175 | yprc_node(pctx, data); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1176 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1180 | ypr_close(pctx, 1); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1184 | yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1185 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1186 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1187 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1188 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1189 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1190 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1191 | ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1192 | |
| 1193 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1194 | yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1195 | yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1196 | |
| 1197 | LY_ARRAY_FOR(notif->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1198 | yprp_restr(pctx, ¬if->musts[u], LY_STMT_MUST, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1199 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1200 | ypr_status(pctx, notif->flags, notif->exts, &flag); |
| 1201 | ypr_description(pctx, notif->dsc, notif->exts, &flag); |
| 1202 | ypr_reference(pctx, notif->ref, notif->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1203 | |
| 1204 | LY_ARRAY_FOR(notif->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1205 | ypr_open(pctx->out, &flag); |
| 1206 | yprp_typedef(pctx, ¬if->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1207 | } |
| 1208 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1209 | LY_LIST_FOR(notif->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1210 | ypr_open(pctx->out, &flag); |
| 1211 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1212 | } |
| 1213 | |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1214 | LY_LIST_FOR(notif->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1215 | ypr_open(pctx->out, &flag); |
| 1216 | yprp_node(pctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1220 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1224 | yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1225 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1226 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1227 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1228 | struct lysc_node *data; |
| 1229 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1230 | ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1231 | |
| 1232 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1233 | yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1234 | |
| 1235 | LY_ARRAY_FOR(notif->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1236 | yprc_must(pctx, ¬if->musts[u], &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1237 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1238 | ypr_status(pctx, notif->flags, notif->exts, &flag); |
| 1239 | ypr_description(pctx, notif->dsc, notif->exts, &flag); |
| 1240 | ypr_reference(pctx, notif->ref, notif->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1241 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1242 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 1243 | LY_LIST_FOR(notif->child, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1244 | ypr_open(pctx->out, &flag); |
| 1245 | yprc_node(pctx, data); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1246 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1250 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1254 | yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1255 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1256 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1257 | ly_bool flag = 0; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1258 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1259 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1260 | ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1261 | |
| 1262 | LEVEL++; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1263 | yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1264 | yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag); |
| 1265 | ypr_status(pctx, action->flags, action->exts, &flag); |
| 1266 | ypr_description(pctx, action->dsc, action->exts, &flag); |
| 1267 | ypr_reference(pctx, action->ref, action->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1268 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1269 | YPR_EXTRA_LINE(flag, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 1270 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1271 | LY_ARRAY_FOR(action->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1272 | ypr_open(pctx->out, &flag); |
| 1273 | YPR_EXTRA_LINE_PRINT(pctx); |
| 1274 | yprp_typedef(pctx, &action->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1275 | } |
| 1276 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1277 | YPR_EXTRA_LINE(action->typedefs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 1278 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1279 | LY_LIST_FOR(action->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1280 | ypr_open(pctx->out, &flag); |
| 1281 | YPR_EXTRA_LINE_PRINT(pctx); |
| 1282 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1283 | } |
| 1284 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1285 | YPR_EXTRA_LINE(action->groupings, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 1286 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1287 | yprp_inout(pctx, &action->input, &flag); |
| 1288 | yprp_inout(pctx, &action->output, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1289 | |
| 1290 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1291 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1295 | yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1296 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1297 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1298 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1299 | ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1300 | |
| 1301 | LEVEL++; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1302 | yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1303 | ypr_status(pctx, action->flags, action->exts, &flag); |
| 1304 | ypr_description(pctx, action->dsc, action->exts, &flag); |
| 1305 | ypr_reference(pctx, action->ref, action->exts, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1306 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1307 | yprc_inout(pctx, &action->input, &flag); |
| 1308 | yprc_inout(pctx, &action->output, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1309 | |
| 1310 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1311 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1315 | yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1316 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1317 | ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1318 | LEVEL++; |
| 1319 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1320 | yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1321 | yprp_when(pctx, lysp_node_when(node), flag); |
| 1322 | yprp_iffeatures(pctx, node->iffeatures, node->exts, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1326 | yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1327 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1328 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1329 | struct lysc_when **when; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1330 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1331 | ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1332 | LEVEL++; |
| 1333 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1334 | yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1335 | |
| 1336 | when = lysc_node_when(node); |
| 1337 | LY_ARRAY_FOR(when, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1338 | yprc_when(pctx, when[u], flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1339 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1342 | /* macro to unify the code */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1343 | #define YPR_NODE_COMMON2 \ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1344 | ypr_config(pctx, node->flags, node->exts, flag); \ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1345 | if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1346 | ypr_mandatory(pctx, node->flags, node->exts, flag); \ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1347 | } \ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1348 | ypr_status(pctx, node->flags, node->exts, flag); \ |
| 1349 | ypr_description(pctx, node->dsc, node->exts, flag); \ |
| 1350 | ypr_reference(pctx, node->ref, node->exts, flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1351 | |
| 1352 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1353 | yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1354 | { |
| 1355 | YPR_NODE_COMMON2; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1356 | } |
| 1357 | |
| 1358 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1359 | yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1360 | { |
| 1361 | YPR_NODE_COMMON2; |
| 1362 | } |
| 1363 | |
| 1364 | #undef YPR_NODE_COMMON2 |
| 1365 | |
| 1366 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1367 | yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1368 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1369 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1370 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1371 | struct lysp_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1372 | struct lysp_node_action *action; |
| 1373 | struct lysp_node_notif *notif; |
| 1374 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1375 | struct lysp_node_container *cont = (struct lysp_node_container *)node; |
| 1376 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1377 | yprp_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1378 | |
| 1379 | LY_ARRAY_FOR(cont->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1380 | yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1381 | } |
| 1382 | if (cont->presence) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1383 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1384 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, 0, cont->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1385 | } |
| 1386 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1387 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1388 | |
| 1389 | LY_ARRAY_FOR(cont->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1390 | ypr_open(pctx->out, &flag); |
| 1391 | yprp_typedef(pctx, &cont->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1394 | LY_LIST_FOR(cont->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1395 | ypr_open(pctx->out, &flag); |
| 1396 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | LY_LIST_FOR(cont->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1400 | ypr_open(pctx->out, &flag); |
| 1401 | yprp_node(pctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1402 | } |
| 1403 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1404 | LY_LIST_FOR(cont->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1405 | ypr_open(pctx->out, &flag); |
| 1406 | yprp_action(pctx, action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1407 | } |
| 1408 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1409 | LY_LIST_FOR(cont->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1410 | ypr_open(pctx->out, &flag); |
| 1411 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1415 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1419 | yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1420 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1421 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1422 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1423 | struct lysc_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1424 | struct lysc_node_action *action; |
| 1425 | struct lysc_node_notif *notif; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1426 | struct lysc_node_container *cont = (struct lysc_node_container *)node; |
| 1427 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1428 | yprc_node_common1(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1429 | |
| 1430 | LY_ARRAY_FOR(cont->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1431 | yprc_must(pctx, &cont->musts[u], &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1432 | } |
| 1433 | if (cont->flags & LYS_PRESENCE) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1434 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1435 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", 0, cont->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1436 | } |
| 1437 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1438 | yprc_node_common2(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1439 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1440 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1441 | LY_LIST_FOR(cont->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1442 | ypr_open(pctx->out, &flag); |
| 1443 | yprc_node(pctx, child); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1444 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1445 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1446 | LY_LIST_FOR(cont->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1447 | ypr_open(pctx->out, &flag); |
| 1448 | yprc_action(pctx, action); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1449 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1450 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1451 | LY_LIST_FOR(cont->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1452 | ypr_open(pctx->out, &flag); |
| 1453 | yprc_notification(pctx, notif); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1454 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1458 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1462 | yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1463 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1464 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1465 | struct lysp_node *child; |
| 1466 | struct lysp_node_case *cas = (struct lysp_node_case *)node; |
| 1467 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1468 | yprp_node_common1(pctx, node, &flag); |
| 1469 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1470 | |
| 1471 | LY_LIST_FOR(cas->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1472 | ypr_open(pctx->out, &flag); |
| 1473 | yprp_node(pctx, child); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1477 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1481 | yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1482 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1483 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1484 | struct lysc_node *child; |
| 1485 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1486 | yprc_node_common1(pctx, &cs->node, &flag); |
| 1487 | yprc_node_common2(pctx, &cs->node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1488 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1489 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1490 | for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1491 | ypr_open(pctx->out, &flag); |
| 1492 | yprc_node(pctx, child); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1493 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1497 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1501 | yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1502 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1503 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1504 | struct lysp_node *child; |
| 1505 | struct lysp_node_choice *choice = (struct lysp_node_choice *)node; |
| 1506 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1507 | yprp_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1508 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1509 | if (choice->dflt.str) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1510 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1511 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, YPR_IS_LYS_SINGLEQUOTED(choice->dflt.flags), choice->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1514 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1515 | |
| 1516 | LY_LIST_FOR(choice->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1517 | ypr_open(pctx->out, &flag); |
| 1518 | yprp_node(pctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1522 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1526 | yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1527 | { |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1528 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1529 | struct lysc_node_case *cs; |
| 1530 | struct lysc_node_choice *choice = (struct lysc_node_choice *)node; |
| 1531 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1532 | yprc_node_common1(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1533 | |
| 1534 | if (choice->dflt) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1535 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1536 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, 0, choice->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1537 | } |
| 1538 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1539 | yprc_node_common2(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1540 | |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1541 | for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1542 | ypr_open(pctx->out, &flag); |
| 1543 | yprc_case(pctx, cs); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1547 | ypr_close(pctx, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1551 | yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1552 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1553 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1554 | struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node; |
| 1555 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1556 | yprp_node_common1(pctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1557 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1558 | yprp_type(pctx, &leaf->type); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1559 | ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1560 | LY_ARRAY_FOR(leaf->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1561 | yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1562 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1563 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, YPR_IS_LYS_SINGLEQUOTED(leaf->dflt.flags), leaf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1564 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1565 | yprp_node_common2(pctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1566 | |
| 1567 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1568 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1572 | yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1573 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1574 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1575 | struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node; |
| 1576 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1577 | yprc_node_common1(pctx, node, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1578 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1579 | yprc_type(pctx, leaf->type); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1580 | ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1581 | LY_ARRAY_FOR(leaf->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1582 | yprc_must(pctx, &leaf->musts[u], NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1583 | } |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1584 | |
| 1585 | if (leaf->dflt) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1586 | yprc_dflt_value(pctx, node->module->ctx, leaf->dflt, leaf->exts); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1587 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1588 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1589 | yprc_node_common2(pctx, node, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1590 | |
| 1591 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1592 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1596 | yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1597 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1598 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1599 | struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node; |
| 1600 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1601 | yprp_node_common1(pctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1602 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1603 | yprp_type(pctx, &llist->type); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1604 | ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1605 | LY_ARRAY_FOR(llist->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1606 | yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1607 | } |
| 1608 | LY_ARRAY_FOR(llist->dflts, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1609 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(llist->dflts[u].flags), |
| 1610 | llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1611 | } |
| 1612 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1613 | ypr_config(pctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1614 | |
| 1615 | if (llist->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1616 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1617 | } |
| 1618 | if (llist->flags & LYS_SET_MAX) { |
| 1619 | if (llist->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1620 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1621 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1622 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | if (llist->flags & LYS_ORDBY_MASK) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1627 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", 0, llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1628 | } |
| 1629 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1630 | ypr_status(pctx, node->flags, node->exts, NULL); |
| 1631 | ypr_description(pctx, node->dsc, node->exts, NULL); |
| 1632 | ypr_reference(pctx, node->ref, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1633 | |
| 1634 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1635 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1639 | yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1640 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1641 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1642 | struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node; |
| 1643 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1644 | yprc_node_common1(pctx, node, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1645 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1646 | yprc_type(pctx, llist->type); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1647 | ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1648 | LY_ARRAY_FOR(llist->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1649 | yprc_must(pctx, &llist->musts[u], NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1650 | } |
| 1651 | LY_ARRAY_FOR(llist->dflts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1652 | yprc_dflt_value(pctx, node->module->ctx, llist->dflts[u], llist->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1653 | } |
| 1654 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1655 | ypr_config(pctx, node->flags, node->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1656 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1657 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1658 | if (llist->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1659 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1660 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1661 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1662 | } |
| 1663 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1664 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", 0, llist->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1665 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1666 | ypr_status(pctx, node->flags, node->exts, NULL); |
| 1667 | ypr_description(pctx, node->dsc, node->exts, NULL); |
| 1668 | ypr_reference(pctx, node->ref, node->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1669 | |
| 1670 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1671 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1675 | yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1676 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1677 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1678 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1679 | struct lysp_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1680 | struct lysp_node_action *action; |
| 1681 | struct lysp_node_notif *notif; |
| 1682 | struct lysp_node_grp *grp; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1683 | struct lysp_node_list *list = (struct lysp_node_list *)node; |
| 1684 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1685 | yprp_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1686 | |
| 1687 | LY_ARRAY_FOR(list->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1688 | yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1689 | } |
| 1690 | if (list->key) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1691 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1692 | ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, 0, list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1693 | } |
| 1694 | LY_ARRAY_FOR(list->uniques, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1695 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1696 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(list->uniques[u].flags), |
| 1697 | list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1698 | } |
| 1699 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1700 | ypr_config(pctx, node->flags, node->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1701 | |
| 1702 | if (list->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1703 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1704 | } |
| 1705 | if (list->flags & LYS_SET_MAX) { |
| 1706 | if (list->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1707 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1708 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1709 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1710 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1711 | } |
| 1712 | } |
| 1713 | |
| 1714 | if (list->flags & LYS_ORDBY_MASK) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1715 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1716 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", 0, list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1717 | } |
| 1718 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1719 | ypr_status(pctx, node->flags, node->exts, &flag); |
| 1720 | ypr_description(pctx, node->dsc, node->exts, &flag); |
| 1721 | ypr_reference(pctx, node->ref, node->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1722 | |
| 1723 | LY_ARRAY_FOR(list->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1724 | ypr_open(pctx->out, &flag); |
| 1725 | yprp_typedef(pctx, &list->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1726 | } |
| 1727 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1728 | LY_LIST_FOR(list->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1729 | ypr_open(pctx->out, &flag); |
| 1730 | yprp_grouping(pctx, grp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | LY_LIST_FOR(list->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1734 | ypr_open(pctx->out, &flag); |
| 1735 | yprp_node(pctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1736 | } |
| 1737 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1738 | LY_LIST_FOR(list->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1739 | ypr_open(pctx->out, &flag); |
| 1740 | yprp_action(pctx, action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1741 | } |
| 1742 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1743 | LY_LIST_FOR(list->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1744 | ypr_open(pctx->out, &flag); |
| 1745 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1749 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1753 | yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1754 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1755 | LY_ARRAY_COUNT_TYPE u, v; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1756 | struct lysc_node_list *list = (struct lysc_node_list *)node; |
| 1757 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1758 | yprc_node_common1(pctx, node, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1759 | |
| 1760 | LY_ARRAY_FOR(list->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1761 | yprc_must(pctx, &list->musts[u], NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1762 | } |
Radek Krejci | 0fe9b51 | 2019-07-26 17:51:05 +0200 | [diff] [blame] | 1763 | if (!(list->flags & LYS_KEYLESS)) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1764 | ly_print_(pctx->out, "%*skey \"", INDENT); |
Radek Krejci | 0fe9b51 | 2019-07-26 17:51:05 +0200 | [diff] [blame] | 1765 | for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1766 | ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1767 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1768 | ly_print_(pctx->out, "\";\n"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1769 | } |
| 1770 | LY_ARRAY_FOR(list->uniques, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1771 | ly_print_(pctx->out, "%*sunique \"", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1772 | LY_ARRAY_FOR(list->uniques[u], v) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1773 | ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1774 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1775 | ypr_close(pctx, 0); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1776 | } |
| 1777 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1778 | ypr_config(pctx, node->flags, node->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1779 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1780 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1781 | if (list->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1782 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1783 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1784 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1785 | } |
| 1786 | |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1787 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", 0, list->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1788 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1789 | ypr_status(pctx, node->flags, node->exts, NULL); |
| 1790 | ypr_description(pctx, node->dsc, node->exts, NULL); |
| 1791 | ypr_reference(pctx, node->ref, node->exts, NULL); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1792 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1793 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1794 | struct lysc_node *child; |
| 1795 | struct lysc_node_action *action; |
| 1796 | struct lysc_node_notif *notif; |
| 1797 | |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1798 | LY_LIST_FOR(list->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1799 | yprc_node(pctx, child); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1800 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1801 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1802 | LY_LIST_FOR(list->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1803 | yprc_action(pctx, action); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1804 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1805 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1806 | LY_LIST_FOR(list->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1807 | yprc_notification(pctx, notif); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 1808 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1812 | ypr_close(pctx, 1); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1816 | yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1817 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1818 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1819 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1820 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1821 | ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1822 | LEVEL++; |
| 1823 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1824 | yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1825 | yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1826 | |
| 1827 | LY_ARRAY_FOR(refine->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1828 | ypr_open(pctx->out, &flag); |
| 1829 | yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | if (refine->presence) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1833 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1834 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, 0, refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1835 | } |
| 1836 | |
| 1837 | LY_ARRAY_FOR(refine->dflts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1838 | ypr_open(pctx->out, &flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1839 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(refine->dflts[u].flags), |
| 1840 | refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1841 | } |
| 1842 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1843 | ypr_config(pctx, refine->flags, refine->exts, &flag); |
| 1844 | ypr_mandatory(pctx, refine->flags, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1845 | |
| 1846 | if (refine->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1847 | ypr_open(pctx->out, &flag); |
| 1848 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1849 | } |
| 1850 | if (refine->flags & LYS_SET_MAX) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1851 | ypr_open(pctx->out, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1852 | if (refine->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1853 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1854 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 1855 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1856 | } |
| 1857 | } |
| 1858 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1859 | ypr_description(pctx, refine->dsc, refine->exts, &flag); |
| 1860 | ypr_reference(pctx, refine->ref, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1861 | |
| 1862 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1863 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1864 | } |
| 1865 | |
| 1866 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1867 | yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1868 | { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1869 | struct lysp_node *child; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1870 | struct lysp_node_action *action; |
| 1871 | struct lysp_node_notif *notif; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1872 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1873 | ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1874 | LEVEL++; |
| 1875 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 1876 | yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1877 | yprp_when(pctx, aug->when, NULL); |
| 1878 | yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL); |
| 1879 | ypr_status(pctx, aug->flags, aug->exts, NULL); |
| 1880 | ypr_description(pctx, aug->dsc, aug->exts, NULL); |
| 1881 | ypr_reference(pctx, aug->ref, aug->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1882 | |
| 1883 | LY_LIST_FOR(aug->child, child) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1884 | yprp_node(pctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1885 | } |
| 1886 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1887 | LY_LIST_FOR(aug->actions, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1888 | yprp_action(pctx, action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1889 | } |
| 1890 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1891 | LY_LIST_FOR(aug->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1892 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1896 | ypr_close(pctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1897 | } |
| 1898 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1899 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1900 | yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1901 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1902 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1903 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1904 | struct lysp_node_uses *uses = (struct lysp_node_uses *)node; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1905 | struct lysp_node_augment *aug; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1906 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1907 | yprp_node_common1(pctx, node, &flag); |
| 1908 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1909 | |
| 1910 | LY_ARRAY_FOR(uses->refines, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1911 | ypr_open(pctx->out, &flag); |
| 1912 | yprp_refine(pctx, &uses->refines[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1913 | } |
| 1914 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1915 | LY_LIST_FOR(uses->augments, aug) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1916 | ypr_open(pctx->out, &flag); |
| 1917 | yprp_augment(pctx, aug); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1921 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1925 | yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1926 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1927 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1928 | ly_bool flag = 0; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1929 | struct lysp_node_anydata *any = (struct lysp_node_anydata *)node; |
| 1930 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1931 | yprp_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1932 | |
| 1933 | LY_ARRAY_FOR(any->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1934 | ypr_open(pctx->out, &flag); |
| 1935 | yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1936 | } |
| 1937 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1938 | yprp_node_common2(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1939 | |
| 1940 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1941 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1945 | yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1946 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1947 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 1948 | ly_bool flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1949 | struct lysc_node_anydata *any = (struct lysc_node_anydata *)node; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1950 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1951 | yprc_node_common1(pctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1952 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1953 | LY_ARRAY_FOR(any->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1954 | ypr_open(pctx->out, &flag); |
| 1955 | yprc_must(pctx, &any->musts[u], NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1956 | } |
| 1957 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1958 | yprc_node_common2(pctx, node, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1959 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1960 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1961 | ypr_close(pctx, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1965 | yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1966 | { |
| 1967 | switch (node->nodetype) { |
| 1968 | case LYS_CONTAINER: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1969 | yprp_container(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1970 | break; |
| 1971 | case LYS_CHOICE: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1972 | yprp_choice(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1973 | break; |
| 1974 | case LYS_LEAF: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1975 | yprp_leaf(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1976 | break; |
| 1977 | case LYS_LEAFLIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1978 | yprp_leaflist(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1979 | break; |
| 1980 | case LYS_LIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1981 | yprp_list(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1982 | break; |
| 1983 | case LYS_USES: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1984 | yprp_uses(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1985 | break; |
| 1986 | case LYS_ANYXML: |
| 1987 | case LYS_ANYDATA: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1988 | yprp_anydata(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1989 | break; |
| 1990 | case LYS_CASE: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1991 | yprp_case(pctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1992 | break; |
| 1993 | default: |
| 1994 | break; |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 1999 | yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2000 | { |
| 2001 | switch (node->nodetype) { |
| 2002 | case LYS_CONTAINER: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2003 | yprc_container(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2004 | break; |
| 2005 | case LYS_CHOICE: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2006 | yprc_choice(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2007 | break; |
| 2008 | case LYS_LEAF: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2009 | yprc_leaf(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2010 | break; |
| 2011 | case LYS_LEAFLIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2012 | yprc_leaflist(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2013 | break; |
| 2014 | case LYS_LIST: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2015 | yprc_list(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2016 | break; |
| 2017 | case LYS_ANYXML: |
| 2018 | case LYS_ANYDATA: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2019 | yprc_anydata(pctx, node); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2020 | break; |
| 2021 | default: |
| 2022 | break; |
| 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2027 | yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2028 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 2029 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2030 | struct lysp_deviate_add *add; |
| 2031 | struct lysp_deviate_rpl *rpl; |
| 2032 | struct lysp_deviate_del *del; |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2033 | struct lysp_deviate *elem; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2034 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2035 | ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2036 | LEVEL++; |
| 2037 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2038 | yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2039 | ypr_description(pctx, deviation->dsc, deviation->exts, NULL); |
| 2040 | ypr_reference(pctx, deviation->ref, deviation->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2041 | |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2042 | LY_LIST_FOR(deviation->deviates, elem) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2043 | ly_print_(pctx->out, "%*sdeviate ", INDENT); |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2044 | if (elem->mod == LYS_DEV_NOT_SUPPORTED) { |
| 2045 | if (elem->exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2046 | ly_print_(pctx->out, "not-supported {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2047 | LEVEL++; |
| 2048 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2049 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2050 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2051 | ly_print_(pctx->out, "not-supported;\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2052 | continue; |
| 2053 | } |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2054 | } else if (elem->mod == LYS_DEV_ADD) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2055 | add = (struct lysp_deviate_add *)elem; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2056 | ly_print_(pctx->out, "add {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2057 | LEVEL++; |
| 2058 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2059 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2060 | ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, 0, add->exts); |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2061 | LY_ARRAY_FOR(add->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2062 | yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2063 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2064 | LY_ARRAY_FOR(add->uniques, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2065 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(add->uniques[u].flags), |
| 2066 | add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2067 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2068 | LY_ARRAY_FOR(add->dflts, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2069 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(add->dflts[u].flags), |
| 2070 | add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2071 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2072 | ypr_config(pctx, add->flags, add->exts, NULL); |
| 2073 | ypr_mandatory(pctx, add->flags, add->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2074 | if (add->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2075 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2076 | } |
| 2077 | if (add->flags & LYS_SET_MAX) { |
| 2078 | if (add->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2079 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2080 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2081 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2082 | } |
| 2083 | } |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2084 | } else if (elem->mod == LYS_DEV_REPLACE) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2085 | rpl = (struct lysp_deviate_rpl *)elem; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2086 | ly_print_(pctx->out, "replace {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2087 | LEVEL++; |
| 2088 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2089 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2090 | if (rpl->type) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2091 | yprp_type(pctx, rpl->type); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2092 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2093 | ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, 0, rpl->exts); |
| 2094 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, YPR_IS_LYS_SINGLEQUOTED(rpl->dflt.flags), rpl->exts); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2095 | ypr_config(pctx, rpl->flags, rpl->exts, NULL); |
| 2096 | ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2097 | if (rpl->flags & LYS_SET_MIN) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2098 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2099 | } |
| 2100 | if (rpl->flags & LYS_SET_MAX) { |
| 2101 | if (rpl->max) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2102 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2103 | } else { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2104 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, rpl->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2105 | } |
| 2106 | } |
fredgan | 2b11ddb | 2019-10-21 11:03:39 +0800 | [diff] [blame] | 2107 | } else if (elem->mod == LYS_DEV_DELETE) { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 2108 | del = (struct lysp_deviate_del *)elem; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2109 | ly_print_(pctx->out, "delete {\n"); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2110 | LEVEL++; |
| 2111 | |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2112 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2113 | ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, 0, del->exts); |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2114 | LY_ARRAY_FOR(del->musts, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2115 | yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2116 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2117 | LY_ARRAY_FOR(del->uniques, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2118 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(del->uniques[u].flags), |
| 2119 | del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2120 | } |
Radek Krejci | 7eb54ba | 2020-05-18 16:30:04 +0200 | [diff] [blame] | 2121 | LY_ARRAY_FOR(del->dflts, u) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2122 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(del->dflts[u].flags), |
| 2123 | del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2124 | } |
| 2125 | } |
| 2126 | |
| 2127 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2128 | ypr_close(pctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2132 | ypr_close(pctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2133 | } |
| 2134 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2135 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2136 | yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2137 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 2138 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2139 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2140 | LY_ARRAY_FOR(modp->imports, u) { |
Michal Vasko | 3e9bc2f | 2020-11-04 17:13:56 +0100 | [diff] [blame] | 2141 | if (modp->imports[u].flags & LYS_INTERNAL) { |
| 2142 | continue; |
| 2143 | } |
| 2144 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2145 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2146 | ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2147 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2148 | yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2149 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, 0, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2150 | if (modp->imports[u].rev[0]) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2151 | ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, 0, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2152 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2153 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, 0, modp->imports[u].exts); |
| 2154 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, 0, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2155 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2156 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2157 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2158 | YPR_EXTRA_LINE(modp->imports, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2159 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2160 | LY_ARRAY_FOR(modp->includes, u) { |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 2161 | if (modp->includes[u].injected) { |
| 2162 | /* do not print the includes injected from submodules */ |
| 2163 | continue; |
| 2164 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2165 | YPR_EXTRA_LINE_PRINT(pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2166 | if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2167 | ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2168 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2169 | yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2170 | if (modp->includes[u].rev[0]) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2171 | ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, 0, modp->includes[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2172 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2173 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, 0, modp->includes[u].exts); |
| 2174 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, 0, modp->includes[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2175 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2176 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2177 | } else { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2178 | ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2179 | } |
| 2180 | } |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2181 | YPR_EXTRA_LINE(modp->includes, pctx); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2182 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2183 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2184 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2185 | yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2186 | { |
| 2187 | LY_ARRAY_COUNT_TYPE u; |
| 2188 | struct lysp_node *data; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2189 | struct lysp_node_action *action; |
| 2190 | struct lysp_node_notif *notif; |
| 2191 | struct lysp_node_grp *grp; |
| 2192 | struct lysp_node_augment *aug; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2193 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2194 | LY_ARRAY_FOR(modp->extensions, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2195 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2196 | yprp_extension(pctx, &modp->extensions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2197 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2198 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2199 | YPR_EXTRA_LINE(modp->extensions, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2200 | |
aPiecek | 6cf1d16 | 2023-11-08 16:07:00 +0100 | [diff] [blame] | 2201 | if (yprp_extension_has_printable_instances(modp->exts)) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2202 | YPR_EXTRA_LINE_PRINT(pctx); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2203 | yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2204 | } |
| 2205 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2206 | YPR_EXTRA_LINE(modp->exts, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2207 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2208 | LY_ARRAY_FOR(modp->features, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2209 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2210 | yprp_feature(pctx, &modp->features[u]); |
| 2211 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2212 | } |
| 2213 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2214 | YPR_EXTRA_LINE(modp->features, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2215 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2216 | LY_ARRAY_FOR(modp->identities, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2217 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2218 | yprp_identity(pctx, &modp->identities[u]); |
| 2219 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2220 | } |
| 2221 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2222 | YPR_EXTRA_LINE(modp->identities, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2223 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2224 | LY_ARRAY_FOR(modp->typedefs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2225 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2226 | yprp_typedef(pctx, &modp->typedefs[u]); |
| 2227 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2228 | } |
| 2229 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2230 | YPR_EXTRA_LINE(modp->typedefs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2231 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2232 | LY_LIST_FOR(modp->groupings, grp) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2233 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2234 | yprp_grouping(pctx, grp); |
| 2235 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2236 | } |
| 2237 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2238 | YPR_EXTRA_LINE(modp->groupings, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2239 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2240 | LY_LIST_FOR(modp->data, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2241 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2242 | yprp_node(pctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2243 | } |
| 2244 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2245 | YPR_EXTRA_LINE(modp->data, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2246 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2247 | LY_LIST_FOR(modp->augments, aug) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2248 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2249 | yprp_augment(pctx, aug); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2250 | } |
| 2251 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2252 | YPR_EXTRA_LINE(modp->augments, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2253 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2254 | LY_LIST_FOR(modp->rpcs, action) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2255 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2256 | yprp_action(pctx, action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2257 | } |
| 2258 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2259 | YPR_EXTRA_LINE(modp->rpcs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2260 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2261 | LY_LIST_FOR(modp->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2262 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2263 | yprp_notification(pctx, notif); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2264 | } |
| 2265 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2266 | YPR_EXTRA_LINE(modp->notifs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2267 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2268 | LY_ARRAY_FOR(modp->deviations, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2269 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2270 | yprp_deviation(pctx, &modp->deviations[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2271 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2272 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2273 | YPR_EXTRA_LINE(modp->deviations, pctx); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | LY_ERR |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 2277 | yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2278 | { |
| 2279 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 2280 | const struct lys_module *module = modp->mod; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2281 | struct lys_ypr_ctx pctx_ = { |
| 2282 | .out = out, |
| 2283 | .level = 0, |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2284 | .options = options, |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2285 | .module = module, |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2286 | .schema = LYS_YPR_PARSED |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2287 | }, *pctx = &pctx_; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2288 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2289 | ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2290 | LEVEL++; |
| 2291 | |
| 2292 | /* module-header-stmts */ |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 2293 | if (modp->version) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2294 | ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, modp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2295 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2296 | ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modp->exts); |
| 2297 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2298 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2299 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2300 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2301 | /* linkage-stmts (import/include) */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2302 | yang_print_parsed_linkage(pctx, modp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2303 | |
| 2304 | /* meta-stmts */ |
| 2305 | if (module->org || module->contact || module->dsc || module->ref) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2306 | YPR_EXTRA_LINE_PRINT(pctx); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2307 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2308 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modp->exts); |
| 2309 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modp->exts); |
| 2310 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modp->exts); |
| 2311 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2312 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2313 | YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2314 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2315 | /* revision-stmts */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2316 | LY_ARRAY_FOR(modp->revs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2317 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2318 | yprp_revision(pctx, &modp->revs[u]); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2319 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2320 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2321 | YPR_EXTRA_LINE(modp->revs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2322 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2323 | /* body-stmts */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2324 | yang_print_parsed_body(pctx, modp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2325 | |
| 2326 | LEVEL--; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 2327 | ly_print_(out, "%*s}\n", INDENT); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2328 | ly_print_flush(out); |
| 2329 | |
| 2330 | return LY_SUCCESS; |
| 2331 | } |
| 2332 | |
| 2333 | static void |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2334 | yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2335 | { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2336 | ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2337 | LEVEL++; |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2338 | yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2339 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, 0, submodp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2340 | LEVEL--; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2341 | ly_print_(pctx->out, "%*s}\n", INDENT); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | LY_ERR |
Michal Vasko | 7997d5a | 2021-02-22 10:55:56 +0100 | [diff] [blame] | 2345 | yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options) |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2346 | { |
| 2347 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2348 | struct lys_ypr_ctx pctx_ = { |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2349 | .out = out, |
| 2350 | .level = 0, |
| 2351 | .options = options, |
| 2352 | .module = submodp->mod, |
| 2353 | .schema = LYS_YPR_PARSED |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2354 | }, *pctx = &pctx_; |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2355 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2356 | ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2357 | LEVEL++; |
| 2358 | |
| 2359 | /* submodule-header-stmts */ |
| 2360 | if (submodp->version) { |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2361 | ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, submodp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2362 | } |
| 2363 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2364 | yprp_belongsto(pctx, submodp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2365 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2366 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2367 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2368 | /* linkage-stmts (import/include) */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2369 | yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2370 | |
| 2371 | /* meta-stmts */ |
| 2372 | if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2373 | YPR_EXTRA_LINE_PRINT(pctx); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2374 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2375 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, 0, submodp->exts); |
| 2376 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, 0, submodp->exts); |
| 2377 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, 0, submodp->exts); |
| 2378 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, 0, submodp->exts); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2379 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2380 | YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2381 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2382 | /* revision-stmts */ |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2383 | LY_ARRAY_FOR(submodp->revs, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2384 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2385 | yprp_revision(pctx, &submodp->revs[u]); |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2386 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2387 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2388 | YPR_EXTRA_LINE(submodp->revs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2389 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2390 | /* body-stmts */ |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2391 | yang_print_parsed_body(pctx, (struct lysp_module *)submodp); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2392 | |
| 2393 | LEVEL--; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 2394 | ly_print_(out, "%*s}\n", INDENT); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2395 | ly_print_flush(out); |
| 2396 | |
| 2397 | return LY_SUCCESS; |
| 2398 | } |
| 2399 | |
| 2400 | LY_ERR |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 2401 | yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options) |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2402 | { |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2403 | struct lys_ypr_ctx pctx_ = { |
| 2404 | .out = out, |
| 2405 | .level = 0, |
| 2406 | .options = options, |
| 2407 | .module = node->module, |
| 2408 | .schema = LYS_YPR_COMPILED |
| 2409 | }, *pctx = &pctx_; |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2410 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2411 | yprc_node(pctx, node); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2412 | |
| 2413 | ly_print_flush(out); |
| 2414 | return LY_SUCCESS; |
| 2415 | } |
| 2416 | |
| 2417 | LY_ERR |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 2418 | yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2419 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 2420 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2421 | struct lysc_module *modc = module->compiled; |
Michal Vasko | 331303f | 2022-08-22 09:51:57 +0200 | [diff] [blame] | 2422 | struct lys_ypr_ctx pctx_ = { |
| 2423 | .out = out, |
| 2424 | .level = 0, |
| 2425 | .options = options, |
| 2426 | .module = module, |
| 2427 | .schema = LYS_YPR_COMPILED |
| 2428 | }, *pctx = &pctx_; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2429 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2430 | ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2431 | LEVEL++; |
| 2432 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2433 | /* module-header-stmts */ |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2434 | ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modc->exts); |
| 2435 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modc->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2436 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2437 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2438 | |
Michal Vasko | 7c8439f | 2020-08-05 13:25:19 +0200 | [diff] [blame] | 2439 | /* no linkage-stmts */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2440 | |
| 2441 | /* meta-stmts */ |
| 2442 | if (module->org || module->contact || module->dsc || module->ref) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2443 | YPR_EXTRA_LINE_PRINT(pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2444 | } |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2445 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modc->exts); |
| 2446 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modc->exts); |
| 2447 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modc->exts); |
| 2448 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modc->exts); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2449 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2450 | YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2451 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2452 | /* revision-stmts */ |
| 2453 | if (module->revision) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2454 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2455 | ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision); |
| 2456 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2457 | } |
| 2458 | |
| 2459 | /* body-stmts */ |
| 2460 | if (modc->exts) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2461 | YPR_EXTRA_LINE_PRINT(pctx); |
Michal Vasko | b26d09d | 2022-08-22 09:52:19 +0200 | [diff] [blame] | 2462 | yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL); |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2463 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2464 | } |
| 2465 | |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 2466 | LY_ARRAY_FOR(module->identities, u) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2467 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2468 | yprc_identity(pctx, &module->identities[u]); |
| 2469 | YPR_EXTRA_LINE(1, pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2470 | } |
| 2471 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2472 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2473 | struct lysc_node *data; |
| 2474 | struct lysc_node_action *rpc; |
| 2475 | struct lysc_node_notif *notif; |
| 2476 | |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2477 | LY_LIST_FOR(modc->data, data) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2478 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2479 | yprc_node(pctx, data); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2480 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2481 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2482 | YPR_EXTRA_LINE(modc->data, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2483 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2484 | LY_LIST_FOR(modc->rpcs, rpc) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2485 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2486 | yprc_action(pctx, rpc); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2487 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2488 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2489 | YPR_EXTRA_LINE(modc->rpcs, pctx); |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2490 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 2491 | LY_LIST_FOR(modc->notifs, notif) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2492 | YPR_EXTRA_LINE_PRINT(pctx); |
| 2493 | yprc_notification(pctx, notif); |
Radek Krejci | d8c0f5e | 2019-11-17 12:18:34 +0800 | [diff] [blame] | 2494 | } |
Radek Krejci | aa14a0c | 2020-09-04 11:16:47 +0200 | [diff] [blame] | 2495 | |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2496 | YPR_EXTRA_LINE(modc->notifs, pctx); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | LEVEL--; |
Michal Vasko | 5233e96 | 2020-08-14 14:26:20 +0200 | [diff] [blame] | 2500 | ly_print_(out, "%*s}\n", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2501 | ly_print_flush(out); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2502 | |
| 2503 | return LY_SUCCESS; |
| 2504 | } |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2505 | |
Michal Vasko | cc28b15 | 2022-08-23 14:44:54 +0200 | [diff] [blame] | 2506 | LIBYANG_API_DEF void |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2507 | lyplg_ext_print_info_extension_instance(struct lyspr_ctx *ctx, const struct lysc_ext_instance *ext, ly_bool *flag) |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2508 | { |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2509 | struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx; |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2510 | LY_ARRAY_COUNT_TYPE u, v; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2511 | ly_bool data_printed = 0; |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2512 | |
| 2513 | LY_ARRAY_FOR(ext->substmts, u) { |
| 2514 | switch (ext->substmts[u].stmt) { |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2515 | case LY_STMT_NOTIFICATION: |
| 2516 | case LY_STMT_INPUT: |
| 2517 | case LY_STMT_OUTPUT: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2518 | case LY_STMT_ACTION: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2519 | case LY_STMT_RPC: |
| 2520 | case LY_STMT_ANYDATA: |
| 2521 | case LY_STMT_ANYXML: |
| 2522 | case LY_STMT_CASE: |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2523 | case LY_STMT_CHOICE: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2524 | case LY_STMT_CONTAINER: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2525 | case LY_STMT_LEAF: |
| 2526 | case LY_STMT_LEAF_LIST: |
| 2527 | case LY_STMT_LIST: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2528 | case LY_STMT_USES: { |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2529 | const struct lysc_node *node; |
| 2530 | |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2531 | if (data_printed) { |
| 2532 | break; |
| 2533 | } |
| 2534 | |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2535 | LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) { |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2536 | ypr_open(pctx->out, flag); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2537 | if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) { |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2538 | yprc_notification(pctx, (struct lysc_node_notif *)node); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2539 | } else if (ext->substmts[u].stmt & (LY_STMT_INPUT | LY_STMT_OUTPUT)) { |
| 2540 | yprc_inout(pctx, (struct lysc_node_action_inout *)node, flag); |
| 2541 | } else if (ext->substmts[u].stmt & (LY_STMT_ACTION | LY_STMT_RPC)) { |
| 2542 | yprc_action(pctx, (struct lysc_node_action *)node); |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2543 | } else { |
| 2544 | yprc_node(pctx, node); |
| 2545 | } |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2546 | } |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2547 | |
| 2548 | /* all data nodes are stored in a linked list so all were printed */ |
| 2549 | data_printed = 1; |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2550 | break; |
| 2551 | } |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2552 | case LY_STMT_ARGUMENT: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2553 | case LY_STMT_CONTACT: |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2554 | case LY_STMT_DESCRIPTION: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2555 | case LY_STMT_ERROR_APP_TAG: |
| 2556 | case LY_STMT_ERROR_MESSAGE: |
| 2557 | case LY_STMT_KEY: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2558 | case LY_STMT_MODIFIER: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2559 | case LY_STMT_NAMESPACE: |
| 2560 | case LY_STMT_ORGANIZATION: |
| 2561 | case LY_STMT_PRESENCE: |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2562 | case LY_STMT_REFERENCE: |
| 2563 | case LY_STMT_UNITS: |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 2564 | if (*(const char **)ext->substmts[u].storage) { |
| 2565 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2566 | ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, 0, ext->exts); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2567 | } |
| 2568 | break; |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2569 | case LY_STMT_BIT: |
| 2570 | case LY_STMT_ENUM: { |
| 2571 | const struct lysc_type_bitenum_item *items = *(struct lysc_type_bitenum_item **)ext->substmts[u].storage; |
| 2572 | |
| 2573 | yprc_bits_enum(pctx, items, ext->substmts[u].stmt == LY_STMT_BIT ? LY_TYPE_BITS : LY_TYPE_ENUM, flag); |
| 2574 | break; |
| 2575 | } |
| 2576 | case LY_STMT_CONFIG: |
| 2577 | ypr_config(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag); |
| 2578 | break; |
| 2579 | case LY_STMT_EXTENSION_INSTANCE: |
| 2580 | yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, |
| 2581 | *(struct lysc_ext_instance **)ext->substmts[u].storage, flag); |
| 2582 | break; |
| 2583 | case LY_STMT_FRACTION_DIGITS: |
| 2584 | if (*(uint8_t *)ext->substmts[u].storage) { |
| 2585 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts, *(uint8_t *)ext->substmts[u].storage, flag); |
| 2586 | } |
| 2587 | break; |
| 2588 | case LY_STMT_IDENTITY: { |
| 2589 | const struct lysc_ident *idents = *(struct lysc_ident **)ext->substmts[u].storage; |
| 2590 | |
| 2591 | LY_ARRAY_FOR(idents, v) { |
| 2592 | yprc_identity(pctx, &idents[v]); |
| 2593 | } |
| 2594 | break; |
| 2595 | } |
| 2596 | case LY_STMT_LENGTH: |
| 2597 | if (*(struct lysc_range **)ext->substmts[u].storage) { |
| 2598 | yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_STRING, flag); |
| 2599 | } |
| 2600 | break; |
| 2601 | case LY_STMT_MANDATORY: |
| 2602 | ypr_mandatory(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag); |
| 2603 | break; |
| 2604 | case LY_STMT_MAX_ELEMENTS: { |
| 2605 | uint32_t max = *(uint32_t *)ext->substmts[u].storage; |
| 2606 | |
| 2607 | if (max) { |
| 2608 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, ext->exts, max, flag); |
| 2609 | } else { |
| 2610 | ypr_open(pctx->out, flag); |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2611 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, ext->exts); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2612 | } |
| 2613 | break; |
| 2614 | } |
| 2615 | case LY_STMT_MIN_ELEMENTS: |
| 2616 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)ext->substmts[u].storage, flag); |
| 2617 | break; |
| 2618 | case LY_STMT_ORDERED_BY: |
| 2619 | ypr_open(pctx->out, flag); |
| 2620 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2621 | (*(uint16_t *)ext->substmts[u].storage & LYS_ORDBY_USER) ? "user" : "system", 0, ext->exts); |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2622 | break; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 2623 | case LY_STMT_MUST: { |
| 2624 | const struct lysc_must *musts = *(struct lysc_must **)ext->substmts[u].storage; |
| 2625 | |
| 2626 | LY_ARRAY_FOR(musts, v) { |
| 2627 | yprc_must(pctx, &musts[v], flag); |
| 2628 | } |
| 2629 | break; |
| 2630 | } |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2631 | case LY_STMT_PATTERN: { |
| 2632 | const struct lysc_pattern *patterns = *(struct lysc_pattern **)ext->substmts[u].storage; |
| 2633 | |
| 2634 | LY_ARRAY_FOR(patterns, v) { |
| 2635 | yprc_pattern(pctx, &patterns[v], flag); |
| 2636 | } |
| 2637 | break; |
| 2638 | } |
| 2639 | case LY_STMT_POSITION: |
| 2640 | if (*(int64_t *)ext->substmts[u].storage) { |
| 2641 | ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag); |
| 2642 | } |
| 2643 | break; |
| 2644 | case LY_STMT_VALUE: |
| 2645 | if (*(int64_t *)ext->substmts[u].storage) { |
| 2646 | ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag); |
| 2647 | } |
| 2648 | break; |
| 2649 | case LY_STMT_RANGE: |
| 2650 | if (*(struct lysc_range **)ext->substmts[u].storage) { |
| 2651 | yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_UINT64, flag); |
| 2652 | } |
| 2653 | break; |
| 2654 | case LY_STMT_REQUIRE_INSTANCE: |
| 2655 | ypr_open(pctx->out, flag); |
| 2656 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)ext->substmts[u].storage ? "true" : "false", |
Michal Vasko | 72c6d64 | 2024-02-27 14:59:01 +0100 | [diff] [blame] | 2657 | 0, ext->exts); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2658 | break; |
| 2659 | case LY_STMT_STATUS: |
Michal Vasko | 61ad1ff | 2022-02-10 15:48:39 +0100 | [diff] [blame] | 2660 | ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2661 | break; |
| 2662 | case LY_STMT_TYPE: |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 2663 | if (*(const struct lysc_type **)ext->substmts[u].storage) { |
| 2664 | ypr_open(pctx->out, flag); |
| 2665 | yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2666 | } |
| 2667 | break; |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2668 | case LY_STMT_WHEN: |
| 2669 | yprc_when(pctx, *(struct lysc_when **)ext->substmts[u].storage, flag); |
| 2670 | break; |
| 2671 | case LY_STMT_AUGMENT: |
| 2672 | case LY_STMT_BASE: |
| 2673 | case LY_STMT_BELONGS_TO: |
| 2674 | case LY_STMT_DEFAULT: |
| 2675 | case LY_STMT_DEVIATE: |
| 2676 | case LY_STMT_DEVIATION: |
| 2677 | case LY_STMT_EXTENSION: |
| 2678 | case LY_STMT_FEATURE: |
| 2679 | case LY_STMT_GROUPING: |
| 2680 | case LY_STMT_IF_FEATURE: |
| 2681 | case LY_STMT_IMPORT: |
| 2682 | case LY_STMT_INCLUDE: |
| 2683 | case LY_STMT_MODULE: |
| 2684 | case LY_STMT_PATH: |
| 2685 | case LY_STMT_PREFIX: |
| 2686 | case LY_STMT_REFINE: |
| 2687 | case LY_STMT_REVISION: |
| 2688 | case LY_STMT_REVISION_DATE: |
| 2689 | case LY_STMT_SUBMODULE: |
| 2690 | case LY_STMT_TYPEDEF: |
| 2691 | case LY_STMT_UNIQUE: |
| 2692 | case LY_STMT_YANG_VERSION: |
| 2693 | case LY_STMT_YIN_ELEMENT: |
| 2694 | /* nothing to do */ |
| 2695 | break; |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2696 | default: |
Michal Vasko | a0ba01e | 2022-10-19 13:26:57 +0200 | [diff] [blame] | 2697 | LOGINT(pctx->module->ctx); |
Radek Krejci | adcf63d | 2021-02-09 10:21:18 +0100 | [diff] [blame] | 2698 | break; |
| 2699 | } |
| 2700 | } |
| 2701 | } |