Fix checkwps for remote screens
[kugel-rb.git] / tools / checkwps / checkwps.c
blob4cb2652c91843b75465083efeba5b29fb6a5cbdd
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2008 by Dave Chapman
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 <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include "config.h"
26 #include "checkwps.h"
27 #include "resize.h"
28 #include "wps.h"
29 #include "wps_internals.h"
30 #include "settings.h"
32 bool debug_wps = true;
33 int wps_verbose_level = 0;
35 int errno;
37 const struct settings_list *settings;
38 const int nb_settings = 0;
40 /* static endianness conversion */
41 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
42 ((unsigned short)(x) << 8)))
44 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
45 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
46 (((unsigned long)(x) & 0xff00ul) << 8) | \
47 ((unsigned long)(x) << 24)))
49 #ifndef letoh16
50 unsigned short letoh16(unsigned short x)
52 unsigned short n = 0x1234;
53 unsigned char* ch = (unsigned char*)&n;
55 if (*ch == 0x34)
57 /* Little-endian */
58 return x;
59 } else {
60 return SWAP_16(x);
63 #endif
65 #ifndef letoh32
66 unsigned short letoh32(unsigned short x)
68 unsigned short n = 0x1234;
69 unsigned char* ch = (unsigned char*)&n;
71 if (*ch == 0x34)
73 /* Little-endian */
74 return x;
75 } else {
76 return SWAP_32(x);
79 #endif
81 #ifndef htole32
82 unsigned int htole32(unsigned int x)
84 unsigned short n = 0x1234;
85 unsigned char* ch = (unsigned char*)&n;
87 if (*ch == 0x34)
89 /* Little-endian */
90 return x;
91 } else {
92 return SWAP_32(x);
95 #endif
97 int read_line(int fd, char* buffer, int buffer_size)
99 int count = 0;
100 int num_read = 0;
102 errno = 0;
104 while (count < buffer_size)
106 unsigned char c;
108 if (1 != read(fd, &c, 1))
109 break;
111 num_read++;
113 if ( c == '\n' )
114 break;
116 if ( c == '\r' )
117 continue;
119 buffer[count++] = c;
122 buffer[MIN(count, buffer_size - 1)] = 0;
124 return errno ? -1 : num_read;
127 bool load_wps_backdrop(const char* filename)
129 return true;
132 bool load_remote_wps_backdrop(const char* filename)
134 return true;
137 int recalc_dimension(struct dim *dst, struct dim *src)
139 return 0;
142 int resize_on_load(struct bitmap *bm, bool dither,
143 struct dim *src, struct rowset *tmp_row,
144 unsigned char *buf, unsigned int len,
145 const struct custom_format *cformat,
146 IF_PIX_FMT(int format_index,)
147 struct img_part* (*store_part)(void *args),
148 void *args)
150 return 0;
153 int audio_status(void)
155 return 0;
158 struct mp3entry* audio_current_track(void)
160 return NULL;
163 void audio_stop(void)
167 void audio_play(long offset)
171 static char pluginbuf[PLUGIN_BUFFER_SIZE];
173 static unsigned dummy_func2(void)
175 return 0;
178 void* plugin_get_buffer(size_t *buffer_size)
180 *buffer_size = PLUGIN_BUFFER_SIZE;
181 return pluginbuf;
184 struct user_settings global_settings = {
185 .statusbar = true,
186 #ifdef HAVE_LCD_COLOR
187 .bg_color = LCD_DEFAULT_BG,
188 .fg_color = LCD_DEFAULT_FG,
189 #endif
192 int getwidth(void) { return LCD_WIDTH; }
193 int getheight(void) { return LCD_HEIGHT; }
194 #ifdef HAVE_REMOTE_LCD
195 int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
196 int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
197 #endif
199 struct screen screens[NB_SCREENS] =
202 .screen_type=SCREEN_MAIN,
203 .lcdwidth=LCD_WIDTH,
204 .lcdheight=LCD_HEIGHT,
205 .depth=LCD_DEPTH,
206 #ifdef HAVE_LCD_COLOR
207 .is_color=true,
208 #else
209 .is_color=false,
210 #endif
211 .getwidth = getwidth,
212 .getheight = getheight,
213 #if LCD_DEPTH > 1
214 .get_foreground=dummy_func2,
215 .get_background=dummy_func2,
216 #endif
217 .backdrop_load=backdrop_load,
219 #ifdef HAVE_REMOTE_LCD
221 .screen_type=SCREEN_REMOTE,
222 .lcdwidth=LCD_REMOTE_WIDTH,
223 .lcdheight=LCD_REMOTE_HEIGHT,
224 .depth=LCD_REMOTE_DEPTH,
225 .is_color=false,/* No color remotes yet */
226 .getwidth=remote_getwidth,
227 .getheight=remote_getheight,
228 #if LCD_REMOTE_DEPTH > 1
229 .get_foreground=dummy_func2,
230 .get_background=dummy_func2,
231 #endif
232 .backdrop_load=backdrop_load,
234 #endif
237 #ifdef HAVE_LCD_BITMAP
238 void screen_clear_area(struct screen * display, int xstart, int ystart,
239 int width, int height)
241 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
242 display->fillrect(xstart, ystart, width, height);
243 display->set_drawmode(DRMODE_SOLID);
245 #endif
247 /* From skin_display.c */
248 void skin_data_init(struct wps_data *wps_data)
250 #ifdef HAVE_LCD_BITMAP
251 wps_data->wps_sb_tag = false;
252 wps_data->show_sb_on_wps = false;
253 wps_data->peak_meter_enabled = false;
254 wps_data->images = NULL;
255 wps_data->progressbars = NULL;
256 /* progress bars */
257 #else /* HAVE_LCD_CHARCELLS */
258 int i;
259 for (i = 0; i < 8; i++)
261 wps_data->wps_progress_pat[i] = 0;
263 wps_data->full_line_progressbar = false;
264 #endif
265 wps_data->button_time_volume = 0;
266 wps_data->wps_loaded = false;
269 #ifdef HAVE_LCD_BITMAP
270 struct gui_img* find_image(char label, struct wps_data *data)
272 struct skin_token_list *list = data->images;
273 while (list)
275 struct gui_img *img = (struct gui_img *)list->token->value.data;
276 if (img->label == label)
277 return img;
278 list = list->next;
280 return NULL;
282 #endif
284 struct skin_viewport* find_viewport(char label, struct wps_data *data)
286 struct skin_token_list *list = data->viewports;
287 while (list)
289 struct skin_viewport *vp = (struct skin_viewport *)list->token->value.data;
290 if (vp->label == label)
291 return vp;
292 list = list->next;
294 return NULL;
297 int skin_last_token_index(struct wps_data *data, int line, int subline)
299 int first_subline_idx = data->lines[line].first_subline_idx;
300 int idx = first_subline_idx + subline;
301 if (idx < data->num_sublines - 1)
303 /* This subline ends where the next begins */
304 return data->sublines[idx+1].first_token_idx - 1;
306 else
308 /* The last subline goes to the end */
309 return data->num_tokens - 1;
313 /* From viewport.c & misc.h */
314 #define LIST_VALUE_PARSED(setvals, position) ((setvals) & BIT_N(position))
316 /*some short cuts for fg/bg/line selector handling */
317 #ifdef HAVE_LCD_COLOR
318 #define LINE_SEL_FROM_SETTINGS(vp) \
319 do { \
320 vp->lss_pattern = global_settings.lss_color; \
321 vp->lse_pattern = global_settings.lse_color; \
322 vp->lst_pattern = global_settings.lst_color; \
323 } while (0)
324 #define FG_FALLBACK global_settings.fg_color
325 #define BG_FALLBACK global_settings.bg_color
326 #else
327 /* mono/greyscale doesn't have most of the above */
328 #define LINE_SEL_FROM_SETTINGS(vp)
329 #define FG_FALLBACK LCD_DEFAULT_FG
330 #define BG_FALLBACK LCD_DEFAULT_BG
331 #endif
333 #ifdef HAVE_LCD_COLOR
334 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
335 #else
336 #define ARG_STRING(_depth) "dddddgg"
337 #endif
339 extern const char* parse_list(const char *fmt, uint32_t *set_vals,
340 const char sep, const char* str, ...);
342 const char* viewport_parse_viewport(struct viewport *vp,
343 enum screen_type screen,
344 const char *bufptr,
345 const char separator)
347 /* parse the list to the viewport struct */
348 const char *ptr = bufptr;
349 int depth;
350 uint32_t set = 0;
352 enum {
353 PL_X = 0,
354 PL_Y,
355 PL_WIDTH,
356 PL_HEIGHT,
357 PL_FONT,
358 PL_FG,
359 PL_BG,
362 /* Work out the depth of this display */
363 depth = screens[screen].depth;
364 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
365 if (depth == 1)
367 if (!(ptr = parse_list("ddddd", &set, separator, ptr,
368 &vp->x, &vp->y, &vp->width, &vp->height, &vp->font)))
369 return NULL;
371 else
372 #endif
373 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
374 if (depth >= 2)
376 if (!(ptr = parse_list(ARG_STRING(depth), &set, separator, ptr,
377 &vp->x, &vp->y, &vp->width, &vp->height, &vp->font,
378 &vp->fg_pattern,&vp->bg_pattern)))
379 return NULL;
381 else
382 #endif
384 #undef ARG_STRING
386 /* X and Y *must* be set */
387 if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y))
388 return NULL;
390 /* fix defaults */
391 if (!LIST_VALUE_PARSED(set, PL_WIDTH))
392 vp->width = screens[screen].lcdwidth - vp->x;
393 if (!LIST_VALUE_PARSED(set, PL_HEIGHT))
394 vp->height = screens[screen].lcdheight - vp->y;
396 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
397 if (!LIST_VALUE_PARSED(set, PL_FG))
398 vp->fg_pattern = FG_FALLBACK;
399 if (!LIST_VALUE_PARSED(set, PL_BG))
400 vp->bg_pattern = BG_FALLBACK;
401 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
403 LINE_SEL_FROM_SETTINGS(vp);
405 /* Validate the viewport dimensions - we know that the numbers are
406 non-negative integers, ignore bars and assume the viewport takes them
407 * into account */
408 if ((vp->x >= screens[screen].lcdwidth) ||
409 ((vp->x + vp->width) > screens[screen].lcdwidth) ||
410 (vp->y >= screens[screen].lcdheight) ||
411 ((vp->y + vp->height) > screens[screen].lcdheight))
413 return NULL;
416 /* Default to using the user font if the font was an invalid number or '-'*/
417 if (((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI))
418 || !LIST_VALUE_PARSED(set, PL_FONT)
420 vp->font = FONT_UI;
422 /* Set the defaults for fields not user-specified */
423 vp->drawmode = DRMODE_SOLID;
425 return ptr;
428 int main(int argc, char **argv)
430 int res;
431 int filearg = 1;
433 struct wps_data wps;
434 struct screen* wps_screen;
436 /* No arguments -> print the help text
437 * Also print the help text upon -h or --help */
438 if( (argc < 2) ||
439 strcmp(argv[1],"-h") == 0 ||
440 strcmp(argv[1],"--help") == 0 )
442 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
443 printf("\nOPTIONS:\n");
444 printf("\t-v\t\tverbose\n");
445 printf("\t-vv\t\tmore verbose\n");
446 printf("\t-vvv\t\tvery verbose\n");
447 printf("\t-h,\t--help\tshow this message\n");
448 return 1;
451 if (argv[1][0] == '-') {
452 filearg++;
453 int i = 1;
454 while (argv[1][i] && argv[1][i] == 'v') {
455 i++;
456 wps_verbose_level++;
460 skin_buffer_init();
462 /* Go through every wps that was thrown at us, error out at the first
463 * flawed wps */
464 while (argv[filearg]) {
465 printf("Checking %s...\n", argv[filearg]);
466 if(strcmp(&argv[filearg][strlen(argv[filearg])-4], "rwps") == 0)
468 wps_screen = &screens[SCREEN_REMOTE];
469 wps.remote_wps = true;
471 else
473 wps_screen = &screens[SCREEN_MAIN];
474 wps.remote_wps = false;
477 res = skin_data_load(&wps, wps_screen, argv[filearg], true);
479 if (!res) {
480 printf("WPS parsing failure\n");
481 return 3;
484 printf("WPS parsed OK\n\n");
485 filearg++;
487 return 0;