Changeset 2744eec in rtems
- Timestamp:
- 10/31/97 19:44:23 (25 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- f70c6adc
- Parents:
- 5a5bd13b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/tools/bmenu/main.c
r5a5bd13b r2744eec 34 34 char *DocsPreviousNode; 35 35 char *DocsUpNode; 36 int NodeNameIncludesChapter = 1; 36 37 37 38 extern int optind; /* Why is this not in <stdlib.h>? */ … … 59 60 char *Usage_Strings[] = { 60 61 "\n", 61 "usage: cmd [- bv] [-p prev] [-n next] [-u up] files ...\n",62 "usage: cmd [-cv] [-p prev] [-n next] [-u up] files ...\n", 62 63 "\n", 63 64 "EOF" … … 84 85 */ 85 86 86 #define TEXT 0 87 #define SECTION 1 88 #define SUBSECTION 2 89 #define HEADING 3 87 #define TEXT 0 88 #define SECTION 1 89 #define SUBSECTION 2 90 #define SUBSUBSECTION 3 91 #define HEADING 4 90 92 91 93 typedef enum { … … 95 97 KEYWORD_SECTION, 96 98 KEYWORD_SUBSECTION, 99 KEYWORD_SUBSUBSECTION, 100 KEYWORD_RAISE, 101 KEYWORD_LOWER, 97 102 KEYWORD_OTHER, 98 103 KEYWORD_END … … 118 123 ExtraFormat_info_t format; 119 124 int number; 125 int level; 120 126 char Contents[ PARAGRAPH_SIZE ]; 121 127 } Line_Control; … … 149 155 150 156 Keyword_info_t Keywords[] = { 151 { "unused", 152 0, 0, 0, NULL }, /* so 0 can be invalid */ 153 { "@chapter", SECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 154 { "@chapheading",SECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 155 { "@section", SECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 156 { "@subsection", SUBSECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 157 { "", HEADING, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 158 { "END OF FILE", SECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL } 157 { "unused", 0, 0, 0, NULL }, /* so 0 can be invalid */ 158 { "@chapter", SECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 159 { "@chapheading", SECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 160 { "@section", SECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 161 { "@subsection", SUBSECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 162 { "@subsubsection", SUBSUBSECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 163 { "@raise", SUBSECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 164 { "@lower", SUBSECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 165 { "", HEADING, RT_FORBIDDEN, BL_FORBIDDEN, NULL }, 166 { "END OF FILE", SECTION, RT_FORBIDDEN, BL_FORBIDDEN, NULL } 159 167 }; 160 168 … … 207 215 fprintf( 208 216 stderr, 209 "<%d,%d >:%s\n",217 "<%d,%d,%d>:%s\n", 210 218 line->keyword, 211 219 line->format, 220 line->level, 212 221 line->Contents 213 222 ); … … 260 269 */ 261 270 new_line->number = -1; 271 new_line->level = -1; 262 272 263 273 new_line->keyword = UNUSED; … … 425 435 DocsUpNode = TopString; 426 436 427 while ((c = getopt(argc, argv, "v p:n:u:")) != EOF) {437 while ((c = getopt(argc, argv, "vcp:n:u:")) != EOF) { 428 438 switch (c) { 429 439 case 'v': 430 440 Verbose = TRUE; 441 break; 442 case 'c': 443 NodeNameIncludesChapter = 0; 431 444 break; 432 445 case 'p': … … 634 647 else if ( strstr( line->Contents, "@subsection" ) ) 635 648 line->keyword = KEYWORD_SUBSECTION; 649 else if ( strstr( line->Contents, "@subsubsection" ) ) 650 line->keyword = KEYWORD_SUBSUBSECTION; 651 else if ( strstr( line->Contents, "@raise" ) ) 652 line->keyword = KEYWORD_RAISE; 653 else if ( strstr( line->Contents, "@lower" ) ) 654 line->keyword = KEYWORD_LOWER; 636 655 else 637 656 line->keyword = KEYWORD_OTHER; … … 666 685 void BuildTexinfoNodes( void ) 667 686 { 687 char Buffer[ BUFFER_SIZE ]; 688 Line_Control *line; 689 Line_Control *next_node; 690 Line_Control *up_node; 691 Line_Control *new_line; 692 Line_Control *menu_insert_point; 693 Line_Control *node_line; 694 int next_found; 695 int menu_items; 696 Keyword_indices_t index; 697 char ChapterName[ BUFFER_SIZE ]; 698 char NodeName[ BUFFER_SIZE ]; 699 char UpNodeName[ BUFFER_SIZE ]; 700 char NextNodeName[ BUFFER_SIZE ]; 701 char PreviousNodeName[ BUFFER_SIZE ]; 702 703 /* 704 * Set Initial Previous Node Name 705 */ 706 707 strcpy( PreviousNodeName, DocsPreviousNode ); 708 709 for ( line = (Line_Control *) Lines.first ; 710 !_Chain_Is_last( &line->Node ) ; 711 line = (Line_Control *) line->Node.next 712 ) { 713 714 if ( line->level == -1 ) 715 continue; 716 717 LineCopyFromRight( line, NodeName ); 718 719 if ( line->keyword == KEYWORD_CHAPTER || 720 line->keyword == KEYWORD_CHAPHEADING ) { 721 722 strcpy( ChapterName, NodeName ); 723 724 } 725 726 /* 727 * Set Default Next Node Name 728 */ 729 730 next_found = FALSE; 731 strcpy( NextNodeName, DocsNextNode ); 732 733 /* 734 * Go ahead and put it on the chain in the right order (ahead of 735 * the menu) and we can fill it in later (after the menu is built). 736 */ 737 738 new_line = AllocateLine(); 739 strcpy( new_line->Contents, "@ifinfo" ); 740 _Chain_Insert( line->Node.previous, &new_line->Node ); 741 742 node_line = AllocateLine(); 743 _Chain_Insert( line->Node.previous, &node_line->Node ); 744 745 new_line = AllocateLine(); 746 strcpy( new_line->Contents, "@end ifinfo" ); 747 _Chain_Insert( line->Node.previous, &new_line->Node ); 748 749 next_node = (Line_Control *) line->Node.next; 750 menu_insert_point = next_node; 751 menu_items = 0; 752 753 for ( ; ; ) { 754 if ( next_node->keyword == KEYWORD_END ) 755 break; 756 757 if ( next_node->level == -1 ) 758 goto continue_menu_loop; 759 760 LineCopySectionName( next_node, Buffer ); 761 if ( !next_found ) { 762 next_found = TRUE; 763 if (NodeNameIncludesChapter) 764 sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); 765 else 766 sprintf( NextNodeName, "%s", Buffer ); 767 } 768 769 if ( next_node->level <= line->level ) 770 break; 771 772 if ( next_node->level != (line->level + 1) ) 773 goto continue_menu_loop; 774 775 if ( menu_items == 0 ) { 776 new_line = AllocateLine(); 777 strcpy( new_line->Contents, "@ifinfo" ); 778 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 779 780 new_line = AllocateLine(); 781 strcpy( new_line->Contents, "@menu" ); 782 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 783 } 784 785 menu_items++; 786 787 new_line = AllocateLine(); 788 if (NodeNameIncludesChapter) 789 sprintf( new_line->Contents, "* %s %s::", ChapterName, Buffer ); 790 else 791 sprintf( new_line->Contents, "* %s::", Buffer ); 792 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 793 794 continue_menu_loop: 795 next_node = (Line_Control *) next_node->Node.next; 796 } 797 798 /* 799 * If menu items were generated, then insert the end of menu stuff. 800 */ 801 802 if ( menu_items ) { 803 new_line = AllocateLine(); 804 strcpy( new_line->Contents, "@end menu" ); 805 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 806 807 new_line = AllocateLine(); 808 strcpy( new_line->Contents, "@end ifinfo" ); 809 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 810 } 811 812 /* 813 * Find the UpNodeName 814 */ 815 816 /* DumpList( &Lines ); */ 817 818 if ( line->level == 0 ) { 819 strcpy( UpNodeName, DocsUpNode ); 820 } else { 821 for ( up_node = line; 822 up_node && !_Chain_Is_first((Chain_Node *)up_node) ; 823 up_node = (Line_Control *) up_node->Node.previous 824 ) { 825 826 if ( (up_node->level == -1) ) 827 continue; 828 829 if ( up_node->level == (line->level - 1) ) { 830 LineCopySectionName( up_node, Buffer ); 831 if (NodeNameIncludesChapter) 832 sprintf( UpNodeName, "%s %s", ChapterName, Buffer ); 833 else 834 sprintf( UpNodeName, "%s", Buffer ); 835 break; 836 } 837 } 838 } 839 840 /* 841 * Update the node information 842 */ 843 844 #if 0 845 fprintf( 846 stderr, 847 "@node %s, %s, %s, %s\n", 848 NodeName, 849 NextNodeName, 850 PreviousNodeName, 851 UpNodeName 852 ); 853 #endif 854 855 /* node_line was previously inserted */ 856 sprintf( 857 node_line->Contents, 858 "@node %s, %s, %s, %s", 859 NodeName, 860 NextNodeName, 861 PreviousNodeName, 862 UpNodeName 863 ); 864 865 strcpy( PreviousNodeName, NodeName ); 866 867 /* PrintLine( line ); */ 868 } 869 } 870 871 /* 872 * FormatToTexinfo 873 */ 874 875 void FormatToTexinfo( void ) 876 { 668 877 Line_Control *line; 669 Line_Control *new_line; 670 Line_Control *next_node; 671 char Buffer[ BUFFER_SIZE ]; 672 char ChapterName[ BUFFER_SIZE ]; 673 char NodeName[ BUFFER_SIZE ]; 674 char NextNode[ BUFFER_SIZE ]; 675 char NextNodeName[ BUFFER_SIZE ]; 676 char PreviousNodeName[ BUFFER_SIZE ]; 677 char UpNodeName[ BUFFER_SIZE ]; 678 char SectionName[ BUFFER_SIZE ]; 679 char MenuBuffer[ BUFFER_SIZE ]; 680 Line_Control *node_insert_point; 681 Line_Control *menu_insert_point; 682 Line_Control *node_line; 683 boolean next_found; 684 int menu_items; 685 686 strcpy( PreviousNodeName, DocsPreviousNode ); 878 int baselevel = 0; 879 int currentlevel; 880 881 if ( Verbose ) 882 fprintf( stderr, "-------->INSERTING TEXINFO MENUS\n" ); 687 883 688 884 for ( line = (Line_Control *) Lines.first ; 689 885 !_Chain_Is_last( &line->Node ) ; 690 line = (Line_Control *) line->Node.next 691 ) { 692 693 menu_insert_point = (Line_Control *) line->Node.next; 694 695 switch ( Keywords[ line->keyword ].level ) { 696 case TEXT: 697 case HEADING: 698 break; 699 case SECTION: 700 if ( line->keyword == KEYWORD_END ) 701 goto bottom; 702 703 if ( line->keyword == KEYWORD_CHAPTER || 704 line->keyword == KEYWORD_CHAPHEADING ) { 705 LineCopyFromRight( line, ChapterName ); 706 strcpy( UpNodeName, DocsUpNode ); 707 strcpy( NodeName, ChapterName ); 708 } else { 709 LineCopySectionName( line, Buffer ); 710 sprintf( NodeName, "%s %s", ChapterName, Buffer ); 711 strcpy( UpNodeName, ChapterName ); 712 } 713 strcpy( SectionName, NodeName ); 714 715 /* 716 * Go ahead and put it on the chain in the right order (ahead of 717 * the menu) and we can fill it in later (after the menu is built). 718 */ 719 720 new_line = AllocateLine(); 721 strcpy( new_line->Contents, "@ifinfo" ); 722 _Chain_Insert( line->Node.previous, &new_line->Node ); 723 724 node_line = AllocateLine(); 725 _Chain_Insert( line->Node.previous, &node_line->Node ); 726 727 new_line = AllocateLine(); 728 strcpy( new_line->Contents, "@end ifinfo" ); 729 _Chain_Insert( line->Node.previous, &new_line->Node ); 730 731 menu_items = 0; 732 733 if ( line->keyword == KEYWORD_CHAPTER || line->keyword == KEYWORD_CHAPHEADING ) { 734 next_node = (Line_Control *) line->Node.next; 735 next_found = FALSE; 736 for ( ; ; ) { 737 if ( next_node->keyword == KEYWORD_END ) 738 break; 739 if ( Keywords[ next_node->keyword ].level == SECTION ) { 740 LineCopySectionName( next_node, Buffer ); 741 if ( !next_found ) { 742 next_found = TRUE; 743 sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); 744 } 745 746 if ( menu_items == 0 ) { 747 new_line = AllocateLine(); 748 strcpy( new_line->Contents, "@ifinfo" ); 749 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 750 751 new_line = AllocateLine(); 752 strcpy( new_line->Contents, "@menu" ); 753 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 754 } 755 756 menu_items++; 757 758 new_line = AllocateLine(); 759 sprintf( new_line->Contents, "* %s %s::", ChapterName, Buffer ); 760 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 761 } 762 next_node = (Line_Control *) next_node->Node.next; 763 } 764 } else { 765 next_node = (Line_Control *) line->Node.next; 766 767 next_found = FALSE; 768 for ( ; ; ) { 769 if ( Keywords[ next_node->keyword ].level == SECTION ) { 770 if ( !next_found ) { 771 if ( next_node->keyword == KEYWORD_END ) { 772 strcpy( NextNodeName, DocsNextNode ); 773 } else { 774 LineCopySectionName( next_node, Buffer ); 775 sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); 776 } 777 next_found = TRUE; 778 } 779 break; 780 } else if ( Keywords[ next_node->keyword ].level == SUBSECTION ) { 781 LineCopySectionName( next_node, MenuBuffer ); /* has next node */ 782 783 if ( menu_items == 0 ) { 784 new_line = AllocateLine(); 785 strcpy( new_line->Contents, "@ifinfo" ); 786 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 787 788 new_line = AllocateLine(); 789 strcpy( new_line->Contents, "@menu" ); 790 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 791 } 792 793 menu_items++; 794 795 new_line = AllocateLine(); 796 sprintf( new_line->Contents, "* %s::", MenuBuffer ); 797 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 798 799 if ( !next_found ) { 800 next_found = TRUE; 801 strcpy( NextNodeName, MenuBuffer ); 802 } 803 } 804 next_node = (Line_Control *) next_node->Node.next; 805 } 806 } 807 808 if ( menu_items ) { 809 new_line = AllocateLine(); 810 strcpy( new_line->Contents, "@end menu" ); 811 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 812 813 new_line = AllocateLine(); 814 strcpy( new_line->Contents, "@end ifinfo" ); 815 _Chain_Insert( menu_insert_point->Node.previous, &new_line->Node ); 816 } 817 #if 0 818 fprintf( 819 stderr, 820 "@node %s, %s, %s, %s\n", 821 NodeName, 822 NextNodeName, 823 PreviousNodeName, 824 UpNodeName 825 ); 826 #endif 827 /* node_line was previously inserted */ 828 sprintf( 829 node_line->Contents, 830 "@node %s, %s, %s, %s", 831 NodeName, 832 NextNodeName, 833 PreviousNodeName, 834 UpNodeName 835 ); 836 837 strcpy( PreviousNodeName, NodeName ); 838 break; 839 840 case SUBSECTION: 841 strcpy( UpNodeName, SectionName ); 842 843 LineCopyFromRight( line, NodeName ); 844 845 new_line = AllocateLine(); 846 strcpy( new_line->Contents, "@ifinfo" ); 847 _Chain_Insert( line->Node.previous, &new_line->Node ); 848 849 next_node = (Line_Control *) line->Node.next; 850 for ( ; ; ) { 851 if ( Keywords[ next_node->keyword ].level == SECTION ) { 852 if ( next_node->keyword == KEYWORD_END ) { 853 strcpy( NextNodeName, DocsNextNode ); 854 } else { 855 LineCopySectionName( next_node, Buffer ); 856 sprintf( NextNodeName, "%s %s", ChapterName, Buffer ); 857 } 858 break; 859 } else if ( Keywords[ next_node->keyword ].level == SUBSECTION ) { 860 LineCopyFromRight( next_node, NextNodeName ); 861 break; 862 } 863 next_node = (Line_Control *) next_node->Node.next; 864 } 865 866 #if 0 867 fprintf( 868 stderr, 869 "@node %s, %s, %s, %s\n", 870 NodeName, 871 NextNodeName, 872 PreviousNodeName, 873 UpNodeName 874 ); 875 #endif 876 new_line = AllocateLine(); 877 sprintf( 878 new_line->Contents, 879 "@node %s, %s, %s, %s", 880 NodeName, 881 NextNodeName, 882 PreviousNodeName, 883 UpNodeName 884 ); 885 _Chain_Insert( line->Node.previous, &new_line->Node ); 886 887 new_line = AllocateLine(); 888 strcpy( new_line->Contents, "@end ifinfo" ); 889 _Chain_Insert( line->Node.previous, &new_line->Node ); 890 891 strcpy( PreviousNodeName, NodeName ); 886 line = (Line_Control *) line->Node.next ) { 887 888 switch (line->keyword) { 889 case UNUSED: 890 case KEYWORD_OTHER: 891 case KEYWORD_END: 892 line->level = -1; 893 break; 894 case KEYWORD_CHAPTER: 895 case KEYWORD_CHAPHEADING: 896 currentlevel = 0; 897 line->level = baselevel + currentlevel; 898 break; 899 case KEYWORD_SECTION: 900 currentlevel = 1; 901 line->level = baselevel + currentlevel; 902 break; 903 case KEYWORD_SUBSECTION: 904 currentlevel = 2; 905 line->level = baselevel + currentlevel; 906 break; 907 case KEYWORD_SUBSUBSECTION: 908 currentlevel = 3; 909 line->level = baselevel + currentlevel; 910 break; 911 case KEYWORD_RAISE: 912 assert( baselevel ); 913 baselevel--; 914 line->level = -1; 915 break; 916 case KEYWORD_LOWER: 917 baselevel++; 918 line->level = -1; 892 919 break; 893 920 } 894 921 } 895 bottom:896 }897 898 /*899 * FormatToTexinfo900 */901 902 void FormatToTexinfo( void )903 {904 if ( Verbose )905 fprintf( stderr, "-------->INSERTING TEXINFO MENUS\n" );906 922 907 923 BuildTexinfoNodes(); … … 957 973 !_Chain_Is_last( &line->Node ) ; 958 974 line = (Line_Control *) line->Node.next ) { 959 fprintf( stderr, "%s\n", line->Contents ); 975 /* if (line->level != -1) */ 976 PrintLine( line ); 977 /* fprintf( stderr, "%s\n", line->Contents ); */ 960 978 } 961 979 }
Note: See TracChangeset
for help on using the changeset viewer.