summaryrefslogtreecommitdiff
path: root/tools/checkwps/checkwps.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/checkwps/checkwps.c')
-rw-r--r--tools/checkwps/checkwps.c184
1 files changed, 184 insertions, 0 deletions
diff --git a/tools/checkwps/checkwps.c b/tools/checkwps/checkwps.c
new file mode 100644
index 0000000000..ddaaf49b73
--- /dev/null
+++ b/tools/checkwps/checkwps.c
@@ -0,0 +1,184 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include "gwps.h"
4
5#define MIN(x,y) ((x) > (y) ? (y) : (x))
6
7bool debug_wps = true;
8int wps_verbose_level = 0;
9
10int errno;
11
12/* static endianness conversion */
13#define SWAP_16(x) ((typeof(x))(unsigned short)(((unsigned short)(x) >> 8) | \
14 ((unsigned short)(x) << 8)))
15
16#define SWAP_32(x) ((typeof(x))(unsigned long)( ((unsigned long)(x) >> 24) | \
17 (((unsigned long)(x) & 0xff0000ul) >> 8) | \
18 (((unsigned long)(x) & 0xff00ul) << 8) | \
19 ((unsigned long)(x) << 24)))
20unsigned short letoh16(unsigned short x)
21{
22 unsigned short n = 0x1234;
23 unsigned char* ch = &n;
24
25 if (*ch == 0x34)
26 {
27 /* Little-endian */
28 return x;
29 } else {
30 return SWAP_16(x);
31 }
32}
33
34unsigned int htole32(unsigned int x)
35{
36 unsigned short n = 0x1234;
37 unsigned char* ch = &n;
38
39 if (*ch == 0x34)
40 {
41 /* Little-endian */
42 return x;
43 } else {
44 return SWAP_32(x);
45 }
46}
47
48int read_line(int fd, char* buffer, int buffer_size)
49{
50 int count = 0;
51 int num_read = 0;
52
53 errno = 0;
54
55 while (count < buffer_size)
56 {
57 unsigned char c;
58
59 if (1 != read(fd, &c, 1))
60 break;
61
62 num_read++;
63
64 if ( c == '\n' )
65 break;
66
67 if ( c == '\r' )
68 continue;
69
70 buffer[count++] = c;
71 }
72
73 buffer[MIN(count, buffer_size - 1)] = 0;
74
75 return errno ? -1 : num_read;
76}
77
78bool load_wps_backdrop(char* filename)
79{
80 return true;
81}
82
83static char pluginbuf[PLUGIN_BUFFER_SIZE];
84
85static int dummy_func1(void)
86{
87 return 0;
88}
89
90static unsigned dummy_func2(void)
91{
92 return 0;
93}
94
95void* plugin_get_buffer(size_t *buffer_size)
96{
97 *buffer_size = PLUGIN_BUFFER_SIZE;
98 return pluginbuf;
99}
100
101struct screen screens[NB_SCREENS] =
102{
103 {
104 .screen_type=SCREEN_MAIN,
105 .width=LCD_WIDTH,
106 .height=LCD_HEIGHT,
107 .depth=LCD_DEPTH,
108 .is_color=true,
109 .has_disk_led=false,
110 .getxmargin=dummy_func1,
111 .getymargin=dummy_func1,
112 .get_foreground=dummy_func2,
113 .get_background=dummy_func2,
114 },
115#ifdef HAVE_REMOTE_LCD
116 {
117 .screen_type=SCREEN_REMOTE,
118 .width=LCD_REMOTE_WIDTH,
119 .height=LCD_REMOTE_HEIGHT,
120 .depth=LCD_REMOTE_DEPTH,
121 .is_color=false,/* No color remotes yet */
122 .getxmargin=dummy_func,
123 .getymargin=dummy_func,
124 .get_foreground=dummy_func,
125 .get_background=dummy_func,
126 }
127#endif
128};
129
130#ifdef HAVE_LCD_BITMAP
131void screen_clear_area(struct screen * display, int xstart, int ystart,
132 int width, int height)
133{
134 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
135 display->fillrect(xstart, ystart, width, height);
136 display->set_drawmode(DRMODE_SOLID);
137}
138#endif
139
140
141int main(int argc, char **argv)
142{
143 int res;
144 int fd;
145 int filearg = 1;
146
147 struct wps_data wps;
148
149 if (argc < 2) {
150 printf("Usage: checkwps [OPTIONS] filename.wps\n");
151 printf("\nOPTIONS:\n");
152 printf("\t-v\tverbose\n");
153 printf("\t-vv\tmore verbose\n");
154 printf("\t-vvv\tvery verbose\n");
155 return 1;
156 }
157
158 if (argv[1][0] == '-') {
159 filearg++;
160 int i = 1;
161 while (argv[1][i] && argv[1][i] == 'v') {
162 i++;
163 wps_verbose_level++;
164 }
165 }
166
167 fd = open(argv[filearg], O_RDONLY);
168 if (fd < 0) {
169 printf("Failed to open %s\n",argv[1]);
170 return 2;
171 }
172 close(fd);
173
174 res = wps_data_load(&wps, &screens[0], argv[filearg], true);
175
176 if (!res) {
177 printf("WPS parsing failure\n");
178 return 3;
179 }
180
181 printf("WPS parsed OK\n");
182 return 0;
183}
184