Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1195 lines
29 KiB

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S "%0" %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. goto endofperl
  11. @rem ';
  12. #!perl
  13. #line 14
  14. eval 'exec P:\Apps\ActivePerl\temp\bin\MSWin32-x86-object\perl.exe -S $0 ${1+"$@"}'
  15. if $running_under_some_shell;
  16. $DEF_PM_SECTION = '3' || '3';
  17. =head1 NAME
  18. pod2man - translate embedded Perl pod directives into man pages
  19. =head1 SYNOPSIS
  20. B<pod2man>
  21. [ B<--section=>I<manext> ]
  22. [ B<--release=>I<relpatch> ]
  23. [ B<--center=>I<string> ]
  24. [ B<--date=>I<string> ]
  25. [ B<--fixed=>I<font> ]
  26. [ B<--official> ]
  27. [ B<--lax> ]
  28. I<inputfile>
  29. =head1 DESCRIPTION
  30. B<pod2man> converts its input file containing embedded pod directives (see
  31. L<perlpod>) into nroff source suitable for viewing with nroff(1) or
  32. troff(1) using the man(7) macro set.
  33. Besides the obvious pod conversions, B<pod2man> also takes care of
  34. func(), func(n), and simple variable references like $foo or @bar so
  35. you don't have to use code escapes for them; complex expressions like
  36. C<$fred{'stuff'}> will still need to be escaped, though. Other nagging
  37. little roffish things that it catches include translating the minus in
  38. something like foo-bar, making a long dash--like this--into a real em
  39. dash, fixing up "paired quotes", putting a little space after the
  40. parens in something like func(), making C++ and PI look right, making
  41. double underbars have a little tiny space between them, making ALLCAPS
  42. a teeny bit smaller in troff(1), and escaping backslashes so you don't
  43. have to.
  44. =head1 OPTIONS
  45. =over 8
  46. =item center
  47. Set the centered header to a specific string. The default is
  48. "User Contributed Perl Documentation", unless the C<--official> flag is
  49. given, in which case the default is "Perl Programmers Reference Guide".
  50. =item date
  51. Set the left-hand footer string to this value. By default,
  52. the modification date of the input file will be used.
  53. =item fixed
  54. The fixed font to use for code refs. Defaults to CW.
  55. =item official
  56. Set the default header to indicate that this page is of
  57. the standard release in case C<--center> is not given.
  58. =item release
  59. Set the centered footer. By default, this is the current
  60. perl release.
  61. =item section
  62. Set the section for the C<.TH> macro. The standard conventions on
  63. sections are to use 1 for user commands, 2 for system calls, 3 for
  64. functions, 4 for devices, 5 for file formats, 6 for games, 7 for
  65. miscellaneous information, and 8 for administrator commands. This works
  66. best if you put your Perl man pages in a separate tree, like
  67. F</usr/local/perl/man/>. By default, section 1 will be used
  68. unless the file ends in F<.pm> in which case section 3 will be selected.
  69. =item lax
  70. Don't complain when required sections aren't present.
  71. =back
  72. =head1 Anatomy of a Proper Man Page
  73. For those not sure of the proper layout of a man page, here's
  74. an example of the skeleton of a proper man page. Head of the
  75. major headers should be setout as a C<=head1> directive, and
  76. are historically written in the rather startling ALL UPPER CASE
  77. format, although this is not mandatory.
  78. Minor headers may be included using C<=head2>, and are
  79. typically in mixed case.
  80. =over 10
  81. =item NAME
  82. Mandatory section; should be a comma-separated list of programs or
  83. functions documented by this podpage, such as:
  84. foo, bar - programs to do something
  85. =item SYNOPSIS
  86. A short usage summary for programs and functions, which
  87. may someday be deemed mandatory.
  88. =item DESCRIPTION
  89. Long drawn out discussion of the program. It's a good idea to break this
  90. up into subsections using the C<=head2> directives, like
  91. =head2 A Sample Subection
  92. =head2 Yet Another Sample Subection
  93. =item OPTIONS
  94. Some people make this separate from the description.
  95. =item RETURN VALUE
  96. What the program or function returns if successful.
  97. =item ERRORS
  98. Exceptions, return codes, exit stati, and errno settings.
  99. =item EXAMPLES
  100. Give some example uses of the program.
  101. =item ENVIRONMENT
  102. Envariables this program might care about.
  103. =item FILES
  104. All files used by the program. You should probably use the FE<lt>E<gt>
  105. for these.
  106. =item SEE ALSO
  107. Other man pages to check out, like man(1), man(7), makewhatis(8), or catman(8).
  108. =item NOTES
  109. Miscellaneous commentary.
  110. =item CAVEATS
  111. Things to take special care with; sometimes called WARNINGS.
  112. =item DIAGNOSTICS
  113. All possible messages the program can print out--and
  114. what they mean.
  115. =item BUGS
  116. Things that are broken or just don't work quite right.
  117. =item RESTRICTIONS
  118. Bugs you don't plan to fix :-)
  119. =item AUTHOR
  120. Who wrote it (or AUTHORS if multiple).
  121. =item HISTORY
  122. Programs derived from other sources sometimes have this, or
  123. you might keep a modification log here.
  124. =back
  125. =head1 EXAMPLES
  126. pod2man program > program.1
  127. pod2man some_module.pm > /usr/perl/man/man3/some_module.3
  128. pod2man --section=7 note.pod > note.7
  129. =head1 DIAGNOSTICS
  130. The following diagnostics are generated by B<pod2man>. Items
  131. marked "(W)" are non-fatal, whereas the "(F)" errors will cause
  132. B<pod2man> to immediately exit with a non-zero status.
  133. =over 4
  134. =item bad option in paragraph %d of %s: ``%s'' should be [%s]<%s>
  135. (W) If you start include an option, you should set it off
  136. as bold, italic, or code.
  137. =item can't open %s: %s
  138. (F) The input file wasn't available for the given reason.
  139. =item Improper man page - no dash in NAME header in paragraph %d of %s
  140. (W) The NAME header did not have an isolated dash in it. This is
  141. considered important.
  142. =item Invalid man page - no NAME line in %s
  143. (F) You did not include a NAME header, which is essential.
  144. =item roff font should be 1 or 2 chars, not `%s' (F)
  145. (F) The font specified with the C<--fixed> option was not
  146. a one- or two-digit roff font.
  147. =item %s is missing required section: %s
  148. (W) Required sections include NAME, DESCRIPTION, and if you're
  149. using a section starting with a 3, also a SYNOPSIS. Actually,
  150. not having a NAME is a fatal.
  151. =item Unknown escape: %s in %s
  152. (W) An unknown HTML entity (probably for an 8-bit character) was given via
  153. a C<EE<lt>E<gt>> directive. Besides amp, lt, gt, and quot, recognized
  154. entities are Aacute, aacute, Acirc, acirc, AElig, aelig, Agrave, agrave,
  155. Aring, aring, Atilde, atilde, Auml, auml, Ccedil, ccedil, Eacute, eacute,
  156. Ecirc, ecirc, Egrave, egrave, ETH, eth, Euml, euml, Iacute, iacute, Icirc,
  157. icirc, Igrave, igrave, Iuml, iuml, Ntilde, ntilde, Oacute, oacute, Ocirc,
  158. ocirc, Ograve, ograve, Oslash, oslash, Otilde, otilde, Ouml, ouml, szlig,
  159. THORN, thorn, Uacute, uacute, Ucirc, ucirc, Ugrave, ugrave, Uuml, uuml,
  160. Yacute, yacute, and yuml.
  161. =item Unmatched =back
  162. (W) You have a C<=back> without a corresponding C<=over>.
  163. =item Unrecognized pod directive: %s
  164. (W) You specified a pod directive that isn't in the known list of
  165. C<=head1>, C<=head2>, C<=item>, C<=over>, C<=back>, or C<=cut>.
  166. =back
  167. =head1 NOTES
  168. If you would like to print out a lot of man page continuously, you
  169. probably want to set the C and D registers to set contiguous page
  170. numbering and even/odd paging, at least on some versions of man(7).
  171. Settting the F register will get you some additional experimental
  172. indexing:
  173. troff -man -rC1 -rD1 -rF1 perl.1 perldata.1 perlsyn.1 ...
  174. The indexing merely outputs messages via C<.tm> for each
  175. major page, section, subsection, item, and any C<XE<lt>E<gt>>
  176. directives.
  177. =head1 RESTRICTIONS
  178. None at this time.
  179. =head1 BUGS
  180. The =over and =back directives don't really work right. They
  181. take absolute positions instead of offsets, don't nest well, and
  182. making people count is suboptimal in any event.
  183. =head1 AUTHORS
  184. Original prototype by Larry Wall, but so massively hacked over by
  185. Tom Christiansen such that Larry probably doesn't recognize it anymore.
  186. =cut
  187. $/ = "";
  188. $cutting = 1;
  189. @Indices = ();
  190. # We try first to get the version number from a local binary, in case we're
  191. # running an installed version of Perl to produce documentation from an
  192. # uninstalled newer version's pod files.
  193. if ($^O ne 'plan9' and $^O ne 'dos' and $^O ne 'os2' and $^O ne 'MSWin32') {
  194. my $perl = (-x './perl' && -f './perl' ) ?
  195. './perl' :
  196. ((-x '../perl' && -f '../perl') ?
  197. '../perl' :
  198. '');
  199. ($version,$patch) = `$perl -e 'print $]'` =~ /^(\d\.\d{3})(\d{2})?/ if $perl;
  200. }
  201. # No luck; we'll just go with the running Perl's version
  202. ($version,$patch) = $] =~ /^(.{5})(\d{2})?/ unless $version;
  203. $DEF_RELEASE = "perl $version";
  204. $DEF_RELEASE .= ", patch $patch" if $patch;
  205. sub makedate {
  206. my $secs = shift;
  207. my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secs);
  208. my $mname = (qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec})[$mon];
  209. $year += 1900;
  210. return "$mday/$mname/$year";
  211. }
  212. use Getopt::Long;
  213. $DEF_SECTION = 1;
  214. $DEF_CENTER = "User Contributed Perl Documentation";
  215. $STD_CENTER = "Perl Programmers Reference Guide";
  216. $DEF_FIXED = 'CW';
  217. $DEF_LAX = 0;
  218. sub usage {
  219. warn "$0: @_\n" if @_;
  220. die <<EOF;
  221. usage: $0 [options] podpage
  222. Options are:
  223. --section=manext (default "$DEF_SECTION")
  224. --release=relpatch (default "$DEF_RELEASE")
  225. --center=string (default "$DEF_CENTER")
  226. --date=string (default "$DEF_DATE")
  227. --fixed=font (default "$DEF_FIXED")
  228. --official (default NOT)
  229. --lax (default NOT)
  230. EOF
  231. }
  232. $uok = GetOptions( qw(
  233. section=s
  234. release=s
  235. center=s
  236. date=s
  237. fixed=s
  238. official
  239. lax
  240. help));
  241. $DEF_DATE = makedate((stat($ARGV[0]))[9] || time());
  242. usage("Usage error!") unless $uok;
  243. usage() if $opt_help;
  244. usage("Need one and only one podpage argument") unless @ARGV == 1;
  245. $section = $opt_section || ($ARGV[0] =~ /\.pm$/
  246. ? $DEF_PM_SECTION : $DEF_SECTION);
  247. $RP = $opt_release || $DEF_RELEASE;
  248. $center = $opt_center || ($opt_official ? $STD_CENTER : $DEF_CENTER);
  249. $lax = $opt_lax || $DEF_LAX;
  250. $CFont = $opt_fixed || $DEF_FIXED;
  251. if (length($CFont) == 2) {
  252. $CFont_embed = "\\f($CFont";
  253. }
  254. elsif (length($CFont) == 1) {
  255. $CFont_embed = "\\f$CFont";
  256. }
  257. else {
  258. die "roff font should be 1 or 2 chars, not `$CFont_embed'";
  259. }
  260. $date = $opt_date || $DEF_DATE;
  261. for (qw{NAME DESCRIPTION}) {
  262. # for (qw{NAME DESCRIPTION AUTHOR}) {
  263. $wanna_see{$_}++;
  264. }
  265. $wanna_see{SYNOPSIS}++ if $section =~ /^3/;
  266. $name = @ARGV ? $ARGV[0] : "<STDIN>";
  267. $Filename = $name;
  268. if ($section =~ /^1/) {
  269. require File::Basename;
  270. $name = uc File::Basename::basename($name);
  271. }
  272. $name =~ s/\.(pod|p[lm])$//i;
  273. # Lose everything up to the first of
  274. # */lib/*perl* standard or site_perl module
  275. # */*perl*/lib from -D prefix=/opt/perl
  276. # */*perl*/ random module hierarchy
  277. # which works.
  278. $name =~ s-//+-/-g;
  279. if ($name =~ s-^.*?/lib/[^/]*perl[^/]*/--i
  280. or $name =~ s-^.*?/[^/]*perl[^/]*/lib/--i
  281. or $name =~ s-^.*?/[^/]*perl[^/]*/--i) {
  282. # Lose ^site(_perl)?/.
  283. $name =~ s-^site(_perl)?/--;
  284. # Lose ^arch/. (XXX should we use Config? Just for archname?)
  285. $name =~ s~^(.*-$^O|$^O-.*)/~~o;
  286. # Lose ^version/.
  287. $name =~ s-^\d+\.\d+/--;
  288. }
  289. # Translate Getopt/Long to Getopt::Long, etc.
  290. $name =~ s(/)(::)g;
  291. if ($name ne 'something') {
  292. FCHECK: {
  293. open(F, "< $ARGV[0]") || die "can't open $ARGV[0]: $!";
  294. while (<F>) {
  295. next unless /^=\b/;
  296. if (/^=head1\s+NAME\s*$/) { # an /m would forgive mistakes
  297. $_ = <F>;
  298. unless (/\s*-+\s+/) {
  299. $oops++;
  300. warn "$0: Improper man page - no dash in NAME header in paragraph $. of $ARGV[0]\n"
  301. } else {
  302. my @n = split /\s+-+\s+/;
  303. if (@n != 2) {
  304. $oops++;
  305. warn "$0: Improper man page - malformed NAME header in paragraph $. of $ARGV[0]\n"
  306. }
  307. else {
  308. %namedesc = @n;
  309. }
  310. }
  311. last FCHECK;
  312. }
  313. next if /^=cut\b/; # DB_File and Net::Ping have =cut before NAME
  314. next if /^=pod\b/; # It is OK to have =pod before NAME
  315. die "$0: Invalid man page - 1st pod line is not NAME in $ARGV[0]\n" unless $lax;
  316. }
  317. die "$0: Invalid man page - no documentation in $ARGV[0]\n" unless $lax;
  318. }
  319. close F;
  320. }
  321. print <<"END";
  322. .rn '' }`
  323. ''' \$RCSfile\$\$Revision\$\$Date\$
  324. '''
  325. ''' \$Log\$
  326. '''
  327. .de Sh
  328. .br
  329. .if t .Sp
  330. .ne 5
  331. .PP
  332. \\fB\\\\\$1\\fR
  333. .PP
  334. ..
  335. .de Sp
  336. .if t .sp .5v
  337. .if n .sp
  338. ..
  339. .de Ip
  340. .br
  341. .ie \\\\n(.\$>=3 .ne \\\\\$3
  342. .el .ne 3
  343. .IP "\\\\\$1" \\\\\$2
  344. ..
  345. .de Vb
  346. .ft $CFont
  347. .nf
  348. .ne \\\\\$1
  349. ..
  350. .de Ve
  351. .ft R
  352. .fi
  353. ..
  354. '''
  355. '''
  356. ''' Set up \\*(-- to give an unbreakable dash;
  357. ''' string Tr holds user defined translation string.
  358. ''' Bell System Logo is used as a dummy character.
  359. '''
  360. .tr \\(*W-|\\(bv\\*(Tr
  361. .ie n \\{\\
  362. .ds -- \\(*W-
  363. .ds PI pi
  364. .if (\\n(.H=4u)&(1m=24u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-12u'-\\" diablo 10 pitch
  365. .if (\\n(.H=4u)&(1m=20u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-8u'-\\" diablo 12 pitch
  366. .ds L" ""
  367. .ds R" ""
  368. ''' \\*(M", \\*(S", \\*(N" and \\*(T" are the equivalent of
  369. ''' \\*(L" and \\*(R", except that they are used on ".xx" lines,
  370. ''' such as .IP and .SH, which do another additional levels of
  371. ''' double-quote interpretation
  372. .ds M" """
  373. .ds S" """
  374. .ds N" """""
  375. .ds T" """""
  376. .ds L' '
  377. .ds R' '
  378. .ds M' '
  379. .ds S' '
  380. .ds N' '
  381. .ds T' '
  382. 'br\\}
  383. .el\\{\\
  384. .ds -- \\(em\\|
  385. .tr \\*(Tr
  386. .ds L" ``
  387. .ds R" ''
  388. .ds M" ``
  389. .ds S" ''
  390. .ds N" ``
  391. .ds T" ''
  392. .ds L' `
  393. .ds R' '
  394. .ds M' `
  395. .ds S' '
  396. .ds N' `
  397. .ds T' '
  398. .ds PI \\(*p
  399. 'br\\}
  400. END
  401. print <<'END';
  402. .\" If the F register is turned on, we'll generate
  403. .\" index entries out stderr for the following things:
  404. .\" TH Title
  405. .\" SH Header
  406. .\" Sh Subsection
  407. .\" Ip Item
  408. .\" X<> Xref (embedded
  409. .\" Of course, you have to process the output yourself
  410. .\" in some meaninful fashion.
  411. .if \nF \{
  412. .de IX
  413. .tm Index:\\$1\t\\n%\t"\\$2"
  414. ..
  415. .nr % 0
  416. .rr F
  417. .\}
  418. END
  419. print <<"END";
  420. .TH $name $section "$RP" "$date" "$center"
  421. .UC
  422. END
  423. push(@Indices, qq{.IX Title "$name $section"});
  424. while (($name, $desc) = each %namedesc) {
  425. for ($name, $desc) { s/^\s+//; s/\s+$//; }
  426. push(@Indices, qq(.IX Name "$name - $desc"\n));
  427. }
  428. print <<'END';
  429. .if n .hy 0
  430. .if n .na
  431. .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
  432. .de CQ \" put $1 in typewriter font
  433. END
  434. print ".ft $CFont\n";
  435. print <<'END';
  436. 'if n "\c
  437. 'if t \\&\\$1\c
  438. 'if n \\&\\$1\c
  439. 'if n \&"
  440. \\&\\$2 \\$3 \\$4 \\$5 \\$6 \\$7
  441. '.ft R
  442. ..
  443. .\" @(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2
  444. . \" AM - accent mark definitions
  445. .bd B 3
  446. . \" fudge factors for nroff and troff
  447. .if n \{\
  448. . ds #H 0
  449. . ds #V .8m
  450. . ds #F .3m
  451. . ds #[ \f1
  452. . ds #] \fP
  453. .\}
  454. .if t \{\
  455. . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
  456. . ds #V .6m
  457. . ds #F 0
  458. . ds #[ \&
  459. . ds #] \&
  460. .\}
  461. . \" simple accents for nroff and troff
  462. .if n \{\
  463. . ds ' \&
  464. . ds ` \&
  465. . ds ^ \&
  466. . ds , \&
  467. . ds ~ ~
  468. . ds ? ?
  469. . ds ! !
  470. . ds /
  471. . ds q
  472. .\}
  473. .if t \{\
  474. . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
  475. . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
  476. . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
  477. . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
  478. . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
  479. . ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
  480. . ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
  481. . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
  482. . ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
  483. .\}
  484. . \" troff and (daisy-wheel) nroff accents
  485. .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
  486. .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
  487. .ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
  488. .ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
  489. .ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
  490. .ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
  491. .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
  492. .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
  493. .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
  494. .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
  495. .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
  496. .ds ae a\h'-(\w'a'u*4/10)'e
  497. .ds Ae A\h'-(\w'A'u*4/10)'E
  498. .ds oe o\h'-(\w'o'u*4/10)'e
  499. .ds Oe O\h'-(\w'O'u*4/10)'E
  500. . \" corrections for vroff
  501. .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
  502. .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
  503. . \" for low resolution devices (crt and lpr)
  504. .if \n(.H>23 .if \n(.V>19 \
  505. \{\
  506. . ds : e
  507. . ds 8 ss
  508. . ds v \h'-1'\o'\(aa\(ga'
  509. . ds _ \h'-1'^
  510. . ds . \h'-1'.
  511. . ds 3 3
  512. . ds o a
  513. . ds d- d\h'-1'\(ga
  514. . ds D- D\h'-1'\(hy
  515. . ds th \o'bp'
  516. . ds Th \o'LP'
  517. . ds ae ae
  518. . ds Ae AE
  519. . ds oe oe
  520. . ds Oe OE
  521. .\}
  522. .rm #[ #] #H #V #F C
  523. END
  524. $indent = 0;
  525. $begun = "";
  526. # Unrolling [^A-Z>]|[A-Z](?!<) gives: // MRE pp 165.
  527. my $nonest = '(?:[^A-Z>]*(?:[A-Z](?!<)[^A-Z>]*)*)';
  528. while (<>) {
  529. if ($cutting) {
  530. next unless /^=/;
  531. $cutting = 0;
  532. }
  533. if ($begun) {
  534. if (/^=end\s+$begun/) {
  535. $begun = "";
  536. }
  537. elsif ($begun =~ /^(roff|man)$/) {
  538. print STDOUT $_;
  539. }
  540. next;
  541. }
  542. chomp;
  543. # Translate verbatim paragraph
  544. if (/^\s/) {
  545. @lines = split(/\n/);
  546. for (@lines) {
  547. 1 while s
  548. {^( [^\t]* ) \t ( \t* ) }
  549. { $1 . ' ' x (8 - (length($1)%8) + 8 * (length($2))) }ex;
  550. s/\\/\\e/g;
  551. s/\A/\\&/s;
  552. }
  553. $lines = @lines;
  554. makespace() unless $verbatim++;
  555. print ".Vb $lines\n";
  556. print join("\n", @lines), "\n";
  557. print ".Ve\n";
  558. $needspace = 0;
  559. next;
  560. }
  561. $verbatim = 0;
  562. if (/^=for\s+(\S+)\s*/s) {
  563. if ($1 eq "man" or $1 eq "roff") {
  564. print STDOUT $',"\n\n";
  565. } else {
  566. # ignore unknown for
  567. }
  568. next;
  569. }
  570. elsif (/^=begin\s+(\S+)\s*/s) {
  571. $begun = $1;
  572. if ($1 eq "man" or $1 eq "roff") {
  573. print STDOUT $'."\n\n";
  574. }
  575. next;
  576. }
  577. # check for things that'll hosed our noremap scheme; affects $_
  578. init_noremap();
  579. if (!/^=item/) {
  580. # trofficate backslashes; must do it before what happens below
  581. s/\\/noremap('\\e')/ge;
  582. # protect leading periods and quotes against *roff
  583. # mistaking them for directives
  584. s/^(?:[A-Z]<)?[.']/\\&$&/gm;
  585. # first hide the escapes in case we need to
  586. # intuit something and get it wrong due to fmting
  587. 1 while s/([A-Z]<$nonest>)/noremap($1)/ge;
  588. # func() is a reference to a perl function
  589. s{
  590. \b
  591. (
  592. [:\w]+ \(\)
  593. )
  594. } {I<$1>}gx;
  595. # func(n) is a reference to a perl function or a man page
  596. s{
  597. ([:\w]+)
  598. (
  599. \( [^\051]+ \)
  600. )
  601. } {I<$1>\\|$2}gx;
  602. # convert simple variable references
  603. s/(\s+)([\$\@%][\w:]+)(?!\()/${1}C<$2>/g;
  604. if (m{ (
  605. [\-\w]+
  606. \(
  607. [^\051]*?
  608. [\@\$,]
  609. [^\051]*?
  610. \)
  611. )
  612. }x && $` !~ /([LCI]<[^<>]*|-)$/ && !/^=\w/)
  613. {
  614. warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [LCI]<$1>\n";
  615. $oops++;
  616. }
  617. while (/(-[a-zA-Z])\b/g && $` !~ /[\w\-]$/) {
  618. warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [CB]<$1>\n";
  619. $oops++;
  620. }
  621. # put it back so we get the <> processed again;
  622. clear_noremap(0); # 0 means leave the E's
  623. } else {
  624. # trofficate backslashes
  625. s/\\/noremap('\\e')/ge;
  626. }
  627. # need to hide E<> first; they're processed in clear_noremap
  628. s/(E<[^<>]+>)/noremap($1)/ge;
  629. $maxnest = 10;
  630. while ($maxnest-- && /[A-Z]</) {
  631. # can't do C font here
  632. s/([BI])<($nonest)>/font($1) . $2 . font('R')/eg;
  633. # files and filelike refs in italics
  634. s/F<($nonest)>/I<$1>/g;
  635. # no break -- usually we want C<> for this
  636. s/S<($nonest)>/nobreak($1)/eg;
  637. # LREF: a la HREF L<show this text|man/section>
  638. s:L<([^|>]+)\|[^>]+>:$1:g;
  639. # LREF: a manpage(3f)
  640. s:L<([a-zA-Z][^\s\/]+)(\([^\)]+\))?>:the I<$1>$2 manpage:g;
  641. # LREF: an =item on another manpage
  642. s{
  643. L<
  644. ([^/]+)
  645. /
  646. (
  647. [:\w]+
  648. (\(\))?
  649. )
  650. >
  651. } {the C<$2> entry in the I<$1> manpage}gx;
  652. # LREF: an =item on this manpage
  653. s{
  654. ((?:
  655. L<
  656. /
  657. (
  658. [:\w]+
  659. (\(\))?
  660. )
  661. >
  662. (,?\s+(and\s+)?)?
  663. )+)
  664. } { internal_lrefs($1) }gex;
  665. # LREF: a =head2 (head1?), maybe on a manpage, maybe right here
  666. # the "func" can disambiguate
  667. s{
  668. L<
  669. (?:
  670. ([a-zA-Z]\S+?) /
  671. )?
  672. "?(.*?)"?
  673. >
  674. }{
  675. do {
  676. $1 # if no $1, assume it means on this page.
  677. ? "the section on I<$2> in the I<$1> manpage"
  678. : "the section on I<$2>"
  679. }
  680. }gesx; # s in case it goes over multiple lines, so . matches \n
  681. s/Z<>/\\&/g;
  682. # comes last because not subject to reprocessing
  683. s/C<($nonest)>/noremap("${CFont_embed}${1}\\fR")/eg;
  684. }
  685. if (s/^=//) {
  686. $needspace = 0; # Assume this.
  687. s/\n/ /g;
  688. ($Cmd, $_) = split(' ', $_, 2);
  689. $dotlevel = 1;
  690. if ($Cmd eq 'head1') {
  691. $dotlevel = 1;
  692. }
  693. elsif ($Cmd eq 'head2') {
  694. $dotlevel = 1;
  695. }
  696. elsif ($Cmd eq 'item') {
  697. $dotlevel = 2;
  698. }
  699. if (defined $_) {
  700. &escapes($dotlevel);
  701. s/"/""/g;
  702. }
  703. clear_noremap(1);
  704. if ($Cmd eq 'cut') {
  705. $cutting = 1;
  706. }
  707. elsif ($Cmd eq 'head1') {
  708. s/\s+$//;
  709. delete $wanna_see{$_} if exists $wanna_see{$_};
  710. print qq{.SH "$_"\n};
  711. push(@Indices, qq{.IX Header "$_"\n});
  712. }
  713. elsif ($Cmd eq 'head2') {
  714. print qq{.Sh "$_"\n};
  715. push(@Indices, qq{.IX Subsection "$_"\n});
  716. }
  717. elsif ($Cmd eq 'over') {
  718. push(@indent,$indent);
  719. $indent += ($_ + 0) || 5;
  720. }
  721. elsif ($Cmd eq 'back') {
  722. $indent = pop(@indent);
  723. warn "$0: Unmatched =back in paragraph $. of $ARGV\n" unless defined $indent;
  724. $needspace = 1;
  725. }
  726. elsif ($Cmd eq 'item') {
  727. s/^\*( |$)/\\(bu$1/g;
  728. # if you know how to get ":s please do
  729. s/\\\*\(L"([^"]+?)\\\*\(R"/'$1'/g;
  730. s/\\\*\(L"([^"]+?)""/'$1'/g;
  731. s/[^"]""([^"]+?)""[^"]/'$1'/g;
  732. # here do something about the $" in perlvar?
  733. print STDOUT qq{.Ip "$_" $indent\n};
  734. push(@Indices, qq{.IX Item "$_"\n});
  735. }
  736. elsif ($Cmd eq 'pod') {
  737. # this is just a comment
  738. }
  739. else {
  740. warn "$0: Unrecognized pod directive in paragraph $. of $ARGV: $Cmd\n";
  741. }
  742. }
  743. else {
  744. if ($needspace) {
  745. &makespace;
  746. }
  747. &escapes(0);
  748. clear_noremap(1);
  749. print $_, "\n";
  750. $needspace = 1;
  751. }
  752. }
  753. print <<"END";
  754. .rn }` ''
  755. END
  756. if (%wanna_see && !$lax) {
  757. @missing = keys %wanna_see;
  758. warn "$0: $Filename is missing required section"
  759. . (@missing > 1 && "s")
  760. . ": @missing\n";
  761. $oops++;
  762. }
  763. foreach (@Indices) { print "$_\n"; }
  764. exit;
  765. #exit ($oops != 0);
  766. #########################################################################
  767. sub nobreak {
  768. my $string = shift;
  769. $string =~ s/ /\\ /g;
  770. $string;
  771. }
  772. sub escapes {
  773. my $indot = shift;
  774. s/X<(.*?)>/mkindex($1)/ge;
  775. # translate the minus in foo-bar into foo\-bar for roff
  776. s/([^0-9a-z-])-([^-])/$1\\-$2/g;
  777. # make -- into the string version \*(-- (defined above)
  778. s/\b--\b/\\*(--/g;
  779. s/"--([^"])/"\\*(--$1/g; # should be a better way
  780. s/([^"])--"/$1\\*(--"/g;
  781. # fix up quotes; this is somewhat tricky
  782. my $dotmacroL = 'L';
  783. my $dotmacroR = 'R';
  784. if ( $indot == 1 ) {
  785. $dotmacroL = 'M';
  786. $dotmacroR = 'S';
  787. }
  788. elsif ( $indot >= 2 ) {
  789. $dotmacroL = 'N';
  790. $dotmacroR = 'T';
  791. }
  792. if (!/""/) {
  793. s/(^|\s)(['"])/noremap("$1\\*($dotmacroL$2")/ge;
  794. s/(['"])($|[\-\s,;\\!?.])/noremap("\\*($dotmacroR$1$2")/ge;
  795. }
  796. #s/(?!")(?:.)--(?!")(?:.)/\\*(--/g;
  797. #s/(?:(?!")(?:.)--(?:"))|(?:(?:")--(?!")(?:.))/\\*(--/g;
  798. # make sure that func() keeps a bit a space tween the parens
  799. ### s/\b\(\)/\\|()/g;
  800. ### s/\b\(\)/(\\|)/g;
  801. # make C++ into \*C+, which is a squinched version (defined above)
  802. s/\bC\+\+/\\*(C+/g;
  803. # make double underbars have a little tiny space between them
  804. s/__/_\\|_/g;
  805. # PI goes to \*(PI (defined above)
  806. s/\bPI\b/noremap('\\*(PI')/ge;
  807. # make all caps a teeny bit smaller, but don't muck with embedded code literals
  808. my $hidCFont = font('C');
  809. if ($Cmd !~ /^head1/) { # SH already makes smaller
  810. # /g isn't enough; 1 while or we'll be off
  811. # 1 while s{
  812. # (?!$hidCFont)(..|^.|^)
  813. # \b
  814. # (
  815. # [A-Z][\/A-Z+:\-\d_$.]+
  816. # )
  817. # (s?)
  818. # \b
  819. # } {$1\\s-1$2\\s0}gmox;
  820. 1 while s{
  821. (?!$hidCFont)(..|^.|^)
  822. (
  823. \b[A-Z]{2,}[\/A-Z+:\-\d_\$]*\b
  824. )
  825. } {
  826. $1 . noremap( '\\s-1' . $2 . '\\s0' )
  827. }egmox;
  828. }
  829. }
  830. # make troff just be normal, but make small nroff get quoted
  831. # decided to just put the quotes in the text; sigh;
  832. sub ccvt {
  833. local($_,$prev) = @_;
  834. noremap(qq{.CQ "$_" \n\\&});
  835. }
  836. sub makespace {
  837. if ($indent) {
  838. print ".Sp\n";
  839. }
  840. else {
  841. print ".PP\n";
  842. }
  843. }
  844. sub mkindex {
  845. my ($entry) = @_;
  846. my @entries = split m:\s*/\s*:, $entry;
  847. push @Indices, ".IX Xref " . join ' ', map {qq("$_")} @entries;
  848. return '';
  849. }
  850. sub font {
  851. local($font) = shift;
  852. return '\\f' . noremap($font);
  853. }
  854. sub noremap {
  855. local($thing_to_hide) = shift;
  856. $thing_to_hide =~ tr/\000-\177/\200-\377/;
  857. return $thing_to_hide;
  858. }
  859. sub init_noremap {
  860. # escape high bit characters in input stream
  861. s/([\200-\377])/"E<".ord($1).">"/ge;
  862. }
  863. sub clear_noremap {
  864. my $ready_to_print = $_[0];
  865. tr/\200-\377/\000-\177/;
  866. # trofficate backslashes
  867. # s/(?!\\e)(?:..|^.|^)\\/\\e/g;
  868. # now for the E<>s, which have been hidden until now
  869. # otherwise the interative \w<> processing would have
  870. # been hosed by the E<gt>
  871. s {
  872. E<
  873. (
  874. ( \d + )
  875. | ( [A-Za-z]+ )
  876. )
  877. >
  878. } {
  879. do {
  880. defined $2
  881. ? chr($2)
  882. :
  883. exists $HTML_Escapes{$3}
  884. ? do { $HTML_Escapes{$3} }
  885. : do {
  886. warn "$0: Unknown escape in paragraph $. of $ARGV: ``$&''\n";
  887. "E<$1>";
  888. }
  889. }
  890. }egx if $ready_to_print;
  891. }
  892. sub internal_lrefs {
  893. local($_) = shift;
  894. local $trailing_and = s/and\s+$// ? "and " : "";
  895. s{L</([^>]+)>}{$1}g;
  896. my(@items) = split( /(?:,?\s+(?:and\s+)?)/ );
  897. my $retstr = "the ";
  898. my $i;
  899. for ($i = 0; $i <= $#items; $i++) {
  900. $retstr .= "C<$items[$i]>";
  901. $retstr .= ", " if @items > 2 && $i != $#items;
  902. $retstr .= " and " if $i+2 == @items;
  903. }
  904. $retstr .= " entr" . ( @items > 1 ? "ies" : "y" )
  905. . " elsewhere in this document";
  906. # terminal space to avoid words running together (pattern used
  907. # strips terminal spaces)
  908. $retstr .= " " if length $trailing_and;
  909. $retstr .= $trailing_and;
  910. return $retstr;
  911. }
  912. BEGIN {
  913. %HTML_Escapes = (
  914. 'amp' => '&', # ampersand
  915. 'lt' => '<', # left chevron, less-than
  916. 'gt' => '>', # right chevron, greater-than
  917. 'quot' => '"', # double quote
  918. "Aacute" => "A\\*'", # capital A, acute accent
  919. "aacute" => "a\\*'", # small a, acute accent
  920. "Acirc" => "A\\*^", # capital A, circumflex accent
  921. "acirc" => "a\\*^", # small a, circumflex accent
  922. "AElig" => '\*(AE', # capital AE diphthong (ligature)
  923. "aelig" => '\*(ae', # small ae diphthong (ligature)
  924. "Agrave" => "A\\*`", # capital A, grave accent
  925. "agrave" => "A\\*`", # small a, grave accent
  926. "Aring" => 'A\\*o', # capital A, ring
  927. "aring" => 'a\\*o', # small a, ring
  928. "Atilde" => 'A\\*~', # capital A, tilde
  929. "atilde" => 'a\\*~', # small a, tilde
  930. "Auml" => 'A\\*:', # capital A, dieresis or umlaut mark
  931. "auml" => 'a\\*:', # small a, dieresis or umlaut mark
  932. "Ccedil" => 'C\\*,', # capital C, cedilla
  933. "ccedil" => 'c\\*,', # small c, cedilla
  934. "Eacute" => "E\\*'", # capital E, acute accent
  935. "eacute" => "e\\*'", # small e, acute accent
  936. "Ecirc" => "E\\*^", # capital E, circumflex accent
  937. "ecirc" => "e\\*^", # small e, circumflex accent
  938. "Egrave" => "E\\*`", # capital E, grave accent
  939. "egrave" => "e\\*`", # small e, grave accent
  940. "ETH" => '\\*(D-', # capital Eth, Icelandic
  941. "eth" => '\\*(d-', # small eth, Icelandic
  942. "Euml" => "E\\*:", # capital E, dieresis or umlaut mark
  943. "euml" => "e\\*:", # small e, dieresis or umlaut mark
  944. "Iacute" => "I\\*'", # capital I, acute accent
  945. "iacute" => "i\\*'", # small i, acute accent
  946. "Icirc" => "I\\*^", # capital I, circumflex accent
  947. "icirc" => "i\\*^", # small i, circumflex accent
  948. "Igrave" => "I\\*`", # capital I, grave accent
  949. "igrave" => "i\\*`", # small i, grave accent
  950. "Iuml" => "I\\*:", # capital I, dieresis or umlaut mark
  951. "iuml" => "i\\*:", # small i, dieresis or umlaut mark
  952. "Ntilde" => 'N\*~', # capital N, tilde
  953. "ntilde" => 'n\*~', # small n, tilde
  954. "Oacute" => "O\\*'", # capital O, acute accent
  955. "oacute" => "o\\*'", # small o, acute accent
  956. "Ocirc" => "O\\*^", # capital O, circumflex accent
  957. "ocirc" => "o\\*^", # small o, circumflex accent
  958. "Ograve" => "O\\*`", # capital O, grave accent
  959. "ograve" => "o\\*`", # small o, grave accent
  960. "Oslash" => "O\\*/", # capital O, slash
  961. "oslash" => "o\\*/", # small o, slash
  962. "Otilde" => "O\\*~", # capital O, tilde
  963. "otilde" => "o\\*~", # small o, tilde
  964. "Ouml" => "O\\*:", # capital O, dieresis or umlaut mark
  965. "ouml" => "o\\*:", # small o, dieresis or umlaut mark
  966. "szlig" => '\*8', # small sharp s, German (sz ligature)
  967. "THORN" => '\\*(Th', # capital THORN, Icelandic
  968. "thorn" => '\\*(th',, # small thorn, Icelandic
  969. "Uacute" => "U\\*'", # capital U, acute accent
  970. "uacute" => "u\\*'", # small u, acute accent
  971. "Ucirc" => "U\\*^", # capital U, circumflex accent
  972. "ucirc" => "u\\*^", # small u, circumflex accent
  973. "Ugrave" => "U\\*`", # capital U, grave accent
  974. "ugrave" => "u\\*`", # small u, grave accent
  975. "Uuml" => "U\\*:", # capital U, dieresis or umlaut mark
  976. "uuml" => "u\\*:", # small u, dieresis or umlaut mark
  977. "Yacute" => "Y\\*'", # capital Y, acute accent
  978. "yacute" => "y\\*'", # small y, acute accent
  979. "yuml" => "y\\*:", # small y, dieresis or umlaut mark
  980. );
  981. }
  982. __END__
  983. :endofperl