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