/**
 * @file main_ni.c
 * @author Radek Krejci <rkrejci@cesnet.cz>
 * @brief libyang's yanglint tool - noninteractive code
 *
 * Copyright (c) 2015-2018 CESNET, z.s.p.o.
 *
 * This source code is licensed under BSD 3-Clause License (the "License").
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://opensource.org/licenses/BSD-3-Clause
 */

#define _GNU_SOURCE

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <getopt.h>
#include <errno.h>
#include <libgen.h>
#include <sys/stat.h>
#include <string.h>
#include <strings.h>

#include "libyang.h"

#include "tools/config.h"

#include "commands.h"


volatile uint8_t verbose = 0;

#if 0
/* from commands.c */
int print_list(FILE *out, struct ly_ctx *ctx, LYD_FORMAT outformat);
#endif

void
help(int shortout)
{
    fprintf(stdout, "Usage:\n");
    fprintf(stdout, "    yanglint [options] [-f { yang | yin | tree | tree-rfc | info}] <file>...\n");
    fprintf(stdout, "        Validates the YANG module in <file>, and all its dependencies.\n\n");
    fprintf(stdout, "    yanglint [options] [-f { xml | json }] <schema>... <file>...\n");
    fprintf(stdout, "        Validates the YANG modeled data in <file> according to the <schema>.\n\n");
    fprintf(stdout, "    yanglint\n");
    fprintf(stdout, "        Starts interactive mode with more features.\n\n");

    if (shortout) {
        return;
    }
    fprintf(stdout, "Options:\n"
        "  -h, --help            Show this help message and exit.\n"
        "  -v, --version         Show version number and exit.\n"
        "  -V, --verbose         Show verbose messages, can be used multiple times to\n"
        "                        increase verbosity.\n"
#ifndef NDEBUG
        "  -G GROUPS, --debug=GROUPS\n"
        "                        Enable printing of specific debugging message group\n"
        "                        (nothing will be printed unless verbosity is set to debug):\n"
        "                        <group>[,<group>]* (dict, yang, yin, xpath, diff)\n\n"
#endif
        "  -p PATH, --path=PATH  Search path for schema (YANG/YIN) modules. The option can be used multiple times.\n"
        "                        Current working directory and path of the module being added is used implicitly.\n\n"
        "  -D, --disable-searchdir\n"
        "                        Do not implicitly search in CWD for schema modules. If specified a second time,\n"
        "                        do not even search the module directory (all modules must be explicitly specified).\n\n"
        "  -s, --strict          Strict data parsing (do not skip unknown data),\n"
        "                        has no effect for schemas.\n\n"
        "  -m, --merge           Merge input data files into a single tree and validate at once,\n"
        "                        has no effect for the auto, rpc, rpcreply and notif TYPEs.\n\n"
        "  -f FORMAT, --format=FORMAT\n"
        "                        Convert to FORMAT. Supported formats: \n"
        "                        yang, yin, tree and info for schemas,\n"
        "                        xml, json for data.\n"
        "  -a, --auto            Modify the xml output by adding envelopes for autodetection.\n\n"
        "  -i, --allimplemented  Make all the imported modules implemented.\n\n"
        "  -l, --list            Print info about the loaded schemas in ietf-yang-library format,\n"
        "                        the -f option applies here to specify data encoding.\n"
        "                        (i - imported module, I - implemented module)\n\n"
        "  -o OUTFILE, --output=OUTFILE\n"
        "                        Write the output to OUTFILE instead of stdout.\n\n"
        "  -F FEATURES, --features=FEATURES\n"
        "                        Features to support, default all.\n"
        "                        <modname>:[<feature>,]*\n\n"
        "  -d MODE, --default=MODE\n"
        "                        Print data with default values, according to the MODE\n"
        "                        (to print attributes, ietf-netconf-with-defaults model\n"
        "                        must be loaded):\n"
        "        all             - Add missing default nodes.\n"
        "        all-tagged      - Add missing default nodes and mark all the default\n"
        "                          nodes with the attribute.\n"
        "        trim            - Remove all nodes with a default value.\n"
        "        implicit-tagged - Add missing nodes and mark them with the attribute.\n\n"
        "  -t TYPE, --type=TYPE\n"
        "                        Specify data tree type in the input data file:\n"
        "        auto            - Resolve data type (one of the following) automatically\n"
        "                          (as pyang does) - applicable only on XML input data.\n"
        "        data            - Complete datastore with status data (default type).\n"
        "        config          - Configuration datastore (without status data).\n"
        "        get             - Result of the NETCONF <get> operation.\n"
        "        getconfig       - Result of the NETCONF <get-config> operation.\n"
        "        edit            - Content of the NETCONF <edit-config> operation.\n"
        "        rpc             - Content of the NETCONF <rpc> message, defined as YANG's rpc input statement.\n"
        "        rpcreply        - Reply to the RPC. The input data <file>s are expected in pairs - each RPC reply\n"
        "                          input data <file> must be followed by the origin RPC input data <file> for the reply.\n"
        "                          The same rule of pairing applies also in case of 'auto' TYPE and input data file\n"
        "                          containing RPC reply.\n"
        "        notif           - Notification instance (content of the <notification> element without <eventTime>.\n\n"
        "  -O FILE, --operational=FILE\n"
        "                        - Optional parameter for 'rpc', 'rpcreply' and 'notif' TYPEs, the FILE contains running\n"
        "                          configuration datastore and state data (operational datastore) referenced from\n"
        "                          the RPC/Notification. The same data apply to all input data <file>s. Note that\n"
        "                          the file is validated as 'data' TYPE. Special value '!' can be used as FILE argument\n"
        "                          to ignore the external references.\n\n"
        "  -y YANGLIB_PATH       - Path to a yang-library data describing the initial context.\n\n"
        "Tree output specific options:\n"
        "  --tree-help           - Print help on tree symbols and exit.\n"
        "  --tree-print-groupings\n"
        "                        Print top-level groupings in a separate section.\n"
        "  --tree-print-uses     - Print uses nodes instead the resolved grouping nodes.\n"
        "  --tree-no-leafref-target\n"
        "                        Do not print target nodes of leafrefs.\n"
        "  --tree-path=SCHEMA_PATH\n"
        "                        Print only the specified subtree.\n"
        "  --tree-line-length=LINE_LENGTH\n"
        "                        Wrap lines if longer than the specified length (it is not a strict limit, longer lines\n"
        "                        can often appear).\n\n"
        "Info output specific options:\n"
        "  -P INFOPATH, --info-path=INFOPATH\n"
        "                        - Schema path with full module names used as node's prefixes, the path identify the root\n"
        "                          node of the subtree to print information about.\n"
        "  --single-node         - Print information about a single node instead of a subtree."
        "\n");
}

void
tree_help(void)
{
    fprintf(stdout, "Each node is printed as:\n\n");
    fprintf(stdout, "<status> <flags> <name> <opts> <type> <if-features>\n\n"
                    "  <status> is one of:\n"
                    "    + for current\n"
                    "    x for deprecated\n"
                    "    o for obsolete\n\n"
                    "  <flags> is one of:\n"
                    "    rw for configuration data\n"
                    "    ro for status data\n"
                    "    -x for RPCs\n"
                    "    -n for Notification\n\n"
                    "  <name> is the name of the node\n"
                    "    (<name>) means that the node is a choice node\n"
                    "    :(<name>) means that the node is a case node\n\n"
                    "    if the node is augmented into the tree from another module,\n"
                    "    it is printed with the module name as <module-name>:<name>.\n\n"
                    "  <opts> is one of:\n"
                    "    ? for an optional leaf or choice\n"
                    "    ! for a presence container\n"
                    "    * for a leaf-list or list\n"
                    "    [<keys>] for a list's keys\n\n"
                    "  <type> is the name of the type for leafs and leaf-lists\n"
                    "    If there is a default value defined, it is printed within\n"
                    "    angle brackets <default-value>.\n"
                    "    If the type is a leafref, the type is printed as -> TARGET`\n\n"
                    "  <if-features> is the list of features this node depends on,\n"
                    "    printed within curly brackets and a question mark {...}?\n\n");
}

void
version(void)
{
    fprintf(stdout, "yanglint %s\n", PROJECT_VERSION);
}

void
libyang_verbclb(LY_LOG_LEVEL level, const char *msg, const char *path)
{
    char *levstr;

    if (level <= verbose) {
        switch(level) {
        case LY_LLERR:
            levstr = "err :";
            break;
        case LY_LLWRN:
            levstr = "warn:";
            break;
        case LY_LLVRB:
            levstr = "verb:";
            break;
        default:
            levstr = "dbg :";
            break;
        }
        if (path) {
            fprintf(stderr, "%s %s (%s)\n", levstr, msg, path);
        } else {
            fprintf(stderr, "%s %s\n", levstr, msg);
        }
    }
}

/*
 * return:
 * 0 - error
 * 1 - schema format
 * 2 - data format
 */
static int
get_fileformat(const char *filename, LYS_INFORMAT *schema, LYD_FORMAT *data)
{
    char *ptr;
    LYS_INFORMAT informat_s;
    LYD_FORMAT informat_d;

    /* get the file format */
    if ((ptr = strrchr(filename, '.')) != NULL) {
        ++ptr;
        if (!strcmp(ptr, "yang")) {
            informat_s = LYS_IN_YANG;
            informat_d = 0;
        } else if (!strcmp(ptr, "yin")) {
            informat_s = LYS_IN_YIN;
            informat_d = 0;
        } else if (!strcmp(ptr, "xml")) {
            informat_s = 0;
            informat_d = LYD_XML;
        } else if (!strcmp(ptr, "json")) {
            informat_s = 0;
            informat_d = LYD_JSON;
        } else {
            fprintf(stderr, "yanglint error: input file in an unknown format \"%s\".\n", ptr);
            return 0;
        }
    } else {
        fprintf(stderr, "yanglint error: input file \"%s\" without file extension - unknown format.\n", filename);
        return 0;
    }

    if (data) {
        (*data) = informat_d;
    }

    if (schema) {
        (*schema) = informat_s;
    }

    if (informat_s) {
        return 1;
    } else {
        return 2;
    }
}

int
main_ni(int argc, char* argv[])
{
    int ret = EXIT_FAILURE;
    int opt, opt_index = 0, i, featsize = 0;
    struct option options[] = {
#if 0
        {"auto",             no_argument,       NULL, 'a'},
#endif
        {"default",          required_argument, NULL, 'd'},
        {"format",           required_argument, NULL, 'f'},
        {"features",         required_argument, NULL, 'F'},
#if 0
        {"tree-print-groupings", no_argument,   NULL, 'g'},
        {"tree-print-uses",  no_argument,       NULL, 'u'},
        {"tree-no-leafref-target", no_argument, NULL, 'n'},
        {"tree-path",        required_argument, NULL, 'P'},
        {"tree-line-length", required_argument, NULL, 'L'},
#endif
        {"help",             no_argument,       NULL, 'h'},
#if 0
        {"tree-help",        no_argument,       NULL, 'H'},
#endif
        {"allimplemented",   no_argument,       NULL, 'i'},
        {"disable-cwd-search", no_argument,     NULL, 'D'},
        {"list",             no_argument,       NULL, 'l'},
#if 0
        {"merge",            no_argument,       NULL, 'm'},
#endif
        {"output",           required_argument, NULL, 'o'},
        {"path",             required_argument, NULL, 'p'},
        {"info-path",        required_argument, NULL, 'P'},
#if 0
        {"running",          required_argument, NULL, 'r'},
        {"operational",      required_argument, NULL, 'O'},
#endif
        {"single-node",      no_argument,       NULL, 'q'},
        {"strict",           no_argument,       NULL, 's'},
        {"type",             required_argument, NULL, 't'},
        {"version",          no_argument,       NULL, 'v'},
        {"verbose",          no_argument,       NULL, 'V'},
#ifndef NDEBUG
        {"debug",            required_argument, NULL, 'G'},
#endif
        {NULL,               required_argument, NULL, 'y'},
        {NULL,               0,                 NULL, 0}
    };
    struct ly_out *out = NULL;
    struct ly_ctx *ctx = NULL;
    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 ylformat = 0;
#endif
    struct ly_set *searchpaths = NULL;
    const char *outtarget_s = NULL;
    char **feat = NULL, *ptr, *featlist, *dir;
    struct stat st;
    uint32_t u;
    int options_ctx = LY_CTX_NO_YANGLIBRARY, list = 0, outoptions_s = 0, outline_length_s = 0;
    int autodetection = 0, options_parser = 0, merge = 0;
    const char *oper_file = NULL;
    int options_dflt = 0;
#if 0
    ly_bool envelope = 0;
    const char *envelope_s = NULL;
    char *ylpath = NULL;
    struct lyxml_elem *iter, *elem;
    struct *subroot, *next, *node;
#endif
    struct lyd_node *tree = NULL;
    struct dataitem {
        const char *filename;
        struct lyd_node *tree;
        struct dataitem *next;
        LYD_FORMAT format;
        int flags;
    } *data = NULL, *data_item, *data_prev = NULL;
    struct ly_set *mods = NULL;
    void *p;

    opterr = 0;
#ifndef NDEBUG
    while ((opt = getopt_long(argc, argv, "acd:f:F:gunP:L:hHiDlmo:p:O:st:vVG:y:", options, &opt_index)) != -1)
#else
    while ((opt = getopt_long(argc, argv, "acd:f:F:gunP:L:hHiDlmo:p:O:st:vVy:", options, &opt_index)) != -1)
#endif
    {
        switch (opt) {
#if 0
        }
        case 'a':
            envelope = 1;
            break;
#endif
        case 'd':
            if (!strcmp(optarg, "all")) {
                options_dflt = (options_dflt & ~LYD_PRINT_WD_MASK) | LYD_PRINT_WD_ALL;
            } else if (!strcmp(optarg, "all-tagged")) {
                options_dflt = (options_dflt & ~LYD_PRINT_WD_MASK) | LYD_PRINT_WD_ALL_TAG;
            } else if (!strcmp(optarg, "trim")) {
                options_dflt = (options_dflt & ~LYD_PRINT_WD_MASK) | LYD_PRINT_WD_TRIM;
            } else if (!strcmp(optarg, "implicit-tagged")) {
                options_dflt = (options_dflt & ~LYD_PRINT_WD_MASK) | LYD_PRINT_WD_IMPL_TAG;
            } else {
                fprintf(stderr, "yanglint error: unknown default mode %s\n", optarg);
                help(1);
                goto cleanup;
            }
            break;
        case 'f':
            if (!strcasecmp(optarg, "yang")) {
                outformat_s = LYS_OUT_YANG;
                outformat_d = 0;
#if 0
            } else if (!strcasecmp(optarg, "tree")) {
                outformat_s = LYS_OUT_TREE;
                outformat_d = 0;
            } else if (!strcasecmp(optarg, "tree-rfc")) {
                outformat_s = LYS_OUT_TREE;
                outoptions_s |= LYS_OUTOPT_TREE_RFC;
                outformat_d = 0;
#endif
            } else if (!strcasecmp(optarg, "yin")) {
                outformat_s = LYS_OUT_YIN;
                outformat_d = 0;
            } else if (!strcasecmp(optarg, "info")) {
                outformat_s = LYS_OUT_YANG_COMPILED;
                outformat_d = 0;
            } else if (!strcasecmp(optarg, "xml")) {
                outformat_s = 0;
                outformat_d = LYD_XML;
            } else if (!strcasecmp(optarg, "json")) {
                outformat_s = 0;
                outformat_d = LYD_JSON;
            } else {
                fprintf(stderr, "yanglint error: unknown output format %s\n", optarg);
                help(1);
                goto cleanup;
            }
            break;
        case 'F':
            featsize++;
            if (!feat) {
                p = malloc(sizeof *feat);
            } else {
                p = realloc(feat, featsize * sizeof *feat);
            }
            if (!p) {
                fprintf(stderr, "yanglint error: Memory allocation failed (%s:%d, %s)", __FILE__, __LINE__, strerror(errno));
                goto cleanup;
            }
            feat = p;
            feat[featsize - 1] = strdup(optarg);
            ptr = strchr(feat[featsize - 1], ':');
            if (!ptr) {
                fprintf(stderr, "yanglint error: Invalid format of the features specification (%s)", optarg);
                goto cleanup;
            }
            *ptr = '\0';

            break;
#if 0
        case 'g':
            outoptions_s |= LYS_OUTOPT_TREE_GROUPING;
            break;
        case 'u':
            outoptions_s |= LYS_OUTOPT_TREE_USES;
            break;
        case 'n':
            outoptions_s |= LYS_OUTOPT_TREE_NO_LEAFREF;
            break;
#endif
        case 'P':
            outtarget_s = optarg;
            break;
#if 0
        case 'L':
            outline_length_s = atoi(optarg);
            break;
#endif
        case 'h':
            help(0);
            ret = EXIT_SUCCESS;
            goto cleanup;
#if 0
        case 'H':
            tree_help();
            ret = EXIT_SUCCESS;
            goto cleanup;
#endif
        case 'i':
            options_ctx |= LY_CTX_ALL_IMPLEMENTED;
            break;
        case 'D':
            if (options_ctx & LY_CTX_DISABLE_SEARCHDIRS) {
                fprintf(stderr, "yanglint error: -D specified too many times.\n");
                goto cleanup;
            } else if (options_ctx & LY_CTX_DISABLE_SEARCHDIR_CWD) {
                options_ctx &= ~LY_CTX_DISABLE_SEARCHDIR_CWD;
                options_ctx |= LY_CTX_DISABLE_SEARCHDIRS;
            } else {
                options_ctx |= LY_CTX_DISABLE_SEARCHDIR_CWD;
            }
            break;
        case 'l':
            list = 1;
            break;
#if 0
        case 'm':
            merge = 1;
            break;
#endif
        case 'o':
            if (out) {
                if (ly_out_filepath(out, optarg) != NULL) {
                    fprintf(stderr, "yanglint error: unable open output file %s (%s)\n", optarg, strerror(errno));
                    goto cleanup;
                }
            } else {
                if (ly_out_new_filepath(optarg, &out)) {
                    fprintf(stderr, "yanglint error: unable open output file %s (%s)\n", optarg, strerror(errno));
                    goto cleanup;
                }
            }
            break;
        case 'p':
            if (stat(optarg, &st) == -1) {
                fprintf(stderr, "yanglint error: Unable to use search path (%s) - %s.\n", optarg, strerror(errno));
                goto cleanup;
            }
            if (!S_ISDIR(st.st_mode)) {
                fprintf(stderr, "yanglint error: Provided search path is not a directory.\n");
                goto cleanup;
            }
            if (!searchpaths) {
                if (ly_set_new(&searchpaths)) {
                    fprintf(stderr, "yanglint error: Preparing storage for searchpaths failed.\n");
                    goto cleanup;
                }
            }
            if (ly_set_add(searchpaths, optarg, 0, NULL)) {
                fprintf(stderr, "yanglint error: Storing searchpath failed.\n");
                goto cleanup;
            }
            break;
#if 0
        case 'O':
            if (oper_file || (options_parser & LYD_OPT_NOEXTDEPS)) {
                fprintf(stderr, "yanglint error: The operational datastore (-O) cannot be set multiple times.\n");
                goto cleanup;
            }
            if (optarg[0] == '!') {
                /* ignore extenral dependencies to the operational datastore */
                options_parser |= LYD_OPT_NOEXTDEPS;
            } else {
                /* external file with the operational datastore */
                oper_file = optarg;
            }
            break;
#endif
        case 's':
            options_parser |= LYD_PARSE_STRICT;
            break;
        case 't':
            if (!strcmp(optarg, "auto")) {
                autodetection = 1;
            /*} else if (!strcmp(optarg, "config")) {
                options_parser |= LYD_OPT_CONFIG;
            } else if (!strcmp(optarg, "get")) {
                options_parser |= LYD_OPT_GET;
            } else if (!strcmp(optarg, "getconfig")) {
                options_parser |= LYD_OPT_GETCONFIG;
            } else if (!strcmp(optarg, "edit")) {
                options_parser |= LYD_OPT_EDIT;*/
            } else if (!strcmp(optarg, "data")) {
                /* no options */
            } else {
                fprintf(stderr, "yanglint error: unknown data tree type %s\n", optarg);
                help(1);
                goto cleanup;
            }
            break;
        case 'v':
            version();
            ret = EXIT_SUCCESS;
            goto cleanup;
        case 'V':
            verbose++;
            break;
#ifndef NDEBUG
        case 'G':
            u = 0;
            ptr = optarg;
            while (ptr[0]) {
                if (!strncmp(ptr, "dict", 4)) {
                    u |= LY_LDGDICT;
                    ptr += 4;
                } else if (!strncmp(ptr, "xpath", 5)) {
                    u |= LY_LDGXPATH;
                    ptr += 5;
                }

                if (ptr[0]) {
                    if (ptr[0] != ',') {
                        fprintf(stderr, "yanglint error: unknown debug group string \"%s\"\n", optarg);
                        goto cleanup;
                    }
                    ++ptr;
                }
            }
            ly_log_dbg_groups(u);
            break;
#endif
#if 0
        case 'y':
            ptr = strrchr(optarg, '.');
            if (ptr) {
                ptr++;
                if (!strcmp(ptr, "xml")) {
                    ylformat = LYD_XML;
                } else if (!strcmp(ptr, "json")) {
                    ylformat = LYD_JSON;
                } else {
                    fprintf(stderr, "yanglint error: yang-library file in an unknown format \"%s\".\n", ptr);
                    goto cleanup;
                }
            } else {
                fprintf(stderr, "yanglint error: yang-library file in an unknown format.\n");
                goto cleanup;
            }
            ylpath = optarg;
            break;
#endif
        default:
            help(1);
            if (optopt) {
                fprintf(stderr, "yanglint error: invalid option: -%c\n", optopt);
            } else {
                fprintf(stderr, "yanglint error: invalid option: %s\n", argv[optind - 1]);
            }
            goto cleanup;
        }
    }

    /* check options compatibility */
    if (!list && optind >= argc) {
        help(1);
        fprintf(stderr, "yanglint error: missing <file> to process\n");
        goto cleanup;
    }
    if (outformat_s && outformat_s != LYS_OUT_TREE && (optind + 1) < argc) {
        /* we have multiple schemas to be printed as YIN or YANG */
        fprintf(stderr, "yanglint error: too many schemas to convert and store.\n");
        goto cleanup;
    }
    if (outoptions_s || outtarget_s || outline_length_s) {
#if 0
        if (outformat_d || (outformat_s && outformat_s != LYS_OUT_TREE)) {
            /* we have --tree-print-grouping with other output format than tree */
            fprintf(stderr,
                    "yanglint warning: --tree options take effect only in case of the tree output format.\n");
        }
    }
    if (merge) {
        if (autodetection || (options_parser & (LYD_OPT_RPC | LYD_OPT_RPCREPLY | LYD_OPT_NOTIF))) {
            fprintf(stderr, "yanglint warning: merging not allowed, ignoring option -m.\n");
            merge = 0;
        } else {
            /* first, files will be parsed as trusted to allow missing data, then the data trees will be merged
             * and the result will be validated */
            options_parser |= LYD_OPT_TRUSTED;
        }
#endif
    }
    if (!outformat_d && options_dflt) {
        /* we have options for printing default nodes, but data output not specified */
        fprintf(stderr, "yanglint warning: default mode is ignored when not printing data.\n");
    }
#if 0
    if (outformat_s && (options_parser || autodetection)) {
        /* we have options for printing data tree, but output is schema */
        fprintf(stderr, "yanglint warning: data parser options are ignored when printing schema.\n");
    }
    if (oper_file && (!autodetection && !(options_parser & (LYD_OPT_RPC | LYD_OPT_RPCREPLY | LYD_OPT_NOTIF)))) {
        fprintf(stderr, "yanglint warning: operational datastore applies only to RPCs or Notifications.\n");
        /* ignore operational datastore file */
        oper_file = NULL;
    }
    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);
#if 0
    /* create libyang context */
    if (ylpath) {
        ctx = ly_ctx_new_ylpath(searchpaths ? (const char*)searchpaths->set.g[0] : NULL, ylpath, ylformat, options_ctx);
    } else {
#else
    {
#endif
        ly_ctx_new(NULL, options_ctx, &ctx);
    }
    if (!ctx) {
        goto cleanup;
    }

    /* set searchpaths */
    if (searchpaths) {
        for (u = 0; u < searchpaths->count; u++) {
            ly_ctx_set_searchdir(ctx, (const char*)searchpaths->objs[u]);
        }
    }

    /* derefered setting of verbosity in libyang after context initiation */
    ly_log_level(verbose);

    if (ly_set_new(&mods)) {
        fprintf(stderr, "yanglint error: Preparing storage for the parsed modules failed.\n");
        goto cleanup;
    }


    /* divide input files */
    for (i = 0; i < argc - optind; i++) {
        /* get the file format */
        if (!get_fileformat(argv[optind + i], &informat_s, &informat_d)) {
            goto cleanup;
        }

        if (informat_s) {
            /* load/validate schema */
            int unset_path = 1;

            if (verbose >= 2) {
                fprintf(stdout, "Validating %s schema file.\n", argv[optind + i]);
            }

            /* add temporarily also the path of the module itself */
            dir = strdup(argv[optind + i]);
            if (ly_ctx_set_searchdir(ctx, ptr = dirname(dir)) == LY_EEXIST) {
                unset_path = 0;
            }
            lys_parse_path(ctx, argv[optind + i], informat_s, &mod);
            ly_ctx_unset_searchdir_last(ctx, unset_path);
            free(dir);
            if (!mod) {
                goto cleanup;
            }
            if (ly_set_add(mods, (void *)mod, 0, NULL)) {
                fprintf(stderr, "yanglint error: Storing parsed module for further processing failed.\n");
                goto cleanup;
            }
        } else {
            if (autodetection && informat_d != LYD_XML) {
                /* data file content autodetection is possible only for XML input */
                fprintf(stderr, "yanglint error: data type autodetection is applicable only to XML files.\n");
                goto cleanup;
            }

            /* remember data filename and its format */
            if (!data) {
                data = data_item = malloc(sizeof *data);
            } else {
                for (data_item = data; data_item->next; data_item = data_item->next);
                data_item->next = malloc(sizeof *data_item);
                data_item = data_item->next;
            }
            data_item->filename = argv[optind + i];
            data_item->format = informat_d;
            data_item->flags = options_parser;
            data_item->tree = NULL;
            data_item->next = NULL;
        }
    }
    if (outformat_d && !data && !list) {
        fprintf(stderr, "yanglint error: no input data file for the specified data output format.\n");
        goto cleanup;
    }

    /* enable specified features, if not specified, all the module's features are enabled */
    u = 4; /* skip internal libyang modules */
    while ((mod = ly_ctx_get_module_iter(ctx, &u))) {
        if (!mod->implemented) {
            continue;
        }

        for (i = 0; i < featsize; i++) {
            if (!strcmp(feat[i], mod->name)) {
                /* parse features spec */
                featlist = strdup(feat[i] + strlen(feat[i]) + 1);
                ptr = NULL;
                while((ptr = strtok(ptr ? NULL : featlist, ","))) {
                    if (verbose >= 2) {
                        fprintf(stdout, "Enabling feature %s in module %s.\n", ptr, mod->name);
                    }
                    /*if (lys_feature_enable(mod, ptr)) {
                        fprintf(stderr, "Feature %s not defined in module %s.\n", ptr, mod->name);
                    }*/
                }
                free(featlist);
                break;
            }
        }
        if (i == featsize) {
            if (verbose >= 2) {
                fprintf(stdout, "Enabling all features in module %s.\n", mod->name);
            }
            //lys_feature_enable(mod, "*");
        }
    }
    if (!out && (outformat_s || data)) {
        ly_out_new_file(stdout, &out);
    }
    /* convert (print) to FORMAT */
    if (outformat_s) {
        if (outtarget_s) {
            const struct lysc_node *node = lys_find_path(ctx, NULL, outtarget_s, 0);
            if (node) {
                lys_print_node(out, node, outformat_s, outline_length_s, outoptions_s);
            } else {
                fprintf(stderr, "yanglint error: The requested schema node \"%s\" does not exists.\n", outtarget_s);
            }
        } else {
            for (u = 0; u < mods->count; u++) {
                if (u) {
                    ly_print(out, "\n");
                }
                lys_print_module(out, (struct lys_module *)mods->objs[u], outformat_s, outline_length_s, outoptions_s);
            }
        }
    } else if (data) {

        /* prepare operational datastore when specified for RPC/Notification */
        if (oper_file) {
            struct ly_in *in;
            tree = NULL;

            if (ly_in_new_filepath(oper_file, 0, &in)) {
                fprintf(stderr, "yanglint error: Unable to open an operational data file \"%s\".\n", oper_file);
                goto cleanup;
            }
            if (lyd_parse_data(ctx, in, 0, LYD_PARSE_ONLY, 0, &tree) || !tree) {
                fprintf(stderr, "yanglint error: Failed to parse the operational datastore file for RPC/Notification validation.\n");
                ly_in_free(in, 0);
                goto cleanup;
            }
            ly_in_free(in, 0);
        }

        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;
                /* automatically detect data type from the data top level */
                data_item->xml = lyxml_parse_path(ctx, data_item->filename, 0);
                if (!data_item->xml) {
                    fprintf(stderr, "yanglint error: parsing XML data for data type autodetection failed.\n");
                    goto cleanup;
                }

                /* NOTE: namespace is ignored to simplify usage of this feature */
                if (!strcmp(data_item->xml->name, "data")) {
                    if (verbose >= 2) {
                        fprintf(stdout, "Parsing %s as complete datastore.\n", data_item->filename);
                    }
                    options_parser = (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_DATA_NO_YANGLIB;
                    data_item->type = LYD_OPT_DATA;
                } else if (!strcmp(data_item->xml->name, "config")) {
                    if (verbose >= 2) {
                        fprintf(stdout, "Parsing %s as config data.\n", data_item->filename);
                    }
                    options_parser = (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_CONFIG;
                    data_item->type = LYD_OPT_CONFIG;
                } else if (!strcmp(data_item->xml->name, "get-reply")) {
                    if (verbose >= 2) {
                        fprintf(stdout, "Parsing %s as <get> reply data.\n", data_item->filename);
                    }
                    options_parser = (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_GET;
                    data_item->type = LYD_OPT_GET;
                } else if (!strcmp(data_item->xml->name, "get-config-reply")) {
                    if (verbose >= 2) {
                        fprintf(stdout, "Parsing %s as <get-config> reply data.\n", data_item->filename);
                    }
                    options_parser = (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_GETCONFIG;
                    data_item->type = LYD_OPT_GETCONFIG;
                } else if (!strcmp(data_item->xml->name, "edit-config")) {
                    if (verbose >= 2) {
                        fprintf(stdout, "Parsing %s as <edit-config> data.\n", data_item->filename);
                    }
                    options_parser = (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_EDIT;
                    data_item->type = LYD_OPT_EDIT;
                } else if (!strcmp(data_item->xml->name, "rpc")) {
                    if (verbose >= 2) {
                        fprintf(stdout, "Parsing %s as <rpc> data.\n", data_item->filename);
                    }
                    options_parser = (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_RPC;
                    data_item->type = LYD_OPT_RPC;
                } else if (!strcmp(data_item->xml->name, "rpc-reply")) {
                    if (verbose >= 2) {
                        fprintf(stdout, "Parsing %s as <rpc-reply> data.\n", data_item->filename);
                    }

                    data_item->type = LYD_OPT_RPCREPLY;
                    if (!data_item->next || (data_prev && !data_prev->tree)) {
                        fprintf(stderr, "RPC reply (%s) must be paired with the original RPC, see help.\n", data_item->filename);
                        goto cleanup;
                    }

                    continue;
                } else if (!strcmp(data_item->xml->name, "notification")) {
                    if (verbose >= 2) {
                        fprintf(stdout, "Parsing %s as <notification> data.\n", data_item->filename);
                    }
                    options_parser = (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_NOTIF;
                    data_item->type = LYD_OPT_NOTIF;

                    /* ignore eventTime element if present */
                    while (data_item->xml->child && !strcmp(data_item->xml->child->name, "eventTime")) {
                        lyxml_free(ctx, data_item->xml->child);
                    }
                } else {
                    fprintf(stderr, "yanglint error: invalid top-level element \"%s\" for data type autodetection.\n",
                            data_item->xml->name);
                    goto cleanup;
                }

                data_item->tree = lyd_parse_xml(ctx, &data_item->xml->child, options_parser, oper);
                if (data_prev && data_prev->type == LYD_OPT_RPCREPLY) {
parse_reply:
                    /* check result of the RPC parsing, we are going to do another parsing in this step */
                    if (ly_errno) {
                        goto cleanup;
                    }

                    /* check that we really have RPC for the reply */
                    if (data_item->type != LYD_OPT_RPC) {
                        fprintf(stderr, "yanglint error: RPC reply (%s) must be paired with the original RPC, see help.\n", data_prev->filename);
                        goto cleanup;
                    }

                    if (data_prev->format == LYD_XML) {
                        /* ignore <ok> and <rpc-error> elements if present */
                        u = 0;
                        LY_TREE_FOR_SAFE(data_prev->xml->child, iter, elem) {
                            if (!strcmp(data_prev->xml->child->name, "ok")) {
                                if (u) {
                                    /* rpc-error or ok already present */
                                    u = 0x8; /* error flag */
                                } else {
                                    u = 0x1 | 0x4; /* <ok> flag with lyxml_free() flag */
                                }
                            } else if (!strcmp(data_prev->xml->child->name, "rpc-error")) {
                                if (u && (u & 0x1)) {
                                    /* ok already present, rpc-error can be present multiple times */
                                    u = 0x8; /* error flag */
                                } else {
                                    u = 0x2 | 0x4; /* <rpc-error> flag with lyxml_free() flag */
                                }
                            }

                            if (u == 0x8) {
                                fprintf(stderr, "yanglint error: Invalid RPC reply (%s) content.\n", data_prev->filename);
                                goto cleanup;
                            } else if (u & 0x4) {
                                lyxml_free(ctx, data_prev->xml->child);
                                u &= ~0x4; /* unset lyxml_free() flag */
                            }
                        }

                        /* finally, parse RPC reply from the previous step */
                        data_prev->tree = lyd_parse_xml(ctx, &data_prev->xml->child,
                                                        (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_RPCREPLY, data_item->tree, oper);
                    } else { /* LYD_JSON */
                        data_prev->tree = lyd_parse_path(ctx, data_prev->filename, data_item->format,
                                                         (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_RPCREPLY, data_item->tree, oper);
                    }
                }
            } else if ((options_parser & LYD_OPT_TYPEMASK) == LYD_OPT_RPCREPLY) {
                if (data_prev && !data_prev->tree) {
                    /* now we should have RPC for the preceding RPC reply */
                    data_item->tree = lyd_parse_path(ctx, data_item->filename, data_item->format,
                                                     (options_parser & ~LYD_OPT_TYPEMASK) | LYD_OPT_RPC, oper);
                    data_item->type = LYD_OPT_RPC;
                    goto parse_reply;
                } else {
                    /* now we have RPC reply which will be parsed in next step together with its RPC */
                    if (!data_item->next) {
                        fprintf(stderr, "yanglint error: RPC reply (%s) must be paired with the original RPC, see help.\n", data_item->filename);
                        goto cleanup;
                    }
                    if (data_item->format == LYD_XML) {
                        /* create rpc-reply container to unify handling with autodetection */
                        data_item->xml = calloc(1, sizeof *data_item->xml);
                        if (!data_item->xml) {
                            fprintf(stderr, "yanglint error: Memory allocation failed failed.\n");
                            goto cleanup;
                        }
                        data_item->xml->name = lydict_insert(ctx, "rpc-reply", 9);
                        data_item->xml->prev = data_item->xml;
                        data_item->xml->child = lyxml_parse_path(ctx, data_item->filename, LYXML_PARSE_MULTIROOT | LYXML_PARSE_NOMIXEDCONTENT);
                        if (data_item->xml->child) {
                            data_item->xml->child->parent = data_item->xml;
                        }
                    }
                    continue;
                }
            } else {
#else
            {
#endif
                /* TODO optimize use of ly_in in the loop */
                struct ly_in *in;
                if (ly_in_new_filepath(data_item->filename, 0, &in)) {
                    fprintf(stderr, "yanglint error: input data file \"%s\".\n", data_item->filename);
                    goto cleanup;
                }
                if (lyd_parse_data(ctx, in, 0, options_parser, LYD_VALIDATE_PRESENT, &data_item->tree)) {
                    fprintf(stderr, "yanglint error: Failed to parse input data file \"%s\".\n", data_item->filename);
                    ly_in_free(in, 0);
                    goto cleanup;
                }
                ly_in_free(in, 0);
            }
#if 0
            if (merge && data != data_item) {
                if (!data->tree) {
                    data->tree = data_item->tree;
                } else if (data_item->tree) {
                    /* merge results */
                    if (lyd_merge(data->tree, data_item->tree, LYD_OPT_DESTRUCT | LYD_OPT_EXPLICIT)) {
                        fprintf(stderr, "yanglint error: merging multiple data trees failed.\n");
                        goto cleanup;
                    }
                }
                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) {
                LY_TREE_DFS_BEGIN(subroot, next, node) {
                    node->validity = LYD_VAL_OK;
                    switch (node->schema->nodetype) {
                    case LYS_LEAFLIST:
                    case LYS_LEAF:
                        if (((struct lys_node_leaf *)node->schema)->type.base == LY_TYPE_LEAFREF) {
                            node->validity |= LYD_VAL_LEAFREF;
                        }
                        break;
                    case LYS_LIST:
                        node->validity |= LYD_VAL_UNIQUE;
                        /* falls through */
                    case LYS_CONTAINER:
                    case LYS_NOTIF:
                    case LYS_RPC:
                    case LYS_ACTION:
                        node->validity |= LYD_VAL_MAND;
                        break;
                    default:
                        break;
                    }
                    LY_TREE_DFS_END(subroot, next, node)
                }
            }
            if (lyd_validate(&data->tree, options_parser & ~LYD_OPT_TRUSTED, ctx)) {
                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:
                        envelope_s = "data";
                        break;
                    case LYD_OPT_CONFIG:
                        envelope_s = "config";
                        break;
                    case LYD_OPT_GET:
                        envelope_s = "get-reply";
                        break;
                    case LYD_OPT_GETCONFIG:
                        envelope_s = "get-config-reply";
                        break;
                    case LYD_OPT_EDIT:
                        envelope_s = "edit-config";
                        break;
                    case LYD_OPT_RPC:
                        envelope_s = "rpc";
                        break;
                    case LYD_OPT_RPCREPLY:
                        envelope_s = "rpc-reply";
                        break;
                    case LYD_OPT_NOTIF:
                        envelope_s = "notification";
                        break;
                    }
                    fprintf(out, "<%s>\n", envelope_s);
                    if (data_item->type == LYD_OPT_RPC && data_item->tree->schema->nodetype != LYS_RPC) {
                        /* action */
                        fprintf(out, "<action xmlns=\"urn:ietf:params:xml:ns:yang:1\">\n");
                    }
                }
#endif
                lyd_print_all(out, data_item->tree, outformat_d, 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");
                    }
                    fprintf(out, "</%s>\n", envelope_s);
                }
                if (merge) {
                    /* stop after first item */
                    break;
                }
#endif
            }
        }
    }
#if 0
    if (list) {
        print_list(out, ctx, outformat_d);
    }
#endif

    ret = EXIT_SUCCESS;

cleanup:
    ly_set_free(mods, NULL);
    ly_set_free(searchpaths, NULL);
    for (i = 0; i < featsize; i++) {
        free(feat[i]);
    }
    free(feat);
    for (; data; data = data_item) {
        data_item = data->next;
        lyd_free_all(data->tree);
        free(data);
    }
    ly_ctx_destroy(ctx, NULL);

    ly_out_free(out, NULL, 1);
    return ret;
}
