Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file printer/tree.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief TREE printer for libyang data model structure |
| 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> |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 25 | #include <assert.h> |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 26 | |
| 27 | #include "../common.h" |
| 28 | #include "../tree.h" |
| 29 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 30 | /* spec_config = 0 (no special config status), 1 (read-only - rpc output, notification), 2 (write-only - rpc input) */ |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 31 | static void tree_print_mnode_choice(FILE *f, struct ly_module* module, int level, char *indent, unsigned int max_name_len, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 32 | struct ly_mnode *mnode, int mask, int spec_config, struct ly_submodule *main_submod); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 33 | static void tree_print_mnode(FILE *f, struct ly_module *module, int level, char *indent, unsigned int max_name_len, struct ly_mnode *mnode, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 34 | int mask, int spec_config, struct ly_submodule *main_submod); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 35 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 36 | static int |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 37 | is_enabled(struct ly_mnode *mnode) |
| 38 | { |
| 39 | int i; |
| 40 | |
| 41 | for (i = 0; i < mnode->features_size; i++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 42 | if (!(mnode->features[i]->flags & LYS_FENABLED)) { |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 43 | return 0; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | if (mnode->parent && (mnode->parent->nodetype == LY_NODE_AUGMENT)) { |
| 48 | for (i = 0; i < mnode->parent->features_size; i++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 49 | if (!(mnode->parent->features[i]->flags & LYS_FENABLED)) { |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 50 | return 0; |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | static int |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 59 | sibling_is_valid_child(const struct ly_mnode *mnode, int including) |
Michal Vasko | 6db4fce | 2015-06-08 14:13:49 +0200 | [diff] [blame] | 60 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 61 | struct ly_mnode *cur; |
Michal Vasko | 7ea0a31 | 2015-06-08 10:36:48 +0200 | [diff] [blame] | 62 | |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 63 | if (mnode == NULL) { |
| 64 | return 0; |
| 65 | } |
Michal Vasko | 7ea0a31 | 2015-06-08 10:36:48 +0200 | [diff] [blame] | 66 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 67 | /* has a following printed child */ |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 68 | LY_TREE_FOR((struct ly_mnode *)(including ? mnode : mnode->next), cur) { |
Michal Vasko | 3d53afd | 2015-07-08 10:38:09 +0200 | [diff] [blame] | 69 | if (is_enabled(cur) && (cur->nodetype & |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 70 | (LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML | LY_NODE_CHOICE | |
Michal Vasko | 3d53afd | 2015-07-08 10:38:09 +0200 | [diff] [blame] | 71 | LY_NODE_RPC | LY_NODE_INPUT | LY_NODE_OUTPUT | LY_NODE_NOTIF | LY_NODE_CASE))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 72 | return 1; |
| 73 | } |
| 74 | } |
Michal Vasko | 7ea0a31 | 2015-06-08 10:36:48 +0200 | [diff] [blame] | 75 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 76 | /* if in uses, the following printed child can actually be in the parent node :-/ */ |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 77 | if (mnode->parent && mnode->parent->nodetype == LY_NODE_USES) { |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 78 | return sibling_is_valid_child(mnode->parent, 0); |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 81 | return 0; |
Michal Vasko | 7ea0a31 | 2015-06-08 10:36:48 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 84 | static char * |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 85 | create_indent(int level, const char *old_indent, const struct ly_mnode *mnode, int shorthand, struct ly_submodule *main_submod) |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 86 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 87 | int next_is_case = 0, is_case = 0, has_next = 0, i, found; |
| 88 | char *new_indent = malloc((level * 4 + 1) * sizeof (char)); |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 89 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 90 | strcpy(new_indent, old_indent); |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 91 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 92 | /* this is the indent of a case (standard or shorthand) */ |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 93 | if ((mnode->nodetype == LY_NODE_CASE) || shorthand) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 94 | is_case = 1; |
| 95 | } |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 96 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 97 | /* this is the direct child of a case */ |
| 98 | if (!is_case && mnode->parent && (mnode->parent->nodetype & (LY_NODE_CASE | LY_NODE_CHOICE))) { |
| 99 | /* it is not the only child */ |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 100 | if (mnode->next && mnode->next->parent && (mnode->next->parent->nodetype == LY_NODE_CHOICE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 101 | next_is_case = 1; |
| 102 | } |
| 103 | } |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 104 | |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 105 | /* next is a node that will actually be printed */ |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 106 | has_next = sibling_is_valid_child(mnode, 0); |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 107 | |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 108 | /* there is no next, but we are in top-level of a submodule */ |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 109 | if (!has_next && (mnode->module->type == 1) && !mnode->parent) { |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 110 | struct ly_submodule *submod = (struct ly_submodule *)mnode->module; |
| 111 | struct ly_module *mod = submod->belongsto; |
Michal Vasko | 1441046 | 2015-06-05 15:08:54 +0200 | [diff] [blame] | 112 | |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 113 | /* a special case when we check the includes of a submodule */ |
| 114 | if (main_submod) { |
| 115 | if (submod != main_submod) { |
| 116 | found = 0; |
| 117 | for (i = 0; i < main_submod->inc_size; i++) { |
| 118 | if (found) { |
| 119 | if (mnode->nodetype == LY_NODE_RPC) { |
| 120 | has_next = sibling_is_valid_child(main_submod->inc[i].submodule->rpc, 1); |
| 121 | } else if (mnode->nodetype == LY_NODE_NOTIF) { |
| 122 | has_next = sibling_is_valid_child(main_submod->inc[i].submodule->notif, 1); |
| 123 | } else { |
| 124 | has_next = sibling_is_valid_child(main_submod->inc[i].submodule->data, 1); |
| 125 | } |
| 126 | if (has_next) { |
| 127 | break; |
| 128 | } |
| 129 | } |
| 130 | if (!found && (submod == main_submod->inc[i].submodule)) { |
| 131 | found = 1; |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | if (!has_next) { |
| 136 | if (mnode->nodetype == LY_NODE_RPC) { |
| 137 | has_next = sibling_is_valid_child(main_submod->rpc, 1); |
| 138 | } else if (mnode->nodetype == LY_NODE_NOTIF) { |
| 139 | has_next = sibling_is_valid_child(main_submod->notif, 1); |
| 140 | } else { |
| 141 | has_next = sibling_is_valid_child(main_submod->data, 1); |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | goto strcat_indent; |
| 147 | } |
| 148 | |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 149 | /* find this submodule, check all the next ones for valid printed nodes */ |
| 150 | found = 0; |
| 151 | for (i = 0; i < mod->inc_size; i++) { |
| 152 | /* we found ours, check all the following submodules and the module */ |
| 153 | if (found) { |
Michal Vasko | f289630 | 2015-06-16 09:30:02 +0200 | [diff] [blame] | 154 | if (mnode->nodetype == LY_NODE_RPC) { |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 155 | has_next = sibling_is_valid_child(mod->inc[i].submodule->rpc, 1); |
Michal Vasko | f289630 | 2015-06-16 09:30:02 +0200 | [diff] [blame] | 156 | } else if (mnode->nodetype == LY_NODE_NOTIF) { |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 157 | has_next = sibling_is_valid_child(mod->inc[i].submodule->notif, 1); |
Michal Vasko | f289630 | 2015-06-16 09:30:02 +0200 | [diff] [blame] | 158 | } else { |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 159 | has_next = sibling_is_valid_child(mod->inc[i].submodule->data, 1); |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 160 | } |
Michal Vasko | 5c7686d | 2015-07-08 13:36:21 +0200 | [diff] [blame] | 161 | if (has_next) { |
| 162 | break; |
| 163 | } |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 164 | } |
Michal Vasko | 5c7686d | 2015-07-08 13:36:21 +0200 | [diff] [blame] | 165 | if (!found && (submod == mod->inc[i].submodule)) { |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 166 | found = 1; |
| 167 | } |
| 168 | } |
Michal Vasko | 7ea0a31 | 2015-06-08 10:36:48 +0200 | [diff] [blame] | 169 | |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 170 | /* there is nothing in submodules, check module */ |
| 171 | if (!has_next) { |
Michal Vasko | f289630 | 2015-06-16 09:30:02 +0200 | [diff] [blame] | 172 | if (mnode->nodetype == LY_NODE_RPC) { |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 173 | has_next = sibling_is_valid_child(mod->rpc, 1); |
Michal Vasko | f289630 | 2015-06-16 09:30:02 +0200 | [diff] [blame] | 174 | } else if (mnode->nodetype == LY_NODE_NOTIF) { |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 175 | has_next = sibling_is_valid_child(mod->notif, 1); |
Michal Vasko | f289630 | 2015-06-16 09:30:02 +0200 | [diff] [blame] | 176 | } else { |
Michal Vasko | 73f94a8 | 2015-06-29 16:00:07 +0200 | [diff] [blame] | 177 | has_next = sibling_is_valid_child(mod->data, 1); |
Michal Vasko | 07898f9 | 2015-06-15 12:17:11 +0200 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | } |
| 181 | |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 182 | strcat_indent: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 183 | if (has_next && !next_is_case) { |
| 184 | strcat(new_indent, "| "); |
| 185 | } else { |
| 186 | strcat(new_indent, " "); |
| 187 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 188 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 189 | return new_indent; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 190 | } |
| 191 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 192 | static unsigned int |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 193 | get_max_name_len(struct ly_module *module, struct ly_mnode *mnode) |
Michal Vasko | 8d479bd | 2015-06-05 10:50:03 +0200 | [diff] [blame] | 194 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 195 | struct ly_mnode *sub; |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 196 | unsigned int max_name_len = 0, uses_max_name_len, name_len; |
Michal Vasko | 8d479bd | 2015-06-05 10:50:03 +0200 | [diff] [blame] | 197 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 198 | LY_TREE_FOR(mnode, sub) { |
| 199 | if (sub->nodetype == LY_NODE_USES) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 200 | uses_max_name_len = get_max_name_len(module, sub->child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 201 | if (uses_max_name_len > max_name_len) { |
| 202 | max_name_len = uses_max_name_len; |
| 203 | } |
| 204 | } else if (sub->nodetype & |
Michal Vasko | a4d19d4 | 2015-07-07 16:10:48 +0200 | [diff] [blame] | 205 | (LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
| 206 | | LY_NODE_ANYXML | LY_NODE_CASE)) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 207 | name_len = strlen(sub->name) + (module == sub->module ? 0 : strlen(sub->module->prefix)+1); |
| 208 | if (name_len > max_name_len) { |
| 209 | max_name_len = name_len; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | } |
Michal Vasko | 8d479bd | 2015-06-05 10:50:03 +0200 | [diff] [blame] | 213 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 214 | return max_name_len; |
Michal Vasko | 8d479bd | 2015-06-05 10:50:03 +0200 | [diff] [blame] | 215 | } |
| 216 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 217 | static void |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 218 | tree_print_type(FILE *f, struct lys_type *type) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 219 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 220 | if (type->base == LY_TYPE_LEAFREF) { |
| 221 | fprintf(f, "-> %s", type->info.lref.path); |
| 222 | } else if (type->prefix) { |
| 223 | fprintf(f, "%s:%s", type->prefix, type->der->name); |
| 224 | } else { |
| 225 | fprintf(f, "%s", type->der->name); |
| 226 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 229 | static void |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 230 | tree_print_features(FILE *f, const struct ly_feature **features, uint8_t features_size) |
| 231 | { |
| 232 | int i; |
| 233 | |
| 234 | if (!features_size) { |
| 235 | return; |
| 236 | } |
| 237 | |
| 238 | fprintf(f, " {"); |
| 239 | for (i = 0; i < features_size; i++) { |
| 240 | if (i > 0) { |
| 241 | fprintf(f, ","); |
| 242 | } |
| 243 | fprintf(f, "%s", features[i]->name); |
| 244 | } |
| 245 | fprintf(f, "}?"); |
| 246 | } |
| 247 | |
| 248 | static void |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 249 | tree_print_input_output(FILE *f, struct ly_module *module, int level, char *indent, struct ly_mnode *mnode, int spec_config, struct ly_submodule *main_submod) |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 250 | { |
| 251 | unsigned int max_child_len; |
| 252 | char *new_indent; |
| 253 | struct ly_mnode *sub; |
| 254 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 255 | assert(spec_config); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 256 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 257 | fprintf(f, "%s+--%s %s\n", indent, (spec_config == 1 ? "-w" : "ro"), (spec_config == 1 ? "input" : "output")); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 258 | |
| 259 | level++; |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 260 | new_indent = create_indent(level, indent, mnode, 0, main_submod); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 261 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 262 | max_child_len = get_max_name_len(module, mnode->child); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 263 | |
| 264 | LY_TREE_FOR(mnode->child, sub) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 265 | tree_print_mnode(f, module, level, new_indent, max_child_len, sub, |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 266 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML | LY_NODE_USES, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 267 | spec_config, main_submod); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | free(new_indent); |
| 271 | } |
| 272 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 273 | static void |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 274 | tree_print_container(FILE *f, struct ly_module *module, int level, char *indent, struct ly_mnode *mnode, int spec_config, struct ly_submodule *main_submod) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 275 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 276 | unsigned int max_child_len; |
| 277 | char *new_indent; |
| 278 | struct ly_mnode_container *cont = (struct ly_mnode_container *)mnode; |
| 279 | struct ly_mnode *sub; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 280 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 281 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 282 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 283 | fprintf(f, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 284 | (cont->flags & LYS_STATUS_DEPRC ? "x" : (cont->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 285 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 286 | if (spec_config == 0) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 287 | fprintf(f, "%s ", (cont->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 288 | } else if (spec_config == 1) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 289 | fprintf(f, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 290 | } else if (spec_config == 2) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 291 | fprintf(f, "ro "); |
| 292 | } |
| 293 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 294 | if (module != cont->module) { |
| 295 | fprintf(f, "%s:", cont->module->prefix); |
| 296 | } |
| 297 | |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 298 | fprintf(f, "%s%s", cont->name, (cont->presence ? "!" : "")); |
| 299 | |
| 300 | tree_print_features(f, (const struct ly_feature **)cont->features, cont->features_size); |
| 301 | |
| 302 | fprintf(f, "\n"); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 303 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 304 | level++; |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 305 | new_indent = create_indent(level, indent, mnode, 0, main_submod); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 306 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 307 | max_child_len = get_max_name_len(module, mnode->child); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 308 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 309 | LY_TREE_FOR(cont->child, sub) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 310 | tree_print_mnode(f, module, level, new_indent, max_child_len, sub, |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 311 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML | LY_NODE_USES, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 312 | spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 313 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 314 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 315 | free(new_indent); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 316 | } |
| 317 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 318 | static void |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 319 | tree_print_choice(FILE *f, struct ly_module *module, int level, char *indent, struct ly_mnode *mnode, int spec_config, struct ly_submodule *main_submod) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 320 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 321 | unsigned int max_child_len; |
| 322 | char *new_indent; |
| 323 | struct ly_mnode_choice *choice = (struct ly_mnode_choice *)mnode; |
| 324 | struct ly_mnode *sub; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 325 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 326 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 327 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 328 | fprintf(f, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 329 | (choice->flags & LYS_STATUS_DEPRC ? "x" : (choice->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 330 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 331 | if (spec_config == 0) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 332 | fprintf(f, "%s ", (choice->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 333 | } else if (spec_config == 1) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 334 | fprintf(f, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 335 | } else if (spec_config == 2) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 336 | fprintf(f, "ro "); |
| 337 | } |
| 338 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 339 | fprintf(f, "("); |
| 340 | |
| 341 | if (module != choice->module) { |
| 342 | fprintf(f, "%s:", choice->module->prefix); |
| 343 | } |
| 344 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 345 | fprintf(f, "%s)%s", choice->name, (choice->flags & LYS_MAND_TRUE ? "" : "?")); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 346 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 347 | if (choice->dflt != NULL) { |
| 348 | fprintf(f, " <%s>", choice->dflt->name); |
| 349 | } |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 350 | |
| 351 | tree_print_features(f, (const struct ly_feature **)choice->features, choice->features_size); |
| 352 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 353 | fprintf(f, "\n"); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 354 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 355 | level++; |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 356 | new_indent = create_indent(level, indent, mnode, 0, main_submod); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 357 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 358 | max_child_len = get_max_name_len(module, mnode->child); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 359 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 360 | LY_TREE_FOR(choice->child, sub) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 361 | tree_print_mnode_choice(f, module, level, new_indent, max_child_len, sub, |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 362 | LY_NODE_CASE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 363 | spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 364 | } |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 365 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 366 | free(new_indent); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 367 | } |
| 368 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 369 | static void |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 370 | tree_print_case(FILE *f, struct ly_module *module, int level, char *indent, unsigned int max_name_len, struct ly_mnode *mnode, int shorthand, int spec_config, struct ly_submodule *main_submod) |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 371 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 372 | char *new_indent; |
| 373 | struct ly_mnode_case *cas = (struct ly_mnode_case *)mnode; |
| 374 | struct ly_mnode *sub; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 375 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 376 | fprintf(f, "%s%s--:(", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 377 | (cas->flags & LYS_STATUS_DEPRC ? "x" : (cas->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 378 | |
| 379 | if (module != cas->module) { |
| 380 | fprintf(f, "%s:", cas->module->prefix); |
| 381 | } |
| 382 | |
| 383 | fprintf(f, "%s)", cas->name); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 384 | |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 385 | tree_print_features(f, (const struct ly_feature **)cas->features, cas->features_size); |
| 386 | |
| 387 | fprintf(f, "\n"); |
| 388 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 389 | level++; |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 390 | new_indent = create_indent(level, indent, mnode, shorthand, main_submod); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 391 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 392 | if (shorthand) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 393 | tree_print_mnode(f, module, level, new_indent, max_name_len, mnode, |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 394 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML | LY_NODE_USES, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 395 | spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 396 | } else { |
| 397 | LY_TREE_FOR(mnode->child, sub) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 398 | tree_print_mnode(f, module, level, new_indent, max_name_len, sub, |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 399 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML | LY_NODE_USES, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 400 | spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 401 | } |
| 402 | } |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 403 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 404 | free(new_indent); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 405 | } |
| 406 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 407 | static void |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 408 | tree_print_anyxml(FILE *f, struct ly_module *module, char *indent, unsigned int max_name_len, struct ly_mnode *mnode, int spec_config) |
Michal Vasko | 315f70b | 2015-06-05 10:48:59 +0200 | [diff] [blame] | 409 | { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 410 | uint8_t prefix_len; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 411 | struct ly_mnode_anyxml *anyxml = (struct ly_mnode_anyxml *)mnode; |
Michal Vasko | 315f70b | 2015-06-05 10:48:59 +0200 | [diff] [blame] | 412 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 413 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 414 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 415 | fprintf(f, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 416 | (anyxml->flags & LYS_STATUS_DEPRC ? "x" : (anyxml->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 417 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 418 | if (spec_config == 0) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 419 | fprintf(f, "%s ", (anyxml->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 420 | } else if (spec_config == 1) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 421 | fprintf(f, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 422 | } else if (spec_config == 2) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 423 | fprintf(f, "ro "); |
| 424 | } |
| 425 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 426 | prefix_len = 0; |
| 427 | if (module != anyxml->module) { |
| 428 | fprintf(f, "%s:", anyxml->module->prefix); |
| 429 | prefix_len = strlen(anyxml->module->prefix)+1; |
| 430 | } |
| 431 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 432 | fprintf(f, "%s%s%*sanyxml", anyxml->name, (anyxml->flags & LYS_MAND_TRUE ? " " : "?"), |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 433 | 3 + (int)((max_name_len - strlen(anyxml->name)) - prefix_len), " "); |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 434 | |
| 435 | tree_print_features(f, (const struct ly_feature **)anyxml->features, anyxml->features_size); |
| 436 | |
| 437 | fprintf(f, "\n"); |
Michal Vasko | 315f70b | 2015-06-05 10:48:59 +0200 | [diff] [blame] | 438 | } |
| 439 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 440 | static void |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 441 | tree_print_leaf(FILE *f, struct ly_module *module, char *indent, unsigned int max_name_len, struct ly_mnode *mnode, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 442 | { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 443 | uint8_t prefix_len; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 444 | struct ly_mnode_leaf *leaf = (struct ly_mnode_leaf *)mnode; |
Michal Vasko | 96929d9 | 2015-08-03 15:30:22 +0200 | [diff] [blame^] | 445 | struct ly_mnode *parent; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 446 | struct ly_mnode_list *list; |
| 447 | int i, is_key = 0; |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 448 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 449 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 450 | |
Michal Vasko | 96929d9 | 2015-08-03 15:30:22 +0200 | [diff] [blame^] | 451 | for (parent = leaf->parent; parent && parent->nodetype == LY_NODE_USES; parent = parent->parent); |
| 452 | if (parent->nodetype == LY_NODE_LIST) { |
| 453 | list = (struct ly_mnode_list *)parent; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 454 | for (i = 0; i < list->keys_size; i++) { |
Michal Vasko | 96929d9 | 2015-08-03 15:30:22 +0200 | [diff] [blame^] | 455 | if (list->keys[i] == leaf) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 456 | is_key = 1; |
| 457 | break; |
| 458 | } |
| 459 | } |
| 460 | } |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 461 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 462 | fprintf(f, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 463 | (leaf->flags & LYS_STATUS_DEPRC ? "x" : (leaf->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 464 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 465 | if (spec_config == 0) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 466 | fprintf(f, "%s ", (leaf->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 467 | } else if (spec_config == 1) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 468 | fprintf(f, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 469 | } else if (spec_config == 2) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 470 | fprintf(f, "ro "); |
| 471 | } |
| 472 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 473 | prefix_len = 0; |
| 474 | if (module != leaf->module) { |
| 475 | fprintf(f, "%s:", leaf->module->prefix); |
| 476 | prefix_len = strlen(leaf->module->prefix)+1; |
| 477 | } |
| 478 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 479 | fprintf(f, "%s%s%*s", leaf->name, ((leaf->flags & LYS_MAND_TRUE) || is_key ? " " : "?"), |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 480 | 3 + (int)((max_name_len - strlen(leaf->name)) - prefix_len), " "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 481 | |
| 482 | tree_print_type(f, &leaf->type); |
| 483 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 484 | if (leaf->dflt != NULL) { |
| 485 | fprintf(f, " <%s>", leaf->dflt); |
| 486 | } |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 487 | |
| 488 | tree_print_features(f, (const struct ly_feature **)leaf->features, leaf->features_size); |
| 489 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 490 | fprintf(f, "\n"); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 491 | } |
| 492 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 493 | static void |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 494 | tree_print_leaflist(FILE *f, struct ly_module *module, char *indent, unsigned int max_name_len, struct ly_mnode *mnode, int spec_config) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 495 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 496 | struct ly_mnode_leaflist *leaflist = (struct ly_mnode_leaflist *)mnode; |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 497 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 498 | assert(spec_config >= 0 && spec_config <= 2); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 499 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 500 | fprintf(f, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 501 | (leaflist->flags & LYS_STATUS_DEPRC ? "x" : (leaflist->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 502 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 503 | if (spec_config == 0) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 504 | fprintf(f, "%s ", (leaflist->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 505 | } else if (spec_config == 1) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 506 | fprintf(f, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 507 | } else if (spec_config == 2) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 508 | fprintf(f, "ro "); |
| 509 | } |
| 510 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 511 | if (module != leaflist->module) { |
| 512 | fprintf(f, "%s:", leaflist->module->prefix); |
| 513 | } |
| 514 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 515 | fprintf(f, "%s*%*s", leaflist->name, 3 + (int)(max_name_len - strlen(leaflist->name)), " "); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 516 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 517 | tree_print_type(f, &leaflist->type); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 518 | |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 519 | tree_print_features(f, (const struct ly_feature **)leaflist->features, leaflist->features_size); |
| 520 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 521 | fprintf(f, "\n"); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 524 | static void |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 525 | tree_print_list(FILE *f, struct ly_module *module, int level, char *indent, struct ly_mnode *mnode, int spec_config, struct ly_submodule *main_submod) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 526 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 527 | int i; |
| 528 | unsigned int max_child_len; |
| 529 | char *new_indent; |
| 530 | struct ly_mnode *sub; |
| 531 | struct ly_mnode_list *list = (struct ly_mnode_list *)mnode; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 532 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 533 | fprintf(f, "%s%s--", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 534 | (list->flags & LYS_STATUS_DEPRC ? "x" : (list->flags & LYS_STATUS_OBSLT ? "o" : "+"))); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 535 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 536 | if (spec_config == 0) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 537 | fprintf(f, "%s ", (list->flags & LYS_CONFIG_W ? "rw" : "ro")); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 538 | } else if (spec_config == 1) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 539 | fprintf(f, "-w "); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 540 | } else if (spec_config == 2) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 541 | fprintf(f, "ro "); |
| 542 | } |
| 543 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 544 | if (module != list->module) { |
| 545 | fprintf(f, "%s:", list->module->prefix); |
| 546 | } |
| 547 | |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 548 | fprintf(f, "%s*", list->name); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 549 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 550 | for (i = 0; i < list->keys_size; i++) { |
| 551 | if (i == 0) { |
| 552 | fprintf(f, " ["); |
| 553 | } |
| 554 | fprintf(f, "%s%s", list->keys[i]->name, i + 1 < list->keys_size ? "," : "]"); |
| 555 | } |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 556 | |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 557 | tree_print_features(f, (const struct ly_feature **)list->features, list->features_size); |
| 558 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 559 | fprintf(f, "\n"); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 560 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 561 | level++; |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 562 | new_indent = create_indent(level, indent, mnode, 0, main_submod); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 563 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 564 | max_child_len = get_max_name_len(module, mnode->child); |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 565 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 566 | LY_TREE_FOR(mnode->child, sub) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 567 | tree_print_mnode(f, module, level, new_indent, max_child_len, sub, |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 568 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_USES | LY_NODE_ANYXML, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 569 | spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 570 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 571 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 572 | free(new_indent); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 573 | } |
| 574 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 575 | static void |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 576 | tree_print_uses(FILE *f, struct ly_module *module, int level, char *indent, unsigned int max_name_len, struct ly_mnode *mnode, int spec_config, struct ly_submodule *main_submod) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 577 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 578 | struct ly_mnode *node; |
| 579 | struct ly_mnode_uses *uses = (struct ly_mnode_uses *)mnode; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 580 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 581 | LY_TREE_FOR(uses->child, node) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 582 | tree_print_mnode(f, module, level, indent, max_name_len, node, |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 583 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_USES | LY_NODE_ANYXML, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 584 | spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 585 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 586 | } |
| 587 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 588 | static void |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 589 | tree_print_rpc(FILE *f, struct ly_module *module, int level, char *indent, struct ly_mnode *mnode, struct ly_submodule *main_submod) |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 590 | { |
| 591 | char *new_indent; |
| 592 | struct ly_mnode *node; |
| 593 | struct ly_mnode_rpc *rpc = (struct ly_mnode_rpc *)mnode; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 594 | |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 595 | if (!is_enabled(mnode)) { |
| 596 | return; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 597 | } |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 598 | |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 599 | fprintf(f, "%s%s---x %s", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 600 | (rpc->flags & LYS_STATUS_DEPRC ? "x" : (rpc->flags & LYS_STATUS_OBSLT ? "o" : "+")), rpc->name); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 601 | |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 602 | tree_print_features(f, (const struct ly_feature **)rpc->features, rpc->features_size); |
| 603 | |
| 604 | fprintf(f, "\n"); |
| 605 | |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 606 | level++; |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 607 | new_indent = create_indent(level, indent, mnode, 0, main_submod); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 608 | |
| 609 | LY_TREE_FOR(rpc->child, node) { |
| 610 | if (node->nodetype == LY_NODE_INPUT) { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 611 | tree_print_input_output(f, module, level, new_indent, node, 1, main_submod); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 612 | } else if (node->nodetype == LY_NODE_OUTPUT) { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 613 | tree_print_input_output(f, module, level, new_indent, node, 2, main_submod); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
| 617 | free(new_indent); |
| 618 | } |
| 619 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 620 | static void |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 621 | tree_print_notif(FILE *f, struct ly_module *module, int level, char *indent, struct ly_mnode *mnode, struct ly_submodule *main_submod) |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 622 | { |
| 623 | unsigned int max_child_len; |
| 624 | char *new_indent; |
| 625 | struct ly_mnode *node; |
| 626 | struct ly_mnode_notif *notif = (struct ly_mnode_notif *)mnode; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 627 | |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 628 | if (!is_enabled(mnode)) { |
| 629 | return; |
Radek Krejci | 7e97c35 | 2015-06-19 16:26:34 +0200 | [diff] [blame] | 630 | } |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 631 | |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 632 | fprintf(f, "%s%s---n %s", indent, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 633 | (notif->flags & LYS_STATUS_DEPRC ? "x" : (notif->flags & LYS_STATUS_OBSLT ? "o" : "+")), |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 634 | notif->name); |
| 635 | |
Michal Vasko | 28c6b57 | 2015-06-18 12:43:31 +0200 | [diff] [blame] | 636 | tree_print_features(f, (const struct ly_feature **)notif->features, notif->features_size); |
| 637 | |
| 638 | fprintf(f, "\n"); |
| 639 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 640 | level++; |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 641 | new_indent = create_indent(level, indent, mnode, 0, main_submod); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 642 | |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 643 | max_child_len = get_max_name_len(module, mnode->child); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 644 | |
| 645 | LY_TREE_FOR(notif->child, node) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 646 | tree_print_mnode(f, module, level, new_indent, max_child_len, node, |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 647 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST | LY_NODE_ANYXML | LY_NODE_USES, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 648 | 2, main_submod); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | free(new_indent); |
| 652 | } |
| 653 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 654 | static void |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 655 | tree_print_mnode_choice(FILE *f, struct ly_module *module, int level, char *indent, unsigned int max_name_len, struct ly_mnode *mnode, int mask, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 656 | int spec_config, struct ly_submodule *main_submod) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 657 | { |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 658 | if (!is_enabled(mnode)) { |
| 659 | return; |
| 660 | } |
| 661 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 662 | if (mnode->nodetype & mask) { |
| 663 | if (mnode->nodetype == LY_NODE_CASE) { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 664 | tree_print_case(f, module, level, indent, max_name_len, mnode, 0, spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 665 | } else { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 666 | tree_print_case(f, module, level, indent, max_name_len, mnode, 1, spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 667 | } |
| 668 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 669 | } |
| 670 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 671 | static void |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 672 | tree_print_mnode(FILE *f, struct ly_module *module, int level, char *indent, unsigned int max_name_len, struct ly_mnode *mnode, int mask, |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 673 | int spec_config, struct ly_submodule *main_submod) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 674 | { |
Michal Vasko | efbb319 | 2015-07-08 10:35:00 +0200 | [diff] [blame] | 675 | if (!is_enabled(mnode)) { |
| 676 | return; |
Radek Krejci | 87e840c | 2015-06-19 16:44:54 +0200 | [diff] [blame] | 677 | } |
| 678 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 679 | switch (mnode->nodetype & mask) { |
| 680 | case LY_NODE_CONTAINER: |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 681 | tree_print_container(f, module, level, indent, mnode, spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 682 | break; |
| 683 | case LY_NODE_CHOICE: |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 684 | tree_print_choice(f, module, level, indent, mnode, spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 685 | break; |
| 686 | case LY_NODE_LEAF: |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 687 | tree_print_leaf(f, module, indent, max_name_len, mnode, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 688 | break; |
| 689 | case LY_NODE_LEAFLIST: |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 690 | tree_print_leaflist(f, module, indent, max_name_len, mnode, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 691 | break; |
| 692 | case LY_NODE_LIST: |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 693 | tree_print_list(f, module, level, indent, mnode, spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 694 | break; |
| 695 | case LY_NODE_ANYXML: |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 696 | tree_print_anyxml(f, module, indent, max_name_len, mnode, spec_config); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 697 | break; |
| 698 | case LY_NODE_USES: |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 699 | tree_print_uses(f, module, level, indent, max_name_len, mnode, spec_config, main_submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 700 | break; |
| 701 | default: |
| 702 | break; |
| 703 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 704 | } |
| 705 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 706 | int |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 707 | tree_print_model(FILE *f, struct ly_module *module) |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 708 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 709 | struct ly_mnode *mnode; |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 710 | struct ly_submodule *submod; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 711 | unsigned int max_child_len; |
| 712 | int level = 1, i, have_rpcs = 0, have_notifs = 0; |
| 713 | char *indent = malloc((level * 4 + 1) * sizeof (char)); |
| 714 | strcpy(indent, " "); |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 715 | |
Michal Vasko | fc6ac17 | 2015-07-07 09:46:46 +0200 | [diff] [blame] | 716 | if (module->type) { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 717 | submod = (struct ly_submodule *)module; |
| 718 | fprintf(f, "submodule: %s (belongs-to %s)\n", submod->name, submod->belongsto->name); |
Michal Vasko | fc6ac17 | 2015-07-07 09:46:46 +0200 | [diff] [blame] | 719 | } else { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 720 | submod = NULL; |
Michal Vasko | fc6ac17 | 2015-07-07 09:46:46 +0200 | [diff] [blame] | 721 | fprintf(f, "module: %s\n", module->name); |
| 722 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 723 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 724 | /* included submodules */ |
| 725 | for (i = 0; i < module->inc_size; i++) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 726 | max_child_len = get_max_name_len((struct ly_module *)module->inc[i].submodule, module->inc[i].submodule->data); |
Michal Vasko | 8d479bd | 2015-06-05 10:50:03 +0200 | [diff] [blame] | 727 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 728 | LY_TREE_FOR(module->inc[i].submodule->data, mnode) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 729 | tree_print_mnode(f, (struct ly_module *)module->inc[i].submodule, level, indent, max_child_len, mnode, |
Michal Vasko | 6a17ca3 | 2015-07-08 10:36:01 +0200 | [diff] [blame] | 730 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 731 | | LY_NODE_ANYXML | LY_NODE_USES, 0, submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 732 | } |
| 733 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 734 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 735 | /* module */ |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 736 | max_child_len = get_max_name_len(module, module->data); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 737 | level++; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 738 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 739 | LY_TREE_FOR(module->data, mnode) { |
Michal Vasko | fc3b0a3 | 2015-06-29 15:50:34 +0200 | [diff] [blame] | 740 | tree_print_mnode(f, module, level, indent, max_child_len, mnode, |
Michal Vasko | 6a17ca3 | 2015-07-08 10:36:01 +0200 | [diff] [blame] | 741 | LY_NODE_CHOICE | LY_NODE_CONTAINER | LY_NODE_LEAF | LY_NODE_LEAFLIST | LY_NODE_LIST |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 742 | | LY_NODE_ANYXML | LY_NODE_USES, 0, submod); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 743 | } |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 744 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 745 | /* rpc */ |
| 746 | if (module->rpc) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 747 | have_rpcs = 1; |
| 748 | } else { |
| 749 | for (i = 0; i < module->inc_size; i++) { |
| 750 | if (module->inc[i].submodule->rpc) { |
| 751 | have_rpcs = 1; |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 756 | if (have_rpcs) { |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 757 | fprintf(f, "rpcs:\n"); |
| 758 | for (i = 0; i < module->inc_size; i++) { |
| 759 | LY_TREE_FOR(module->inc[i].submodule->rpc, mnode) { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 760 | tree_print_rpc(f, (struct ly_module *)module->inc[i].submodule, level, indent, mnode, submod); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 761 | } |
| 762 | } |
| 763 | LY_TREE_FOR(module->rpc, mnode) { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 764 | tree_print_rpc(f, module, level, indent, mnode, submod); |
Michal Vasko | b5c75d7 | 2015-06-15 12:16:52 +0200 | [diff] [blame] | 765 | } |
| 766 | } |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 767 | |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 768 | /* notification */ |
| 769 | if (module->notif) { |
| 770 | have_notifs = 1; |
| 771 | } else { |
| 772 | for (i = 0; i < module->inc_size; i++) { |
| 773 | if (module->inc[i].submodule->notif) { |
| 774 | have_notifs = 1; |
| 775 | break; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | if (have_notifs) { |
| 780 | fprintf(f, "notifications:\n"); |
| 781 | for (i = 0; i < module->inc_size; i++) { |
| 782 | LY_TREE_FOR(module->inc[i].submodule->notif, mnode) { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 783 | tree_print_notif(f, (struct ly_module *)module->inc[i].submodule, level, indent, mnode, submod); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | LY_TREE_FOR(module->notif, mnode) { |
Michal Vasko | 64448d7 | 2015-07-08 13:35:24 +0200 | [diff] [blame] | 787 | tree_print_notif(f, module, level, indent, mnode, submod); |
Michal Vasko | e03bfbb | 2015-06-16 09:07:49 +0200 | [diff] [blame] | 788 | } |
| 789 | } |
Michal Vasko | 449afde | 2015-06-04 16:06:49 +0200 | [diff] [blame] | 790 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 791 | free(indent); |
| 792 | return EXIT_SUCCESS; |
Michal Vasko | 5ed10f1 | 2015-06-04 10:04:57 +0200 | [diff] [blame] | 793 | } |