libyang REFACTOR return values and options changes

Unified, all functions that return a variety
of errors return LY_ERR. Any options such as
NOSIBLINGS, WITHSIBLINGS and so on were replaced
by function variants with suffixes _single, _all,
_tree, and _siblings.
diff --git a/src/printer_data.c b/src/printer_data.c
index bbb2eda..3d78d3b 100644
--- a/src/printer_data.c
+++ b/src/printer_data.c
@@ -23,15 +23,10 @@
 #include "printer_internal.h"
 #include "tree_data.h"
 
-API LY_ERR
-lyd_print(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
+static LY_ERR
+lyd_print_(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
 {
-    LY_ERR ret = LY_EINVAL;
-
-    LY_CHECK_ARG_RET(NULL, out, root, LY_EINVAL);
-
-    /* reset number of printed bytes */
-    out->func_printed = 0;
+    LY_ERR ret = LY_SUCCESS;
 
     switch (format) {
     case LYD_XML:
@@ -54,22 +49,46 @@
     return ret;
 }
 
-static LY_ERR
-lyd_print_(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
+API LY_ERR
+lyd_print_all(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
 {
-    LY_ERR ret;
+    LY_CHECK_ARG_RET(NULL, out, root, !(options & LYD_PRINT_WITHSIBLINGS), LY_EINVAL);
 
-    LY_CHECK_ARG_RET(NULL, out, LY_EINVAL);
+    /* reset the number of printed bytes */
+    out->func_printed = 0;
 
-    ret = lyd_print(out, root, format, options);
+    /* get first top-level sibling */
+    while (root->parent) {
+        root = (struct lyd_node *)root->parent;
+    }
+    while (root->prev->next) {
+        root = root->prev;
+    }
 
-    ly_out_free(out, NULL, 0);
-    return ret;
+    /* print each top-level sibling */
+    LY_CHECK_RET(lyd_print_(out, root, format, options | LYD_PRINT_WITHSIBLINGS));
+
+    return LY_SUCCESS;
+}
+
+API LY_ERR
+lyd_print_tree(struct ly_out *out, const struct lyd_node *root, LYD_FORMAT format, int options)
+{
+    LY_CHECK_ARG_RET(NULL, out, root, !(options & LYD_PRINT_WITHSIBLINGS), LY_EINVAL);
+
+    /* reset the number of printed bytes */
+    out->func_printed = 0;
+
+    /* print the subtree */
+    LY_CHECK_RET(lyd_print_(out, root, format, options));
+
+    return LY_SUCCESS;
 }
 
 API LY_ERR
 lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options)
 {
+    LY_ERR ret;
     struct ly_out *out;
 
     LY_CHECK_ARG_RET(NULL, strp, root, LY_EINVAL);
@@ -78,50 +97,64 @@
     *strp = NULL;
 
     LY_CHECK_RET(ly_out_new_memory(strp, 0, &out));
-    return lyd_print_(out, root, format, options);
+    ret = lyd_print_(out, root, format, options);
+    ly_out_free(out, NULL, 0);
+    return ret;
 }
 
 API LY_ERR
 lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options)
 {
+    LY_ERR ret;
     struct ly_out *out;
 
     LY_CHECK_ARG_RET(NULL, fd != -1, root, LY_EINVAL);
 
     LY_CHECK_RET(ly_out_new_fd(fd, &out));
-    return lyd_print_(out, root, format, options);
+    ret = lyd_print_(out, root, format, options);
+    ly_out_free(out, NULL, 0);
+    return ret;
 }
 
 API LY_ERR
 lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options)
 {
+    LY_ERR ret;
     struct ly_out *out;
 
     LY_CHECK_ARG_RET(NULL, f, root, LY_EINVAL);
 
     LY_CHECK_RET(ly_out_new_file(f, &out));
-    return lyd_print_(out, root, format, options);
+    ret = lyd_print_(out, root, format, options);
+    ly_out_free(out, NULL, 0);
+    return ret;
 }
 
 API LY_ERR
 lyd_print_path(const char *path, const struct lyd_node *root, LYD_FORMAT format, int options)
 {
+    LY_ERR ret;
     struct ly_out *out;
 
     LY_CHECK_ARG_RET(NULL, path, root, LY_EINVAL);
 
     LY_CHECK_RET(ly_out_new_filepath(path, &out));
-    return lyd_print_(out, root, format, options);
+    ret = lyd_print_(out, root, format, options);
+    ly_out_free(out, NULL, 0);
+    return ret;
 }
 
 API LY_ERR
 lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg,
               const struct lyd_node *root, LYD_FORMAT format, int options)
 {
+    LY_ERR ret;
     struct ly_out *out;
 
     LY_CHECK_ARG_RET(NULL, writeclb, root, LY_EINVAL);
 
     LY_CHECK_RET(ly_out_new_clb(writeclb, arg, &out));
-    return lyd_print_(out, root, format, options);
+    ret = lyd_print_(out, root, format, options);
+    ly_out_free(out, NULL, 0);
+    return ret;
 }