Welcome to mirror list, hosted at ThFree Co, Russian Federation.

tree.c « render « modest « source - github.com/lexborisov/Modest.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6c705dd74a7fa34dd61c05a24d7f543cb6e1c8dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 Copyright (C) 2016-2017 Alexander Borisov
 
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.
 
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 Lesser General Public License for more details.
 
 You should have received a copy of the GNU Lesser General Public
 License along with this library; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 Author: lex.borisov@gmail.com (Alexander Borisov)
*/

#include "modest/render/tree.h"

modest_render_tree_t * modest_render_tree_create(void)
{
    return mycore_calloc(1, sizeof(modest_render_tree_t));
}

mystatus_t modest_render_tree_init(modest_render_tree_t* render_tree)
{
    render_tree->mc_nodes = mcobject_create();
    if(render_tree->mc_nodes == NULL)
        return MODEST_STATUS_ERROR_MEMORY_ALLOCATION;
    
    mystatus_t myhtml_status = mcobject_init(render_tree->mc_nodes, 1024, sizeof(modest_render_tree_node_t));
    if(myhtml_status)
        return MODEST_STATUS_ERROR;
    
    return MODEST_STATUS_OK;
}

void modest_render_tree_clean_all(modest_render_tree_t* render_tree)
{
    memset(render_tree, 0, sizeof(modest_render_tree_t));
}

modest_render_tree_t * modest_render_tree_destroy(modest_render_tree_t* render_tree, bool self_destroy)
{
    if(render_tree == NULL)
        return NULL;
    
    render_tree->mc_nodes = mcobject_destroy(render_tree->mc_nodes, true);
    
    if(self_destroy) {
        mycore_free(render_tree);
        return NULL;
    }
    
    return render_tree;
}

void modest_render_tree_serialization(myhtml_tree_t* html_tree, modest_render_tree_t* tree,
                                      modest_render_tree_node_t* scope_node, mycore_callback_serialize_f callback, void* context)
{
    modest_render_tree_node_t* node = scope_node;
    size_t depth = 0;
    
    while(node) {
        for(size_t i = 0; i < depth; i++)
            callback("\t", 1, context);
        
        modest_render_tree_node_serialization(html_tree, node, callback, context);
        callback("\n", 1, context);
        
        if(node->child) {
            depth++;
            node = node->child;
        }
        else {
            while(node != scope_node && node->next == NULL) {
                depth--;
                node = node->parent;
            }
            
            if(node == scope_node)
                break;
            
            node = node->next;
        }
    }
    
    
}