Initialuse user font table for checkwps. This is normally done from the settings...
[kugel-rb.git] / tools / checkwps / checkwps.c
blob84d722ee46ee4f549c5f1455c32ec75c17429812
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"
34 #include "font.h"
36 bool debug_wps = true;
37 int wps_verbose_level = 0;
39 int errno;
41 const struct settings_list *settings;
42 const int nb_settings = 0;
44 /* static endianness conversion */
45 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
46 ((unsigned short)(x) << 8)))
48 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
49 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
50 (((unsigned long)(x) & 0xff00ul) << 8) | \
51 ((unsigned long)(x) << 24)))
53 #ifndef letoh16
54 unsigned short letoh16(unsigned short x)
56 unsigned short n = 0x1234;
57 unsigned char* ch = (unsigned char*)&n;
59 if (*ch == 0x34)
61 /* Little-endian */
62 return x;
63 } else {
64 return SWAP_16(x);
67 #endif
69 #ifndef letoh32
70 unsigned short letoh32(unsigned short x)
72 unsigned short n = 0x1234;
73 unsigned char* ch = (unsigned char*)&n;
75 if (*ch == 0x34)
77 /* Little-endian */
78 return x;
79 } else {
80 return SWAP_32(x);
83 #endif
85 #ifndef htole32
86 unsigned int htole32(unsigned int x)
88 unsigned short n = 0x1234;
89 unsigned char* ch = (unsigned char*)&n;
91 if (*ch == 0x34)
93 /* Little-endian */
94 return x;
95 } else {
96 return SWAP_32(x);
99 #endif
101 int read_line(int fd, char* buffer, int buffer_size)
103 int count = 0;
104 int num_read = 0;
106 errno = 0;
108 while (count < buffer_size)
110 unsigned char c;
112 if (1 != read(fd, &c, 1))
113 break;
115 num_read++;
117 if ( c == '\n' )
118 break;
120 if ( c == '\r' )
121 continue;
123 buffer[count++] = c;
126 buffer[MIN(count, buffer_size - 1)] = 0;
128 return errno ? -1 : num_read;
131 int recalc_dimension(struct dim *dst, struct dim *src)
133 return 0;
136 #ifdef HAVE_ALBUMART
137 int playback_claim_aa_slot(struct dim *dim)
139 return 0;
142 void playback_release_aa_slot(int slot)
144 return;
146 #endif
148 int resize_on_load(struct bitmap *bm, bool dither,
149 struct dim *src, struct rowset *tmp_row,
150 unsigned char *buf, unsigned int len,
151 const struct custom_format *cformat,
152 IF_PIX_FMT(int format_index,)
153 struct img_part* (*store_part)(void *args),
154 void *args)
156 return 0;
159 static char pluginbuf[PLUGIN_BUFFER_SIZE];
161 static unsigned dummy_func2(void)
163 return 0;
166 void* plugin_get_buffer(size_t *buffer_size)
168 *buffer_size = PLUGIN_BUFFER_SIZE;
169 return pluginbuf;
172 struct user_settings global_settings = {
173 .statusbar = true,
174 #ifdef HAVE_LCD_COLOR
175 .bg_color = LCD_DEFAULT_BG,
176 .fg_color = LCD_DEFAULT_FG,
177 #endif
180 int getwidth(void) { return LCD_WIDTH; }
181 int getheight(void) { return LCD_HEIGHT; }
182 #ifdef HAVE_REMOTE_LCD
183 int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
184 int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
185 #endif
187 static inline bool backdrop_load(const char *filename, char* backdrop_buffer)
189 (void)filename; (void)backdrop_buffer; return true;
192 struct screen screens[NB_SCREENS] =
195 .screen_type=SCREEN_MAIN,
196 .lcdwidth=LCD_WIDTH,
197 .lcdheight=LCD_HEIGHT,
198 .depth=LCD_DEPTH,
199 #ifdef HAVE_LCD_COLOR
200 .is_color=true,
201 #else
202 .is_color=false,
203 #endif
204 .getwidth = getwidth,
205 .getheight = getheight,
206 #if LCD_DEPTH > 1
207 .get_foreground=dummy_func2,
208 .get_background=dummy_func2,
209 .backdrop_load=backdrop_load,
210 #endif
212 #ifdef HAVE_REMOTE_LCD
214 .screen_type=SCREEN_REMOTE,
215 .lcdwidth=LCD_REMOTE_WIDTH,
216 .lcdheight=LCD_REMOTE_HEIGHT,
217 .depth=LCD_REMOTE_DEPTH,
218 .is_color=false,/* No color remotes yet */
219 .getwidth=remote_getwidth,
220 .getheight=remote_getheight,
221 #if LCD_REMOTE_DEPTH > 1
222 .get_foreground=dummy_func2,
223 .get_background=dummy_func2,
224 .backdrop_load=backdrop_load,
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
240 #ifdef HAVE_LCD_BITMAP
241 static int loaded_fonts = 0;
242 int font_load(struct font* pf, const char *path)
244 int id = SYSTEMFONTCOUNT + loaded_fonts;
245 loaded_fonts++;
246 return id;
249 void font_unload(int font_id)
251 (void)font_id;
253 #endif
255 int main(int argc, char **argv)
257 int res;
258 int filearg = 1;
260 struct wps_data wps;
261 enum screen_type screen = SCREEN_MAIN;
262 struct screen* wps_screen;
264 /* No arguments -> print the help text
265 * Also print the help text upon -h or --help */
266 if( (argc < 2) ||
267 strcmp(argv[1],"-h") == 0 ||
268 strcmp(argv[1],"--help") == 0 )
270 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
271 printf("\nOPTIONS:\n");
272 printf("\t-v\t\tverbose\n");
273 printf("\t-vv\t\tmore verbose\n");
274 printf("\t-vvv\t\tvery verbose\n");
275 printf("\t-h,\t--help\tshow this message\n");
276 return 1;
279 if (argv[1][0] == '-') {
280 filearg++;
281 int i = 1;
282 while (argv[1][i] && argv[1][i] == 'v') {
283 i++;
284 wps_verbose_level++;
288 skin_buffer_init();
289 skin_font_init();
291 /* Go through every wps that was thrown at us, error out at the first
292 * flawed wps */
293 while (argv[filearg]) {
294 printf("Checking %s...\n", argv[filearg]);
295 #ifdef HAVE_REMOTE_LCD
296 if((strcmp(&argv[filearg][strlen(argv[filearg])-4], "rwps") == 0) ||
297 (strcmp(&argv[filearg][strlen(argv[filearg])-4], "rsbs") == 0))
298 screen = SCREEN_REMOTE;
299 else
300 screen = SCREEN_MAIN;
301 #endif
302 wps_screen = &screens[screen];
304 res = skin_data_load(screen, &wps, argv[filearg], true);
306 if (!res) {
307 printf("WPS parsing failure\n");
308 return 3;
311 printf("WPS parsed OK\n\n");
312 filearg++;
314 return 0;