1 /* $Id: man_term.c,v 1.219 2018/08/18 17:07:23 schwarze Exp $ */
3 * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010-2015, 2017, 2018 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_DT(DECL_ARGS
);
72 static int pre_HP(DECL_ARGS
);
73 static int pre_I(DECL_ARGS
);
74 static int pre_IP(DECL_ARGS
);
75 static int pre_OP(DECL_ARGS
);
76 static int pre_PD(DECL_ARGS
);
77 static int pre_PP(DECL_ARGS
);
78 static int pre_RS(DECL_ARGS
);
79 static int pre_SH(DECL_ARGS
);
80 static int pre_SS(DECL_ARGS
);
81 static int pre_SY(DECL_ARGS
);
82 static int pre_TP(DECL_ARGS
);
83 static int pre_UR(DECL_ARGS
);
84 static int pre_alternate(DECL_ARGS
);
85 static int pre_ign(DECL_ARGS
);
86 static int pre_in(DECL_ARGS
);
87 static int pre_literal(DECL_ARGS
);
89 static void post_IP(DECL_ARGS
);
90 static void post_HP(DECL_ARGS
);
91 static void post_RS(DECL_ARGS
);
92 static void post_SH(DECL_ARGS
);
93 static void post_SS(DECL_ARGS
);
94 static void post_SY(DECL_ARGS
);
95 static void post_TP(DECL_ARGS
);
96 static void post_UR(DECL_ARGS
);
98 static const struct man_term_act man_term_acts
[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_TP
, post_TP
, 0 }, /* TQ */
104 { pre_PP
, NULL
, 0 }, /* LP */
105 { pre_PP
, NULL
, 0 }, /* PP */
106 { pre_PP
, NULL
, 0 }, /* P */
107 { pre_IP
, post_IP
, 0 }, /* IP */
108 { pre_HP
, post_HP
, 0 }, /* HP */
109 { NULL
, NULL
, 0 }, /* SM */
110 { pre_B
, NULL
, 0 }, /* SB */
111 { pre_alternate
, NULL
, 0 }, /* BI */
112 { pre_alternate
, NULL
, 0 }, /* IB */
113 { pre_alternate
, NULL
, 0 }, /* BR */
114 { pre_alternate
, NULL
, 0 }, /* RB */
115 { NULL
, NULL
, 0 }, /* R */
116 { pre_B
, NULL
, 0 }, /* B */
117 { pre_I
, NULL
, 0 }, /* I */
118 { pre_alternate
, NULL
, 0 }, /* IR */
119 { pre_alternate
, NULL
, 0 }, /* RI */
120 { pre_literal
, NULL
, MAN_NOTEXT
}, /* nf */
121 { pre_literal
, NULL
, MAN_NOTEXT
}, /* fi */
122 { NULL
, NULL
, 0 }, /* RE */
123 { pre_RS
, post_RS
, 0 }, /* RS */
124 { pre_DT
, 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_SY
, post_SY
, 0 }, /* SY */
130 { NULL
, NULL
, 0 }, /* YS */
131 { pre_OP
, NULL
, 0 }, /* OP */
132 { pre_literal
, NULL
, 0 }, /* EX */
133 { pre_literal
, NULL
, 0 }, /* EE */
134 { pre_UR
, post_UR
, 0 }, /* UR */
135 { NULL
, NULL
, 0 }, /* UE */
136 { pre_UR
, post_UR
, 0 }, /* MT */
137 { NULL
, NULL
, 0 }, /* ME */
139 static const struct man_term_act
*man_term_act(enum roff_tok
);
142 static const struct man_term_act
*
143 man_term_act(enum roff_tok tok
)
145 assert(tok
>= MAN_TH
&& tok
<= MAN_MAX
);
146 return man_term_acts
+ (tok
- MAN_TH
);
150 terminal_man(void *arg
, const struct roff_man
*man
)
155 size_t save_defindent
;
157 p
= (struct termp
*)arg
;
158 save_defindent
= p
->defindent
;
159 if (p
->synopsisonly
== 0 && p
->defindent
== 0)
161 p
->tcol
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
162 term_tab_set(p
, NULL
);
163 term_tab_set(p
, "T");
164 term_tab_set(p
, ".5i");
166 memset(&mt
, 0, sizeof(struct mtermp
));
167 mt
.lmargin
[mt
.lmargincur
] = term_len(p
, p
->defindent
);
168 mt
.offset
= term_len(p
, p
->defindent
);
171 n
= man
->first
->child
;
172 if (p
->synopsisonly
) {
174 if (n
->tok
== MAN_SH
&&
175 n
->child
->child
->type
== ROFFT_TEXT
&&
176 !strcmp(n
->child
->child
->string
, "SYNOPSIS")) {
177 if (n
->child
->next
->child
!= NULL
)
178 print_man_nodelist(p
, &mt
,
179 n
->child
->next
->child
,
187 term_begin(p
, print_man_head
, print_man_foot
, &man
->meta
);
188 p
->flags
|= TERMP_NOSPACE
;
190 print_man_nodelist(p
, &mt
, n
, &man
->meta
);
193 p
->defindent
= save_defindent
;
197 * Printing leading vertical space before a block.
198 * This is used for the paragraph macros.
199 * The rules are pretty simple, since there's very little nesting going
200 * on here. Basically, if we're the first within another block (SS/SH),
201 * then don't emit vertical space. If we are (RS), then do. If not the
205 print_bvspace(struct termp
*p
, const struct roff_node
*n
, int pardist
)
211 if (n
->body
&& n
->body
->child
)
212 if (n
->body
->child
->type
== ROFFT_TBL
)
215 if (n
->parent
->type
== ROFFT_ROOT
|| n
->parent
->tok
!= MAN_RS
)
219 for (i
= 0; i
< pardist
; i
++)
235 term_fontrepl(p
, TERMFONT_UNDER
);
240 pre_literal(DECL_ARGS
)
245 if (n
->tok
== MAN_nf
|| n
->tok
== MAN_EX
)
246 mt
->fl
|= MANT_LITERAL
;
248 mt
->fl
&= ~MANT_LITERAL
;
251 * Unlike .IP and .TP, .HP does not have a HEAD.
252 * So in case a second call to term_flushln() is needed,
253 * indentation has to be set up explicitly.
255 if (n
->parent
->tok
== MAN_HP
&& p
->tcol
->rmargin
< p
->maxrmargin
) {
256 p
->tcol
->offset
= p
->tcol
->rmargin
;
257 p
->tcol
->rmargin
= p
->maxrmargin
;
259 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
260 p
->flags
|= TERMP_NOSPACE
;
276 assert(n
->type
== ROFFT_TEXT
);
277 if (a2roffsu(n
->string
, &su
, SCALE_VS
) != NULL
)
278 mt
->pardist
= term_vspan(p
, &su
);
283 pre_alternate(DECL_ARGS
)
285 enum termfont font
[2];
286 struct roff_node
*nn
;
291 font
[0] = TERMFONT_NONE
;
292 font
[1] = TERMFONT_BOLD
;
295 font
[0] = TERMFONT_NONE
;
296 font
[1] = TERMFONT_UNDER
;
299 font
[0] = TERMFONT_BOLD
;
300 font
[1] = TERMFONT_NONE
;
303 font
[0] = TERMFONT_BOLD
;
304 font
[1] = TERMFONT_UNDER
;
307 font
[0] = TERMFONT_UNDER
;
308 font
[1] = TERMFONT_NONE
;
311 font
[0] = TERMFONT_UNDER
;
312 font
[1] = TERMFONT_BOLD
;
318 savelit
= MANT_LITERAL
& mt
->fl
;
319 mt
->fl
&= ~MANT_LITERAL
;
321 for (i
= 0, nn
= n
->child
; nn
; nn
= nn
->next
, i
= 1 - i
) {
322 term_fontrepl(p
, font
[i
]);
323 if (savelit
&& NULL
== nn
->next
)
324 mt
->fl
|= MANT_LITERAL
;
325 assert(nn
->type
== ROFFT_TEXT
);
326 term_word(p
, nn
->string
);
327 if (nn
->flags
& NODE_EOS
)
328 p
->flags
|= TERMP_SENTENCE
;
330 p
->flags
|= TERMP_NOSPACE
;
340 term_fontrepl(p
, TERMFONT_BOLD
);
349 p
->flags
|= TERMP_KEEP
| TERMP_NOSPACE
;
351 if (NULL
!= (n
= n
->child
)) {
352 term_fontrepl(p
, TERMFONT_BOLD
);
353 term_word(p
, n
->string
);
355 if (NULL
!= n
&& NULL
!= n
->next
) {
356 term_fontrepl(p
, TERMFONT_UNDER
);
357 term_word(p
, n
->next
->string
);
360 term_fontrepl(p
, TERMFONT_NONE
);
361 p
->flags
&= ~TERMP_KEEP
;
362 p
->flags
|= TERMP_NOSPACE
;
377 if (n
->child
== NULL
) {
378 p
->tcol
->offset
= mt
->offset
;
382 cp
= n
->child
->string
;
392 if (a2roffsu(++cp
, &su
, SCALE_EN
) == NULL
)
395 v
= term_hen(p
, &su
);
398 p
->tcol
->offset
-= p
->tcol
->offset
> v
? v
: p
->tcol
->offset
;
400 p
->tcol
->offset
+= v
;
403 if (p
->tcol
->offset
> SHRT_MAX
)
404 p
->tcol
->offset
= term_len(p
, p
->defindent
);
412 term_tab_set(p
, NULL
);
413 term_tab_set(p
, "T");
414 term_tab_set(p
, ".5i");
422 const struct roff_node
*nn
;
427 print_bvspace(p
, n
, mt
->pardist
);
435 if ( ! (MANT_LITERAL
& mt
->fl
)) {
436 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
440 /* Calculate offset. */
442 if ((nn
= n
->parent
->head
->child
) != NULL
&&
443 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
444 len
= term_hen(p
, &su
);
445 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
447 else if (len
> SHRT_MAX
)
448 len
= term_len(p
, p
->defindent
);
449 mt
->lmargin
[mt
->lmargincur
] = len
;
451 len
= mt
->lmargin
[mt
->lmargincur
];
453 p
->tcol
->offset
= mt
->offset
;
454 p
->tcol
->rmargin
= mt
->offset
+ len
;
467 * Compatibility with a groff bug.
468 * The .HP macro uses the undocumented .tag request
469 * which causes a line break and cancels no-space
470 * mode even if there isn't any output.
473 if (n
->child
== NULL
)
476 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
478 p
->tcol
->offset
= mt
->offset
;
479 p
->tcol
->rmargin
= p
->maxrmargin
;
492 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
493 print_bvspace(p
, n
, mt
->pardist
);
496 p
->tcol
->offset
= mt
->offset
;
500 return n
->type
!= ROFFT_HEAD
;
507 const struct roff_node
*nn
;
512 p
->flags
|= TERMP_NOSPACE
;
515 p
->flags
|= TERMP_NOBREAK
;
519 print_bvspace(p
, n
, mt
->pardist
);
525 /* Calculate the offset from the optional second argument. */
526 if ((nn
= n
->parent
->head
->child
) != NULL
&&
527 (nn
= nn
->next
) != NULL
&&
528 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
529 len
= term_hen(p
, &su
);
530 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
532 else if (len
> SHRT_MAX
)
533 len
= term_len(p
, p
->defindent
);
534 mt
->lmargin
[mt
->lmargincur
] = len
;
536 len
= mt
->lmargin
[mt
->lmargincur
];
540 p
->tcol
->offset
= mt
->offset
;
541 p
->tcol
->rmargin
= mt
->offset
+ len
;
543 savelit
= MANT_LITERAL
& mt
->fl
;
544 mt
->fl
&= ~MANT_LITERAL
;
547 print_man_node(p
, mt
, n
->child
, meta
);
550 mt
->fl
|= MANT_LITERAL
;
554 p
->tcol
->offset
= mt
->offset
+ len
;
555 p
->tcol
->rmargin
= p
->maxrmargin
;
571 p
->flags
&= ~TERMP_NOBREAK
;
573 p
->tcol
->rmargin
= p
->maxrmargin
;
577 p
->tcol
->offset
= mt
->offset
;
588 struct roff_node
*nn
;
593 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
;
597 p
->flags
|= TERMP_NOSPACE
;
600 if (n
->tok
== MAN_TP
)
601 print_bvspace(p
, n
, mt
->pardist
);
607 /* Calculate offset. */
609 if ((nn
= n
->parent
->head
->child
) != NULL
&&
610 nn
->string
!= NULL
&& ! (NODE_LINE
& nn
->flags
) &&
611 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
612 len
= term_hen(p
, &su
);
613 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
615 else if (len
> SHRT_MAX
)
616 len
= term_len(p
, p
->defindent
);
617 mt
->lmargin
[mt
->lmargincur
] = len
;
619 len
= mt
->lmargin
[mt
->lmargincur
];
623 p
->tcol
->offset
= mt
->offset
;
624 p
->tcol
->rmargin
= mt
->offset
+ len
;
626 savelit
= MANT_LITERAL
& mt
->fl
;
627 mt
->fl
&= ~MANT_LITERAL
;
629 /* Don't print same-line elements. */
631 while (NULL
!= nn
&& 0 == (NODE_LINE
& nn
->flags
))
635 print_man_node(p
, mt
, nn
, meta
);
640 mt
->fl
|= MANT_LITERAL
;
643 p
->tcol
->offset
= mt
->offset
+ len
;
644 p
->tcol
->rmargin
= p
->maxrmargin
;
646 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
);
665 p
->tcol
->offset
= mt
->offset
;
679 mt
->fl
&= ~MANT_LITERAL
;
680 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
681 mt
->offset
= term_len(p
, p
->defindent
);
684 * No vertical space before the first subsection
685 * and after an empty subsection.
690 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
691 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
692 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
693 (n
->tok
== MAN_SS
&& n
->body
->child
== NULL
))
696 for (i
= 0; i
< mt
->pardist
; i
++)
700 term_fontrepl(p
, TERMFONT_BOLD
);
701 p
->tcol
->offset
= term_len(p
, 3);
702 p
->tcol
->rmargin
= mt
->offset
;
703 p
->trailspace
= mt
->offset
;
704 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
707 p
->tcol
->offset
= mt
->offset
;
708 p
->tcol
->rmargin
= p
->maxrmargin
;
710 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
742 mt
->fl
&= ~MANT_LITERAL
;
743 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
744 mt
->offset
= term_len(p
, p
->defindent
);
747 * No vertical space before the first section
748 * and after an empty section.
753 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
754 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
755 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
756 (n
->tok
== MAN_SH
&& n
->body
->child
== NULL
))
759 for (i
= 0; i
< mt
->pardist
; i
++)
763 term_fontrepl(p
, TERMFONT_BOLD
);
765 p
->tcol
->rmargin
= mt
->offset
;
766 p
->trailspace
= mt
->offset
;
767 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
770 p
->tcol
->offset
= mt
->offset
;
771 p
->tcol
->rmargin
= p
->maxrmargin
;
773 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
814 n
->aux
= SHRT_MAX
+ 1;
815 if (n
->child
== NULL
)
816 n
->aux
= mt
->lmargin
[mt
->lmargincur
];
817 else if (a2roffsu(n
->child
->string
, &su
, SCALE_EN
) != NULL
)
818 n
->aux
= term_hen(p
, &su
);
819 if (n
->aux
< 0 && (size_t)(-n
->aux
) > mt
->offset
)
820 n
->aux
= -mt
->offset
;
821 else if (n
->aux
> SHRT_MAX
)
822 n
->aux
= term_len(p
, p
->defindent
);
824 mt
->offset
+= n
->aux
;
825 p
->tcol
->offset
= mt
->offset
;
826 p
->tcol
->rmargin
= p
->maxrmargin
;
828 if (++mt
->lmarginsz
< MAXMARGINS
)
829 mt
->lmargincur
= mt
->lmarginsz
;
831 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
849 mt
->offset
-= n
->parent
->head
->aux
;
850 p
->tcol
->offset
= mt
->offset
;
852 if (--mt
->lmarginsz
< MAXMARGINS
)
853 mt
->lmargincur
= mt
->lmarginsz
;
859 const struct roff_node
*nn
;
864 if (n
->prev
== NULL
|| n
->prev
->tok
!= MAN_SY
)
865 print_bvspace(p
, n
, mt
->pardist
);
874 nn
= n
->parent
->head
->child
;
875 len
= nn
== NULL
? 1 : term_strlen(p
, nn
->string
) + 1;
879 p
->tcol
->offset
= mt
->offset
;
880 p
->tcol
->rmargin
= mt
->offset
+ len
;
881 p
->flags
|= TERMP_NOBREAK
;
882 term_fontrepl(p
, TERMFONT_BOLD
);
885 mt
->lmargin
[mt
->lmargincur
] = len
;
886 p
->tcol
->offset
= mt
->offset
+ len
;
887 p
->tcol
->rmargin
= p
->maxrmargin
;
888 p
->flags
|= TERMP_NOSPACE
;
902 p
->flags
&= ~TERMP_NOBREAK
;
906 p
->tcol
->offset
= mt
->offset
;
917 return n
->type
!= ROFFT_HEAD
;
924 if (n
->type
!= ROFFT_BLOCK
)
928 p
->flags
|= TERMP_NOSPACE
;
930 if (NULL
!= n
->child
->child
)
931 print_man_node(p
, mt
, n
->child
->child
, meta
);
933 p
->flags
|= TERMP_NOSPACE
;
938 print_man_node(DECL_ARGS
)
940 const struct man_term_act
*act
;
946 * If we have a blank line, output a vertical space.
947 * If we have a space as the first character, break
948 * before printing the line's data.
950 if (*n
->string
== '\0') {
951 if (p
->flags
& TERMP_NONEWLINE
)
956 } else if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
957 (p
->flags
& TERMP_NONEWLINE
) == 0)
959 else if (n
->flags
& NODE_DELIMC
)
960 p
->flags
|= TERMP_NOSPACE
;
962 term_word(p
, n
->string
);
967 if ( ! (n
->flags
& NODE_LINE
))
968 p
->flags
|= TERMP_NOSPACE
;
970 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
971 p
->flags
|= TERMP_NOSPACE
;
974 if (p
->tbl
.cols
== NULL
)
976 term_tbl(p
, n
->span
);
982 if (n
->tok
< ROFF_MAX
) {
987 act
= man_term_act(n
->tok
);
988 if ((act
->flags
& MAN_NOTEXT
) == 0)
989 term_fontrepl(p
, TERMFONT_NONE
);
992 if (act
->pre
!= NULL
)
993 c
= (*act
->pre
)(p
, mt
, n
, meta
);
996 print_man_nodelist(p
, mt
, n
->child
, meta
);
998 if (act
->post
!= NULL
)
999 (*act
->post
)(p
, mt
, n
, meta
);
1000 if ((act
->flags
& MAN_NOTEXT
) == 0)
1001 term_fontrepl(p
, TERMFONT_NONE
);
1005 * If we're in a literal context, make sure that words
1006 * together on the same line stay together. This is a
1007 * POST-printing call, so we check the NEXT word. Since
1008 * -man doesn't have nested macros, we don't need to be
1009 * more specific than this.
1011 if (mt
->fl
& MANT_LITERAL
&&
1012 ! (p
->flags
& (TERMP_NOBREAK
| TERMP_NONEWLINE
)) &&
1013 (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
)) {
1014 p
->flags
|= TERMP_BRNEVER
| TERMP_NOSPACE
;
1015 if (n
->string
!= NULL
&& *n
->string
!= '\0')
1019 p
->flags
&= ~TERMP_BRNEVER
;
1020 if (p
->tcol
->rmargin
< p
->maxrmargin
&&
1021 n
->parent
->tok
== MAN_HP
) {
1022 p
->tcol
->offset
= p
->tcol
->rmargin
;
1023 p
->tcol
->rmargin
= p
->maxrmargin
;
1026 if (NODE_EOS
& n
->flags
)
1027 p
->flags
|= TERMP_SENTENCE
;
1032 print_man_nodelist(DECL_ARGS
)
1036 print_man_node(p
, mt
, n
, meta
);
1042 print_man_foot(struct termp
*p
, const struct roff_meta
*meta
)
1045 size_t datelen
, titlen
;
1047 assert(meta
->title
);
1051 term_fontrepl(p
, TERMFONT_NONE
);
1057 * Temporary, undocumented option to imitate mdoc(7) output.
1058 * In the bottom right corner, use the operating system
1059 * instead of the title.
1062 if ( ! p
->mdocstyle
) {
1063 if (meta
->hasbody
) {
1067 mandoc_asprintf(&title
, "%s(%s)",
1068 meta
->title
, meta
->msec
);
1069 } else if (meta
->os
) {
1070 title
= mandoc_strdup(meta
->os
);
1072 title
= mandoc_strdup("");
1074 datelen
= term_strlen(p
, meta
->date
);
1076 /* Bottom left corner: operating system. */
1078 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
1080 p
->tcol
->offset
= 0;
1081 p
->tcol
->rmargin
= p
->maxrmargin
> datelen
?
1082 (p
->maxrmargin
+ term_len(p
, 1) - datelen
) / 2 : 0;
1085 term_word(p
, meta
->os
);
1088 /* At the bottom in the middle: manual date. */
1090 p
->tcol
->offset
= p
->tcol
->rmargin
;
1091 titlen
= term_strlen(p
, title
);
1092 p
->tcol
->rmargin
= p
->maxrmargin
> titlen
?
1093 p
->maxrmargin
- titlen
: 0;
1094 p
->flags
|= TERMP_NOSPACE
;
1096 term_word(p
, meta
->date
);
1099 /* Bottom right corner: manual title and section. */
1101 p
->flags
&= ~TERMP_NOBREAK
;
1102 p
->flags
|= TERMP_NOSPACE
;
1104 p
->tcol
->offset
= p
->tcol
->rmargin
;
1105 p
->tcol
->rmargin
= p
->maxrmargin
;
1107 term_word(p
, title
);
1111 * Reset the terminal state for more output after the footer:
1112 * Some output modes, in particular PostScript and PDF, print
1113 * the header and the footer into a buffer such that it can be
1114 * reused for multiple output pages, then go on to format the
1118 p
->tcol
->offset
= 0;
1125 print_man_head(struct termp
*p
, const struct roff_meta
*meta
)
1129 size_t vollen
, titlen
;
1131 assert(meta
->title
);
1134 volume
= NULL
== meta
->vol
? "" : meta
->vol
;
1135 vollen
= term_strlen(p
, volume
);
1137 /* Top left corner: manual title and section. */
1139 mandoc_asprintf(&title
, "%s(%s)", meta
->title
, meta
->msec
);
1140 titlen
= term_strlen(p
, title
);
1142 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
1144 p
->tcol
->offset
= 0;
1145 p
->tcol
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
1146 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
1147 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
1149 term_word(p
, title
);
1152 /* At the top in the middle: manual volume. */
1154 p
->flags
|= TERMP_NOSPACE
;
1155 p
->tcol
->offset
= p
->tcol
->rmargin
;
1156 p
->tcol
->rmargin
= p
->tcol
->offset
+ vollen
+ titlen
<
1157 p
->maxrmargin
? p
->maxrmargin
- titlen
: p
->maxrmargin
;
1159 term_word(p
, volume
);
1162 /* Top right corner: title and section, again. */
1164 p
->flags
&= ~TERMP_NOBREAK
;
1166 if (p
->tcol
->rmargin
+ titlen
<= p
->maxrmargin
) {
1167 p
->flags
|= TERMP_NOSPACE
;
1168 p
->tcol
->offset
= p
->tcol
->rmargin
;
1169 p
->tcol
->rmargin
= p
->maxrmargin
;
1170 term_word(p
, title
);
1174 p
->flags
&= ~TERMP_NOSPACE
;
1175 p
->tcol
->offset
= 0;
1176 p
->tcol
->rmargin
= p
->maxrmargin
;
1179 * Groff prints three blank lines before the content.
1180 * Do the same, except in the temporary, undocumented
1181 * mode imitating mdoc(7) output.
1185 if ( ! p
->mdocstyle
) {