blob: c42909476f314550b16925cfdc58f2d4dab617ae [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{
483 unsigned int u;
484 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++;
498 LY_ARRAY_FOR(exts, u) {
499 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
500 continue;
501 }
502 yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
503 }
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
704 ypr_open(ctx->out, flag);
705 ly_print(ctx->out, "%*s%s \"", (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY)? "length" : "range", INDENT);
706 LY_ARRAY_FOR(range->parts, u) {
707 if (u > 0) {
708 ly_print(ctx->out, " | ");
709 }
710 if (range->parts[u].max_64 == range->parts[u].min_64) {
711 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
712 ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64);
713 } else { /* signed values */
714 ly_print(ctx->out, "%"PRId64, range->parts[u].max_64);
715 }
716 } else {
717 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
718 ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
719 } else { /* signed values */
720 ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64);
721 }
722 }
723 }
724 ly_print(ctx->out, "\"");
725
726 LEVEL++;
727 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0);
728 if (range->emsg) {
729 ypr_open(ctx->out, &inner_flag);
730 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts);
731 }
732 if (range->eapptag) {
733 ypr_open(ctx->out, &inner_flag);
734 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts);
735 }
736 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
737 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
738
739 LEVEL--;
740 ypr_close(ctx, inner_flag);
741}
742
743static void
744yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag)
745{
746 int inner_flag = 0;
747
748 ypr_open(ctx->out, flag);
749 ly_print(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200750 ypr_encode(ctx->out, pattern->expr, -1);
Radek Krejci693262f2019-04-29 15:23:20 +0200751 ly_print(ctx->out, "\"");
752
753 LEVEL++;
754 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0);
755 if (pattern->inverted) {
756 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
757 ypr_open(ctx->out, &inner_flag);
758 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts);
759 }
760 if (pattern->emsg) {
761 ypr_open(ctx->out, &inner_flag);
762 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts);
763 }
764 if (pattern->eapptag) {
765 ypr_open(ctx->out, &inner_flag);
766 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts);
767 }
768 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
769 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
770
771 LEVEL--;
772 ypr_close(ctx, inner_flag);
773}
774
775static void
776yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200777{
778 int inner_flag = 0;
779
780 if (!when) {
781 return;
782 }
783 ypr_open(ctx->out, flag);
784
785 ly_print(ctx->out, "%*swhen \"", INDENT);
786 ypr_encode(ctx->out, when->cond, -1);
787 ly_print(ctx->out, "\"");
788
789 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200790 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200791 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
792 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
793 LEVEL--;
794 ypr_close(ctx, inner_flag);
795}
796
797static void
Radek Krejci693262f2019-04-29 15:23:20 +0200798yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag)
799{
800 int inner_flag = 0;
801
802 if (!when) {
803 return;
804 }
805 ypr_open(ctx->out, flag);
806
807 ly_print(ctx->out, "%*swhen \"", INDENT);
808 ypr_encode(ctx->out, when->cond->expr, -1);
809 ly_print(ctx->out, "\"");
810
811 LEVEL++;
812 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
813 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
814 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
815 LEVEL--;
816 ypr_close(ctx, inner_flag);
817}
818
819static void
820yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200821{
822 unsigned int u;
823 int inner_flag;
824
825 LY_ARRAY_FOR(items, u) {
826 ypr_open(ctx->out, flag);
827 ly_print(ctx->out, "%*s%s \"", INDENT, type == LY_TYPE_BITS ? "bit" : "enum");
828 ypr_encode(ctx->out, items[u].name, -1);
829 ly_print(ctx->out, "\"");
830 inner_flag = 0;
831 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200832 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
833 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200834 if (items[u].flags & LYS_SET_VALUE) {
835 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200836 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200837 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200838 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200839 }
840 }
Radek Krejci693262f2019-04-29 15:23:20 +0200841 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200842 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
843 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
844 LEVEL--;
845 ypr_close(ctx, inner_flag);
846 }
847}
848
849static void
Radek Krejci693262f2019-04-29 15:23:20 +0200850yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200851{
852 unsigned int u;
853 int flag = 0;
854
855 ly_print(ctx->out, "%*stype %s", INDENT, type->name);
856 LEVEL++;
857
Radek Krejci693262f2019-04-29 15:23:20 +0200858 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200859
Radek Krejci693262f2019-04-29 15:23:20 +0200860 yprp_restr(ctx, type->range, "range", &flag);
861 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200862 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200863 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200864 }
Radek Krejci693262f2019-04-29 15:23:20 +0200865 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
866 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200867
868 if (type->path) {
869 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200870 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200871 }
872 if (type->flags & LYS_SET_REQINST) {
873 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200874 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200875 }
876 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200877 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200878 }
879 LY_ARRAY_FOR(type->bases, u) {
880 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200881 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200882 }
883 LY_ARRAY_FOR(type->types, u) {
884 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200885 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200886 }
887
888 LEVEL--;
889 ypr_close(ctx, flag);
890}
891
892static void
Radek Krejci693262f2019-04-29 15:23:20 +0200893yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
894{
895 unsigned int u;
896 int flag = 0;
897
898 ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
899 LEVEL++;
900
901 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
902 if (type->dflt) {
903 ypr_open(ctx->out, &flag);
904 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, type->dflt, type->exts);
905 }
906
907 switch(type->basetype) {
908 case LY_TYPE_BINARY: {
909 struct lysc_type_bin *bin = (struct lysc_type_bin*)type;
910 yprc_range(ctx, bin->length, type->basetype, &flag);
911 break;
912 }
913 case LY_TYPE_UINT8:
914 case LY_TYPE_UINT16:
915 case LY_TYPE_UINT32:
916 case LY_TYPE_UINT64:
917 case LY_TYPE_INT8:
918 case LY_TYPE_INT16:
919 case LY_TYPE_INT32:
920 case LY_TYPE_INT64: {
921 struct lysc_type_num *num = (struct lysc_type_num*)type;
922 yprc_range(ctx, num->range, type->basetype, &flag);
923 break;
924 }
925 case LY_TYPE_STRING: {
926 struct lysc_type_str *str = (struct lysc_type_str*)type;
927 yprc_range(ctx, str->length, type->basetype, &flag);
928 LY_ARRAY_FOR(str->patterns, u) {
929 yprc_pattern(ctx, str->patterns[u], &flag);
930 }
931 break;
932 }
933 case LY_TYPE_BITS:
934 case LY_TYPE_ENUM: {
935 /* bits and enums structures are compatible */
936 struct lysc_type_bits *bits = (struct lysc_type_bits*)type;
937 LY_ARRAY_FOR(bits->bits, u) {
938 struct lysc_type_bitenum_item *item = &bits->bits[u];
939 int inner_flag = 0;
940
941 ypr_open(ctx->out, &flag);
942 ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
943 ypr_encode(ctx->out, item->name, -1);
944 ly_print(ctx->out, "\"");
945 LEVEL++;
946 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
947 yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag);
948 if (type->basetype == LY_TYPE_BITS) {
949 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
950 } else { /* LY_TYPE_ENUM */
951 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
952 }
953 ypr_status(ctx, item->flags, item->exts, &inner_flag);
954 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
955 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
956 LEVEL--;
957 ypr_close(ctx, inner_flag);
958 }
959 break;
960 }
961 case LY_TYPE_BOOL:
962 case LY_TYPE_EMPTY:
963 /* nothing to do */
964 break;
965 case LY_TYPE_DEC64: {
966 struct lysc_type_dec *dec = (struct lysc_type_dec*)type;
967 ypr_open(ctx->out, &flag);
968 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag);
969 yprc_range(ctx, dec->range, dec->basetype, &flag);
970 break;
971 }
972 case LY_TYPE_IDENT: {
973 struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type;
974 LY_ARRAY_FOR(ident->bases, u) {
975 ypr_open(ctx->out, &flag);
976 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
977 }
978 break;
979 }
980 case LY_TYPE_INST: {
981 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type;
982 ypr_open(ctx->out, &flag);
983 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
984 break;
985 }
986 case LY_TYPE_LEAFREF: {
987 struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type;
988 ypr_open(ctx->out, &flag);
989 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts);
990 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
991 yprc_type(ctx, lr->realtype);
992 break;
993 }
994 case LY_TYPE_UNION: {
995 struct lysc_type_union *un = (struct lysc_type_union*)type;
996 LY_ARRAY_FOR(un->types, u) {
997 ypr_open(ctx->out, &flag);
998 yprc_type(ctx, un->types[u]);
999 }
1000 break;
1001 }
1002 default:
1003 LOGINT(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +02001004 ctx->out->status = LY_EINT;
Radek Krejci693262f2019-04-29 15:23:20 +02001005 }
1006
1007 LEVEL--;
1008 ypr_close(ctx, flag);
1009}
1010
1011static void
1012yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001013{
Radek Krejci56cc0872019-04-30 09:22:27 +02001014 LYOUT_CHECK(ctx->out);
1015
Radek Krejcid3ca0632019-04-16 16:54:54 +02001016 ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
1017 LEVEL++;
1018
Radek Krejci693262f2019-04-29 15:23:20 +02001019 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001020
Radek Krejci693262f2019-04-29 15:23:20 +02001021 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001022
1023 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +02001024 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001025 }
1026 if (tpdf->dflt) {
Radek Krejci693262f2019-04-29 15:23:20 +02001027 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001028 }
1029
Radek Krejci693262f2019-04-29 15:23:20 +02001030 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001031 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
1032 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
1033
1034 LEVEL--;
1035 ly_print(ctx->out, "%*s}\n", INDENT);
1036}
1037
Radek Krejci693262f2019-04-29 15:23:20 +02001038static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node);
1039static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node);
1040static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001041
1042static void
Radek Krejci693262f2019-04-29 15:23:20 +02001043yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001044{
1045 unsigned int u;
1046 int flag = 0;
1047 struct lysp_node *data;
1048
Radek Krejci56cc0872019-04-30 09:22:27 +02001049 LYOUT_CHECK(ctx->out);
1050
Radek Krejcid3ca0632019-04-16 16:54:54 +02001051 ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
1052 LEVEL++;
1053
Radek Krejci693262f2019-04-29 15:23:20 +02001054 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
1055 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +02001056 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1057 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001058
1059 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001060 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001061 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001062 }
1063
1064 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001065 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001066 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001067 }
1068
1069 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001070 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001071 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001072 }
1073
1074 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001075 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001076 }
1077
1078 LEVEL--;
1079 ypr_close(ctx, flag);
1080}
1081
1082static void
Radek Krejci693262f2019-04-29 15:23:20 +02001083yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001084{
1085 unsigned int u;
1086 struct lysp_node *data;
1087
1088 if (!inout->nodetype) {
1089 /* nodetype not set -> input/output is empty */
1090 return;
1091 }
1092 ypr_open(ctx->out, flag);
1093
1094 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1095 LEVEL++;
1096
Radek Krejci693262f2019-04-29 15:23:20 +02001097 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001098 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001099 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001100 }
1101 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001102 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001103 }
1104 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001105 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001106 }
1107
1108 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001109 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001110 }
1111
1112 LEVEL--;
1113 ypr_close(ctx, 1);
1114}
1115
1116static void
Radek Krejci693262f2019-04-29 15:23:20 +02001117yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1118{
1119 unsigned int u;
1120 struct lysc_node *data;
1121
1122 if (!inout->data) {
1123 /* input/output is empty */
1124 return;
1125 }
1126 ypr_open(ctx->out, flag);
1127
1128 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1129 LEVEL++;
1130
1131 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1132 LY_ARRAY_FOR(inout->musts, u) {
1133 yprc_must(ctx, &inout->musts[u], NULL);
1134 }
1135
1136 LY_LIST_FOR(inout->data, data) {
1137 yprc_node(ctx, data);
1138 }
1139
1140 LEVEL--;
1141 ypr_close(ctx, 1);
1142}
1143
1144static void
1145yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001146{
1147 unsigned int u;
1148 int flag = 0;
1149 struct lysp_node *data;
1150
Radek Krejci56cc0872019-04-30 09:22:27 +02001151 LYOUT_CHECK(ctx->out);
1152
Radek Krejcid3ca0632019-04-16 16:54:54 +02001153 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1154
1155 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001156 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1157 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001158
1159 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001160 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001161 }
Radek Krejci693262f2019-04-29 15:23:20 +02001162 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001163 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1164 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1165
1166 LY_ARRAY_FOR(notif->typedefs, u) {
1167 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001168 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001169 }
1170
1171 LY_ARRAY_FOR(notif->groupings, u) {
1172 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001173 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001174 }
1175
1176 LY_LIST_FOR(notif->data, data) {
1177 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001178 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001179 }
1180
1181 LEVEL--;
1182 ypr_close(ctx, flag);
1183}
1184
1185static void
Radek Krejci693262f2019-04-29 15:23:20 +02001186yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1187{
1188 unsigned int u;
1189 int flag = 0;
1190 struct lysc_node *data;
1191
Radek Krejci56cc0872019-04-30 09:22:27 +02001192 LYOUT_CHECK(ctx->out);
1193
Radek Krejci693262f2019-04-29 15:23:20 +02001194 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1195
1196 LEVEL++;
1197 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1198 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1199
1200 LY_ARRAY_FOR(notif->musts, u) {
1201 yprc_must(ctx, &notif->musts[u], &flag);
1202 }
1203 ypr_status(ctx, notif->flags, notif->exts, &flag);
1204 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1205 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1206
1207 LY_LIST_FOR(notif->data, data) {
1208 ypr_open(ctx->out, &flag);
1209 yprc_node(ctx, data);
1210 }
1211
1212 LEVEL--;
1213 ypr_close(ctx, flag);
1214}
1215
1216static void
1217yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001218{
1219 unsigned int u;
1220 int flag = 0;
1221
Radek Krejci56cc0872019-04-30 09:22:27 +02001222 LYOUT_CHECK(ctx->out);
1223
Radek Krejcid3ca0632019-04-16 16:54:54 +02001224 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1225
1226 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001227 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1228 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1229 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001230 ypr_description(ctx, action->dsc, action->exts, &flag);
1231 ypr_reference(ctx, action->ref, action->exts, &flag);
1232
1233 LY_ARRAY_FOR(action->typedefs, u) {
1234 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001235 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001236 }
1237
1238 LY_ARRAY_FOR(action->groupings, u) {
1239 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001240 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001241 }
1242
Radek Krejci693262f2019-04-29 15:23:20 +02001243 yprp_inout(ctx, &action->input, &flag);
1244 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001245
1246 LEVEL--;
1247 ypr_close(ctx, flag);
1248}
1249
1250static void
Radek Krejci693262f2019-04-29 15:23:20 +02001251yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1252{
1253 int flag = 0;
1254
Radek Krejci56cc0872019-04-30 09:22:27 +02001255 LYOUT_CHECK(ctx->out);
1256
Radek Krejci693262f2019-04-29 15:23:20 +02001257 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1258
1259 LEVEL++;
1260 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1261 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1262 ypr_status(ctx, action->flags, action->exts, &flag);
1263 ypr_description(ctx, action->dsc, action->exts, &flag);
1264 ypr_reference(ctx, action->ref, action->exts, &flag);
1265
1266 yprc_inout(ctx, action, &action->input, &flag);
1267 yprc_inout(ctx, action, &action->output, &flag);
1268
1269 LEVEL--;
1270 ypr_close(ctx, flag);
1271}
1272
1273static void
1274yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001275{
1276 ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
1277 LEVEL++;
1278
Radek Krejci693262f2019-04-29 15:23:20 +02001279 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1280 yprp_when(ctx, node->when, flag);
1281 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001282}
1283
1284static void
Radek Krejci693262f2019-04-29 15:23:20 +02001285yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286{
Radek Krejci693262f2019-04-29 15:23:20 +02001287 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001288
Radek Krejci693262f2019-04-29 15:23:20 +02001289 ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
1290 LEVEL++;
1291
1292 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1293 LY_ARRAY_FOR(node->when, u) {
1294 yprc_when(ctx, node->when[u], flag);
1295 }
1296 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1297}
1298
1299/* macr oto unify the code */
1300#define YPR_NODE_COMMON2 \
1301 ypr_config(ctx, node->flags, node->exts, flag); \
1302 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1303 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1304 } \
1305 ypr_status(ctx, node->flags, node->exts, flag); \
1306 ypr_description(ctx, node->dsc, node->exts, flag); \
1307 ypr_reference(ctx, node->ref, node->exts, flag)
1308
1309static void
1310yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1311{
1312 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001313}
1314
1315static void
Radek Krejci693262f2019-04-29 15:23:20 +02001316yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1317{
1318 YPR_NODE_COMMON2;
1319}
1320
1321#undef YPR_NODE_COMMON2
1322
1323static void
1324yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001325{
1326 unsigned int u;
1327 int flag = 0;
1328 struct lysp_node *child;
1329 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1330
Radek Krejci693262f2019-04-29 15:23:20 +02001331 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001332
1333 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001334 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001335 }
1336 if (cont->presence) {
1337 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001338 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001339 }
1340
Radek Krejci693262f2019-04-29 15:23:20 +02001341 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001342
1343 LY_ARRAY_FOR(cont->typedefs, u) {
1344 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001345 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001346 }
1347
1348 LY_ARRAY_FOR(cont->groupings, u) {
1349 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001350 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001351 }
1352
1353 LY_LIST_FOR(cont->child, child) {
1354 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001355 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001356 }
1357
1358 LY_ARRAY_FOR(cont->actions, u) {
1359 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001360 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001361 }
1362
1363 LY_ARRAY_FOR(cont->notifs, u) {
1364 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001365 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001366 }
1367
1368 LEVEL--;
1369 ypr_close(ctx, flag);
1370}
1371
1372static void
Radek Krejci693262f2019-04-29 15:23:20 +02001373yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1374{
1375 unsigned int u;
1376 int flag = 0;
1377 struct lysc_node *child;
1378 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1379
1380 yprc_node_common1(ctx, node, &flag);
1381
1382 LY_ARRAY_FOR(cont->musts, u) {
1383 yprc_must(ctx, &cont->musts[u], &flag);
1384 }
1385 if (cont->flags & LYS_PRESENCE) {
1386 ypr_open(ctx->out, &flag);
1387 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1388 }
1389
1390 yprc_node_common2(ctx, node, &flag);
1391
1392 LY_LIST_FOR(cont->child, child) {
1393 ypr_open(ctx->out, &flag);
1394 yprc_node(ctx, child);
1395 }
1396
1397 LY_ARRAY_FOR(cont->actions, u) {
1398 ypr_open(ctx->out, &flag);
1399 yprc_action(ctx, &cont->actions[u]);
1400 }
1401
1402 LY_ARRAY_FOR(cont->notifs, u) {
1403 ypr_open(ctx->out, &flag);
1404 yprc_notification(ctx, &cont->notifs[u]);
1405 }
1406
1407 LEVEL--;
1408 ypr_close(ctx, flag);
1409}
1410
1411static void
1412yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1413{
1414 int flag = 0;
1415 struct lysp_node *child;
1416 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1417
1418 yprp_node_common1(ctx, node, &flag);
1419 yprp_node_common2(ctx, node, &flag);
1420
1421 LY_LIST_FOR(cas->child, child) {
1422 ypr_open(ctx->out, &flag);
1423 yprp_node(ctx, child);
1424 }
1425
1426 LEVEL--;
1427 ypr_close(ctx, flag);
1428}
1429
1430static void
1431yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1432{
1433 int flag = 0;
1434 struct lysc_node *child;
1435
1436 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1437 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1438
1439 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1440 ypr_open(ctx->out, &flag);
1441 yprc_node(ctx, child);
1442 }
1443
1444 LEVEL--;
1445 ypr_close(ctx, flag);
1446}
1447
1448static void
1449yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001450{
1451 int flag = 0;
1452 struct lysp_node *child;
1453 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1454
Radek Krejci693262f2019-04-29 15:23:20 +02001455 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001456
1457 if (choice->dflt) {
1458 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001459 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001460 }
1461
Radek Krejci693262f2019-04-29 15:23:20 +02001462 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001463
1464 LY_LIST_FOR(choice->child, child) {
1465 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001466 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001467 }
1468
1469 LEVEL--;
1470 ypr_close(ctx, flag);
1471}
1472
1473static void
Radek Krejci693262f2019-04-29 15:23:20 +02001474yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1475{
1476 int flag = 0;
1477 struct lysc_node_case *cs;
1478 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1479
1480 yprc_node_common1(ctx, node, &flag);
1481
1482 if (choice->dflt) {
1483 ypr_open(ctx->out, &flag);
1484 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1485 }
1486
1487 yprc_node_common2(ctx, node, &flag);
1488
1489 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1490 ypr_open(ctx->out, &flag);
1491 yprc_case(ctx, cs);
1492 }
1493
1494 LEVEL--;
1495 ypr_close(ctx, flag);
1496}
1497
1498static void
1499yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001500{
1501 unsigned int u;
1502 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1503
Radek Krejci693262f2019-04-29 15:23:20 +02001504 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001505
Radek Krejci693262f2019-04-29 15:23:20 +02001506 yprp_type(ctx, &leaf->type);
1507 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001508 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001509 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001510 }
Radek Krejci693262f2019-04-29 15:23:20 +02001511 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001512
Radek Krejci693262f2019-04-29 15:23:20 +02001513 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001514
1515 LEVEL--;
1516 ly_print(ctx->out, "%*s}\n", INDENT);
1517}
1518
1519static void
Radek Krejci693262f2019-04-29 15:23:20 +02001520yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1521{
1522 unsigned int u;
1523 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1524
1525 yprc_node_common1(ctx, node, NULL);
1526
1527 yprc_type(ctx, leaf->type);
1528 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1529 LY_ARRAY_FOR(leaf->musts, u) {
1530 yprc_must(ctx, &leaf->musts[u], NULL);
1531 }
1532 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
1533
1534 yprc_node_common2(ctx, node, NULL);
1535
1536 LEVEL--;
1537 ly_print(ctx->out, "%*s}\n", INDENT);
1538}
1539
1540static void
1541yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001542{
1543 unsigned int u;
1544 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1545
Radek Krejci693262f2019-04-29 15:23:20 +02001546 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001547
Radek Krejci693262f2019-04-29 15:23:20 +02001548 yprp_type(ctx, &llist->type);
1549 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001550 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001551 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001552 }
1553 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001554 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001555 }
1556
Radek Krejci693262f2019-04-29 15:23:20 +02001557 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001558
1559 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001560 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001561 }
1562 if (llist->flags & LYS_SET_MAX) {
1563 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001564 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001565 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001566 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001567 }
1568 }
1569
1570 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001571 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001572 }
1573
Radek Krejci693262f2019-04-29 15:23:20 +02001574 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001575 ypr_description(ctx, node->dsc, node->exts, NULL);
1576 ypr_reference(ctx, node->ref, node->exts, NULL);
1577
1578 LEVEL--;
1579 ly_print(ctx->out, "%*s}\n", INDENT);
1580}
1581
1582static void
Radek Krejci693262f2019-04-29 15:23:20 +02001583yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1584{
1585 unsigned int u;
1586 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1587
1588 yprc_node_common1(ctx, node, NULL);
1589
1590 yprc_type(ctx, llist->type);
1591 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1592 LY_ARRAY_FOR(llist->musts, u) {
1593 yprc_must(ctx, &llist->musts[u], NULL);
1594 }
1595 LY_ARRAY_FOR(llist->dflts, u) {
1596 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
1597 }
1598
1599 ypr_config(ctx, node->flags, node->exts, NULL);
1600
1601 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1602 if (llist->max) {
1603 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1604 } else {
1605 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1606 }
1607
1608 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1609
1610 ypr_status(ctx, node->flags, node->exts, NULL);
1611 ypr_description(ctx, node->dsc, node->exts, NULL);
1612 ypr_reference(ctx, node->ref, node->exts, NULL);
1613
1614 LEVEL--;
1615 ly_print(ctx->out, "%*s}\n", INDENT);
1616}
1617
1618static void
1619yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001620{
1621 unsigned int u;
1622 int flag = 0;
1623 struct lysp_node *child;
1624 struct lysp_node_list *list = (struct lysp_node_list *)node;
1625
Radek Krejci693262f2019-04-29 15:23:20 +02001626 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001627
1628 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001629 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001630 }
1631 if (list->key) {
1632 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001633 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001634 }
1635 LY_ARRAY_FOR(list->uniques, u) {
1636 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001637 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001638 }
1639
Radek Krejci693262f2019-04-29 15:23:20 +02001640 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001641
1642 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001643 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001644 }
1645 if (list->flags & LYS_SET_MAX) {
1646 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001647 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001648 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001649 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001650 }
1651 }
1652
1653 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001654 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001655 }
1656
Radek Krejci693262f2019-04-29 15:23:20 +02001657 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001658 ypr_description(ctx, node->dsc, node->exts, NULL);
1659 ypr_reference(ctx, node->ref, node->exts, NULL);
1660
1661 LY_ARRAY_FOR(list->typedefs, u) {
1662 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001663 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001664 }
1665
1666 LY_ARRAY_FOR(list->groupings, u) {
1667 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001668 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001669 }
1670
1671 LY_LIST_FOR(list->child, child) {
1672 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001673 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001674 }
1675
1676 LY_ARRAY_FOR(list->actions, u) {
1677 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001678 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001679 }
1680
1681 LY_ARRAY_FOR(list->notifs, u) {
1682 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001683 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001684 }
1685
1686 LEVEL--;
1687 ypr_close(ctx, flag);
1688}
1689
1690static void
Radek Krejci693262f2019-04-29 15:23:20 +02001691yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1692{
1693 unsigned int u, v;
1694 int flag = 0;
1695 struct lysc_node *child;
1696 struct lysc_node_list *list = (struct lysc_node_list *)node;
1697
1698 yprc_node_common1(ctx, node, &flag);
1699
1700 LY_ARRAY_FOR(list->musts, u) {
1701 yprc_must(ctx, &list->musts[u], NULL);
1702 }
1703 if (list->keys) {
1704 ypr_open(ctx->out, &flag);
1705 ly_print(ctx->out, "%*skey \"", INDENT);
1706 LY_ARRAY_FOR(list->keys, u) {
1707 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", list->keys[u]->name);
1708 }
1709 ypr_close(ctx, 0);
1710 }
1711 LY_ARRAY_FOR(list->uniques, u) {
1712 ypr_open(ctx->out, &flag);
1713 ly_print(ctx->out, "%*sunique \"", INDENT);
1714 LY_ARRAY_FOR(list->uniques[u], v) {
1715 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1716 }
1717 ypr_close(ctx, 0);
1718 }
1719
1720 ypr_config(ctx, node->flags, node->exts, NULL);
1721
1722 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1723 if (list->max) {
1724 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1725 } else {
1726 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1727 }
1728
1729 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1730
1731 ypr_status(ctx, node->flags, node->exts, NULL);
1732 ypr_description(ctx, node->dsc, node->exts, NULL);
1733 ypr_reference(ctx, node->ref, node->exts, NULL);
1734
1735 LY_LIST_FOR(list->child, child) {
1736 ypr_open(ctx->out, &flag);
1737 yprc_node(ctx, child);
1738 }
1739
1740 LY_ARRAY_FOR(list->actions, u) {
1741 ypr_open(ctx->out, &flag);
1742 yprc_action(ctx, &list->actions[u]);
1743 }
1744
1745 LY_ARRAY_FOR(list->notifs, u) {
1746 ypr_open(ctx->out, &flag);
1747 yprc_notification(ctx, &list->notifs[u]);
1748 }
1749
1750 LEVEL--;
1751 ypr_close(ctx, flag);
1752}
1753
1754static void
1755yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001756{
1757 unsigned int u;
1758 int flag = 0;
1759
1760 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1761 LEVEL++;
1762
Radek Krejci693262f2019-04-29 15:23:20 +02001763 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1764 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001765
1766 LY_ARRAY_FOR(refine->musts, u) {
1767 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001768 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001769 }
1770
1771 if (refine->presence) {
1772 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001773 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001774 }
1775
1776 LY_ARRAY_FOR(refine->dflts, u) {
1777 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001778 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001779 }
1780
Radek Krejci693262f2019-04-29 15:23:20 +02001781 ypr_config(ctx, refine->flags, refine->exts, &flag);
1782 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001783
1784 if (refine->flags & LYS_SET_MIN) {
1785 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001786 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001787 }
1788 if (refine->flags & LYS_SET_MAX) {
1789 ypr_open(ctx->out, &flag);
1790 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001791 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001792 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001793 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001794 }
1795 }
1796
1797 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1798 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1799
1800 LEVEL--;
1801 ypr_close(ctx, flag);
1802}
1803
1804static void
Radek Krejci693262f2019-04-29 15:23:20 +02001805yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001806{
1807 unsigned int u;
1808 struct lysp_node *child;
1809
1810 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1811 LEVEL++;
1812
Radek Krejci693262f2019-04-29 15:23:20 +02001813 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1814 yprp_when(ctx, aug->when, NULL);
1815 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1816 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001817 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1818 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1819
1820 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001821 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001822 }
1823
1824 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001825 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001826 }
1827
1828 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001829 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830 }
1831
1832 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001833 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001834}
1835
1836
1837static void
Radek Krejci693262f2019-04-29 15:23:20 +02001838yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001839{
1840 unsigned int u;
1841 int flag = 0;
1842 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1843
Radek Krejci693262f2019-04-29 15:23:20 +02001844 yprp_node_common1(ctx, node, &flag);
1845 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001846
1847 LY_ARRAY_FOR(uses->refines, u) {
1848 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001849 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001850 }
1851
1852 LY_ARRAY_FOR(uses->augments, u) {
1853 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001854 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001855 }
1856
1857 LEVEL--;
1858 ypr_close(ctx, flag);
1859}
1860
1861static void
Radek Krejci693262f2019-04-29 15:23:20 +02001862yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001863{
1864 unsigned int u;
1865 int flag = 0;
1866 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1867
Radek Krejci693262f2019-04-29 15:23:20 +02001868 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001869
1870 LY_ARRAY_FOR(any->musts, u) {
1871 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001872 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001873 }
1874
Radek Krejci693262f2019-04-29 15:23:20 +02001875 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001876
1877 LEVEL--;
1878 ypr_close(ctx, flag);
1879}
1880
1881static void
Radek Krejci693262f2019-04-29 15:23:20 +02001882yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001883{
Radek Krejci693262f2019-04-29 15:23:20 +02001884 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001885 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001886 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001887
Radek Krejci693262f2019-04-29 15:23:20 +02001888 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001889
Radek Krejci693262f2019-04-29 15:23:20 +02001890 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001891 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001892 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893 }
1894
Radek Krejci693262f2019-04-29 15:23:20 +02001895 yprc_node_common2(ctx, node, &flag);
1896
Radek Krejcid3ca0632019-04-16 16:54:54 +02001897 LEVEL--;
1898 ypr_close(ctx, flag);
1899}
1900
1901static void
Radek Krejci693262f2019-04-29 15:23:20 +02001902yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001903{
Radek Krejci56cc0872019-04-30 09:22:27 +02001904 LYOUT_CHECK(ctx->out);
1905
Radek Krejcid3ca0632019-04-16 16:54:54 +02001906 switch (node->nodetype) {
1907 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001908 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001909 break;
1910 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001911 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001912 break;
1913 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001914 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001915 break;
1916 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001917 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001918 break;
1919 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001920 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001921 break;
1922 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001923 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001924 break;
1925 case LYS_ANYXML:
1926 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001927 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001928 break;
1929 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001930 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001931 break;
1932 default:
1933 break;
1934 }
1935}
1936
1937static void
Radek Krejci693262f2019-04-29 15:23:20 +02001938yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1939{
Radek Krejci56cc0872019-04-30 09:22:27 +02001940 LYOUT_CHECK(ctx->out);
1941
Radek Krejci693262f2019-04-29 15:23:20 +02001942 switch (node->nodetype) {
1943 case LYS_CONTAINER:
1944 yprc_container(ctx, node);
1945 break;
1946 case LYS_CHOICE:
1947 yprc_choice(ctx, node);
1948 break;
1949 case LYS_LEAF:
1950 yprc_leaf(ctx, node);
1951 break;
1952 case LYS_LEAFLIST:
1953 yprc_leaflist(ctx, node);
1954 break;
1955 case LYS_LIST:
1956 yprc_list(ctx, node);
1957 break;
1958 case LYS_ANYXML:
1959 case LYS_ANYDATA:
1960 yprc_anydata(ctx, node);
1961 break;
1962 default:
1963 break;
1964 }
1965}
1966
1967static void
1968yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001969{
1970 unsigned int u, v;
1971 struct lysp_deviate_add *add;
1972 struct lysp_deviate_rpl *rpl;
1973 struct lysp_deviate_del *del;
1974
1975 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
1976 LEVEL++;
1977
Radek Krejci693262f2019-04-29 15:23:20 +02001978 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001979 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1980 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1981
1982 LY_ARRAY_FOR(deviation->deviates, u) {
1983 ly_print(ctx->out, "%*sdeviate ", INDENT);
1984 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
1985 if (deviation->deviates[u].exts) {
1986 ly_print(ctx->out, "not-supported {\n");
1987 LEVEL++;
1988
Radek Krejci693262f2019-04-29 15:23:20 +02001989 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001990 } else {
1991 ly_print(ctx->out, "not-supported;\n");
1992 continue;
1993 }
1994 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
1995 add = (struct lysp_deviate_add*)&deviation->deviates[u];
1996 ly_print(ctx->out, "add {\n");
1997 LEVEL++;
1998
Radek Krejci693262f2019-04-29 15:23:20 +02001999 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
2000 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002001 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002002 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002003 }
2004 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002005 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002006 }
2007 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002008 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002009 }
Radek Krejci693262f2019-04-29 15:23:20 +02002010 ypr_config(ctx, add->flags, add->exts, NULL);
2011 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002012 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002013 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002014 }
2015 if (add->flags & LYS_SET_MAX) {
2016 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002017 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002018 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002019 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002020 }
2021 }
2022 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
2023 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
2024 ly_print(ctx->out, "replace {\n");
2025 LEVEL++;
2026
Radek Krejci693262f2019-04-29 15:23:20 +02002027 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02002029 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002030 }
Radek Krejci693262f2019-04-29 15:23:20 +02002031 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
2032 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
2033 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
2034 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002035 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002036 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002037 }
2038 if (rpl->flags & LYS_SET_MAX) {
2039 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002040 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002041 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002042 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002043 }
2044 }
2045 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
2046 del = (struct lysp_deviate_del*)&deviation->deviates[u];
2047 ly_print(ctx->out, "delete {\n");
2048 LEVEL++;
2049
Radek Krejci693262f2019-04-29 15:23:20 +02002050 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2051 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002052 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002053 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002054 }
2055 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002056 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002057 }
2058 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002059 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002060 }
2061 }
2062
2063 LEVEL--;
2064 ypr_close(ctx, 1);
2065 }
2066
2067 LEVEL--;
2068 ypr_close(ctx, 1);
2069}
2070
Radek Krejci693262f2019-04-29 15:23:20 +02002071/**
2072 * @brief Minimal print of a schema.
2073 *
2074 * To print
2075 * a) compiled schema when it is not compiled or
2076 * b) parsed when the parsed form was already removed
2077 */
2078static LY_ERR
2079ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2080{
2081 /* module-header-stmts */
2082 if (module->version) {
2083 if (module->version) {
2084 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2085 }
2086 }
2087 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2088 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2089
2090 /* meta-stmts */
2091 if (module->org || module->contact || module->dsc || module->ref) {
2092 ly_print(ctx->out, "\n");
2093 }
2094 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2095 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2096 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2097 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2098
2099 /* revision-stmts */
2100 if (module->revision) {
2101 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2102 }
2103
2104 LEVEL--;
2105 ly_print(ctx->out, "%*s}\n", INDENT);
2106 ly_print_flush(ctx->out);
2107
2108 return LY_SUCCESS;
2109}
2110
Radek Krejcid3ca0632019-04-16 16:54:54 +02002111LY_ERR
2112yang_print_parsed(struct lyout *out, const struct lys_module *module)
2113{
2114 unsigned int u;
2115 struct lysp_node *data;
2116 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002117 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002118
2119 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2120 LEVEL++;
2121
Radek Krejci693262f2019-04-29 15:23:20 +02002122 if (!modp) {
2123 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2124 return ypr_missing_format(ctx, module);
2125 }
2126
Radek Krejcid3ca0632019-04-16 16:54:54 +02002127 /* module-header-stmts */
2128 if (module->version) {
2129 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002130 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 +02002131 }
2132 }
Radek Krejci693262f2019-04-29 15:23:20 +02002133 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2134 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002135
2136 /* linkage-stmts */
2137 LY_ARRAY_FOR(modp->imports, u) {
2138 ly_print(out, "\n%*simport %s {\n", INDENT, modp->imports[u].module->name);
2139 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002140 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2141 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002142 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002143 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002144 }
Radek Krejci693262f2019-04-29 15:23:20 +02002145 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2146 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002147 LEVEL--;
2148 ly_print(out, "%*s}\n", INDENT);
2149 }
2150 LY_ARRAY_FOR(modp->includes, u) {
2151 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
2152 ly_print(out, "\n%*sinclude %s {\n", INDENT, modp->includes[u].submodule->name);
2153 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002154 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002155 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002156 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002157 }
Radek Krejci693262f2019-04-29 15:23:20 +02002158 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2159 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002160 LEVEL--;
2161 ly_print(out, "%*s}\n", INDENT);
2162 } else {
2163 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2164 }
2165 }
2166
2167 /* meta-stmts */
2168 if (module->org || module->contact || module->dsc || module->ref) {
2169 ly_print(out, "\n");
2170 }
Radek Krejci693262f2019-04-29 15:23:20 +02002171 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2172 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2173 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2174 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002175
2176 /* revision-stmts */
2177 if (modp->revs) {
2178 ly_print(out, "\n");
2179 }
2180 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002181 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002182 }
2183 /* body-stmts */
2184 LY_ARRAY_FOR(modp->extensions, u) {
2185 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002186 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002187 }
2188 if (modp->exts) {
2189 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002190 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002191 }
2192
2193 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002194 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002195 }
2196
2197 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002198 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002199 }
2200
2201 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002202 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002203 }
2204
2205 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002206 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002207 }
2208
2209 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002210 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002211 }
2212
2213 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002214 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002215 }
2216
2217 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002218 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002219 }
2220
2221 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002222 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002223 }
2224
2225 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002226 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002227 }
2228
2229 LEVEL--;
2230 ly_print(out, "%*s}\n", INDENT);
2231 ly_print_flush(out);
2232
2233 return LY_SUCCESS;
2234}
2235
2236LY_ERR
2237yang_print_compiled(struct lyout *out, const struct lys_module *module)
2238{
Radek Krejci693262f2019-04-29 15:23:20 +02002239 unsigned int u;
2240 struct lysc_node *data;
2241 struct lysc_module *modc = module->compiled;
2242 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2243
2244 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2245 LEVEL++;
2246
2247 if (!modc) {
2248 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2249 return ypr_missing_format(ctx, module);
2250 }
2251
2252 /* module-header-stmts */
2253 if (module->version) {
2254 if (module->version) {
2255 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2256 }
2257 }
2258 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2259 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2260
2261 /* linkage-stmts */
2262 LY_ARRAY_FOR(modc->imports, u) {
2263 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2264 LEVEL++;
2265 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2266 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2267 if (modc->imports[u].module->revision) {
2268 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2269 }
2270 LEVEL--;
2271 ly_print(out, "%*s}\n", INDENT);
2272 }
2273
2274 /* meta-stmts */
2275 if (module->org || module->contact || module->dsc || module->ref) {
2276 ly_print(out, "\n");
2277 }
2278 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2279 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2280 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2281 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2282
2283 /* revision-stmts */
2284 if (module->revision) {
2285 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2286 }
2287
2288 /* body-stmts */
2289 if (modc->exts) {
2290 ly_print(out, "\n");
2291 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2292 }
2293
2294 LY_ARRAY_FOR(modc->features, u) {
2295 yprc_feature(ctx, &modc->features[u]);
2296 }
2297
2298 LY_ARRAY_FOR(modc->identities, u) {
2299 yprc_identity(ctx, &modc->identities[u]);
2300 }
2301
2302 LY_LIST_FOR(modc->data, data) {
2303 yprc_node(ctx, data);
2304 }
2305
2306 LY_ARRAY_FOR(modc->rpcs, u) {
2307 yprc_action(ctx, &modc->rpcs[u]);
2308 }
2309
2310 LY_ARRAY_FOR(modc->notifs, u) {
2311 yprc_notification(ctx, &modc->notifs[u]);
2312 }
2313
2314 LEVEL--;
2315 ly_print(out, "%*s}\n", INDENT);
2316 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002317
2318 return LY_SUCCESS;
2319}