Added SILC Thread Queue API
[silc.git] / util / robodoc / Source / generator.c
index a4012ee81e08a4529c495e7ca4be8b78b9c8afa3..632c2990f94c880e285de6fc97da3534cfec23a6 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;
 
@@ -63,13 +62,24 @@ RB_Generate_Documentation (
 
       RB_Say ("generating documentation for \"%s\"\n", cur_header->name);
 
+#if 1
+     /* If MAIN_HEADER, do not create file */
+     if (cur_header->type == MAIN_HEADER)
+       continue;
+#endif
+
       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 +119,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;
@@ -160,7 +173,7 @@ RB_Generate_Doc_Start (
       else
        fprintf (dest_doc, "@database %s\n", name);
       fprintf (dest_doc, "@rem Source: %s\n", src_name);
-      fprintf (dest_doc, "@rem " COMMENT_ROBODOC);
+/*      fprintf (dest_doc, "@rem " COMMENT_ROBODOC); */
       fprintf (dest_doc, "@rem " COMMENT_COPYRIGHT);
       fprintf (dest_doc, "@node Main %s\n", name);
       fprintf (dest_doc, "@{jcenter}\n");
@@ -253,20 +266,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 +292,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 +342,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);
@@ -348,11 +370,22 @@ RB_Generate_Doc_Start (
 
     case LATEX:
       fprintf (dest_doc, "%% Document: %s\n", name);
-      fprintf (dest_doc, "%% Source: %s\n", src_name);
-      fprintf (dest_doc, "%% " COMMENT_ROBODOC);
+       fprintf (dest_doc, "%% Source: %s\n", src_name);
+/*      fprintf (dest_doc, "%% " COMMENT_ROBODOC);*/
       fprintf (dest_doc, "%% " COMMENT_COPYRIGHT);
       if (course_of_action & DO_SINGLEDOC) {
-       fprintf (dest_doc, "\\section{%s}\n", src_name);
+        if (!strchr(src_name, '_')) {
+         fprintf (dest_doc, "\\section{%s}\n", src_name);
+       } else {
+         char *tmp = calloc(strlen(src_name) + 2, sizeof(*tmp));
+         *strchr(src_name, '_') = '\\';
+         strncat(tmp, src_name, strcspn(src_name, "\\") + 1);
+         strncat(tmp, "_", 1); 
+         strncat(tmp, src_name + strcspn(src_name, "\\") + 1,
+                 strlen(src_name) - strcspn(src_name, "\\") - 1);
+         fprintf (dest_doc, "\\section{%s}\n", tmp);
+         free(tmp);
+        }
       } else {
        fprintf (dest_doc, "\\documentclass{article}\n");
         fprintf (dest_doc, "\\usepackage{makeidx}\n");
@@ -376,7 +409,7 @@ RB_Generate_Doc_Start (
        } else {
          fprintf (dest_doc, "\\title{API Reference}\n");
        }
-       fprintf (dest_doc, "\\author{%s}\n", COMMENT_ROBODOC);
+/*     fprintf (dest_doc, "\\author{%s}\n", COMMENT_ROBODOC); */
        fprintf (dest_doc, "\\makeindex\n");
        fprintf (dest_doc, "\\begin{document}\n");
        fprintf (dest_doc, "\\maketitle\n");
@@ -411,7 +444,6 @@ RB_Generate_Doc_Start (
                 "{\\title %s}"
                 "{\\comment\n"
                 " Source: %s\n"
-                " " COMMENT_ROBODOC
                 " " COMMENT_COPYRIGHT
                 "}"
                 "}", name, src_name);
@@ -533,7 +565,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 +592,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 +771,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 +867,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 +923,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 +1298,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
                        {
@@ -1416,8 +1472,8 @@ RB_Generate_Index (FILE * dest, char *source)
          fprintf (dest, "<H1>Master Index File</H1>\n");
        }
        if (RB_Number_Of_Links (MAIN_HEADER, NULL))
-         RB_Generate_Index_Table (dest, MAIN_HEADER, "Project Modules");
-       RB_Generate_Index_Table (dest, NO_HEADER, "Source Files");
+         RB_Generate_Index_Table (dest, MAIN_HEADER, "Modules");
+//     RB_Generate_Index_Table (dest, NO_HEADER, "Source Files");
        if (RB_Number_Of_Links (CLASS_HEADER, NULL))
          RB_Generate_Index_Table (dest, CLASS_HEADER, "Classes");
        if (RB_Number_Of_Links (METHOD_HEADER, NULL))
@@ -1427,7 +1483,7 @@ RB_Generate_Index (FILE * dest, char *source)
        if (RB_Number_Of_Links (FUNCTION_HEADER, NULL))
          RB_Generate_Index_Table (dest, FUNCTION_HEADER, "Functions");
        if (RB_Number_Of_Links (VARIABLE_HEADER, NULL))
-         RB_Generate_Index_Table (dest, VARIABLE_HEADER, "Variables");
+         RB_Generate_Index_Table (dest, VARIABLE_HEADER, "Global Variables");
        if (RB_Number_Of_Links (CONSTANT_HEADER, NULL))
          RB_Generate_Index_Table (dest, CONSTANT_HEADER, "Constants");
        if (RB_Number_Of_Links (GENERIC_HEADER, NULL))
@@ -1517,8 +1573,9 @@ RB_Generate_Index_Table (FILE * dest, int type, char *title)
              if (RB_Number_Of_Links (NO_HEADER, cur_link->file_name) > 1)
                {
                  fprintf (dest,
-                          "<TD><A HREF=\"%s#%s\"><TT>%s</TT></A></TD>\n",
-                          cur_link->file_name, cur_link->label_name,
+                          "<TD><A HREF=\"%s-%s.html\"><TT>%s</TT></A></TD>\n",
+                          RB_FilePartStart(cur_link->file_name),
+                          cur_link->label_name,
                           cur_link->label_name);
                }
              else
@@ -1528,9 +1585,19 @@ RB_Generate_Index_Table (FILE * dest, int type, char *title)
            }
          else
            {
-             fprintf (dest, "<TD><A HREF=\"%s#%s\"><TT>%s</TT></A></TD>\n",
-                      cur_link->file_name, cur_link->label_name,
+             if (type == MAIN_HEADER)
+               {
+                 fprintf (dest, "<TD><A HREF=\"%s.html\"><TT>%s</TT></A></TD>\n",
+                      RB_FilePartStart(cur_link->file_name), 
                       cur_link->label_name);
+               }
+             else
+               {
+                 fprintf (dest, "<TD><A HREF=\"%s-%s.html\"><TT>%s</TT></A></TD>\n",
+                      RB_FilePartStart(cur_link->file_name), 
+                      cur_link->label_name,
+                      cur_link->label_name);
+               }
            };
          cur_column++;
          if (cur_column > number_of_columns)