summaryrefslogtreecommitdiff
path: root/utils/newparser/skin_render.c
blob: e71a867130357266d5c60c120ebd71df899e40f9 (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
95
96
97
98
99
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id: skin_parser.c 26752 2010-06-10 21:22:16Z bieber $
 *
 * Copyright (C) 2010 Jonathan Gordon
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

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

#include "skin_parser.h"
#include "skin_debug.h"
#include "tag_table.h"
#include "symbols.h"
#include "skin_scan.h"

void skin_render_alternator(struct skin_element* alternator, int line_number);

/* Draw a LINE element onto the display */
void skin_render_line(struct skin_element* line, int line_number)
{
    int i=0, value;
    if (line->children_count == 0)
        return; /* empty line, do nothing */
    struct skin_element *child = line->children[0];
    while (child)
    {
        switch (child->type)
        {
            case CONDITIONAL:
                value = 0; /* actually get it from the token :p */
                if (value >= child->children_count)
                    value = child->children_count-1;
                if (child->children[value]->type == SUBLINES)
                    skin_render_alternator(child->children[value], line_number);
                else if (child->children[value]->type == LINE)
                    skin_render_line(child->children[value], line_number);
                break;
            case TAG:
                printf("%%%s", child->tag->name);
                break;
            case TEXT:
                printf("%s", (char*)(child->data));
                break;
            case COMMENT:
            default:
                break;
        }
        child = child->next;
    }
}

void skin_render_alternator(struct skin_element* alternator, int line_number)
{
    /*TODO Choose which subline to draw */
    skin_render_line(alternator->children[0], line_number);
}

void skin_render_viewport(struct skin_element* viewport)
{
    struct skin_element *line = viewport;
    int line_number = 0;
    while (line)
    {
        printf("\n[%d]", line_number); /* might be incorrect */
        if (line->type == SUBLINES)
            skin_render_alternator(line, line_number);
        else if (line->type == LINE)
            skin_render_line(line, line_number);
        line_number++;
        line = line->next;
    }
}

void skin_render(struct skin_element* root)
{
    struct skin_element* viewport = root;
    while (viewport)
    {
        skin_render_viewport(viewport->children[0]);
        viewport = viewport->next;
    }
}