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