diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2010-05-27 15:35:22 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2010-05-27 15:35:22 +0000 |
commit | e7ef935448a958efb07cbffa3d6c9e0c20c5022f (patch) | |
tree | a6074bd578c0351c7a31b9331f851abfa91b21cc | |
parent | 7b197352a271a236f3bb5f785192bfa5b29e730d (diff) | |
download | rockbox-e7ef935448a958efb07cbffa3d6c9e0c20c5022f.tar.gz rockbox-e7ef935448a958efb07cbffa3d6c9e0c20c5022f.zip |
first go at a general skin updater program. not very useful yet
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26332 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | utils/skinupdater/skinupdater.c | 199 | ||||
-rw-r--r-- | utils/skinupdater/tag_table.c | 252 | ||||
-rw-r--r-- | utils/skinupdater/tag_table.h | 82 |
3 files changed, 533 insertions, 0 deletions
diff --git a/utils/skinupdater/skinupdater.c b/utils/skinupdater/skinupdater.c new file mode 100644 index 0000000000..060d4dda47 --- /dev/null +++ b/utils/skinupdater/skinupdater.c | |||
@@ -0,0 +1,199 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <stdbool.h> | ||
4 | #include <string.h> | ||
5 | #include "tag_table.h" | ||
6 | |||
7 | #define PUTCH(out, c) fprintf(out, "%c", c) | ||
8 | extern struct tag_info legal_tags[]; | ||
9 | /* dump "count" args to output replacing '|' with ',' except after the last count. | ||
10 | * return the amount of chars read. (start+return will be after the last | ) | ||
11 | */ | ||
12 | int dump_arg(FILE* out, const char* start, int count, bool close) | ||
13 | { | ||
14 | int l = 0; | ||
15 | while (count) | ||
16 | { | ||
17 | if (start[l] == '|') | ||
18 | { | ||
19 | if (count > 1) | ||
20 | { | ||
21 | printf(","); | ||
22 | } else if (close) { | ||
23 | printf(")"); | ||
24 | } | ||
25 | count--; | ||
26 | } else { | ||
27 | PUTCH(out, start[l]); | ||
28 | } | ||
29 | l++; | ||
30 | } | ||
31 | return l; | ||
32 | } | ||
33 | #define MATCH(s) (!strcmp(tag->name, s)) | ||
34 | int parse_tag(FILE* out, const char* start) | ||
35 | { | ||
36 | struct tag_info *tag; | ||
37 | int len = 0; | ||
38 | for(tag = legal_tags; | ||
39 | tag->name[0] && strncmp(start, tag->name, strlen(tag->name)) != 0; | ||
40 | tag++) ; | ||
41 | if (!tag->name[0]) | ||
42 | return -1; | ||
43 | if (tag->params[0] == '\0') | ||
44 | { | ||
45 | fprintf(out, "%s", tag->name); | ||
46 | return strlen(tag->name); | ||
47 | } | ||
48 | fprintf(out, "%s", tag->name); | ||
49 | len += strlen(tag->name); | ||
50 | start += len; | ||
51 | /* handle individual tags which accept params */ | ||
52 | if (MATCH("bl") || MATCH("pb") || MATCH("pv")) | ||
53 | { | ||
54 | start++; len++; | ||
55 | if (*start == '|') | ||
56 | { | ||
57 | PUTCH(out, '('); | ||
58 | /* TODO: need to verify that we are actually using the long form... */ | ||
59 | len += dump_arg(out, start, 5, true); | ||
60 | } | ||
61 | } | ||
62 | else if (MATCH("d") || MATCH("D") || MATCH("mv") || MATCH("pS") || MATCH("pE") || MATCH("t") || MATCH("Tl")) | ||
63 | { | ||
64 | char temp[8] = {'\0'}; | ||
65 | int i = 0; | ||
66 | /* tags which maybe have a number after them */ | ||
67 | while ((*start >= '0' && *start <= '9') || *start == '.') | ||
68 | { | ||
69 | temp[i++] = *start++; | ||
70 | } | ||
71 | if (i!= 0) | ||
72 | { | ||
73 | fprintf(out, "(%s)", temp); | ||
74 | len += i; | ||
75 | } | ||
76 | } | ||
77 | else if (MATCH("xl")) | ||
78 | { | ||
79 | PUTCH(out, '('); | ||
80 | len += 1+dump_arg(out, start+1, 5, true); | ||
81 | } | ||
82 | else if (MATCH("xd")) | ||
83 | { | ||
84 | /* NOTE: almost certainly needs work */ | ||
85 | PUTCH(out, '('); | ||
86 | PUTCH(out, *start++); len++; | ||
87 | if ((*start >= 'a' && *start <= 'z') || | ||
88 | (*start >= 'A' && *start <= 'Z')) | ||
89 | PUTCH(out, *start); len++; | ||
90 | PUTCH(out, ')'); | ||
91 | } | ||
92 | else if (MATCH("x")) | ||
93 | { | ||
94 | PUTCH(out, '('); | ||
95 | len += 1+dump_arg(out, start+1, 4, true); | ||
96 | } | ||
97 | else if (MATCH("Fl")) | ||
98 | { | ||
99 | PUTCH(out, '('); | ||
100 | len += 1+dump_arg(out, start+1, 2, true); | ||
101 | } | ||
102 | else if (MATCH("Cl")) | ||
103 | { | ||
104 | PUTCH(out, '('); | ||
105 | len += 1+dump_arg(out, start+1, 4, true); | ||
106 | } | ||
107 | else if (MATCH("Vd") || MATCH("VI")) | ||
108 | { | ||
109 | PUTCH(out, '('); | ||
110 | PUTCH(out, *start); len++; | ||
111 | PUTCH(out, ')'); | ||
112 | } | ||
113 | else if (MATCH("Vp")) | ||
114 | { | ||
115 | /* NOTE: almost certainly needs work */ | ||
116 | PUTCH(out, '('); | ||
117 | len += 1+dump_arg(out, start+1, 3, true); | ||
118 | } | ||
119 | else if (MATCH("Vl") || MATCH("Vi")) | ||
120 | { | ||
121 | PUTCH(out, '('); | ||
122 | len += 1+dump_arg(out, start+1, 8, true); | ||
123 | } | ||
124 | else if (MATCH("V")) | ||
125 | { | ||
126 | PUTCH(out, '('); | ||
127 | len += 1+dump_arg(out, start+1, 7, true); | ||
128 | } | ||
129 | else if (MATCH("X")) | ||
130 | { | ||
131 | if (*start+1 == 'd') | ||
132 | { | ||
133 | fprintf(out, "(d)"); | ||
134 | len ++; | ||
135 | } | ||
136 | else | ||
137 | { | ||
138 | PUTCH(out, '('); | ||
139 | len += 1+dump_arg(out, start+1, 1, true); | ||
140 | } | ||
141 | } | ||
142 | else if (MATCH("St") || MATCH("Sx")) | ||
143 | { | ||
144 | PUTCH(out, '('); | ||
145 | len += 1+dump_arg(out, start+1, 1, true); | ||
146 | } | ||
147 | |||
148 | else if (MATCH("T")) | ||
149 | { | ||
150 | PUTCH(out, '('); | ||
151 | len += 1+dump_arg(out, start+1, 5, true); | ||
152 | } | ||
153 | return len; | ||
154 | } | ||
155 | |||
156 | void parse_text(const char* in, FILE* out) | ||
157 | { | ||
158 | const char* end = in+strlen(in); | ||
159 | top: | ||
160 | while (in < end && *in) | ||
161 | { | ||
162 | if (*in == '%') | ||
163 | { | ||
164 | PUTCH(out, *in++); | ||
165 | switch(*in) | ||
166 | { | ||
167 | |||
168 | case '%': | ||
169 | case '<': | ||
170 | case '|': | ||
171 | case '>': | ||
172 | case ';': | ||
173 | case '#': | ||
174 | PUTCH(out, *in++); | ||
175 | goto top; | ||
176 | break; | ||
177 | case '?': | ||
178 | PUTCH(out, *in++); | ||
179 | break; | ||
180 | } | ||
181 | in += parse_tag(out, in); | ||
182 | } | ||
183 | else | ||
184 | { | ||
185 | PUTCH(out, *in++); | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | |||
190 | int main(int argc, char* argv[]) | ||
191 | { | ||
192 | parse_text("%s%?it<%?in<%in. |>%it|%fn>\n" | ||
193 | "%s%?ia<%ia|%?d2<%d2|(root)>>\n" | ||
194 | "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n" | ||
195 | "%al%pc/%pt%ar[%pp:%pe]\n" | ||
196 | "%fbkBit %?fv<avg|> %?iv<(id3v%iv)|(no id3)>\n" | ||
197 | "%pb\n%pm\n", stdout); | ||
198 | return 0; | ||
199 | } | ||
diff --git a/utils/skinupdater/tag_table.c b/utils/skinupdater/tag_table.c new file mode 100644 index 0000000000..1f5015feae --- /dev/null +++ b/utils/skinupdater/tag_table.c | |||
@@ -0,0 +1,252 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: tag_table.c 26297 2010-05-26 03:53:06Z jdgordon $ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
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 "tag_table.h" | ||
23 | |||
24 | #include <string.h> | ||
25 | |||
26 | /* The tag definition table */ | ||
27 | struct tag_info legal_tags[] = | ||
28 | { | ||
29 | { "ac", "" }, | ||
30 | { "al", "" }, | ||
31 | { "aL", "" }, | ||
32 | { "ar", "" }, | ||
33 | { "aR", "" }, | ||
34 | { "aX", "" }, | ||
35 | |||
36 | { "bl" , "*fIIII" }, | ||
37 | { "bv", "" }, | ||
38 | { "bt", "" }, | ||
39 | { "bs", "" }, | ||
40 | { "bc", "" }, | ||
41 | { "bp", "" }, | ||
42 | { "bu", "" }, | ||
43 | |||
44 | |||
45 | { "cc", "" }, | ||
46 | { "cd", "" }, | ||
47 | { "ce", "" }, | ||
48 | { "cf", "" }, | ||
49 | { "cH", "" }, | ||
50 | { "ck", "" }, | ||
51 | { "cI", "" }, | ||
52 | { "cl", "" }, | ||
53 | { "cm", "" }, | ||
54 | { "cM", "" }, | ||
55 | { "cS", "" }, | ||
56 | { "cy", "" }, | ||
57 | { "cY", "" }, | ||
58 | { "cP", "" }, | ||
59 | { "cp", "" }, | ||
60 | { "ca", "" }, | ||
61 | { "cb", "" }, | ||
62 | { "cu", "" }, | ||
63 | { "cw", "" }, | ||
64 | |||
65 | { "fb", "" }, | ||
66 | { "fc", "" }, | ||
67 | { "ff", "" }, | ||
68 | { "fk", "" }, | ||
69 | { "fm", "" }, | ||
70 | { "fn", "" }, | ||
71 | { "fp", "" }, | ||
72 | { "fs", "" }, | ||
73 | { "fv", "" }, | ||
74 | { "d" , "I" }, | ||
75 | |||
76 | { "Fb", "" }, | ||
77 | { "Fc", "" }, | ||
78 | { "Ff", "" }, | ||
79 | { "Fk", "" }, | ||
80 | { "Fm", "" }, | ||
81 | { "Fn", "" }, | ||
82 | { "Fp", "" }, | ||
83 | { "Fs", "" }, | ||
84 | { "Fv", "" }, | ||
85 | { "D" , "I" }, | ||
86 | |||
87 | |||
88 | { "ia", "" }, | ||
89 | { "ic", "" }, | ||
90 | { "id", "" }, | ||
91 | { "iA", "" }, | ||
92 | { "iG", "" }, | ||
93 | { "ig", "" }, | ||
94 | { "ik", "" }, | ||
95 | { "in", "" }, | ||
96 | { "it", "" }, | ||
97 | { "iv", "" }, | ||
98 | { "iy", "" }, | ||
99 | { "iC", "" }, | ||
100 | |||
101 | { "Ia", "" }, | ||
102 | { "Ic", "" }, | ||
103 | { "Id", "" }, | ||
104 | { "IA", "" }, | ||
105 | { "IG", "" }, | ||
106 | { "Ig", "" }, | ||
107 | { "Ik", "" }, | ||
108 | { "In", "" }, | ||
109 | { "It", "" }, | ||
110 | { "Iv", "" }, | ||
111 | { "Iy", "" }, | ||
112 | { "IC", "" }, | ||
113 | |||
114 | { "Sp", "" }, | ||
115 | { "Ss", "" }, | ||
116 | |||
117 | { "lh", "" }, | ||
118 | |||
119 | { "mh", "" }, | ||
120 | { "mr", "" }, | ||
121 | { "mm", "" }, | ||
122 | { "mp", "" }, | ||
123 | { "mv", "|I" }, | ||
124 | |||
125 | { "pm", "" }, | ||
126 | { "pf", "" }, | ||
127 | { "pb" , "*fIIII" }, | ||
128 | { "pv" , "*fIIII" }, | ||
129 | |||
130 | { "px", "" }, | ||
131 | { "pc", "" }, | ||
132 | { "pr", "" }, | ||
133 | { "pt", "" }, | ||
134 | { "pS" , "|I"}, | ||
135 | { "pE" , "|I"}, | ||
136 | { "pp", "" }, | ||
137 | { "pe", "" }, | ||
138 | { "pn", "" }, | ||
139 | { "ps", "" }, | ||
140 | |||
141 | { "rp", "" }, | ||
142 | { "rr", "" }, | ||
143 | { "ra", "" }, | ||
144 | |||
145 | { "rg", "" }, | ||
146 | { "xf", "" }, | ||
147 | |||
148 | { "tp", "" }, | ||
149 | { "tt", "" }, | ||
150 | { "tm", "" }, | ||
151 | { "ts", "" }, | ||
152 | { "ta", "" }, | ||
153 | { "tb", "" }, | ||
154 | { "tf", "" }, | ||
155 | { "Ti", "" }, | ||
156 | { "Tn", "" }, | ||
157 | { "Tf", "" }, | ||
158 | { "Tc", "" }, | ||
159 | { "tx", "" }, | ||
160 | { "ty", "" }, | ||
161 | { "tz", "" }, | ||
162 | |||
163 | { "s", "" }, | ||
164 | { "t" , "I" }, | ||
165 | |||
166 | { "we", "" }, | ||
167 | { "wd", "" }, | ||
168 | { "wi", "" }, | ||
169 | |||
170 | { "xl", "SFIIi" }, | ||
171 | { "xd", "S" }, | ||
172 | { "x", "SFII" }, | ||
173 | |||
174 | { "Fl" , "IF"}, | ||
175 | { "Cl" , "IISS"}, | ||
176 | { "C" , ""}, | ||
177 | |||
178 | { "Vd" , "S"}, | ||
179 | { "VI" , "S"}, | ||
180 | |||
181 | { "Vp" , "ICC"}, | ||
182 | { "Lt" , ""}, | ||
183 | { "Li" , ""}, | ||
184 | |||
185 | { "Vl" , "SIIiii|ii"}, | ||
186 | { "Vi" , "sIIiii|ii"}, | ||
187 | { "V" , "IIiii|ii"}, | ||
188 | |||
189 | { "X" , "f"}, | ||
190 | |||
191 | { "St" , "S"}, | ||
192 | { "Sx" , "S"}, | ||
193 | { "Sr" , ""}, | ||
194 | |||
195 | { "Tl" , "|I"}, | ||
196 | { "cs", "" }, | ||
197 | { "T" , "IIiiI"}, | ||
198 | |||
199 | { "Rp" , ""}, | ||
200 | { "Rr" , ""}, | ||
201 | { "Rf" , ""}, | ||
202 | { "Re" , ""}, | ||
203 | { "Rb" , ""}, | ||
204 | { "Rm" , ""}, | ||
205 | { "Rs" , ""}, | ||
206 | { "Rn" , ""}, | ||
207 | { "Rh" , ""}, | ||
208 | { "s",""}, | ||
209 | |||
210 | { "" , ""} /* Keep this here to mark the end of the table */ | ||
211 | }; | ||
212 | |||
213 | /* A table of legal escapable characters */ | ||
214 | char legal_escape_characters[] = "%(,);#<|>"; | ||
215 | |||
216 | /* | ||
217 | * Just does a straight search through the tag table to find one by | ||
218 | * the given name | ||
219 | */ | ||
220 | char* find_tag(char* name) | ||
221 | { | ||
222 | |||
223 | struct tag_info* current = legal_tags; | ||
224 | |||
225 | /* | ||
226 | * Continue searching so long as we have a non-empty name string | ||
227 | * and the name of the current element doesn't match the name | ||
228 | * we're searching for | ||
229 | */ | ||
230 | |||
231 | while(strcmp(current->name, name) && current->name[0] != '\0') | ||
232 | current++; | ||
233 | |||
234 | if(current->name[0] == '\0') | ||
235 | return NULL; | ||
236 | else | ||
237 | return current->params; | ||
238 | |||
239 | } | ||
240 | |||
241 | /* Searches through the legal escape characters string */ | ||
242 | int find_escape_character(char lookup) | ||
243 | { | ||
244 | char* current = legal_escape_characters; | ||
245 | while(*current != lookup && *current != '\0') | ||
246 | current++; | ||
247 | |||
248 | if(*current == lookup) | ||
249 | return 1; | ||
250 | else | ||
251 | return 0; | ||
252 | } | ||
diff --git a/utils/skinupdater/tag_table.h b/utils/skinupdater/tag_table.h new file mode 100644 index 0000000000..7cbabfe768 --- /dev/null +++ b/utils/skinupdater/tag_table.h | |||
@@ -0,0 +1,82 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: tag_table.h 26292 2010-05-25 22:24:08Z bieber $ | ||
9 | * | ||
10 | * Copyright (C) 2010 Robert Bieber | ||
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 | #ifndef TAG_TABLE_H | ||
23 | #define TAG_TABLE_H | ||
24 | |||
25 | #ifdef __cplusplus | ||
26 | extern "C" | ||
27 | { | ||
28 | namespace wps | ||
29 | { | ||
30 | #endif | ||
31 | |||
32 | |||
33 | /* | ||
34 | * Struct for tag parsing information | ||
35 | * name - The name of the tag, i.e. V for %V | ||
36 | * params - A string specifying all of the tags parameters, each | ||
37 | * character representing a single parameter. Valid | ||
38 | * characters for parameters are: | ||
39 | * I - Required integer | ||
40 | * i - Nullable integer | ||
41 | * S - Required string | ||
42 | * s - Nullable string | ||
43 | * F - Required file name | ||
44 | * f - Nullable file name | ||
45 | * C - Required WPS code | ||
46 | * Any nullable parameter may be replaced in the WPS file | ||
47 | * with a '-'. To specify that parameters may be left off | ||
48 | * altogether, place a '|' in the parameter string. For | ||
49 | * instance, with the parameter string... | ||
50 | * Ii|Ss | ||
51 | * one integer must be specified, one integer can be | ||
52 | * specified or set to default with '-', and the user can | ||
53 | * stop providing parameters at any time after that. | ||
54 | * To specify multiple instances of the same type, put a | ||
55 | * number before the character. For instance, the string... | ||
56 | * 2s | ||
57 | * will specify two strings. An asterisk (*) at the beginning of the | ||
58 | * string will specify that either all or none of the optional | ||
59 | * | ||
60 | */ | ||
61 | struct tag_info | ||
62 | { | ||
63 | |||
64 | char* name; | ||
65 | char* params; | ||
66 | |||
67 | }; | ||
68 | |||
69 | /* | ||
70 | * Finds a tag by name and returns its parameter list, or an empty | ||
71 | * string if the tag is not found in the table | ||
72 | */ | ||
73 | char* find_tag(char* name); | ||
74 | |||
75 | /* | ||
76 | * Determines whether a character is legal to escape or not. If | ||
77 | * lookup is not found in the legal escape characters string, returns | ||
78 | * false, otherwise returns true | ||
79 | */ | ||
80 | int find_escape_character(char lookup); | ||
81 | |||
82 | #endif /* TAG_TABLE_H */ | ||