Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

sbtools: factor code in command parser

Change-Id: I790c373b8a0319cdb00650d3c59919bd4b0b96f6

+19 -83
+19 -83
utils/imxtools/sbtools/dbparser.c
··· 582 582 583 583 /* add initial constants */ 584 584 for(int i = 0; i < NR_INITIAL_CONSTANTS; i++) 585 - { 586 - struct cmd_option_t *opt = xmalloc(sizeof(struct cmd_option_t)); 587 - memset(opt, 0, sizeof(struct cmd_option_t)); 588 - opt->name = strdup(init_const_name[i]); 589 - opt->is_string = false; 590 - opt->val = init_const_value[i]; 591 - opt->next = cmd_file->constant_list; 592 - cmd_file->constant_list = opt; 593 - } 585 + db_add_int_opt(&cmd_file->constant_list, init_const_name[i], init_const_value[i]); 594 586 595 587 struct lex_ctx_t lctx; 596 588 lctx.ctx.file = file; ··· 611 603 612 604 while(true) 613 605 { 614 - struct cmd_option_t *opt = xmalloc(sizeof(struct cmd_option_t)); 615 - memset(opt, 0, sizeof(struct cmd_option_t)); 616 606 next(true); 617 607 if(lexem.type == LEX_RBRACE) 618 608 break; 619 609 if(lexem.type != LEX_IDENTIFIER) 620 610 parse_error(lexem, "Identifier expected in constants\n"); 621 - opt->name = lexem.str; 611 + const char *name = lexem.str; 622 612 next(false); /* lexem string is kept as option name */ 623 613 if(lexem.type != LEX_EQUAL) 624 614 parse_error(lexem, "'=' expected after identifier\n"); 625 615 next(true); 626 - opt->is_string = false; 627 - opt->val = parse_intexpr(&lctx, cmd_file->constant_list); 628 - opt->next = cmd_file->constant_list; 629 - cmd_file->constant_list = opt; 616 + db_add_int_opt(&cmd_file->constant_list, name, parse_intexpr(&lctx, cmd_file->constant_list)); 630 617 if(lexem.type != LEX_SEMICOLON) 631 618 parse_error(lexem, "';' expected after string\n"); 632 619 } ··· 644 631 next(true); 645 632 if(lexem.type == LEX_RBRACE) 646 633 break; 647 - struct cmd_option_t *opt = xmalloc(sizeof(struct cmd_option_t)); 648 - memset(opt, 0, sizeof(struct cmd_option_t)); 649 634 if(lexem.type != LEX_IDENTIFIER) 650 635 parse_error(lexem, "Identifier expected in options\n"); 651 - opt->name = lexem.str; 636 + const char *name = lexem.str; 652 637 next(false); /* lexem string is kept as option name */ 653 638 if(lexem.type != LEX_EQUAL) 654 639 parse_error(lexem, "'=' expected after identifier\n"); 655 640 next(true); 656 641 if(lexem.type == LEX_STRING) 657 642 { 658 - opt->is_string = true; 659 - opt->str = lexem.str; 660 - next(false); /* lexem string is kept as option name */ 643 + db_add_str_opt(&cmd_file->opt_list, name, lexem.str); 644 + next(true); 661 645 } 662 646 else 663 - { 664 - opt->is_string = false; 665 - opt->val = parse_intexpr(&lctx, cmd_file->constant_list); 666 - } 667 - opt->next = cmd_file->opt_list; 668 - cmd_file->opt_list = opt; 647 + db_add_int_opt(&cmd_file->opt_list, name, parse_intexpr(&lctx, cmd_file->constant_list)); 669 648 if(lexem.type != LEX_SEMICOLON) 670 649 parse_error(lexem, "';' expected after string\n"); 671 650 } ··· 683 662 next(true); 684 663 if(lexem.type == LEX_RBRACE) 685 664 break; 686 - struct cmd_source_t *src = xmalloc(sizeof(struct cmd_source_t)); 687 - memset(src, 0, sizeof(struct cmd_source_t)); 688 665 if(lexem.type != LEX_IDENTIFIER) 689 666 parse_error(lexem, "identifier expected in sources\n"); 690 - src->identifier = lexem.str; 667 + const char *srcid = lexem.str; 668 + if(db_find_source_by_id(cmd_file, srcid) != NULL) 669 + parse_error(lexem, "Duplicate source identifier\n"); 691 670 next(false); /* lexem string is kept as source name */ 692 671 if(lexem.type != LEX_EQUAL) 693 672 parse_error(lexem, "'=' expected after identifier\n"); 694 673 next(true); 695 674 if(lexem.type == LEX_STRING) 696 675 { 697 - src->is_extern = false; 698 - src->filename = lexem.str; 699 - next(false); /* lexem string is kept as file name */ 676 + db_add_source(cmd_file, srcid, lexem.str); 677 + next(true); 700 678 } 701 679 else if(lexem.type == LEX_IDENTIFIER && !strcmp(lexem.str, "extern")) 702 680 { 703 - src->is_extern = true; 704 - src->filename = strdup("<extern>"); /* duplicate because it will be free'd */ 705 681 next(true); 706 682 if(lexem.type != LEX_LPAREN) 707 683 parse_error(lexem, "'(' expected after 'extern'\n"); 708 684 next(true); 709 - src->extern_nr = parse_intexpr(&lctx, cmd_file->constant_list); 685 + db_add_extern_source(cmd_file, srcid, parse_intexpr(&lctx, cmd_file->constant_list)); 710 686 if(lexem.type != LEX_RPAREN) 711 687 parse_error(lexem, "')' expected\n"); 712 688 next(true); ··· 715 691 parse_error(lexem, "String or 'extern' expected after '='\n"); 716 692 if(lexem.type != LEX_SEMICOLON) 717 693 parse_error(lexem, "';' expected\n"); 718 - if(db_find_source_by_id(cmd_file, src->identifier) != NULL) 719 - parse_error(lexem, "Duplicate source identifier\n"); 720 - /* type filled later */ 721 - src->type = CMD_SRC_UNK; 722 - src->next = cmd_file->source_list; 723 - cmd_file->source_list = src; 724 694 } 725 695 726 696 /* sections */ 727 - struct cmd_section_t *end_sec = NULL; 728 697 while(true) 729 698 { 730 699 next(true); 731 700 if(lexem.type == LEX_EOF) 732 701 break; 733 - struct cmd_section_t *sec = xmalloc(sizeof(struct cmd_section_t)); 734 - struct cmd_inst_t *end_list = NULL; 735 - memset(sec, 0, sizeof(struct cmd_section_t)); 736 702 if(lexem.type != LEX_IDENTIFIER || strcmp(lexem.str, "section") != 0) 737 703 parse_error(lexem, "'section' expected\n"); 738 704 next(true); ··· 740 706 parse_error(lexem, "'(' expected after 'section'\n"); 741 707 next(true); 742 708 /* can be any number */ 743 - sec->identifier = parse_intexpr(&lctx, cmd_file->constant_list); 709 + struct cmd_section_t *sec = db_add_section(cmd_file, parse_intexpr(&lctx, cmd_file->constant_list), false); 744 710 /* options ? */ 745 711 if(lexem.type == LEX_SEMICOLON) 746 712 { 747 713 do 748 714 { 749 715 next(true); 750 - struct cmd_option_t *opt = xmalloc(sizeof(struct cmd_option_t)); 751 - memset(opt, 0, sizeof(struct cmd_option_t)); 752 716 if(lexem.type != LEX_IDENTIFIER) 753 717 parse_error(lexem, "Identifier expected for section option\n"); 754 - opt->name = lexem.str; 718 + const char *name = lexem.str; 755 719 next(false); /* lexem string is kept as option name */ 756 720 if(lexem.type != LEX_EQUAL) 757 721 parse_error(lexem, "'=' expected after option identifier\n"); 758 722 next(true); 759 723 if(lexem.type == LEX_STRING) 760 724 { 761 - opt->is_string = true; 762 - opt->str = lexem.str; 763 - next(false); /* lexem string is kept as option string */ 725 + db_add_str_opt(&sec->opt_list, name, lexem.str); 726 + next(true); 764 727 } 765 728 else 766 - { 767 - opt->is_string = false; 768 - opt->val = parse_intexpr(&lctx, cmd_file->constant_list); 769 - } 770 - opt->next = sec->opt_list; 771 - sec->opt_list = opt; 729 + db_add_int_opt(&sec->opt_list, name, parse_intexpr(&lctx, cmd_file->constant_list)); 772 730 }while(lexem.type == LEX_COLON); 773 731 } 774 732 if(lexem.type != LEX_RPAREN) ··· 783 741 next(true); 784 742 if(lexem.type == LEX_RBRACE) 785 743 break; 786 - struct cmd_inst_t *inst = xmalloc(sizeof(struct cmd_inst_t)); 787 - memset(inst, 0, sizeof(struct cmd_inst_t)); 744 + struct cmd_inst_t *inst = db_add_inst(&sec->inst_list, CMD_LOAD, 0); 788 745 if(lexem.type != LEX_IDENTIFIER) 789 746 parse_error(lexem, "Instruction expected in section\n"); 790 747 if(strcmp(lexem.str, "load") == 0) ··· 851 808 } 852 809 else 853 810 parse_error(lexem, "Internal error"); 854 - if(end_list == NULL) 855 - { 856 - sec->inst_list = inst; 857 - end_list = inst; 858 - } 859 - else 860 - { 861 - end_list->next = inst; 862 - end_list = inst; 863 - } 864 811 } 865 812 } 866 813 else if(lexem.type == LEX_LE) ··· 876 823 } 877 824 else 878 825 parse_error(lexem, "'{' or '<=' expected after section directive\n"); 879 - 880 - if(end_sec == NULL) 881 - { 882 - cmd_file->section_list = sec; 883 - end_sec = sec; 884 - } 885 - else 886 - { 887 - end_sec->next = sec; 888 - end_sec = sec; 889 - } 890 826 } 891 827 #undef lexem 892 828 #undef next