blob: c042707d5e753ea2fde72b740bb347721940f8fe [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);
Radek Krejci7871ce52019-06-11 16:44:56 +0200827 if (type == LY_TYPE_BITS) {
828 ly_print(ctx->out, "%*sbit %s", INDENT, items[u].name);
829 } else { /* LY_TYPE_ENUM */
830 ly_print(ctx->out, "%*senum \"", INDENT);
831 ypr_encode(ctx->out, items[u].name, -1);
832 ly_print(ctx->out, "\"");
833 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200834 inner_flag = 0;
835 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200836 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
837 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200838 if (items[u].flags & LYS_SET_VALUE) {
839 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200840 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200841 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200842 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200843 }
844 }
Radek Krejci693262f2019-04-29 15:23:20 +0200845 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200846 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
847 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
848 LEVEL--;
849 ypr_close(ctx, inner_flag);
850 }
851}
852
853static void
Radek Krejci693262f2019-04-29 15:23:20 +0200854yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200855{
856 unsigned int u;
857 int flag = 0;
858
859 ly_print(ctx->out, "%*stype %s", INDENT, type->name);
860 LEVEL++;
861
Radek Krejci693262f2019-04-29 15:23:20 +0200862 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200863
Radek Krejci693262f2019-04-29 15:23:20 +0200864 yprp_restr(ctx, type->range, "range", &flag);
865 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200866 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200867 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200868 }
Radek Krejci693262f2019-04-29 15:23:20 +0200869 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
870 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200871
872 if (type->path) {
873 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200874 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200875 }
876 if (type->flags & LYS_SET_REQINST) {
877 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200878 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200879 }
880 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200881 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200882 }
883 LY_ARRAY_FOR(type->bases, u) {
884 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200885 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200886 }
887 LY_ARRAY_FOR(type->types, u) {
888 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200889 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200890 }
891
892 LEVEL--;
893 ypr_close(ctx, flag);
894}
895
896static void
Radek Krejci693262f2019-04-29 15:23:20 +0200897yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
898{
899 unsigned int u;
900 int flag = 0;
901
902 ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
903 LEVEL++;
904
905 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
906 if (type->dflt) {
907 ypr_open(ctx->out, &flag);
908 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, type->dflt, type->exts);
909 }
910
911 switch(type->basetype) {
912 case LY_TYPE_BINARY: {
913 struct lysc_type_bin *bin = (struct lysc_type_bin*)type;
914 yprc_range(ctx, bin->length, type->basetype, &flag);
915 break;
916 }
917 case LY_TYPE_UINT8:
918 case LY_TYPE_UINT16:
919 case LY_TYPE_UINT32:
920 case LY_TYPE_UINT64:
921 case LY_TYPE_INT8:
922 case LY_TYPE_INT16:
923 case LY_TYPE_INT32:
924 case LY_TYPE_INT64: {
925 struct lysc_type_num *num = (struct lysc_type_num*)type;
926 yprc_range(ctx, num->range, type->basetype, &flag);
927 break;
928 }
929 case LY_TYPE_STRING: {
930 struct lysc_type_str *str = (struct lysc_type_str*)type;
931 yprc_range(ctx, str->length, type->basetype, &flag);
932 LY_ARRAY_FOR(str->patterns, u) {
933 yprc_pattern(ctx, str->patterns[u], &flag);
934 }
935 break;
936 }
937 case LY_TYPE_BITS:
938 case LY_TYPE_ENUM: {
939 /* bits and enums structures are compatible */
940 struct lysc_type_bits *bits = (struct lysc_type_bits*)type;
941 LY_ARRAY_FOR(bits->bits, u) {
942 struct lysc_type_bitenum_item *item = &bits->bits[u];
943 int inner_flag = 0;
944
945 ypr_open(ctx->out, &flag);
946 ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
947 ypr_encode(ctx->out, item->name, -1);
948 ly_print(ctx->out, "\"");
949 LEVEL++;
950 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
951 yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag);
952 if (type->basetype == LY_TYPE_BITS) {
953 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
954 } else { /* LY_TYPE_ENUM */
955 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
956 }
957 ypr_status(ctx, item->flags, item->exts, &inner_flag);
958 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
959 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
960 LEVEL--;
961 ypr_close(ctx, inner_flag);
962 }
963 break;
964 }
965 case LY_TYPE_BOOL:
966 case LY_TYPE_EMPTY:
967 /* nothing to do */
968 break;
969 case LY_TYPE_DEC64: {
970 struct lysc_type_dec *dec = (struct lysc_type_dec*)type;
971 ypr_open(ctx->out, &flag);
972 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag);
973 yprc_range(ctx, dec->range, dec->basetype, &flag);
974 break;
975 }
976 case LY_TYPE_IDENT: {
977 struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type;
978 LY_ARRAY_FOR(ident->bases, u) {
979 ypr_open(ctx->out, &flag);
980 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
981 }
982 break;
983 }
984 case LY_TYPE_INST: {
985 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type;
986 ypr_open(ctx->out, &flag);
987 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
988 break;
989 }
990 case LY_TYPE_LEAFREF: {
991 struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type;
992 ypr_open(ctx->out, &flag);
993 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts);
994 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
995 yprc_type(ctx, lr->realtype);
996 break;
997 }
998 case LY_TYPE_UNION: {
999 struct lysc_type_union *un = (struct lysc_type_union*)type;
1000 LY_ARRAY_FOR(un->types, u) {
1001 ypr_open(ctx->out, &flag);
1002 yprc_type(ctx, un->types[u]);
1003 }
1004 break;
1005 }
1006 default:
1007 LOGINT(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +02001008 ctx->out->status = LY_EINT;
Radek Krejci693262f2019-04-29 15:23:20 +02001009 }
1010
1011 LEVEL--;
1012 ypr_close(ctx, flag);
1013}
1014
1015static void
1016yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001017{
Radek Krejci56cc0872019-04-30 09:22:27 +02001018 LYOUT_CHECK(ctx->out);
1019
Radek Krejcid3ca0632019-04-16 16:54:54 +02001020 ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
1021 LEVEL++;
1022
Radek Krejci693262f2019-04-29 15:23:20 +02001023 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001024
Radek Krejci693262f2019-04-29 15:23:20 +02001025 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001026
1027 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +02001028 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001029 }
1030 if (tpdf->dflt) {
Radek Krejci693262f2019-04-29 15:23:20 +02001031 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001032 }
1033
Radek Krejci693262f2019-04-29 15:23:20 +02001034 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001035 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
1036 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
1037
1038 LEVEL--;
1039 ly_print(ctx->out, "%*s}\n", INDENT);
1040}
1041
Radek Krejci693262f2019-04-29 15:23:20 +02001042static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node);
1043static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node);
1044static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001045
1046static void
Radek Krejci693262f2019-04-29 15:23:20 +02001047yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001048{
1049 unsigned int u;
1050 int flag = 0;
1051 struct lysp_node *data;
1052
Radek Krejci56cc0872019-04-30 09:22:27 +02001053 LYOUT_CHECK(ctx->out);
1054
Radek Krejcid3ca0632019-04-16 16:54:54 +02001055 ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
1056 LEVEL++;
1057
Radek Krejci693262f2019-04-29 15:23:20 +02001058 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
1059 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +02001060 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1061 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001062
1063 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001064 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001065 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001066 }
1067
1068 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001069 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001070 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001071 }
1072
1073 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001074 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001075 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001076 }
1077
1078 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001079 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001080 }
1081
1082 LEVEL--;
1083 ypr_close(ctx, flag);
1084}
1085
1086static void
Radek Krejci693262f2019-04-29 15:23:20 +02001087yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001088{
1089 unsigned int u;
1090 struct lysp_node *data;
1091
1092 if (!inout->nodetype) {
1093 /* nodetype not set -> input/output is empty */
1094 return;
1095 }
1096 ypr_open(ctx->out, flag);
1097
1098 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1099 LEVEL++;
1100
Radek Krejci693262f2019-04-29 15:23:20 +02001101 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001102 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001103 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001104 }
1105 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001106 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001107 }
1108 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001109 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001110 }
1111
1112 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001113 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001114 }
1115
1116 LEVEL--;
1117 ypr_close(ctx, 1);
1118}
1119
1120static void
Radek Krejci693262f2019-04-29 15:23:20 +02001121yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1122{
1123 unsigned int u;
1124 struct lysc_node *data;
1125
1126 if (!inout->data) {
1127 /* input/output is empty */
1128 return;
1129 }
1130 ypr_open(ctx->out, flag);
1131
1132 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1133 LEVEL++;
1134
1135 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1136 LY_ARRAY_FOR(inout->musts, u) {
1137 yprc_must(ctx, &inout->musts[u], NULL);
1138 }
1139
1140 LY_LIST_FOR(inout->data, data) {
1141 yprc_node(ctx, data);
1142 }
1143
1144 LEVEL--;
1145 ypr_close(ctx, 1);
1146}
1147
1148static void
1149yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001150{
1151 unsigned int u;
1152 int flag = 0;
1153 struct lysp_node *data;
1154
Radek Krejci56cc0872019-04-30 09:22:27 +02001155 LYOUT_CHECK(ctx->out);
1156
Radek Krejcid3ca0632019-04-16 16:54:54 +02001157 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1158
1159 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001160 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1161 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001162
1163 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001164 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001165 }
Radek Krejci693262f2019-04-29 15:23:20 +02001166 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001167 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1168 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1169
1170 LY_ARRAY_FOR(notif->typedefs, u) {
1171 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001172 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001173 }
1174
1175 LY_ARRAY_FOR(notif->groupings, u) {
1176 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001177 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001178 }
1179
1180 LY_LIST_FOR(notif->data, data) {
1181 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001182 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001183 }
1184
1185 LEVEL--;
1186 ypr_close(ctx, flag);
1187}
1188
1189static void
Radek Krejci693262f2019-04-29 15:23:20 +02001190yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1191{
1192 unsigned int u;
1193 int flag = 0;
1194 struct lysc_node *data;
1195
Radek Krejci56cc0872019-04-30 09:22:27 +02001196 LYOUT_CHECK(ctx->out);
1197
Radek Krejci693262f2019-04-29 15:23:20 +02001198 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1199
1200 LEVEL++;
1201 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1202 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1203
1204 LY_ARRAY_FOR(notif->musts, u) {
1205 yprc_must(ctx, &notif->musts[u], &flag);
1206 }
1207 ypr_status(ctx, notif->flags, notif->exts, &flag);
1208 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1209 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1210
1211 LY_LIST_FOR(notif->data, data) {
1212 ypr_open(ctx->out, &flag);
1213 yprc_node(ctx, data);
1214 }
1215
1216 LEVEL--;
1217 ypr_close(ctx, flag);
1218}
1219
1220static void
1221yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001222{
1223 unsigned int u;
1224 int flag = 0;
1225
Radek Krejci56cc0872019-04-30 09:22:27 +02001226 LYOUT_CHECK(ctx->out);
1227
Radek Krejcid3ca0632019-04-16 16:54:54 +02001228 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1229
1230 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001231 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1232 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1233 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001234 ypr_description(ctx, action->dsc, action->exts, &flag);
1235 ypr_reference(ctx, action->ref, action->exts, &flag);
1236
1237 LY_ARRAY_FOR(action->typedefs, u) {
1238 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001239 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001240 }
1241
1242 LY_ARRAY_FOR(action->groupings, u) {
1243 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001244 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001245 }
1246
Radek Krejci693262f2019-04-29 15:23:20 +02001247 yprp_inout(ctx, &action->input, &flag);
1248 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001249
1250 LEVEL--;
1251 ypr_close(ctx, flag);
1252}
1253
1254static void
Radek Krejci693262f2019-04-29 15:23:20 +02001255yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1256{
1257 int flag = 0;
1258
Radek Krejci56cc0872019-04-30 09:22:27 +02001259 LYOUT_CHECK(ctx->out);
1260
Radek Krejci693262f2019-04-29 15:23:20 +02001261 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1262
1263 LEVEL++;
1264 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1265 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1266 ypr_status(ctx, action->flags, action->exts, &flag);
1267 ypr_description(ctx, action->dsc, action->exts, &flag);
1268 ypr_reference(ctx, action->ref, action->exts, &flag);
1269
1270 yprc_inout(ctx, action, &action->input, &flag);
1271 yprc_inout(ctx, action, &action->output, &flag);
1272
1273 LEVEL--;
1274 ypr_close(ctx, flag);
1275}
1276
1277static void
1278yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001279{
Radek Krejci7871ce52019-06-11 16:44:56 +02001280 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001281 LEVEL++;
1282
Radek Krejci693262f2019-04-29 15:23:20 +02001283 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1284 yprp_when(ctx, node->when, flag);
1285 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286}
1287
1288static void
Radek Krejci693262f2019-04-29 15:23:20 +02001289yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001290{
Radek Krejci693262f2019-04-29 15:23:20 +02001291 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001292
Radek Krejci693262f2019-04-29 15:23:20 +02001293 ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
1294 LEVEL++;
1295
1296 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1297 LY_ARRAY_FOR(node->when, u) {
1298 yprc_when(ctx, node->when[u], flag);
1299 }
1300 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1301}
1302
1303/* macr oto unify the code */
1304#define YPR_NODE_COMMON2 \
1305 ypr_config(ctx, node->flags, node->exts, flag); \
1306 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1307 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1308 } \
1309 ypr_status(ctx, node->flags, node->exts, flag); \
1310 ypr_description(ctx, node->dsc, node->exts, flag); \
1311 ypr_reference(ctx, node->ref, node->exts, flag)
1312
1313static void
1314yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1315{
1316 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001317}
1318
1319static void
Radek Krejci693262f2019-04-29 15:23:20 +02001320yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1321{
1322 YPR_NODE_COMMON2;
1323}
1324
1325#undef YPR_NODE_COMMON2
1326
1327static void
1328yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001329{
1330 unsigned int u;
1331 int flag = 0;
1332 struct lysp_node *child;
1333 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1334
Radek Krejci693262f2019-04-29 15:23:20 +02001335 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001336
1337 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001338 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001339 }
1340 if (cont->presence) {
1341 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001342 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001343 }
1344
Radek Krejci693262f2019-04-29 15:23:20 +02001345 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001346
1347 LY_ARRAY_FOR(cont->typedefs, u) {
1348 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001349 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001350 }
1351
1352 LY_ARRAY_FOR(cont->groupings, u) {
1353 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001354 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001355 }
1356
1357 LY_LIST_FOR(cont->child, child) {
1358 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001359 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001360 }
1361
1362 LY_ARRAY_FOR(cont->actions, u) {
1363 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001364 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001365 }
1366
1367 LY_ARRAY_FOR(cont->notifs, u) {
1368 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001369 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001370 }
1371
1372 LEVEL--;
1373 ypr_close(ctx, flag);
1374}
1375
1376static void
Radek Krejci693262f2019-04-29 15:23:20 +02001377yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1378{
1379 unsigned int u;
1380 int flag = 0;
1381 struct lysc_node *child;
1382 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1383
1384 yprc_node_common1(ctx, node, &flag);
1385
1386 LY_ARRAY_FOR(cont->musts, u) {
1387 yprc_must(ctx, &cont->musts[u], &flag);
1388 }
1389 if (cont->flags & LYS_PRESENCE) {
1390 ypr_open(ctx->out, &flag);
1391 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1392 }
1393
1394 yprc_node_common2(ctx, node, &flag);
1395
1396 LY_LIST_FOR(cont->child, child) {
1397 ypr_open(ctx->out, &flag);
1398 yprc_node(ctx, child);
1399 }
1400
1401 LY_ARRAY_FOR(cont->actions, u) {
1402 ypr_open(ctx->out, &flag);
1403 yprc_action(ctx, &cont->actions[u]);
1404 }
1405
1406 LY_ARRAY_FOR(cont->notifs, u) {
1407 ypr_open(ctx->out, &flag);
1408 yprc_notification(ctx, &cont->notifs[u]);
1409 }
1410
1411 LEVEL--;
1412 ypr_close(ctx, flag);
1413}
1414
1415static void
1416yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1417{
1418 int flag = 0;
1419 struct lysp_node *child;
1420 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1421
1422 yprp_node_common1(ctx, node, &flag);
1423 yprp_node_common2(ctx, node, &flag);
1424
1425 LY_LIST_FOR(cas->child, child) {
1426 ypr_open(ctx->out, &flag);
1427 yprp_node(ctx, child);
1428 }
1429
1430 LEVEL--;
1431 ypr_close(ctx, flag);
1432}
1433
1434static void
1435yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1436{
1437 int flag = 0;
1438 struct lysc_node *child;
1439
1440 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1441 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1442
1443 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1444 ypr_open(ctx->out, &flag);
1445 yprc_node(ctx, child);
1446 }
1447
1448 LEVEL--;
1449 ypr_close(ctx, flag);
1450}
1451
1452static void
1453yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001454{
1455 int flag = 0;
1456 struct lysp_node *child;
1457 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1458
Radek Krejci693262f2019-04-29 15:23:20 +02001459 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001460
1461 if (choice->dflt) {
1462 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001463 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001464 }
1465
Radek Krejci693262f2019-04-29 15:23:20 +02001466 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001467
1468 LY_LIST_FOR(choice->child, child) {
1469 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001470 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001471 }
1472
1473 LEVEL--;
1474 ypr_close(ctx, flag);
1475}
1476
1477static void
Radek Krejci693262f2019-04-29 15:23:20 +02001478yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1479{
1480 int flag = 0;
1481 struct lysc_node_case *cs;
1482 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1483
1484 yprc_node_common1(ctx, node, &flag);
1485
1486 if (choice->dflt) {
1487 ypr_open(ctx->out, &flag);
1488 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1489 }
1490
1491 yprc_node_common2(ctx, node, &flag);
1492
1493 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1494 ypr_open(ctx->out, &flag);
1495 yprc_case(ctx, cs);
1496 }
1497
1498 LEVEL--;
1499 ypr_close(ctx, flag);
1500}
1501
1502static void
1503yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001504{
1505 unsigned int u;
1506 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1507
Radek Krejci693262f2019-04-29 15:23:20 +02001508 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001509
Radek Krejci693262f2019-04-29 15:23:20 +02001510 yprp_type(ctx, &leaf->type);
1511 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001512 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001513 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001514 }
Radek Krejci693262f2019-04-29 15:23:20 +02001515 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001516
Radek Krejci693262f2019-04-29 15:23:20 +02001517 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001518
1519 LEVEL--;
1520 ly_print(ctx->out, "%*s}\n", INDENT);
1521}
1522
1523static void
Radek Krejci693262f2019-04-29 15:23:20 +02001524yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1525{
1526 unsigned int u;
1527 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1528
1529 yprc_node_common1(ctx, node, NULL);
1530
1531 yprc_type(ctx, leaf->type);
1532 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1533 LY_ARRAY_FOR(leaf->musts, u) {
1534 yprc_must(ctx, &leaf->musts[u], NULL);
1535 }
1536 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
1537
1538 yprc_node_common2(ctx, node, NULL);
1539
1540 LEVEL--;
1541 ly_print(ctx->out, "%*s}\n", INDENT);
1542}
1543
1544static void
1545yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001546{
1547 unsigned int u;
1548 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1549
Radek Krejci693262f2019-04-29 15:23:20 +02001550 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001551
Radek Krejci693262f2019-04-29 15:23:20 +02001552 yprp_type(ctx, &llist->type);
1553 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001554 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001555 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001556 }
1557 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001558 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001559 }
1560
Radek Krejci693262f2019-04-29 15:23:20 +02001561 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001562
1563 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001564 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001565 }
1566 if (llist->flags & LYS_SET_MAX) {
1567 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001568 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001569 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001570 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001571 }
1572 }
1573
1574 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001575 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001576 }
1577
Radek Krejci693262f2019-04-29 15:23:20 +02001578 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001579 ypr_description(ctx, node->dsc, node->exts, NULL);
1580 ypr_reference(ctx, node->ref, node->exts, NULL);
1581
1582 LEVEL--;
1583 ly_print(ctx->out, "%*s}\n", INDENT);
1584}
1585
1586static void
Radek Krejci693262f2019-04-29 15:23:20 +02001587yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1588{
1589 unsigned int u;
1590 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1591
1592 yprc_node_common1(ctx, node, NULL);
1593
1594 yprc_type(ctx, llist->type);
1595 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1596 LY_ARRAY_FOR(llist->musts, u) {
1597 yprc_must(ctx, &llist->musts[u], NULL);
1598 }
1599 LY_ARRAY_FOR(llist->dflts, u) {
1600 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
1601 }
1602
1603 ypr_config(ctx, node->flags, node->exts, NULL);
1604
1605 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1606 if (llist->max) {
1607 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1608 } else {
1609 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1610 }
1611
1612 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1613
1614 ypr_status(ctx, node->flags, node->exts, NULL);
1615 ypr_description(ctx, node->dsc, node->exts, NULL);
1616 ypr_reference(ctx, node->ref, node->exts, NULL);
1617
1618 LEVEL--;
1619 ly_print(ctx->out, "%*s}\n", INDENT);
1620}
1621
1622static void
1623yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001624{
1625 unsigned int u;
1626 int flag = 0;
1627 struct lysp_node *child;
1628 struct lysp_node_list *list = (struct lysp_node_list *)node;
1629
Radek Krejci693262f2019-04-29 15:23:20 +02001630 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001631
1632 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001633 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001634 }
1635 if (list->key) {
1636 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001637 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001638 }
1639 LY_ARRAY_FOR(list->uniques, u) {
1640 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001641 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001642 }
1643
Radek Krejci693262f2019-04-29 15:23:20 +02001644 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001645
1646 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001647 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001648 }
1649 if (list->flags & LYS_SET_MAX) {
1650 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001651 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001652 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001653 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001654 }
1655 }
1656
1657 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001658 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001659 }
1660
Radek Krejci693262f2019-04-29 15:23:20 +02001661 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001662 ypr_description(ctx, node->dsc, node->exts, NULL);
1663 ypr_reference(ctx, node->ref, node->exts, NULL);
1664
1665 LY_ARRAY_FOR(list->typedefs, u) {
1666 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001667 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001668 }
1669
1670 LY_ARRAY_FOR(list->groupings, u) {
1671 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001672 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001673 }
1674
1675 LY_LIST_FOR(list->child, child) {
1676 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001677 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001678 }
1679
1680 LY_ARRAY_FOR(list->actions, u) {
1681 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001682 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001683 }
1684
1685 LY_ARRAY_FOR(list->notifs, u) {
1686 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001687 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001688 }
1689
1690 LEVEL--;
1691 ypr_close(ctx, flag);
1692}
1693
1694static void
Radek Krejci693262f2019-04-29 15:23:20 +02001695yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1696{
1697 unsigned int u, v;
1698 int flag = 0;
1699 struct lysc_node *child;
1700 struct lysc_node_list *list = (struct lysc_node_list *)node;
1701
1702 yprc_node_common1(ctx, node, &flag);
1703
1704 LY_ARRAY_FOR(list->musts, u) {
1705 yprc_must(ctx, &list->musts[u], NULL);
1706 }
1707 if (list->keys) {
1708 ypr_open(ctx->out, &flag);
1709 ly_print(ctx->out, "%*skey \"", INDENT);
1710 LY_ARRAY_FOR(list->keys, u) {
1711 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", list->keys[u]->name);
1712 }
1713 ypr_close(ctx, 0);
1714 }
1715 LY_ARRAY_FOR(list->uniques, u) {
1716 ypr_open(ctx->out, &flag);
1717 ly_print(ctx->out, "%*sunique \"", INDENT);
1718 LY_ARRAY_FOR(list->uniques[u], v) {
1719 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1720 }
1721 ypr_close(ctx, 0);
1722 }
1723
1724 ypr_config(ctx, node->flags, node->exts, NULL);
1725
1726 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1727 if (list->max) {
1728 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1729 } else {
1730 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1731 }
1732
1733 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1734
1735 ypr_status(ctx, node->flags, node->exts, NULL);
1736 ypr_description(ctx, node->dsc, node->exts, NULL);
1737 ypr_reference(ctx, node->ref, node->exts, NULL);
1738
1739 LY_LIST_FOR(list->child, child) {
1740 ypr_open(ctx->out, &flag);
1741 yprc_node(ctx, child);
1742 }
1743
1744 LY_ARRAY_FOR(list->actions, u) {
1745 ypr_open(ctx->out, &flag);
1746 yprc_action(ctx, &list->actions[u]);
1747 }
1748
1749 LY_ARRAY_FOR(list->notifs, u) {
1750 ypr_open(ctx->out, &flag);
1751 yprc_notification(ctx, &list->notifs[u]);
1752 }
1753
1754 LEVEL--;
1755 ypr_close(ctx, flag);
1756}
1757
1758static void
1759yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001760{
1761 unsigned int u;
1762 int flag = 0;
1763
1764 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1765 LEVEL++;
1766
Radek Krejci693262f2019-04-29 15:23:20 +02001767 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1768 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001769
1770 LY_ARRAY_FOR(refine->musts, u) {
1771 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001772 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001773 }
1774
1775 if (refine->presence) {
1776 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001777 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001778 }
1779
1780 LY_ARRAY_FOR(refine->dflts, u) {
1781 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001782 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001783 }
1784
Radek Krejci693262f2019-04-29 15:23:20 +02001785 ypr_config(ctx, refine->flags, refine->exts, &flag);
1786 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001787
1788 if (refine->flags & LYS_SET_MIN) {
1789 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001790 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001791 }
1792 if (refine->flags & LYS_SET_MAX) {
1793 ypr_open(ctx->out, &flag);
1794 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001795 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001796 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001797 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001798 }
1799 }
1800
1801 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1802 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1803
1804 LEVEL--;
1805 ypr_close(ctx, flag);
1806}
1807
1808static void
Radek Krejci693262f2019-04-29 15:23:20 +02001809yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001810{
1811 unsigned int u;
1812 struct lysp_node *child;
1813
1814 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1815 LEVEL++;
1816
Radek Krejci693262f2019-04-29 15:23:20 +02001817 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1818 yprp_when(ctx, aug->when, NULL);
1819 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1820 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001821 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1822 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1823
1824 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001825 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001826 }
1827
1828 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001829 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830 }
1831
1832 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001833 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001834 }
1835
1836 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001837 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001838}
1839
1840
1841static void
Radek Krejci693262f2019-04-29 15:23:20 +02001842yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001843{
1844 unsigned int u;
1845 int flag = 0;
1846 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1847
Radek Krejci693262f2019-04-29 15:23:20 +02001848 yprp_node_common1(ctx, node, &flag);
1849 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001850
1851 LY_ARRAY_FOR(uses->refines, u) {
1852 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001853 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001854 }
1855
1856 LY_ARRAY_FOR(uses->augments, u) {
1857 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001858 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001859 }
1860
1861 LEVEL--;
1862 ypr_close(ctx, flag);
1863}
1864
1865static void
Radek Krejci693262f2019-04-29 15:23:20 +02001866yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001867{
1868 unsigned int u;
1869 int flag = 0;
1870 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1871
Radek Krejci693262f2019-04-29 15:23:20 +02001872 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001873
1874 LY_ARRAY_FOR(any->musts, u) {
1875 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001876 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001877 }
1878
Radek Krejci693262f2019-04-29 15:23:20 +02001879 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001880
1881 LEVEL--;
1882 ypr_close(ctx, flag);
1883}
1884
1885static void
Radek Krejci693262f2019-04-29 15:23:20 +02001886yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001887{
Radek Krejci693262f2019-04-29 15:23:20 +02001888 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001889 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001890 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001891
Radek Krejci693262f2019-04-29 15:23:20 +02001892 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893
Radek Krejci693262f2019-04-29 15:23:20 +02001894 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001895 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001896 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001897 }
1898
Radek Krejci693262f2019-04-29 15:23:20 +02001899 yprc_node_common2(ctx, node, &flag);
1900
Radek Krejcid3ca0632019-04-16 16:54:54 +02001901 LEVEL--;
1902 ypr_close(ctx, flag);
1903}
1904
1905static void
Radek Krejci693262f2019-04-29 15:23:20 +02001906yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001907{
Radek Krejci56cc0872019-04-30 09:22:27 +02001908 LYOUT_CHECK(ctx->out);
1909
Radek Krejcid3ca0632019-04-16 16:54:54 +02001910 switch (node->nodetype) {
1911 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001912 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001913 break;
1914 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001915 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001916 break;
1917 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001918 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001919 break;
1920 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001921 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001922 break;
1923 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001924 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001925 break;
1926 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001927 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001928 break;
1929 case LYS_ANYXML:
1930 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001931 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001932 break;
1933 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001934 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001935 break;
1936 default:
1937 break;
1938 }
1939}
1940
1941static void
Radek Krejci693262f2019-04-29 15:23:20 +02001942yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1943{
Radek Krejci56cc0872019-04-30 09:22:27 +02001944 LYOUT_CHECK(ctx->out);
1945
Radek Krejci693262f2019-04-29 15:23:20 +02001946 switch (node->nodetype) {
1947 case LYS_CONTAINER:
1948 yprc_container(ctx, node);
1949 break;
1950 case LYS_CHOICE:
1951 yprc_choice(ctx, node);
1952 break;
1953 case LYS_LEAF:
1954 yprc_leaf(ctx, node);
1955 break;
1956 case LYS_LEAFLIST:
1957 yprc_leaflist(ctx, node);
1958 break;
1959 case LYS_LIST:
1960 yprc_list(ctx, node);
1961 break;
1962 case LYS_ANYXML:
1963 case LYS_ANYDATA:
1964 yprc_anydata(ctx, node);
1965 break;
1966 default:
1967 break;
1968 }
1969}
1970
1971static void
1972yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001973{
1974 unsigned int u, v;
1975 struct lysp_deviate_add *add;
1976 struct lysp_deviate_rpl *rpl;
1977 struct lysp_deviate_del *del;
1978
1979 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
1980 LEVEL++;
1981
Radek Krejci693262f2019-04-29 15:23:20 +02001982 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001983 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1984 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1985
1986 LY_ARRAY_FOR(deviation->deviates, u) {
1987 ly_print(ctx->out, "%*sdeviate ", INDENT);
1988 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
1989 if (deviation->deviates[u].exts) {
1990 ly_print(ctx->out, "not-supported {\n");
1991 LEVEL++;
1992
Radek Krejci693262f2019-04-29 15:23:20 +02001993 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001994 } else {
1995 ly_print(ctx->out, "not-supported;\n");
1996 continue;
1997 }
1998 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
1999 add = (struct lysp_deviate_add*)&deviation->deviates[u];
2000 ly_print(ctx->out, "add {\n");
2001 LEVEL++;
2002
Radek Krejci693262f2019-04-29 15:23:20 +02002003 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
2004 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002005 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002006 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002007 }
2008 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002009 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002010 }
2011 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002012 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002013 }
Radek Krejci693262f2019-04-29 15:23:20 +02002014 ypr_config(ctx, add->flags, add->exts, NULL);
2015 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002016 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002017 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002018 }
2019 if (add->flags & LYS_SET_MAX) {
2020 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002021 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002022 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002023 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002024 }
2025 }
2026 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
2027 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
2028 ly_print(ctx->out, "replace {\n");
2029 LEVEL++;
2030
Radek Krejci693262f2019-04-29 15:23:20 +02002031 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002032 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02002033 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002034 }
Radek Krejci693262f2019-04-29 15:23:20 +02002035 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
2036 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
2037 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
2038 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002039 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002040 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002041 }
2042 if (rpl->flags & LYS_SET_MAX) {
2043 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002044 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002046 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002047 }
2048 }
2049 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
2050 del = (struct lysp_deviate_del*)&deviation->deviates[u];
2051 ly_print(ctx->out, "delete {\n");
2052 LEVEL++;
2053
Radek Krejci693262f2019-04-29 15:23:20 +02002054 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2055 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002056 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002057 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002058 }
2059 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002060 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002061 }
2062 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002063 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002064 }
2065 }
2066
2067 LEVEL--;
2068 ypr_close(ctx, 1);
2069 }
2070
2071 LEVEL--;
2072 ypr_close(ctx, 1);
2073}
2074
Radek Krejci693262f2019-04-29 15:23:20 +02002075/**
2076 * @brief Minimal print of a schema.
2077 *
2078 * To print
2079 * a) compiled schema when it is not compiled or
2080 * b) parsed when the parsed form was already removed
2081 */
2082static LY_ERR
2083ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2084{
2085 /* module-header-stmts */
2086 if (module->version) {
2087 if (module->version) {
2088 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2089 }
2090 }
2091 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2092 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2093
2094 /* meta-stmts */
2095 if (module->org || module->contact || module->dsc || module->ref) {
2096 ly_print(ctx->out, "\n");
2097 }
2098 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2099 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2100 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2101 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2102
2103 /* revision-stmts */
2104 if (module->revision) {
2105 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2106 }
2107
2108 LEVEL--;
2109 ly_print(ctx->out, "%*s}\n", INDENT);
2110 ly_print_flush(ctx->out);
2111
2112 return LY_SUCCESS;
2113}
2114
Radek Krejcid3ca0632019-04-16 16:54:54 +02002115LY_ERR
2116yang_print_parsed(struct lyout *out, const struct lys_module *module)
2117{
2118 unsigned int u;
2119 struct lysp_node *data;
2120 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002121 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002122
2123 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2124 LEVEL++;
2125
Radek Krejci693262f2019-04-29 15:23:20 +02002126 if (!modp) {
2127 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2128 return ypr_missing_format(ctx, module);
2129 }
2130
Radek Krejcid3ca0632019-04-16 16:54:54 +02002131 /* module-header-stmts */
2132 if (module->version) {
2133 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002134 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 +02002135 }
2136 }
Radek Krejci693262f2019-04-29 15:23:20 +02002137 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2138 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002139
2140 /* linkage-stmts */
2141 LY_ARRAY_FOR(modp->imports, u) {
Radek Krejci7871ce52019-06-11 16:44:56 +02002142 ly_print(out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].module->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002143 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002144 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2145 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002146 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002147 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002148 }
Radek Krejci693262f2019-04-29 15:23:20 +02002149 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2150 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002151 LEVEL--;
2152 ly_print(out, "%*s}\n", INDENT);
2153 }
2154 LY_ARRAY_FOR(modp->includes, u) {
2155 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 +02002156 ly_print(out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].submodule->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002157 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002158 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002159 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002160 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002161 }
Radek Krejci693262f2019-04-29 15:23:20 +02002162 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2163 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002164 LEVEL--;
2165 ly_print(out, "%*s}\n", INDENT);
2166 } else {
2167 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2168 }
2169 }
2170
2171 /* meta-stmts */
2172 if (module->org || module->contact || module->dsc || module->ref) {
2173 ly_print(out, "\n");
2174 }
Radek Krejci693262f2019-04-29 15:23:20 +02002175 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2176 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2177 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2178 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002179
2180 /* revision-stmts */
2181 if (modp->revs) {
2182 ly_print(out, "\n");
2183 }
2184 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002185 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002186 }
2187 /* body-stmts */
2188 LY_ARRAY_FOR(modp->extensions, u) {
2189 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002190 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002191 }
2192 if (modp->exts) {
2193 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002194 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002195 }
2196
2197 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002198 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002199 }
2200
2201 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002202 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002203 }
2204
2205 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002206 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002207 }
2208
2209 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002210 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002211 }
2212
2213 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002214 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002215 }
2216
2217 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002218 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002219 }
2220
2221 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002222 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002223 }
2224
2225 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002226 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002227 }
2228
2229 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002230 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002231 }
2232
2233 LEVEL--;
2234 ly_print(out, "%*s}\n", INDENT);
2235 ly_print_flush(out);
2236
2237 return LY_SUCCESS;
2238}
2239
2240LY_ERR
2241yang_print_compiled(struct lyout *out, const struct lys_module *module)
2242{
Radek Krejci693262f2019-04-29 15:23:20 +02002243 unsigned int u;
2244 struct lysc_node *data;
2245 struct lysc_module *modc = module->compiled;
2246 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2247
2248 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2249 LEVEL++;
2250
2251 if (!modc) {
2252 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2253 return ypr_missing_format(ctx, module);
2254 }
2255
2256 /* module-header-stmts */
2257 if (module->version) {
2258 if (module->version) {
2259 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2260 }
2261 }
2262 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2263 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2264
2265 /* linkage-stmts */
2266 LY_ARRAY_FOR(modc->imports, u) {
2267 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2268 LEVEL++;
2269 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2270 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2271 if (modc->imports[u].module->revision) {
2272 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2273 }
2274 LEVEL--;
2275 ly_print(out, "%*s}\n", INDENT);
2276 }
2277
2278 /* meta-stmts */
2279 if (module->org || module->contact || module->dsc || module->ref) {
2280 ly_print(out, "\n");
2281 }
2282 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2283 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2284 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2285 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2286
2287 /* revision-stmts */
2288 if (module->revision) {
2289 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2290 }
2291
2292 /* body-stmts */
2293 if (modc->exts) {
2294 ly_print(out, "\n");
2295 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2296 }
2297
2298 LY_ARRAY_FOR(modc->features, u) {
2299 yprc_feature(ctx, &modc->features[u]);
2300 }
2301
2302 LY_ARRAY_FOR(modc->identities, u) {
2303 yprc_identity(ctx, &modc->identities[u]);
2304 }
2305
2306 LY_LIST_FOR(modc->data, data) {
2307 yprc_node(ctx, data);
2308 }
2309
2310 LY_ARRAY_FOR(modc->rpcs, u) {
2311 yprc_action(ctx, &modc->rpcs[u]);
2312 }
2313
2314 LY_ARRAY_FOR(modc->notifs, u) {
2315 yprc_notification(ctx, &modc->notifs[u]);
2316 }
2317
2318 LEVEL--;
2319 ly_print(out, "%*s}\n", INDENT);
2320 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002321
2322 return LY_SUCCESS;
2323}