Fix a compile warning.
[kugel-rb.git] / tools / checkwps / checkwps.c
blobdaeb0ea9354861ae8097b86eb154dc3082f49957
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 int recalc_dimension(struct dim *dst, struct dim *src)
132 return 0;
135 #ifdef HAVE_ALBUMART
136 int playback_claim_aa_slot(struct dim *dim)
138 return 0;
141 void playback_release_aa_slot(int slot)
143 return;
145 #endif
147 int resize_on_load(struct bitmap *bm, bool dither,
148 struct dim *src, struct rowset *tmp_row,
149 unsigned char *buf, unsigned int len,
150 const struct custom_format *cformat,
151 IF_PIX_FMT(int format_index,)
152 struct img_part* (*store_part)(void *args),
153 void *args)
155 return 0;
158 static char pluginbuf[PLUGIN_BUFFER_SIZE];
160 static unsigned dummy_func2(void)
162 return 0;
165 void* plugin_get_buffer(size_t *buffer_size)
167 *buffer_size = PLUGIN_BUFFER_SIZE;
168 return pluginbuf;
171 struct user_settings global_settings = {
172 .statusbar = true,
173 #ifdef HAVE_LCD_COLOR
174 .bg_color = LCD_DEFAULT_BG,
175 .fg_color = LCD_DEFAULT_FG,
176 #endif
179 int getwidth(void) { return LCD_WIDTH; }
180 int getheight(void) { return LCD_HEIGHT; }
181 #ifdef HAVE_REMOTE_LCD
182 int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
183 int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
184 #endif
186 struct screen screens[NB_SCREENS] =
189 .screen_type=SCREEN_MAIN,
190 .lcdwidth=LCD_WIDTH,
191 .lcdheight=LCD_HEIGHT,
192 .depth=LCD_DEPTH,
193 #ifdef HAVE_LCD_COLOR
194 .is_color=true,
195 #else
196 .is_color=false,
197 #endif
198 .getwidth = getwidth,
199 .getheight = getheight,
200 #if LCD_DEPTH > 1
201 .get_foreground=dummy_func2,
202 .get_background=dummy_func2,
203 #endif
204 .backdrop_load=backdrop_load,
206 #ifdef HAVE_REMOTE_LCD
208 .screen_type=SCREEN_REMOTE,
209 .lcdwidth=LCD_REMOTE_WIDTH,
210 .lcdheight=LCD_REMOTE_HEIGHT,
211 .depth=LCD_REMOTE_DEPTH,
212 .is_color=false,/* No color remotes yet */
213 .getwidth=remote_getwidth,
214 .getheight=remote_getheight,
215 #if LCD_REMOTE_DEPTH > 1
216 .get_foreground=dummy_func2,
217 .get_background=dummy_func2,
218 #endif
219 .backdrop_load=backdrop_load,
221 #endif
224 #ifdef HAVE_LCD_BITMAP
225 void screen_clear_area(struct screen * display, int xstart, int ystart,
226 int width, int height)
228 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
229 display->fillrect(xstart, ystart, width, height);
230 display->set_drawmode(DRMODE_SOLID);
232 #endif
234 int main(int argc, char **argv)
236 int res;
237 int filearg = 1;
239 struct wps_data wps;
240 enum screen_type screen = SCREEN_MAIN;
241 struct screen* wps_screen;
243 /* No arguments -> print the help text
244 * Also print the help text upon -h or --help */
245 if( (argc < 2) ||
246 strcmp(argv[1],"-h") == 0 ||
247 strcmp(argv[1],"--help") == 0 )
249 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
250 printf("\nOPTIONS:\n");
251 printf("\t-v\t\tverbose\n");
252 printf("\t-vv\t\tmore verbose\n");
253 printf("\t-vvv\t\tvery verbose\n");
254 printf("\t-h,\t--help\tshow this message\n");
255 return 1;
258 if (argv[1][0] == '-') {
259 filearg++;
260 int i = 1;
261 while (argv[1][i] && argv[1][i] == 'v') {
262 i++;
263 wps_verbose_level++;
267 skin_buffer_init();
269 /* Go through every wps that was thrown at us, error out at the first
270 * flawed wps */
271 while (argv[filearg]) {
272 printf("Checking %s...\n", argv[filearg]);
273 #ifdef HAVE_REMOTE_LCD
274 if(strcmp(&argv[filearg][strlen(argv[filearg])-4], "rwps") == 0)
275 screen = SCREEN_REMOTE;
276 #endif
277 wps_screen = &screens[screen];
279 res = skin_data_load(screen, &wps, argv[filearg], true);
281 if (!res) {
282 printf("WPS parsing failure\n");
283 return 3;
286 printf("WPS parsed OK\n\n");
287 filearg++;
289 return 0;