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