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