Cleaner solution to plugin-included core files.
[kugel-rb.git] / tools / checkwps / checkwps.c
blob29813037016a72038fe6727e4e58f58a3e10849c
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"
29 #define MIN(x,y) ((x) > (y) ? (y) : (x))
31 bool debug_wps = true;
32 int wps_verbose_level = 0;
34 int errno;
36 /* static endianness conversion */
37 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
38 ((unsigned short)(x) << 8)))
40 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
41 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
42 (((unsigned long)(x) & 0xff00ul) << 8) | \
43 ((unsigned long)(x) << 24)))
44 unsigned short letoh16(unsigned short x)
46 unsigned short n = 0x1234;
47 unsigned char* ch = (unsigned char*)&n;
49 if (*ch == 0x34)
51 /* Little-endian */
52 return x;
53 } else {
54 return SWAP_16(x);
58 unsigned int htole32(unsigned int x)
60 unsigned short n = 0x1234;
61 unsigned char* ch = (unsigned char*)&n;
63 if (*ch == 0x34)
65 /* Little-endian */
66 return x;
67 } else {
68 return SWAP_32(x);
72 int read_line(int fd, char* buffer, int buffer_size)
74 int count = 0;
75 int num_read = 0;
77 errno = 0;
79 while (count < buffer_size)
81 unsigned char c;
83 if (1 != read(fd, &c, 1))
84 break;
86 num_read++;
88 if ( c == '\n' )
89 break;
91 if ( c == '\r' )
92 continue;
94 buffer[count++] = c;
97 buffer[MIN(count, buffer_size - 1)] = 0;
99 return errno ? -1 : num_read;
102 bool load_wps_backdrop(const char* filename)
104 return true;
107 bool load_remote_wps_backdrop(const char* filename)
109 return true;
112 static char pluginbuf[PLUGIN_BUFFER_SIZE];
114 static unsigned dummy_func2(void)
116 return 0;
119 void* plugin_get_buffer(size_t *buffer_size)
121 *buffer_size = PLUGIN_BUFFER_SIZE;
122 return pluginbuf;
124 struct user_settings global_settings = {
125 .statusbar = true,
126 #ifdef HAVE_LCD_COLOR
127 .bg_color = LCD_DEFAULT_BG,
128 .fg_color = LCD_DEFAULT_FG,
129 #endif
132 int getwidth(void) { return LCD_WIDTH; }
133 int getheight(void) { return LCD_HEIGHT; }
134 #ifdef HAVE_REMOTE_LCD
135 int remote_getwidth(void) { return LCD_REMOTE_WIDTH; }
136 int remote_getheight(void) { return LCD_REMOTE_HEIGHT; }
137 #endif
139 struct screen screens[NB_SCREENS] =
142 .screen_type=SCREEN_MAIN,
143 .lcdwidth=LCD_WIDTH,
144 .lcdheight=LCD_HEIGHT,
145 .depth=LCD_DEPTH,
146 #ifdef HAVE_LCD_COLOR
147 .is_color=true,
148 #else
149 .is_color=false,
150 #endif
151 .getwidth = getwidth,
152 .getheight = getheight,
153 #if LCD_DEPTH > 1
154 .get_foreground=dummy_func2,
155 .get_background=dummy_func2,
156 #endif
158 #ifdef HAVE_REMOTE_LCD
160 .screen_type=SCREEN_REMOTE,
161 .lcdwidth=LCD_REMOTE_WIDTH,
162 .lcdheight=LCD_REMOTE_HEIGHT,
163 .depth=LCD_REMOTE_DEPTH,
164 .is_color=false,/* No color remotes yet */
165 .getwidth = remote_getwidth,
166 .getheight = remote_getheight,
167 #if LCD_REMOTE_DEPTH > 1
168 .get_foreground=dummy_func2,
169 .get_background=dummy_func2,
170 #endif
172 #endif
175 #ifdef HAVE_LCD_BITMAP
176 void screen_clear_area(struct screen * display, int xstart, int ystart,
177 int width, int height)
179 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
180 display->fillrect(xstart, ystart, width, height);
181 display->set_drawmode(DRMODE_SOLID);
183 #endif
186 int main(int argc, char **argv)
188 int res;
189 int fd;
190 int filearg = 1;
192 struct wps_data wps;
194 /* No arguments -> print the help text
195 * Also print the help text upon -h or --help */
196 if( (argc < 2) ||
197 strcmp(argv[1],"-h") == 0 ||
198 strcmp(argv[1],"--help") == 0 )
200 printf("Usage: checkwps [OPTIONS] filename.wps [filename2.wps]...\n");
201 printf("\nOPTIONS:\n");
202 printf("\t-v\t\tverbose\n");
203 printf("\t-vv\t\tmore verbose\n");
204 printf("\t-vvv\t\tvery verbose\n");
205 printf("\t-h,\t--help\tshow this message\n");
206 return 1;
209 if (argv[1][0] == '-') {
210 filearg++;
211 int i = 1;
212 while (argv[1][i] && argv[1][i] == 'v') {
213 i++;
214 wps_verbose_level++;
218 fd = open(argv[filearg], O_RDONLY);
219 if (fd < 0) {
220 printf("Failed to open %s\n",argv[1]);
221 return 2;
223 close(fd);
225 /* Go through every wps that was thrown at us, error out at the first
226 * flawed wps */
227 while (argv[filearg]) {
228 printf("Checking %s...\n", argv[filearg]);
229 res = wps_data_load(&wps, &screens[0], argv[filearg], true);
231 if (!res) {
232 printf("WPS parsing failure\n");
233 return 3;
236 printf("WPS parsed OK\n\n");
237 filearg++;
239 return 0;