<commit_before>/**
 * @file printer/tree.c
 * @author <NAME> <<EMAIL>>
 * @brief TREE printer for libyang data model structure
 *
 * Copyright (c) 2015 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
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

#include "common.h"
#include "printer.h"
#include "tree_schema.h"

/* spec_config = 0 (no special config status), 1 (read-only - rpc output, notification), 2 (write-only - rpc input) */
static void tree_print_choice_content(struct lyout *out, const struct lys_module* module, int level, uint64_t indent,
                                      unsigned int max_name_len, const struct lys_node *node, int mask,
                                      int spec_config);
static void tree_print_snode(struct lyout *out, const struct lys_module *module, int level, uint64_t indent,
                             unsigned int max_name_len, const struct lys_node *node, int mask, int spec_config);

static void
print_indent(struct lyout *out, uint64_t indent, int level)
{
    int i;

    for (i = 1; i < level; ++i) {
        if (indent & (1 << i)) {
            ly_print(out, "|  ");
        } else {
            ly_print(out, "   ");
        }
    }
}

static int
sibling_is_valid_child(const struct lys_node *node, int including, const struct lys_module *module)
{
    struct lys_node *cur;

    if (!node) {
        return 0;
    }

    /* has a following printed child */
    LY_TREE_FOR((struct lys_node *)(including ? node : node->next), cur) {
        if (module != lys_node_module(cur)) {
            continue;
        }

        if (!lys_is_disabled(cur, 0)) {
            if (cur->nodetype & (LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYDATA | LYS_CHOICE |
                    LYS_INPUT | LYS_OUTPUT | LYS_CASE)) {
                return 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 (lys_parent(node) && (lys_parent(node)->nodetype == LYS_USES)) {
        return sibling_is_valid_child(lys_parent(node), 0, module);
    }

    return 0;
}<commit_msg>tree printer BUGFIX proper sibling detection<commit_after>/**
 * @file printer/tree.c
 * @author <NAME> <<EMAIL>>
 * @brief TREE printer for libyang data model structure
 *
 * Copyright (c) 2015 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
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>

#include "common.h"
#include "printer.h"
#include "tree_schema.h"

/* spec_config = 0 (no special config status), 1 (read-only - rpc output, notification), 2 (write-only - rpc input) */
static void tree_print_choice_content(struct lyout *out, const struct lys_module* module, int level, uint64_t indent,
                                      unsigned int max_name_len, const struct lys_node *node, int mask,
                                      int spec_config);
static void tree_print_snode(struct lyout *out, const struct lys_module *module, int level, uint64_t indent,
                             unsigned int max_name_len, const struct lys_node *node, int mask, int spec_config);

static void
print_indent(struct lyout *out, uint64_t indent, int level)
{
    int i;

    for (i = 1; i < level; ++i) {
        if (indent & (1 << i)) {
            ly_print(out, "|  ");
        } else {
            ly_print(out, "   ");
        }
    }
}

static int
sibling_is_valid_child(const struct lys_node *node, int including, const struct lys_module *module)
{
    struct lys_node *cur;

    if (!node) {
        return 0;
    }

    /* has a following printed child */
    LY_TREE_FOR((struct lys_node *)(including ? node : node->next), cur) {
        if (module != lys_node_module(cur)) {
            continue;
        }

        if (!lys_is_disabled(cur, 0)) {
            if (cur->nodetype & (LYS_CONTAINER | LYS_LEAF | LYS_LEAFLIST | LYS_LIST | LYS_ANYDATA | LYS_CHOICE
                    | LYS_CASE | LYS_NOTIF | LYS_ACTION)) {
                return 1;
            }
            if ((cur->nodetype & (LYS_INPUT | LYS_OUTPUT)) && cur->child) {
                return 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 (lys_parent(node) && (lys_parent(node)->nodetype == LYS_USES)) {
        return sibling_is_valid_child(lys_parent(node), 0, module);
    }

    return 0;
}
{'fraction_non_alphanumeric': 0.11506153545614378, 'fraction_numerical': 0.009572182066809924, 'mean_word_length': 2.3203631647211416, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '873699', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1605, 'n_words': 482}