Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id: skin_parser.c 26752 2010-06-10 21:22:16Z bieber $ |
| 9 | * |
| 10 | * Copyright (C) 2010 Jonathan Gordon |
| 11 | * |
| 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. |
| 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <stdio.h> |
| 24 | #include <string.h> |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 25 | #include <stdbool.h> |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 26 | #include <ctype.h> |
| 27 | |
| 28 | #include "skin_parser.h" |
| 29 | #include "skin_debug.h" |
| 30 | #include "tag_table.h" |
| 31 | #include "symbols.h" |
| 32 | #include "skin_scan.h" |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 33 | #include "skin_structs.h" |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 34 | |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 35 | #define MAX_LINE 1024 |
| 36 | |
| 37 | typedef void (*skin_render_func)(struct skin_element* alternator, |
| 38 | char* buf, size_t buf_size, int line_number); |
| 39 | void skin_render_alternator(struct skin_element* alternator, |
| 40 | char* buf, size_t buf_size, int line_number); |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 41 | |
Jonathan Gordon | b49577b | 2010-06-14 10:00:22 +0000 | [diff] [blame] | 42 | static void do_tags_in_hidden_conditional(struct skin_element* branch) |
| 43 | { |
| 44 | /* Tags here are ones which need to be "turned off" or cleared |
| 45 | * if they are in a conditional branch which isnt being used */ |
| 46 | if (branch->type == SUBLINES) |
| 47 | { |
| 48 | int i; |
| 49 | for (i=0; i<branch->children_count; i++) |
| 50 | { |
| 51 | do_tags_in_hidden_conditional(branch->children[i]); |
| 52 | } |
| 53 | } |
| 54 | else if (branch->type == LINE) |
| 55 | { |
| 56 | struct skin_element *child = branch->children[0]; |
| 57 | while (child) |
| 58 | { |
| 59 | if (child->type != TAG) |
| 60 | { |
| 61 | child = child->next; |
| 62 | continue; |
| 63 | } |
| 64 | switch (child->tag->type) |
| 65 | { |
| 66 | case SKIN_TOKEN_PEAKMETER: |
| 67 | /* stop the peak meter */ |
| 68 | break; |
| 69 | case SKIN_TOKEN_ALBUMART_DISPLAY: |
| 70 | /* clear the AA image */ |
| 71 | break; |
| 72 | case SKIN_TOKEN_IMAGE_DISPLAY: |
| 73 | case SKIN_TOKEN_IMAGE_PRELOAD_DISPLAY: |
| 74 | printf("disable image\n"); |
| 75 | /* clear images */ |
| 76 | break; |
| 77 | default: |
| 78 | break; |
| 79 | } |
| 80 | child = child->next; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 86 | /* Draw a LINE element onto the display */ |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 87 | void skin_render_line(struct skin_element* line, |
| 88 | char* buf, size_t buf_size, int line_number) |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 89 | { |
Jonathan Gordon | b49577b | 2010-06-14 10:00:22 +0000 | [diff] [blame] | 90 | int last_value, value; |
Jonathan Gordon | 3f06273 | 2010-06-13 02:27:13 +0000 | [diff] [blame] | 91 | if (line->children_count == 0) |
| 92 | return; /* empty line, do nothing */ |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 93 | struct skin_element *child = line->children[0]; |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 94 | skin_render_func func = skin_render_line; |
| 95 | char tempbuf[128]; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 96 | while (child) |
| 97 | { |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 98 | tempbuf[0] = '\0'; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 99 | switch (child->type) |
| 100 | { |
| 101 | case CONDITIONAL: |
Jonathan Gordon | b49577b | 2010-06-14 10:00:22 +0000 | [diff] [blame] | 102 | last_value = ((struct conditional*)(child->data))->last_value; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 103 | value = 0; /* actually get it from the token :p */ |
| 104 | if (value >= child->children_count) |
| 105 | value = child->children_count-1; |
Jonathan Gordon | b49577b | 2010-06-14 10:00:22 +0000 | [diff] [blame] | 106 | |
| 107 | /* some tags need handling if they are being disabled */ |
| 108 | if (value != last_value && last_value < child->children_count) |
| 109 | do_tags_in_hidden_conditional(child->children[last_value]); |
| 110 | last_value = value; |
| 111 | |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 112 | if (child->children[value]->type == SUBLINES) |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 113 | func = skin_render_alternator; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 114 | else if (child->children[value]->type == LINE) |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 115 | func = skin_render_line; |
| 116 | func(child->children[value], buf, buf_size, line_number); |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 117 | break; |
| 118 | case TAG: |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 119 | snprintf(tempbuf, sizeof(tempbuf), "%%%s", child->tag->name); |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 120 | break; |
| 121 | case TEXT: |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 122 | snprintf(tempbuf, sizeof(tempbuf), "%s", (char*)(child->data)); |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 123 | break; |
| 124 | case COMMENT: |
| 125 | default: |
| 126 | break; |
| 127 | } |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 128 | strcat(buf, tempbuf); |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 129 | child = child->next; |
| 130 | } |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 131 | } |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 132 | #define TIME_AFTER(a,b) 1 |
| 133 | void skin_render_alternator(struct skin_element* alternator, |
| 134 | char* buf, size_t buf_size, int line_number) |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 135 | { |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 136 | struct subline *subline = (struct subline*)alternator->data; |
| 137 | if (TIME_AFTER(subline->last_change_tick + subline->timeout, 0/*FIXME*/)) |
| 138 | { |
| 139 | subline->current_line++; |
| 140 | if (subline->current_line >= alternator->children_count) |
| 141 | subline->current_line = 0; |
| 142 | } |
| 143 | skin_render_line(alternator->children[subline->current_line], |
| 144 | buf, buf_size, line_number); |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Jonathan Gordon | 17c3484 | 2010-06-13 14:42:09 +0000 | [diff] [blame] | 147 | void skin_render_viewport(struct skin_element* viewport, bool draw_tags) |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 148 | { |
Jonathan Gordon | 3f06273 | 2010-06-13 02:27:13 +0000 | [diff] [blame] | 149 | int line_number = 0; |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 150 | char linebuf[MAX_LINE]; |
| 151 | skin_render_func func = skin_render_line; |
Jonathan Gordon | 17c3484 | 2010-06-13 14:42:09 +0000 | [diff] [blame] | 152 | struct skin_element* line = viewport; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 153 | while (line) |
| 154 | { |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 155 | linebuf[0] = '\0'; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 156 | if (line->type == SUBLINES) |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 157 | func = skin_render_alternator; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 158 | else if (line->type == LINE) |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 159 | func = skin_render_line; |
| 160 | |
Jonathan Gordon | 17c3484 | 2010-06-13 14:42:09 +0000 | [diff] [blame] | 161 | func(line, linebuf, sizeof(linebuf), line_number); |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 162 | if (draw_tags) |
| 163 | { |
Jonathan Gordon | 3f5851f | 2010-06-14 01:08:39 +0000 | [diff] [blame] | 164 | printf("[%d]%s", line_number, linebuf); |
Jonathan Gordon | 17c3484 | 2010-06-13 14:42:09 +0000 | [diff] [blame] | 165 | if (!((struct line*)line->data)->eat_line_ending) |
| 166 | { |
| 167 | printf("\n"); |
| 168 | } |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 169 | } |
Jonathan Gordon | dfce357 | 2010-06-13 14:42:47 +0000 | [diff] [blame] | 170 | if (!((struct line*)line->data)->eat_line_ending) |
| 171 | line_number++; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 172 | line = line->next; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | void skin_render(struct skin_element* root) |
| 177 | { |
| 178 | struct skin_element* viewport = root; |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 179 | bool draw_tags = viewport->next ? false : true; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 180 | while (viewport) |
| 181 | { |
Jonathan Gordon | 21cbdac | 2010-06-13 13:54:34 +0000 | [diff] [blame] | 182 | skin_render_viewport(viewport->children[0], draw_tags); |
| 183 | draw_tags = true; |
Jonathan Gordon | b4a9564 | 2010-06-11 04:47:46 +0000 | [diff] [blame] | 184 | viewport = viewport->next; |
| 185 | } |
| 186 | } |