checkwps: Do not error out on rwps for non-remote targets.
[maemo-rb.git] / tools / checkwps / checkwps.c
blob06f88bbbbfa7ae0828085927900177852e13f058
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 "skin_buffer.h"
30 #include "skin_debug.h"
31 #include "skin_engine.h"
32 #include "wps_internals.h"
33 #include "settings.h"
34 #include "viewport.h"
35 #include "file.h"
36 #include "font.h"
38 bool debug_wps = true;
39 int wps_verbose_level = 0;
40 char *skin_buffer;
42 int errno;
44 const struct settings_list *settings;
45 const int nb_settings = 0;
47 /* static endianness conversion */
48 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
49 ((unsigned short)(x) << 8)))
51 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
52 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
53 (((unsigned long)(x) & 0xff00ul) << 8) | \
54 ((unsigned long)(x) << 24)))
56 #ifndef letoh16
57 unsigned short letoh16(unsigned short x)
59 unsigned short n = 0x1234;
60 unsigned char* ch = (unsigned char*)&n;
62 if (*ch == 0x34)
64 /* Little-endian */
65 return x;
66 } else {
67 return SWAP_16(x);
70 #endif
72 #ifndef letoh32
73 unsigned short letoh32(unsigned short x)
75 unsigned short n = 0x1234;
76 unsigned char* ch = (unsigned char*)&n;
78 if (*ch == 0x34)
80 /* Little-endian */
81 return x;
82 } else {
83 return SWAP_32(x);
86 #endif
88 #ifndef htole32
89 unsigned int htole32(unsigned int x)
91 unsigned short n = 0x1234;
92 unsigned char* ch = (unsigned char*)&n;
94 if (*ch == 0x34)
96 /* Little-endian */
97 return x;
98 } else {
99 return SWAP_32(x);
102 #endif
104 int recalc_dimension(struct dim *dst, struct dim *src)
106 return 0;
109 #ifdef HAVE_ALBUMART
110 int playback_claim_aa_slot(struct dim *dim)
112 return 0;
115 void playback_release_aa_slot(int slot)
117 return;
119 #endif
121 int resize_on_load(struct bitmap *bm, bool dither,
122 struct dim *src, struct rowset *tmp_row,
123 unsigned char *buf, unsigned int len,
124 const struct custom_format *cformat,
125 IF_PIX_FMT(int format_index,)
126 struct img_part* (*store_part)(void *args),
127 void *args)
129 return 0;
132 static char pluginbuf[PLUGIN_BUFFER_SIZE];
134 static unsigned dummy_func2(void)
136 return 0;
139 void* plugin_get_buffer(size_t *buffer_size)
141 *buffer_size = PLUGIN_BUFFER_SIZE;
142 return pluginbuf;
145 struct user_settings global_settings = {
146 .statusbar = STATUSBAR_TOP,
147 #ifdef HAVE_LCD_COLOR
148 .bg_color = LCD_DEFAULT_BG,
149 .fg_color = LCD_DEFAULT_FG,
150 #endif
153 struct system_status global_status;
155 int getwidth(void) { return LCD_WIDTH; }
156 int getheight(void) { return LCD_HEIGHT; }
157 int getuifont(void) { return 0; }
158 #ifdef HAVE_REMOTE_LCD
159 int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
160 int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
161 #endif
163 static inline bool backdrop_load(const char *filename, char* backdrop_buffer)
165 (void)filename; (void)backdrop_buffer; return true;
168 struct screen screens[NB_SCREENS] =
171 .screen_type=SCREEN_MAIN,
172 .lcdwidth=LCD_WIDTH,
173 .lcdheight=LCD_HEIGHT,
174 .depth=LCD_DEPTH,
175 #ifdef HAVE_LCD_COLOR
176 .is_color=true,
177 #else
178 .is_color=false,
179 #endif
180 .getwidth = getwidth,
181 .getheight = getheight,
182 #ifdef HAVE_LCD_BITMAP
183 .getuifont = getuifont,
184 #endif
185 #if LCD_DEPTH > 1
186 .get_foreground=dummy_func2,
187 .get_background=dummy_func2,
188 .backdrop_load=backdrop_load,
189 #endif
191 #ifdef HAVE_REMOTE_LCD
193 .screen_type=SCREEN_REMOTE,
194 .lcdwidth=LCD_REMOTE_WIDTH,
195 .lcdheight=LCD_REMOTE_HEIGHT,
196 .depth=LCD_REMOTE_DEPTH,
197 .getuifont = getuifont,
198 .is_color=false,/* No color remotes yet */
199 .getwidth=remote_getwidth,
200 .getheight=remote_getheight,
201 #if LCD_REMOTE_DEPTH > 1
202 .get_foreground=dummy_func2,
203 .get_background=dummy_func2,
204 .backdrop_load=backdrop_load,
205 #endif
207 #endif
210 #ifdef HAVE_LCD_BITMAP
211 void screen_clear_area(struct screen * display, int xstart, int ystart,
212 int width, int height)
214 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
215 display->fillrect(xstart, ystart, width, height);
216 display->set_drawmode(DRMODE_SOLID);
218 #endif
220 #if CONFIG_TUNER
221 bool radio_hardware_present(void)
223 return true;
225 #endif
227 #ifdef HAVE_LCD_BITMAP
228 static int loaded_fonts = 0;
229 static struct font _font;
230 int font_load(const char *path)
232 int id = 2 + loaded_fonts;
233 loaded_fonts++;
234 return id;
237 void font_unload(int font_id)
239 (void)font_id;
242 struct font* font_get(int font)
244 return &_font;
246 #endif
248 /* This is no longer defined in ROCKBOX builds so just use a huge value */
249 #define SKIN_BUFFER_SIZE (200*1024)
251 int main(int argc, char **argv)
253 int res;
254 int filearg = 1;
256 struct wps_data wps={0};
257 enum screen_type screen = SCREEN_MAIN;
258 struct screen* wps_screen;
260 /* No arguments -> print the help text
261 * Also print the help text upon -h or --help */
262 if( (argc < 2) ||
263 strcmp(argv[1],"-h") == 0 ||
264 strcmp(argv[1],"--help") == 0 )
266 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
267 printf("\nOPTIONS:\n");
268 printf("\t-v\t\tverbose\n");
269 printf("\t-vv\t\tmore verbose\n");
270 printf("\t-vvv\t\tvery verbose\n");
271 printf("\t-h,\t--help\tshow this message\n");
272 return 1;
275 if (argv[1][0] == '-') {
276 filearg++;
277 int i = 1;
278 while (argv[1][i] && argv[1][i] == 'v') {
279 i++;
280 wps_verbose_level++;
283 skin_buffer = malloc(SKIN_BUFFER_SIZE);
284 if (!skin_buffer)
286 printf("mallloc fail!\n");
287 return 1;
290 skin_buffer_init(skin_buffer, SKIN_BUFFER_SIZE);
292 /* Go through every skin that was thrown at us, error out at the first
293 * flawed wps */
294 while (argv[filearg]) {
295 const char* name = argv[filearg++];
296 char *ext = strrchr(name, '.');
297 printf("Checking %s...\n", name);
298 if (!ext)
300 printf("Invalid extension\n");
301 return 2;
303 ext++;
304 if (!strcmp(ext, "rwps") || !strcmp(ext, "rsbs") || !strcmp(ext, "rfms"))
306 #ifdef HAVE_REMOTE_LCD
307 screen = SCREEN_REMOTE;
308 #else
309 /* skip rwps etc. if not supported on this target (not an error) */
310 continue;
311 #endif
313 else if (!strcmp(ext, "wps") || !strcmp(ext, "sbs") || !strcmp(ext, "fms"))
315 screen = SCREEN_MAIN;
317 else
319 printf("Invalid extension\n");
320 return 2;
322 wps_screen = &screens[screen];
324 res = skin_data_load(screen, &wps, name, true);
326 if (!res) {
327 printf("WPS parsing failure\n");
328 skin_error_format_message();
329 return 3;
332 printf("WPS parsed OK\n\n");
333 if (wps_verbose_level>2)
334 skin_debug_tree(SKINOFFSETTOPTR(skin_buffer, wps.tree));
336 return 0;