blob: 42fcb14ae15951416c31542f4468c9021a827152 [file] [log] [blame]
Radek Krejcid3ca0632019-04-16 16:54:54 +02001/**
2 * @file printer_yang.c
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief YANG printer
5 *
6 * Copyright (c) 2015 - 2019 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#include "common.h"
16
Radek Krejci693262f2019-04-29 15:23:20 +020017#include <inttypes.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020018#include <stdint.h>
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
Radek Krejci693262f2019-04-29 15:23:20 +020022
Radek Krejcie7b95092019-05-15 11:03:07 +020023#include "extensions.h"
24#include "log.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020025#include "printer_internal.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020026#include "tree.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020027#include "tree_schema.h"
28#include "tree_schema_internal.h"
Radek Krejci693262f2019-04-29 15:23:20 +020029#include "xpath.h"
Radek Krejcid3ca0632019-04-16 16:54:54 +020030
Radek Krejcie7b95092019-05-15 11:03:07 +020031/**
32 * @brief Types of the YANG printers
33 */
Radek Krejci693262f2019-04-29 15:23:20 +020034enum schema_type {
Radek Krejcie7b95092019-05-15 11:03:07 +020035 YPR_PARSED, /**< YANG printer of the parsed schema */
36 YPR_COMPILED /**< YANG printer of the compiled schema */
Radek Krejci693262f2019-04-29 15:23:20 +020037};
38
Radek Krejcie7b95092019-05-15 11:03:07 +020039/**
40 * @brief YANG printer context.
41 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020042struct ypr_ctx {
Radek Krejcie7b95092019-05-15 11:03:07 +020043 struct lyout *out; /**< output specification */
44 unsigned int level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */
45 const struct lys_module *module; /**< schema to print */
46 enum schema_type schema; /**< type of the schema to print */
Radek Krejcid3ca0632019-04-16 16:54:54 +020047};
48
Radek Krejcie7b95092019-05-15 11:03:07 +020049#define LEVEL ctx->level /**< current level */
50#define INDENT (LEVEL)*2,"" /**< indentation parameters for printer functions */
51
52/**
53 * @brief Print the given text as content of a double quoted YANG string,
54 * including encoding characters that have special meanings. The quotation marks
55 * are not printed.
56 *
57 * Follows RFC 7950, section 6.1.3.
58 *
59 * @param[in] out Output specification.
60 * @param[in] text String to be printed.
61 * @param[in] len Length of the string from @p text to be printed. In case of 0,
62 * the @p text is printed completely as a NULL-terminated string.
63 */
Radek Krejcid3ca0632019-04-16 16:54:54 +020064static void
65ypr_encode(struct lyout *out, const char *text, int len)
66{
67 int i, start_len;
68 const char *start;
69 char special = 0;
70
71 if (!len) {
72 return;
73 }
74
75 if (len < 0) {
76 len = strlen(text);
77 }
78
79 start = text;
80 start_len = 0;
81 for (i = 0; i < len; ++i) {
82 switch (text[i]) {
83 case '\n':
84 case '\t':
85 case '\"':
86 case '\\':
87 special = text[i];
88 break;
89 default:
90 ++start_len;
91 break;
92 }
93
94 if (special) {
95 ly_write(out, start, start_len);
96 switch (special) {
97 case '\n':
98 ly_write(out, "\\n", 2);
99 break;
100 case '\t':
101 ly_write(out, "\\t", 2);
102 break;
103 case '\"':
104 ly_write(out, "\\\"", 2);
105 break;
106 case '\\':
107 ly_write(out, "\\\\", 2);
108 break;
109 }
110
111 start += start_len + 1;
112 start_len = 0;
113
114 special = 0;
115 }
116 }
117
118 ly_write(out, start, start_len);
119}
120
121static void
122ypr_open(struct lyout *out, int *flag)
123{
124 if (flag && !*flag) {
125 *flag = 1;
126 ly_print(out, " {\n");
127 }
128}
129
130static void
131ypr_close(struct ypr_ctx *ctx, int flag)
132{
133 if (flag) {
134 ly_print(ctx->out, "%*s}\n", INDENT);
135 } else {
136 ly_print(ctx->out, ";\n");
137 }
138}
139
140static void
141ypr_text(struct ypr_ctx *ctx, const char *name, const char *text, int singleline, int closed)
142{
143 const char *s, *t;
144
145 if (singleline) {
146 ly_print(ctx->out, "%*s%s \"", INDENT, name);
147 } else {
148 ly_print(ctx->out, "%*s%s\n", INDENT, name);
149 LEVEL++;
150
151 ly_print(ctx->out, "%*s\"", INDENT);
152 }
153 t = text;
154 while ((s = strchr(t, '\n'))) {
155 ypr_encode(ctx->out, t, s - t);
156 ly_print(ctx->out, "\n");
157 t = s + 1;
158 if (*t != '\n') {
159 ly_print(ctx->out, "%*s ", INDENT);
160 }
161 }
162
163 ypr_encode(ctx->out, t, strlen(t));
164 if (closed) {
165 ly_print(ctx->out, "\";\n");
166 } else {
167 ly_print(ctx->out, "\"");
168 }
169 if (!singleline) {
170 LEVEL--;
171 }
172}
173
174static void
Radek Krejci693262f2019-04-29 15:23:20 +0200175yprp_stmt(struct ypr_ctx *ctx, struct lysp_stmt *stmt)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200176{
177 struct lysp_stmt *childstmt;
178 const char *s, *t;
179
180 if (stmt->arg) {
181 if (stmt->flags) {
182 ly_print(ctx->out, "%*s%s\n", INDENT, stmt->stmt);
183 LEVEL++;
184 ly_print(ctx->out, "%*s%c", INDENT, (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'');
185 t = stmt->arg;
186 while ((s = strchr(t, '\n'))) {
187 ypr_encode(ctx->out, t, s - t);
188 ly_print(ctx->out, "\n");
189 t = s + 1;
190 if (*t != '\n') {
191 ly_print(ctx->out, "%*s ", INDENT);
192 }
193 }
194 LEVEL--;
195 ypr_encode(ctx->out, t, strlen(t));
196 ly_print(ctx->out, "%c%s", (stmt->flags & LYS_DOUBLEQUOTED) ? '\"' : '\'', stmt->child ? " {\n" : ";\n");
197 } else {
198 ly_print(ctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n");
199 }
200 } else {
201 ly_print(ctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n");
202 }
203
204 if (stmt->child) {
205 LEVEL++;
206 LY_LIST_FOR(stmt->child, childstmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200207 yprp_stmt(ctx, childstmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200208 }
209 LEVEL--;
210 ly_print(ctx->out, "%*s}\n", INDENT);
211 }
212}
213
214/**
215 * @param[in] count Number of extensions to print, 0 to print them all.
216 */
217static void
Radek Krejci693262f2019-04-29 15:23:20 +0200218yprp_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
Radek Krejcid3ca0632019-04-16 16:54:54 +0200219 struct lysp_ext_instance *ext, int *flag, unsigned int count)
220{
221 unsigned int u;
222 struct lysp_stmt *stmt;
223
224 if (!count && ext) {
225 count = LY_ARRAY_SIZE(ext);
226 }
227 LY_ARRAY_FOR(ext, u) {
228 if (!count) {
229 break;
230 }
David Sedlákbbd06ca2019-06-27 14:15:38 +0200231 if (ext->yin) {
232 ly_print(ctx->out, "%*s%s Model comes from different input format, extensions must be resolved first.", INDENT, ext[u].name);
233 } else if (ext->insubstmt == substmt && ext->insubstmt_index == substmt_index) {
Radek Krejcid3ca0632019-04-16 16:54:54 +0200234 ypr_open(ctx->out, flag);
235 if (ext[u].argument) {
236 ly_print(ctx->out, "%*s%s %s%s", INDENT, ext[u].name, ext[u].argument, ext[u].child ? " {\n" : ";\n");
237 } else {
238 ly_print(ctx->out, "%*s%s%s", INDENT, ext[u].name, ext[u].child ? " {\n" : ";\n");
239 }
240
241 if (ext[u].child) {
242 LEVEL++;
243 LY_LIST_FOR(ext[u].child, stmt) {
Radek Krejci693262f2019-04-29 15:23:20 +0200244 yprp_stmt(ctx, stmt);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200245 }
246 LEVEL--;
247 ly_print(ctx->out, "%*s}\n", INDENT);
248 }
249 }
250 count--;
251 }
252}
253
Radek Krejci693262f2019-04-29 15:23:20 +0200254/**
255 * @param[in] count Number of extensions to print, 0 to print them all.
256 */
Radek Krejcid3ca0632019-04-16 16:54:54 +0200257static void
Radek Krejci693262f2019-04-29 15:23:20 +0200258yprc_extension_instances(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index,
259 struct lysc_ext_instance *ext, int *flag, unsigned int count)
260{
261 unsigned int u;
262
263 if (!count && ext) {
264 count = LY_ARRAY_SIZE(ext);
265 }
266 LY_ARRAY_FOR(ext, u) {
267 if (!count) {
268 break;
269 }
270 /* TODO compiled extensions */
271 (void) ctx;
272 (void) substmt;
273 (void) substmt_index;
274 (void) flag;
275
276 count--;
277 }
278}
279
280static void
281ypr_substmt(struct ypr_ctx *ctx, LYEXT_SUBSTMT substmt, uint8_t substmt_index, const char *text, void *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200282{
283 unsigned int u;
284 int extflag = 0;
285
286 if (!text) {
287 /* nothing to print */
288 return;
289 }
290
291 if (ext_substmt_info[substmt].flags & SUBST_FLAG_ID) {
292 ly_print(ctx->out, "%*s%s %s", INDENT, ext_substmt_info[substmt].name, text);
293 } else {
294 ypr_text(ctx, ext_substmt_info[substmt].name, text,
295 (ext_substmt_info[substmt].flags & SUBST_FLAG_YIN) ? 0 : 1, 0);
296 }
297
298 LEVEL++;
299 LY_ARRAY_FOR(ext, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200300 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 +0200301 continue;
302 }
Radek Krejci693262f2019-04-29 15:23:20 +0200303 if (ctx->schema == YPR_PARSED) {
304 yprp_extension_instances(ctx, substmt, substmt_index, &((struct lysp_ext_instance*)ext)[u], &extflag, 1);
305 } else {
306 yprc_extension_instances(ctx, substmt, substmt_index, &((struct lysc_ext_instance*)ext)[u], &extflag, 1);
307 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200308 }
309 LEVEL--;
310 ypr_close(ctx, extflag);
311}
312
313static void
Radek Krejci693262f2019-04-29 15:23:20 +0200314ypr_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 +0200315{
316 char *str;
317
318 if (asprintf(&str, "%u", attr_value) == -1) {
319 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200320 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200321 return;
322 }
323 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200324 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200325 free(str);
326}
327
328static void
Radek Krejci693262f2019-04-29 15:23:20 +0200329ypr_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 +0200330{
331 char *str;
332
333 if (asprintf(&str, "%d", attr_value) == -1) {
334 LOGMEM(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +0200335 ctx->out->status = LY_EMEM;
Radek Krejcid3ca0632019-04-16 16:54:54 +0200336 return;
337 }
338 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200339 ypr_substmt(ctx, substmt, substmt_index, str, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200340 free(str);
341}
342
343static void
Radek Krejci693262f2019-04-29 15:23:20 +0200344yprp_revision(struct ypr_ctx *ctx, const struct lysp_revision *rev)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200345{
346 if (rev->dsc || rev->ref || rev->exts) {
347 ly_print(ctx->out, "%*srevision %s {\n", INDENT, rev->date);
348 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200349 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rev->exts, NULL, 0);
350 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, rev->dsc, rev->exts);
351 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, rev->ref, rev->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200352 LEVEL--;
353 ly_print(ctx->out, "%*s}\n", INDENT);
354 } else {
355 ly_print(ctx->out, "%*srevision %s;\n", INDENT, rev->date);
356 }
357}
358
359static void
Radek Krejci693262f2019-04-29 15:23:20 +0200360ypr_mandatory(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200361{
362 if (flags & LYS_MAND_MASK) {
363 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200364 ypr_substmt(ctx, LYEXT_SUBSTMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200365 }
366}
367
368static void
Radek Krejci693262f2019-04-29 15:23:20 +0200369ypr_config(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200370{
371 if (flags & LYS_CONFIG_MASK) {
372 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200373 ypr_substmt(ctx, LYEXT_SUBSTMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200374 }
375}
376
377static void
Radek Krejci693262f2019-04-29 15:23:20 +0200378ypr_status(struct ypr_ctx *ctx, uint16_t flags, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200379{
380 const char *status = NULL;
381
382 if (flags & LYS_STATUS_CURR) {
383 ypr_open(ctx->out, flag);
384 status = "current";
385 } else if (flags & LYS_STATUS_DEPRC) {
386 ypr_open(ctx->out, flag);
387 status = "deprecated";
388 } else if (flags & LYS_STATUS_OBSLT) {
389 ypr_open(ctx->out, flag);
390 status = "obsolete";
391 }
Radek Krejci693262f2019-04-29 15:23:20 +0200392
393 ypr_substmt(ctx, LYEXT_SUBSTMT_STATUS, 0, status, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200394}
395
396static void
Radek Krejci693262f2019-04-29 15:23:20 +0200397ypr_description(struct ypr_ctx *ctx, const char *dsc, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200398{
399 if (dsc) {
400 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200401 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, dsc, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200402 }
403}
404
405static void
Radek Krejci693262f2019-04-29 15:23:20 +0200406ypr_reference(struct ypr_ctx *ctx, const char *ref, void *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200407{
408 if (ref) {
409 ypr_open(ctx->out, flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200410 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, ref, exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200411 }
412}
413
414static void
Radek Krejci693262f2019-04-29 15:23:20 +0200415yprp_iffeatures(struct ypr_ctx *ctx, const char **iff, struct lysp_ext_instance *exts, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200416{
417 unsigned int u;
418 int extflag;
419
420 LY_ARRAY_FOR(iff, u) {
421 ypr_open(ctx->out, flag);
422 extflag = 0;
423
424 ly_print(ctx->out, "%*sif-feature \"%s\"", INDENT, iff[u]);
425
426 /* extensions */
427 LEVEL++;
428 LY_ARRAY_FOR(exts, u) {
429 if (exts[u].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[u].insubstmt_index != u) {
430 continue;
431 }
Radek Krejci693262f2019-04-29 15:23:20 +0200432 yprp_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[u], &extflag, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200433 }
434 LEVEL--;
435 ypr_close(ctx, extflag);
436 }
437}
438
439static void
Radek Krejci693262f2019-04-29 15:23:20 +0200440yprc_iffeature(struct ypr_ctx *ctx, struct lysc_iffeature *feat, int *index_e, int *index_f)
441{
442 int brackets_flag = *index_e;
443 uint8_t op;
444
445 op = lysc_iff_getop(feat->expr, *index_e);
446 (*index_e)++;
447
448 switch (op) {
449 case LYS_IFF_F:
450 if (ctx->module == feat->features[*index_f]->module) {
451 ly_print(ctx->out, "%s", feat->features[*index_f]->name);
452 } else {
453 ly_print(ctx->out, "%s:%s", feat->features[*index_f]->module->prefix, feat->features[*index_f]->name);
454 }
455 (*index_f)++;
456 break;
457 case LYS_IFF_NOT:
458 ly_print(ctx->out, "not ");
459 yprc_iffeature(ctx, feat, index_e, index_f);
460 break;
461 case LYS_IFF_AND:
462 if (brackets_flag) {
463 /* AND need brackets only if previous op was not */
464 if (*index_e < 2 || lysc_iff_getop(feat->expr, *index_e - 2) != LYS_IFF_NOT) {
465 brackets_flag = 0;
466 }
467 }
468 /* falls through */
469 case LYS_IFF_OR:
470 if (brackets_flag) {
471 ly_print(ctx->out, "(");
472 }
473 yprc_iffeature(ctx, feat, index_e, index_f);
474 ly_print(ctx->out, " %s ", op == LYS_IFF_OR ? "or" : "and");
475 yprc_iffeature(ctx, feat, index_e, index_f);
476 if (brackets_flag) {
477 ly_print(ctx->out, ")");
478 }
479 }
480}
481
482static void
483yprc_iffeatures(struct ypr_ctx *ctx, struct lysc_iffeature *iff, struct lysc_ext_instance *exts, int *flag)
484{
Radek Krejci334ccc72019-06-12 13:49:29 +0200485 unsigned int u, v;
Radek Krejci693262f2019-04-29 15:23:20 +0200486 int extflag;
487
488 LY_ARRAY_FOR(iff, u) {
489 int index_e = 0, index_f = 0;
490
491 ypr_open(ctx->out, flag);
492 extflag = 0;
493
Radek Krejci989e53b2019-04-30 09:51:09 +0200494 ly_print(ctx->out, "%*sif-feature \"", INDENT);
Radek Krejci693262f2019-04-29 15:23:20 +0200495 yprc_iffeature(ctx, iff, &index_e, &index_f);
Radek Krejci989e53b2019-04-30 09:51:09 +0200496 ly_print(ctx->out, "\"");
Radek Krejci693262f2019-04-29 15:23:20 +0200497
498 /* extensions */
499 LEVEL++;
Radek Krejci334ccc72019-06-12 13:49:29 +0200500 LY_ARRAY_FOR(exts, v) {
501 if (exts[v].insubstmt != LYEXT_SUBSTMT_IFFEATURE || exts[v].insubstmt_index != u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200502 continue;
503 }
Radek Krejci334ccc72019-06-12 13:49:29 +0200504 yprc_extension_instances(ctx, LYEXT_SUBSTMT_IFFEATURE, u, &exts[v], &extflag, 1);
Radek Krejci693262f2019-04-29 15:23:20 +0200505 }
506 LEVEL--;
507 ypr_close(ctx, extflag);
508 }
509}
510
511static void
512yprp_extension(struct ypr_ctx *ctx, const struct lysp_ext *ext)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200513{
514 int flag = 0, flag2 = 0;
515 unsigned int i;
516
517 ly_print(ctx->out, "%*sextension %s", INDENT, ext->name);
518 LEVEL++;
519
520 if (ext->exts) {
Radek Krejci693262f2019-04-29 15:23:20 +0200521 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ext->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200522 }
523
524 if (ext->argument) {
525 ypr_open(ctx->out, &flag);
526 ly_print(ctx->out, "%*sargument %s", INDENT, ext->argument);
527 if (ext->exts) {
528 LEVEL++;
529 i = -1;
530 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 +0200531 yprp_extension_instances(ctx, LYEXT_SUBSTMT_ARGUMENT, 0, &ext->exts[i], &flag2, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200532 }
533 LEVEL--;
534 }
535 if ((ext->flags & LYS_YINELEM_MASK) ||
536 (ext->exts && lysp_ext_instance_iter(ext->exts, 0, LYEXT_SUBSTMT_YINELEM) != LY_ARRAY_SIZE(ext->exts))) {
537 ypr_open(ctx->out, &flag2);
Radek Krejci693262f2019-04-29 15:23:20 +0200538 ypr_substmt(ctx, LYEXT_SUBSTMT_YINELEM, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", ext->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200539 }
540 ypr_close(ctx, flag2);
541 }
542
Radek Krejci693262f2019-04-29 15:23:20 +0200543 ypr_status(ctx, ext->flags, ext->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200544 ypr_description(ctx, ext->dsc, ext->exts, &flag);
545 ypr_reference(ctx, ext->ref, ext->exts, &flag);
546
547 LEVEL--;
548 ypr_close(ctx, flag);
549}
550
551static void
Radek Krejci693262f2019-04-29 15:23:20 +0200552yprp_feature(struct ypr_ctx *ctx, const struct lysp_feature *feat)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200553{
554 int flag = 0;
555
556 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
557 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200558 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
559 yprp_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
560 ypr_status(ctx, feat->flags, feat->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200561 ypr_description(ctx, feat->dsc, feat->exts, &flag);
562 ypr_reference(ctx, feat->ref, feat->exts, &flag);
563 LEVEL--;
564 ypr_close(ctx, flag);
565}
566
567static void
Radek Krejci693262f2019-04-29 15:23:20 +0200568yprc_feature(struct ypr_ctx *ctx, const struct lysc_feature *feat)
569{
570 int flag = 0;
571
572 ly_print(ctx->out, "\n%*sfeature %s", INDENT, feat->name);
573 LEVEL++;
574 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, feat->exts, &flag, 0);
575 yprc_iffeatures(ctx, feat->iffeatures, feat->exts, &flag);
576 ypr_status(ctx, feat->flags, feat->exts, &flag);
577 ypr_description(ctx, feat->dsc, feat->exts, &flag);
578 ypr_reference(ctx, feat->ref, feat->exts, &flag);
579 LEVEL--;
580 ypr_close(ctx, flag);
581}
582
583static void
584yprp_identity(struct ypr_ctx *ctx, const struct lysp_ident *ident)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200585{
586 int flag = 0;
587 unsigned int u;
588
589 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
590 LEVEL++;
591
Radek Krejci693262f2019-04-29 15:23:20 +0200592 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
593 yprp_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200594
595 LY_ARRAY_FOR(ident->bases, u) {
596 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200597 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u], ident->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200598 }
599
Radek Krejci693262f2019-04-29 15:23:20 +0200600 ypr_status(ctx, ident->flags, ident->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200601 ypr_description(ctx, ident->dsc, ident->exts, &flag);
602 ypr_reference(ctx, ident->ref, ident->exts, &flag);
603
604 LEVEL--;
605 ypr_close(ctx, flag);
606}
607
608static void
Radek Krejci693262f2019-04-29 15:23:20 +0200609yprc_identity(struct ypr_ctx *ctx, const struct lysc_ident *ident)
610{
611 int flag = 0;
612 unsigned int u;
613
614 ly_print(ctx->out, "\n%*sidentity %s", INDENT, ident->name);
615 LEVEL++;
616
617 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, ident->exts, &flag, 0);
618 yprc_iffeatures(ctx, ident->iffeatures, ident->exts, &flag);
619
620 LY_ARRAY_FOR(ident->derived, u) {
621 ypr_open(ctx->out, &flag);
622 if (ctx->module != ident->derived[u]->module) {
623 ly_print(ctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name);
624 } else {
625 ly_print(ctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name);
626 }
627 }
628
629 ypr_status(ctx, ident->flags, ident->exts, &flag);
630 ypr_description(ctx, ident->dsc, ident->exts, &flag);
631 ypr_reference(ctx, ident->ref, ident->exts, &flag);
632
633 LEVEL--;
634 ypr_close(ctx, flag);
635}
636
637static void
638yprp_restr(struct ypr_ctx *ctx, const struct lysp_restr *restr, const char *name, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200639{
640 int inner_flag = 0;
641
642 if (!restr) {
643 return;
644 }
645
646 ypr_open(ctx->out, flag);
647 ly_print(ctx->out, "%*s%s \"", INDENT, name);
648 ypr_encode(ctx->out, (restr->arg[0] != 0x15 && restr->arg[0] != 0x06) ? restr->arg : &restr->arg[1], -1);
649 ly_print(ctx->out, "\"");
650
651 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200652 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, restr->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200653 if (restr->arg[0] == 0x15) {
654 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
655 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200656 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200657 }
658 if (restr->emsg) {
659 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200660 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, restr->emsg, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200661 }
662 if (restr->eapptag) {
663 ypr_open(ctx->out, &inner_flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200664 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, restr->eapptag, restr->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200665 }
Radek Krejci693262f2019-04-29 15:23:20 +0200666 ypr_description(ctx, restr->dsc, restr->exts, &inner_flag);
667 ypr_reference(ctx, restr->ref, restr->exts, &inner_flag);
668
Radek Krejcid3ca0632019-04-16 16:54:54 +0200669 LEVEL--;
670 ypr_close(ctx, inner_flag);
671}
672
673static void
Radek Krejci693262f2019-04-29 15:23:20 +0200674yprc_must(struct ypr_ctx *ctx, const struct lysc_must *must, int *flag)
675{
676 int inner_flag = 0;
677
678 ypr_open(ctx->out, flag);
679 ly_print(ctx->out, "%*smust \"", INDENT);
680 ypr_encode(ctx->out, must->cond->expr, -1);
681 ly_print(ctx->out, "\"");
682
683 LEVEL++;
684 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, must->exts, &inner_flag, 0);
685 if (must->emsg) {
686 ypr_open(ctx->out, &inner_flag);
687 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, must->emsg, must->exts);
688 }
689 if (must->eapptag) {
690 ypr_open(ctx->out, &inner_flag);
691 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, must->eapptag, must->exts);
692 }
693 ypr_description(ctx, must->dsc, must->exts, &inner_flag);
694 ypr_reference(ctx, must->ref, must->exts, &inner_flag);
695
696 LEVEL--;
697 ypr_close(ctx, inner_flag);
698}
699
700static void
701yprc_range(struct ypr_ctx *ctx, const struct lysc_range *range, LY_DATA_TYPE basetype, int *flag)
702{
703 int inner_flag = 0;
704 unsigned int u;
705
Radek Krejci334ccc72019-06-12 13:49:29 +0200706 if (!range) {
707 return;
708 }
709
Radek Krejci693262f2019-04-29 15:23:20 +0200710 ypr_open(ctx->out, flag);
Radek Krejci334ccc72019-06-12 13:49:29 +0200711 ly_print(ctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range");
Radek Krejci693262f2019-04-29 15:23:20 +0200712 LY_ARRAY_FOR(range->parts, u) {
713 if (u > 0) {
714 ly_print(ctx->out, " | ");
715 }
716 if (range->parts[u].max_64 == range->parts[u].min_64) {
717 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
718 ly_print(ctx->out, "%"PRIu64, range->parts[u].max_u64);
719 } else { /* signed values */
720 ly_print(ctx->out, "%"PRId64, range->parts[u].max_64);
721 }
722 } else {
723 if (basetype <= LY_TYPE_STRING) { /* unsigned values */
724 ly_print(ctx->out, "%"PRIu64"..%"PRIu64, range->parts[u].min_u64, range->parts[u].max_u64);
725 } else { /* signed values */
726 ly_print(ctx->out, "%"PRId64"..%"PRId64, range->parts[u].min_64, range->parts[u].max_64);
727 }
728 }
729 }
730 ly_print(ctx->out, "\"");
731
732 LEVEL++;
733 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, range->exts, &inner_flag, 0);
734 if (range->emsg) {
735 ypr_open(ctx->out, &inner_flag);
736 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, range->emsg, range->exts);
737 }
738 if (range->eapptag) {
739 ypr_open(ctx->out, &inner_flag);
740 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, range->eapptag, range->exts);
741 }
742 ypr_description(ctx, range->dsc, range->exts, &inner_flag);
743 ypr_reference(ctx, range->ref, range->exts, &inner_flag);
744
745 LEVEL--;
746 ypr_close(ctx, inner_flag);
747}
748
749static void
750yprc_pattern(struct ypr_ctx *ctx, const struct lysc_pattern *pattern, int *flag)
751{
752 int inner_flag = 0;
753
754 ypr_open(ctx->out, flag);
755 ly_print(ctx->out, "%*spattern \"", INDENT);
Radek Krejci54579462019-04-30 12:47:06 +0200756 ypr_encode(ctx->out, pattern->expr, -1);
Radek Krejci693262f2019-04-29 15:23:20 +0200757 ly_print(ctx->out, "\"");
758
759 LEVEL++;
760 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, pattern->exts, &inner_flag, 0);
761 if (pattern->inverted) {
762 /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */
763 ypr_open(ctx->out, &inner_flag);
764 ypr_substmt(ctx, LYEXT_SUBSTMT_MODIFIER, 0, "invert-match", pattern->exts);
765 }
766 if (pattern->emsg) {
767 ypr_open(ctx->out, &inner_flag);
768 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRMSG, 0, pattern->emsg, pattern->exts);
769 }
770 if (pattern->eapptag) {
771 ypr_open(ctx->out, &inner_flag);
772 ypr_substmt(ctx, LYEXT_SUBSTMT_ERRTAG, 0, pattern->eapptag, pattern->exts);
773 }
774 ypr_description(ctx, pattern->dsc, pattern->exts, &inner_flag);
775 ypr_reference(ctx, pattern->ref, pattern->exts, &inner_flag);
776
777 LEVEL--;
778 ypr_close(ctx, inner_flag);
779}
780
781static void
782yprp_when(struct ypr_ctx *ctx, struct lysp_when *when, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200783{
784 int inner_flag = 0;
785
786 if (!when) {
787 return;
788 }
789 ypr_open(ctx->out, flag);
790
791 ly_print(ctx->out, "%*swhen \"", INDENT);
792 ypr_encode(ctx->out, when->cond, -1);
793 ly_print(ctx->out, "\"");
794
795 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200796 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200797 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
798 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
799 LEVEL--;
800 ypr_close(ctx, inner_flag);
801}
802
803static void
Radek Krejci693262f2019-04-29 15:23:20 +0200804yprc_when(struct ypr_ctx *ctx, struct lysc_when *when, int *flag)
805{
806 int inner_flag = 0;
807
808 if (!when) {
809 return;
810 }
811 ypr_open(ctx->out, flag);
812
813 ly_print(ctx->out, "%*swhen \"", INDENT);
814 ypr_encode(ctx->out, when->cond->expr, -1);
815 ly_print(ctx->out, "\"");
816
817 LEVEL++;
818 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, when->exts, &inner_flag, 0);
819 ypr_description(ctx, when->dsc, when->exts, &inner_flag);
820 ypr_reference(ctx, when->ref, when->exts, &inner_flag);
821 LEVEL--;
822 ypr_close(ctx, inner_flag);
823}
824
825static void
826yprp_enum(struct ypr_ctx *ctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200827{
828 unsigned int u;
829 int inner_flag;
830
831 LY_ARRAY_FOR(items, u) {
832 ypr_open(ctx->out, flag);
Radek Krejci7871ce52019-06-11 16:44:56 +0200833 if (type == LY_TYPE_BITS) {
834 ly_print(ctx->out, "%*sbit %s", INDENT, items[u].name);
835 } else { /* LY_TYPE_ENUM */
836 ly_print(ctx->out, "%*senum \"", INDENT);
837 ypr_encode(ctx->out, items[u].name, -1);
838 ly_print(ctx->out, "\"");
839 }
Radek Krejcid3ca0632019-04-16 16:54:54 +0200840 inner_flag = 0;
841 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +0200842 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, items[u].exts, &inner_flag, 0);
843 yprp_iffeatures(ctx, items[u].iffeatures, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200844 if (items[u].flags & LYS_SET_VALUE) {
845 if (type == LY_TYPE_BITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200846 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200847 } else { /* LY_TYPE_ENUM */
Radek Krejci693262f2019-04-29 15:23:20 +0200848 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200849 }
850 }
Radek Krejci693262f2019-04-29 15:23:20 +0200851 ypr_status(ctx, items[u].flags, items[u].exts, &inner_flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200852 ypr_description(ctx, items[u].dsc, items[u].exts, &inner_flag);
853 ypr_reference(ctx, items[u].ref, items[u].exts, &inner_flag);
854 LEVEL--;
855 ypr_close(ctx, inner_flag);
856 }
857}
858
859static void
Radek Krejci693262f2019-04-29 15:23:20 +0200860yprp_type(struct ypr_ctx *ctx, const struct lysp_type *type)
Radek Krejcid3ca0632019-04-16 16:54:54 +0200861{
862 unsigned int u;
863 int flag = 0;
864
865 ly_print(ctx->out, "%*stype %s", INDENT, type->name);
866 LEVEL++;
867
Radek Krejci693262f2019-04-29 15:23:20 +0200868 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200869
Radek Krejci693262f2019-04-29 15:23:20 +0200870 yprp_restr(ctx, type->range, "range", &flag);
871 yprp_restr(ctx, type->length, "length", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200872 LY_ARRAY_FOR(type->patterns, u) {
Radek Krejci693262f2019-04-29 15:23:20 +0200873 yprp_restr(ctx, &type->patterns[u], "pattern", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200874 }
Radek Krejci693262f2019-04-29 15:23:20 +0200875 yprp_enum(ctx, type->bits, LY_TYPE_BITS, &flag);
876 yprp_enum(ctx, type->enums, LY_TYPE_ENUM, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200877
878 if (type->path) {
879 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200880 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, type->path, type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200881 }
882 if (type->flags & LYS_SET_REQINST) {
883 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200884 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, type->require_instance ? "true" : "false", type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200885 }
886 if (type->flags & LYS_SET_FRDIGITS) {
Radek Krejci693262f2019-04-29 15:23:20 +0200887 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, type->fraction_digits, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200888 }
889 LY_ARRAY_FOR(type->bases, u) {
890 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200891 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, type->bases[u], type->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200892 }
893 LY_ARRAY_FOR(type->types, u) {
894 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +0200895 yprp_type(ctx, &type->types[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +0200896 }
897
898 LEVEL--;
899 ypr_close(ctx, flag);
900}
901
902static void
Radek Krejci693262f2019-04-29 15:23:20 +0200903yprc_type(struct ypr_ctx *ctx, const struct lysc_type *type)
904{
905 unsigned int u;
906 int flag = 0;
907
908 ly_print(ctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype));
909 LEVEL++;
910
911 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, type->exts, &flag, 0);
912 if (type->dflt) {
913 ypr_open(ctx->out, &flag);
914 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, type->dflt, type->exts);
915 }
916
917 switch(type->basetype) {
918 case LY_TYPE_BINARY: {
919 struct lysc_type_bin *bin = (struct lysc_type_bin*)type;
920 yprc_range(ctx, bin->length, type->basetype, &flag);
921 break;
922 }
923 case LY_TYPE_UINT8:
924 case LY_TYPE_UINT16:
925 case LY_TYPE_UINT32:
926 case LY_TYPE_UINT64:
927 case LY_TYPE_INT8:
928 case LY_TYPE_INT16:
929 case LY_TYPE_INT32:
930 case LY_TYPE_INT64: {
931 struct lysc_type_num *num = (struct lysc_type_num*)type;
932 yprc_range(ctx, num->range, type->basetype, &flag);
933 break;
934 }
935 case LY_TYPE_STRING: {
936 struct lysc_type_str *str = (struct lysc_type_str*)type;
937 yprc_range(ctx, str->length, type->basetype, &flag);
938 LY_ARRAY_FOR(str->patterns, u) {
939 yprc_pattern(ctx, str->patterns[u], &flag);
940 }
941 break;
942 }
943 case LY_TYPE_BITS:
944 case LY_TYPE_ENUM: {
945 /* bits and enums structures are compatible */
946 struct lysc_type_bits *bits = (struct lysc_type_bits*)type;
947 LY_ARRAY_FOR(bits->bits, u) {
948 struct lysc_type_bitenum_item *item = &bits->bits[u];
949 int inner_flag = 0;
950
951 ypr_open(ctx->out, &flag);
952 ly_print(ctx->out, "%*s%s \"", INDENT, type->basetype == LY_TYPE_BITS ? "bit" : "enum");
953 ypr_encode(ctx->out, item->name, -1);
954 ly_print(ctx->out, "\"");
955 LEVEL++;
956 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, item->exts, &inner_flag, 0);
957 yprc_iffeatures(ctx, item->iffeatures, item->exts, &inner_flag);
958 if (type->basetype == LY_TYPE_BITS) {
959 ypr_unsigned(ctx, LYEXT_SUBSTMT_POSITION, 0, item->exts, item->position, &inner_flag);
960 } else { /* LY_TYPE_ENUM */
961 ypr_signed(ctx, LYEXT_SUBSTMT_VALUE, 0, item->exts, item->value, &inner_flag);
962 }
963 ypr_status(ctx, item->flags, item->exts, &inner_flag);
964 ypr_description(ctx, item->dsc, item->exts, &inner_flag);
965 ypr_reference(ctx, item->ref, item->exts, &inner_flag);
966 LEVEL--;
967 ypr_close(ctx, inner_flag);
968 }
969 break;
970 }
971 case LY_TYPE_BOOL:
972 case LY_TYPE_EMPTY:
973 /* nothing to do */
974 break;
975 case LY_TYPE_DEC64: {
976 struct lysc_type_dec *dec = (struct lysc_type_dec*)type;
977 ypr_open(ctx->out, &flag);
978 ypr_unsigned(ctx, LYEXT_SUBSTMT_FRACDIGITS, 0, type->exts, dec->fraction_digits, &flag);
979 yprc_range(ctx, dec->range, dec->basetype, &flag);
980 break;
981 }
982 case LY_TYPE_IDENT: {
983 struct lysc_type_identityref *ident = (struct lysc_type_identityref*)type;
984 LY_ARRAY_FOR(ident->bases, u) {
985 ypr_open(ctx->out, &flag);
986 ypr_substmt(ctx, LYEXT_SUBSTMT_BASE, u, ident->bases[u]->name, type->exts);
987 }
988 break;
989 }
990 case LY_TYPE_INST: {
991 struct lysc_type_instanceid *inst = (struct lysc_type_instanceid*)type;
992 ypr_open(ctx->out, &flag);
993 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, inst->require_instance ? "true" : "false", inst->exts);
994 break;
995 }
996 case LY_TYPE_LEAFREF: {
997 struct lysc_type_leafref *lr = (struct lysc_type_leafref*)type;
998 ypr_open(ctx->out, &flag);
999 ypr_substmt(ctx, LYEXT_SUBSTMT_PATH, 0, lr->path, lr->exts);
1000 ypr_substmt(ctx, LYEXT_SUBSTMT_REQINSTANCE, 0, lr->require_instance ? "true" : "false", lr->exts);
1001 yprc_type(ctx, lr->realtype);
1002 break;
1003 }
1004 case LY_TYPE_UNION: {
1005 struct lysc_type_union *un = (struct lysc_type_union*)type;
1006 LY_ARRAY_FOR(un->types, u) {
1007 ypr_open(ctx->out, &flag);
1008 yprc_type(ctx, un->types[u]);
1009 }
1010 break;
1011 }
1012 default:
1013 LOGINT(ctx->module->ctx);
Radek Krejci56cc0872019-04-30 09:22:27 +02001014 ctx->out->status = LY_EINT;
Radek Krejci693262f2019-04-29 15:23:20 +02001015 }
1016
1017 LEVEL--;
1018 ypr_close(ctx, flag);
1019}
1020
1021static void
1022yprp_typedef(struct ypr_ctx *ctx, const struct lysp_tpdf *tpdf)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001023{
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%*stypedef %s {\n", INDENT, tpdf->name);
1027 LEVEL++;
1028
Radek Krejci693262f2019-04-29 15:23:20 +02001029 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, tpdf->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001030
Radek Krejci693262f2019-04-29 15:23:20 +02001031 yprp_type(ctx, &tpdf->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001032
1033 if (tpdf->units) {
Radek Krejci693262f2019-04-29 15:23:20 +02001034 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, tpdf->units, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001035 }
1036 if (tpdf->dflt) {
Radek Krejci693262f2019-04-29 15:23:20 +02001037 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, tpdf->dflt, tpdf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001038 }
1039
Radek Krejci693262f2019-04-29 15:23:20 +02001040 ypr_status(ctx, tpdf->flags, tpdf->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001041 ypr_description(ctx, tpdf->dsc, tpdf->exts, NULL);
1042 ypr_reference(ctx, tpdf->ref, tpdf->exts, NULL);
1043
1044 LEVEL--;
1045 ly_print(ctx->out, "%*s}\n", INDENT);
1046}
1047
Radek Krejci693262f2019-04-29 15:23:20 +02001048static void yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node);
1049static void yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node);
1050static void yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001051
1052static void
Radek Krejci693262f2019-04-29 15:23:20 +02001053yprp_grouping(struct ypr_ctx *ctx, const struct lysp_grp *grp)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001054{
1055 unsigned int u;
1056 int flag = 0;
1057 struct lysp_node *data;
1058
Radek Krejci56cc0872019-04-30 09:22:27 +02001059 LYOUT_CHECK(ctx->out);
1060
Radek Krejcid3ca0632019-04-16 16:54:54 +02001061 ly_print(ctx->out, "\n%*sgrouping %s", INDENT, grp->name);
1062 LEVEL++;
1063
Radek Krejci693262f2019-04-29 15:23:20 +02001064 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, grp->exts, &flag, 0);
1065 ypr_status(ctx, grp->flags, grp->exts, &flag);
Radek Krejcifc81ea82019-04-18 13:27:22 +02001066 ypr_description(ctx, grp->dsc, grp->exts, &flag);
1067 ypr_reference(ctx, grp->ref, grp->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001068
1069 LY_ARRAY_FOR(grp->typedefs, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001070 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001071 yprp_typedef(ctx, &grp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001072 }
1073
1074 LY_ARRAY_FOR(grp->groupings, u) {
Radek Krejci59edcf72019-05-02 09:53:17 +02001075 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001076 yprp_grouping(ctx, &grp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001077 }
1078
1079 LY_LIST_FOR(grp->data, data) {
Radek Krejcifc81ea82019-04-18 13:27:22 +02001080 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001081 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001082 }
1083
1084 LY_ARRAY_FOR(grp->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001085 yprp_action(ctx, &grp->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001086 }
1087
1088 LEVEL--;
1089 ypr_close(ctx, flag);
1090}
1091
1092static void
Radek Krejci693262f2019-04-29 15:23:20 +02001093yprp_inout(struct ypr_ctx *ctx, const struct lysp_action_inout *inout, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001094{
1095 unsigned int u;
1096 struct lysp_node *data;
1097
1098 if (!inout->nodetype) {
1099 /* nodetype not set -> input/output is empty */
1100 return;
1101 }
1102 ypr_open(ctx->out, flag);
1103
1104 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (inout->nodetype == LYS_INPUT ? "input" : "output"));
1105 LEVEL++;
1106
Radek Krejci693262f2019-04-29 15:23:20 +02001107 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, inout->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001108 LY_ARRAY_FOR(inout->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001109 yprp_restr(ctx, &inout->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001110 }
1111 LY_ARRAY_FOR(inout->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001112 yprp_typedef(ctx, &inout->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001113 }
1114 LY_ARRAY_FOR(inout->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001115 yprp_grouping(ctx, &inout->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001116 }
1117
1118 LY_LIST_FOR(inout->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02001119 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001120 }
1121
1122 LEVEL--;
1123 ypr_close(ctx, 1);
1124}
1125
1126static void
Radek Krejci693262f2019-04-29 15:23:20 +02001127yprc_inout(struct ypr_ctx *ctx, const struct lysc_action *action, const struct lysc_action_inout *inout, int *flag)
1128{
1129 unsigned int u;
1130 struct lysc_node *data;
1131
1132 if (!inout->data) {
1133 /* input/output is empty */
1134 return;
1135 }
1136 ypr_open(ctx->out, flag);
1137
1138 ly_print(ctx->out, "\n%*s%s {\n", INDENT, (&action->input == inout) ? "input" : "output");
1139 LEVEL++;
1140
1141 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, (&action->input == inout) ? action->input_exts : action->output_exts, NULL, 0);
1142 LY_ARRAY_FOR(inout->musts, u) {
1143 yprc_must(ctx, &inout->musts[u], NULL);
1144 }
1145
1146 LY_LIST_FOR(inout->data, data) {
1147 yprc_node(ctx, data);
1148 }
1149
1150 LEVEL--;
1151 ypr_close(ctx, 1);
1152}
1153
1154static void
1155yprp_notification(struct ypr_ctx *ctx, const struct lysp_notif *notif)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001156{
1157 unsigned int u;
1158 int flag = 0;
1159 struct lysp_node *data;
1160
Radek Krejci56cc0872019-04-30 09:22:27 +02001161 LYOUT_CHECK(ctx->out);
1162
Radek Krejcid3ca0632019-04-16 16:54:54 +02001163 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1164
1165 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001166 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1167 yprp_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001168
1169 LY_ARRAY_FOR(notif->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001170 yprp_restr(ctx, &notif->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001171 }
Radek Krejci693262f2019-04-29 15:23:20 +02001172 ypr_status(ctx, notif->flags, notif->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001173 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1174 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1175
1176 LY_ARRAY_FOR(notif->typedefs, u) {
1177 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001178 yprp_typedef(ctx, &notif->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001179 }
1180
1181 LY_ARRAY_FOR(notif->groupings, u) {
1182 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001183 yprp_grouping(ctx, &notif->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001184 }
1185
1186 LY_LIST_FOR(notif->data, data) {
1187 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001188 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001189 }
1190
1191 LEVEL--;
1192 ypr_close(ctx, flag);
1193}
1194
1195static void
Radek Krejci693262f2019-04-29 15:23:20 +02001196yprc_notification(struct ypr_ctx *ctx, const struct lysc_notif *notif)
1197{
1198 unsigned int u;
1199 int flag = 0;
1200 struct lysc_node *data;
1201
Radek Krejci56cc0872019-04-30 09:22:27 +02001202 LYOUT_CHECK(ctx->out);
1203
Radek Krejci693262f2019-04-29 15:23:20 +02001204 ly_print(ctx->out, "%*snotification %s", INDENT, notif->name);
1205
1206 LEVEL++;
1207 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, notif->exts, &flag, 0);
1208 yprc_iffeatures(ctx, notif->iffeatures, notif->exts, &flag);
1209
1210 LY_ARRAY_FOR(notif->musts, u) {
1211 yprc_must(ctx, &notif->musts[u], &flag);
1212 }
1213 ypr_status(ctx, notif->flags, notif->exts, &flag);
1214 ypr_description(ctx, notif->dsc, notif->exts, &flag);
1215 ypr_reference(ctx, notif->ref, notif->exts, &flag);
1216
1217 LY_LIST_FOR(notif->data, data) {
1218 ypr_open(ctx->out, &flag);
1219 yprc_node(ctx, data);
1220 }
1221
1222 LEVEL--;
1223 ypr_close(ctx, flag);
1224}
1225
1226static void
1227yprp_action(struct ypr_ctx *ctx, const struct lysp_action *action)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001228{
1229 unsigned int u;
1230 int flag = 0;
1231
Radek Krejci56cc0872019-04-30 09:22:27 +02001232 LYOUT_CHECK(ctx->out);
1233
Radek Krejcid3ca0632019-04-16 16:54:54 +02001234 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1235
1236 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02001237 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1238 yprp_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1239 ypr_status(ctx, action->flags, action->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001240 ypr_description(ctx, action->dsc, action->exts, &flag);
1241 ypr_reference(ctx, action->ref, action->exts, &flag);
1242
1243 LY_ARRAY_FOR(action->typedefs, u) {
1244 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001245 yprp_typedef(ctx, &action->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001246 }
1247
1248 LY_ARRAY_FOR(action->groupings, u) {
1249 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001250 yprp_grouping(ctx, &action->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001251 }
1252
Radek Krejci693262f2019-04-29 15:23:20 +02001253 yprp_inout(ctx, &action->input, &flag);
1254 yprp_inout(ctx, &action->output, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001255
1256 LEVEL--;
1257 ypr_close(ctx, flag);
1258}
1259
1260static void
Radek Krejci693262f2019-04-29 15:23:20 +02001261yprc_action(struct ypr_ctx *ctx, const struct lysc_action *action)
1262{
1263 int flag = 0;
1264
Radek Krejci56cc0872019-04-30 09:22:27 +02001265 LYOUT_CHECK(ctx->out);
1266
Radek Krejci693262f2019-04-29 15:23:20 +02001267 ly_print(ctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name);
1268
1269 LEVEL++;
1270 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, action->exts, &flag, 0);
1271 yprc_iffeatures(ctx, action->iffeatures, action->exts, &flag);
1272 ypr_status(ctx, action->flags, action->exts, &flag);
1273 ypr_description(ctx, action->dsc, action->exts, &flag);
1274 ypr_reference(ctx, action->ref, action->exts, &flag);
1275
1276 yprc_inout(ctx, action, &action->input, &flag);
1277 yprc_inout(ctx, action, &action->output, &flag);
1278
1279 LEVEL--;
1280 ypr_close(ctx, flag);
1281}
1282
1283static void
1284yprp_node_common1(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001285{
Radek Krejci7871ce52019-06-11 16:44:56 +02001286 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejcid3ca0632019-04-16 16:54:54 +02001287 LEVEL++;
1288
Radek Krejci693262f2019-04-29 15:23:20 +02001289 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1290 yprp_when(ctx, node->when, flag);
1291 yprp_iffeatures(ctx, node->iffeatures, node->exts, flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001292}
1293
1294static void
Radek Krejci693262f2019-04-29 15:23:20 +02001295yprc_node_common1(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001296{
Radek Krejci693262f2019-04-29 15:23:20 +02001297 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001298
Radek Krejci42903ea2019-06-14 16:24:56 +02001299 ly_print(ctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001300 LEVEL++;
1301
1302 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, node->exts, flag, 0);
1303 LY_ARRAY_FOR(node->when, u) {
1304 yprc_when(ctx, node->when[u], flag);
1305 }
1306 yprc_iffeatures(ctx, node->iffeatures, node->exts, flag);
1307}
1308
1309/* macr oto unify the code */
1310#define YPR_NODE_COMMON2 \
1311 ypr_config(ctx, node->flags, node->exts, flag); \
1312 if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \
1313 ypr_mandatory(ctx, node->flags, node->exts, flag); \
1314 } \
1315 ypr_status(ctx, node->flags, node->exts, flag); \
1316 ypr_description(ctx, node->dsc, node->exts, flag); \
1317 ypr_reference(ctx, node->ref, node->exts, flag)
1318
1319static void
1320yprp_node_common2(struct ypr_ctx *ctx, const struct lysp_node *node, int *flag)
1321{
1322 YPR_NODE_COMMON2;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001323}
1324
1325static void
Radek Krejci693262f2019-04-29 15:23:20 +02001326yprc_node_common2(struct ypr_ctx *ctx, const struct lysc_node *node, int *flag)
1327{
1328 YPR_NODE_COMMON2;
1329}
1330
1331#undef YPR_NODE_COMMON2
1332
1333static void
1334yprp_container(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001335{
1336 unsigned int u;
1337 int flag = 0;
1338 struct lysp_node *child;
1339 struct lysp_node_container *cont = (struct lysp_node_container *)node;
1340
Radek Krejci693262f2019-04-29 15:23:20 +02001341 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001342
1343 LY_ARRAY_FOR(cont->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001344 yprp_restr(ctx, &cont->musts[u], "must", &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001345 }
1346 if (cont->presence) {
1347 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001348 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, cont->presence, cont->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001349 }
1350
Radek Krejci693262f2019-04-29 15:23:20 +02001351 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001352
1353 LY_ARRAY_FOR(cont->typedefs, u) {
1354 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001355 yprp_typedef(ctx, &cont->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001356 }
1357
1358 LY_ARRAY_FOR(cont->groupings, u) {
1359 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001360 yprp_grouping(ctx, &cont->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001361 }
1362
1363 LY_LIST_FOR(cont->child, child) {
1364 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001365 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001366 }
1367
1368 LY_ARRAY_FOR(cont->actions, u) {
1369 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001370 yprp_action(ctx, &cont->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001371 }
1372
1373 LY_ARRAY_FOR(cont->notifs, u) {
1374 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001375 yprp_notification(ctx, &cont->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001376 }
1377
1378 LEVEL--;
1379 ypr_close(ctx, flag);
1380}
1381
1382static void
Radek Krejci693262f2019-04-29 15:23:20 +02001383yprc_container(struct ypr_ctx *ctx, const struct lysc_node *node)
1384{
1385 unsigned int u;
1386 int flag = 0;
1387 struct lysc_node *child;
1388 struct lysc_node_container *cont = (struct lysc_node_container *)node;
1389
1390 yprc_node_common1(ctx, node, &flag);
1391
1392 LY_ARRAY_FOR(cont->musts, u) {
1393 yprc_must(ctx, &cont->musts[u], &flag);
1394 }
1395 if (cont->flags & LYS_PRESENCE) {
1396 ypr_open(ctx->out, &flag);
1397 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, "true", cont->exts);
1398 }
1399
1400 yprc_node_common2(ctx, node, &flag);
1401
1402 LY_LIST_FOR(cont->child, child) {
1403 ypr_open(ctx->out, &flag);
1404 yprc_node(ctx, child);
1405 }
1406
1407 LY_ARRAY_FOR(cont->actions, u) {
1408 ypr_open(ctx->out, &flag);
1409 yprc_action(ctx, &cont->actions[u]);
1410 }
1411
1412 LY_ARRAY_FOR(cont->notifs, u) {
1413 ypr_open(ctx->out, &flag);
1414 yprc_notification(ctx, &cont->notifs[u]);
1415 }
1416
1417 LEVEL--;
1418 ypr_close(ctx, flag);
1419}
1420
1421static void
1422yprp_case(struct ypr_ctx *ctx, const struct lysp_node *node)
1423{
1424 int flag = 0;
1425 struct lysp_node *child;
1426 struct lysp_node_case *cas = (struct lysp_node_case *)node;
1427
1428 yprp_node_common1(ctx, node, &flag);
1429 yprp_node_common2(ctx, node, &flag);
1430
1431 LY_LIST_FOR(cas->child, child) {
1432 ypr_open(ctx->out, &flag);
1433 yprp_node(ctx, child);
1434 }
1435
1436 LEVEL--;
1437 ypr_close(ctx, flag);
1438}
1439
1440static void
1441yprc_case(struct ypr_ctx *ctx, const struct lysc_node_case *cs)
1442{
1443 int flag = 0;
1444 struct lysc_node *child;
1445
1446 yprc_node_common1(ctx, (struct lysc_node*)cs, &flag);
1447 yprc_node_common2(ctx, (struct lysc_node*)cs, &flag);
1448
1449 for (child = cs->child; child && child->parent == (struct lysc_node*)cs; child = child->next) {
1450 ypr_open(ctx->out, &flag);
1451 yprc_node(ctx, child);
1452 }
1453
1454 LEVEL--;
1455 ypr_close(ctx, flag);
1456}
1457
1458static void
1459yprp_choice(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001460{
1461 int flag = 0;
1462 struct lysp_node *child;
1463 struct lysp_node_choice *choice = (struct lysp_node_choice *)node;
1464
Radek Krejci693262f2019-04-29 15:23:20 +02001465 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001466
1467 if (choice->dflt) {
1468 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001469 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt, choice->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001470 }
1471
Radek Krejci693262f2019-04-29 15:23:20 +02001472 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001473
1474 LY_LIST_FOR(choice->child, child) {
1475 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001476 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001477 }
1478
1479 LEVEL--;
1480 ypr_close(ctx, flag);
1481}
1482
1483static void
Radek Krejci693262f2019-04-29 15:23:20 +02001484yprc_choice(struct ypr_ctx *ctx, const struct lysc_node *node)
1485{
1486 int flag = 0;
1487 struct lysc_node_case *cs;
1488 struct lysc_node_choice *choice = (struct lysc_node_choice *)node;
1489
1490 yprc_node_common1(ctx, node, &flag);
1491
1492 if (choice->dflt) {
1493 ypr_open(ctx->out, &flag);
1494 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, choice->dflt->name, choice->exts);
1495 }
1496
1497 yprc_node_common2(ctx, node, &flag);
1498
1499 for (cs = choice->cases; cs; cs = (struct lysc_node_case*)cs->next) {
1500 ypr_open(ctx->out, &flag);
1501 yprc_case(ctx, cs);
1502 }
1503
1504 LEVEL--;
1505 ypr_close(ctx, flag);
1506}
1507
1508static void
1509yprp_leaf(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001510{
1511 unsigned int u;
1512 struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node;
1513
Radek Krejci693262f2019-04-29 15:23:20 +02001514 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001515
Radek Krejci693262f2019-04-29 15:23:20 +02001516 yprp_type(ctx, &leaf->type);
1517 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001518 LY_ARRAY_FOR(leaf->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001519 yprp_restr(ctx, &leaf->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001520 }
Radek Krejci693262f2019-04-29 15:23:20 +02001521 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001522
Radek Krejci693262f2019-04-29 15:23:20 +02001523 yprp_node_common2(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001524
1525 LEVEL--;
1526 ly_print(ctx->out, "%*s}\n", INDENT);
1527}
1528
1529static void
Radek Krejci693262f2019-04-29 15:23:20 +02001530yprc_leaf(struct ypr_ctx *ctx, const struct lysc_node *node)
1531{
1532 unsigned int u;
1533 struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node;
1534
1535 yprc_node_common1(ctx, node, NULL);
1536
1537 yprc_type(ctx, leaf->type);
1538 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, leaf->units, leaf->exts);
1539 LY_ARRAY_FOR(leaf->musts, u) {
1540 yprc_must(ctx, &leaf->musts[u], NULL);
1541 }
1542 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, leaf->dflt, leaf->exts);
1543
1544 yprc_node_common2(ctx, node, NULL);
1545
1546 LEVEL--;
1547 ly_print(ctx->out, "%*s}\n", INDENT);
1548}
1549
1550static void
1551yprp_leaflist(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001552{
1553 unsigned int u;
1554 struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node;
1555
Radek Krejci693262f2019-04-29 15:23:20 +02001556 yprp_node_common1(ctx, node, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001557
Radek Krejci693262f2019-04-29 15:23:20 +02001558 yprp_type(ctx, &llist->type);
1559 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001560 LY_ARRAY_FOR(llist->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001561 yprp_restr(ctx, &llist->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001562 }
1563 LY_ARRAY_FOR(llist->dflts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001564 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001565 }
1566
Radek Krejci693262f2019-04-29 15:23:20 +02001567 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001568
1569 if (llist->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001570 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001571 }
1572 if (llist->flags & LYS_SET_MAX) {
1573 if (llist->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001574 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001575 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001576 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001577 }
1578 }
1579
1580 if (llist->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001581 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001582 }
1583
Radek Krejci693262f2019-04-29 15:23:20 +02001584 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001585 ypr_description(ctx, node->dsc, node->exts, NULL);
1586 ypr_reference(ctx, node->ref, node->exts, NULL);
1587
1588 LEVEL--;
1589 ly_print(ctx->out, "%*s}\n", INDENT);
1590}
1591
1592static void
Radek Krejci693262f2019-04-29 15:23:20 +02001593yprc_leaflist(struct ypr_ctx *ctx, const struct lysc_node *node)
1594{
1595 unsigned int u;
1596 struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node;
1597
1598 yprc_node_common1(ctx, node, NULL);
1599
1600 yprc_type(ctx, llist->type);
1601 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, llist->units, llist->exts);
1602 LY_ARRAY_FOR(llist->musts, u) {
1603 yprc_must(ctx, &llist->musts[u], NULL);
1604 }
1605 LY_ARRAY_FOR(llist->dflts, u) {
1606 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, llist->dflts[u], llist->exts);
1607 }
1608
1609 ypr_config(ctx, node->flags, node->exts, NULL);
1610
1611 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, llist->exts, llist->min, NULL);
1612 if (llist->max) {
1613 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, llist->exts, llist->max, NULL);
1614 } else {
1615 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", llist->exts);
1616 }
1617
1618 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", llist->exts);
1619
1620 ypr_status(ctx, node->flags, node->exts, NULL);
1621 ypr_description(ctx, node->dsc, node->exts, NULL);
1622 ypr_reference(ctx, node->ref, node->exts, NULL);
1623
1624 LEVEL--;
1625 ly_print(ctx->out, "%*s}\n", INDENT);
1626}
1627
1628static void
1629yprp_list(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001630{
1631 unsigned int u;
1632 int flag = 0;
1633 struct lysp_node *child;
1634 struct lysp_node_list *list = (struct lysp_node_list *)node;
1635
Radek Krejci693262f2019-04-29 15:23:20 +02001636 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001637
1638 LY_ARRAY_FOR(list->musts, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001639 yprp_restr(ctx, &list->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001640 }
1641 if (list->key) {
1642 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001643 ypr_substmt(ctx, LYEXT_SUBSTMT_KEY, 0, list->key, list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001644 }
1645 LY_ARRAY_FOR(list->uniques, u) {
1646 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001647 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, u, list->uniques[u], list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001648 }
1649
Radek Krejci693262f2019-04-29 15:23:20 +02001650 ypr_config(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001651
1652 if (list->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02001653 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001654 }
1655 if (list->flags & LYS_SET_MAX) {
1656 if (list->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001657 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001658 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001659 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001660 }
1661 }
1662
1663 if (list->flags & LYS_ORDBY_MASK) {
Radek Krejci693262f2019-04-29 15:23:20 +02001664 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001665 }
1666
Radek Krejci693262f2019-04-29 15:23:20 +02001667 ypr_status(ctx, node->flags, node->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001668 ypr_description(ctx, node->dsc, node->exts, NULL);
1669 ypr_reference(ctx, node->ref, node->exts, NULL);
1670
1671 LY_ARRAY_FOR(list->typedefs, u) {
1672 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001673 yprp_typedef(ctx, &list->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001674 }
1675
1676 LY_ARRAY_FOR(list->groupings, u) {
1677 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001678 yprp_grouping(ctx, &list->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001679 }
1680
1681 LY_LIST_FOR(list->child, child) {
1682 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001683 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001684 }
1685
1686 LY_ARRAY_FOR(list->actions, u) {
1687 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001688 yprp_action(ctx, &list->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001689 }
1690
1691 LY_ARRAY_FOR(list->notifs, u) {
1692 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001693 yprp_notification(ctx, &list->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001694 }
1695
1696 LEVEL--;
1697 ypr_close(ctx, flag);
1698}
1699
1700static void
Radek Krejci693262f2019-04-29 15:23:20 +02001701yprc_list(struct ypr_ctx *ctx, const struct lysc_node *node)
1702{
1703 unsigned int u, v;
1704 int flag = 0;
1705 struct lysc_node *child;
1706 struct lysc_node_list *list = (struct lysc_node_list *)node;
1707
1708 yprc_node_common1(ctx, node, &flag);
1709
1710 LY_ARRAY_FOR(list->musts, u) {
1711 yprc_must(ctx, &list->musts[u], NULL);
1712 }
1713 if (list->keys) {
1714 ypr_open(ctx->out, &flag);
1715 ly_print(ctx->out, "%*skey \"", INDENT);
1716 LY_ARRAY_FOR(list->keys, u) {
1717 ly_print(ctx->out, "%s%s", u > 0 ? ", " : "", list->keys[u]->name);
1718 }
Radek Krejci73c88f52019-06-14 16:24:19 +02001719 ly_print(ctx->out, "\";\n");
Radek Krejci693262f2019-04-29 15:23:20 +02001720 }
1721 LY_ARRAY_FOR(list->uniques, u) {
1722 ypr_open(ctx->out, &flag);
1723 ly_print(ctx->out, "%*sunique \"", INDENT);
1724 LY_ARRAY_FOR(list->uniques[u], v) {
1725 ly_print(ctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name);
1726 }
1727 ypr_close(ctx, 0);
1728 }
1729
1730 ypr_config(ctx, node->flags, node->exts, NULL);
1731
1732 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, list->exts, list->min, NULL);
1733 if (list->max) {
1734 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, list->exts, list->max, NULL);
1735 } else {
1736 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", list->exts);
1737 }
1738
1739 ypr_substmt(ctx, LYEXT_SUBSTMT_ORDEREDBY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", list->exts);
1740
1741 ypr_status(ctx, node->flags, node->exts, NULL);
1742 ypr_description(ctx, node->dsc, node->exts, NULL);
1743 ypr_reference(ctx, node->ref, node->exts, NULL);
1744
1745 LY_LIST_FOR(list->child, child) {
1746 ypr_open(ctx->out, &flag);
1747 yprc_node(ctx, child);
1748 }
1749
1750 LY_ARRAY_FOR(list->actions, u) {
1751 ypr_open(ctx->out, &flag);
1752 yprc_action(ctx, &list->actions[u]);
1753 }
1754
1755 LY_ARRAY_FOR(list->notifs, u) {
1756 ypr_open(ctx->out, &flag);
1757 yprc_notification(ctx, &list->notifs[u]);
1758 }
1759
1760 LEVEL--;
1761 ypr_close(ctx, flag);
1762}
1763
1764static void
1765yprp_refine(struct ypr_ctx *ctx, struct lysp_refine *refine)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001766{
1767 unsigned int u;
1768 int flag = 0;
1769
1770 ly_print(ctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid);
1771 LEVEL++;
1772
Radek Krejci693262f2019-04-29 15:23:20 +02001773 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, refine->exts, &flag, 0);
1774 yprp_iffeatures(ctx, refine->iffeatures, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001775
1776 LY_ARRAY_FOR(refine->musts, u) {
1777 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001778 yprp_restr(ctx, &refine->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001779 }
1780
1781 if (refine->presence) {
1782 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001783 ypr_substmt(ctx, LYEXT_SUBSTMT_PRESENCE, 0, refine->presence, refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001784 }
1785
1786 LY_ARRAY_FOR(refine->dflts, u) {
1787 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001788 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, u, refine->dflts[u], refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001789 }
1790
Radek Krejci693262f2019-04-29 15:23:20 +02001791 ypr_config(ctx, refine->flags, refine->exts, &flag);
1792 ypr_mandatory(ctx, refine->flags, refine->exts, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001793
1794 if (refine->flags & LYS_SET_MIN) {
1795 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001796 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, refine->exts, refine->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001797 }
1798 if (refine->flags & LYS_SET_MAX) {
1799 ypr_open(ctx->out, &flag);
1800 if (refine->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02001801 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, refine->exts, refine->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001802 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02001803 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", refine->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001804 }
1805 }
1806
1807 ypr_description(ctx, refine->dsc, refine->exts, &flag);
1808 ypr_reference(ctx, refine->ref, refine->exts, &flag);
1809
1810 LEVEL--;
1811 ypr_close(ctx, flag);
1812}
1813
1814static void
Radek Krejci693262f2019-04-29 15:23:20 +02001815yprp_augment(struct ypr_ctx *ctx, const struct lysp_augment *aug)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001816{
1817 unsigned int u;
1818 struct lysp_node *child;
1819
1820 ly_print(ctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid);
1821 LEVEL++;
1822
Radek Krejci693262f2019-04-29 15:23:20 +02001823 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, aug->exts, NULL, 0);
1824 yprp_when(ctx, aug->when, NULL);
1825 yprp_iffeatures(ctx, aug->iffeatures, aug->exts, NULL);
1826 ypr_status(ctx, aug->flags, aug->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001827 ypr_description(ctx, aug->dsc, aug->exts, NULL);
1828 ypr_reference(ctx, aug->ref, aug->exts, NULL);
1829
1830 LY_LIST_FOR(aug->child, child) {
Radek Krejci693262f2019-04-29 15:23:20 +02001831 yprp_node(ctx, child);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001832 }
1833
1834 LY_ARRAY_FOR(aug->actions, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001835 yprp_action(ctx, &aug->actions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001836 }
1837
1838 LY_ARRAY_FOR(aug->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02001839 yprp_notification(ctx, &aug->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001840 }
1841
1842 LEVEL--;
Radek Krejcifc81ea82019-04-18 13:27:22 +02001843 ypr_close(ctx, 1);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001844}
1845
1846
1847static void
Radek Krejci693262f2019-04-29 15:23:20 +02001848yprp_uses(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001849{
1850 unsigned int u;
1851 int flag = 0;
1852 struct lysp_node_uses *uses = (struct lysp_node_uses *)node;
1853
Radek Krejci693262f2019-04-29 15:23:20 +02001854 yprp_node_common1(ctx, node, &flag);
1855 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001856
1857 LY_ARRAY_FOR(uses->refines, u) {
1858 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001859 yprp_refine(ctx, &uses->refines[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001860 }
1861
1862 LY_ARRAY_FOR(uses->augments, u) {
1863 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001864 yprp_augment(ctx, &uses->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001865 }
1866
1867 LEVEL--;
1868 ypr_close(ctx, flag);
1869}
1870
1871static void
Radek Krejci693262f2019-04-29 15:23:20 +02001872yprp_anydata(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001873{
1874 unsigned int u;
1875 int flag = 0;
1876 struct lysp_node_anydata *any = (struct lysp_node_anydata *)node;
1877
Radek Krejci693262f2019-04-29 15:23:20 +02001878 yprp_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001879
1880 LY_ARRAY_FOR(any->musts, u) {
1881 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001882 yprp_restr(ctx, &any->musts[u], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001883 }
1884
Radek Krejci693262f2019-04-29 15:23:20 +02001885 yprp_node_common2(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001886
1887 LEVEL--;
1888 ypr_close(ctx, flag);
1889}
1890
1891static void
Radek Krejci693262f2019-04-29 15:23:20 +02001892yprc_anydata(struct ypr_ctx *ctx, const struct lysc_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001893{
Radek Krejci693262f2019-04-29 15:23:20 +02001894 unsigned int u;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001895 int flag = 0;
Radek Krejci693262f2019-04-29 15:23:20 +02001896 struct lysc_node_anydata *any = (struct lysc_node_anydata *)node;
Radek Krejcid3ca0632019-04-16 16:54:54 +02001897
Radek Krejci693262f2019-04-29 15:23:20 +02001898 yprc_node_common1(ctx, node, &flag);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001899
Radek Krejci693262f2019-04-29 15:23:20 +02001900 LY_ARRAY_FOR(any->musts, u) {
Radek Krejcid3ca0632019-04-16 16:54:54 +02001901 ypr_open(ctx->out, &flag);
Radek Krejci693262f2019-04-29 15:23:20 +02001902 yprc_must(ctx, &any->musts[u], NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001903 }
1904
Radek Krejci693262f2019-04-29 15:23:20 +02001905 yprc_node_common2(ctx, node, &flag);
1906
Radek Krejcid3ca0632019-04-16 16:54:54 +02001907 LEVEL--;
1908 ypr_close(ctx, flag);
1909}
1910
1911static void
Radek Krejci693262f2019-04-29 15:23:20 +02001912yprp_node(struct ypr_ctx *ctx, const struct lysp_node *node)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001913{
Radek Krejci56cc0872019-04-30 09:22:27 +02001914 LYOUT_CHECK(ctx->out);
1915
Radek Krejcid3ca0632019-04-16 16:54:54 +02001916 switch (node->nodetype) {
1917 case LYS_CONTAINER:
Radek Krejci693262f2019-04-29 15:23:20 +02001918 yprp_container(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001919 break;
1920 case LYS_CHOICE:
Radek Krejci693262f2019-04-29 15:23:20 +02001921 yprp_choice(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001922 break;
1923 case LYS_LEAF:
Radek Krejci693262f2019-04-29 15:23:20 +02001924 yprp_leaf(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001925 break;
1926 case LYS_LEAFLIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001927 yprp_leaflist(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001928 break;
1929 case LYS_LIST:
Radek Krejci693262f2019-04-29 15:23:20 +02001930 yprp_list(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001931 break;
1932 case LYS_USES:
Radek Krejci693262f2019-04-29 15:23:20 +02001933 yprp_uses(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001934 break;
1935 case LYS_ANYXML:
1936 case LYS_ANYDATA:
Radek Krejci693262f2019-04-29 15:23:20 +02001937 yprp_anydata(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001938 break;
1939 case LYS_CASE:
Radek Krejci693262f2019-04-29 15:23:20 +02001940 yprp_case(ctx, node);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001941 break;
1942 default:
1943 break;
1944 }
1945}
1946
1947static void
Radek Krejci693262f2019-04-29 15:23:20 +02001948yprc_node(struct ypr_ctx *ctx, const struct lysc_node *node)
1949{
Radek Krejci56cc0872019-04-30 09:22:27 +02001950 LYOUT_CHECK(ctx->out);
1951
Radek Krejci693262f2019-04-29 15:23:20 +02001952 switch (node->nodetype) {
1953 case LYS_CONTAINER:
1954 yprc_container(ctx, node);
1955 break;
1956 case LYS_CHOICE:
1957 yprc_choice(ctx, node);
1958 break;
1959 case LYS_LEAF:
1960 yprc_leaf(ctx, node);
1961 break;
1962 case LYS_LEAFLIST:
1963 yprc_leaflist(ctx, node);
1964 break;
1965 case LYS_LIST:
1966 yprc_list(ctx, node);
1967 break;
1968 case LYS_ANYXML:
1969 case LYS_ANYDATA:
1970 yprc_anydata(ctx, node);
1971 break;
1972 default:
1973 break;
1974 }
1975}
1976
1977static void
1978yprp_deviation(struct ypr_ctx *ctx, const struct lysp_deviation *deviation)
Radek Krejcid3ca0632019-04-16 16:54:54 +02001979{
1980 unsigned int u, v;
1981 struct lysp_deviate_add *add;
1982 struct lysp_deviate_rpl *rpl;
1983 struct lysp_deviate_del *del;
1984
1985 ly_print(ctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid);
1986 LEVEL++;
1987
Radek Krejci693262f2019-04-29 15:23:20 +02001988 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02001989 ypr_description(ctx, deviation->dsc, deviation->exts, NULL);
1990 ypr_reference(ctx, deviation->ref, deviation->exts, NULL);
1991
1992 LY_ARRAY_FOR(deviation->deviates, u) {
1993 ly_print(ctx->out, "%*sdeviate ", INDENT);
1994 if (deviation->deviates[u].mod == LYS_DEV_NOT_SUPPORTED) {
1995 if (deviation->deviates[u].exts) {
1996 ly_print(ctx->out, "not-supported {\n");
1997 LEVEL++;
1998
Radek Krejci693262f2019-04-29 15:23:20 +02001999 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, deviation->deviates[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002000 } else {
2001 ly_print(ctx->out, "not-supported;\n");
2002 continue;
2003 }
2004 } else if (deviation->deviates[u].mod == LYS_DEV_ADD) {
2005 add = (struct lysp_deviate_add*)&deviation->deviates[u];
2006 ly_print(ctx->out, "add {\n");
2007 LEVEL++;
2008
Radek Krejci693262f2019-04-29 15:23:20 +02002009 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, add->exts, NULL, 0);
2010 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, add->units, add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002011 LY_ARRAY_FOR(add->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002012 yprp_restr(ctx, &add->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002013 }
2014 LY_ARRAY_FOR(add->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002015 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, add->uniques[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002016 }
2017 LY_ARRAY_FOR(add->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002018 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, add->dflts[v], add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002019 }
Radek Krejci693262f2019-04-29 15:23:20 +02002020 ypr_config(ctx, add->flags, add->exts, NULL);
2021 ypr_mandatory(ctx, add->flags, add->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002022 if (add->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002023 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, add->exts, add->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002024 }
2025 if (add->flags & LYS_SET_MAX) {
2026 if (add->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002027 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, add->exts, add->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002028 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002029 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", add->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002030 }
2031 }
2032 } else if (deviation->deviates[u].mod == LYS_DEV_REPLACE) {
2033 rpl = (struct lysp_deviate_rpl*)&deviation->deviates[u];
2034 ly_print(ctx->out, "replace {\n");
2035 LEVEL++;
2036
Radek Krejci693262f2019-04-29 15:23:20 +02002037 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, rpl->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002038 if (rpl->type) {
Radek Krejci693262f2019-04-29 15:23:20 +02002039 yprp_type(ctx, rpl->type);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002040 }
Radek Krejci693262f2019-04-29 15:23:20 +02002041 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, rpl->units, rpl->exts);
2042 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, 0, rpl->dflt, rpl->exts);
2043 ypr_config(ctx, rpl->flags, rpl->exts, NULL);
2044 ypr_mandatory(ctx, rpl->flags, rpl->exts, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002045 if (rpl->flags & LYS_SET_MIN) {
Radek Krejci693262f2019-04-29 15:23:20 +02002046 ypr_unsigned(ctx, LYEXT_SUBSTMT_MIN, 0, rpl->exts, rpl->min, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002047 }
2048 if (rpl->flags & LYS_SET_MAX) {
2049 if (rpl->max) {
Radek Krejci693262f2019-04-29 15:23:20 +02002050 ypr_unsigned(ctx, LYEXT_SUBSTMT_MAX, 0, rpl->exts, rpl->max, NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002051 } else {
Radek Krejci693262f2019-04-29 15:23:20 +02002052 ypr_substmt(ctx, LYEXT_SUBSTMT_MAX, 0, "unbounded", rpl->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002053 }
2054 }
2055 } else if (deviation->deviates[u].mod == LYS_DEV_DELETE) {
2056 del = (struct lysp_deviate_del*)&deviation->deviates[u];
2057 ly_print(ctx->out, "delete {\n");
2058 LEVEL++;
2059
Radek Krejci693262f2019-04-29 15:23:20 +02002060 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, del->exts, NULL, 0);
2061 ypr_substmt(ctx, LYEXT_SUBSTMT_UNITS, 0, del->units, del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002062 LY_ARRAY_FOR(del->musts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002063 yprp_restr(ctx, &del->musts[v], "must", NULL);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002064 }
2065 LY_ARRAY_FOR(del->uniques, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002066 ypr_substmt(ctx, LYEXT_SUBSTMT_UNIQUE, v, del->uniques[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002067 }
2068 LY_ARRAY_FOR(del->dflts, v) {
Radek Krejci693262f2019-04-29 15:23:20 +02002069 ypr_substmt(ctx, LYEXT_SUBSTMT_DEFAULT, v, del->dflts[v], del->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002070 }
2071 }
2072
2073 LEVEL--;
2074 ypr_close(ctx, 1);
2075 }
2076
2077 LEVEL--;
2078 ypr_close(ctx, 1);
2079}
2080
Radek Krejci693262f2019-04-29 15:23:20 +02002081/**
2082 * @brief Minimal print of a schema.
2083 *
2084 * To print
2085 * a) compiled schema when it is not compiled or
2086 * b) parsed when the parsed form was already removed
2087 */
2088static LY_ERR
2089ypr_missing_format(struct ypr_ctx *ctx, const struct lys_module *module)
2090{
2091 /* module-header-stmts */
2092 if (module->version) {
2093 if (module->version) {
2094 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", NULL);
2095 }
2096 }
2097 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, NULL);
2098 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, NULL);
2099
2100 /* meta-stmts */
2101 if (module->org || module->contact || module->dsc || module->ref) {
2102 ly_print(ctx->out, "\n");
2103 }
2104 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, NULL);
2105 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, NULL);
2106 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, NULL);
2107 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, NULL);
2108
2109 /* revision-stmts */
2110 if (module->revision) {
2111 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2112 }
2113
2114 LEVEL--;
2115 ly_print(ctx->out, "%*s}\n", INDENT);
2116 ly_print_flush(ctx->out);
2117
2118 return LY_SUCCESS;
2119}
2120
Radek Krejcid3ca0632019-04-16 16:54:54 +02002121LY_ERR
2122yang_print_parsed(struct lyout *out, const struct lys_module *module)
2123{
2124 unsigned int u;
2125 struct lysp_node *data;
2126 struct lysp_module *modp = module->parsed;
Radek Krejci693262f2019-04-29 15:23:20 +02002127 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module, .schema = YPR_PARSED}, *ctx = &ctx_;
Radek Krejcid3ca0632019-04-16 16:54:54 +02002128
2129 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2130 LEVEL++;
2131
Radek Krejci693262f2019-04-29 15:23:20 +02002132 if (!modp) {
2133 ly_print(ctx->out, "%*s/* PARSED INFORMATION ARE NOT FULLY PRESENT */\n", INDENT);
2134 return ypr_missing_format(ctx, module);
2135 }
2136
Radek Krejcid3ca0632019-04-16 16:54:54 +02002137 /* module-header-stmts */
2138 if (module->version) {
2139 if (module->version) {
Radek Krejci693262f2019-04-29 15:23:20 +02002140 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 +02002141 }
2142 }
Radek Krejci693262f2019-04-29 15:23:20 +02002143 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modp->exts);
2144 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002145
2146 /* linkage-stmts */
2147 LY_ARRAY_FOR(modp->imports, u) {
Radek Krejci7871ce52019-06-11 16:44:56 +02002148 ly_print(out, "%s%*simport %s {\n", u ? "" : "\n", INDENT, modp->imports[u].module->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002149 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002150 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->imports[u].exts, NULL, 0);
2151 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modp->imports[u].prefix, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002152 if (modp->imports[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002153 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->imports[u].rev, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002154 }
Radek Krejci693262f2019-04-29 15:23:20 +02002155 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->imports[u].dsc, modp->imports[u].exts);
2156 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->imports[u].ref, modp->imports[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002157 LEVEL--;
2158 ly_print(out, "%*s}\n", INDENT);
2159 }
2160 LY_ARRAY_FOR(modp->includes, u) {
2161 if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) {
Radek Krejci7871ce52019-06-11 16:44:56 +02002162 ly_print(out, "%s%*sinclude %s {\n", u ? "" : "\n", INDENT, modp->includes[u].submodule->name);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002163 LEVEL++;
Radek Krejci693262f2019-04-29 15:23:20 +02002164 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modp->includes[u].exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002165 if (modp->includes[u].rev[0]) {
Radek Krejci693262f2019-04-29 15:23:20 +02002166 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modp->includes[u].rev, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002167 }
Radek Krejci693262f2019-04-29 15:23:20 +02002168 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, modp->includes[u].dsc, modp->includes[u].exts);
2169 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, modp->includes[u].ref, modp->includes[u].exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002170 LEVEL--;
2171 ly_print(out, "%*s}\n", INDENT);
2172 } else {
2173 ly_print(out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].submodule->name);
2174 }
2175 }
2176
2177 /* meta-stmts */
2178 if (module->org || module->contact || module->dsc || module->ref) {
2179 ly_print(out, "\n");
2180 }
Radek Krejci693262f2019-04-29 15:23:20 +02002181 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modp->exts);
2182 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modp->exts);
2183 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modp->exts);
2184 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modp->exts);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002185
2186 /* revision-stmts */
2187 if (modp->revs) {
2188 ly_print(out, "\n");
2189 }
2190 LY_ARRAY_FOR(modp->revs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002191 yprp_revision(ctx, &modp->revs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002192 }
2193 /* body-stmts */
2194 LY_ARRAY_FOR(modp->extensions, u) {
2195 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002196 yprp_extension(ctx, &modp->extensions[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002197 }
2198 if (modp->exts) {
2199 ly_print(out, "\n");
Radek Krejci693262f2019-04-29 15:23:20 +02002200 yprp_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->parsed->exts, NULL, 0);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002201 }
2202
2203 LY_ARRAY_FOR(modp->features, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002204 yprp_feature(ctx, &modp->features[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002205 }
2206
2207 LY_ARRAY_FOR(modp->identities, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002208 yprp_identity(ctx, &modp->identities[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002209 }
2210
2211 LY_ARRAY_FOR(modp->typedefs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002212 yprp_typedef(ctx, &modp->typedefs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002213 }
2214
2215 LY_ARRAY_FOR(modp->groupings, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002216 yprp_grouping(ctx, &modp->groupings[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002217 }
2218
2219 LY_LIST_FOR(modp->data, data) {
Radek Krejci693262f2019-04-29 15:23:20 +02002220 yprp_node(ctx, data);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002221 }
2222
2223 LY_ARRAY_FOR(modp->augments, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002224 yprp_augment(ctx, &modp->augments[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002225 }
2226
2227 LY_ARRAY_FOR(modp->rpcs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002228 yprp_action(ctx, &modp->rpcs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002229 }
2230
2231 LY_ARRAY_FOR(modp->notifs, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002232 yprp_notification(ctx, &modp->notifs[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002233 }
2234
2235 LY_ARRAY_FOR(modp->deviations, u) {
Radek Krejci693262f2019-04-29 15:23:20 +02002236 yprp_deviation(ctx, &modp->deviations[u]);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002237 }
2238
2239 LEVEL--;
2240 ly_print(out, "%*s}\n", INDENT);
2241 ly_print_flush(out);
2242
2243 return LY_SUCCESS;
2244}
2245
2246LY_ERR
2247yang_print_compiled(struct lyout *out, const struct lys_module *module)
2248{
Radek Krejci693262f2019-04-29 15:23:20 +02002249 unsigned int u;
2250 struct lysc_node *data;
2251 struct lysc_module *modc = module->compiled;
2252 struct ypr_ctx ctx_ = {.out = out, .level = 0, .module = module}, *ctx = &ctx_;
2253
2254 ly_print(ctx->out, "%*smodule %s {\n", INDENT, module->name);
2255 LEVEL++;
2256
2257 if (!modc) {
2258 ly_print(ctx->out, "%*s/* COMPILED INFORMATION ARE NOT PRESENT */\n", INDENT);
2259 return ypr_missing_format(ctx, module);
2260 }
2261
2262 /* module-header-stmts */
2263 if (module->version) {
2264 if (module->version) {
2265 ypr_substmt(ctx, LYEXT_SUBSTMT_VERSION, 0, module->version == LYS_VERSION_1_1 ? "1.1" : "1", modc->exts);
2266 }
2267 }
2268 ypr_substmt(ctx, LYEXT_SUBSTMT_NAMESPACE, 0, module->ns, modc->exts);
2269 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, module->prefix, modc->exts);
2270
2271 /* linkage-stmts */
2272 LY_ARRAY_FOR(modc->imports, u) {
2273 ly_print(out, "\n%*simport %s {\n", INDENT, modc->imports[u].module->name);
2274 LEVEL++;
2275 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, modc->imports[u].exts, NULL, 0);
2276 ypr_substmt(ctx, LYEXT_SUBSTMT_PREFIX, 0, modc->imports[u].prefix, modc->imports[u].exts);
2277 if (modc->imports[u].module->revision) {
2278 ypr_substmt(ctx, LYEXT_SUBSTMT_REVISIONDATE, 0, modc->imports[u].module->revision, modc->imports[u].exts);
2279 }
2280 LEVEL--;
2281 ly_print(out, "%*s}\n", INDENT);
2282 }
2283
2284 /* meta-stmts */
2285 if (module->org || module->contact || module->dsc || module->ref) {
2286 ly_print(out, "\n");
2287 }
2288 ypr_substmt(ctx, LYEXT_SUBSTMT_ORGANIZATION, 0, module->org, modc->exts);
2289 ypr_substmt(ctx, LYEXT_SUBSTMT_CONTACT, 0, module->contact, modc->exts);
2290 ypr_substmt(ctx, LYEXT_SUBSTMT_DESCRIPTION, 0, module->dsc, modc->exts);
2291 ypr_substmt(ctx, LYEXT_SUBSTMT_REFERENCE, 0, module->ref, modc->exts);
2292
2293 /* revision-stmts */
2294 if (module->revision) {
2295 ly_print(ctx->out, "\n%*srevision %s;\n", INDENT, module->revision);
2296 }
2297
2298 /* body-stmts */
2299 if (modc->exts) {
2300 ly_print(out, "\n");
2301 yprc_extension_instances(ctx, LYEXT_SUBSTMT_SELF, 0, module->compiled->exts, NULL, 0);
2302 }
2303
2304 LY_ARRAY_FOR(modc->features, u) {
2305 yprc_feature(ctx, &modc->features[u]);
2306 }
2307
2308 LY_ARRAY_FOR(modc->identities, u) {
2309 yprc_identity(ctx, &modc->identities[u]);
2310 }
2311
2312 LY_LIST_FOR(modc->data, data) {
2313 yprc_node(ctx, data);
2314 }
2315
2316 LY_ARRAY_FOR(modc->rpcs, u) {
2317 yprc_action(ctx, &modc->rpcs[u]);
2318 }
2319
2320 LY_ARRAY_FOR(modc->notifs, u) {
2321 yprc_notification(ctx, &modc->notifs[u]);
2322 }
2323
2324 LEVEL--;
2325 ly_print(out, "%*s}\n", INDENT);
2326 ly_print_flush(out);
Radek Krejcid3ca0632019-04-16 16:54:54 +02002327
2328 return LY_SUCCESS;
2329}