blob: 2dfd5e6b29ac9c1664a83cc521ca9eb46f75c60e [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>
18
Radek Krejcid3ca0632019-04-16 16:54:54 +020019#include "printer_internal.h"
20#include "tree_schema.h"
21#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020022#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020023
24#define LEVEL ctx->level
25#define INDENT (LEVEL)*2,""
26
Radek Krejci693262f2019-04-29 15:23:20 +020027enum schema_type {
28 YPR_PARSED,
29 YPR_COMPILED
30};
31
Radek Krejcid3ca0632019-04-16 16:54:54 +020032struct ypr_ctx {
33 struct lyout *out;
34 unsigned int level;
35 const struct lys_module *module;
Radek Krejci693262f2019-04-29 15:23:20 +020036 enum schema_type schema;
Radek Krejcid3ca0632019-04-16 16:54:54 +020037};
38
39static void
40ypr_encode(struct lyout *out, const char *text, int len)
41{
42 int i, start_len;
43 const char *start;
44 char special = 0;
45
46 if (!len) {
47 return;
48 }
49
50 if (len < 0) {
51 len = strlen(text);
52 }
53
54 start = text;
55 start_len = 0;
56 for (i = 0; i < len; ++i) {
57 switch (text[i]) {
58 case '\n':
59 case '\t':
60 case '\"':
61 case '\\':
62 special = text[i];
63 break;
64 default:
65 ++start_len;
66 break;
67 }
68
69 if (special) {
70 ly_write(out, start, start_len);
71 switch (special) {
72 case '\n':
73 ly_write(out, "\\n", 2);
74 break;
75 case '\t':
76 ly_write(out, "\\t", 2);
77 break;
78 case '\"':
79 ly_write(out, "\\\"", 2);
80 break;
81 case '\\':
82 ly_write(out, "\\\\", 2);
83 break;
84 }
85
86 start += start_len + 1;
87 start_len = 0;
88
89 special = 0;
90 }
91 }
92
93 ly_write(out, start, start_len);
94}
95
96static void
97ypr_open(struct lyout *out, int *flag)
98{
99 if (flag && !*flag) {
100 *flag = 1;
101 ly_print(out, " {\n");
102 }
103}
104
105static void
106ypr_close(struct ypr_ctx *ctx, int flag)
107{
108 if (flag) {
109 ly_print(ctx->out, "%*s}\n", INDENT);
110 } else {
111 ly_print(ctx->out, ";\n");
112 }
113}
114
115static void
116ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, int singleline, int closed)
117{
118 const char *s, *t;
119
120 if (singleline) {
121 ly_print(ctx->out, "%*s%s \"", INDENT, name);
122 } else {
123 ly_print(ctx->out, "%*s%s\n", INDENT, name);
124 LEVEL++;
125
126 ly_print(ctx->out, "%*s\"", INDENT);
127 }
128 t = text;
129 while ((s = strchr(t, '\n'))) {
130 ypr_encode(ctx->out, t, s - t);
131 ly_print(ctx->out, "\n");
132 t = s + 1;
133 if (*t != '\n') {
134 ly_print(ctx->out, "%*s ", INDENT);
135 }
136 }
137
138 ypr_encode(ctx->out, t, strlen(t));
139 if (closed) {
140 ly_print(ctx->out, "\";\n");
141 } else {
142 ly_print(ctx->out, "\"");
143 }
144 if (!singleline) {
145 LEVEL--;
146 }
147}
148
149static void
Radek Krejci693262f2019-04-29 15:23:20 +0200150yprp_stmt(struct ypr_ctx *ctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200151{
152 struct lysp_stmt *childstmt;
153 const char *s, *t;
154
155 if (stmt->arg) {
156 if (stmt->flags) {
157 ly_print(ctx->out, "%*s%s\n", INDENT, stmt->stmt);
158 LEVEL++;
159 ly_print(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
160 t = stmt->arg;
161 while ((s = strchr(t, '\n'))) {
162 ypr_encode(ctx->out, t, s - t);
163 ly_print(ctx->out, "\n");
164 t = s + 1;
165 if (*t != '\n') {
166 ly_print(ctx->out, "%*s ", INDENT);
167 }
168 }
169 LEVEL--;
170 ypr_encode(ctx->out, t, strlen(t));
171 ly_print(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
172 } else {
173 ly_print(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
174 }
175 } else {
176 ly_print(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
177 }
178
179 if (stmt->child) {
180 LEVEL++;
181 LY_LIST_FOR(stmt->child, childstmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200182 yprp_stmt(ctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200183 }
184 LEVEL--;
185 ly_print(ctx->out, "%*s}\n", INDENT);
186 }
187}
188
189/**
190 * @param[in] count Number of extensions to print, 0 to print them all.
191 */
192static void
Radek Krejci693262f2019-04-29 15:23:20 +0200193yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
Radek Krejcid3ca0632019-04-16 16:54:54 +0200194 struct lysp_ext_instance *ext, int *flag, unsigned int count)
195{
196 unsigned int u;
197 struct lysp_stmt *stmt;
198
199 if (!count && ext) {
200 count = LY_ARRAY_SIZE(ext);
201 }
202 LY_ARRAY_FOR(ext, u) {
203 if (!count) {
204 break;
205 }
206 if (ext->insubstmt == substmt && ext->insubstmt_index == substmt_index) {
207 ypr_open(ctx->out, flag);
208 if (ext[u].argument) {
209 ly_print(ctx->out, "%*s%s %s%s", INDENT, ext[u].name, ext[u].argument, ext[u].child ? " {\n" : ";\n");
210 } else {
211 ly_print(ctx->out, "%*s%s%s", INDENT, ext[u].name, ext[u].child ? " {\n" : ";\n");
212 }
213
214 if (ext[u].child) {
215 LEVEL++;
216 LY_LIST_FOR(ext[u].child, stmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200217 yprp_stmt(ctx, stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200218 }
219 LEVEL--;
220 ly_print(ctx->out, "%*s}\n", INDENT);
221 }
222 }
223 count--;
224 }
225}
226
Radek Krejci693262f2019-04-29 15:23:20 +0200227/**
228 * @param[in] count Number of extensions to print, 0 to print them all.
229 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200230static void
Radek Krejci693262f2019-04-29 15:23:20 +0200231yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
232 struct lysc_ext_instance *ext, int *flag, unsigned int count)
233{
234 unsigned int u;
235
236 if (!count && ext) {
237 count = LY_ARRAY_SIZE(ext);
238 }
239 LY_ARRAY_FOR(ext, u) {
240 if (!count) {
241 break;
242 }
243 /* TODO compiled extensions */
244 (void) ctx;
245 (void) substmt;
246 (void) substmt_index;
247 (void) flag;
248
249 count--;
250 }
251}
252
253static void
254ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200255{
256 unsigned int u;
257 int extflag = 0;
258
259 if (!text) {
260 /* nothing to print */
261 return;
262 }
263
264 if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) {
265 ly_print(ctx->out, "%*s%s %s", INDENT, ext_substmt_info[substmt].name, text);
266 } else {
267 ypr_text(ctx, ext_substmt_info[substmt].name, text,
268 (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, 0);
269 }
270
271 LEVEL++;
272 LY_ARRAY_FOR(ext, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200273 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 +0200274 continue;
275 }
Radek Krejci693262f2019-04-29 15:23:20 +0200276 if (ctx->schema == YPR_PARSED) {
277 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance*)ext)[u], &extflag, 1);
278 } else {
279 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance*)ext)[u], &extflag, 1);
280 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200281 }
282 LEVEL--;
283 ypr_close(ctx, extflag);
284}
285
286static void
Radek Krejci693262f2019-04-29 15:23:20 +0200287ypr_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 +0200288{
289 char *str;
290
291 if (asprintf(&str, "%u", attr_value) == -1) {
292 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200293 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200294 return;
295 }
296 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200297 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200298 free(str);
299}
300
301static void
Radek Krejci693262f2019-04-29 15:23:20 +0200302ypr_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 +0200303{
304 char *str;
305
306 if (asprintf(&str, "%d", attr_value) == -1) {
307 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200308 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200309 return;
310 }
311 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200312 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200313 free(str);
314}
315
316static void
Radek Krejci693262f2019-04-29 15:23:20 +0200317yprp_revision(struct ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200318{
319 if (rev->dsc || rev->ref || rev->exts) {
320 ly_print(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
321 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200322 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0);
323 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts);
324 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200325 LEVEL--;
326 ly_print(ctx->out, "%*s}\n", INDENT);
327 } else {
328 ly_print(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
329 }
330}
331
332static void
Radek Krejci693262f2019-04-29 15:23:20 +0200333ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200334{
335 if (flags & LYS_MAND_MASK) {
336 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200337 ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200338 }
339}
340
341static void
Radek Krejci693262f2019-04-29 15:23:20 +0200342ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200343{
344 if (flags & LYS_CONFIG_MASK) {
345 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200346 ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200347 }
348}
349
350static void
Radek Krejci693262f2019-04-29 15:23:20 +0200351ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200352{
353 const char *status = NULL;
354
355 if (flags & LYS_STATUS_CURR) {
356 ypr_open(ctx->out, flag);
357 status = "current";
358 } else if (flags & LYS_STATUS_DEPRC) {
359 ypr_open(ctx->out, flag);
360 status = "deprecated";
361 } else if (flags & LYS_STATUS_OBSLT) {
362 ypr_open(ctx->out, flag);
363 status = "obsolete";
364 }
Radek Krejci693262f2019-04-29 15:23:20 +0200365
366 ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200367}
368
369static void
Radek Krejci693262f2019-04-29 15:23:20 +0200370ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200371{
372 if (dsc) {
373 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200374 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200375 }
376}
377
378static void
Radek Krejci693262f2019-04-29 15:23:20 +0200379ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200380{
381 if (ref) {
382 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200383 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200384 }
385}
386
387static void
Radek Krejci693262f2019-04-29 15:23:20 +0200388yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200389{
390 unsigned int u;
391 int extflag;
392
393 LY_ARRAY_FOR(iff, u) {
394 ypr_open(ctx->out, flag);
395 extflag = 0;
396
397 ly_print(ctx->out, "%*sif-feature \"%s\"", INDENT, iff[u]);
398
399 /* extensions */
400 LEVEL++;
401 LY_ARRAY_FOR(exts, u) {
402 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
403 continue;
404 }
Radek Krejci693262f2019-04-29 15:23:20 +0200405 yprp_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200406 }
407 LEVEL--;
408 ypr_close(ctx, extflag);
409 }
410}
411
412static void
Radek Krejci693262f2019-04-29 15:23:20 +0200413yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f)
414{
415 int brackets_flag = *index_e;
416 uint8_t op;
417
418 op = lysc_iff_getop(feat->expr, *index_e);
419 (*index_e)++;
420
421 switch (op) {
422 case LYS_IFF_F:
423 if (ctx->module == feat->features[*index_f]->module) {
424 ly_print(ctx->out, "%s", feat->features[*index_f]->name);
425 } else {
426 ly_print(ctx->out, "%s:%s", feat->features[*index_f]->module->prefix, feat->features[*index_f]->name);
427 }
428 (*index_f)++;
429 break;
430 case LYS_IFF_NOT:
431 ly_print(ctx->out, "not ");
432 yprc_iffeature(ctx, feat, index_e, index_f);
433 break;
434 case LYS_IFF_AND:
435 if (brackets_flag) {
436 /* AND need brackets only if previous op was not */
437 if (*index_e < 2 || lysc_iff_getop(feat->expr, *index_e - 2) != LYS_IFF_NOT) {
438 brackets_flag = 0;
439 }
440 }
441 /* falls through */
442 case LYS_IFF_OR:
443 if (brackets_flag) {
444 ly_print(ctx->out, "(");
445 }
446 yprc_iffeature(ctx, feat, index_e, index_f);
447 ly_print(ctx->out, " %s ", op == LYS_IFF_OR ? "or" : "and");
448 yprc_iffeature(ctx, feat, index_e, index_f);
449 if (brackets_flag) {
450 ly_print(ctx->out, ")");
451 }
452 }
453}
454
455static void
456yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
457{
458 unsigned int u;
459 int extflag;
460
461 LY_ARRAY_FOR(iff, u) {
462 int index_e = 0, index_f = 0;
463
464 ypr_open(ctx->out, flag);
465 extflag = 0;
466
Radek Krejci989e53b2019-04-30 09:51:09 +0200467 ly_print(ctx->out, "%*sif-feature \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200468 yprc_iffeature(ctx, iff, &index_e, &index_f);
Radek Krejci989e53b2019-04-30 09:51:09 +0200469 ly_print(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200470
471 /* extensions */
472 LEVEL++;
473 LY_ARRAY_FOR(exts, u) {
474 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
475 continue;
476 }
477 yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
478 }
479 LEVEL--;
480 ypr_close(ctx, extflag);
481 }
482}
483
484static void
485yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200486{
487 int flag = 0, flag2 = 0;
488 unsigned int i;
489
490 ly_print(ctx->out, "%*sextension %s", INDENT, ext->name);
491 LEVEL++;
492
493 if (ext->exts) {
Radek Krejci693262f2019-04-29 15:23:20 +0200494 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200495 }
496
497 if (ext->argument) {
498 ypr_open(ctx->out, &flag);
499 ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument);
500 if (ext->exts) {
501 LEVEL++;
502 i = -1;
503 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 +0200504 yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200505 }
506 LEVEL--;
507 }
508 if ((ext->flags & LYS_YINELEM_MASK) ||
509 (ext->exts && lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YINELEM) != LY_ARRAY_SIZE(ext->exts))) {
510 ypr_open(ctx->out, &flag2);
Radek Krejci693262f2019-04-29 15:23:20 +0200511 ypr_substmt(ctx, LYEXT_SUBSTMT_YINELEM, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200512 }
513 ypr_close(ctx, flag2);
514 }
515
Radek Krejci693262f2019-04-29 15:23:20 +0200516 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200517 ypr_description(ctx, ext->dsc, ext->exts, &flag);
518 ypr_reference(ctx, ext->ref, ext->exts, &flag);
519
520 LEVEL--;
521 ypr_close(ctx, flag);
522}
523
524static void
Radek Krejci693262f2019-04-29 15:23:20 +0200525yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200526{
527 int flag = 0;
528
529 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
530 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200531 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
532 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
533 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200534 ypr_description(ctx, feat->dsc, feat->exts, &flag);
535 ypr_reference(ctx, feat->ref, feat->exts, &flag);
536 LEVEL--;
537 ypr_close(ctx, flag);
538}
539
540static void
Radek Krejci693262f2019-04-29 15:23:20 +0200541yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat)
542{
543 int flag = 0;
544
545 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
546 LEVEL++;
547 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
548 yprc_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
549 ypr_status(ctx, feat->flags, feat->exts, &flag);
550 ypr_description(ctx, feat->dsc, feat->exts, &flag);
551 ypr_reference(ctx, feat->ref, feat->exts, &flag);
552 LEVEL--;
553 ypr_close(ctx, flag);
554}
555
556static void
557yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200558{
559 int flag = 0;
560 unsigned int u;
561
562 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
563 LEVEL++;
564
Radek Krejci693262f2019-04-29 15:23:20 +0200565 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
566 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200567
568 LY_ARRAY_FOR(ident->bases, u) {
569 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200570 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200571 }
572
Radek Krejci693262f2019-04-29 15:23:20 +0200573 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200574 ypr_description(ctx, ident->dsc, ident->exts, &flag);
575 ypr_reference(ctx, ident->ref, ident->exts, &flag);
576
577 LEVEL--;
578 ypr_close(ctx, flag);
579}
580
581static void
Radek Krejci693262f2019-04-29 15:23:20 +0200582yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident)
583{
584 int flag = 0;
585 unsigned int u;
586
587 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
588 LEVEL++;
589
590 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
591 yprc_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
592
593 LY_ARRAY_FOR(ident->derived, u) {
594 ypr_open(ctx->out, &flag);
595 if (ctx->module != ident->derived[u]->module) {
596 ly_print(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
597 } else {
598 ly_print(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
599 }
600 }
601
602 ypr_status(ctx, ident->flags, ident->exts, &flag);
603 ypr_description(ctx, ident->dsc, ident->exts, &flag);
604 ypr_reference(ctx, ident->ref, ident->exts, &flag);
605
606 LEVEL--;
607 ypr_close(ctx, flag);
608}
609
610static void
611yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200612{
613 int inner_flag = 0;
614
615 if (!restr) {
616 return;
617 }
618
619 ypr_open(ctx->out, flag);
620 ly_print(ctx->out, "%*s%s \"", INDENT, name);
621 ypr_encode(ctx->out, (restr->arg[0] != 0x15 && restr->arg[0] != 0x06) ? restr->arg : &restr->arg[1], -1);
622 ly_print(ctx->out, "\"");
623
624 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200625 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200626 if (restr->arg[0] == 0x15) {
627 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
628 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200629 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200630 }
631 if (restr->emsg) {
632 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200633 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200634 }
635 if (restr->eapptag) {
636 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200637 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200638 }
Radek Krejci693262f2019-04-29 15:23:20 +0200639 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
640 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
641
Radek Krejcid3ca0632019-04-16 16:54:54 +0200642 LEVEL--;
643 ypr_close(ctx, inner_flag);
644}
645
646static void
Radek Krejci693262f2019-04-29 15:23:20 +0200647yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag)
648{
649 int inner_flag = 0;
650
651 ypr_open(ctx->out, flag);
652 ly_print(ctx->out, "%*smust \"", INDENT);
653 ypr_encode(ctx->out, must->cond->expr, -1);
654 ly_print(ctx->out, "\"");
655
656 LEVEL++;
657 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0);
658 if (must->emsg) {
659 ypr_open(ctx->out, &inner_flag);
660 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, must->emsg, must->exts);
661 }
662 if (must->eapptag) {
663 ypr_open(ctx->out, &inner_flag);
664 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, must->eapptag, must->exts);
665 }
666 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
667 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
668
669 LEVEL--;
670 ypr_close(ctx, inner_flag);
671}
672
673static void
674yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag)
675{
676 int inner_flag = 0;
677 unsigned int u;
678
679 ypr_open(ctx->out, flag);
680 ly_print(ctx->out, "%*s%s \"", (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY)? "length" : "range", INDENT);
681 LY_ARRAY_FOR(range->parts, u) {
682 if (u > 0) {
683 ly_print(ctx->out, " | ");
684 }
685 if (range->parts[u].max_64 == range->parts[u].min_64) {
686 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
687 ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64);
688 } else { /* signed values */
689 ly_print(ctx->out, "%"PRId64, range->parts[u].max_64);
690 }
691 } else {
692 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
693 ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
694 } else { /* signed values */
695 ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64);
696 }
697 }
698 }
699 ly_print(ctx->out, "\"");
700
701 LEVEL++;
702 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0);
703 if (range->emsg) {
704 ypr_open(ctx->out, &inner_flag);
705 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts);
706 }
707 if (range->eapptag) {
708 ypr_open(ctx->out, &inner_flag);
709 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts);
710 }
711 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
712 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
713
714 LEVEL--;
715 ypr_close(ctx, inner_flag);
716}
717
718static void
719yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag)
720{
721 int inner_flag = 0;
722
723 ypr_open(ctx->out, flag);
724 ly_print(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200725 ypr_encode(ctx->out, pattern->expr, -1);
Radek Krejci693262f2019-04-29 15:23:20 +0200726 ly_print(ctx->out, "\"");
727
728 LEVEL++;
729 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0);
730 if (pattern->inverted) {
731 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
732 ypr_open(ctx->out, &inner_flag);
733 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts);
734 }
735 if (pattern->emsg) {
736 ypr_open(ctx->out, &inner_flag);
737 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts);
738 }
739 if (pattern->eapptag) {
740 ypr_open(ctx->out, &inner_flag);
741 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts);
742 }
743 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
744 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
745
746 LEVEL--;
747 ypr_close(ctx, inner_flag);
748}
749
750static void
751yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200752{
753 int inner_flag = 0;
754
755 if (!when) {
756 return;
757 }
758 ypr_open(ctx->out, flag);
759
760 ly_print(ctx->out, "%*swhen \"", INDENT);
761 ypr_encode(ctx->out, when->cond, -1);
762 ly_print(ctx->out, "\"");
763
764 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200765 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200766 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
767 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
768 LEVEL--;
769 ypr_close(ctx, inner_flag);
770}
771
772static void
Radek Krejci693262f2019-04-29 15:23:20 +0200773yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag)
774{
775 int inner_flag = 0;
776
777 if (!when) {
778 return;
779 }
780 ypr_open(ctx->out, flag);
781
782 ly_print(ctx->out, "%*swhen \"", INDENT);
783 ypr_encode(ctx->out, when->cond->expr, -1);
784 ly_print(ctx->out, "\"");
785
786 LEVEL++;
787 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
788 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
789 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
790 LEVEL--;
791 ypr_close(ctx, inner_flag);
792}
793
794static void
795yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200796{
797 unsigned int u;
798 int inner_flag;
799
800 LY_ARRAY_FOR(items, u) {
801 ypr_open(ctx->out, flag);
802 ly_print(ctx->out, "%*s%s \"", INDENT, type == LY_TYPE_BITS ? "bit" : "enum");
803 ypr_encode(ctx->out, items[u].name, -1);
804 ly_print(ctx->out, "\"");
805 inner_flag = 0;
806 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200807 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
808 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200809 if (items[u].flags & LYS_SET_VALUE) {
810 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200811 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200812 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200813 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200814 }
815 }
Radek Krejci693262f2019-04-29 15:23:20 +0200816 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200817 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
818 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
819 LEVEL--;
820 ypr_close(ctx, inner_flag);
821 }
822}
823
824static void
Radek Krejci693262f2019-04-29 15:23:20 +0200825yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200826{
827 unsigned int u;
828 int flag = 0;
829
830 ly_print(ctx->out, "%*stype %s", INDENT, type->name);
831 LEVEL++;
832
Radek Krejci693262f2019-04-29 15:23:20 +0200833 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200834
Radek Krejci693262f2019-04-29 15:23:20 +0200835 yprp_restr(ctx, type->range, "range", &flag);
836 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200837 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200838 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200839 }
Radek Krejci693262f2019-04-29 15:23:20 +0200840 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
841 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200842
843 if (type->path) {
844 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200845 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200846 }
847 if (type->flags & LYS_SET_REQINST) {
848 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200849 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200850 }
851 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200852 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200853 }
854 LY_ARRAY_FOR(type->bases, u) {
855 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200856 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200857 }
858 LY_ARRAY_FOR(type->types, u) {
859 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200860 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200861 }
862
863 LEVEL--;
864 ypr_close(ctx, flag);
865}
866
867static void
Radek Krejci693262f2019-04-29 15:23:20 +0200868yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
869{
870 unsigned int u;
871 int flag = 0;
872
873 ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
874 LEVEL++;
875
876 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
877 if (type->dflt) {
878 ypr_open(ctx->out, &flag);
879 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, type->dflt, type->exts);
880 }
881
882 switch(type->basetype) {
883 case LY_TYPE_BINARY: {
884 struct lysc_type_bin *bin = (struct lysc_type_bin*)type;
885 yprc_range(ctx, bin->length, type->basetype, &flag);
886 break;
887 }
888 case LY_TYPE_UINT8:
889 case LY_TYPE_UINT16:
890 case LY_TYPE_UINT32:
891 case LY_TYPE_UINT64:
892 case LY_TYPE_INT8:
893 case LY_TYPE_INT16:
894 case LY_TYPE_INT32:
895 case LY_TYPE_INT64: {
896 struct lysc_type_num *num = (struct lysc_type_num*)type;
897 yprc_range(ctx, num->range, type->basetype, &flag);
898 break;
899 }
900 case LY_TYPE_STRING: {
901 struct lysc_type_str *str = (struct lysc_type_str*)type;
902 yprc_range(ctx, str->length, type->basetype, &flag);
903 LY_ARRAY_FOR(str->patterns, u) {
904 yprc_pattern(ctx, str->patterns[u], &flag);
905 }
906 break;
907 }
908 case LY_TYPE_BITS:
909 case LY_TYPE_ENUM: {
910 /* bits and enums structures are compatible */
911 struct lysc_type_bits *bits = (struct lysc_type_bits*)type;
912 LY_ARRAY_FOR(bits->bits, u) {
913 struct lysc_type_bitenum_item *item = &bits->bits[u];
914 int inner_flag = 0;
915
916 ypr_open(ctx->out, &flag);
917 ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
918 ypr_encode(ctx->out, item->name, -1);
919 ly_print(ctx->out, "\"");
920 LEVEL++;
921 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
922 yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag);
923 if (type->basetype == LY_TYPE_BITS) {
924 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
925 } else { /* LY_TYPE_ENUM */
926 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
927 }
928 ypr_status(ctx, item->flags, item->exts, &inner_flag);
929 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
930 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
931 LEVEL--;
932 ypr_close(ctx, inner_flag);
933 }
934 break;
935 }
936 case LY_TYPE_BOOL:
937 case LY_TYPE_EMPTY:
938 /* nothing to do */
939 break;
940 case LY_TYPE_DEC64: {
941 struct lysc_type_dec *dec = (struct lysc_type_dec*)type;
942 ypr_open(ctx->out, &flag);
943 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag);
944 yprc_range(ctx, dec->range, dec->basetype, &flag);
945 break;
946 }
947 case LY_TYPE_IDENT: {
948 struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type;
949 LY_ARRAY_FOR(ident->bases, u) {
950 ypr_open(ctx->out, &flag);
951 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
952 }
953 break;
954 }
955 case LY_TYPE_INST: {
956 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type;
957 ypr_open(ctx->out, &flag);
958 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
959 break;
960 }
961 case LY_TYPE_LEAFREF: {
962 struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type;
963 ypr_open(ctx->out, &flag);
964 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts);
965 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
966 yprc_type(ctx, lr->realtype);
967 break;
968 }
969 case LY_TYPE_UNION: {
970 struct lysc_type_union *un = (struct lysc_type_union*)type;
971 LY_ARRAY_FOR(un->types, u) {
972 ypr_open(ctx->out, &flag);
973 yprc_type(ctx, un->types[u]);
974 }
975 break;
976 }
977 default:
978 LOGINT(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200979 ctx->out->status = LY_EINT;
Radek Krejci693262f2019-04-29 15:23:20 +0200980 }
981
982 LEVEL--;
983 ypr_close(ctx, flag);
984}
985
986static void
987yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200988{
Radek Krejci56cc0872019-04-30 09:22:27 +0200989 LYOUT_CHECK(ctx->out);
990
Radek Krejcid3ca0632019-04-16 16:54:54 +0200991 ly_print(ctx->out, "\n%*stypedef %s {\n", INDENT, tpdf->name);
992 LEVEL++;
993
Radek Krejci693262f2019-04-29 15:23:20 +0200994 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200995
Radek Krejci693262f2019-04-29 15:23:20 +0200996 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200997
998 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +0200999 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001000 }
1001 if (tpdf->dflt) {
Radek Krejci693262f2019-04-29 15:23:20 +02001002 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001003 }
1004
Radek Krejci693262f2019-04-29 15:23:20 +02001005 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001006 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
1007 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
1008
1009 LEVEL--;
1010 ly_print(ctx->out, "%*s}\n", INDENT);
1011}
1012
Radek Krejci693262f2019-04-29 15:23:20 +02001013static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node);
1014static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node);
1015static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001016
1017static void
Radek Krejci693262f2019-04-29 15:23:20 +02001018yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001019{
1020 unsigned int u;
1021 int flag = 0;
1022 struct lysp_node *data;
1023
Radek Krejci56cc0872019-04-30 09:22:27 +02001024 LYOUT_CHECK(ctx->out);
1025
Radek Krejcid3ca0632019-04-16 16:54:54 +02001026 ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
1027 LEVEL++;
1028
Radek Krejci693262f2019-04-29 15:23:20 +02001029 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
1030 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +02001031 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1032 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001033
1034 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001035 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001036 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001037 }
1038
1039 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001040 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001041 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001042 }
1043
1044 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001045 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001046 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001047 }
1048
1049 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001050 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001051 }
1052
1053 LEVEL--;
1054 ypr_close(ctx, flag);
1055}
1056
1057static void
Radek Krejci693262f2019-04-29 15:23:20 +02001058yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001059{
1060 unsigned int u;
1061 struct lysp_node *data;
1062
1063 if (!inout->nodetype) {
1064 /* nodetype not set -> input/output is empty */
1065 return;
1066 }
1067 ypr_open(ctx->out, flag);
1068
1069 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1070 LEVEL++;
1071
Radek Krejci693262f2019-04-29 15:23:20 +02001072 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001073 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001074 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001075 }
1076 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001077 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001078 }
1079 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001080 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001081 }
1082
1083 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001084 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001085 }
1086
1087 LEVEL--;
1088 ypr_close(ctx, 1);
1089}
1090
1091static void
Radek Krejci693262f2019-04-29 15:23:20 +02001092yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1093{
1094 unsigned int u;
1095 struct lysc_node *data;
1096
1097 if (!inout->data) {
1098 /* input/output is empty */
1099 return;
1100 }
1101 ypr_open(ctx->out, flag);
1102
1103 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1104 LEVEL++;
1105
1106 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1107 LY_ARRAY_FOR(inout->musts, u) {
1108 yprc_must(ctx, &inout->musts[u], NULL);
1109 }
1110
1111 LY_LIST_FOR(inout->data, data) {
1112 yprc_node(ctx, data);
1113 }
1114
1115 LEVEL--;
1116 ypr_close(ctx, 1);
1117}
1118
1119static void
1120yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001121{
1122 unsigned int u;
1123 int flag = 0;
1124 struct lysp_node *data;
1125
Radek Krejci56cc0872019-04-30 09:22:27 +02001126 LYOUT_CHECK(ctx->out);
1127
Radek Krejcid3ca0632019-04-16 16:54:54 +02001128 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1129
1130 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001131 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1132 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001133
1134 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001135 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001136 }
Radek Krejci693262f2019-04-29 15:23:20 +02001137 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001138 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1139 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1140
1141 LY_ARRAY_FOR(notif->typedefs, u) {
1142 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001143 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001144 }
1145
1146 LY_ARRAY_FOR(notif->groupings, u) {
1147 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001148 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001149 }
1150
1151 LY_LIST_FOR(notif->data, data) {
1152 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001153 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001154 }
1155
1156 LEVEL--;
1157 ypr_close(ctx, flag);
1158}
1159
1160static void
Radek Krejci693262f2019-04-29 15:23:20 +02001161yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1162{
1163 unsigned int u;
1164 int flag = 0;
1165 struct lysc_node *data;
1166
Radek Krejci56cc0872019-04-30 09:22:27 +02001167 LYOUT_CHECK(ctx->out);
1168
Radek Krejci693262f2019-04-29 15:23:20 +02001169 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1170
1171 LEVEL++;
1172 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1173 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1174
1175 LY_ARRAY_FOR(notif->musts, u) {
1176 yprc_must(ctx, &notif->musts[u], &flag);
1177 }
1178 ypr_status(ctx, notif->flags, notif->exts, &flag);
1179 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1180 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1181
1182 LY_LIST_FOR(notif->data, data) {
1183 ypr_open(ctx->out, &flag);
1184 yprc_node(ctx, data);
1185 }
1186
1187 LEVEL--;
1188 ypr_close(ctx, flag);
1189}
1190
1191static void
1192yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001193{
1194 unsigned int u;
1195 int flag = 0;
1196
Radek Krejci56cc0872019-04-30 09:22:27 +02001197 LYOUT_CHECK(ctx->out);
1198
Radek Krejcid3ca0632019-04-16 16:54:54 +02001199 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1200
1201 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001202 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1203 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1204 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001205 ypr_description(ctx, action->dsc, action->exts, &flag);
1206 ypr_reference(ctx, action->ref, action->exts, &flag);
1207
1208 LY_ARRAY_FOR(action->typedefs, u) {
1209 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001210 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001211 }
1212
1213 LY_ARRAY_FOR(action->groupings, u) {
1214 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001215 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001216 }
1217
Radek Krejci693262f2019-04-29 15:23:20 +02001218 yprp_inout(ctx, &action->input, &flag);
1219 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001220
1221 LEVEL--;
1222 ypr_close(ctx, flag);
1223}
1224
1225static void
Radek Krejci693262f2019-04-29 15:23:20 +02001226yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1227{
1228 int flag = 0;
1229
Radek Krejci56cc0872019-04-30 09:22:27 +02001230 LYOUT_CHECK(ctx->out);
1231
Radek Krejci693262f2019-04-29 15:23:20 +02001232 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1233
1234 LEVEL++;
1235 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1236 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1237 ypr_status(ctx, action->flags, action->exts, &flag);
1238 ypr_description(ctx, action->dsc, action->exts, &flag);
1239 ypr_reference(ctx, action->ref, action->exts, &flag);
1240
1241 yprc_inout(ctx, action, &action->input, &flag);
1242 yprc_inout(ctx, action, &action->output, &flag);
1243
1244 LEVEL--;
1245 ypr_close(ctx, flag);
1246}
1247
1248static void
1249yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001250{
1251 ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
1252 LEVEL++;
1253
Radek Krejci693262f2019-04-29 15:23:20 +02001254 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1255 yprp_when(ctx, node->when, flag);
1256 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001257}
1258
1259static void
Radek Krejci693262f2019-04-29 15:23:20 +02001260yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001261{
Radek Krejci693262f2019-04-29 15:23:20 +02001262 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001263
Radek Krejci693262f2019-04-29 15:23:20 +02001264 ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
1265 LEVEL++;
1266
1267 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1268 LY_ARRAY_FOR(node->when, u) {
1269 yprc_when(ctx, node->when[u], flag);
1270 }
1271 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1272}
1273
1274/* macr oto unify the code */
1275#define YPR_NODE_COMMON2 \
1276 ypr_config(ctx, node->flags, node->exts, flag); \
1277 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1278 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1279 } \
1280 ypr_status(ctx, node->flags, node->exts, flag); \
1281 ypr_description(ctx, node->dsc, node->exts, flag); \
1282 ypr_reference(ctx, node->ref, node->exts, flag)
1283
1284static void
1285yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1286{
1287 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001288}
1289
1290static void
Radek Krejci693262f2019-04-29 15:23:20 +02001291yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1292{
1293 YPR_NODE_COMMON2;
1294}
1295
1296#undef YPR_NODE_COMMON2
1297
1298static void
1299yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001300{
1301 unsigned int u;
1302 int flag = 0;
1303 struct lysp_node *child;
1304 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1305
Radek Krejci693262f2019-04-29 15:23:20 +02001306 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001307
1308 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001309 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001310 }
1311 if (cont->presence) {
1312 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001313 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001314 }
1315
Radek Krejci693262f2019-04-29 15:23:20 +02001316 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001317
1318 LY_ARRAY_FOR(cont->typedefs, u) {
1319 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001320 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001321 }
1322
1323 LY_ARRAY_FOR(cont->groupings, u) {
1324 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001325 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001326 }
1327
1328 LY_LIST_FOR(cont->child, child) {
1329 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001330 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001331 }
1332
1333 LY_ARRAY_FOR(cont->actions, u) {
1334 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001335 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001336 }
1337
1338 LY_ARRAY_FOR(cont->notifs, u) {
1339 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001340 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001341 }
1342
1343 LEVEL--;
1344 ypr_close(ctx, flag);
1345}
1346
1347static void
Radek Krejci693262f2019-04-29 15:23:20 +02001348yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1349{
1350 unsigned int u;
1351 int flag = 0;
1352 struct lysc_node *child;
1353 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1354
1355 yprc_node_common1(ctx, node, &flag);
1356
1357 LY_ARRAY_FOR(cont->musts, u) {
1358 yprc_must(ctx, &cont->musts[u], &flag);
1359 }
1360 if (cont->flags & LYS_PRESENCE) {
1361 ypr_open(ctx->out, &flag);
1362 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1363 }
1364
1365 yprc_node_common2(ctx, node, &flag);
1366
1367 LY_LIST_FOR(cont->child, child) {
1368 ypr_open(ctx->out, &flag);
1369 yprc_node(ctx, child);
1370 }
1371
1372 LY_ARRAY_FOR(cont->actions, u) {
1373 ypr_open(ctx->out, &flag);
1374 yprc_action(ctx, &cont->actions[u]);
1375 }
1376
1377 LY_ARRAY_FOR(cont->notifs, u) {
1378 ypr_open(ctx->out, &flag);
1379 yprc_notification(ctx, &cont->notifs[u]);
1380 }
1381
1382 LEVEL--;
1383 ypr_close(ctx, flag);
1384}
1385
1386static void
1387yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1388{
1389 int flag = 0;
1390 struct lysp_node *child;
1391 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1392
1393 yprp_node_common1(ctx, node, &flag);
1394 yprp_node_common2(ctx, node, &flag);
1395
1396 LY_LIST_FOR(cas->child, child) {
1397 ypr_open(ctx->out, &flag);
1398 yprp_node(ctx, child);
1399 }
1400
1401 LEVEL--;
1402 ypr_close(ctx, flag);
1403}
1404
1405static void
1406yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1407{
1408 int flag = 0;
1409 struct lysc_node *child;
1410
1411 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1412 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1413
1414 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1415 ypr_open(ctx->out, &flag);
1416 yprc_node(ctx, child);
1417 }
1418
1419 LEVEL--;
1420 ypr_close(ctx, flag);
1421}
1422
1423static void
1424yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001425{
1426 int flag = 0;
1427 struct lysp_node *child;
1428 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1429
Radek Krejci693262f2019-04-29 15:23:20 +02001430 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001431
1432 if (choice->dflt) {
1433 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001434 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001435 }
1436
Radek Krejci693262f2019-04-29 15:23:20 +02001437 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001438
1439 LY_LIST_FOR(choice->child, child) {
1440 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001441 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001442 }
1443
1444 LEVEL--;
1445 ypr_close(ctx, flag);
1446}
1447
1448static void
Radek Krejci693262f2019-04-29 15:23:20 +02001449yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1450{
1451 int flag = 0;
1452 struct lysc_node_case *cs;
1453 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1454
1455 yprc_node_common1(ctx, node, &flag);
1456
1457 if (choice->dflt) {
1458 ypr_open(ctx->out, &flag);
1459 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1460 }
1461
1462 yprc_node_common2(ctx, node, &flag);
1463
1464 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1465 ypr_open(ctx->out, &flag);
1466 yprc_case(ctx, cs);
1467 }
1468
1469 LEVEL--;
1470 ypr_close(ctx, flag);
1471}
1472
1473static void
1474yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001475{
1476 unsigned int u;
1477 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1478
Radek Krejci693262f2019-04-29 15:23:20 +02001479 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001480
Radek Krejci693262f2019-04-29 15:23:20 +02001481 yprp_type(ctx, &leaf->type);
1482 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001483 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001484 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001485 }
Radek Krejci693262f2019-04-29 15:23:20 +02001486 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001487
Radek Krejci693262f2019-04-29 15:23:20 +02001488 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001489
1490 LEVEL--;
1491 ly_print(ctx->out, "%*s}\n", INDENT);
1492}
1493
1494static void
Radek Krejci693262f2019-04-29 15:23:20 +02001495yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1496{
1497 unsigned int u;
1498 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1499
1500 yprc_node_common1(ctx, node, NULL);
1501
1502 yprc_type(ctx, leaf->type);
1503 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1504 LY_ARRAY_FOR(leaf->musts, u) {
1505 yprc_must(ctx, &leaf->musts[u], NULL);
1506 }
1507 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
1508
1509 yprc_node_common2(ctx, node, NULL);
1510
1511 LEVEL--;
1512 ly_print(ctx->out, "%*s}\n", INDENT);
1513}
1514
1515static void
1516yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001517{
1518 unsigned int u;
1519 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1520
Radek Krejci693262f2019-04-29 15:23:20 +02001521 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001522
Radek Krejci693262f2019-04-29 15:23:20 +02001523 yprp_type(ctx, &llist->type);
1524 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001525 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001526 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001527 }
1528 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001529 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001530 }
1531
Radek Krejci693262f2019-04-29 15:23:20 +02001532 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001533
1534 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001535 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001536 }
1537 if (llist->flags & LYS_SET_MAX) {
1538 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001539 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001540 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001541 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001542 }
1543 }
1544
1545 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001546 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001547 }
1548
Radek Krejci693262f2019-04-29 15:23:20 +02001549 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001550 ypr_description(ctx, node->dsc, node->exts, NULL);
1551 ypr_reference(ctx, node->ref, node->exts, NULL);
1552
1553 LEVEL--;
1554 ly_print(ctx->out, "%*s}\n", INDENT);
1555}
1556
1557static void
Radek Krejci693262f2019-04-29 15:23:20 +02001558yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1559{
1560 unsigned int u;
1561 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1562
1563 yprc_node_common1(ctx, node, NULL);
1564
1565 yprc_type(ctx, llist->type);
1566 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1567 LY_ARRAY_FOR(llist->musts, u) {
1568 yprc_must(ctx, &llist->musts[u], NULL);
1569 }
1570 LY_ARRAY_FOR(llist->dflts, u) {
1571 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
1572 }
1573
1574 ypr_config(ctx, node->flags, node->exts, NULL);
1575
1576 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1577 if (llist->max) {
1578 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1579 } else {
1580 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1581 }
1582
1583 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1584
1585 ypr_status(ctx, node->flags, node->exts, NULL);
1586 ypr_description(ctx, node->dsc, node->exts, NULL);
1587 ypr_reference(ctx, node->ref, node->exts, NULL);
1588
1589 LEVEL--;
1590 ly_print(ctx->out, "%*s}\n", INDENT);
1591}
1592
1593static void
1594yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001595{
1596 unsigned int u;
1597 int flag = 0;
1598 struct lysp_node *child;
1599 struct lysp_node_list *list = (struct lysp_node_list *)node;
1600
Radek Krejci693262f2019-04-29 15:23:20 +02001601 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001602
1603 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001604 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001605 }
1606 if (list->key) {
1607 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001608 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001609 }
1610 LY_ARRAY_FOR(list->uniques, u) {
1611 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001612 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001613 }
1614
Radek Krejci693262f2019-04-29 15:23:20 +02001615 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001616
1617 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001618 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001619 }
1620 if (list->flags & LYS_SET_MAX) {
1621 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001622 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001623 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001624 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001625 }
1626 }
1627
1628 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001629 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001630 }
1631
Radek Krejci693262f2019-04-29 15:23:20 +02001632 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001633 ypr_description(ctx, node->dsc, node->exts, NULL);
1634 ypr_reference(ctx, node->ref, node->exts, NULL);
1635
1636 LY_ARRAY_FOR(list->typedefs, u) {
1637 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001638 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001639 }
1640
1641 LY_ARRAY_FOR(list->groupings, u) {
1642 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001643 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001644 }
1645
1646 LY_LIST_FOR(list->child, child) {
1647 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001648 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001649 }
1650
1651 LY_ARRAY_FOR(list->actions, u) {
1652 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001653 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001654 }
1655
1656 LY_ARRAY_FOR(list->notifs, u) {
1657 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001658 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001659 }
1660
1661 LEVEL--;
1662 ypr_close(ctx, flag);
1663}
1664
1665static void
Radek Krejci693262f2019-04-29 15:23:20 +02001666yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1667{
1668 unsigned int u, v;
1669 int flag = 0;
1670 struct lysc_node *child;
1671 struct lysc_node_list *list = (struct lysc_node_list *)node;
1672
1673 yprc_node_common1(ctx, node, &flag);
1674
1675 LY_ARRAY_FOR(list->musts, u) {
1676 yprc_must(ctx, &list->musts[u], NULL);
1677 }
1678 if (list->keys) {
1679 ypr_open(ctx->out, &flag);
1680 ly_print(ctx->out, "%*skey \"", INDENT);
1681 LY_ARRAY_FOR(list->keys, u) {
1682 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", list->keys[u]->name);
1683 }
1684 ypr_close(ctx, 0);
1685 }
1686 LY_ARRAY_FOR(list->uniques, u) {
1687 ypr_open(ctx->out, &flag);
1688 ly_print(ctx->out, "%*sunique \"", INDENT);
1689 LY_ARRAY_FOR(list->uniques[u], v) {
1690 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1691 }
1692 ypr_close(ctx, 0);
1693 }
1694
1695 ypr_config(ctx, node->flags, node->exts, NULL);
1696
1697 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1698 if (list->max) {
1699 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1700 } else {
1701 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1702 }
1703
1704 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1705
1706 ypr_status(ctx, node->flags, node->exts, NULL);
1707 ypr_description(ctx, node->dsc, node->exts, NULL);
1708 ypr_reference(ctx, node->ref, node->exts, NULL);
1709
1710 LY_LIST_FOR(list->child, child) {
1711 ypr_open(ctx->out, &flag);
1712 yprc_node(ctx, child);
1713 }
1714
1715 LY_ARRAY_FOR(list->actions, u) {
1716 ypr_open(ctx->out, &flag);
1717 yprc_action(ctx, &list->actions[u]);
1718 }
1719
1720 LY_ARRAY_FOR(list->notifs, u) {
1721 ypr_open(ctx->out, &flag);
1722 yprc_notification(ctx, &list->notifs[u]);
1723 }
1724
1725 LEVEL--;
1726 ypr_close(ctx, flag);
1727}
1728
1729static void
1730yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001731{
1732 unsigned int u;
1733 int flag = 0;
1734
1735 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1736 LEVEL++;
1737
Radek Krejci693262f2019-04-29 15:23:20 +02001738 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1739 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001740
1741 LY_ARRAY_FOR(refine->musts, u) {
1742 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001743 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001744 }
1745
1746 if (refine->presence) {
1747 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001748 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001749 }
1750
1751 LY_ARRAY_FOR(refine->dflts, u) {
1752 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001753 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001754 }
1755
Radek Krejci693262f2019-04-29 15:23:20 +02001756 ypr_config(ctx, refine->flags, refine->exts, &flag);
1757 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001758
1759 if (refine->flags & LYS_SET_MIN) {
1760 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001761 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001762 }
1763 if (refine->flags & LYS_SET_MAX) {
1764 ypr_open(ctx->out, &flag);
1765 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001766 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001767 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001768 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001769 }
1770 }
1771
1772 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1773 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1774
1775 LEVEL--;
1776 ypr_close(ctx, flag);
1777}
1778
1779static void
Radek Krejci693262f2019-04-29 15:23:20 +02001780yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001781{
1782 unsigned int u;
1783 struct lysp_node *child;
1784
1785 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1786 LEVEL++;
1787
Radek Krejci693262f2019-04-29 15:23:20 +02001788 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1789 yprp_when(ctx, aug->when, NULL);
1790 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1791 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001792 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1793 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1794
1795 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001796 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001797 }
1798
1799 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001800 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001801 }
1802
1803 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001804 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001805 }
1806
1807 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001808 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001809}
1810
1811
1812static void
Radek Krejci693262f2019-04-29 15:23:20 +02001813yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001814{
1815 unsigned int u;
1816 int flag = 0;
1817 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1818
Radek Krejci693262f2019-04-29 15:23:20 +02001819 yprp_node_common1(ctx, node, &flag);
1820 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001821
1822 LY_ARRAY_FOR(uses->refines, u) {
1823 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001824 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001825 }
1826
1827 LY_ARRAY_FOR(uses->augments, u) {
1828 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001829 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001830 }
1831
1832 LEVEL--;
1833 ypr_close(ctx, flag);
1834}
1835
1836static void
Radek Krejci693262f2019-04-29 15:23:20 +02001837yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001838{
1839 unsigned int u;
1840 int flag = 0;
1841 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1842
Radek Krejci693262f2019-04-29 15:23:20 +02001843 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001844
1845 LY_ARRAY_FOR(any->musts, u) {
1846 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001847 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001848 }
1849
Radek Krejci693262f2019-04-29 15:23:20 +02001850 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001851
1852 LEVEL--;
1853 ypr_close(ctx, flag);
1854}
1855
1856static void
Radek Krejci693262f2019-04-29 15:23:20 +02001857yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001858{
Radek Krejci693262f2019-04-29 15:23:20 +02001859 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001860 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001861 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001862
Radek Krejci693262f2019-04-29 15:23:20 +02001863 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001864
Radek Krejci693262f2019-04-29 15:23:20 +02001865 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001866 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001867 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001868 }
1869
Radek Krejci693262f2019-04-29 15:23:20 +02001870 yprc_node_common2(ctx, node, &flag);
1871
Radek Krejcid3ca0632019-04-16 16:54:54 +02001872 LEVEL--;
1873 ypr_close(ctx, flag);
1874}
1875
1876static void
Radek Krejci693262f2019-04-29 15:23:20 +02001877yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001878{
Radek Krejci56cc0872019-04-30 09:22:27 +02001879 LYOUT_CHECK(ctx->out);
1880
Radek Krejcid3ca0632019-04-16 16:54:54 +02001881 switch (node->nodetype) {
1882 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001883 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001884 break;
1885 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001886 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001887 break;
1888 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001889 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001890 break;
1891 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001892 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893 break;
1894 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001895 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001896 break;
1897 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001898 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001899 break;
1900 case LYS_ANYXML:
1901 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001902 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001903 break;
1904 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001905 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001906 break;
1907 default:
1908 break;
1909 }
1910}
1911
1912static void
Radek Krejci693262f2019-04-29 15:23:20 +02001913yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1914{
Radek Krejci56cc0872019-04-30 09:22:27 +02001915 LYOUT_CHECK(ctx->out);
1916
Radek Krejci693262f2019-04-29 15:23:20 +02001917 switch (node->nodetype) {
1918 case LYS_CONTAINER:
1919 yprc_container(ctx, node);
1920 break;
1921 case LYS_CHOICE:
1922 yprc_choice(ctx, node);
1923 break;
1924 case LYS_LEAF:
1925 yprc_leaf(ctx, node);
1926 break;
1927 case LYS_LEAFLIST:
1928 yprc_leaflist(ctx, node);
1929 break;
1930 case LYS_LIST:
1931 yprc_list(ctx, node);
1932 break;
1933 case LYS_ANYXML:
1934 case LYS_ANYDATA:
1935 yprc_anydata(ctx, node);
1936 break;
1937 default:
1938 break;
1939 }
1940}
1941
1942static void
1943yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001944{
1945 unsigned int u, v;
1946 struct lysp_deviate_add *add;
1947 struct lysp_deviate_rpl *rpl;
1948 struct lysp_deviate_del *del;
1949
1950 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
1951 LEVEL++;
1952
Radek Krejci693262f2019-04-29 15:23:20 +02001953 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001954 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1955 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1956
1957 LY_ARRAY_FOR(deviation->deviates, u) {
1958 ly_print(ctx->out, "%*sdeviate ", INDENT);
1959 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
1960 if (deviation->deviates[u].exts) {
1961 ly_print(ctx->out, "not-supported {\n");
1962 LEVEL++;
1963
Radek Krejci693262f2019-04-29 15:23:20 +02001964 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001965 } else {
1966 ly_print(ctx->out, "not-supported;\n");
1967 continue;
1968 }
1969 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
1970 add = (struct lysp_deviate_add*)&deviation->deviates[u];
1971 ly_print(ctx->out, "add {\n");
1972 LEVEL++;
1973
Radek Krejci693262f2019-04-29 15:23:20 +02001974 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
1975 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001976 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02001977 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001978 }
1979 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02001980 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001981 }
1982 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02001983 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001984 }
Radek Krejci693262f2019-04-29 15:23:20 +02001985 ypr_config(ctx, add->flags, add->exts, NULL);
1986 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001987 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001988 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001989 }
1990 if (add->flags & LYS_SET_MAX) {
1991 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001992 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001993 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001994 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001995 }
1996 }
1997 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
1998 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
1999 ly_print(ctx->out, "replace {\n");
2000 LEVEL++;
2001
Radek Krejci693262f2019-04-29 15:23:20 +02002002 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002003 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02002004 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002005 }
Radek Krejci693262f2019-04-29 15:23:20 +02002006 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
2007 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
2008 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
2009 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002010 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002011 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002012 }
2013 if (rpl->flags & LYS_SET_MAX) {
2014 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002015 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002016 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002017 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002018 }
2019 }
2020 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
2021 del = (struct lysp_deviate_del*)&deviation->deviates[u];
2022 ly_print(ctx->out, "delete {\n");
2023 LEVEL++;
2024
Radek Krejci693262f2019-04-29 15:23:20 +02002025 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2026 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002027 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002028 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002029 }
2030 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002031 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002032 }
2033 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002034 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002035 }
2036 }
2037
2038 LEVEL--;
2039 ypr_close(ctx, 1);
2040 }
2041
2042 LEVEL--;
2043 ypr_close(ctx, 1);
2044}
2045
Radek Krejci693262f2019-04-29 15:23:20 +02002046/**
2047 * @brief Minimal print of a schema.
2048 *
2049 * To print
2050 * a) compiled schema when it is not compiled or
2051 * b) parsed when the parsed form was already removed
2052 */
2053static LY_ERR
2054ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2055{
2056 /* module-header-stmts */
2057 if (module->version) {
2058 if (module->version) {
2059 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2060 }
2061 }
2062 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2063 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2064
2065 /* meta-stmts */
2066 if (module->org || module->contact || module->dsc || module->ref) {
2067 ly_print(ctx->out, "\n");
2068 }
2069 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2070 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2071 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2072 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2073
2074 /* revision-stmts */
2075 if (module->revision) {
2076 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2077 }
2078
2079 LEVEL--;
2080 ly_print(ctx->out, "%*s}\n", INDENT);
2081 ly_print_flush(ctx->out);
2082
2083 return LY_SUCCESS;
2084}
2085
Radek Krejcid3ca0632019-04-16 16:54:54 +02002086LY_ERR
2087yang_print_parsed(struct lyout *out, const struct lys_module *module)
2088{
2089 unsigned int u;
2090 struct lysp_node *data;
2091 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002092 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002093
2094 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2095 LEVEL++;
2096
Radek Krejci693262f2019-04-29 15:23:20 +02002097 if (!modp) {
2098 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2099 return ypr_missing_format(ctx, module);
2100 }
2101
Radek Krejcid3ca0632019-04-16 16:54:54 +02002102 /* module-header-stmts */
2103 if (module->version) {
2104 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002105 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 +02002106 }
2107 }
Radek Krejci693262f2019-04-29 15:23:20 +02002108 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2109 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002110
2111 /* linkage-stmts */
2112 LY_ARRAY_FOR(modp->imports, u) {
2113 ly_print(out, "\n%*simport %s {\n", INDENT, modp->imports[u].module->name);
2114 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002115 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2116 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002117 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002118 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002119 }
Radek Krejci693262f2019-04-29 15:23:20 +02002120 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2121 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002122 LEVEL--;
2123 ly_print(out, "%*s}\n", INDENT);
2124 }
2125 LY_ARRAY_FOR(modp->includes, u) {
2126 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
2127 ly_print(out, "\n%*sinclude %s {\n", INDENT, modp->includes[u].submodule->name);
2128 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002129 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002130 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002131 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002132 }
Radek Krejci693262f2019-04-29 15:23:20 +02002133 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2134 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002135 LEVEL--;
2136 ly_print(out, "%*s}\n", INDENT);
2137 } else {
2138 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2139 }
2140 }
2141
2142 /* meta-stmts */
2143 if (module->org || module->contact || module->dsc || module->ref) {
2144 ly_print(out, "\n");
2145 }
Radek Krejci693262f2019-04-29 15:23:20 +02002146 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2147 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2148 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2149 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002150
2151 /* revision-stmts */
2152 if (modp->revs) {
2153 ly_print(out, "\n");
2154 }
2155 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002156 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002157 }
2158 /* body-stmts */
2159 LY_ARRAY_FOR(modp->extensions, u) {
2160 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002161 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002162 }
2163 if (modp->exts) {
2164 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002165 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002166 }
2167
2168 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002169 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002170 }
2171
2172 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002173 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002174 }
2175
2176 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002177 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002178 }
2179
2180 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002181 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002182 }
2183
2184 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002185 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002186 }
2187
2188 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002189 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002190 }
2191
2192 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002193 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002194 }
2195
2196 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002197 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002198 }
2199
2200 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002201 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002202 }
2203
2204 LEVEL--;
2205 ly_print(out, "%*s}\n", INDENT);
2206 ly_print_flush(out);
2207
2208 return LY_SUCCESS;
2209}
2210
2211LY_ERR
2212yang_print_compiled(struct lyout *out, const struct lys_module *module)
2213{
Radek Krejci693262f2019-04-29 15:23:20 +02002214 unsigned int u;
2215 struct lysc_node *data;
2216 struct lysc_module *modc = module->compiled;
2217 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2218
2219 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2220 LEVEL++;
2221
2222 if (!modc) {
2223 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2224 return ypr_missing_format(ctx, module);
2225 }
2226
2227 /* module-header-stmts */
2228 if (module->version) {
2229 if (module->version) {
2230 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2231 }
2232 }
2233 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2234 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2235
2236 /* linkage-stmts */
2237 LY_ARRAY_FOR(modc->imports, u) {
2238 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2239 LEVEL++;
2240 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2241 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2242 if (modc->imports[u].module->revision) {
2243 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2244 }
2245 LEVEL--;
2246 ly_print(out, "%*s}\n", INDENT);
2247 }
2248
2249 /* meta-stmts */
2250 if (module->org || module->contact || module->dsc || module->ref) {
2251 ly_print(out, "\n");
2252 }
2253 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2254 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2255 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2256 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2257
2258 /* revision-stmts */
2259 if (module->revision) {
2260 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2261 }
2262
2263 /* body-stmts */
2264 if (modc->exts) {
2265 ly_print(out, "\n");
2266 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2267 }
2268
2269 LY_ARRAY_FOR(modc->features, u) {
2270 yprc_feature(ctx, &modc->features[u]);
2271 }
2272
2273 LY_ARRAY_FOR(modc->identities, u) {
2274 yprc_identity(ctx, &modc->identities[u]);
2275 }
2276
2277 LY_LIST_FOR(modc->data, data) {
2278 yprc_node(ctx, data);
2279 }
2280
2281 LY_ARRAY_FOR(modc->rpcs, u) {
2282 yprc_action(ctx, &modc->rpcs[u]);
2283 }
2284
2285 LY_ARRAY_FOR(modc->notifs, u) {
2286 yprc_notification(ctx, &modc->notifs[u]);
2287 }
2288
2289 LEVEL--;
2290 ly_print(out, "%*s}\n", INDENT);
2291 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002292
2293 return LY_SUCCESS;
2294}