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