Previous 15994 Revisions Next

r11060 Sunday 3rd April, 2011 at 13:31:02 UTC by Miodrag Milanović
Fix building messdocs
[src/mess/tools/messdocs]messdocs.c

src/mess/tools/messdocs/messdocs.c
r11059r11060
1515
1616struct messdocs_state
1717{
18   const char *dest_dir;
18   const char *m_dest_dir;
1919
20   const char *title;
21   const char *default_topic;
20   const char *m_title;
21   const char *m_default_topic;
2222
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;
2929};
3030
3131
r11059r11060
639639   XML_Memory_Handling_Suite memcallbacks;
640640
641641   memset(&state, 0, sizeof(state));
642   state.pool = pool_alloc_lib(NULL);
642   state.m_pool = pool_alloc_lib(NULL);
643643
644644   /* open the DOC */
645645   in = fopen(toc_filename, "r");
r11059r11060
650650   }
651651
652652   /* 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)
655655      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';
658658
659659   /* clean the target directory */
660660   rmdir_recursive(dest_dir);
661661   osd_mkdir(dest_dir);
662662
663663   /* 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);
665665   if (!s)
666666      goto outofmemory;
667667   strcpy(s, dest_dir);
668668   strcat(s, PATH_SEPARATOR);
669669   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)
673673   {
674674      fprintf(stderr, "Cannot open file %s\n", s);
675675      goto error;
676676   }
677677
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");
689689
690690   /* create the XML parser */
691691   memcallbacks.malloc_fcn = expat_malloc;
692692   memcallbacks.realloc_fcn = expat_realloc;
693693   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)
696696      goto outofmemory;
697697
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);
701701
702702   do
703703   {
704704      len = (int) fread(buf, 1, sizeof(buf), in);
705705      done = feof(in);
706706
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)
708708      {
709709         process_error(&state, NULL, NULL);
710710         break;
r11059r11060
712712   }
713713   while(!done);
714714
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);
718718
719719   /* 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);
721721   if (!s)
722722      goto outofmemory;
723723   strcpy(s, dest_dir);
r11059r11060
733733   fprintf(chm_hhp, "[OPTIONS]\n");
734734   fprintf(chm_hhp, "Compiled file=%s\n", help_filename);
735735   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);
737737   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);
739739   fprintf(chm_hhp, "\n");
740740   fclose(chm_hhp);
741741
742742   /* finish up */
743   XML_ParserFree(state.parser);
743   XML_ParserFree(state.m_parser);
744744   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;
747747
748748outofmemory:
749749   fprintf(stderr, "Out of memory");
750750error:
751   if (state.chm_toc) fclose(state.chm_toc);
751   if (state.m_chm_toc) fclose(state.m_chm_toc);
752752   if (in)   fclose(in);
753753   return -1;
754754}

Previous 15994 Revisions Next


© 1998-2018 The MESS Team