summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-05-29 19:00:36 +0000
committerDave Chapman <dave@dchapman.com>2007-05-29 19:00:36 +0000
commitf0d4fc6c6b146197c0fc51753d838252766aeda2 (patch)
tree14a80b9a30d14b63c50f3350f9c2cececdc1baef
parentbe0cbc940641264fe536ea1b3c1153f627367f55 (diff)
downloadrockbox-f0d4fc6c6b146197c0fc51753d838252766aeda2.tar.gz
rockbox-f0d4fc6c6b146197c0fc51753d838252766aeda2.zip
Commit my patch from FS#7179 - a standalone command-line checkwps tool. To build, just type "make checkwps" in tools and run it with "checkwps wpsname.wps".
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13517 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/gui/gwps-common.c26
-rw-r--r--apps/gui/wps_debug.c8
-rw-r--r--apps/gui/wps_parser.c32
-rw-r--r--tools/Makefile5
-rw-r--r--tools/checkwps.c91
5 files changed, 134 insertions, 28 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index b25168f252..2cdb92d964 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -1969,29 +1969,3 @@ bool gui_wps_refresh(struct gui_wps *gwps,
1969 return true; 1969 return true;
1970} 1970}
1971 1971
1972int wps_subline_index(struct wps_data *data, int line, int subline)
1973{
1974 return data->lines[line].first_subline_idx + subline;
1975}
1976
1977int wps_first_token_index(struct wps_data *data, int line, int subline)
1978{
1979 int first_subline_idx = data->lines[line].first_subline_idx;
1980 return data->sublines[first_subline_idx + subline].first_token_idx;
1981}
1982
1983int wps_last_token_index(struct wps_data *data, int line, int subline)
1984{
1985 int first_subline_idx = data->lines[line].first_subline_idx;
1986 int idx = first_subline_idx + subline;
1987 if (idx < data->num_sublines - 1)
1988 {
1989 /* This subline ends where the next begins */
1990 return data->sublines[idx+1].first_token_idx - 1;
1991 }
1992 else
1993 {
1994 /* The last subline goes to the end */
1995 return data->num_tokens - 1;
1996 }
1997}
diff --git a/apps/gui/wps_debug.c b/apps/gui/wps_debug.c
index 8ba4b6f000..ae542785ae 100644
--- a/apps/gui/wps_debug.c
+++ b/apps/gui/wps_debug.c
@@ -22,13 +22,17 @@
22#include <stdio.h> 22#include <stdio.h>
23#include <string.h> 23#include <string.h>
24#include "gwps.h" 24#include "gwps.h"
25#ifdef __PCTOOL__
26#define DEBUGF printf
27#else
25#include "debug.h" 28#include "debug.h"
29#endif
26 30
27#define PARSE_FAIL_UNCLOSED_COND 1 31#define PARSE_FAIL_UNCLOSED_COND 1
28#define PARSE_FAIL_INVALID_CHAR 2 32#define PARSE_FAIL_INVALID_CHAR 2
29#define PARSE_FAIL_COND_SYNTAX_ERROR 3 33#define PARSE_FAIL_COND_SYNTAX_ERROR 3
30 34
31#ifdef SIMULATOR 35#if defined(SIMULATOR) || defined(__PCTOOL__)
32extern bool debug_wps; 36extern bool debug_wps;
33#endif 37#endif
34 38
@@ -467,7 +471,7 @@ static void print_img_cond_indexes(struct wps_data *data)
467 471
468void print_debug_info(struct wps_data *data, int fail, int line) 472void print_debug_info(struct wps_data *data, int fail, int line)
469{ 473{
470#ifdef SIMULATOR 474#if defined(SIMULATOR) || defined(__PCTOOL__)
471 if (debug_wps) 475 if (debug_wps)
472 { 476 {
473 dump_wps_tokens(data); 477 dump_wps_tokens(data);
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index be0ef4e271..d363d6d8cb 100644
--- a/apps/gui/wps_parser.c
+++ b/apps/gui/wps_parser.c
@@ -24,6 +24,7 @@
24#include <string.h> 24#include <string.h>
25#include "atoi.h" 25#include "atoi.h"
26#include "gwps.h" 26#include "gwps.h"
27#ifndef __PCTOOL__
27#include "settings.h" 28#include "settings.h"
28#include "debug.h" 29#include "debug.h"
29#include "plugin.h" 30#include "plugin.h"
@@ -36,6 +37,8 @@
36#include "backdrop.h" 37#include "backdrop.h"
37#endif 38#endif
38 39
40#endif
41
39#define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps" 42#define WPS_DEFAULTCFG WPS_DIR "/rockbox_default.wps"
40#define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps" 43#define RWPS_DEFAULTCFG WPS_DIR "/rockbox_default.rwps"
41 44
@@ -1008,6 +1011,7 @@ bool wps_data_load(struct wps_data *wps_data,
1008 * wants to be a virtual file. Feel free to modify dirbrowse() 1011 * wants to be a virtual file. Feel free to modify dirbrowse()
1009 * if you're feeling brave. 1012 * if you're feeling brave.
1010 */ 1013 */
1014#ifndef __PCTOOL__
1011 if (! strcmp(buf, WPS_DEFAULTCFG) ) 1015 if (! strcmp(buf, WPS_DEFAULTCFG) )
1012 { 1016 {
1013 global_settings.wps_file[0] = 0; 1017 global_settings.wps_file[0] = 0;
@@ -1021,6 +1025,7 @@ bool wps_data_load(struct wps_data *wps_data,
1021 return false; 1025 return false;
1022 } 1026 }
1023#endif 1027#endif
1028#endif /* __PCTOOL__ */
1024 1029
1025 int fd = open(buf, O_RDONLY); 1030 int fd = open(buf, O_RDONLY);
1026 1031
@@ -1080,3 +1085,30 @@ bool wps_data_load(struct wps_data *wps_data,
1080 return true; 1085 return true;
1081 } 1086 }
1082} 1087}
1088
1089int wps_subline_index(struct wps_data *data, int line, int subline)
1090{
1091 return data->lines[line].first_subline_idx + subline;
1092}
1093
1094int wps_first_token_index(struct wps_data *data, int line, int subline)
1095{
1096 int first_subline_idx = data->lines[line].first_subline_idx;
1097 return data->sublines[first_subline_idx + subline].first_token_idx;
1098}
1099
1100int wps_last_token_index(struct wps_data *data, int line, int subline)
1101{
1102 int first_subline_idx = data->lines[line].first_subline_idx;
1103 int idx = first_subline_idx + subline;
1104 if (idx < data->num_sublines - 1)
1105 {
1106 /* This subline ends where the next begins */
1107 return data->sublines[idx+1].first_token_idx - 1;
1108 }
1109 else
1110 {
1111 /* The last subline goes to the end */
1112 return data->num_tokens - 1;
1113 }
1114}
diff --git a/tools/Makefile b/tools/Makefile
index a25447c20e..ac9fbac6d0 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -47,6 +47,11 @@ database: database.c ../apps/tagcache.c ../apps/metadata.c \
47-D__PCTOOL__ -DHAVE_TAGCACHE -DROCKBOX_HAS_LOGF -DSIMULATOR \ 47-D__PCTOOL__ -DHAVE_TAGCACHE -DROCKBOX_HAS_LOGF -DSIMULATOR \
48-DCONFIG_CODEC=1 -ldl -I../apps $+ -o $@ 48-DCONFIG_CODEC=1 -ldl -I../apps $+ -o $@
49 49
50checkwps: checkwps.c ../apps/gui/wps_parser.c ../apps/gui/wps_debug.c ../firmware/common/ctype.c
51 $(SILENT)$(CC) -g -I ../apps/gui -I../firmware/export \
52-D__PCTOOL__ -DDEBUG -DROCKBOX_HAS_LOGF -DIPOD_COLOR -D ROCKBOX_DIR_LEN=255 -D WPS_DIR=\".\" \
53-I../apps -I../firmware/target/arm/ipod -I../firmware/include $+ -o $@
54
50convbdf: convbdf.c 55convbdf: convbdf.c
51 $(SILENT)$(CC) -g $+ -o $@ 56 $(SILENT)$(CC) -g $+ -o $@
52 57
diff --git a/tools/checkwps.c b/tools/checkwps.c
new file mode 100644
index 0000000000..74ce1e82be
--- /dev/null
+++ b/tools/checkwps.c
@@ -0,0 +1,91 @@
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;
8
9int read_bmp_file(char* filename,
10 struct bitmap *bm,
11 int maxsize,
12 int format)
13{
14 return 0;
15}
16
17int errno;
18
19int read_line(int fd, char* buffer, int buffer_size)
20{
21 int count = 0;
22 int num_read = 0;
23
24 errno = 0;
25
26 while (count < buffer_size)
27 {
28 unsigned char c;
29
30 if (1 != read(fd, &c, 1))
31 break;
32
33 num_read++;
34
35 if ( c == '\n' )
36 break;
37
38 if ( c == '\r' )
39 continue;
40
41 buffer[count++] = c;
42 }
43
44 buffer[MIN(count, buffer_size - 1)] = 0;
45
46 return errno ? -1 : num_read;
47}
48
49bool load_wps_backdrop(char* filename)
50{
51 return true;
52}
53
54static char pluginbuf[PLUGIN_BUFFER_SIZE];
55
56void* plugin_get_buffer(size_t *buffer_size)
57{
58 *buffer_size = PLUGIN_BUFFER_SIZE;
59 return pluginbuf;
60}
61
62int main(int argc, char **argv)
63{
64 int res;
65 int fd;
66
67 struct wps_data wps;
68
69 if (argc != 2) {
70 printf("Usage: checkwps filename.wps\n");
71 return 1;
72 }
73
74 fd = open(argv[1], O_RDONLY);
75 if (fd < 0) {
76 printf("Failed to open %s\n",argv[1]);
77 return 2;
78 }
79 close(fd);
80
81 res = wps_data_load(&wps, argv[1], true);
82
83 if (!res) {
84 printf("WPS parsing failure\n");
85 return 3;
86 }
87
88 printf("WPS parsed OK\n");
89 return 0;
90}
91