RBUtil: 1) Add Dutch language
[Rockbox.git] / tools / checkwps / checkwps.c
blob409a62c5668e81387f33ff44aa95bccad53d590b
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include "config.h"
5 #include "gwps.h"
7 #define MIN(x,y) ((x) > (y) ? (y) : (x))
9 bool debug_wps = true;
10 int wps_verbose_level = 0;
12 int errno;
14 /* static endianness conversion */
15 #define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
16 ((unsigned short)(x) << 8)))
18 #define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
19 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
20 (((unsigned long)(x) & 0xff00ul) << 8) | \
21 ((unsigned long)(x) << 24)))
22 unsigned short letoh16(unsigned short x)
24 unsigned short n = 0x1234;
25 unsigned char* ch = (unsigned char*)&n;
27 if (*ch == 0x34)
29 /* Little-endian */
30 return x;
31 } else {
32 return SWAP_16(x);
36 unsigned int htole32(unsigned int x)
38 unsigned short n = 0x1234;
39 unsigned char* ch = (unsigned char*)&n;
41 if (*ch == 0x34)
43 /* Little-endian */
44 return x;
45 } else {
46 return SWAP_32(x);
50 int read_line(int fd, char* buffer, int buffer_size)
52 int count = 0;
53 int num_read = 0;
55 errno = 0;
57 while (count < buffer_size)
59 unsigned char c;
61 if (1 != read(fd, &c, 1))
62 break;
64 num_read++;
66 if ( c == '\n' )
67 break;
69 if ( c == '\r' )
70 continue;
72 buffer[count++] = c;
75 buffer[MIN(count, buffer_size - 1)] = 0;
77 return errno ? -1 : num_read;
80 bool load_wps_backdrop(const char* filename)
82 return true;
85 bool load_remote_wps_backdrop(const char* filename)
87 return true;
90 static char pluginbuf[PLUGIN_BUFFER_SIZE];
92 static int dummy_func1(void)
94 return 0;
97 static unsigned dummy_func2(void)
99 return 0;
102 void* plugin_get_buffer(size_t *buffer_size)
104 *buffer_size = PLUGIN_BUFFER_SIZE;
105 return pluginbuf;
108 struct screen screens[NB_SCREENS] =
111 .screen_type=SCREEN_MAIN,
112 .width=LCD_WIDTH,
113 .height=LCD_HEIGHT,
114 .depth=LCD_DEPTH,
115 #ifdef HAVE_LCD_COLOR
116 .is_color=true,
117 #else
118 .is_color=false,
119 #endif
120 .getxmargin=dummy_func1,
121 .getymargin=dummy_func1,
122 #if LCD_DEPTH > 1
123 .get_foreground=dummy_func2,
124 .get_background=dummy_func2,
125 #endif
127 #ifdef HAVE_REMOTE_LCD
129 .screen_type=SCREEN_REMOTE,
130 .width=LCD_REMOTE_WIDTH,
131 .height=LCD_REMOTE_HEIGHT,
132 .depth=LCD_REMOTE_DEPTH,
133 .is_color=false,/* No color remotes yet */
134 .getxmargin=dummy_func1,
135 .getymargin=dummy_func1,
136 #if LCD_REMOTE_DEPTH > 1
137 .get_foreground=dummy_func2,
138 .get_background=dummy_func2,
139 #endif
141 #endif
144 #ifdef HAVE_LCD_BITMAP
145 void screen_clear_area(struct screen * display, int xstart, int ystart,
146 int width, int height)
148 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
149 display->fillrect(xstart, ystart, width, height);
150 display->set_drawmode(DRMODE_SOLID);
152 #endif
155 int main(int argc, char **argv)
157 int res;
158 int fd;
159 int filearg = 1;
161 struct wps_data wps;
163 if (argc < 2) {
164 printf("Usage: checkwps [OPTIONS] filename.wps\n");
165 printf("\nOPTIONS:\n");
166 printf("\t-v\tverbose\n");
167 printf("\t-vv\tmore verbose\n");
168 printf("\t-vvv\tvery verbose\n");
169 return 1;
172 if (argv[1][0] == '-') {
173 filearg++;
174 int i = 1;
175 while (argv[1][i] && argv[1][i] == 'v') {
176 i++;
177 wps_verbose_level++;
181 fd = open(argv[filearg], O_RDONLY);
182 if (fd < 0) {
183 printf("Failed to open %s\n",argv[1]);
184 return 2;
186 close(fd);
188 res = wps_data_load(&wps, &screens[0], argv[filearg], true);
190 if (!res) {
191 printf("WPS parsing failure\n");
192 return 3;
195 printf("WPS parsed OK\n");
196 return 0;