home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / c2man-2.0pl33.lha / c2man-2.0 / amiga / autodoc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-26  |  7.2 KB  |  400 lines

  1. /*
  2. ** $PROJECT:
  3. **
  4. ** $VER: autodoc.c 2.2 (25.01.95)
  5. **
  6. ** by
  7. **
  8. ** Stefan Ruppert , Windthorststraße 5 , 65439 Flörsheim , GERMANY
  9. **
  10. ** (C) Copyright 1995
  11. ** All Rights Reserved !
  12. **
  13. ** $HISTORY:
  14. **
  15. ** 25.01.95 : 002.002 : changed to patchlevel 33
  16. ** 22.01.95 : 000.001 : initial
  17. */
  18.  
  19. #include "/c2man.h"
  20. #include "/manpage.h"
  21. #include "/output.h"
  22.  
  23. #ifdef DEBUG
  24. #define D(x)  x
  25. #else
  26. #define D(x)
  27. #endif
  28.  
  29. #define MAX_TAG      10
  30.  
  31. static const int linelength   = 79;
  32. static const int tablength    =  4;
  33. static const int indentlength =  4;
  34.  
  35. static int indent      = 4;
  36. static int list_indent = 0;
  37. static int column      = 0;
  38. static int newline     = FALSE;
  39. static int breakline   = FALSE;
  40. static int see_also    = FALSE;
  41. static int fileend     = FALSE;
  42. static int acttable    = -1;
  43. static int tablemaxtag[MAX_TAG];
  44.  
  45. void autodoc_format(text)
  46. const char *text;
  47. {
  48.     if(see_also)
  49.     {
  50.        if(column + ((text) ? strlen(text) + 2 : 1) > linelength)
  51.        {
  52.            putchar('\n');
  53.            newline = TRUE;
  54.        }
  55.     }
  56.  
  57.     if(newline)
  58.     {
  59.        int i;
  60.        column = i = indent + list_indent;
  61.        for(; i ; i--)
  62.           putchar(' ');
  63.        newline = FALSE;
  64.     }
  65. }
  66.  
  67. void autodoc_text(text)
  68. const char *text;
  69. {
  70.     int br = 1;
  71.     autodoc_format(text);
  72.  
  73.     if(!see_also || (br = strcmp(text,",\n")))
  74.     {
  75.         if(see_also < 2)
  76.         {
  77.            put_string(text);
  78.            column += strlen(text);
  79.         }
  80.     } else if(!br)
  81.     {
  82.         column += 2;
  83.         put_string(", ");
  84.     }
  85. }
  86.  
  87. void autodoc_char(c)
  88. const int c;
  89. {
  90.     if(c != '\f')
  91.     {
  92.        autodoc_format(NULL);
  93.  
  94.        if(c == '\t')
  95.        {
  96.           int i = tablength - (column % tablength);
  97.           column += i;
  98.           for(; i ; i--)
  99.              putchar(' ');
  100.        } else
  101.        {
  102.           if(see_also)
  103.           {
  104.              if(c == '(')
  105.                  see_also++;
  106.              else if(c == ')')
  107.                  see_also--;
  108.           }
  109.  
  110.           putchar(c);
  111.           column++;
  112.        }
  113.  
  114.        if((newline = (c == '\n')))
  115.            column = 0;
  116.    }
  117. }
  118.  
  119. void autodoc_comment() { }
  120.  
  121. void autodoc_header(firstpage, input_files, grouped, name, section)
  122. ManualPage *firstpage;
  123. int input_files;
  124. boolean grouped;
  125. const char *name;
  126. const char *section;
  127. {
  128.     const char *basename = strrchr(firstpage->sourcefile, '/');
  129.     int len;
  130.     int spc;
  131.  
  132.     fileend = FALSE;
  133.  
  134.     if(basename && *basename == '/')
  135.         basename++;
  136.  
  137.     len =  ((basename) ? strlen(basename) + 1 : 0) + strlen(name);
  138.     spc  = linelength - 2 * len;
  139.  
  140.     see_also = FALSE;
  141.  
  142.     if(basename)
  143.     {
  144.        autodoc_text(basename);
  145.        autodoc_char('/');
  146.     }
  147.     autodoc_text(name);
  148.  
  149.     if(spc > 0)
  150.     {
  151.       while(spc)
  152.       {
  153.          autodoc_char(' ');
  154.          spc--;
  155.       }
  156.        if(basename)
  157.        {
  158.           autodoc_text(basename);
  159.           autodoc_char('/');
  160.        }
  161.        autodoc_text(name);
  162.     } else
  163.     {
  164.        const char *ptr = name;
  165.        len = linelength - 1 - len;
  166.  
  167.        while(len)
  168.        {
  169.           if(basename && *basename)
  170.           {
  171.              autodoc_char(*basename);
  172.              basename++;
  173.           } else
  174.           {
  175.              if(ptr == name && basename)
  176.                 autodoc_char('/');
  177.              else
  178.              {
  179.                 autodoc_char(*ptr);
  180.                 ptr++;
  181.              }
  182.           }
  183.           len--;
  184.        }
  185.     }
  186.  
  187.     put_string("\n");
  188. }
  189.  
  190. void autodoc_dash()       { put_string("-"); }
  191.  
  192. void autodoc_section(name)
  193. const char *name;
  194. {
  195.     D((fprintf(stderr,"section : %s\n",name)));
  196.     newline = FALSE;
  197.     see_also = FALSE;
  198.     put_string("\n");
  199.     if(!strcmp(name,"DESCRIPTION"))
  200.        name = "FUNCTION";
  201.     else if(!strcmp(name,"PARAMETERS"))
  202.        name = "INPUTS";
  203.     else if(!strcmp(name,"RETURNS"))
  204.        name = "RESULT";
  205.     else if(!strcmp(name,"SEE ALSO"))
  206.        see_also = TRUE;
  207.  
  208.     put_string("    ");
  209.     autodoc_text(name);
  210.     indent = 8;
  211.     list_indent = 0;
  212.     autodoc_char('\n');
  213. }
  214.  
  215. void autodoc_sub_section(name)
  216. const char *name;
  217. {
  218.     autodoc_text(name);
  219.     indent = 12;
  220. }
  221.  
  222. void autodoc_break_line()
  223. {
  224.    breakline = TRUE;
  225. }
  226.  
  227. void autodoc_blank_line()
  228. {
  229.     autodoc_char('\n');
  230. }
  231.  
  232. void autodoc_code_start() {  }
  233. void autodoc_code_end()   {  }
  234.  
  235. void autodoc_code(text)
  236. const char *text;
  237. {
  238.     autodoc_text(text);
  239. }
  240.  
  241. void autodoc_tag_entry_start()
  242. {
  243.     if(list_indent > 0)
  244.     {
  245.         autodoc_char('\n');
  246.         list_indent -= indentlength;
  247.     }
  248. }
  249. void autodoc_tag_entry_start_extra()
  250. {
  251.     if(list_indent > 0)
  252.     {
  253.         autodoc_char('\n');
  254.         list_indent -= indentlength;
  255.     }
  256. }
  257. void autodoc_tag_entry_end()
  258. {
  259.    list_indent += indentlength;
  260.    autodoc_char('\n');
  261. }
  262. void autodoc_tag_entry_end_extra(text)
  263. const char *text;
  264. {
  265.     put_string("\" \"\t(");
  266.     autodoc_text(text);
  267.     put_string(")\"\n");
  268.     list_indent += indentlength;
  269. }
  270.         
  271. void autodoc_table_start(longestag)
  272. const char *longestag;
  273. {
  274.    if(acttable < MAX_TAG - 1)
  275.    {
  276.       acttable++;
  277.       tablemaxtag[acttable] = strlen(longestag);
  278.    }
  279.  
  280.    indent += indentlength;
  281.    newline = TRUE;
  282. }
  283.  
  284. void autodoc_table_entry(name, description)
  285. const char *name;
  286. const char *description;
  287. {
  288.     int i = tablemaxtag[acttable] - strlen(name) + 1;
  289.  
  290.     autodoc_code(name);
  291.     while(i > 0)
  292.     {
  293.        putchar(' ');
  294.        i--;
  295.     }
  296.     putchar('-');
  297.     putchar(' ');
  298.  
  299.     if (description)
  300.         output_comment(description);
  301.     else
  302.         autodoc_char('\n');
  303. }
  304.  
  305. void autodoc_table_end()
  306. {
  307.     if(acttable > -1)
  308.       acttable--;
  309.  
  310.     autodoc_char('\n');
  311.     indent -= indentlength;
  312.     if(list_indent > 0)
  313.        list_indent -= indentlength;
  314. }
  315.  
  316. void autodoc_indent()
  317. {
  318.     int i;
  319.     for(i = indent + list_indent; i ; i--)
  320.        autodoc_char(' ');
  321. }
  322.  
  323. void autodoc_list_entry(name)
  324. const char *name;
  325. {
  326.     autodoc_code(name);
  327. }
  328.  
  329. void autodoc_list_separator() { put_string(" ,"); }
  330. void autodoc_list_end()   { autodoc_char('\n'); autodoc_table_end(); }
  331.  
  332. void autodoc_include(filename)
  333. const char *filename;
  334. {
  335.  
  336. }
  337.  
  338. void autodoc_terse_sep()
  339. {
  340.     autodoc_char(' ');
  341.     autodoc_dash();
  342.     autodoc_char(' ');
  343. }
  344.  
  345. void autodoc_name(name)
  346. const char *name;
  347. {
  348.    if(name)
  349.       autodoc_text(name);
  350.    else
  351.       autodoc_section("NAME");
  352. }
  353.  
  354. void autodoc_file_end()
  355. {
  356.    if(!fileend)
  357.       putchar('\f');
  358.    fileend = TRUE;
  359.    newline = FALSE;
  360. }
  361.  
  362. struct Output autodoc_output =
  363. {
  364.     autodoc_comment,
  365.     autodoc_header,
  366.     autodoc_dash,
  367.     autodoc_section,
  368.     autodoc_sub_section,
  369.     autodoc_break_line,
  370.     autodoc_blank_line,
  371.     autodoc_code_start,
  372.     autodoc_code_end,
  373.     autodoc_code,
  374.     dummy,              /* autodoc_tag_list_start */
  375.     dummy,              /* autodoc_tag_list_end */
  376.     autodoc_tag_entry_start,
  377.     autodoc_tag_entry_start_extra,
  378.     autodoc_tag_entry_end,
  379.     autodoc_tag_entry_end_extra,
  380.     autodoc_table_start,
  381.     autodoc_table_entry,
  382.     autodoc_table_end,
  383.     autodoc_indent,
  384.     autodoc_table_start,  /* autodoc_list_start */
  385.     autodoc_code,         /* autodoc_list_entry */
  386.     autodoc_list_separator,
  387.     autodoc_list_end,
  388.     autodoc_include,
  389.     autodoc_file_end,      /* autodoc_file_end */
  390.     autodoc_text,
  391.     autodoc_char,
  392.     NULL,                  /* autodoc_parse_option */
  393.     dummy,                 /* autodoc_print_options */
  394.     autodoc_name,
  395.     autodoc_terse_sep,
  396.     autodoc_text,          /* autodoc_reference */
  397.     autodoc_text           /* autodoc_emphasized */
  398. };
  399.  
  400.