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

  1. /* $Id: nroff.c,v 2.0.1.13 1994/07/25 11:47:26 greyham Exp greyham $
  2.  * functions for nroff style output.
  3.  */
  4. #include "c2man.h"
  5. #include "manpage.h"
  6. #include "output.h"
  7.  
  8.  
  9. void nroff_text(text)
  10. const char *text;
  11. {
  12.     put_string(text);
  13. }
  14.  
  15. void nroff_char(c)
  16. const int c;
  17. {
  18.     putchar(c);
  19. }
  20.  
  21. void nroff_comment() { put_string(".\\\" "); }
  22.  
  23. void nroff_header(firstpage, input_files, grouped, name, section)
  24. ManualPage *firstpage;
  25. int input_files;
  26. boolean grouped;
  27. const char *name;
  28. const char *section;
  29. {
  30. #ifdef HAS_STRFTIME
  31.     char month[20];
  32. #else
  33.     char *month;
  34.     static char *month_list[] =
  35.     { "January", "February", "March", "April", "May", "June",
  36.       "July", "August", "September", "October", "November", "December" };
  37. #endif
  38.     Time_t raw_time;
  39.     struct tm *filetime;
  40.     
  41.     if (make_embeddable) return;
  42.  
  43.     output_warning();
  44.     put_string(".TH \"");
  45.  
  46.     /* if lots of files contributed, use the current time; otherwise use the
  47.      * time of the source file they came from.
  48.      */
  49.     raw_time = (grouped && input_files > 1) ? time((Time_t *)NULL)
  50.                         : firstpage->sourcetime;
  51.  
  52.     filetime = localtime(&raw_time);
  53.  
  54. #ifdef HAS_STRFTIME
  55.     /* generate the date format string */
  56.     strftime(month, sizeof month,"%B",filetime);
  57. #else
  58.     month = month_list[filetime->tm_mon];
  59. #endif
  60.  
  61.     nroff_text(name);
  62.  
  63.     printf("\" %s \"%d %s %d\"",
  64.         section,filetime->tm_mday,month,filetime->tm_year+1900);
  65.  
  66. /* I have conflicting info about how the .TH macro works.... */
  67. #ifdef HENRYS_TH /* As per Henry Spencer's "How to write a manual page" */
  68.     if (manual_name) printf(" \"%s\"", manual_name);
  69.     put_string("\n.BY");    
  70. #endif
  71.     printf(" \"%s",progname);
  72.     if ((input_files <= 1 || !grouped) && firstpage->sourcefile)
  73.     {
  74.     const char *basename = strrchr(firstpage->sourcefile, '/');
  75.     if (basename == NULL)
  76.         basename = firstpage->sourcefile;
  77.     else
  78.         basename++;
  79.     printf(" %s", basename);
  80.     }
  81. #ifndef HENRYS_TH
  82.     if (manual_name) printf("\" \"%s", manual_name);
  83. #endif
  84.     put_string("\"\n");    
  85.  
  86. #ifdef NeXT
  87.     /* define our own .SS on packages (such as NeXT's) where it doesn't move
  88.      * left a little. Sorry, awf doesn't support .SS.
  89.      */
  90.     put_string(".de SS\n.}X .25i \"\" \"\"\n.nr )E 2\n");
  91.     put_string("\\&\\\\$1\n.br\n..\n");
  92. #endif
  93. }
  94.  
  95. void nroff_dash()    { put_string("\\-"); }
  96.  
  97. void nroff_section(name)
  98. const char *name;
  99. {
  100.     put_string(".SH \"");
  101.     nroff_text(name);
  102.     put_string("\"\n");
  103. }
  104.  
  105. void nroff_sub_section(name)
  106. const char *name;
  107. {
  108.     put_string(".SS \"");
  109.     nroff_text(name);
  110.     put_string("\"\n");
  111. }
  112.  
  113. void nroff_break_line()    { put_string(".br\n"); }
  114. void nroff_blank_line() { put_string(".sp\n"); }
  115.  
  116. void nroff_code_start() { put_string(".ft B\n"); }
  117. void nroff_code_end()    { put_string(".ft R\n"); }
  118.  
  119. void nroff_code(text)
  120. const char *text;
  121. {
  122.     put_string("\\fB");
  123.     nroff_text(text);
  124.     put_string("\\fR");
  125. }
  126.  
  127. void nroff_tag_entry_start()        { put_string(".TP\n.B \""); }
  128. void nroff_tag_entry_start_extra()    { put_string(".TP\n.BR \""); }
  129. void nroff_tag_entry_end()        { put_string("\"\n"); }
  130. void nroff_tag_entry_end_extra(text)
  131. const char *text;
  132. {
  133.     put_string("\" \"\t(");
  134.     nroff_text(text);
  135.     put_string(")\"\n");
  136. }
  137.     
  138. void nroff_table_start(longestag)
  139. const char *longestag;
  140. {
  141.     void nroff_list_start();
  142.     nroff_list_start();
  143.  
  144.     /* We measure the length of the longest tag in the table by changing to the
  145.      * code font, taking it's width with \w'string' and adding a little for
  146.      * the space between the tag and description.  This gets stored in the TL
  147.      * number register, where the nroff_table_entry can find it.
  148.      * This isn't foolproof, because a shorter tag may be longer if it contains
  149.      * wider characters, but the extra space gives a little head room anyway.
  150.      */
  151.     nroff_code_start();
  152.     printf(".nr TL \\w'%s'u+0.2i\n", longestag);
  153.     nroff_code_end();
  154. }
  155.  
  156. void nroff_table_entry(name, description)
  157. const char *name;
  158. const char *description;
  159. {
  160.     put_string(".TP \\n(TLu\n");
  161.  
  162.     nroff_code(name);
  163.     nroff_char('\n');
  164.     if (description)
  165.     output_comment(description);
  166.     else
  167.     nroff_char('\n');
  168. }
  169.  
  170. void nroff_table_end()    { put_string(".RE\n.PD\n"); }
  171.  
  172. void nroff_indent()    { put_string(".IP\n"); }
  173.  
  174. void nroff_list_start() { put_string(".RS 0.75in\n.PD 0\n"); }
  175.  
  176. void nroff_list_entry(name)
  177. const char *name;
  178. {
  179.     nroff_code(name);
  180. }
  181.  
  182. void nroff_list_separator() { put_string(",\n"); }
  183. void nroff_list_end()    { nroff_char('\n'); nroff_table_end(); }
  184.  
  185. void nroff_include(filename)
  186. const char *filename;
  187. {
  188.     printf(".so %s\n", filename);
  189. }
  190.  
  191. void nroff_name(name)
  192. const char *name;
  193. {
  194.     if (name) nroff_text(name);
  195.     else      nroff_section("NAME");
  196. }
  197.  
  198. void nroff_terse_sep()
  199. {
  200.     nroff_char(' ');
  201.     nroff_dash();
  202.     nroff_char(' ');
  203. }
  204.  
  205. void nroff_emphasized(text)
  206. const char *text;
  207. {
  208.     put_string("\\fI");
  209.     nroff_text(text);
  210.     put_string("\\fR");
  211. }
  212.  
  213. void nroff_reference(text)
  214. const char *text;
  215. {
  216.     nroff_text(text);
  217.     nroff_char('(');
  218.     nroff_text(manual_section);
  219.     nroff_char(')');
  220. }
  221.  
  222. struct Output nroff_output =
  223. {
  224.     nroff_comment,
  225.     nroff_header,
  226.     nroff_dash,
  227.     nroff_section,
  228.     nroff_sub_section,
  229.     nroff_break_line,
  230.     nroff_blank_line,
  231.     nroff_code_start,
  232.     nroff_code_end,
  233.     nroff_code,
  234.     dummy,        /* nroff_tag_list_start */
  235.     dummy,        /* nroff_tag_list_end */
  236.     nroff_tag_entry_start,
  237.     nroff_tag_entry_start_extra,
  238.     nroff_tag_entry_end,
  239.     nroff_tag_entry_end_extra,
  240.     nroff_table_start,
  241.     nroff_table_entry,
  242.     nroff_table_end,
  243.     nroff_indent,
  244.     nroff_list_start,
  245.     nroff_code,        /* nroff_list_entry */
  246.     nroff_list_separator,
  247.     nroff_list_end,
  248.     nroff_include,
  249.     dummy,       /* nroff_file_end */
  250.     nroff_text,
  251.     nroff_char,
  252.     NULL,    /* nroff_parse_option */
  253.     dummy,    /* nroff_print_options */
  254.     nroff_name,
  255.     nroff_terse_sep,
  256.     nroff_reference,
  257.     nroff_emphasized
  258. };
  259.