Fix the pitch detector plugin for iaudioM3
[kugel-rb.git] / tools / checkwps / checkwps.c
blob6e985195fbcc012b0816dd53f71ac664ebff0706
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 /* From viewport.c & misc.h */
298 #define LIST_VALUE_PARSED(setvals, position) ((setvals) & BIT_N(position))
300 /*some short cuts for fg/bg/line selector handling */
301 #ifdef HAVE_LCD_COLOR
302 #define LINE_SEL_FROM_SETTINGS(vp) \
303 do { \
304 vp->lss_pattern = global_settings.lss_color; \
305 vp->lse_pattern = global_settings.lse_color; \
306 vp->lst_pattern = global_settings.lst_color; \
307 } while (0)
308 #define FG_FALLBACK global_settings.fg_color
309 #define BG_FALLBACK global_settings.bg_color
310 #else
311 /* mono/greyscale doesn't have most of the above */
312 #define LINE_SEL_FROM_SETTINGS(vp)
313 #define FG_FALLBACK LCD_DEFAULT_FG
314 #define BG_FALLBACK LCD_DEFAULT_BG
315 #endif
317 #ifdef HAVE_LCD_COLOR
318 #define ARG_STRING(_depth) ((_depth) == 2 ? "dddddgg":"dddddcc")
319 #else
320 #define ARG_STRING(_depth) "dddddgg"
321 #endif
323 extern const char* parse_list(const char *fmt, uint32_t *set_vals,
324 const char sep, const char* str, ...);
326 const char* viewport_parse_viewport(struct viewport *vp,
327 enum screen_type screen,
328 const char *bufptr,
329 const char separator)
331 /* parse the list to the viewport struct */
332 const char *ptr = bufptr;
333 int depth;
334 uint32_t set = 0;
336 enum {
337 PL_X = 0,
338 PL_Y,
339 PL_WIDTH,
340 PL_HEIGHT,
341 PL_FONT,
342 PL_FG,
343 PL_BG,
346 /* Work out the depth of this display */
347 depth = screens[screen].depth;
348 #if (LCD_DEPTH == 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH == 1)
349 if (depth == 1)
351 #ifdef HAVE_LCD_BITMAP
352 if (!(ptr = parse_list("ddddd", &set, separator, ptr,
353 &vp->x, &vp->y, &vp->width, &vp->height, &vp->font)))
354 return NULL;
355 #endif
357 else
358 #endif
359 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
360 if (depth >= 2)
362 if (!(ptr = parse_list(ARG_STRING(depth), &set, separator, ptr,
363 &vp->x, &vp->y, &vp->width, &vp->height, &vp->font,
364 &vp->fg_pattern,&vp->bg_pattern)))
365 return NULL;
367 else
368 #endif
370 #undef ARG_STRING
372 /* X and Y *must* be set */
373 if (!LIST_VALUE_PARSED(set, PL_X) || !LIST_VALUE_PARSED(set, PL_Y))
374 return NULL;
376 /* fix defaults */
377 if (!LIST_VALUE_PARSED(set, PL_WIDTH))
378 vp->width = screens[screen].lcdwidth - vp->x;
379 if (!LIST_VALUE_PARSED(set, PL_HEIGHT))
380 vp->height = screens[screen].lcdheight - vp->y;
382 #if (LCD_DEPTH > 1) || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
383 if (!LIST_VALUE_PARSED(set, PL_FG))
384 vp->fg_pattern = FG_FALLBACK;
385 if (!LIST_VALUE_PARSED(set, PL_BG))
386 vp->bg_pattern = BG_FALLBACK;
387 #endif /* LCD_DEPTH > 1 || LCD_REMOTE_DEPTH > 1 */
389 LINE_SEL_FROM_SETTINGS(vp);
391 /* Validate the viewport dimensions - we know that the numbers are
392 non-negative integers, ignore bars and assume the viewport takes them
393 * into account */
394 if ((vp->x >= screens[screen].lcdwidth) ||
395 ((vp->x + vp->width) > screens[screen].lcdwidth) ||
396 (vp->y >= screens[screen].lcdheight) ||
397 ((vp->y + vp->height) > screens[screen].lcdheight))
399 return NULL;
402 #ifdef HAVE_LCD_BITMAP
403 /* Default to using the user font if the font was an invalid number or '-'*/
404 if (((vp->font != FONT_SYSFIXED) && (vp->font != FONT_UI))
405 || !LIST_VALUE_PARSED(set, PL_FONT)
407 vp->font = FONT_UI;
409 /* Set the defaults for fields not user-specified */
410 vp->drawmode = DRMODE_SOLID;
411 #endif
413 return ptr;
416 int main(int argc, char **argv)
418 int res;
419 int filearg = 1;
421 struct wps_data wps;
422 struct screen* wps_screen = &screens[SCREEN_MAIN];
424 /* No arguments -> print the help text
425 * Also print the help text upon -h or --help */
426 if( (argc < 2) ||
427 strcmp(argv[1],"-h") == 0 ||
428 strcmp(argv[1],"--help") == 0 )
430 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
431 printf("\nOPTIONS:\n");
432 printf("\t-v\t\tverbose\n");
433 printf("\t-vv\t\tmore verbose\n");
434 printf("\t-vvv\t\tvery verbose\n");
435 printf("\t-h,\t--help\tshow this message\n");
436 return 1;
439 if (argv[1][0] == '-') {
440 filearg++;
441 int i = 1;
442 while (argv[1][i] && argv[1][i] == 'v') {
443 i++;
444 wps_verbose_level++;
448 skin_buffer_init();
450 /* Go through every wps that was thrown at us, error out at the first
451 * flawed wps */
452 while (argv[filearg]) {
453 printf("Checking %s...\n", argv[filearg]);
454 #ifdef HAVE_REMOTE_LCD
455 if(strcmp(&argv[filearg][strlen(argv[filearg])-4], "rwps") == 0)
457 wps_screen = &screens[SCREEN_REMOTE];
458 wps.remote_wps = true;
460 else
462 wps_screen = &screens[SCREEN_MAIN];
463 wps.remote_wps = false;
465 #endif
467 res = skin_data_load(&wps, wps_screen, argv[filearg], true);
469 if (!res) {
470 printf("WPS parsing failure\n");
471 return 3;
474 printf("WPS parsed OK\n\n");
475 filearg++;
477 return 0;