blob: e6812479d2a7a5c26ff84712f5bb8954024989fa [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);
725 ypr_encode(ctx->out, pattern->orig, -1);
726 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 Krejci693262f2019-04-29 15:23:20 +02001035 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001036 }
1037
1038 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001039 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001040 }
1041
1042 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001043 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001044 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001045 }
1046
1047 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001048 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001049 }
1050
1051 LEVEL--;
1052 ypr_close(ctx, flag);
1053}
1054
1055static void
Radek Krejci693262f2019-04-29 15:23:20 +02001056yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001057{
1058 unsigned int u;
1059 struct lysp_node *data;
1060
1061 if (!inout->nodetype) {
1062 /* nodetype not set -> input/output is empty */
1063 return;
1064 }
1065 ypr_open(ctx->out, flag);
1066
1067 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1068 LEVEL++;
1069
Radek Krejci693262f2019-04-29 15:23:20 +02001070 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001071 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001072 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001073 }
1074 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001075 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001076 }
1077 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001078 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001079 }
1080
1081 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001082 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001083 }
1084
1085 LEVEL--;
1086 ypr_close(ctx, 1);
1087}
1088
1089static void
Radek Krejci693262f2019-04-29 15:23:20 +02001090yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1091{
1092 unsigned int u;
1093 struct lysc_node *data;
1094
1095 if (!inout->data) {
1096 /* input/output is empty */
1097 return;
1098 }
1099 ypr_open(ctx->out, flag);
1100
1101 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1102 LEVEL++;
1103
1104 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1105 LY_ARRAY_FOR(inout->musts, u) {
1106 yprc_must(ctx, &inout->musts[u], NULL);
1107 }
1108
1109 LY_LIST_FOR(inout->data, data) {
1110 yprc_node(ctx, data);
1111 }
1112
1113 LEVEL--;
1114 ypr_close(ctx, 1);
1115}
1116
1117static void
1118yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001119{
1120 unsigned int u;
1121 int flag = 0;
1122 struct lysp_node *data;
1123
Radek Krejci56cc0872019-04-30 09:22:27 +02001124 LYOUT_CHECK(ctx->out);
1125
Radek Krejcid3ca0632019-04-16 16:54:54 +02001126 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1127
1128 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001129 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1130 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001131
1132 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001133 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001134 }
Radek Krejci693262f2019-04-29 15:23:20 +02001135 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001136 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1137 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1138
1139 LY_ARRAY_FOR(notif->typedefs, u) {
1140 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001141 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001142 }
1143
1144 LY_ARRAY_FOR(notif->groupings, u) {
1145 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001146 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001147 }
1148
1149 LY_LIST_FOR(notif->data, data) {
1150 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001151 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001152 }
1153
1154 LEVEL--;
1155 ypr_close(ctx, flag);
1156}
1157
1158static void
Radek Krejci693262f2019-04-29 15:23:20 +02001159yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1160{
1161 unsigned int u;
1162 int flag = 0;
1163 struct lysc_node *data;
1164
Radek Krejci56cc0872019-04-30 09:22:27 +02001165 LYOUT_CHECK(ctx->out);
1166
Radek Krejci693262f2019-04-29 15:23:20 +02001167 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1168
1169 LEVEL++;
1170 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1171 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1172
1173 LY_ARRAY_FOR(notif->musts, u) {
1174 yprc_must(ctx, &notif->musts[u], &flag);
1175 }
1176 ypr_status(ctx, notif->flags, notif->exts, &flag);
1177 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1178 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1179
1180 LY_LIST_FOR(notif->data, data) {
1181 ypr_open(ctx->out, &flag);
1182 yprc_node(ctx, data);
1183 }
1184
1185 LEVEL--;
1186 ypr_close(ctx, flag);
1187}
1188
1189static void
1190yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001191{
1192 unsigned int u;
1193 int flag = 0;
1194
Radek Krejci56cc0872019-04-30 09:22:27 +02001195 LYOUT_CHECK(ctx->out);
1196
Radek Krejcid3ca0632019-04-16 16:54:54 +02001197 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1198
1199 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001200 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1201 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1202 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001203 ypr_description(ctx, action->dsc, action->exts, &flag);
1204 ypr_reference(ctx, action->ref, action->exts, &flag);
1205
1206 LY_ARRAY_FOR(action->typedefs, u) {
1207 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001208 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001209 }
1210
1211 LY_ARRAY_FOR(action->groupings, u) {
1212 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001213 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001214 }
1215
Radek Krejci693262f2019-04-29 15:23:20 +02001216 yprp_inout(ctx, &action->input, &flag);
1217 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001218
1219 LEVEL--;
1220 ypr_close(ctx, flag);
1221}
1222
1223static void
Radek Krejci693262f2019-04-29 15:23:20 +02001224yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1225{
1226 int flag = 0;
1227
Radek Krejci56cc0872019-04-30 09:22:27 +02001228 LYOUT_CHECK(ctx->out);
1229
Radek Krejci693262f2019-04-29 15:23:20 +02001230 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1231
1232 LEVEL++;
1233 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1234 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1235 ypr_status(ctx, action->flags, action->exts, &flag);
1236 ypr_description(ctx, action->dsc, action->exts, &flag);
1237 ypr_reference(ctx, action->ref, action->exts, &flag);
1238
1239 yprc_inout(ctx, action, &action->input, &flag);
1240 yprc_inout(ctx, action, &action->output, &flag);
1241
1242 LEVEL--;
1243 ypr_close(ctx, flag);
1244}
1245
1246static void
1247yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001248{
1249 ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
1250 LEVEL++;
1251
Radek Krejci693262f2019-04-29 15:23:20 +02001252 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1253 yprp_when(ctx, node->when, flag);
1254 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001255}
1256
1257static void
Radek Krejci693262f2019-04-29 15:23:20 +02001258yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001259{
Radek Krejci693262f2019-04-29 15:23:20 +02001260 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001261
Radek Krejci693262f2019-04-29 15:23:20 +02001262 ly_print(ctx->out, "\n%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
1263 LEVEL++;
1264
1265 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1266 LY_ARRAY_FOR(node->when, u) {
1267 yprc_when(ctx, node->when[u], flag);
1268 }
1269 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1270}
1271
1272/* macr oto unify the code */
1273#define YPR_NODE_COMMON2 \
1274 ypr_config(ctx, node->flags, node->exts, flag); \
1275 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1276 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1277 } \
1278 ypr_status(ctx, node->flags, node->exts, flag); \
1279 ypr_description(ctx, node->dsc, node->exts, flag); \
1280 ypr_reference(ctx, node->ref, node->exts, flag)
1281
1282static void
1283yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1284{
1285 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001286}
1287
1288static void
Radek Krejci693262f2019-04-29 15:23:20 +02001289yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1290{
1291 YPR_NODE_COMMON2;
1292}
1293
1294#undef YPR_NODE_COMMON2
1295
1296static void
1297yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001298{
1299 unsigned int u;
1300 int flag = 0;
1301 struct lysp_node *child;
1302 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1303
Radek Krejci693262f2019-04-29 15:23:20 +02001304 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001305
1306 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001307 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001308 }
1309 if (cont->presence) {
1310 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001311 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001312 }
1313
Radek Krejci693262f2019-04-29 15:23:20 +02001314 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001315
1316 LY_ARRAY_FOR(cont->typedefs, u) {
1317 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001318 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001319 }
1320
1321 LY_ARRAY_FOR(cont->groupings, u) {
1322 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001323 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001324 }
1325
1326 LY_LIST_FOR(cont->child, child) {
1327 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001328 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001329 }
1330
1331 LY_ARRAY_FOR(cont->actions, u) {
1332 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001333 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001334 }
1335
1336 LY_ARRAY_FOR(cont->notifs, u) {
1337 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001338 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001339 }
1340
1341 LEVEL--;
1342 ypr_close(ctx, flag);
1343}
1344
1345static void
Radek Krejci693262f2019-04-29 15:23:20 +02001346yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1347{
1348 unsigned int u;
1349 int flag = 0;
1350 struct lysc_node *child;
1351 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1352
1353 yprc_node_common1(ctx, node, &flag);
1354
1355 LY_ARRAY_FOR(cont->musts, u) {
1356 yprc_must(ctx, &cont->musts[u], &flag);
1357 }
1358 if (cont->flags & LYS_PRESENCE) {
1359 ypr_open(ctx->out, &flag);
1360 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1361 }
1362
1363 yprc_node_common2(ctx, node, &flag);
1364
1365 LY_LIST_FOR(cont->child, child) {
1366 ypr_open(ctx->out, &flag);
1367 yprc_node(ctx, child);
1368 }
1369
1370 LY_ARRAY_FOR(cont->actions, u) {
1371 ypr_open(ctx->out, &flag);
1372 yprc_action(ctx, &cont->actions[u]);
1373 }
1374
1375 LY_ARRAY_FOR(cont->notifs, u) {
1376 ypr_open(ctx->out, &flag);
1377 yprc_notification(ctx, &cont->notifs[u]);
1378 }
1379
1380 LEVEL--;
1381 ypr_close(ctx, flag);
1382}
1383
1384static void
1385yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1386{
1387 int flag = 0;
1388 struct lysp_node *child;
1389 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1390
1391 yprp_node_common1(ctx, node, &flag);
1392 yprp_node_common2(ctx, node, &flag);
1393
1394 LY_LIST_FOR(cas->child, child) {
1395 ypr_open(ctx->out, &flag);
1396 yprp_node(ctx, child);
1397 }
1398
1399 LEVEL--;
1400 ypr_close(ctx, flag);
1401}
1402
1403static void
1404yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1405{
1406 int flag = 0;
1407 struct lysc_node *child;
1408
1409 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1410 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1411
1412 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1413 ypr_open(ctx->out, &flag);
1414 yprc_node(ctx, child);
1415 }
1416
1417 LEVEL--;
1418 ypr_close(ctx, flag);
1419}
1420
1421static void
1422yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001423{
1424 int flag = 0;
1425 struct lysp_node *child;
1426 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1427
Radek Krejci693262f2019-04-29 15:23:20 +02001428 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001429
1430 if (choice->dflt) {
1431 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001432 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001433 }
1434
Radek Krejci693262f2019-04-29 15:23:20 +02001435 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001436
1437 LY_LIST_FOR(choice->child, child) {
1438 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001439 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001440 }
1441
1442 LEVEL--;
1443 ypr_close(ctx, flag);
1444}
1445
1446static void
Radek Krejci693262f2019-04-29 15:23:20 +02001447yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1448{
1449 int flag = 0;
1450 struct lysc_node_case *cs;
1451 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1452
1453 yprc_node_common1(ctx, node, &flag);
1454
1455 if (choice->dflt) {
1456 ypr_open(ctx->out, &flag);
1457 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1458 }
1459
1460 yprc_node_common2(ctx, node, &flag);
1461
1462 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1463 ypr_open(ctx->out, &flag);
1464 yprc_case(ctx, cs);
1465 }
1466
1467 LEVEL--;
1468 ypr_close(ctx, flag);
1469}
1470
1471static void
1472yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001473{
1474 unsigned int u;
1475 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1476
Radek Krejci693262f2019-04-29 15:23:20 +02001477 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001478
Radek Krejci693262f2019-04-29 15:23:20 +02001479 yprp_type(ctx, &leaf->type);
1480 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001481 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001482 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001483 }
Radek Krejci693262f2019-04-29 15:23:20 +02001484 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001485
Radek Krejci693262f2019-04-29 15:23:20 +02001486 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001487
1488 LEVEL--;
1489 ly_print(ctx->out, "%*s}\n", INDENT);
1490}
1491
1492static void
Radek Krejci693262f2019-04-29 15:23:20 +02001493yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1494{
1495 unsigned int u;
1496 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1497
1498 yprc_node_common1(ctx, node, NULL);
1499
1500 yprc_type(ctx, leaf->type);
1501 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1502 LY_ARRAY_FOR(leaf->musts, u) {
1503 yprc_must(ctx, &leaf->musts[u], NULL);
1504 }
1505 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
1506
1507 yprc_node_common2(ctx, node, NULL);
1508
1509 LEVEL--;
1510 ly_print(ctx->out, "%*s}\n", INDENT);
1511}
1512
1513static void
1514yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001515{
1516 unsigned int u;
1517 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1518
Radek Krejci693262f2019-04-29 15:23:20 +02001519 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001520
Radek Krejci693262f2019-04-29 15:23:20 +02001521 yprp_type(ctx, &llist->type);
1522 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001523 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001524 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001525 }
1526 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001527 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001528 }
1529
Radek Krejci693262f2019-04-29 15:23:20 +02001530 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001531
1532 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001533 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001534 }
1535 if (llist->flags & LYS_SET_MAX) {
1536 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001537 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001538 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001539 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001540 }
1541 }
1542
1543 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001544 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001545 }
1546
Radek Krejci693262f2019-04-29 15:23:20 +02001547 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001548 ypr_description(ctx, node->dsc, node->exts, NULL);
1549 ypr_reference(ctx, node->ref, node->exts, NULL);
1550
1551 LEVEL--;
1552 ly_print(ctx->out, "%*s}\n", INDENT);
1553}
1554
1555static void
Radek Krejci693262f2019-04-29 15:23:20 +02001556yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1557{
1558 unsigned int u;
1559 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1560
1561 yprc_node_common1(ctx, node, NULL);
1562
1563 yprc_type(ctx, llist->type);
1564 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1565 LY_ARRAY_FOR(llist->musts, u) {
1566 yprc_must(ctx, &llist->musts[u], NULL);
1567 }
1568 LY_ARRAY_FOR(llist->dflts, u) {
1569 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
1570 }
1571
1572 ypr_config(ctx, node->flags, node->exts, NULL);
1573
1574 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1575 if (llist->max) {
1576 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1577 } else {
1578 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1579 }
1580
1581 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1582
1583 ypr_status(ctx, node->flags, node->exts, NULL);
1584 ypr_description(ctx, node->dsc, node->exts, NULL);
1585 ypr_reference(ctx, node->ref, node->exts, NULL);
1586
1587 LEVEL--;
1588 ly_print(ctx->out, "%*s}\n", INDENT);
1589}
1590
1591static void
1592yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001593{
1594 unsigned int u;
1595 int flag = 0;
1596 struct lysp_node *child;
1597 struct lysp_node_list *list = (struct lysp_node_list *)node;
1598
Radek Krejci693262f2019-04-29 15:23:20 +02001599 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001600
1601 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001602 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001603 }
1604 if (list->key) {
1605 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001606 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001607 }
1608 LY_ARRAY_FOR(list->uniques, u) {
1609 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001610 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001611 }
1612
Radek Krejci693262f2019-04-29 15:23:20 +02001613 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001614
1615 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001616 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001617 }
1618 if (list->flags & LYS_SET_MAX) {
1619 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001620 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001621 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001622 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001623 }
1624 }
1625
1626 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001627 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001628 }
1629
Radek Krejci693262f2019-04-29 15:23:20 +02001630 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001631 ypr_description(ctx, node->dsc, node->exts, NULL);
1632 ypr_reference(ctx, node->ref, node->exts, NULL);
1633
1634 LY_ARRAY_FOR(list->typedefs, u) {
1635 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001636 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001637 }
1638
1639 LY_ARRAY_FOR(list->groupings, u) {
1640 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001641 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001642 }
1643
1644 LY_LIST_FOR(list->child, child) {
1645 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001646 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001647 }
1648
1649 LY_ARRAY_FOR(list->actions, u) {
1650 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001651 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001652 }
1653
1654 LY_ARRAY_FOR(list->notifs, u) {
1655 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001656 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001657 }
1658
1659 LEVEL--;
1660 ypr_close(ctx, flag);
1661}
1662
1663static void
Radek Krejci693262f2019-04-29 15:23:20 +02001664yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1665{
1666 unsigned int u, v;
1667 int flag = 0;
1668 struct lysc_node *child;
1669 struct lysc_node_list *list = (struct lysc_node_list *)node;
1670
1671 yprc_node_common1(ctx, node, &flag);
1672
1673 LY_ARRAY_FOR(list->musts, u) {
1674 yprc_must(ctx, &list->musts[u], NULL);
1675 }
1676 if (list->keys) {
1677 ypr_open(ctx->out, &flag);
1678 ly_print(ctx->out, "%*skey \"", INDENT);
1679 LY_ARRAY_FOR(list->keys, u) {
1680 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", list->keys[u]->name);
1681 }
1682 ypr_close(ctx, 0);
1683 }
1684 LY_ARRAY_FOR(list->uniques, u) {
1685 ypr_open(ctx->out, &flag);
1686 ly_print(ctx->out, "%*sunique \"", INDENT);
1687 LY_ARRAY_FOR(list->uniques[u], v) {
1688 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1689 }
1690 ypr_close(ctx, 0);
1691 }
1692
1693 ypr_config(ctx, node->flags, node->exts, NULL);
1694
1695 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1696 if (list->max) {
1697 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1698 } else {
1699 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1700 }
1701
1702 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1703
1704 ypr_status(ctx, node->flags, node->exts, NULL);
1705 ypr_description(ctx, node->dsc, node->exts, NULL);
1706 ypr_reference(ctx, node->ref, node->exts, NULL);
1707
1708 LY_LIST_FOR(list->child, child) {
1709 ypr_open(ctx->out, &flag);
1710 yprc_node(ctx, child);
1711 }
1712
1713 LY_ARRAY_FOR(list->actions, u) {
1714 ypr_open(ctx->out, &flag);
1715 yprc_action(ctx, &list->actions[u]);
1716 }
1717
1718 LY_ARRAY_FOR(list->notifs, u) {
1719 ypr_open(ctx->out, &flag);
1720 yprc_notification(ctx, &list->notifs[u]);
1721 }
1722
1723 LEVEL--;
1724 ypr_close(ctx, flag);
1725}
1726
1727static void
1728yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001729{
1730 unsigned int u;
1731 int flag = 0;
1732
1733 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1734 LEVEL++;
1735
Radek Krejci693262f2019-04-29 15:23:20 +02001736 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1737 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001738
1739 LY_ARRAY_FOR(refine->musts, u) {
1740 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001741 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001742 }
1743
1744 if (refine->presence) {
1745 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001746 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001747 }
1748
1749 LY_ARRAY_FOR(refine->dflts, u) {
1750 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001751 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001752 }
1753
Radek Krejci693262f2019-04-29 15:23:20 +02001754 ypr_config(ctx, refine->flags, refine->exts, &flag);
1755 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001756
1757 if (refine->flags & LYS_SET_MIN) {
1758 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001759 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001760 }
1761 if (refine->flags & LYS_SET_MAX) {
1762 ypr_open(ctx->out, &flag);
1763 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001764 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001765 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001766 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001767 }
1768 }
1769
1770 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1771 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1772
1773 LEVEL--;
1774 ypr_close(ctx, flag);
1775}
1776
1777static void
Radek Krejci693262f2019-04-29 15:23:20 +02001778yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001779{
1780 unsigned int u;
1781 struct lysp_node *child;
1782
1783 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1784 LEVEL++;
1785
Radek Krejci693262f2019-04-29 15:23:20 +02001786 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1787 yprp_when(ctx, aug->when, NULL);
1788 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1789 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001790 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1791 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1792
1793 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001794 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001795 }
1796
1797 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001798 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001799 }
1800
1801 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001802 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001803 }
1804
1805 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001806 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001807}
1808
1809
1810static void
Radek Krejci693262f2019-04-29 15:23:20 +02001811yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001812{
1813 unsigned int u;
1814 int flag = 0;
1815 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1816
Radek Krejci693262f2019-04-29 15:23:20 +02001817 yprp_node_common1(ctx, node, &flag);
1818 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001819
1820 LY_ARRAY_FOR(uses->refines, u) {
1821 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001822 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001823 }
1824
1825 LY_ARRAY_FOR(uses->augments, u) {
1826 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001827 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001828 }
1829
1830 LEVEL--;
1831 ypr_close(ctx, flag);
1832}
1833
1834static void
Radek Krejci693262f2019-04-29 15:23:20 +02001835yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001836{
1837 unsigned int u;
1838 int flag = 0;
1839 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1840
Radek Krejci693262f2019-04-29 15:23:20 +02001841 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001842
1843 LY_ARRAY_FOR(any->musts, u) {
1844 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001845 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001846 }
1847
Radek Krejci693262f2019-04-29 15:23:20 +02001848 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849
1850 LEVEL--;
1851 ypr_close(ctx, flag);
1852}
1853
1854static void
Radek Krejci693262f2019-04-29 15:23:20 +02001855yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001856{
Radek Krejci693262f2019-04-29 15:23:20 +02001857 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001858 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001859 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001860
Radek Krejci693262f2019-04-29 15:23:20 +02001861 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001862
Radek Krejci693262f2019-04-29 15:23:20 +02001863 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001864 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001865 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001866 }
1867
Radek Krejci693262f2019-04-29 15:23:20 +02001868 yprc_node_common2(ctx, node, &flag);
1869
Radek Krejcid3ca0632019-04-16 16:54:54 +02001870 LEVEL--;
1871 ypr_close(ctx, flag);
1872}
1873
1874static void
Radek Krejci693262f2019-04-29 15:23:20 +02001875yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001876{
Radek Krejci56cc0872019-04-30 09:22:27 +02001877 LYOUT_CHECK(ctx->out);
1878
Radek Krejcid3ca0632019-04-16 16:54:54 +02001879 switch (node->nodetype) {
1880 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001881 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001882 break;
1883 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001884 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001885 break;
1886 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001887 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001888 break;
1889 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001890 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001891 break;
1892 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001893 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001894 break;
1895 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001896 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001897 break;
1898 case LYS_ANYXML:
1899 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001900 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001901 break;
1902 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001903 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001904 break;
1905 default:
1906 break;
1907 }
1908}
1909
1910static void
Radek Krejci693262f2019-04-29 15:23:20 +02001911yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1912{
Radek Krejci56cc0872019-04-30 09:22:27 +02001913 LYOUT_CHECK(ctx->out);
1914
Radek Krejci693262f2019-04-29 15:23:20 +02001915 switch (node->nodetype) {
1916 case LYS_CONTAINER:
1917 yprc_container(ctx, node);
1918 break;
1919 case LYS_CHOICE:
1920 yprc_choice(ctx, node);
1921 break;
1922 case LYS_LEAF:
1923 yprc_leaf(ctx, node);
1924 break;
1925 case LYS_LEAFLIST:
1926 yprc_leaflist(ctx, node);
1927 break;
1928 case LYS_LIST:
1929 yprc_list(ctx, node);
1930 break;
1931 case LYS_ANYXML:
1932 case LYS_ANYDATA:
1933 yprc_anydata(ctx, node);
1934 break;
1935 default:
1936 break;
1937 }
1938}
1939
1940static void
1941yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001942{
1943 unsigned int u, v;
1944 struct lysp_deviate_add *add;
1945 struct lysp_deviate_rpl *rpl;
1946 struct lysp_deviate_del *del;
1947
1948 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
1949 LEVEL++;
1950
Radek Krejci693262f2019-04-29 15:23:20 +02001951 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001952 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1953 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1954
1955 LY_ARRAY_FOR(deviation->deviates, u) {
1956 ly_print(ctx->out, "%*sdeviate ", INDENT);
1957 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
1958 if (deviation->deviates[u].exts) {
1959 ly_print(ctx->out, "not-supported {\n");
1960 LEVEL++;
1961
Radek Krejci693262f2019-04-29 15:23:20 +02001962 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001963 } else {
1964 ly_print(ctx->out, "not-supported;\n");
1965 continue;
1966 }
1967 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
1968 add = (struct lysp_deviate_add*)&deviation->deviates[u];
1969 ly_print(ctx->out, "add {\n");
1970 LEVEL++;
1971
Radek Krejci693262f2019-04-29 15:23:20 +02001972 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
1973 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001974 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02001975 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001976 }
1977 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02001978 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001979 }
1980 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02001981 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001982 }
Radek Krejci693262f2019-04-29 15:23:20 +02001983 ypr_config(ctx, add->flags, add->exts, NULL);
1984 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001985 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001986 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001987 }
1988 if (add->flags & LYS_SET_MAX) {
1989 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001990 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001991 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001992 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001993 }
1994 }
1995 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
1996 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
1997 ly_print(ctx->out, "replace {\n");
1998 LEVEL++;
1999
Radek Krejci693262f2019-04-29 15:23:20 +02002000 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002001 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02002002 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002003 }
Radek Krejci693262f2019-04-29 15:23:20 +02002004 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
2005 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
2006 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
2007 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002008 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002009 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002010 }
2011 if (rpl->flags & LYS_SET_MAX) {
2012 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002013 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002014 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002015 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002016 }
2017 }
2018 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
2019 del = (struct lysp_deviate_del*)&deviation->deviates[u];
2020 ly_print(ctx->out, "delete {\n");
2021 LEVEL++;
2022
Radek Krejci693262f2019-04-29 15:23:20 +02002023 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2024 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002025 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002026 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002027 }
2028 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002029 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002030 }
2031 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002032 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002033 }
2034 }
2035
2036 LEVEL--;
2037 ypr_close(ctx, 1);
2038 }
2039
2040 LEVEL--;
2041 ypr_close(ctx, 1);
2042}
2043
Radek Krejci693262f2019-04-29 15:23:20 +02002044/**
2045 * @brief Minimal print of a schema.
2046 *
2047 * To print
2048 * a) compiled schema when it is not compiled or
2049 * b) parsed when the parsed form was already removed
2050 */
2051static LY_ERR
2052ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2053{
2054 /* module-header-stmts */
2055 if (module->version) {
2056 if (module->version) {
2057 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2058 }
2059 }
2060 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2061 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2062
2063 /* meta-stmts */
2064 if (module->org || module->contact || module->dsc || module->ref) {
2065 ly_print(ctx->out, "\n");
2066 }
2067 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2068 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2069 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2070 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2071
2072 /* revision-stmts */
2073 if (module->revision) {
2074 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2075 }
2076
2077 LEVEL--;
2078 ly_print(ctx->out, "%*s}\n", INDENT);
2079 ly_print_flush(ctx->out);
2080
2081 return LY_SUCCESS;
2082}
2083
Radek Krejcid3ca0632019-04-16 16:54:54 +02002084LY_ERR
2085yang_print_parsed(struct lyout *out, const struct lys_module *module)
2086{
2087 unsigned int u;
2088 struct lysp_node *data;
2089 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002090 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002091
2092 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2093 LEVEL++;
2094
Radek Krejci693262f2019-04-29 15:23:20 +02002095 if (!modp) {
2096 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2097 return ypr_missing_format(ctx, module);
2098 }
2099
Radek Krejcid3ca0632019-04-16 16:54:54 +02002100 /* module-header-stmts */
2101 if (module->version) {
2102 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002103 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 +02002104 }
2105 }
Radek Krejci693262f2019-04-29 15:23:20 +02002106 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2107 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002108
2109 /* linkage-stmts */
2110 LY_ARRAY_FOR(modp->imports, u) {
2111 ly_print(out, "\n%*simport %s {\n", INDENT, modp->imports[u].module->name);
2112 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002113 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2114 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002115 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002116 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002117 }
Radek Krejci693262f2019-04-29 15:23:20 +02002118 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2119 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002120 LEVEL--;
2121 ly_print(out, "%*s}\n", INDENT);
2122 }
2123 LY_ARRAY_FOR(modp->includes, u) {
2124 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
2125 ly_print(out, "\n%*sinclude %s {\n", INDENT, modp->includes[u].submodule->name);
2126 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002127 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002128 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002129 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002130 }
Radek Krejci693262f2019-04-29 15:23:20 +02002131 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2132 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002133 LEVEL--;
2134 ly_print(out, "%*s}\n", INDENT);
2135 } else {
2136 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2137 }
2138 }
2139
2140 /* meta-stmts */
2141 if (module->org || module->contact || module->dsc || module->ref) {
2142 ly_print(out, "\n");
2143 }
Radek Krejci693262f2019-04-29 15:23:20 +02002144 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2145 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2146 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2147 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002148
2149 /* revision-stmts */
2150 if (modp->revs) {
2151 ly_print(out, "\n");
2152 }
2153 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002154 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002155 }
2156 /* body-stmts */
2157 LY_ARRAY_FOR(modp->extensions, u) {
2158 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002159 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002160 }
2161 if (modp->exts) {
2162 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002163 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002164 }
2165
2166 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002167 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002168 }
2169
2170 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002171 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002172 }
2173
2174 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002175 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002176 }
2177
2178 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002179 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002180 }
2181
2182 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002183 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002184 }
2185
2186 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002187 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002188 }
2189
2190 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002191 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002192 }
2193
2194 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002195 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002196 }
2197
2198 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002199 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002200 }
2201
2202 LEVEL--;
2203 ly_print(out, "%*s}\n", INDENT);
2204 ly_print_flush(out);
2205
2206 return LY_SUCCESS;
2207}
2208
2209LY_ERR
2210yang_print_compiled(struct lyout *out, const struct lys_module *module)
2211{
Radek Krejci693262f2019-04-29 15:23:20 +02002212 unsigned int u;
2213 struct lysc_node *data;
2214 struct lysc_module *modc = module->compiled;
2215 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2216
2217 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2218 LEVEL++;
2219
2220 if (!modc) {
2221 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2222 return ypr_missing_format(ctx, module);
2223 }
2224
2225 /* module-header-stmts */
2226 if (module->version) {
2227 if (module->version) {
2228 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2229 }
2230 }
2231 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2232 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2233
2234 /* linkage-stmts */
2235 LY_ARRAY_FOR(modc->imports, u) {
2236 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2237 LEVEL++;
2238 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2239 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2240 if (modc->imports[u].module->revision) {
2241 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2242 }
2243 LEVEL--;
2244 ly_print(out, "%*s}\n", INDENT);
2245 }
2246
2247 /* meta-stmts */
2248 if (module->org || module->contact || module->dsc || module->ref) {
2249 ly_print(out, "\n");
2250 }
2251 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2252 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2253 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2254 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2255
2256 /* revision-stmts */
2257 if (module->revision) {
2258 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2259 }
2260
2261 /* body-stmts */
2262 if (modc->exts) {
2263 ly_print(out, "\n");
2264 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2265 }
2266
2267 LY_ARRAY_FOR(modc->features, u) {
2268 yprc_feature(ctx, &modc->features[u]);
2269 }
2270
2271 LY_ARRAY_FOR(modc->identities, u) {
2272 yprc_identity(ctx, &modc->identities[u]);
2273 }
2274
2275 LY_LIST_FOR(modc->data, data) {
2276 yprc_node(ctx, data);
2277 }
2278
2279 LY_ARRAY_FOR(modc->rpcs, u) {
2280 yprc_action(ctx, &modc->rpcs[u]);
2281 }
2282
2283 LY_ARRAY_FOR(modc->notifs, u) {
2284 yprc_notification(ctx, &modc->notifs[u]);
2285 }
2286
2287 LEVEL--;
2288 ly_print(out, "%*s}\n", INDENT);
2289 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002290
2291 return LY_SUCCESS;
2292}