compile checkwps with -Wall, to avoid accidentally breaking it again when a function...
[kugel-rb.git] / tools / checkwps / checkwps.c
blob4736f31e761ceedb44478b627a492576475bec0c
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_engine.h"
30 #include "wps_internals.h"
31 #include "settings.h"
32 #include "viewport.h"
33 #include "file.h"
35 bool debug_wps = true;
36 int wps_verbose_level = 0;
38 int errno;
40 const struct settings_list *settings;
41 const int nb_settings = 0;
43 /* static endianness conversion */
44 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
45 ((unsigned short)(x) << 8)))
47 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
48 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
49 (((unsigned long)(x) & 0xff00ul) << 8) | \
50 ((unsigned long)(x) << 24)))
52 #ifndef letoh16
53 unsigned short letoh16(unsigned short x)
55 unsigned short n = 0x1234;
56 unsigned char* ch = (unsigned char*)&n;
58 if (*ch == 0x34)
60 /* Little-endian */
61 return x;
62 } else {
63 return SWAP_16(x);
66 #endif
68 #ifndef letoh32
69 unsigned short letoh32(unsigned short x)
71 unsigned short n = 0x1234;
72 unsigned char* ch = (unsigned char*)&n;
74 if (*ch == 0x34)
76 /* Little-endian */
77 return x;
78 } else {
79 return SWAP_32(x);
82 #endif
84 #ifndef htole32
85 unsigned int htole32(unsigned int x)
87 unsigned short n = 0x1234;
88 unsigned char* ch = (unsigned char*)&n;
90 if (*ch == 0x34)
92 /* Little-endian */
93 return x;
94 } else {
95 return SWAP_32(x);
98 #endif
100 int read_line(int fd, char* buffer, int buffer_size)
102 int count = 0;
103 int num_read = 0;
105 errno = 0;
107 while (count < buffer_size)
109 unsigned char c;
111 if (1 != read(fd, &c, 1))
112 break;
114 num_read++;
116 if ( c == '\n' )
117 break;
119 if ( c == '\r' )
120 continue;
122 buffer[count++] = c;
125 buffer[MIN(count, buffer_size - 1)] = 0;
127 return errno ? -1 : num_read;
130 bool load_wps_backdrop(const char* filename)
132 return true;
135 bool load_remote_wps_backdrop(const char* filename)
137 return true;
140 int recalc_dimension(struct dim *dst, struct dim *src)
142 return 0;
145 #ifdef HAVE_ALBUMART
146 int playback_claim_aa_slot(struct dim *dim)
148 return 0;
151 void playback_release_aa_slot(int slot)
153 return;
155 #endif
157 int resize_on_load(struct bitmap *bm, bool dither,
158 struct dim *src, struct rowset *tmp_row,
159 unsigned char *buf, unsigned int len,
160 const struct custom_format *cformat,
161 IF_PIX_FMT(int format_index,)
162 struct img_part* (*store_part)(void *args),
163 void *args)
165 return 0;
168 int audio_status(void)
170 return 0;
173 struct mp3entry* audio_current_track(void)
175 return NULL;
178 void audio_stop(void)
182 void audio_play(long offset)
186 static char pluginbuf[PLUGIN_BUFFER_SIZE];
188 static unsigned dummy_func2(void)
190 return 0;
193 void* plugin_get_buffer(size_t *buffer_size)
195 *buffer_size = PLUGIN_BUFFER_SIZE;
196 return pluginbuf;
199 struct user_settings global_settings = {
200 .statusbar = true,
201 #ifdef HAVE_LCD_COLOR
202 .bg_color = LCD_DEFAULT_BG,
203 .fg_color = LCD_DEFAULT_FG,
204 #endif
207 int getwidth(void) { return LCD_WIDTH; }
208 int getheight(void) { return LCD_HEIGHT; }
209 #ifdef HAVE_REMOTE_LCD
210 int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
211 int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
212 #endif
214 struct screen screens[NB_SCREENS] =
217 .screen_type=SCREEN_MAIN,
218 .lcdwidth=LCD_WIDTH,
219 .lcdheight=LCD_HEIGHT,
220 .depth=LCD_DEPTH,
221 #ifdef HAVE_LCD_COLOR
222 .is_color=true,
223 #else
224 .is_color=false,
225 #endif
226 .getwidth = getwidth,
227 .getheight = getheight,
228 #if LCD_DEPTH > 1
229 .get_foreground=dummy_func2,
230 .get_background=dummy_func2,
231 #endif
232 .backdrop_load=backdrop_load,
234 #ifdef HAVE_REMOTE_LCD
236 .screen_type=SCREEN_REMOTE,
237 .lcdwidth=LCD_REMOTE_WIDTH,
238 .lcdheight=LCD_REMOTE_HEIGHT,
239 .depth=LCD_REMOTE_DEPTH,
240 .is_color=false,/* No color remotes yet */
241 .getwidth=remote_getwidth,
242 .getheight=remote_getheight,
243 #if LCD_REMOTE_DEPTH > 1
244 .get_foreground=dummy_func2,
245 .get_background=dummy_func2,
246 #endif
247 .backdrop_load=backdrop_load,
249 #endif
252 #ifdef HAVE_LCD_BITMAP
253 void screen_clear_area(struct screen * display, int xstart, int ystart,
254 int width, int height)
256 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
257 display->fillrect(xstart, ystart, width, height);
258 display->set_drawmode(DRMODE_SOLID);
260 #endif
262 /* From skin_display.c */
263 void skin_data_init(struct wps_data *wps_data)
265 #ifdef HAVE_LCD_BITMAP
266 wps_data->wps_sb_tag = false;
267 wps_data->show_sb_on_wps = false;
268 wps_data->peak_meter_enabled = false;
269 wps_data->images = NULL;
270 wps_data->progressbars = NULL;
271 /* progress bars */
272 #else /* HAVE_LCD_CHARCELLS */
273 int i;
274 for (i = 0; i < 8; i++)
276 wps_data->wps_progress_pat[i] = 0;
278 wps_data->full_line_progressbar = false;
279 #endif
280 wps_data->button_time_volume = 0;
281 wps_data->wps_loaded = false;
284 #ifdef HAVE_LCD_BITMAP
285 struct gui_img* find_image(char label, struct wps_data *data)
287 struct skin_token_list *list = data->images;
288 while (list)
290 struct gui_img *img = (struct gui_img *)list->token->value.data;
291 if (img->label == label)
292 return img;
293 list = list->next;
295 return NULL;
297 #endif
299 struct skin_viewport* find_viewport(char label, struct wps_data *data)
301 struct skin_token_list *list = data->viewports;
302 while (list)
304 struct skin_viewport *vp = (struct skin_viewport *)list->token->value.data;
305 if (vp->label == label)
306 return vp;
307 list = list->next;
309 return NULL;
312 int main(int argc, char **argv)
314 int res;
315 int filearg = 1;
317 struct wps_data wps;
319 /* No arguments -> print the help text
320 * Also print the help text upon -h or --help */
321 if( (argc < 2) ||
322 strcmp(argv[1],"-h") == 0 ||
323 strcmp(argv[1],"--help") == 0 )
325 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
326 printf("\nOPTIONS:\n");
327 printf("\t-v\t\tverbose\n");
328 printf("\t-vv\t\tmore verbose\n");
329 printf("\t-vvv\t\tvery verbose\n");
330 printf("\t-h,\t--help\tshow this message\n");
331 return 1;
334 if (argv[1][0] == '-') {
335 filearg++;
336 int i = 1;
337 while (argv[1][i] && argv[1][i] == 'v') {
338 i++;
339 wps_verbose_level++;
343 skin_buffer_init();
345 /* Go through every wps that was thrown at us, error out at the first
346 * flawed wps */
347 while (argv[filearg]) {
348 printf("Checking %s...\n", argv[filearg]);
349 #ifdef HAVE_REMOTE_LCD
350 if(strcmp(&argv[filearg][strlen(argv[filearg])-4], "rwps") == 0)
352 wps_screen = &screens[SCREEN_REMOTE];
353 wps.remote_wps = true;
355 else
357 wps_screen = &screens[SCREEN_MAIN];
358 wps.remote_wps = false;
360 #endif
362 res = skin_data_load(&wps, argv[filearg], true);
364 if (!res) {
365 printf("WPS parsing failure\n");
366 return 3;
369 printf("WPS parsed OK\n\n");
370 filearg++;
372 return 0;