]>
git.cameronkatri.com Git - mandoc.git/blob - man_term.c
d6ddf7625aa86e69d519275b53c80e98055446ad
1 /* $Id: man_term.c,v 1.194 2017/05/04 22:16:09 schwarze Exp $ */
3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <sys/types.h>
29 #include "mandoc_aux.h"
37 #define MAXMARGINS 64 /* maximum number of indented scopes */
41 #define MANT_LITERAL (1 << 0)
42 int lmargin
[MAXMARGINS
]; /* margins (incl. vis. page) */
43 int lmargincur
; /* index of current margin */
44 int lmarginsz
; /* actual number of nested margins */
45 size_t offset
; /* default offset to visible page */
46 int pardist
; /* vert. space before par., unit: [v] */
49 #define DECL_ARGS struct termp *p, \
51 struct roff_node *n, \
52 const struct roff_meta *meta
55 int (*pre
)(DECL_ARGS
);
56 void (*post
)(DECL_ARGS
);
58 #define MAN_NOTEXT (1 << 0) /* Never has text children. */
61 static void print_man_nodelist(DECL_ARGS
);
62 static void print_man_node(DECL_ARGS
);
63 static void print_man_head(struct termp
*,
64 const struct roff_meta
*);
65 static void print_man_foot(struct termp
*,
66 const struct roff_meta
*);
67 static void print_bvspace(struct termp
*,
68 const struct roff_node
*, int);
70 static int pre_B(DECL_ARGS
);
71 static int pre_HP(DECL_ARGS
);
72 static int pre_I(DECL_ARGS
);
73 static int pre_IP(DECL_ARGS
);
74 static int pre_OP(DECL_ARGS
);
75 static int pre_PD(DECL_ARGS
);
76 static int pre_PP(DECL_ARGS
);
77 static int pre_RS(DECL_ARGS
);
78 static int pre_SH(DECL_ARGS
);
79 static int pre_SS(DECL_ARGS
);
80 static int pre_TP(DECL_ARGS
);
81 static int pre_UR(DECL_ARGS
);
82 static int pre_alternate(DECL_ARGS
);
83 static int pre_ft(DECL_ARGS
);
84 static int pre_ign(DECL_ARGS
);
85 static int pre_in(DECL_ARGS
);
86 static int pre_literal(DECL_ARGS
);
87 static int pre_ll(DECL_ARGS
);
88 static int pre_sp(DECL_ARGS
);
90 static void post_IP(DECL_ARGS
);
91 static void post_HP(DECL_ARGS
);
92 static void post_RS(DECL_ARGS
);
93 static void post_SH(DECL_ARGS
);
94 static void post_SS(DECL_ARGS
);
95 static void post_TP(DECL_ARGS
);
96 static void post_UR(DECL_ARGS
);
98 static const struct termact __termacts
[MAN_MAX
- MAN_TH
] = {
99 { NULL
, NULL
, 0 }, /* TH */
100 { pre_SH
, post_SH
, 0 }, /* SH */
101 { pre_SS
, post_SS
, 0 }, /* SS */
102 { pre_TP
, post_TP
, 0 }, /* TP */
103 { pre_PP
, NULL
, 0 }, /* LP */
104 { pre_PP
, NULL
, 0 }, /* PP */
105 { pre_PP
, NULL
, 0 }, /* P */
106 { pre_IP
, post_IP
, 0 }, /* IP */
107 { pre_HP
, post_HP
, 0 }, /* HP */
108 { NULL
, NULL
, 0 }, /* SM */
109 { pre_B
, NULL
, 0 }, /* SB */
110 { pre_alternate
, NULL
, 0 }, /* BI */
111 { pre_alternate
, NULL
, 0 }, /* IB */
112 { pre_alternate
, NULL
, 0 }, /* BR */
113 { pre_alternate
, NULL
, 0 }, /* RB */
114 { NULL
, NULL
, 0 }, /* R */
115 { pre_B
, NULL
, 0 }, /* B */
116 { pre_I
, NULL
, 0 }, /* I */
117 { pre_alternate
, NULL
, 0 }, /* IR */
118 { pre_alternate
, NULL
, 0 }, /* RI */
119 { pre_sp
, NULL
, MAN_NOTEXT
}, /* sp */
120 { pre_literal
, NULL
, 0 }, /* nf */
121 { pre_literal
, NULL
, 0 }, /* fi */
122 { NULL
, NULL
, 0 }, /* RE */
123 { pre_RS
, post_RS
, 0 }, /* RS */
124 { pre_ign
, NULL
, 0 }, /* DT */
125 { pre_ign
, NULL
, MAN_NOTEXT
}, /* UC */
126 { pre_PD
, NULL
, MAN_NOTEXT
}, /* PD */
127 { pre_ign
, NULL
, 0 }, /* AT */
128 { pre_in
, NULL
, MAN_NOTEXT
}, /* in */
129 { pre_ft
, NULL
, MAN_NOTEXT
}, /* ft */
130 { pre_OP
, NULL
, 0 }, /* OP */
131 { pre_literal
, NULL
, 0 }, /* EX */
132 { pre_literal
, NULL
, 0 }, /* EE */
133 { pre_UR
, post_UR
, 0 }, /* UR */
134 { NULL
, NULL
, 0 }, /* UE */
135 { pre_ll
, NULL
, MAN_NOTEXT
}, /* ll */
137 static const struct termact
*termacts
= __termacts
- MAN_TH
;
141 terminal_man(void *arg
, const struct roff_man
*man
)
146 size_t save_defindent
;
148 p
= (struct termp
*)arg
;
150 p
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
151 p
->tabwidth
= term_len(p
, 5);
153 memset(&mt
, 0, sizeof(struct mtermp
));
154 mt
.lmargin
[mt
.lmargincur
] = term_len(p
, p
->defindent
);
155 mt
.offset
= term_len(p
, p
->defindent
);
158 n
= man
->first
->child
;
159 if (p
->synopsisonly
) {
161 if (n
->tok
== MAN_SH
&&
162 n
->child
->child
->type
== ROFFT_TEXT
&&
163 !strcmp(n
->child
->child
->string
, "SYNOPSIS")) {
164 if (n
->child
->next
->child
!= NULL
)
165 print_man_nodelist(p
, &mt
,
166 n
->child
->next
->child
,
174 save_defindent
= p
->defindent
;
175 if (p
->defindent
== 0)
177 term_begin(p
, print_man_head
, print_man_foot
, &man
->meta
);
178 p
->flags
|= TERMP_NOSPACE
;
180 print_man_nodelist(p
, &mt
, n
, &man
->meta
);
182 p
->defindent
= save_defindent
;
187 * Printing leading vertical space before a block.
188 * This is used for the paragraph macros.
189 * The rules are pretty simple, since there's very little nesting going
190 * on here. Basically, if we're the first within another block (SS/SH),
191 * then don't emit vertical space. If we are (RS), then do. If not the
195 print_bvspace(struct termp
*p
, const struct roff_node
*n
, int pardist
)
201 if (n
->body
&& n
->body
->child
)
202 if (n
->body
->child
->type
== ROFFT_TBL
)
205 if (n
->parent
->type
== ROFFT_ROOT
|| n
->parent
->tok
!= MAN_RS
)
209 for (i
= 0; i
< pardist
; i
++)
225 term_setwidth(p
, n
->child
!= NULL
? n
->child
->string
: NULL
);
233 term_fontrepl(p
, TERMFONT_UNDER
);
238 pre_literal(DECL_ARGS
)
243 if (MAN_nf
== n
->tok
|| MAN_EX
== n
->tok
)
244 mt
->fl
|= MANT_LITERAL
;
246 mt
->fl
&= ~MANT_LITERAL
;
249 * Unlike .IP and .TP, .HP does not have a HEAD.
250 * So in case a second call to term_flushln() is needed,
251 * indentation has to be set up explicitly.
253 if (MAN_HP
== n
->parent
->tok
&& p
->rmargin
< p
->maxrmargin
) {
254 p
->offset
= p
->rmargin
;
255 p
->rmargin
= p
->maxrmargin
;
257 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
258 p
->flags
|= TERMP_NOSPACE
;
274 assert(n
->type
== ROFFT_TEXT
);
275 if (a2roffsu(n
->string
, &su
, SCALE_VS
))
276 mt
->pardist
= term_vspan(p
, &su
);
281 pre_alternate(DECL_ARGS
)
283 enum termfont font
[2];
284 struct roff_node
*nn
;
289 font
[0] = TERMFONT_NONE
;
290 font
[1] = TERMFONT_BOLD
;
293 font
[0] = TERMFONT_NONE
;
294 font
[1] = TERMFONT_UNDER
;
297 font
[0] = TERMFONT_BOLD
;
298 font
[1] = TERMFONT_NONE
;
301 font
[0] = TERMFONT_BOLD
;
302 font
[1] = TERMFONT_UNDER
;
305 font
[0] = TERMFONT_UNDER
;
306 font
[1] = TERMFONT_NONE
;
309 font
[0] = TERMFONT_UNDER
;
310 font
[1] = TERMFONT_BOLD
;
316 savelit
= MANT_LITERAL
& mt
->fl
;
317 mt
->fl
&= ~MANT_LITERAL
;
319 for (i
= 0, nn
= n
->child
; nn
; nn
= nn
->next
, i
= 1 - i
) {
320 term_fontrepl(p
, font
[i
]);
321 if (savelit
&& NULL
== nn
->next
)
322 mt
->fl
|= MANT_LITERAL
;
323 assert(nn
->type
== ROFFT_TEXT
);
324 term_word(p
, nn
->string
);
325 if (nn
->flags
& NODE_EOS
)
326 p
->flags
|= TERMP_SENTENCE
;
328 p
->flags
|= TERMP_NOSPACE
;
338 term_fontrepl(p
, TERMFONT_BOLD
);
347 p
->flags
|= TERMP_NOSPACE
;
349 if (NULL
!= (n
= n
->child
)) {
350 term_fontrepl(p
, TERMFONT_BOLD
);
351 term_word(p
, n
->string
);
353 if (NULL
!= n
&& NULL
!= n
->next
) {
354 term_fontrepl(p
, TERMFONT_UNDER
);
355 term_word(p
, n
->next
->string
);
358 term_fontrepl(p
, TERMFONT_NONE
);
359 p
->flags
|= TERMP_NOSPACE
;
369 if (NULL
== n
->child
) {
374 cp
= n
->child
->string
;
379 term_fontrepl(p
, TERMFONT_BOLD
);
383 term_fontrepl(p
, TERMFONT_UNDER
);
391 term_fontrepl(p
, TERMFONT_NONE
);
409 if (NULL
== n
->child
) {
410 p
->offset
= mt
->offset
;
414 cp
= n
->child
->string
;
424 if ( ! a2roffsu(++cp
, &su
, SCALE_EN
))
427 v
= (term_hspan(p
, &su
) + 11) / 24;
430 p
->offset
-= p
->offset
> v
? v
: p
->offset
;
435 if (p
->offset
> SHRT_MAX
)
436 p
->offset
= term_len(p
, p
->defindent
);
447 if ((NULL
== n
->prev
&& n
->parent
)) {
448 switch (n
->parent
->tok
) {
460 if (n
->child
== NULL
)
463 if ( ! a2roffsu(n
->child
->string
, &su
, SCALE_VS
))
465 len
= term_vspan(p
, &su
);
473 for (i
= 0; i
< len
; i
++)
477 * Handle an explicit break request in the same way
478 * as an overflowing line.
481 if (p
->flags
& TERMP_BRIND
) {
482 p
->offset
= p
->rmargin
;
483 p
->rmargin
= p
->maxrmargin
;
484 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
494 const struct roff_node
*nn
;
499 print_bvspace(p
, n
, mt
->pardist
);
507 if ( ! (MANT_LITERAL
& mt
->fl
)) {
508 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
512 /* Calculate offset. */
514 if ((nn
= n
->parent
->head
->child
) != NULL
&&
515 a2roffsu(nn
->string
, &su
, SCALE_EN
)) {
516 len
= term_hspan(p
, &su
) / 24;
517 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
519 else if (len
> SHRT_MAX
)
520 len
= term_len(p
, p
->defindent
);
521 mt
->lmargin
[mt
->lmargincur
] = len
;
523 len
= mt
->lmargin
[mt
->lmargincur
];
525 p
->offset
= mt
->offset
;
526 p
->rmargin
= mt
->offset
+ len
;
539 * Compatibility with a groff bug.
540 * The .HP macro uses the undocumented .tag request
541 * which causes a line break and cancels no-space
542 * mode even if there isn't any output.
545 if (n
->child
== NULL
)
548 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
550 p
->offset
= mt
->offset
;
551 p
->rmargin
= p
->maxrmargin
;
564 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
565 print_bvspace(p
, n
, mt
->pardist
);
568 p
->offset
= mt
->offset
;
572 return n
->type
!= ROFFT_HEAD
;
579 const struct roff_node
*nn
;
584 p
->flags
|= TERMP_NOSPACE
;
587 p
->flags
|= TERMP_NOBREAK
;
591 print_bvspace(p
, n
, mt
->pardist
);
597 /* Calculate the offset from the optional second argument. */
598 if ((nn
= n
->parent
->head
->child
) != NULL
&&
599 (nn
= nn
->next
) != NULL
&&
600 a2roffsu(nn
->string
, &su
, SCALE_EN
)) {
601 len
= term_hspan(p
, &su
) / 24;
602 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
604 else if (len
> SHRT_MAX
)
605 len
= term_len(p
, p
->defindent
);
606 mt
->lmargin
[mt
->lmargincur
] = len
;
608 len
= mt
->lmargin
[mt
->lmargincur
];
612 p
->offset
= mt
->offset
;
613 p
->rmargin
= mt
->offset
+ len
;
615 savelit
= MANT_LITERAL
& mt
->fl
;
616 mt
->fl
&= ~MANT_LITERAL
;
619 print_man_node(p
, mt
, n
->child
, meta
);
622 mt
->fl
|= MANT_LITERAL
;
626 p
->offset
= mt
->offset
+ len
;
627 p
->rmargin
= p
->maxrmargin
;
643 p
->flags
&= ~TERMP_NOBREAK
;
645 p
->rmargin
= p
->maxrmargin
;
649 p
->offset
= mt
->offset
;
660 struct roff_node
*nn
;
665 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
;
669 p
->flags
|= TERMP_NOSPACE
;
672 print_bvspace(p
, n
, mt
->pardist
);
678 /* Calculate offset. */
680 if ((nn
= n
->parent
->head
->child
) != NULL
&&
681 nn
->string
!= NULL
&& ! (NODE_LINE
& nn
->flags
) &&
682 a2roffsu(nn
->string
, &su
, SCALE_EN
)) {
683 len
= term_hspan(p
, &su
) / 24;
684 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
686 else if (len
> SHRT_MAX
)
687 len
= term_len(p
, p
->defindent
);
688 mt
->lmargin
[mt
->lmargincur
] = len
;
690 len
= mt
->lmargin
[mt
->lmargincur
];
694 p
->offset
= mt
->offset
;
695 p
->rmargin
= mt
->offset
+ len
;
697 savelit
= MANT_LITERAL
& mt
->fl
;
698 mt
->fl
&= ~MANT_LITERAL
;
700 /* Don't print same-line elements. */
702 while (NULL
!= nn
&& 0 == (NODE_LINE
& nn
->flags
))
706 print_man_node(p
, mt
, nn
, meta
);
711 mt
->fl
|= MANT_LITERAL
;
714 p
->offset
= mt
->offset
+ len
;
715 p
->rmargin
= p
->maxrmargin
;
717 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
);
736 p
->offset
= mt
->offset
;
750 mt
->fl
&= ~MANT_LITERAL
;
751 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
752 mt
->offset
= term_len(p
, p
->defindent
);
755 * No vertical space before the first subsection
756 * and after an empty subsection.
761 } while (n
!= NULL
&& n
->tok
!= TOKEN_NONE
&&
762 termacts
[n
->tok
].flags
& MAN_NOTEXT
);
763 if (n
== NULL
|| (n
->tok
== MAN_SS
&& n
->body
->child
== NULL
))
766 for (i
= 0; i
< mt
->pardist
; i
++)
770 term_fontrepl(p
, TERMFONT_BOLD
);
771 p
->offset
= term_len(p
, 3);
772 p
->rmargin
= mt
->offset
;
773 p
->trailspace
= mt
->offset
;
774 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
777 p
->offset
= mt
->offset
;
778 p
->rmargin
= p
->maxrmargin
;
780 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
812 mt
->fl
&= ~MANT_LITERAL
;
813 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
814 mt
->offset
= term_len(p
, p
->defindent
);
817 * No vertical space before the first section
818 * and after an empty section.
823 } while (n
!= NULL
&& n
->tok
!= TOKEN_NONE
&&
824 termacts
[n
->tok
].flags
& MAN_NOTEXT
);
825 if (n
== NULL
|| (n
->tok
== MAN_SH
&& n
->body
->child
== NULL
))
828 for (i
= 0; i
< mt
->pardist
; i
++)
832 term_fontrepl(p
, TERMFONT_BOLD
);
834 p
->rmargin
= mt
->offset
;
835 p
->trailspace
= mt
->offset
;
836 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
839 p
->offset
= mt
->offset
;
840 p
->rmargin
= p
->maxrmargin
;
842 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
883 n
->aux
= SHRT_MAX
+ 1;
884 if (n
->child
== NULL
)
885 n
->aux
= mt
->lmargin
[mt
->lmargincur
];
886 else if (a2roffsu(n
->child
->string
, &su
, SCALE_EN
))
887 n
->aux
= term_hspan(p
, &su
) / 24;
888 if (n
->aux
< 0 && (size_t)(-n
->aux
) > mt
->offset
)
889 n
->aux
= -mt
->offset
;
890 else if (n
->aux
> SHRT_MAX
)
891 n
->aux
= term_len(p
, p
->defindent
);
893 mt
->offset
+= n
->aux
;
894 p
->offset
= mt
->offset
;
895 p
->rmargin
= p
->maxrmargin
;
897 if (++mt
->lmarginsz
< MAXMARGINS
)
898 mt
->lmargincur
= mt
->lmarginsz
;
900 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
918 mt
->offset
-= n
->parent
->head
->aux
;
919 p
->offset
= mt
->offset
;
921 if (--mt
->lmarginsz
< MAXMARGINS
)
922 mt
->lmargincur
= mt
->lmarginsz
;
929 return n
->type
!= ROFFT_HEAD
;
936 if (n
->type
!= ROFFT_BLOCK
)
940 p
->flags
|= TERMP_NOSPACE
;
942 if (NULL
!= n
->child
->child
)
943 print_man_node(p
, mt
, n
->child
->child
, meta
);
945 p
->flags
|= TERMP_NOSPACE
;
950 print_man_node(DECL_ARGS
)
958 * If we have a blank line, output a vertical space.
959 * If we have a space as the first character, break
960 * before printing the line's data.
962 if ('\0' == *n
->string
) {
965 } else if (' ' == *n
->string
&& NODE_LINE
& n
->flags
)
968 term_word(p
, n
->string
);
972 if ( ! (n
->flags
& NODE_LINE
))
973 p
->flags
|= TERMP_NOSPACE
;
975 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
976 p
->flags
|= TERMP_NOSPACE
;
979 if (p
->tbl
.cols
== NULL
)
981 term_tbl(p
, n
->span
);
987 if (n
->tok
< ROFF_MAX
) {
992 assert(n
->tok
>= MAN_TH
&& n
->tok
<= MAN_MAX
);
993 if ( ! (MAN_NOTEXT
& termacts
[n
->tok
].flags
))
994 term_fontrepl(p
, TERMFONT_NONE
);
997 if (termacts
[n
->tok
].pre
)
998 c
= (*termacts
[n
->tok
].pre
)(p
, mt
, n
, meta
);
1001 print_man_nodelist(p
, mt
, n
->child
, meta
);
1003 if (termacts
[n
->tok
].post
)
1004 (*termacts
[n
->tok
].post
)(p
, mt
, n
, meta
);
1005 if ( ! (MAN_NOTEXT
& termacts
[n
->tok
].flags
))
1006 term_fontrepl(p
, TERMFONT_NONE
);
1010 * If we're in a literal context, make sure that words
1011 * together on the same line stay together. This is a
1012 * POST-printing call, so we check the NEXT word. Since
1013 * -man doesn't have nested macros, we don't need to be
1014 * more specific than this.
1016 if (mt
->fl
& MANT_LITERAL
&&
1017 ! (p
->flags
& (TERMP_NOBREAK
| TERMP_NONEWLINE
)) &&
1018 (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
)) {
1020 rmax
= p
->maxrmargin
;
1021 p
->rmargin
= p
->maxrmargin
= TERM_MAXMARGIN
;
1022 p
->flags
|= TERMP_NOSPACE
;
1023 if (n
->string
!= NULL
&& *n
->string
!= '\0')
1027 if (rm
< rmax
&& n
->parent
->tok
== MAN_HP
) {
1032 p
->maxrmargin
= rmax
;
1034 if (NODE_EOS
& n
->flags
)
1035 p
->flags
|= TERMP_SENTENCE
;
1040 print_man_nodelist(DECL_ARGS
)
1044 print_man_node(p
, mt
, n
, meta
);
1050 print_man_foot(struct termp
*p
, const struct roff_meta
*meta
)
1053 size_t datelen
, titlen
;
1055 assert(meta
->title
);
1059 term_fontrepl(p
, TERMFONT_NONE
);
1065 * Temporary, undocumented option to imitate mdoc(7) output.
1066 * In the bottom right corner, use the operating system
1067 * instead of the title.
1070 if ( ! p
->mdocstyle
) {
1071 if (meta
->hasbody
) {
1075 mandoc_asprintf(&title
, "%s(%s)",
1076 meta
->title
, meta
->msec
);
1077 } else if (meta
->os
) {
1078 title
= mandoc_strdup(meta
->os
);
1080 title
= mandoc_strdup("");
1082 datelen
= term_strlen(p
, meta
->date
);
1084 /* Bottom left corner: operating system. */
1086 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
1089 p
->rmargin
= p
->maxrmargin
> datelen
?
1090 (p
->maxrmargin
+ term_len(p
, 1) - datelen
) / 2 : 0;
1093 term_word(p
, meta
->os
);
1096 /* At the bottom in the middle: manual date. */
1098 p
->offset
= p
->rmargin
;
1099 titlen
= term_strlen(p
, title
);
1100 p
->rmargin
= p
->maxrmargin
> titlen
? p
->maxrmargin
- titlen
: 0;
1101 p
->flags
|= TERMP_NOSPACE
;
1103 term_word(p
, meta
->date
);
1106 /* Bottom right corner: manual title and section. */
1108 p
->flags
&= ~TERMP_NOBREAK
;
1109 p
->flags
|= TERMP_NOSPACE
;
1111 p
->offset
= p
->rmargin
;
1112 p
->rmargin
= p
->maxrmargin
;
1114 term_word(p
, title
);
1120 print_man_head(struct termp
*p
, const struct roff_meta
*meta
)
1124 size_t vollen
, titlen
;
1126 assert(meta
->title
);
1129 volume
= NULL
== meta
->vol
? "" : meta
->vol
;
1130 vollen
= term_strlen(p
, volume
);
1132 /* Top left corner: manual title and section. */
1134 mandoc_asprintf(&title
, "%s(%s)", meta
->title
, meta
->msec
);
1135 titlen
= term_strlen(p
, title
);
1137 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
1140 p
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
1141 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
1142 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
1144 term_word(p
, title
);
1147 /* At the top in the middle: manual volume. */
1149 p
->flags
|= TERMP_NOSPACE
;
1150 p
->offset
= p
->rmargin
;
1151 p
->rmargin
= p
->offset
+ vollen
+ titlen
< p
->maxrmargin
?
1152 p
->maxrmargin
- titlen
: p
->maxrmargin
;
1154 term_word(p
, volume
);
1157 /* Top right corner: title and section, again. */
1159 p
->flags
&= ~TERMP_NOBREAK
;
1161 if (p
->rmargin
+ titlen
<= p
->maxrmargin
) {
1162 p
->flags
|= TERMP_NOSPACE
;
1163 p
->offset
= p
->rmargin
;
1164 p
->rmargin
= p
->maxrmargin
;
1165 term_word(p
, title
);
1169 p
->flags
&= ~TERMP_NOSPACE
;
1171 p
->rmargin
= p
->maxrmargin
;
1174 * Groff prints three blank lines before the content.
1175 * Do the same, except in the temporary, undocumented
1176 * mode imitating mdoc(7) output.
1180 if ( ! p
->mdocstyle
) {