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 | |
| 55 | /* |
| 56 | * Covers: |
| 57 | * description, reference, status |
| 58 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 59 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 60 | yang_print_mnode_common(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 61 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 62 | if (mnode->flags & LY_NODE_STATUS_CURR) { |
| 63 | fprintf(f, "%*sstatus \"current\";\n", LEVEL, INDENT); |
| 64 | } else if (mnode->flags & LY_NODE_STATUS_DEPRC) { |
| 65 | fprintf(f, "%*sstatus \"deprecated\";\n", LEVEL, INDENT); |
| 66 | } else if (mnode->flags & LY_NODE_STATUS_OBSLT) { |
| 67 | fprintf(f, "%*sstatus \"obsolete\";\n", LEVEL, INDENT); |
| 68 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 69 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 70 | if (mnode->dsc) { |
| 71 | yang_print_text(f, level, "description", mnode->dsc); |
| 72 | } |
| 73 | if (mnode->ref) { |
| 74 | yang_print_text(f, level, "reference", mnode->ref); |
| 75 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /* |
| 79 | * Covers: |
Michal Vasko | 2b8faed | 2015-06-09 12:51:20 +0200 | [diff] [blame] | 80 | * config, mandatory |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 81 | * description, reference, status |
| 82 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 83 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 84 | yang_print_mnode_common2(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 85 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 86 | if (!mnode->parent || (mnode->parent->flags & LY_NODE_CONFIG_MASK) != (mnode->flags & LY_NODE_CONFIG_MASK)) { |
| 87 | /* print config only when it differs from the parent or in root */ |
| 88 | if (mnode->flags & LY_NODE_CONFIG_W) { |
| 89 | fprintf(f, "%*sconfig \"true\";\n", LEVEL, INDENT); |
| 90 | } else if (mnode->flags & LY_NODE_CONFIG_R) { |
| 91 | fprintf(f, "%*sconfig \"false\";\n", LEVEL, INDENT); |
| 92 | } |
| 93 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 94 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 95 | if (mnode->flags & LY_NODE_MAND_TRUE) { |
| 96 | fprintf(f, "%*smandatory \"true\";\n", LEVEL, INDENT); |
| 97 | } else if (mnode->flags & LY_NODE_MAND_FALSE) { |
| 98 | fprintf(f, "%*smandatory \"false\";\n", LEVEL, INDENT); |
| 99 | } |
Michal Vasko | 2b8faed | 2015-06-09 12:51:20 +0200 | [diff] [blame] | 100 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 101 | yang_print_mnode_common(f, level, mnode); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 104 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 105 | 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] | 106 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 107 | int i; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 108 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 109 | if (type->prefix) { |
| 110 | fprintf(f, "%*stype %s:%s {\n", LEVEL, INDENT, type->prefix, type->der->name); |
| 111 | } else { |
| 112 | fprintf(f, "%*stype %s {\n", LEVEL, INDENT, type->der->name); |
| 113 | } |
| 114 | level++; |
| 115 | switch (type->base) { |
| 116 | case LY_TYPE_BINARY: |
| 117 | if (type->info.binary.length != NULL) { |
| 118 | fprintf(f, "%*slength \"%s\";\n", LEVEL, INDENT, type->info.binary.length); |
| 119 | } |
| 120 | break; |
| 121 | case LY_TYPE_BITS: |
| 122 | for (i = 0; i < type->info.bits.count; ++i) { |
| 123 | fprintf(f, "%*sbit %s {\n", LEVEL, INDENT, type->info.bits.bit[i].value); |
| 124 | level++; |
| 125 | yang_print_mnode_common(f, level, (struct ly_mnode *)&type->info.bits.bit[i]); |
| 126 | fprintf(f, "%*sposition %u;\n", LEVEL, INDENT, type->info.bits.bit[i].pos); |
| 127 | level--; |
| 128 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 129 | } |
| 130 | break; |
| 131 | case LY_TYPE_DEC64: |
| 132 | fprintf(f, "%*sfraction-digits %d;\n", LEVEL, INDENT, type->info.dec64.dig); |
| 133 | /* TODO range incomplete */ |
| 134 | break; |
| 135 | case LY_TYPE_ENUM: |
| 136 | for (i = 0; i < type->info.enums.count; i++) { |
| 137 | fprintf(f, "%*senum %s {\n", LEVEL, INDENT, type->info.enums.list[i].name); |
| 138 | level++; |
| 139 | yang_print_mnode_common(f, level, (struct ly_mnode *)&type->info.enums.list[i]); |
| 140 | fprintf(f, "%*svalue %d;\n", LEVEL, INDENT, type->info.enums.list[i].value); |
| 141 | level--; |
| 142 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 143 | } |
| 144 | break; |
| 145 | case LY_TYPE_IDENT: |
| 146 | if (module == type->info.ident.ref->module) { |
| 147 | fprintf(f, "%*sbase %s;\n", LEVEL, INDENT, type->info.ident.ref->name); |
| 148 | } else { |
| 149 | fprintf(f, "%*sbase %s:%s;\n", LEVEL, INDENT, type->info.ident.ref->module->prefix, |
| 150 | type->info.ident.ref->name); |
| 151 | } |
| 152 | break; |
| 153 | case LY_TYPE_INST: |
| 154 | /* TODO */ |
| 155 | break; |
| 156 | case LY_TYPE_INT8: |
| 157 | case LY_TYPE_INT16: |
| 158 | case LY_TYPE_INT32: |
| 159 | case LY_TYPE_INT64: |
| 160 | case LY_TYPE_UINT8: |
| 161 | case LY_TYPE_UINT16: |
| 162 | case LY_TYPE_UINT32: |
| 163 | case LY_TYPE_UINT64: |
| 164 | /* TODO wrong - incomplete */ |
| 165 | /*if (type->info.num.range != NULL) { |
| 166 | * fprintf(f, "%*srange \"%s\";\n", LEVEL, INDENT, type->info.num.range); |
| 167 | * } */ |
| 168 | break; |
| 169 | case LY_TYPE_LEAFREF: |
| 170 | fprintf(f, "%*spath \"%s\";\n", LEVEL, INDENT, type->info.lref.path); |
| 171 | break; |
| 172 | case LY_TYPE_STRING: |
| 173 | /* TODO length, pattern (same as range) incomplete */ |
| 174 | break; |
| 175 | case LY_TYPE_UNION: |
| 176 | for (i = 0; i < type->info.uni.count; ++i) { |
| 177 | yang_print_type(f, level, module, &type->info.uni.type[i]); |
| 178 | } |
| 179 | break; |
| 180 | default: |
| 181 | /* other types do not have substatements */ |
| 182 | break; |
| 183 | } |
| 184 | level--; |
| 185 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 186 | } |
| 187 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 188 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 189 | yang_print_must(FILE *f, int level, struct ly_must *must) |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 190 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 191 | fprintf(f, "%*smust \"%s\" {\n", LEVEL, INDENT, must->cond); |
| 192 | level++; |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 193 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 194 | if (must->eapptag != NULL) { |
| 195 | fprintf(f, "%*serror-app-tag \"%s\";\n", LEVEL, INDENT, must->eapptag); |
| 196 | } |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 197 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 198 | if (must->emsg != NULL) { |
| 199 | yang_print_text(f, level, "error-message", must->emsg); |
| 200 | } |
| 201 | if (must->dsc != NULL) { |
| 202 | yang_print_text(f, level, "description", must->dsc); |
| 203 | } |
| 204 | if (must->ref != NULL) { |
| 205 | yang_print_text(f, level, "reference", must->ref); |
| 206 | } |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 207 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 208 | level--; |
| 209 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 212 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 213 | yang_print_refine(FILE *f, int level, struct ly_refine *refine) |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 214 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 215 | int i; |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 216 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 217 | fprintf(f, "%*srefine \"%s\" {\n", LEVEL, INDENT, refine->target); |
| 218 | level++; |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 219 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 220 | yang_print_mnode_common2(f, level, (struct ly_mnode *)refine); |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 221 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 222 | for (i = 0; i < refine->must_size; ++i) { |
| 223 | yang_print_must(f, level, &refine->must[i]); |
| 224 | } |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 225 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 226 | if (refine->target_type & (LY_NODE_LEAF | LY_NODE_CHOICE)) { |
| 227 | if (refine->mod.dflt != NULL) { |
| 228 | fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, refine->mod.dflt); |
| 229 | } |
| 230 | } else if (refine->target_type == LY_NODE_CONTAINER) { |
| 231 | if (refine->mod.presence != NULL) { |
| 232 | yang_print_text(f, level, "presence", refine->mod.presence); |
| 233 | } |
| 234 | } else if (refine->target_type & (LY_NODE_LIST | LY_NODE_LEAFLIST)) { |
| 235 | if (refine->mod.list.min > 0) { |
| 236 | fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, refine->mod.list.min); |
| 237 | } |
| 238 | if (refine->mod.list.max > 0) { |
| 239 | fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, refine->mod.list.max); |
| 240 | } |
| 241 | } |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 242 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 243 | level--; |
| 244 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 245 | } |
| 246 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 247 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 248 | 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] | 249 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 250 | fprintf(f, "%*stypedef %s {\n", LEVEL, INDENT, tpdf->name); |
| 251 | level++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 252 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 253 | yang_print_mnode_common(f, level, (struct ly_mnode *)tpdf); |
| 254 | yang_print_type(f, level, module, &tpdf->type); |
| 255 | if (tpdf->units != NULL) { |
| 256 | fprintf(f, "%*sunits \"%s\";\n", LEVEL, INDENT, tpdf->units); |
| 257 | } |
| 258 | if (tpdf->dflt != NULL) { |
| 259 | fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, tpdf->dflt); |
| 260 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 261 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 262 | level--; |
| 263 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 264 | } |
| 265 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 266 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 267 | yang_print_identity(FILE *f, int level, struct ly_ident *ident) |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 268 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 269 | fprintf(f, "%*sidentity %s {\n", LEVEL, INDENT, ident->name); |
| 270 | level++; |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 271 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 272 | yang_print_mnode_common(f, level, (struct ly_mnode *)ident); |
| 273 | if (ident->base) { |
| 274 | if (ident->base->module == ident->module) { |
| 275 | fprintf(f, "%*sbase %s;\n", LEVEL, INDENT, ident->base->name); |
| 276 | } else { |
| 277 | fprintf(f, "%*sbase %s:%s;\n", LEVEL, INDENT, ident->base->module->prefix, ident->base->name); |
| 278 | } |
| 279 | } |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 280 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 281 | level--; |
| 282 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 283 | |
| 284 | } |
| 285 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 286 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 287 | yang_print_container(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 288 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 289 | int i; |
| 290 | struct ly_mnode *sub; |
| 291 | struct ly_mnode_container *cont = (struct ly_mnode_container *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 292 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 293 | fprintf(f, "%*scontainer %s {\n", LEVEL, INDENT, mnode->name); |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 294 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 295 | level++; |
| 296 | if (cont->presence != NULL) { |
| 297 | yang_print_text(f, level, "presence", cont->presence); |
| 298 | } |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 299 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 300 | for (i = 0; i < cont->must_size; i++) { |
| 301 | yang_print_must(f, level, &cont->must[i]); |
| 302 | } |
Michal Vasko | 7f976ee | 2015-06-09 13:55:41 +0200 | [diff] [blame] | 303 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 304 | yang_print_mnode_common2(f, level, mnode); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 305 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 306 | for (i = 0; i < cont->tpdf_size; i++) { |
| 307 | yang_print_typedef(f, level, mnode->module, &cont->tpdf[i]); |
| 308 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 309 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 310 | LY_TREE_FOR(mnode->child, sub) { |
| 311 | yang_print_mnode(f, level, sub, |
| 312 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 313 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 314 | } |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 315 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 316 | level--; |
| 317 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 318 | } |
| 319 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 320 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 321 | yang_print_case(FILE *f, int level, struct ly_mnode *mnode) |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 322 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 323 | struct ly_mnode *sub; |
| 324 | struct ly_mnode_case *cas = (struct ly_mnode_case *)mnode; |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 325 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 326 | fprintf(f, "%*scase %s {\n", LEVEL, INDENT, cas->name); |
| 327 | level++; |
| 328 | yang_print_mnode_common2(f, level, mnode); |
Michal Vasko | c1329bc | 2015-06-09 13:58:18 +0200 | [diff] [blame] | 329 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 330 | LY_TREE_FOR(mnode->child, sub) { |
| 331 | yang_print_mnode(f, level, sub, |
| 332 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 333 | LY_NODE_USES | LY_NODE_ANYXML); |
| 334 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 335 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 336 | level--; |
| 337 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 338 | } |
| 339 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 340 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 341 | yang_print_choice(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 342 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 343 | struct ly_mnode *sub; |
| 344 | struct ly_mnode_choice *choice = (struct ly_mnode_choice *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 345 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 346 | fprintf(f, "%*schoice %s {\n", LEVEL, INDENT, mnode->name); |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 347 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 348 | level++; |
| 349 | if (choice->dflt != NULL) { |
| 350 | fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, choice->dflt->name); |
| 351 | } |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 352 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 353 | yang_print_mnode_common2(f, level, mnode); |
| 354 | LY_TREE_FOR(mnode->child, sub) { |
| 355 | yang_print_mnode(f, level, sub, |
| 356 | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML | LY_NODE_CASE); |
| 357 | } |
| 358 | level--; |
| 359 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 360 | } |
| 361 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 362 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 363 | yang_print_leaf(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 364 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 365 | int i; |
| 366 | struct ly_mnode_leaf *leaf = (struct ly_mnode_leaf *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 367 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 368 | fprintf(f, "%*sleaf %s {\n", LEVEL, INDENT, mnode->name); |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 369 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 370 | level++; |
| 371 | yang_print_mnode_common2(f, level, mnode); |
| 372 | for (i = 0; i < leaf->must_size; i++) { |
| 373 | yang_print_must(f, level, &leaf->must[i]); |
| 374 | } |
| 375 | yang_print_type(f, level, mnode->module, &leaf->type); |
| 376 | if (leaf->units != NULL) { |
| 377 | fprintf(f, "%*sunits \"%s\";\n", LEVEL, INDENT, leaf->units); |
| 378 | } |
| 379 | if (leaf->dflt != NULL) { |
| 380 | fprintf(f, "%*sdefault \"%s\";\n", LEVEL, INDENT, leaf->dflt); |
| 381 | } |
| 382 | level--; |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 383 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 384 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 385 | } |
| 386 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 387 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 388 | yang_print_anyxml(FILE *f, int level, struct ly_mnode *mnode) |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 389 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 390 | int i; |
| 391 | struct ly_mnode_anyxml *anyxml = (struct ly_mnode_anyxml *)mnode; |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 392 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 393 | fprintf(f, "%*sanyxml %s {\n", LEVEL, INDENT, anyxml->name); |
| 394 | level++; |
| 395 | yang_print_mnode_common2(f, level, mnode); |
| 396 | for (i = 0; i < anyxml->must_size; i++) { |
| 397 | yang_print_must(f, level, &anyxml->must[i]); |
| 398 | } |
| 399 | level--; |
| 400 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 403 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 404 | yang_print_leaflist(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 405 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 406 | int i; |
| 407 | struct ly_mnode_leaflist *llist = (struct ly_mnode_leaflist *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 408 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 409 | fprintf(f, "%*sleaf-list %s {\n", LEVEL, INDENT, mnode->name); |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 410 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 411 | level++; |
| 412 | yang_print_mnode_common2(f, level, mnode); |
| 413 | if (llist->flags & LY_NODE_USERORDERED) { |
| 414 | fprintf(f, "%*sordered-by user;\n", LEVEL, INDENT); |
| 415 | } |
| 416 | if (llist->min > 0) { |
| 417 | fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, llist->min); |
| 418 | } |
| 419 | if (llist->max > 0) { |
| 420 | fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, llist->max); |
| 421 | } |
| 422 | for (i = 0; i < llist->must_size; i++) { |
| 423 | yang_print_must(f, level, &llist->must[i]); |
| 424 | } |
| 425 | yang_print_type(f, level, mnode->module, &llist->type); |
| 426 | if (llist->units != NULL) { |
| 427 | fprintf(f, "%*sunits \"%s\";\n", LEVEL, INDENT, llist->units); |
| 428 | } |
| 429 | level--; |
Michal Vasko | 1608366 | 2015-06-09 14:00:45 +0200 | [diff] [blame] | 430 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 431 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 432 | } |
| 433 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 434 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 435 | yang_print_list(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 436 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 437 | int i, j; |
| 438 | struct ly_mnode *sub; |
| 439 | struct ly_unique *uniq; |
| 440 | struct ly_mnode_list *list = (struct ly_mnode_list *)mnode; |
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, "%*slist %s {\n", LEVEL, INDENT, mnode->name); |
| 443 | level++; |
| 444 | yang_print_mnode_common2(f, level, mnode); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 445 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 446 | if (list->keys_size) { |
| 447 | fprintf(f, "%*skey \"", LEVEL, INDENT); |
| 448 | for (i = 0; i < list->keys_size; i++) { |
| 449 | fprintf(f, "%s%s", list->keys[i]->name, i + 1 < list->keys_size ? " " : ""); |
| 450 | } |
| 451 | fprintf(f, "\";\n"); |
| 452 | } |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 453 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 454 | for (i = 0; i < list->unique_size; i++) { |
| 455 | uniq = &list->unique[i]; |
| 456 | fprintf(f, "%*sunique \"", LEVEL, INDENT); |
| 457 | for (j = 0; j < uniq->leafs_size; j++) { |
| 458 | fprintf(f, "%s%s", uniq->leafs[j]->name, j + 1 < uniq->leafs_size ? " " : ""); |
| 459 | } |
| 460 | fprintf(f, "\";\n"); |
| 461 | } |
Michal Vasko | dff818b | 2015-06-09 14:01:12 +0200 | [diff] [blame] | 462 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 463 | if (list->flags & LY_NODE_USERORDERED) { |
| 464 | fprintf(f, "%*sordered-by user;\n", LEVEL, INDENT); |
| 465 | } |
| 466 | if (list->min > 0) { |
| 467 | fprintf(f, "%*smin-elements %u;\n", LEVEL, INDENT, list->min); |
| 468 | } |
| 469 | if (list->max > 0) { |
| 470 | fprintf(f, "%*smax-elements %u;\n", LEVEL, INDENT, list->max); |
| 471 | } |
| 472 | for (i = 0; i < list->must_size; i++) { |
| 473 | yang_print_must(f, level, &list->must[i]); |
| 474 | } |
Michal Vasko | dff818b | 2015-06-09 14:01:12 +0200 | [diff] [blame] | 475 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 476 | for (i = 0; i < list->tpdf_size; i++) { |
| 477 | yang_print_typedef(f, level, list->module, &list->tpdf[i]); |
| 478 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 479 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 480 | LY_TREE_FOR(mnode->child, sub) { |
| 481 | yang_print_mnode(f, level, sub, |
| 482 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 483 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 484 | } |
| 485 | level--; |
| 486 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 487 | } |
| 488 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 489 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 490 | yang_print_grouping(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 491 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 492 | int i; |
| 493 | struct ly_mnode *node; |
| 494 | struct ly_mnode_grp *grp = (struct ly_mnode_grp *)mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 495 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 496 | fprintf(f, "%*sgrouping %s {\n", LEVEL, INDENT, mnode->name); |
| 497 | level++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 498 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 499 | yang_print_mnode_common(f, level, mnode); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 500 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 501 | for (i = 0; i < grp->tpdf_size; i++) { |
| 502 | yang_print_typedef(f, level, mnode->module, &grp->tpdf[i]); |
| 503 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 504 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 505 | LY_TREE_FOR(mnode->child, node) { |
| 506 | yang_print_mnode(f, level, node, |
| 507 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 508 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 509 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 510 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 511 | level--; |
| 512 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 513 | } |
| 514 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 515 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 516 | yang_print_uses(FILE *f, int level, struct ly_mnode *mnode) |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 517 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 518 | int i; |
| 519 | struct ly_mnode_uses *uses = (struct ly_mnode_uses *)mnode; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 520 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 521 | fprintf(f, "%*suses %s {\n", LEVEL, INDENT, uses->name); |
| 522 | level++; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 523 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 524 | yang_print_mnode_common(f, level, mnode); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 525 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 526 | for (i = 0; i < uses->refine_size; i++) { |
| 527 | yang_print_refine(f, level, &uses->refine[i]); |
| 528 | } |
Michal Vasko | 00b7cfe | 2015-06-09 13:56:38 +0200 | [diff] [blame] | 529 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 530 | level--; |
| 531 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 532 | } |
| 533 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 534 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 535 | yang_print_input_output(FILE *f, int level, struct ly_mnode *mnode) |
| 536 | { |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 537 | int i; |
| 538 | struct ly_mnode *sub; |
Michal Vasko | fb69a84 | 2015-06-16 12:07:40 +0200 | [diff] [blame] | 539 | struct ly_mnode_input_output *inout = (struct ly_mnode_input_output *)mnode; |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 540 | |
| 541 | fprintf(f, "%*s%s {\n", LEVEL, INDENT, (inout->nodetype == LY_NODE_INPUT ? "input" : "output")); |
| 542 | |
| 543 | level++; |
| 544 | for (i = 0; i < inout->tpdf_size; i++) { |
| 545 | yang_print_typedef(f, level, mnode->module, &inout->tpdf[i]); |
| 546 | } |
| 547 | |
| 548 | LY_TREE_FOR(mnode->child, sub) { |
| 549 | yang_print_mnode(f, level, sub, |
| 550 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 551 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 552 | } |
| 553 | |
| 554 | level--; |
| 555 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 556 | } |
| 557 | |
| 558 | static void |
| 559 | yang_print_rpc(FILE *f, int level, struct ly_mnode *mnode) |
| 560 | { |
| 561 | int i; |
| 562 | struct ly_mnode *sub; |
| 563 | struct ly_mnode_rpc *rpc = (struct ly_mnode_rpc *)mnode; |
| 564 | |
| 565 | fprintf(f, "%*srpc %s {\n", LEVEL, INDENT, mnode->name); |
| 566 | |
| 567 | level++; |
| 568 | yang_print_mnode_common(f, level, mnode); |
| 569 | |
| 570 | for (i = 0; i < rpc->tpdf_size; i++) { |
| 571 | yang_print_typedef(f, level, mnode->module, &rpc->tpdf[i]); |
| 572 | } |
| 573 | |
| 574 | LY_TREE_FOR(mnode->child, sub) { |
| 575 | yang_print_mnode(f, level, sub, |
| 576 | LY_NODE_GROUPING | LY_NODE_INPUT | LY_NODE_OUTPUT); |
| 577 | } |
| 578 | |
| 579 | level--; |
| 580 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 581 | } |
| 582 | |
| 583 | static void |
| 584 | yang_print_notif(FILE *f, int level, struct ly_mnode *mnode) { |
| 585 | int i; |
| 586 | struct ly_mnode *sub; |
| 587 | struct ly_mnode_notif *notif = (struct ly_mnode_notif *)mnode; |
| 588 | |
| 589 | fprintf(f, "%*snotification %s {\n", LEVEL, INDENT, mnode->name); |
| 590 | |
| 591 | level++; |
| 592 | yang_print_mnode_common(f, level, mnode); |
| 593 | |
| 594 | for (i = 0; i < notif->tpdf_size; i++) { |
| 595 | yang_print_typedef(f, level, mnode->module, ¬if->tpdf[i]); |
| 596 | } |
| 597 | |
| 598 | LY_TREE_FOR(mnode->child, sub) { |
| 599 | yang_print_mnode(f, level, sub, |
| 600 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 601 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 602 | } |
| 603 | |
| 604 | level--; |
| 605 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 606 | } |
| 607 | |
| 608 | static void |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 609 | 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] | 610 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 611 | switch (mnode->nodetype & mask) { |
| 612 | case LY_NODE_CONTAINER: |
| 613 | yang_print_container(f, level, mnode); |
| 614 | break; |
| 615 | case LY_NODE_CHOICE: |
| 616 | yang_print_choice(f, level, mnode); |
| 617 | break; |
| 618 | case LY_NODE_LEAF: |
| 619 | yang_print_leaf(f, level, mnode); |
| 620 | break; |
| 621 | case LY_NODE_LEAFLIST: |
| 622 | yang_print_leaflist(f, level, mnode); |
| 623 | break; |
| 624 | case LY_NODE_LIST: |
| 625 | yang_print_list(f, level, mnode); |
| 626 | break; |
| 627 | case LY_NODE_USES: |
| 628 | yang_print_uses(f, level, mnode); |
| 629 | break; |
| 630 | case LY_NODE_GROUPING: |
| 631 | yang_print_grouping(f, level, mnode); |
| 632 | break; |
| 633 | case LY_NODE_ANYXML: |
| 634 | yang_print_anyxml(f, level, mnode); |
| 635 | break; |
| 636 | case LY_NODE_CASE: |
| 637 | yang_print_case(f, level, mnode); |
| 638 | break; |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 639 | case LY_NODE_INPUT: |
| 640 | case LY_NODE_OUTPUT: |
| 641 | yang_print_input_output(f, level, mnode); |
| 642 | break; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 643 | default: |
| 644 | break; |
| 645 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 646 | } |
| 647 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 648 | int |
Michal Vasko | 5bbae10 | 2015-06-16 12:16:44 +0200 | [diff] [blame^] | 649 | yang_print_model(FILE *f, struct ly_module *module) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 650 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 651 | unsigned int i; |
| 652 | int level = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 653 | #define LEVEL (level*2) |
| 654 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 655 | struct ly_mnode *mnode; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 656 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 657 | fprintf(f, "module %s {\n", module->name); |
| 658 | level++; |
Radek Krejci | b0594bf | 2015-05-21 23:51:27 +0200 | [diff] [blame] | 659 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 660 | fprintf(f, "%*snamespace \"%s\";\n", LEVEL, INDENT, module->ns); |
| 661 | fprintf(f, "%*sprefix \"%s\";\n", LEVEL, INDENT, module->prefix); |
Radek Krejci | b0594bf | 2015-05-21 23:51:27 +0200 | [diff] [blame] | 662 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 663 | if (module->version) { |
| 664 | fprintf(f, "%*syang-version \"%s\";\n", LEVEL, INDENT, module->version == 1 ? "1.0" : "1.1"); |
| 665 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 666 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 667 | for (i = 0; i < module->imp_size; i++) { |
| 668 | fprintf(f, "%*simport \"%s\" {\n", LEVEL, INDENT, module->imp[i].module->name); |
| 669 | level++; |
| 670 | yang_print_text(f, level, "prefix", module->imp[i].prefix); |
| 671 | if (module->imp[i].rev[0]) { |
| 672 | yang_print_text(f, level, "revision-date", module->imp[i].rev); |
| 673 | } |
| 674 | level--; |
| 675 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 676 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 677 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 678 | for (i = 0; i < module->inc_size; i++) { |
| 679 | if (module->inc[i].rev[0]) { |
| 680 | fprintf(f, "%*sinclude \"%s\" {\n", LEVEL, INDENT, module->inc[i].submodule->name); |
| 681 | yang_print_text(f, level + 1, "revision-date", module->imp[i].rev); |
| 682 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 683 | } else { |
| 684 | fprintf(f, "%*sinclude \"%s\";\n", LEVEL, INDENT, module->inc[i].submodule->name); |
| 685 | } |
| 686 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 687 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 688 | if (module->org) { |
| 689 | yang_print_text(f, level, "organization", module->org); |
| 690 | } |
| 691 | if (module->contact) { |
| 692 | yang_print_text(f, level, "contact", module->contact); |
| 693 | } |
| 694 | if (module->dsc) { |
| 695 | yang_print_text(f, level, "description", module->dsc); |
| 696 | } |
| 697 | if (module->ref) { |
| 698 | yang_print_text(f, level, "reference", module->ref); |
| 699 | } |
| 700 | for (i = 0; i < module->rev_size; i++) { |
| 701 | if (module->rev[i].dsc || module->rev[i].ref) { |
| 702 | fprintf(f, "%*srevision \"%s\" {\n", LEVEL, INDENT, module->rev[i].date); |
| 703 | level++; |
| 704 | if (module->rev[i].dsc) { |
| 705 | yang_print_text(f, level, "description", module->rev[i].dsc); |
| 706 | } |
| 707 | if (module->rev[i].ref) { |
| 708 | yang_print_text(f, level, "reference", module->rev[i].ref); |
| 709 | } |
| 710 | level--; |
| 711 | fprintf(f, "%*s}\n", LEVEL, INDENT); |
| 712 | } else { |
| 713 | yang_print_text(f, level, "revision", module->rev[i].date); |
| 714 | } |
| 715 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 716 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 717 | for (i = 0; i < module->ident_size; i++) { |
| 718 | yang_print_identity(f, level, &module->ident[i]); |
| 719 | } |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 720 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 721 | for (i = 0; i < module->tpdf_size; i++) { |
| 722 | yang_print_typedef(f, level, module, &module->tpdf[i]); |
| 723 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 724 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 725 | LY_TREE_FOR(module->data, mnode) { |
| 726 | yang_print_mnode(f, level, mnode, |
| 727 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | |
| 728 | LY_NODE_USES | LY_NODE_GROUPING | LY_NODE_ANYXML); |
| 729 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 730 | |
Michal Vasko | f4d3d74 | 2015-06-16 11:51:09 +0200 | [diff] [blame] | 731 | LY_TREE_FOR(module->rpc, mnode) { |
| 732 | yang_print_rpc(f, level, mnode); |
| 733 | } |
| 734 | |
| 735 | LY_TREE_FOR(module->notif, mnode) { |
| 736 | yang_print_notif(f, level, mnode); |
| 737 | } |
| 738 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 739 | fprintf(f, "}\n"); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 740 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 741 | return EXIT_SUCCESS; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 742 | #undef LEVEL |
| 743 | } |