blob: 68daec6543453a3aa15f1a7b6cf7f2e0cb05daee [file] [log] [blame]
Radek Krejcida04f4a2015-05-21 12:54:09 +02001/**
Radek Krejciefdd0ce2015-05-26 16:48:29 +02002 * @file printer/yang.c
Radek Krejcida04f4a2015-05-21 12:54:09 +02003 * @author Radek Krejci <rkrejci@cesnet.cz>
Radek Krejciefdd0ce2015-05-26 16:48:29 +02004 * @brief YANG printer for libyang data model structure
Radek Krejcida04f4a2015-05-21 12:54:09 +02005 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of the Company nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 */
21
22#include <stdlib.h>
23#include <stdio.h>
24#include <string.h>
25
Radek Krejciefdd0ce2015-05-26 16:48:29 +020026#include "../common.h"
27#include "../tree.h"
Radek Krejcida04f4a2015-05-21 12:54:09 +020028
29#define INDENT ""
30#define LEVEL (level*2)
31
Michal Vasko5bbae102015-06-16 12:16:44 +020032static void yang_print_mnode(FILE *f, int level, struct ly_mnode *mnode, int mask);
Radek Krejcida04f4a2015-05-21 12:54:09 +020033
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020034static void
Michal Vasko5bbae102015-06-16 12:16:44 +020035yang_print_text(FILE *f, int level, const char *name, const char *text)
Radek Krejcida04f4a2015-05-21 12:54:09 +020036{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020037 const char *s, *t;
Radek Krejcida04f4a2015-05-21 12:54:09 +020038
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020039 fprintf(f, "%*s%s\n", LEVEL, INDENT, name);
40 level++;
Radek Krejcida04f4a2015-05-21 12:54:09 +020041
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020042 fprintf(f, "%*s\"", LEVEL, INDENT);
43 t = text;
44 while ((s = strchr(t, '\n'))) {
Michal Vasko5bbae102015-06-16 12:16:44 +020045 fwrite(t, sizeof *t, (s - t) + 1, f);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020046 t = s + 1;
47 fprintf(f, "%*s", LEVEL, INDENT);
48 }
Radek Krejcida04f4a2015-05-21 12:54:09 +020049
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020050 fprintf(f, "%s\";\n\n", t);
51 level--;
Radek Krejcida04f4a2015-05-21 12:54:09 +020052
53}
54
Radek Krejci6e4ffbb2015-06-16 10:34:41 +020055static void
Radek Krejci6a113852015-07-03 16:04:20 +020056yang_print_nacmext(FILE *f, int level, struct ly_mnode *mnode)
Radek Krejcida04f4a2015-05-21 12:54:09 +020057{
Radek Krejci6764bb32015-07-03 15:16:04 +020058 int i, j;
Radek Krejci86909d22015-07-03 16:11:25 +020059 const char *prefix = NULL;
Radek Krejci6764bb32015-07-03 15:16:04 +020060
61 if (mnode->nacm && (!mnode->parent || mnode->parent->nacm != mnode->nacm)) {
62 /* locate ietf-netconf-acm module in imports */
63 if (!strcmp(mnode->module->name, "ietf-netconf-acm")) {
64 prefix = mnode->module->prefix;
65 } else {
66 /* search in imports */
67 for (i = 0; i < mnode->module->imp_size; i++) {
68 if (!strcmp(mnode->module->imp[i].module->name, "ietf-netconf-acm")) {
69 prefix = mnode->module->imp[i].prefix;
70 break;
71 }
72 }
73 /* and in imports of includes */
74 if (!prefix) {
75 for (j = 0; j < mnode->module->inc_size; j++) {
76 for (i = 0; i < mnode->module->inc[j].submodule->imp_size; i++) {
77 if (!strcmp(mnode->module->inc[j].submodule->imp[i].module->name, "ietf-netconf-acm")) {
78 prefix = mnode->module->inc[j].submodule->imp[i].prefix;
79 break;
80 }
81 }
82 }
83 }
84 }
85
86 if ((mnode->nacm & LY_NACM_DENYW) && (!mnode->parent || !(mnode->parent->nacm & LY_NACM_DENYW))) {
87 fprintf(f, "%*s%s:default-deny-write;\n", LEVEL, INDENT, prefix);
88 }
89 if ((mnode->nacm & LY_NACM_DENYA) && (!mnode->parent || !(mnode->parent->nacm & LY_NACM_DENYA))) {
90 fprintf(f, "%*s%s:default-deny-all;\n", LEVEL, INDENT, prefix);
91 }
92 }
Radek Krejci6a113852015-07-03 16:04:20 +020093}
94
95/*
96 * Covers:
97 * description, reference, status
98 */
99static void
100yang_print_mnode_common(FILE *f, int level, struct ly_mnode *mnode)
101{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200102 if (mnode->flags & LY_NODE_STATUS_CURR) {
103 fprintf(f, "%*sstatus \"current\";\n", LEVEL, INDENT);
104 } else if (mnode->flags & LY_NODE_STATUS_DEPRC) {
105 fprintf(f, "%*sstatus \"deprecated\";\n", LEVEL, INDENT);
106 } else if (mnode->flags & LY_NODE_STATUS_OBSLT) {
107 fprintf(f, "%*sstatus \"obsolete\";\n", LEVEL, INDENT);
108 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200109
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200110 if (mnode->dsc) {
111 yang_print_text(f, level, "description", mnode->dsc);
112 }
113 if (mnode->ref) {
114 yang_print_text(f, level, "reference", mnode->ref);
115 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200116}
117
118/*
119 * Covers:
Michal Vasko2b8faed2015-06-09 12:51:20 +0200120 * config, mandatory
Radek Krejcida04f4a2015-05-21 12:54:09 +0200121 * description, reference, status
122 */
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200123static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200124yang_print_mnode_common2(FILE *f, int level, struct ly_mnode *mnode)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200125{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200126 if (!mnode->parent || (mnode->parent->flags & LY_NODE_CONFIG_MASK) != (mnode->flags & LY_NODE_CONFIG_MASK)) {
127 /* print config only when it differs from the parent or in root */
128 if (mnode->flags & LY_NODE_CONFIG_W) {
129 fprintf(f, "%*sconfig \"true\";\n", LEVEL, INDENT);
130 } else if (mnode->flags & LY_NODE_CONFIG_R) {
131 fprintf(f, "%*sconfig \"false\";\n", LEVEL, INDENT);
132 }
133 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200134
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200135 if (mnode->flags & LY_NODE_MAND_TRUE) {
136 fprintf(f, "%*smandatory \"true\";\n", LEVEL, INDENT);
137 } else if (mnode->flags & LY_NODE_MAND_FALSE) {
138 fprintf(f, "%*smandatory \"false\";\n", LEVEL, INDENT);
139 }
Michal Vasko2b8faed2015-06-09 12:51:20 +0200140
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200141 yang_print_mnode_common(f, level, mnode);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200142}
143
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200144static void
Radek Krejci0bd5db42015-06-19 13:30:07 +0200145yang_print_restr(FILE *f, int level, struct ly_restr *restr)
Radek Krejci41726f92015-06-19 13:11:05 +0200146{
Radek Krejci0bd5db42015-06-19 13:30:07 +0200147 if (restr->dsc != NULL) {
148 yang_print_text(f, level, "description", restr->dsc);
Radek Krejci41726f92015-06-19 13:11:05 +0200149 }
Radek Krejci0bd5db42015-06-19 13:30:07 +0200150 if (restr->ref != NULL) {
151 yang_print_text(f, level, "reference", restr->ref);
Radek Krejci41726f92015-06-19 13:11:05 +0200152 }
Radek Krejci0bd5db42015-06-19 13:30:07 +0200153 if (restr->eapptag != NULL) {
154 fprintf(f, "%*serror-app-tag \"%s\";\n", LEVEL, INDENT, restr->eapptag);
Radek Krejci41726f92015-06-19 13:11:05 +0200155 }
Radek Krejci0bd5db42015-06-19 13:30:07 +0200156 if (restr->emsg != NULL) {
157 yang_print_text(f, level, "error-message", restr->emsg);
Radek Krejci41726f92015-06-19 13:11:05 +0200158 }
159}
160
161static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200162yang_print_type(FILE *f, int level, struct ly_module *module, struct ly_type *type)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200163{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200164 int i;
Radek Krejci25d782a2015-05-22 15:03:23 +0200165
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200166 if (type->prefix) {
167 fprintf(f, "%*stype %s:%s {\n", LEVEL, INDENT, type->prefix, type->der->name);
168 } else {
169 fprintf(f, "%*stype %s {\n", LEVEL, INDENT, type->der->name);
170 }
171 level++;
172 switch (type->base) {
173 case LY_TYPE_BINARY:
174 if (type->info.binary.length != NULL) {
Radek Krejci41726f92015-06-19 13:11:05 +0200175 fprintf(f, "%*slength \"%s\" {\n", LEVEL, INDENT, type->info.binary.length->expr);
Radek Krejci0bd5db42015-06-19 13:30:07 +0200176 yang_print_restr(f, level + 1, type->info.binary.length);
Radek Krejci41726f92015-06-19 13:11:05 +0200177 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200178 }
179 break;
180 case LY_TYPE_BITS:
181 for (i = 0; i < type->info.bits.count; ++i) {
Radek Krejci994b6f62015-06-18 16:47:27 +0200182 fprintf(f, "%*sbit %s {\n", LEVEL, INDENT, type->info.bits.bit[i].name);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200183 level++;
184 yang_print_mnode_common(f, level, (struct ly_mnode *)&type->info.bits.bit[i]);
185 fprintf(f, "%*sposition %u;\n", LEVEL, INDENT, type->info.bits.bit[i].pos);
186 level--;
187 fprintf(f, "%*s}\n", LEVEL, INDENT);
188 }
189 break;
190 case LY_TYPE_DEC64:
191 fprintf(f, "%*sfraction-digits %d;\n", LEVEL, INDENT, type->info.dec64.dig);
192 /* TODO range incomplete */
193 break;
194 case LY_TYPE_ENUM:
195 for (i = 0; i < type->info.enums.count; i++) {
196 fprintf(f, "%*senum %s {\n", LEVEL, INDENT, type->info.enums.list[i].name);
197 level++;
198 yang_print_mnode_common(f, level, (struct ly_mnode *)&type->info.enums.list[i]);
199 fprintf(f, "%*svalue %d;\n", LEVEL, INDENT, type->info.enums.list[i].value);
200 level--;
201 fprintf(f, "%*s}\n", LEVEL, INDENT);
202 }
203 break;
204 case LY_TYPE_IDENT:
205 if (module == type->info.ident.ref->module) {
206 fprintf(f, "%*sbase %s;\n", LEVEL, INDENT, type->info.ident.ref->name);
207 } else {
208 fprintf(f, "%*sbase %s:%s;\n", LEVEL, INDENT, type->info.ident.ref->module->prefix,
209 type->info.ident.ref->name);
210 }
211 break;
212 case LY_TYPE_INST:
Radek Krejciaf351422015-06-19 14:49:38 +0200213 if (type->info.inst.req == 1) {
214 fprintf(f, "%*srequire-instance \"true\";\n", LEVEL, INDENT);
215 } else if (type->info.inst.req == -1) {
216 fprintf(f, "%*srequire-instance \"false\";\n", LEVEL, INDENT);
217 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200218 break;
219 case LY_TYPE_INT8:
220 case LY_TYPE_INT16:
221 case LY_TYPE_INT32:
222 case LY_TYPE_INT64:
223 case LY_TYPE_UINT8:
224 case LY_TYPE_UINT16:
225 case LY_TYPE_UINT32:
226 case LY_TYPE_UINT64:
Radek Krejcif2860132015-06-20 12:37:20 +0200227 if (type->info.num.range != NULL) {
228 fprintf(f, "%*srange \"%s\" {\n", LEVEL, INDENT, type->info.num.range->expr);
229 yang_print_restr(f, level + 1, type->info.num.range);
230 fprintf(f, "%*s}\n", LEVEL, INDENT);
231 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200232 break;
233 case LY_TYPE_LEAFREF:
234 fprintf(f, "%*spath \"%s\";\n", LEVEL, INDENT, type->info.lref.path);
235 break;
236 case LY_TYPE_STRING:
Radek Krejci5fbc9162015-06-19 14:11:11 +0200237 if (type->info.str.length) {
Radek Krejci061bd522015-06-19 13:45:16 +0200238 fprintf(f, "%*slength \"%s\" {\n", LEVEL, INDENT, type->info.str.length->expr);
239 yang_print_restr(f, level + 1, type->info.str.length);
240 fprintf(f, "%*s}\n", LEVEL, INDENT);
241 }
Radek Krejci5fbc9162015-06-19 14:11:11 +0200242 for (i = 0; i < type->info.str.pat_count; i++) {
243 fprintf(f, "%*spattern \"%s\" {\n", LEVEL, INDENT, type->info.str.patterns[i].expr);
244 yang_print_restr(f, level + 1, &type->info.str.patterns[i]);
245 fprintf(f, "%*s}\n", LEVEL, INDENT);
246 }
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200247 break;
248 case LY_TYPE_UNION:
249 for (i = 0; i < type->info.uni.count; ++i) {
250 yang_print_type(f, level, module, &type->info.uni.type[i]);
251 }
252 break;
253 default:
254 /* other types do not have substatements */
255 break;
256 }
257 level--;
258 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200259}
260
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200261static void
Radek Krejci0bd5db42015-06-19 13:30:07 +0200262yang_print_must(FILE *f, int level, struct ly_restr *must)
Michal Vasko7f976ee2015-06-09 13:55:41 +0200263{
Radek Krejci0bd5db42015-06-19 13:30:07 +0200264 fprintf(f, "%*smust \"%s\" {\n", LEVEL, INDENT, must->expr);
Radek Krejci41726f92015-06-19 13:11:05 +0200265 yang_print_restr(f, level + 1, must);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200266 fprintf(f, "%*s}\n", LEVEL, INDENT);
Michal Vasko7f976ee2015-06-09 13:55:41 +0200267}
268
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200269static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200270yang_print_refine(FILE *f, int level, struct ly_refine *refine)
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200271{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200272 int i;
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200273
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200274 fprintf(f, "%*srefine \"%s\" {\n", LEVEL, INDENT, refine->target);
275 level++;
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200276
Radek Krejci6a113852015-07-03 16:04:20 +0200277 if (refine->flags & LY_NODE_CONFIG_W) {
278 fprintf(f, "%*sconfig \"true\";\n", LEVEL, INDENT);
279 } else if (refine->flags & LY_NODE_CONFIG_R) {
280 fprintf(f, "%*sconfig \"false\";\n", LEVEL, INDENT);
281 }
282
283 if (refine->flags & LY_NODE_MAND_TRUE) {
284 fprintf(f, "%*smandatory \"true\";\n", LEVEL, INDENT);
285 } else if (refine->flags & LY_NODE_MAND_FALSE) {
286 fprintf(f, "%*smandatory \"false\";\n", LEVEL, INDENT);
287 }
288
289 yang_print_mnode_common(f, level, (struct ly_mnode *)refine);
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200290
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200291 for (i = 0; i < refine->must_size; ++i) {
292 yang_print_must(f, level, &refine->must[i]);
293 }
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200294
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200295 if (refine->target_type & (LY_NODE_LEAF | LY_NODE_CHOICE)) {
296 if (refine->mod.dflt != NULL) {
297 fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, refine->mod.dflt);
298 }
299 } else if (refine->target_type == LY_NODE_CONTAINER) {
300 if (refine->mod.presence != NULL) {
301 yang_print_text(f, level, "presence", refine->mod.presence);
302 }
303 } else if (refine->target_type & (LY_NODE_LIST | LY_NODE_LEAFLIST)) {
304 if (refine->mod.list.min > 0) {
305 fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, refine->mod.list.min);
306 }
307 if (refine->mod.list.max > 0) {
308 fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, refine->mod.list.max);
309 }
310 }
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200311
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200312 level--;
313 fprintf(f, "%*s}\n", LEVEL, INDENT);
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200314}
315
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200316static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200317yang_print_typedef(FILE *f, int level, struct ly_module *module, struct ly_tpdf *tpdf)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200318{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200319 fprintf(f, "%*stypedef %s {\n", LEVEL, INDENT, tpdf->name);
320 level++;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200321
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200322 yang_print_mnode_common(f, level, (struct ly_mnode *)tpdf);
323 yang_print_type(f, level, module, &tpdf->type);
324 if (tpdf->units != NULL) {
325 fprintf(f, "%*sunits \"%s\";\n", LEVEL, INDENT, tpdf->units);
326 }
327 if (tpdf->dflt != NULL) {
328 fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, tpdf->dflt);
329 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200330
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200331 level--;
332 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200333}
334
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200335static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200336yang_print_identity(FILE *f, int level, struct ly_ident *ident)
Radek Krejci6793db02015-05-22 17:49:54 +0200337{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200338 fprintf(f, "%*sidentity %s {\n", LEVEL, INDENT, ident->name);
339 level++;
Radek Krejci6793db02015-05-22 17:49:54 +0200340
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200341 yang_print_mnode_common(f, level, (struct ly_mnode *)ident);
342 if (ident->base) {
343 if (ident->base->module == ident->module) {
344 fprintf(f, "%*sbase %s;\n", LEVEL, INDENT, ident->base->name);
345 } else {
346 fprintf(f, "%*sbase %s:%s;\n", LEVEL, INDENT, ident->base->module->prefix, ident->base->name);
347 }
348 }
Radek Krejci6793db02015-05-22 17:49:54 +0200349
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200350 level--;
351 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejci6793db02015-05-22 17:49:54 +0200352
353}
354
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200355static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200356yang_print_container(FILE *f, int level, struct ly_mnode *mnode)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200357{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200358 int i;
359 struct ly_mnode *sub;
360 struct ly_mnode_container *cont = (struct ly_mnode_container *)mnode;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200361
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200362 fprintf(f, "%*scontainer %s {\n", LEVEL, INDENT, mnode->name);
Michal Vasko7f976ee2015-06-09 13:55:41 +0200363
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200364 level++;
Radek Krejci6a113852015-07-03 16:04:20 +0200365
366 yang_print_nacmext(f, level, mnode);
367
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200368 if (cont->presence != NULL) {
369 yang_print_text(f, level, "presence", cont->presence);
370 }
Michal Vasko7f976ee2015-06-09 13:55:41 +0200371
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200372 for (i = 0; i < cont->must_size; i++) {
373 yang_print_must(f, level, &cont->must[i]);
374 }
Michal Vasko7f976ee2015-06-09 13:55:41 +0200375
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200376 yang_print_mnode_common2(f, level, mnode);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200377
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200378 for (i = 0; i < cont->tpdf_size; i++) {
379 yang_print_typedef(f, level, mnode->module, &cont->tpdf[i]);
380 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200381
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200382 LY_TREE_FOR(mnode->child, sub) {
383 yang_print_mnode(f, level, sub,
384 LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
385 LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML);
386 }
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200387
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200388 level--;
389 fprintf(f, "%*s}\n", LEVEL, INDENT);
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200390}
391
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200392static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200393yang_print_case(FILE *f, int level, struct ly_mnode *mnode)
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200394{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200395 struct ly_mnode *sub;
396 struct ly_mnode_case *cas = (struct ly_mnode_case *)mnode;
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200397
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200398 fprintf(f, "%*scase %s {\n", LEVEL, INDENT, cas->name);
399 level++;
Radek Krejci6a113852015-07-03 16:04:20 +0200400 yang_print_nacmext(f, level, mnode);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200401 yang_print_mnode_common2(f, level, mnode);
Michal Vaskoc1329bc2015-06-09 13:58:18 +0200402
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200403 LY_TREE_FOR(mnode->child, sub) {
404 yang_print_mnode(f, level, sub,
405 LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
406 LY_NODE_USES | LY_NODE_ANYXML);
407 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200408
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200409 level--;
410 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200411}
412
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200413static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200414yang_print_choice(FILE *f, int level, struct ly_mnode *mnode)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200415{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200416 struct ly_mnode *sub;
417 struct ly_mnode_choice *choice = (struct ly_mnode_choice *)mnode;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200418
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200419 fprintf(f, "%*schoice %s {\n", LEVEL, INDENT, mnode->name);
Michal Vasko16083662015-06-09 14:00:45 +0200420
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200421 level++;
Radek Krejci6a113852015-07-03 16:04:20 +0200422 yang_print_nacmext(f, level, mnode);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200423 if (choice->dflt != NULL) {
424 fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, choice->dflt->name);
425 }
Michal Vasko16083662015-06-09 14:00:45 +0200426
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200427 yang_print_mnode_common2(f, level, mnode);
428 LY_TREE_FOR(mnode->child, sub) {
429 yang_print_mnode(f, level, sub,
430 LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML | LY_NODE_CASE);
431 }
432 level--;
433 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200434}
435
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200436static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200437yang_print_leaf(FILE *f, int level, struct ly_mnode *mnode)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200438{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200439 int i;
440 struct ly_mnode_leaf *leaf = (struct ly_mnode_leaf *)mnode;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200441
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200442 fprintf(f, "%*sleaf %s {\n", LEVEL, INDENT, mnode->name);
Michal Vasko16083662015-06-09 14:00:45 +0200443
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200444 level++;
Radek Krejci6a113852015-07-03 16:04:20 +0200445 yang_print_nacmext(f, level, mnode);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200446 yang_print_mnode_common2(f, level, mnode);
447 for (i = 0; i < leaf->must_size; i++) {
448 yang_print_must(f, level, &leaf->must[i]);
449 }
450 yang_print_type(f, level, mnode->module, &leaf->type);
451 if (leaf->units != NULL) {
452 fprintf(f, "%*sunits \"%s\";\n", LEVEL, INDENT, leaf->units);
453 }
454 if (leaf->dflt != NULL) {
455 fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, leaf->dflt);
456 }
457 level--;
Michal Vasko16083662015-06-09 14:00:45 +0200458
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200459 fprintf(f, "%*s}\n", LEVEL, INDENT);
Michal Vasko16083662015-06-09 14:00:45 +0200460}
461
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200462static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200463yang_print_anyxml(FILE *f, int level, struct ly_mnode *mnode)
Michal Vasko16083662015-06-09 14:00:45 +0200464{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200465 int i;
466 struct ly_mnode_anyxml *anyxml = (struct ly_mnode_anyxml *)mnode;
Michal Vasko16083662015-06-09 14:00:45 +0200467
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200468 fprintf(f, "%*sanyxml %s {\n", LEVEL, INDENT, anyxml->name);
469 level++;
Radek Krejci6a113852015-07-03 16:04:20 +0200470 yang_print_nacmext(f, level, mnode);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200471 yang_print_mnode_common2(f, level, mnode);
472 for (i = 0; i < anyxml->must_size; i++) {
473 yang_print_must(f, level, &anyxml->must[i]);
474 }
475 level--;
476 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200477}
478
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200479static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200480yang_print_leaflist(FILE *f, int level, struct ly_mnode *mnode)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200481{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200482 int i;
483 struct ly_mnode_leaflist *llist = (struct ly_mnode_leaflist *)mnode;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200484
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200485 fprintf(f, "%*sleaf-list %s {\n", LEVEL, INDENT, mnode->name);
Michal Vasko16083662015-06-09 14:00:45 +0200486
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200487 level++;
Radek Krejci6a113852015-07-03 16:04:20 +0200488 yang_print_nacmext(f, level, mnode);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200489 yang_print_mnode_common2(f, level, mnode);
490 if (llist->flags & LY_NODE_USERORDERED) {
491 fprintf(f, "%*sordered-by user;\n", LEVEL, INDENT);
492 }
493 if (llist->min > 0) {
494 fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, llist->min);
495 }
496 if (llist->max > 0) {
497 fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, llist->max);
498 }
499 for (i = 0; i < llist->must_size; i++) {
500 yang_print_must(f, level, &llist->must[i]);
501 }
502 yang_print_type(f, level, mnode->module, &llist->type);
503 if (llist->units != NULL) {
504 fprintf(f, "%*sunits \"%s\";\n", LEVEL, INDENT, llist->units);
505 }
506 level--;
Michal Vasko16083662015-06-09 14:00:45 +0200507
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200508 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200509}
510
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200511static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200512yang_print_list(FILE *f, int level, struct ly_mnode *mnode)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200513{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200514 int i, j;
515 struct ly_mnode *sub;
516 struct ly_unique *uniq;
517 struct ly_mnode_list *list = (struct ly_mnode_list *)mnode;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200518
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200519 fprintf(f, "%*slist %s {\n", LEVEL, INDENT, mnode->name);
520 level++;
Radek Krejci6a113852015-07-03 16:04:20 +0200521 yang_print_nacmext(f, level, mnode);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200522 yang_print_mnode_common2(f, level, mnode);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200523
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200524 if (list->keys_size) {
525 fprintf(f, "%*skey \"", LEVEL, INDENT);
526 for (i = 0; i < list->keys_size; i++) {
527 fprintf(f, "%s%s", list->keys[i]->name, i + 1 < list->keys_size ? " " : "");
528 }
529 fprintf(f, "\";\n");
530 }
Radek Krejcid7f0d012015-05-25 15:04:52 +0200531
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200532 for (i = 0; i < list->unique_size; i++) {
533 uniq = &list->unique[i];
534 fprintf(f, "%*sunique \"", LEVEL, INDENT);
535 for (j = 0; j < uniq->leafs_size; j++) {
536 fprintf(f, "%s%s", uniq->leafs[j]->name, j + 1 < uniq->leafs_size ? " " : "");
537 }
538 fprintf(f, "\";\n");
539 }
Michal Vaskodff818b2015-06-09 14:01:12 +0200540
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200541 if (list->flags & LY_NODE_USERORDERED) {
542 fprintf(f, "%*sordered-by user;\n", LEVEL, INDENT);
543 }
544 if (list->min > 0) {
545 fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, list->min);
546 }
547 if (list->max > 0) {
548 fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, list->max);
549 }
550 for (i = 0; i < list->must_size; i++) {
551 yang_print_must(f, level, &list->must[i]);
552 }
Michal Vaskodff818b2015-06-09 14:01:12 +0200553
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200554 for (i = 0; i < list->tpdf_size; i++) {
555 yang_print_typedef(f, level, list->module, &list->tpdf[i]);
556 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200557
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200558 LY_TREE_FOR(mnode->child, sub) {
559 yang_print_mnode(f, level, sub,
560 LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
561 LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML);
562 }
563 level--;
564 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200565}
566
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200567static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200568yang_print_grouping(FILE *f, int level, struct ly_mnode *mnode)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200569{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200570 int i;
571 struct ly_mnode *node;
572 struct ly_mnode_grp *grp = (struct ly_mnode_grp *)mnode;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200573
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200574 fprintf(f, "%*sgrouping %s {\n", LEVEL, INDENT, mnode->name);
575 level++;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200576
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200577 yang_print_mnode_common(f, level, mnode);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200578
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200579 for (i = 0; i < grp->tpdf_size; i++) {
580 yang_print_typedef(f, level, mnode->module, &grp->tpdf[i]);
581 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200582
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200583 LY_TREE_FOR(mnode->child, node) {
584 yang_print_mnode(f, level, node,
585 LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
586 LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML);
587 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200588
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200589 level--;
590 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejcida04f4a2015-05-21 12:54:09 +0200591}
592
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200593static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200594yang_print_uses(FILE *f, int level, struct ly_mnode *mnode)
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200595{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200596 int i;
597 struct ly_mnode_uses *uses = (struct ly_mnode_uses *)mnode;
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200598
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200599 fprintf(f, "%*suses %s {\n", LEVEL, INDENT, uses->name);
600 level++;
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200601
Radek Krejci6a113852015-07-03 16:04:20 +0200602 yang_print_nacmext(f, level, mnode);
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200603 yang_print_mnode_common(f, level, mnode);
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200604
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200605 for (i = 0; i < uses->refine_size; i++) {
606 yang_print_refine(f, level, &uses->refine[i]);
607 }
Michal Vasko00b7cfe2015-06-09 13:56:38 +0200608
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200609 level--;
610 fprintf(f, "%*s}\n", LEVEL, INDENT);
Radek Krejcic7c9a6c2015-05-25 16:35:06 +0200611}
612
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200613static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200614yang_print_input_output(FILE *f, int level, struct ly_mnode *mnode)
615{
Michal Vaskof4d3d742015-06-16 11:51:09 +0200616 int i;
617 struct ly_mnode *sub;
Michal Vaskofb69a842015-06-16 12:07:40 +0200618 struct ly_mnode_input_output *inout = (struct ly_mnode_input_output *)mnode;
Michal Vaskof4d3d742015-06-16 11:51:09 +0200619
620 fprintf(f, "%*s%s {\n", LEVEL, INDENT, (inout->nodetype == LY_NODE_INPUT ? "input" : "output"));
621
622 level++;
623 for (i = 0; i < inout->tpdf_size; i++) {
624 yang_print_typedef(f, level, mnode->module, &inout->tpdf[i]);
625 }
626
627 LY_TREE_FOR(mnode->child, sub) {
628 yang_print_mnode(f, level, sub,
629 LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
630 LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML);
631 }
632
633 level--;
634 fprintf(f, "%*s}\n", LEVEL, INDENT);
635}
636
637static void
638yang_print_rpc(FILE *f, int level, struct ly_mnode *mnode)
639{
640 int i;
641 struct ly_mnode *sub;
642 struct ly_mnode_rpc *rpc = (struct ly_mnode_rpc *)mnode;
643
644 fprintf(f, "%*srpc %s {\n", LEVEL, INDENT, mnode->name);
645
646 level++;
647 yang_print_mnode_common(f, level, mnode);
648
649 for (i = 0; i < rpc->tpdf_size; i++) {
650 yang_print_typedef(f, level, mnode->module, &rpc->tpdf[i]);
651 }
652
653 LY_TREE_FOR(mnode->child, sub) {
654 yang_print_mnode(f, level, sub,
655 LY_NODE_GROUPING | LY_NODE_INPUT | LY_NODE_OUTPUT);
656 }
657
658 level--;
659 fprintf(f, "%*s}\n", LEVEL, INDENT);
660}
661
662static void
Michal Vasko7690bc12015-06-16 12:26:05 +0200663yang_print_notif(FILE *f, int level, struct ly_mnode *mnode)
664{
Michal Vaskof4d3d742015-06-16 11:51:09 +0200665 int i;
666 struct ly_mnode *sub;
667 struct ly_mnode_notif *notif = (struct ly_mnode_notif *)mnode;
668
669 fprintf(f, "%*snotification %s {\n", LEVEL, INDENT, mnode->name);
670
671 level++;
672 yang_print_mnode_common(f, level, mnode);
673
674 for (i = 0; i < notif->tpdf_size; i++) {
675 yang_print_typedef(f, level, mnode->module, &notif->tpdf[i]);
676 }
677
678 LY_TREE_FOR(mnode->child, sub) {
679 yang_print_mnode(f, level, sub,
680 LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
681 LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML);
682 }
683
684 level--;
685 fprintf(f, "%*s}\n", LEVEL, INDENT);
686}
687
688static void
Michal Vasko5bbae102015-06-16 12:16:44 +0200689yang_print_mnode(FILE *f, int level, struct ly_mnode *mnode, int mask)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200690{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200691 switch (mnode->nodetype & mask) {
692 case LY_NODE_CONTAINER:
693 yang_print_container(f, level, mnode);
694 break;
695 case LY_NODE_CHOICE:
696 yang_print_choice(f, level, mnode);
697 break;
698 case LY_NODE_LEAF:
699 yang_print_leaf(f, level, mnode);
700 break;
701 case LY_NODE_LEAFLIST:
702 yang_print_leaflist(f, level, mnode);
703 break;
704 case LY_NODE_LIST:
705 yang_print_list(f, level, mnode);
706 break;
707 case LY_NODE_USES:
708 yang_print_uses(f, level, mnode);
709 break;
710 case LY_NODE_GROUPING:
711 yang_print_grouping(f, level, mnode);
712 break;
713 case LY_NODE_ANYXML:
714 yang_print_anyxml(f, level, mnode);
715 break;
716 case LY_NODE_CASE:
717 yang_print_case(f, level, mnode);
718 break;
Michal Vaskof4d3d742015-06-16 11:51:09 +0200719 case LY_NODE_INPUT:
720 case LY_NODE_OUTPUT:
721 yang_print_input_output(f, level, mnode);
722 break;
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200723 default:
724 break;
725 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200726}
727
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200728int
Michal Vasko5bbae102015-06-16 12:16:44 +0200729yang_print_model(FILE *f, struct ly_module *module)
Radek Krejcida04f4a2015-05-21 12:54:09 +0200730{
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200731 unsigned int i;
732 int level = 0;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200733#define LEVEL (level*2)
734
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200735 struct ly_mnode *mnode;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200736
Michal Vasko116172e2015-07-07 11:54:37 +0200737 if (module->type) {
738 fprintf(f, "submodule %s {\n", module->name);
739 level++;
740 fprintf(f, "%*sbelongs-to %s {\n", LEVEL, INDENT, ((struct ly_submodule *)module)->belongsto->name);
741 level++;
742 fprintf(f, "%*sprefix \"%s\";\n", LEVEL, INDENT, module->prefix);
743 level--;
744 fprintf(f, "%*s}\n", LEVEL, INDENT);
745 } else {
746 fprintf(f, "module %s {\n", module->name);
747 level++;
748 fprintf(f, "%*snamespace \"%s\";\n", LEVEL, INDENT, module->ns);
749 fprintf(f, "%*sprefix \"%s\";\n", LEVEL, INDENT, module->prefix);
750 }
Radek Krejcib0594bf2015-05-21 23:51:27 +0200751
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200752 if (module->version) {
753 fprintf(f, "%*syang-version \"%s\";\n", LEVEL, INDENT, module->version == 1 ? "1.0" : "1.1");
754 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200755
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200756 for (i = 0; i < module->imp_size; i++) {
757 fprintf(f, "%*simport \"%s\" {\n", LEVEL, INDENT, module->imp[i].module->name);
758 level++;
759 yang_print_text(f, level, "prefix", module->imp[i].prefix);
760 if (module->imp[i].rev[0]) {
761 yang_print_text(f, level, "revision-date", module->imp[i].rev);
762 }
763 level--;
764 fprintf(f, "%*s}\n", LEVEL, INDENT);
765 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200766
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200767 for (i = 0; i < module->inc_size; i++) {
768 if (module->inc[i].rev[0]) {
769 fprintf(f, "%*sinclude \"%s\" {\n", LEVEL, INDENT, module->inc[i].submodule->name);
770 yang_print_text(f, level + 1, "revision-date", module->imp[i].rev);
771 fprintf(f, "%*s}\n", LEVEL, INDENT);
772 } else {
773 fprintf(f, "%*sinclude \"%s\";\n", LEVEL, INDENT, module->inc[i].submodule->name);
774 }
775 }
Radek Krejciefaeba32015-05-27 14:30:57 +0200776
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200777 if (module->org) {
778 yang_print_text(f, level, "organization", module->org);
779 }
780 if (module->contact) {
781 yang_print_text(f, level, "contact", module->contact);
782 }
783 if (module->dsc) {
784 yang_print_text(f, level, "description", module->dsc);
785 }
786 if (module->ref) {
787 yang_print_text(f, level, "reference", module->ref);
788 }
789 for (i = 0; i < module->rev_size; i++) {
790 if (module->rev[i].dsc || module->rev[i].ref) {
791 fprintf(f, "%*srevision \"%s\" {\n", LEVEL, INDENT, module->rev[i].date);
792 level++;
793 if (module->rev[i].dsc) {
794 yang_print_text(f, level, "description", module->rev[i].dsc);
795 }
796 if (module->rev[i].ref) {
797 yang_print_text(f, level, "reference", module->rev[i].ref);
798 }
799 level--;
800 fprintf(f, "%*s}\n", LEVEL, INDENT);
801 } else {
802 yang_print_text(f, level, "revision", module->rev[i].date);
803 }
804 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200805
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200806 for (i = 0; i < module->ident_size; i++) {
807 yang_print_identity(f, level, &module->ident[i]);
808 }
Radek Krejci6793db02015-05-22 17:49:54 +0200809
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200810 for (i = 0; i < module->tpdf_size; i++) {
811 yang_print_typedef(f, level, module, &module->tpdf[i]);
812 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200813
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200814 LY_TREE_FOR(module->data, mnode) {
815 yang_print_mnode(f, level, mnode,
816 LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
817 LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML);
818 }
Radek Krejcida04f4a2015-05-21 12:54:09 +0200819
Michal Vaskof4d3d742015-06-16 11:51:09 +0200820 LY_TREE_FOR(module->rpc, mnode) {
821 yang_print_rpc(f, level, mnode);
822 }
823
824 LY_TREE_FOR(module->notif, mnode) {
825 yang_print_notif(f, level, mnode);
826 }
827
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200828 fprintf(f, "}\n");
Radek Krejcida04f4a2015-05-21 12:54:09 +0200829
Radek Krejci6e4ffbb2015-06-16 10:34:41 +0200830 return EXIT_SUCCESS;
Radek Krejcida04f4a2015-05-21 12:54:09 +0200831#undef LEVEL
832}