1 /* $Id: man_term.c,v 1.230 2019/07/01 22:56:24 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_SY(DECL_ARGS
);
92 static void post_TP(DECL_ARGS
);
93 static void post_UR(DECL_ARGS
);
95 static const struct man_term_act man_term_acts
[MAN_MAX
- MAN_TH
] = {
96 { NULL
, NULL
, 0 }, /* TH */
97 { pre_SH
, post_SH
, 0 }, /* SH */
98 { pre_SS
, post_SH
, 0 }, /* SS */
99 { pre_TP
, post_TP
, 0 }, /* TP */
100 { pre_TP
, post_TP
, 0 }, /* TQ */
101 { pre_abort
, NULL
, 0 }, /* LP */
102 { pre_PP
, NULL
, 0 }, /* PP */
103 { pre_abort
, NULL
, 0 }, /* P */
104 { pre_IP
, post_IP
, 0 }, /* IP */
105 { pre_HP
, post_HP
, 0 }, /* HP */
106 { NULL
, NULL
, 0 }, /* SM */
107 { pre_B
, NULL
, 0 }, /* SB */
108 { pre_alternate
, NULL
, 0 }, /* BI */
109 { pre_alternate
, NULL
, 0 }, /* IB */
110 { pre_alternate
, NULL
, 0 }, /* BR */
111 { pre_alternate
, NULL
, 0 }, /* RB */
112 { NULL
, NULL
, 0 }, /* R */
113 { pre_B
, NULL
, 0 }, /* B */
114 { pre_I
, NULL
, 0 }, /* I */
115 { pre_alternate
, NULL
, 0 }, /* IR */
116 { pre_alternate
, NULL
, 0 }, /* RI */
117 { NULL
, NULL
, 0 }, /* RE */
118 { pre_RS
, post_RS
, 0 }, /* RS */
119 { pre_DT
, NULL
, 0 }, /* DT */
120 { pre_ign
, NULL
, MAN_NOTEXT
}, /* UC */
121 { pre_PD
, NULL
, MAN_NOTEXT
}, /* PD */
122 { pre_ign
, NULL
, 0 }, /* AT */
123 { pre_in
, NULL
, MAN_NOTEXT
}, /* in */
124 { pre_SY
, post_SY
, 0 }, /* SY */
125 { NULL
, NULL
, 0 }, /* YS */
126 { pre_OP
, NULL
, 0 }, /* OP */
127 { pre_literal
, NULL
, 0 }, /* EX */
128 { pre_literal
, NULL
, 0 }, /* EE */
129 { pre_UR
, post_UR
, 0 }, /* UR */
130 { NULL
, NULL
, 0 }, /* UE */
131 { pre_UR
, post_UR
, 0 }, /* MT */
132 { NULL
, NULL
, 0 }, /* ME */
134 static const struct man_term_act
*man_term_act(enum roff_tok
);
137 static const struct man_term_act
*
138 man_term_act(enum roff_tok tok
)
140 assert(tok
>= MAN_TH
&& tok
<= MAN_MAX
);
141 return man_term_acts
+ (tok
- MAN_TH
);
145 terminal_man(void *arg
, const struct roff_meta
*man
)
149 struct roff_node
*n
, *nc
, *nn
;
150 size_t save_defindent
;
152 p
= (struct termp
*)arg
;
153 save_defindent
= p
->defindent
;
154 if (p
->synopsisonly
== 0 && p
->defindent
== 0)
156 p
->tcol
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
157 term_tab_set(p
, NULL
);
158 term_tab_set(p
, "T");
159 term_tab_set(p
, ".5i");
161 memset(&mt
, 0, sizeof(mt
));
162 mt
.lmargin
[mt
.lmargincur
] = term_len(p
, p
->defindent
);
163 mt
.offset
= term_len(p
, p
->defindent
);
166 n
= man
->first
->child
;
167 if (p
->synopsisonly
) {
168 for (nn
= NULL
; n
!= NULL
; n
= n
->next
) {
169 if (n
->tok
!= MAN_SH
)
171 nc
= n
->child
->child
;
172 if (nc
->type
!= ROFFT_TEXT
)
174 if (strcmp(nc
->string
, "SYNOPSIS") == 0)
176 if (nn
== NULL
&& strcmp(nc
->string
, "NAME") == 0)
181 p
->flags
|= TERMP_NOSPACE
;
182 if (n
!= NULL
&& (n
= n
->child
->next
->child
) != NULL
)
183 print_man_nodelist(p
, &mt
, n
, man
);
186 term_begin(p
, print_man_head
, print_man_foot
, man
);
187 p
->flags
|= TERMP_NOSPACE
;
189 print_man_nodelist(p
, &mt
, n
, man
);
192 p
->defindent
= save_defindent
;
196 * Printing leading vertical space before a block.
197 * This is used for the paragraph macros.
198 * The rules are pretty simple, since there's very little nesting going
199 * on here. Basically, if we're the first within another block (SS/SH),
200 * then don't emit vertical space. If we are (RS), then do. If not the
204 print_bvspace(struct termp
*p
, const struct roff_node
*n
, int pardist
)
210 if (n
->body
!= NULL
&& n
->body
->child
!= NULL
)
211 if (n
->body
->child
->type
== ROFFT_TBL
)
214 if (n
->parent
->type
== ROFFT_ROOT
|| n
->parent
->tok
!= MAN_RS
)
218 for (i
= 0; i
< pardist
; i
++)
238 term_fontrepl(p
, TERMFONT_UNDER
);
243 pre_literal(DECL_ARGS
)
248 * Unlike .IP and .TP, .HP does not have a HEAD.
249 * So in case a second call to term_flushln() is needed,
250 * indentation has to be set up explicitly.
252 if (n
->parent
->tok
== MAN_HP
&& p
->tcol
->rmargin
< p
->maxrmargin
) {
253 p
->tcol
->offset
= p
->tcol
->rmargin
;
254 p
->tcol
->rmargin
= p
->maxrmargin
;
256 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
257 p
->flags
|= TERMP_NOSPACE
;
272 assert(n
->type
== ROFFT_TEXT
);
273 if (a2roffsu(n
->string
, &su
, SCALE_VS
) != NULL
)
274 mt
->pardist
= term_vspan(p
, &su
);
279 pre_alternate(DECL_ARGS
)
281 enum termfont font
[2];
282 struct roff_node
*nn
;
287 font
[0] = TERMFONT_NONE
;
288 font
[1] = TERMFONT_BOLD
;
291 font
[0] = TERMFONT_NONE
;
292 font
[1] = TERMFONT_UNDER
;
295 font
[0] = TERMFONT_BOLD
;
296 font
[1] = TERMFONT_NONE
;
299 font
[0] = TERMFONT_BOLD
;
300 font
[1] = TERMFONT_UNDER
;
303 font
[0] = TERMFONT_UNDER
;
304 font
[1] = TERMFONT_NONE
;
307 font
[0] = TERMFONT_UNDER
;
308 font
[1] = TERMFONT_BOLD
;
313 for (i
= 0, nn
= n
->child
; nn
!= NULL
; nn
= nn
->next
, i
= 1 - i
) {
314 term_fontrepl(p
, font
[i
]);
315 assert(nn
->type
== ROFFT_TEXT
);
316 term_word(p
, nn
->string
);
317 if (nn
->flags
& NODE_EOS
)
318 p
->flags
|= TERMP_SENTENCE
;
319 if (nn
->next
!= NULL
)
320 p
->flags
|= TERMP_NOSPACE
;
328 term_fontrepl(p
, TERMFONT_BOLD
);
336 p
->flags
|= TERMP_KEEP
| TERMP_NOSPACE
;
338 if ((n
= n
->child
) != NULL
) {
339 term_fontrepl(p
, TERMFONT_BOLD
);
340 term_word(p
, n
->string
);
342 if (n
!= NULL
&& n
->next
!= NULL
) {
343 term_fontrepl(p
, TERMFONT_UNDER
);
344 term_word(p
, n
->next
->string
);
346 term_fontrepl(p
, TERMFONT_NONE
);
347 p
->flags
&= ~TERMP_KEEP
;
348 p
->flags
|= TERMP_NOSPACE
;
363 if (n
->child
== NULL
) {
364 p
->tcol
->offset
= mt
->offset
;
368 cp
= n
->child
->string
;
378 if (a2roffsu(++cp
, &su
, SCALE_EN
) == NULL
)
381 v
= term_hen(p
, &su
);
384 p
->tcol
->offset
-= p
->tcol
->offset
> v
? v
: p
->tcol
->offset
;
386 p
->tcol
->offset
+= v
;
389 if (p
->tcol
->offset
> SHRT_MAX
)
390 p
->tcol
->offset
= term_len(p
, p
->defindent
);
398 term_tab_set(p
, NULL
);
399 term_tab_set(p
, "T");
400 term_tab_set(p
, ".5i");
408 const struct roff_node
*nn
;
413 print_bvspace(p
, n
, mt
->pardist
);
423 if (n
->child
== NULL
)
426 if ((n
->child
->flags
& NODE_NOFILL
) == 0) {
427 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
431 /* Calculate offset. */
433 if ((nn
= n
->parent
->head
->child
) != NULL
&&
434 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
435 len
= term_hen(p
, &su
);
436 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
438 else if (len
> SHRT_MAX
)
439 len
= term_len(p
, p
->defindent
);
440 mt
->lmargin
[mt
->lmargincur
] = len
;
442 len
= mt
->lmargin
[mt
->lmargincur
];
444 p
->tcol
->offset
= mt
->offset
;
445 p
->tcol
->rmargin
= mt
->offset
+ len
;
460 * Compatibility with a groff bug.
461 * The .HP macro uses the undocumented .tag request
462 * which causes a line break and cancels no-space
463 * mode even if there isn't any output.
466 if (n
->child
== NULL
)
469 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
471 p
->tcol
->offset
= mt
->offset
;
472 p
->tcol
->rmargin
= p
->maxrmargin
;
484 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
485 print_bvspace(p
, n
, mt
->pardist
);
490 p
->tcol
->offset
= mt
->offset
;
502 const struct roff_node
*nn
;
507 print_bvspace(p
, n
, mt
->pardist
);
510 p
->flags
|= TERMP_NOBREAK
;
514 p
->flags
|= TERMP_NOSPACE
;
520 /* Calculate the offset from the optional second argument. */
521 if ((nn
= n
->parent
->head
->child
) != NULL
&&
522 (nn
= nn
->next
) != NULL
&&
523 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
524 len
= term_hen(p
, &su
);
525 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
527 else if (len
> SHRT_MAX
)
528 len
= term_len(p
, p
->defindent
);
529 mt
->lmargin
[mt
->lmargincur
] = len
;
531 len
= mt
->lmargin
[mt
->lmargincur
];
535 p
->tcol
->offset
= mt
->offset
;
536 p
->tcol
->rmargin
= mt
->offset
+ len
;
537 if (n
->child
!= NULL
)
538 print_man_node(p
, mt
, n
->child
, meta
);
541 p
->tcol
->offset
= mt
->offset
+ len
;
542 p
->tcol
->rmargin
= p
->maxrmargin
;
558 p
->flags
&= ~TERMP_NOBREAK
;
560 p
->tcol
->rmargin
= p
->maxrmargin
;
564 p
->tcol
->offset
= mt
->offset
;
575 struct roff_node
*nn
;
580 if (n
->tok
== MAN_TP
)
581 print_bvspace(p
, n
, mt
->pardist
);
584 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
;
588 p
->flags
|= TERMP_NOSPACE
;
594 /* Calculate offset. */
596 if ((nn
= n
->parent
->head
->child
) != NULL
&&
597 nn
->string
!= NULL
&& ! (NODE_LINE
& nn
->flags
) &&
598 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
599 len
= term_hen(p
, &su
);
600 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
602 else if (len
> SHRT_MAX
)
603 len
= term_len(p
, p
->defindent
);
604 mt
->lmargin
[mt
->lmargincur
] = len
;
606 len
= mt
->lmargin
[mt
->lmargincur
];
610 p
->tcol
->offset
= mt
->offset
;
611 p
->tcol
->rmargin
= mt
->offset
+ len
;
613 /* Don't print same-line elements. */
615 while (nn
!= NULL
&& (nn
->flags
& NODE_LINE
) == 0)
619 print_man_node(p
, mt
, nn
, meta
);
624 p
->tcol
->offset
= mt
->offset
+ len
;
625 p
->tcol
->rmargin
= p
->maxrmargin
;
627 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
);
646 p
->tcol
->offset
= mt
->offset
;
660 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
661 mt
->offset
= term_len(p
, p
->defindent
);
664 * No vertical space before the first subsection
665 * and after an empty subsection.
670 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
671 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
672 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
673 (n
->tok
== MAN_SS
&& n
->body
->child
== NULL
))
676 for (i
= 0; i
< mt
->pardist
; i
++)
680 term_fontrepl(p
, TERMFONT_BOLD
);
681 p
->tcol
->offset
= term_len(p
, 3);
682 p
->tcol
->rmargin
= mt
->offset
;
683 p
->trailspace
= mt
->offset
;
684 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
687 p
->tcol
->offset
= mt
->offset
;
688 p
->tcol
->rmargin
= p
->maxrmargin
;
690 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
705 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
706 mt
->offset
= term_len(p
, p
->defindent
);
709 * No vertical space before the first section
710 * and after an empty section.
715 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
716 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
717 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
718 (n
->tok
== MAN_SH
&& n
->body
->child
== NULL
))
721 for (i
= 0; i
< mt
->pardist
; i
++)
725 term_fontrepl(p
, TERMFONT_BOLD
);
727 p
->tcol
->rmargin
= mt
->offset
;
728 p
->trailspace
= mt
->offset
;
729 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
732 p
->tcol
->offset
= mt
->offset
;
733 p
->tcol
->rmargin
= p
->maxrmargin
;
735 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
776 n
->aux
= SHRT_MAX
+ 1;
777 if (n
->child
== NULL
)
778 n
->aux
= mt
->lmargin
[mt
->lmargincur
];
779 else if (a2roffsu(n
->child
->string
, &su
, SCALE_EN
) != NULL
)
780 n
->aux
= term_hen(p
, &su
);
781 if (n
->aux
< 0 && (size_t)(-n
->aux
) > mt
->offset
)
782 n
->aux
= -mt
->offset
;
783 else if (n
->aux
> SHRT_MAX
)
784 n
->aux
= term_len(p
, p
->defindent
);
786 mt
->offset
+= n
->aux
;
787 p
->tcol
->offset
= mt
->offset
;
788 p
->tcol
->rmargin
= p
->maxrmargin
;
790 if (++mt
->lmarginsz
< MAXMARGINS
)
791 mt
->lmargincur
= mt
->lmarginsz
;
793 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
810 mt
->offset
-= n
->parent
->head
->aux
;
811 p
->tcol
->offset
= mt
->offset
;
812 if (--mt
->lmarginsz
< MAXMARGINS
)
813 mt
->lmargincur
= mt
->lmarginsz
;
819 const struct roff_node
*nn
;
824 if (n
->prev
== NULL
|| n
->prev
->tok
!= MAN_SY
)
825 print_bvspace(p
, n
, mt
->pardist
);
834 nn
= n
->parent
->head
->child
;
835 len
= nn
== NULL
? 1 : term_strlen(p
, nn
->string
) + 1;
839 p
->tcol
->offset
= mt
->offset
;
840 p
->tcol
->rmargin
= mt
->offset
+ len
;
841 if (n
->next
->child
== NULL
||
842 (n
->next
->child
->flags
& NODE_NOFILL
) == 0)
843 p
->flags
|= TERMP_NOBREAK
;
844 term_fontrepl(p
, TERMFONT_BOLD
);
847 mt
->lmargin
[mt
->lmargincur
] = len
;
848 p
->tcol
->offset
= mt
->offset
+ len
;
849 p
->tcol
->rmargin
= p
->maxrmargin
;
850 p
->flags
|= TERMP_NOSPACE
;
866 p
->flags
&= ~TERMP_NOBREAK
;
870 p
->tcol
->offset
= mt
->offset
;
880 return n
->type
!= ROFFT_HEAD
;
886 if (n
->type
!= ROFFT_BLOCK
)
890 p
->flags
|= TERMP_NOSPACE
;
892 if (n
->child
->child
!= NULL
)
893 print_man_node(p
, mt
, n
->child
->child
, meta
);
895 p
->flags
|= TERMP_NOSPACE
;
900 print_man_node(DECL_ARGS
)
902 const struct man_term_act
*act
;
908 * If we have a blank line, output a vertical space.
909 * If we have a space as the first character, break
910 * before printing the line's data.
912 if (*n
->string
== '\0') {
913 if (p
->flags
& TERMP_NONEWLINE
)
918 } else if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
919 (p
->flags
& TERMP_NONEWLINE
) == 0)
921 else if (n
->flags
& NODE_DELIMC
)
922 p
->flags
|= TERMP_NOSPACE
;
924 term_word(p
, n
->string
);
929 if ( ! (n
->flags
& NODE_LINE
))
930 p
->flags
|= TERMP_NOSPACE
;
932 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
933 p
->flags
|= TERMP_NOSPACE
;
936 if (p
->tbl
.cols
== NULL
)
938 term_tbl(p
, n
->span
);
944 if (n
->tok
< ROFF_MAX
) {
949 act
= man_term_act(n
->tok
);
950 if ((act
->flags
& MAN_NOTEXT
) == 0 && n
->tok
!= MAN_SM
)
951 term_fontrepl(p
, TERMFONT_NONE
);
954 if (act
->pre
!= NULL
)
955 c
= (*act
->pre
)(p
, mt
, n
, meta
);
957 if (c
&& n
->child
!= NULL
)
958 print_man_nodelist(p
, mt
, n
->child
, meta
);
960 if (act
->post
!= NULL
)
961 (*act
->post
)(p
, mt
, n
, meta
);
962 if ((act
->flags
& MAN_NOTEXT
) == 0 && n
->tok
!= MAN_SM
)
963 term_fontrepl(p
, TERMFONT_NONE
);
967 * If we're in a literal context, make sure that words
968 * together on the same line stay together. This is a
969 * POST-printing call, so we check the NEXT word. Since
970 * -man doesn't have nested macros, we don't need to be
971 * more specific than this.
973 if (n
->flags
& NODE_NOFILL
&&
974 ! (p
->flags
& (TERMP_NOBREAK
| TERMP_NONEWLINE
)) &&
975 (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
)) {
976 p
->flags
|= TERMP_BRNEVER
| TERMP_NOSPACE
;
977 if (n
->string
!= NULL
&& *n
->string
!= '\0')
981 p
->flags
&= ~TERMP_BRNEVER
;
982 if (p
->tcol
->rmargin
< p
->maxrmargin
&&
983 n
->parent
->tok
== MAN_HP
) {
984 p
->tcol
->offset
= p
->tcol
->rmargin
;
985 p
->tcol
->rmargin
= p
->maxrmargin
;
988 if (n
->flags
& NODE_EOS
)
989 p
->flags
|= TERMP_SENTENCE
;
993 print_man_nodelist(DECL_ARGS
)
996 print_man_node(p
, mt
, n
, meta
);
1002 print_man_foot(struct termp
*p
, const struct roff_meta
*meta
)
1005 size_t datelen
, titlen
;
1007 assert(meta
->title
);
1011 term_fontrepl(p
, TERMFONT_NONE
);
1017 * Temporary, undocumented option to imitate mdoc(7) output.
1018 * In the bottom right corner, use the operating system
1019 * instead of the title.
1022 if ( ! p
->mdocstyle
) {
1023 if (meta
->hasbody
) {
1027 mandoc_asprintf(&title
, "%s(%s)",
1028 meta
->title
, meta
->msec
);
1029 } else if (meta
->os
!= NULL
) {
1030 title
= mandoc_strdup(meta
->os
);
1032 title
= mandoc_strdup("");
1034 datelen
= term_strlen(p
, meta
->date
);
1036 /* Bottom left corner: operating system. */
1038 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
1040 p
->tcol
->offset
= 0;
1041 p
->tcol
->rmargin
= p
->maxrmargin
> datelen
?
1042 (p
->maxrmargin
+ term_len(p
, 1) - datelen
) / 2 : 0;
1045 term_word(p
, meta
->os
);
1048 /* At the bottom in the middle: manual date. */
1050 p
->tcol
->offset
= p
->tcol
->rmargin
;
1051 titlen
= term_strlen(p
, title
);
1052 p
->tcol
->rmargin
= p
->maxrmargin
> titlen
?
1053 p
->maxrmargin
- titlen
: 0;
1054 p
->flags
|= TERMP_NOSPACE
;
1056 term_word(p
, meta
->date
);
1059 /* Bottom right corner: manual title and section. */
1061 p
->flags
&= ~TERMP_NOBREAK
;
1062 p
->flags
|= TERMP_NOSPACE
;
1064 p
->tcol
->offset
= p
->tcol
->rmargin
;
1065 p
->tcol
->rmargin
= p
->maxrmargin
;
1067 term_word(p
, title
);
1071 * Reset the terminal state for more output after the footer:
1072 * Some output modes, in particular PostScript and PDF, print
1073 * the header and the footer into a buffer such that it can be
1074 * reused for multiple output pages, then go on to format the
1078 p
->tcol
->offset
= 0;
1085 print_man_head(struct termp
*p
, const struct roff_meta
*meta
)
1089 size_t vollen
, titlen
;
1091 assert(meta
->title
);
1094 volume
= NULL
== meta
->vol
? "" : meta
->vol
;
1095 vollen
= term_strlen(p
, volume
);
1097 /* Top left corner: manual title and section. */
1099 mandoc_asprintf(&title
, "%s(%s)", meta
->title
, meta
->msec
);
1100 titlen
= term_strlen(p
, title
);
1102 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
1104 p
->tcol
->offset
= 0;
1105 p
->tcol
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
1106 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
1107 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
1109 term_word(p
, title
);
1112 /* At the top in the middle: manual volume. */
1114 p
->flags
|= TERMP_NOSPACE
;
1115 p
->tcol
->offset
= p
->tcol
->rmargin
;
1116 p
->tcol
->rmargin
= p
->tcol
->offset
+ vollen
+ titlen
<
1117 p
->maxrmargin
? p
->maxrmargin
- titlen
: p
->maxrmargin
;
1119 term_word(p
, volume
);
1122 /* Top right corner: title and section, again. */
1124 p
->flags
&= ~TERMP_NOBREAK
;
1126 if (p
->tcol
->rmargin
+ titlen
<= p
->maxrmargin
) {
1127 p
->flags
|= TERMP_NOSPACE
;
1128 p
->tcol
->offset
= p
->tcol
->rmargin
;
1129 p
->tcol
->rmargin
= p
->maxrmargin
;
1130 term_word(p
, title
);
1134 p
->flags
&= ~TERMP_NOSPACE
;
1135 p
->tcol
->offset
= 0;
1136 p
->tcol
->rmargin
= p
->maxrmargin
;
1139 * Groff prints three blank lines before the content.
1140 * Do the same, except in the temporary, undocumented
1141 * mode imitating mdoc(7) output.
1145 if ( ! p
->mdocstyle
) {