Repair build-all.sh and clean-all.sh.
[kugel-rb.git] / tools / checkwps / checkwps.c
blob079454def1ea109977c368c3c86dbf07bb0e6747
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 int resize_on_load(struct bitmap *bm, bool dither,
144 struct dim *src, struct rowset *tmp_row,
145 unsigned char *buf, unsigned int len,
146 const struct custom_format *cformat,
147 IF_PIX_FMT(int format_index,)
148 struct img_part* (*store_part)(void *args),
149 void *args)
151 return 0;
154 int audio_status(void)
156 return 0;
159 struct mp3entry* audio_current_track(void)
161 return NULL;
164 void audio_stop(void)
168 void audio_play(long offset)
172 static char pluginbuf[PLUGIN_BUFFER_SIZE];
174 static unsigned dummy_func2(void)
176 return 0;
179 void* plugin_get_buffer(size_t *buffer_size)
181 *buffer_size = PLUGIN_BUFFER_SIZE;
182 return pluginbuf;
185 struct user_settings global_settings = {
186 .statusbar = true,
187 #ifdef HAVE_LCD_COLOR
188 .bg_color = LCD_DEFAULT_BG,
189 .fg_color = LCD_DEFAULT_FG,
190 #endif
193 int getwidth(void) { return LCD_WIDTH; }
194 int getheight(void) { return LCD_HEIGHT; }
195 #ifdef HAVE_REMOTE_LCD
196 int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
197 int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
198 #endif
200 struct screen screens[NB_SCREENS] =
203 .screen_type=SCREEN_MAIN,
204 .lcdwidth=LCD_WIDTH,
205 .lcdheight=LCD_HEIGHT,
206 .depth=LCD_DEPTH,
207 #ifdef HAVE_LCD_COLOR
208 .is_color=true,
209 #else
210 .is_color=false,
211 #endif
212 .getwidth = getwidth,
213 .getheight = getheight,
214 #if LCD_DEPTH > 1
215 .get_foreground=dummy_func2,
216 .get_background=dummy_func2,
217 #endif
218 .backdrop_load=backdrop_load,
220 #ifdef HAVE_REMOTE_LCD
222 .screen_type=SCREEN_REMOTE,
223 .lcdwidth=LCD_REMOTE_WIDTH,
224 .lcdheight=LCD_REMOTE_HEIGHT,
225 .depth=LCD_REMOTE_DEPTH,
226 .is_color=false,/* No color remotes yet */
227 .getwidth=remote_getwidth,
228 .getheight=remote_getheight,
229 #if LCD_REMOTE_DEPTH > 1
230 .get_foreground=dummy_func2,
231 .get_background=dummy_func2,
232 #endif
233 .backdrop_load=backdrop_load,
235 #endif
238 #ifdef HAVE_LCD_BITMAP
239 void screen_clear_area(struct screen * display, int xstart, int ystart,
240 int width, int height)
242 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
243 display->fillrect(xstart, ystart, width, height);
244 display->set_drawmode(DRMODE_SOLID);
246 #endif
248 /* From skin_display.c */
249 void skin_data_init(struct wps_data *wps_data)
251 #ifdef HAVE_LCD_BITMAP
252 wps_data->wps_sb_tag = false;
253 wps_data->show_sb_on_wps = false;
254 wps_data->peak_meter_enabled = false;
255 wps_data->images = NULL;
256 wps_data->progressbars = NULL;
257 /* progress bars */
258 #else /* HAVE_LCD_CHARCELLS */
259 int i;
260 for (i = 0; i < 8; i++)
262 wps_data->wps_progress_pat[i] = 0;
264 wps_data->full_line_progressbar = false;
265 #endif
266 wps_data->button_time_volume = 0;
267 wps_data->wps_loaded = false;
270 #ifdef HAVE_LCD_BITMAP
271 struct gui_img* find_image(char label, struct wps_data *data)
273 struct skin_token_list *list = data->images;
274 while (list)
276 struct gui_img *img = (struct gui_img *)list->token->value.data;
277 if (img->label == label)
278 return img;
279 list = list->next;
281 return NULL;
283 #endif
285 struct skin_viewport* find_viewport(char label, struct wps_data *data)
287 struct skin_token_list *list = data->viewports;
288 while (list)
290 struct skin_viewport *vp = (struct skin_viewport *)list->token->value.data;
291 if (vp->label == label)
292 return vp;
293 list = list->next;
295 return NULL;
298 int main(int argc, char **argv)
300 int res;
301 int filearg = 1;
303 struct wps_data wps;
304 struct screen* wps_screen = &screens[SCREEN_MAIN];
306 /* No arguments -> print the help text
307 * Also print the help text upon -h or --help */
308 if( (argc < 2) ||
309 strcmp(argv[1],"-h") == 0 ||
310 strcmp(argv[1],"--help") == 0 )
312 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
313 printf("\nOPTIONS:\n");
314 printf("\t-v\t\tverbose\n");
315 printf("\t-vv\t\tmore verbose\n");
316 printf("\t-vvv\t\tvery verbose\n");
317 printf("\t-h,\t--help\tshow this message\n");
318 return 1;
321 if (argv[1][0] == '-') {
322 filearg++;
323 int i = 1;
324 while (argv[1][i] && argv[1][i] == 'v') {
325 i++;
326 wps_verbose_level++;
330 skin_buffer_init();
332 /* Go through every wps that was thrown at us, error out at the first
333 * flawed wps */
334 while (argv[filearg]) {
335 printf("Checking %s...\n", argv[filearg]);
336 #ifdef HAVE_REMOTE_LCD
337 if(strcmp(&argv[filearg][strlen(argv[filearg])-4], "rwps") == 0)
339 wps_screen = &screens[SCREEN_REMOTE];
340 wps.remote_wps = true;
342 else
344 wps_screen = &screens[SCREEN_MAIN];
345 wps.remote_wps = false;
347 #endif
349 res = skin_data_load(&wps, wps_screen, argv[filearg], true);
351 if (!res) {
352 printf("WPS parsing failure\n");
353 return 3;
356 printf("WPS parsed OK\n\n");
357 filearg++;
359 return 0;