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/themeeditor/skin_parser.c | |
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/themeeditor/skin_parser.c')
-rw-r--r-- | utils/themeeditor/skin_parser.c | 188 |
1 files changed, 90 insertions, 98 deletions
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; |