blob: 8736639e4177b56e4c717bc5bd6c572493729dd6 [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 Krejcia1911222019-07-22 17:24:50 +020029#include "plugins_types.h"
Radek Krejci693262f2019-04-29 15:23:20 +020030#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020031
Radek Krejcie7b95092019-05-15 11:03:07 +020032/**
33 * @brief Types of the YANG printers
34 */
Radek Krejci693262f2019-04-29 15:23:20 +020035enum schema_type {
Radek Krejcie7b95092019-05-15 11:03:07 +020036 YPR_PARSED, /**< YANG printer of the parsed schema */
37 YPR_COMPILED /**< YANG printer of the compiled schema */
Radek Krejci693262f2019-04-29 15:23:20 +020038};
39
Radek Krejcie7b95092019-05-15 11:03:07 +020040/**
41 * @brief YANG printer context.
42 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020043struct ypr_ctx {
Radek Krejcie7b95092019-05-15 11:03:07 +020044 struct lyout *out; /**< output specification */
45 unsigned int level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
46 const struct lys_module *module; /**< schema to print */
47 enum schema_type schema; /**< type of the schema to print */
Radek Krejcid3ca0632019-04-16 16:54:54 +020048};
49
Radek Krejcie7b95092019-05-15 11:03:07 +020050#define LEVEL ctx->level /**< current level */
51#define INDENT (LEVEL)*2,"" /**< indentation parameters for printer functions */
52
53/**
54 * @brief Print the given text as content of a double quoted YANG string,
55 * including encoding characters that have special meanings. The quotation marks
56 * are not printed.
57 *
58 * Follows RFC 7950, section 6.1.3.
59 *
60 * @param[in] out Output specification.
61 * @param[in] text String to be printed.
62 * @param[in] len Length of the string from @p text to be printed. In case of 0,
63 * the @p text is printed completely as a NULL-terminated string.
64 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020065static void
66ypr_encode(struct lyout *out, const char *text, int len)
67{
68 int i, start_len;
69 const char *start;
70 char special = 0;
71
72 if (!len) {
73 return;
74 }
75
76 if (len < 0) {
77 len = strlen(text);
78 }
79
80 start = text;
81 start_len = 0;
82 for (i = 0; i < len; ++i) {
83 switch (text[i]) {
84 case '\n':
85 case '\t':
86 case '\"':
87 case '\\':
88 special = text[i];
89 break;
90 default:
91 ++start_len;
92 break;
93 }
94
95 if (special) {
96 ly_write(out, start, start_len);
97 switch (special) {
98 case '\n':
99 ly_write(out, "\\n", 2);
100 break;
101 case '\t':
102 ly_write(out, "\\t", 2);
103 break;
104 case '\"':
105 ly_write(out, "\\\"", 2);
106 break;
107 case '\\':
108 ly_write(out, "\\\\", 2);
109 break;
110 }
111
112 start += start_len + 1;
113 start_len = 0;
114
115 special = 0;
116 }
117 }
118
119 ly_write(out, start, start_len);
120}
121
122static void
123ypr_open(struct lyout *out, int *flag)
124{
125 if (flag && !*flag) {
126 *flag = 1;
127 ly_print(out, " {\n");
128 }
129}
130
131static void
132ypr_close(struct ypr_ctx *ctx, int flag)
133{
134 if (flag) {
135 ly_print(ctx->out, "%*s}\n", INDENT);
136 } else {
137 ly_print(ctx->out, ";\n");
138 }
139}
140
141static void
142ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, int singleline, int closed)
143{
144 const char *s, *t;
145
146 if (singleline) {
147 ly_print(ctx->out, "%*s%s \"", INDENT, name);
148 } else {
149 ly_print(ctx->out, "%*s%s\n", INDENT, name);
150 LEVEL++;
151
152 ly_print(ctx->out, "%*s\"", INDENT);
153 }
154 t = text;
155 while ((s = strchr(t, '\n'))) {
156 ypr_encode(ctx->out, t, s - t);
157 ly_print(ctx->out, "\n");
158 t = s + 1;
159 if (*t != '\n') {
160 ly_print(ctx->out, "%*s ", INDENT);
161 }
162 }
163
164 ypr_encode(ctx->out, t, strlen(t));
165 if (closed) {
166 ly_print(ctx->out, "\";\n");
167 } else {
168 ly_print(ctx->out, "\"");
169 }
170 if (!singleline) {
171 LEVEL--;
172 }
173}
174
175static void
Radek Krejci693262f2019-04-29 15:23:20 +0200176yprp_stmt(struct ypr_ctx *ctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200177{
178 struct lysp_stmt *childstmt;
179 const char *s, *t;
180
181 if (stmt->arg) {
182 if (stmt->flags) {
183 ly_print(ctx->out, "%*s%s\n", INDENT, stmt->stmt);
184 LEVEL++;
185 ly_print(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
186 t = stmt->arg;
187 while ((s = strchr(t, '\n'))) {
188 ypr_encode(ctx->out, t, s - t);
189 ly_print(ctx->out, "\n");
190 t = s + 1;
191 if (*t != '\n') {
192 ly_print(ctx->out, "%*s ", INDENT);
193 }
194 }
195 LEVEL--;
196 ypr_encode(ctx->out, t, strlen(t));
197 ly_print(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
198 } else {
199 ly_print(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
200 }
201 } else {
202 ly_print(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
203 }
204
205 if (stmt->child) {
206 LEVEL++;
207 LY_LIST_FOR(stmt->child, childstmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200208 yprp_stmt(ctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200209 }
210 LEVEL--;
211 ly_print(ctx->out, "%*s}\n", INDENT);
212 }
213}
214
215/**
216 * @param[in] count Number of extensions to print, 0 to print them all.
217 */
218static void
Radek Krejci693262f2019-04-29 15:23:20 +0200219yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
Radek Krejcid3ca0632019-04-16 16:54:54 +0200220 struct lysp_ext_instance *ext, int *flag, unsigned int count)
221{
222 unsigned int u;
223 struct lysp_stmt *stmt;
224
225 if (!count && ext) {
226 count = LY_ARRAY_SIZE(ext);
227 }
228 LY_ARRAY_FOR(ext, u) {
229 if (!count) {
230 break;
231 }
232 if (ext->insubstmt == substmt && ext->insubstmt_index == substmt_index) {
233 ypr_open(ctx->out, flag);
234 if (ext[u].argument) {
235 ly_print(ctx->out, "%*s%s %s%s", INDENT, ext[u].name, ext[u].argument, ext[u].child ? " {\n" : ";\n");
236 } else {
237 ly_print(ctx->out, "%*s%s%s", INDENT, ext[u].name, ext[u].child ? " {\n" : ";\n");
238 }
239
240 if (ext[u].child) {
241 LEVEL++;
242 LY_LIST_FOR(ext[u].child, stmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200243 yprp_stmt(ctx, stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200244 }
245 LEVEL--;
246 ly_print(ctx->out, "%*s}\n", INDENT);
247 }
248 }
249 count--;
250 }
251}
252
Radek Krejci693262f2019-04-29 15:23:20 +0200253/**
254 * @param[in] count Number of extensions to print, 0 to print them all.
255 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200256static void
Radek Krejci693262f2019-04-29 15:23:20 +0200257yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
258 struct lysc_ext_instance *ext, int *flag, unsigned int count)
259{
260 unsigned int u;
261
262 if (!count && ext) {
263 count = LY_ARRAY_SIZE(ext);
264 }
265 LY_ARRAY_FOR(ext, u) {
266 if (!count) {
267 break;
268 }
269 /* TODO compiled extensions */
270 (void) ctx;
271 (void) substmt;
272 (void) substmt_index;
273 (void) flag;
274
275 count--;
276 }
277}
278
279static void
280ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200281{
282 unsigned int u;
283 int extflag = 0;
284
285 if (!text) {
286 /* nothing to print */
287 return;
288 }
289
290 if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) {
291 ly_print(ctx->out, "%*s%s %s", INDENT, ext_substmt_info[substmt].name, text);
292 } else {
293 ypr_text(ctx, ext_substmt_info[substmt].name, text,
294 (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, 0);
295 }
296
297 LEVEL++;
298 LY_ARRAY_FOR(ext, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200299 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 +0200300 continue;
301 }
Radek Krejci693262f2019-04-29 15:23:20 +0200302 if (ctx->schema == YPR_PARSED) {
303 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance*)ext)[u], &extflag, 1);
304 } else {
305 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance*)ext)[u], &extflag, 1);
306 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200307 }
308 LEVEL--;
309 ypr_close(ctx, extflag);
310}
311
312static void
Radek Krejci693262f2019-04-29 15:23:20 +0200313ypr_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 +0200314{
315 char *str;
316
317 if (asprintf(&str, "%u", attr_value) == -1) {
318 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200319 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200320 return;
321 }
322 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200323 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200324 free(str);
325}
326
327static void
Radek Krejci693262f2019-04-29 15:23:20 +0200328ypr_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 +0200329{
330 char *str;
331
332 if (asprintf(&str, "%d", attr_value) == -1) {
333 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200334 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200335 return;
336 }
337 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200338 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200339 free(str);
340}
341
342static void
Radek Krejci693262f2019-04-29 15:23:20 +0200343yprp_revision(struct ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200344{
345 if (rev->dsc || rev->ref || rev->exts) {
346 ly_print(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
347 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200348 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0);
349 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts);
350 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200351 LEVEL--;
352 ly_print(ctx->out, "%*s}\n", INDENT);
353 } else {
354 ly_print(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
355 }
356}
357
358static void
Radek Krejci693262f2019-04-29 15:23:20 +0200359ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200360{
361 if (flags & LYS_MAND_MASK) {
362 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200363 ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200364 }
365}
366
367static void
Radek Krejci693262f2019-04-29 15:23:20 +0200368ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200369{
370 if (flags & LYS_CONFIG_MASK) {
371 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200372 ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200373 }
374}
375
376static void
Radek Krejci693262f2019-04-29 15:23:20 +0200377ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200378{
379 const char *status = NULL;
380
381 if (flags & LYS_STATUS_CURR) {
382 ypr_open(ctx->out, flag);
383 status = "current";
384 } else if (flags & LYS_STATUS_DEPRC) {
385 ypr_open(ctx->out, flag);
386 status = "deprecated";
387 } else if (flags & LYS_STATUS_OBSLT) {
388 ypr_open(ctx->out, flag);
389 status = "obsolete";
390 }
Radek Krejci693262f2019-04-29 15:23:20 +0200391
392 ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200393}
394
395static void
Radek Krejci693262f2019-04-29 15:23:20 +0200396ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200397{
398 if (dsc) {
399 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200400 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200401 }
402}
403
404static void
Radek Krejci693262f2019-04-29 15:23:20 +0200405ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200406{
407 if (ref) {
408 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200409 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200410 }
411}
412
413static void
Radek Krejci693262f2019-04-29 15:23:20 +0200414yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200415{
416 unsigned int u;
417 int extflag;
418
419 LY_ARRAY_FOR(iff, u) {
420 ypr_open(ctx->out, flag);
421 extflag = 0;
422
423 ly_print(ctx->out, "%*sif-feature \"%s\"", INDENT, iff[u]);
424
425 /* extensions */
426 LEVEL++;
427 LY_ARRAY_FOR(exts, u) {
428 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
429 continue;
430 }
Radek Krejci693262f2019-04-29 15:23:20 +0200431 yprp_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200432 }
433 LEVEL--;
434 ypr_close(ctx, extflag);
435 }
436}
437
438static void
Radek Krejci693262f2019-04-29 15:23:20 +0200439yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f)
440{
441 int brackets_flag = *index_e;
442 uint8_t op;
443
444 op = lysc_iff_getop(feat->expr, *index_e);
445 (*index_e)++;
446
447 switch (op) {
448 case LYS_IFF_F:
449 if (ctx->module == feat->features[*index_f]->module) {
450 ly_print(ctx->out, "%s", feat->features[*index_f]->name);
451 } else {
452 ly_print(ctx->out, "%s:%s", feat->features[*index_f]->module->prefix, feat->features[*index_f]->name);
453 }
454 (*index_f)++;
455 break;
456 case LYS_IFF_NOT:
457 ly_print(ctx->out, "not ");
458 yprc_iffeature(ctx, feat, index_e, index_f);
459 break;
460 case LYS_IFF_AND:
461 if (brackets_flag) {
462 /* AND need brackets only if previous op was not */
463 if (*index_e < 2 || lysc_iff_getop(feat->expr, *index_e - 2) != LYS_IFF_NOT) {
464 brackets_flag = 0;
465 }
466 }
467 /* falls through */
468 case LYS_IFF_OR:
469 if (brackets_flag) {
470 ly_print(ctx->out, "(");
471 }
472 yprc_iffeature(ctx, feat, index_e, index_f);
473 ly_print(ctx->out, " %s ", op == LYS_IFF_OR ? "or" : "and");
474 yprc_iffeature(ctx, feat, index_e, index_f);
475 if (brackets_flag) {
476 ly_print(ctx->out, ")");
477 }
478 }
479}
480
481static void
482yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
483{
Radek Krejci334ccc72019-06-12 13:49:29 +0200484 unsigned int u, v;
Radek Krejci693262f2019-04-29 15:23:20 +0200485 int extflag;
486
487 LY_ARRAY_FOR(iff, u) {
488 int index_e = 0, index_f = 0;
489
490 ypr_open(ctx->out, flag);
491 extflag = 0;
492
Radek Krejci989e53b2019-04-30 09:51:09 +0200493 ly_print(ctx->out, "%*sif-feature \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200494 yprc_iffeature(ctx, iff, &index_e, &index_f);
Radek Krejci989e53b2019-04-30 09:51:09 +0200495 ly_print(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200496
497 /* extensions */
498 LEVEL++;
Radek Krejci334ccc72019-06-12 13:49:29 +0200499 LY_ARRAY_FOR(exts, v) {
500 if (exts[v].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[v].insubstmt_index != u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200501 continue;
502 }
Radek Krejci334ccc72019-06-12 13:49:29 +0200503 yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[v], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200504 }
505 LEVEL--;
506 ypr_close(ctx, extflag);
507 }
508}
509
510static void
511yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200512{
513 int flag = 0, flag2 = 0;
514 unsigned int i;
515
516 ly_print(ctx->out, "%*sextension %s", INDENT, ext->name);
517 LEVEL++;
518
519 if (ext->exts) {
Radek Krejci693262f2019-04-29 15:23:20 +0200520 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200521 }
522
523 if (ext->argument) {
524 ypr_open(ctx->out, &flag);
525 ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument);
526 if (ext->exts) {
527 LEVEL++;
528 i = -1;
529 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 +0200530 yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200531 }
532 LEVEL--;
533 }
534 if ((ext->flags & LYS_YINELEM_MASK) ||
535 (ext->exts && lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YINELEM) != LY_ARRAY_SIZE(ext->exts))) {
536 ypr_open(ctx->out, &flag2);
Radek Krejci693262f2019-04-29 15:23:20 +0200537 ypr_substmt(ctx, LYEXT_SUBSTMT_YINELEM, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200538 }
539 ypr_close(ctx, flag2);
540 }
541
Radek Krejci693262f2019-04-29 15:23:20 +0200542 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200543 ypr_description(ctx, ext->dsc, ext->exts, &flag);
544 ypr_reference(ctx, ext->ref, ext->exts, &flag);
545
546 LEVEL--;
547 ypr_close(ctx, flag);
548}
549
550static void
Radek Krejci693262f2019-04-29 15:23:20 +0200551yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200552{
553 int flag = 0;
554
555 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
556 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200557 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
558 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
559 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200560 ypr_description(ctx, feat->dsc, feat->exts, &flag);
561 ypr_reference(ctx, feat->ref, feat->exts, &flag);
562 LEVEL--;
563 ypr_close(ctx, flag);
564}
565
566static void
Radek Krejci693262f2019-04-29 15:23:20 +0200567yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat)
568{
569 int flag = 0;
570
571 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
572 LEVEL++;
573 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
574 yprc_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
575 ypr_status(ctx, feat->flags, feat->exts, &flag);
576 ypr_description(ctx, feat->dsc, feat->exts, &flag);
577 ypr_reference(ctx, feat->ref, feat->exts, &flag);
578 LEVEL--;
579 ypr_close(ctx, flag);
580}
581
582static void
583yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200584{
585 int flag = 0;
586 unsigned int u;
587
588 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
589 LEVEL++;
590
Radek Krejci693262f2019-04-29 15:23:20 +0200591 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
592 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200593
594 LY_ARRAY_FOR(ident->bases, u) {
595 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200596 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200597 }
598
Radek Krejci693262f2019-04-29 15:23:20 +0200599 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200600 ypr_description(ctx, ident->dsc, ident->exts, &flag);
601 ypr_reference(ctx, ident->ref, ident->exts, &flag);
602
603 LEVEL--;
604 ypr_close(ctx, flag);
605}
606
607static void
Radek Krejci693262f2019-04-29 15:23:20 +0200608yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident)
609{
610 int flag = 0;
611 unsigned int u;
612
613 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
614 LEVEL++;
615
616 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
617 yprc_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
618
619 LY_ARRAY_FOR(ident->derived, u) {
620 ypr_open(ctx->out, &flag);
621 if (ctx->module != ident->derived[u]->module) {
622 ly_print(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
623 } else {
624 ly_print(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
625 }
626 }
627
628 ypr_status(ctx, ident->flags, ident->exts, &flag);
629 ypr_description(ctx, ident->dsc, ident->exts, &flag);
630 ypr_reference(ctx, ident->ref, ident->exts, &flag);
631
632 LEVEL--;
633 ypr_close(ctx, flag);
634}
635
636static void
637yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200638{
639 int inner_flag = 0;
640
641 if (!restr) {
642 return;
643 }
644
645 ypr_open(ctx->out, flag);
646 ly_print(ctx->out, "%*s%s \"", INDENT, name);
647 ypr_encode(ctx->out, (restr->arg[0] != 0x15 && restr->arg[0] != 0x06) ? restr->arg : &restr->arg[1], -1);
648 ly_print(ctx->out, "\"");
649
650 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200651 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200652 if (restr->arg[0] == 0x15) {
653 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
654 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200655 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200656 }
657 if (restr->emsg) {
658 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200659 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200660 }
661 if (restr->eapptag) {
662 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200663 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200664 }
Radek Krejci693262f2019-04-29 15:23:20 +0200665 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
666 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
667
Radek Krejcid3ca0632019-04-16 16:54:54 +0200668 LEVEL--;
669 ypr_close(ctx, inner_flag);
670}
671
672static void
Radek Krejci693262f2019-04-29 15:23:20 +0200673yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag)
674{
675 int inner_flag = 0;
676
677 ypr_open(ctx->out, flag);
678 ly_print(ctx->out, "%*smust \"", INDENT);
679 ypr_encode(ctx->out, must->cond->expr, -1);
680 ly_print(ctx->out, "\"");
681
682 LEVEL++;
683 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0);
684 if (must->emsg) {
685 ypr_open(ctx->out, &inner_flag);
686 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, must->emsg, must->exts);
687 }
688 if (must->eapptag) {
689 ypr_open(ctx->out, &inner_flag);
690 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, must->eapptag, must->exts);
691 }
692 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
693 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
694
695 LEVEL--;
696 ypr_close(ctx, inner_flag);
697}
698
699static void
700yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag)
701{
702 int inner_flag = 0;
703 unsigned int u;
704
Radek Krejci334ccc72019-06-12 13:49:29 +0200705 if (!range) {
706 return;
707 }
708
Radek Krejci693262f2019-04-29 15:23:20 +0200709 ypr_open(ctx->out, flag);
Radek Krejci334ccc72019-06-12 13:49:29 +0200710 ly_print(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200711 LY_ARRAY_FOR(range->parts, u) {
712 if (u > 0) {
713 ly_print(ctx->out, " | ");
714 }
715 if (range->parts[u].max_64 == range->parts[u].min_64) {
716 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
717 ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64);
718 } else { /* signed values */
719 ly_print(ctx->out, "%"PRId64, range->parts[u].max_64);
720 }
721 } else {
722 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
723 ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
724 } else { /* signed values */
725 ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64);
726 }
727 }
728 }
729 ly_print(ctx->out, "\"");
730
731 LEVEL++;
732 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0);
733 if (range->emsg) {
734 ypr_open(ctx->out, &inner_flag);
735 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts);
736 }
737 if (range->eapptag) {
738 ypr_open(ctx->out, &inner_flag);
739 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts);
740 }
741 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
742 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
743
744 LEVEL--;
745 ypr_close(ctx, inner_flag);
746}
747
748static void
749yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag)
750{
751 int inner_flag = 0;
752
753 ypr_open(ctx->out, flag);
754 ly_print(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200755 ypr_encode(ctx->out, pattern->expr, -1);
Radek Krejci693262f2019-04-29 15:23:20 +0200756 ly_print(ctx->out, "\"");
757
758 LEVEL++;
759 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0);
760 if (pattern->inverted) {
761 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
762 ypr_open(ctx->out, &inner_flag);
763 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts);
764 }
765 if (pattern->emsg) {
766 ypr_open(ctx->out, &inner_flag);
767 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts);
768 }
769 if (pattern->eapptag) {
770 ypr_open(ctx->out, &inner_flag);
771 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts);
772 }
773 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
774 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
775
776 LEVEL--;
777 ypr_close(ctx, inner_flag);
778}
779
780static void
781yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200782{
783 int inner_flag = 0;
784
785 if (!when) {
786 return;
787 }
788 ypr_open(ctx->out, flag);
789
790 ly_print(ctx->out, "%*swhen \"", INDENT);
791 ypr_encode(ctx->out, when->cond, -1);
792 ly_print(ctx->out, "\"");
793
794 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200795 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200796 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
797 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
798 LEVEL--;
799 ypr_close(ctx, inner_flag);
800}
801
802static void
Radek Krejci693262f2019-04-29 15:23:20 +0200803yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag)
804{
805 int inner_flag = 0;
806
807 if (!when) {
808 return;
809 }
810 ypr_open(ctx->out, flag);
811
812 ly_print(ctx->out, "%*swhen \"", INDENT);
813 ypr_encode(ctx->out, when->cond->expr, -1);
814 ly_print(ctx->out, "\"");
815
816 LEVEL++;
817 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
818 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
819 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
820 LEVEL--;
821 ypr_close(ctx, inner_flag);
822}
823
824static void
825yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200826{
827 unsigned int u;
828 int inner_flag;
829
830 LY_ARRAY_FOR(items, u) {
831 ypr_open(ctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200832 if (type == LY_TYPE_BITS) {
833 ly_print(ctx->out, "%*sbit %s", INDENT, items[u].name);
834 } else { /* LY_TYPE_ENUM */
835 ly_print(ctx->out, "%*senum \"", INDENT);
836 ypr_encode(ctx->out, items[u].name, -1);
837 ly_print(ctx->out, "\"");
838 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200839 inner_flag = 0;
840 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200841 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
842 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200843 if (items[u].flags & LYS_SET_VALUE) {
844 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200845 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200846 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200847 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200848 }
849 }
Radek Krejci693262f2019-04-29 15:23:20 +0200850 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200851 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
852 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
853 LEVEL--;
854 ypr_close(ctx, inner_flag);
855 }
856}
857
858static void
Radek Krejci693262f2019-04-29 15:23:20 +0200859yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200860{
861 unsigned int u;
862 int flag = 0;
863
864 ly_print(ctx->out, "%*stype %s", INDENT, type->name);
865 LEVEL++;
866
Radek Krejci693262f2019-04-29 15:23:20 +0200867 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200868
Radek Krejci693262f2019-04-29 15:23:20 +0200869 yprp_restr(ctx, type->range, "range", &flag);
870 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200871 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200872 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200873 }
Radek Krejci693262f2019-04-29 15:23:20 +0200874 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
875 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200876
877 if (type->path) {
878 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200879 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200880 }
881 if (type->flags & LYS_SET_REQINST) {
882 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200883 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200884 }
885 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200886 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200887 }
888 LY_ARRAY_FOR(type->bases, u) {
889 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200890 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200891 }
892 LY_ARRAY_FOR(type->types, u) {
893 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200894 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200895 }
896
897 LEVEL--;
898 ypr_close(ctx, flag);
899}
900
901static void
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200902yprc_dflt_value(struct ypr_ctx *ctx, const struct lyd_value *value, const struct lys_module *value_mod, struct lysc_ext_instance *exts)
Radek Krejcia1911222019-07-22 17:24:50 +0200903{
904 int dynamic;
905 const char *str;
906
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200907 str = value->realtype->plugin->print(value, LYD_JSON, lys_get_prefix, (void*)value_mod, &dynamic);
Radek Krejcia1911222019-07-22 17:24:50 +0200908 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, str, exts);
909 if (dynamic) {
910 free((void*)str);
911 }
912}
913
914static void
Radek Krejci693262f2019-04-29 15:23:20 +0200915yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
916{
917 unsigned int u;
918 int flag = 0;
919
920 ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
921 LEVEL++;
922
923 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
924 if (type->dflt) {
925 ypr_open(ctx->out, &flag);
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200926 yprc_dflt_value(ctx, type->dflt, type->dflt_mod, type->exts);
Radek Krejci693262f2019-04-29 15:23:20 +0200927 }
928
929 switch(type->basetype) {
930 case LY_TYPE_BINARY: {
931 struct lysc_type_bin *bin = (struct lysc_type_bin*)type;
932 yprc_range(ctx, bin->length, type->basetype, &flag);
933 break;
934 }
935 case LY_TYPE_UINT8:
936 case LY_TYPE_UINT16:
937 case LY_TYPE_UINT32:
938 case LY_TYPE_UINT64:
939 case LY_TYPE_INT8:
940 case LY_TYPE_INT16:
941 case LY_TYPE_INT32:
942 case LY_TYPE_INT64: {
943 struct lysc_type_num *num = (struct lysc_type_num*)type;
944 yprc_range(ctx, num->range, type->basetype, &flag);
945 break;
946 }
947 case LY_TYPE_STRING: {
948 struct lysc_type_str *str = (struct lysc_type_str*)type;
949 yprc_range(ctx, str->length, type->basetype, &flag);
950 LY_ARRAY_FOR(str->patterns, u) {
951 yprc_pattern(ctx, str->patterns[u], &flag);
952 }
953 break;
954 }
955 case LY_TYPE_BITS:
956 case LY_TYPE_ENUM: {
957 /* bits and enums structures are compatible */
958 struct lysc_type_bits *bits = (struct lysc_type_bits*)type;
959 LY_ARRAY_FOR(bits->bits, u) {
960 struct lysc_type_bitenum_item *item = &bits->bits[u];
961 int inner_flag = 0;
962
963 ypr_open(ctx->out, &flag);
964 ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
965 ypr_encode(ctx->out, item->name, -1);
966 ly_print(ctx->out, "\"");
967 LEVEL++;
968 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
969 yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag);
970 if (type->basetype == LY_TYPE_BITS) {
971 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
972 } else { /* LY_TYPE_ENUM */
973 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
974 }
975 ypr_status(ctx, item->flags, item->exts, &inner_flag);
976 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
977 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
978 LEVEL--;
979 ypr_close(ctx, inner_flag);
980 }
981 break;
982 }
983 case LY_TYPE_BOOL:
984 case LY_TYPE_EMPTY:
985 /* nothing to do */
986 break;
987 case LY_TYPE_DEC64: {
988 struct lysc_type_dec *dec = (struct lysc_type_dec*)type;
989 ypr_open(ctx->out, &flag);
990 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag);
991 yprc_range(ctx, dec->range, dec->basetype, &flag);
992 break;
993 }
994 case LY_TYPE_IDENT: {
995 struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type;
996 LY_ARRAY_FOR(ident->bases, u) {
997 ypr_open(ctx->out, &flag);
998 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
999 }
1000 break;
1001 }
1002 case LY_TYPE_INST: {
1003 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type;
1004 ypr_open(ctx->out, &flag);
1005 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
1006 break;
1007 }
1008 case LY_TYPE_LEAFREF: {
1009 struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type;
1010 ypr_open(ctx->out, &flag);
1011 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts);
1012 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
1013 yprc_type(ctx, lr->realtype);
1014 break;
1015 }
1016 case LY_TYPE_UNION: {
1017 struct lysc_type_union *un = (struct lysc_type_union*)type;
1018 LY_ARRAY_FOR(un->types, u) {
1019 ypr_open(ctx->out, &flag);
1020 yprc_type(ctx, un->types[u]);
1021 }
1022 break;
1023 }
1024 default:
1025 LOGINT(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +02001026 ctx->out->status = LY_EINT;
Radek Krejci693262f2019-04-29 15:23:20 +02001027 }
1028
1029 LEVEL--;
1030 ypr_close(ctx, flag);
1031}
1032
1033static void
1034yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001035{
Radek Krejci56cc0872019-04-30 09:22:27 +02001036 LYOUT_CHECK(ctx->out);
1037
Radek Krejcid3ca0632019-04-16 16:54:54 +02001038 ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
1039 LEVEL++;
1040
Radek Krejci693262f2019-04-29 15:23:20 +02001041 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001042
Radek Krejci693262f2019-04-29 15:23:20 +02001043 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001044
1045 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +02001046 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001047 }
1048 if (tpdf->dflt) {
Radek Krejci693262f2019-04-29 15:23:20 +02001049 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001050 }
1051
Radek Krejci693262f2019-04-29 15:23:20 +02001052 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001053 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
1054 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
1055
1056 LEVEL--;
1057 ly_print(ctx->out, "%*s}\n", INDENT);
1058}
1059
Radek Krejci693262f2019-04-29 15:23:20 +02001060static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node);
1061static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node);
1062static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001063
1064static void
Radek Krejci693262f2019-04-29 15:23:20 +02001065yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001066{
1067 unsigned int u;
1068 int flag = 0;
1069 struct lysp_node *data;
1070
Radek Krejci56cc0872019-04-30 09:22:27 +02001071 LYOUT_CHECK(ctx->out);
1072
Radek Krejcid3ca0632019-04-16 16:54:54 +02001073 ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
1074 LEVEL++;
1075
Radek Krejci693262f2019-04-29 15:23:20 +02001076 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
1077 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +02001078 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1079 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001080
1081 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001082 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001083 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001084 }
1085
1086 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001087 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001088 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001089 }
1090
1091 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001092 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001093 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001094 }
1095
1096 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001097 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001098 }
1099
1100 LEVEL--;
1101 ypr_close(ctx, flag);
1102}
1103
1104static void
Radek Krejci693262f2019-04-29 15:23:20 +02001105yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001106{
1107 unsigned int u;
1108 struct lysp_node *data;
1109
1110 if (!inout->nodetype) {
1111 /* nodetype not set -> input/output is empty */
1112 return;
1113 }
1114 ypr_open(ctx->out, flag);
1115
1116 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1117 LEVEL++;
1118
Radek Krejci693262f2019-04-29 15:23:20 +02001119 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001120 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001121 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001122 }
1123 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001124 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001125 }
1126 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001127 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001128 }
1129
1130 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001131 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001132 }
1133
1134 LEVEL--;
1135 ypr_close(ctx, 1);
1136}
1137
1138static void
Radek Krejci693262f2019-04-29 15:23:20 +02001139yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1140{
1141 unsigned int u;
1142 struct lysc_node *data;
1143
1144 if (!inout->data) {
1145 /* input/output is empty */
1146 return;
1147 }
1148 ypr_open(ctx->out, flag);
1149
1150 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1151 LEVEL++;
1152
1153 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1154 LY_ARRAY_FOR(inout->musts, u) {
1155 yprc_must(ctx, &inout->musts[u], NULL);
1156 }
1157
1158 LY_LIST_FOR(inout->data, data) {
1159 yprc_node(ctx, data);
1160 }
1161
1162 LEVEL--;
1163 ypr_close(ctx, 1);
1164}
1165
1166static void
1167yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001168{
1169 unsigned int u;
1170 int flag = 0;
1171 struct lysp_node *data;
1172
Radek Krejci56cc0872019-04-30 09:22:27 +02001173 LYOUT_CHECK(ctx->out);
1174
Radek Krejcid3ca0632019-04-16 16:54:54 +02001175 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1176
1177 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001178 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1179 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001180
1181 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001182 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001183 }
Radek Krejci693262f2019-04-29 15:23:20 +02001184 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001185 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1186 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1187
1188 LY_ARRAY_FOR(notif->typedefs, u) {
1189 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001190 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001191 }
1192
1193 LY_ARRAY_FOR(notif->groupings, u) {
1194 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001195 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001196 }
1197
1198 LY_LIST_FOR(notif->data, data) {
1199 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001200 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001201 }
1202
1203 LEVEL--;
1204 ypr_close(ctx, flag);
1205}
1206
1207static void
Radek Krejci693262f2019-04-29 15:23:20 +02001208yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1209{
1210 unsigned int u;
1211 int flag = 0;
1212 struct lysc_node *data;
1213
Radek Krejci56cc0872019-04-30 09:22:27 +02001214 LYOUT_CHECK(ctx->out);
1215
Radek Krejci693262f2019-04-29 15:23:20 +02001216 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1217
1218 LEVEL++;
1219 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1220 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1221
1222 LY_ARRAY_FOR(notif->musts, u) {
1223 yprc_must(ctx, &notif->musts[u], &flag);
1224 }
1225 ypr_status(ctx, notif->flags, notif->exts, &flag);
1226 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1227 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1228
1229 LY_LIST_FOR(notif->data, data) {
1230 ypr_open(ctx->out, &flag);
1231 yprc_node(ctx, data);
1232 }
1233
1234 LEVEL--;
1235 ypr_close(ctx, flag);
1236}
1237
1238static void
1239yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001240{
1241 unsigned int u;
1242 int flag = 0;
1243
Radek Krejci56cc0872019-04-30 09:22:27 +02001244 LYOUT_CHECK(ctx->out);
1245
Radek Krejcid3ca0632019-04-16 16:54:54 +02001246 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1247
1248 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001249 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1250 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1251 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001252 ypr_description(ctx, action->dsc, action->exts, &flag);
1253 ypr_reference(ctx, action->ref, action->exts, &flag);
1254
1255 LY_ARRAY_FOR(action->typedefs, u) {
1256 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001257 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001258 }
1259
1260 LY_ARRAY_FOR(action->groupings, u) {
1261 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001262 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001263 }
1264
Radek Krejci693262f2019-04-29 15:23:20 +02001265 yprp_inout(ctx, &action->input, &flag);
1266 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001267
1268 LEVEL--;
1269 ypr_close(ctx, flag);
1270}
1271
1272static void
Radek Krejci693262f2019-04-29 15:23:20 +02001273yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1274{
1275 int flag = 0;
1276
Radek Krejci56cc0872019-04-30 09:22:27 +02001277 LYOUT_CHECK(ctx->out);
1278
Radek Krejci693262f2019-04-29 15:23:20 +02001279 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1280
1281 LEVEL++;
1282 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1283 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1284 ypr_status(ctx, action->flags, action->exts, &flag);
1285 ypr_description(ctx, action->dsc, action->exts, &flag);
1286 ypr_reference(ctx, action->ref, action->exts, &flag);
1287
1288 yprc_inout(ctx, action, &action->input, &flag);
1289 yprc_inout(ctx, action, &action->output, &flag);
1290
1291 LEVEL--;
1292 ypr_close(ctx, flag);
1293}
1294
1295static void
1296yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001297{
Radek Krejci7871ce52019-06-11 16:44:56 +02001298 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001299 LEVEL++;
1300
Radek Krejci693262f2019-04-29 15:23:20 +02001301 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1302 yprp_when(ctx, node->when, flag);
1303 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001304}
1305
1306static void
Radek Krejci693262f2019-04-29 15:23:20 +02001307yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001308{
Radek Krejci693262f2019-04-29 15:23:20 +02001309 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001310
Radek Krejci42903ea2019-06-14 16:24:56 +02001311 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001312 LEVEL++;
1313
1314 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1315 LY_ARRAY_FOR(node->when, u) {
1316 yprc_when(ctx, node->when[u], flag);
1317 }
1318 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1319}
1320
1321/* macr oto unify the code */
1322#define YPR_NODE_COMMON2 \
1323 ypr_config(ctx, node->flags, node->exts, flag); \
1324 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1325 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1326 } \
1327 ypr_status(ctx, node->flags, node->exts, flag); \
1328 ypr_description(ctx, node->dsc, node->exts, flag); \
1329 ypr_reference(ctx, node->ref, node->exts, flag)
1330
1331static void
1332yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1333{
1334 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001335}
1336
1337static void
Radek Krejci693262f2019-04-29 15:23:20 +02001338yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1339{
1340 YPR_NODE_COMMON2;
1341}
1342
1343#undef YPR_NODE_COMMON2
1344
1345static void
1346yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001347{
1348 unsigned int u;
1349 int flag = 0;
1350 struct lysp_node *child;
1351 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1352
Radek Krejci693262f2019-04-29 15:23:20 +02001353 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001354
1355 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001356 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001357 }
1358 if (cont->presence) {
1359 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001360 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001361 }
1362
Radek Krejci693262f2019-04-29 15:23:20 +02001363 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001364
1365 LY_ARRAY_FOR(cont->typedefs, u) {
1366 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001367 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001368 }
1369
1370 LY_ARRAY_FOR(cont->groupings, u) {
1371 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001372 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001373 }
1374
1375 LY_LIST_FOR(cont->child, child) {
1376 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001377 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001378 }
1379
1380 LY_ARRAY_FOR(cont->actions, u) {
1381 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001382 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001383 }
1384
1385 LY_ARRAY_FOR(cont->notifs, u) {
1386 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001387 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001388 }
1389
1390 LEVEL--;
1391 ypr_close(ctx, flag);
1392}
1393
1394static void
Radek Krejci693262f2019-04-29 15:23:20 +02001395yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1396{
1397 unsigned int u;
1398 int flag = 0;
1399 struct lysc_node *child;
1400 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1401
1402 yprc_node_common1(ctx, node, &flag);
1403
1404 LY_ARRAY_FOR(cont->musts, u) {
1405 yprc_must(ctx, &cont->musts[u], &flag);
1406 }
1407 if (cont->flags & LYS_PRESENCE) {
1408 ypr_open(ctx->out, &flag);
1409 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1410 }
1411
1412 yprc_node_common2(ctx, node, &flag);
1413
1414 LY_LIST_FOR(cont->child, child) {
1415 ypr_open(ctx->out, &flag);
1416 yprc_node(ctx, child);
1417 }
1418
1419 LY_ARRAY_FOR(cont->actions, u) {
1420 ypr_open(ctx->out, &flag);
1421 yprc_action(ctx, &cont->actions[u]);
1422 }
1423
1424 LY_ARRAY_FOR(cont->notifs, u) {
1425 ypr_open(ctx->out, &flag);
1426 yprc_notification(ctx, &cont->notifs[u]);
1427 }
1428
1429 LEVEL--;
1430 ypr_close(ctx, flag);
1431}
1432
1433static void
1434yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1435{
1436 int flag = 0;
1437 struct lysp_node *child;
1438 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1439
1440 yprp_node_common1(ctx, node, &flag);
1441 yprp_node_common2(ctx, node, &flag);
1442
1443 LY_LIST_FOR(cas->child, child) {
1444 ypr_open(ctx->out, &flag);
1445 yprp_node(ctx, child);
1446 }
1447
1448 LEVEL--;
1449 ypr_close(ctx, flag);
1450}
1451
1452static void
1453yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1454{
1455 int flag = 0;
1456 struct lysc_node *child;
1457
1458 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1459 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1460
1461 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1462 ypr_open(ctx->out, &flag);
1463 yprc_node(ctx, child);
1464 }
1465
1466 LEVEL--;
1467 ypr_close(ctx, flag);
1468}
1469
1470static void
1471yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001472{
1473 int flag = 0;
1474 struct lysp_node *child;
1475 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1476
Radek Krejci693262f2019-04-29 15:23:20 +02001477 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001478
1479 if (choice->dflt) {
1480 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001481 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001482 }
1483
Radek Krejci693262f2019-04-29 15:23:20 +02001484 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001485
1486 LY_LIST_FOR(choice->child, child) {
1487 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001488 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001489 }
1490
1491 LEVEL--;
1492 ypr_close(ctx, flag);
1493}
1494
1495static void
Radek Krejci693262f2019-04-29 15:23:20 +02001496yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1497{
1498 int flag = 0;
1499 struct lysc_node_case *cs;
1500 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1501
1502 yprc_node_common1(ctx, node, &flag);
1503
1504 if (choice->dflt) {
1505 ypr_open(ctx->out, &flag);
1506 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1507 }
1508
1509 yprc_node_common2(ctx, node, &flag);
1510
1511 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1512 ypr_open(ctx->out, &flag);
1513 yprc_case(ctx, cs);
1514 }
1515
1516 LEVEL--;
1517 ypr_close(ctx, flag);
1518}
1519
1520static void
1521yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001522{
1523 unsigned int u;
1524 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1525
Radek Krejci693262f2019-04-29 15:23:20 +02001526 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001527
Radek Krejci693262f2019-04-29 15:23:20 +02001528 yprp_type(ctx, &leaf->type);
1529 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001530 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001531 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001532 }
Radek Krejci693262f2019-04-29 15:23:20 +02001533 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001534
Radek Krejci693262f2019-04-29 15:23:20 +02001535 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001536
1537 LEVEL--;
1538 ly_print(ctx->out, "%*s}\n", INDENT);
1539}
1540
1541static void
Radek Krejci693262f2019-04-29 15:23:20 +02001542yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1543{
1544 unsigned int u;
1545 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1546
1547 yprc_node_common1(ctx, node, NULL);
1548
1549 yprc_type(ctx, leaf->type);
1550 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1551 LY_ARRAY_FOR(leaf->musts, u) {
1552 yprc_must(ctx, &leaf->musts[u], NULL);
1553 }
Radek Krejcia1911222019-07-22 17:24:50 +02001554
1555 if (leaf->dflt) {
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001556 yprc_dflt_value(ctx, leaf->dflt, leaf->dflt_mod, leaf->exts);
Radek Krejcia1911222019-07-22 17:24:50 +02001557 }
Radek Krejci693262f2019-04-29 15:23:20 +02001558
1559 yprc_node_common2(ctx, node, NULL);
1560
1561 LEVEL--;
1562 ly_print(ctx->out, "%*s}\n", INDENT);
1563}
1564
1565static void
1566yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001567{
1568 unsigned int u;
1569 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1570
Radek Krejci693262f2019-04-29 15:23:20 +02001571 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001572
Radek Krejci693262f2019-04-29 15:23:20 +02001573 yprp_type(ctx, &llist->type);
1574 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001575 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001576 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001577 }
1578 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001579 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001580 }
1581
Radek Krejci693262f2019-04-29 15:23:20 +02001582 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001583
1584 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001585 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001586 }
1587 if (llist->flags & LYS_SET_MAX) {
1588 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001589 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001590 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001591 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001592 }
1593 }
1594
1595 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001596 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001597 }
1598
Radek Krejci693262f2019-04-29 15:23:20 +02001599 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001600 ypr_description(ctx, node->dsc, node->exts, NULL);
1601 ypr_reference(ctx, node->ref, node->exts, NULL);
1602
1603 LEVEL--;
1604 ly_print(ctx->out, "%*s}\n", INDENT);
1605}
1606
1607static void
Radek Krejci693262f2019-04-29 15:23:20 +02001608yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1609{
1610 unsigned int u;
1611 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1612
1613 yprc_node_common1(ctx, node, NULL);
1614
1615 yprc_type(ctx, llist->type);
1616 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1617 LY_ARRAY_FOR(llist->musts, u) {
1618 yprc_must(ctx, &llist->musts[u], NULL);
1619 }
1620 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejcid0ef1af2019-07-23 12:22:05 +02001621 yprc_dflt_value(ctx, llist->dflts[u], llist->dflts_mods[u], llist->exts);
Radek Krejci693262f2019-04-29 15:23:20 +02001622 }
1623
1624 ypr_config(ctx, node->flags, node->exts, NULL);
1625
1626 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1627 if (llist->max) {
1628 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1629 } else {
1630 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1631 }
1632
1633 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1634
1635 ypr_status(ctx, node->flags, node->exts, NULL);
1636 ypr_description(ctx, node->dsc, node->exts, NULL);
1637 ypr_reference(ctx, node->ref, node->exts, NULL);
1638
1639 LEVEL--;
1640 ly_print(ctx->out, "%*s}\n", INDENT);
1641}
1642
1643static void
1644yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001645{
1646 unsigned int u;
1647 int flag = 0;
1648 struct lysp_node *child;
1649 struct lysp_node_list *list = (struct lysp_node_list *)node;
1650
Radek Krejci693262f2019-04-29 15:23:20 +02001651 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001652
1653 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001654 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001655 }
1656 if (list->key) {
1657 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001658 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001659 }
1660 LY_ARRAY_FOR(list->uniques, u) {
1661 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001662 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001663 }
1664
Radek Krejci693262f2019-04-29 15:23:20 +02001665 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001666
1667 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001668 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001669 }
1670 if (list->flags & LYS_SET_MAX) {
1671 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001672 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001673 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001674 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001675 }
1676 }
1677
1678 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001679 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001680 }
1681
Radek Krejci693262f2019-04-29 15:23:20 +02001682 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001683 ypr_description(ctx, node->dsc, node->exts, NULL);
1684 ypr_reference(ctx, node->ref, node->exts, NULL);
1685
1686 LY_ARRAY_FOR(list->typedefs, u) {
1687 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001688 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001689 }
1690
1691 LY_ARRAY_FOR(list->groupings, u) {
1692 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001693 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001694 }
1695
1696 LY_LIST_FOR(list->child, child) {
1697 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001698 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001699 }
1700
1701 LY_ARRAY_FOR(list->actions, u) {
1702 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001703 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001704 }
1705
1706 LY_ARRAY_FOR(list->notifs, u) {
1707 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001708 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001709 }
1710
1711 LEVEL--;
1712 ypr_close(ctx, flag);
1713}
1714
1715static void
Radek Krejci693262f2019-04-29 15:23:20 +02001716yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1717{
1718 unsigned int u, v;
1719 int flag = 0;
1720 struct lysc_node *child;
1721 struct lysc_node_list *list = (struct lysc_node_list *)node;
1722
1723 yprc_node_common1(ctx, node, &flag);
1724
1725 LY_ARRAY_FOR(list->musts, u) {
1726 yprc_must(ctx, &list->musts[u], NULL);
1727 }
Radek Krejci0fe9b512019-07-26 17:51:05 +02001728 if (!(list->flags & LYS_KEYLESS)) {
Radek Krejci693262f2019-04-29 15:23:20 +02001729 ypr_open(ctx->out, &flag);
1730 ly_print(ctx->out, "%*skey \"", INDENT);
Radek Krejci0fe9b512019-07-26 17:51:05 +02001731 for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) {
1732 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", key->name);
Radek Krejci693262f2019-04-29 15:23:20 +02001733 }
Radek Krejci73c88f52019-06-14 16:24:19 +02001734 ly_print(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001735 }
1736 LY_ARRAY_FOR(list->uniques, u) {
1737 ypr_open(ctx->out, &flag);
1738 ly_print(ctx->out, "%*sunique \"", INDENT);
1739 LY_ARRAY_FOR(list->uniques[u], v) {
1740 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1741 }
1742 ypr_close(ctx, 0);
1743 }
1744
1745 ypr_config(ctx, node->flags, node->exts, NULL);
1746
1747 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1748 if (list->max) {
1749 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1750 } else {
1751 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1752 }
1753
1754 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1755
1756 ypr_status(ctx, node->flags, node->exts, NULL);
1757 ypr_description(ctx, node->dsc, node->exts, NULL);
1758 ypr_reference(ctx, node->ref, node->exts, NULL);
1759
1760 LY_LIST_FOR(list->child, child) {
1761 ypr_open(ctx->out, &flag);
1762 yprc_node(ctx, child);
1763 }
1764
1765 LY_ARRAY_FOR(list->actions, u) {
1766 ypr_open(ctx->out, &flag);
1767 yprc_action(ctx, &list->actions[u]);
1768 }
1769
1770 LY_ARRAY_FOR(list->notifs, u) {
1771 ypr_open(ctx->out, &flag);
1772 yprc_notification(ctx, &list->notifs[u]);
1773 }
1774
1775 LEVEL--;
1776 ypr_close(ctx, flag);
1777}
1778
1779static void
1780yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001781{
1782 unsigned int u;
1783 int flag = 0;
1784
1785 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1786 LEVEL++;
1787
Radek Krejci693262f2019-04-29 15:23:20 +02001788 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1789 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001790
1791 LY_ARRAY_FOR(refine->musts, u) {
1792 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001793 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001794 }
1795
1796 if (refine->presence) {
1797 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001798 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001799 }
1800
1801 LY_ARRAY_FOR(refine->dflts, u) {
1802 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001803 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001804 }
1805
Radek Krejci693262f2019-04-29 15:23:20 +02001806 ypr_config(ctx, refine->flags, refine->exts, &flag);
1807 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001808
1809 if (refine->flags & LYS_SET_MIN) {
1810 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001811 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001812 }
1813 if (refine->flags & LYS_SET_MAX) {
1814 ypr_open(ctx->out, &flag);
1815 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001816 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001817 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001818 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001819 }
1820 }
1821
1822 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1823 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1824
1825 LEVEL--;
1826 ypr_close(ctx, flag);
1827}
1828
1829static void
Radek Krejci693262f2019-04-29 15:23:20 +02001830yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001831{
1832 unsigned int u;
1833 struct lysp_node *child;
1834
1835 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1836 LEVEL++;
1837
Radek Krejci693262f2019-04-29 15:23:20 +02001838 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1839 yprp_when(ctx, aug->when, NULL);
1840 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1841 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001842 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1843 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1844
1845 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001846 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001847 }
1848
1849 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001850 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001851 }
1852
1853 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001854 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001855 }
1856
1857 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001858 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001859}
1860
1861
1862static void
Radek Krejci693262f2019-04-29 15:23:20 +02001863yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001864{
1865 unsigned int u;
1866 int flag = 0;
1867 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1868
Radek Krejci693262f2019-04-29 15:23:20 +02001869 yprp_node_common1(ctx, node, &flag);
1870 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001871
1872 LY_ARRAY_FOR(uses->refines, u) {
1873 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001874 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001875 }
1876
1877 LY_ARRAY_FOR(uses->augments, u) {
1878 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001879 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001880 }
1881
1882 LEVEL--;
1883 ypr_close(ctx, flag);
1884}
1885
1886static void
Radek Krejci693262f2019-04-29 15:23:20 +02001887yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001888{
1889 unsigned int u;
1890 int flag = 0;
1891 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1892
Radek Krejci693262f2019-04-29 15:23:20 +02001893 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001894
1895 LY_ARRAY_FOR(any->musts, u) {
1896 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001897 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001898 }
1899
Radek Krejci693262f2019-04-29 15:23:20 +02001900 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001901
1902 LEVEL--;
1903 ypr_close(ctx, flag);
1904}
1905
1906static void
Radek Krejci693262f2019-04-29 15:23:20 +02001907yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001908{
Radek Krejci693262f2019-04-29 15:23:20 +02001909 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001910 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001911 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001912
Radek Krejci693262f2019-04-29 15:23:20 +02001913 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001914
Radek Krejci693262f2019-04-29 15:23:20 +02001915 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001916 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001917 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001918 }
1919
Radek Krejci693262f2019-04-29 15:23:20 +02001920 yprc_node_common2(ctx, node, &flag);
1921
Radek Krejcid3ca0632019-04-16 16:54:54 +02001922 LEVEL--;
1923 ypr_close(ctx, flag);
1924}
1925
1926static void
Radek Krejci693262f2019-04-29 15:23:20 +02001927yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001928{
Radek Krejci56cc0872019-04-30 09:22:27 +02001929 LYOUT_CHECK(ctx->out);
1930
Radek Krejcid3ca0632019-04-16 16:54:54 +02001931 switch (node->nodetype) {
1932 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001933 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001934 break;
1935 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001936 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001937 break;
1938 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001939 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001940 break;
1941 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001942 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001943 break;
1944 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001945 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001946 break;
1947 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001948 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001949 break;
1950 case LYS_ANYXML:
1951 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001952 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001953 break;
1954 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001955 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001956 break;
1957 default:
1958 break;
1959 }
1960}
1961
1962static void
Radek Krejci693262f2019-04-29 15:23:20 +02001963yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1964{
Radek Krejci56cc0872019-04-30 09:22:27 +02001965 LYOUT_CHECK(ctx->out);
1966
Radek Krejci693262f2019-04-29 15:23:20 +02001967 switch (node->nodetype) {
1968 case LYS_CONTAINER:
1969 yprc_container(ctx, node);
1970 break;
1971 case LYS_CHOICE:
1972 yprc_choice(ctx, node);
1973 break;
1974 case LYS_LEAF:
1975 yprc_leaf(ctx, node);
1976 break;
1977 case LYS_LEAFLIST:
1978 yprc_leaflist(ctx, node);
1979 break;
1980 case LYS_LIST:
1981 yprc_list(ctx, node);
1982 break;
1983 case LYS_ANYXML:
1984 case LYS_ANYDATA:
1985 yprc_anydata(ctx, node);
1986 break;
1987 default:
1988 break;
1989 }
1990}
1991
1992static void
1993yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001994{
1995 unsigned int u, v;
1996 struct lysp_deviate_add *add;
1997 struct lysp_deviate_rpl *rpl;
1998 struct lysp_deviate_del *del;
1999
2000 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
2001 LEVEL++;
2002
Radek Krejci693262f2019-04-29 15:23:20 +02002003 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002004 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
2005 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
2006
2007 LY_ARRAY_FOR(deviation->deviates, u) {
2008 ly_print(ctx->out, "%*sdeviate ", INDENT);
2009 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
2010 if (deviation->deviates[u].exts) {
2011 ly_print(ctx->out, "not-supported {\n");
2012 LEVEL++;
2013
Radek Krejci693262f2019-04-29 15:23:20 +02002014 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002015 } else {
2016 ly_print(ctx->out, "not-supported;\n");
2017 continue;
2018 }
2019 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
2020 add = (struct lysp_deviate_add*)&deviation->deviates[u];
2021 ly_print(ctx->out, "add {\n");
2022 LEVEL++;
2023
Radek Krejci693262f2019-04-29 15:23:20 +02002024 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
2025 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002026 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002027 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 }
2029 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002030 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002031 }
2032 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002033 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002034 }
Radek Krejci693262f2019-04-29 15:23:20 +02002035 ypr_config(ctx, add->flags, add->exts, NULL);
2036 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002037 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002038 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002039 }
2040 if (add->flags & LYS_SET_MAX) {
2041 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002042 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002043 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002044 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045 }
2046 }
2047 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
2048 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
2049 ly_print(ctx->out, "replace {\n");
2050 LEVEL++;
2051
Radek Krejci693262f2019-04-29 15:23:20 +02002052 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002053 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02002054 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002055 }
Radek Krejci693262f2019-04-29 15:23:20 +02002056 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
2057 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
2058 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
2059 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002060 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002061 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062 }
2063 if (rpl->flags & LYS_SET_MAX) {
2064 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002065 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002066 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002067 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002068 }
2069 }
2070 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
2071 del = (struct lysp_deviate_del*)&deviation->deviates[u];
2072 ly_print(ctx->out, "delete {\n");
2073 LEVEL++;
2074
Radek Krejci693262f2019-04-29 15:23:20 +02002075 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2076 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002077 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002078 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002079 }
2080 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002081 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002082 }
2083 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002084 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002085 }
2086 }
2087
2088 LEVEL--;
2089 ypr_close(ctx, 1);
2090 }
2091
2092 LEVEL--;
2093 ypr_close(ctx, 1);
2094}
2095
Radek Krejci693262f2019-04-29 15:23:20 +02002096/**
2097 * @brief Minimal print of a schema.
2098 *
2099 * To print
2100 * a) compiled schema when it is not compiled or
2101 * b) parsed when the parsed form was already removed
2102 */
2103static LY_ERR
2104ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2105{
2106 /* module-header-stmts */
2107 if (module->version) {
2108 if (module->version) {
2109 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2110 }
2111 }
2112 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2113 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2114
2115 /* meta-stmts */
2116 if (module->org || module->contact || module->dsc || module->ref) {
2117 ly_print(ctx->out, "\n");
2118 }
2119 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2120 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2121 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2122 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2123
2124 /* revision-stmts */
2125 if (module->revision) {
2126 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2127 }
2128
2129 LEVEL--;
2130 ly_print(ctx->out, "%*s}\n", INDENT);
2131 ly_print_flush(ctx->out);
2132
2133 return LY_SUCCESS;
2134}
2135
Radek Krejcid3ca0632019-04-16 16:54:54 +02002136LY_ERR
2137yang_print_parsed(struct lyout *out, const struct lys_module *module)
2138{
2139 unsigned int u;
2140 struct lysp_node *data;
2141 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002142 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002143
2144 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2145 LEVEL++;
2146
Radek Krejci693262f2019-04-29 15:23:20 +02002147 if (!modp) {
2148 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2149 return ypr_missing_format(ctx, module);
2150 }
2151
Radek Krejcid3ca0632019-04-16 16:54:54 +02002152 /* module-header-stmts */
2153 if (module->version) {
2154 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002155 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 +02002156 }
2157 }
Radek Krejci693262f2019-04-29 15:23:20 +02002158 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2159 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002160
2161 /* linkage-stmts */
2162 LY_ARRAY_FOR(modp->imports, u) {
Radek Krejci7871ce52019-06-11 16:44:56 +02002163 ly_print(out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].module->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002164 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002165 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2166 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002167 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002168 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002169 }
Radek Krejci693262f2019-04-29 15:23:20 +02002170 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2171 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002172 LEVEL--;
2173 ly_print(out, "%*s}\n", INDENT);
2174 }
2175 LY_ARRAY_FOR(modp->includes, u) {
2176 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 +02002177 ly_print(out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].submodule->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002178 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002179 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002180 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002181 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002182 }
Radek Krejci693262f2019-04-29 15:23:20 +02002183 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2184 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002185 LEVEL--;
2186 ly_print(out, "%*s}\n", INDENT);
2187 } else {
2188 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2189 }
2190 }
2191
2192 /* meta-stmts */
2193 if (module->org || module->contact || module->dsc || module->ref) {
2194 ly_print(out, "\n");
2195 }
Radek Krejci693262f2019-04-29 15:23:20 +02002196 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2197 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2198 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2199 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002200
2201 /* revision-stmts */
2202 if (modp->revs) {
2203 ly_print(out, "\n");
2204 }
2205 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002206 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002207 }
2208 /* body-stmts */
2209 LY_ARRAY_FOR(modp->extensions, u) {
2210 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002211 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002212 }
2213 if (modp->exts) {
2214 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002215 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002216 }
2217
2218 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002219 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002220 }
2221
2222 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002223 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002224 }
2225
2226 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002227 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002228 }
2229
2230 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002231 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002232 }
2233
2234 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002235 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002236 }
2237
2238 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002239 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002240 }
2241
2242 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002243 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002244 }
2245
2246 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002247 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002248 }
2249
2250 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002251 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002252 }
2253
2254 LEVEL--;
2255 ly_print(out, "%*s}\n", INDENT);
2256 ly_print_flush(out);
2257
2258 return LY_SUCCESS;
2259}
2260
2261LY_ERR
2262yang_print_compiled(struct lyout *out, const struct lys_module *module)
2263{
Radek Krejci693262f2019-04-29 15:23:20 +02002264 unsigned int u;
2265 struct lysc_node *data;
2266 struct lysc_module *modc = module->compiled;
2267 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2268
2269 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2270 LEVEL++;
2271
2272 if (!modc) {
2273 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2274 return ypr_missing_format(ctx, module);
2275 }
2276
2277 /* module-header-stmts */
2278 if (module->version) {
2279 if (module->version) {
2280 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2281 }
2282 }
2283 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2284 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2285
2286 /* linkage-stmts */
2287 LY_ARRAY_FOR(modc->imports, u) {
2288 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2289 LEVEL++;
2290 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2291 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2292 if (modc->imports[u].module->revision) {
2293 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2294 }
2295 LEVEL--;
2296 ly_print(out, "%*s}\n", INDENT);
2297 }
2298
2299 /* meta-stmts */
2300 if (module->org || module->contact || module->dsc || module->ref) {
2301 ly_print(out, "\n");
2302 }
2303 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2304 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2305 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2306 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2307
2308 /* revision-stmts */
2309 if (module->revision) {
2310 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2311 }
2312
2313 /* body-stmts */
2314 if (modc->exts) {
2315 ly_print(out, "\n");
2316 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2317 }
2318
2319 LY_ARRAY_FOR(modc->features, u) {
2320 yprc_feature(ctx, &modc->features[u]);
2321 }
2322
2323 LY_ARRAY_FOR(modc->identities, u) {
2324 yprc_identity(ctx, &modc->identities[u]);
2325 }
2326
2327 LY_LIST_FOR(modc->data, data) {
2328 yprc_node(ctx, data);
2329 }
2330
2331 LY_ARRAY_FOR(modc->rpcs, u) {
2332 yprc_action(ctx, &modc->rpcs[u]);
2333 }
2334
2335 LY_ARRAY_FOR(modc->notifs, u) {
2336 yprc_notification(ctx, &modc->notifs[u]);
2337 }
2338
2339 LEVEL--;
2340 ly_print(out, "%*s}\n", INDENT);
2341 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002342
2343 return LY_SUCCESS;
2344}