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