Added cross-reference support for document generator.
[silc.git] / util / robodoc / Source / generator.c
index a4012ee81e08a4529c495e7ca4be8b78b9c8afa3..e057f077cab913bd71e92a5b99bb5265470cba9a 100644 (file)
@@ -10,7 +10,7 @@
 #include "links.h"
 #include "generator.h"
 #include "analyser.h"
-
+#include <errno.h>
 
 /****f* ROBODoc/RB_Generate_Documentation [3.0h]
  * NAME
@@ -46,7 +46,6 @@ RB_Generate_Documentation (
                            FILE * dest_doc, char *src_name, char *dest_name)
 {
   struct RB_header *cur_header;
-  int expc = 0;
   char fname[256];
   FILE *orig_doc = dest_doc;
 
@@ -65,11 +64,16 @@ RB_Generate_Documentation (
 
       if (output_mode == HTML)
         {
-          sprintf(fname, "%s_exp_%d.html", doc_base, expc++);
+          sprintf(fname, "%s-%s.html", doc_base, cur_header->function_name);
           dest_doc = fopen(fname, "w");
+          if (!dest_doc)
+            {
+             fprintf(stderr, "%s\n", strerror(errno));
+             exit(1);
+           }
         }
 
-      RB_Generate_Header_Start (dest_doc, cur_header);
+      RB_Generate_Header_Start (dest_doc, cur_header, src_name);
 
       next_line = cur_header->contents;
       item_type = RB_Find_Item (&next_line, &item_line);
@@ -109,6 +113,9 @@ RB_Generate_Documentation (
                whoami, cur_header->name);
 
       RB_Generate_Header_End (dest_doc, cur_header);
+
+      if (output_mode == HTML)
+        fclose(dest_doc);
     }
 
   dest_doc = orig_doc;
@@ -253,20 +260,25 @@ RB_Generate_Doc_Start (
       fprintf (dest_doc, "<BR>\n");
       if (toc)
        {
-         int expc = 0;
          char iname[256];
          FILE *index;
+         int start = 0;
 
          /* do toc if not in fold */
 #if 0
          fprintf (dest_doc,
                   "<H3 ALIGN=\"center\">TABLE OF CONTENTS</H3>\n");
-#endif
          fprintf (dest_doc, "<OL>\n");
+#endif
 
          /* Generate quick index file, for fast referencing */
-         sprintf(iname, "%s_index.html", doc_base);
+         sprintf(iname, "%s-index.tmpl", doc_base);
           index = fopen(iname, "w");
+          if (!index)
+           {
+             fprintf(stderr, "%s\n", strerror(errno));
+             exit(1);
+           }
 
          for (cur_header = first_header;
               cur_header;
@@ -274,16 +286,18 @@ RB_Generate_Doc_Start (
            {
              char fname[256];
 
-             sprintf(fname, "%s_exp_%d.html", doc_base, expc);
+             sprintf(fname, "%s-%s.html", RB_FilePart(doc_base), 
+                     cur_header->function_name);
 
              if (cur_header->name && cur_header->function_name)
                {
-                 if (expc == 0) 
+                 if (start == 0) 
                    {
                      int item_type;
                      char *next_line, *item_line = NULL;
                    
-                     RB_Generate_Header_Start (dest_doc, cur_header);
+                     RB_Generate_Header_Start (dest_doc, cur_header, 
+                                               src_name);
 
                      next_line = cur_header->contents;
                      item_type = RB_Find_Item (&next_line, &item_line);
@@ -322,24 +336,26 @@ RB_Generate_Doc_Start (
 
                      if (index)
                        {
-                         fprintf (index, " >> <A HREF=\"%s\">%s</A><BR>\n",
+                         fprintf (index, "<A HREF=\"%s\"><IMG SRC=\"index_pic.gif\" BORDER=\"0\" ALT=\"\">%s</A><BR>\n",
                                   name, cur_header->function_name);
                        }
+
+                     start = 1;
                    }
                  else
                    {
                      fprintf (dest_doc, "<LI><A HREF=\"%s\">%s</A>\n",
-                              fname, cur_header->name);
+                              fname, cur_header->function_name);
                      if (index)
-                       fprintf (index, " >> <A HREF=\"%s\">%s</A><BR>\n",
+                       fprintf (index, "<A HREF=\"%s\"><IMG SRC=\"index_pic.gif\" BORDER=\"0\" ALT=\"\">%s</A><BR>\n",
                                 fname, cur_header->function_name);
                    }
-
-                 expc++;
                }
            }
 
+#if 0
          fprintf (dest_doc, "</OL>\n");
+#endif
 
          if (index)
            fclose(index);
@@ -533,7 +549,8 @@ RB_Generate_Doc_End (FILE * dest_doc, char *name)
  */
 
 void
-RB_Generate_Header_Start (FILE * dest_doc, struct RB_header *cur_header)
+RB_Generate_Header_Start (FILE * dest_doc, struct RB_header *cur_header,
+                         const char *src_name)
 {
   char *cook_link;
 
@@ -559,28 +576,35 @@ RB_Generate_Header_Start (FILE * dest_doc, struct RB_header *cur_header)
 #endif
          if (cur_header->type == FUNCTION_HEADER)
            fprintf (dest_doc, 
-                    "\n<FONT SIZE=\"+3\" COLOR=\"#000044\"><B>"
+                    "\n<FONT SIZE=\"+2\" COLOR=\"#000055\"><B>"
                     "Function <A NAME=\"%s\">%s</A>"
                     "</FONT></B><BR><BR>\n\n",
                     cur_header->function_name,
                     cur_header->function_name);
          else if (cur_header->type == STRUCT_HEADER)
            fprintf (dest_doc, 
-                    "\n<FONT SIZE=\"+3\" COLOR=\"#000044\"><B>"
+                    "\n<FONT SIZE=\"+2\" COLOR=\"#000055\"><B>"
                     "Structure <A NAME=\"%s\">%s</A>"
                     "</FONT></B><BR><BR>\n\n",
                     cur_header->function_name,
                     cur_header->function_name);
          else if (cur_header->type == VARIABLE_HEADER)
            fprintf (dest_doc, 
-                    "\n<FONT SIZE=\"+3\" COLOR=\"#000044\"><B>"
+                    "\n<FONT SIZE=\"+2\" COLOR=\"#000055\"><B>"
                     "Variable <A NAME=\"%s\">%s</A>"
                     "</FONT></B><BR><BR>\n\n",
                     cur_header->function_name,
                     cur_header->function_name);
+         else if (cur_header->type == MAIN_HEADER)
+           fprintf (dest_doc, 
+                    "\n<FONT SIZE=\"+2\" COLOR=\"#000055\"><B>"
+                    "<A NAME=\"%s\">%s</A>"
+                    "</FONT></B><BR><SMALL>Header: %s</SMALL><BR><BR>\n\n",
+                    cur_header->function_name,
+                    cur_header->function_name, src_name);
          else
            fprintf (dest_doc, 
-                    "\n<FONT SIZE=\"+3\" COLOR=\"#000044\"><B>"
+                    "\n<FONT SIZE=\"+2\" COLOR=\"#000055\"><B>"
                     "<A NAME=\"%s\">%s</A>"
                     "</FONT></B><BR><BR>\n\n",
                     cur_header->function_name,
@@ -731,7 +755,7 @@ RB_Generate_Item_Name (FILE * dest_doc, int item_type)
       fprintf (dest_doc, format_str,
               att_start_command[MAKE_BOLD][output_mode]);
       if (output_mode == HTML)
-       fprintf (dest_doc, "\n<FONT COLOR=\"#000044\">");
+       fprintf (dest_doc, "\n<FONT COLOR=\"#000055\">");
       fprintf (dest_doc, format_str, item_names[item_type]);
       if (output_mode == HTML)
        fprintf (dest_doc, "\n</FONT>");
@@ -827,6 +851,9 @@ RB_Generate_Item_Doc (FILE * dest_doc, char *dest_name,
   if (item_attributes[item_type] & TEXT_BODY_SHINE)
     fprintf (dest_doc, format_str,
             att_start_command[MAKE_SHINE][output_mode]);
+  if (item_attributes[item_type] & TEXT_BODY_DEFAULT)
+    fprintf (dest_doc, format_str,
+            att_start_command[MAKE_DEFAULT][output_mode]);
 
   /* 
    * For some modes, the text body is always non-prop
@@ -880,6 +907,9 @@ RB_Generate_Item_Doc (FILE * dest_doc, char *dest_name,
   if (item_attributes[item_type] & TEXT_BODY_LARGE_FONT)
     fprintf (dest_doc, format_str,
             att_stop_command[MAKE_LARGE][output_mode]);
+  if (item_attributes[item_type] & TEXT_BODY_DEFAULT)
+    fprintf (dest_doc, format_str,
+            att_stop_command[MAKE_DEFAULT][output_mode]);
 
   if (output_mode != HTML)
     {
@@ -1252,15 +1282,25 @@ RB_Generate_Item_Body (FILE * dest_doc, char *dest_name,
                    }
                  else if (file_name && strcmp (file_name, dest_name))
                    {
+#if 0
                      fprintf (dest_doc, "<A HREF=\"%s#%s\">%s</A>",
                               file_name, label_name, label_name);
+#endif
+                     fprintf (dest_doc, "<A HREF=\"%s-%s.html\">%s</A>",
+                              RB_FilePartStart(file_name), label_name, 
+                              label_name);
                    }
                  else
                    {
                      if (strcmp (label_name, function_name))
                        {
+#if 0
                          fprintf (dest_doc, "<A HREF=\"#%s\">%s</A>",
                                   label_name, label_name);
+#endif
+                         fprintf (dest_doc, "<A HREF=\"%s-%s.html\">%s</A>",
+                                  RB_FilePart(doc_base), label_name, 
+                                              label_name);
                        }
                      else
                        {