Make the mips compiler not complain when bitwise operations do not have parenthesis.
[kugel-rb.git] / tools / checkwps / checkwps.c
blobffe428885d9f2cb4d5f70ed9bb5d4fec42e634a5
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 <fcntl.h>
25 #include "config.h"
26 #include "gwps.h"
27 #include "checkwps.h"
28 #include "resize.h"
30 bool debug_wps = true;
31 int wps_verbose_level = 0;
33 int errno;
35 const struct settings_list *settings;
36 const int nb_settings = 0;
38 /* static endianness conversion */
39 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
40 ((unsigned short)(x) << 8)))
42 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
43 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
44 (((unsigned long)(x) & 0xff00ul) << 8) | \
45 ((unsigned long)(x) << 24)))
47 #ifndef letoh16
48 unsigned short letoh16(unsigned short x)
50 unsigned short n = 0x1234;
51 unsigned char* ch = (unsigned char*)&n;
53 if (*ch == 0x34)
55 /* Little-endian */
56 return x;
57 } else {
58 return SWAP_16(x);
61 #endif
63 #ifndef letoh32
64 unsigned short letoh32(unsigned short x)
66 unsigned short n = 0x1234;
67 unsigned char* ch = (unsigned char*)&n;
69 if (*ch == 0x34)
71 /* Little-endian */
72 return x;
73 } else {
74 return SWAP_32(x);
77 #endif
79 #ifndef htole32
80 unsigned int htole32(unsigned int x)
82 unsigned short n = 0x1234;
83 unsigned char* ch = (unsigned char*)&n;
85 if (*ch == 0x34)
87 /* Little-endian */
88 return x;
89 } else {
90 return SWAP_32(x);
93 #endif
95 int read_line(int fd, char* buffer, int buffer_size)
97 int count = 0;
98 int num_read = 0;
100 errno = 0;
102 while (count < buffer_size)
104 unsigned char c;
106 if (1 != read(fd, &c, 1))
107 break;
109 num_read++;
111 if ( c == '\n' )
112 break;
114 if ( c == '\r' )
115 continue;
117 buffer[count++] = c;
120 buffer[MIN(count, buffer_size - 1)] = 0;
122 return errno ? -1 : num_read;
125 bool load_wps_backdrop(const char* filename)
127 return true;
130 bool load_remote_wps_backdrop(const char* filename)
132 return true;
135 int recalc_dimension(struct dim *dst, struct dim *src)
137 return 0;
140 int resize_on_load(struct bitmap *bm, bool dither, struct dim *src,
141 struct rowset *rset, unsigned char *buf, unsigned int len,
142 const struct custom_format *format,
143 struct img_part* (*store_part)(void *args),
144 void *args)
146 return 0;
149 int audio_status(void)
151 return 0;
154 struct mp3entry* audio_current_track(void)
156 return NULL;
159 void audio_stop(void)
163 void audio_play(long offset)
167 static char pluginbuf[PLUGIN_BUFFER_SIZE];
169 static unsigned dummy_func2(void)
171 return 0;
174 void* plugin_get_buffer(size_t *buffer_size)
176 *buffer_size = PLUGIN_BUFFER_SIZE;
177 return pluginbuf;
179 struct user_settings global_settings = {
180 .statusbar = true,
181 #ifdef HAVE_LCD_COLOR
182 .bg_color = LCD_DEFAULT_BG,
183 .fg_color = LCD_DEFAULT_FG,
184 #endif
187 int getwidth(void) { return LCD_WIDTH; }
188 int getheight(void) { return LCD_HEIGHT; }
189 #ifdef HAVE_REMOTE_LCD
190 int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
191 int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
192 #endif
194 struct screen screens[NB_SCREENS] =
197 .screen_type=SCREEN_MAIN,
198 .lcdwidth=LCD_WIDTH,
199 .lcdheight=LCD_HEIGHT,
200 .depth=LCD_DEPTH,
201 #ifdef HAVE_LCD_COLOR
202 .is_color=true,
203 #else
204 .is_color=false,
205 #endif
206 .getwidth = getwidth,
207 .getheight = getheight,
208 #if LCD_DEPTH > 1
209 .get_foreground=dummy_func2,
210 .get_background=dummy_func2,
211 #endif
213 #ifdef HAVE_REMOTE_LCD
215 .screen_type=SCREEN_REMOTE,
216 .lcdwidth=LCD_REMOTE_WIDTH,
217 .lcdheight=LCD_REMOTE_HEIGHT,
218 .depth=LCD_REMOTE_DEPTH,
219 .is_color=false,/* No color remotes yet */
220 .getwidth = remote_getwidth,
221 .getheight = remote_getheight,
222 #if LCD_REMOTE_DEPTH > 1
223 .get_foreground=dummy_func2,
224 .get_background=dummy_func2,
225 #endif
227 #endif
230 #ifdef HAVE_LCD_BITMAP
231 void screen_clear_area(struct screen * display, int xstart, int ystart,
232 int width, int height)
234 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
235 display->fillrect(xstart, ystart, width, height);
236 display->set_drawmode(DRMODE_SOLID);
238 #endif
241 int main(int argc, char **argv)
243 int res;
244 int fd;
245 int filearg = 1;
247 struct wps_data wps;
249 /* No arguments -> print the help text
250 * Also print the help text upon -h or --help */
251 if( (argc < 2) ||
252 strcmp(argv[1],"-h") == 0 ||
253 strcmp(argv[1],"--help") == 0 )
255 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
256 printf("\nOPTIONS:\n");
257 printf("\t-v\t\tverbose\n");
258 printf("\t-vv\t\tmore verbose\n");
259 printf("\t-vvv\t\tvery verbose\n");
260 printf("\t-h,\t--help\tshow this message\n");
261 return 1;
264 if (argv[1][0] == '-') {
265 filearg++;
266 int i = 1;
267 while (argv[1][i] && argv[1][i] == 'v') {
268 i++;
269 wps_verbose_level++;
273 fd = open(argv[filearg], O_RDONLY);
274 if (fd < 0) {
275 printf("Failed to open %s\n",argv[1]);
276 return 2;
278 close(fd);
280 /* Go through every wps that was thrown at us, error out at the first
281 * flawed wps */
282 while (argv[filearg]) {
283 printf("Checking %s...\n", argv[filearg]);
284 res = wps_data_load(&wps, &screens[0], argv[filearg], true);
286 if (!res) {
287 printf("WPS parsing failure\n");
288 return 3;
291 printf("WPS parsed OK\n\n");
292 filearg++;
294 return 0;