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