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