/src/libyang/src/printer_yang.c
Line | Count | Source |
1 | | /** |
2 | | * @file printer_yang.c |
3 | | * @author Radek Krejci <rkrejci@cesnet.cz> |
4 | | * @author Michal Vasko <mvasko@cesnet.cz> |
5 | | * @brief YANG printer |
6 | | * |
7 | | * Copyright (c) 2015 - 2026 CESNET, z.s.p.o. |
8 | | * |
9 | | * This source code is licensed under BSD 3-Clause License (the "License"). |
10 | | * You may not use this file except in compliance with the License. |
11 | | * You may obtain a copy of the License at |
12 | | * |
13 | | * https://opensource.org/licenses/BSD-3-Clause |
14 | | */ |
15 | | |
16 | | #define _GNU_SOURCE |
17 | | |
18 | | #include <assert.h> |
19 | | #include <inttypes.h> |
20 | | #include <stdint.h> |
21 | | #include <stdio.h> |
22 | | #include <stdlib.h> |
23 | | #include <string.h> |
24 | | #include <sys/types.h> |
25 | | |
26 | | #include "compat.h" |
27 | | #include "log.h" |
28 | | #include "ly_common.h" |
29 | | #include "out.h" |
30 | | #include "out_internal.h" |
31 | | #include "plugins_exts.h" |
32 | | #include "plugins_internal.h" |
33 | | #include "plugins_types.h" |
34 | | #include "printer_internal.h" |
35 | | #include "printer_schema.h" |
36 | | #include "tree.h" |
37 | | #include "tree_data.h" |
38 | | #include "tree_schema.h" |
39 | | #include "tree_schema_internal.h" |
40 | | #include "xpath.h" |
41 | | |
42 | | /** |
43 | | * @brief Types of the YANG printers |
44 | | */ |
45 | | enum lys_ypr_schema_type { |
46 | | LYS_YPR_PARSED, /**< YANG printer of the parsed schema */ |
47 | | LYS_YPR_COMPILED /**< YANG printer of the compiled schema */ |
48 | | }; |
49 | | |
50 | | enum lys_ypr_text_flags { |
51 | | LYS_YPR_TEXT_SINGLELINE = 0x01, /**< print 'text' on the same line as 'name' */ |
52 | | LYS_YPR_TEXT_SINGLEQUOTED = 0x02 /**< do not encode 'text' and print it in single quotes */ |
53 | | }; |
54 | | |
55 | 0 | #define YPR_CTX_FLAG_EXTRA_LINE 0x01 /**< Flag for ::ypr_ctx::flags to print extra line in schema */ |
56 | | |
57 | 0 | #define YPR_EXTRA_LINE(COND, PCTX) if (COND) { (PCTX)->flags |= YPR_CTX_FLAG_EXTRA_LINE; } |
58 | | #define YPR_EXTRA_LINE_PRINT(PCTX) \ |
59 | 0 | if ((PCTX)->flags & YPR_CTX_FLAG_EXTRA_LINE) { \ |
60 | 0 | (PCTX)->flags &= ~YPR_CTX_FLAG_EXTRA_LINE; \ |
61 | 0 | if (DO_FORMAT) { \ |
62 | 0 | ly_print_((PCTX)->out, "\n"); \ |
63 | 0 | } \ |
64 | 0 | } |
65 | | |
66 | 0 | #define YPR_IS_LYS_SINGLEQUOTED(FLAGS) (((FLAGS) & LYS_SINGLEQUOTED) ? 1 : 0) |
67 | | |
68 | | /** |
69 | | * @brief Compiled YANG printer context |
70 | | * |
71 | | * Note that the YANG extensions API provides getter to the members for the extension plugins. |
72 | | */ |
73 | | struct lys_ypr_ctx { |
74 | | union { |
75 | | struct { |
76 | | struct ly_out *out; /**< output specification */ |
77 | | uint16_t level; /**< current indentation level: 0 - no formatting, >= 1 indentation levels */ |
78 | | uint16_t flags; /**< internal flags for use by printer */ |
79 | | uint32_t options; /**< Schema output options (see @ref schemaprinterflags). */ |
80 | | const struct lys_module *module; /**< schema to print */ |
81 | | }; |
82 | | struct lyspr_ctx printer_ctx; |
83 | | }; |
84 | | |
85 | | /* YANG printer specific members */ |
86 | | enum lys_ypr_schema_type schema; /**< type of the schema to print */ |
87 | | }; |
88 | | |
89 | | /** |
90 | | * @brief Print the given text as content of a double quoted YANG string, |
91 | | * including encoding characters that have special meanings. The quotation marks |
92 | | * are not printed. |
93 | | * |
94 | | * Follows RFC 7950, section 6.1.3. |
95 | | * |
96 | | * @param[in] out Output specification. |
97 | | * @param[in] text String to be printed. |
98 | | * @param[in] len Length of the string from @p text to be printed. In case of -1, |
99 | | * the @p text is printed completely as a NULL-terminated string. |
100 | | */ |
101 | | static void |
102 | | ypr_encode(struct ly_out *out, const char *text, ssize_t len) |
103 | 0 | { |
104 | 0 | size_t i, start_len; |
105 | 0 | const char *start; |
106 | 0 | char special = 0; |
107 | |
|
108 | 0 | if (!len) { |
109 | 0 | return; |
110 | 0 | } |
111 | | |
112 | 0 | if (len < 0) { |
113 | 0 | len = strlen(text); |
114 | 0 | } |
115 | |
|
116 | 0 | start = text; |
117 | 0 | start_len = 0; |
118 | 0 | for (i = 0; i < (size_t)len; ++i) { |
119 | 0 | switch (text[i]) { |
120 | 0 | case '\n': |
121 | 0 | case '\t': |
122 | 0 | case '\"': |
123 | 0 | case '\\': |
124 | 0 | special = text[i]; |
125 | 0 | break; |
126 | 0 | default: |
127 | 0 | ++start_len; |
128 | 0 | break; |
129 | 0 | } |
130 | | |
131 | 0 | if (special) { |
132 | 0 | ly_write_(out, start, start_len); |
133 | 0 | switch (special) { |
134 | 0 | case '\n': |
135 | 0 | ly_write_(out, "\\n", 2); |
136 | 0 | break; |
137 | 0 | case '\t': |
138 | 0 | ly_write_(out, "\\t", 2); |
139 | 0 | break; |
140 | 0 | case '\"': |
141 | 0 | ly_write_(out, "\\\"", 2); |
142 | 0 | break; |
143 | 0 | case '\\': |
144 | 0 | ly_write_(out, "\\\\", 2); |
145 | 0 | break; |
146 | 0 | } |
147 | | |
148 | 0 | start += start_len + 1; |
149 | 0 | start_len = 0; |
150 | |
|
151 | 0 | special = 0; |
152 | 0 | } |
153 | 0 | } |
154 | | |
155 | 0 | ly_write_(out, start, start_len); |
156 | 0 | } |
157 | | |
158 | | static void |
159 | | ypr_open(struct ly_out *out, ly_bool *flag) |
160 | 0 | { |
161 | 0 | if (flag && !*flag) { |
162 | 0 | *flag = 1; |
163 | 0 | ly_print_(out, " {\n"); |
164 | 0 | } |
165 | 0 | } |
166 | | |
167 | | static void |
168 | | ypr_close(struct lys_ypr_ctx *pctx, ly_bool flag) |
169 | 0 | { |
170 | 0 | if (flag) { |
171 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
172 | 0 | } else { |
173 | 0 | ly_print_(pctx->out, ";\n"); |
174 | 0 | } |
175 | 0 | } |
176 | | |
177 | | static void |
178 | | ypr_text_squote_line(struct lys_ypr_ctx *pctx, const char *text, int text_len) |
179 | 0 | { |
180 | 0 | const char *end = text + text_len, *squote; |
181 | 0 | int squote_len; |
182 | |
|
183 | 0 | while ((text != end) && (squote = ly_strnchr(text, '\'', end - text))) { |
184 | | /* before squote */ |
185 | 0 | ly_print_(pctx->out, "%.*s", (int)(squote - text), text); |
186 | | |
187 | | /* specially-encoded squote(s) */ |
188 | 0 | squote_len = 0; |
189 | 0 | do { |
190 | 0 | ++squote_len; |
191 | 0 | } while ((squote + squote_len != end) && (squote[squote_len] == '\'')); |
192 | 0 | ly_print_(pctx->out, "' + \"%.*s\" +\n%*s'", squote_len, squote, INDENT); |
193 | | |
194 | | /* next iter */ |
195 | 0 | text = squote + squote_len; |
196 | 0 | } |
197 | |
|
198 | 0 | ly_print_(pctx->out, "%.*s", (int)(end - text), text); |
199 | 0 | } |
200 | | |
201 | | static void |
202 | | ypr_text(struct lys_ypr_ctx *pctx, const char *name, const char *text, enum lys_ypr_text_flags flags) |
203 | 0 | { |
204 | 0 | const char *nl, *t; |
205 | 0 | char quot; |
206 | |
|
207 | 0 | if (flags & LYS_YPR_TEXT_SINGLEQUOTED) { |
208 | 0 | quot = '\''; |
209 | 0 | if (strchr(text, '\'')) { |
210 | | /* need to encode single quotes specially, split to several lines */ |
211 | 0 | flags &= ~LYS_YPR_TEXT_SINGLELINE; |
212 | 0 | } |
213 | 0 | } else { |
214 | 0 | quot = '\"'; |
215 | 0 | } |
216 | | |
217 | | /* statement name and quote */ |
218 | 0 | if (flags & LYS_YPR_TEXT_SINGLELINE) { |
219 | 0 | ly_print_(pctx->out, "%*s%s %c", INDENT, name, quot); |
220 | 0 | } else { |
221 | 0 | ly_print_(pctx->out, "%*s%s\n", INDENT, name); |
222 | 0 | LEVEL++; |
223 | |
|
224 | 0 | ly_print_(pctx->out, "%*s%c", INDENT, quot); |
225 | 0 | } |
226 | | |
227 | | /* text with newlines */ |
228 | 0 | t = text; |
229 | 0 | while ((nl = strchr(t, '\n'))) { |
230 | 0 | if (flags & LYS_YPR_TEXT_SINGLEQUOTED) { |
231 | 0 | ypr_text_squote_line(pctx, t, nl - t); |
232 | 0 | } else { |
233 | 0 | ypr_encode(pctx->out, t, nl - t); |
234 | 0 | } |
235 | 0 | ly_print_(pctx->out, "\n"); |
236 | |
|
237 | 0 | t = nl + 1; |
238 | 0 | if (*t != '\n') { |
239 | 0 | ly_print_(pctx->out, "%*s ", INDENT); |
240 | 0 | } |
241 | 0 | } |
242 | | |
243 | | /* finish text and the last quote */ |
244 | 0 | if (flags & LYS_YPR_TEXT_SINGLEQUOTED) { |
245 | 0 | ypr_text_squote_line(pctx, t, strlen(t)); |
246 | 0 | } else { |
247 | 0 | ypr_encode(pctx->out, t, strlen(t)); |
248 | 0 | } |
249 | 0 | ly_print_(pctx->out, "%c", quot); |
250 | 0 | if (!(flags & LYS_YPR_TEXT_SINGLELINE)) { |
251 | 0 | LEVEL--; |
252 | 0 | } |
253 | 0 | } |
254 | | |
255 | | static void |
256 | | yprp_stmt(struct lys_ypr_ctx *pctx, struct lysp_stmt *stmt) |
257 | 0 | { |
258 | 0 | struct lysp_stmt *childstmt; |
259 | 0 | uint16_t tflags = 0; |
260 | |
|
261 | 0 | if (stmt->arg) { |
262 | 0 | if (stmt->flags) { |
263 | 0 | if (stmt->flags & LYS_SINGLEQUOTED) { |
264 | 0 | tflags |= LYS_YPR_TEXT_SINGLEQUOTED; |
265 | 0 | } |
266 | 0 | ypr_text(pctx, stmt->stmt, stmt->arg, tflags); |
267 | 0 | ly_print_(pctx->out, "%s", stmt->child ? " {\n" : ";\n"); |
268 | 0 | } else { |
269 | 0 | ly_print_(pctx->out, "%*s%s %s%s", INDENT, stmt->stmt, stmt->arg, stmt->child ? " {\n" : ";\n"); |
270 | 0 | } |
271 | 0 | } else { |
272 | 0 | ly_print_(pctx->out, "%*s%s%s", INDENT, stmt->stmt, stmt->child ? " {\n" : ";\n"); |
273 | 0 | } |
274 | |
|
275 | 0 | if (stmt->child) { |
276 | 0 | LEVEL++; |
277 | 0 | LY_LIST_FOR(stmt->child, childstmt) { |
278 | 0 | yprp_stmt(pctx, childstmt); |
279 | 0 | } |
280 | 0 | LEVEL--; |
281 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
282 | 0 | } |
283 | 0 | } |
284 | | |
285 | | static void |
286 | | yprp_extension_instance(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
287 | | struct lysp_ext_instance *ext, ly_bool *flag) |
288 | 0 | { |
289 | 0 | struct lysp_stmt *stmt; |
290 | 0 | ly_bool child_presence; |
291 | 0 | uint16_t flags = 0; |
292 | |
|
293 | 0 | if ((ext->flags & LYS_INTERNAL) || (ext->parent_stmt != substmt) || (ext->parent_stmt_index != substmt_index)) { |
294 | 0 | return; |
295 | 0 | } |
296 | | |
297 | 0 | ypr_open(pctx->out, flag); |
298 | |
|
299 | 0 | if (ext->argument) { |
300 | 0 | if (!strchr(ext->argument, '\n')) { |
301 | 0 | flags |= LYS_YPR_TEXT_SINGLELINE; |
302 | 0 | } |
303 | 0 | if (ext->flags & LYS_SINGLEQUOTED) { |
304 | 0 | flags |= LYS_YPR_TEXT_SINGLEQUOTED; |
305 | 0 | } |
306 | 0 | ypr_text(pctx, ext->name, ext->argument, flags); |
307 | 0 | } else { |
308 | 0 | ly_print_(pctx->out, "%*s%s", INDENT, ext->name); |
309 | 0 | } |
310 | |
|
311 | 0 | child_presence = 0; |
312 | 0 | LEVEL++; |
313 | 0 | LY_LIST_FOR(ext->child, stmt) { |
314 | 0 | if (stmt->flags & (LYS_YIN_ATTR | LYS_YIN_ARGUMENT)) { |
315 | 0 | continue; |
316 | 0 | } |
317 | 0 | if (!child_presence) { |
318 | 0 | ly_print_(pctx->out, " {\n"); |
319 | 0 | child_presence = 1; |
320 | 0 | } |
321 | 0 | yprp_stmt(pctx, stmt); |
322 | 0 | } |
323 | 0 | LEVEL--; |
324 | 0 | if (child_presence) { |
325 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
326 | 0 | } else { |
327 | 0 | ly_print_(pctx->out, ";\n"); |
328 | 0 | } |
329 | 0 | } |
330 | | |
331 | | static void |
332 | | yprp_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
333 | | struct lysp_ext_instance *exts, ly_bool *flag) |
334 | 0 | { |
335 | 0 | LY_ARRAY_COUNT_TYPE u; |
336 | |
|
337 | 0 | LY_ARRAY_FOR(exts, u) { |
338 | 0 | if (exts[u].flags & LYS_INTERNAL) { |
339 | 0 | continue; |
340 | 0 | } |
341 | 0 | yprp_extension_instance(pctx, substmt, substmt_index, &exts[u], flag); |
342 | 0 | } |
343 | 0 | } |
344 | | |
345 | | static ly_bool |
346 | | yprp_extension_has_printable_instances(struct lysp_ext_instance *exts) |
347 | 0 | { |
348 | 0 | LY_ARRAY_COUNT_TYPE u; |
349 | |
|
350 | 0 | LY_ARRAY_FOR(exts, u) { |
351 | 0 | if (!(exts[u].flags & LYS_INTERNAL)) { |
352 | 0 | return 1; |
353 | 0 | } |
354 | 0 | } |
355 | | |
356 | 0 | return 0; |
357 | 0 | } |
358 | | |
359 | | static void |
360 | | yprc_extension_instances(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, |
361 | | struct lysc_ext_instance *exts, ly_bool *flag) |
362 | 0 | { |
363 | 0 | LY_ARRAY_COUNT_TYPE u; |
364 | 0 | ly_bool inner_flag; |
365 | 0 | struct lyplg_ext *ext_plg; |
366 | |
|
367 | 0 | LY_ARRAY_FOR(exts, u) { |
368 | 0 | if ((exts[u].parent_stmt != substmt) || (exts[u].parent_stmt_index != substmt_index)) { |
369 | 0 | return; |
370 | 0 | } |
371 | | |
372 | 0 | ypr_open(pctx->out, flag); |
373 | 0 | if (exts[u].argument) { |
374 | 0 | ly_print_(pctx->out, "%*s%s:%s \"", INDENT, exts[u].def->module->name, exts[u].def->name); |
375 | 0 | ypr_encode(pctx->out, exts[u].argument, -1); |
376 | 0 | ly_print_(pctx->out, "\""); |
377 | 0 | } else { |
378 | 0 | ly_print_(pctx->out, "%*s%s:%s", INDENT, exts[u].def->module->name, exts[u].def->name); |
379 | 0 | } |
380 | |
|
381 | 0 | LEVEL++; |
382 | 0 | inner_flag = 0; |
383 | 0 | yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, exts[u].exts, &inner_flag); |
384 | |
|
385 | 0 | if (exts[u].def->plugin_ref && (ext_plg = LYSC_GET_EXT_PLG(exts[u].def->plugin_ref))->printer_info) { |
386 | 0 | ext_plg->printer_info(&pctx->printer_ctx, &exts[u], &inner_flag); |
387 | 0 | } |
388 | |
|
389 | 0 | LEVEL--; |
390 | 0 | ypr_close(pctx, inner_flag); |
391 | 0 | } |
392 | 0 | } |
393 | | |
394 | | static void |
395 | | ypr_substmt(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, const char *text, |
396 | | ly_bool singlequoted, void *exts) |
397 | 0 | { |
398 | 0 | ly_bool extflag = 0; |
399 | 0 | uint16_t flags = 0; |
400 | |
|
401 | 0 | if (!text) { |
402 | | /* nothing to print */ |
403 | 0 | return; |
404 | 0 | } |
405 | | |
406 | 0 | if (lys_stmt_flags(substmt) & LY_STMT_FLAG_ID) { |
407 | 0 | ly_print_(pctx->out, "%*s%s %s", INDENT, lys_stmt_str(substmt), text); |
408 | 0 | } else { |
409 | 0 | if (!(lys_stmt_flags(substmt) & LY_STMT_FLAG_YIN)) { |
410 | 0 | flags |= LYS_YPR_TEXT_SINGLELINE; |
411 | 0 | } |
412 | 0 | if (singlequoted) { |
413 | 0 | flags |= LYS_YPR_TEXT_SINGLEQUOTED; |
414 | 0 | } |
415 | 0 | ypr_text(pctx, lys_stmt_str(substmt), text, flags); |
416 | 0 | } |
417 | |
|
418 | 0 | LEVEL++; |
419 | 0 | if (pctx->schema == LYS_YPR_PARSED) { |
420 | 0 | yprp_extension_instances(pctx, substmt, substmt_index, exts, &extflag); |
421 | 0 | } else { |
422 | 0 | yprc_extension_instances(pctx, substmt, substmt_index, exts, &extflag); |
423 | 0 | } |
424 | 0 | LEVEL--; |
425 | 0 | ypr_close(pctx, extflag); |
426 | 0 | } |
427 | | |
428 | | static void |
429 | | ypr_unsigned(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, |
430 | | unsigned long attr_value, ly_bool *flag) |
431 | 0 | { |
432 | 0 | char *str; |
433 | |
|
434 | 0 | if (asprintf(&str, "%lu", attr_value) == -1) { |
435 | 0 | LOGMEM(pctx->module->ctx); |
436 | 0 | return; |
437 | 0 | } |
438 | 0 | ypr_open(pctx->out, flag); |
439 | 0 | ypr_substmt(pctx, substmt, substmt_index, str, 0, exts); |
440 | 0 | free(str); |
441 | 0 | } |
442 | | |
443 | | static void |
444 | | ypr_signed(struct lys_ypr_ctx *pctx, enum ly_stmt substmt, uint8_t substmt_index, void *exts, long attr_value, |
445 | | ly_bool *flag) |
446 | 0 | { |
447 | 0 | char *str; |
448 | |
|
449 | 0 | if (asprintf(&str, "%ld", attr_value) == -1) { |
450 | 0 | LOGMEM(pctx->module->ctx); |
451 | 0 | return; |
452 | 0 | } |
453 | 0 | ypr_open(pctx->out, flag); |
454 | 0 | ypr_substmt(pctx, substmt, substmt_index, str, 0, exts); |
455 | 0 | free(str); |
456 | 0 | } |
457 | | |
458 | | static void |
459 | | yprp_revision(struct lys_ypr_ctx *pctx, const struct lysp_revision *rev) |
460 | 0 | { |
461 | 0 | if (rev->dsc || rev->ref || rev->exts) { |
462 | 0 | ly_print_(pctx->out, "%*srevision %s {\n", INDENT, rev->date); |
463 | 0 | LEVEL++; |
464 | 0 | yprp_extension_instances(pctx, LY_STMT_REVISION, 0, rev->exts, NULL); |
465 | 0 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, rev->dsc, 0, rev->exts); |
466 | 0 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, rev->ref, 0, rev->exts); |
467 | 0 | LEVEL--; |
468 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
469 | 0 | } else { |
470 | 0 | ly_print_(pctx->out, "%*srevision %s;\n", INDENT, rev->date); |
471 | 0 | } |
472 | 0 | } |
473 | | |
474 | | static void |
475 | | ypr_mandatory(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag) |
476 | 0 | { |
477 | 0 | if (flags & LYS_MAND_MASK) { |
478 | 0 | ypr_open(pctx->out, flag); |
479 | 0 | ypr_substmt(pctx, LY_STMT_MANDATORY, 0, (flags & LYS_MAND_TRUE) ? "true" : "false", 0, exts); |
480 | 0 | } |
481 | 0 | } |
482 | | |
483 | | static void |
484 | | ypr_config(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag) |
485 | 0 | { |
486 | 0 | if (flags & LYS_CONFIG_MASK) { |
487 | 0 | ypr_open(pctx->out, flag); |
488 | 0 | ypr_substmt(pctx, LY_STMT_CONFIG, 0, (flags & LYS_CONFIG_W) ? "true" : "false", 0, exts); |
489 | 0 | } |
490 | 0 | } |
491 | | |
492 | | static void |
493 | | ypr_status(struct lys_ypr_ctx *pctx, uint16_t flags, void *exts, ly_bool *flag) |
494 | 0 | { |
495 | 0 | const char *status = NULL; |
496 | |
|
497 | 0 | if (flags & LYS_STATUS_CURR) { |
498 | 0 | ypr_open(pctx->out, flag); |
499 | 0 | status = "current"; |
500 | 0 | } else if (flags & LYS_STATUS_DEPRC) { |
501 | 0 | ypr_open(pctx->out, flag); |
502 | 0 | status = "deprecated"; |
503 | 0 | } else if (flags & LYS_STATUS_OBSLT) { |
504 | 0 | ypr_open(pctx->out, flag); |
505 | 0 | status = "obsolete"; |
506 | 0 | } |
507 | |
|
508 | 0 | ypr_substmt(pctx, LY_STMT_STATUS, 0, status, 0, exts); |
509 | 0 | } |
510 | | |
511 | | static void |
512 | | ypr_description(struct lys_ypr_ctx *pctx, const char *dsc, void *exts, ly_bool *flag) |
513 | 0 | { |
514 | 0 | if (dsc) { |
515 | 0 | ypr_open(pctx->out, flag); |
516 | 0 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, dsc, 0, exts); |
517 | 0 | } |
518 | 0 | } |
519 | | |
520 | | static void |
521 | | ypr_reference(struct lys_ypr_ctx *pctx, const char *ref, void *exts, ly_bool *flag) |
522 | 0 | { |
523 | 0 | if (ref) { |
524 | 0 | ypr_open(pctx->out, flag); |
525 | 0 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, ref, 0, exts); |
526 | 0 | } |
527 | 0 | } |
528 | | |
529 | | static void |
530 | | yprp_iffeatures(struct lys_ypr_ctx *pctx, struct lysp_qname *iffs, struct lysp_ext_instance *exts, ly_bool *flag) |
531 | 0 | { |
532 | 0 | LY_ARRAY_COUNT_TYPE u; |
533 | 0 | ly_bool extflag; |
534 | 0 | uint16_t flags; |
535 | |
|
536 | 0 | LY_ARRAY_FOR(iffs, u) { |
537 | 0 | ypr_open(pctx->out, flag); |
538 | 0 | extflag = 0; |
539 | |
|
540 | 0 | flags = LYS_YPR_TEXT_SINGLELINE | ((iffs[u].flags & LYS_SINGLEQUOTED) ? LYS_YPR_TEXT_SINGLEQUOTED : 0); |
541 | 0 | ypr_text(pctx, "if-feature", iffs[u].str, flags); |
542 | | |
543 | | /* extensions */ |
544 | 0 | LEVEL++; |
545 | 0 | yprp_extension_instances(pctx, LY_STMT_IF_FEATURE, u, exts, &extflag); |
546 | 0 | LEVEL--; |
547 | 0 | ypr_close(pctx, extflag); |
548 | 0 | } |
549 | 0 | } |
550 | | |
551 | | static void |
552 | | yprp_extension(struct lys_ypr_ctx *pctx, const struct lysp_ext *ext) |
553 | 0 | { |
554 | 0 | ly_bool flag = 0, flag2 = 0; |
555 | 0 | LY_ARRAY_COUNT_TYPE u; |
556 | |
|
557 | 0 | ly_print_(pctx->out, "%*sextension %s", INDENT, ext->name); |
558 | 0 | LEVEL++; |
559 | |
|
560 | 0 | yprp_extension_instances(pctx, LY_STMT_EXTENSION, 0, ext->exts, &flag); |
561 | |
|
562 | 0 | if (ext->argname) { |
563 | 0 | ypr_open(pctx->out, &flag); |
564 | 0 | ly_print_(pctx->out, "%*sargument %s", INDENT, ext->argname); |
565 | 0 | LEVEL++; |
566 | 0 | if (ext->exts) { |
567 | 0 | u = -1; |
568 | 0 | while ((u = lysp_ext_instance_iter(ext->exts, u + 1, LY_STMT_ARGUMENT)) != LY_ARRAY_COUNT(ext->exts)) { |
569 | 0 | yprp_extension_instance(pctx, LY_STMT_ARGUMENT, 0, &ext->exts[u], &flag2); |
570 | 0 | } |
571 | 0 | } |
572 | 0 | if ((ext->flags & LYS_YINELEM_MASK) || |
573 | 0 | (ext->exts && (lysp_ext_instance_iter(ext->exts, 0, LY_STMT_YIN_ELEMENT) != LY_ARRAY_COUNT(ext->exts)))) { |
574 | 0 | ypr_open(pctx->out, &flag2); |
575 | 0 | ypr_substmt(pctx, LY_STMT_YIN_ELEMENT, 0, (ext->flags & LYS_YINELEM_TRUE) ? "true" : "false", 0, ext->exts); |
576 | 0 | } |
577 | 0 | LEVEL--; |
578 | 0 | ypr_close(pctx, flag2); |
579 | 0 | } |
580 | |
|
581 | 0 | ypr_status(pctx, ext->flags, ext->exts, &flag); |
582 | 0 | ypr_description(pctx, ext->dsc, ext->exts, &flag); |
583 | 0 | ypr_reference(pctx, ext->ref, ext->exts, &flag); |
584 | |
|
585 | 0 | LEVEL--; |
586 | 0 | ypr_close(pctx, flag); |
587 | 0 | } |
588 | | |
589 | | static void |
590 | | yprp_feature(struct lys_ypr_ctx *pctx, const struct lysp_feature *feat) |
591 | 0 | { |
592 | 0 | ly_bool flag = 0; |
593 | |
|
594 | 0 | ly_print_(pctx->out, "%*sfeature %s", INDENT, feat->name); |
595 | 0 | LEVEL++; |
596 | 0 | yprp_extension_instances(pctx, LY_STMT_FEATURE, 0, feat->exts, &flag); |
597 | 0 | yprp_iffeatures(pctx, feat->iffeatures, feat->exts, &flag); |
598 | 0 | ypr_status(pctx, feat->flags, feat->exts, &flag); |
599 | 0 | ypr_description(pctx, feat->dsc, feat->exts, &flag); |
600 | 0 | ypr_reference(pctx, feat->ref, feat->exts, &flag); |
601 | 0 | LEVEL--; |
602 | 0 | ypr_close(pctx, flag); |
603 | 0 | } |
604 | | |
605 | | static void |
606 | | yprp_identity(struct lys_ypr_ctx *pctx, const struct lysp_ident *ident) |
607 | 0 | { |
608 | 0 | ly_bool flag = 0; |
609 | 0 | LY_ARRAY_COUNT_TYPE u; |
610 | |
|
611 | 0 | ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name); |
612 | 0 | LEVEL++; |
613 | |
|
614 | 0 | yprp_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag); |
615 | 0 | yprp_iffeatures(pctx, ident->iffeatures, ident->exts, &flag); |
616 | |
|
617 | 0 | LY_ARRAY_FOR(ident->bases, u) { |
618 | 0 | ypr_open(pctx->out, &flag); |
619 | 0 | ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u], 0, ident->exts); |
620 | 0 | } |
621 | |
|
622 | 0 | ypr_status(pctx, ident->flags, ident->exts, &flag); |
623 | 0 | ypr_description(pctx, ident->dsc, ident->exts, &flag); |
624 | 0 | ypr_reference(pctx, ident->ref, ident->exts, &flag); |
625 | |
|
626 | 0 | LEVEL--; |
627 | 0 | ypr_close(pctx, flag); |
628 | 0 | } |
629 | | |
630 | | static void |
631 | | yprc_identity(struct lys_ypr_ctx *pctx, const struct lysc_ident *ident) |
632 | 0 | { |
633 | 0 | ly_bool flag = 0; |
634 | 0 | LY_ARRAY_COUNT_TYPE u; |
635 | |
|
636 | 0 | ly_print_(pctx->out, "%*sidentity %s", INDENT, ident->name); |
637 | 0 | LEVEL++; |
638 | |
|
639 | 0 | yprc_extension_instances(pctx, LY_STMT_IDENTITY, 0, ident->exts, &flag); |
640 | |
|
641 | 0 | ypr_open(pctx->out, &flag); |
642 | 0 | if (lys_identity_iffeature_value(ident) == LY_ENOT) { |
643 | 0 | ly_print_(pctx->out, "%*s/* identity \"%s\" is disabled by if-feature(s) */\n", INDENT, ident->name); |
644 | 0 | } |
645 | |
|
646 | 0 | LY_ARRAY_FOR(ident->derived, u) { |
647 | 0 | if (pctx->module != ident->derived[u]->module) { |
648 | 0 | ly_print_(pctx->out, "%*sderived %s:%s;\n", INDENT, ident->derived[u]->module->prefix, ident->derived[u]->name); |
649 | 0 | } else { |
650 | 0 | ly_print_(pctx->out, "%*sderived %s;\n", INDENT, ident->derived[u]->name); |
651 | 0 | } |
652 | 0 | } |
653 | |
|
654 | 0 | ypr_status(pctx, ident->flags, ident->exts, &flag); |
655 | 0 | ypr_description(pctx, ident->dsc, ident->exts, &flag); |
656 | 0 | ypr_reference(pctx, ident->ref, ident->exts, &flag); |
657 | |
|
658 | 0 | LEVEL--; |
659 | 0 | ypr_close(pctx, flag); |
660 | 0 | } |
661 | | |
662 | | static void |
663 | | yprp_restr(struct lys_ypr_ctx *pctx, const struct lysp_restr *restr, enum ly_stmt stmt, ly_bool *flag) |
664 | 0 | { |
665 | 0 | ly_bool inner_flag = 0; |
666 | 0 | const char *text; |
667 | 0 | uint16_t flags = 0; |
668 | |
|
669 | 0 | if (!restr) { |
670 | 0 | return; |
671 | 0 | } |
672 | | |
673 | 0 | ypr_open(pctx->out, flag); |
674 | 0 | text = ((restr->arg.str[0] != LYSP_RESTR_PATTERN_NACK) && (restr->arg.str[0] != LYSP_RESTR_PATTERN_ACK)) ? |
675 | 0 | restr->arg.str : restr->arg.str + 1; |
676 | 0 | if (!strchr(text, '\n')) { |
677 | 0 | flags |= LYS_YPR_TEXT_SINGLELINE; |
678 | 0 | } |
679 | 0 | if (restr->arg.flags & LYS_SINGLEQUOTED) { |
680 | 0 | flags |= LYS_YPR_TEXT_SINGLEQUOTED; |
681 | 0 | } |
682 | 0 | ypr_text(pctx, lyplg_ext_stmt2str(stmt), text, flags); |
683 | |
|
684 | 0 | LEVEL++; |
685 | 0 | yprp_extension_instances(pctx, stmt, 0, restr->exts, &inner_flag); |
686 | 0 | if (restr->arg.str[0] == LYSP_RESTR_PATTERN_NACK) { |
687 | | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
688 | 0 | ypr_open(pctx->out, &inner_flag); |
689 | 0 | ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, restr->exts); |
690 | 0 | } |
691 | 0 | if (restr->emsg) { |
692 | 0 | ypr_open(pctx->out, &inner_flag); |
693 | 0 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, restr->emsg, 0, restr->exts); |
694 | 0 | } |
695 | 0 | if (restr->eapptag) { |
696 | 0 | ypr_open(pctx->out, &inner_flag); |
697 | 0 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, restr->eapptag, 0, restr->exts); |
698 | 0 | } |
699 | 0 | ypr_description(pctx, restr->dsc, restr->exts, &inner_flag); |
700 | 0 | ypr_reference(pctx, restr->ref, restr->exts, &inner_flag); |
701 | |
|
702 | 0 | LEVEL--; |
703 | 0 | ypr_close(pctx, inner_flag); |
704 | 0 | } |
705 | | |
706 | | static void |
707 | | yprc_must(struct lys_ypr_ctx *pctx, const struct lysc_must *must, ly_bool *flag) |
708 | 0 | { |
709 | 0 | ly_bool inner_flag = 0; |
710 | |
|
711 | 0 | ypr_open(pctx->out, flag); |
712 | 0 | ypr_text(pctx, "must", must->cond->expr, LYS_YPR_TEXT_SINGLELINE); |
713 | |
|
714 | 0 | LEVEL++; |
715 | 0 | yprc_extension_instances(pctx, LY_STMT_MUST, 0, must->exts, &inner_flag); |
716 | 0 | if (must->emsg) { |
717 | 0 | ypr_open(pctx->out, &inner_flag); |
718 | 0 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, must->emsg, 0, must->exts); |
719 | 0 | } |
720 | 0 | if (must->eapptag) { |
721 | 0 | ypr_open(pctx->out, &inner_flag); |
722 | 0 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, must->eapptag, 0, must->exts); |
723 | 0 | } |
724 | 0 | ypr_description(pctx, must->dsc, must->exts, &inner_flag); |
725 | 0 | ypr_reference(pctx, must->ref, must->exts, &inner_flag); |
726 | |
|
727 | 0 | LEVEL--; |
728 | 0 | ypr_close(pctx, inner_flag); |
729 | 0 | } |
730 | | |
731 | | static void |
732 | | yprc_range(struct lys_ypr_ctx *pctx, const struct lysc_range *range, LY_DATA_TYPE basetype, ly_bool *flag) |
733 | 0 | { |
734 | 0 | ly_bool inner_flag = 0; |
735 | 0 | LY_ARRAY_COUNT_TYPE u; |
736 | |
|
737 | 0 | if (!range) { |
738 | 0 | return; |
739 | 0 | } |
740 | | |
741 | 0 | ypr_open(pctx->out, flag); |
742 | 0 | ly_print_(pctx->out, "%*s%s \"", INDENT, (basetype == LY_TYPE_STRING || basetype == LY_TYPE_BINARY) ? "length" : "range"); |
743 | 0 | LY_ARRAY_FOR(range->parts, u) { |
744 | 0 | if (u > 0) { |
745 | 0 | ly_print_(pctx->out, " | "); |
746 | 0 | } |
747 | 0 | if (range->parts[u].max_64 == range->parts[u].min_64) { |
748 | 0 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
749 | 0 | ly_print_(pctx->out, "%" PRIu64, range->parts[u].max_u64); |
750 | 0 | } else { /* signed values */ |
751 | 0 | ly_print_(pctx->out, "%" PRId64, range->parts[u].max_64); |
752 | 0 | } |
753 | 0 | } else { |
754 | 0 | if (basetype <= LY_TYPE_STRING) { /* unsigned values */ |
755 | 0 | ly_print_(pctx->out, "%" PRIu64 "..%" PRIu64, range->parts[u].min_u64, range->parts[u].max_u64); |
756 | 0 | } else { /* signed values */ |
757 | 0 | ly_print_(pctx->out, "%" PRId64 "..%" PRId64, range->parts[u].min_64, range->parts[u].max_64); |
758 | 0 | } |
759 | 0 | } |
760 | 0 | } |
761 | 0 | ly_print_(pctx->out, "\""); |
762 | |
|
763 | 0 | LEVEL++; |
764 | 0 | yprc_extension_instances(pctx, LY_STMT_RANGE, 0, range->exts, &inner_flag); |
765 | 0 | if (range->emsg) { |
766 | 0 | ypr_open(pctx->out, &inner_flag); |
767 | 0 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, range->emsg, 0, range->exts); |
768 | 0 | } |
769 | 0 | if (range->eapptag) { |
770 | 0 | ypr_open(pctx->out, &inner_flag); |
771 | 0 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, range->eapptag, 0, range->exts); |
772 | 0 | } |
773 | 0 | ypr_description(pctx, range->dsc, range->exts, &inner_flag); |
774 | 0 | ypr_reference(pctx, range->ref, range->exts, &inner_flag); |
775 | |
|
776 | 0 | LEVEL--; |
777 | 0 | ypr_close(pctx, inner_flag); |
778 | 0 | } |
779 | | |
780 | | static void |
781 | | yprc_pattern(struct lys_ypr_ctx *pctx, const struct lysc_pattern *pattern, ly_bool *flag) |
782 | 0 | { |
783 | 0 | ly_bool inner_flag = 0; |
784 | |
|
785 | 0 | ypr_open(pctx->out, flag); |
786 | 0 | ly_print_(pctx->out, "%*spattern \"", INDENT); |
787 | 0 | ypr_encode(pctx->out, pattern->expr, -1); |
788 | 0 | ly_print_(pctx->out, "\""); |
789 | |
|
790 | 0 | LEVEL++; |
791 | 0 | yprc_extension_instances(pctx, LY_STMT_PATTERN, 0, pattern->exts, &inner_flag); |
792 | 0 | if (pattern->inverted) { |
793 | | /* special byte value in pattern's expression: 0x15 - invert-match, 0x06 - match */ |
794 | 0 | ypr_open(pctx->out, &inner_flag); |
795 | 0 | ypr_substmt(pctx, LY_STMT_MODIFIER, 0, "invert-match", 0, pattern->exts); |
796 | 0 | } |
797 | 0 | if (pattern->emsg) { |
798 | 0 | ypr_open(pctx->out, &inner_flag); |
799 | 0 | ypr_substmt(pctx, LY_STMT_ERROR_MESSAGE, 0, pattern->emsg, 0, pattern->exts); |
800 | 0 | } |
801 | 0 | if (pattern->eapptag) { |
802 | 0 | ypr_open(pctx->out, &inner_flag); |
803 | 0 | ypr_substmt(pctx, LY_STMT_ERROR_APP_TAG, 0, pattern->eapptag, 0, pattern->exts); |
804 | 0 | } |
805 | 0 | ypr_description(pctx, pattern->dsc, pattern->exts, &inner_flag); |
806 | 0 | ypr_reference(pctx, pattern->ref, pattern->exts, &inner_flag); |
807 | |
|
808 | 0 | LEVEL--; |
809 | 0 | ypr_close(pctx, inner_flag); |
810 | 0 | } |
811 | | |
812 | | static void |
813 | | yprc_bits_enum(struct lys_ypr_ctx *pctx, const struct lysc_type_bitenum_item *items, LY_DATA_TYPE basetype, ly_bool *flag) |
814 | 0 | { |
815 | 0 | LY_ARRAY_COUNT_TYPE u; |
816 | 0 | const struct lysc_type_bitenum_item *item; |
817 | 0 | ly_bool inner_flag; |
818 | |
|
819 | 0 | assert((basetype == LY_TYPE_BITS) || (basetype == LY_TYPE_ENUM)); |
820 | | |
821 | 0 | LY_ARRAY_FOR(items, u) { |
822 | 0 | item = &items[u]; |
823 | 0 | inner_flag = 0; |
824 | |
|
825 | 0 | ypr_open(pctx->out, flag); |
826 | 0 | ly_print_(pctx->out, "%*s%s \"", INDENT, basetype == LY_TYPE_BITS ? "bit" : "enum"); |
827 | 0 | ypr_encode(pctx->out, item->name, -1); |
828 | 0 | ly_print_(pctx->out, "\""); |
829 | 0 | LEVEL++; |
830 | 0 | if (basetype == LY_TYPE_BITS) { |
831 | 0 | yprc_extension_instances(pctx, LY_STMT_BIT, 0, item->exts, &inner_flag); |
832 | 0 | ypr_unsigned(pctx, LY_STMT_POSITION, 0, item->exts, item->position, &inner_flag); |
833 | 0 | } else { /* LY_TYPE_ENUM */ |
834 | 0 | yprc_extension_instances(pctx, LY_STMT_ENUM, 0, item->exts, &inner_flag); |
835 | 0 | ypr_signed(pctx, LY_STMT_VALUE, 0, item->exts, item->value, &inner_flag); |
836 | 0 | } |
837 | 0 | ypr_status(pctx, item->flags, item->exts, &inner_flag); |
838 | 0 | ypr_description(pctx, item->dsc, item->exts, &inner_flag); |
839 | 0 | ypr_reference(pctx, item->ref, item->exts, &inner_flag); |
840 | 0 | LEVEL--; |
841 | 0 | ypr_close(pctx, inner_flag); |
842 | 0 | } |
843 | 0 | } |
844 | | |
845 | | static void |
846 | | yprp_when(struct lys_ypr_ctx *pctx, const struct lysp_when *when, ly_bool *flag) |
847 | 0 | { |
848 | 0 | ly_bool inner_flag = 0; |
849 | |
|
850 | 0 | if (!when) { |
851 | 0 | return; |
852 | 0 | } |
853 | 0 | ypr_open(pctx->out, flag); |
854 | |
|
855 | 0 | ypr_text(pctx, "when", when->cond, LYS_YPR_TEXT_SINGLELINE); |
856 | |
|
857 | 0 | LEVEL++; |
858 | 0 | yprp_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag); |
859 | 0 | ypr_description(pctx, when->dsc, when->exts, &inner_flag); |
860 | 0 | ypr_reference(pctx, when->ref, when->exts, &inner_flag); |
861 | 0 | LEVEL--; |
862 | 0 | ypr_close(pctx, inner_flag); |
863 | 0 | } |
864 | | |
865 | | static void |
866 | | yprc_when(struct lys_ypr_ctx *pctx, const struct lysc_when *when, ly_bool *flag) |
867 | 0 | { |
868 | 0 | ly_bool inner_flag = 0; |
869 | |
|
870 | 0 | if (!when) { |
871 | 0 | return; |
872 | 0 | } |
873 | 0 | ypr_open(pctx->out, flag); |
874 | |
|
875 | 0 | ypr_text(pctx, "when", when->cond->expr, LYS_YPR_TEXT_SINGLELINE); |
876 | |
|
877 | 0 | LEVEL++; |
878 | 0 | yprc_extension_instances(pctx, LY_STMT_WHEN, 0, when->exts, &inner_flag); |
879 | 0 | ypr_description(pctx, when->dsc, when->exts, &inner_flag); |
880 | 0 | ypr_reference(pctx, when->ref, when->exts, &inner_flag); |
881 | 0 | LEVEL--; |
882 | 0 | ypr_close(pctx, inner_flag); |
883 | 0 | } |
884 | | |
885 | | static void |
886 | | yprp_bits_enum(struct lys_ypr_ctx *pctx, const struct lysp_type_enum *items, LY_DATA_TYPE type, ly_bool *flag) |
887 | 0 | { |
888 | 0 | LY_ARRAY_COUNT_TYPE u; |
889 | 0 | ly_bool inner_flag; |
890 | |
|
891 | 0 | LY_ARRAY_FOR(items, u) { |
892 | 0 | ypr_open(pctx->out, flag); |
893 | 0 | if (type == LY_TYPE_BITS) { |
894 | 0 | ly_print_(pctx->out, "%*sbit %s", INDENT, items[u].name); |
895 | 0 | } else { /* LY_TYPE_ENUM */ |
896 | 0 | ly_print_(pctx->out, "%*senum \"", INDENT); |
897 | 0 | ypr_encode(pctx->out, items[u].name, -1); |
898 | 0 | ly_print_(pctx->out, "\""); |
899 | 0 | } |
900 | 0 | inner_flag = 0; |
901 | 0 | LEVEL++; |
902 | 0 | yprp_extension_instances(pctx, LY_STMT_ENUM, 0, items[u].exts, &inner_flag); |
903 | 0 | yprp_iffeatures(pctx, items[u].iffeatures, items[u].exts, &inner_flag); |
904 | 0 | if (items[u].flags & LYS_SET_VALUE) { |
905 | 0 | if (type == LY_TYPE_BITS) { |
906 | 0 | ypr_unsigned(pctx, LY_STMT_POSITION, 0, items[u].exts, items[u].value, &inner_flag); |
907 | 0 | } else { /* LY_TYPE_ENUM */ |
908 | 0 | ypr_signed(pctx, LY_STMT_VALUE, 0, items[u].exts, items[u].value, &inner_flag); |
909 | 0 | } |
910 | 0 | } |
911 | 0 | ypr_status(pctx, items[u].flags, items[u].exts, &inner_flag); |
912 | 0 | ypr_description(pctx, items[u].dsc, items[u].exts, &inner_flag); |
913 | 0 | ypr_reference(pctx, items[u].ref, items[u].exts, &inner_flag); |
914 | 0 | LEVEL--; |
915 | 0 | ypr_close(pctx, inner_flag); |
916 | 0 | } |
917 | 0 | } |
918 | | |
919 | | static void |
920 | | yprp_type(struct lys_ypr_ctx *pctx, const struct lysp_type *type) |
921 | 0 | { |
922 | 0 | LY_ARRAY_COUNT_TYPE u; |
923 | 0 | ly_bool flag = 0; |
924 | |
|
925 | 0 | ly_print_(pctx->out, "%*stype %s", INDENT, type->name); |
926 | 0 | LEVEL++; |
927 | |
|
928 | 0 | yprp_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag); |
929 | |
|
930 | 0 | yprp_restr(pctx, type->range, LY_STMT_RANGE, &flag); |
931 | 0 | yprp_restr(pctx, type->length, LY_STMT_LENGTH, &flag); |
932 | 0 | LY_ARRAY_FOR(type->patterns, u) { |
933 | 0 | yprp_restr(pctx, &type->patterns[u], LY_STMT_PATTERN, &flag); |
934 | 0 | } |
935 | 0 | yprp_bits_enum(pctx, type->bits, LY_TYPE_BITS, &flag); |
936 | 0 | yprp_bits_enum(pctx, type->enums, LY_TYPE_ENUM, &flag); |
937 | |
|
938 | 0 | if (type->path) { |
939 | 0 | ypr_open(pctx->out, &flag); |
940 | 0 | ypr_substmt(pctx, LY_STMT_PATH, 0, type->path->expr, 0, type->exts); |
941 | 0 | } |
942 | 0 | if (type->flags & LYS_SET_REQINST) { |
943 | 0 | ypr_open(pctx->out, &flag); |
944 | 0 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, type->require_instance ? "true" : "false", 0, type->exts); |
945 | 0 | } |
946 | 0 | if (type->flags & LYS_SET_FRDIGITS) { |
947 | 0 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, type->fraction_digits, &flag); |
948 | 0 | } |
949 | 0 | LY_ARRAY_FOR(type->bases, u) { |
950 | 0 | ypr_open(pctx->out, &flag); |
951 | 0 | ypr_substmt(pctx, LY_STMT_BASE, u, type->bases[u], 0, type->exts); |
952 | 0 | } |
953 | 0 | LY_ARRAY_FOR(type->types, u) { |
954 | 0 | ypr_open(pctx->out, &flag); |
955 | 0 | yprp_type(pctx, &type->types[u]); |
956 | 0 | } |
957 | |
|
958 | 0 | LEVEL--; |
959 | 0 | ypr_close(pctx, flag); |
960 | 0 | } |
961 | | |
962 | | static void |
963 | | yprc_type(struct lys_ypr_ctx *pctx, const struct lysc_type *type) |
964 | 0 | { |
965 | 0 | LY_ARRAY_COUNT_TYPE u; |
966 | 0 | ly_bool flag = 0; |
967 | |
|
968 | 0 | ly_print_(pctx->out, "%*stype %s", INDENT, lys_datatype2str(type->basetype)); |
969 | 0 | LEVEL++; |
970 | |
|
971 | 0 | yprc_extension_instances(pctx, LY_STMT_TYPE, 0, type->exts, &flag); |
972 | |
|
973 | 0 | switch (type->basetype) { |
974 | 0 | case LY_TYPE_BINARY: { |
975 | 0 | struct lysc_type_bin *bin = (struct lysc_type_bin *)type; |
976 | |
|
977 | 0 | yprc_range(pctx, bin->length, type->basetype, &flag); |
978 | 0 | break; |
979 | 0 | } |
980 | 0 | case LY_TYPE_UINT8: |
981 | 0 | case LY_TYPE_UINT16: |
982 | 0 | case LY_TYPE_UINT32: |
983 | 0 | case LY_TYPE_UINT64: |
984 | 0 | case LY_TYPE_INT8: |
985 | 0 | case LY_TYPE_INT16: |
986 | 0 | case LY_TYPE_INT32: |
987 | 0 | case LY_TYPE_INT64: { |
988 | 0 | struct lysc_type_num *num = (struct lysc_type_num *)type; |
989 | |
|
990 | 0 | yprc_range(pctx, num->range, type->basetype, &flag); |
991 | 0 | break; |
992 | 0 | } |
993 | 0 | case LY_TYPE_STRING: { |
994 | 0 | struct lysc_type_str *str = (struct lysc_type_str *)type; |
995 | |
|
996 | 0 | yprc_range(pctx, str->length, type->basetype, &flag); |
997 | 0 | LY_ARRAY_FOR(str->patterns, u) { |
998 | 0 | yprc_pattern(pctx, str->patterns[u], &flag); |
999 | 0 | } |
1000 | 0 | break; |
1001 | 0 | } |
1002 | 0 | case LY_TYPE_BITS: |
1003 | 0 | case LY_TYPE_ENUM: { |
1004 | | /* bits and enums structures are compatible */ |
1005 | 0 | struct lysc_type_bits *bits = (struct lysc_type_bits *)type; |
1006 | |
|
1007 | 0 | yprc_bits_enum(pctx, bits->bits, type->basetype, &flag); |
1008 | 0 | break; |
1009 | 0 | } |
1010 | 0 | case LY_TYPE_BOOL: |
1011 | 0 | case LY_TYPE_EMPTY: |
1012 | | /* nothing to do */ |
1013 | 0 | break; |
1014 | 0 | case LY_TYPE_DEC64: { |
1015 | 0 | struct lysc_type_dec *dec = (struct lysc_type_dec *)type; |
1016 | |
|
1017 | 0 | ypr_open(pctx->out, &flag); |
1018 | 0 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, type->exts, dec->fraction_digits, &flag); |
1019 | 0 | yprc_range(pctx, dec->range, dec->basetype, &flag); |
1020 | 0 | break; |
1021 | 0 | } |
1022 | 0 | case LY_TYPE_IDENT: { |
1023 | 0 | struct lysc_type_identityref *ident = (struct lysc_type_identityref *)type; |
1024 | |
|
1025 | 0 | LY_ARRAY_FOR(ident->bases, u) { |
1026 | 0 | ypr_open(pctx->out, &flag); |
1027 | 0 | ypr_substmt(pctx, LY_STMT_BASE, u, ident->bases[u]->name, 0, type->exts); |
1028 | 0 | } |
1029 | 0 | break; |
1030 | 0 | } |
1031 | 0 | case LY_TYPE_INST: { |
1032 | 0 | struct lysc_type_instanceid *inst = (struct lysc_type_instanceid *)type; |
1033 | |
|
1034 | 0 | ypr_open(pctx->out, &flag); |
1035 | 0 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, inst->require_instance ? "true" : "false", 0, inst->exts); |
1036 | 0 | break; |
1037 | 0 | } |
1038 | 0 | case LY_TYPE_LEAFREF: { |
1039 | 0 | struct lysc_type_leafref *lr = (struct lysc_type_leafref *)type; |
1040 | |
|
1041 | 0 | ypr_open(pctx->out, &flag); |
1042 | 0 | ypr_substmt(pctx, LY_STMT_PATH, 0, lr->path->expr, 0, lr->exts); |
1043 | 0 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, lr->require_instance ? "true" : "false", 0, lr->exts); |
1044 | 0 | yprc_type(pctx, lr->realtype); |
1045 | 0 | break; |
1046 | 0 | } |
1047 | 0 | case LY_TYPE_UNION: { |
1048 | 0 | struct lysc_type_union *un = (struct lysc_type_union *)type; |
1049 | |
|
1050 | 0 | LY_ARRAY_FOR(un->types, u) { |
1051 | 0 | ypr_open(pctx->out, &flag); |
1052 | 0 | yprc_type(pctx, un->types[u]); |
1053 | 0 | } |
1054 | 0 | break; |
1055 | 0 | } |
1056 | 0 | default: |
1057 | 0 | LOGINT(pctx->module->ctx); |
1058 | 0 | } |
1059 | | |
1060 | 0 | LEVEL--; |
1061 | 0 | ypr_close(pctx, flag); |
1062 | 0 | } |
1063 | | |
1064 | | static void |
1065 | | yprp_typedef(struct lys_ypr_ctx *pctx, const struct lysp_tpdf *tpdf) |
1066 | 0 | { |
1067 | 0 | ly_print_(pctx->out, "%*stypedef %s {\n", INDENT, tpdf->name); |
1068 | 0 | LEVEL++; |
1069 | |
|
1070 | 0 | yprp_extension_instances(pctx, LY_STMT_TYPEDEF, 0, tpdf->exts, NULL); |
1071 | |
|
1072 | 0 | yprp_type(pctx, &tpdf->type); |
1073 | |
|
1074 | 0 | if (tpdf->units) { |
1075 | 0 | ypr_substmt(pctx, LY_STMT_UNITS, 0, tpdf->units, 0, tpdf->exts); |
1076 | 0 | } |
1077 | 0 | if (tpdf->dflt.str) { |
1078 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, tpdf->dflt.str, YPR_IS_LYS_SINGLEQUOTED(tpdf->dflt.flags), tpdf->exts); |
1079 | 0 | } |
1080 | |
|
1081 | 0 | ypr_status(pctx, tpdf->flags, tpdf->exts, NULL); |
1082 | 0 | ypr_description(pctx, tpdf->dsc, tpdf->exts, NULL); |
1083 | 0 | ypr_reference(pctx, tpdf->ref, tpdf->exts, NULL); |
1084 | |
|
1085 | 0 | LEVEL--; |
1086 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
1087 | 0 | } |
1088 | | |
1089 | | static void yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node); |
1090 | | static void yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node); |
1091 | | static void yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action); |
1092 | | static void yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif); |
1093 | | |
1094 | | static void |
1095 | | yprp_grouping(struct lys_ypr_ctx *pctx, const struct lysp_node_grp *grp) |
1096 | 0 | { |
1097 | 0 | LY_ARRAY_COUNT_TYPE u; |
1098 | 0 | ly_bool flag = 0; |
1099 | 0 | struct lysp_node *data; |
1100 | 0 | struct lysp_node_action *action; |
1101 | 0 | struct lysp_node_notif *notif; |
1102 | 0 | struct lysp_node_grp *subgrp; |
1103 | |
|
1104 | 0 | ly_print_(pctx->out, "%*sgrouping %s", INDENT, grp->name); |
1105 | 0 | LEVEL++; |
1106 | |
|
1107 | 0 | yprp_extension_instances(pctx, LY_STMT_GROUPING, 0, grp->exts, &flag); |
1108 | 0 | ypr_status(pctx, grp->flags, grp->exts, &flag); |
1109 | 0 | ypr_description(pctx, grp->dsc, grp->exts, &flag); |
1110 | 0 | ypr_reference(pctx, grp->ref, grp->exts, &flag); |
1111 | |
|
1112 | 0 | LY_ARRAY_FOR(grp->typedefs, u) { |
1113 | 0 | ypr_open(pctx->out, &flag); |
1114 | 0 | yprp_typedef(pctx, &grp->typedefs[u]); |
1115 | 0 | } |
1116 | |
|
1117 | 0 | LY_LIST_FOR(grp->groupings, subgrp) { |
1118 | 0 | ypr_open(pctx->out, &flag); |
1119 | 0 | yprp_grouping(pctx, subgrp); |
1120 | 0 | } |
1121 | |
|
1122 | 0 | LY_LIST_FOR(grp->child, data) { |
1123 | 0 | ypr_open(pctx->out, &flag); |
1124 | 0 | yprp_node(pctx, data); |
1125 | 0 | } |
1126 | |
|
1127 | 0 | LY_LIST_FOR(grp->actions, action) { |
1128 | 0 | ypr_open(pctx->out, &flag); |
1129 | 0 | yprp_action(pctx, action); |
1130 | 0 | } |
1131 | |
|
1132 | 0 | LY_LIST_FOR(grp->notifs, notif) { |
1133 | 0 | ypr_open(pctx->out, &flag); |
1134 | 0 | yprp_notification(pctx, notif); |
1135 | 0 | } |
1136 | |
|
1137 | 0 | LEVEL--; |
1138 | 0 | ypr_close(pctx, flag); |
1139 | 0 | } |
1140 | | |
1141 | | static void |
1142 | | yprp_inout(struct lys_ypr_ctx *pctx, const struct lysp_node_action_inout *inout, ly_bool *flag) |
1143 | 0 | { |
1144 | 0 | LY_ARRAY_COUNT_TYPE u; |
1145 | 0 | struct lysp_node *data; |
1146 | 0 | struct lysp_node_grp *grp; |
1147 | |
|
1148 | 0 | if (!inout->child) { |
1149 | | /* no children */ |
1150 | 0 | return; |
1151 | 0 | } |
1152 | 0 | ypr_open(pctx->out, flag); |
1153 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
1154 | |
|
1155 | 0 | ly_print_(pctx->out, "%*s%s {\n", INDENT, inout->name); |
1156 | 0 | LEVEL++; |
1157 | |
|
1158 | 0 | yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL); |
1159 | 0 | LY_ARRAY_FOR(inout->musts, u) { |
1160 | 0 | yprp_restr(pctx, &inout->musts[u], LY_STMT_MUST, NULL); |
1161 | 0 | } |
1162 | 0 | LY_ARRAY_FOR(inout->typedefs, u) { |
1163 | 0 | yprp_typedef(pctx, &inout->typedefs[u]); |
1164 | 0 | } |
1165 | 0 | LY_LIST_FOR(inout->groupings, grp) { |
1166 | 0 | yprp_grouping(pctx, grp); |
1167 | 0 | } |
1168 | |
|
1169 | 0 | LY_LIST_FOR(inout->child, data) { |
1170 | 0 | yprp_node(pctx, data); |
1171 | 0 | } |
1172 | |
|
1173 | 0 | LEVEL--; |
1174 | 0 | ypr_close(pctx, 1); |
1175 | 0 | } |
1176 | | |
1177 | | static void |
1178 | | yprc_inout(struct lys_ypr_ctx *pctx, const struct lysc_node_action_inout *inout, ly_bool *flag) |
1179 | 0 | { |
1180 | 0 | LY_ARRAY_COUNT_TYPE u; |
1181 | 0 | struct lysc_node *data; |
1182 | |
|
1183 | 0 | if (!inout->child) { |
1184 | | /* input/output is empty */ |
1185 | 0 | return; |
1186 | 0 | } |
1187 | 0 | ypr_open(pctx->out, flag); |
1188 | |
|
1189 | 0 | ly_print_(pctx->out, "\n%*s%s {\n", INDENT, inout->name); |
1190 | 0 | LEVEL++; |
1191 | |
|
1192 | 0 | yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(inout->nodetype), 0, inout->exts, NULL); |
1193 | 0 | LY_ARRAY_FOR(inout->musts, u) { |
1194 | 0 | yprc_must(pctx, &inout->musts[u], NULL); |
1195 | 0 | } |
1196 | |
|
1197 | 0 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
1198 | 0 | LY_LIST_FOR(inout->child, data) { |
1199 | 0 | yprc_node(pctx, data); |
1200 | 0 | } |
1201 | 0 | } |
1202 | |
|
1203 | 0 | LEVEL--; |
1204 | 0 | ypr_close(pctx, 1); |
1205 | 0 | } |
1206 | | |
1207 | | static void |
1208 | | yprp_notification(struct lys_ypr_ctx *pctx, const struct lysp_node_notif *notif) |
1209 | 0 | { |
1210 | 0 | LY_ARRAY_COUNT_TYPE u; |
1211 | 0 | ly_bool flag = 0; |
1212 | 0 | struct lysp_node *data; |
1213 | 0 | struct lysp_node_grp *grp; |
1214 | |
|
1215 | 0 | ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name); |
1216 | |
|
1217 | 0 | LEVEL++; |
1218 | 0 | yprp_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag); |
1219 | 0 | yprp_iffeatures(pctx, notif->iffeatures, notif->exts, &flag); |
1220 | |
|
1221 | 0 | LY_ARRAY_FOR(notif->musts, u) { |
1222 | 0 | yprp_restr(pctx, ¬if->musts[u], LY_STMT_MUST, &flag); |
1223 | 0 | } |
1224 | 0 | ypr_status(pctx, notif->flags, notif->exts, &flag); |
1225 | 0 | ypr_description(pctx, notif->dsc, notif->exts, &flag); |
1226 | 0 | ypr_reference(pctx, notif->ref, notif->exts, &flag); |
1227 | |
|
1228 | 0 | LY_ARRAY_FOR(notif->typedefs, u) { |
1229 | 0 | ypr_open(pctx->out, &flag); |
1230 | 0 | yprp_typedef(pctx, ¬if->typedefs[u]); |
1231 | 0 | } |
1232 | |
|
1233 | 0 | LY_LIST_FOR(notif->groupings, grp) { |
1234 | 0 | ypr_open(pctx->out, &flag); |
1235 | 0 | yprp_grouping(pctx, grp); |
1236 | 0 | } |
1237 | |
|
1238 | 0 | LY_LIST_FOR(notif->child, data) { |
1239 | 0 | ypr_open(pctx->out, &flag); |
1240 | 0 | yprp_node(pctx, data); |
1241 | 0 | } |
1242 | |
|
1243 | 0 | LEVEL--; |
1244 | 0 | ypr_close(pctx, flag); |
1245 | 0 | } |
1246 | | |
1247 | | static void |
1248 | | yprc_notification(struct lys_ypr_ctx *pctx, const struct lysc_node_notif *notif) |
1249 | 0 | { |
1250 | 0 | LY_ARRAY_COUNT_TYPE u; |
1251 | 0 | ly_bool flag = 0; |
1252 | 0 | struct lysc_node *data; |
1253 | |
|
1254 | 0 | ly_print_(pctx->out, "%*snotification %s", INDENT, notif->name); |
1255 | |
|
1256 | 0 | LEVEL++; |
1257 | 0 | yprc_extension_instances(pctx, LY_STMT_NOTIFICATION, 0, notif->exts, &flag); |
1258 | |
|
1259 | 0 | LY_ARRAY_FOR(notif->musts, u) { |
1260 | 0 | yprc_must(pctx, ¬if->musts[u], &flag); |
1261 | 0 | } |
1262 | 0 | ypr_status(pctx, notif->flags, notif->exts, &flag); |
1263 | 0 | ypr_description(pctx, notif->dsc, notif->exts, &flag); |
1264 | 0 | ypr_reference(pctx, notif->ref, notif->exts, &flag); |
1265 | |
|
1266 | 0 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
1267 | 0 | LY_LIST_FOR(notif->child, data) { |
1268 | 0 | ypr_open(pctx->out, &flag); |
1269 | 0 | yprc_node(pctx, data); |
1270 | 0 | } |
1271 | 0 | } |
1272 | |
|
1273 | 0 | LEVEL--; |
1274 | 0 | ypr_close(pctx, flag); |
1275 | 0 | } |
1276 | | |
1277 | | static void |
1278 | | yprp_action(struct lys_ypr_ctx *pctx, const struct lysp_node_action *action) |
1279 | 0 | { |
1280 | 0 | LY_ARRAY_COUNT_TYPE u; |
1281 | 0 | ly_bool flag = 0; |
1282 | 0 | struct lysp_node_grp *grp; |
1283 | |
|
1284 | 0 | ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
1285 | |
|
1286 | 0 | LEVEL++; |
1287 | 0 | yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag); |
1288 | 0 | yprp_iffeatures(pctx, action->iffeatures, action->exts, &flag); |
1289 | 0 | ypr_status(pctx, action->flags, action->exts, &flag); |
1290 | 0 | ypr_description(pctx, action->dsc, action->exts, &flag); |
1291 | 0 | ypr_reference(pctx, action->ref, action->exts, &flag); |
1292 | |
|
1293 | 0 | YPR_EXTRA_LINE(flag, pctx); |
1294 | |
|
1295 | 0 | LY_ARRAY_FOR(action->typedefs, u) { |
1296 | 0 | ypr_open(pctx->out, &flag); |
1297 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
1298 | 0 | yprp_typedef(pctx, &action->typedefs[u]); |
1299 | 0 | } |
1300 | |
|
1301 | 0 | YPR_EXTRA_LINE(action->typedefs, pctx); |
1302 | |
|
1303 | 0 | LY_LIST_FOR(action->groupings, grp) { |
1304 | 0 | ypr_open(pctx->out, &flag); |
1305 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
1306 | 0 | yprp_grouping(pctx, grp); |
1307 | 0 | } |
1308 | |
|
1309 | 0 | YPR_EXTRA_LINE(action->groupings, pctx); |
1310 | |
|
1311 | 0 | yprp_inout(pctx, &action->input, &flag); |
1312 | 0 | yprp_inout(pctx, &action->output, &flag); |
1313 | |
|
1314 | 0 | LEVEL--; |
1315 | 0 | ypr_close(pctx, flag); |
1316 | 0 | } |
1317 | | |
1318 | | static void |
1319 | | yprc_action(struct lys_ypr_ctx *pctx, const struct lysc_node_action *action) |
1320 | 0 | { |
1321 | 0 | ly_bool flag = 0; |
1322 | |
|
1323 | 0 | ly_print_(pctx->out, "%*s%s %s", INDENT, action->parent ? "action" : "rpc", action->name); |
1324 | |
|
1325 | 0 | LEVEL++; |
1326 | 0 | yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(action->nodetype), 0, action->exts, &flag); |
1327 | 0 | ypr_status(pctx, action->flags, action->exts, &flag); |
1328 | 0 | ypr_description(pctx, action->dsc, action->exts, &flag); |
1329 | 0 | ypr_reference(pctx, action->ref, action->exts, &flag); |
1330 | |
|
1331 | 0 | yprc_inout(pctx, &action->input, &flag); |
1332 | 0 | yprc_inout(pctx, &action->output, &flag); |
1333 | |
|
1334 | 0 | LEVEL--; |
1335 | 0 | ypr_close(pctx, flag); |
1336 | 0 | } |
1337 | | |
1338 | | static void |
1339 | | yprp_node_common1(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag) |
1340 | 0 | { |
1341 | 0 | ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n"); |
1342 | 0 | LEVEL++; |
1343 | |
|
1344 | 0 | yprp_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag); |
1345 | 0 | yprp_when(pctx, lysp_node_when(node), flag); |
1346 | 0 | yprp_iffeatures(pctx, node->iffeatures, node->exts, flag); |
1347 | 0 | } |
1348 | | |
1349 | | static void |
1350 | | yprc_node_common1(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag) |
1351 | 0 | { |
1352 | 0 | LY_ARRAY_COUNT_TYPE u; |
1353 | 0 | struct lysc_when **when; |
1354 | |
|
1355 | 0 | ly_print_(pctx->out, "%*s%s %s%s", INDENT, lys_nodetype2str(node->nodetype), node->name, flag ? "" : " {\n"); |
1356 | 0 | LEVEL++; |
1357 | |
|
1358 | 0 | yprc_extension_instances(pctx, lyplg_ext_nodetype2stmt(node->nodetype), 0, node->exts, flag); |
1359 | |
|
1360 | 0 | when = lysc_node_when(node); |
1361 | 0 | LY_ARRAY_FOR(when, u) { |
1362 | 0 | yprc_when(pctx, when[u], flag); |
1363 | 0 | } |
1364 | 0 | } |
1365 | | |
1366 | | /* macro to unify the code */ |
1367 | | #define YPR_NODE_COMMON2 \ |
1368 | 0 | ypr_config(pctx, node->flags, node->exts, flag); \ |
1369 | 0 | if (node->nodetype & (LYS_CHOICE | LYS_LEAF | LYS_ANYDATA)) { \ |
1370 | 0 | ypr_mandatory(pctx, node->flags, node->exts, flag); \ |
1371 | 0 | } \ |
1372 | 0 | ypr_status(pctx, node->flags, node->exts, flag); \ |
1373 | 0 | ypr_description(pctx, node->dsc, node->exts, flag); \ |
1374 | 0 | ypr_reference(pctx, node->ref, node->exts, flag) |
1375 | | |
1376 | | static void |
1377 | | yprp_node_common2(struct lys_ypr_ctx *pctx, const struct lysp_node *node, ly_bool *flag) |
1378 | 0 | { |
1379 | 0 | YPR_NODE_COMMON2; |
1380 | 0 | } |
1381 | | |
1382 | | static void |
1383 | | yprc_node_common2(struct lys_ypr_ctx *pctx, const struct lysc_node *node, ly_bool *flag) |
1384 | 0 | { |
1385 | 0 | YPR_NODE_COMMON2; |
1386 | 0 | } |
1387 | | |
1388 | | #undef YPR_NODE_COMMON2 |
1389 | | |
1390 | | static void |
1391 | | yprp_container(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
1392 | 0 | { |
1393 | 0 | LY_ARRAY_COUNT_TYPE u; |
1394 | 0 | ly_bool flag = 0; |
1395 | 0 | struct lysp_node *child; |
1396 | 0 | struct lysp_node_action *action; |
1397 | 0 | struct lysp_node_notif *notif; |
1398 | 0 | struct lysp_node_grp *grp; |
1399 | 0 | struct lysp_node_container *cont = (struct lysp_node_container *)node; |
1400 | |
|
1401 | 0 | yprp_node_common1(pctx, node, &flag); |
1402 | |
|
1403 | 0 | LY_ARRAY_FOR(cont->musts, u) { |
1404 | 0 | yprp_restr(pctx, &cont->musts[u], LY_STMT_MUST, &flag); |
1405 | 0 | } |
1406 | 0 | if (cont->presence) { |
1407 | 0 | ypr_open(pctx->out, &flag); |
1408 | 0 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, cont->presence, 0, cont->exts); |
1409 | 0 | } |
1410 | |
|
1411 | 0 | yprp_node_common2(pctx, node, &flag); |
1412 | |
|
1413 | 0 | LY_ARRAY_FOR(cont->typedefs, u) { |
1414 | 0 | ypr_open(pctx->out, &flag); |
1415 | 0 | yprp_typedef(pctx, &cont->typedefs[u]); |
1416 | 0 | } |
1417 | |
|
1418 | 0 | LY_LIST_FOR(cont->groupings, grp) { |
1419 | 0 | ypr_open(pctx->out, &flag); |
1420 | 0 | yprp_grouping(pctx, grp); |
1421 | 0 | } |
1422 | |
|
1423 | 0 | LY_LIST_FOR(cont->child, child) { |
1424 | 0 | ypr_open(pctx->out, &flag); |
1425 | 0 | yprp_node(pctx, child); |
1426 | 0 | } |
1427 | |
|
1428 | 0 | LY_LIST_FOR(cont->actions, action) { |
1429 | 0 | ypr_open(pctx->out, &flag); |
1430 | 0 | yprp_action(pctx, action); |
1431 | 0 | } |
1432 | |
|
1433 | 0 | LY_LIST_FOR(cont->notifs, notif) { |
1434 | 0 | ypr_open(pctx->out, &flag); |
1435 | 0 | yprp_notification(pctx, notif); |
1436 | 0 | } |
1437 | |
|
1438 | 0 | LEVEL--; |
1439 | 0 | ypr_close(pctx, flag); |
1440 | 0 | } |
1441 | | |
1442 | | static void |
1443 | | yprc_container(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
1444 | 0 | { |
1445 | 0 | LY_ARRAY_COUNT_TYPE u; |
1446 | 0 | ly_bool flag = 0; |
1447 | 0 | struct lysc_node *child; |
1448 | 0 | struct lysc_node_action *action; |
1449 | 0 | struct lysc_node_notif *notif; |
1450 | 0 | struct lysc_node_container *cont = (struct lysc_node_container *)node; |
1451 | |
|
1452 | 0 | yprc_node_common1(pctx, node, &flag); |
1453 | |
|
1454 | 0 | LY_ARRAY_FOR(cont->musts, u) { |
1455 | 0 | yprc_must(pctx, &cont->musts[u], &flag); |
1456 | 0 | } |
1457 | 0 | if (cont->flags & LYS_PRESENCE) { |
1458 | 0 | ypr_open(pctx->out, &flag); |
1459 | 0 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, "true", 0, cont->exts); |
1460 | 0 | } |
1461 | |
|
1462 | 0 | yprc_node_common2(pctx, node, &flag); |
1463 | |
|
1464 | 0 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
1465 | 0 | LY_LIST_FOR(cont->child, child) { |
1466 | 0 | ypr_open(pctx->out, &flag); |
1467 | 0 | yprc_node(pctx, child); |
1468 | 0 | } |
1469 | |
|
1470 | 0 | LY_LIST_FOR(cont->actions, action) { |
1471 | 0 | ypr_open(pctx->out, &flag); |
1472 | 0 | yprc_action(pctx, action); |
1473 | 0 | } |
1474 | |
|
1475 | 0 | LY_LIST_FOR(cont->notifs, notif) { |
1476 | 0 | ypr_open(pctx->out, &flag); |
1477 | 0 | yprc_notification(pctx, notif); |
1478 | 0 | } |
1479 | 0 | } |
1480 | |
|
1481 | 0 | LEVEL--; |
1482 | 0 | ypr_close(pctx, flag); |
1483 | 0 | } |
1484 | | |
1485 | | static void |
1486 | | yprp_case(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
1487 | 0 | { |
1488 | 0 | ly_bool flag = 0; |
1489 | 0 | struct lysp_node *child; |
1490 | 0 | struct lysp_node_case *cas = (struct lysp_node_case *)node; |
1491 | |
|
1492 | 0 | yprp_node_common1(pctx, node, &flag); |
1493 | 0 | yprp_node_common2(pctx, node, &flag); |
1494 | |
|
1495 | 0 | LY_LIST_FOR(cas->child, child) { |
1496 | 0 | ypr_open(pctx->out, &flag); |
1497 | 0 | yprp_node(pctx, child); |
1498 | 0 | } |
1499 | |
|
1500 | 0 | LEVEL--; |
1501 | 0 | ypr_close(pctx, flag); |
1502 | 0 | } |
1503 | | |
1504 | | static void |
1505 | | yprc_case(struct lys_ypr_ctx *pctx, const struct lysc_node_case *cs) |
1506 | 0 | { |
1507 | 0 | ly_bool flag = 0; |
1508 | 0 | struct lysc_node *child; |
1509 | |
|
1510 | 0 | yprc_node_common1(pctx, &cs->node, &flag); |
1511 | 0 | yprc_node_common2(pctx, &cs->node, &flag); |
1512 | |
|
1513 | 0 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
1514 | 0 | for (child = cs->child; child && child->parent == (struct lysc_node *)cs; child = child->next) { |
1515 | 0 | ypr_open(pctx->out, &flag); |
1516 | 0 | yprc_node(pctx, child); |
1517 | 0 | } |
1518 | 0 | } |
1519 | |
|
1520 | 0 | LEVEL--; |
1521 | 0 | ypr_close(pctx, flag); |
1522 | 0 | } |
1523 | | |
1524 | | static void |
1525 | | yprp_choice(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
1526 | 0 | { |
1527 | 0 | ly_bool flag = 0; |
1528 | 0 | struct lysp_node *child; |
1529 | 0 | struct lysp_node_choice *choice = (struct lysp_node_choice *)node; |
1530 | |
|
1531 | 0 | yprp_node_common1(pctx, node, &flag); |
1532 | |
|
1533 | 0 | if (choice->dflt.str) { |
1534 | 0 | ypr_open(pctx->out, &flag); |
1535 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt.str, YPR_IS_LYS_SINGLEQUOTED(choice->dflt.flags), choice->exts); |
1536 | 0 | } |
1537 | |
|
1538 | 0 | yprp_node_common2(pctx, node, &flag); |
1539 | |
|
1540 | 0 | LY_LIST_FOR(choice->child, child) { |
1541 | 0 | ypr_open(pctx->out, &flag); |
1542 | 0 | yprp_node(pctx, child); |
1543 | 0 | } |
1544 | |
|
1545 | 0 | LEVEL--; |
1546 | 0 | ypr_close(pctx, flag); |
1547 | 0 | } |
1548 | | |
1549 | | static void |
1550 | | yprc_choice(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
1551 | 0 | { |
1552 | 0 | ly_bool flag = 0; |
1553 | 0 | struct lysc_node_case *cs; |
1554 | 0 | struct lysc_node_choice *choice = (struct lysc_node_choice *)node; |
1555 | |
|
1556 | 0 | yprc_node_common1(pctx, node, &flag); |
1557 | |
|
1558 | 0 | if (choice->dflt) { |
1559 | 0 | ypr_open(pctx->out, &flag); |
1560 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, choice->dflt->name, 0, choice->exts); |
1561 | 0 | } |
1562 | |
|
1563 | 0 | yprc_node_common2(pctx, node, &flag); |
1564 | |
|
1565 | 0 | for (cs = choice->cases; cs; cs = (struct lysc_node_case *)cs->next) { |
1566 | 0 | ypr_open(pctx->out, &flag); |
1567 | 0 | yprc_case(pctx, cs); |
1568 | 0 | } |
1569 | |
|
1570 | 0 | LEVEL--; |
1571 | 0 | ypr_close(pctx, flag); |
1572 | 0 | } |
1573 | | |
1574 | | static void |
1575 | | yprp_leaf(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
1576 | 0 | { |
1577 | 0 | LY_ARRAY_COUNT_TYPE u; |
1578 | 0 | struct lysp_node_leaf *leaf = (struct lysp_node_leaf *)node; |
1579 | |
|
1580 | 0 | yprp_node_common1(pctx, node, NULL); |
1581 | |
|
1582 | 0 | yprp_type(pctx, &leaf->type); |
1583 | 0 | ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts); |
1584 | 0 | LY_ARRAY_FOR(leaf->musts, u) { |
1585 | 0 | yprp_restr(pctx, &leaf->musts[u], LY_STMT_MUST, NULL); |
1586 | 0 | } |
1587 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, YPR_IS_LYS_SINGLEQUOTED(leaf->dflt.flags), leaf->exts); |
1588 | |
|
1589 | 0 | yprp_node_common2(pctx, node, NULL); |
1590 | |
|
1591 | 0 | LEVEL--; |
1592 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
1593 | 0 | } |
1594 | | |
1595 | | static void |
1596 | | yprc_leaf(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
1597 | 0 | { |
1598 | 0 | LY_ARRAY_COUNT_TYPE u; |
1599 | 0 | struct lysc_node_leaf *leaf = (struct lysc_node_leaf *)node; |
1600 | |
|
1601 | 0 | yprc_node_common1(pctx, node, NULL); |
1602 | |
|
1603 | 0 | yprc_type(pctx, leaf->type); |
1604 | 0 | ypr_substmt(pctx, LY_STMT_UNITS, 0, leaf->units, 0, leaf->exts); |
1605 | 0 | LY_ARRAY_FOR(leaf->musts, u) { |
1606 | 0 | yprc_must(pctx, &leaf->musts[u], NULL); |
1607 | 0 | } |
1608 | |
|
1609 | 0 | if (leaf->dflt.str) { |
1610 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, leaf->dflt.str, 0, leaf->exts); |
1611 | 0 | } |
1612 | |
|
1613 | 0 | yprc_node_common2(pctx, node, NULL); |
1614 | |
|
1615 | 0 | LEVEL--; |
1616 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
1617 | 0 | } |
1618 | | |
1619 | | static void |
1620 | | yprp_leaflist(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
1621 | 0 | { |
1622 | 0 | LY_ARRAY_COUNT_TYPE u; |
1623 | 0 | struct lysp_node_leaflist *llist = (struct lysp_node_leaflist *)node; |
1624 | |
|
1625 | 0 | yprp_node_common1(pctx, node, NULL); |
1626 | |
|
1627 | 0 | yprp_type(pctx, &llist->type); |
1628 | 0 | ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts); |
1629 | 0 | LY_ARRAY_FOR(llist->musts, u) { |
1630 | 0 | yprp_restr(pctx, &llist->musts[u], LY_STMT_MUST, NULL); |
1631 | 0 | } |
1632 | 0 | LY_ARRAY_FOR(llist->dflts, u) { |
1633 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, llist->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(llist->dflts[u].flags), |
1634 | 0 | llist->exts); |
1635 | 0 | } |
1636 | |
|
1637 | 0 | ypr_config(pctx, node->flags, node->exts, NULL); |
1638 | |
|
1639 | 0 | if (llist->flags & LYS_SET_MIN) { |
1640 | 0 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL); |
1641 | 0 | } |
1642 | 0 | if (llist->flags & LYS_SET_MAX) { |
1643 | 0 | if (llist->max) { |
1644 | 0 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL); |
1645 | 0 | } else { |
1646 | 0 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts); |
1647 | 0 | } |
1648 | 0 | } |
1649 | |
|
1650 | 0 | if (llist->flags & LYS_ORDBY_MASK) { |
1651 | 0 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", 0, llist->exts); |
1652 | 0 | } |
1653 | |
|
1654 | 0 | ypr_status(pctx, node->flags, node->exts, NULL); |
1655 | 0 | ypr_description(pctx, node->dsc, node->exts, NULL); |
1656 | 0 | ypr_reference(pctx, node->ref, node->exts, NULL); |
1657 | |
|
1658 | 0 | LEVEL--; |
1659 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
1660 | 0 | } |
1661 | | |
1662 | | static void |
1663 | | yprc_leaflist(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
1664 | 0 | { |
1665 | 0 | LY_ARRAY_COUNT_TYPE u; |
1666 | 0 | struct lysc_node_leaflist *llist = (struct lysc_node_leaflist *)node; |
1667 | |
|
1668 | 0 | yprc_node_common1(pctx, node, NULL); |
1669 | |
|
1670 | 0 | yprc_type(pctx, llist->type); |
1671 | 0 | ypr_substmt(pctx, LY_STMT_UNITS, 0, llist->units, 0, llist->exts); |
1672 | 0 | LY_ARRAY_FOR(llist->musts, u) { |
1673 | 0 | yprc_must(pctx, &llist->musts[u], NULL); |
1674 | 0 | } |
1675 | 0 | LY_ARRAY_FOR(llist->dflts, u) { |
1676 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, llist->dflts[u].str, 0, llist->exts); |
1677 | 0 | } |
1678 | |
|
1679 | 0 | ypr_config(pctx, node->flags, node->exts, NULL); |
1680 | |
|
1681 | 0 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, llist->exts, llist->min, NULL); |
1682 | 0 | if (llist->max) { |
1683 | 0 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, llist->exts, llist->max, NULL); |
1684 | 0 | } else { |
1685 | 0 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, llist->exts); |
1686 | 0 | } |
1687 | |
|
1688 | 0 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (llist->flags & LYS_ORDBY_USER) ? "user" : "system", 0, llist->exts); |
1689 | |
|
1690 | 0 | ypr_status(pctx, node->flags, node->exts, NULL); |
1691 | 0 | ypr_description(pctx, node->dsc, node->exts, NULL); |
1692 | 0 | ypr_reference(pctx, node->ref, node->exts, NULL); |
1693 | |
|
1694 | 0 | LEVEL--; |
1695 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
1696 | 0 | } |
1697 | | |
1698 | | static void |
1699 | | yprp_list(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
1700 | 0 | { |
1701 | 0 | LY_ARRAY_COUNT_TYPE u; |
1702 | 0 | ly_bool flag = 0; |
1703 | 0 | struct lysp_node *child; |
1704 | 0 | struct lysp_node_action *action; |
1705 | 0 | struct lysp_node_notif *notif; |
1706 | 0 | struct lysp_node_grp *grp; |
1707 | 0 | struct lysp_node_list *list = (struct lysp_node_list *)node; |
1708 | |
|
1709 | 0 | yprp_node_common1(pctx, node, &flag); |
1710 | |
|
1711 | 0 | LY_ARRAY_FOR(list->musts, u) { |
1712 | 0 | yprp_restr(pctx, &list->musts[u], LY_STMT_MUST, &flag); |
1713 | 0 | } |
1714 | 0 | if (list->key) { |
1715 | 0 | ypr_open(pctx->out, &flag); |
1716 | 0 | ypr_substmt(pctx, LY_STMT_KEY, 0, list->key, 0, list->exts); |
1717 | 0 | } |
1718 | 0 | LY_ARRAY_FOR(list->uniques, u) { |
1719 | 0 | ypr_open(pctx->out, &flag); |
1720 | 0 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, list->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(list->uniques[u].flags), |
1721 | 0 | list->exts); |
1722 | 0 | } |
1723 | |
|
1724 | 0 | ypr_config(pctx, node->flags, node->exts, &flag); |
1725 | |
|
1726 | 0 | if (list->flags & LYS_SET_MIN) { |
1727 | 0 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, &flag); |
1728 | 0 | } |
1729 | 0 | if (list->flags & LYS_SET_MAX) { |
1730 | 0 | if (list->max) { |
1731 | 0 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, &flag); |
1732 | 0 | } else { |
1733 | 0 | ypr_open(pctx->out, &flag); |
1734 | 0 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts); |
1735 | 0 | } |
1736 | 0 | } |
1737 | |
|
1738 | 0 | if (list->flags & LYS_ORDBY_MASK) { |
1739 | 0 | ypr_open(pctx->out, &flag); |
1740 | 0 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", 0, list->exts); |
1741 | 0 | } |
1742 | |
|
1743 | 0 | ypr_status(pctx, node->flags, node->exts, &flag); |
1744 | 0 | ypr_description(pctx, node->dsc, node->exts, &flag); |
1745 | 0 | ypr_reference(pctx, node->ref, node->exts, &flag); |
1746 | |
|
1747 | 0 | LY_ARRAY_FOR(list->typedefs, u) { |
1748 | 0 | ypr_open(pctx->out, &flag); |
1749 | 0 | yprp_typedef(pctx, &list->typedefs[u]); |
1750 | 0 | } |
1751 | |
|
1752 | 0 | LY_LIST_FOR(list->groupings, grp) { |
1753 | 0 | ypr_open(pctx->out, &flag); |
1754 | 0 | yprp_grouping(pctx, grp); |
1755 | 0 | } |
1756 | |
|
1757 | 0 | LY_LIST_FOR(list->child, child) { |
1758 | 0 | ypr_open(pctx->out, &flag); |
1759 | 0 | yprp_node(pctx, child); |
1760 | 0 | } |
1761 | |
|
1762 | 0 | LY_LIST_FOR(list->actions, action) { |
1763 | 0 | ypr_open(pctx->out, &flag); |
1764 | 0 | yprp_action(pctx, action); |
1765 | 0 | } |
1766 | |
|
1767 | 0 | LY_LIST_FOR(list->notifs, notif) { |
1768 | 0 | ypr_open(pctx->out, &flag); |
1769 | 0 | yprp_notification(pctx, notif); |
1770 | 0 | } |
1771 | |
|
1772 | 0 | LEVEL--; |
1773 | 0 | ypr_close(pctx, flag); |
1774 | 0 | } |
1775 | | |
1776 | | static void |
1777 | | yprc_list(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
1778 | 0 | { |
1779 | 0 | LY_ARRAY_COUNT_TYPE u, v; |
1780 | 0 | struct lysc_node_list *list = (struct lysc_node_list *)node; |
1781 | |
|
1782 | 0 | yprc_node_common1(pctx, node, NULL); |
1783 | |
|
1784 | 0 | LY_ARRAY_FOR(list->musts, u) { |
1785 | 0 | yprc_must(pctx, &list->musts[u], NULL); |
1786 | 0 | } |
1787 | 0 | if (!(list->flags & LYS_KEYLESS)) { |
1788 | 0 | ly_print_(pctx->out, "%*skey \"", INDENT); |
1789 | 0 | for (struct lysc_node *key = list->child; key && key->nodetype == LYS_LEAF && (key->flags & LYS_KEY); key = key->next) { |
1790 | 0 | ly_print_(pctx->out, "%s%s", u > 0 ? ", " : "", key->name); |
1791 | 0 | } |
1792 | 0 | ly_print_(pctx->out, "\";\n"); |
1793 | 0 | } |
1794 | 0 | LY_ARRAY_FOR(list->uniques, u) { |
1795 | 0 | ly_print_(pctx->out, "%*sunique \"", INDENT); |
1796 | 0 | LY_ARRAY_FOR(list->uniques[u], v) { |
1797 | 0 | ly_print_(pctx->out, "%s%s", v > 0 ? ", " : "", list->uniques[u][v]->name); |
1798 | 0 | } |
1799 | 0 | ypr_close(pctx, 0); |
1800 | 0 | } |
1801 | |
|
1802 | 0 | ypr_config(pctx, node->flags, node->exts, NULL); |
1803 | |
|
1804 | 0 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, list->exts, list->min, NULL); |
1805 | 0 | if (list->max) { |
1806 | 0 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, list->exts, list->max, NULL); |
1807 | 0 | } else { |
1808 | 0 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, list->exts); |
1809 | 0 | } |
1810 | |
|
1811 | 0 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, (list->flags & LYS_ORDBY_USER) ? "user" : "system", 0, list->exts); |
1812 | |
|
1813 | 0 | ypr_status(pctx, node->flags, node->exts, NULL); |
1814 | 0 | ypr_description(pctx, node->dsc, node->exts, NULL); |
1815 | 0 | ypr_reference(pctx, node->ref, node->exts, NULL); |
1816 | |
|
1817 | 0 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
1818 | 0 | struct lysc_node *child; |
1819 | 0 | struct lysc_node_action *action; |
1820 | 0 | struct lysc_node_notif *notif; |
1821 | |
|
1822 | 0 | LY_LIST_FOR(list->child, child) { |
1823 | 0 | yprc_node(pctx, child); |
1824 | 0 | } |
1825 | |
|
1826 | 0 | LY_LIST_FOR(list->actions, action) { |
1827 | 0 | yprc_action(pctx, action); |
1828 | 0 | } |
1829 | |
|
1830 | 0 | LY_LIST_FOR(list->notifs, notif) { |
1831 | 0 | yprc_notification(pctx, notif); |
1832 | 0 | } |
1833 | 0 | } |
1834 | |
|
1835 | 0 | LEVEL--; |
1836 | 0 | ypr_close(pctx, 1); |
1837 | 0 | } |
1838 | | |
1839 | | static void |
1840 | | yprp_refine(struct lys_ypr_ctx *pctx, struct lysp_refine *refine) |
1841 | 0 | { |
1842 | 0 | LY_ARRAY_COUNT_TYPE u; |
1843 | 0 | ly_bool flag = 0; |
1844 | |
|
1845 | 0 | ly_print_(pctx->out, "%*srefine \"%s\"", INDENT, refine->nodeid); |
1846 | 0 | LEVEL++; |
1847 | |
|
1848 | 0 | yprp_extension_instances(pctx, LY_STMT_REFINE, 0, refine->exts, &flag); |
1849 | 0 | yprp_iffeatures(pctx, refine->iffeatures, refine->exts, &flag); |
1850 | |
|
1851 | 0 | LY_ARRAY_FOR(refine->musts, u) { |
1852 | 0 | ypr_open(pctx->out, &flag); |
1853 | 0 | yprp_restr(pctx, &refine->musts[u], LY_STMT_MUST, NULL); |
1854 | 0 | } |
1855 | |
|
1856 | 0 | if (refine->presence) { |
1857 | 0 | ypr_open(pctx->out, &flag); |
1858 | 0 | ypr_substmt(pctx, LY_STMT_PRESENCE, 0, refine->presence, 0, refine->exts); |
1859 | 0 | } |
1860 | |
|
1861 | 0 | LY_ARRAY_FOR(refine->dflts, u) { |
1862 | 0 | ypr_open(pctx->out, &flag); |
1863 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, refine->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(refine->dflts[u].flags), |
1864 | 0 | refine->exts); |
1865 | 0 | } |
1866 | |
|
1867 | 0 | ypr_config(pctx, refine->flags, refine->exts, &flag); |
1868 | 0 | ypr_mandatory(pctx, refine->flags, refine->exts, &flag); |
1869 | |
|
1870 | 0 | if (refine->flags & LYS_SET_MIN) { |
1871 | 0 | ypr_open(pctx->out, &flag); |
1872 | 0 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, refine->exts, refine->min, NULL); |
1873 | 0 | } |
1874 | 0 | if (refine->flags & LYS_SET_MAX) { |
1875 | 0 | ypr_open(pctx->out, &flag); |
1876 | 0 | if (refine->max) { |
1877 | 0 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, refine->exts, refine->max, NULL); |
1878 | 0 | } else { |
1879 | 0 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, refine->exts); |
1880 | 0 | } |
1881 | 0 | } |
1882 | |
|
1883 | 0 | ypr_description(pctx, refine->dsc, refine->exts, &flag); |
1884 | 0 | ypr_reference(pctx, refine->ref, refine->exts, &flag); |
1885 | |
|
1886 | 0 | LEVEL--; |
1887 | 0 | ypr_close(pctx, flag); |
1888 | 0 | } |
1889 | | |
1890 | | static void |
1891 | | yprp_augment(struct lys_ypr_ctx *pctx, const struct lysp_node_augment *aug) |
1892 | 0 | { |
1893 | 0 | struct lysp_node *child; |
1894 | 0 | struct lysp_node_action *action; |
1895 | 0 | struct lysp_node_notif *notif; |
1896 | |
|
1897 | 0 | ly_print_(pctx->out, "%*saugment \"%s\" {\n", INDENT, aug->nodeid); |
1898 | 0 | LEVEL++; |
1899 | |
|
1900 | 0 | yprp_extension_instances(pctx, LY_STMT_AUGMENT, 0, aug->exts, NULL); |
1901 | 0 | yprp_when(pctx, aug->when, NULL); |
1902 | 0 | yprp_iffeatures(pctx, aug->iffeatures, aug->exts, NULL); |
1903 | 0 | ypr_status(pctx, aug->flags, aug->exts, NULL); |
1904 | 0 | ypr_description(pctx, aug->dsc, aug->exts, NULL); |
1905 | 0 | ypr_reference(pctx, aug->ref, aug->exts, NULL); |
1906 | |
|
1907 | 0 | LY_LIST_FOR(aug->child, child) { |
1908 | 0 | yprp_node(pctx, child); |
1909 | 0 | } |
1910 | |
|
1911 | 0 | LY_LIST_FOR(aug->actions, action) { |
1912 | 0 | yprp_action(pctx, action); |
1913 | 0 | } |
1914 | |
|
1915 | 0 | LY_LIST_FOR(aug->notifs, notif) { |
1916 | 0 | yprp_notification(pctx, notif); |
1917 | 0 | } |
1918 | |
|
1919 | 0 | LEVEL--; |
1920 | 0 | ypr_close(pctx, 1); |
1921 | 0 | } |
1922 | | |
1923 | | static void |
1924 | | yprp_uses(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
1925 | 0 | { |
1926 | 0 | LY_ARRAY_COUNT_TYPE u; |
1927 | 0 | ly_bool flag = 0; |
1928 | 0 | struct lysp_node_uses *uses = (struct lysp_node_uses *)node; |
1929 | 0 | struct lysp_node_augment *aug; |
1930 | |
|
1931 | 0 | yprp_node_common1(pctx, node, &flag); |
1932 | 0 | yprp_node_common2(pctx, node, &flag); |
1933 | |
|
1934 | 0 | LY_ARRAY_FOR(uses->refines, u) { |
1935 | 0 | ypr_open(pctx->out, &flag); |
1936 | 0 | yprp_refine(pctx, &uses->refines[u]); |
1937 | 0 | } |
1938 | |
|
1939 | 0 | LY_LIST_FOR(uses->augments, aug) { |
1940 | 0 | ypr_open(pctx->out, &flag); |
1941 | 0 | yprp_augment(pctx, aug); |
1942 | 0 | } |
1943 | |
|
1944 | 0 | LEVEL--; |
1945 | 0 | ypr_close(pctx, flag); |
1946 | 0 | } |
1947 | | |
1948 | | static void |
1949 | | yprp_anydata(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
1950 | 0 | { |
1951 | 0 | LY_ARRAY_COUNT_TYPE u; |
1952 | 0 | ly_bool flag = 0; |
1953 | 0 | struct lysp_node_anydata *any = (struct lysp_node_anydata *)node; |
1954 | |
|
1955 | 0 | yprp_node_common1(pctx, node, &flag); |
1956 | |
|
1957 | 0 | LY_ARRAY_FOR(any->musts, u) { |
1958 | 0 | ypr_open(pctx->out, &flag); |
1959 | 0 | yprp_restr(pctx, &any->musts[u], LY_STMT_MUST, NULL); |
1960 | 0 | } |
1961 | |
|
1962 | 0 | yprp_node_common2(pctx, node, &flag); |
1963 | |
|
1964 | 0 | LEVEL--; |
1965 | 0 | ypr_close(pctx, flag); |
1966 | 0 | } |
1967 | | |
1968 | | static void |
1969 | | yprc_anydata(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
1970 | 0 | { |
1971 | 0 | LY_ARRAY_COUNT_TYPE u; |
1972 | 0 | ly_bool flag = 0; |
1973 | 0 | struct lysc_node_anydata *any = (struct lysc_node_anydata *)node; |
1974 | |
|
1975 | 0 | yprc_node_common1(pctx, node, &flag); |
1976 | |
|
1977 | 0 | LY_ARRAY_FOR(any->musts, u) { |
1978 | 0 | ypr_open(pctx->out, &flag); |
1979 | 0 | yprc_must(pctx, &any->musts[u], NULL); |
1980 | 0 | } |
1981 | |
|
1982 | 0 | yprc_node_common2(pctx, node, &flag); |
1983 | |
|
1984 | 0 | LEVEL--; |
1985 | 0 | ypr_close(pctx, flag); |
1986 | 0 | } |
1987 | | |
1988 | | static void |
1989 | | yprp_node(struct lys_ypr_ctx *pctx, const struct lysp_node *node) |
1990 | 0 | { |
1991 | 0 | switch (node->nodetype) { |
1992 | 0 | case LYS_CONTAINER: |
1993 | 0 | yprp_container(pctx, node); |
1994 | 0 | break; |
1995 | 0 | case LYS_CHOICE: |
1996 | 0 | yprp_choice(pctx, node); |
1997 | 0 | break; |
1998 | 0 | case LYS_LEAF: |
1999 | 0 | yprp_leaf(pctx, node); |
2000 | 0 | break; |
2001 | 0 | case LYS_LEAFLIST: |
2002 | 0 | yprp_leaflist(pctx, node); |
2003 | 0 | break; |
2004 | 0 | case LYS_LIST: |
2005 | 0 | yprp_list(pctx, node); |
2006 | 0 | break; |
2007 | 0 | case LYS_USES: |
2008 | 0 | yprp_uses(pctx, node); |
2009 | 0 | break; |
2010 | 0 | case LYS_ANYXML: |
2011 | 0 | case LYS_ANYDATA: |
2012 | 0 | yprp_anydata(pctx, node); |
2013 | 0 | break; |
2014 | 0 | case LYS_CASE: |
2015 | 0 | yprp_case(pctx, node); |
2016 | 0 | break; |
2017 | 0 | default: |
2018 | 0 | break; |
2019 | 0 | } |
2020 | 0 | } |
2021 | | |
2022 | | static void |
2023 | | yprc_node(struct lys_ypr_ctx *pctx, const struct lysc_node *node) |
2024 | 0 | { |
2025 | 0 | switch (node->nodetype) { |
2026 | 0 | case LYS_CONTAINER: |
2027 | 0 | yprc_container(pctx, node); |
2028 | 0 | break; |
2029 | 0 | case LYS_CHOICE: |
2030 | 0 | yprc_choice(pctx, node); |
2031 | 0 | break; |
2032 | 0 | case LYS_LEAF: |
2033 | 0 | yprc_leaf(pctx, node); |
2034 | 0 | break; |
2035 | 0 | case LYS_LEAFLIST: |
2036 | 0 | yprc_leaflist(pctx, node); |
2037 | 0 | break; |
2038 | 0 | case LYS_LIST: |
2039 | 0 | yprc_list(pctx, node); |
2040 | 0 | break; |
2041 | 0 | case LYS_ANYXML: |
2042 | 0 | case LYS_ANYDATA: |
2043 | 0 | yprc_anydata(pctx, node); |
2044 | 0 | break; |
2045 | 0 | default: |
2046 | 0 | break; |
2047 | 0 | } |
2048 | 0 | } |
2049 | | |
2050 | | static void |
2051 | | yprp_deviation(struct lys_ypr_ctx *pctx, const struct lysp_deviation *deviation) |
2052 | 0 | { |
2053 | 0 | LY_ARRAY_COUNT_TYPE u; |
2054 | 0 | struct lysp_deviate_add *add; |
2055 | 0 | struct lysp_deviate_rpl *rpl; |
2056 | 0 | struct lysp_deviate_del *del; |
2057 | 0 | struct lysp_deviate *elem; |
2058 | |
|
2059 | 0 | ly_print_(pctx->out, "%*sdeviation \"%s\" {\n", INDENT, deviation->nodeid); |
2060 | 0 | LEVEL++; |
2061 | |
|
2062 | 0 | yprp_extension_instances(pctx, LY_STMT_DEVIATION, 0, deviation->exts, NULL); |
2063 | 0 | ypr_description(pctx, deviation->dsc, deviation->exts, NULL); |
2064 | 0 | ypr_reference(pctx, deviation->ref, deviation->exts, NULL); |
2065 | |
|
2066 | 0 | LY_LIST_FOR(deviation->deviates, elem) { |
2067 | 0 | ly_print_(pctx->out, "%*sdeviate ", INDENT); |
2068 | 0 | if (elem->mod == LYS_DEV_NOT_SUPPORTED) { |
2069 | 0 | if (elem->exts) { |
2070 | 0 | ly_print_(pctx->out, "not-supported {\n"); |
2071 | 0 | LEVEL++; |
2072 | |
|
2073 | 0 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, elem->exts, NULL); |
2074 | 0 | } else { |
2075 | 0 | ly_print_(pctx->out, "not-supported;\n"); |
2076 | 0 | continue; |
2077 | 0 | } |
2078 | 0 | } else if (elem->mod == LYS_DEV_ADD) { |
2079 | 0 | add = (struct lysp_deviate_add *)elem; |
2080 | 0 | ly_print_(pctx->out, "add {\n"); |
2081 | 0 | LEVEL++; |
2082 | |
|
2083 | 0 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, add->exts, NULL); |
2084 | 0 | ypr_substmt(pctx, LY_STMT_UNITS, 0, add->units, 0, add->exts); |
2085 | 0 | LY_ARRAY_FOR(add->musts, u) { |
2086 | 0 | yprp_restr(pctx, &add->musts[u], LY_STMT_MUST, NULL); |
2087 | 0 | } |
2088 | 0 | LY_ARRAY_FOR(add->uniques, u) { |
2089 | 0 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, add->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(add->uniques[u].flags), |
2090 | 0 | add->exts); |
2091 | 0 | } |
2092 | 0 | LY_ARRAY_FOR(add->dflts, u) { |
2093 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, add->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(add->dflts[u].flags), |
2094 | 0 | add->exts); |
2095 | 0 | } |
2096 | 0 | ypr_config(pctx, add->flags, add->exts, NULL); |
2097 | 0 | ypr_mandatory(pctx, add->flags, add->exts, NULL); |
2098 | 0 | if (add->flags & LYS_SET_MIN) { |
2099 | 0 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, add->exts, add->min, NULL); |
2100 | 0 | } |
2101 | 0 | if (add->flags & LYS_SET_MAX) { |
2102 | 0 | if (add->max) { |
2103 | 0 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, add->exts, add->max, NULL); |
2104 | 0 | } else { |
2105 | 0 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, add->exts); |
2106 | 0 | } |
2107 | 0 | } |
2108 | 0 | } else if (elem->mod == LYS_DEV_REPLACE) { |
2109 | 0 | rpl = (struct lysp_deviate_rpl *)elem; |
2110 | 0 | ly_print_(pctx->out, "replace {\n"); |
2111 | 0 | LEVEL++; |
2112 | |
|
2113 | 0 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, rpl->exts, NULL); |
2114 | 0 | if (rpl->type) { |
2115 | 0 | yprp_type(pctx, rpl->type); |
2116 | 0 | } |
2117 | 0 | ypr_substmt(pctx, LY_STMT_UNITS, 0, rpl->units, 0, rpl->exts); |
2118 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, 0, rpl->dflt.str, YPR_IS_LYS_SINGLEQUOTED(rpl->dflt.flags), rpl->exts); |
2119 | 0 | ypr_config(pctx, rpl->flags, rpl->exts, NULL); |
2120 | 0 | ypr_mandatory(pctx, rpl->flags, rpl->exts, NULL); |
2121 | 0 | if (rpl->flags & LYS_SET_MIN) { |
2122 | 0 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, rpl->exts, rpl->min, NULL); |
2123 | 0 | } |
2124 | 0 | if (rpl->flags & LYS_SET_MAX) { |
2125 | 0 | if (rpl->max) { |
2126 | 0 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, rpl->exts, rpl->max, NULL); |
2127 | 0 | } else { |
2128 | 0 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, rpl->exts); |
2129 | 0 | } |
2130 | 0 | } |
2131 | 0 | } else if (elem->mod == LYS_DEV_DELETE) { |
2132 | 0 | del = (struct lysp_deviate_del *)elem; |
2133 | 0 | ly_print_(pctx->out, "delete {\n"); |
2134 | 0 | LEVEL++; |
2135 | |
|
2136 | 0 | yprp_extension_instances(pctx, LY_STMT_DEVIATE, 0, del->exts, NULL); |
2137 | 0 | ypr_substmt(pctx, LY_STMT_UNITS, 0, del->units, 0, del->exts); |
2138 | 0 | LY_ARRAY_FOR(del->musts, u) { |
2139 | 0 | yprp_restr(pctx, &del->musts[u], LY_STMT_MUST, NULL); |
2140 | 0 | } |
2141 | 0 | LY_ARRAY_FOR(del->uniques, u) { |
2142 | 0 | ypr_substmt(pctx, LY_STMT_UNIQUE, u, del->uniques[u].str, YPR_IS_LYS_SINGLEQUOTED(del->uniques[u].flags), |
2143 | 0 | del->exts); |
2144 | 0 | } |
2145 | 0 | LY_ARRAY_FOR(del->dflts, u) { |
2146 | 0 | ypr_substmt(pctx, LY_STMT_DEFAULT, u, del->dflts[u].str, YPR_IS_LYS_SINGLEQUOTED(del->dflts[u].flags), |
2147 | 0 | del->exts); |
2148 | 0 | } |
2149 | 0 | } |
2150 | | |
2151 | 0 | LEVEL--; |
2152 | 0 | ypr_close(pctx, 1); |
2153 | 0 | } |
2154 | |
|
2155 | 0 | LEVEL--; |
2156 | 0 | ypr_close(pctx, 1); |
2157 | 0 | } |
2158 | | |
2159 | | static void |
2160 | | yang_print_parsed_linkage(struct lys_ypr_ctx *pctx, const struct lysp_module *modp) |
2161 | 0 | { |
2162 | 0 | LY_ARRAY_COUNT_TYPE u; |
2163 | |
|
2164 | 0 | LY_ARRAY_FOR(modp->imports, u) { |
2165 | 0 | if (modp->imports[u].flags & LYS_INTERNAL) { |
2166 | 0 | continue; |
2167 | 0 | } |
2168 | | |
2169 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2170 | 0 | ly_print_(pctx->out, "%*simport %s {\n", INDENT, modp->imports[u].name); |
2171 | 0 | LEVEL++; |
2172 | 0 | yprp_extension_instances(pctx, LY_STMT_IMPORT, 0, modp->imports[u].exts, NULL); |
2173 | 0 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, modp->imports[u].prefix, 0, modp->imports[u].exts); |
2174 | 0 | if (modp->imports[u].rev[0]) { |
2175 | 0 | ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->imports[u].rev, 0, modp->imports[u].exts); |
2176 | 0 | } |
2177 | 0 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->imports[u].dsc, 0, modp->imports[u].exts); |
2178 | 0 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->imports[u].ref, 0, modp->imports[u].exts); |
2179 | 0 | LEVEL--; |
2180 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
2181 | 0 | } |
2182 | 0 | YPR_EXTRA_LINE(modp->imports, pctx); |
2183 | |
|
2184 | 0 | LY_ARRAY_FOR(modp->includes, u) { |
2185 | 0 | if (modp->includes[u].injected) { |
2186 | | /* do not print the includes injected from submodules */ |
2187 | 0 | continue; |
2188 | 0 | } |
2189 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2190 | 0 | if (modp->includes[u].rev[0] || modp->includes[u].dsc || modp->includes[u].ref || modp->includes[u].exts) { |
2191 | 0 | ly_print_(pctx->out, "%*sinclude %s {\n", INDENT, modp->includes[u].name); |
2192 | 0 | LEVEL++; |
2193 | 0 | yprp_extension_instances(pctx, LY_STMT_INCLUDE, 0, modp->includes[u].exts, NULL); |
2194 | 0 | if (modp->includes[u].rev[0]) { |
2195 | 0 | ypr_substmt(pctx, LY_STMT_REVISION_DATE, 0, modp->includes[u].rev, 0, modp->includes[u].exts); |
2196 | 0 | } |
2197 | 0 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, modp->includes[u].dsc, 0, modp->includes[u].exts); |
2198 | 0 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, modp->includes[u].ref, 0, modp->includes[u].exts); |
2199 | 0 | LEVEL--; |
2200 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
2201 | 0 | } else { |
2202 | 0 | ly_print_(pctx->out, "\n%*sinclude \"%s\";\n", INDENT, modp->includes[u].name); |
2203 | 0 | } |
2204 | 0 | } |
2205 | 0 | YPR_EXTRA_LINE(modp->includes, pctx); |
2206 | 0 | } |
2207 | | |
2208 | | static void |
2209 | | yang_print_parsed_body(struct lys_ypr_ctx *pctx, const struct lysp_module *modp) |
2210 | 0 | { |
2211 | 0 | LY_ARRAY_COUNT_TYPE u; |
2212 | 0 | struct lysp_node *data; |
2213 | 0 | struct lysp_node_action *action; |
2214 | 0 | struct lysp_node_notif *notif; |
2215 | 0 | struct lysp_node_grp *grp; |
2216 | 0 | struct lysp_node_augment *aug; |
2217 | |
|
2218 | 0 | LY_ARRAY_FOR(modp->extensions, u) { |
2219 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2220 | 0 | yprp_extension(pctx, &modp->extensions[u]); |
2221 | 0 | } |
2222 | |
|
2223 | 0 | YPR_EXTRA_LINE(modp->extensions, pctx); |
2224 | |
|
2225 | 0 | if (yprp_extension_has_printable_instances(modp->exts)) { |
2226 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2227 | 0 | yprp_extension_instances(pctx, LY_STMT_MODULE, 0, modp->exts, NULL); |
2228 | 0 | } |
2229 | |
|
2230 | 0 | YPR_EXTRA_LINE(modp->exts, pctx); |
2231 | |
|
2232 | 0 | LY_ARRAY_FOR(modp->features, u) { |
2233 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2234 | 0 | yprp_feature(pctx, &modp->features[u]); |
2235 | 0 | YPR_EXTRA_LINE(1, pctx); |
2236 | 0 | } |
2237 | |
|
2238 | 0 | YPR_EXTRA_LINE(modp->features, pctx); |
2239 | |
|
2240 | 0 | LY_ARRAY_FOR(modp->identities, u) { |
2241 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2242 | 0 | yprp_identity(pctx, &modp->identities[u]); |
2243 | 0 | YPR_EXTRA_LINE(1, pctx); |
2244 | 0 | } |
2245 | |
|
2246 | 0 | YPR_EXTRA_LINE(modp->identities, pctx); |
2247 | |
|
2248 | 0 | LY_ARRAY_FOR(modp->typedefs, u) { |
2249 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2250 | 0 | yprp_typedef(pctx, &modp->typedefs[u]); |
2251 | 0 | YPR_EXTRA_LINE(1, pctx); |
2252 | 0 | } |
2253 | |
|
2254 | 0 | YPR_EXTRA_LINE(modp->typedefs, pctx); |
2255 | |
|
2256 | 0 | LY_LIST_FOR(modp->groupings, grp) { |
2257 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2258 | 0 | yprp_grouping(pctx, grp); |
2259 | 0 | YPR_EXTRA_LINE(1, pctx); |
2260 | 0 | } |
2261 | |
|
2262 | 0 | YPR_EXTRA_LINE(modp->groupings, pctx); |
2263 | |
|
2264 | 0 | LY_LIST_FOR(modp->data, data) { |
2265 | 0 | if (data->flags & LYS_INTERNAL) { |
2266 | 0 | continue; |
2267 | 0 | } |
2268 | | |
2269 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2270 | 0 | yprp_node(pctx, data); |
2271 | 0 | } |
2272 | |
|
2273 | 0 | YPR_EXTRA_LINE(modp->data, pctx); |
2274 | |
|
2275 | 0 | LY_LIST_FOR(modp->augments, aug) { |
2276 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2277 | 0 | yprp_augment(pctx, aug); |
2278 | 0 | } |
2279 | |
|
2280 | 0 | YPR_EXTRA_LINE(modp->augments, pctx); |
2281 | |
|
2282 | 0 | LY_LIST_FOR(modp->rpcs, action) { |
2283 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2284 | 0 | yprp_action(pctx, action); |
2285 | 0 | } |
2286 | |
|
2287 | 0 | YPR_EXTRA_LINE(modp->rpcs, pctx); |
2288 | |
|
2289 | 0 | LY_LIST_FOR(modp->notifs, notif) { |
2290 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2291 | 0 | yprp_notification(pctx, notif); |
2292 | 0 | } |
2293 | |
|
2294 | 0 | YPR_EXTRA_LINE(modp->notifs, pctx); |
2295 | |
|
2296 | 0 | LY_ARRAY_FOR(modp->deviations, u) { |
2297 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2298 | 0 | yprp_deviation(pctx, &modp->deviations[u]); |
2299 | 0 | } |
2300 | |
|
2301 | 0 | YPR_EXTRA_LINE(modp->deviations, pctx); |
2302 | 0 | } |
2303 | | |
2304 | | LY_ERR |
2305 | | yang_print_parsed_module(struct ly_out *out, const struct lysp_module *modp, uint32_t options) |
2306 | 0 | { |
2307 | 0 | LY_ARRAY_COUNT_TYPE u; |
2308 | 0 | const struct lys_module *module = modp->mod; |
2309 | 0 | struct lys_ypr_ctx pctx_ = { |
2310 | 0 | .out = out, |
2311 | 0 | .level = 0, |
2312 | 0 | .options = options, |
2313 | 0 | .module = module, |
2314 | 0 | .schema = LYS_YPR_PARSED |
2315 | 0 | }, *pctx = &pctx_; |
2316 | |
|
2317 | 0 | ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name); |
2318 | 0 | LEVEL++; |
2319 | | |
2320 | | /* module-header-stmts */ |
2321 | 0 | if (modp->version) { |
2322 | 0 | ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, modp->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, modp->exts); |
2323 | 0 | } |
2324 | 0 | ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modp->exts); |
2325 | 0 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modp->exts); |
2326 | |
|
2327 | 0 | YPR_EXTRA_LINE(1, pctx); |
2328 | | |
2329 | | /* linkage-stmts (import/include) */ |
2330 | 0 | yang_print_parsed_linkage(pctx, modp); |
2331 | | |
2332 | | /* meta-stmts */ |
2333 | 0 | if (module->org || module->contact || module->dsc || module->ref) { |
2334 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2335 | 0 | } |
2336 | 0 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modp->exts); |
2337 | 0 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modp->exts); |
2338 | 0 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modp->exts); |
2339 | 0 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modp->exts); |
2340 | |
|
2341 | 0 | YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx); |
2342 | | |
2343 | | /* revision-stmts */ |
2344 | 0 | LY_ARRAY_FOR(modp->revs, u) { |
2345 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2346 | 0 | yprp_revision(pctx, &modp->revs[u]); |
2347 | 0 | } |
2348 | |
|
2349 | 0 | YPR_EXTRA_LINE(modp->revs, pctx); |
2350 | | |
2351 | | /* body-stmts */ |
2352 | 0 | yang_print_parsed_body(pctx, modp); |
2353 | |
|
2354 | 0 | LEVEL--; |
2355 | 0 | ly_print_(out, "%*s}\n", INDENT); |
2356 | 0 | ly_print_flush(out); |
2357 | |
|
2358 | 0 | return LY_SUCCESS; |
2359 | 0 | } |
2360 | | |
2361 | | static void |
2362 | | yprp_belongsto(struct lys_ypr_ctx *pctx, const struct lysp_submodule *submodp) |
2363 | 0 | { |
2364 | 0 | ly_print_(pctx->out, "%*sbelongs-to %s {\n", INDENT, submodp->mod->name); |
2365 | 0 | LEVEL++; |
2366 | 0 | yprp_extension_instances(pctx, LY_STMT_BELONGS_TO, 0, submodp->exts, NULL); |
2367 | 0 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, submodp->prefix, 0, submodp->exts); |
2368 | 0 | LEVEL--; |
2369 | 0 | ly_print_(pctx->out, "%*s}\n", INDENT); |
2370 | 0 | } |
2371 | | |
2372 | | LY_ERR |
2373 | | yang_print_parsed_submodule(struct ly_out *out, const struct lysp_submodule *submodp, uint32_t options) |
2374 | 0 | { |
2375 | 0 | LY_ARRAY_COUNT_TYPE u; |
2376 | 0 | struct lys_ypr_ctx pctx_ = { |
2377 | 0 | .out = out, |
2378 | 0 | .level = 0, |
2379 | 0 | .options = options, |
2380 | 0 | .module = submodp->mod, |
2381 | 0 | .schema = LYS_YPR_PARSED |
2382 | 0 | }, *pctx = &pctx_; |
2383 | |
|
2384 | 0 | ly_print_(pctx->out, "%*ssubmodule %s {\n", INDENT, submodp->name); |
2385 | 0 | LEVEL++; |
2386 | | |
2387 | | /* submodule-header-stmts */ |
2388 | 0 | if (submodp->version) { |
2389 | 0 | ypr_substmt(pctx, LY_STMT_YANG_VERSION, 0, submodp->version == LYS_VERSION_1_1 ? "1.1" : "1", 0, submodp->exts); |
2390 | 0 | } |
2391 | |
|
2392 | 0 | yprp_belongsto(pctx, submodp); |
2393 | |
|
2394 | 0 | YPR_EXTRA_LINE(1, pctx); |
2395 | | |
2396 | | /* linkage-stmts (import/include) */ |
2397 | 0 | yang_print_parsed_linkage(pctx, (struct lysp_module *)submodp); |
2398 | | |
2399 | | /* meta-stmts */ |
2400 | 0 | if (submodp->org || submodp->contact || submodp->dsc || submodp->ref) { |
2401 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2402 | 0 | } |
2403 | 0 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, submodp->org, 0, submodp->exts); |
2404 | 0 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, submodp->contact, 0, submodp->exts); |
2405 | 0 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, submodp->dsc, 0, submodp->exts); |
2406 | 0 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, submodp->ref, 0, submodp->exts); |
2407 | |
|
2408 | 0 | YPR_EXTRA_LINE(submodp->org || submodp->contact || submodp->dsc || submodp->ref, pctx); |
2409 | | |
2410 | | /* revision-stmts */ |
2411 | 0 | LY_ARRAY_FOR(submodp->revs, u) { |
2412 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2413 | 0 | yprp_revision(pctx, &submodp->revs[u]); |
2414 | 0 | } |
2415 | |
|
2416 | 0 | YPR_EXTRA_LINE(submodp->revs, pctx); |
2417 | | |
2418 | | /* body-stmts */ |
2419 | 0 | yang_print_parsed_body(pctx, (struct lysp_module *)submodp); |
2420 | |
|
2421 | 0 | LEVEL--; |
2422 | 0 | ly_print_(out, "%*s}\n", INDENT); |
2423 | 0 | ly_print_flush(out); |
2424 | |
|
2425 | 0 | return LY_SUCCESS; |
2426 | 0 | } |
2427 | | |
2428 | | LY_ERR |
2429 | | yang_print_compiled_node(struct ly_out *out, const struct lysc_node *node, uint32_t options) |
2430 | 0 | { |
2431 | 0 | struct lys_ypr_ctx pctx_ = { |
2432 | 0 | .out = out, |
2433 | 0 | .level = 0, |
2434 | 0 | .options = options, |
2435 | 0 | .module = node->module, |
2436 | 0 | .schema = LYS_YPR_COMPILED |
2437 | 0 | }, *pctx = &pctx_; |
2438 | |
|
2439 | 0 | yprc_node(pctx, node); |
2440 | |
|
2441 | 0 | ly_print_flush(out); |
2442 | 0 | return LY_SUCCESS; |
2443 | 0 | } |
2444 | | |
2445 | | LY_ERR |
2446 | | yang_print_compiled(struct ly_out *out, const struct lys_module *module, uint32_t options) |
2447 | 0 | { |
2448 | 0 | LY_ARRAY_COUNT_TYPE u; |
2449 | 0 | struct lysc_module *modc = module->compiled; |
2450 | 0 | struct lys_ypr_ctx pctx_ = { |
2451 | 0 | .out = out, |
2452 | 0 | .level = 0, |
2453 | 0 | .options = options, |
2454 | 0 | .module = module, |
2455 | 0 | .schema = LYS_YPR_COMPILED |
2456 | 0 | }, *pctx = &pctx_; |
2457 | |
|
2458 | 0 | ly_print_(pctx->out, "%*smodule %s {\n", INDENT, module->name); |
2459 | 0 | LEVEL++; |
2460 | | |
2461 | | /* module-header-stmts */ |
2462 | 0 | ypr_substmt(pctx, LY_STMT_NAMESPACE, 0, module->ns, 0, modc->exts); |
2463 | 0 | ypr_substmt(pctx, LY_STMT_PREFIX, 0, module->prefix, 0, modc->exts); |
2464 | |
|
2465 | 0 | YPR_EXTRA_LINE(1, pctx); |
2466 | | |
2467 | | /* no linkage-stmts */ |
2468 | | |
2469 | | /* meta-stmts */ |
2470 | 0 | if (module->org || module->contact || module->dsc || module->ref) { |
2471 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2472 | 0 | } |
2473 | 0 | ypr_substmt(pctx, LY_STMT_ORGANIZATION, 0, module->org, 0, modc->exts); |
2474 | 0 | ypr_substmt(pctx, LY_STMT_CONTACT, 0, module->contact, 0, modc->exts); |
2475 | 0 | ypr_substmt(pctx, LY_STMT_DESCRIPTION, 0, module->dsc, 0, modc->exts); |
2476 | 0 | ypr_substmt(pctx, LY_STMT_REFERENCE, 0, module->ref, 0, modc->exts); |
2477 | |
|
2478 | 0 | YPR_EXTRA_LINE(module->org || module->contact || module->dsc || module->ref, pctx); |
2479 | | |
2480 | | /* revision-stmts */ |
2481 | 0 | if (module->revision) { |
2482 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2483 | 0 | ly_print_(pctx->out, "%*srevision %s;\n", INDENT, module->revision); |
2484 | 0 | YPR_EXTRA_LINE(1, pctx); |
2485 | 0 | } |
2486 | | |
2487 | | /* body-stmts */ |
2488 | 0 | if (modc->exts) { |
2489 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2490 | 0 | yprc_extension_instances(pctx, LY_STMT_MODULE, 0, module->compiled->exts, NULL); |
2491 | 0 | YPR_EXTRA_LINE(1, pctx); |
2492 | 0 | } |
2493 | |
|
2494 | 0 | LY_ARRAY_FOR(module->identities, u) { |
2495 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2496 | 0 | yprc_identity(pctx, &module->identities[u]); |
2497 | 0 | YPR_EXTRA_LINE(1, pctx); |
2498 | 0 | } |
2499 | |
|
2500 | 0 | if (!(pctx->options & LYS_PRINT_NO_SUBSTMT)) { |
2501 | 0 | struct lysc_node *data; |
2502 | 0 | struct lysc_node_action *rpc; |
2503 | 0 | struct lysc_node_notif *notif; |
2504 | |
|
2505 | 0 | LY_LIST_FOR(modc->data, data) { |
2506 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2507 | 0 | yprc_node(pctx, data); |
2508 | 0 | } |
2509 | |
|
2510 | 0 | YPR_EXTRA_LINE(modc->data, pctx); |
2511 | |
|
2512 | 0 | LY_LIST_FOR(modc->rpcs, rpc) { |
2513 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2514 | 0 | yprc_action(pctx, rpc); |
2515 | 0 | } |
2516 | |
|
2517 | 0 | YPR_EXTRA_LINE(modc->rpcs, pctx); |
2518 | |
|
2519 | 0 | LY_LIST_FOR(modc->notifs, notif) { |
2520 | 0 | YPR_EXTRA_LINE_PRINT(pctx); |
2521 | 0 | yprc_notification(pctx, notif); |
2522 | 0 | } |
2523 | |
|
2524 | 0 | YPR_EXTRA_LINE(modc->notifs, pctx); |
2525 | 0 | } |
2526 | |
|
2527 | 0 | LEVEL--; |
2528 | 0 | ly_print_(out, "%*s}\n", INDENT); |
2529 | 0 | ly_print_flush(out); |
2530 | |
|
2531 | 0 | return LY_SUCCESS; |
2532 | 0 | } |
2533 | | |
2534 | | LIBYANG_API_DEF void |
2535 | | lyplg_ext_print_info_extension_instance(struct lyspr_ctx *ctx, const struct lysc_ext_instance *ext, ly_bool *flag) |
2536 | 0 | { |
2537 | 0 | struct lys_ypr_ctx *pctx = (struct lys_ypr_ctx *)ctx; |
2538 | 0 | LY_ARRAY_COUNT_TYPE u, v; |
2539 | 0 | ly_bool data_printed = 0; |
2540 | |
|
2541 | 0 | LY_ARRAY_FOR(ext->substmts, u) { |
2542 | 0 | switch (ext->substmts[u].stmt) { |
2543 | 0 | case LY_STMT_NOTIFICATION: |
2544 | 0 | case LY_STMT_INPUT: |
2545 | 0 | case LY_STMT_OUTPUT: |
2546 | 0 | case LY_STMT_ACTION: |
2547 | 0 | case LY_STMT_RPC: |
2548 | 0 | case LY_STMT_ANYDATA: |
2549 | 0 | case LY_STMT_ANYXML: |
2550 | 0 | case LY_STMT_CASE: |
2551 | 0 | case LY_STMT_CHOICE: |
2552 | 0 | case LY_STMT_CONTAINER: |
2553 | 0 | case LY_STMT_LEAF: |
2554 | 0 | case LY_STMT_LEAF_LIST: |
2555 | 0 | case LY_STMT_LIST: |
2556 | 0 | case LY_STMT_USES: { |
2557 | 0 | const struct lysc_node *node; |
2558 | |
|
2559 | 0 | if (data_printed) { |
2560 | 0 | break; |
2561 | 0 | } |
2562 | | |
2563 | 0 | LY_LIST_FOR(*ext->substmts[u].storage_p, node) { |
2564 | 0 | ypr_open(pctx->out, flag); |
2565 | 0 | if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) { |
2566 | 0 | yprc_notification(pctx, (struct lysc_node_notif *)node); |
2567 | 0 | } else if (ext->substmts[u].stmt & (LY_STMT_INPUT | LY_STMT_OUTPUT)) { |
2568 | 0 | yprc_inout(pctx, (struct lysc_node_action_inout *)node, flag); |
2569 | 0 | } else if (ext->substmts[u].stmt & (LY_STMT_ACTION | LY_STMT_RPC)) { |
2570 | 0 | yprc_action(pctx, (struct lysc_node_action *)node); |
2571 | 0 | } else { |
2572 | 0 | yprc_node(pctx, node); |
2573 | 0 | } |
2574 | 0 | } |
2575 | | |
2576 | | /* all data nodes are stored in a linked list so all were printed */ |
2577 | 0 | data_printed = 1; |
2578 | 0 | break; |
2579 | 0 | } |
2580 | 0 | case LY_STMT_ARGUMENT: |
2581 | 0 | case LY_STMT_CONTACT: |
2582 | 0 | case LY_STMT_DESCRIPTION: |
2583 | 0 | case LY_STMT_ERROR_APP_TAG: |
2584 | 0 | case LY_STMT_ERROR_MESSAGE: |
2585 | 0 | case LY_STMT_KEY: |
2586 | 0 | case LY_STMT_MODIFIER: |
2587 | 0 | case LY_STMT_NAMESPACE: |
2588 | 0 | case LY_STMT_ORGANIZATION: |
2589 | 0 | case LY_STMT_PRESENCE: |
2590 | 0 | case LY_STMT_REFERENCE: |
2591 | 0 | case LY_STMT_UNITS: |
2592 | 0 | if (*ext->substmts[u].storage_p) { |
2593 | 0 | ypr_open(pctx->out, flag); |
2594 | 0 | ypr_substmt(pctx, ext->substmts[u].stmt, 0, *ext->substmts[u].storage_p, 0, ext->exts); |
2595 | 0 | } |
2596 | 0 | break; |
2597 | 0 | case LY_STMT_BIT: |
2598 | 0 | case LY_STMT_ENUM: { |
2599 | 0 | const struct lysc_type_bitenum_item *items = *ext->substmts[u].storage_p; |
2600 | |
|
2601 | 0 | yprc_bits_enum(pctx, items, ext->substmts[u].stmt == LY_STMT_BIT ? LY_TYPE_BITS : LY_TYPE_ENUM, flag); |
2602 | 0 | break; |
2603 | 0 | } |
2604 | 0 | case LY_STMT_CONFIG: |
2605 | 0 | ypr_config(pctx, *(uint16_t *)ext->substmts[u].storage_p, ext->exts, flag); |
2606 | 0 | break; |
2607 | 0 | case LY_STMT_EXTENSION_INSTANCE: |
2608 | 0 | yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, *ext->substmts[u].storage_p, flag); |
2609 | 0 | break; |
2610 | 0 | case LY_STMT_FRACTION_DIGITS: |
2611 | 0 | if (*ext->substmts[u].storage_p) { |
2612 | 0 | ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts, |
2613 | 0 | (long unsigned int)*ext->substmts[u].storage_p, flag); |
2614 | 0 | } |
2615 | 0 | break; |
2616 | 0 | case LY_STMT_IDENTITY: { |
2617 | 0 | const struct lysc_ident *idents = *ext->substmts[u].storage_p; |
2618 | |
|
2619 | 0 | LY_ARRAY_FOR(idents, v) { |
2620 | 0 | yprc_identity(pctx, &idents[v]); |
2621 | 0 | } |
2622 | 0 | break; |
2623 | 0 | } |
2624 | 0 | case LY_STMT_LENGTH: |
2625 | 0 | if (*ext->substmts[u].storage_p) { |
2626 | 0 | yprc_range(pctx, *ext->substmts[u].storage_p, LY_TYPE_STRING, flag); |
2627 | 0 | } |
2628 | 0 | break; |
2629 | 0 | case LY_STMT_MANDATORY: |
2630 | 0 | ypr_mandatory(pctx, *(uint16_t *)ext->substmts[u].storage_p, ext->exts, flag); |
2631 | 0 | break; |
2632 | 0 | case LY_STMT_MAX_ELEMENTS: { |
2633 | 0 | uint32_t max = *(uint32_t *)ext->substmts[u].storage_p; |
2634 | |
|
2635 | 0 | if (max) { |
2636 | 0 | ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, ext->exts, max, flag); |
2637 | 0 | } else { |
2638 | 0 | ypr_open(pctx->out, flag); |
2639 | 0 | ypr_substmt(pctx, LY_STMT_MAX_ELEMENTS, 0, "unbounded", 0, ext->exts); |
2640 | 0 | } |
2641 | 0 | break; |
2642 | 0 | } |
2643 | 0 | case LY_STMT_MIN_ELEMENTS: |
2644 | 0 | ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)ext->substmts[u].storage_p, flag); |
2645 | 0 | break; |
2646 | 0 | case LY_STMT_ORDERED_BY: |
2647 | 0 | ypr_open(pctx->out, flag); |
2648 | 0 | ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0, |
2649 | 0 | ((*(uint16_t *)ext->substmts[u].storage_p) & LYS_ORDBY_USER) ? "user" : "system", 0, ext->exts); |
2650 | 0 | break; |
2651 | 0 | case LY_STMT_MUST: { |
2652 | 0 | const struct lysc_must *musts = *ext->substmts[u].storage_p; |
2653 | |
|
2654 | 0 | LY_ARRAY_FOR(musts, v) { |
2655 | 0 | yprc_must(pctx, &musts[v], flag); |
2656 | 0 | } |
2657 | 0 | break; |
2658 | 0 | } |
2659 | 0 | case LY_STMT_PATTERN: { |
2660 | 0 | const struct lysc_pattern *patterns = *ext->substmts[u].storage_p; |
2661 | |
|
2662 | 0 | LY_ARRAY_FOR(patterns, v) { |
2663 | 0 | yprc_pattern(pctx, &patterns[v], flag); |
2664 | 0 | } |
2665 | 0 | break; |
2666 | 0 | } |
2667 | 0 | case LY_STMT_POSITION: |
2668 | 0 | if (*ext->substmts[u].storage_p) { |
2669 | 0 | ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage_p, flag); |
2670 | 0 | } |
2671 | 0 | break; |
2672 | 0 | case LY_STMT_VALUE: |
2673 | 0 | if (*ext->substmts[u].storage_p) { |
2674 | 0 | ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage_p, flag); |
2675 | 0 | } |
2676 | 0 | break; |
2677 | 0 | case LY_STMT_RANGE: |
2678 | 0 | if (*ext->substmts[u].storage_p) { |
2679 | 0 | yprc_range(pctx, *ext->substmts[u].storage_p, LY_TYPE_UINT64, flag); |
2680 | 0 | } |
2681 | 0 | break; |
2682 | 0 | case LY_STMT_REQUIRE_INSTANCE: |
2683 | 0 | ypr_open(pctx->out, flag); |
2684 | 0 | ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)ext->substmts[u].storage_p ? "true" : "false", |
2685 | 0 | 0, ext->exts); |
2686 | 0 | break; |
2687 | 0 | case LY_STMT_STATUS: |
2688 | 0 | ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage_p, ext->exts, flag); |
2689 | 0 | break; |
2690 | 0 | case LY_STMT_TYPE: |
2691 | 0 | if (*ext->substmts[u].storage_p) { |
2692 | 0 | ypr_open(pctx->out, flag); |
2693 | 0 | yprc_type(pctx, *ext->substmts[u].storage_p); |
2694 | 0 | } |
2695 | 0 | break; |
2696 | 0 | case LY_STMT_WHEN: |
2697 | 0 | yprc_when(pctx, *ext->substmts[u].storage_p, flag); |
2698 | 0 | break; |
2699 | 0 | case LY_STMT_AUGMENT: |
2700 | 0 | case LY_STMT_BASE: |
2701 | 0 | case LY_STMT_BELONGS_TO: |
2702 | 0 | case LY_STMT_DEFAULT: |
2703 | 0 | case LY_STMT_DEVIATE: |
2704 | 0 | case LY_STMT_DEVIATION: |
2705 | 0 | case LY_STMT_EXTENSION: |
2706 | 0 | case LY_STMT_FEATURE: |
2707 | 0 | case LY_STMT_GROUPING: |
2708 | 0 | case LY_STMT_IF_FEATURE: |
2709 | 0 | case LY_STMT_IMPORT: |
2710 | 0 | case LY_STMT_INCLUDE: |
2711 | 0 | case LY_STMT_MODULE: |
2712 | 0 | case LY_STMT_PATH: |
2713 | 0 | case LY_STMT_PREFIX: |
2714 | 0 | case LY_STMT_REFINE: |
2715 | 0 | case LY_STMT_REVISION: |
2716 | 0 | case LY_STMT_REVISION_DATE: |
2717 | 0 | case LY_STMT_SUBMODULE: |
2718 | 0 | case LY_STMT_TYPEDEF: |
2719 | 0 | case LY_STMT_UNIQUE: |
2720 | 0 | case LY_STMT_YANG_VERSION: |
2721 | 0 | case LY_STMT_YIN_ELEMENT: |
2722 | | /* nothing to do */ |
2723 | 0 | break; |
2724 | 0 | default: |
2725 | 0 | LOGINT(pctx->module->ctx); |
2726 | 0 | break; |
2727 | 0 | } |
2728 | 0 | } |
2729 | 0 | } |