diff options
author | Miika Pekkarinen <miipekk@ihme.org> | 2006-10-21 20:37:33 +0000 |
---|---|---|
committer | Miika Pekkarinen <miipekk@ihme.org> | 2006-10-21 20:37:33 +0000 |
commit | a1ac7434534240f9ce88054028a77466c6e61c7c (patch) | |
tree | b2d4fc2f7d8fc0dbea12607ee93df8f2320859a7 /apps/tagtree.c | |
parent | 593b552486c6502d415f9f31fbaff871a0248cdc (diff) | |
download | rockbox-a1ac7434534240f9ce88054028a77466c6e61c7c.tar.gz rockbox-a1ac7434534240f9ce88054028a77466c6e61c7c.zip |
Implement fast_readline as a function and use it for tagtree also.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11301 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/tagtree.c')
-rw-r--r-- | apps/tagtree.c | 258 |
1 files changed, 132 insertions, 126 deletions
diff --git a/apps/tagtree.c b/apps/tagtree.c index 97339fa13a..082e10d7d9 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c | |||
@@ -42,6 +42,7 @@ | |||
42 | #include "atoi.h" | 42 | #include "atoi.h" |
43 | #include "playback.h" | 43 | #include "playback.h" |
44 | #include "yesno.h" | 44 | #include "yesno.h" |
45 | #include "misc.h" | ||
45 | 46 | ||
46 | #define FILE_SEARCH_INSTRUCTIONS ROCKBOX_DIR "/tagnavi.config" | 47 | #define FILE_SEARCH_INSTRUCTIONS ROCKBOX_DIR "/tagnavi.config" |
47 | 48 | ||
@@ -678,157 +679,162 @@ bool tagtree_import(void) | |||
678 | return false; | 679 | return false; |
679 | } | 680 | } |
680 | 681 | ||
681 | static bool parse_menu(const char *filename) | 682 | static bool parse_menu(const char *filename); |
683 | |||
684 | int parse_line(int n, const char *buf, void *parameters) | ||
682 | { | 685 | { |
683 | int fd; | ||
684 | char buf[256]; | ||
685 | char data[256]; | 686 | char data[256]; |
686 | int variable; | 687 | int variable; |
687 | int rc; | 688 | static bool read_menu; |
688 | bool first = true; | ||
689 | bool read_menu = false; | ||
690 | int i; | 689 | int i; |
691 | |||
692 | if (menu_count >= TAGMENU_MAX_MENUS) | ||
693 | { | ||
694 | logf("max menucount reached"); | ||
695 | return false; | ||
696 | } | ||
697 | 690 | ||
698 | fd = open(filename, O_RDONLY); | 691 | (void)parameters; |
699 | if (fd < 0) | ||
700 | { | ||
701 | logf("Search instruction file not found."); | ||
702 | return false; | ||
703 | } | ||
704 | 692 | ||
705 | /* Now read file for real, parsing into si */ | 693 | /* First line, do initialisation. */ |
706 | while ( 1 ) | 694 | if (n == 0) |
707 | { | 695 | { |
708 | rc = read_line(fd, buf, sizeof(buf)-1); | 696 | if (strcasecmp(TAGNAVI_VERSION, buf)) |
709 | if (rc <= 0) | ||
710 | break; | ||
711 | |||
712 | if (first) | ||
713 | { | 697 | { |
714 | if (strcasecmp(TAGNAVI_VERSION, buf)) | 698 | logf("Version mismatch"); |
715 | { | 699 | return -1; |
716 | logf("Version mismatch"); | ||
717 | break; | ||
718 | } | ||
719 | first = false; | ||
720 | } | 700 | } |
721 | 701 | ||
722 | if (buf[0] == '#') | 702 | read_menu = false; |
723 | continue; | 703 | } |
724 | 704 | ||
725 | if (buf[0] == '\0') | 705 | if (buf[0] == '#') |
706 | return 0; | ||
707 | |||
708 | if (buf[0] == '\0') | ||
709 | { | ||
710 | if (read_menu) | ||
726 | { | 711 | { |
727 | if (read_menu) | 712 | /* End the menu */ |
728 | { | 713 | menu_count++; |
729 | /* End the menu */ | 714 | read_menu = false; |
730 | menu_count++; | ||
731 | read_menu = false; | ||
732 | } | ||
733 | continue; | ||
734 | } | 715 | } |
716 | return 0; | ||
717 | } | ||
718 | |||
719 | if (!read_menu) | ||
720 | { | ||
721 | strp = buf; | ||
722 | if (get_tag(&variable) <= 0) | ||
723 | return 0; | ||
735 | 724 | ||
736 | if (!read_menu) | 725 | switch (variable) |
737 | { | 726 | { |
738 | strp = buf; | 727 | case var_format: |
739 | if (get_tag(&variable) <= 0) | 728 | if (add_format(strp) < 0) |
740 | continue; | 729 | { |
730 | logf("Format add fail: %s", data); | ||
731 | } | ||
732 | break; | ||
733 | |||
734 | case var_include: | ||
735 | if (get_token_str(data, sizeof(data)) < 0) | ||
736 | { | ||
737 | logf("%include empty"); | ||
738 | return false; | ||
739 | } | ||
741 | 740 | ||
742 | switch (variable) | 741 | if (!parse_menu(data)) |
743 | { | 742 | { |
744 | case var_format: | 743 | logf("Load menu fail: %s", data); |
745 | if (add_format(strp) < 0) | 744 | } |
746 | { | 745 | break; |
747 | logf("Format add fail: %s", data); | ||
748 | } | ||
749 | break; | ||
750 | 746 | ||
751 | case var_include: | 747 | case var_menu_start: |
752 | if (get_token_str(data, sizeof(data)) < 0) | 748 | if (menu_count >= TAGMENU_MAX_MENUS) |
753 | { | 749 | { |
754 | logf("%include empty"); | 750 | logf("max menucount reached"); |
755 | return false; | 751 | return false; |
756 | } | 752 | } |
757 | 753 | ||
758 | if (!parse_menu(data)) | 754 | menus[menu_count] = buffer_alloc(sizeof(struct root_menu)); |
759 | { | 755 | menu = menus[menu_count]; |
760 | logf("Load menu fail: %s", data); | 756 | memset(menu, 0, sizeof(struct root_menu)); |
761 | } | 757 | if (get_token_str(menu->id, sizeof(menu->id)) < 0) |
762 | break; | 758 | { |
759 | logf("%menu_start id empty"); | ||
760 | return false; | ||
761 | } | ||
762 | if (get_token_str(menu->title, sizeof(menu->title)) < 0) | ||
763 | { | ||
764 | logf("%menu_start title empty"); | ||
765 | return false; | ||
766 | } | ||
767 | menu->itemcount = 0; | ||
768 | read_menu = true; | ||
769 | break; | ||
763 | 770 | ||
764 | case var_menu_start: | 771 | case var_rootmenu: |
765 | if (menu_count >= TAGMENU_MAX_MENUS) | 772 | /* Only set root menu once. */ |
766 | { | 773 | if (root_menu) |
767 | logf("max menucount reached"); | ||
768 | return false; | ||
769 | } | ||
770 | |||
771 | menus[menu_count] = buffer_alloc(sizeof(struct root_menu)); | ||
772 | menu = menus[menu_count]; | ||
773 | memset(menu, 0, sizeof(struct root_menu)); | ||
774 | if (get_token_str(menu->id, sizeof(menu->id)) < 0) | ||
775 | { | ||
776 | logf("%menu_start id empty"); | ||
777 | return false; | ||
778 | } | ||
779 | if (get_token_str(menu->title, sizeof(menu->title)) < 0) | ||
780 | { | ||
781 | logf("%menu_start title empty"); | ||
782 | return false; | ||
783 | } | ||
784 | menu->itemcount = 0; | ||
785 | read_menu = true; | ||
786 | break; | 774 | break; |
787 | 775 | ||
788 | case var_rootmenu: | 776 | if (get_token_str(data, sizeof(data)) < 0) |
789 | /* Only set root menu once. */ | 777 | { |
790 | if (root_menu) | 778 | logf("%root_menu empty"); |
791 | break; | 779 | return false; |
792 | 780 | } | |
793 | if (get_token_str(data, sizeof(data)) < 0) | ||
794 | { | ||
795 | logf("%root_menu empty"); | ||
796 | return false; | ||
797 | } | ||
798 | 781 | ||
799 | for (i = 0; i < menu_count; i++) | 782 | for (i = 0; i < menu_count; i++) |
783 | { | ||
784 | if (!strcasecmp(menus[i]->id, data)) | ||
800 | { | 785 | { |
801 | if (!strcasecmp(menus[i]->id, data)) | 786 | root_menu = i; |
802 | { | ||
803 | root_menu = i; | ||
804 | } | ||
805 | } | 787 | } |
806 | break; | 788 | } |
807 | } | 789 | break; |
808 | |||
809 | continue; | ||
810 | } | ||
811 | |||
812 | if (menu->itemcount >= TAGMENU_MAX_ITEMS) | ||
813 | { | ||
814 | logf("max itemcount reached"); | ||
815 | continue; | ||
816 | } | ||
817 | |||
818 | /* Allocate */ | ||
819 | if (menu->items[menu->itemcount] == NULL) | ||
820 | { | ||
821 | menu->items[menu->itemcount] = buffer_alloc(sizeof(struct menu_entry)); | ||
822 | memset(menu->items[menu->itemcount], 0, sizeof(struct menu_entry)); | ||
823 | menu->items[menu->itemcount]->si = buffer_alloc(sizeof(struct search_instruction)); | ||
824 | } | 790 | } |
825 | 791 | ||
826 | memset(menu->items[menu->itemcount]->si, 0, sizeof(struct search_instruction)); | 792 | return 0; |
827 | if (!parse_search(menu->items[menu->itemcount], buf)) | ||
828 | continue; | ||
829 | |||
830 | menu->itemcount++; | ||
831 | } | 793 | } |
794 | |||
795 | if (menu->itemcount >= TAGMENU_MAX_ITEMS) | ||
796 | { | ||
797 | logf("max itemcount reached"); | ||
798 | return 0; | ||
799 | } | ||
800 | |||
801 | /* Allocate */ | ||
802 | if (menu->items[menu->itemcount] == NULL) | ||
803 | { | ||
804 | menu->items[menu->itemcount] = buffer_alloc(sizeof(struct menu_entry)); | ||
805 | memset(menu->items[menu->itemcount], 0, sizeof(struct menu_entry)); | ||
806 | menu->items[menu->itemcount]->si = buffer_alloc(sizeof(struct search_instruction)); | ||
807 | } | ||
808 | |||
809 | memset(menu->items[menu->itemcount]->si, 0, sizeof(struct search_instruction)); | ||
810 | if (!parse_search(menu->items[menu->itemcount], buf)) | ||
811 | return 0; | ||
812 | |||
813 | menu->itemcount++; | ||
814 | |||
815 | return 0; | ||
816 | } | ||
817 | |||
818 | static bool parse_menu(const char *filename) | ||
819 | { | ||
820 | int fd; | ||
821 | char buf[256]; | ||
822 | |||
823 | if (menu_count >= TAGMENU_MAX_MENUS) | ||
824 | { | ||
825 | logf("max menucount reached"); | ||
826 | return false; | ||
827 | } | ||
828 | |||
829 | fd = open(filename, O_RDONLY); | ||
830 | if (fd < 0) | ||
831 | { | ||
832 | logf("Search instruction file not found."); | ||
833 | return false; | ||
834 | } | ||
835 | |||
836 | /* Now read file for real, parsing into si */ | ||
837 | fast_readline(fd, buf, sizeof buf, NULL, parse_line); | ||
832 | close(fd); | 838 | close(fd); |
833 | 839 | ||
834 | return true; | 840 | return true; |