fix checkwps
[kugel-rb.git] / tools / checkwps / checkwps.c
blobd72938b6c1ba8fe027fbd512f3ec75a4ddc3c56d
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"
31 #include "viewport.h"
33 bool debug_wps = true;
34 int wps_verbose_level = 0;
36 int errno;
38 const struct settings_list *settings;
39 const int nb_settings = 0;
41 /* static endianness conversion */
42 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
43 ((unsigned short)(x) << 8)))
45 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
46 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
47 (((unsigned long)(x) & 0xff00ul) << 8) | \
48 ((unsigned long)(x) << 24)))
50 #ifndef letoh16
51 unsigned short letoh16(unsigned short x)
53 unsigned short n = 0x1234;
54 unsigned char* ch = (unsigned char*)&n;
56 if (*ch == 0x34)
58 /* Little-endian */
59 return x;
60 } else {
61 return SWAP_16(x);
64 #endif
66 #ifndef letoh32
67 unsigned short letoh32(unsigned short x)
69 unsigned short n = 0x1234;
70 unsigned char* ch = (unsigned char*)&n;
72 if (*ch == 0x34)
74 /* Little-endian */
75 return x;
76 } else {
77 return SWAP_32(x);
80 #endif
82 #ifndef htole32
83 unsigned int htole32(unsigned int x)
85 unsigned short n = 0x1234;
86 unsigned char* ch = (unsigned char*)&n;
88 if (*ch == 0x34)
90 /* Little-endian */
91 return x;
92 } else {
93 return SWAP_32(x);
96 #endif
98 int read_line(int fd, char* buffer, int buffer_size)
100 int count = 0;
101 int num_read = 0;
103 errno = 0;
105 while (count < buffer_size)
107 unsigned char c;
109 if (1 != read(fd, &c, 1))
110 break;
112 num_read++;
114 if ( c == '\n' )
115 break;
117 if ( c == '\r' )
118 continue;
120 buffer[count++] = c;
123 buffer[MIN(count, buffer_size - 1)] = 0;
125 return errno ? -1 : num_read;
128 bool load_wps_backdrop(const char* filename)
130 return true;
133 bool load_remote_wps_backdrop(const char* filename)
135 return true;
138 int recalc_dimension(struct dim *dst, struct dim *src)
140 return 0;
143 #ifdef HAVE_ALBUMART
144 int playback_claim_aa_slot(struct dim *dim)
146 return 0;
149 void playback_release_aa_slot(int slot)
151 return;
153 #endif
155 int resize_on_load(struct bitmap *bm, bool dither,
156 struct dim *src, struct rowset *tmp_row,
157 unsigned char *buf, unsigned int len,
158 const struct custom_format *cformat,
159 IF_PIX_FMT(int format_index,)
160 struct img_part* (*store_part)(void *args),
161 void *args)
163 return 0;
166 int audio_status(void)
168 return 0;
171 struct mp3entry* audio_current_track(void)
173 return NULL;
176 void audio_stop(void)
180 void audio_play(long offset)
184 static char pluginbuf[PLUGIN_BUFFER_SIZE];
186 static unsigned dummy_func2(void)
188 return 0;
191 void* plugin_get_buffer(size_t *buffer_size)
193 *buffer_size = PLUGIN_BUFFER_SIZE;
194 return pluginbuf;
197 struct user_settings global_settings = {
198 .statusbar = true,
199 #ifdef HAVE_LCD_COLOR
200 .bg_color = LCD_DEFAULT_BG,
201 .fg_color = LCD_DEFAULT_FG,
202 #endif
205 int getwidth(void) { return LCD_WIDTH; }
206 int getheight(void) { return LCD_HEIGHT; }
207 #ifdef HAVE_REMOTE_LCD
208 int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
209 int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
210 #endif
212 struct screen screens[NB_SCREENS] =
215 .screen_type=SCREEN_MAIN,
216 .lcdwidth=LCD_WIDTH,
217 .lcdheight=LCD_HEIGHT,
218 .depth=LCD_DEPTH,
219 #ifdef HAVE_LCD_COLOR
220 .is_color=true,
221 #else
222 .is_color=false,
223 #endif
224 .getwidth = getwidth,
225 .getheight = getheight,
226 #if LCD_DEPTH > 1
227 .get_foreground=dummy_func2,
228 .get_background=dummy_func2,
229 #endif
230 .backdrop_load=backdrop_load,
232 #ifdef HAVE_REMOTE_LCD
234 .screen_type=SCREEN_REMOTE,
235 .lcdwidth=LCD_REMOTE_WIDTH,
236 .lcdheight=LCD_REMOTE_HEIGHT,
237 .depth=LCD_REMOTE_DEPTH,
238 .is_color=false,/* No color remotes yet */
239 .getwidth=remote_getwidth,
240 .getheight=remote_getheight,
241 #if LCD_REMOTE_DEPTH > 1
242 .get_foreground=dummy_func2,
243 .get_background=dummy_func2,
244 #endif
245 .backdrop_load=backdrop_load,
247 #endif
250 #ifdef HAVE_LCD_BITMAP
251 void screen_clear_area(struct screen * display, int xstart, int ystart,
252 int width, int height)
254 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
255 display->fillrect(xstart, ystart, width, height);
256 display->set_drawmode(DRMODE_SOLID);
258 #endif
260 /* From skin_display.c */
261 void skin_data_init(struct wps_data *wps_data)
263 #ifdef HAVE_LCD_BITMAP
264 wps_data->wps_sb_tag = false;
265 wps_data->show_sb_on_wps = false;
266 wps_data->peak_meter_enabled = false;
267 wps_data->images = NULL;
268 wps_data->progressbars = NULL;
269 /* progress bars */
270 #else /* HAVE_LCD_CHARCELLS */
271 int i;
272 for (i = 0; i < 8; i++)
274 wps_data->wps_progress_pat[i] = 0;
276 wps_data->full_line_progressbar = false;
277 #endif
278 wps_data->button_time_volume = 0;
279 wps_data->wps_loaded = false;
282 #ifdef HAVE_LCD_BITMAP
283 struct gui_img* find_image(char label, struct wps_data *data)
285 struct skin_token_list *list = data->images;
286 while (list)
288 struct gui_img *img = (struct gui_img *)list->token->value.data;
289 if (img->label == label)
290 return img;
291 list = list->next;
293 return NULL;
295 #endif
297 struct skin_viewport* find_viewport(char label, struct wps_data *data)
299 struct skin_token_list *list = data->viewports;
300 while (list)
302 struct skin_viewport *vp = (struct skin_viewport *)list->token->value.data;
303 if (vp->label == label)
304 return vp;
305 list = list->next;
307 return NULL;
310 int main(int argc, char **argv)
312 int res;
313 int filearg = 1;
315 struct wps_data wps;
316 struct screen* wps_screen = &screens[SCREEN_MAIN];
318 /* No arguments -> print the help text
319 * Also print the help text upon -h or --help */
320 if( (argc < 2) ||
321 strcmp(argv[1],"-h") == 0 ||
322 strcmp(argv[1],"--help") == 0 )
324 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
325 printf("\nOPTIONS:\n");
326 printf("\t-v\t\tverbose\n");
327 printf("\t-vv\t\tmore verbose\n");
328 printf("\t-vvv\t\tvery verbose\n");
329 printf("\t-h,\t--help\tshow this message\n");
330 return 1;
333 if (argv[1][0] == '-') {
334 filearg++;
335 int i = 1;
336 while (argv[1][i] && argv[1][i] == 'v') {
337 i++;
338 wps_verbose_level++;
342 skin_buffer_init();
344 /* Go through every wps that was thrown at us, error out at the first
345 * flawed wps */
346 while (argv[filearg]) {
347 printf("Checking %s...\n", argv[filearg]);
348 #ifdef HAVE_REMOTE_LCD
349 if(strcmp(&argv[filearg][strlen(argv[filearg])-4], "rwps") == 0)
351 wps_screen = &screens[SCREEN_REMOTE];
352 wps.remote_wps = true;
354 else
356 wps_screen = &screens[SCREEN_MAIN];
357 wps.remote_wps = false;
359 #endif
361 res = skin_data_load(&wps, argv[filearg], true);
363 if (!res) {
364 printf("WPS parsing failure\n");
365 return 3;
368 printf("WPS parsed OK\n\n");
369 filearg++;
371 return 0;