tree printer BUGFIX submodule does not have any data anymore

So, if printing module, print it with any submodules,
but when printint a submodule, print only it and
nothing else (even if it has includes, we're following
YANG 1.1 where includes are ignored, assumed actually).
diff --git a/src/printer_tree.c b/src/printer_tree.c
index 47cfb2a..2899664 100644
--- a/src/printer_tree.c
+++ b/src/printer_tree.c
@@ -36,37 +36,41 @@
                              unsigned int max_name_len, const struct lys_node *node, int mask, int spec_config);
 
 static int
-sibling_is_valid_child(const struct lys_node *node, int including)
+sibling_is_valid_child(const struct lys_node *node, int including, const struct lys_module *module)
 {
     struct lys_node *cur;
 
-    if (node == NULL) {
+    if (!node) {
         return 0;
     }
 
     /* has a following printed child */
     LY_TREE_FOR((struct lys_node *)(including ? node : node->next), cur) {
+        if (module->type && (cur->module != module)) {
+            continue;
+        }
+
         if (!lys_is_disabled(cur, 0)) {
             if (cur->nodetype & (LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYXML | LYS_CHOICE |
                     LYS_INPUT | LYS_OUTPUT | LYS_CASE)) {
                 return 1;
             }
-            if ((cur->nodetype == LYS_USES) && sibling_is_valid_child(cur->child, 1)) {
+            if ((cur->nodetype == LYS_USES) && sibling_is_valid_child(cur->child, 1, module)) {
                 return 1;
             }
         }
     }
 
     /* if in uses, the following printed child can actually be in the parent node :-/ */
-    if (node->parent && node->parent->nodetype == LYS_USES) {
-        return sibling_is_valid_child(node->parent, 0);
+    if (node->parent && (node->parent->nodetype == LYS_USES)) {
+        return sibling_is_valid_child(node->parent, 0, module);
     }
 
     return 0;
 }
 
 static char *
-create_indent(int level, const char *old_indent, const struct lys_node *node, int shorthand)
+create_indent(int level, const char *old_indent, const struct lys_node *node, int shorthand, const struct lys_module *module)
 {
     int next_is_case = 0, is_case = 0, has_next = 0;
     char *new_indent = malloc((level * 4 + 1) * sizeof (char));
@@ -92,7 +96,7 @@
     }
 
     /* next is a node that will actually be printed */
-    has_next = sibling_is_valid_child(node, 0);
+    has_next = sibling_is_valid_child(node, 0, module);
 
     if (has_next && !next_is_case) {
         strcat(new_indent, "|  ");
@@ -111,6 +115,11 @@
     unsigned int max_name_len = 0, uses_max_name_len, name_len;
 
     LY_TREE_FOR(node, sub) {
+        if (module->type && (sub->module != module)) {
+            /* when printing submodule, we are only concerned with its own data (they are in the module data) */
+            continue;
+        }
+
         if (sub->nodetype == LYS_USES) {
             uses_max_name_len = get_max_name_len(module, sub->child);
             if (uses_max_name_len > max_name_len) {
@@ -119,8 +128,8 @@
         } else if (sub->nodetype &
                 (LYS_CHOICE | LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST
                 | LYS_ANYXML | LYS_CASE)) {
-            mod = lys_mainmodule(sub);
-            name_len = strlen(sub->name) + (module == mod ? 0 : strlen(mod->name)+1);
+            mod = lys_node_module(sub);
+            name_len = strlen(sub->name) + (module == mod ? 0 : strlen(mod->name) + 1);
             if (name_len > max_name_len) {
                 max_name_len = name_len;
             }
@@ -174,7 +183,7 @@
     ly_print(out, "%s+--%s %s\n", indent, (spec_config == 1 ? "-w" : "ro"), (spec_config == 1 ? "input" : "output"));
 
     level++;
-    new_indent = create_indent(level, indent, node, 0);
+    new_indent = create_indent(level, indent, node, 0, module);
 
     max_child_len = get_max_name_len(module, node->child);
 
@@ -210,8 +219,8 @@
         ly_print(out, "ro ");
     }
 
-    nodemod = lys_mainmodule(node);
-    if (module != nodemod) {
+    nodemod = lys_node_module(node);
+    if (lys_module(module) != nodemod) {
         ly_print(out, "%s:", nodemod->name);
     }
 
@@ -222,7 +231,7 @@
     ly_print(out, "\n");
 
     level++;
-    new_indent = create_indent(level, indent, node, 0);
+    new_indent = create_indent(level, indent, node, 0, module);
 
     max_child_len = get_max_name_len(module, node->child);
 
@@ -260,8 +269,8 @@
 
     ly_print(out, "(");
 
-    nodemod = lys_mainmodule(node);
-    if (module != nodemod) {
+    nodemod = lys_node_module(node);
+    if (lys_module(module) != nodemod) {
         ly_print(out, "%s:", nodemod->name);
     }
 
@@ -276,7 +285,7 @@
     ly_print(out, "\n");
 
     level++;
-    new_indent = create_indent(level, indent, node, 0);
+    new_indent = create_indent(level, indent, node, 0, module);
 
     max_child_len = get_max_name_len(module, node->child);
 
@@ -301,8 +310,8 @@
     ly_print(out, "%s%s--:(", indent,
             (cas->flags & LYS_STATUS_DEPRC ? "x" : (cas->flags & LYS_STATUS_OBSLT ? "o" : "+")));
 
-    nodemod = lys_mainmodule(node);
-    if (module != nodemod) {
+    nodemod = lys_node_module(node);
+    if (lys_module(module) != nodemod) {
         ly_print(out, "%s:", nodemod->name);
     }
 
@@ -313,7 +322,7 @@
     ly_print(out, "\n");
 
     level++;
-    new_indent = create_indent(level, indent, node, shorthand);
+    new_indent = create_indent(level, indent, node, shorthand, module);
 
     if (shorthand) {
         tree_print_snode(out, module, level, new_indent, max_name_len, node,
@@ -352,8 +361,8 @@
     }
 
     prefix_len = 0;
-    nodemod = lys_mainmodule(node);
-    if (module != nodemod) {
+    nodemod = lys_node_module(node);
+    if (lys_module(module) != nodemod) {
         ly_print(out, "%s:", nodemod->name);
         prefix_len = strlen(nodemod->name)+1;
     }
@@ -404,8 +413,8 @@
     }
 
     prefix_len = 0;
-    nodemod = lys_mainmodule(node);
-    if (module != nodemod) {
+    nodemod = lys_node_module(node);
+    if (lys_module(module) != nodemod) {
         ly_print(out, "%s:", nodemod->name);
         prefix_len = strlen(nodemod->name)+1;
     }
@@ -415,7 +424,7 @@
 
     tree_print_type(out, &leaf->type);
 
-    if (leaf->dflt != NULL) {
+    if (leaf->dflt) {
         ly_print(out, " <%s>", leaf->dflt);
     }
 
@@ -444,8 +453,8 @@
         ly_print(out, "ro ");
     }
 
-    nodemod = lys_mainmodule(node);
-    if (module != nodemod) {
+    nodemod = lys_node_module(node);
+    if (lys_module(module) != nodemod) {
         ly_print(out, "%s:", nodemod->name);
     }
 
@@ -480,8 +489,8 @@
         ly_print(out, "ro ");
     }
 
-    nodemod = lys_mainmodule(node);
-    if (module != nodemod) {
+    nodemod = lys_node_module(node);
+    if (lys_module(module) != nodemod) {
         ly_print(out, "%s:", nodemod->name);
     }
 
@@ -499,7 +508,7 @@
     ly_print(out, "\n");
 
     level++;
-    new_indent = create_indent(level, indent, node, 0);
+    new_indent = create_indent(level, indent, node, 0, module);
 
     max_child_len = get_max_name_len(module, node->child);
 
@@ -546,7 +555,7 @@
     ly_print(out, "\n");
 
     level++;
-    new_indent = create_indent(level, indent, node, 0);
+    new_indent = create_indent(level, indent, node, 0, module);
 
     LY_TREE_FOR(rpc->child, child) {
         if (child->nodetype == LYS_INPUT) {
@@ -581,7 +590,7 @@
     ly_print(out, "\n");
 
     level++;
-    new_indent = create_indent(level, indent, node, 0);
+    new_indent = create_indent(level, indent, node, 0, module);
 
     max_child_len = get_max_name_len(module, node->child);
 
@@ -649,7 +658,7 @@
 int
 tree_print_model(struct lyout *out, const struct lys_module *module)
 {
-    struct lys_node *node;
+    struct lys_node *node, *data;
     unsigned int max_child_len;
     int level = 1, have_rpcs = 0, have_notifs = 0;
     char *indent = malloc((level * 4 + 1) * sizeof (char));
@@ -664,15 +673,22 @@
     if (module->type) {
         ly_print(out, "submodule: %s (belongs-to %s)\n", module->name,
                  ((struct lys_submodule *)module)->belongsto->name);
+        data = ((struct lys_submodule *)module)->belongsto->data;
     } else {
         ly_print(out, "module: %s\n", module->name);
+        data = module->data;
     }
 
     /* module */
-    max_child_len = get_max_name_len(module, module->data);
+    max_child_len = get_max_name_len(module, data);
     level++;
 
-    LY_TREE_FOR(module->data, node) {
+    LY_TREE_FOR(data, node) {
+        if (module->type && (node->module != module)) {
+            /* we're printing the submodule only */
+            continue;
+        }
+
         switch(node->nodetype) {
         case LYS_RPC:
             if (!lys_is_disabled(node, 0)) {
@@ -705,7 +721,7 @@
     /* rpc */
     if (have_rpcs) {
         ly_print(out, "rpcs:\n");
-        LY_TREE_FOR(module->data, node) {
+        LY_TREE_FOR(data, node) {
             if (!have_rpcs) {
                 break;
             }
@@ -719,7 +735,7 @@
     /* notification */
     if (have_notifs) {
         ly_print(out, "notifications:\n");
-        LY_TREE_FOR(module->data, node) {
+        LY_TREE_FOR(data, node) {
             if (!have_notifs) {
                 break;
             }