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