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