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