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> |
| 4 | * @brief YANG printer |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2019 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
| 15 | #include "common.h" |
| 16 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 17 | #include <inttypes.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 22 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 23 | #include "extensions.h" |
| 24 | #include "log.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 25 | #include "printer_internal.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 26 | #include "tree.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 27 | #include "tree_schema.h" |
| 28 | #include "tree_schema_internal.h" |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 29 | #include "xpath.h" |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 30 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 31 | /** |
| 32 | * @brief Types of the YANG printers |
| 33 | */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 34 | enum schema_type { |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 35 | YPR_PARSED, /**< YANG printer of the parsed schema */ |
| 36 | YPR_COMPILED /**< YANG printer of the compiled schema */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 37 | }; |
| 38 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 39 | /** |
| 40 | * @brief YANG printer context. |
| 41 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 42 | struct ypr_ctx { |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 43 | struct lyout *out; /**< output specification */ |
| 44 | unsigned int level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */ |
| 45 | const struct lys_module *module; /**< schema to print */ |
| 46 | enum schema_type schema; /**< type of the schema to print */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 47 | }; |
| 48 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 49 | #define LEVEL ctx->level /**< current level */ |
| 50 | #define INDENT (LEVEL)*2,"" /**< indentation parameters for printer functions */ |
| 51 | |
| 52 | /** |
| 53 | * @brief Print the given text as content of a double quoted YANG string, |
| 54 | * including encoding characters that have special meanings. The quotation marks |
| 55 | * are not printed. |
| 56 | * |
| 57 | * Follows RFC 7950, section 6.1.3. |
| 58 | * |
| 59 | * @param[in] out Output specification. |
| 60 | * @param[in] text String to be printed. |
| 61 | * @param[in] len Length of the string from @p text to be printed. In case of 0, |
| 62 | * the @p text is printed completely as a NULL-terminated string. |
| 63 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 64 | static void |
| 65 | ypr_encode(struct lyout *out, const char *text, int len) |
| 66 | { |
| 67 | int i, start_len; |
| 68 | const char *start; |
| 69 | char special = 0; |
| 70 | |
| 71 | if (!len) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | if (len < 0) { |
| 76 | len = strlen(text); |
| 77 | } |
| 78 | |
| 79 | start = text; |
| 80 | start_len = 0; |
| 81 | for (i = 0; i < len; ++i) { |
| 82 | switch (text[i]) { |
| 83 | case '\n': |
| 84 | case '\t': |
| 85 | case '\"': |
| 86 | case '\\': |
| 87 | special = text[i]; |
| 88 | break; |
| 89 | default: |
| 90 | ++start_len; |
| 91 | break; |
| 92 | } |
| 93 | |
| 94 | if (special) { |
| 95 | ly_write(out, start, start_len); |
| 96 | switch (special) { |
| 97 | case '\n': |
| 98 | ly_write(out, "\\n", 2); |
| 99 | break; |
| 100 | case '\t': |
| 101 | ly_write(out, "\\t", 2); |
| 102 | break; |
| 103 | case '\"': |
| 104 | ly_write(out, "\\\"", 2); |
| 105 | break; |
| 106 | case '\\': |
| 107 | ly_write(out, "\\\\", 2); |
| 108 | break; |
| 109 | } |
| 110 | |
| 111 | start += start_len + 1; |
| 112 | start_len = 0; |
| 113 | |
| 114 | special = 0; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | ly_write(out, start, start_len); |
| 119 | } |
| 120 | |
| 121 | static void |
| 122 | ypr_open(struct lyout *out, int *flag) |
| 123 | { |
| 124 | if (flag && !*flag) { |
| 125 | *flag = 1; |
| 126 | ly_print(out, " {\n"); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | static void |
| 131 | ypr_close(struct ypr_ctx *ctx, int flag) |
| 132 | { |
| 133 | if (flag) { |
| 134 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 135 | } else { |
| 136 | ly_print(ctx->out, ";\n"); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | static void |
| 141 | ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, int singleline, int closed) |
| 142 | { |
| 143 | const char *s, *t; |
| 144 | |
| 145 | if (singleline) { |
| 146 | ly_print(ctx->out, "%*s%s \"", INDENT, name); |
| 147 | } else { |
| 148 | ly_print(ctx->out, "%*s%s\n", INDENT, name); |
| 149 | LEVEL++; |
| 150 | |
| 151 | ly_print(ctx->out, "%*s\"", INDENT); |
| 152 | } |
| 153 | t = text; |
| 154 | while ((s = strchr(t, '\n'))) { |
| 155 | ypr_encode(ctx->out, t, s - t); |
| 156 | ly_print(ctx->out, "\n"); |
| 157 | t = s + 1; |
| 158 | if (*t != '\n') { |
| 159 | ly_print(ctx->out, "%*s ", INDENT); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | ypr_encode(ctx->out, t, strlen(t)); |
| 164 | if (closed) { |
| 165 | ly_print(ctx->out, "\";\n"); |
| 166 | } else { |
| 167 | ly_print(ctx->out, "\""); |
| 168 | } |
| 169 | if (!singleline) { |
| 170 | LEVEL--; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 175 | yprp_stmt(struct ypr_ctx *ctx, struct lysp_stmt *stmt) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 176 | { |
| 177 | struct lysp_stmt *childstmt; |
| 178 | const char *s, *t; |
| 179 | |
| 180 | if (stmt->arg) { |
| 181 | if (stmt->flags) { |
| 182 | ly_print(ctx->out, "%*s%s\n", INDENT, stmt->stmt); |
| 183 | LEVEL++; |
| 184 | ly_print(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\''); |
| 185 | t = stmt->arg; |
| 186 | while ((s = strchr(t, '\n'))) { |
| 187 | ypr_encode(ctx->out, t, s - t); |
| 188 | ly_print(ctx->out, "\n"); |
| 189 | t = s + 1; |
| 190 | if (*t != '\n') { |
| 191 | ly_print(ctx->out, "%*s ", INDENT); |
| 192 | } |
| 193 | } |
| 194 | LEVEL--; |
| 195 | ypr_encode(ctx->out, t, strlen(t)); |
| 196 | ly_print(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n"); |
| 197 | } else { |
| 198 | ly_print(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n"); |
| 199 | } |
| 200 | } else { |
| 201 | ly_print(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n"); |
| 202 | } |
| 203 | |
| 204 | if (stmt->child) { |
| 205 | LEVEL++; |
| 206 | LY_LIST_FOR(stmt->child, childstmt) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 207 | yprp_stmt(ctx, childstmt); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 208 | } |
| 209 | LEVEL--; |
| 210 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @param[in] count Number of extensions to print, 0 to print them all. |
| 216 | */ |
| 217 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 218 | yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 219 | struct lysp_ext_instance *ext, int *flag, unsigned int count) |
| 220 | { |
| 221 | unsigned int u; |
| 222 | struct lysp_stmt *stmt; |
| 223 | |
| 224 | if (!count && ext) { |
| 225 | count = LY_ARRAY_SIZE(ext); |
| 226 | } |
| 227 | LY_ARRAY_FOR(ext, u) { |
| 228 | if (!count) { |
| 229 | break; |
| 230 | } |
| 231 | if (ext->insubstmt == substmt && ext->insubstmt_index == substmt_index) { |
| 232 | ypr_open(ctx->out, flag); |
| 233 | if (ext[u].argument) { |
| 234 | ly_print(ctx->out, "%*s%s %s%s", INDENT, ext[u].name, ext[u].argument, ext[u].child ? " {\n" : ";\n"); |
| 235 | } else { |
| 236 | ly_print(ctx->out, "%*s%s%s", INDENT, ext[u].name, ext[u].child ? " {\n" : ";\n"); |
| 237 | } |
| 238 | |
| 239 | if (ext[u].child) { |
| 240 | LEVEL++; |
| 241 | LY_LIST_FOR(ext[u].child, stmt) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 242 | yprp_stmt(ctx, stmt); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 243 | } |
| 244 | LEVEL--; |
| 245 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 246 | } |
| 247 | } |
| 248 | count--; |
| 249 | } |
| 250 | } |
| 251 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 252 | /** |
| 253 | * @param[in] count Number of extensions to print, 0 to print them all. |
| 254 | */ |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 255 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 256 | yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, |
| 257 | struct lysc_ext_instance *ext, int *flag, unsigned int count) |
| 258 | { |
| 259 | unsigned int u; |
| 260 | |
| 261 | if (!count && ext) { |
| 262 | count = LY_ARRAY_SIZE(ext); |
| 263 | } |
| 264 | LY_ARRAY_FOR(ext, u) { |
| 265 | if (!count) { |
| 266 | break; |
| 267 | } |
| 268 | /* TODO compiled extensions */ |
| 269 | (void) ctx; |
| 270 | (void) substmt; |
| 271 | (void) substmt_index; |
| 272 | (void) flag; |
| 273 | |
| 274 | count--; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | static void |
| 279 | ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 280 | { |
| 281 | unsigned int u; |
| 282 | int extflag = 0; |
| 283 | |
| 284 | if (!text) { |
| 285 | /* nothing to print */ |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) { |
| 290 | ly_print(ctx->out, "%*s%s %s", INDENT, ext_substmt_info[substmt].name, text); |
| 291 | } else { |
| 292 | ypr_text(ctx, ext_substmt_info[substmt].name, text, |
| 293 | (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, 0); |
| 294 | } |
| 295 | |
| 296 | LEVEL++; |
| 297 | LY_ARRAY_FOR(ext, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 298 | if (((struct lysp_ext_instance*)ext)[u].insubstmt != substmt || ((struct lysp_ext_instance*)ext)[u].insubstmt_index != substmt_index) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 299 | continue; |
| 300 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 301 | if (ctx->schema == YPR_PARSED) { |
| 302 | yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance*)ext)[u], &extflag, 1); |
| 303 | } else { |
| 304 | yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance*)ext)[u], &extflag, 1); |
| 305 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 306 | } |
| 307 | LEVEL--; |
| 308 | ypr_close(ctx, extflag); |
| 309 | } |
| 310 | |
| 311 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 312 | ypr_unsigned(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, unsigned int attr_value, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 313 | { |
| 314 | char *str; |
| 315 | |
| 316 | if (asprintf(&str, "%u", attr_value) == -1) { |
| 317 | LOGMEM(ctx->module->ctx); |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 318 | ctx->out->status = LY_EMEM; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 319 | return; |
| 320 | } |
| 321 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 322 | ypr_substmt(ctx, substmt, substmt_index, str, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 323 | free(str); |
| 324 | } |
| 325 | |
| 326 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 327 | ypr_signed(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, signed int attr_value, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 328 | { |
| 329 | char *str; |
| 330 | |
| 331 | if (asprintf(&str, "%d", attr_value) == -1) { |
| 332 | LOGMEM(ctx->module->ctx); |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 333 | ctx->out->status = LY_EMEM; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 334 | return; |
| 335 | } |
| 336 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 337 | ypr_substmt(ctx, substmt, substmt_index, str, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 338 | free(str); |
| 339 | } |
| 340 | |
| 341 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 342 | yprp_revision(struct ypr_ctx *ctx, const struct lysp_revision *rev) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 343 | { |
| 344 | if (rev->dsc || rev->ref || rev->exts) { |
| 345 | ly_print(ctx->out, "%*srevision %s {\n", INDENT, rev->date); |
| 346 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 347 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0); |
| 348 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts); |
| 349 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 350 | LEVEL--; |
| 351 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 352 | } else { |
| 353 | ly_print(ctx->out, "%*srevision %s;\n", INDENT, rev->date); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 358 | ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 359 | { |
| 360 | if (flags & LYS_MAND_MASK) { |
| 361 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 362 | ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
| 366 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 367 | ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 368 | { |
| 369 | if (flags & LYS_CONFIG_MASK) { |
| 370 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 371 | ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
| 375 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 376 | ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 377 | { |
| 378 | const char *status = NULL; |
| 379 | |
| 380 | if (flags & LYS_STATUS_CURR) { |
| 381 | ypr_open(ctx->out, flag); |
| 382 | status = "current"; |
| 383 | } else if (flags & LYS_STATUS_DEPRC) { |
| 384 | ypr_open(ctx->out, flag); |
| 385 | status = "deprecated"; |
| 386 | } else if (flags & LYS_STATUS_OBSLT) { |
| 387 | ypr_open(ctx->out, flag); |
| 388 | status = "obsolete"; |
| 389 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 390 | |
| 391 | ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 395 | ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 396 | { |
| 397 | if (dsc) { |
| 398 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 399 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
| 403 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 404 | ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 405 | { |
| 406 | if (ref) { |
| 407 | ypr_open(ctx->out, flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 408 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
| 412 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 413 | yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 414 | { |
| 415 | unsigned int u; |
| 416 | int extflag; |
| 417 | |
| 418 | LY_ARRAY_FOR(iff, u) { |
| 419 | ypr_open(ctx->out, flag); |
| 420 | extflag = 0; |
| 421 | |
| 422 | ly_print(ctx->out, "%*sif-feature \"%s\"", INDENT, iff[u]); |
| 423 | |
| 424 | /* extensions */ |
| 425 | LEVEL++; |
| 426 | LY_ARRAY_FOR(exts, u) { |
| 427 | if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) { |
| 428 | continue; |
| 429 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 430 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 431 | } |
| 432 | LEVEL--; |
| 433 | ypr_close(ctx, extflag); |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 438 | yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f) |
| 439 | { |
| 440 | int brackets_flag = *index_e; |
| 441 | uint8_t op; |
| 442 | |
| 443 | op = lysc_iff_getop(feat->expr, *index_e); |
| 444 | (*index_e)++; |
| 445 | |
| 446 | switch (op) { |
| 447 | case LYS_IFF_F: |
| 448 | if (ctx->module == feat->features[*index_f]->module) { |
| 449 | ly_print(ctx->out, "%s", feat->features[*index_f]->name); |
| 450 | } else { |
| 451 | ly_print(ctx->out, "%s:%s", feat->features[*index_f]->module->prefix, feat->features[*index_f]->name); |
| 452 | } |
| 453 | (*index_f)++; |
| 454 | break; |
| 455 | case LYS_IFF_NOT: |
| 456 | ly_print(ctx->out, "not "); |
| 457 | yprc_iffeature(ctx, feat, index_e, index_f); |
| 458 | break; |
| 459 | case LYS_IFF_AND: |
| 460 | if (brackets_flag) { |
| 461 | /* AND need brackets only if previous op was not */ |
| 462 | if (*index_e < 2 || lysc_iff_getop(feat->expr, *index_e - 2) != LYS_IFF_NOT) { |
| 463 | brackets_flag = 0; |
| 464 | } |
| 465 | } |
| 466 | /* falls through */ |
| 467 | case LYS_IFF_OR: |
| 468 | if (brackets_flag) { |
| 469 | ly_print(ctx->out, "("); |
| 470 | } |
| 471 | yprc_iffeature(ctx, feat, index_e, index_f); |
| 472 | ly_print(ctx->out, " %s ", op == LYS_IFF_OR ? "or" : "and"); |
| 473 | yprc_iffeature(ctx, feat, index_e, index_f); |
| 474 | if (brackets_flag) { |
| 475 | ly_print(ctx->out, ")"); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | |
| 480 | static void |
| 481 | yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag) |
| 482 | { |
Radek Krejci | 334ccc7 | 2019-06-12 13:49:29 +0200 | [diff] [blame^] | 483 | unsigned int u, v; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 484 | int extflag; |
| 485 | |
| 486 | LY_ARRAY_FOR(iff, u) { |
| 487 | int index_e = 0, index_f = 0; |
| 488 | |
| 489 | ypr_open(ctx->out, flag); |
| 490 | extflag = 0; |
| 491 | |
Radek Krejci | 989e53b | 2019-04-30 09:51:09 +0200 | [diff] [blame] | 492 | ly_print(ctx->out, "%*sif-feature \"", INDENT); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 493 | yprc_iffeature(ctx, iff, &index_e, &index_f); |
Radek Krejci | 989e53b | 2019-04-30 09:51:09 +0200 | [diff] [blame] | 494 | ly_print(ctx->out, "\""); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 495 | |
| 496 | /* extensions */ |
| 497 | LEVEL++; |
Radek Krejci | 334ccc7 | 2019-06-12 13:49:29 +0200 | [diff] [blame^] | 498 | LY_ARRAY_FOR(exts, v) { |
| 499 | if (exts[v].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[v].insubstmt_index != u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 500 | continue; |
| 501 | } |
Radek Krejci | 334ccc7 | 2019-06-12 13:49:29 +0200 | [diff] [blame^] | 502 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[v], &extflag, 1); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 503 | } |
| 504 | LEVEL--; |
| 505 | ypr_close(ctx, extflag); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | static void |
| 510 | yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 511 | { |
| 512 | int flag = 0, flag2 = 0; |
| 513 | unsigned int i; |
| 514 | |
| 515 | ly_print(ctx->out, "%*sextension %s", INDENT, ext->name); |
| 516 | LEVEL++; |
| 517 | |
| 518 | if (ext->exts) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 519 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | if (ext->argument) { |
| 523 | ypr_open(ctx->out, &flag); |
| 524 | ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument); |
| 525 | if (ext->exts) { |
| 526 | LEVEL++; |
| 527 | i = -1; |
| 528 | while ((i = lysp_ext_instance_iter(ext->exts, i + 1, LYEXT_SUBSTMT_ARGUMENT)) != LY_ARRAY_SIZE(ext->exts)) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 529 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 530 | } |
| 531 | LEVEL--; |
| 532 | } |
| 533 | if ((ext->flags & LYS_YINELEM_MASK) || |
| 534 | (ext->exts && lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YINELEM) != LY_ARRAY_SIZE(ext->exts))) { |
| 535 | ypr_open(ctx->out, &flag2); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 536 | ypr_substmt(ctx, LYEXT_SUBSTMT_YINELEM, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 537 | } |
| 538 | ypr_close(ctx, flag2); |
| 539 | } |
| 540 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 541 | ypr_status(ctx, ext->flags, ext->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 542 | ypr_description(ctx, ext->dsc, ext->exts, &flag); |
| 543 | ypr_reference(ctx, ext->ref, ext->exts, &flag); |
| 544 | |
| 545 | LEVEL--; |
| 546 | ypr_close(ctx, flag); |
| 547 | } |
| 548 | |
| 549 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 550 | yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 551 | { |
| 552 | int flag = 0; |
| 553 | |
| 554 | ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name); |
| 555 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 556 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0); |
| 557 | yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag); |
| 558 | ypr_status(ctx, feat->flags, feat->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 559 | ypr_description(ctx, feat->dsc, feat->exts, &flag); |
| 560 | ypr_reference(ctx, feat->ref, feat->exts, &flag); |
| 561 | LEVEL--; |
| 562 | ypr_close(ctx, flag); |
| 563 | } |
| 564 | |
| 565 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 566 | yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat) |
| 567 | { |
| 568 | int flag = 0; |
| 569 | |
| 570 | ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name); |
| 571 | LEVEL++; |
| 572 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0); |
| 573 | yprc_iffeatures(ctx, feat->iffeatures, feat->exts, &flag); |
| 574 | ypr_status(ctx, feat->flags, feat->exts, &flag); |
| 575 | ypr_description(ctx, feat->dsc, feat->exts, &flag); |
| 576 | ypr_reference(ctx, feat->ref, feat->exts, &flag); |
| 577 | LEVEL--; |
| 578 | ypr_close(ctx, flag); |
| 579 | } |
| 580 | |
| 581 | static void |
| 582 | yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 583 | { |
| 584 | int flag = 0; |
| 585 | unsigned int u; |
| 586 | |
| 587 | ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name); |
| 588 | LEVEL++; |
| 589 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 590 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0); |
| 591 | yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 592 | |
| 593 | LY_ARRAY_FOR(ident->bases, u) { |
| 594 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 595 | ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 598 | ypr_status(ctx, ident->flags, ident->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 599 | ypr_description(ctx, ident->dsc, ident->exts, &flag); |
| 600 | ypr_reference(ctx, ident->ref, ident->exts, &flag); |
| 601 | |
| 602 | LEVEL--; |
| 603 | ypr_close(ctx, flag); |
| 604 | } |
| 605 | |
| 606 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 607 | yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident) |
| 608 | { |
| 609 | int flag = 0; |
| 610 | unsigned int u; |
| 611 | |
| 612 | ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name); |
| 613 | LEVEL++; |
| 614 | |
| 615 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0); |
| 616 | yprc_iffeatures(ctx, ident->iffeatures, ident->exts, &flag); |
| 617 | |
| 618 | LY_ARRAY_FOR(ident->derived, u) { |
| 619 | ypr_open(ctx->out, &flag); |
| 620 | if (ctx->module != ident->derived[u]->module) { |
| 621 | ly_print(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name); |
| 622 | } else { |
| 623 | ly_print(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | ypr_status(ctx, ident->flags, ident->exts, &flag); |
| 628 | ypr_description(ctx, ident->dsc, ident->exts, &flag); |
| 629 | ypr_reference(ctx, ident->ref, ident->exts, &flag); |
| 630 | |
| 631 | LEVEL--; |
| 632 | ypr_close(ctx, flag); |
| 633 | } |
| 634 | |
| 635 | static void |
| 636 | yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 637 | { |
| 638 | int inner_flag = 0; |
| 639 | |
| 640 | if (!restr) { |
| 641 | return; |
| 642 | } |
| 643 | |
| 644 | ypr_open(ctx->out, flag); |
| 645 | ly_print(ctx->out, "%*s%s \"", INDENT, name); |
| 646 | ypr_encode(ctx->out, (restr->arg[0] != 0x15 && restr->arg[0] != 0x06) ? restr->arg : &restr->arg[1], -1); |
| 647 | ly_print(ctx->out, "\""); |
| 648 | |
| 649 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 650 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 651 | if (restr->arg[0] == 0x15) { |
| 652 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
| 653 | ypr_open(ctx->out, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 654 | ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 655 | } |
| 656 | if (restr->emsg) { |
| 657 | ypr_open(ctx->out, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 658 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 659 | } |
| 660 | if (restr->eapptag) { |
| 661 | ypr_open(ctx->out, &inner_flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 662 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, restr->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 663 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 664 | ypr_description(ctx, restr->dsc, restr->exts, &inner_flag); |
| 665 | ypr_reference(ctx, restr->ref, restr->exts, &inner_flag); |
| 666 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 667 | LEVEL--; |
| 668 | ypr_close(ctx, inner_flag); |
| 669 | } |
| 670 | |
| 671 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 672 | yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag) |
| 673 | { |
| 674 | int inner_flag = 0; |
| 675 | |
| 676 | ypr_open(ctx->out, flag); |
| 677 | ly_print(ctx->out, "%*smust \"", INDENT); |
| 678 | ypr_encode(ctx->out, must->cond->expr, -1); |
| 679 | ly_print(ctx->out, "\""); |
| 680 | |
| 681 | LEVEL++; |
| 682 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0); |
| 683 | if (must->emsg) { |
| 684 | ypr_open(ctx->out, &inner_flag); |
| 685 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, must->emsg, must->exts); |
| 686 | } |
| 687 | if (must->eapptag) { |
| 688 | ypr_open(ctx->out, &inner_flag); |
| 689 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, must->eapptag, must->exts); |
| 690 | } |
| 691 | ypr_description(ctx, must->dsc, must->exts, &inner_flag); |
| 692 | ypr_reference(ctx, must->ref, must->exts, &inner_flag); |
| 693 | |
| 694 | LEVEL--; |
| 695 | ypr_close(ctx, inner_flag); |
| 696 | } |
| 697 | |
| 698 | static void |
| 699 | yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag) |
| 700 | { |
| 701 | int inner_flag = 0; |
| 702 | unsigned int u; |
| 703 | |
Radek Krejci | 334ccc7 | 2019-06-12 13:49:29 +0200 | [diff] [blame^] | 704 | if (!range) { |
| 705 | return; |
| 706 | } |
| 707 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 708 | ypr_open(ctx->out, flag); |
Radek Krejci | 334ccc7 | 2019-06-12 13:49:29 +0200 | [diff] [blame^] | 709 | ly_print(ctx->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] | 710 | LY_ARRAY_FOR(range->parts, u) { |
| 711 | if (u > 0) { |
| 712 | ly_print(ctx->out, " | "); |
| 713 | } |
| 714 | if (range->parts[u].max_64 == range->parts[u].min_64) { |
| 715 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
| 716 | ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64); |
| 717 | } else { /* signed values */ |
| 718 | ly_print(ctx->out, "%"PRId64, range->parts[u].max_64); |
| 719 | } |
| 720 | } else { |
| 721 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
| 722 | ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64); |
| 723 | } else { /* signed values */ |
| 724 | ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64); |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | ly_print(ctx->out, "\""); |
| 729 | |
| 730 | LEVEL++; |
| 731 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0); |
| 732 | if (range->emsg) { |
| 733 | ypr_open(ctx->out, &inner_flag); |
| 734 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts); |
| 735 | } |
| 736 | if (range->eapptag) { |
| 737 | ypr_open(ctx->out, &inner_flag); |
| 738 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts); |
| 739 | } |
| 740 | ypr_description(ctx, range->dsc, range->exts, &inner_flag); |
| 741 | ypr_reference(ctx, range->ref, range->exts, &inner_flag); |
| 742 | |
| 743 | LEVEL--; |
| 744 | ypr_close(ctx, inner_flag); |
| 745 | } |
| 746 | |
| 747 | static void |
| 748 | yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag) |
| 749 | { |
| 750 | int inner_flag = 0; |
| 751 | |
| 752 | ypr_open(ctx->out, flag); |
| 753 | ly_print(ctx->out, "%*spattern \"", INDENT); |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 754 | ypr_encode(ctx->out, pattern->expr, -1); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 755 | ly_print(ctx->out, "\""); |
| 756 | |
| 757 | LEVEL++; |
| 758 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0); |
| 759 | if (pattern->inverted) { |
| 760 | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
| 761 | ypr_open(ctx->out, &inner_flag); |
| 762 | ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts); |
| 763 | } |
| 764 | if (pattern->emsg) { |
| 765 | ypr_open(ctx->out, &inner_flag); |
| 766 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts); |
| 767 | } |
| 768 | if (pattern->eapptag) { |
| 769 | ypr_open(ctx->out, &inner_flag); |
| 770 | ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts); |
| 771 | } |
| 772 | ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag); |
| 773 | ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag); |
| 774 | |
| 775 | LEVEL--; |
| 776 | ypr_close(ctx, inner_flag); |
| 777 | } |
| 778 | |
| 779 | static void |
| 780 | yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 781 | { |
| 782 | int inner_flag = 0; |
| 783 | |
| 784 | if (!when) { |
| 785 | return; |
| 786 | } |
| 787 | ypr_open(ctx->out, flag); |
| 788 | |
| 789 | ly_print(ctx->out, "%*swhen \"", INDENT); |
| 790 | ypr_encode(ctx->out, when->cond, -1); |
| 791 | ly_print(ctx->out, "\""); |
| 792 | |
| 793 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 794 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 795 | ypr_description(ctx, when->dsc, when->exts, &inner_flag); |
| 796 | ypr_reference(ctx, when->ref, when->exts, &inner_flag); |
| 797 | LEVEL--; |
| 798 | ypr_close(ctx, inner_flag); |
| 799 | } |
| 800 | |
| 801 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 802 | yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag) |
| 803 | { |
| 804 | int inner_flag = 0; |
| 805 | |
| 806 | if (!when) { |
| 807 | return; |
| 808 | } |
| 809 | ypr_open(ctx->out, flag); |
| 810 | |
| 811 | ly_print(ctx->out, "%*swhen \"", INDENT); |
| 812 | ypr_encode(ctx->out, when->cond->expr, -1); |
| 813 | ly_print(ctx->out, "\""); |
| 814 | |
| 815 | LEVEL++; |
| 816 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0); |
| 817 | ypr_description(ctx, when->dsc, when->exts, &inner_flag); |
| 818 | ypr_reference(ctx, when->ref, when->exts, &inner_flag); |
| 819 | LEVEL--; |
| 820 | ypr_close(ctx, inner_flag); |
| 821 | } |
| 822 | |
| 823 | static void |
| 824 | yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 825 | { |
| 826 | unsigned int u; |
| 827 | int inner_flag; |
| 828 | |
| 829 | LY_ARRAY_FOR(items, u) { |
| 830 | ypr_open(ctx->out, flag); |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 831 | if (type == LY_TYPE_BITS) { |
| 832 | ly_print(ctx->out, "%*sbit %s", INDENT, items[u].name); |
| 833 | } else { /* LY_TYPE_ENUM */ |
| 834 | ly_print(ctx->out, "%*senum \"", INDENT); |
| 835 | ypr_encode(ctx->out, items[u].name, -1); |
| 836 | ly_print(ctx->out, "\""); |
| 837 | } |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 838 | inner_flag = 0; |
| 839 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 840 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0); |
| 841 | yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 842 | if (items[u].flags & LYS_SET_VALUE) { |
| 843 | if (type == LY_TYPE_BITS) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 844 | ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 845 | } else { /* LY_TYPE_ENUM */ |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 846 | ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 847 | } |
| 848 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 849 | ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 850 | ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag); |
| 851 | ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag); |
| 852 | LEVEL--; |
| 853 | ypr_close(ctx, inner_flag); |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 858 | yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 859 | { |
| 860 | unsigned int u; |
| 861 | int flag = 0; |
| 862 | |
| 863 | ly_print(ctx->out, "%*stype %s", INDENT, type->name); |
| 864 | LEVEL++; |
| 865 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 866 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 867 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 868 | yprp_restr(ctx, type->range, "range", &flag); |
| 869 | yprp_restr(ctx, type->length, "length", &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 870 | LY_ARRAY_FOR(type->patterns, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 871 | yprp_restr(ctx, &type->patterns[u], "pattern", &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 872 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 873 | yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag); |
| 874 | yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 875 | |
| 876 | if (type->path) { |
| 877 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 878 | ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 879 | } |
| 880 | if (type->flags & LYS_SET_REQINST) { |
| 881 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 882 | ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 883 | } |
| 884 | if (type->flags & LYS_SET_FRDIGITS) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 885 | ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 886 | } |
| 887 | LY_ARRAY_FOR(type->bases, u) { |
| 888 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 889 | ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 890 | } |
| 891 | LY_ARRAY_FOR(type->types, u) { |
| 892 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 893 | yprp_type(ctx, &type->types[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 894 | } |
| 895 | |
| 896 | LEVEL--; |
| 897 | ypr_close(ctx, flag); |
| 898 | } |
| 899 | |
| 900 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 901 | yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type) |
| 902 | { |
| 903 | unsigned int u; |
| 904 | int flag = 0; |
| 905 | |
| 906 | ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype)); |
| 907 | LEVEL++; |
| 908 | |
| 909 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0); |
| 910 | if (type->dflt) { |
| 911 | ypr_open(ctx->out, &flag); |
| 912 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, type->dflt, type->exts); |
| 913 | } |
| 914 | |
| 915 | switch(type->basetype) { |
| 916 | case LY_TYPE_BINARY: { |
| 917 | struct lysc_type_bin *bin = (struct lysc_type_bin*)type; |
| 918 | yprc_range(ctx, bin->length, type->basetype, &flag); |
| 919 | break; |
| 920 | } |
| 921 | case LY_TYPE_UINT8: |
| 922 | case LY_TYPE_UINT16: |
| 923 | case LY_TYPE_UINT32: |
| 924 | case LY_TYPE_UINT64: |
| 925 | case LY_TYPE_INT8: |
| 926 | case LY_TYPE_INT16: |
| 927 | case LY_TYPE_INT32: |
| 928 | case LY_TYPE_INT64: { |
| 929 | struct lysc_type_num *num = (struct lysc_type_num*)type; |
| 930 | yprc_range(ctx, num->range, type->basetype, &flag); |
| 931 | break; |
| 932 | } |
| 933 | case LY_TYPE_STRING: { |
| 934 | struct lysc_type_str *str = (struct lysc_type_str*)type; |
| 935 | yprc_range(ctx, str->length, type->basetype, &flag); |
| 936 | LY_ARRAY_FOR(str->patterns, u) { |
| 937 | yprc_pattern(ctx, str->patterns[u], &flag); |
| 938 | } |
| 939 | break; |
| 940 | } |
| 941 | case LY_TYPE_BITS: |
| 942 | case LY_TYPE_ENUM: { |
| 943 | /* bits and enums structures are compatible */ |
| 944 | struct lysc_type_bits *bits = (struct lysc_type_bits*)type; |
| 945 | LY_ARRAY_FOR(bits->bits, u) { |
| 946 | struct lysc_type_bitenum_item *item = &bits->bits[u]; |
| 947 | int inner_flag = 0; |
| 948 | |
| 949 | ypr_open(ctx->out, &flag); |
| 950 | ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum"); |
| 951 | ypr_encode(ctx->out, item->name, -1); |
| 952 | ly_print(ctx->out, "\""); |
| 953 | LEVEL++; |
| 954 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0); |
| 955 | yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag); |
| 956 | if (type->basetype == LY_TYPE_BITS) { |
| 957 | ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag); |
| 958 | } else { /* LY_TYPE_ENUM */ |
| 959 | ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag); |
| 960 | } |
| 961 | ypr_status(ctx, item->flags, item->exts, &inner_flag); |
| 962 | ypr_description(ctx, item->dsc, item->exts, &inner_flag); |
| 963 | ypr_reference(ctx, item->ref, item->exts, &inner_flag); |
| 964 | LEVEL--; |
| 965 | ypr_close(ctx, inner_flag); |
| 966 | } |
| 967 | break; |
| 968 | } |
| 969 | case LY_TYPE_BOOL: |
| 970 | case LY_TYPE_EMPTY: |
| 971 | /* nothing to do */ |
| 972 | break; |
| 973 | case LY_TYPE_DEC64: { |
| 974 | struct lysc_type_dec *dec = (struct lysc_type_dec*)type; |
| 975 | ypr_open(ctx->out, &flag); |
| 976 | ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag); |
| 977 | yprc_range(ctx, dec->range, dec->basetype, &flag); |
| 978 | break; |
| 979 | } |
| 980 | case LY_TYPE_IDENT: { |
| 981 | struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type; |
| 982 | LY_ARRAY_FOR(ident->bases, u) { |
| 983 | ypr_open(ctx->out, &flag); |
| 984 | ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts); |
| 985 | } |
| 986 | break; |
| 987 | } |
| 988 | case LY_TYPE_INST: { |
| 989 | struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type; |
| 990 | ypr_open(ctx->out, &flag); |
| 991 | ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts); |
| 992 | break; |
| 993 | } |
| 994 | case LY_TYPE_LEAFREF: { |
| 995 | struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type; |
| 996 | ypr_open(ctx->out, &flag); |
| 997 | ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts); |
| 998 | ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts); |
| 999 | yprc_type(ctx, lr->realtype); |
| 1000 | break; |
| 1001 | } |
| 1002 | case LY_TYPE_UNION: { |
| 1003 | struct lysc_type_union *un = (struct lysc_type_union*)type; |
| 1004 | LY_ARRAY_FOR(un->types, u) { |
| 1005 | ypr_open(ctx->out, &flag); |
| 1006 | yprc_type(ctx, un->types[u]); |
| 1007 | } |
| 1008 | break; |
| 1009 | } |
| 1010 | default: |
| 1011 | LOGINT(ctx->module->ctx); |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1012 | ctx->out->status = LY_EINT; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | LEVEL--; |
| 1016 | ypr_close(ctx, flag); |
| 1017 | } |
| 1018 | |
| 1019 | static void |
| 1020 | yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1021 | { |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1022 | LYOUT_CHECK(ctx->out); |
| 1023 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1024 | ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name); |
| 1025 | LEVEL++; |
| 1026 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1027 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1028 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1029 | yprp_type(ctx, &tpdf->type); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1030 | |
| 1031 | if (tpdf->units) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1032 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1033 | } |
| 1034 | if (tpdf->dflt) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1035 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1036 | } |
| 1037 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1038 | ypr_status(ctx, tpdf->flags, tpdf->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1039 | ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL); |
| 1040 | ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL); |
| 1041 | |
| 1042 | LEVEL--; |
| 1043 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1044 | } |
| 1045 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1046 | static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node); |
| 1047 | static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node); |
| 1048 | static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1049 | |
| 1050 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1051 | yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1052 | { |
| 1053 | unsigned int u; |
| 1054 | int flag = 0; |
| 1055 | struct lysp_node *data; |
| 1056 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1057 | LYOUT_CHECK(ctx->out); |
| 1058 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1059 | ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name); |
| 1060 | LEVEL++; |
| 1061 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1062 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0); |
| 1063 | ypr_status(ctx, grp->flags, grp->exts, &flag); |
Radek Krejci | fc81ea8 | 2019-04-18 13:27:22 +0200 | [diff] [blame] | 1064 | ypr_description(ctx, grp->dsc, grp->exts, &flag); |
| 1065 | ypr_reference(ctx, grp->ref, grp->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1066 | |
| 1067 | LY_ARRAY_FOR(grp->typedefs, u) { |
Radek Krejci | 59edcf7 | 2019-05-02 09:53:17 +0200 | [diff] [blame] | 1068 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1069 | yprp_typedef(ctx, &grp->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | LY_ARRAY_FOR(grp->groupings, u) { |
Radek Krejci | 59edcf7 | 2019-05-02 09:53:17 +0200 | [diff] [blame] | 1073 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1074 | yprp_grouping(ctx, &grp->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | LY_LIST_FOR(grp->data, data) { |
Radek Krejci | fc81ea8 | 2019-04-18 13:27:22 +0200 | [diff] [blame] | 1078 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1079 | yprp_node(ctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | LY_ARRAY_FOR(grp->actions, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1083 | yprp_action(ctx, &grp->actions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | LEVEL--; |
| 1087 | ypr_close(ctx, flag); |
| 1088 | } |
| 1089 | |
| 1090 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1091 | yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1092 | { |
| 1093 | unsigned int u; |
| 1094 | struct lysp_node *data; |
| 1095 | |
| 1096 | if (!inout->nodetype) { |
| 1097 | /* nodetype not set -> input/output is empty */ |
| 1098 | return; |
| 1099 | } |
| 1100 | ypr_open(ctx->out, flag); |
| 1101 | |
| 1102 | ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output")); |
| 1103 | LEVEL++; |
| 1104 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1105 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1106 | LY_ARRAY_FOR(inout->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1107 | yprp_restr(ctx, &inout->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1108 | } |
| 1109 | LY_ARRAY_FOR(inout->typedefs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1110 | yprp_typedef(ctx, &inout->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1111 | } |
| 1112 | LY_ARRAY_FOR(inout->groupings, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1113 | yprp_grouping(ctx, &inout->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | LY_LIST_FOR(inout->data, data) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1117 | yprp_node(ctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | LEVEL--; |
| 1121 | ypr_close(ctx, 1); |
| 1122 | } |
| 1123 | |
| 1124 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1125 | yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag) |
| 1126 | { |
| 1127 | unsigned int u; |
| 1128 | struct lysc_node *data; |
| 1129 | |
| 1130 | if (!inout->data) { |
| 1131 | /* input/output is empty */ |
| 1132 | return; |
| 1133 | } |
| 1134 | ypr_open(ctx->out, flag); |
| 1135 | |
| 1136 | ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output"); |
| 1137 | LEVEL++; |
| 1138 | |
| 1139 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0); |
| 1140 | LY_ARRAY_FOR(inout->musts, u) { |
| 1141 | yprc_must(ctx, &inout->musts[u], NULL); |
| 1142 | } |
| 1143 | |
| 1144 | LY_LIST_FOR(inout->data, data) { |
| 1145 | yprc_node(ctx, data); |
| 1146 | } |
| 1147 | |
| 1148 | LEVEL--; |
| 1149 | ypr_close(ctx, 1); |
| 1150 | } |
| 1151 | |
| 1152 | static void |
| 1153 | yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1154 | { |
| 1155 | unsigned int u; |
| 1156 | int flag = 0; |
| 1157 | struct lysp_node *data; |
| 1158 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1159 | LYOUT_CHECK(ctx->out); |
| 1160 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1161 | ly_print(ctx->out, "%*snotification %s", INDENT, notif->name); |
| 1162 | |
| 1163 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1164 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0); |
| 1165 | yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1166 | |
| 1167 | LY_ARRAY_FOR(notif->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1168 | yprp_restr(ctx, ¬if->musts[u], "must", &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1169 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1170 | ypr_status(ctx, notif->flags, notif->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1171 | ypr_description(ctx, notif->dsc, notif->exts, &flag); |
| 1172 | ypr_reference(ctx, notif->ref, notif->exts, &flag); |
| 1173 | |
| 1174 | LY_ARRAY_FOR(notif->typedefs, u) { |
| 1175 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1176 | yprp_typedef(ctx, ¬if->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | LY_ARRAY_FOR(notif->groupings, u) { |
| 1180 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1181 | yprp_grouping(ctx, ¬if->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | LY_LIST_FOR(notif->data, data) { |
| 1185 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1186 | yprp_node(ctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | LEVEL--; |
| 1190 | ypr_close(ctx, flag); |
| 1191 | } |
| 1192 | |
| 1193 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1194 | yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif) |
| 1195 | { |
| 1196 | unsigned int u; |
| 1197 | int flag = 0; |
| 1198 | struct lysc_node *data; |
| 1199 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1200 | LYOUT_CHECK(ctx->out); |
| 1201 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1202 | ly_print(ctx->out, "%*snotification %s", INDENT, notif->name); |
| 1203 | |
| 1204 | LEVEL++; |
| 1205 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0); |
| 1206 | yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag); |
| 1207 | |
| 1208 | LY_ARRAY_FOR(notif->musts, u) { |
| 1209 | yprc_must(ctx, ¬if->musts[u], &flag); |
| 1210 | } |
| 1211 | ypr_status(ctx, notif->flags, notif->exts, &flag); |
| 1212 | ypr_description(ctx, notif->dsc, notif->exts, &flag); |
| 1213 | ypr_reference(ctx, notif->ref, notif->exts, &flag); |
| 1214 | |
| 1215 | LY_LIST_FOR(notif->data, data) { |
| 1216 | ypr_open(ctx->out, &flag); |
| 1217 | yprc_node(ctx, data); |
| 1218 | } |
| 1219 | |
| 1220 | LEVEL--; |
| 1221 | ypr_close(ctx, flag); |
| 1222 | } |
| 1223 | |
| 1224 | static void |
| 1225 | yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1226 | { |
| 1227 | unsigned int u; |
| 1228 | int flag = 0; |
| 1229 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1230 | LYOUT_CHECK(ctx->out); |
| 1231 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1232 | ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
| 1233 | |
| 1234 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1235 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0); |
| 1236 | yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag); |
| 1237 | ypr_status(ctx, action->flags, action->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1238 | ypr_description(ctx, action->dsc, action->exts, &flag); |
| 1239 | ypr_reference(ctx, action->ref, action->exts, &flag); |
| 1240 | |
| 1241 | LY_ARRAY_FOR(action->typedefs, u) { |
| 1242 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1243 | yprp_typedef(ctx, &action->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | LY_ARRAY_FOR(action->groupings, u) { |
| 1247 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1248 | yprp_grouping(ctx, &action->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1249 | } |
| 1250 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1251 | yprp_inout(ctx, &action->input, &flag); |
| 1252 | yprp_inout(ctx, &action->output, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1253 | |
| 1254 | LEVEL--; |
| 1255 | ypr_close(ctx, flag); |
| 1256 | } |
| 1257 | |
| 1258 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1259 | yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action) |
| 1260 | { |
| 1261 | int flag = 0; |
| 1262 | |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1263 | LYOUT_CHECK(ctx->out); |
| 1264 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1265 | ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
| 1266 | |
| 1267 | LEVEL++; |
| 1268 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0); |
| 1269 | yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag); |
| 1270 | ypr_status(ctx, action->flags, action->exts, &flag); |
| 1271 | ypr_description(ctx, action->dsc, action->exts, &flag); |
| 1272 | ypr_reference(ctx, action->ref, action->exts, &flag); |
| 1273 | |
| 1274 | yprc_inout(ctx, action, &action->input, &flag); |
| 1275 | yprc_inout(ctx, action, &action->output, &flag); |
| 1276 | |
| 1277 | LEVEL--; |
| 1278 | ypr_close(ctx, flag); |
| 1279 | } |
| 1280 | |
| 1281 | static void |
| 1282 | yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1283 | { |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 1284 | ly_print(ctx->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] | 1285 | LEVEL++; |
| 1286 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1287 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0); |
| 1288 | yprp_when(ctx, node->when, flag); |
| 1289 | yprp_iffeatures(ctx, node->iffeatures, node->exts, flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1293 | yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1294 | { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1295 | unsigned int u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1296 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1297 | ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n"); |
| 1298 | LEVEL++; |
| 1299 | |
| 1300 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0); |
| 1301 | LY_ARRAY_FOR(node->when, u) { |
| 1302 | yprc_when(ctx, node->when[u], flag); |
| 1303 | } |
| 1304 | yprc_iffeatures(ctx, node->iffeatures, node->exts, flag); |
| 1305 | } |
| 1306 | |
| 1307 | /* macr oto unify the code */ |
| 1308 | #define YPR_NODE_COMMON2 \ |
| 1309 | ypr_config(ctx, node->flags, node->exts, flag); \ |
| 1310 | if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \ |
| 1311 | ypr_mandatory(ctx, node->flags, node->exts, flag); \ |
| 1312 | } \ |
| 1313 | ypr_status(ctx, node->flags, node->exts, flag); \ |
| 1314 | ypr_description(ctx, node->dsc, node->exts, flag); \ |
| 1315 | ypr_reference(ctx, node->ref, node->exts, flag) |
| 1316 | |
| 1317 | static void |
| 1318 | yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag) |
| 1319 | { |
| 1320 | YPR_NODE_COMMON2; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1324 | yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag) |
| 1325 | { |
| 1326 | YPR_NODE_COMMON2; |
| 1327 | } |
| 1328 | |
| 1329 | #undef YPR_NODE_COMMON2 |
| 1330 | |
| 1331 | static void |
| 1332 | yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1333 | { |
| 1334 | unsigned int u; |
| 1335 | int flag = 0; |
| 1336 | struct lysp_node *child; |
| 1337 | struct lysp_node_container *cont = (struct lysp_node_container *)node; |
| 1338 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1339 | yprp_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1340 | |
| 1341 | LY_ARRAY_FOR(cont->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1342 | yprp_restr(ctx, &cont->musts[u], "must", &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1343 | } |
| 1344 | if (cont->presence) { |
| 1345 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1346 | ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1347 | } |
| 1348 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1349 | yprp_node_common2(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1350 | |
| 1351 | LY_ARRAY_FOR(cont->typedefs, u) { |
| 1352 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1353 | yprp_typedef(ctx, &cont->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | LY_ARRAY_FOR(cont->groupings, u) { |
| 1357 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1358 | yprp_grouping(ctx, &cont->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | LY_LIST_FOR(cont->child, child) { |
| 1362 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1363 | yprp_node(ctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1364 | } |
| 1365 | |
| 1366 | LY_ARRAY_FOR(cont->actions, u) { |
| 1367 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1368 | yprp_action(ctx, &cont->actions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | LY_ARRAY_FOR(cont->notifs, u) { |
| 1372 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1373 | yprp_notification(ctx, &cont->notifs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | LEVEL--; |
| 1377 | ypr_close(ctx, flag); |
| 1378 | } |
| 1379 | |
| 1380 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1381 | yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1382 | { |
| 1383 | unsigned int u; |
| 1384 | int flag = 0; |
| 1385 | struct lysc_node *child; |
| 1386 | struct lysc_node_container *cont = (struct lysc_node_container *)node; |
| 1387 | |
| 1388 | yprc_node_common1(ctx, node, &flag); |
| 1389 | |
| 1390 | LY_ARRAY_FOR(cont->musts, u) { |
| 1391 | yprc_must(ctx, &cont->musts[u], &flag); |
| 1392 | } |
| 1393 | if (cont->flags & LYS_PRESENCE) { |
| 1394 | ypr_open(ctx->out, &flag); |
| 1395 | ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts); |
| 1396 | } |
| 1397 | |
| 1398 | yprc_node_common2(ctx, node, &flag); |
| 1399 | |
| 1400 | LY_LIST_FOR(cont->child, child) { |
| 1401 | ypr_open(ctx->out, &flag); |
| 1402 | yprc_node(ctx, child); |
| 1403 | } |
| 1404 | |
| 1405 | LY_ARRAY_FOR(cont->actions, u) { |
| 1406 | ypr_open(ctx->out, &flag); |
| 1407 | yprc_action(ctx, &cont->actions[u]); |
| 1408 | } |
| 1409 | |
| 1410 | LY_ARRAY_FOR(cont->notifs, u) { |
| 1411 | ypr_open(ctx->out, &flag); |
| 1412 | yprc_notification(ctx, &cont->notifs[u]); |
| 1413 | } |
| 1414 | |
| 1415 | LEVEL--; |
| 1416 | ypr_close(ctx, flag); |
| 1417 | } |
| 1418 | |
| 1419 | static void |
| 1420 | yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node) |
| 1421 | { |
| 1422 | int flag = 0; |
| 1423 | struct lysp_node *child; |
| 1424 | struct lysp_node_case *cas = (struct lysp_node_case *)node; |
| 1425 | |
| 1426 | yprp_node_common1(ctx, node, &flag); |
| 1427 | yprp_node_common2(ctx, node, &flag); |
| 1428 | |
| 1429 | LY_LIST_FOR(cas->child, child) { |
| 1430 | ypr_open(ctx->out, &flag); |
| 1431 | yprp_node(ctx, child); |
| 1432 | } |
| 1433 | |
| 1434 | LEVEL--; |
| 1435 | ypr_close(ctx, flag); |
| 1436 | } |
| 1437 | |
| 1438 | static void |
| 1439 | yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs) |
| 1440 | { |
| 1441 | int flag = 0; |
| 1442 | struct lysc_node *child; |
| 1443 | |
| 1444 | yprc_node_common1(ctx, (struct lysc_node*)cs, &flag); |
| 1445 | yprc_node_common2(ctx, (struct lysc_node*)cs, &flag); |
| 1446 | |
| 1447 | for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) { |
| 1448 | ypr_open(ctx->out, &flag); |
| 1449 | yprc_node(ctx, child); |
| 1450 | } |
| 1451 | |
| 1452 | LEVEL--; |
| 1453 | ypr_close(ctx, flag); |
| 1454 | } |
| 1455 | |
| 1456 | static void |
| 1457 | yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1458 | { |
| 1459 | int flag = 0; |
| 1460 | struct lysp_node *child; |
| 1461 | struct lysp_node_choice *choice = (struct lysp_node_choice *)node; |
| 1462 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1463 | yprp_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1464 | |
| 1465 | if (choice->dflt) { |
| 1466 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1467 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1468 | } |
| 1469 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1470 | yprp_node_common2(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1471 | |
| 1472 | LY_LIST_FOR(choice->child, child) { |
| 1473 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1474 | yprp_node(ctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | LEVEL--; |
| 1478 | ypr_close(ctx, flag); |
| 1479 | } |
| 1480 | |
| 1481 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1482 | yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1483 | { |
| 1484 | int flag = 0; |
| 1485 | struct lysc_node_case *cs; |
| 1486 | struct lysc_node_choice *choice = (struct lysc_node_choice *)node; |
| 1487 | |
| 1488 | yprc_node_common1(ctx, node, &flag); |
| 1489 | |
| 1490 | if (choice->dflt) { |
| 1491 | ypr_open(ctx->out, &flag); |
| 1492 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts); |
| 1493 | } |
| 1494 | |
| 1495 | yprc_node_common2(ctx, node, &flag); |
| 1496 | |
| 1497 | for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) { |
| 1498 | ypr_open(ctx->out, &flag); |
| 1499 | yprc_case(ctx, cs); |
| 1500 | } |
| 1501 | |
| 1502 | LEVEL--; |
| 1503 | ypr_close(ctx, flag); |
| 1504 | } |
| 1505 | |
| 1506 | static void |
| 1507 | yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1508 | { |
| 1509 | unsigned int u; |
| 1510 | struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node; |
| 1511 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1512 | yprp_node_common1(ctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1513 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1514 | yprp_type(ctx, &leaf->type); |
| 1515 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1516 | LY_ARRAY_FOR(leaf->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1517 | yprp_restr(ctx, &leaf->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1518 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1519 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1520 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1521 | yprp_node_common2(ctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1522 | |
| 1523 | LEVEL--; |
| 1524 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1525 | } |
| 1526 | |
| 1527 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1528 | yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1529 | { |
| 1530 | unsigned int u; |
| 1531 | struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node; |
| 1532 | |
| 1533 | yprc_node_common1(ctx, node, NULL); |
| 1534 | |
| 1535 | yprc_type(ctx, leaf->type); |
| 1536 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts); |
| 1537 | LY_ARRAY_FOR(leaf->musts, u) { |
| 1538 | yprc_must(ctx, &leaf->musts[u], NULL); |
| 1539 | } |
| 1540 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts); |
| 1541 | |
| 1542 | yprc_node_common2(ctx, node, NULL); |
| 1543 | |
| 1544 | LEVEL--; |
| 1545 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1546 | } |
| 1547 | |
| 1548 | static void |
| 1549 | yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1550 | { |
| 1551 | unsigned int u; |
| 1552 | struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node; |
| 1553 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1554 | yprp_node_common1(ctx, node, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1555 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1556 | yprp_type(ctx, &llist->type); |
| 1557 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1558 | LY_ARRAY_FOR(llist->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1559 | yprp_restr(ctx, &llist->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1560 | } |
| 1561 | LY_ARRAY_FOR(llist->dflts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1562 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1563 | } |
| 1564 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1565 | ypr_config(ctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1566 | |
| 1567 | if (llist->flags & LYS_SET_MIN) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1568 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1569 | } |
| 1570 | if (llist->flags & LYS_SET_MAX) { |
| 1571 | if (llist->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1572 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1573 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1574 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1575 | } |
| 1576 | } |
| 1577 | |
| 1578 | if (llist->flags & LYS_ORDBY_MASK) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1579 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1580 | } |
| 1581 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1582 | ypr_status(ctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1583 | ypr_description(ctx, node->dsc, node->exts, NULL); |
| 1584 | ypr_reference(ctx, node->ref, node->exts, NULL); |
| 1585 | |
| 1586 | LEVEL--; |
| 1587 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1588 | } |
| 1589 | |
| 1590 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1591 | yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1592 | { |
| 1593 | unsigned int u; |
| 1594 | struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node; |
| 1595 | |
| 1596 | yprc_node_common1(ctx, node, NULL); |
| 1597 | |
| 1598 | yprc_type(ctx, llist->type); |
| 1599 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts); |
| 1600 | LY_ARRAY_FOR(llist->musts, u) { |
| 1601 | yprc_must(ctx, &llist->musts[u], NULL); |
| 1602 | } |
| 1603 | LY_ARRAY_FOR(llist->dflts, u) { |
| 1604 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts); |
| 1605 | } |
| 1606 | |
| 1607 | ypr_config(ctx, node->flags, node->exts, NULL); |
| 1608 | |
| 1609 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL); |
| 1610 | if (llist->max) { |
| 1611 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL); |
| 1612 | } else { |
| 1613 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts); |
| 1614 | } |
| 1615 | |
| 1616 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts); |
| 1617 | |
| 1618 | ypr_status(ctx, node->flags, node->exts, NULL); |
| 1619 | ypr_description(ctx, node->dsc, node->exts, NULL); |
| 1620 | ypr_reference(ctx, node->ref, node->exts, NULL); |
| 1621 | |
| 1622 | LEVEL--; |
| 1623 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 1624 | } |
| 1625 | |
| 1626 | static void |
| 1627 | yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1628 | { |
| 1629 | unsigned int u; |
| 1630 | int flag = 0; |
| 1631 | struct lysp_node *child; |
| 1632 | struct lysp_node_list *list = (struct lysp_node_list *)node; |
| 1633 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1634 | yprp_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1635 | |
| 1636 | LY_ARRAY_FOR(list->musts, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1637 | yprp_restr(ctx, &list->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1638 | } |
| 1639 | if (list->key) { |
| 1640 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1641 | ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1642 | } |
| 1643 | LY_ARRAY_FOR(list->uniques, u) { |
| 1644 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1645 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1646 | } |
| 1647 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1648 | ypr_config(ctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1649 | |
| 1650 | if (list->flags & LYS_SET_MIN) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1651 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1652 | } |
| 1653 | if (list->flags & LYS_SET_MAX) { |
| 1654 | if (list->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1655 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1656 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1657 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1658 | } |
| 1659 | } |
| 1660 | |
| 1661 | if (list->flags & LYS_ORDBY_MASK) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1662 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1663 | } |
| 1664 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1665 | ypr_status(ctx, node->flags, node->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1666 | ypr_description(ctx, node->dsc, node->exts, NULL); |
| 1667 | ypr_reference(ctx, node->ref, node->exts, NULL); |
| 1668 | |
| 1669 | LY_ARRAY_FOR(list->typedefs, u) { |
| 1670 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1671 | yprp_typedef(ctx, &list->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | LY_ARRAY_FOR(list->groupings, u) { |
| 1675 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1676 | yprp_grouping(ctx, &list->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | LY_LIST_FOR(list->child, child) { |
| 1680 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1681 | yprp_node(ctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | LY_ARRAY_FOR(list->actions, u) { |
| 1685 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1686 | yprp_action(ctx, &list->actions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1687 | } |
| 1688 | |
| 1689 | LY_ARRAY_FOR(list->notifs, u) { |
| 1690 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1691 | yprp_notification(ctx, &list->notifs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | LEVEL--; |
| 1695 | ypr_close(ctx, flag); |
| 1696 | } |
| 1697 | |
| 1698 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1699 | yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1700 | { |
| 1701 | unsigned int u, v; |
| 1702 | int flag = 0; |
| 1703 | struct lysc_node *child; |
| 1704 | struct lysc_node_list *list = (struct lysc_node_list *)node; |
| 1705 | |
| 1706 | yprc_node_common1(ctx, node, &flag); |
| 1707 | |
| 1708 | LY_ARRAY_FOR(list->musts, u) { |
| 1709 | yprc_must(ctx, &list->musts[u], NULL); |
| 1710 | } |
| 1711 | if (list->keys) { |
| 1712 | ypr_open(ctx->out, &flag); |
| 1713 | ly_print(ctx->out, "%*skey \"", INDENT); |
| 1714 | LY_ARRAY_FOR(list->keys, u) { |
| 1715 | ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", list->keys[u]->name); |
| 1716 | } |
| 1717 | ypr_close(ctx, 0); |
| 1718 | } |
| 1719 | LY_ARRAY_FOR(list->uniques, u) { |
| 1720 | ypr_open(ctx->out, &flag); |
| 1721 | ly_print(ctx->out, "%*sunique \"", INDENT); |
| 1722 | LY_ARRAY_FOR(list->uniques[u], v) { |
| 1723 | ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name); |
| 1724 | } |
| 1725 | ypr_close(ctx, 0); |
| 1726 | } |
| 1727 | |
| 1728 | ypr_config(ctx, node->flags, node->exts, NULL); |
| 1729 | |
| 1730 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL); |
| 1731 | if (list->max) { |
| 1732 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL); |
| 1733 | } else { |
| 1734 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts); |
| 1735 | } |
| 1736 | |
| 1737 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts); |
| 1738 | |
| 1739 | ypr_status(ctx, node->flags, node->exts, NULL); |
| 1740 | ypr_description(ctx, node->dsc, node->exts, NULL); |
| 1741 | ypr_reference(ctx, node->ref, node->exts, NULL); |
| 1742 | |
| 1743 | LY_LIST_FOR(list->child, child) { |
| 1744 | ypr_open(ctx->out, &flag); |
| 1745 | yprc_node(ctx, child); |
| 1746 | } |
| 1747 | |
| 1748 | LY_ARRAY_FOR(list->actions, u) { |
| 1749 | ypr_open(ctx->out, &flag); |
| 1750 | yprc_action(ctx, &list->actions[u]); |
| 1751 | } |
| 1752 | |
| 1753 | LY_ARRAY_FOR(list->notifs, u) { |
| 1754 | ypr_open(ctx->out, &flag); |
| 1755 | yprc_notification(ctx, &list->notifs[u]); |
| 1756 | } |
| 1757 | |
| 1758 | LEVEL--; |
| 1759 | ypr_close(ctx, flag); |
| 1760 | } |
| 1761 | |
| 1762 | static void |
| 1763 | yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1764 | { |
| 1765 | unsigned int u; |
| 1766 | int flag = 0; |
| 1767 | |
| 1768 | ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid); |
| 1769 | LEVEL++; |
| 1770 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1771 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0); |
| 1772 | yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1773 | |
| 1774 | LY_ARRAY_FOR(refine->musts, u) { |
| 1775 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1776 | yprp_restr(ctx, &refine->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | if (refine->presence) { |
| 1780 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1781 | ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | LY_ARRAY_FOR(refine->dflts, u) { |
| 1785 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1786 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1787 | } |
| 1788 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1789 | ypr_config(ctx, refine->flags, refine->exts, &flag); |
| 1790 | ypr_mandatory(ctx, refine->flags, refine->exts, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1791 | |
| 1792 | if (refine->flags & LYS_SET_MIN) { |
| 1793 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1794 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1795 | } |
| 1796 | if (refine->flags & LYS_SET_MAX) { |
| 1797 | ypr_open(ctx->out, &flag); |
| 1798 | if (refine->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1799 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1800 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1801 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1802 | } |
| 1803 | } |
| 1804 | |
| 1805 | ypr_description(ctx, refine->dsc, refine->exts, &flag); |
| 1806 | ypr_reference(ctx, refine->ref, refine->exts, &flag); |
| 1807 | |
| 1808 | LEVEL--; |
| 1809 | ypr_close(ctx, flag); |
| 1810 | } |
| 1811 | |
| 1812 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1813 | yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1814 | { |
| 1815 | unsigned int u; |
| 1816 | struct lysp_node *child; |
| 1817 | |
| 1818 | ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid); |
| 1819 | LEVEL++; |
| 1820 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1821 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0); |
| 1822 | yprp_when(ctx, aug->when, NULL); |
| 1823 | yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL); |
| 1824 | ypr_status(ctx, aug->flags, aug->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1825 | ypr_description(ctx, aug->dsc, aug->exts, NULL); |
| 1826 | ypr_reference(ctx, aug->ref, aug->exts, NULL); |
| 1827 | |
| 1828 | LY_LIST_FOR(aug->child, child) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1829 | yprp_node(ctx, child); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | LY_ARRAY_FOR(aug->actions, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1833 | yprp_action(ctx, &aug->actions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | LY_ARRAY_FOR(aug->notifs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1837 | yprp_notification(ctx, &aug->notifs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | LEVEL--; |
Radek Krejci | fc81ea8 | 2019-04-18 13:27:22 +0200 | [diff] [blame] | 1841 | ypr_close(ctx, 1); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | |
| 1845 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1846 | yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1847 | { |
| 1848 | unsigned int u; |
| 1849 | int flag = 0; |
| 1850 | struct lysp_node_uses *uses = (struct lysp_node_uses *)node; |
| 1851 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1852 | yprp_node_common1(ctx, node, &flag); |
| 1853 | yprp_node_common2(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1854 | |
| 1855 | LY_ARRAY_FOR(uses->refines, u) { |
| 1856 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1857 | yprp_refine(ctx, &uses->refines[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | LY_ARRAY_FOR(uses->augments, u) { |
| 1861 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1862 | yprp_augment(ctx, &uses->augments[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | LEVEL--; |
| 1866 | ypr_close(ctx, flag); |
| 1867 | } |
| 1868 | |
| 1869 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1870 | yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1871 | { |
| 1872 | unsigned int u; |
| 1873 | int flag = 0; |
| 1874 | struct lysp_node_anydata *any = (struct lysp_node_anydata *)node; |
| 1875 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1876 | yprp_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1877 | |
| 1878 | LY_ARRAY_FOR(any->musts, u) { |
| 1879 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1880 | yprp_restr(ctx, &any->musts[u], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1881 | } |
| 1882 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1883 | yprp_node_common2(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1884 | |
| 1885 | LEVEL--; |
| 1886 | ypr_close(ctx, flag); |
| 1887 | } |
| 1888 | |
| 1889 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1890 | yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1891 | { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1892 | unsigned int u; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1893 | int flag = 0; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1894 | struct lysc_node_anydata *any = (struct lysc_node_anydata *)node; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1895 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1896 | yprc_node_common1(ctx, node, &flag); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1897 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1898 | LY_ARRAY_FOR(any->musts, u) { |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1899 | ypr_open(ctx->out, &flag); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1900 | yprc_must(ctx, &any->musts[u], NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1901 | } |
| 1902 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1903 | yprc_node_common2(ctx, node, &flag); |
| 1904 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1905 | LEVEL--; |
| 1906 | ypr_close(ctx, flag); |
| 1907 | } |
| 1908 | |
| 1909 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1910 | yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1911 | { |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1912 | LYOUT_CHECK(ctx->out); |
| 1913 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1914 | switch (node->nodetype) { |
| 1915 | case LYS_CONTAINER: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1916 | yprp_container(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1917 | break; |
| 1918 | case LYS_CHOICE: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1919 | yprp_choice(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1920 | break; |
| 1921 | case LYS_LEAF: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1922 | yprp_leaf(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1923 | break; |
| 1924 | case LYS_LEAFLIST: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1925 | yprp_leaflist(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1926 | break; |
| 1927 | case LYS_LIST: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1928 | yprp_list(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1929 | break; |
| 1930 | case LYS_USES: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1931 | yprp_uses(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1932 | break; |
| 1933 | case LYS_ANYXML: |
| 1934 | case LYS_ANYDATA: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1935 | yprp_anydata(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1936 | break; |
| 1937 | case LYS_CASE: |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1938 | yprp_case(ctx, node); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1939 | break; |
| 1940 | default: |
| 1941 | break; |
| 1942 | } |
| 1943 | } |
| 1944 | |
| 1945 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1946 | yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node) |
| 1947 | { |
Radek Krejci | 56cc087 | 2019-04-30 09:22:27 +0200 | [diff] [blame] | 1948 | LYOUT_CHECK(ctx->out); |
| 1949 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1950 | switch (node->nodetype) { |
| 1951 | case LYS_CONTAINER: |
| 1952 | yprc_container(ctx, node); |
| 1953 | break; |
| 1954 | case LYS_CHOICE: |
| 1955 | yprc_choice(ctx, node); |
| 1956 | break; |
| 1957 | case LYS_LEAF: |
| 1958 | yprc_leaf(ctx, node); |
| 1959 | break; |
| 1960 | case LYS_LEAFLIST: |
| 1961 | yprc_leaflist(ctx, node); |
| 1962 | break; |
| 1963 | case LYS_LIST: |
| 1964 | yprc_list(ctx, node); |
| 1965 | break; |
| 1966 | case LYS_ANYXML: |
| 1967 | case LYS_ANYDATA: |
| 1968 | yprc_anydata(ctx, node); |
| 1969 | break; |
| 1970 | default: |
| 1971 | break; |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | static void |
| 1976 | yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation) |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1977 | { |
| 1978 | unsigned int u, v; |
| 1979 | struct lysp_deviate_add *add; |
| 1980 | struct lysp_deviate_rpl *rpl; |
| 1981 | struct lysp_deviate_del *del; |
| 1982 | |
| 1983 | ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid); |
| 1984 | LEVEL++; |
| 1985 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1986 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1987 | ypr_description(ctx, deviation->dsc, deviation->exts, NULL); |
| 1988 | ypr_reference(ctx, deviation->ref, deviation->exts, NULL); |
| 1989 | |
| 1990 | LY_ARRAY_FOR(deviation->deviates, u) { |
| 1991 | ly_print(ctx->out, "%*sdeviate ", INDENT); |
| 1992 | if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) { |
| 1993 | if (deviation->deviates[u].exts) { |
| 1994 | ly_print(ctx->out, "not-supported {\n"); |
| 1995 | LEVEL++; |
| 1996 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 1997 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 1998 | } else { |
| 1999 | ly_print(ctx->out, "not-supported;\n"); |
| 2000 | continue; |
| 2001 | } |
| 2002 | } else if (deviation->deviates[u].mod == LYS_DEV_ADD) { |
| 2003 | add = (struct lysp_deviate_add*)&deviation->deviates[u]; |
| 2004 | ly_print(ctx->out, "add {\n"); |
| 2005 | LEVEL++; |
| 2006 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2007 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0); |
| 2008 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2009 | LY_ARRAY_FOR(add->musts, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2010 | yprp_restr(ctx, &add->musts[v], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2011 | } |
| 2012 | LY_ARRAY_FOR(add->uniques, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2013 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2014 | } |
| 2015 | LY_ARRAY_FOR(add->dflts, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2016 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2017 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2018 | ypr_config(ctx, add->flags, add->exts, NULL); |
| 2019 | ypr_mandatory(ctx, add->flags, add->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2020 | if (add->flags & LYS_SET_MIN) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2021 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2022 | } |
| 2023 | if (add->flags & LYS_SET_MAX) { |
| 2024 | if (add->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2025 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2026 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2027 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2028 | } |
| 2029 | } |
| 2030 | } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) { |
| 2031 | rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u]; |
| 2032 | ly_print(ctx->out, "replace {\n"); |
| 2033 | LEVEL++; |
| 2034 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2035 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2036 | if (rpl->type) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2037 | yprp_type(ctx, rpl->type); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2038 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2039 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts); |
| 2040 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts); |
| 2041 | ypr_config(ctx, rpl->flags, rpl->exts, NULL); |
| 2042 | ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2043 | if (rpl->flags & LYS_SET_MIN) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2044 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2045 | } |
| 2046 | if (rpl->flags & LYS_SET_MAX) { |
| 2047 | if (rpl->max) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2048 | ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2049 | } else { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2050 | ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2051 | } |
| 2052 | } |
| 2053 | } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) { |
| 2054 | del = (struct lysp_deviate_del*)&deviation->deviates[u]; |
| 2055 | ly_print(ctx->out, "delete {\n"); |
| 2056 | LEVEL++; |
| 2057 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2058 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0); |
| 2059 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2060 | LY_ARRAY_FOR(del->musts, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2061 | yprp_restr(ctx, &del->musts[v], "must", NULL); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2062 | } |
| 2063 | LY_ARRAY_FOR(del->uniques, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2064 | ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2065 | } |
| 2066 | LY_ARRAY_FOR(del->dflts, v) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2067 | ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | LEVEL--; |
| 2072 | ypr_close(ctx, 1); |
| 2073 | } |
| 2074 | |
| 2075 | LEVEL--; |
| 2076 | ypr_close(ctx, 1); |
| 2077 | } |
| 2078 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2079 | /** |
| 2080 | * @brief Minimal print of a schema. |
| 2081 | * |
| 2082 | * To print |
| 2083 | * a) compiled schema when it is not compiled or |
| 2084 | * b) parsed when the parsed form was already removed |
| 2085 | */ |
| 2086 | static LY_ERR |
| 2087 | ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module) |
| 2088 | { |
| 2089 | /* module-header-stmts */ |
| 2090 | if (module->version) { |
| 2091 | if (module->version) { |
| 2092 | ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL); |
| 2093 | } |
| 2094 | } |
| 2095 | ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL); |
| 2096 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL); |
| 2097 | |
| 2098 | /* meta-stmts */ |
| 2099 | if (module->org || module->contact || module->dsc || module->ref) { |
| 2100 | ly_print(ctx->out, "\n"); |
| 2101 | } |
| 2102 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL); |
| 2103 | ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL); |
| 2104 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL); |
| 2105 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL); |
| 2106 | |
| 2107 | /* revision-stmts */ |
| 2108 | if (module->revision) { |
| 2109 | ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision); |
| 2110 | } |
| 2111 | |
| 2112 | LEVEL--; |
| 2113 | ly_print(ctx->out, "%*s}\n", INDENT); |
| 2114 | ly_print_flush(ctx->out); |
| 2115 | |
| 2116 | return LY_SUCCESS; |
| 2117 | } |
| 2118 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2119 | LY_ERR |
| 2120 | yang_print_parsed(struct lyout *out, const struct lys_module *module) |
| 2121 | { |
| 2122 | unsigned int u; |
| 2123 | struct lysp_node *data; |
| 2124 | struct lysp_module *modp = module->parsed; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2125 | struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_; |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2126 | |
| 2127 | ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name); |
| 2128 | LEVEL++; |
| 2129 | |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2130 | if (!modp) { |
| 2131 | ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT); |
| 2132 | return ypr_missing_format(ctx, module); |
| 2133 | } |
| 2134 | |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2135 | /* module-header-stmts */ |
| 2136 | if (module->version) { |
| 2137 | if (module->version) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2138 | ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2139 | } |
| 2140 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2141 | ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts); |
| 2142 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2143 | |
| 2144 | /* linkage-stmts */ |
| 2145 | LY_ARRAY_FOR(modp->imports, u) { |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 2146 | ly_print(out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].module->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2147 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2148 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0); |
| 2149 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2150 | if (modp->imports[u].rev[0]) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2151 | ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2152 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2153 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts); |
| 2154 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2155 | LEVEL--; |
| 2156 | ly_print(out, "%*s}\n", INDENT); |
| 2157 | } |
| 2158 | LY_ARRAY_FOR(modp->includes, u) { |
| 2159 | if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) { |
Radek Krejci | 7871ce5 | 2019-06-11 16:44:56 +0200 | [diff] [blame] | 2160 | ly_print(out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].submodule->name); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2161 | LEVEL++; |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2162 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2163 | if (modp->includes[u].rev[0]) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2164 | ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2165 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2166 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts); |
| 2167 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2168 | LEVEL--; |
| 2169 | ly_print(out, "%*s}\n", INDENT); |
| 2170 | } else { |
| 2171 | ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name); |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | /* meta-stmts */ |
| 2176 | if (module->org || module->contact || module->dsc || module->ref) { |
| 2177 | ly_print(out, "\n"); |
| 2178 | } |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2179 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts); |
| 2180 | ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts); |
| 2181 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts); |
| 2182 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2183 | |
| 2184 | /* revision-stmts */ |
| 2185 | if (modp->revs) { |
| 2186 | ly_print(out, "\n"); |
| 2187 | } |
| 2188 | LY_ARRAY_FOR(modp->revs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2189 | yprp_revision(ctx, &modp->revs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2190 | } |
| 2191 | /* body-stmts */ |
| 2192 | LY_ARRAY_FOR(modp->extensions, u) { |
| 2193 | ly_print(out, "\n"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2194 | yprp_extension(ctx, &modp->extensions[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2195 | } |
| 2196 | if (modp->exts) { |
| 2197 | ly_print(out, "\n"); |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2198 | yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | LY_ARRAY_FOR(modp->features, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2202 | yprp_feature(ctx, &modp->features[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | LY_ARRAY_FOR(modp->identities, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2206 | yprp_identity(ctx, &modp->identities[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | LY_ARRAY_FOR(modp->typedefs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2210 | yprp_typedef(ctx, &modp->typedefs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | LY_ARRAY_FOR(modp->groupings, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2214 | yprp_grouping(ctx, &modp->groupings[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | LY_LIST_FOR(modp->data, data) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2218 | yprp_node(ctx, data); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | LY_ARRAY_FOR(modp->augments, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2222 | yprp_augment(ctx, &modp->augments[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2223 | } |
| 2224 | |
| 2225 | LY_ARRAY_FOR(modp->rpcs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2226 | yprp_action(ctx, &modp->rpcs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | LY_ARRAY_FOR(modp->notifs, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2230 | yprp_notification(ctx, &modp->notifs[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | LY_ARRAY_FOR(modp->deviations, u) { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2234 | yprp_deviation(ctx, &modp->deviations[u]); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2235 | } |
| 2236 | |
| 2237 | LEVEL--; |
| 2238 | ly_print(out, "%*s}\n", INDENT); |
| 2239 | ly_print_flush(out); |
| 2240 | |
| 2241 | return LY_SUCCESS; |
| 2242 | } |
| 2243 | |
| 2244 | LY_ERR |
| 2245 | yang_print_compiled(struct lyout *out, const struct lys_module *module) |
| 2246 | { |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 2247 | unsigned int u; |
| 2248 | struct lysc_node *data; |
| 2249 | struct lysc_module *modc = module->compiled; |
| 2250 | struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_; |
| 2251 | |
| 2252 | ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name); |
| 2253 | LEVEL++; |
| 2254 | |
| 2255 | if (!modc) { |
| 2256 | ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT); |
| 2257 | return ypr_missing_format(ctx, module); |
| 2258 | } |
| 2259 | |
| 2260 | /* module-header-stmts */ |
| 2261 | if (module->version) { |
| 2262 | if (module->version) { |
| 2263 | ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts); |
| 2264 | } |
| 2265 | } |
| 2266 | ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts); |
| 2267 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts); |
| 2268 | |
| 2269 | /* linkage-stmts */ |
| 2270 | LY_ARRAY_FOR(modc->imports, u) { |
| 2271 | ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name); |
| 2272 | LEVEL++; |
| 2273 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0); |
| 2274 | ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts); |
| 2275 | if (modc->imports[u].module->revision) { |
| 2276 | ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts); |
| 2277 | } |
| 2278 | LEVEL--; |
| 2279 | ly_print(out, "%*s}\n", INDENT); |
| 2280 | } |
| 2281 | |
| 2282 | /* meta-stmts */ |
| 2283 | if (module->org || module->contact || module->dsc || module->ref) { |
| 2284 | ly_print(out, "\n"); |
| 2285 | } |
| 2286 | ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts); |
| 2287 | ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts); |
| 2288 | ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts); |
| 2289 | ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts); |
| 2290 | |
| 2291 | /* revision-stmts */ |
| 2292 | if (module->revision) { |
| 2293 | ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision); |
| 2294 | } |
| 2295 | |
| 2296 | /* body-stmts */ |
| 2297 | if (modc->exts) { |
| 2298 | ly_print(out, "\n"); |
| 2299 | yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0); |
| 2300 | } |
| 2301 | |
| 2302 | LY_ARRAY_FOR(modc->features, u) { |
| 2303 | yprc_feature(ctx, &modc->features[u]); |
| 2304 | } |
| 2305 | |
| 2306 | LY_ARRAY_FOR(modc->identities, u) { |
| 2307 | yprc_identity(ctx, &modc->identities[u]); |
| 2308 | } |
| 2309 | |
| 2310 | LY_LIST_FOR(modc->data, data) { |
| 2311 | yprc_node(ctx, data); |
| 2312 | } |
| 2313 | |
| 2314 | LY_ARRAY_FOR(modc->rpcs, u) { |
| 2315 | yprc_action(ctx, &modc->rpcs[u]); |
| 2316 | } |
| 2317 | |
| 2318 | LY_ARRAY_FOR(modc->notifs, u) { |
| 2319 | yprc_notification(ctx, &modc->notifs[u]); |
| 2320 | } |
| 2321 | |
| 2322 | LEVEL--; |
| 2323 | ly_print(out, "%*s}\n", INDENT); |
| 2324 | ly_print_flush(out); |
Radek Krejci | d3ca063 | 2019-04-16 16:54:54 +0200 | [diff] [blame] | 2325 | |
| 2326 | return LY_SUCCESS; |
| 2327 | } |