blob: bf1c8a60104fd8a88f0ed271976a59d713b76648 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
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 Krejci535ea9f2020-05-29 16:01:05 +020015#define _GNU_SOURCE
Radek Krejcid3ca0632019-04-16 16:54:54 +020016
Radek Krejci693262f2019-04-29 15:23:20 +020017#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020018#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
Radek Krejci47fab892020-11-05 17:02:41 +010022#include <sys/types.h>
Radek Krejci693262f2019-04-29 15:23:20 +020023
Radek Krejci535ea9f2020-05-29 16:01:05 +020024#include "common.h"
Radek Krejciaa45bda2020-07-20 07:43:38 +020025#include "compat.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "log.h"
Radek Krejci47fab892020-11-05 17:02:41 +010027#include "out.h"
Michal Vaskoafac7822020-10-20 14:22:26 +020028#include "out_internal.h"
Radek Krejciadcf63d2021-02-09 10:21:18 +010029#include "plugins_exts.h"
30#include "plugins_exts_internal.h"
Radek Krejci47fab892020-11-05 17:02:41 +010031#include "plugins_types.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020032#include "printer_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020033#include "printer_schema.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020034#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020035#include "tree_data.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020036#include "tree_schema.h"
37#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020038#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020039
Radek Krejcie7b95092019-05-15 11:03:07 +020040/**
Radek Krejcie7b95092019-05-15 11:03:07 +020041 * @brief Print the given text as content of a double quoted YANG string,
42 * including encoding characters that have special meanings. The quotation marks
43 * are not printed.
44 *
45 * Follows RFC 7950, section 6.1.3.
46 *
47 * @param[in] out Output specification.
48 * @param[in] text String to be printed.
Radek Krejcif56e2a42019-09-09 14:15:25 +020049 * @param[in] len Length of the string from @p text to be printed. In case of -1,
Radek Krejcie7b95092019-05-15 11:03:07 +020050 * the @p text is printed completely as a NULL-terminated string.
51 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020052static void
Radek Krejci1deb5be2020-08-26 16:43:36 +020053ypr_encode(struct ly_out *out, const char *text, ssize_t len)
Radek Krejcid3ca0632019-04-16 16:54:54 +020054{
Radek Krejci1deb5be2020-08-26 16:43:36 +020055 size_t i, start_len;
Radek Krejcid3ca0632019-04-16 16:54:54 +020056 const char *start;
57 char special = 0;
58
59 if (!len) {
60 return;
61 }
62
63 if (len < 0) {
64 len = strlen(text);
65 }
66
67 start = text;
68 start_len = 0;
Radek Krejci1deb5be2020-08-26 16:43:36 +020069 for (i = 0; i < (size_t)len; ++i) {
Radek Krejcid3ca0632019-04-16 16:54:54 +020070 switch (text[i]) {
71 case '\n':
72 case '\t':
73 case '\"':
74 case '\\':
75 special = text[i];
76 break;
77 default:
78 ++start_len;
79 break;
80 }
81
82 if (special) {
Michal Vasko5233e962020-08-14 14:26:20 +020083 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +020084 switch (special) {
85 case '\n':
Michal Vasko5233e962020-08-14 14:26:20 +020086 ly_write_(out, "\\n", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +020087 break;
88 case '\t':
Michal Vasko5233e962020-08-14 14:26:20 +020089 ly_write_(out, "\\t", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +020090 break;
91 case '\"':
Michal Vasko5233e962020-08-14 14:26:20 +020092 ly_write_(out, "\\\"", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +020093 break;
94 case '\\':
Michal Vasko5233e962020-08-14 14:26:20 +020095 ly_write_(out, "\\\\", 2);
Radek Krejcid3ca0632019-04-16 16:54:54 +020096 break;
97 }
98
99 start += start_len + 1;
100 start_len = 0;
101
102 special = 0;
103 }
104 }
105
Michal Vasko5233e962020-08-14 14:26:20 +0200106 ly_write_(out, start, start_len);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200107}
108
109static void
Radek Krejci857189e2020-09-01 13:26:36 +0200110ypr_open(struct ly_out *out, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200111{
112 if (flag && !*flag) {
113 *flag = 1;
Michal Vasko5233e962020-08-14 14:26:20 +0200114 ly_print_(out, " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200115 }
116}
117
118static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100119ypr_close(struct lys_ypr_ctx *ctx, ly_bool flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200120{
121 if (flag) {
Michal Vasko5233e962020-08-14 14:26:20 +0200122 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200123 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200124 ly_print_(ctx->out, ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200125 }
126}
127
128static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100129ypr_text(struct lys_ypr_ctx *ctx, const char *name, const char *text, ly_bool singleline, ly_bool closed)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200130{
131 const char *s, *t;
132
133 if (singleline) {
Michal Vasko5233e962020-08-14 14:26:20 +0200134 ly_print_(ctx->out, "%*s%s \"", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200135 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200136 ly_print_(ctx->out, "%*s%s\n", INDENT, name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200137 LEVEL++;
138
Michal Vasko5233e962020-08-14 14:26:20 +0200139 ly_print_(ctx->out, "%*s\"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200140 }
141 t = text;
142 while ((s = strchr(t, '\n'))) {
143 ypr_encode(ctx->out, t, s - t);
Michal Vasko5233e962020-08-14 14:26:20 +0200144 ly_print_(ctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200145 t = s + 1;
146 if (*t != '\n') {
Michal Vasko5233e962020-08-14 14:26:20 +0200147 ly_print_(ctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200148 }
149 }
150
151 ypr_encode(ctx->out, t, strlen(t));
152 if (closed) {
Michal Vasko5233e962020-08-14 14:26:20 +0200153 ly_print_(ctx->out, "\";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200154 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200155 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200156 }
157 if (!singleline) {
158 LEVEL--;
159 }
160}
161
162static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100163yprp_stmt(struct lys_ypr_ctx *ctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200164{
165 struct lysp_stmt *childstmt;
166 const char *s, *t;
167
168 if (stmt->arg) {
169 if (stmt->flags) {
Michal Vasko5233e962020-08-14 14:26:20 +0200170 ly_print_(ctx->out, "%*s%s\n", INDENT, stmt->stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200171 LEVEL++;
Michal Vasko5233e962020-08-14 14:26:20 +0200172 ly_print_(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
Radek Krejcid3ca0632019-04-16 16:54:54 +0200173 t = stmt->arg;
174 while ((s = strchr(t, '\n'))) {
175 ypr_encode(ctx->out, t, s - t);
Michal Vasko5233e962020-08-14 14:26:20 +0200176 ly_print_(ctx->out, "\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200177 t = s + 1;
178 if (*t != '\n') {
Michal Vasko5233e962020-08-14 14:26:20 +0200179 ly_print_(ctx->out, "%*s ", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200180 }
181 }
182 LEVEL--;
183 ypr_encode(ctx->out, t, strlen(t));
Michal Vasko5233e962020-08-14 14:26:20 +0200184 ly_print_(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200185 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200186 ly_print_(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200187 }
188 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200189 ly_print_(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200190 }
191
192 if (stmt->child) {
193 LEVEL++;
194 LY_LIST_FOR(stmt->child, childstmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200195 yprp_stmt(ctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200196 }
197 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200198 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200199 }
200}
201
202/**
203 * @param[in] count Number of extensions to print, 0 to print them all.
204 */
205static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100206yprp_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejci857189e2020-09-01 13:26:36 +0200207 struct lysp_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200208{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200209 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200210 struct lysp_stmt *stmt;
Radek Krejci857189e2020-09-01 13:26:36 +0200211 ly_bool child_presence;
Radek Krejcif56e2a42019-09-09 14:15:25 +0200212 const char *argument;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200213
214 if (!count && ext) {
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200215 count = LY_ARRAY_COUNT(ext);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200216 }
217 LY_ARRAY_FOR(ext, u) {
218 if (!count) {
219 break;
220 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200221
Radek Krejcid3ca0632019-04-16 16:54:54 +0200222 count--;
Michal Vasko3e9bc2f2020-11-04 17:13:56 +0100223 if ((ext->flags & LYS_INTERNAL) || (ext->insubstmt != substmt) || (ext->insubstmt_index != substmt_index)) {
Radek Krejcif56e2a42019-09-09 14:15:25 +0200224 continue;
225 }
226
Radek Krejcif56e2a42019-09-09 14:15:25 +0200227 ypr_open(ctx->out, flag);
228 argument = NULL;
229 if (ext[u].compiled) {
230 argument = ext[u].compiled->argument;
231 } else {
232 argument = ext[u].argument;
233 }
234 if (argument) {
Michal Vasko5233e962020-08-14 14:26:20 +0200235 ly_print_(ctx->out, "%*s%s \"", INDENT, ext[u].name);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200236 ypr_encode(ctx->out, argument, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200237 ly_print_(ctx->out, "\"");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200238 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200239 ly_print_(ctx->out, "%*s%s", INDENT, ext[u].name);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200240 }
241
242 child_presence = 0;
243 LEVEL++;
244 LY_LIST_FOR(ext[u].child, stmt) {
245 if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) {
246 continue;
247 }
248 if (!child_presence) {
Michal Vasko5233e962020-08-14 14:26:20 +0200249 ly_print_(ctx->out, " {\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200250 child_presence = 1;
251 }
252 yprp_stmt(ctx, stmt);
253 }
254 LEVEL--;
255 if (child_presence) {
Michal Vasko5233e962020-08-14 14:26:20 +0200256 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcif56e2a42019-09-09 14:15:25 +0200257 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200258 ly_print_(ctx->out, ";\n");
Radek Krejcif56e2a42019-09-09 14:15:25 +0200259 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200260 }
261}
262
Radek Krejcifc596f92021-02-26 22:40:26 +0100263static void yprc_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +0100264 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count);
Radek Krejci693262f2019-04-29 15:23:20 +0200265
266static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100267ypr_substmt(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200268{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200269 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200270 ly_bool extflag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200271
272 if (!text) {
273 /* nothing to print */
274 return;
275 }
276
Radek Krejcieccf6602021-02-05 19:42:54 +0100277 if (stmt_attr_info[substmt].flags & STMT_FLAG_ID) {
278 ly_print_(ctx->out, "%*s%s %s", INDENT, stmt_attr_info[substmt].name, text);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200279 } else {
Radek Krejcieccf6602021-02-05 19:42:54 +0100280 ypr_text(ctx, stmt_attr_info[substmt].name, text,
281 (stmt_attr_info[substmt].flags & STMT_FLAG_YIN) ? 0 : 1, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200282 }
283
284 LEVEL++;
285 LY_ARRAY_FOR(ext, u) {
Michal Vasko69730152020-10-09 16:30:07 +0200286 if ((((struct lysp_ext_instance *)ext)[u].insubstmt != substmt) || (((struct lysp_ext_instance *)ext)[u].insubstmt_index != substmt_index)) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200287 continue;
288 }
Radek Krejciadcf63d2021-02-09 10:21:18 +0100289 if (ctx->schema == LYS_YPR_PARSED) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200290 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200291 } else {
Michal Vasko22df3f02020-08-24 13:29:22 +0200292 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance *)ext)[u], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200293 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200294 }
295 LEVEL--;
296 ypr_close(ctx, extflag);
297}
298
299static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100300ypr_unsigned(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, unsigned long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200301{
302 char *str;
303
Radek Krejci1deb5be2020-08-26 16:43:36 +0200304 if (asprintf(&str, "%lu", attr_value) == -1) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200305 LOGMEM(ctx->module->ctx);
306 return;
307 }
308 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200309 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200310 free(str);
311}
312
313static void
Radek Krejcifc596f92021-02-26 22:40:26 +0100314ypr_signed(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, signed long int attr_value, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200315{
316 char *str;
317
Radek Krejci1deb5be2020-08-26 16:43:36 +0200318 if (asprintf(&str, "%ld", attr_value) == -1) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200319 LOGMEM(ctx->module->ctx);
320 return;
321 }
322 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200323 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200324 free(str);
325}
326
327static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100328yprp_revision(struct lys_ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200329{
330 if (rev->dsc || rev->ref || rev->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +0200331 ly_print_(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200332 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100333 yprp_extension_instances(ctx, LY_STMT_REVISION, 0, rev->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100334 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, rev->dsc, rev->exts);
335 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200336 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200337 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200338 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200339 ly_print_(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200340 }
341}
342
343static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100344ypr_mandatory(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200345{
346 if (flags & LYS_MAND_MASK) {
347 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100348 ypr_substmt(ctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200349 }
350}
351
352static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100353ypr_config(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200354{
355 if (flags & LYS_CONFIG_MASK) {
356 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100357 ypr_substmt(ctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200358 }
359}
360
361static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100362ypr_status(struct lys_ypr_ctx *ctx, uint16_t flags, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200363{
364 const char *status = NULL;
365
366 if (flags & LYS_STATUS_CURR) {
367 ypr_open(ctx->out, flag);
368 status = "current";
369 } else if (flags & LYS_STATUS_DEPRC) {
370 ypr_open(ctx->out, flag);
371 status = "deprecated";
372 } else if (flags & LYS_STATUS_OBSLT) {
373 ypr_open(ctx->out, flag);
374 status = "obsolete";
375 }
Radek Krejci693262f2019-04-29 15:23:20 +0200376
Radek Krejcifc596f92021-02-26 22:40:26 +0100377 ypr_substmt(ctx, LY_STMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200378}
379
380static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100381ypr_description(struct lys_ypr_ctx *ctx, const char *dsc, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200382{
383 if (dsc) {
384 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100385 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200386 }
387}
388
389static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100390ypr_reference(struct lys_ypr_ctx *ctx, const char *ref, void *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200391{
392 if (ref) {
393 ypr_open(ctx->out, flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100394 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200395 }
396}
397
398static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100399yprp_iffeatures(struct lys_ypr_ctx *ctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200400{
Michal Vasko7f45cf22020-10-01 12:49:44 +0200401 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci857189e2020-09-01 13:26:36 +0200402 ly_bool extflag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200403
Michal Vasko7f45cf22020-10-01 12:49:44 +0200404 LY_ARRAY_FOR(iffs, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200405 ypr_open(ctx->out, flag);
406 extflag = 0;
407
Michal Vasko7f45cf22020-10-01 12:49:44 +0200408 ly_print_(ctx->out, "%*sif-feature \"%s\"", INDENT, iffs[u].str);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200409
410 /* extensions */
411 LEVEL++;
Michal Vasko7f45cf22020-10-01 12:49:44 +0200412 LY_ARRAY_FOR(exts, v) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100413 yprp_extension_instances(ctx, LY_STMT_IF_FEATURE, u, &exts[v], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200414 }
415 LEVEL--;
416 ypr_close(ctx, extflag);
417 }
418}
419
420static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100421yprp_extension(struct lys_ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200422{
Radek Krejci857189e2020-09-01 13:26:36 +0200423 ly_bool flag = 0, flag2 = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200424 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200425
Michal Vasko5233e962020-08-14 14:26:20 +0200426 ly_print_(ctx->out, "%*sextension %s", INDENT, ext->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200427 LEVEL++;
428
429 if (ext->exts) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100430 yprp_extension_instances(ctx, LY_STMT_EXTENSION, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200431 }
432
433 if (ext->argument) {
434 ypr_open(ctx->out, &flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200435 ly_print_(ctx->out, "%*sargument %s", INDENT, ext->argument);
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200436 LEVEL++;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200437 if (ext->exts) {
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200438 u = -1;
Radek Krejcifc596f92021-02-26 22:40:26 +0100439 while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) {
440 yprp_extension_instances(ctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200441 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200442 }
443 if ((ext->flags & LYS_YINELEM_MASK) ||
Radek Krejcifc596f92021-02-26 22:40:26 +0100444 (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200445 ypr_open(ctx->out, &flag2);
Radek Krejcifc596f92021-02-26 22:40:26 +0100446 ypr_substmt(ctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200447 }
Radek Krejci38d2e9f2019-09-09 10:31:51 +0200448 LEVEL--;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200449 ypr_close(ctx, flag2);
450 }
451
Radek Krejci693262f2019-04-29 15:23:20 +0200452 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200453 ypr_description(ctx, ext->dsc, ext->exts, &flag);
454 ypr_reference(ctx, ext->ref, ext->exts, &flag);
455
456 LEVEL--;
457 ypr_close(ctx, flag);
458}
459
460static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100461yprp_feature(struct lys_ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200462{
Radek Krejci857189e2020-09-01 13:26:36 +0200463 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200464
Michal Vasko5233e962020-08-14 14:26:20 +0200465 ly_print_(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200466 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100467 yprp_extension_instances(ctx, LY_STMT_FEATURE, 0, feat->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200468 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
469 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200470 ypr_description(ctx, feat->dsc, feat->exts, &flag);
471 ypr_reference(ctx, feat->ref, feat->exts, &flag);
472 LEVEL--;
473 ypr_close(ctx, flag);
474}
475
476static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100477yprp_identity(struct lys_ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200478{
Radek Krejci857189e2020-09-01 13:26:36 +0200479 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200480 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200481
Michal Vasko5233e962020-08-14 14:26:20 +0200482 ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200483 LEVEL++;
484
Radek Krejci39b7fc22021-02-26 23:29:18 +0100485 yprp_extension_instances(ctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200486 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200487
488 LY_ARRAY_FOR(ident->bases, u) {
489 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100490 ypr_substmt(ctx, LY_STMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200491 }
492
Radek Krejci693262f2019-04-29 15:23:20 +0200493 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200494 ypr_description(ctx, ident->dsc, ident->exts, &flag);
495 ypr_reference(ctx, ident->ref, ident->exts, &flag);
496
497 LEVEL--;
498 ypr_close(ctx, flag);
499}
500
501static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100502yprc_identity(struct lys_ypr_ctx *ctx, const struct lysc_ident *ident)
Radek Krejci693262f2019-04-29 15:23:20 +0200503{
Radek Krejci857189e2020-09-01 13:26:36 +0200504 ly_bool flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200505 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200506
Michal Vasko5233e962020-08-14 14:26:20 +0200507 ly_print_(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200508 LEVEL++;
509
Radek Krejci39b7fc22021-02-26 23:29:18 +0100510 yprc_extension_instances(ctx, LY_STMT_IDENTITY, 0, ident->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200511
512 LY_ARRAY_FOR(ident->derived, u) {
513 ypr_open(ctx->out, &flag);
514 if (ctx->module != ident->derived[u]->module) {
Michal Vasko5233e962020-08-14 14:26:20 +0200515 ly_print_(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200516 } else {
Michal Vasko5233e962020-08-14 14:26:20 +0200517 ly_print_(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
Radek Krejci693262f2019-04-29 15:23:20 +0200518 }
519 }
520
521 ypr_status(ctx, ident->flags, ident->exts, &flag);
522 ypr_description(ctx, ident->dsc, ident->exts, &flag);
523 ypr_reference(ctx, ident->ref, ident->exts, &flag);
524
525 LEVEL--;
526 ypr_close(ctx, flag);
527}
528
529static void
Radek Krejci39b7fc22021-02-26 23:29:18 +0100530yprp_restr(struct lys_ypr_ctx *ctx, const struct lysp_restr *restr, enum ly_stmt stmt, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200531{
Radek Krejci857189e2020-09-01 13:26:36 +0200532 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200533
534 if (!restr) {
535 return;
536 }
537
538 ypr_open(ctx->out, flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +0100539 ly_print_(ctx->out, "%*s%s \"", INDENT, ly_stmt2str(stmt));
Radek Krejcif13b87b2020-12-01 22:02:17 +0100540 ypr_encode(ctx->out,
541 (restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK && restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK) ?
542 restr->arg.str : &restr->arg.str[1], -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200543 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200544
545 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100546 yprp_extension_instances(ctx, stmt, 0, restr->exts, &inner_flag, 0);
Radek Krejcif13b87b2020-12-01 22:02:17 +0100547 if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200548 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
549 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100550 ypr_substmt(ctx, LY_STMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200551 }
552 if (restr->emsg) {
553 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100554 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200555 }
556 if (restr->eapptag) {
557 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100558 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200559 }
Radek Krejci693262f2019-04-29 15:23:20 +0200560 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
561 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
562
Radek Krejcid3ca0632019-04-16 16:54:54 +0200563 LEVEL--;
564 ypr_close(ctx, inner_flag);
565}
566
567static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100568yprc_must(struct lys_ypr_ctx *ctx, const struct lysc_must *must, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200569{
Radek Krejci857189e2020-09-01 13:26:36 +0200570 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200571
572 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200573 ly_print_(ctx->out, "%*smust \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200574 ypr_encode(ctx->out, must->cond->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200575 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200576
577 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100578 yprc_extension_instances(ctx, LY_STMT_MUST, 0, must->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200579 if (must->emsg) {
580 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100581 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200582 }
583 if (must->eapptag) {
584 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100585 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, must->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200586 }
587 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
588 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
589
590 LEVEL--;
591 ypr_close(ctx, inner_flag);
592}
593
594static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100595yprc_range(struct lys_ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200596{
Radek Krejci857189e2020-09-01 13:26:36 +0200597 ly_bool inner_flag = 0;
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200598 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +0200599
Radek Krejci334ccc72019-06-12 13:49:29 +0200600 if (!range) {
601 return;
602 }
603
Radek Krejci693262f2019-04-29 15:23:20 +0200604 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200605 ly_print_(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200606 LY_ARRAY_FOR(range->parts, u) {
607 if (u > 0) {
Michal Vasko5233e962020-08-14 14:26:20 +0200608 ly_print_(ctx->out, " | ");
Radek Krejci693262f2019-04-29 15:23:20 +0200609 }
610 if (range->parts[u].max_64 == range->parts[u].min_64) {
611 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Radek Krejci0f969882020-08-21 16:56:47 +0200612 ly_print_(ctx->out, "%" PRIu64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200613 } else { /* signed values */
Radek Krejci0f969882020-08-21 16:56:47 +0200614 ly_print_(ctx->out, "%" PRId64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200615 }
616 } else {
617 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
Radek Krejci0f969882020-08-21 16:56:47 +0200618 ly_print_(ctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
Radek Krejci693262f2019-04-29 15:23:20 +0200619 } else { /* signed values */
Radek Krejci0f969882020-08-21 16:56:47 +0200620 ly_print_(ctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64);
Radek Krejci693262f2019-04-29 15:23:20 +0200621 }
622 }
623 }
Michal Vasko5233e962020-08-14 14:26:20 +0200624 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200625
626 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100627 yprc_extension_instances(ctx, LY_STMT_RANGE, 0, range->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200628 if (range->emsg) {
629 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100630 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200631 }
632 if (range->eapptag) {
633 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100634 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, range->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200635 }
636 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
637 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
638
639 LEVEL--;
640 ypr_close(ctx, inner_flag);
641}
642
643static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100644yprc_pattern(struct lys_ypr_ctx *ctx, const struct lysc_pattern *pattern, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200645{
Radek Krejci857189e2020-09-01 13:26:36 +0200646 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200647
648 ypr_open(ctx->out, flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200649 ly_print_(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200650 ypr_encode(ctx->out, pattern->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200651 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200652
653 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100654 yprc_extension_instances(ctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200655 if (pattern->inverted) {
656 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
657 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100658 ypr_substmt(ctx, LY_STMT_MODIFIER, 0, "invert-match", pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200659 }
660 if (pattern->emsg) {
661 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100662 ypr_substmt(ctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200663 }
664 if (pattern->eapptag) {
665 ypr_open(ctx->out, &inner_flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100666 ypr_substmt(ctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, pattern->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200667 }
668 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
669 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
670
671 LEVEL--;
672 ypr_close(ctx, inner_flag);
673}
674
675static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100676yprp_when(struct lys_ypr_ctx *ctx, struct lysp_when *when, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200677{
Radek Krejci857189e2020-09-01 13:26:36 +0200678 ly_bool inner_flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200679
680 if (!when) {
681 return;
682 }
683 ypr_open(ctx->out, flag);
684
Michal Vasko5233e962020-08-14 14:26:20 +0200685 ly_print_(ctx->out, "%*swhen \"", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200686 ypr_encode(ctx->out, when->cond, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200687 ly_print_(ctx->out, "\"");
Radek Krejcid3ca0632019-04-16 16:54:54 +0200688
689 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100690 yprp_extension_instances(ctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200691 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
692 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
693 LEVEL--;
694 ypr_close(ctx, inner_flag);
695}
696
697static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100698yprc_when(struct lys_ypr_ctx *ctx, struct lysc_when *when, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +0200699{
Radek Krejci857189e2020-09-01 13:26:36 +0200700 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200701
702 if (!when) {
703 return;
704 }
705 ypr_open(ctx->out, flag);
706
Michal Vasko5233e962020-08-14 14:26:20 +0200707 ly_print_(ctx->out, "%*swhen \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200708 ypr_encode(ctx->out, when->cond->expr, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200709 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200710
711 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100712 yprc_extension_instances(ctx, LY_STMT_WHEN, 0, when->exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200713 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
714 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
715 LEVEL--;
716 ypr_close(ctx, inner_flag);
717}
718
719static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100720yprp_enum(struct lys_ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200721{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200722 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200723 ly_bool inner_flag;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200724
725 LY_ARRAY_FOR(items, u) {
726 ypr_open(ctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200727 if (type == LY_TYPE_BITS) {
Michal Vasko5233e962020-08-14 14:26:20 +0200728 ly_print_(ctx->out, "%*sbit %s", INDENT, items[u].name);
Radek Krejci7871ce52019-06-11 16:44:56 +0200729 } else { /* LY_TYPE_ENUM */
Michal Vasko5233e962020-08-14 14:26:20 +0200730 ly_print_(ctx->out, "%*senum \"", INDENT);
Radek Krejci7871ce52019-06-11 16:44:56 +0200731 ypr_encode(ctx->out, items[u].name, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200732 ly_print_(ctx->out, "\"");
Radek Krejci7871ce52019-06-11 16:44:56 +0200733 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200734 inner_flag = 0;
735 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +0100736 yprp_extension_instances(ctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200737 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200738 if (items[u].flags & LYS_SET_VALUE) {
739 if (type == LY_TYPE_BITS) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100740 ypr_unsigned(ctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200741 } else { /* LY_TYPE_ENUM */
Radek Krejcifc596f92021-02-26 22:40:26 +0100742 ypr_signed(ctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200743 }
744 }
Radek Krejci693262f2019-04-29 15:23:20 +0200745 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200746 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
747 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
748 LEVEL--;
749 ypr_close(ctx, inner_flag);
750 }
751}
752
753static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100754yprp_type(struct lys_ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200755{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200756 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200757 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200758
Michal Vasko5233e962020-08-14 14:26:20 +0200759 ly_print_(ctx->out, "%*stype %s", INDENT, type->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200760 LEVEL++;
761
Radek Krejci39b7fc22021-02-26 23:29:18 +0100762 yprp_extension_instances(ctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200763
Radek Krejci39b7fc22021-02-26 23:29:18 +0100764 yprp_restr(ctx, type->range, LY_STMT_RANGE, &flag);
765 yprp_restr(ctx, type->length, LY_STMT_LENGTH, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200766 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100767 yprp_restr(ctx, &type->patterns[u], LY_STMT_PATTERN, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200768 }
Radek Krejci693262f2019-04-29 15:23:20 +0200769 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
770 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200771
772 if (type->path) {
773 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100774 ypr_substmt(ctx, LY_STMT_PATH, 0, type->path->expr, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200775 }
776 if (type->flags & LYS_SET_REQINST) {
777 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100778 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200779 }
780 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100781 ypr_unsigned(ctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200782 }
783 LY_ARRAY_FOR(type->bases, u) {
784 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100785 ypr_substmt(ctx, LY_STMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200786 }
787 LY_ARRAY_FOR(type->types, u) {
788 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200789 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200790 }
791
792 LEVEL--;
793 ypr_close(ctx, flag);
794}
795
796static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100797yprc_dflt_value(struct lys_ypr_ctx *ctx, const struct lyd_value *value, struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200798{
Radek Krejci857189e2020-09-01 13:26:36 +0200799 ly_bool dynamic;
Radek Krejcia1911222019-07-22 17:24:50 +0200800 const char *str;
801
Michal Vaskoba99a3e2020-08-18 15:50:05 +0200802 str = value->realtype->plugin->print(value, LY_PREF_JSON, NULL, &dynamic);
Radek Krejcifc596f92021-02-26 22:40:26 +0100803 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, str, exts);
Radek Krejcia1911222019-07-22 17:24:50 +0200804 if (dynamic) {
Michal Vasko22df3f02020-08-24 13:29:22 +0200805 free((void *)str);
Radek Krejcia1911222019-07-22 17:24:50 +0200806 }
807}
808
809static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100810yprc_type(struct lys_ypr_ctx *ctx, const struct lysc_type *type)
Radek Krejci693262f2019-04-29 15:23:20 +0200811{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200812 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200813 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200814
Michal Vasko5233e962020-08-14 14:26:20 +0200815 ly_print_(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
Radek Krejci693262f2019-04-29 15:23:20 +0200816 LEVEL++;
817
Radek Krejci39b7fc22021-02-26 23:29:18 +0100818 yprc_extension_instances(ctx, LY_STMT_TYPE, 0, type->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200819
Michal Vasko2bb55bc2020-08-05 13:27:04 +0200820 switch (type->basetype) {
Radek Krejci693262f2019-04-29 15:23:20 +0200821 case LY_TYPE_BINARY: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200822 struct lysc_type_bin *bin = (struct lysc_type_bin *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200823 yprc_range(ctx, bin->length, type->basetype, &flag);
824 break;
825 }
826 case LY_TYPE_UINT8:
827 case LY_TYPE_UINT16:
828 case LY_TYPE_UINT32:
829 case LY_TYPE_UINT64:
830 case LY_TYPE_INT8:
831 case LY_TYPE_INT16:
832 case LY_TYPE_INT32:
833 case LY_TYPE_INT64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200834 struct lysc_type_num *num = (struct lysc_type_num *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200835 yprc_range(ctx, num->range, type->basetype, &flag);
836 break;
837 }
838 case LY_TYPE_STRING: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200839 struct lysc_type_str *str = (struct lysc_type_str *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200840 yprc_range(ctx, str->length, type->basetype, &flag);
841 LY_ARRAY_FOR(str->patterns, u) {
842 yprc_pattern(ctx, str->patterns[u], &flag);
843 }
844 break;
845 }
846 case LY_TYPE_BITS:
847 case LY_TYPE_ENUM: {
848 /* bits and enums structures are compatible */
Michal Vasko22df3f02020-08-24 13:29:22 +0200849 struct lysc_type_bits *bits = (struct lysc_type_bits *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200850 LY_ARRAY_FOR(bits->bits, u) {
851 struct lysc_type_bitenum_item *item = &bits->bits[u];
Radek Krejci857189e2020-09-01 13:26:36 +0200852 ly_bool inner_flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +0200853
854 ypr_open(ctx->out, &flag);
Michal Vasko5233e962020-08-14 14:26:20 +0200855 ly_print_(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
Radek Krejci693262f2019-04-29 15:23:20 +0200856 ypr_encode(ctx->out, item->name, -1);
Michal Vasko5233e962020-08-14 14:26:20 +0200857 ly_print_(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200858 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200859 if (type->basetype == LY_TYPE_BITS) {
Radek Krejci39b7fc22021-02-26 23:29:18 +0100860 yprc_extension_instances(ctx, LY_STMT_BIT, 0, item->exts, &inner_flag, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100861 ypr_unsigned(ctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200862 } else { /* LY_TYPE_ENUM */
Radek Krejci39b7fc22021-02-26 23:29:18 +0100863 yprc_extension_instances(ctx, LY_STMT_ENUM, 0, item->exts, &inner_flag, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +0100864 ypr_signed(ctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200865 }
866 ypr_status(ctx, item->flags, item->exts, &inner_flag);
867 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
868 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
869 LEVEL--;
870 ypr_close(ctx, inner_flag);
871 }
872 break;
873 }
874 case LY_TYPE_BOOL:
875 case LY_TYPE_EMPTY:
876 /* nothing to do */
877 break;
878 case LY_TYPE_DEC64: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200879 struct lysc_type_dec *dec = (struct lysc_type_dec *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200880 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100881 ypr_unsigned(ctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200882 yprc_range(ctx, dec->range, dec->basetype, &flag);
883 break;
884 }
885 case LY_TYPE_IDENT: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200886 struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200887 LY_ARRAY_FOR(ident->bases, u) {
888 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100889 ypr_substmt(ctx, LY_STMT_BASE, u, ident->bases[u]->name, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200890 }
891 break;
892 }
893 case LY_TYPE_INST: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200894 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200895 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100896 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200897 break;
898 }
899 case LY_TYPE_LEAFREF: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200900 struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200901 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +0100902 ypr_substmt(ctx, LY_STMT_PATH, 0, lr->path->expr, lr->exts);
903 ypr_substmt(ctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200904 yprc_type(ctx, lr->realtype);
905 break;
906 }
907 case LY_TYPE_UNION: {
Michal Vasko22df3f02020-08-24 13:29:22 +0200908 struct lysc_type_union *un = (struct lysc_type_union *)type;
Radek Krejci693262f2019-04-29 15:23:20 +0200909 LY_ARRAY_FOR(un->types, u) {
910 ypr_open(ctx->out, &flag);
911 yprc_type(ctx, un->types[u]);
912 }
913 break;
914 }
915 default:
916 LOGINT(ctx->module->ctx);
917 }
918
919 LEVEL--;
920 ypr_close(ctx, flag);
921}
922
923static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100924yprp_typedef(struct lys_ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200925{
Michal Vasko5233e962020-08-14 14:26:20 +0200926 ly_print_(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200927 LEVEL++;
928
Radek Krejci39b7fc22021-02-26 23:29:18 +0100929 yprp_extension_instances(ctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200930
Radek Krejci693262f2019-04-29 15:23:20 +0200931 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200932
933 if (tpdf->units) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100934 ypr_substmt(ctx, LY_STMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200935 }
Michal Vasko7f45cf22020-10-01 12:49:44 +0200936 if (tpdf->dflt.str) {
Radek Krejcifc596f92021-02-26 22:40:26 +0100937 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200938 }
939
Radek Krejci693262f2019-04-29 15:23:20 +0200940 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200941 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
942 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
943
944 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +0200945 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200946}
947
Radek Krejciadcf63d2021-02-09 10:21:18 +0100948static void yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node);
949static void yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node);
950static void yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action);
951static void yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200952
953static void
Radek Krejciadcf63d2021-02-09 10:21:18 +0100954yprp_grouping(struct lys_ypr_ctx *ctx, const struct lysp_node_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200955{
Michal Vaskofd69e1d2020-07-03 11:57:17 +0200956 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +0200957 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200958 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +0100959 struct lysp_node_action *action;
960 struct lysp_node_notif *notif;
961 struct lysp_node_grp *subgrp;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200962
Michal Vasko5233e962020-08-14 14:26:20 +0200963 ly_print_(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200964 LEVEL++;
965
Radek Krejci39b7fc22021-02-26 23:29:18 +0100966 yprp_extension_instances(ctx, LY_STMT_GROUPING, 0, grp->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +0200967 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +0200968 ypr_description(ctx, grp->dsc, grp->exts, &flag);
969 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200970
971 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +0200972 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200973 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200974 }
975
Radek Krejci2a9fc652021-01-22 17:44:34 +0100976 LY_LIST_FOR(grp->groupings, subgrp) {
Radek Krejci59edcf72019-05-02 09:53:17 +0200977 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100978 yprp_grouping(ctx, subgrp);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200979 }
980
Radek Krejci01180ac2021-01-27 08:48:22 +0100981 LY_LIST_FOR(grp->child, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +0200982 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200983 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200984 }
985
Radek Krejci2a9fc652021-01-22 17:44:34 +0100986 LY_LIST_FOR(grp->actions, action) {
987 ypr_open(ctx->out, &flag);
988 yprp_action(ctx, action);
989 }
990
991 LY_LIST_FOR(grp->notifs, notif) {
992 ypr_open(ctx->out, &flag);
993 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200994 }
995
996 LEVEL--;
997 ypr_close(ctx, flag);
998}
999
1000static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001001yprp_inout(struct lys_ypr_ctx *ctx, const struct lysp_node_action_inout *inout, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001002{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001003 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001004 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001005 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001006
Radek Krejci01180ac2021-01-27 08:48:22 +01001007 if (!inout->child) {
Michal Vasko7f45cf22020-10-01 12:49:44 +02001008 /* no children */
Radek Krejcid3ca0632019-04-16 16:54:54 +02001009 return;
1010 }
1011 ypr_open(ctx->out, flag);
1012
Michal Vasko544e58a2021-01-28 14:33:41 +01001013 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001014 LEVEL++;
1015
Radek Krejci39b7fc22021-02-26 23:29:18 +01001016 yprp_extension_instances(ctx, LY_STMT_MUST, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001017 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001018 yprp_restr(ctx, &inout->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001019 }
1020 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001021 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001022 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001023 LY_LIST_FOR(inout->groupings, grp) {
1024 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001025 }
1026
Radek Krejci01180ac2021-01-27 08:48:22 +01001027 LY_LIST_FOR(inout->child, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001028 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001029 }
1030
1031 LEVEL--;
1032 ypr_close(ctx, 1);
1033}
1034
1035static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001036yprc_inout(struct lys_ypr_ctx *ctx, const struct lysc_node_action_inout *inout, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001037{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001038 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001039 struct lysc_node *data;
1040
Radek Krejci01180ac2021-01-27 08:48:22 +01001041 if (!inout->child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001042 /* input/output is empty */
1043 return;
1044 }
1045 ypr_open(ctx->out, flag);
1046
Michal Vasko544e58a2021-01-28 14:33:41 +01001047 ly_print_(ctx->out, "\n%*s%s {\n", INDENT, inout->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001048 LEVEL++;
1049
Radek Krejci39b7fc22021-02-26 23:29:18 +01001050 yprc_extension_instances(ctx, lys_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001051 LY_ARRAY_FOR(inout->musts, u) {
1052 yprc_must(ctx, &inout->musts[u], NULL);
1053 }
1054
Radek Krejci52f65552020-09-01 17:03:35 +02001055 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001056 LY_LIST_FOR(inout->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001057 yprc_node(ctx, data);
1058 }
Radek Krejci693262f2019-04-29 15:23:20 +02001059 }
1060
1061 LEVEL--;
1062 ypr_close(ctx, 1);
1063}
1064
1065static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001066yprp_notification(struct lys_ypr_ctx *ctx, const struct lysp_node_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001067{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001068 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001069 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001070 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001071 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001072
Michal Vasko5233e962020-08-14 14:26:20 +02001073 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001074
1075 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001076 yprp_extension_instances(ctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001077 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001078
1079 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001080 yprp_restr(ctx, &notif->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001081 }
Radek Krejci693262f2019-04-29 15:23:20 +02001082 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001083 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1084 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1085
1086 LY_ARRAY_FOR(notif->typedefs, u) {
1087 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001088 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001089 }
1090
Radek Krejci2a9fc652021-01-22 17:44:34 +01001091 LY_LIST_FOR(notif->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001092 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001093 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001094 }
1095
Radek Krejci01180ac2021-01-27 08:48:22 +01001096 LY_LIST_FOR(notif->child, data) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001097 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001098 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001099 }
1100
1101 LEVEL--;
1102 ypr_close(ctx, flag);
1103}
1104
1105static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001106yprc_notification(struct lys_ypr_ctx *ctx, const struct lysc_node_notif *notif)
Radek Krejci693262f2019-04-29 15:23:20 +02001107{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001108 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001109 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001110 struct lysc_node *data;
1111
Michal Vasko5233e962020-08-14 14:26:20 +02001112 ly_print_(ctx->out, "%*snotification %s", INDENT, notif->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001113
1114 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001115 yprc_extension_instances(ctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001116
1117 LY_ARRAY_FOR(notif->musts, u) {
1118 yprc_must(ctx, &notif->musts[u], &flag);
1119 }
1120 ypr_status(ctx, notif->flags, notif->exts, &flag);
1121 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1122 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1123
Radek Krejci52f65552020-09-01 17:03:35 +02001124 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci01180ac2021-01-27 08:48:22 +01001125 LY_LIST_FOR(notif->child, data) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001126 ypr_open(ctx->out, &flag);
1127 yprc_node(ctx, data);
1128 }
Radek Krejci693262f2019-04-29 15:23:20 +02001129 }
1130
1131 LEVEL--;
1132 ypr_close(ctx, flag);
1133}
1134
1135static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001136yprp_action(struct lys_ypr_ctx *ctx, const struct lysp_node_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001137{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001138 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001139 ly_bool flag = 0;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001140 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001141
Michal Vasko5233e962020-08-14 14:26:20 +02001142 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001143
1144 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001145 yprp_extension_instances(ctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001146 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1147 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001148 ypr_description(ctx, action->dsc, action->exts, &flag);
1149 ypr_reference(ctx, action->ref, action->exts, &flag);
1150
1151 LY_ARRAY_FOR(action->typedefs, u) {
1152 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001153 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001154 }
1155
Radek Krejci2a9fc652021-01-22 17:44:34 +01001156 LY_LIST_FOR(action->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001157 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001158 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001159 }
1160
Radek Krejci693262f2019-04-29 15:23:20 +02001161 yprp_inout(ctx, &action->input, &flag);
1162 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001163
1164 LEVEL--;
1165 ypr_close(ctx, flag);
1166}
1167
1168static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001169yprc_action(struct lys_ypr_ctx *ctx, const struct lysc_node_action *action)
Radek Krejci693262f2019-04-29 15:23:20 +02001170{
Radek Krejci857189e2020-09-01 13:26:36 +02001171 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001172
Michal Vasko5233e962020-08-14 14:26:20 +02001173 ly_print_(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001174
1175 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01001176 yprc_extension_instances(ctx, lys_nodetype2stmt(action->nodetype), 0, action->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001177 ypr_status(ctx, action->flags, action->exts, &flag);
1178 ypr_description(ctx, action->dsc, action->exts, &flag);
1179 ypr_reference(ctx, action->ref, action->exts, &flag);
1180
Michal Vasko544e58a2021-01-28 14:33:41 +01001181 yprc_inout(ctx, &action->input, &flag);
1182 yprc_inout(ctx, &action->output, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001183
1184 LEVEL--;
1185 ypr_close(ctx, flag);
1186}
1187
1188static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001189yprp_node_common1(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001190{
Michal Vasko5233e962020-08-14 14:26:20 +02001191 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001192 LEVEL++;
1193
Radek Krejci39b7fc22021-02-26 23:29:18 +01001194 yprp_extension_instances(ctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001195 yprp_when(ctx, lysp_node_when(node), flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001196 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001197}
1198
1199static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001200yprc_node_common1(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001201{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001202 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9a3823e2021-01-27 20:26:46 +01001203 struct lysc_when **when;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001204
Michal Vasko5233e962020-08-14 14:26:20 +02001205 ly_print_(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001206 LEVEL++;
1207
Radek Krejci39b7fc22021-02-26 23:29:18 +01001208 yprc_extension_instances(ctx, lys_nodetype2stmt(node->nodetype), 0, node->exts, flag, 0);
Radek Krejci9a3823e2021-01-27 20:26:46 +01001209
1210 when = lysc_node_when(node);
1211 LY_ARRAY_FOR(when, u) {
1212 yprc_when(ctx, when[u], flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001213 }
Radek Krejci693262f2019-04-29 15:23:20 +02001214}
1215
1216/* macr oto unify the code */
1217#define YPR_NODE_COMMON2 \
1218 ypr_config(ctx, node->flags, node->exts, flag); \
1219 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1220 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1221 } \
1222 ypr_status(ctx, node->flags, node->exts, flag); \
1223 ypr_description(ctx, node->dsc, node->exts, flag); \
1224 ypr_reference(ctx, node->ref, node->exts, flag)
1225
1226static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001227yprp_node_common2(struct lys_ypr_ctx *ctx, const struct lysp_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001228{
1229 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001230}
1231
1232static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001233yprc_node_common2(struct lys_ypr_ctx *ctx, const struct lysc_node *node, ly_bool *flag)
Radek Krejci693262f2019-04-29 15:23:20 +02001234{
1235 YPR_NODE_COMMON2;
1236}
1237
1238#undef YPR_NODE_COMMON2
1239
1240static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001241yprp_container(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001242{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001243 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001244 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001245 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001246 struct lysp_node_action *action;
1247 struct lysp_node_notif *notif;
1248 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001249 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1250
Radek Krejci693262f2019-04-29 15:23:20 +02001251 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001252
1253 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001254 yprp_restr(ctx, &cont->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001255 }
1256 if (cont->presence) {
1257 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001258 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001259 }
1260
Radek Krejci693262f2019-04-29 15:23:20 +02001261 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001262
1263 LY_ARRAY_FOR(cont->typedefs, u) {
1264 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001265 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001266 }
1267
Radek Krejci2a9fc652021-01-22 17:44:34 +01001268 LY_LIST_FOR(cont->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001269 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001270 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001271 }
1272
1273 LY_LIST_FOR(cont->child, child) {
1274 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001275 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001276 }
1277
Radek Krejci2a9fc652021-01-22 17:44:34 +01001278 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001279 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001280 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001281 }
1282
Radek Krejci2a9fc652021-01-22 17:44:34 +01001283 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001284 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001285 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286 }
1287
1288 LEVEL--;
1289 ypr_close(ctx, flag);
1290}
1291
1292static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001293yprc_container(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001294{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001295 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001296 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001297 struct lysc_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001298 struct lysc_node_action *action;
1299 struct lysc_node_notif *notif;
Radek Krejci693262f2019-04-29 15:23:20 +02001300 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1301
1302 yprc_node_common1(ctx, node, &flag);
1303
1304 LY_ARRAY_FOR(cont->musts, u) {
1305 yprc_must(ctx, &cont->musts[u], &flag);
1306 }
1307 if (cont->flags & LYS_PRESENCE) {
1308 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001309 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, "true", cont->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001310 }
1311
1312 yprc_node_common2(ctx, node, &flag);
1313
Radek Krejci52f65552020-09-01 17:03:35 +02001314 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001315 LY_LIST_FOR(cont->child, child) {
1316 ypr_open(ctx->out, &flag);
1317 yprc_node(ctx, child);
1318 }
Radek Krejci693262f2019-04-29 15:23:20 +02001319
Radek Krejci2a9fc652021-01-22 17:44:34 +01001320 LY_LIST_FOR(cont->actions, action) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001321 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001322 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001323 }
Radek Krejci693262f2019-04-29 15:23:20 +02001324
Radek Krejci2a9fc652021-01-22 17:44:34 +01001325 LY_LIST_FOR(cont->notifs, notif) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001326 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001327 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001328 }
Radek Krejci693262f2019-04-29 15:23:20 +02001329 }
1330
1331 LEVEL--;
1332 ypr_close(ctx, flag);
1333}
1334
1335static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001336yprp_case(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001337{
Radek Krejci857189e2020-09-01 13:26:36 +02001338 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001339 struct lysp_node *child;
1340 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1341
1342 yprp_node_common1(ctx, node, &flag);
1343 yprp_node_common2(ctx, node, &flag);
1344
1345 LY_LIST_FOR(cas->child, child) {
1346 ypr_open(ctx->out, &flag);
1347 yprp_node(ctx, child);
1348 }
1349
1350 LEVEL--;
1351 ypr_close(ctx, flag);
1352}
1353
1354static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001355yprc_case(struct lys_ypr_ctx *ctx, const struct lysc_node_case *cs)
Radek Krejci693262f2019-04-29 15:23:20 +02001356{
Radek Krejci857189e2020-09-01 13:26:36 +02001357 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001358 struct lysc_node *child;
1359
Michal Vasko14ed9cd2021-01-28 14:16:25 +01001360 yprc_node_common1(ctx, &cs->node, &flag);
1361 yprc_node_common2(ctx, &cs->node, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001362
Radek Krejci52f65552020-09-01 17:03:35 +02001363 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001364 for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001365 ypr_open(ctx->out, &flag);
1366 yprc_node(ctx, child);
1367 }
Radek Krejci693262f2019-04-29 15:23:20 +02001368 }
1369
1370 LEVEL--;
1371 ypr_close(ctx, flag);
1372}
1373
1374static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001375yprp_choice(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001376{
Radek Krejci857189e2020-09-01 13:26:36 +02001377 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001378 struct lysp_node *child;
1379 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1380
Radek Krejci693262f2019-04-29 15:23:20 +02001381 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001382
Michal Vasko7f45cf22020-10-01 12:49:44 +02001383 if (choice->dflt.str) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001384 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001385 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, choice->dflt.str, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001386 }
1387
Radek Krejci693262f2019-04-29 15:23:20 +02001388 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001389
1390 LY_LIST_FOR(choice->child, child) {
1391 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001392 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001393 }
1394
1395 LEVEL--;
1396 ypr_close(ctx, flag);
1397}
1398
1399static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001400yprc_choice(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001401{
Radek Krejci857189e2020-09-01 13:26:36 +02001402 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001403 struct lysc_node_case *cs;
1404 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1405
1406 yprc_node_common1(ctx, node, &flag);
1407
1408 if (choice->dflt) {
1409 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001410 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, choice->dflt->name, choice->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001411 }
1412
1413 yprc_node_common2(ctx, node, &flag);
1414
Michal Vasko22df3f02020-08-24 13:29:22 +02001415 for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) {
Radek Krejci693262f2019-04-29 15:23:20 +02001416 ypr_open(ctx->out, &flag);
1417 yprc_case(ctx, cs);
1418 }
1419
1420 LEVEL--;
1421 ypr_close(ctx, flag);
1422}
1423
1424static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001425yprp_leaf(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001426{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001427 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001428 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1429
Radek Krejci693262f2019-04-29 15:23:20 +02001430 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001431
Radek Krejci693262f2019-04-29 15:23:20 +02001432 yprp_type(ctx, &leaf->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001433 ypr_substmt(ctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001434 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001435 yprp_restr(ctx, &leaf->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001436 }
Radek Krejcifc596f92021-02-26 22:40:26 +01001437 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001438
Radek Krejci693262f2019-04-29 15:23:20 +02001439 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001440
1441 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001442 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001443}
1444
1445static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001446yprc_leaf(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001447{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001448 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001449 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1450
1451 yprc_node_common1(ctx, node, NULL);
1452
1453 yprc_type(ctx, leaf->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001454 ypr_substmt(ctx, LY_STMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001455 LY_ARRAY_FOR(leaf->musts, u) {
1456 yprc_must(ctx, &leaf->musts[u], NULL);
1457 }
Radek Krejcia1911222019-07-22 17:24:50 +02001458
1459 if (leaf->dflt) {
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001460 yprc_dflt_value(ctx, leaf->dflt, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001461 }
Radek Krejci693262f2019-04-29 15:23:20 +02001462
1463 yprc_node_common2(ctx, node, NULL);
1464
1465 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001466 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001467}
1468
1469static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001470yprp_leaflist(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001471{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001472 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001473 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1474
Radek Krejci693262f2019-04-29 15:23:20 +02001475 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001476
Radek Krejci693262f2019-04-29 15:23:20 +02001477 yprp_type(ctx, &llist->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001478 ypr_substmt(ctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001479 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001480 yprp_restr(ctx, &llist->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001481 }
1482 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001483 ypr_substmt(ctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001484 }
1485
Radek Krejci693262f2019-04-29 15:23:20 +02001486 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001487
1488 if (llist->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001489 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001490 }
1491 if (llist->flags & LYS_SET_MAX) {
1492 if (llist->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001493 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001494 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001495 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001496 }
1497 }
1498
1499 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001500 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001501 }
1502
Radek Krejci693262f2019-04-29 15:23:20 +02001503 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001504 ypr_description(ctx, node->dsc, node->exts, NULL);
1505 ypr_reference(ctx, node->ref, node->exts, NULL);
1506
1507 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001508 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001509}
1510
1511static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001512yprc_leaflist(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001513{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001514 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02001515 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1516
1517 yprc_node_common1(ctx, node, NULL);
1518
1519 yprc_type(ctx, llist->type);
Radek Krejcifc596f92021-02-26 22:40:26 +01001520 ypr_substmt(ctx, LY_STMT_UNITS, 0, llist->units, llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001521 LY_ARRAY_FOR(llist->musts, u) {
1522 yprc_must(ctx, &llist->musts[u], NULL);
1523 }
1524 LY_ARRAY_FOR(llist->dflts, u) {
Michal Vaskoba99a3e2020-08-18 15:50:05 +02001525 yprc_dflt_value(ctx, llist->dflts[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001526 }
1527
1528 ypr_config(ctx, node->flags, node->exts, NULL);
1529
Radek Krejcifc596f92021-02-26 22:40:26 +01001530 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001531 if (llist->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001532 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001533 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001534 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001535 }
1536
Radek Krejcifc596f92021-02-26 22:40:26 +01001537 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001538
1539 ypr_status(ctx, node->flags, node->exts, NULL);
1540 ypr_description(ctx, node->dsc, node->exts, NULL);
1541 ypr_reference(ctx, node->ref, node->exts, NULL);
1542
1543 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02001544 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001545}
1546
1547static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001548yprp_list(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001549{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001550 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001551 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001552 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001553 struct lysp_node_action *action;
1554 struct lysp_node_notif *notif;
1555 struct lysp_node_grp *grp;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001556 struct lysp_node_list *list = (struct lysp_node_list *)node;
1557
Radek Krejci693262f2019-04-29 15:23:20 +02001558 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001559
1560 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001561 yprp_restr(ctx, &list->musts[u], LY_STMT_MUST, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001562 }
1563 if (list->key) {
1564 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001565 ypr_substmt(ctx, LY_STMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001566 }
1567 LY_ARRAY_FOR(list->uniques, u) {
1568 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001569 ypr_substmt(ctx, LY_STMT_UNIQUE, u, list->uniques[u].str, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001570 }
1571
Michal Vaskoacb8e742020-10-20 10:28:02 +02001572 ypr_config(ctx, node->flags, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001573
1574 if (list->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001575 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001576 }
1577 if (list->flags & LYS_SET_MAX) {
1578 if (list->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001579 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001580 } else {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001581 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001582 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001583 }
1584 }
1585
1586 if (list->flags & LYS_ORDBY_MASK) {
Michal Vaskoacb8e742020-10-20 10:28:02 +02001587 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001588 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001589 }
1590
Michal Vaskoacb8e742020-10-20 10:28:02 +02001591 ypr_status(ctx, node->flags, node->exts, &flag);
1592 ypr_description(ctx, node->dsc, node->exts, &flag);
1593 ypr_reference(ctx, node->ref, node->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001594
1595 LY_ARRAY_FOR(list->typedefs, u) {
1596 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001597 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001598 }
1599
Radek Krejci2a9fc652021-01-22 17:44:34 +01001600 LY_LIST_FOR(list->groupings, grp) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001601 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001602 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001603 }
1604
1605 LY_LIST_FOR(list->child, child) {
1606 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001607 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001608 }
1609
Radek Krejci2a9fc652021-01-22 17:44:34 +01001610 LY_LIST_FOR(list->actions, action) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001611 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001612 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001613 }
1614
Radek Krejci2a9fc652021-01-22 17:44:34 +01001615 LY_LIST_FOR(list->notifs, notif) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001616 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001617 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001618 }
1619
1620 LEVEL--;
1621 ypr_close(ctx, flag);
1622}
1623
1624static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001625yprc_list(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001626{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001627 LY_ARRAY_COUNT_TYPE u, v;
Radek Krejci693262f2019-04-29 15:23:20 +02001628 struct lysc_node_list *list = (struct lysc_node_list *)node;
1629
Michal Vaskoacb8e742020-10-20 10:28:02 +02001630 yprc_node_common1(ctx, node, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001631
1632 LY_ARRAY_FOR(list->musts, u) {
1633 yprc_must(ctx, &list->musts[u], NULL);
1634 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001635 if (!(list->flags & LYS_KEYLESS)) {
Michal Vasko5233e962020-08-14 14:26:20 +02001636 ly_print_(ctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001637 for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) {
Michal Vasko5233e962020-08-14 14:26:20 +02001638 ly_print_(ctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001639 }
Michal Vasko5233e962020-08-14 14:26:20 +02001640 ly_print_(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001641 }
1642 LY_ARRAY_FOR(list->uniques, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02001643 ly_print_(ctx->out, "%*sunique \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02001644 LY_ARRAY_FOR(list->uniques[u], v) {
Michal Vasko5233e962020-08-14 14:26:20 +02001645 ly_print_(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001646 }
1647 ypr_close(ctx, 0);
1648 }
1649
1650 ypr_config(ctx, node->flags, node->exts, NULL);
1651
Radek Krejcifc596f92021-02-26 22:40:26 +01001652 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001653 if (list->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001654 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL);
Radek Krejci693262f2019-04-29 15:23:20 +02001655 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001656 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001657 }
1658
Radek Krejcifc596f92021-02-26 22:40:26 +01001659 ypr_substmt(ctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001660
1661 ypr_status(ctx, node->flags, node->exts, NULL);
1662 ypr_description(ctx, node->dsc, node->exts, NULL);
1663 ypr_reference(ctx, node->ref, node->exts, NULL);
1664
Radek Krejci52f65552020-09-01 17:03:35 +02001665 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001666 struct lysc_node *child;
1667 struct lysc_node_action *action;
1668 struct lysc_node_notif *notif;
1669
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001670 LY_LIST_FOR(list->child, child) {
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001671 yprc_node(ctx, child);
1672 }
Radek Krejci693262f2019-04-29 15:23:20 +02001673
Radek Krejci2a9fc652021-01-22 17:44:34 +01001674 LY_LIST_FOR(list->actions, action) {
1675 yprc_action(ctx, action);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001676 }
Radek Krejci693262f2019-04-29 15:23:20 +02001677
Radek Krejci2a9fc652021-01-22 17:44:34 +01001678 LY_LIST_FOR(list->notifs, notif) {
1679 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08001680 }
Radek Krejci693262f2019-04-29 15:23:20 +02001681 }
1682
1683 LEVEL--;
Michal Vaskoacb8e742020-10-20 10:28:02 +02001684 ypr_close(ctx, 1);
Radek Krejci693262f2019-04-29 15:23:20 +02001685}
1686
1687static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001688yprp_refine(struct lys_ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001689{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001690 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001691 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001692
Michal Vasko5233e962020-08-14 14:26:20 +02001693 ly_print_(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001694 LEVEL++;
1695
Radek Krejci39b7fc22021-02-26 23:29:18 +01001696 yprp_extension_instances(ctx, LY_STMT_REFINE, 0, refine->exts, &flag, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001697 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001698
1699 LY_ARRAY_FOR(refine->musts, u) {
1700 ypr_open(ctx->out, &flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001701 yprp_restr(ctx, &refine->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001702 }
1703
1704 if (refine->presence) {
1705 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001706 ypr_substmt(ctx, LY_STMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001707 }
1708
1709 LY_ARRAY_FOR(refine->dflts, u) {
1710 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001711 ypr_substmt(ctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001712 }
1713
Radek Krejci693262f2019-04-29 15:23:20 +02001714 ypr_config(ctx, refine->flags, refine->exts, &flag);
1715 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001716
1717 if (refine->flags & LYS_SET_MIN) {
1718 ypr_open(ctx->out, &flag);
Radek Krejcifc596f92021-02-26 22:40:26 +01001719 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001720 }
1721 if (refine->flags & LYS_SET_MAX) {
1722 ypr_open(ctx->out, &flag);
1723 if (refine->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001724 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001725 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001726 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001727 }
1728 }
1729
1730 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1731 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1732
1733 LEVEL--;
1734 ypr_close(ctx, flag);
1735}
1736
1737static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001738yprp_augment(struct lys_ypr_ctx *ctx, const struct lysp_node_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001739{
Radek Krejcid3ca0632019-04-16 16:54:54 +02001740 struct lysp_node *child;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001741 struct lysp_node_action *action;
1742 struct lysp_node_notif *notif;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001743
Michal Vasko5233e962020-08-14 14:26:20 +02001744 ly_print_(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001745 LEVEL++;
1746
Radek Krejci39b7fc22021-02-26 23:29:18 +01001747 yprp_extension_instances(ctx, LY_STMT_AUGMENT, 0, aug->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02001748 yprp_when(ctx, aug->when, NULL);
1749 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1750 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001751 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1752 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1753
1754 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001755 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001756 }
1757
Radek Krejci2a9fc652021-01-22 17:44:34 +01001758 LY_LIST_FOR(aug->actions, action) {
1759 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001760 }
1761
Radek Krejci2a9fc652021-01-22 17:44:34 +01001762 LY_LIST_FOR(aug->notifs, notif) {
1763 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001764 }
1765
1766 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001767 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001768}
1769
Radek Krejcid3ca0632019-04-16 16:54:54 +02001770static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001771yprp_uses(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001772{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001773 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001774 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001775 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001776 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001777
Radek Krejci693262f2019-04-29 15:23:20 +02001778 yprp_node_common1(ctx, node, &flag);
1779 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001780
1781 LY_ARRAY_FOR(uses->refines, u) {
1782 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001783 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001784 }
1785
Radek Krejci2a9fc652021-01-22 17:44:34 +01001786 LY_LIST_FOR(uses->augments, aug) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001787 ypr_open(ctx->out, &flag);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001788 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001789 }
1790
1791 LEVEL--;
1792 ypr_close(ctx, flag);
1793}
1794
1795static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001796yprp_anydata(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001797{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001798 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001799 ly_bool flag = 0;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001800 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1801
Radek Krejci693262f2019-04-29 15:23:20 +02001802 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001803
1804 LY_ARRAY_FOR(any->musts, u) {
1805 ypr_open(ctx->out, &flag);
Radek Krejci39b7fc22021-02-26 23:29:18 +01001806 yprp_restr(ctx, &any->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001807 }
1808
Radek Krejci693262f2019-04-29 15:23:20 +02001809 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001810
1811 LEVEL--;
1812 ypr_close(ctx, flag);
1813}
1814
1815static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001816yprc_anydata(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001817{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001818 LY_ARRAY_COUNT_TYPE u;
Radek Krejci857189e2020-09-01 13:26:36 +02001819 ly_bool flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001820 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001821
Radek Krejci693262f2019-04-29 15:23:20 +02001822 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001823
Radek Krejci693262f2019-04-29 15:23:20 +02001824 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001825 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001826 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001827 }
1828
Radek Krejci693262f2019-04-29 15:23:20 +02001829 yprc_node_common2(ctx, node, &flag);
1830
Radek Krejcid3ca0632019-04-16 16:54:54 +02001831 LEVEL--;
1832 ypr_close(ctx, flag);
1833}
1834
1835static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001836yprp_node(struct lys_ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001837{
1838 switch (node->nodetype) {
1839 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001840 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001841 break;
1842 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001843 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001844 break;
1845 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001846 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001847 break;
1848 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001849 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001850 break;
1851 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001852 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001853 break;
1854 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001855 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001856 break;
1857 case LYS_ANYXML:
1858 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001859 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001860 break;
1861 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001862 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001863 break;
1864 default:
1865 break;
1866 }
1867}
1868
1869static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001870yprc_node(struct lys_ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejci693262f2019-04-29 15:23:20 +02001871{
1872 switch (node->nodetype) {
1873 case LYS_CONTAINER:
1874 yprc_container(ctx, node);
1875 break;
1876 case LYS_CHOICE:
1877 yprc_choice(ctx, node);
1878 break;
1879 case LYS_LEAF:
1880 yprc_leaf(ctx, node);
1881 break;
1882 case LYS_LEAFLIST:
1883 yprc_leaflist(ctx, node);
1884 break;
1885 case LYS_LIST:
1886 yprc_list(ctx, node);
1887 break;
1888 case LYS_ANYXML:
1889 case LYS_ANYDATA:
1890 yprc_anydata(ctx, node);
1891 break;
1892 default:
1893 break;
1894 }
1895}
1896
1897static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01001898yprp_deviation(struct lys_ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001899{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001900 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001901 struct lysp_deviate_add *add;
1902 struct lysp_deviate_rpl *rpl;
1903 struct lysp_deviate_del *del;
fredgan2b11ddb2019-10-21 11:03:39 +08001904 struct lysp_deviate *elem;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001905
Michal Vasko5233e962020-08-14 14:26:20 +02001906 ly_print_(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001907 LEVEL++;
1908
Radek Krejci39b7fc22021-02-26 23:29:18 +01001909 yprp_extension_instances(ctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001910 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1911 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1912
fredgan2b11ddb2019-10-21 11:03:39 +08001913 LY_LIST_FOR(deviation->deviates, elem) {
Michal Vasko5233e962020-08-14 14:26:20 +02001914 ly_print_(ctx->out, "%*sdeviate ", INDENT);
fredgan2b11ddb2019-10-21 11:03:39 +08001915 if (elem->mod == LYS_DEV_NOT_SUPPORTED) {
1916 if (elem->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02001917 ly_print_(ctx->out, "not-supported {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001918 LEVEL++;
1919
Radek Krejci39b7fc22021-02-26 23:29:18 +01001920 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, elem->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001921 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02001922 ly_print_(ctx->out, "not-supported;\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001923 continue;
1924 }
fredgan2b11ddb2019-10-21 11:03:39 +08001925 } else if (elem->mod == LYS_DEV_ADD) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001926 add = (struct lysp_deviate_add *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001927 ly_print_(ctx->out, "add {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001928 LEVEL++;
1929
Radek Krejci39b7fc22021-02-26 23:29:18 +01001930 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, add->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01001931 ypr_substmt(ctx, LY_STMT_UNITS, 0, add->units, add->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001932 LY_ARRAY_FOR(add->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001933 yprp_restr(ctx, &add->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001934 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001935 LY_ARRAY_FOR(add->uniques, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001936 ypr_substmt(ctx, LY_STMT_UNIQUE, u, add->uniques[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001937 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001938 LY_ARRAY_FOR(add->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001939 ypr_substmt(ctx, LY_STMT_DEFAULT, u, add->dflts[u].str, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001940 }
Radek Krejci693262f2019-04-29 15:23:20 +02001941 ypr_config(ctx, add->flags, add->exts, NULL);
1942 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001943 if (add->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001944 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001945 }
1946 if (add->flags & LYS_SET_MAX) {
1947 if (add->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001948 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001949 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001950 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001951 }
1952 }
fredgan2b11ddb2019-10-21 11:03:39 +08001953 } else if (elem->mod == LYS_DEV_REPLACE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001954 rpl = (struct lysp_deviate_rpl *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001955 ly_print_(ctx->out, "replace {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001956 LEVEL++;
1957
Radek Krejci39b7fc22021-02-26 23:29:18 +01001958 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001959 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02001960 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001961 }
Radek Krejcifc596f92021-02-26 22:40:26 +01001962 ypr_substmt(ctx, LY_STMT_UNITS, 0, rpl->units, rpl->exts);
1963 ypr_substmt(ctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, rpl->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001964 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
1965 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001966 if (rpl->flags & LYS_SET_MIN) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001967 ypr_unsigned(ctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001968 }
1969 if (rpl->flags & LYS_SET_MAX) {
1970 if (rpl->max) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001971 ypr_unsigned(ctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001972 } else {
Radek Krejcifc596f92021-02-26 22:40:26 +01001973 ypr_substmt(ctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001974 }
1975 }
fredgan2b11ddb2019-10-21 11:03:39 +08001976 } else if (elem->mod == LYS_DEV_DELETE) {
Michal Vasko22df3f02020-08-24 13:29:22 +02001977 del = (struct lysp_deviate_del *)elem;
Michal Vasko5233e962020-08-14 14:26:20 +02001978 ly_print_(ctx->out, "delete {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001979 LEVEL++;
1980
Radek Krejci39b7fc22021-02-26 23:29:18 +01001981 yprp_extension_instances(ctx, LY_STMT_DEVIATE, 0, del->exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01001982 ypr_substmt(ctx, LY_STMT_UNITS, 0, del->units, del->exts);
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001983 LY_ARRAY_FOR(del->musts, u) {
Radek Krejci39b7fc22021-02-26 23:29:18 +01001984 yprp_restr(ctx, &del->musts[u], LY_STMT_MUST, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001985 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001986 LY_ARRAY_FOR(del->uniques, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001987 ypr_substmt(ctx, LY_STMT_UNIQUE, u, del->uniques[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001988 }
Radek Krejci7eb54ba2020-05-18 16:30:04 +02001989 LY_ARRAY_FOR(del->dflts, u) {
Radek Krejcifc596f92021-02-26 22:40:26 +01001990 ypr_substmt(ctx, LY_STMT_DEFAULT, u, del->dflts[u].str, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001991 }
1992 }
1993
1994 LEVEL--;
1995 ypr_close(ctx, 1);
1996 }
1997
1998 LEVEL--;
1999 ypr_close(ctx, 1);
2000}
2001
Michal Vasko7c8439f2020-08-05 13:25:19 +02002002static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002003yang_print_parsed_linkage(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002004{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002005 LY_ARRAY_COUNT_TYPE u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002006
Radek Krejcid3ca0632019-04-16 16:54:54 +02002007 LY_ARRAY_FOR(modp->imports, u) {
Michal Vasko3e9bc2f2020-11-04 17:13:56 +01002008 if (modp->imports[u].flags & LYS_INTERNAL) {
2009 continue;
2010 }
2011
Michal Vasko5233e962020-08-14 14:26:20 +02002012 ly_print_(ctx->out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002013 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002014 yprp_extension_instances(ctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL, 0);
Radek Krejcifc596f92021-02-26 22:40:26 +01002015 ypr_substmt(ctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002016 if (modp->imports[u].rev[0]) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002017 ypr_substmt(ctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002018 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002019 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2020 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002021 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002022 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002023 }
2024 LY_ARRAY_FOR(modp->includes, u) {
Radek Krejci771928a2021-01-19 13:42:36 +01002025 if (modp->includes[u].injected) {
2026 /* do not print the includes injected from submodules */
2027 continue;
2028 }
Radek Krejcid3ca0632019-04-16 16:54:54 +02002029 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002030 ly_print_(ctx->out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002031 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002032 yprp_extension_instances(ctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002033 if (modp->includes[u].rev[0]) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002034 ypr_substmt(ctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002035 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002036 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2037 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002038 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002039 ly_print_(ctx->out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002040 } else {
Michal Vasko5233e962020-08-14 14:26:20 +02002041 ly_print_(ctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002042 }
2043 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002044}
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045
Michal Vasko7c8439f2020-08-05 13:25:19 +02002046static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002047yang_print_parsed_body(struct lys_ypr_ctx *ctx, const struct lysp_module *modp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002048{
2049 LY_ARRAY_COUNT_TYPE u;
2050 struct lysp_node *data;
Radek Krejci2a9fc652021-01-22 17:44:34 +01002051 struct lysp_node_action *action;
2052 struct lysp_node_notif *notif;
2053 struct lysp_node_grp *grp;
2054 struct lysp_node_augment *aug;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002055
Radek Krejcid3ca0632019-04-16 16:54:54 +02002056 LY_ARRAY_FOR(modp->extensions, u) {
Michal Vasko5233e962020-08-14 14:26:20 +02002057 ly_print_(ctx->out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002058 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002059 }
2060 if (modp->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002061 ly_print_(ctx->out, "\n");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002062 yprp_extension_instances(ctx, LY_STMT_MODULE, 0, modp->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002063 }
2064
2065 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002066 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002067 }
2068
2069 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002070 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002071 }
2072
2073 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002074 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002075 }
2076
Radek Krejci2a9fc652021-01-22 17:44:34 +01002077 LY_LIST_FOR(modp->groupings, grp) {
2078 yprp_grouping(ctx, grp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002079 }
2080
2081 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002082 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002083 }
2084
Radek Krejci2a9fc652021-01-22 17:44:34 +01002085 LY_LIST_FOR(modp->augments, aug) {
2086 yprp_augment(ctx, aug);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002087 }
2088
Radek Krejci2a9fc652021-01-22 17:44:34 +01002089 LY_LIST_FOR(modp->rpcs, action) {
2090 yprp_action(ctx, action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091 }
2092
Radek Krejci2a9fc652021-01-22 17:44:34 +01002093 LY_LIST_FOR(modp->notifs, notif) {
2094 yprp_notification(ctx, notif);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002095 }
2096
2097 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002098 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002099 }
Michal Vasko7c8439f2020-08-05 13:25:19 +02002100}
2101
2102LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002103yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002104{
2105 LY_ARRAY_COUNT_TYPE u;
Michal Vasko7997d5a2021-02-22 10:55:56 +01002106 const struct lys_module *module = modp->mod;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002107 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = LYS_YPR_PARSED, .options = options}, *ctx = &ctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002108
Michal Vasko5233e962020-08-14 14:26:20 +02002109 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002110 LEVEL++;
2111
2112 /* module-header-stmts */
Michal Vasko5d24f6c2020-10-13 13:49:06 +02002113 if (modp->version) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002114 ypr_substmt(ctx, LY_STMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002115 }
2116
Radek Krejcifc596f92021-02-26 22:40:26 +01002117 ypr_substmt(ctx, LY_STMT_NAMESPACE, 0, module->ns, modp->exts);
2118 ypr_substmt(ctx, LY_STMT_PREFIX, 0, module->prefix, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002119
2120 /* linkage-stmts (import/include) */
2121 yang_print_parsed_linkage(ctx, modp);
2122
2123 /* meta-stmts */
2124 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002125 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002126 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002127 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, module->org, modp->exts);
2128 ypr_substmt(ctx, LY_STMT_CONTACT, 0, module->contact, modp->exts);
2129 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, module->dsc, modp->exts);
2130 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, module->ref, modp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002131
2132 /* revision-stmts */
2133 if (modp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002134 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002135 }
2136 LY_ARRAY_FOR(modp->revs, u) {
2137 yprp_revision(ctx, &modp->revs[u]);
2138 }
2139 /* body-stmts */
2140 yang_print_parsed_body(ctx, modp);
2141
2142 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002143 ly_print_(out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002144 ly_print_flush(out);
2145
2146 return LY_SUCCESS;
2147}
2148
2149static void
Radek Krejciadcf63d2021-02-09 10:21:18 +01002150yprp_belongsto(struct lys_ypr_ctx *ctx, const struct lysp_submodule *submodp)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002151{
Michal Vaskoc3781c32020-10-06 14:04:08 +02002152 ly_print_(ctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002153 LEVEL++;
Radek Krejcifc596f92021-02-26 22:40:26 +01002154 yprp_extension_instances(ctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL, 0);
2155 ypr_substmt(ctx, LY_STMT_PREFIX, 0, submodp->prefix, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002156 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002157 ly_print_(ctx->out, "%*s}\n", INDENT);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002158}
2159
2160LY_ERR
Michal Vasko7997d5a2021-02-22 10:55:56 +01002161yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options)
Michal Vasko7c8439f2020-08-05 13:25:19 +02002162{
2163 LY_ARRAY_COUNT_TYPE u;
Radek Krejci07a55962021-03-02 20:16:43 +01002164 struct lys_ypr_ctx ctx_ = {
2165 .out = out, .level = 0, .module = submodp->mod, .schema = LYS_YPR_PARSED,
2166 .options = options
2167 }, *ctx = &ctx_;
Michal Vasko7c8439f2020-08-05 13:25:19 +02002168
Michal Vasko5233e962020-08-14 14:26:20 +02002169 ly_print_(ctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002170 LEVEL++;
2171
2172 /* submodule-header-stmts */
2173 if (submodp->version) {
Radek Krejcifc596f92021-02-26 22:40:26 +01002174 ypr_substmt(ctx, LY_STMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002175 }
2176
2177 yprp_belongsto(ctx, submodp);
2178
2179 /* linkage-stmts (import/include) */
2180 yang_print_parsed_linkage(ctx, (struct lysp_module *)submodp);
2181
2182 /* meta-stmts */
2183 if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002184 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002185 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002186 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, submodp->org, submodp->exts);
2187 ypr_substmt(ctx, LY_STMT_CONTACT, 0, submodp->contact, submodp->exts);
2188 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, submodp->exts);
2189 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, submodp->ref, submodp->exts);
Michal Vasko7c8439f2020-08-05 13:25:19 +02002190
2191 /* revision-stmts */
2192 if (submodp->revs) {
Michal Vasko5233e962020-08-14 14:26:20 +02002193 ly_print_(out, "\n");
Michal Vasko7c8439f2020-08-05 13:25:19 +02002194 }
2195 LY_ARRAY_FOR(submodp->revs, u) {
2196 yprp_revision(ctx, &submodp->revs[u]);
2197 }
2198 /* body-stmts */
2199 yang_print_parsed_body(ctx, (struct lysp_module *)submodp);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002200
2201 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002202 ly_print_(out, "%*s}\n", INDENT);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002203 ly_print_flush(out);
2204
2205 return LY_SUCCESS;
2206}
2207
2208LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002209yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options)
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002210{
Radek Krejciadcf63d2021-02-09 10:21:18 +01002211 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = node->module, .options = options}, *ctx = &ctx_;
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002212
2213 yprc_node(ctx, node);
2214
2215 ly_print_flush(out);
2216 return LY_SUCCESS;
2217}
2218
2219LY_ERR
Radek Krejci1deb5be2020-08-26 16:43:36 +02002220yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options)
Radek Krejcid3ca0632019-04-16 16:54:54 +02002221{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02002222 LY_ARRAY_COUNT_TYPE u;
Radek Krejci693262f2019-04-29 15:23:20 +02002223 struct lysc_module *modc = module->compiled;
Radek Krejciadcf63d2021-02-09 10:21:18 +01002224 struct lys_ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .options = options}, *ctx = &ctx_;
Radek Krejci693262f2019-04-29 15:23:20 +02002225
Michal Vasko5233e962020-08-14 14:26:20 +02002226 ly_print_(ctx->out, "%*smodule %s {\n", INDENT, module->name);
Radek Krejci693262f2019-04-29 15:23:20 +02002227 LEVEL++;
2228
Radek Krejci693262f2019-04-29 15:23:20 +02002229 /* module-header-stmts */
Radek Krejcifc596f92021-02-26 22:40:26 +01002230 ypr_substmt(ctx, LY_STMT_NAMESPACE, 0, module->ns, modc->exts);
2231 ypr_substmt(ctx, LY_STMT_PREFIX, 0, module->prefix, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002232
Michal Vasko7c8439f2020-08-05 13:25:19 +02002233 /* no linkage-stmts */
Radek Krejci693262f2019-04-29 15:23:20 +02002234
2235 /* meta-stmts */
2236 if (module->org || module->contact || module->dsc || module->ref) {
Michal Vasko5233e962020-08-14 14:26:20 +02002237 ly_print_(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002238 }
Radek Krejcifc596f92021-02-26 22:40:26 +01002239 ypr_substmt(ctx, LY_STMT_ORGANIZATION, 0, module->org, modc->exts);
2240 ypr_substmt(ctx, LY_STMT_CONTACT, 0, module->contact, modc->exts);
2241 ypr_substmt(ctx, LY_STMT_DESCRIPTION, 0, module->dsc, modc->exts);
2242 ypr_substmt(ctx, LY_STMT_REFERENCE, 0, module->ref, modc->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02002243
2244 /* revision-stmts */
2245 if (module->revision) {
Michal Vasko5233e962020-08-14 14:26:20 +02002246 ly_print_(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
Radek Krejci693262f2019-04-29 15:23:20 +02002247 }
2248
2249 /* body-stmts */
2250 if (modc->exts) {
Michal Vasko5233e962020-08-14 14:26:20 +02002251 ly_print_(out, "\n");
Radek Krejci39b7fc22021-02-26 23:29:18 +01002252 yprc_extension_instances(ctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL, 0);
Radek Krejci693262f2019-04-29 15:23:20 +02002253 }
2254
Radek Krejci80d281e2020-09-14 17:42:54 +02002255 LY_ARRAY_FOR(module->identities, u) {
2256 yprc_identity(ctx, &module->identities[u]);
Radek Krejci693262f2019-04-29 15:23:20 +02002257 }
2258
Radek Krejci52f65552020-09-01 17:03:35 +02002259 if (!(ctx->options & LYS_PRINT_NO_SUBSTMT)) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01002260 struct lysc_node *data;
2261 struct lysc_node_action *rpc;
2262 struct lysc_node_notif *notif;
2263
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002264 LY_LIST_FOR(modc->data, data) {
2265 yprc_node(ctx, data);
2266 }
Radek Krejci693262f2019-04-29 15:23:20 +02002267
Radek Krejci2a9fc652021-01-22 17:44:34 +01002268 LY_LIST_FOR(modc->rpcs, rpc) {
2269 yprc_action(ctx, rpc);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002270 }
Radek Krejci693262f2019-04-29 15:23:20 +02002271
Radek Krejci2a9fc652021-01-22 17:44:34 +01002272 LY_LIST_FOR(modc->notifs, notif) {
2273 yprc_notification(ctx, notif);
Radek Krejcid8c0f5e2019-11-17 12:18:34 +08002274 }
Radek Krejci693262f2019-04-29 15:23:20 +02002275 }
2276
2277 LEVEL--;
Michal Vasko5233e962020-08-14 14:26:20 +02002278 ly_print_(out, "%*s}\n", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +02002279 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002280
2281 return LY_SUCCESS;
2282}
Radek Krejciadcf63d2021-02-09 10:21:18 +01002283
2284/**
2285 * @param[in] count Number of extensions to print, 0 to print them all.
2286 */
2287static void
Radek Krejcifc596f92021-02-26 22:40:26 +01002288yprc_extension_instances(struct lys_ypr_ctx *ctx, enum ly_stmt substmt, uint8_t substmt_index,
Radek Krejciadcf63d2021-02-09 10:21:18 +01002289 struct lysc_ext_instance *ext, ly_bool *flag, LY_ARRAY_COUNT_TYPE count)
2290{
2291 LY_ARRAY_COUNT_TYPE u;
2292
2293 if (!count && ext) {
2294 count = LY_ARRAY_COUNT(ext);
2295 }
2296 LY_ARRAY_FOR(ext, u) {
2297 ly_bool inner_flag = 0;
2298
2299 if (!count) {
2300 break;
2301 }
2302
2303 count--;
2304 if ((ext->insubstmt != substmt) || (ext->insubstmt_index != substmt_index)) {
2305 continue;
2306 }
2307
2308 ypr_open(ctx->out, flag);
2309 if (ext[u].argument) {
2310 ly_print_(ctx->out, "%*s%s:%s \"", INDENT, ext[u].def->module->name, ext[u].def->name);
2311 ypr_encode(ctx->out, ext[u].argument, -1);
2312 ly_print_(ctx->out, "\"");
2313 } else {
2314 ly_print_(ctx->out, "%*s%s:%s", INDENT, ext[u].def->module->name, ext[u].def->name);
2315 }
2316
2317 LEVEL++;
Radek Krejci39b7fc22021-02-26 23:29:18 +01002318 yprc_extension_instances(ctx, LY_STMT_EXTENSION_INSTANCE, 0, ext[u].exts, &inner_flag, 0);
Radek Krejciadcf63d2021-02-09 10:21:18 +01002319
2320 if (ext[u].def->plugin->sprinter) {
2321 ext[u].def->plugin->sprinter(ctx, &ext[u], &inner_flag);
2322 }
2323
2324 LEVEL--;
2325 ypr_close(ctx, inner_flag);
2326 }
2327}
2328
2329void
2330lysc_print_extension_instance(struct lys_ypr_ctx *ctx, const struct lysc_ext_instance *ext, ly_bool *flag)
2331{
2332 LY_ARRAY_COUNT_TYPE u, v;
2333
2334 LY_ARRAY_FOR(ext->substmts, u) {
2335 switch (ext->substmts[u].stmt) {
2336 case LY_STMT_CHOICE:
2337 case LY_STMT_CONTAINER: {
2338 const struct lysc_node *node;
2339
2340 LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
2341 ypr_open(ctx->out, flag);
2342 yprc_node(ctx, node);
2343 }
2344 break;
2345 }
2346 case LY_STMT_DESCRIPTION:
2347 case LY_STMT_REFERENCE:
2348 case LY_STMT_UNITS:
2349 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2350 if (*(const char **)ext->substmts[u].storage) {
2351 ypr_open(ctx->out, flag);
2352 ypr_substmt(ctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, ext->exts);
2353 }
2354 } else {
2355 const char **strings = *(const char ***)ext->substmts[u].storage;
2356 LY_ARRAY_FOR(strings, v) {
2357 ypr_open(ctx->out, flag);
2358 ypr_substmt(ctx, ext->substmts[u].stmt, v, strings[v], ext->exts);
2359 }
2360 }
2361 break;
2362 case LY_STMT_IF_FEATURE:
2363 /* nothing to do */
2364 break;
2365 case LY_STMT_STATUS:
2366 ypr_status(ctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
2367 break;
2368 case LY_STMT_TYPE:
2369 if (ext->substmts[u].cardinality < LY_STMT_CARD_SOME) {
2370 if (*(const struct lysc_type **)ext->substmts[u].storage) {
2371 ypr_open(ctx->out, flag);
2372 yprc_type(ctx, *(const struct lysc_type **)ext->substmts[u].storage);
2373 }
2374 } else {
2375 const struct lysc_type **types = *(const struct lysc_type ***)ext->substmts[u].storage;
2376 LY_ARRAY_FOR(types, v) {
2377 ypr_open(ctx->out, flag);
2378 yprc_type(ctx, types[v]);
2379 }
2380 }
2381 break;
2382 /* TODO support other substatements */
2383 default:
2384 LOGWRN(ctx->module->ctx, "Statement \"%s\" is not supported for an extension printer.",
2385 ly_stmt2str(ext->substmts[u].stmt));
2386 break;
2387 }
2388 }
2389}