4 # Properly implement -columns in the "my %lists" definition...
6 # .Xr requires at least 1 arg, the code here expects at least 2
13 use lib dirname(__FILE__);
14 use Mdoc qw(hs ns pp mapwords son soff stoggle gen_encloser);
20 Mdoc::def_macro( '.Sh', sub { '.SH', hs, @_ }, raw => 1);
21 Mdoc::def_macro( '.Ss', sub { '.SS', hs, @_ }, raw => 1);
22 Mdoc::def_macro( '.Pp', sub { ".sp \\n(Ppu\n.ne 2\n" } );
23 Mdoc::def_macro( '.Nd', sub { "\\- @_" } );
25 # Macros that enclose things
26 Mdoc::def_macro( '.Brq', gen_encloser(qw({ })) , greedy => 1 );
27 Mdoc::def_macro( '.Op' , gen_encloser(qw([ ])) , greedy => 1 );
28 Mdoc::def_macro( '.Qq' , gen_encloser(qw(" ")) , greedy => 1 );
29 Mdoc::def_macro( '.Dq' , gen_encloser(qw(\*[Lq] \*[Rq])), greedy => 1 );
30 Mdoc::def_macro( '.Ql' , gen_encloser(qw(\[oq] \[cq])) , greedy => 1 );
31 Mdoc::def_macro( '.Sq' , gen_encloser(qw(\[oq] \[cq])) , greedy => 1 );
32 Mdoc::def_macro( '.Pq' , gen_encloser(qw/( )/) , greedy => 1 );
33 Mdoc::def_macro( '.D1' , sub { ".in +4\n", ns, @_ , ns , "\n.in -4" } , greedy => 1);
35 Mdoc::def_macro( 'Oo', sub { '[', @_ } );
36 Mdoc::def_macro( 'Oc', sub { ']', @_ } );
38 Mdoc::def_macro( 'Po', sub { '(', @_} );
39 Mdoc::def_macro( 'Pc', sub { ')', @_ } );
41 Mdoc::def_macro( 'Bro', sub { '{', ns, @_ } );
42 Mdoc::def_macro( 'Brc', sub { '}', @_ } );
44 Mdoc::def_macro( '.Oo', gen_encloser(qw([ ])), concat_until => '.Oc' );
45 Mdoc::def_macro( '.Bro', gen_encloser(qw({ })), concat_until => '.Brc' );
46 Mdoc::def_macro( '.Po', gen_encloser(qw/( )/), concat_until => '.Pc' );
48 Mdoc::def_macro( '.Ev', sub { @_ } );
49 Mdoc::def_macro( '.An', sub { ".NOP ", @_, "\n.br" }, raw => 1 );
50 Mdoc::def_macro( '.Li', sub { mapwords {"\\f[C]$_\\f[]"} @_ } );
51 Mdoc::def_macro( '.Cm', sub { mapwords {"\\f\\*[B-Font]$_\\f[]"} @_ } );
52 Mdoc::def_macro( '.Ic', sub { mapwords {"\\f\\*[B-Font]$_\\f[]"} @_ } );
53 Mdoc::def_macro( '.Fl', sub { mapwords {"\\f\\*[B-Font]\\-$_\\f[]"} @_ } );
54 Mdoc::def_macro( '.Ar', sub { mapwords {"\\f\\*[I-Font]$_\\f[]"} @_ } );
55 Mdoc::def_macro( '.Em', sub { mapwords {"\\fI$_\\f[]"} @_ } );
56 Mdoc::def_macro( '.Va', sub { mapwords {"\\fI$_\\f[]"} @_ } );
57 Mdoc::def_macro( '.Sx', sub { mapwords {"\\fI$_\\f[]"} @_ } );
58 Mdoc::def_macro( '.Xr', sub { "\\fC".(shift)."\\fR(".(shift).")\\f[]", @_ } );
59 Mdoc::def_macro( '.Fn', sub { "\\f\\*[B-Font]".(shift)."\\fR()\\f[]" } );
60 Mdoc::def_macro( '.Fn', sub { "\\fB".(shift)."\\fR()\\f[]" } );
61 Mdoc::def_macro( '.Fx', sub { "FreeBSD", @_ } );
62 Mdoc::def_macro( '.Ux', sub { "UNIX", @_ } );
64 Mdoc::def_macro( '.No', sub { ".NOP", map { ($_, ns) } @_ } );
65 Mdoc::def_macro( '.Pa', sub { mapwords {"\\fI$_\\f[]"} @_; } );
68 Mdoc::def_macro('.Nm', sub {
69 $name = shift if (!$name);
70 "\\f\\*[B-Font]$name\\fP", @_
80 Mdoc::def_macro('.It', sub { '.IP \fB\(bu\fP 2' });
84 Mdoc::def_macro('.It', sub { '.IP \fB\(bu\fP 2' });
92 if (exists $opts{width}) {
93 $width = ' '.((length $opts{width})+1);
96 if (exists $opts{compact}) {
98 Mdoc::def_macro('.It', sub {
99 my @ret = (".TP$width\n.NOP", hs);
101 ".br\n.ns\n", ns, @ret, @_;
110 Mdoc::def_macro('.It', sub {
111 ".TP$width\n.NOP", hs, @_
117 Mdoc::set_Bl_callback(do { my $nested = 0; sub {
119 my %opts = Mdoc::parse_opts(@_);
120 if (defined $type && $type =~ /-(\w+)/ && exists $lists{$1}) {
122 # Wrap nested lists with .RS and .RE
123 Mdoc::set_El_callback(sub {
124 return '.RE' if $nested-- > 1;
138 die "Invalid list type <$type>";
142 # don't bother with arguments for now and do what mdoc2man'.sh' did
144 Mdoc::def_macro('.Bd', sub { ".br\n.in +4\n.nf" } );
145 Mdoc::def_macro('.Ed', sub { ".in -4\n.fi" } );
147 Mdoc::set_Re_callback(sub {
148 my ($reference) = @_;
150 $reference->{authors},
151 \\fI$reference->{title}\\fR,
152 $reference->{optional}\n.PP
156 # Define all macros which have the same sub for inline and standalone macro
157 for (qw(Xr Em Ar Fl Ic Cm Qq Op Nm Pa Sq Li Va Brq Pq Fx Ux)) {
158 my $m = Mdoc::get_macro(".$_");
159 Mdoc::def_macro($_, delete $m->{run}, %$m);
171 . if \\n[.$] \,\\$*\/
183 while (my ($macro, @args) = Mdoc::parse_line(\*STDIN, \&print_line)) {
184 my @ret = Mdoc::call_macro($macro, @args);
185 print_line(Mdoc::to_string(@ret)) if @ret;
190 exit run(@ARGV) unless caller;