summaryrefslogtreecommitdiff
path: root/apps/gui/wps_parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/wps_parser.c')
-rw-r--r--apps/gui/wps_parser.c132
1 files changed, 67 insertions, 65 deletions
diff --git a/apps/gui/wps_parser.c b/apps/gui/wps_parser.c
index cf71f2d6aa..b51a76a594 100644
--- a/apps/gui/wps_parser.c
+++ b/apps/gui/wps_parser.c
@@ -69,7 +69,10 @@ extern void print_img_cond_indexes(struct wps_data *data);
69extern void print_wps_strings(struct wps_data *data); 69extern void print_wps_strings(struct wps_data *data);
70#endif 70#endif
71 71
72typedef int (*wps_tag_parse_func)(const char *wps_token, struct wps_data *wps_data); 72/* special parsing function.
73 wps_bufptr points to the char following the tag.
74 The return value is the number of chars read. */
75typedef int (*wps_tag_parse_func)(const char *wps_bufptr, struct wps_data *wps_data);
73 76
74struct wps_tag { 77struct wps_tag {
75 enum wps_token_type type; 78 enum wps_token_type type;
@@ -79,18 +82,17 @@ struct wps_tag {
79}; 82};
80 83
81/* prototypes of all special parse functions : */ 84/* prototypes of all special parse functions : */
82 85static int parse_subline_timeout(const char *wps_bufptr, struct wps_data *wps_data);
83static int parse_subline_timeout(const char *wps_token, struct wps_data *wps_data); 86static int parse_progressbar(const char *wps_bufptr, struct wps_data *wps_data);
84static int parse_progressbar(const char *wps_token, struct wps_data *wps_data); 87static int parse_dir_level(const char *wps_bufptr, struct wps_data *wps_data);
85static int parse_dir_level(const char *wps_token, struct wps_data *wps_data);
86#ifdef HAVE_LCD_BITMAP 88#ifdef HAVE_LCD_BITMAP
87static int parse_image_special(const char *wps_token, struct wps_data *wps_data); 89static int parse_image_special(const char *wps_bufptr, struct wps_data *wps_data);
88static int parse_statusbar(const char *wps_token, struct wps_data *wps_data); 90static int parse_statusbar(const char *wps_bufptr, struct wps_data *wps_data);
89static int parse_image_display(const char *wps_token, struct wps_data *wps_data); 91static int parse_image_display(const char *wps_bufptr, struct wps_data *wps_data);
90static int parse_image_load(const char *wps_token, struct wps_data *wps_data); 92static int parse_image_load(const char *wps_bufptr, struct wps_data *wps_data);
91#endif /*HAVE_LCD_BITMAP */ 93#endif /*HAVE_LCD_BITMAP */
92#if CONFIG_RTC 94#if CONFIG_RTC
93static int parse_rtc_format(const char *wps_token, struct wps_data *wps_data); 95static int parse_rtc_format(const char *wps_bufptr, struct wps_data *wps_data);
94 96
95/* RTC tokens array */ 97/* RTC tokens array */
96static const struct wps_tag rtc_tags[] = { 98static const struct wps_tag rtc_tags[] = {
@@ -250,36 +252,36 @@ static const struct wps_tag all_tags[] = {
250}; 252};
251 253
252 254
253static int skip_end_of_line(const char *wps_token) 255static int skip_end_of_line(const char *wps_bufptr)
254{ 256{
255 int skip = 0; 257 int skip = 0;
256 while(*(wps_token + skip) != '\n') 258 while(*(wps_bufptr + skip) != '\n')
257 skip++; 259 skip++;
258 return ++skip; 260 return ++skip;
259} 261}
260 262
261#if CONFIG_RTC 263#if CONFIG_RTC
262static int parse_rtc_format(const char *wps_token, struct wps_data *wps_data) 264static int parse_rtc_format(const char *wps_bufptr, struct wps_data *wps_data)
263{ 265{
264 int skip = 0, i; 266 int skip = 0, i;
265 267
266 /* RTC tag format ends with a c or a newline */ 268 /* RTC tag format ends with a c or a newline */
267 while (wps_token && *wps_token != 'c' && *wps_token != '\n') 269 while (wps_bufptr && *wps_bufptr != 'c' && *wps_bufptr != '\n')
268 { 270 {
269 /* find what format char we have */ 271 /* find what format char we have */
270 i = 0; 272 i = 0;
271 while (*(rtc_tags[i].name) && *wps_token != *(rtc_tags[i].name)) 273 while (*(rtc_tags[i].name) && *wps_bufptr != *(rtc_tags[i].name))
272 i++; 274 i++;
273 275
274 wps_data->num_tokens++; 276 wps_data->num_tokens++;
275 wps_data->tokens[wps_data->num_tokens].type = rtc_tags[i].type; 277 wps_data->tokens[wps_data->num_tokens].type = rtc_tags[i].type;
276 wps_data->tokens[wps_data->num_tokens].value.c = *wps_token; 278 wps_data->tokens[wps_data->num_tokens].value.c = *wps_bufptr;
277 skip ++; 279 skip ++;
278 wps_token++; 280 wps_bufptr++;
279 } 281 }
280 282
281 /* eat the unwanted c at the end of the format */ 283 /* eat the unwanted c at the end of the format */
282 if (*wps_token == 'c') 284 if (*wps_bufptr == 'c')
283 skip++; 285 skip++;
284 286
285 return skip; 287 return skip;
@@ -288,7 +290,7 @@ static int parse_rtc_format(const char *wps_token, struct wps_data *wps_data)
288 290
289#ifdef HAVE_LCD_BITMAP 291#ifdef HAVE_LCD_BITMAP
290 292
291static int parse_statusbar(const char *wps_token, struct wps_data *wps_data) 293static int parse_statusbar(const char *wps_bufptr, struct wps_data *wps_data)
292{ 294{
293 wps_data->wps_sb_tag = true; 295 wps_data->wps_sb_tag = true;
294 296
@@ -298,7 +300,7 @@ static int parse_statusbar(const char *wps_token, struct wps_data *wps_data)
298 wps_data->show_sb_on_wps = false; 300 wps_data->show_sb_on_wps = false;
299 301
300 /* Skip the rest of the line */ 302 /* Skip the rest of the line */
301 return skip_end_of_line(wps_token); 303 return skip_end_of_line(wps_bufptr);
302} 304}
303 305
304static bool load_bitmap(struct wps_data *wps_data, 306static bool load_bitmap(struct wps_data *wps_data,
@@ -355,9 +357,9 @@ static char *get_image_filename(const char *start, const char* bmpdir,
355 return buf; 357 return buf;
356} 358}
357 359
358static int parse_image_display(const char *wps_token, struct wps_data *wps_data) 360static int parse_image_display(const char *wps_bufptr, struct wps_data *wps_data)
359{ 361{
360 int n = get_image_id(*wps_token); 362 int n = get_image_id(*wps_bufptr);
361 wps_data->tokens[wps_data->num_tokens].value.i = n; 363 wps_data->tokens[wps_data->num_tokens].value.i = n;
362 364
363 /* if the image is in a conditional, remember it */ 365 /* if the image is in a conditional, remember it */
@@ -367,10 +369,10 @@ static int parse_image_display(const char *wps_token, struct wps_data *wps_data)
367 return 1; 369 return 1;
368} 370}
369 371
370static int parse_image_load(const char *wps_token, struct wps_data *wps_data) 372static int parse_image_load(const char *wps_bufptr, struct wps_data *wps_data)
371{ 373{
372 int n; 374 int n;
373 const char *ptr = wps_token; 375 const char *ptr = wps_bufptr;
374 char *pos = NULL; 376 char *pos = NULL;
375 377
376 /* format: %x|n|filename.bmp|x|y| 378 /* format: %x|n|filename.bmp|x|y|
@@ -387,7 +389,7 @@ static int parse_image_load(const char *wps_token, struct wps_data *wps_data)
387 if(n < 0 || n >= MAX_IMAGES || wps_data->img[n].loaded) 389 if(n < 0 || n >= MAX_IMAGES || wps_data->img[n].loaded)
388 { 390 {
389 /* Skip the rest of the line */ 391 /* Skip the rest of the line */
390 return skip_end_of_line(wps_token); 392 return skip_end_of_line(wps_bufptr);
391 } 393 }
392 394
393 ptr = pos + 1; 395 ptr = pos + 1;
@@ -405,7 +407,7 @@ static int parse_image_load(const char *wps_token, struct wps_data *wps_data)
405 else 407 else
406 { 408 {
407 /* weird syntax, bail out */ 409 /* weird syntax, bail out */
408 return skip_end_of_line(wps_token); 410 return skip_end_of_line(wps_bufptr);
409 } 411 }
410 412
411 /* get y-position */ 413 /* get y-position */
@@ -416,7 +418,7 @@ static int parse_image_load(const char *wps_token, struct wps_data *wps_data)
416 else 418 else
417 { 419 {
418 /* weird syntax, bail out */ 420 /* weird syntax, bail out */
419 return skip_end_of_line(wps_token); 421 return skip_end_of_line(wps_bufptr);
420 } 422 }
421 423
422 if (wps_data->tokens[wps_data->num_tokens].type == WPS_TOKEN_IMAGE_DISPLAY) 424 if (wps_data->tokens[wps_data->num_tokens].type == WPS_TOKEN_IMAGE_DISPLAY)
@@ -424,56 +426,56 @@ static int parse_image_load(const char *wps_token, struct wps_data *wps_data)
424 } 426 }
425 427
426 /* Skip the rest of the line */ 428 /* Skip the rest of the line */
427 return skip_end_of_line(wps_token); 429 return skip_end_of_line(wps_bufptr);
428} 430}
429 431
430static int parse_image_special(const char *wps_token, struct wps_data *wps_data) 432static int parse_image_special(const char *wps_bufptr, struct wps_data *wps_data)
431{ 433{
432 if (wps_data->tokens[wps_data->num_tokens].type == WPS_TOKEN_IMAGE_PROGRESS_BAR) 434 if (wps_data->tokens[wps_data->num_tokens].type == WPS_TOKEN_IMAGE_PROGRESS_BAR)
433 { 435 {
434 /* format: %P|filename.bmp| */ 436 /* format: %P|filename.bmp| */
435 pb_bmp_name = wps_token + 1; 437 pb_bmp_name = wps_bufptr + 1;
436 } 438 }
437#if LCD_DEPTH > 1 439#if LCD_DEPTH > 1
438 else if (wps_data->tokens[wps_data->num_tokens].type == WPS_TOKEN_IMAGE_BACKDROP) 440 else if (wps_data->tokens[wps_data->num_tokens].type == WPS_TOKEN_IMAGE_BACKDROP)
439 { 441 {
440 /* format: %X|filename.bmp| */ 442 /* format: %X|filename.bmp| */
441 backdrop_bmp_name = wps_token + 1; 443 backdrop_bmp_name = wps_bufptr + 1;
442 } 444 }
443#endif 445#endif
444 446
445 (void)wps_data; /* to avoid a warning */ 447 (void)wps_data; /* to avoid a warning */
446 448
447 /* Skip the rest of the line */ 449 /* Skip the rest of the line */
448 return skip_end_of_line(wps_token); 450 return skip_end_of_line(wps_bufptr);
449} 451}
450 452
451#endif /* HAVE_LCD_BITMAP */ 453#endif /* HAVE_LCD_BITMAP */
452 454
453static int parse_dir_level(const char *wps_token, struct wps_data *wps_data) 455static int parse_dir_level(const char *wps_bufptr, struct wps_data *wps_data)
454{ 456{
455 char val[] = { *wps_token, '\0' }; 457 char val[] = { *wps_bufptr, '\0' };
456 wps_data->tokens[wps_data->num_tokens].value.i = atoi(val); 458 wps_data->tokens[wps_data->num_tokens].value.i = atoi(val);
457 return 1; 459 return 1;
458} 460}
459 461
460static int parse_subline_timeout(const char *wps_token, struct wps_data *wps_data) 462static int parse_subline_timeout(const char *wps_bufptr, struct wps_data *wps_data)
461{ 463{
462 int skip = 0; 464 int skip = 0;
463 int val = 0; 465 int val = 0;
464 bool have_point = false; 466 bool have_point = false;
465 bool have_tenth = false; 467 bool have_tenth = false;
466 468
467 while ( isdigit(*wps_token) || *wps_token == '.' ) 469 while ( isdigit(*wps_bufptr) || *wps_bufptr == '.' )
468 { 470 {
469 if (*wps_token != '.') 471 if (*wps_bufptr != '.')
470 { 472 {
471 val *= 10; 473 val *= 10;
472 val += *wps_token - '0'; 474 val += *wps_bufptr - '0';
473 if (have_point) 475 if (have_point)
474 { 476 {
475 have_tenth = true; 477 have_tenth = true;
476 wps_token++; 478 wps_bufptr++;
477 skip++; 479 skip++;
478 break; 480 break;
479 } 481 }
@@ -481,7 +483,7 @@ static int parse_subline_timeout(const char *wps_token, struct wps_data *wps_dat
481 else 483 else
482 have_point = true; 484 have_point = true;
483 485
484 wps_token++; 486 wps_bufptr++;
485 skip++; 487 skip++;
486 } 488 }
487 489
@@ -492,7 +494,7 @@ static int parse_subline_timeout(const char *wps_token, struct wps_data *wps_dat
492 return skip; 494 return skip;
493} 495}
494 496
495static int parse_progressbar(const char *wps_token, struct wps_data *wps_data) 497static int parse_progressbar(const char *wps_bufptr, struct wps_data *wps_data)
496{ 498{
497#ifdef HAVE_LCD_BITMAP 499#ifdef HAVE_LCD_BITMAP
498 500
@@ -509,8 +511,8 @@ static int parse_progressbar(const char *wps_token, struct wps_data *wps_data)
509 wps_data->progress_top = -1; 511 wps_data->progress_top = -1;
510 512
511 int i = 0; 513 int i = 0;
512 char *newline = strchr(wps_token, '\n'); 514 char *newline = strchr(wps_bufptr, '\n');
513 char *prev = strchr(wps_token, '|'); 515 char *prev = strchr(wps_bufptr, '|');
514 if (prev && prev < newline) { 516 if (prev && prev < newline) {
515 char *next = strchr(prev+1, '|'); 517 char *next = strchr(prev+1, '|');
516 while (i < 4 && next && next < newline) 518 while (i < 4 && next && next < newline)
@@ -526,11 +528,11 @@ static int parse_progressbar(const char *wps_token, struct wps_data *wps_data)
526 wps_data->progress_end = 0; 528 wps_data->progress_end = 0;
527 } 529 }
528 530
529 return newline - wps_token; 531 return newline - wps_bufptr;
530 532
531#else 533#else
532 534
533 if (*(wps_token-1) == 'f') 535 if (*(wps_bufptr-1) == 'f')
534 wps_data->full_line_progressbar = true; 536 wps_data->full_line_progressbar = true;
535 else 537 else
536 wps_data->full_line_progressbar = false; 538 wps_data->full_line_progressbar = false;
@@ -541,14 +543,14 @@ static int parse_progressbar(const char *wps_token, struct wps_data *wps_data)
541} 543}
542 544
543/* Parse a generic token from the given string. Return the length read */ 545/* Parse a generic token from the given string. Return the length read */
544static int parse_token(const char *wps_token, struct wps_data *wps_data) 546static int parse_token(const char *wps_bufptr, struct wps_data *wps_data)
545{ 547{
546 int skip = 0, taglen = 0; 548 int skip = 0, taglen = 0;
547 int i = 0; 549 int i = 0;
548 int line = wps_data->num_lines; 550 int line = wps_data->num_lines;
549 int subline = wps_data->num_sublines[line]; 551 int subline = wps_data->num_sublines[line];
550 552
551 switch(*wps_token) 553 switch(*wps_bufptr)
552 { 554 {
553 555
554 case '%': 556 case '%':
@@ -558,7 +560,7 @@ static int parse_token(const char *wps_token, struct wps_data *wps_data)
558 case ';': 560 case ';':
559 /* escaped characters */ 561 /* escaped characters */
560 wps_data->tokens[wps_data->num_tokens].type = WPS_TOKEN_CHARACTER; 562 wps_data->tokens[wps_data->num_tokens].type = WPS_TOKEN_CHARACTER;
561 wps_data->tokens[wps_data->num_tokens].value.c = *wps_token; 563 wps_data->tokens[wps_data->num_tokens].value.c = *wps_bufptr;
562 wps_data->num_tokens++; 564 wps_data->num_tokens++;
563 skip++; 565 skip++;
564 break; 566 break;
@@ -570,14 +572,14 @@ static int parse_token(const char *wps_token, struct wps_data *wps_data)
570 condindex[level] = wps_data->num_tokens; 572 condindex[level] = wps_data->num_tokens;
571 numoptions[level] = 1; 573 numoptions[level] = 1;
572 wps_data->num_tokens++; 574 wps_data->num_tokens++;
573 wps_token++; 575 wps_bufptr++;
574 skip++; 576 skip++;
575 /* no "break" because a '?' is followed by a regular tag */ 577 /* no "break" because a '?' is followed by a regular tag */
576 578
577 default: 579 default:
578 /* find what tag we have */ 580 /* find what tag we have */
579 while (all_tags[i].name && 581 while (all_tags[i].name &&
580 strncmp(wps_token, all_tags[i].name, strlen(all_tags[i].name))) 582 strncmp(wps_bufptr, all_tags[i].name, strlen(all_tags[i].name)))
581 i++; 583 i++;
582 584
583 taglen = strlen(all_tags[i].name); 585 taglen = strlen(all_tags[i].name);
@@ -586,7 +588,7 @@ static int parse_token(const char *wps_token, struct wps_data *wps_data)
586 588
587 /* if the tag has a special parsing function, we call it */ 589 /* if the tag has a special parsing function, we call it */
588 if (all_tags[i].parse_func) 590 if (all_tags[i].parse_func)
589 skip += all_tags[i].parse_func(wps_token + taglen, wps_data); 591 skip += all_tags[i].parse_func(wps_bufptr + taglen, wps_data);
590 592
591 /* Some tags we don't want to save as tokens */ 593 /* Some tags we don't want to save as tokens */
592 if (all_tags[i].type == WPS_NO_TOKEN) 594 if (all_tags[i].type == WPS_NO_TOKEN)
@@ -605,24 +607,24 @@ static int parse_token(const char *wps_token, struct wps_data *wps_data)
605 return skip; 607 return skip;
606} 608}
607 609
608static bool wps_parse(struct wps_data *data, const char *wps_buffer) 610static bool wps_parse(struct wps_data *data, const char *wps_bufptr)
609{ 611{
610 if (!data || !wps_buffer || !*wps_buffer) 612 if (!data || !wps_bufptr || !*wps_bufptr)
611 return false; 613 return false;
612 614
613 int subline; 615 int subline;
614 data->num_tokens = 0; 616 data->num_tokens = 0;
615 char *current_string = data->string_buffer; 617 char *current_string = data->string_buffer;
616 618
617 while(wps_buffer && *wps_buffer && data->num_tokens < WPS_MAX_TOKENS 619 while(wps_bufptr && *wps_bufptr && data->num_tokens < WPS_MAX_TOKENS
618 && data->num_lines < WPS_MAX_LINES) 620 && data->num_lines < WPS_MAX_LINES)
619 { 621 {
620 switch(*wps_buffer++) 622 switch(*wps_bufptr++)
621 { 623 {
622 624
623 /* Regular tag */ 625 /* Regular tag */
624 case '%': 626 case '%':
625 wps_buffer += parse_token(wps_buffer, data); 627 wps_bufptr += parse_token(wps_bufptr, data);
626 break; 628 break;
627 629
628 /* Alternating sublines separator */ 630 /* Alternating sublines separator */
@@ -634,7 +636,7 @@ static bool wps_parse(struct wps_data *data, const char *wps_buffer)
634 data->format_lines[data->num_lines][subline] = data->num_tokens; 636 data->format_lines[data->num_lines][subline] = data->num_tokens;
635 } 637 }
636 else 638 else
637 wps_buffer += skip_end_of_line(wps_buffer); 639 wps_bufptr += skip_end_of_line(wps_bufptr);
638 640
639 break; 641 break;
640 642
@@ -678,7 +680,7 @@ condlistend: /* close a conditional. sometimes we want to close them even when
678 680
679 /* Comment */ 681 /* Comment */
680 case '#': 682 case '#':
681 wps_buffer += skip_end_of_line(wps_buffer); 683 wps_bufptr += skip_end_of_line(wps_bufptr);
682 break; 684 break;
683 685
684 /* End of this line */ 686 /* End of this line */
@@ -687,7 +689,7 @@ condlistend: /* close a conditional. sometimes we want to close them even when
687 { 689 {
688 /* We have unclosed conditionals, so we 690 /* We have unclosed conditionals, so we
689 close them before adding the EOL token */ 691 close them before adding the EOL token */
690 wps_buffer--; 692 wps_bufptr--;
691 goto condlistend; 693 goto condlistend;
692 break; 694 break;
693 } 695 }
@@ -712,15 +714,15 @@ condlistend: /* close a conditional. sometimes we want to close them even when
712 data->num_tokens++; 714 data->num_tokens++;
713 715
714 /* Copy the first byte */ 716 /* Copy the first byte */
715 *current_string++ = *(wps_buffer - 1); 717 *current_string++ = *(wps_bufptr - 1);
716 718
717 /* continue until we hit something that ends the string */ 719 /* continue until we hit something that ends the string */
718 while(wps_buffer && 720 while(wps_bufptr &&
719 *wps_buffer != '%' && //*wps_buffer != '#' && 721 *wps_bufptr != '%' && *wps_bufptr != ';' &&
720 *wps_buffer != '<' && *wps_buffer != '>' && 722 *wps_bufptr != '<' && *wps_bufptr != '>' &&
721 *wps_buffer != '|' && *wps_buffer != '\n') 723 *wps_bufptr != '|' && *wps_bufptr != '\n')
722 { 724 {
723 *current_string++ = *wps_buffer++; 725 *current_string++ = *wps_bufptr++;
724 } 726 }
725 727
726 /* null terminate the string */ 728 /* null terminate the string */