data tree FEATURE initial implementation of YANG data support
diff --git a/tools/lint/main_ni.c b/tools/lint/main_ni.c
index e128649..8b72e15 100644
--- a/tools/lint/main_ni.c
+++ b/tools/lint/main_ni.c
@@ -202,26 +202,27 @@
  * 2 - data format
  */
 static int
-get_fileformat(const char *filename, LYS_INFORMAT *schema/* TODO , LYD_FORMAT *data */)
+get_fileformat(const char *filename, LYS_INFORMAT *schema, LYD_FORMAT *data)
 {
     char *ptr;
     LYS_INFORMAT informat_s;
-#if 0
     LYD_FORMAT informat_d;
-#endif
+
     /* get the file format */
     if ((ptr = strrchr(filename, '.')) != NULL) {
         ++ptr;
         if (!strcmp(ptr, "yang")) {
             informat_s = LYS_IN_YANG;
-#if 0
             informat_d = 0;
+#if 0
         } else if (!strcmp(ptr, "yin")) {
             informat_s = LYS_IN_YIN;
             informat_d = 0;
+#endif
         } else if (!strcmp(ptr, "xml")) {
             informat_s = 0;
             informat_d = LYD_XML;
+#if 0
         } else if (!strcmp(ptr, "json")) {
             informat_s = 0;
             informat_d = LYD_JSON;
@@ -234,24 +235,20 @@
         fprintf(stderr, "yanglint error: input file \"%s\" without file extension - unknown format.\n", filename);
         return 0;
     }
-#if 0
+
     if (data) {
         (*data) = informat_d;
     }
-#endif
+
     if (schema) {
         (*schema) = informat_s;
     }
 
-#if 0
     if (informat_s) {
         return 1;
     } else {
         return 2;
     }
-#else
-    return 1;
-#endif
 }
 
 int
@@ -289,9 +286,9 @@
 #if 0
         {"running",          required_argument, NULL, 'r'},
         {"operational",      required_argument, NULL, 'O'},
+#endif
         {"strict",           no_argument,       NULL, 's'},
         {"type",             required_argument, NULL, 't'},
-#endif
         {"version",          no_argument,       NULL, 'v'},
         {"verbose",          no_argument,       NULL, 'V'},
 #ifndef NDEBUG
@@ -305,8 +302,9 @@
     const struct lys_module *mod;
     LYS_OUTFORMAT outformat_s = 0;
     LYS_INFORMAT informat_s;
+    LYD_FORMAT informat_d, outformat_d = 0;
 #if 0
-    LYD_FORMAT informat_d, outformat_d = 0, ylformat = 0;
+    LYD_FORMAT ylformat = 0;
 #endif
     struct ly_set *searchpaths = NULL;
     const char *outtarget_s = NULL;
@@ -314,21 +312,23 @@
     struct stat st;
     uint32_t u;
     int options_ctx = LY_CTX_NOYANGLIBRARY, list = 0, outoptions_s = 0, outline_length_s = 0;
+    int autodetection = 0, options_parser = 0, merge = 0;
+    const char *oper_file = NULL;
 #if 0
-    const char *oper_file = NULL, *envelope_s = NULL;
+    const char *envelope_s = NULL;
     char *ylpath = NULL;
-    int options_dflt = 0, options_parser = 0, envelope = 0, autodetection = 0, merge = 0;
+    int options_dflt = 0, envelope = 0;
+    struct lyxml_elem *iter, *elem;
+    struct *subroot, *next, *node;
+#endif
+    struct lyd_node *oper = NULL;
     struct dataitem {
         const char *filename;
-        struct lyxml_elem *xml;
         struct lyd_node *tree;
         struct dataitem *next;
         LYD_FORMAT format;
         int type;
     } *data = NULL, *data_item, *data_prev = NULL;
-    struct lyxml_elem *iter, *elem;
-    struct lyd_node *oper = NULL, *subroot, *next, *node;
-#endif
     struct ly_set *mods = NULL;
     void *p;
     int index = 0;
@@ -367,8 +367,8 @@
         case 'f':
             if (!strcasecmp(optarg, "yang")) {
                 outformat_s = LYS_OUT_YANG;
-#if 0
                 outformat_d = 0;
+#if 0
             } else if (!strcasecmp(optarg, "tree")) {
                 outformat_s = LYS_OUT_TREE;
                 outformat_d = 0;
@@ -382,9 +382,11 @@
             } else if (!strcasecmp(optarg, "jsons")) {
                 outformat_s = LYS_OUT_JSON;
                 outformat_d = 0;
+#endif
             } else if (!strcasecmp(optarg, "xml")) {
                 outformat_s = 0;
                 outformat_d = LYD_XML;
+#if 0
             } else if (!strcasecmp(optarg, "json")) {
                 outformat_s = 0;
                 outformat_d = LYD_JSON;
@@ -504,6 +506,7 @@
                 oper_file = optarg;
             }
             break;
+#endif
         case 's':
             options_parser |= LYD_OPT_STRICT;
             break;
@@ -533,7 +536,6 @@
                 goto cleanup;
             }
             break;
-#endif
         case 'v':
             version();
             ret = EXIT_SUCCESS;
@@ -656,11 +658,11 @@
         /* ignore operational datastore file */
         oper_file = NULL;
     }
+#endif
     if ((options_parser & LYD_OPT_TYPEMASK) == LYD_OPT_DATA) {
         /* add option to ignore ietf-yang-library data for implicit data type */
         options_parser |= LYD_OPT_DATA_NO_YANGLIB;
     }
-#endif
 
     /* set callback for printing libyang messages */
     ly_set_log_clb(libyang_verbclb, 1);
@@ -695,7 +697,7 @@
     /* divide input files */
     for (i = 0; i < argc - optind; i++) {
         /* get the file format */
-        if (!get_fileformat(argv[optind + i], &informat_s/* TODO, &informat_d */)) {
+        if (!get_fileformat(argv[optind + i], &informat_s, &informat_d)) {
             goto cleanup;
         }
 
@@ -713,7 +715,6 @@
                 goto cleanup;
             }
             ly_set_add(mods, (void *)mod, 0);
-#if 0
         } else {
             if (autodetection && informat_d != LYD_XML) {
                 /* data file content autodetection is possible only for XML input */
@@ -733,17 +734,13 @@
             data_item->format = informat_d;
             data_item->type = options_parser & LYD_OPT_TYPEMASK;
             data_item->tree = NULL;
-            data_item->xml = NULL;
             data_item->next = NULL;
-#endif
         }
     }
-#if 0
     if (outformat_d && !data && !list) {
         fprintf(stderr, "yanglint error: no input data file for the specified data output format.\n");
         goto cleanup;
     }
-#endif
 
     /* enable specified features, if not specified, all the module's features are enabled */
     u = 4; /* skip internal libyang modules */
@@ -795,9 +792,7 @@
                 fputs("\n", out);
             }
         }
-#if 0
     } else if (data) {
-        ly_errno = 0;
 
         /* prepare operational datastore when specified for RPC/Notification */
         if (oper_file) {
@@ -817,6 +812,7 @@
 
         for (data_item = data, data_prev = NULL; data_item; data_prev = data_item, data_item = data_item->next) {
             /* parse data file - via LYD_OPT_TRUSTED postpone validation when all data are loaded and merged */
+#if 0
             if (autodetection) {
                 /* erase option not covered by LYD_OPT_TYPEMASK, but used according to the type */
                 options_parser &= ~LYD_OPT_DATA_NO_YANGLIB;
@@ -974,12 +970,15 @@
                     continue;
                 }
             } else {
+#else
+            {
+#endif
                 data_item->tree = lyd_parse_path(ctx, data_item->filename, data_item->format, options_parser, oper);
             }
-            if (ly_errno) {
+            if (ly_err_first(ctx)) {
                 goto cleanup;
             }
-
+#if 0
             if (merge && data != data_item) {
                 if (!data->tree) {
                     data->tree = data_item->tree;
@@ -992,8 +991,9 @@
                 }
                 data_item->tree = NULL;
             }
+#endif
         }
-
+#if 0
         if (merge) {
             /* validate the merged data tree, do not trust the input, invalidate all the data first */
             LY_TREE_FOR(data->tree, subroot) {
@@ -1025,13 +1025,14 @@
                 goto cleanup;
             }
         }
-
+#endif
         /* print only if data output format specified */
         if (outformat_d) {
             for (data_item = data; data_item; data_item = data_item->next) {
                 if (!merge && verbose >= 2) {
                     fprintf(stdout, "File %s:\n", data_item->filename);
                 }
+#if 0
                 if (outformat_d == LYD_XML && envelope) {
                     switch (data_item->type) {
                     case LYD_OPT_DATA:
@@ -1065,8 +1066,10 @@
                         fprintf(out, "<action xmlns=\"urn:ietf:params:xml:ns:yang:1\">\n");
                     }
                 }
-                lyd_print_file(out, (data_item->type == LYD_OPT_RPCREPLY) ? data_item->tree->child : data_item->tree,
-                               outformat_d, LYP_WITHSIBLINGS | LYP_FORMAT | options_dflt);
+#endif
+                lyd_print_file(out, (data_item->type == LYD_OPT_RPCREPLY) ? lyd_node_children(data_item->tree) : data_item->tree,
+                               outformat_d, LYDP_WITHSIBLINGS | LYDP_FORMAT /* TODO defaults | options_dflt */);
+#if 0
                 if (envelope_s) {
                     if (data_item->type == LYD_OPT_RPC && data_item->tree->schema->nodetype != LYS_RPC) {
                         fprintf(out, "</action>\n");
@@ -1077,9 +1080,9 @@
                     /* stop after first item */
                     break;
                 }
+#endif
             }
         }
-#endif
     }
 #if 0
     if (list) {
@@ -1099,15 +1102,12 @@
         free(feat[i]);
     }
     free(feat);
-#if 0
     for (; data; data = data_item) {
         data_item = data->next;
-        lyxml_free(ctx, data->xml);
-        lyd_free_withsiblings(data->tree);
+        lyd_free_all(data->tree);
         free(data);
     }
-    lyd_free_withsiblings(oper);
-#endif
+    lyd_free_all(oper);
     ly_ctx_destroy(ctx, NULL);
 
     return ret;