Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1 | /** |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 2 | * @file printer/yang.c |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 4 | * @brief YANG printer for libyang data model structure |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5 | * |
| 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 Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 26 | #include "../common.h" |
| 27 | #include "../tree.h" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 28 | |
| 29 | #define INDENT "" |
| 30 | #define LEVEL (level*2) |
| 31 | |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 32 | static void yang_print_mnode(FILE *f, int level, struct ly_mnode *mnode, int mask); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 33 | |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 34 | static const char* |
| 35 | get_module_import_prefix(struct ly_module *main_mod, struct ly_module *imp_mod) |
| 36 | { |
| 37 | int i, j; |
| 38 | |
| 39 | for (i = 0; i < main_mod->imp_size; ++i) { |
| 40 | if (main_mod->imp[i].module == imp_mod) { |
| 41 | return main_mod->imp[i].prefix; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | for (j = 0; j < main_mod->inc_size; ++j) { |
| 46 | for (i = 0; i < main_mod->inc[j].submodule->imp_size; ++i) { |
| 47 | if (main_mod->inc[j].submodule->imp[i].module == imp_mod) { |
| 48 | return main_mod->inc[j].submodule->imp[i].prefix; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return NULL; |
| 54 | } |
| 55 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 56 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 57 | yang_print_text(FILE *f, int level, const char *name, const char *text) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 58 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 59 | const char *s, *t; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 60 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 61 | fprintf(f, "%*s%s\n", LEVEL, INDENT, name); |
| 62 | level++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 63 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 64 | fprintf(f, "%*s\"", LEVEL, INDENT); |
| 65 | t = text; |
| 66 | while ((s = strchr(t, '\n'))) { |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 67 | fwrite(t, sizeof *t, (s - t) + 1, f); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 68 | t = s + 1; |
| 69 | fprintf(f, "%*s", LEVEL, INDENT); |
| 70 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 71 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 72 | fprintf(f, "%s\";\n\n", t); |
| 73 | level--; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 74 | |
| 75 | } |
| 76 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 77 | static void |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 78 | yang_print_nacmext(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 79 | { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 80 | int i, j; |
Radek Krejci | 86909d2 | 2015-07-03 16:11:25 +0200 | [diff] [blame] | 81 | const char *prefix = NULL; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 82 | |
| 83 | if (mnode->nacm && (!mnode->parent || mnode->parent->nacm != mnode->nacm)) { |
| 84 | /* locate ietf-netconf-acm module in imports */ |
| 85 | if (!strcmp(mnode->module->name, "ietf-netconf-acm")) { |
| 86 | prefix = mnode->module->prefix; |
| 87 | } else { |
| 88 | /* search in imports */ |
| 89 | for (i = 0; i < mnode->module->imp_size; i++) { |
| 90 | if (!strcmp(mnode->module->imp[i].module->name, "ietf-netconf-acm")) { |
| 91 | prefix = mnode->module->imp[i].prefix; |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | /* and in imports of includes */ |
| 96 | if (!prefix) { |
| 97 | for (j = 0; j < mnode->module->inc_size; j++) { |
| 98 | for (i = 0; i < mnode->module->inc[j].submodule->imp_size; i++) { |
| 99 | if (!strcmp(mnode->module->inc[j].submodule->imp[i].module->name, "ietf-netconf-acm")) { |
| 100 | prefix = mnode->module->inc[j].submodule->imp[i].prefix; |
| 101 | break; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if ((mnode->nacm & LY_NACM_DENYW) && (!mnode->parent || !(mnode->parent->nacm & LY_NACM_DENYW))) { |
| 109 | fprintf(f, "%*s%s:default-deny-write;\n", LEVEL, INDENT, prefix); |
| 110 | } |
| 111 | if ((mnode->nacm & LY_NACM_DENYA) && (!mnode->parent || !(mnode->parent->nacm & LY_NACM_DENYA))) { |
| 112 | fprintf(f, "%*s%s:default-deny-all;\n", LEVEL, INDENT, prefix); |
| 113 | } |
| 114 | } |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Covers: |
| 119 | * description, reference, status |
| 120 | */ |
| 121 | static void |
| 122 | yang_print_mnode_common(FILE *f, int level, struct ly_mnode *mnode) |
| 123 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 124 | if (mnode->flags & LY_NODE_STATUS_CURR) { |
| 125 | fprintf(f, "%*sstatus \"current\";\n", LEVEL, INDENT); |
| 126 | } else if (mnode->flags & LY_NODE_STATUS_DEPRC) { |
| 127 | fprintf(f, "%*sstatus \"deprecated\";\n", LEVEL, INDENT); |
| 128 | } else if (mnode->flags & LY_NODE_STATUS_OBSLT) { |
| 129 | fprintf(f, "%*sstatus \"obsolete\";\n", LEVEL, INDENT); |
| 130 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 131 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 132 | if (mnode->dsc) { |
| 133 | yang_print_text(f, level, "description", mnode->dsc); |
| 134 | } |
| 135 | if (mnode->ref) { |
| 136 | yang_print_text(f, level, "reference", mnode->ref); |
| 137 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /* |
| 141 | * Covers: |
Michal Vasko | 2b8faed | 2015-06-09 12:51:20 +0200 | [diff] [blame] | 142 | * config, mandatory |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 143 | * description, reference, status |
| 144 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 145 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 146 | yang_print_mnode_common2(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 147 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 148 | if (!mnode->parent || (mnode->parent->flags & LY_NODE_CONFIG_MASK) != (mnode->flags & LY_NODE_CONFIG_MASK)) { |
| 149 | /* print config only when it differs from the parent or in root */ |
| 150 | if (mnode->flags & LY_NODE_CONFIG_W) { |
| 151 | fprintf(f, "%*sconfig \"true\";\n", LEVEL, INDENT); |
| 152 | } else if (mnode->flags & LY_NODE_CONFIG_R) { |
| 153 | fprintf(f, "%*sconfig \"false\";\n", LEVEL, INDENT); |
| 154 | } |
| 155 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 156 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 157 | if (mnode->flags & LY_NODE_MAND_TRUE) { |
| 158 | fprintf(f, "%*smandatory \"true\";\n", LEVEL, INDENT); |
| 159 | } else if (mnode->flags & LY_NODE_MAND_FALSE) { |
| 160 | fprintf(f, "%*smandatory \"false\";\n", LEVEL, INDENT); |
| 161 | } |
Michal Vasko | 2b8faed | 2015-06-09 12:51:20 +0200 | [diff] [blame] | 162 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 163 | yang_print_mnode_common(f, level, mnode); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 164 | } |
| 165 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 166 | static void |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 167 | yang_print_iffeature(FILE *f, int level, struct ly_module *module, struct ly_feature *feat) |
| 168 | { |
| 169 | fprintf(f, "%*sif-feature ", LEVEL, INDENT); |
| 170 | if ((feat->module != module) && !feat->module->type) { |
| 171 | fprintf(f, "%s:", get_module_import_prefix(module, feat->module)); |
| 172 | } |
| 173 | fprintf(f, "%s;\n", feat->name); |
| 174 | } |
| 175 | |
| 176 | static void |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 177 | yang_print_feature(FILE *f, int level, struct ly_feature *feat) |
| 178 | { |
Michal Vasko | 30f6e91 | 2015-07-07 12:24:27 +0200 | [diff] [blame] | 179 | int i; |
| 180 | |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 181 | fprintf(f, "%*sfeature %s {\n", LEVEL, INDENT, feat->name); |
| 182 | level++; |
| 183 | |
Michal Vasko | 30f6e91 | 2015-07-07 12:24:27 +0200 | [diff] [blame] | 184 | yang_print_mnode_common(f, level, (struct ly_mnode *)feat); |
| 185 | for (i = 0; i < feat->features_size; ++i) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 186 | yang_print_iffeature(f, level, feat->module, feat->features[i]); |
Michal Vasko | 30f6e91 | 2015-07-07 12:24:27 +0200 | [diff] [blame] | 187 | } |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 188 | |
| 189 | level--; |
| 190 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 191 | } |
| 192 | |
| 193 | static void |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 194 | yang_print_restr(FILE *f, int level, struct ly_restr *restr) |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 195 | { |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 196 | if (restr->dsc != NULL) { |
| 197 | yang_print_text(f, level, "description", restr->dsc); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 198 | } |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 199 | if (restr->ref != NULL) { |
| 200 | yang_print_text(f, level, "reference", restr->ref); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 201 | } |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 202 | if (restr->eapptag != NULL) { |
| 203 | fprintf(f, "%*serror-app-tag \"%s\";\n", LEVEL, INDENT, restr->eapptag); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 204 | } |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 205 | if (restr->emsg != NULL) { |
| 206 | yang_print_text(f, level, "error-message", restr->emsg); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
| 210 | static void |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 211 | yang_print_when(FILE *f, int level, struct ly_when *when) |
| 212 | { |
| 213 | fprintf(f, "%*swhen \"%s\" {\n", LEVEL, INDENT, when->cond); |
| 214 | level++; |
| 215 | if (when->dsc) { |
| 216 | yang_print_text(f, level, "description", when->dsc); |
| 217 | } |
| 218 | if (when->ref) { |
| 219 | yang_print_text(f, level, "reference", when->ref); |
| 220 | } |
| 221 | level--; |
| 222 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 223 | } |
| 224 | |
| 225 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 226 | yang_print_type(FILE *f, int level, struct ly_module *module, struct ly_type *type) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 227 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 228 | int i; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 229 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 230 | if (type->prefix) { |
| 231 | fprintf(f, "%*stype %s:%s {\n", LEVEL, INDENT, type->prefix, type->der->name); |
| 232 | } else { |
| 233 | fprintf(f, "%*stype %s {\n", LEVEL, INDENT, type->der->name); |
| 234 | } |
| 235 | level++; |
| 236 | switch (type->base) { |
| 237 | case LY_TYPE_BINARY: |
| 238 | if (type->info.binary.length != NULL) { |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 239 | fprintf(f, "%*slength \"%s\" {\n", LEVEL, INDENT, type->info.binary.length->expr); |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 240 | yang_print_restr(f, level + 1, type->info.binary.length); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 241 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 242 | } |
| 243 | break; |
| 244 | case LY_TYPE_BITS: |
| 245 | for (i = 0; i < type->info.bits.count; ++i) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 246 | fprintf(f, "%*sbit %s {\n", LEVEL, INDENT, type->info.bits.bit[i].name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 247 | level++; |
| 248 | yang_print_mnode_common(f, level, (struct ly_mnode *)&type->info.bits.bit[i]); |
| 249 | fprintf(f, "%*sposition %u;\n", LEVEL, INDENT, type->info.bits.bit[i].pos); |
| 250 | level--; |
| 251 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 252 | } |
| 253 | break; |
| 254 | case LY_TYPE_DEC64: |
| 255 | fprintf(f, "%*sfraction-digits %d;\n", LEVEL, INDENT, type->info.dec64.dig); |
Michal Vasko | ea505ee | 2015-07-07 14:01:00 +0200 | [diff] [blame] | 256 | if (type->info.dec64.range != NULL) { |
| 257 | fprintf(f, "%*srange \"%s\" {\n", LEVEL, INDENT, type->info.dec64.range->expr); |
| 258 | yang_print_restr(f, level + 1, type->info.dec64.range); |
| 259 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 260 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 261 | break; |
| 262 | case LY_TYPE_ENUM: |
| 263 | for (i = 0; i < type->info.enums.count; i++) { |
| 264 | fprintf(f, "%*senum %s {\n", LEVEL, INDENT, type->info.enums.list[i].name); |
| 265 | level++; |
| 266 | yang_print_mnode_common(f, level, (struct ly_mnode *)&type->info.enums.list[i]); |
| 267 | fprintf(f, "%*svalue %d;\n", LEVEL, INDENT, type->info.enums.list[i].value); |
| 268 | level--; |
| 269 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 270 | } |
| 271 | break; |
| 272 | case LY_TYPE_IDENT: |
| 273 | if (module == type->info.ident.ref->module) { |
| 274 | fprintf(f, "%*sbase %s;\n", LEVEL, INDENT, type->info.ident.ref->name); |
| 275 | } else { |
| 276 | fprintf(f, "%*sbase %s:%s;\n", LEVEL, INDENT, type->info.ident.ref->module->prefix, |
| 277 | type->info.ident.ref->name); |
| 278 | } |
| 279 | break; |
| 280 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 281 | if (type->info.inst.req == 1) { |
| 282 | fprintf(f, "%*srequire-instance \"true\";\n", LEVEL, INDENT); |
| 283 | } else if (type->info.inst.req == -1) { |
| 284 | fprintf(f, "%*srequire-instance \"false\";\n", LEVEL, INDENT); |
| 285 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 286 | break; |
| 287 | case LY_TYPE_INT8: |
| 288 | case LY_TYPE_INT16: |
| 289 | case LY_TYPE_INT32: |
| 290 | case LY_TYPE_INT64: |
| 291 | case LY_TYPE_UINT8: |
| 292 | case LY_TYPE_UINT16: |
| 293 | case LY_TYPE_UINT32: |
| 294 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 295 | if (type->info.num.range != NULL) { |
| 296 | fprintf(f, "%*srange \"%s\" {\n", LEVEL, INDENT, type->info.num.range->expr); |
| 297 | yang_print_restr(f, level + 1, type->info.num.range); |
| 298 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 299 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 300 | break; |
| 301 | case LY_TYPE_LEAFREF: |
| 302 | fprintf(f, "%*spath \"%s\";\n", LEVEL, INDENT, type->info.lref.path); |
| 303 | break; |
| 304 | case LY_TYPE_STRING: |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 305 | if (type->info.str.length) { |
Radek Krejci | 061bd52 | 2015-06-19 13:45:16 +0200 | [diff] [blame] | 306 | fprintf(f, "%*slength \"%s\" {\n", LEVEL, INDENT, type->info.str.length->expr); |
| 307 | yang_print_restr(f, level + 1, type->info.str.length); |
| 308 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 309 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 310 | for (i = 0; i < type->info.str.pat_count; i++) { |
| 311 | fprintf(f, "%*spattern \"%s\" {\n", LEVEL, INDENT, type->info.str.patterns[i].expr); |
| 312 | yang_print_restr(f, level + 1, &type->info.str.patterns[i]); |
| 313 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 314 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 315 | break; |
| 316 | case LY_TYPE_UNION: |
| 317 | for (i = 0; i < type->info.uni.count; ++i) { |
| 318 | yang_print_type(f, level, module, &type->info.uni.type[i]); |
| 319 | } |
| 320 | break; |
| 321 | default: |
| 322 | /* other types do not have substatements */ |
| 323 | break; |
| 324 | } |
| 325 | level--; |
| 326 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 327 | } |
| 328 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 329 | static void |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 330 | yang_print_must(FILE *f, int level, struct ly_restr *must) |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 331 | { |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 332 | fprintf(f, "%*smust \"%s\" {\n", LEVEL, INDENT, must->expr); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 333 | yang_print_restr(f, level + 1, must); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 334 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 337 | static void |
Michal Vasko | 1ef0797 | 2015-07-07 14:01:35 +0200 | [diff] [blame] | 338 | yang_print_unique(FILE *f, int level, struct ly_unique *uniq) |
| 339 | { |
| 340 | int i; |
| 341 | |
| 342 | fprintf(f, "%*sunique \"", LEVEL, INDENT); |
| 343 | for (i = 0; i < uniq->leafs_size; i++) { |
| 344 | fprintf(f, "%s%s", uniq->leafs[i]->name, i + 1 < uniq->leafs_size ? " " : ""); |
| 345 | } |
| 346 | fprintf(f, "\";\n"); |
| 347 | } |
| 348 | |
| 349 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 350 | yang_print_refine(FILE *f, int level, struct ly_refine *refine) |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 351 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 352 | int i; |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 353 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 354 | fprintf(f, "%*srefine \"%s\" {\n", LEVEL, INDENT, refine->target); |
| 355 | level++; |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 356 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 357 | if (refine->flags & LY_NODE_CONFIG_W) { |
| 358 | fprintf(f, "%*sconfig \"true\";\n", LEVEL, INDENT); |
| 359 | } else if (refine->flags & LY_NODE_CONFIG_R) { |
| 360 | fprintf(f, "%*sconfig \"false\";\n", LEVEL, INDENT); |
| 361 | } |
| 362 | |
| 363 | if (refine->flags & LY_NODE_MAND_TRUE) { |
| 364 | fprintf(f, "%*smandatory \"true\";\n", LEVEL, INDENT); |
| 365 | } else if (refine->flags & LY_NODE_MAND_FALSE) { |
| 366 | fprintf(f, "%*smandatory \"false\";\n", LEVEL, INDENT); |
| 367 | } |
| 368 | |
| 369 | yang_print_mnode_common(f, level, (struct ly_mnode *)refine); |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 370 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 371 | for (i = 0; i < refine->must_size; ++i) { |
| 372 | yang_print_must(f, level, &refine->must[i]); |
| 373 | } |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 374 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 375 | if (refine->target_type & (LY_NODE_LEAF | LY_NODE_CHOICE)) { |
| 376 | if (refine->mod.dflt != NULL) { |
| 377 | fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, refine->mod.dflt); |
| 378 | } |
| 379 | } else if (refine->target_type == LY_NODE_CONTAINER) { |
| 380 | if (refine->mod.presence != NULL) { |
| 381 | yang_print_text(f, level, "presence", refine->mod.presence); |
| 382 | } |
| 383 | } else if (refine->target_type & (LY_NODE_LIST | LY_NODE_LEAFLIST)) { |
| 384 | if (refine->mod.list.min > 0) { |
| 385 | fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, refine->mod.list.min); |
| 386 | } |
| 387 | if (refine->mod.list.max > 0) { |
| 388 | fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, refine->mod.list.max); |
| 389 | } |
| 390 | } |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 391 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 392 | level--; |
| 393 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 394 | } |
| 395 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 396 | static void |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 397 | yang_print_deviation(FILE *f, int level, struct ly_module *module, struct ly_deviation *deviation) |
| 398 | { |
| 399 | int i, j; |
| 400 | |
| 401 | fprintf(f, "%*sdeviation \"%s\" {\n", LEVEL, INDENT, deviation->target_name); |
| 402 | level++; |
| 403 | |
| 404 | if (deviation->dsc) { |
| 405 | yang_print_text(f, level, "description", deviation->dsc); |
| 406 | } |
| 407 | if (deviation->ref) { |
| 408 | yang_print_text(f, level, "reference", deviation->ref); |
| 409 | } |
| 410 | |
| 411 | for (i = 0; i < deviation->deviate_size; ++i) { |
| 412 | fprintf(f, "%*sdeviate ", LEVEL, INDENT); |
| 413 | if (deviation->deviate[i].mod == LY_DEVIATE_NO) { |
| 414 | fprintf(f, "not-supported {\n"); |
| 415 | } else if (deviation->deviate[i].mod == LY_DEVIATE_ADD) { |
| 416 | fprintf(f, "add {\n"); |
| 417 | } else if (deviation->deviate[i].mod == LY_DEVIATE_RPL) { |
| 418 | fprintf(f, "replace {\n"); |
| 419 | } else if (deviation->deviate[i].mod == LY_DEVIATE_DEL) { |
| 420 | fprintf(f, "delete {\n"); |
| 421 | } |
| 422 | level++; |
| 423 | |
| 424 | if (deviation->deviate[i].flags & LY_NODE_CONFIG_W) { |
| 425 | fprintf(f, "%*sconfig \"true\";\n", LEVEL, INDENT); |
| 426 | } else if (deviation->deviate[i].flags & LY_NODE_CONFIG_R) { |
| 427 | fprintf(f, "%*sconfig \"false\";\n", LEVEL, INDENT); |
| 428 | } |
| 429 | |
| 430 | if (deviation->deviate[i].flags & LY_NODE_MAND_TRUE) { |
| 431 | fprintf(f, "%*smandatory \"true\";\n", LEVEL, INDENT); |
| 432 | } else if (deviation->deviate[i].flags & LY_NODE_MAND_FALSE) { |
| 433 | fprintf(f, "%*smandatory \"false\";\n", LEVEL, INDENT); |
| 434 | } |
| 435 | |
| 436 | if (deviation->deviate[i].dflt) { |
| 437 | fprintf(f, "%*sdefault %s;\n", LEVEL, INDENT, deviation->deviate[i].dflt); |
| 438 | } |
| 439 | |
| 440 | if (deviation->deviate[i].min) { |
| 441 | fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, deviation->deviate[i].min); |
| 442 | } |
| 443 | if (deviation->deviate[i].max) { |
| 444 | fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, deviation->deviate[i].max); |
| 445 | } |
| 446 | |
| 447 | for (j = 0; j < deviation->deviate[i].must_size; ++j) { |
| 448 | yang_print_must(f, level, &deviation->deviate[i].must[j]); |
| 449 | } |
| 450 | |
| 451 | for (j = 0; j < deviation->deviate[i].unique_size; ++j) { |
| 452 | yang_print_unique(f, level, &deviation->deviate[i].unique[j]); |
| 453 | } |
| 454 | |
| 455 | if (deviation->deviate[i].type) { |
| 456 | yang_print_type(f, level, module, deviation->deviate[i].type); |
| 457 | } |
| 458 | |
| 459 | if (deviation->deviate[i].units) { |
| 460 | fprintf(f, "%*sunits %s;\n", LEVEL, INDENT, deviation->deviate[i].units); |
| 461 | } |
| 462 | |
| 463 | level--; |
| 464 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 465 | } |
| 466 | |
| 467 | level--; |
| 468 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 469 | } |
| 470 | |
| 471 | static void |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame^] | 472 | yang_print_augment(FILE *f, int level, struct ly_module *module, struct ly_augment *augment) |
| 473 | { |
| 474 | int i; |
| 475 | struct ly_mnode *sub; |
| 476 | |
| 477 | fprintf(f, "%*saugment \"%s\" {\n", LEVEL, INDENT, augment->target_name); |
| 478 | level++; |
| 479 | |
| 480 | yang_print_mnode_common(f, level, (struct ly_mnode *)augment); |
| 481 | |
| 482 | for (i = 0; i < augment->features_size; i++) { |
| 483 | yang_print_iffeature(f, level, module, augment->features[i]); |
| 484 | } |
| 485 | |
| 486 | if (augment->when) { |
| 487 | yang_print_when(f, level, augment->when); |
| 488 | } |
| 489 | |
| 490 | LY_TREE_FOR(augment->child, sub) { |
| 491 | yang_print_mnode(f, level, sub, |
| 492 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 493 | LY_NODE_USES | LY_NODE_ANYXML | LY_NODE_CASE); |
| 494 | } |
| 495 | |
| 496 | level--; |
| 497 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 498 | } |
| 499 | |
| 500 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 501 | yang_print_typedef(FILE *f, int level, struct ly_module *module, struct ly_tpdf *tpdf) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 502 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 503 | fprintf(f, "%*stypedef %s {\n", LEVEL, INDENT, tpdf->name); |
| 504 | level++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 505 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 506 | yang_print_mnode_common(f, level, (struct ly_mnode *)tpdf); |
| 507 | yang_print_type(f, level, module, &tpdf->type); |
| 508 | if (tpdf->units != NULL) { |
| 509 | fprintf(f, "%*sunits \"%s\";\n", LEVEL, INDENT, tpdf->units); |
| 510 | } |
| 511 | if (tpdf->dflt != NULL) { |
| 512 | fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, tpdf->dflt); |
| 513 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 514 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 515 | level--; |
| 516 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 517 | } |
| 518 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 519 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 520 | yang_print_identity(FILE *f, int level, struct ly_ident *ident) |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 521 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 522 | fprintf(f, "%*sidentity %s {\n", LEVEL, INDENT, ident->name); |
| 523 | level++; |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 524 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 525 | yang_print_mnode_common(f, level, (struct ly_mnode *)ident); |
| 526 | if (ident->base) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 527 | fprintf(f, "%*sbase ", LEVEL, INDENT); |
| 528 | if ((ident->module != ident->base->module) && !ident->base->module->type) { |
| 529 | fprintf(f, "%s:", get_module_import_prefix(ident->module, ident->base->module)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 530 | } |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 531 | fprintf(f, "%s;\n", ident->base->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 532 | } |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 533 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 534 | level--; |
| 535 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 536 | |
| 537 | } |
| 538 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 539 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 540 | yang_print_container(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 541 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 542 | int i; |
| 543 | struct ly_mnode *sub; |
| 544 | struct ly_mnode_container *cont = (struct ly_mnode_container *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 545 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 546 | fprintf(f, "%*scontainer %s {\n", LEVEL, INDENT, mnode->name); |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 547 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 548 | level++; |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 549 | |
| 550 | yang_print_nacmext(f, level, mnode); |
| 551 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 552 | if (cont->presence != NULL) { |
| 553 | yang_print_text(f, level, "presence", cont->presence); |
| 554 | } |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 555 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 556 | for (i = 0; i < cont->must_size; i++) { |
| 557 | yang_print_must(f, level, &cont->must[i]); |
| 558 | } |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 559 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 560 | yang_print_mnode_common2(f, level, mnode); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 561 | |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 562 | for (i = 0; i < cont->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 563 | yang_print_iffeature(f, level, mnode->module, cont->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 564 | } |
| 565 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 566 | for (i = 0; i < cont->tpdf_size; i++) { |
| 567 | yang_print_typedef(f, level, mnode->module, &cont->tpdf[i]); |
| 568 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 569 | |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 570 | if (cont->when) { |
| 571 | yang_print_when(f, level, cont->when); |
| 572 | } |
| 573 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 574 | LY_TREE_FOR(mnode->child, sub) { |
| 575 | yang_print_mnode(f, level, sub, |
| 576 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 577 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 578 | } |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 579 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 580 | level--; |
| 581 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 582 | } |
| 583 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 584 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 585 | yang_print_case(FILE *f, int level, struct ly_mnode *mnode) |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 586 | { |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 587 | int i; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 588 | struct ly_mnode *sub; |
| 589 | struct ly_mnode_case *cas = (struct ly_mnode_case *)mnode; |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 590 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 591 | fprintf(f, "%*scase %s {\n", LEVEL, INDENT, cas->name); |
| 592 | level++; |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 593 | yang_print_nacmext(f, level, mnode); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 594 | yang_print_mnode_common2(f, level, mnode); |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 595 | |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 596 | for (i = 0; i < cas->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 597 | yang_print_iffeature(f, level, mnode->module, cas->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 598 | } |
| 599 | |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 600 | if (cas->when) { |
| 601 | yang_print_when(f, level, cas->when); |
| 602 | } |
| 603 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 604 | LY_TREE_FOR(mnode->child, sub) { |
| 605 | yang_print_mnode(f, level, sub, |
| 606 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 607 | LY_NODE_USES | LY_NODE_ANYXML); |
| 608 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 609 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 610 | level--; |
| 611 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 612 | } |
| 613 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 614 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 615 | yang_print_choice(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 616 | { |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 617 | int i; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 618 | struct ly_mnode *sub; |
| 619 | struct ly_mnode_choice *choice = (struct ly_mnode_choice *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 620 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 621 | fprintf(f, "%*schoice %s {\n", LEVEL, INDENT, mnode->name); |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 622 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 623 | level++; |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 624 | yang_print_nacmext(f, level, mnode); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 625 | if (choice->dflt != NULL) { |
| 626 | fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, choice->dflt->name); |
| 627 | } |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 628 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 629 | yang_print_mnode_common2(f, level, mnode); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 630 | |
| 631 | for (i = 0; i < choice->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 632 | yang_print_iffeature(f, level, mnode->module, choice->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 633 | } |
| 634 | |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 635 | if (choice->when) { |
| 636 | yang_print_when(f, level, choice->when); |
| 637 | } |
| 638 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 639 | LY_TREE_FOR(mnode->child, sub) { |
| 640 | yang_print_mnode(f, level, sub, |
| 641 | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML | LY_NODE_CASE); |
| 642 | } |
| 643 | level--; |
| 644 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 647 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 648 | yang_print_leaf(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 649 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 650 | int i; |
| 651 | struct ly_mnode_leaf *leaf = (struct ly_mnode_leaf *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 652 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 653 | fprintf(f, "%*sleaf %s {\n", LEVEL, INDENT, mnode->name); |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 654 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 655 | level++; |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 656 | yang_print_nacmext(f, level, mnode); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 657 | yang_print_mnode_common2(f, level, mnode); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 658 | for (i = 0; i < leaf->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 659 | yang_print_iffeature(f, level, mnode->module, leaf->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 660 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 661 | for (i = 0; i < leaf->must_size; i++) { |
| 662 | yang_print_must(f, level, &leaf->must[i]); |
| 663 | } |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 664 | if (leaf->when) { |
| 665 | yang_print_when(f, level, leaf->when); |
| 666 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 667 | yang_print_type(f, level, mnode->module, &leaf->type); |
| 668 | if (leaf->units != NULL) { |
| 669 | fprintf(f, "%*sunits \"%s\";\n", LEVEL, INDENT, leaf->units); |
| 670 | } |
| 671 | if (leaf->dflt != NULL) { |
| 672 | fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, leaf->dflt); |
| 673 | } |
| 674 | level--; |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 675 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 676 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 677 | } |
| 678 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 679 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 680 | yang_print_anyxml(FILE *f, int level, struct ly_mnode *mnode) |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 681 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 682 | int i; |
| 683 | struct ly_mnode_anyxml *anyxml = (struct ly_mnode_anyxml *)mnode; |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 684 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 685 | fprintf(f, "%*sanyxml %s {\n", LEVEL, INDENT, anyxml->name); |
| 686 | level++; |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 687 | yang_print_nacmext(f, level, mnode); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 688 | yang_print_mnode_common2(f, level, mnode); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 689 | for (i = 0; i < anyxml->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 690 | yang_print_iffeature(f, level, mnode->module, anyxml->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 691 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 692 | for (i = 0; i < anyxml->must_size; i++) { |
| 693 | yang_print_must(f, level, &anyxml->must[i]); |
| 694 | } |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 695 | if (anyxml->when) { |
| 696 | yang_print_when(f, level, anyxml->when); |
| 697 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 698 | level--; |
| 699 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 700 | } |
| 701 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 702 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 703 | yang_print_leaflist(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 704 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 705 | int i; |
| 706 | struct ly_mnode_leaflist *llist = (struct ly_mnode_leaflist *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 707 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 708 | fprintf(f, "%*sleaf-list %s {\n", LEVEL, INDENT, mnode->name); |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 709 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 710 | level++; |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 711 | yang_print_nacmext(f, level, mnode); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 712 | yang_print_mnode_common2(f, level, mnode); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 713 | for (i = 0; i < llist->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 714 | yang_print_iffeature(f, level, mnode->module, llist->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 715 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 716 | if (llist->flags & LY_NODE_USERORDERED) { |
| 717 | fprintf(f, "%*sordered-by user;\n", LEVEL, INDENT); |
| 718 | } |
| 719 | if (llist->min > 0) { |
| 720 | fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, llist->min); |
| 721 | } |
| 722 | if (llist->max > 0) { |
| 723 | fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, llist->max); |
| 724 | } |
| 725 | for (i = 0; i < llist->must_size; i++) { |
| 726 | yang_print_must(f, level, &llist->must[i]); |
| 727 | } |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 728 | if (llist->when) { |
| 729 | yang_print_when(f, level, llist->when); |
| 730 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 731 | yang_print_type(f, level, mnode->module, &llist->type); |
| 732 | if (llist->units != NULL) { |
| 733 | fprintf(f, "%*sunits \"%s\";\n", LEVEL, INDENT, llist->units); |
| 734 | } |
| 735 | level--; |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 736 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 737 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 738 | } |
| 739 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 740 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 741 | yang_print_list(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 742 | { |
Michal Vasko | 1ef0797 | 2015-07-07 14:01:35 +0200 | [diff] [blame] | 743 | int i; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 744 | struct ly_mnode *sub; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 745 | struct ly_mnode_list *list = (struct ly_mnode_list *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 746 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 747 | fprintf(f, "%*slist %s {\n", LEVEL, INDENT, mnode->name); |
| 748 | level++; |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 749 | yang_print_nacmext(f, level, mnode); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 750 | yang_print_mnode_common2(f, level, mnode); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 751 | |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 752 | for (i = 0; i < list->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 753 | yang_print_iffeature(f, level, mnode->module, list->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 754 | } |
| 755 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 756 | if (list->keys_size) { |
| 757 | fprintf(f, "%*skey \"", LEVEL, INDENT); |
| 758 | for (i = 0; i < list->keys_size; i++) { |
| 759 | fprintf(f, "%s%s", list->keys[i]->name, i + 1 < list->keys_size ? " " : ""); |
| 760 | } |
| 761 | fprintf(f, "\";\n"); |
| 762 | } |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 763 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 764 | for (i = 0; i < list->unique_size; i++) { |
Michal Vasko | 1ef0797 | 2015-07-07 14:01:35 +0200 | [diff] [blame] | 765 | yang_print_unique(f, level, &list->unique[i]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 766 | } |
Michal Vasko | dff818b | 2015-06-09 14:01:12 +0200 | [diff] [blame] | 767 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 768 | if (list->flags & LY_NODE_USERORDERED) { |
| 769 | fprintf(f, "%*sordered-by user;\n", LEVEL, INDENT); |
| 770 | } |
| 771 | if (list->min > 0) { |
| 772 | fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, list->min); |
| 773 | } |
| 774 | if (list->max > 0) { |
| 775 | fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, list->max); |
| 776 | } |
| 777 | for (i = 0; i < list->must_size; i++) { |
| 778 | yang_print_must(f, level, &list->must[i]); |
| 779 | } |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 780 | if (list->when) { |
| 781 | yang_print_when(f, level, list->when); |
| 782 | } |
Michal Vasko | dff818b | 2015-06-09 14:01:12 +0200 | [diff] [blame] | 783 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 784 | for (i = 0; i < list->tpdf_size; i++) { |
| 785 | yang_print_typedef(f, level, list->module, &list->tpdf[i]); |
| 786 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 787 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 788 | LY_TREE_FOR(mnode->child, sub) { |
| 789 | yang_print_mnode(f, level, sub, |
| 790 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 791 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 792 | } |
| 793 | level--; |
| 794 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 795 | } |
| 796 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 797 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 798 | yang_print_grouping(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 799 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 800 | int i; |
| 801 | struct ly_mnode *node; |
| 802 | struct ly_mnode_grp *grp = (struct ly_mnode_grp *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 803 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 804 | fprintf(f, "%*sgrouping %s {\n", LEVEL, INDENT, mnode->name); |
| 805 | level++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 806 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 807 | yang_print_mnode_common(f, level, mnode); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 808 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 809 | for (i = 0; i < grp->tpdf_size; i++) { |
| 810 | yang_print_typedef(f, level, mnode->module, &grp->tpdf[i]); |
| 811 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 812 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 813 | LY_TREE_FOR(mnode->child, node) { |
| 814 | yang_print_mnode(f, level, node, |
| 815 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 816 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 817 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 818 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 819 | level--; |
| 820 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 821 | } |
| 822 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 823 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 824 | yang_print_uses(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 825 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 826 | int i; |
| 827 | struct ly_mnode_uses *uses = (struct ly_mnode_uses *)mnode; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 828 | |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 829 | fprintf(f, "%*suses ", LEVEL, INDENT); |
| 830 | if (mnode->child && (mnode->module != mnode->child->module) && !mnode->child->module->type) { |
| 831 | fprintf(f, "%s:", get_module_import_prefix(mnode->module, mnode->child->module)); |
| 832 | } |
| 833 | fprintf(f, "%s {\n",uses->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 834 | level++; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 835 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 836 | yang_print_nacmext(f, level, mnode); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 837 | yang_print_mnode_common(f, level, mnode); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 838 | for (i = 0; i < uses->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 839 | yang_print_iffeature(f, level, mnode->module, uses->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 840 | } |
Michal Vasko | 1f0428a | 2015-07-07 14:55:04 +0200 | [diff] [blame] | 841 | if (uses->when) { |
| 842 | yang_print_when(f, level, uses->when); |
| 843 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 844 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 845 | for (i = 0; i < uses->refine_size; i++) { |
| 846 | yang_print_refine(f, level, &uses->refine[i]); |
| 847 | } |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 848 | |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame^] | 849 | for (i = 0; i < uses->augment_size; i++) { |
| 850 | yang_print_augment(f, level, mnode->module, &uses->augment[i]); |
| 851 | } |
| 852 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 853 | level--; |
| 854 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 855 | } |
| 856 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 857 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 858 | yang_print_input_output(FILE *f, int level, struct ly_mnode *mnode) |
| 859 | { |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 860 | int i; |
| 861 | struct ly_mnode *sub; |
Michal Vasko | fb69a84 | 2015-06-16 12:07:40 +0200 | [diff] [blame] | 862 | struct ly_mnode_input_output *inout = (struct ly_mnode_input_output *)mnode; |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 863 | |
| 864 | fprintf(f, "%*s%s {\n", LEVEL, INDENT, (inout->nodetype == LY_NODE_INPUT ? "input" : "output")); |
| 865 | |
| 866 | level++; |
| 867 | for (i = 0; i < inout->tpdf_size; i++) { |
| 868 | yang_print_typedef(f, level, mnode->module, &inout->tpdf[i]); |
| 869 | } |
| 870 | |
| 871 | LY_TREE_FOR(mnode->child, sub) { |
| 872 | yang_print_mnode(f, level, sub, |
| 873 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 874 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 875 | } |
| 876 | |
| 877 | level--; |
| 878 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 879 | } |
| 880 | |
| 881 | static void |
| 882 | yang_print_rpc(FILE *f, int level, struct ly_mnode *mnode) |
| 883 | { |
| 884 | int i; |
| 885 | struct ly_mnode *sub; |
| 886 | struct ly_mnode_rpc *rpc = (struct ly_mnode_rpc *)mnode; |
| 887 | |
| 888 | fprintf(f, "%*srpc %s {\n", LEVEL, INDENT, mnode->name); |
| 889 | |
| 890 | level++; |
| 891 | yang_print_mnode_common(f, level, mnode); |
| 892 | |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 893 | for (i = 0; i < rpc->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 894 | yang_print_iffeature(f, level, mnode->module, rpc->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 895 | } |
| 896 | |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 897 | for (i = 0; i < rpc->tpdf_size; i++) { |
| 898 | yang_print_typedef(f, level, mnode->module, &rpc->tpdf[i]); |
| 899 | } |
| 900 | |
| 901 | LY_TREE_FOR(mnode->child, sub) { |
| 902 | yang_print_mnode(f, level, sub, |
| 903 | LY_NODE_GROUPING | LY_NODE_INPUT | LY_NODE_OUTPUT); |
| 904 | } |
| 905 | |
| 906 | level--; |
| 907 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 908 | } |
| 909 | |
| 910 | static void |
Michal Vasko | 7690bc1 | 2015-06-16 12:26:05 +0200 | [diff] [blame] | 911 | yang_print_notif(FILE *f, int level, struct ly_mnode *mnode) |
| 912 | { |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 913 | int i; |
| 914 | struct ly_mnode *sub; |
| 915 | struct ly_mnode_notif *notif = (struct ly_mnode_notif *)mnode; |
| 916 | |
| 917 | fprintf(f, "%*snotification %s {\n", LEVEL, INDENT, mnode->name); |
| 918 | |
| 919 | level++; |
| 920 | yang_print_mnode_common(f, level, mnode); |
| 921 | |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 922 | for (i = 0; i < notif->features_size; i++) { |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 923 | yang_print_iffeature(f, level, mnode->module, notif->features[i]); |
Michal Vasko | 4773b76 | 2015-07-07 12:15:10 +0200 | [diff] [blame] | 924 | } |
| 925 | |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 926 | for (i = 0; i < notif->tpdf_size; i++) { |
| 927 | yang_print_typedef(f, level, mnode->module, ¬if->tpdf[i]); |
| 928 | } |
| 929 | |
| 930 | LY_TREE_FOR(mnode->child, sub) { |
| 931 | yang_print_mnode(f, level, sub, |
| 932 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 933 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 934 | } |
| 935 | |
| 936 | level--; |
| 937 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 938 | } |
| 939 | |
| 940 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 941 | yang_print_mnode(FILE *f, int level, struct ly_mnode *mnode, int mask) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 942 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 943 | switch (mnode->nodetype & mask) { |
| 944 | case LY_NODE_CONTAINER: |
| 945 | yang_print_container(f, level, mnode); |
| 946 | break; |
| 947 | case LY_NODE_CHOICE: |
| 948 | yang_print_choice(f, level, mnode); |
| 949 | break; |
| 950 | case LY_NODE_LEAF: |
| 951 | yang_print_leaf(f, level, mnode); |
| 952 | break; |
| 953 | case LY_NODE_LEAFLIST: |
| 954 | yang_print_leaflist(f, level, mnode); |
| 955 | break; |
| 956 | case LY_NODE_LIST: |
| 957 | yang_print_list(f, level, mnode); |
| 958 | break; |
| 959 | case LY_NODE_USES: |
| 960 | yang_print_uses(f, level, mnode); |
| 961 | break; |
| 962 | case LY_NODE_GROUPING: |
| 963 | yang_print_grouping(f, level, mnode); |
| 964 | break; |
| 965 | case LY_NODE_ANYXML: |
| 966 | yang_print_anyxml(f, level, mnode); |
| 967 | break; |
| 968 | case LY_NODE_CASE: |
| 969 | yang_print_case(f, level, mnode); |
| 970 | break; |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 971 | case LY_NODE_INPUT: |
| 972 | case LY_NODE_OUTPUT: |
| 973 | yang_print_input_output(f, level, mnode); |
| 974 | break; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 975 | default: |
| 976 | break; |
| 977 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 978 | } |
| 979 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 980 | int |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame] | 981 | yang_print_model(FILE *f, struct ly_module *module) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 982 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 983 | unsigned int i; |
| 984 | int level = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 985 | #define LEVEL (level*2) |
| 986 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 987 | struct ly_mnode *mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 988 | |
Michal Vasko | 116172e | 2015-07-07 11:54:37 +0200 | [diff] [blame] | 989 | if (module->type) { |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 990 | fprintf(f, "submodule %s {%s\n", module->name, (module->deviated ? " // DEVIATED" : "")); |
Michal Vasko | 116172e | 2015-07-07 11:54:37 +0200 | [diff] [blame] | 991 | level++; |
| 992 | fprintf(f, "%*sbelongs-to %s {\n", LEVEL, INDENT, ((struct ly_submodule *)module)->belongsto->name); |
| 993 | level++; |
| 994 | fprintf(f, "%*sprefix \"%s\";\n", LEVEL, INDENT, module->prefix); |
| 995 | level--; |
| 996 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 997 | } else { |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 998 | fprintf(f, "module %s {%s\n", module->name, (module->deviated ? " // DEVIATED" : "")); |
Michal Vasko | 116172e | 2015-07-07 11:54:37 +0200 | [diff] [blame] | 999 | level++; |
| 1000 | fprintf(f, "%*snamespace \"%s\";\n", LEVEL, INDENT, module->ns); |
| 1001 | fprintf(f, "%*sprefix \"%s\";\n", LEVEL, INDENT, module->prefix); |
| 1002 | } |
Radek Krejci | b0594bf | 2015-05-21 23:51:27 +0200 | [diff] [blame] | 1003 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1004 | if (module->version) { |
Michal Vasko | 6c722a6 | 2015-07-07 11:54:57 +0200 | [diff] [blame] | 1005 | fprintf(f, "%*syang-version %s;\n", LEVEL, INDENT, module->version == 1 ? "1" : "1.1"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1006 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1007 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1008 | for (i = 0; i < module->imp_size; i++) { |
| 1009 | fprintf(f, "%*simport \"%s\" {\n", LEVEL, INDENT, module->imp[i].module->name); |
| 1010 | level++; |
Michal Vasko | c39c4b1 | 2015-07-07 14:55:33 +0200 | [diff] [blame] | 1011 | fprintf(f, "%*sprefix \"%s\";\n", LEVEL, INDENT, module->imp[i].prefix); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1012 | if (module->imp[i].rev[0]) { |
| 1013 | yang_print_text(f, level, "revision-date", module->imp[i].rev); |
| 1014 | } |
| 1015 | level--; |
| 1016 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 1017 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1018 | |
Michal Vasko | e0af1e2 | 2015-07-07 14:02:02 +0200 | [diff] [blame] | 1019 | for (i = 0; i < module->deviation_size; ++i) { |
| 1020 | yang_print_deviation(f, level, module, &module->deviation[i]); |
| 1021 | } |
| 1022 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1023 | for (i = 0; i < module->inc_size; i++) { |
| 1024 | if (module->inc[i].rev[0]) { |
| 1025 | fprintf(f, "%*sinclude \"%s\" {\n", LEVEL, INDENT, module->inc[i].submodule->name); |
Michal Vasko | 3d7b856 | 2015-07-07 15:40:34 +0200 | [diff] [blame] | 1026 | yang_print_text(f, level + 1, "revision-date", module->inc[i].rev); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1027 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 1028 | } else { |
| 1029 | fprintf(f, "%*sinclude \"%s\";\n", LEVEL, INDENT, module->inc[i].submodule->name); |
| 1030 | } |
| 1031 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 1032 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1033 | if (module->org) { |
| 1034 | yang_print_text(f, level, "organization", module->org); |
| 1035 | } |
| 1036 | if (module->contact) { |
| 1037 | yang_print_text(f, level, "contact", module->contact); |
| 1038 | } |
| 1039 | if (module->dsc) { |
| 1040 | yang_print_text(f, level, "description", module->dsc); |
| 1041 | } |
| 1042 | if (module->ref) { |
| 1043 | yang_print_text(f, level, "reference", module->ref); |
| 1044 | } |
| 1045 | for (i = 0; i < module->rev_size; i++) { |
| 1046 | if (module->rev[i].dsc || module->rev[i].ref) { |
| 1047 | fprintf(f, "%*srevision \"%s\" {\n", LEVEL, INDENT, module->rev[i].date); |
| 1048 | level++; |
| 1049 | if (module->rev[i].dsc) { |
| 1050 | yang_print_text(f, level, "description", module->rev[i].dsc); |
| 1051 | } |
| 1052 | if (module->rev[i].ref) { |
| 1053 | yang_print_text(f, level, "reference", module->rev[i].ref); |
| 1054 | } |
| 1055 | level--; |
| 1056 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 1057 | } else { |
| 1058 | yang_print_text(f, level, "revision", module->rev[i].date); |
| 1059 | } |
| 1060 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1061 | |
Michal Vasko | 30f6e91 | 2015-07-07 12:24:27 +0200 | [diff] [blame] | 1062 | for (i = 0; i < module->features_size; i++) { |
| 1063 | yang_print_feature(f, level, &module->features[i]); |
| 1064 | } |
| 1065 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1066 | for (i = 0; i < module->ident_size; i++) { |
| 1067 | yang_print_identity(f, level, &module->ident[i]); |
| 1068 | } |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 1069 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1070 | for (i = 0; i < module->tpdf_size; i++) { |
| 1071 | yang_print_typedef(f, level, module, &module->tpdf[i]); |
| 1072 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1073 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1074 | LY_TREE_FOR(module->data, mnode) { |
| 1075 | yang_print_mnode(f, level, mnode, |
| 1076 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 1077 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 1078 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1079 | |
Michal Vasko | 6f25f21 | 2015-07-07 15:42:07 +0200 | [diff] [blame^] | 1080 | for (i = 0; i < module->augment_size; i++) { |
| 1081 | yang_print_augment(f, level, module, &module->augment[i]); |
| 1082 | } |
| 1083 | |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 1084 | LY_TREE_FOR(module->rpc, mnode) { |
| 1085 | yang_print_rpc(f, level, mnode); |
| 1086 | } |
| 1087 | |
| 1088 | LY_TREE_FOR(module->notif, mnode) { |
| 1089 | yang_print_notif(f, level, mnode); |
| 1090 | } |
| 1091 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1092 | fprintf(f, "}\n"); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1093 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1094 | return EXIT_SUCCESS; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1095 | #undef LEVEL |
| 1096 | } |