blob: 445afc2079e121300e192bbe52a3fc6c911a8337 [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
15#include "common.h"
16
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 Krejci693262f2019-04-29 15:23:20 +020022
Radek Krejcie7b95092019-05-15 11:03:07 +020023#include "extensions.h"
24#include "log.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020025#include "printer_internal.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "tree.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020027#include "tree_schema.h"
28#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020029#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020030
Radek Krejcie7b95092019-05-15 11:03:07 +020031/**
32 * @brief Types of the YANG printers
33 */
Radek Krejci693262f2019-04-29 15:23:20 +020034enum schema_type {
Radek Krejcie7b95092019-05-15 11:03:07 +020035 YPR_PARSED, /**< YANG printer of the parsed schema */
36 YPR_COMPILED /**< YANG printer of the compiled schema */
Radek Krejci693262f2019-04-29 15:23:20 +020037};
38
Radek Krejcie7b95092019-05-15 11:03:07 +020039/**
40 * @brief YANG printer context.
41 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020042struct ypr_ctx {
Radek Krejcie7b95092019-05-15 11:03:07 +020043 struct lyout *out; /**< output specification */
44 unsigned int level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
45 const struct lys_module *module; /**< schema to print */
46 enum schema_type schema; /**< type of the schema to print */
Radek Krejcid3ca0632019-04-16 16:54:54 +020047};
48
Radek Krejcie7b95092019-05-15 11:03:07 +020049#define LEVEL ctx->level /**< current level */
50#define INDENT (LEVEL)*2,"" /**< indentation parameters for printer functions */
51
52/**
53 * @brief Print the given text as content of a double quoted YANG string,
54 * including encoding characters that have special meanings. The quotation marks
55 * are not printed.
56 *
57 * Follows RFC 7950, section 6.1.3.
58 *
59 * @param[in] out Output specification.
60 * @param[in] text String to be printed.
61 * @param[in] len Length of the string from @p text to be printed. In case of 0,
62 * the @p text is printed completely as a NULL-terminated string.
63 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020064static void
65ypr_encode(struct lyout *out, const char *text, int len)
66{
67 int i, start_len;
68 const char *start;
69 char special = 0;
70
71 if (!len) {
72 return;
73 }
74
75 if (len < 0) {
76 len = strlen(text);
77 }
78
79 start = text;
80 start_len = 0;
81 for (i = 0; i < len; ++i) {
82 switch (text[i]) {
83 case '\n':
84 case '\t':
85 case '\"':
86 case '\\':
87 special = text[i];
88 break;
89 default:
90 ++start_len;
91 break;
92 }
93
94 if (special) {
95 ly_write(out, start, start_len);
96 switch (special) {
97 case '\n':
98 ly_write(out, "\\n", 2);
99 break;
100 case '\t':
101 ly_write(out, "\\t", 2);
102 break;
103 case '\"':
104 ly_write(out, "\\\"", 2);
105 break;
106 case '\\':
107 ly_write(out, "\\\\", 2);
108 break;
109 }
110
111 start += start_len + 1;
112 start_len = 0;
113
114 special = 0;
115 }
116 }
117
118 ly_write(out, start, start_len);
119}
120
121static void
122ypr_open(struct lyout *out, int *flag)
123{
124 if (flag && !*flag) {
125 *flag = 1;
126 ly_print(out, " {\n");
127 }
128}
129
130static void
131ypr_close(struct ypr_ctx *ctx, int flag)
132{
133 if (flag) {
134 ly_print(ctx->out, "%*s}\n", INDENT);
135 } else {
136 ly_print(ctx->out, ";\n");
137 }
138}
139
140static void
141ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, int singleline, int closed)
142{
143 const char *s, *t;
144
145 if (singleline) {
146 ly_print(ctx->out, "%*s%s \"", INDENT, name);
147 } else {
148 ly_print(ctx->out, "%*s%s\n", INDENT, name);
149 LEVEL++;
150
151 ly_print(ctx->out, "%*s\"", INDENT);
152 }
153 t = text;
154 while ((s = strchr(t, '\n'))) {
155 ypr_encode(ctx->out, t, s - t);
156 ly_print(ctx->out, "\n");
157 t = s + 1;
158 if (*t != '\n') {
159 ly_print(ctx->out, "%*s ", INDENT);
160 }
161 }
162
163 ypr_encode(ctx->out, t, strlen(t));
164 if (closed) {
165 ly_print(ctx->out, "\";\n");
166 } else {
167 ly_print(ctx->out, "\"");
168 }
169 if (!singleline) {
170 LEVEL--;
171 }
172}
173
174static void
Radek Krejci693262f2019-04-29 15:23:20 +0200175yprp_stmt(struct ypr_ctx *ctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200176{
177 struct lysp_stmt *childstmt;
178 const char *s, *t;
179
180 if (stmt->arg) {
181 if (stmt->flags) {
182 ly_print(ctx->out, "%*s%s\n", INDENT, stmt->stmt);
183 LEVEL++;
184 ly_print(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
185 t = stmt->arg;
186 while ((s = strchr(t, '\n'))) {
187 ypr_encode(ctx->out, t, s - t);
188 ly_print(ctx->out, "\n");
189 t = s + 1;
190 if (*t != '\n') {
191 ly_print(ctx->out, "%*s ", INDENT);
192 }
193 }
194 LEVEL--;
195 ypr_encode(ctx->out, t, strlen(t));
196 ly_print(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
197 } else {
198 ly_print(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
199 }
200 } else {
201 ly_print(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
202 }
203
204 if (stmt->child) {
205 LEVEL++;
206 LY_LIST_FOR(stmt->child, childstmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200207 yprp_stmt(ctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200208 }
209 LEVEL--;
210 ly_print(ctx->out, "%*s}\n", INDENT);
211 }
212}
213
214/**
215 * @param[in] count Number of extensions to print, 0 to print them all.
216 */
217static void
Radek Krejci693262f2019-04-29 15:23:20 +0200218yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
Radek Krejcid3ca0632019-04-16 16:54:54 +0200219 struct lysp_ext_instance *ext, int *flag, unsigned int count)
220{
221 unsigned int u;
222 struct lysp_stmt *stmt;
223
224 if (!count && ext) {
225 count = LY_ARRAY_SIZE(ext);
226 }
227 LY_ARRAY_FOR(ext, u) {
228 if (!count) {
229 break;
230 }
231 if (ext->insubstmt == substmt && ext->insubstmt_index == substmt_index) {
232 ypr_open(ctx->out, flag);
233 if (ext[u].argument) {
234 ly_print(ctx->out, "%*s%s %s%s", INDENT, ext[u].name, ext[u].argument, ext[u].child ? " {\n" : ";\n");
235 } else {
236 ly_print(ctx->out, "%*s%s%s", INDENT, ext[u].name, ext[u].child ? " {\n" : ";\n");
237 }
238
239 if (ext[u].child) {
240 LEVEL++;
241 LY_LIST_FOR(ext[u].child, stmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200242 yprp_stmt(ctx, stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200243 }
244 LEVEL--;
245 ly_print(ctx->out, "%*s}\n", INDENT);
246 }
247 }
248 count--;
249 }
250}
251
Radek Krejci693262f2019-04-29 15:23:20 +0200252/**
253 * @param[in] count Number of extensions to print, 0 to print them all.
254 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200255static void
Radek Krejci693262f2019-04-29 15:23:20 +0200256yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
257 struct lysc_ext_instance *ext, int *flag, unsigned int count)
258{
259 unsigned int u;
260
261 if (!count && ext) {
262 count = LY_ARRAY_SIZE(ext);
263 }
264 LY_ARRAY_FOR(ext, u) {
265 if (!count) {
266 break;
267 }
268 /* TODO compiled extensions */
269 (void) ctx;
270 (void) substmt;
271 (void) substmt_index;
272 (void) flag;
273
274 count--;
275 }
276}
277
278static void
279ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200280{
281 unsigned int u;
282 int extflag = 0;
283
284 if (!text) {
285 /* nothing to print */
286 return;
287 }
288
289 if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) {
290 ly_print(ctx->out, "%*s%s %s", INDENT, ext_substmt_info[substmt].name, text);
291 } else {
292 ypr_text(ctx, ext_substmt_info[substmt].name, text,
293 (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, 0);
294 }
295
296 LEVEL++;
297 LY_ARRAY_FOR(ext, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200298 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 +0200299 continue;
300 }
Radek Krejci693262f2019-04-29 15:23:20 +0200301 if (ctx->schema == YPR_PARSED) {
302 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance*)ext)[u], &extflag, 1);
303 } else {
304 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance*)ext)[u], &extflag, 1);
305 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200306 }
307 LEVEL--;
308 ypr_close(ctx, extflag);
309}
310
311static void
Radek Krejci693262f2019-04-29 15:23:20 +0200312ypr_unsigned(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, unsigned int attr_value, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200313{
314 char *str;
315
316 if (asprintf(&str, "%u", attr_value) == -1) {
317 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200318 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200319 return;
320 }
321 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200322 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200323 free(str);
324}
325
326static void
Radek Krejci693262f2019-04-29 15:23:20 +0200327ypr_signed(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, void *exts, signed int attr_value, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200328{
329 char *str;
330
331 if (asprintf(&str, "%d", attr_value) == -1) {
332 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200333 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200334 return;
335 }
336 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200337 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200338 free(str);
339}
340
341static void
Radek Krejci693262f2019-04-29 15:23:20 +0200342yprp_revision(struct ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200343{
344 if (rev->dsc || rev->ref || rev->exts) {
345 ly_print(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
346 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200347 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0);
348 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts);
349 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200350 LEVEL--;
351 ly_print(ctx->out, "%*s}\n", INDENT);
352 } else {
353 ly_print(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
354 }
355}
356
357static void
Radek Krejci693262f2019-04-29 15:23:20 +0200358ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200359{
360 if (flags & LYS_MAND_MASK) {
361 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200362 ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200363 }
364}
365
366static void
Radek Krejci693262f2019-04-29 15:23:20 +0200367ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200368{
369 if (flags & LYS_CONFIG_MASK) {
370 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200371 ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200372 }
373}
374
375static void
Radek Krejci693262f2019-04-29 15:23:20 +0200376ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200377{
378 const char *status = NULL;
379
380 if (flags & LYS_STATUS_CURR) {
381 ypr_open(ctx->out, flag);
382 status = "current";
383 } else if (flags & LYS_STATUS_DEPRC) {
384 ypr_open(ctx->out, flag);
385 status = "deprecated";
386 } else if (flags & LYS_STATUS_OBSLT) {
387 ypr_open(ctx->out, flag);
388 status = "obsolete";
389 }
Radek Krejci693262f2019-04-29 15:23:20 +0200390
391 ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200392}
393
394static void
Radek Krejci693262f2019-04-29 15:23:20 +0200395ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200396{
397 if (dsc) {
398 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200399 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200400 }
401}
402
403static void
Radek Krejci693262f2019-04-29 15:23:20 +0200404ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200405{
406 if (ref) {
407 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200408 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200409 }
410}
411
412static void
Radek Krejci693262f2019-04-29 15:23:20 +0200413yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200414{
415 unsigned int u;
416 int extflag;
417
418 LY_ARRAY_FOR(iff, u) {
419 ypr_open(ctx->out, flag);
420 extflag = 0;
421
422 ly_print(ctx->out, "%*sif-feature \"%s\"", INDENT, iff[u]);
423
424 /* extensions */
425 LEVEL++;
426 LY_ARRAY_FOR(exts, u) {
427 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
428 continue;
429 }
Radek Krejci693262f2019-04-29 15:23:20 +0200430 yprp_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200431 }
432 LEVEL--;
433 ypr_close(ctx, extflag);
434 }
435}
436
437static void
Radek Krejci693262f2019-04-29 15:23:20 +0200438yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f)
439{
440 int brackets_flag = *index_e;
441 uint8_t op;
442
443 op = lysc_iff_getop(feat->expr, *index_e);
444 (*index_e)++;
445
446 switch (op) {
447 case LYS_IFF_F:
448 if (ctx->module == feat->features[*index_f]->module) {
449 ly_print(ctx->out, "%s", feat->features[*index_f]->name);
450 } else {
451 ly_print(ctx->out, "%s:%s", feat->features[*index_f]->module->prefix, feat->features[*index_f]->name);
452 }
453 (*index_f)++;
454 break;
455 case LYS_IFF_NOT:
456 ly_print(ctx->out, "not ");
457 yprc_iffeature(ctx, feat, index_e, index_f);
458 break;
459 case LYS_IFF_AND:
460 if (brackets_flag) {
461 /* AND need brackets only if previous op was not */
462 if (*index_e < 2 || lysc_iff_getop(feat->expr, *index_e - 2) != LYS_IFF_NOT) {
463 brackets_flag = 0;
464 }
465 }
466 /* falls through */
467 case LYS_IFF_OR:
468 if (brackets_flag) {
469 ly_print(ctx->out, "(");
470 }
471 yprc_iffeature(ctx, feat, index_e, index_f);
472 ly_print(ctx->out, " %s ", op == LYS_IFF_OR ? "or" : "and");
473 yprc_iffeature(ctx, feat, index_e, index_f);
474 if (brackets_flag) {
475 ly_print(ctx->out, ")");
476 }
477 }
478}
479
480static void
481yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
482{
Radek Krejci334ccc72019-06-12 13:49:29 +0200483 unsigned int u, v;
Radek Krejci693262f2019-04-29 15:23:20 +0200484 int extflag;
485
486 LY_ARRAY_FOR(iff, u) {
487 int index_e = 0, index_f = 0;
488
489 ypr_open(ctx->out, flag);
490 extflag = 0;
491
Radek Krejci989e53b2019-04-30 09:51:09 +0200492 ly_print(ctx->out, "%*sif-feature \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200493 yprc_iffeature(ctx, iff, &index_e, &index_f);
Radek Krejci989e53b2019-04-30 09:51:09 +0200494 ly_print(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200495
496 /* extensions */
497 LEVEL++;
Radek Krejci334ccc72019-06-12 13:49:29 +0200498 LY_ARRAY_FOR(exts, v) {
499 if (exts[v].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[v].insubstmt_index != u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200500 continue;
501 }
Radek Krejci334ccc72019-06-12 13:49:29 +0200502 yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[v], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200503 }
504 LEVEL--;
505 ypr_close(ctx, extflag);
506 }
507}
508
509static void
510yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200511{
512 int flag = 0, flag2 = 0;
513 unsigned int i;
514
515 ly_print(ctx->out, "%*sextension %s", INDENT, ext->name);
516 LEVEL++;
517
518 if (ext->exts) {
Radek Krejci693262f2019-04-29 15:23:20 +0200519 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200520 }
521
522 if (ext->argument) {
523 ypr_open(ctx->out, &flag);
524 ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument);
525 if (ext->exts) {
526 LEVEL++;
527 i = -1;
528 while ((i = lysp_ext_instance_iter(ext->exts, i + 1, LYEXT_SUBSTMT_ARGUMENT)) != LY_ARRAY_SIZE(ext->exts)) {
Radek Krejci693262f2019-04-29 15:23:20 +0200529 yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200530 }
531 LEVEL--;
532 }
533 if ((ext->flags & LYS_YINELEM_MASK) ||
534 (ext->exts && lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YINELEM) != LY_ARRAY_SIZE(ext->exts))) {
535 ypr_open(ctx->out, &flag2);
Radek Krejci693262f2019-04-29 15:23:20 +0200536 ypr_substmt(ctx, LYEXT_SUBSTMT_YINELEM, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200537 }
538 ypr_close(ctx, flag2);
539 }
540
Radek Krejci693262f2019-04-29 15:23:20 +0200541 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200542 ypr_description(ctx, ext->dsc, ext->exts, &flag);
543 ypr_reference(ctx, ext->ref, ext->exts, &flag);
544
545 LEVEL--;
546 ypr_close(ctx, flag);
547}
548
549static void
Radek Krejci693262f2019-04-29 15:23:20 +0200550yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200551{
552 int flag = 0;
553
554 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
555 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200556 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
557 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
558 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200559 ypr_description(ctx, feat->dsc, feat->exts, &flag);
560 ypr_reference(ctx, feat->ref, feat->exts, &flag);
561 LEVEL--;
562 ypr_close(ctx, flag);
563}
564
565static void
Radek Krejci693262f2019-04-29 15:23:20 +0200566yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat)
567{
568 int flag = 0;
569
570 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
571 LEVEL++;
572 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
573 yprc_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
574 ypr_status(ctx, feat->flags, feat->exts, &flag);
575 ypr_description(ctx, feat->dsc, feat->exts, &flag);
576 ypr_reference(ctx, feat->ref, feat->exts, &flag);
577 LEVEL--;
578 ypr_close(ctx, flag);
579}
580
581static void
582yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200583{
584 int flag = 0;
585 unsigned int u;
586
587 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
588 LEVEL++;
589
Radek Krejci693262f2019-04-29 15:23:20 +0200590 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
591 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200592
593 LY_ARRAY_FOR(ident->bases, u) {
594 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200595 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200596 }
597
Radek Krejci693262f2019-04-29 15:23:20 +0200598 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200599 ypr_description(ctx, ident->dsc, ident->exts, &flag);
600 ypr_reference(ctx, ident->ref, ident->exts, &flag);
601
602 LEVEL--;
603 ypr_close(ctx, flag);
604}
605
606static void
Radek Krejci693262f2019-04-29 15:23:20 +0200607yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident)
608{
609 int flag = 0;
610 unsigned int u;
611
612 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
613 LEVEL++;
614
615 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
616 yprc_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
617
618 LY_ARRAY_FOR(ident->derived, u) {
619 ypr_open(ctx->out, &flag);
620 if (ctx->module != ident->derived[u]->module) {
621 ly_print(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
622 } else {
623 ly_print(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
624 }
625 }
626
627 ypr_status(ctx, ident->flags, ident->exts, &flag);
628 ypr_description(ctx, ident->dsc, ident->exts, &flag);
629 ypr_reference(ctx, ident->ref, ident->exts, &flag);
630
631 LEVEL--;
632 ypr_close(ctx, flag);
633}
634
635static void
636yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200637{
638 int inner_flag = 0;
639
640 if (!restr) {
641 return;
642 }
643
644 ypr_open(ctx->out, flag);
645 ly_print(ctx->out, "%*s%s \"", INDENT, name);
646 ypr_encode(ctx->out, (restr->arg[0] != 0x15 && restr->arg[0] != 0x06) ? restr->arg : &restr->arg[1], -1);
647 ly_print(ctx->out, "\"");
648
649 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200650 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200651 if (restr->arg[0] == 0x15) {
652 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
653 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200654 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200655 }
656 if (restr->emsg) {
657 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200658 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200659 }
660 if (restr->eapptag) {
661 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200662 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200663 }
Radek Krejci693262f2019-04-29 15:23:20 +0200664 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
665 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
666
Radek Krejcid3ca0632019-04-16 16:54:54 +0200667 LEVEL--;
668 ypr_close(ctx, inner_flag);
669}
670
671static void
Radek Krejci693262f2019-04-29 15:23:20 +0200672yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag)
673{
674 int inner_flag = 0;
675
676 ypr_open(ctx->out, flag);
677 ly_print(ctx->out, "%*smust \"", INDENT);
678 ypr_encode(ctx->out, must->cond->expr, -1);
679 ly_print(ctx->out, "\"");
680
681 LEVEL++;
682 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0);
683 if (must->emsg) {
684 ypr_open(ctx->out, &inner_flag);
685 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, must->emsg, must->exts);
686 }
687 if (must->eapptag) {
688 ypr_open(ctx->out, &inner_flag);
689 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, must->eapptag, must->exts);
690 }
691 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
692 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
693
694 LEVEL--;
695 ypr_close(ctx, inner_flag);
696}
697
698static void
699yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag)
700{
701 int inner_flag = 0;
702 unsigned int u;
703
Radek Krejci334ccc72019-06-12 13:49:29 +0200704 if (!range) {
705 return;
706 }
707
Radek Krejci693262f2019-04-29 15:23:20 +0200708 ypr_open(ctx->out, flag);
Radek Krejci334ccc72019-06-12 13:49:29 +0200709 ly_print(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200710 LY_ARRAY_FOR(range->parts, u) {
711 if (u > 0) {
712 ly_print(ctx->out, " | ");
713 }
714 if (range->parts[u].max_64 == range->parts[u].min_64) {
715 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
716 ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64);
717 } else { /* signed values */
718 ly_print(ctx->out, "%"PRId64, range->parts[u].max_64);
719 }
720 } else {
721 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
722 ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
723 } else { /* signed values */
724 ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64);
725 }
726 }
727 }
728 ly_print(ctx->out, "\"");
729
730 LEVEL++;
731 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0);
732 if (range->emsg) {
733 ypr_open(ctx->out, &inner_flag);
734 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts);
735 }
736 if (range->eapptag) {
737 ypr_open(ctx->out, &inner_flag);
738 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts);
739 }
740 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
741 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
742
743 LEVEL--;
744 ypr_close(ctx, inner_flag);
745}
746
747static void
748yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag)
749{
750 int inner_flag = 0;
751
752 ypr_open(ctx->out, flag);
753 ly_print(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200754 ypr_encode(ctx->out, pattern->expr, -1);
Radek Krejci693262f2019-04-29 15:23:20 +0200755 ly_print(ctx->out, "\"");
756
757 LEVEL++;
758 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0);
759 if (pattern->inverted) {
760 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
761 ypr_open(ctx->out, &inner_flag);
762 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts);
763 }
764 if (pattern->emsg) {
765 ypr_open(ctx->out, &inner_flag);
766 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts);
767 }
768 if (pattern->eapptag) {
769 ypr_open(ctx->out, &inner_flag);
770 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts);
771 }
772 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
773 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
774
775 LEVEL--;
776 ypr_close(ctx, inner_flag);
777}
778
779static void
780yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200781{
782 int inner_flag = 0;
783
784 if (!when) {
785 return;
786 }
787 ypr_open(ctx->out, flag);
788
789 ly_print(ctx->out, "%*swhen \"", INDENT);
790 ypr_encode(ctx->out, when->cond, -1);
791 ly_print(ctx->out, "\"");
792
793 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200794 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200795 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
796 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
797 LEVEL--;
798 ypr_close(ctx, inner_flag);
799}
800
801static void
Radek Krejci693262f2019-04-29 15:23:20 +0200802yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag)
803{
804 int inner_flag = 0;
805
806 if (!when) {
807 return;
808 }
809 ypr_open(ctx->out, flag);
810
811 ly_print(ctx->out, "%*swhen \"", INDENT);
812 ypr_encode(ctx->out, when->cond->expr, -1);
813 ly_print(ctx->out, "\"");
814
815 LEVEL++;
816 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
817 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
818 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
819 LEVEL--;
820 ypr_close(ctx, inner_flag);
821}
822
823static void
824yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200825{
826 unsigned int u;
827 int inner_flag;
828
829 LY_ARRAY_FOR(items, u) {
830 ypr_open(ctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200831 if (type == LY_TYPE_BITS) {
832 ly_print(ctx->out, "%*sbit %s", INDENT, items[u].name);
833 } else { /* LY_TYPE_ENUM */
834 ly_print(ctx->out, "%*senum \"", INDENT);
835 ypr_encode(ctx->out, items[u].name, -1);
836 ly_print(ctx->out, "\"");
837 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200838 inner_flag = 0;
839 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200840 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
841 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200842 if (items[u].flags & LYS_SET_VALUE) {
843 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200844 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200845 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200846 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200847 }
848 }
Radek Krejci693262f2019-04-29 15:23:20 +0200849 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200850 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
851 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
852 LEVEL--;
853 ypr_close(ctx, inner_flag);
854 }
855}
856
857static void
Radek Krejci693262f2019-04-29 15:23:20 +0200858yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200859{
860 unsigned int u;
861 int flag = 0;
862
863 ly_print(ctx->out, "%*stype %s", INDENT, type->name);
864 LEVEL++;
865
Radek Krejci693262f2019-04-29 15:23:20 +0200866 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200867
Radek Krejci693262f2019-04-29 15:23:20 +0200868 yprp_restr(ctx, type->range, "range", &flag);
869 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200870 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200871 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200872 }
Radek Krejci693262f2019-04-29 15:23:20 +0200873 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
874 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200875
876 if (type->path) {
877 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200878 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200879 }
880 if (type->flags & LYS_SET_REQINST) {
881 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200882 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200883 }
884 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200885 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200886 }
887 LY_ARRAY_FOR(type->bases, u) {
888 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200889 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200890 }
891 LY_ARRAY_FOR(type->types, u) {
892 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200893 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200894 }
895
896 LEVEL--;
897 ypr_close(ctx, flag);
898}
899
900static void
Radek Krejci693262f2019-04-29 15:23:20 +0200901yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
902{
903 unsigned int u;
904 int flag = 0;
905
906 ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
907 LEVEL++;
908
909 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
910 if (type->dflt) {
911 ypr_open(ctx->out, &flag);
912 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, type->dflt, type->exts);
913 }
914
915 switch(type->basetype) {
916 case LY_TYPE_BINARY: {
917 struct lysc_type_bin *bin = (struct lysc_type_bin*)type;
918 yprc_range(ctx, bin->length, type->basetype, &flag);
919 break;
920 }
921 case LY_TYPE_UINT8:
922 case LY_TYPE_UINT16:
923 case LY_TYPE_UINT32:
924 case LY_TYPE_UINT64:
925 case LY_TYPE_INT8:
926 case LY_TYPE_INT16:
927 case LY_TYPE_INT32:
928 case LY_TYPE_INT64: {
929 struct lysc_type_num *num = (struct lysc_type_num*)type;
930 yprc_range(ctx, num->range, type->basetype, &flag);
931 break;
932 }
933 case LY_TYPE_STRING: {
934 struct lysc_type_str *str = (struct lysc_type_str*)type;
935 yprc_range(ctx, str->length, type->basetype, &flag);
936 LY_ARRAY_FOR(str->patterns, u) {
937 yprc_pattern(ctx, str->patterns[u], &flag);
938 }
939 break;
940 }
941 case LY_TYPE_BITS:
942 case LY_TYPE_ENUM: {
943 /* bits and enums structures are compatible */
944 struct lysc_type_bits *bits = (struct lysc_type_bits*)type;
945 LY_ARRAY_FOR(bits->bits, u) {
946 struct lysc_type_bitenum_item *item = &bits->bits[u];
947 int inner_flag = 0;
948
949 ypr_open(ctx->out, &flag);
950 ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
951 ypr_encode(ctx->out, item->name, -1);
952 ly_print(ctx->out, "\"");
953 LEVEL++;
954 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
955 yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag);
956 if (type->basetype == LY_TYPE_BITS) {
957 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
958 } else { /* LY_TYPE_ENUM */
959 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
960 }
961 ypr_status(ctx, item->flags, item->exts, &inner_flag);
962 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
963 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
964 LEVEL--;
965 ypr_close(ctx, inner_flag);
966 }
967 break;
968 }
969 case LY_TYPE_BOOL:
970 case LY_TYPE_EMPTY:
971 /* nothing to do */
972 break;
973 case LY_TYPE_DEC64: {
974 struct lysc_type_dec *dec = (struct lysc_type_dec*)type;
975 ypr_open(ctx->out, &flag);
976 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag);
977 yprc_range(ctx, dec->range, dec->basetype, &flag);
978 break;
979 }
980 case LY_TYPE_IDENT: {
981 struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type;
982 LY_ARRAY_FOR(ident->bases, u) {
983 ypr_open(ctx->out, &flag);
984 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
985 }
986 break;
987 }
988 case LY_TYPE_INST: {
989 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type;
990 ypr_open(ctx->out, &flag);
991 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
992 break;
993 }
994 case LY_TYPE_LEAFREF: {
995 struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type;
996 ypr_open(ctx->out, &flag);
997 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts);
998 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
999 yprc_type(ctx, lr->realtype);
1000 break;
1001 }
1002 case LY_TYPE_UNION: {
1003 struct lysc_type_union *un = (struct lysc_type_union*)type;
1004 LY_ARRAY_FOR(un->types, u) {
1005 ypr_open(ctx->out, &flag);
1006 yprc_type(ctx, un->types[u]);
1007 }
1008 break;
1009 }
1010 default:
1011 LOGINT(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +02001012 ctx->out->status = LY_EINT;
Radek Krejci693262f2019-04-29 15:23:20 +02001013 }
1014
1015 LEVEL--;
1016 ypr_close(ctx, flag);
1017}
1018
1019static void
1020yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001021{
Radek Krejci56cc0872019-04-30 09:22:27 +02001022 LYOUT_CHECK(ctx->out);
1023
Radek Krejcid3ca0632019-04-16 16:54:54 +02001024 ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
1025 LEVEL++;
1026
Radek Krejci693262f2019-04-29 15:23:20 +02001027 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001028
Radek Krejci693262f2019-04-29 15:23:20 +02001029 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001030
1031 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +02001032 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001033 }
1034 if (tpdf->dflt) {
Radek Krejci693262f2019-04-29 15:23:20 +02001035 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001036 }
1037
Radek Krejci693262f2019-04-29 15:23:20 +02001038 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001039 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
1040 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
1041
1042 LEVEL--;
1043 ly_print(ctx->out, "%*s}\n", INDENT);
1044}
1045
Radek Krejci693262f2019-04-29 15:23:20 +02001046static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node);
1047static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node);
1048static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001049
1050static void
Radek Krejci693262f2019-04-29 15:23:20 +02001051yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001052{
1053 unsigned int u;
1054 int flag = 0;
1055 struct lysp_node *data;
1056
Radek Krejci56cc0872019-04-30 09:22:27 +02001057 LYOUT_CHECK(ctx->out);
1058
Radek Krejcid3ca0632019-04-16 16:54:54 +02001059 ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
1060 LEVEL++;
1061
Radek Krejci693262f2019-04-29 15:23:20 +02001062 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
1063 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +02001064 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1065 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001066
1067 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001068 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001069 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001070 }
1071
1072 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001073 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001074 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001075 }
1076
1077 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001078 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001079 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001080 }
1081
1082 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001083 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001084 }
1085
1086 LEVEL--;
1087 ypr_close(ctx, flag);
1088}
1089
1090static void
Radek Krejci693262f2019-04-29 15:23:20 +02001091yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001092{
1093 unsigned int u;
1094 struct lysp_node *data;
1095
1096 if (!inout->nodetype) {
1097 /* nodetype not set -> input/output is empty */
1098 return;
1099 }
1100 ypr_open(ctx->out, flag);
1101
1102 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1103 LEVEL++;
1104
Radek Krejci693262f2019-04-29 15:23:20 +02001105 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001106 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001107 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001108 }
1109 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001110 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001111 }
1112 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001113 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001114 }
1115
1116 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001117 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001118 }
1119
1120 LEVEL--;
1121 ypr_close(ctx, 1);
1122}
1123
1124static void
Radek Krejci693262f2019-04-29 15:23:20 +02001125yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1126{
1127 unsigned int u;
1128 struct lysc_node *data;
1129
1130 if (!inout->data) {
1131 /* input/output is empty */
1132 return;
1133 }
1134 ypr_open(ctx->out, flag);
1135
1136 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1137 LEVEL++;
1138
1139 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1140 LY_ARRAY_FOR(inout->musts, u) {
1141 yprc_must(ctx, &inout->musts[u], NULL);
1142 }
1143
1144 LY_LIST_FOR(inout->data, data) {
1145 yprc_node(ctx, data);
1146 }
1147
1148 LEVEL--;
1149 ypr_close(ctx, 1);
1150}
1151
1152static void
1153yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001154{
1155 unsigned int u;
1156 int flag = 0;
1157 struct lysp_node *data;
1158
Radek Krejci56cc0872019-04-30 09:22:27 +02001159 LYOUT_CHECK(ctx->out);
1160
Radek Krejcid3ca0632019-04-16 16:54:54 +02001161 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1162
1163 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001164 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1165 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001166
1167 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001168 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001169 }
Radek Krejci693262f2019-04-29 15:23:20 +02001170 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001171 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1172 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1173
1174 LY_ARRAY_FOR(notif->typedefs, u) {
1175 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001176 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001177 }
1178
1179 LY_ARRAY_FOR(notif->groupings, u) {
1180 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001181 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001182 }
1183
1184 LY_LIST_FOR(notif->data, data) {
1185 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001186 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001187 }
1188
1189 LEVEL--;
1190 ypr_close(ctx, flag);
1191}
1192
1193static void
Radek Krejci693262f2019-04-29 15:23:20 +02001194yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1195{
1196 unsigned int u;
1197 int flag = 0;
1198 struct lysc_node *data;
1199
Radek Krejci56cc0872019-04-30 09:22:27 +02001200 LYOUT_CHECK(ctx->out);
1201
Radek Krejci693262f2019-04-29 15:23:20 +02001202 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1203
1204 LEVEL++;
1205 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1206 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1207
1208 LY_ARRAY_FOR(notif->musts, u) {
1209 yprc_must(ctx, &notif->musts[u], &flag);
1210 }
1211 ypr_status(ctx, notif->flags, notif->exts, &flag);
1212 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1213 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1214
1215 LY_LIST_FOR(notif->data, data) {
1216 ypr_open(ctx->out, &flag);
1217 yprc_node(ctx, data);
1218 }
1219
1220 LEVEL--;
1221 ypr_close(ctx, flag);
1222}
1223
1224static void
1225yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001226{
1227 unsigned int u;
1228 int flag = 0;
1229
Radek Krejci56cc0872019-04-30 09:22:27 +02001230 LYOUT_CHECK(ctx->out);
1231
Radek Krejcid3ca0632019-04-16 16:54:54 +02001232 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1233
1234 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001235 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1236 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1237 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001238 ypr_description(ctx, action->dsc, action->exts, &flag);
1239 ypr_reference(ctx, action->ref, action->exts, &flag);
1240
1241 LY_ARRAY_FOR(action->typedefs, u) {
1242 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001243 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001244 }
1245
1246 LY_ARRAY_FOR(action->groupings, u) {
1247 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001248 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001249 }
1250
Radek Krejci693262f2019-04-29 15:23:20 +02001251 yprp_inout(ctx, &action->input, &flag);
1252 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001253
1254 LEVEL--;
1255 ypr_close(ctx, flag);
1256}
1257
1258static void
Radek Krejci693262f2019-04-29 15:23:20 +02001259yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1260{
1261 int flag = 0;
1262
Radek Krejci56cc0872019-04-30 09:22:27 +02001263 LYOUT_CHECK(ctx->out);
1264
Radek Krejci693262f2019-04-29 15:23:20 +02001265 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1266
1267 LEVEL++;
1268 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1269 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1270 ypr_status(ctx, action->flags, action->exts, &flag);
1271 ypr_description(ctx, action->dsc, action->exts, &flag);
1272 ypr_reference(ctx, action->ref, action->exts, &flag);
1273
1274 yprc_inout(ctx, action, &action->input, &flag);
1275 yprc_inout(ctx, action, &action->output, &flag);
1276
1277 LEVEL--;
1278 ypr_close(ctx, flag);
1279}
1280
1281static void
1282yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001283{
Radek Krejci7871ce52019-06-11 16:44:56 +02001284 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001285 LEVEL++;
1286
Radek Krejci693262f2019-04-29 15:23:20 +02001287 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1288 yprp_when(ctx, node->when, flag);
1289 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001290}
1291
1292static void
Radek Krejci693262f2019-04-29 15:23:20 +02001293yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001294{
Radek Krejci693262f2019-04-29 15:23:20 +02001295 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001296
Radek Krejci42903ea2019-06-14 16:24:56 +02001297 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001298 LEVEL++;
1299
1300 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1301 LY_ARRAY_FOR(node->when, u) {
1302 yprc_when(ctx, node->when[u], flag);
1303 }
1304 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1305}
1306
1307/* macr oto unify the code */
1308#define YPR_NODE_COMMON2 \
1309 ypr_config(ctx, node->flags, node->exts, flag); \
1310 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1311 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1312 } \
1313 ypr_status(ctx, node->flags, node->exts, flag); \
1314 ypr_description(ctx, node->dsc, node->exts, flag); \
1315 ypr_reference(ctx, node->ref, node->exts, flag)
1316
1317static void
1318yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1319{
1320 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001321}
1322
1323static void
Radek Krejci693262f2019-04-29 15:23:20 +02001324yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1325{
1326 YPR_NODE_COMMON2;
1327}
1328
1329#undef YPR_NODE_COMMON2
1330
1331static void
1332yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001333{
1334 unsigned int u;
1335 int flag = 0;
1336 struct lysp_node *child;
1337 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1338
Radek Krejci693262f2019-04-29 15:23:20 +02001339 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001340
1341 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001342 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001343 }
1344 if (cont->presence) {
1345 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001346 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001347 }
1348
Radek Krejci693262f2019-04-29 15:23:20 +02001349 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001350
1351 LY_ARRAY_FOR(cont->typedefs, u) {
1352 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001353 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001354 }
1355
1356 LY_ARRAY_FOR(cont->groupings, u) {
1357 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001358 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001359 }
1360
1361 LY_LIST_FOR(cont->child, child) {
1362 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001363 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001364 }
1365
1366 LY_ARRAY_FOR(cont->actions, u) {
1367 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001368 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001369 }
1370
1371 LY_ARRAY_FOR(cont->notifs, u) {
1372 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001373 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001374 }
1375
1376 LEVEL--;
1377 ypr_close(ctx, flag);
1378}
1379
1380static void
Radek Krejci693262f2019-04-29 15:23:20 +02001381yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1382{
1383 unsigned int u;
1384 int flag = 0;
1385 struct lysc_node *child;
1386 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1387
1388 yprc_node_common1(ctx, node, &flag);
1389
1390 LY_ARRAY_FOR(cont->musts, u) {
1391 yprc_must(ctx, &cont->musts[u], &flag);
1392 }
1393 if (cont->flags & LYS_PRESENCE) {
1394 ypr_open(ctx->out, &flag);
1395 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1396 }
1397
1398 yprc_node_common2(ctx, node, &flag);
1399
1400 LY_LIST_FOR(cont->child, child) {
1401 ypr_open(ctx->out, &flag);
1402 yprc_node(ctx, child);
1403 }
1404
1405 LY_ARRAY_FOR(cont->actions, u) {
1406 ypr_open(ctx->out, &flag);
1407 yprc_action(ctx, &cont->actions[u]);
1408 }
1409
1410 LY_ARRAY_FOR(cont->notifs, u) {
1411 ypr_open(ctx->out, &flag);
1412 yprc_notification(ctx, &cont->notifs[u]);
1413 }
1414
1415 LEVEL--;
1416 ypr_close(ctx, flag);
1417}
1418
1419static void
1420yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1421{
1422 int flag = 0;
1423 struct lysp_node *child;
1424 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1425
1426 yprp_node_common1(ctx, node, &flag);
1427 yprp_node_common2(ctx, node, &flag);
1428
1429 LY_LIST_FOR(cas->child, child) {
1430 ypr_open(ctx->out, &flag);
1431 yprp_node(ctx, child);
1432 }
1433
1434 LEVEL--;
1435 ypr_close(ctx, flag);
1436}
1437
1438static void
1439yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1440{
1441 int flag = 0;
1442 struct lysc_node *child;
1443
1444 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1445 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1446
1447 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1448 ypr_open(ctx->out, &flag);
1449 yprc_node(ctx, child);
1450 }
1451
1452 LEVEL--;
1453 ypr_close(ctx, flag);
1454}
1455
1456static void
1457yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001458{
1459 int flag = 0;
1460 struct lysp_node *child;
1461 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1462
Radek Krejci693262f2019-04-29 15:23:20 +02001463 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001464
1465 if (choice->dflt) {
1466 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001467 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001468 }
1469
Radek Krejci693262f2019-04-29 15:23:20 +02001470 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001471
1472 LY_LIST_FOR(choice->child, child) {
1473 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001474 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001475 }
1476
1477 LEVEL--;
1478 ypr_close(ctx, flag);
1479}
1480
1481static void
Radek Krejci693262f2019-04-29 15:23:20 +02001482yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1483{
1484 int flag = 0;
1485 struct lysc_node_case *cs;
1486 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1487
1488 yprc_node_common1(ctx, node, &flag);
1489
1490 if (choice->dflt) {
1491 ypr_open(ctx->out, &flag);
1492 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1493 }
1494
1495 yprc_node_common2(ctx, node, &flag);
1496
1497 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1498 ypr_open(ctx->out, &flag);
1499 yprc_case(ctx, cs);
1500 }
1501
1502 LEVEL--;
1503 ypr_close(ctx, flag);
1504}
1505
1506static void
1507yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001508{
1509 unsigned int u;
1510 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1511
Radek Krejci693262f2019-04-29 15:23:20 +02001512 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001513
Radek Krejci693262f2019-04-29 15:23:20 +02001514 yprp_type(ctx, &leaf->type);
1515 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001516 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001517 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001518 }
Radek Krejci693262f2019-04-29 15:23:20 +02001519 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001520
Radek Krejci693262f2019-04-29 15:23:20 +02001521 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001522
1523 LEVEL--;
1524 ly_print(ctx->out, "%*s}\n", INDENT);
1525}
1526
1527static void
Radek Krejci693262f2019-04-29 15:23:20 +02001528yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1529{
1530 unsigned int u;
1531 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1532
1533 yprc_node_common1(ctx, node, NULL);
1534
1535 yprc_type(ctx, leaf->type);
1536 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1537 LY_ARRAY_FOR(leaf->musts, u) {
1538 yprc_must(ctx, &leaf->musts[u], NULL);
1539 }
1540 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
1541
1542 yprc_node_common2(ctx, node, NULL);
1543
1544 LEVEL--;
1545 ly_print(ctx->out, "%*s}\n", INDENT);
1546}
1547
1548static void
1549yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001550{
1551 unsigned int u;
1552 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1553
Radek Krejci693262f2019-04-29 15:23:20 +02001554 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001555
Radek Krejci693262f2019-04-29 15:23:20 +02001556 yprp_type(ctx, &llist->type);
1557 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001558 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001559 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001560 }
1561 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001562 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001563 }
1564
Radek Krejci693262f2019-04-29 15:23:20 +02001565 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001566
1567 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001568 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001569 }
1570 if (llist->flags & LYS_SET_MAX) {
1571 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001572 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001573 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001574 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001575 }
1576 }
1577
1578 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001579 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001580 }
1581
Radek Krejci693262f2019-04-29 15:23:20 +02001582 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001583 ypr_description(ctx, node->dsc, node->exts, NULL);
1584 ypr_reference(ctx, node->ref, node->exts, NULL);
1585
1586 LEVEL--;
1587 ly_print(ctx->out, "%*s}\n", INDENT);
1588}
1589
1590static void
Radek Krejci693262f2019-04-29 15:23:20 +02001591yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1592{
1593 unsigned int u;
1594 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1595
1596 yprc_node_common1(ctx, node, NULL);
1597
1598 yprc_type(ctx, llist->type);
1599 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1600 LY_ARRAY_FOR(llist->musts, u) {
1601 yprc_must(ctx, &llist->musts[u], NULL);
1602 }
1603 LY_ARRAY_FOR(llist->dflts, u) {
1604 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
1605 }
1606
1607 ypr_config(ctx, node->flags, node->exts, NULL);
1608
1609 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1610 if (llist->max) {
1611 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1612 } else {
1613 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1614 }
1615
1616 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1617
1618 ypr_status(ctx, node->flags, node->exts, NULL);
1619 ypr_description(ctx, node->dsc, node->exts, NULL);
1620 ypr_reference(ctx, node->ref, node->exts, NULL);
1621
1622 LEVEL--;
1623 ly_print(ctx->out, "%*s}\n", INDENT);
1624}
1625
1626static void
1627yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001628{
1629 unsigned int u;
1630 int flag = 0;
1631 struct lysp_node *child;
1632 struct lysp_node_list *list = (struct lysp_node_list *)node;
1633
Radek Krejci693262f2019-04-29 15:23:20 +02001634 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001635
1636 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001637 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001638 }
1639 if (list->key) {
1640 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001641 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001642 }
1643 LY_ARRAY_FOR(list->uniques, u) {
1644 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001645 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001646 }
1647
Radek Krejci693262f2019-04-29 15:23:20 +02001648 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001649
1650 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001651 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001652 }
1653 if (list->flags & LYS_SET_MAX) {
1654 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001655 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001656 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001657 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001658 }
1659 }
1660
1661 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001662 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001663 }
1664
Radek Krejci693262f2019-04-29 15:23:20 +02001665 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001666 ypr_description(ctx, node->dsc, node->exts, NULL);
1667 ypr_reference(ctx, node->ref, node->exts, NULL);
1668
1669 LY_ARRAY_FOR(list->typedefs, u) {
1670 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001671 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001672 }
1673
1674 LY_ARRAY_FOR(list->groupings, u) {
1675 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001676 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001677 }
1678
1679 LY_LIST_FOR(list->child, child) {
1680 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001681 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001682 }
1683
1684 LY_ARRAY_FOR(list->actions, u) {
1685 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001686 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001687 }
1688
1689 LY_ARRAY_FOR(list->notifs, u) {
1690 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001691 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001692 }
1693
1694 LEVEL--;
1695 ypr_close(ctx, flag);
1696}
1697
1698static void
Radek Krejci693262f2019-04-29 15:23:20 +02001699yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1700{
1701 unsigned int u, v;
1702 int flag = 0;
1703 struct lysc_node *child;
1704 struct lysc_node_list *list = (struct lysc_node_list *)node;
1705
1706 yprc_node_common1(ctx, node, &flag);
1707
1708 LY_ARRAY_FOR(list->musts, u) {
1709 yprc_must(ctx, &list->musts[u], NULL);
1710 }
1711 if (list->keys) {
1712 ypr_open(ctx->out, &flag);
1713 ly_print(ctx->out, "%*skey \"", INDENT);
1714 LY_ARRAY_FOR(list->keys, u) {
1715 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", list->keys[u]->name);
1716 }
Radek Krejci73c88f52019-06-14 16:24:19 +02001717 ly_print(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001718 }
1719 LY_ARRAY_FOR(list->uniques, u) {
1720 ypr_open(ctx->out, &flag);
1721 ly_print(ctx->out, "%*sunique \"", INDENT);
1722 LY_ARRAY_FOR(list->uniques[u], v) {
1723 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1724 }
1725 ypr_close(ctx, 0);
1726 }
1727
1728 ypr_config(ctx, node->flags, node->exts, NULL);
1729
1730 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1731 if (list->max) {
1732 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1733 } else {
1734 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1735 }
1736
1737 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1738
1739 ypr_status(ctx, node->flags, node->exts, NULL);
1740 ypr_description(ctx, node->dsc, node->exts, NULL);
1741 ypr_reference(ctx, node->ref, node->exts, NULL);
1742
1743 LY_LIST_FOR(list->child, child) {
1744 ypr_open(ctx->out, &flag);
1745 yprc_node(ctx, child);
1746 }
1747
1748 LY_ARRAY_FOR(list->actions, u) {
1749 ypr_open(ctx->out, &flag);
1750 yprc_action(ctx, &list->actions[u]);
1751 }
1752
1753 LY_ARRAY_FOR(list->notifs, u) {
1754 ypr_open(ctx->out, &flag);
1755 yprc_notification(ctx, &list->notifs[u]);
1756 }
1757
1758 LEVEL--;
1759 ypr_close(ctx, flag);
1760}
1761
1762static void
1763yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001764{
1765 unsigned int u;
1766 int flag = 0;
1767
1768 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1769 LEVEL++;
1770
Radek Krejci693262f2019-04-29 15:23:20 +02001771 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1772 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001773
1774 LY_ARRAY_FOR(refine->musts, u) {
1775 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001776 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001777 }
1778
1779 if (refine->presence) {
1780 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001781 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001782 }
1783
1784 LY_ARRAY_FOR(refine->dflts, u) {
1785 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001786 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001787 }
1788
Radek Krejci693262f2019-04-29 15:23:20 +02001789 ypr_config(ctx, refine->flags, refine->exts, &flag);
1790 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001791
1792 if (refine->flags & LYS_SET_MIN) {
1793 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001794 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001795 }
1796 if (refine->flags & LYS_SET_MAX) {
1797 ypr_open(ctx->out, &flag);
1798 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001799 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001800 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001801 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001802 }
1803 }
1804
1805 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1806 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1807
1808 LEVEL--;
1809 ypr_close(ctx, flag);
1810}
1811
1812static void
Radek Krejci693262f2019-04-29 15:23:20 +02001813yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001814{
1815 unsigned int u;
1816 struct lysp_node *child;
1817
1818 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1819 LEVEL++;
1820
Radek Krejci693262f2019-04-29 15:23:20 +02001821 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1822 yprp_when(ctx, aug->when, NULL);
1823 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1824 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001825 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1826 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1827
1828 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001829 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830 }
1831
1832 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001833 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001834 }
1835
1836 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001837 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001838 }
1839
1840 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001841 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001842}
1843
1844
1845static void
Radek Krejci693262f2019-04-29 15:23:20 +02001846yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001847{
1848 unsigned int u;
1849 int flag = 0;
1850 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1851
Radek Krejci693262f2019-04-29 15:23:20 +02001852 yprp_node_common1(ctx, node, &flag);
1853 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001854
1855 LY_ARRAY_FOR(uses->refines, u) {
1856 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001857 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001858 }
1859
1860 LY_ARRAY_FOR(uses->augments, u) {
1861 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001862 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001863 }
1864
1865 LEVEL--;
1866 ypr_close(ctx, flag);
1867}
1868
1869static void
Radek Krejci693262f2019-04-29 15:23:20 +02001870yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001871{
1872 unsigned int u;
1873 int flag = 0;
1874 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1875
Radek Krejci693262f2019-04-29 15:23:20 +02001876 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001877
1878 LY_ARRAY_FOR(any->musts, u) {
1879 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001880 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001881 }
1882
Radek Krejci693262f2019-04-29 15:23:20 +02001883 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001884
1885 LEVEL--;
1886 ypr_close(ctx, flag);
1887}
1888
1889static void
Radek Krejci693262f2019-04-29 15:23:20 +02001890yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001891{
Radek Krejci693262f2019-04-29 15:23:20 +02001892 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001894 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001895
Radek Krejci693262f2019-04-29 15:23:20 +02001896 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001897
Radek Krejci693262f2019-04-29 15:23:20 +02001898 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001899 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001900 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001901 }
1902
Radek Krejci693262f2019-04-29 15:23:20 +02001903 yprc_node_common2(ctx, node, &flag);
1904
Radek Krejcid3ca0632019-04-16 16:54:54 +02001905 LEVEL--;
1906 ypr_close(ctx, flag);
1907}
1908
1909static void
Radek Krejci693262f2019-04-29 15:23:20 +02001910yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001911{
Radek Krejci56cc0872019-04-30 09:22:27 +02001912 LYOUT_CHECK(ctx->out);
1913
Radek Krejcid3ca0632019-04-16 16:54:54 +02001914 switch (node->nodetype) {
1915 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001916 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001917 break;
1918 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001919 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001920 break;
1921 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001922 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001923 break;
1924 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001925 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001926 break;
1927 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001928 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001929 break;
1930 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001931 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001932 break;
1933 case LYS_ANYXML:
1934 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001935 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001936 break;
1937 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001938 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001939 break;
1940 default:
1941 break;
1942 }
1943}
1944
1945static void
Radek Krejci693262f2019-04-29 15:23:20 +02001946yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1947{
Radek Krejci56cc0872019-04-30 09:22:27 +02001948 LYOUT_CHECK(ctx->out);
1949
Radek Krejci693262f2019-04-29 15:23:20 +02001950 switch (node->nodetype) {
1951 case LYS_CONTAINER:
1952 yprc_container(ctx, node);
1953 break;
1954 case LYS_CHOICE:
1955 yprc_choice(ctx, node);
1956 break;
1957 case LYS_LEAF:
1958 yprc_leaf(ctx, node);
1959 break;
1960 case LYS_LEAFLIST:
1961 yprc_leaflist(ctx, node);
1962 break;
1963 case LYS_LIST:
1964 yprc_list(ctx, node);
1965 break;
1966 case LYS_ANYXML:
1967 case LYS_ANYDATA:
1968 yprc_anydata(ctx, node);
1969 break;
1970 default:
1971 break;
1972 }
1973}
1974
1975static void
1976yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001977{
1978 unsigned int u, v;
1979 struct lysp_deviate_add *add;
1980 struct lysp_deviate_rpl *rpl;
1981 struct lysp_deviate_del *del;
1982
1983 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
1984 LEVEL++;
1985
Radek Krejci693262f2019-04-29 15:23:20 +02001986 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001987 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1988 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1989
1990 LY_ARRAY_FOR(deviation->deviates, u) {
1991 ly_print(ctx->out, "%*sdeviate ", INDENT);
1992 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
1993 if (deviation->deviates[u].exts) {
1994 ly_print(ctx->out, "not-supported {\n");
1995 LEVEL++;
1996
Radek Krejci693262f2019-04-29 15:23:20 +02001997 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001998 } else {
1999 ly_print(ctx->out, "not-supported;\n");
2000 continue;
2001 }
2002 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
2003 add = (struct lysp_deviate_add*)&deviation->deviates[u];
2004 ly_print(ctx->out, "add {\n");
2005 LEVEL++;
2006
Radek Krejci693262f2019-04-29 15:23:20 +02002007 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
2008 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002009 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002010 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002011 }
2012 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002013 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002014 }
2015 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002016 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002017 }
Radek Krejci693262f2019-04-29 15:23:20 +02002018 ypr_config(ctx, add->flags, add->exts, NULL);
2019 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002020 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002021 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002022 }
2023 if (add->flags & LYS_SET_MAX) {
2024 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002025 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002026 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002027 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 }
2029 }
2030 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
2031 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
2032 ly_print(ctx->out, "replace {\n");
2033 LEVEL++;
2034
Radek Krejci693262f2019-04-29 15:23:20 +02002035 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002036 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02002037 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002038 }
Radek Krejci693262f2019-04-29 15:23:20 +02002039 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
2040 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
2041 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
2042 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002043 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002044 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045 }
2046 if (rpl->flags & LYS_SET_MAX) {
2047 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002048 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002049 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002050 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002051 }
2052 }
2053 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
2054 del = (struct lysp_deviate_del*)&deviation->deviates[u];
2055 ly_print(ctx->out, "delete {\n");
2056 LEVEL++;
2057
Radek Krejci693262f2019-04-29 15:23:20 +02002058 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2059 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002060 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002061 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062 }
2063 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002064 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002065 }
2066 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002067 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002068 }
2069 }
2070
2071 LEVEL--;
2072 ypr_close(ctx, 1);
2073 }
2074
2075 LEVEL--;
2076 ypr_close(ctx, 1);
2077}
2078
Radek Krejci693262f2019-04-29 15:23:20 +02002079/**
2080 * @brief Minimal print of a schema.
2081 *
2082 * To print
2083 * a) compiled schema when it is not compiled or
2084 * b) parsed when the parsed form was already removed
2085 */
2086static LY_ERR
2087ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2088{
2089 /* module-header-stmts */
2090 if (module->version) {
2091 if (module->version) {
2092 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2093 }
2094 }
2095 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2096 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2097
2098 /* meta-stmts */
2099 if (module->org || module->contact || module->dsc || module->ref) {
2100 ly_print(ctx->out, "\n");
2101 }
2102 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2103 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2104 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2105 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2106
2107 /* revision-stmts */
2108 if (module->revision) {
2109 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2110 }
2111
2112 LEVEL--;
2113 ly_print(ctx->out, "%*s}\n", INDENT);
2114 ly_print_flush(ctx->out);
2115
2116 return LY_SUCCESS;
2117}
2118
Radek Krejcid3ca0632019-04-16 16:54:54 +02002119LY_ERR
2120yang_print_parsed(struct lyout *out, const struct lys_module *module)
2121{
2122 unsigned int u;
2123 struct lysp_node *data;
2124 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002125 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002126
2127 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2128 LEVEL++;
2129
Radek Krejci693262f2019-04-29 15:23:20 +02002130 if (!modp) {
2131 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2132 return ypr_missing_format(ctx, module);
2133 }
2134
Radek Krejcid3ca0632019-04-16 16:54:54 +02002135 /* module-header-stmts */
2136 if (module->version) {
2137 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002138 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002139 }
2140 }
Radek Krejci693262f2019-04-29 15:23:20 +02002141 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2142 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002143
2144 /* linkage-stmts */
2145 LY_ARRAY_FOR(modp->imports, u) {
Radek Krejci7871ce52019-06-11 16:44:56 +02002146 ly_print(out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].module->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002147 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002148 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2149 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002150 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002151 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002152 }
Radek Krejci693262f2019-04-29 15:23:20 +02002153 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2154 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002155 LEVEL--;
2156 ly_print(out, "%*s}\n", INDENT);
2157 }
2158 LY_ARRAY_FOR(modp->includes, u) {
2159 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
Radek Krejci7871ce52019-06-11 16:44:56 +02002160 ly_print(out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].submodule->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002161 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002162 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002163 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002164 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002165 }
Radek Krejci693262f2019-04-29 15:23:20 +02002166 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2167 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002168 LEVEL--;
2169 ly_print(out, "%*s}\n", INDENT);
2170 } else {
2171 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2172 }
2173 }
2174
2175 /* meta-stmts */
2176 if (module->org || module->contact || module->dsc || module->ref) {
2177 ly_print(out, "\n");
2178 }
Radek Krejci693262f2019-04-29 15:23:20 +02002179 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2180 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2181 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2182 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002183
2184 /* revision-stmts */
2185 if (modp->revs) {
2186 ly_print(out, "\n");
2187 }
2188 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002189 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002190 }
2191 /* body-stmts */
2192 LY_ARRAY_FOR(modp->extensions, u) {
2193 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002194 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002195 }
2196 if (modp->exts) {
2197 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002198 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002199 }
2200
2201 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002202 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002203 }
2204
2205 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002206 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002207 }
2208
2209 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002210 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002211 }
2212
2213 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002214 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002215 }
2216
2217 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002218 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002219 }
2220
2221 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002222 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002223 }
2224
2225 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002226 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002227 }
2228
2229 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002230 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002231 }
2232
2233 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002234 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002235 }
2236
2237 LEVEL--;
2238 ly_print(out, "%*s}\n", INDENT);
2239 ly_print_flush(out);
2240
2241 return LY_SUCCESS;
2242}
2243
2244LY_ERR
2245yang_print_compiled(struct lyout *out, const struct lys_module *module)
2246{
Radek Krejci693262f2019-04-29 15:23:20 +02002247 unsigned int u;
2248 struct lysc_node *data;
2249 struct lysc_module *modc = module->compiled;
2250 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2251
2252 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2253 LEVEL++;
2254
2255 if (!modc) {
2256 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2257 return ypr_missing_format(ctx, module);
2258 }
2259
2260 /* module-header-stmts */
2261 if (module->version) {
2262 if (module->version) {
2263 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2264 }
2265 }
2266 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2267 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2268
2269 /* linkage-stmts */
2270 LY_ARRAY_FOR(modc->imports, u) {
2271 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2272 LEVEL++;
2273 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2274 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2275 if (modc->imports[u].module->revision) {
2276 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2277 }
2278 LEVEL--;
2279 ly_print(out, "%*s}\n", INDENT);
2280 }
2281
2282 /* meta-stmts */
2283 if (module->org || module->contact || module->dsc || module->ref) {
2284 ly_print(out, "\n");
2285 }
2286 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2287 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2288 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2289 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2290
2291 /* revision-stmts */
2292 if (module->revision) {
2293 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2294 }
2295
2296 /* body-stmts */
2297 if (modc->exts) {
2298 ly_print(out, "\n");
2299 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2300 }
2301
2302 LY_ARRAY_FOR(modc->features, u) {
2303 yprc_feature(ctx, &modc->features[u]);
2304 }
2305
2306 LY_ARRAY_FOR(modc->identities, u) {
2307 yprc_identity(ctx, &modc->identities[u]);
2308 }
2309
2310 LY_LIST_FOR(modc->data, data) {
2311 yprc_node(ctx, data);
2312 }
2313
2314 LY_ARRAY_FOR(modc->rpcs, u) {
2315 yprc_action(ctx, &modc->rpcs[u]);
2316 }
2317
2318 LY_ARRAY_FOR(modc->notifs, u) {
2319 yprc_notification(ctx, &modc->notifs[u]);
2320 }
2321
2322 LEVEL--;
2323 ly_print(out, "%*s}\n", INDENT);
2324 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002325
2326 return LY_SUCCESS;
2327}