diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-06-11 04:47:46 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-06-11 04:47:46 +0000 |
commit | b4a9564790575c645d855c23f7f2e07ae03c1c19 (patch) | |
tree | 39aa7fa77345edb78f4b4e9a9745aaf88c69f689 | |
parent | 45c7498f59ad2889f2120a865a51043004eddd5d (diff) | |
download | rockbox-b4a9564790575c645d855c23f7f2e07ae03c1c19.tar.gz rockbox-b4a9564790575c645d855c23f7f2e07ae03c1c19.zip |
Add my new parser playground to svn.
Currently it can load a skin, and walk the parse tree and output the tags as required. It always chooses the first value for a conditional and subline, but a good working start
there seems to be a error in the new parser if ROCKBOX is defined... need to fix that
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26757 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | utils/newparser/Makefile | 3 | ||||
-rw-r--r-- | utils/newparser/cabbiev2.220x176x16.wps | 42 | ||||
-rw-r--r-- | utils/newparser/handle_tags.c | 157 | ||||
-rw-r--r-- | utils/newparser/newparser.c | 81 | ||||
-rw-r--r-- | utils/newparser/skin_render.c | 95 | ||||
-rw-r--r-- | utils/newparser/skin_structs.h | 68 |
6 files changed, 446 insertions, 0 deletions
diff --git a/utils/newparser/Makefile b/utils/newparser/Makefile new file mode 100644 index 0000000000..5a0e76f140 --- /dev/null +++ b/utils/newparser/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | all: | ||
2 | gcc -I../themeeditor -g -Wall -o newparser newparser.c skin_render.c handle_tags.c ../themeeditor/skin_parser.c ../themeeditor/skin_scan.c ../themeeditor/skin_debug.c ../themeeditor/tag_table.c | ||
3 | |||
diff --git a/utils/newparser/cabbiev2.220x176x16.wps b/utils/newparser/cabbiev2.220x176x16.wps new file mode 100644 index 0000000000..764a506e1f --- /dev/null +++ b/utils/newparser/cabbiev2.220x176x16.wps | |||
@@ -0,0 +1,42 @@ | |||
1 | # cabbie 2.0 default | ||
2 | # (C) 2007, Johannes Voggenthaler (Zinc Alloy) | ||
3 | #derived from "cabbie" (C) Yohann Misquitta | ||
4 | %wd | ||
5 | %X(wpsbackdrop-220x176x16.bmp) | ||
6 | %xl(A,lock-220x176x16.bmp,88,152,2) | ||
7 | %xl(B,battery-220x176x16.bmp,110,153,10) | ||
8 | %xl(C,volume-220x176x16.bmp,134,153,10) | ||
9 | %xl(D,shuffle-220x176x16.bmp,155,153) | ||
10 | %xl(E,repeat-220x176x16.bmp,182,151,4) | ||
11 | %xl(F,playmode-220x176x16.bmp,200,152,5) | ||
12 | %ax%Cl(15,32,75,75) | ||
13 | %pb(11,121,199,8,pb-220x176x16.bmp) | ||
14 | %?mh<%xd(Aa)|%xd(Ab)> | ||
15 | %?bp<%?bc<%xd(Ba)|%xd(Bb)>|%?bl<|%xd(Bc)|%xd(Bd)|%xd(Be)|%xd(Bf)|%xd(Bg)|%xd(Bh)|%xd(Bi)|%xd(Bj)>> | ||
16 | %?pv<%xd(Ca)|%xd(Cb)|%xd(Cc)|%xd(Cd)|%xd(Ce)|%xd(Cf)|%xd(Cg)|%xd(Ch)|%xd(Ci)|%xd(Cj)> | ||
17 | %?ps<%xd(D)> | ||
18 | %?mm<|%xd(Ea)|%xd(Eb)|%xd(Ec)|%xd(Ed)> | ||
19 | %?mp<%xd(Fa)|%xd(Fb)|%xd(Fc)|%xd(Fd)|%xd(Fe)> | ||
20 | |||
21 | #NowPlaying | ||
22 | %?C<%Vd(a)%C|%Vd(b)> | ||
23 | |||
24 | %ax%Vl(a,105,30,-,90,1) | ||
25 | %s%al%?it<%it|%fn> | ||
26 | %s%al%?ia<%ia|%?d(2)<%d(2)|%(root%)>> | ||
27 | %s%al%?id<%id|%?d(1)<%d(1)|%(root%)>> | ||
28 | |||
29 | %s%al%Sx(Next Track:) | ||
30 | %s%al%?It<%It|%Fn> | ||
31 | |||
32 | %Vl(b,0,30,-,90,1) | ||
33 | %s%ac%?it<%it|%fn> | ||
34 | %s%ac%?ia<%ia|%?d(2)<%d(2)|%(root%)>> | ||
35 | %s%ac%?id<%id|%?d(1)<%d(1)|%(root%)>> | ||
36 | |||
37 | %ac%Sx(Next Track:) | ||
38 | %s%ac%?It<%It|%Fn> | ||
39 | |||
40 | |||
41 | %V(11,130,199,20,1) | ||
42 | %al%pc%ac%?Sr<%pe %Sx(of) %pp|%pp %Sx(of) %pe>%ar%pr | ||
diff --git a/utils/newparser/handle_tags.c b/utils/newparser/handle_tags.c new file mode 100644 index 0000000000..9047e0bae4 --- /dev/null +++ b/utils/newparser/handle_tags.c | |||
@@ -0,0 +1,157 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: tag_table.c 26346 2010-05-28 02:30:27Z jdgordon $ | ||
9 | * | ||
10 | * Copyright (C) 2010 Jonathan Gordon | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <stdbool.h> | ||
25 | #include <string.h> | ||
26 | #include <ctype.h> | ||
27 | |||
28 | #include "skin_parser.h" | ||
29 | #include "tag_table.h" | ||
30 | #include "skin_structs.h" | ||
31 | |||
32 | typedef int (tag_handler)(struct skin *skin, struct skin_element* element, bool size_only); | ||
33 | |||
34 | |||
35 | |||
36 | int handle_translate_string(struct skin *skin, struct skin_element* element, bool size_only) | ||
37 | { | ||
38 | struct skin_token *token = &skin->tokens[skin->token_count++]; | ||
39 | token->type = element->tag->type; | ||
40 | token->next = false; | ||
41 | token->value.i = 1; /* actually need to fix this */ | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | int handle_this_or_next_track(struct skin *skin, struct skin_element* element, bool size_only) | ||
46 | { | ||
47 | struct skin_token *token = &skin->tokens[skin->token_count++]; | ||
48 | token->type = element->tag->type; | ||
49 | token->next = element->tag->name[0] == 'D' | ||
50 | || element->tag->name[0] == 'I' | ||
51 | || element->tag->name[0] == 'F'; | ||
52 | if (element->tag->type == SKIN_TOKEN_FILE_DIRECTORY) | ||
53 | { | ||
54 | if (element->params_count != 1 || element->params[0].type_code != NUMERIC) | ||
55 | return -1; | ||
56 | token->value.i = element->params[0].data.numeric; | ||
57 | } | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | int handle_bar(struct skin *skin, struct skin_element* element, bool size_only) | ||
62 | { | ||
63 | struct skin_token *token = &skin->tokens[skin->token_count++]; | ||
64 | struct progressbar bar; | ||
65 | /* %bar with no params is different for each one so handle that! */ | ||
66 | if (element->params_count == 0) | ||
67 | { | ||
68 | if (size_only) | ||
69 | { | ||
70 | if (element->tag->type == SKIN_TOKEN_PROGRESSBAR) | ||
71 | return sizeof(struct progressbar); | ||
72 | else | ||
73 | return 0; | ||
74 | } | ||
75 | } | ||
76 | else | ||
77 | { | ||
78 | if (size_only) | ||
79 | return sizeof(struct progressbar); | ||
80 | } | ||
81 | |||
82 | token->type = element->tag->type; | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | struct tag_handler_table { | ||
87 | enum skin_token_type type; | ||
88 | int flags; | ||
89 | tag_handler *func; | ||
90 | }; | ||
91 | |||
92 | struct tag_handler_table table[] = { | ||
93 | /* file tags */ | ||
94 | { SKIN_TOKEN_FILE_BITRATE , 0, handle_this_or_next_track }, | ||
95 | { SKIN_TOKEN_FILE_CODEC , 0, handle_this_or_next_track }, | ||
96 | { SKIN_TOKEN_FILE_FREQUENCY , 0, handle_this_or_next_track }, | ||
97 | { SKIN_TOKEN_FILE_FREQUENCY_KHZ , 0, handle_this_or_next_track }, | ||
98 | { SKIN_TOKEN_FILE_NAME_WITH_EXTENSION , 0, handle_this_or_next_track }, | ||
99 | { SKIN_TOKEN_FILE_NAME , 0, handle_this_or_next_track }, | ||
100 | { SKIN_TOKEN_FILE_PATH , 0, handle_this_or_next_track }, | ||
101 | { SKIN_TOKEN_FILE_SIZE , 0, handle_this_or_next_track }, | ||
102 | { SKIN_TOKEN_FILE_VBR , 0, handle_this_or_next_track }, | ||
103 | { SKIN_TOKEN_FILE_DIRECTORY , 0, handle_this_or_next_track }, | ||
104 | /* track metadata */ | ||
105 | { SKIN_TOKEN_METADATA_ARTIST , 0, handle_this_or_next_track }, | ||
106 | { SKIN_TOKEN_METADATA_COMPOSER , 0, handle_this_or_next_track }, | ||
107 | { SKIN_TOKEN_METADATA_ALBUM , 0, handle_this_or_next_track }, | ||
108 | { SKIN_TOKEN_METADATA_ALBUM_ARTIST , 0, handle_this_or_next_track }, | ||
109 | { SKIN_TOKEN_METADATA_GROUPING , 0, handle_this_or_next_track }, | ||
110 | { SKIN_TOKEN_METADATA_GENRE , 0, handle_this_or_next_track }, | ||
111 | { SKIN_TOKEN_METADATA_DISC_NUMBER , 0, handle_this_or_next_track }, | ||
112 | { SKIN_TOKEN_METADATA_TRACK_NUMBER , 0, handle_this_or_next_track }, | ||
113 | { SKIN_TOKEN_METADATA_TRACK_TITLE , 0, handle_this_or_next_track }, | ||
114 | { SKIN_TOKEN_METADATA_VERSION , 0, handle_this_or_next_track }, | ||
115 | { SKIN_TOKEN_METADATA_YEAR , 0, handle_this_or_next_track }, | ||
116 | { SKIN_TOKEN_METADATA_COMMENT , 0, handle_this_or_next_track }, | ||
117 | /* misc */ | ||
118 | { SKIN_TOKEN_TRANSLATEDSTRING, 0, handle_translate_string}, | ||
119 | }; | ||
120 | |||
121 | int handle_tree(struct skin *skin, struct skin_element* tree) | ||
122 | { | ||
123 | /* for later.. do this in two steps | ||
124 | * 1) count how much skin buffer is needed | ||
125 | * 2) do the actual tree->skin conversion | ||
126 | */ | ||
127 | struct skin_element* element = tree; | ||
128 | int counter; | ||
129 | while (element) | ||
130 | { | ||
131 | if (element->type == TAG) | ||
132 | { | ||
133 | int i; | ||
134 | for(i=0;i<sizeof(table)/sizeof(*table);i++) | ||
135 | { | ||
136 | if (table[i].type == element->tag->type) | ||
137 | { | ||
138 | table[i].func(skin, element, false); | ||
139 | break; | ||
140 | } | ||
141 | } | ||
142 | } | ||
143 | else if (element->type == TEXT) | ||
144 | { | ||
145 | /* handle */ | ||
146 | } | ||
147 | |||
148 | counter = 0; | ||
149 | while (counter < element->children_count) | ||
150 | { | ||
151 | int ret = handle_tree(skin, element->children[counter]); | ||
152 | counter++; | ||
153 | } | ||
154 | element = element->next; | ||
155 | } | ||
156 | return 0; | ||
157 | } | ||
diff --git a/utils/newparser/newparser.c b/utils/newparser/newparser.c new file mode 100644 index 0000000000..2f58b64d15 --- /dev/null +++ b/utils/newparser/newparser.c | |||
@@ -0,0 +1,81 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: tag_table.c 26346 2010-05-28 02:30:27Z jdgordon $ | ||
9 | * | ||
10 | * Copyright (C) 2010 Jonathan Gordon | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <stdbool.h> | ||
25 | #include <string.h> | ||
26 | #include <ctype.h> | ||
27 | |||
28 | #include "skin_parser.h" | ||
29 | #include "tag_table.h" | ||
30 | #include "skin_structs.h" | ||
31 | |||
32 | int handle_tree(struct skin *skin, struct skin_element* tree); | ||
33 | void skin_render(struct skin_element* root); | ||
34 | |||
35 | int main(int argc, char* argv[]) | ||
36 | { | ||
37 | char buffer[10*1024], temp[512]; | ||
38 | FILE *in; | ||
39 | int filearg = 1, i=0; | ||
40 | if( (argc < 2) || | ||
41 | strcmp(argv[1],"-h") == 0 || | ||
42 | strcmp(argv[1],"--help") == 0 ) | ||
43 | { | ||
44 | printf("Usage: %s infile \n", argv[0]); | ||
45 | return 0; | ||
46 | } | ||
47 | |||
48 | while ((argc > filearg) && argv[filearg][0] == '-') | ||
49 | { | ||
50 | i=1; | ||
51 | while (argv[filearg][i]) | ||
52 | { | ||
53 | switch(argv[filearg][i]) | ||
54 | { | ||
55 | } | ||
56 | i++; | ||
57 | } | ||
58 | filearg++; | ||
59 | } | ||
60 | if (argc == filearg) | ||
61 | { | ||
62 | printf("Missing input filename\n"); | ||
63 | return 1; | ||
64 | } | ||
65 | |||
66 | in = fopen(argv[filearg], "r"); | ||
67 | if (!in) | ||
68 | return 1; | ||
69 | while (fgets(temp, 512, in)) | ||
70 | strcat(buffer, temp); | ||
71 | fclose(in); | ||
72 | filearg++; | ||
73 | |||
74 | struct skin_element* tree = skin_parse(buffer); | ||
75 | struct skin skin; | ||
76 | skin_render(tree); | ||
77 | //handle_tree(&skin, tree); | ||
78 | |||
79 | skin_free_tree(tree); | ||
80 | return 0; | ||
81 | } | ||
diff --git a/utils/newparser/skin_render.c b/utils/newparser/skin_render.c new file mode 100644 index 0000000000..68dfd78949 --- /dev/null +++ b/utils/newparser/skin_render.c | |||
@@ -0,0 +1,95 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: skin_parser.c 26752 2010-06-10 21:22:16Z bieber $ | ||
9 | * | ||
10 | * Copyright (C) 2010 Jonathan Gordon | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdlib.h> | ||
23 | #include <stdio.h> | ||
24 | #include <string.h> | ||
25 | #include <ctype.h> | ||
26 | |||
27 | #include "skin_parser.h" | ||
28 | #include "skin_debug.h" | ||
29 | #include "tag_table.h" | ||
30 | #include "symbols.h" | ||
31 | #include "skin_scan.h" | ||
32 | |||
33 | void skin_render_alternator(struct skin_element* alternator); | ||
34 | |||
35 | /* Draw a LINE element onto the display */ | ||
36 | void skin_render_line(struct skin_element* line) | ||
37 | { | ||
38 | int i=0, value; | ||
39 | struct skin_element *child = line->children[0]; | ||
40 | while (child) | ||
41 | { | ||
42 | switch (child->type) | ||
43 | { | ||
44 | case CONDITIONAL: | ||
45 | value = 0; /* actually get it from the token :p */ | ||
46 | if (value >= child->children_count) | ||
47 | value = child->children_count-1; | ||
48 | if (child->children[value]->type == SUBLINES) | ||
49 | skin_render_alternator(child->children[value]); | ||
50 | else if (child->children[value]->type == LINE) | ||
51 | skin_render_line(child->children[value]); | ||
52 | break; | ||
53 | case TAG: | ||
54 | printf("%%%s", child->tag->name); | ||
55 | break; | ||
56 | case TEXT: | ||
57 | printf("%s", (char*)(child->data)); | ||
58 | break; | ||
59 | case COMMENT: | ||
60 | default: | ||
61 | break; | ||
62 | } | ||
63 | child = child->next; | ||
64 | } | ||
65 | printf("\n"); /* might be incorrect */ | ||
66 | } | ||
67 | |||
68 | void skin_render_alternator(struct skin_element* alternator) | ||
69 | { | ||
70 | /*TODO Choose which subline to draw */ | ||
71 | skin_render_line(alternator->children[0]); | ||
72 | } | ||
73 | |||
74 | void skin_render_viewport(struct skin_element* viewport) | ||
75 | { | ||
76 | struct skin_element *line = viewport; | ||
77 | while (line) | ||
78 | { | ||
79 | if (line->type == SUBLINES) | ||
80 | skin_render_alternator(line); | ||
81 | else if (line->type == LINE) | ||
82 | skin_render_line(line); | ||
83 | line = line->next; | ||
84 | } | ||
85 | } | ||
86 | |||
87 | void skin_render(struct skin_element* root) | ||
88 | { | ||
89 | struct skin_element* viewport = root; | ||
90 | while (viewport) | ||
91 | { | ||
92 | skin_render_viewport(viewport->children[viewport->children_count-1]); | ||
93 | viewport = viewport->next; | ||
94 | } | ||
95 | } | ||
diff --git a/utils/newparser/skin_structs.h b/utils/newparser/skin_structs.h new file mode 100644 index 0000000000..c86e683589 --- /dev/null +++ b/utils/newparser/skin_structs.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: tag_table.c 26346 2010-05-28 02:30:27Z jdgordon $ | ||
9 | * | ||
10 | * Copyright (C) 2010 Jonathan Gordon | ||
11 | * | ||
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. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <stdio.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <stdbool.h> | ||
25 | #include <string.h> | ||
26 | #include <ctype.h> | ||
27 | |||
28 | #include "skin_parser.h" | ||
29 | #include "tag_table.h" | ||
30 | |||
31 | struct skin_token { | ||
32 | enum skin_token_type type; /* enough to store the token type */ | ||
33 | |||
34 | /* Whether the tag (e.g. track name or the album) refers the | ||
35 | current or the next song (false=current, true=next) */ | ||
36 | bool next; | ||
37 | |||
38 | union { | ||
39 | char c; | ||
40 | unsigned int i; | ||
41 | void* data; | ||
42 | } value; | ||
43 | }; | ||
44 | |||
45 | #define MAX_TOKENS 10000 | ||
46 | struct skin | ||
47 | { | ||
48 | int token_count; | ||
49 | struct skin_token tokens[MAX_TOKENS]; | ||
50 | }; | ||
51 | |||
52 | |||
53 | struct progressbar { | ||
54 | enum skin_token_type type; | ||
55 | struct viewport *vp; | ||
56 | /* regular pb */ | ||
57 | short x; | ||
58 | /* >=0: explicitly set in the tag -> y-coord within the viewport | ||
59 | <0 : not set in the tag -> negated 1-based line number within | ||
60 | the viewport. y-coord will be computed based on the font height */ | ||
61 | short y; | ||
62 | short width; | ||
63 | short height; | ||
64 | bool follow_lang_direction; | ||
65 | /*progressbar image*/ | ||
66 | // struct bitmap bm; | ||
67 | bool have_bitmap_pb; | ||
68 | }; | ||