home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / SLAKWARE / D12 / PERL1.TGZ / perl1.tar / usr / bin / pod2man < prev    next >
Text File  |  1996-06-28  |  26KB  |  1,047 lines

  1. #!/usr/bin/perl
  2. eval 'exec perl -S $0 "$@"'
  3.     if 0;
  4.  
  5. =head1 NAME
  6.  
  7. pod2man - translate embedded Perl pod directives into man pages
  8.  
  9. =head1 SYNOPSIS
  10.  
  11. B<pod2man>
  12. [ B<--section=>I<manext> ]
  13. [ B<--release=>I<relpatch> ]
  14. [ B<--center=>I<string> ]
  15. [ B<--date=>I<string> ]
  16. [ B<--fixed=>I<font> ]
  17. [ B<--official> ]
  18. I<inputfile>
  19.  
  20. =head1 DESCRIPTION
  21.  
  22. B<pod2man> converts its input file containing embedded pod directives (see
  23. L<perlpod>) into nroff source suitable for viewing with nroff(1) or
  24. troff(1) using the man(7) macro set.
  25.  
  26. Besides the obvious pod conversions, B<pod2man> also takes care of
  27. func(), func(n), and simple variable references like $foo or @bar so
  28. you don't have to use code escapes for them; complex expressions like
  29. C<$fred{'stuff'}> will still need to be escaped, though.  Other nagging
  30. little roffish things that it catches include translating the minus in
  31. something like foo-bar, making a long dash--like this--into a real em
  32. dash, fixing up "paired quotes", putting a little space after the
  33. parens in something like func(), making C++ and PI look right, making
  34. double underbars have a little tiny space between them, making ALLCAPS
  35. a teeny bit smaller in troff(1), and escaping backslashes so you don't
  36. have to.
  37.  
  38. =head1 OPTIONS
  39.  
  40. =over 8
  41.  
  42. =item center
  43.  
  44. Set the centered header to a specific string.  The default is
  45. "User Contributed Perl Documentation", unless the C<--official> flag is
  46. given, in which case the default is "Perl Programmers Reference Guide".
  47.  
  48. =item date
  49.  
  50. Set the left-hand footer string to this value.  By default,
  51. the modification date of the input file will be used.
  52.  
  53. =item fixed
  54.  
  55. The fixed font to use for code refs.  Defaults to CW.
  56.  
  57. =item official
  58.  
  59. Set the default header to indicate that this page is of
  60. the standard release in case C<--center> is not given.
  61.  
  62. =item release
  63.  
  64. Set the centered footer.  By default, this is the current
  65. perl release.
  66.  
  67. =item section
  68.  
  69. Set the section for the C<.TH> macro.  The standard conventions on
  70. sections are to use 1 for user commands,  2 for system calls, 3 for
  71. functions, 4 for devices, 5 for file formats, 6 for games, 7 for
  72. miscellaneous information, and 8 for administrator commands.  This works
  73. best if you put your Perl man pages in a separate tree, like
  74. F</usr/local/perl/man/>.  By default, section 1 will be used
  75. unless the file ends in F<.pm> in which case section 3 will be selected.
  76.  
  77. =back
  78.  
  79. =head1 Anatomy of a Proper Man Page
  80.  
  81. For those not sure of the proper layout of a man page, here's
  82. an example of the skeleton of a proper man page.  Head of the
  83. major headers should be setout as a C<=head1> directive, and
  84. are historically written in the rather startling ALL UPPER CASE
  85. format, although this is not mandatory.
  86. Minor headers may be included using C<=head2>, and are
  87. typically in mixed case.
  88.  
  89. =over 10
  90.  
  91. =item NAME
  92.  
  93. Mandatory section; should be a comma-separated list of programs or
  94. functions documented by this podpage, such as:
  95.  
  96.     foo, bar - programs to do something
  97.  
  98. =item SYNOPSIS
  99.  
  100. A short usage summary for programs and functions, which
  101. may someday be deemed mandatory.
  102.  
  103. =item DESCRIPTION
  104.  
  105. Long drawn out discussion of the program.  It's a good idea to break this
  106. up into subsections using the C<=head2> directives, like
  107.  
  108.     =head2 A Sample Subection
  109.  
  110.     =head2 Yet Another Sample Subection
  111.  
  112. =item OPTIONS
  113.  
  114. Some people make this separate from the description.
  115.  
  116. =item RETURN VALUE
  117.  
  118. What the program or function returns if successful.
  119.  
  120. =item ERRORS
  121.  
  122. Exceptions, return codes, exit stati, and errno settings.
  123.  
  124. =item EXAMPLES
  125.  
  126. Give some example uses of the program.
  127.  
  128. =item ENVIRONMENT
  129.  
  130. Envariables this program might care about.
  131.  
  132. =item FILES
  133.  
  134. All files used by the program.  You should probably use the FE<lt>E<gt>
  135. for these.
  136.  
  137. =item SEE ALSO
  138.  
  139. Other man pages to check out, like man(1), man(7), makewhatis(8), or catman(8).
  140.  
  141. =item NOTES
  142.  
  143. Miscellaneous commentary.
  144.  
  145. =item CAVEATS
  146.  
  147. Things to take special care with; sometimes called WARNINGS.
  148.  
  149. =item DIAGNOSTICS
  150.  
  151. All possible messages the program can print out--and
  152. what they mean.
  153.  
  154. =item BUGS
  155.  
  156. Things that are broken or just don't work quite right.
  157.  
  158. =item RESTRICTIONS
  159.  
  160. Bugs you don't plan to fix :-)
  161.  
  162. =item AUTHOR
  163.  
  164. Who wrote it (or AUTHORS if multiple).
  165.  
  166. =item HISTORY
  167.  
  168. Programs derived from other sources sometimes have this, or
  169. you might keep a modification long here.
  170.  
  171. =back
  172.  
  173. =head1 EXAMPLES
  174.  
  175.     pod2man program > program.1
  176.     pod2man some_module.pm > /usr/perl/man/man3/some_module.3
  177.     pod2man --section=7 note.pod > note.7
  178.  
  179. =head1 DIAGNOSTICS
  180.  
  181. The following diagnostics are generated by B<pod2man>.  Items
  182. marked "(W)" are non-fatal, whereas the "(F)" errors will cause
  183. B<pod2man> to immediately exit with a non-zero status.
  184.  
  185. =over 4
  186.  
  187. =item bad option in paragraph %d of %s: ``%s'' should be [%s]<%s>
  188.  
  189. (W) If you start include an option, you should set it off
  190. as bold, italic, or code.
  191.  
  192. =item can't open %s: %s
  193.  
  194. (F) The input file wasn't available for the given reason.
  195.  
  196. =item high bit char in input stream
  197.  
  198. (W) You can't use high-bit characters in the input stream,
  199. because the translator uses them for its own nefarious purposes.
  200. Use an HTML entity in angle brackets instead.
  201.  
  202. =item Improper man page - no dash in NAME header in paragraph %d of %s
  203.  
  204. (W) The NAME header did not have an isolated dash in it.  This is
  205. considered important.
  206.  
  207. =item Invalid man page - no NAME line in %s
  208.  
  209. (F) You did not include a NAME header, which is essential.
  210.  
  211. =item roff font should be 1 or 2 chars, not `%s'  (F)
  212.  
  213. (F) The font specified with the C<--fixed> option was not
  214. a one- or two-digit roff font.
  215.  
  216. =item %s is missing required section: %s
  217.  
  218. (W) Required sections include NAME, DESCRIPTION, and if you're
  219. using a section starting with a 3, also a SYNOPSIS.  Actually,
  220. not having a NAME is a fatal.
  221.  
  222. =item Unknown escape: %s in %s
  223.  
  224. (W) An unknown HTML entity (probably for an 8-bit character) was given via
  225. a C<E<lt>E<gt>> directive.  Besides amp, lt, gt, and quot, recognized
  226. entities are Aacute, aacute, Acirc, acirc, AElig, aelig, Agrave, agrave,
  227. Aring, aring, Atilde, atilde, Auml, auml, Ccedil, ccedil, Eacute, eacute,
  228. Ecirc, ecirc, Egrave, egrave, ETH, eth, Euml, euml, Iacute, iacute, Icirc,
  229. icirc, Igrave, igrave, Iuml, iuml, Ntilde, ntilde, Oacute, oacute, Ocirc,
  230. ocirc, Ograve, ograve, Oslash, oslash, Otilde, otilde, Ouml, ouml, szlig,
  231. THORN, thorn, Uacute, uacute, Ucirc, ucirc, Ugrave, ugrave, Uuml, uuml,
  232. Yacute, yacute, and yuml.
  233.  
  234. =item Unmatched =back
  235.  
  236. (W) You have a C<=back> without a corresponding C<=over>.
  237.  
  238. =item Unrecognized pod directive: %s
  239.  
  240. (W) You specified a pod directive that isn't in the known list of
  241. C<=head1>, C<=head2>, C<=item>, C<=over>, C<=back>, or C<=cut>.
  242.  
  243.  
  244. =back
  245.  
  246. =head1 NOTES
  247.  
  248. If you would like to print out a lot of man page continuously, you
  249. probably want to set the C and D registers to set contiguous page
  250. numbering and even/odd paging, at least one some versions of man(7).
  251. Settting the F register will get you some additional experimental
  252. indexing:
  253.  
  254.     troff -man -rC1 -rD1 -rF1 perl.1 perldata.1 perlsyn.1 ...
  255.  
  256. The indexing merely outputs messages via C<.tm> for each
  257. major page, section, subsection, item, and any C<XE<lt>E<gt>>
  258. directives.
  259.  
  260.  
  261. =head1 RESTRICTIONS
  262.  
  263. You shouldn't use 8-bit characters in the input stream, as these
  264. will be used by the translator.
  265.  
  266. =head1 BUGS
  267.  
  268. The =over and =back directives don't really work right.  They
  269. take absolute positions instead of offsets, don't nest well, and
  270. making people count is suboptimal in any event.
  271.  
  272. =head1 AUTHORS
  273.  
  274. Original prototype by Larry Wall, but so massively hacked over by
  275. Tom Christiansen such that Larry probably doesn't recognize it anymore.
  276.  
  277. =cut
  278.  
  279. $/ = "";
  280. $cutting = 1;
  281.  
  282. ($version,$patch) = `\PATH=.:..:\$PATH; perl -v` =~ /version (\d\.\d{3}(?: +)(?:\S+)?)(?:.*patchlevel (\d\S*))?/s;
  283. $DEF_RELEASE  = "perl $version";
  284. $DEF_RELEASE .= ", patch $patch" if $patch;
  285.  
  286.  
  287. sub makedate {
  288.     my $secs = shift;
  289.     my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secs);
  290.     my $mname = (qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec})[$mon];
  291.     return "$mday/$mname/$year";
  292. }
  293.  
  294. use Getopt::Long;
  295.  
  296. $DEF_SECTION = 1;
  297. $DEF_CENTER = "User Contributed Perl Documentation";
  298. $STD_CENTER = "Perl Programmers Reference Guide