diff options
author | Robert Bieber <robby@bieberphoto.com> | 2010-05-25 17:22:39 +0000 |
---|---|---|
committer | Robert Bieber <robby@bieberphoto.com> | 2010-05-25 17:22:39 +0000 |
commit | 1937b1b1ae0527f2c80834c0461532f1a3cceeaa (patch) | |
tree | 7426ffcef783bfff60e73211cd42849c52ef9470 /utils | |
parent | 58b4fe10076e053664a598dc252ef107d1da6fa2 (diff) | |
download | rockbox-1937b1b1ae0527f2c80834c0461532f1a3cceeaa.tar.gz rockbox-1937b1b1ae0527f2c80834c0461532f1a3cceeaa.zip |
Fixed some bugs in the theme editor, added the tags with parameters to the tag table
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26288 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils')
-rw-r--r-- | utils/themeeditor/main.c | 3 | ||||
-rw-r--r-- | utils/themeeditor/skin_parser.c | 188 | ||||
-rw-r--r-- | utils/themeeditor/skin_scan.c | 1 | ||||
-rw-r--r-- | utils/themeeditor/symbols.h | 2 | ||||
-rw-r--r-- | utils/themeeditor/tag_table.c | 28 | ||||
-rw-r--r-- | utils/themeeditor/tag_table.h | 3 |
6 files changed, 119 insertions, 106 deletions
diff --git a/utils/themeeditor/main.c b/utils/themeeditor/main.c index 9f45c90317..269cad7840 100644 --- a/utils/themeeditor/main.c +++ b/utils/themeeditor/main.c | |||
@@ -6,8 +6,7 @@ | |||
6 | 6 | ||
7 | int main(int argc, char* argv[]) | 7 | int main(int argc, char* argv[]) |
8 | { | 8 | { |
9 | char* doc = "This is a sample %V(1, 2, 3, 4, 5, six, seven)\n" | 9 | char* doc = "%Vd(U))\n\n%?bl(test,3,5,2,1)<param2|param3>"; |
10 | "WPS document, with ; sublines and a %?T(conditional| or| two)"; | ||
11 | 10 | ||
12 | struct skin_element* test = skin_parse(doc); | 11 | struct skin_element* test = skin_parse(doc); |
13 | 12 | ||
diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c index 89952a615b..bc1f2a5ed2 100644 --- a/utils/themeeditor/skin_parser.c +++ b/utils/themeeditor/skin_parser.c | |||
@@ -153,8 +153,11 @@ struct skin_element* skin_parse_line_optional(char** document, int conditional) | |||
153 | struct skin_element* current = NULL; | 153 | struct skin_element* current = NULL; |
154 | 154 | ||
155 | while(*cursor != '\n' && *cursor != '\0' && *cursor != MULTILINESYM | 155 | while(*cursor != '\n' && *cursor != '\0' && *cursor != MULTILINESYM |
156 | && !((*cursor == ARGLISTSEPERATESYM || *cursor == ARGLISTCLOSESYM | 156 | && !((*cursor == ARGLISTSEPERATESYM |
157 | || *cursor == ENUMLISTSEPERATESYM) && conditional)) | 157 | || *cursor == ARGLISTCLOSESYM |
158 | || *cursor == ENUMLISTSEPERATESYM | ||
159 | || *cursor == ENUMLISTCLOSESYM) | ||
160 | && conditional)) | ||
158 | { | 161 | { |
159 | /* Allocating memory if necessary */ | 162 | /* Allocating memory if necessary */ |
160 | if(root) | 163 | if(root) |
@@ -233,8 +236,11 @@ struct skin_element* skin_parse_sublines_optional(char** document, | |||
233 | 236 | ||
234 | /* First we count the sublines */ | 237 | /* First we count the sublines */ |
235 | while(*cursor != '\0' && *cursor != '\n' | 238 | while(*cursor != '\0' && *cursor != '\n' |
236 | && !((*cursor == ARGLISTSEPERATESYM || *cursor == ARGLISTCLOSESYM | 239 | && !((*cursor == ARGLISTSEPERATESYM |
237 | || *cursor == ENUMLISTSEPERATESYM) && conditional)) | 240 | || *cursor == ARGLISTCLOSESYM |
241 | || *cursor == ENUMLISTSEPERATESYM | ||
242 | || *cursor == ENUMLISTCLOSESYM) | ||
243 | && conditional)) | ||
238 | { | 244 | { |
239 | if(*cursor == COMMENTSYM) | 245 | if(*cursor == COMMENTSYM) |
240 | skip_comment(&cursor); | 246 | skip_comment(&cursor); |
@@ -292,7 +298,8 @@ int skin_parse_tag(struct skin_element* element, char** document) | |||
292 | 298 | ||
293 | int num_args = 1; | 299 | int num_args = 1; |
294 | int i; | 300 | int i; |
295 | int count; | 301 | int star = 0; /* Flag for the all-or-none option */ |
302 | int req_args; /* To mark when we enter optional arguments */ | ||
296 | 303 | ||
297 | int optional = 0; | 304 | int optional = 0; |
298 | 305 | ||
@@ -327,8 +334,16 @@ int skin_parse_tag(struct skin_element* element, char** document) | |||
327 | strcpy(element->name, tag_name); | 334 | strcpy(element->name, tag_name); |
328 | element->line = skin_line; | 335 | element->line = skin_line; |
329 | 336 | ||
337 | /* Checking for the * flag */ | ||
338 | if(tag_args[0] == '*') | ||
339 | { | ||
340 | star = 1; | ||
341 | tag_args++; | ||
342 | } | ||
343 | |||
330 | /* If this tag has no arguments, we can bail out now */ | 344 | /* If this tag has no arguments, we can bail out now */ |
331 | if(strlen(tag_args) == 0) | 345 | if(strlen(tag_args) == 0 |
346 | || (tag_args[0] == '|' && *cursor != ARGLISTOPENSYM)) | ||
332 | { | 347 | { |
333 | *document = cursor; | 348 | *document = cursor; |
334 | return 1; | 349 | return 1; |
@@ -374,8 +389,7 @@ int skin_parse_tag(struct skin_element* element, char** document) | |||
374 | element->params = skin_alloc_params(num_args); | 389 | element->params = skin_alloc_params(num_args); |
375 | 390 | ||
376 | /* Now we have to actually parse each argument */ | 391 | /* Now we have to actually parse each argument */ |
377 | i = 0; | 392 | for(i = 0; i < num_args; i++) |
378 | while(i < num_args) | ||
379 | { | 393 | { |
380 | /* Making sure we haven't run out of arguments */ | 394 | /* Making sure we haven't run out of arguments */ |
381 | if(*tag_args == '\0') | 395 | if(*tag_args == '\0') |
@@ -388,113 +402,88 @@ int skin_parse_tag(struct skin_element* element, char** document) | |||
388 | if(*tag_args == '|') | 402 | if(*tag_args == '|') |
389 | { | 403 | { |
390 | optional = 1; | 404 | optional = 1; |
405 | req_args = i - 1; | ||
391 | tag_args++; | 406 | tag_args++; |
392 | } | 407 | } |
393 | 408 | ||
394 | /* Checking for a repeated argument */ | ||
395 | if(isdigit(*tag_args)) | ||
396 | { | ||
397 | count = scan_int(&tag_args); | ||
398 | } | ||
399 | else | ||
400 | { | ||
401 | count = 1; | ||
402 | } | ||
403 | |||
404 | /* Scanning the arguments */ | 409 | /* Scanning the arguments */ |
405 | while(count > 0) | 410 | skip_whitespace(&cursor); |
406 | { | ||
407 | |||
408 | skip_whitespace(&cursor); | ||
409 | 411 | ||
410 | /* Checking for a premature end */ | ||
411 | if(num_args - i < count) | ||
412 | { | ||
413 | if(optional && (num_args - i == 0)) | ||
414 | { | ||
415 | break; | ||
416 | } | ||
417 | else | ||
418 | { | ||
419 | /* | ||
420 | We error out if there are too few arguments, or if there | ||
421 | is an optional argument that was supposed to be grouped | ||
422 | with another | ||
423 | */ | ||
424 | skin_error(INSUFFICIENT_ARGS); | ||
425 | return 0; | ||
426 | } | ||
427 | } | ||
428 | 412 | ||
429 | /* Checking for comments */ | 413 | /* Checking for comments */ |
430 | if(*cursor == COMMENTSYM) | 414 | if(*cursor == COMMENTSYM) |
431 | skip_comment(&cursor); | 415 | skip_comment(&cursor); |
432 | 416 | ||
433 | /* Checking a nullable argument for null */ | 417 | /* Checking a nullable argument for null */ |
434 | if(*cursor == DEFAULTSYM) | 418 | if(*cursor == DEFAULTSYM) |
435 | { | 419 | { |
436 | if(islower(*tag_args)) | 420 | if(islower(*tag_args)) |
437 | { | ||
438 | element->params[i].type = DEFAULT; | ||
439 | cursor++; | ||
440 | } | ||
441 | else | ||
442 | { | ||
443 | skin_error(DEFAULT_NOT_ALLOWED); | ||
444 | return 0; | ||
445 | } | ||
446 | } | ||
447 | else if(tolower(*tag_args) == 'i') | ||
448 | { | 421 | { |
449 | /* Scanning an int argument */ | 422 | element->params[i].type = DEFAULT; |
450 | if(!isdigit(*cursor)) | 423 | cursor++; |
451 | { | ||
452 | skin_error(INT_EXPECTED); | ||
453 | return 0; | ||
454 | } | ||
455 | |||
456 | element->params[i].type = NUMERIC; | ||
457 | element->params[i].data.numeric = scan_int(&cursor); | ||
458 | } | 424 | } |
459 | else if(tolower(*tag_args) == 's' || tolower(*tag_args) == 'f') | 425 | else |
460 | { | 426 | { |
461 | /* Scanning a string argument */ | 427 | skin_error(DEFAULT_NOT_ALLOWED); |
462 | element->params[i].type = STRING; | 428 | return 0; |
463 | element->params[i].data.text = scan_string(&cursor); | ||
464 | |||
465 | } | 429 | } |
466 | else if(tolower(*tag_args) == 'c') | 430 | } |
431 | else if(tolower(*tag_args) == 'i') | ||
432 | { | ||
433 | /* Scanning an int argument */ | ||
434 | if(!isdigit(*cursor)) | ||
467 | { | 435 | { |
468 | element->params[i].type = CODE; | 436 | skin_error(INT_EXPECTED); |
469 | element->params[i].data.code = skin_parse_code_as_arg(&cursor); | 437 | return 0; |
470 | if(!element->params[i].data.code) | ||
471 | return 0; | ||
472 | } | 438 | } |
473 | 439 | ||
474 | i++; | 440 | element->params[i].type = NUMERIC; |
475 | count--; | 441 | element->params[i].data.numeric = scan_int(&cursor); |
476 | skip_whitespace(&cursor); | 442 | } |
443 | else if(tolower(*tag_args) == 's' || tolower(*tag_args) == 'f') | ||
444 | { | ||
445 | /* Scanning a string argument */ | ||
446 | element->params[i].type = STRING; | ||
447 | element->params[i].data.text = scan_string(&cursor); | ||
477 | 448 | ||
478 | if(*cursor != ARGLISTSEPERATESYM && i < num_args) | 449 | } |
479 | { | 450 | else if(tolower(*tag_args) == 'c') |
480 | skin_error(SEPERATOR_EXPECTED); | 451 | { |
481 | return 0; | 452 | /* Recursively parsing a code argument */ |
482 | } | 453 | element->params[i].type = CODE; |
483 | else if(*cursor != ARGLISTCLOSESYM && i == num_args) | 454 | element->params[i].data.code = skin_parse_code_as_arg(&cursor); |
484 | { | 455 | if(!element->params[i].data.code) |
485 | skin_error(CLOSE_EXPECTED); | ||
486 | return 0; | 456 | return 0; |
487 | } | 457 | } |
488 | else | 458 | |
489 | { | 459 | skip_whitespace(&cursor); |
490 | cursor++; | 460 | |
491 | } | 461 | if(*cursor != ARGLISTSEPERATESYM && i < num_args - 1) |
462 | { | ||
463 | skin_error(SEPERATOR_EXPECTED); | ||
464 | return 0; | ||
465 | } | ||
466 | else if(*cursor != ARGLISTCLOSESYM && i == num_args - 1) | ||
467 | { | ||
468 | skin_error(CLOSE_EXPECTED); | ||
469 | return 0; | ||
470 | } | ||
471 | else | ||
472 | { | ||
473 | cursor++; | ||
492 | } | 474 | } |
493 | 475 | ||
494 | tag_args++; | 476 | tag_args++; |
495 | 477 | ||
496 | } | 478 | } |
497 | 479 | ||
480 | /* Checking for a premature end */ | ||
481 | if(*tag_args != '\0' && !(optional && (!star || num_args == req_args))) | ||
482 | { | ||
483 | skin_error(INSUFFICIENT_ARGS); | ||
484 | return 0; | ||
485 | } | ||
486 | |||
498 | *document = cursor; | 487 | *document = cursor; |
499 | 488 | ||
500 | return 1; | 489 | return 1; |
@@ -516,8 +505,11 @@ int skin_parse_text(struct skin_element* element, char** document, | |||
516 | /* First figure out how much text we're copying */ | 505 | /* First figure out how much text we're copying */ |
517 | while(*cursor != '\0' && *cursor != '\n' && *cursor != MULTILINESYM | 506 | while(*cursor != '\0' && *cursor != '\n' && *cursor != MULTILINESYM |
518 | && *cursor != COMMENTSYM | 507 | && *cursor != COMMENTSYM |
519 | && !((*cursor == ARGLISTSEPERATESYM || *cursor == ARGLISTCLOSESYM | 508 | && !((*cursor == ARGLISTSEPERATESYM |
520 | || *cursor == ENUMLISTSEPERATESYM) && conditional)) | 509 | || *cursor == ARGLISTCLOSESYM |
510 | || *cursor == ENUMLISTSEPERATESYM | ||
511 | || *cursor == ENUMLISTCLOSESYM) | ||
512 | && conditional)) | ||
521 | { | 513 | { |
522 | /* Dealing with possibility of escaped characters */ | 514 | /* Dealing with possibility of escaped characters */ |
523 | if(*cursor == TAGSYM) | 515 | if(*cursor == TAGSYM) |
@@ -573,13 +565,13 @@ int skin_parse_conditional(struct skin_element* element, char** document) | |||
573 | return 0; | 565 | return 0; |
574 | 566 | ||
575 | /* Counting the children */ | 567 | /* Counting the children */ |
576 | if(*(cursor++) != ARGLISTOPENSYM) | 568 | if(*(cursor++) != ENUMLISTOPENSYM) |
577 | { | 569 | { |
578 | skin_error(ARGLIST_EXPECTED); | 570 | skin_error(ARGLIST_EXPECTED); |
579 | return 0; | 571 | return 0; |
580 | } | 572 | } |
581 | bookmark = cursor; | 573 | bookmark = cursor; |
582 | while(*cursor != ARGLISTCLOSESYM && *cursor != '\n' && *cursor != '\0') | 574 | while(*cursor != ENUMLISTCLOSESYM && *cursor != '\n' && *cursor != '\0') |
583 | { | 575 | { |
584 | if(*cursor == COMMENTSYM) | 576 | if(*cursor == COMMENTSYM) |
585 | { | 577 | { |
@@ -618,7 +610,7 @@ int skin_parse_conditional(struct skin_element* element, char** document) | |||
618 | skin_error(SEPERATOR_EXPECTED); | 610 | skin_error(SEPERATOR_EXPECTED); |
619 | return 0; | 611 | return 0; |
620 | } | 612 | } |
621 | else if(i == children && *cursor != ARGLISTCLOSESYM) | 613 | else if(i == children && *cursor != ENUMLISTCLOSESYM) |
622 | { | 614 | { |
623 | skin_error(CLOSE_EXPECTED); | 615 | skin_error(CLOSE_EXPECTED); |
624 | return 0; | 616 | return 0; |
diff --git a/utils/themeeditor/skin_scan.c b/utils/themeeditor/skin_scan.c index 92ee521176..dfe5d008e5 100644 --- a/utils/themeeditor/skin_scan.c +++ b/utils/themeeditor/skin_scan.c | |||
@@ -73,6 +73,7 @@ char* scan_string(char** document) | |||
73 | /* Copying the string */ | 73 | /* Copying the string */ |
74 | cursor = *document; | 74 | cursor = *document; |
75 | buffer = skin_alloc_string(length); | 75 | buffer = skin_alloc_string(length); |
76 | buffer[length] = '\0'; | ||
76 | for(i = 0; i < length; i++) | 77 | for(i = 0; i < length; i++) |
77 | { | 78 | { |
78 | if(*cursor == COMMENTSYM) | 79 | if(*cursor == COMMENTSYM) |
diff --git a/utils/themeeditor/symbols.h b/utils/themeeditor/symbols.h index a82bb09393..cc82890a16 100644 --- a/utils/themeeditor/symbols.h +++ b/utils/themeeditor/symbols.h | |||
@@ -32,6 +32,8 @@ | |||
32 | #define ARGLISTCLOSESYM ')' | 32 | #define ARGLISTCLOSESYM ')' |
33 | #define ARGLISTSEPERATESYM ',' | 33 | #define ARGLISTSEPERATESYM ',' |
34 | #define ENUMLISTSEPERATESYM '|' | 34 | #define ENUMLISTSEPERATESYM '|' |
35 | #define ENUMLISTOPENSYM '<' | ||
36 | #define ENUMLISTCLOSESYM '>' | ||
35 | #define DEFAULTSYM '-' | 37 | #define DEFAULTSYM '-' |
36 | 38 | ||
37 | #endif /* SYMBOLS_H */ | 39 | #endif /* SYMBOLS_H */ |
diff --git a/utils/themeeditor/tag_table.c b/utils/themeeditor/tag_table.c index ac0537f4a1..4bfae17a97 100644 --- a/utils/themeeditor/tag_table.c +++ b/utils/themeeditor/tag_table.c | |||
@@ -26,15 +26,33 @@ | |||
26 | /* The tag definition table */ | 26 | /* The tag definition table */ |
27 | struct tag_info legal_tags[] = | 27 | struct tag_info legal_tags[] = |
28 | { | 28 | { |
29 | { "V" , "IIiii|2sc" }, | 29 | { "bl" , "*|fIIII" }, |
30 | { "Vi" , "SIIiii|2s" }, | 30 | { "pb" , "*|fIIII" }, |
31 | { "Vd" , "S" }, | 31 | { "pv" , "*|fIIII" }, |
32 | { "T" , "" }, | 32 | { "d" , "I" }, |
33 | { "D" , "I" }, | ||
34 | { "t" , "I" }, | ||
35 | { "mv" , "|I"}, | ||
36 | { "pS" , "|I"}, | ||
37 | { "pE" , "|I"}, | ||
38 | { "Tl" , "|I"}, | ||
39 | { "X" , "F"}, | ||
40 | { "Fl" , "IF"}, | ||
41 | { "Cl" , "II|II"}, | ||
42 | { "V" , "*IIiii|ii"}, | ||
43 | { "Vl" , "*SIIiii|ii"}, | ||
44 | { "Vi" , "*sIIiii|ii"}, | ||
45 | { "Vd" , "S"}, | ||
46 | { "VI" , "S"}, | ||
47 | { "Vp" , "ICC"}, | ||
48 | { "St" , "S"}, | ||
49 | { "Sx" , "S"}, | ||
50 | { "T" , "IIiiI"}, | ||
33 | { "" , ""} /* Keep this here to mark the end of the table */ | 51 | { "" , ""} /* Keep this here to mark the end of the table */ |
34 | }; | 52 | }; |
35 | 53 | ||
36 | /* A table of legal escapable characters */ | 54 | /* A table of legal escapable characters */ |
37 | char legal_escape_characters[] = "%(|);#,"; | 55 | char legal_escape_characters[] = "%(,);#<|>"; |
38 | 56 | ||
39 | /* | 57 | /* |
40 | * Just does a straight search through the tag table to find one by | 58 | * Just does a straight search through the tag table to find one by |
diff --git a/utils/themeeditor/tag_table.h b/utils/themeeditor/tag_table.h index 935380ddd9..807d3e15ac 100644 --- a/utils/themeeditor/tag_table.h +++ b/utils/themeeditor/tag_table.h | |||
@@ -46,7 +46,8 @@ | |||
46 | * To specify multiple instances of the same type, put a | 46 | * To specify multiple instances of the same type, put a |
47 | * number before the character. For instance, the string... | 47 | * number before the character. For instance, the string... |
48 | * 2s | 48 | * 2s |
49 | * will specify two strings. | 49 | * will specify two strings. An asterisk (*) at the beginning of the |
50 | * string will specify that either all or none of the optional | ||
50 | * | 51 | * |
51 | */ | 52 | */ |
52 | struct tag_info | 53 | struct tag_info |