home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / c2man-2.0pl33.lha / c2man-2.0 / texinfo.c < prev   
Encoding:
C/C++ Source or Header  |  1995-01-24  |  6.0 KB  |  288 lines

  1. /* $Id: texinfo.c,v 2.0.1.10 1994/09/16 05:55:19 greyham Exp $
  2.  * functions for texinfo style output.
  3.  */
  4. #include "c2man.h"
  5. #include "manpage.h"
  6. #include "output.h"
  7.  
  8. static char *heading_not_in_contents[] =
  9.      {"@chapheading ", "@heading ", "@subheading ", "@subsubheading "};
  10. static char *heading_in_contents[] =
  11.      {"@chapter ", "@section ", "@subsection ", "@subsubsection "};
  12.  
  13. #define n_levels  (sizeof(heading_not_in_contents) / sizeof(char *))
  14.  
  15. #define level(n) ((n) >= n_levels ? n_levels - 1 : (n))
  16.  
  17. /* section level for man page entry */
  18. static int top_level = 1;
  19.  
  20. /* always output node for manpage, even if embedded */
  21. static int embed_node_info = 0;
  22.  
  23. /* use title as name of section, rather than "NAME" */
  24. static int title_name = 0;
  25.  
  26. /* the section title, filled in by texinfo_header */
  27. static const char *title = "INTERNAL ERROR, BOGUS TITLE DUDE!";
  28.  
  29. void texinfo_char(c)
  30. const int c;
  31. {
  32.     int i;
  33.  
  34.     switch(c)
  35.     {
  36.     case '\t':
  37.     for (i = 0; i < NUM_TAB_SPACES; i++)
  38.         putchar(' ');
  39.     break;
  40.     default:
  41.         putchar(c);
  42.     break;
  43.     }
  44. }
  45.  
  46. void texinfo_text(text)
  47. const char *text;
  48. {
  49.     while (*text)
  50.     texinfo_char(*text++);
  51. }
  52.  
  53. void texinfo_comment() { put_string("@c "); }
  54.  
  55. void texinfo_header(firstpage, input_files, grouped, name, section)
  56. ManualPage *firstpage;
  57. int input_files;
  58. boolean grouped;
  59. const char *name;
  60. const char *section;
  61. {
  62.     if (! make_embeddable)
  63.     {
  64.     put_string("\\input texinfo @c -*-texinfo-*-\n");
  65.     output_warning();
  66.     put_string("@c %**start of header\n");
  67.     put_string("@setfilename ");
  68.     texinfo_text(name);
  69.     put_string(".info\n@settitle ");
  70.     texinfo_text(name);
  71.     putchar('\n');
  72.     put_string("@c %**end of header\n");
  73.  
  74.     put_string("@node Top, ");
  75.     texinfo_text(name);
  76.     put_string(", (dir), (dir)\n");
  77.     }
  78.  
  79.     if (! make_embeddable || embed_node_info)
  80.     {
  81.       put_string("@node ");
  82.       texinfo_text(name);
  83.       put_string(", (dir), Top, (dir)\n");
  84.     }
  85.  
  86.     title = name;
  87. }
  88.  
  89. void texinfo_dash()    { put_string("---"); }
  90.  
  91. void texinfo_section(name)
  92. const char *name;
  93. {
  94.     put_string(heading_not_in_contents[level(top_level)]);
  95.     texinfo_text(name);
  96.     putchar('\n');
  97.     put_string("@noindent\n");
  98. }
  99.  
  100. void texinfo_section_in_contents(name)
  101. const char *name;
  102. {
  103.     put_string(heading_in_contents[level(top_level)]);
  104.     texinfo_text(name);
  105.     putchar('\n');
  106.     put_string("@noindent\n");
  107. }
  108.  
  109. void texinfo_sub_section(name)
  110. const char *name;
  111. {
  112.     put_string(heading_not_in_contents[level(top_level+1)]);
  113.     texinfo_text(name);
  114.     putchar('\n');
  115.     put_string("@noindent\n");
  116. }
  117.  
  118. void texinfo_break_line() { /* put_string("@*\n"); */ }
  119. void texinfo_blank_line() { put_string("@sp 1\n"); }
  120.  
  121. void texinfo_code_start() { put_string("@example\n"); }
  122. void texinfo_code_end()    { put_string("@end example\n"); }
  123.  
  124. void texinfo_code(text)
  125. const char *text;
  126. {
  127.     put_string("@code{");
  128.     texinfo_text(text);
  129.     put_string("}");
  130. }
  131.  
  132. void texinfo_tag_list_start()    { put_string("@display\n@table @code\n"); }
  133. void texinfo_tag_entry_start()    { put_string("@item "); }
  134. void texinfo_tag_entry_end()    { putchar('\n'); }
  135.  
  136. void texinfo_tag_entry_end_extra(text)
  137. const char *text;
  138. {
  139.     putchar('(');
  140.     texinfo_text(text);
  141.     putchar(')');
  142.     texinfo_tag_entry_end();
  143. }
  144. void texinfo_tag_list_end()    { put_string("@end table\n@end display\n"); }
  145.     
  146. void texinfo_table_start(longestag)
  147. const char *longestag;
  148. { put_string("@display\n@table @code\n"); }
  149.  
  150. void texinfo_table_entry(name, description)
  151. const char *name;
  152. const char *description;
  153. {
  154.     put_string("@item ");
  155.     texinfo_text(name);
  156.     putchar('\n');
  157.     if (description)
  158.     output_comment(description);
  159.     else
  160.     putchar('\n');
  161. }
  162.  
  163. void texinfo_table_end()    { put_string("@end table\n@end display\n"); }
  164.  
  165. void texinfo_list_start()    { }
  166. void texinfo_list_entry(text)
  167. const char *text;
  168. {
  169.     texinfo_code(text);
  170. }
  171. void texinfo_list_separator() { put_string(",\n"); }
  172. void texinfo_list_end()    { putchar('\n'); }
  173.  
  174. void texinfo_include(filename)
  175. const char *filename;
  176. {
  177.     put_string("@include ");
  178.     texinfo_text(filename);
  179.     put_string("\n");
  180. }
  181.  
  182. void texinfo_file_end() { put_string("@bye\n"); }
  183.  
  184. static first_name = 1;
  185. void texinfo_name(name)
  186. char *name;
  187. {
  188.     if (name)
  189.     {
  190.     if (!first_name || !title_name || strcmp(title,name))
  191.        texinfo_text(name);
  192.     first_name = 0;
  193.     }
  194.     else
  195.     {
  196.     first_name = 1;
  197.     if (title_name)
  198.         texinfo_section_in_contents(title);
  199.     else
  200.         texinfo_section("NAME");
  201.     }
  202. }
  203.  
  204. void texinfo_terse_sep()
  205. {
  206.     if (!title_name || group_together)
  207.     {
  208.     texinfo_char(' ');
  209.     texinfo_dash();
  210.     texinfo_char(' ');
  211.     }
  212. }
  213.  
  214. void texinfo_reference(text)
  215. const char *text;
  216. {
  217.     texinfo_text(text);
  218.     texinfo_char('(');
  219.     texinfo_text(manual_section);
  220.     texinfo_char(')');
  221. }
  222.  
  223.  
  224.  
  225. int texinfo_parse_option(option)
  226. char *option;
  227. {
  228.     if        (option[0] == 't')
  229.     title_name = 1;
  230.     else if (option[0] == 'n')
  231.     embed_node_info = 1;
  232.     else if (option[0] == 's')
  233.     {
  234.     top_level = atoi(&option[1]);
  235.     if (top_level < 0) return 1;
  236.     }
  237.     else return 1;
  238.  
  239.     return 0;
  240. }
  241.  
  242. void texinfo_print_options()
  243. {
  244.     fputs("\ttexinfo options:\n", stderr);
  245.     fputs("\tt\tuse manpage title as NAME title\n", stderr);
  246.     fputs("\tn\toutput node info if embedded output\n", stderr);
  247.     fputs("\ts<n>\tset top heading level to <n>\n", stderr);
  248. }
  249.  
  250.  
  251. struct Output texinfo_output =
  252. {
  253.     texinfo_comment,
  254.     texinfo_header,
  255.     texinfo_dash,
  256.     texinfo_section,
  257.     texinfo_sub_section,
  258.     texinfo_break_line,
  259.     texinfo_blank_line,
  260.     texinfo_code_start,
  261.     texinfo_code_end,
  262.     texinfo_code,
  263.     texinfo_tag_list_start,
  264.     texinfo_tag_list_end,
  265.     texinfo_tag_entry_start,
  266.     texinfo_tag_entry_start,    /* entry_start_extra */
  267.     texinfo_tag_entry_end,
  268.     texinfo_tag_entry_end_extra,
  269.     texinfo_table_start,
  270.     texinfo_table_entry,
  271.     texinfo_table_end,
  272.     dummy,        /* texinfo_indent */
  273.     texinfo_list_start,
  274.     texinfo_list_entry,
  275.     texinfo_list_separator,
  276.     texinfo_list_end,
  277.     texinfo_include,
  278.     texinfo_file_end,
  279.     texinfo_text,
  280.     texinfo_char,
  281.     texinfo_parse_option,
  282.     texinfo_print_options,
  283.     texinfo_name,
  284.     texinfo_terse_sep,
  285.     texinfo_reference,
  286.     texinfo_text
  287. };
  288.