src/mess/tools/messdocs/messdocs.c
| r11059 | r11060 | |
| 15 | 15 | |
| 16 | 16 | struct messdocs_state |
| 17 | 17 | { |
| 18 | | const char *dest_dir; |
| 18 | const char *m_dest_dir; |
| 19 | 19 | |
| 20 | | const char *title; |
| 21 | | const char *default_topic; |
| 20 | const char *m_title; |
| 21 | const char *m_default_topic; |
| 22 | 22 | |
| 23 | | object_pool *pool; |
| 24 | | XML_Parser parser; |
| 25 | | int depth; |
| 26 | | int error; |
| 27 | | char *toc_dir; |
| 28 | | FILE *chm_toc; |
| 23 | object_pool *m_pool; |
| 24 | XML_Parser m_parser; |
| 25 | int m_depth; |
| 26 | int m_error; |
| 27 | char *m_toc_dir; |
| 28 | FILE *m_chm_toc; |
| 29 | 29 | }; |
| 30 | 30 | |
| 31 | 31 | |
| r11059 | r11060 | |
| 639 | 639 | XML_Memory_Handling_Suite memcallbacks; |
| 640 | 640 | |
| 641 | 641 | memset(&state, 0, sizeof(state)); |
| 642 | | state.pool = pool_alloc_lib(NULL); |
| 642 | state.m_pool = pool_alloc_lib(NULL); |
| 643 | 643 | |
| 644 | 644 | /* open the DOC */ |
| 645 | 645 | in = fopen(toc_filename, "r"); |
| r11059 | r11060 | |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | /* figure out the TOC directory */ |
| 653 | | state.toc_dir = pool_strdup_lib(state.pool, toc_filename); |
| 654 | | if (!state.toc_dir) |
| 653 | state.m_toc_dir = pool_strdup_lib(state.m_pool, toc_filename); |
| 654 | if (!state.m_toc_dir) |
| 655 | 655 | goto outofmemory; |
| 656 | | for (i = strlen(state.toc_dir) - 1; (i > 0) && !osd_is_path_separator(state.toc_dir[i]); i--) |
| 657 | | state.toc_dir[i] = '\0'; |
| 656 | for (i = strlen(state.m_toc_dir) - 1; (i > 0) && !osd_is_path_separator(state.m_toc_dir[i]); i--) |
| 657 | state.m_toc_dir[i] = '\0'; |
| 658 | 658 | |
| 659 | 659 | /* clean the target directory */ |
| 660 | 660 | rmdir_recursive(dest_dir); |
| 661 | 661 | osd_mkdir(dest_dir); |
| 662 | 662 | |
| 663 | 663 | /* create the help contents file */ |
| 664 | | s = (char*)pool_malloc_lib(state.pool, strlen(dest_dir) + 1 + strlen(help_project_filename) + 1); |
| 664 | s = (char*)pool_malloc_lib(state.m_pool, strlen(dest_dir) + 1 + strlen(help_project_filename) + 1); |
| 665 | 665 | if (!s) |
| 666 | 666 | goto outofmemory; |
| 667 | 667 | strcpy(s, dest_dir); |
| 668 | 668 | strcat(s, PATH_SEPARATOR); |
| 669 | 669 | strcat(s, help_contents_filename); |
| 670 | | state.chm_toc = fopen(s, "w"); |
| 671 | | state.dest_dir = dest_dir; |
| 672 | | if (!state.chm_toc) |
| 670 | state.m_chm_toc = fopen(s, "w"); |
| 671 | state.m_dest_dir = dest_dir; |
| 672 | if (!state.m_chm_toc) |
| 673 | 673 | { |
| 674 | 674 | fprintf(stderr, "Cannot open file %s\n", s); |
| 675 | 675 | goto error; |
| 676 | 676 | } |
| 677 | 677 | |
| 678 | | fprintf(state.chm_toc, "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\"\n"); |
| 679 | | fprintf(state.chm_toc, "<HTML>\n"); |
| 680 | | fprintf(state.chm_toc, "<HEAD>\n"); |
| 681 | | fprintf(state.chm_toc, "</HEAD>\n"); |
| 682 | | fprintf(state.chm_toc, "<BODY>\n"); |
| 683 | | fprintf(state.chm_toc, "<OBJECT type=\"text/site properties\">\n"); |
| 684 | | fprintf(state.chm_toc, "\t<param name=\"Window Styles\" value=\"0x800625\">\n"); |
| 685 | | fprintf(state.chm_toc, "\t<param name=\"ImageType\" value=\"Folder\">\n"); |
| 686 | | fprintf(state.chm_toc, "\t<param name=\"Font\" value=\"Arial,8,0\">\n"); |
| 687 | | fprintf(state.chm_toc, "</OBJECT>\n"); |
| 688 | | fprintf(state.chm_toc, "<UL>\n"); |
| 678 | fprintf(state.m_chm_toc, "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\"\n"); |
| 679 | fprintf(state.m_chm_toc, "<HTML>\n"); |
| 680 | fprintf(state.m_chm_toc, "<HEAD>\n"); |
| 681 | fprintf(state.m_chm_toc, "</HEAD>\n"); |
| 682 | fprintf(state.m_chm_toc, "<BODY>\n"); |
| 683 | fprintf(state.m_chm_toc, "<OBJECT type=\"text/site properties\">\n"); |
| 684 | fprintf(state.m_chm_toc, "\t<param name=\"Window Styles\" value=\"0x800625\">\n"); |
| 685 | fprintf(state.m_chm_toc, "\t<param name=\"ImageType\" value=\"Folder\">\n"); |
| 686 | fprintf(state.m_chm_toc, "\t<param name=\"Font\" value=\"Arial,8,0\">\n"); |
| 687 | fprintf(state.m_chm_toc, "</OBJECT>\n"); |
| 688 | fprintf(state.m_chm_toc, "<UL>\n"); |
| 689 | 689 | |
| 690 | 690 | /* create the XML parser */ |
| 691 | 691 | memcallbacks.malloc_fcn = expat_malloc; |
| 692 | 692 | memcallbacks.realloc_fcn = expat_realloc; |
| 693 | 693 | memcallbacks.free_fcn = expat_free; |
| 694 | | state.parser = XML_ParserCreate_MM(NULL, &memcallbacks, NULL); |
| 695 | | if (!state.parser) |
| 694 | state.m_parser = XML_ParserCreate_MM(NULL, &memcallbacks, NULL); |
| 695 | if (!state.m_parser) |
| 696 | 696 | goto outofmemory; |
| 697 | 697 | |
| 698 | | XML_SetUserData(state.parser, &state); |
| 699 | | XML_SetElementHandler(state.parser, start_handler, end_handler); |
| 700 | | XML_SetCharacterDataHandler(state.parser, data_handler); |
| 698 | XML_SetUserData(state.m_parser, &state); |
| 699 | XML_SetElementHandler(state.m_parser, start_handler, end_handler); |
| 700 | XML_SetCharacterDataHandler(state.m_parser, data_handler); |
| 701 | 701 | |
| 702 | 702 | do |
| 703 | 703 | { |
| 704 | 704 | len = (int) fread(buf, 1, sizeof(buf), in); |
| 705 | 705 | done = feof(in); |
| 706 | 706 | |
| 707 | | if (XML_Parse(state.parser, buf, len, done) == XML_STATUS_ERROR) |
| 707 | if (XML_Parse(state.m_parser, buf, len, done) == XML_STATUS_ERROR) |
| 708 | 708 | { |
| 709 | 709 | process_error(&state, NULL, NULL); |
| 710 | 710 | break; |
| r11059 | r11060 | |
| 712 | 712 | } |
| 713 | 713 | while(!done); |
| 714 | 714 | |
| 715 | | fprintf(state.chm_toc, "</UL>\n"); |
| 716 | | fprintf(state.chm_toc, "</BODY></HTML>"); |
| 717 | | fclose(state.chm_toc); |
| 715 | fprintf(state.m_chm_toc, "</UL>\n"); |
| 716 | fprintf(state.m_chm_toc, "</BODY></HTML>"); |
| 717 | fclose(state.m_chm_toc); |
| 718 | 718 | |
| 719 | 719 | /* create the help project file */ |
| 720 | | s = (char*)pool_malloc_lib(state.pool, strlen(dest_dir) + 1 + strlen(help_project_filename) + 1); |
| 720 | s = (char*)pool_malloc_lib(state.m_pool, strlen(dest_dir) + 1 + strlen(help_project_filename) + 1); |
| 721 | 721 | if (!s) |
| 722 | 722 | goto outofmemory; |
| 723 | 723 | strcpy(s, dest_dir); |
| r11059 | r11060 | |
| 733 | 733 | fprintf(chm_hhp, "[OPTIONS]\n"); |
| 734 | 734 | fprintf(chm_hhp, "Compiled file=%s\n", help_filename); |
| 735 | 735 | fprintf(chm_hhp, "Contents file=%s\n", help_contents_filename); |
| 736 | | fprintf(chm_hhp, "Default topic=%s\n", state.default_topic); |
| 736 | fprintf(chm_hhp, "Default topic=%s\n", state.m_default_topic); |
| 737 | 737 | fprintf(chm_hhp, "Language=0x409 English (United States)\n"); |
| 738 | | fprintf(chm_hhp, "Title=%s\n", state.title); |
| 738 | fprintf(chm_hhp, "Title=%s\n", state.m_title); |
| 739 | 739 | fprintf(chm_hhp, "\n"); |
| 740 | 740 | fclose(chm_hhp); |
| 741 | 741 | |
| 742 | 742 | /* finish up */ |
| 743 | | XML_ParserFree(state.parser); |
| 743 | XML_ParserFree(state.m_parser); |
| 744 | 744 | fclose(in); |
| 745 | | pool_free_lib(state.pool); |
| 746 | | return state.error ? -1 : 0; |
| 745 | pool_free_lib(state.m_pool); |
| 746 | return state.m_error ? -1 : 0; |
| 747 | 747 | |
| 748 | 748 | outofmemory: |
| 749 | 749 | fprintf(stderr, "Out of memory"); |
| 750 | 750 | error: |
| 751 | | if (state.chm_toc) fclose(state.chm_toc); |
| 751 | if (state.m_chm_toc) fclose(state.m_chm_toc); |
| 752 | 752 | if (in) fclose(in); |
| 753 | 753 | return -1; |
| 754 | 754 | } |