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