count line numbers correctly, handle the VIEWPORT change so it only ever has one...
[kugel-rb.git] / utils / newparser / skin_render.c
blobe71a867130357266d5c60c120ebd71df899e40f9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: skin_parser.c 26752 2010-06-10 21:22:16Z bieber $
10 * Copyright (C) 2010 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <ctype.h>
27 #include "skin_parser.h"
28 #include "skin_debug.h"
29 #include "tag_table.h"
30 #include "symbols.h"
31 #include "skin_scan.h"
33 void skin_render_alternator(struct skin_element* alternator, int line_number);
35 /* Draw a LINE element onto the display */
36 void skin_render_line(struct skin_element* line, int line_number)
38 int i=0, value;
39 if (line->children_count == 0)
40 return; /* empty line, do nothing */
41 struct skin_element *child = line->children[0];
42 while (child)
44 switch (child->type)
46 case CONDITIONAL:
47 value = 0; /* actually get it from the token :p */
48 if (value >= child->children_count)
49 value = child->children_count-1;
50 if (child->children[value]->type == SUBLINES)
51 skin_render_alternator(child->children[value], line_number);
52 else if (child->children[value]->type == LINE)
53 skin_render_line(child->children[value], line_number);
54 break;
55 case TAG:
56 printf("%%%s", child->tag->name);
57 break;
58 case TEXT:
59 printf("%s", (char*)(child->data));
60 break;
61 case COMMENT:
62 default:
63 break;
65 child = child->next;
69 void skin_render_alternator(struct skin_element* alternator, int line_number)
71 /*TODO Choose which subline to draw */
72 skin_render_line(alternator->children[0], line_number);
75 void skin_render_viewport(struct skin_element* viewport)
77 struct skin_element *line = viewport;
78 int line_number = 0;
79 while (line)
81 printf("\n[%d]", line_number); /* might be incorrect */
82 if (line->type == SUBLINES)
83 skin_render_alternator(line, line_number);
84 else if (line->type == LINE)
85 skin_render_line(line, line_number);
86 line_number++;
87 line = line->next;
91 void skin_render(struct skin_element* root)
93 struct skin_element* viewport = root;
94 while (viewport)
96 skin_render_viewport(viewport->children[0]);
97 viewport = viewport->next;