1 /* $Id: man_term.c,v 1.226 2019/01/05 00:36:50 schwarze Exp $ */
3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2015, 2017-2019 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"
36 #define MAXMARGINS 64 /* maximum number of indented scopes */
39 int lmargin
[MAXMARGINS
]; /* margins (incl. vis. page) */
40 int lmargincur
; /* index of current margin */
41 int lmarginsz
; /* actual number of nested margins */
42 size_t offset
; /* default offset to visible page */
43 int pardist
; /* vert. space before par., unit: [v] */
46 #define DECL_ARGS struct termp *p, \
48 struct roff_node *n, \
49 const struct roff_meta *meta
52 int (*pre
)(DECL_ARGS
);
53 void (*post
)(DECL_ARGS
);
55 #define MAN_NOTEXT (1 << 0) /* Never has text children. */
58 static void print_man_nodelist(DECL_ARGS
);
59 static void print_man_node(DECL_ARGS
);
60 static void print_man_head(struct termp
*,
61 const struct roff_meta
*);
62 static void print_man_foot(struct termp
*,
63 const struct roff_meta
*);
64 static void print_bvspace(struct termp
*,
65 const struct roff_node
*, int);
67 static int pre_B(DECL_ARGS
);
68 static int pre_DT(DECL_ARGS
);
69 static int pre_HP(DECL_ARGS
);
70 static int pre_I(DECL_ARGS
);
71 static int pre_IP(DECL_ARGS
);
72 static int pre_OP(DECL_ARGS
);
73 static int pre_PD(DECL_ARGS
);
74 static int pre_PP(DECL_ARGS
);
75 static int pre_RS(DECL_ARGS
);
76 static int pre_SH(DECL_ARGS
);
77 static int pre_SS(DECL_ARGS
);
78 static int pre_SY(DECL_ARGS
);
79 static int pre_TP(DECL_ARGS
);
80 static int pre_UR(DECL_ARGS
);
81 static int pre_abort(DECL_ARGS
);
82 static int pre_alternate(DECL_ARGS
);
83 static int pre_ign(DECL_ARGS
);
84 static int pre_in(DECL_ARGS
);
85 static int pre_literal(DECL_ARGS
);
87 static void post_IP(DECL_ARGS
);
88 static void post_HP(DECL_ARGS
);
89 static void post_RS(DECL_ARGS
);
90 static void post_SH(DECL_ARGS
);
91 static void post_SS(DECL_ARGS
);
92 static void post_SY(DECL_ARGS
);
93 static void post_TP(DECL_ARGS
);
94 static void post_UR(DECL_ARGS
);
96 static const struct man_term_act man_term_acts
[MAN_MAX
- MAN_TH
] = {
97 { NULL
, NULL
, 0 }, /* TH */
98 { pre_SH
, post_SH
, 0 }, /* SH */
99 { pre_SS
, post_SS
, 0 }, /* SS */
100 { pre_TP
, post_TP
, 0 }, /* TP */
101 { pre_TP
, post_TP
, 0 }, /* TQ */
102 { pre_abort
, NULL
, 0 }, /* LP */
103 { pre_PP
, NULL
, 0 }, /* PP */
104 { pre_abort
, NULL
, 0 }, /* P */
105 { pre_IP
, post_IP
, 0 }, /* IP */
106 { pre_HP
, post_HP
, 0 }, /* HP */
107 { NULL
, NULL
, 0 }, /* SM */
108 { pre_B
, NULL
, 0 }, /* SB */
109 { pre_alternate
, NULL
, 0 }, /* BI */
110 { pre_alternate
, NULL
, 0 }, /* IB */
111 { pre_alternate
, NULL
, 0 }, /* BR */
112 { pre_alternate
, NULL
, 0 }, /* RB */
113 { NULL
, NULL
, 0 }, /* R */
114 { pre_B
, NULL
, 0 }, /* B */
115 { pre_I
, NULL
, 0 }, /* I */
116 { pre_alternate
, NULL
, 0 }, /* IR */
117 { pre_alternate
, NULL
, 0 }, /* RI */
118 { NULL
, NULL
, 0 }, /* RE */
119 { pre_RS
, post_RS
, 0 }, /* RS */
120 { pre_DT
, NULL
, 0 }, /* DT */
121 { pre_ign
, NULL
, MAN_NOTEXT
}, /* UC */
122 { pre_PD
, NULL
, MAN_NOTEXT
}, /* PD */
123 { pre_ign
, NULL
, 0 }, /* AT */
124 { pre_in
, NULL
, MAN_NOTEXT
}, /* in */
125 { pre_SY
, post_SY
, 0 }, /* SY */
126 { NULL
, NULL
, 0 }, /* YS */
127 { pre_OP
, NULL
, 0 }, /* OP */
128 { pre_literal
, NULL
, 0 }, /* EX */
129 { pre_literal
, NULL
, 0 }, /* EE */
130 { pre_UR
, post_UR
, 0 }, /* UR */
131 { NULL
, NULL
, 0 }, /* UE */
132 { pre_UR
, post_UR
, 0 }, /* MT */
133 { NULL
, NULL
, 0 }, /* ME */
135 static const struct man_term_act
*man_term_act(enum roff_tok
);
138 static const struct man_term_act
*
139 man_term_act(enum roff_tok tok
)
141 assert(tok
>= MAN_TH
&& tok
<= MAN_MAX
);
142 return man_term_acts
+ (tok
- MAN_TH
);
146 terminal_man(void *arg
, const struct roff_meta
*man
)
151 size_t save_defindent
;
153 p
= (struct termp
*)arg
;
154 save_defindent
= p
->defindent
;
155 if (p
->synopsisonly
== 0 && p
->defindent
== 0)
157 p
->tcol
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
158 term_tab_set(p
, NULL
);
159 term_tab_set(p
, "T");
160 term_tab_set(p
, ".5i");
162 memset(&mt
, 0, sizeof(struct mtermp
));
163 mt
.lmargin
[mt
.lmargincur
] = term_len(p
, p
->defindent
);
164 mt
.offset
= term_len(p
, p
->defindent
);
167 n
= man
->first
->child
;
168 if (p
->synopsisonly
) {
170 if (n
->tok
== MAN_SH
&&
171 n
->child
->child
->type
== ROFFT_TEXT
&&
172 !strcmp(n
->child
->child
->string
, "SYNOPSIS")) {
173 if (n
->child
->next
->child
!= NULL
)
174 print_man_nodelist(p
, &mt
,
175 n
->child
->next
->child
, man
);
182 term_begin(p
, print_man_head
, print_man_foot
, man
);
183 p
->flags
|= TERMP_NOSPACE
;
185 print_man_nodelist(p
, &mt
, n
, man
);
188 p
->defindent
= save_defindent
;
192 * Printing leading vertical space before a block.
193 * This is used for the paragraph macros.
194 * The rules are pretty simple, since there's very little nesting going
195 * on here. Basically, if we're the first within another block (SS/SH),
196 * then don't emit vertical space. If we are (RS), then do. If not the
200 print_bvspace(struct termp
*p
, const struct roff_node
*n
, int pardist
)
206 if (n
->body
&& n
->body
->child
)
207 if (n
->body
->child
->type
== ROFFT_TBL
)
210 if (n
->parent
->type
== ROFFT_ROOT
|| n
->parent
->tok
!= MAN_RS
)
214 for (i
= 0; i
< pardist
; i
++)
236 term_fontrepl(p
, TERMFONT_UNDER
);
241 pre_literal(DECL_ARGS
)
246 * Unlike .IP and .TP, .HP does not have a HEAD.
247 * So in case a second call to term_flushln() is needed,
248 * indentation has to be set up explicitly.
250 if (n
->parent
->tok
== MAN_HP
&& p
->tcol
->rmargin
< p
->maxrmargin
) {
251 p
->tcol
->offset
= p
->tcol
->rmargin
;
252 p
->tcol
->rmargin
= p
->maxrmargin
;
254 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
255 p
->flags
|= TERMP_NOSPACE
;
270 assert(n
->type
== ROFFT_TEXT
);
271 if (a2roffsu(n
->string
, &su
, SCALE_VS
) != NULL
)
272 mt
->pardist
= term_vspan(p
, &su
);
277 pre_alternate(DECL_ARGS
)
279 enum termfont font
[2];
280 struct roff_node
*nn
;
285 font
[0] = TERMFONT_NONE
;
286 font
[1] = TERMFONT_BOLD
;
289 font
[0] = TERMFONT_NONE
;
290 font
[1] = TERMFONT_UNDER
;
293 font
[0] = TERMFONT_BOLD
;
294 font
[1] = TERMFONT_NONE
;
297 font
[0] = TERMFONT_BOLD
;
298 font
[1] = TERMFONT_UNDER
;
301 font
[0] = TERMFONT_UNDER
;
302 font
[1] = TERMFONT_NONE
;
305 font
[0] = TERMFONT_UNDER
;
306 font
[1] = TERMFONT_BOLD
;
311 for (i
= 0, nn
= n
->child
; nn
!= NULL
; nn
= nn
->next
, i
= 1 - i
) {
312 term_fontrepl(p
, font
[i
]);
313 assert(nn
->type
== ROFFT_TEXT
);
314 term_word(p
, nn
->string
);
315 if (nn
->flags
& NODE_EOS
)
316 p
->flags
|= TERMP_SENTENCE
;
318 p
->flags
|= TERMP_NOSPACE
;
327 term_fontrepl(p
, TERMFONT_BOLD
);
336 p
->flags
|= TERMP_KEEP
| TERMP_NOSPACE
;
338 if (NULL
!= (n
= n
->child
)) {
339 term_fontrepl(p
, TERMFONT_BOLD
);
340 term_word(p
, n
->string
);
342 if (NULL
!= n
&& NULL
!= n
->next
) {
343 term_fontrepl(p
, TERMFONT_UNDER
);
344 term_word(p
, n
->next
->string
);
347 term_fontrepl(p
, TERMFONT_NONE
);
348 p
->flags
&= ~TERMP_KEEP
;
349 p
->flags
|= TERMP_NOSPACE
;
364 if (n
->child
== NULL
) {
365 p
->tcol
->offset
= mt
->offset
;
369 cp
= n
->child
->string
;
379 if (a2roffsu(++cp
, &su
, SCALE_EN
) == NULL
)
382 v
= term_hen(p
, &su
);
385 p
->tcol
->offset
-= p
->tcol
->offset
> v
? v
: p
->tcol
->offset
;
387 p
->tcol
->offset
+= v
;
390 if (p
->tcol
->offset
> SHRT_MAX
)
391 p
->tcol
->offset
= term_len(p
, p
->defindent
);
399 term_tab_set(p
, NULL
);
400 term_tab_set(p
, "T");
401 term_tab_set(p
, ".5i");
409 const struct roff_node
*nn
;
414 print_bvspace(p
, n
, mt
->pardist
);
422 if (n
->child
== NULL
)
425 if ((n
->child
->flags
& NODE_NOFILL
) == 0) {
426 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
430 /* Calculate offset. */
432 if ((nn
= n
->parent
->head
->child
) != NULL
&&
433 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
434 len
= term_hen(p
, &su
);
435 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
437 else if (len
> SHRT_MAX
)
438 len
= term_len(p
, p
->defindent
);
439 mt
->lmargin
[mt
->lmargincur
] = len
;
441 len
= mt
->lmargin
[mt
->lmargincur
];
443 p
->tcol
->offset
= mt
->offset
;
444 p
->tcol
->rmargin
= mt
->offset
+ len
;
457 * Compatibility with a groff bug.
458 * The .HP macro uses the undocumented .tag request
459 * which causes a line break and cancels no-space
460 * mode even if there isn't any output.
463 if (n
->child
== NULL
)
466 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
468 p
->tcol
->offset
= mt
->offset
;
469 p
->tcol
->rmargin
= p
->maxrmargin
;
482 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
483 print_bvspace(p
, n
, mt
->pardist
);
486 p
->tcol
->offset
= mt
->offset
;
490 return n
->type
!= ROFFT_HEAD
;
497 const struct roff_node
*nn
;
502 p
->flags
|= TERMP_NOSPACE
;
505 p
->flags
|= TERMP_NOBREAK
;
509 print_bvspace(p
, n
, mt
->pardist
);
515 /* Calculate the offset from the optional second argument. */
516 if ((nn
= n
->parent
->head
->child
) != NULL
&&
517 (nn
= nn
->next
) != NULL
&&
518 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
519 len
= term_hen(p
, &su
);
520 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
522 else if (len
> SHRT_MAX
)
523 len
= term_len(p
, p
->defindent
);
524 mt
->lmargin
[mt
->lmargincur
] = len
;
526 len
= mt
->lmargin
[mt
->lmargincur
];
530 p
->tcol
->offset
= mt
->offset
;
531 p
->tcol
->rmargin
= mt
->offset
+ len
;
533 print_man_node(p
, mt
, n
->child
, meta
);
536 p
->tcol
->offset
= mt
->offset
+ len
;
537 p
->tcol
->rmargin
= p
->maxrmargin
;
551 p
->flags
&= ~TERMP_NOBREAK
;
553 p
->tcol
->rmargin
= p
->maxrmargin
;
557 p
->tcol
->offset
= mt
->offset
;
568 struct roff_node
*nn
;
573 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
;
577 p
->flags
|= TERMP_NOSPACE
;
580 if (n
->tok
== MAN_TP
)
581 print_bvspace(p
, n
, mt
->pardist
);
587 /* Calculate offset. */
589 if ((nn
= n
->parent
->head
->child
) != NULL
&&
590 nn
->string
!= NULL
&& ! (NODE_LINE
& nn
->flags
) &&
591 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
592 len
= term_hen(p
, &su
);
593 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
595 else if (len
> SHRT_MAX
)
596 len
= term_len(p
, p
->defindent
);
597 mt
->lmargin
[mt
->lmargincur
] = len
;
599 len
= mt
->lmargin
[mt
->lmargincur
];
603 p
->tcol
->offset
= mt
->offset
;
604 p
->tcol
->rmargin
= mt
->offset
+ len
;
606 /* Don't print same-line elements. */
608 while (NULL
!= nn
&& 0 == (NODE_LINE
& nn
->flags
))
612 print_man_node(p
, mt
, nn
, meta
);
617 p
->tcol
->offset
= mt
->offset
+ len
;
618 p
->tcol
->rmargin
= p
->maxrmargin
;
620 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
);
637 p
->tcol
->offset
= mt
->offset
;
651 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
652 mt
->offset
= term_len(p
, p
->defindent
);
655 * No vertical space before the first subsection
656 * and after an empty subsection.
661 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
662 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
663 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
664 (n
->tok
== MAN_SS
&& n
->body
->child
== NULL
))
667 for (i
= 0; i
< mt
->pardist
; i
++)
671 term_fontrepl(p
, TERMFONT_BOLD
);
672 p
->tcol
->offset
= term_len(p
, 3);
673 p
->tcol
->rmargin
= mt
->offset
;
674 p
->trailspace
= mt
->offset
;
675 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
678 p
->tcol
->offset
= mt
->offset
;
679 p
->tcol
->rmargin
= p
->maxrmargin
;
681 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
713 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
714 mt
->offset
= term_len(p
, p
->defindent
);
717 * No vertical space before the first section
718 * and after an empty section.
723 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
724 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
725 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
726 (n
->tok
== MAN_SH
&& n
->body
->child
== NULL
))
729 for (i
= 0; i
< mt
->pardist
; i
++)
733 term_fontrepl(p
, TERMFONT_BOLD
);
735 p
->tcol
->rmargin
= mt
->offset
;
736 p
->trailspace
= mt
->offset
;
737 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
740 p
->tcol
->offset
= mt
->offset
;
741 p
->tcol
->rmargin
= p
->maxrmargin
;
743 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
784 n
->aux
= SHRT_MAX
+ 1;
785 if (n
->child
== NULL
)
786 n
->aux
= mt
->lmargin
[mt
->lmargincur
];
787 else if (a2roffsu(n
->child
->string
, &su
, SCALE_EN
) != NULL
)
788 n
->aux
= term_hen(p
, &su
);
789 if (n
->aux
< 0 && (size_t)(-n
->aux
) > mt
->offset
)
790 n
->aux
= -mt
->offset
;
791 else if (n
->aux
> SHRT_MAX
)
792 n
->aux
= term_len(p
, p
->defindent
);
794 mt
->offset
+= n
->aux
;
795 p
->tcol
->offset
= mt
->offset
;
796 p
->tcol
->rmargin
= p
->maxrmargin
;
798 if (++mt
->lmarginsz
< MAXMARGINS
)
799 mt
->lmargincur
= mt
->lmarginsz
;
801 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
819 mt
->offset
-= n
->parent
->head
->aux
;
820 p
->tcol
->offset
= mt
->offset
;
822 if (--mt
->lmarginsz
< MAXMARGINS
)
823 mt
->lmargincur
= mt
->lmarginsz
;
829 const struct roff_node
*nn
;
834 if (n
->prev
== NULL
|| n
->prev
->tok
!= MAN_SY
)
835 print_bvspace(p
, n
, mt
->pardist
);
844 nn
= n
->parent
->head
->child
;
845 len
= nn
== NULL
? 1 : term_strlen(p
, nn
->string
) + 1;
849 p
->tcol
->offset
= mt
->offset
;
850 p
->tcol
->rmargin
= mt
->offset
+ len
;
851 p
->flags
|= TERMP_NOBREAK
;
852 term_fontrepl(p
, TERMFONT_BOLD
);
855 mt
->lmargin
[mt
->lmargincur
] = len
;
856 p
->tcol
->offset
= mt
->offset
+ len
;
857 p
->tcol
->rmargin
= p
->maxrmargin
;
858 p
->flags
|= TERMP_NOSPACE
;
872 p
->flags
&= ~TERMP_NOBREAK
;
876 p
->tcol
->offset
= mt
->offset
;
887 return n
->type
!= ROFFT_HEAD
;
894 if (n
->type
!= ROFFT_BLOCK
)
898 p
->flags
|= TERMP_NOSPACE
;
900 if (NULL
!= n
->child
->child
)
901 print_man_node(p
, mt
, n
->child
->child
, meta
);
903 p
->flags
|= TERMP_NOSPACE
;
908 print_man_node(DECL_ARGS
)
910 const struct man_term_act
*act
;
916 * If we have a blank line, output a vertical space.
917 * If we have a space as the first character, break
918 * before printing the line's data.
920 if (*n
->string
== '\0') {
921 if (p
->flags
& TERMP_NONEWLINE
)
926 } else if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
927 (p
->flags
& TERMP_NONEWLINE
) == 0)
929 else if (n
->flags
& NODE_DELIMC
)
930 p
->flags
|= TERMP_NOSPACE
;
932 term_word(p
, n
->string
);
937 if ( ! (n
->flags
& NODE_LINE
))
938 p
->flags
|= TERMP_NOSPACE
;
940 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
941 p
->flags
|= TERMP_NOSPACE
;
944 if (p
->tbl
.cols
== NULL
)
946 term_tbl(p
, n
->span
);
952 if (n
->tok
< ROFF_MAX
) {
957 act
= man_term_act(n
->tok
);
958 if ((act
->flags
& MAN_NOTEXT
) == 0 && n
->tok
!= MAN_SM
)
959 term_fontrepl(p
, TERMFONT_NONE
);
962 if (act
->pre
!= NULL
)
963 c
= (*act
->pre
)(p
, mt
, n
, meta
);
966 print_man_nodelist(p
, mt
, n
->child
, meta
);
968 if (act
->post
!= NULL
)
969 (*act
->post
)(p
, mt
, n
, meta
);
970 if ((act
->flags
& MAN_NOTEXT
) == 0 && n
->tok
!= MAN_SM
)
971 term_fontrepl(p
, TERMFONT_NONE
);
975 * If we're in a literal context, make sure that words
976 * together on the same line stay together. This is a
977 * POST-printing call, so we check the NEXT word. Since
978 * -man doesn't have nested macros, we don't need to be
979 * more specific than this.
981 if (n
->flags
& NODE_NOFILL
&&
982 ! (p
->flags
& (TERMP_NOBREAK
| TERMP_NONEWLINE
)) &&
983 (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
)) {
984 p
->flags
|= TERMP_BRNEVER
| TERMP_NOSPACE
;
985 if (n
->string
!= NULL
&& *n
->string
!= '\0')
989 p
->flags
&= ~TERMP_BRNEVER
;
990 if (p
->tcol
->rmargin
< p
->maxrmargin
&&
991 n
->parent
->tok
== MAN_HP
) {
992 p
->tcol
->offset
= p
->tcol
->rmargin
;
993 p
->tcol
->rmargin
= p
->maxrmargin
;
996 if (NODE_EOS
& n
->flags
)
997 p
->flags
|= TERMP_SENTENCE
;
1002 print_man_nodelist(DECL_ARGS
)
1006 print_man_node(p
, mt
, n
, meta
);
1012 print_man_foot(struct termp
*p
, const struct roff_meta
*meta
)
1015 size_t datelen
, titlen
;
1017 assert(meta
->title
);
1021 term_fontrepl(p
, TERMFONT_NONE
);
1027 * Temporary, undocumented option to imitate mdoc(7) output.
1028 * In the bottom right corner, use the operating system
1029 * instead of the title.
1032 if ( ! p
->mdocstyle
) {
1033 if (meta
->hasbody
) {
1037 mandoc_asprintf(&title
, "%s(%s)",
1038 meta
->title
, meta
->msec
);
1039 } else if (meta
->os
) {
1040 title
= mandoc_strdup(meta
->os
);
1042 title
= mandoc_strdup("");
1044 datelen
= term_strlen(p
, meta
->date
);
1046 /* Bottom left corner: operating system. */
1048 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
1050 p
->tcol
->offset
= 0;
1051 p
->tcol
->rmargin
= p
->maxrmargin
> datelen
?
1052 (p
->maxrmargin
+ term_len(p
, 1) - datelen
) / 2 : 0;
1055 term_word(p
, meta
->os
);
1058 /* At the bottom in the middle: manual date. */
1060 p
->tcol
->offset
= p
->tcol
->rmargin
;
1061 titlen
= term_strlen(p
, title
);
1062 p
->tcol
->rmargin
= p
->maxrmargin
> titlen
?
1063 p
->maxrmargin
- titlen
: 0;
1064 p
->flags
|= TERMP_NOSPACE
;
1066 term_word(p
, meta
->date
);
1069 /* Bottom right corner: manual title and section. */
1071 p
->flags
&= ~TERMP_NOBREAK
;
1072 p
->flags
|= TERMP_NOSPACE
;
1074 p
->tcol
->offset
= p
->tcol
->rmargin
;
1075 p
->tcol
->rmargin
= p
->maxrmargin
;
1077 term_word(p
, title
);
1081 * Reset the terminal state for more output after the footer:
1082 * Some output modes, in particular PostScript and PDF, print
1083 * the header and the footer into a buffer such that it can be
1084 * reused for multiple output pages, then go on to format the
1088 p
->tcol
->offset
= 0;
1095 print_man_head(struct termp
*p
, const struct roff_meta
*meta
)
1099 size_t vollen
, titlen
;
1101 assert(meta
->title
);
1104 volume
= NULL
== meta
->vol
? "" : meta
->vol
;
1105 vollen
= term_strlen(p
, volume
);
1107 /* Top left corner: manual title and section. */
1109 mandoc_asprintf(&title
, "%s(%s)", meta
->title
, meta
->msec
);
1110 titlen
= term_strlen(p
, title
);
1112 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
1114 p
->tcol
->offset
= 0;
1115 p
->tcol
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
1116 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
1117 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
1119 term_word(p
, title
);
1122 /* At the top in the middle: manual volume. */
1124 p
->flags
|= TERMP_NOSPACE
;
1125 p
->tcol
->offset
= p
->tcol
->rmargin
;
1126 p
->tcol
->rmargin
= p
->tcol
->offset
+ vollen
+ titlen
<
1127 p
->maxrmargin
? p
->maxrmargin
- titlen
: p
->maxrmargin
;
1129 term_word(p
, volume
);
1132 /* Top right corner: title and section, again. */
1134 p
->flags
&= ~TERMP_NOBREAK
;
1136 if (p
->tcol
->rmargin
+ titlen
<= p
->maxrmargin
) {
1137 p
->flags
|= TERMP_NOSPACE
;
1138 p
->tcol
->offset
= p
->tcol
->rmargin
;
1139 p
->tcol
->rmargin
= p
->maxrmargin
;
1140 term_word(p
, title
);
1144 p
->flags
&= ~TERMP_NOSPACE
;
1145 p
->tcol
->offset
= 0;
1146 p
->tcol
->rmargin
= p
->maxrmargin
;
1149 * Groff prints three blank lines before the content.
1150 * Do the same, except in the temporary, undocumented
1151 * mode imitating mdoc(7) output.
1155 if ( ! p
->mdocstyle
) {