1 /* $Id: man_term.c,v 1.215 2018/08/18 02:08:27 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
, 0 }, /* nf */
121 { pre_literal
, NULL
, 0 }, /* 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_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_NOSPACE
;
376 if (n
->child
== NULL
) {
377 p
->tcol
->offset
= mt
->offset
;
381 cp
= n
->child
->string
;
391 if (a2roffsu(++cp
, &su
, SCALE_EN
) == NULL
)
394 v
= term_hen(p
, &su
);
397 p
->tcol
->offset
-= p
->tcol
->offset
> v
? v
: p
->tcol
->offset
;
399 p
->tcol
->offset
+= v
;
402 if (p
->tcol
->offset
> SHRT_MAX
)
403 p
->tcol
->offset
= term_len(p
, p
->defindent
);
411 term_tab_set(p
, NULL
);
412 term_tab_set(p
, "T");
413 term_tab_set(p
, ".5i");
421 const struct roff_node
*nn
;
426 print_bvspace(p
, n
, mt
->pardist
);
434 if ( ! (MANT_LITERAL
& mt
->fl
)) {
435 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
439 /* Calculate offset. */
441 if ((nn
= n
->parent
->head
->child
) != NULL
&&
442 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
443 len
= term_hen(p
, &su
);
444 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
446 else if (len
> SHRT_MAX
)
447 len
= term_len(p
, p
->defindent
);
448 mt
->lmargin
[mt
->lmargincur
] = len
;
450 len
= mt
->lmargin
[mt
->lmargincur
];
452 p
->tcol
->offset
= mt
->offset
;
453 p
->tcol
->rmargin
= mt
->offset
+ len
;
466 * Compatibility with a groff bug.
467 * The .HP macro uses the undocumented .tag request
468 * which causes a line break and cancels no-space
469 * mode even if there isn't any output.
472 if (n
->child
== NULL
)
475 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
477 p
->tcol
->offset
= mt
->offset
;
478 p
->tcol
->rmargin
= p
->maxrmargin
;
491 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
492 print_bvspace(p
, n
, mt
->pardist
);
495 p
->tcol
->offset
= mt
->offset
;
499 return n
->type
!= ROFFT_HEAD
;
506 const struct roff_node
*nn
;
511 p
->flags
|= TERMP_NOSPACE
;
514 p
->flags
|= TERMP_NOBREAK
;
518 print_bvspace(p
, n
, mt
->pardist
);
524 /* Calculate the offset from the optional second argument. */
525 if ((nn
= n
->parent
->head
->child
) != NULL
&&
526 (nn
= nn
->next
) != NULL
&&
527 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
528 len
= term_hen(p
, &su
);
529 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
531 else if (len
> SHRT_MAX
)
532 len
= term_len(p
, p
->defindent
);
533 mt
->lmargin
[mt
->lmargincur
] = len
;
535 len
= mt
->lmargin
[mt
->lmargincur
];
539 p
->tcol
->offset
= mt
->offset
;
540 p
->tcol
->rmargin
= mt
->offset
+ len
;
542 savelit
= MANT_LITERAL
& mt
->fl
;
543 mt
->fl
&= ~MANT_LITERAL
;
546 print_man_node(p
, mt
, n
->child
, meta
);
549 mt
->fl
|= MANT_LITERAL
;
553 p
->tcol
->offset
= mt
->offset
+ len
;
554 p
->tcol
->rmargin
= p
->maxrmargin
;
570 p
->flags
&= ~TERMP_NOBREAK
;
572 p
->tcol
->rmargin
= p
->maxrmargin
;
576 p
->tcol
->offset
= mt
->offset
;
587 struct roff_node
*nn
;
592 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
;
596 p
->flags
|= TERMP_NOSPACE
;
599 if (n
->tok
== MAN_TP
)
600 print_bvspace(p
, n
, mt
->pardist
);
606 /* Calculate offset. */
608 if ((nn
= n
->parent
->head
->child
) != NULL
&&
609 nn
->string
!= NULL
&& ! (NODE_LINE
& nn
->flags
) &&
610 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
611 len
= term_hen(p
, &su
);
612 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
614 else if (len
> SHRT_MAX
)
615 len
= term_len(p
, p
->defindent
);
616 mt
->lmargin
[mt
->lmargincur
] = len
;
618 len
= mt
->lmargin
[mt
->lmargincur
];
622 p
->tcol
->offset
= mt
->offset
;
623 p
->tcol
->rmargin
= mt
->offset
+ len
;
625 savelit
= MANT_LITERAL
& mt
->fl
;
626 mt
->fl
&= ~MANT_LITERAL
;
628 /* Don't print same-line elements. */
630 while (NULL
!= nn
&& 0 == (NODE_LINE
& nn
->flags
))
634 print_man_node(p
, mt
, nn
, meta
);
639 mt
->fl
|= MANT_LITERAL
;
642 p
->tcol
->offset
= mt
->offset
+ len
;
643 p
->tcol
->rmargin
= p
->maxrmargin
;
645 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRTRSP
);
664 p
->tcol
->offset
= mt
->offset
;
678 mt
->fl
&= ~MANT_LITERAL
;
679 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
680 mt
->offset
= term_len(p
, p
->defindent
);
683 * No vertical space before the first subsection
684 * and after an empty subsection.
689 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
690 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
691 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
692 (n
->tok
== MAN_SS
&& n
->body
->child
== NULL
))
695 for (i
= 0; i
< mt
->pardist
; i
++)
699 term_fontrepl(p
, TERMFONT_BOLD
);
700 p
->tcol
->offset
= term_len(p
, 3);
701 p
->tcol
->rmargin
= mt
->offset
;
702 p
->trailspace
= mt
->offset
;
703 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
706 p
->tcol
->offset
= mt
->offset
;
707 p
->tcol
->rmargin
= p
->maxrmargin
;
709 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
741 mt
->fl
&= ~MANT_LITERAL
;
742 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
743 mt
->offset
= term_len(p
, p
->defindent
);
746 * No vertical space before the first section
747 * and after an empty section.
752 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
753 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
754 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
755 (n
->tok
== MAN_SH
&& n
->body
->child
== NULL
))
758 for (i
= 0; i
< mt
->pardist
; i
++)
762 term_fontrepl(p
, TERMFONT_BOLD
);
764 p
->tcol
->rmargin
= mt
->offset
;
765 p
->trailspace
= mt
->offset
;
766 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
769 p
->tcol
->offset
= mt
->offset
;
770 p
->tcol
->rmargin
= p
->maxrmargin
;
772 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
813 n
->aux
= SHRT_MAX
+ 1;
814 if (n
->child
== NULL
)
815 n
->aux
= mt
->lmargin
[mt
->lmargincur
];
816 else if (a2roffsu(n
->child
->string
, &su
, SCALE_EN
) != NULL
)
817 n
->aux
= term_hen(p
, &su
);
818 if (n
->aux
< 0 && (size_t)(-n
->aux
) > mt
->offset
)
819 n
->aux
= -mt
->offset
;
820 else if (n
->aux
> SHRT_MAX
)
821 n
->aux
= term_len(p
, p
->defindent
);
823 mt
->offset
+= n
->aux
;
824 p
->tcol
->offset
= mt
->offset
;
825 p
->tcol
->rmargin
= p
->maxrmargin
;
827 if (++mt
->lmarginsz
< MAXMARGINS
)
828 mt
->lmargincur
= mt
->lmarginsz
;
830 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
848 mt
->offset
-= n
->parent
->head
->aux
;
849 p
->tcol
->offset
= mt
->offset
;
851 if (--mt
->lmarginsz
< MAXMARGINS
)
852 mt
->lmargincur
= mt
->lmarginsz
;
858 const struct roff_node
*nn
;
863 print_bvspace(p
, n
, mt
->pardist
);
872 nn
= n
->parent
->head
->child
;
873 len
= nn
== NULL
? 0 : term_strlen(p
, nn
->string
) + 1;
877 p
->tcol
->offset
= mt
->offset
;
878 p
->tcol
->rmargin
= mt
->offset
+ len
;
879 p
->flags
|= TERMP_NOBREAK
;
880 term_fontrepl(p
, TERMFONT_BOLD
);
883 mt
->lmargin
[mt
->lmargincur
] = len
;
884 p
->tcol
->offset
= mt
->offset
+ len
;
885 p
->tcol
->rmargin
= p
->maxrmargin
;
886 p
->flags
|= TERMP_NOSPACE
;
900 p
->flags
&= ~TERMP_NOBREAK
;
904 p
->tcol
->offset
= mt
->offset
;
915 return n
->type
!= ROFFT_HEAD
;
922 if (n
->type
!= ROFFT_BLOCK
)
926 p
->flags
|= TERMP_NOSPACE
;
928 if (NULL
!= n
->child
->child
)
929 print_man_node(p
, mt
, n
->child
->child
, meta
);
931 p
->flags
|= TERMP_NOSPACE
;
936 print_man_node(DECL_ARGS
)
938 const struct man_term_act
*act
;
944 * If we have a blank line, output a vertical space.
945 * If we have a space as the first character, break
946 * before printing the line's data.
948 if (*n
->string
== '\0') {
949 if (p
->flags
& TERMP_NONEWLINE
)
954 } else if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
955 (p
->flags
& TERMP_NONEWLINE
) == 0)
957 else if (n
->flags
& NODE_DELIMC
)
958 p
->flags
|= TERMP_NOSPACE
;
960 term_word(p
, n
->string
);
965 if ( ! (n
->flags
& NODE_LINE
))
966 p
->flags
|= TERMP_NOSPACE
;
968 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
969 p
->flags
|= TERMP_NOSPACE
;
972 if (p
->tbl
.cols
== NULL
)
974 term_tbl(p
, n
->span
);
980 if (n
->tok
< ROFF_MAX
) {
985 act
= man_term_act(n
->tok
);
986 if ((act
->flags
& MAN_NOTEXT
) == 0)
987 term_fontrepl(p
, TERMFONT_NONE
);
990 if (act
->pre
!= NULL
)
991 c
= (*act
->pre
)(p
, mt
, n
, meta
);
994 print_man_nodelist(p
, mt
, n
->child
, meta
);
996 if (act
->post
!= NULL
)
997 (*act
->post
)(p
, mt
, n
, meta
);
998 if ((act
->flags
& MAN_NOTEXT
) == 0)
999 term_fontrepl(p
, TERMFONT_NONE
);
1003 * If we're in a literal context, make sure that words
1004 * together on the same line stay together. This is a
1005 * POST-printing call, so we check the NEXT word. Since
1006 * -man doesn't have nested macros, we don't need to be
1007 * more specific than this.
1009 if (mt
->fl
& MANT_LITERAL
&&
1010 ! (p
->flags
& (TERMP_NOBREAK
| TERMP_NONEWLINE
)) &&
1011 (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
)) {
1012 p
->flags
|= TERMP_BRNEVER
| TERMP_NOSPACE
;
1013 if (n
->string
!= NULL
&& *n
->string
!= '\0')
1017 p
->flags
&= ~TERMP_BRNEVER
;
1018 if (p
->tcol
->rmargin
< p
->maxrmargin
&&
1019 n
->parent
->tok
== MAN_HP
) {
1020 p
->tcol
->offset
= p
->tcol
->rmargin
;
1021 p
->tcol
->rmargin
= p
->maxrmargin
;
1024 if (NODE_EOS
& n
->flags
)
1025 p
->flags
|= TERMP_SENTENCE
;
1030 print_man_nodelist(DECL_ARGS
)
1034 print_man_node(p
, mt
, n
, meta
);
1040 print_man_foot(struct termp
*p
, const struct roff_meta
*meta
)
1043 size_t datelen
, titlen
;
1045 assert(meta
->title
);
1049 term_fontrepl(p
, TERMFONT_NONE
);
1055 * Temporary, undocumented option to imitate mdoc(7) output.
1056 * In the bottom right corner, use the operating system
1057 * instead of the title.
1060 if ( ! p
->mdocstyle
) {
1061 if (meta
->hasbody
) {
1065 mandoc_asprintf(&title
, "%s(%s)",
1066 meta
->title
, meta
->msec
);
1067 } else if (meta
->os
) {
1068 title
= mandoc_strdup(meta
->os
);
1070 title
= mandoc_strdup("");
1072 datelen
= term_strlen(p
, meta
->date
);
1074 /* Bottom left corner: operating system. */
1076 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
1078 p
->tcol
->offset
= 0;
1079 p
->tcol
->rmargin
= p
->maxrmargin
> datelen
?
1080 (p
->maxrmargin
+ term_len(p
, 1) - datelen
) / 2 : 0;
1083 term_word(p
, meta
->os
);
1086 /* At the bottom in the middle: manual date. */
1088 p
->tcol
->offset
= p
->tcol
->rmargin
;
1089 titlen
= term_strlen(p
, title
);
1090 p
->tcol
->rmargin
= p
->maxrmargin
> titlen
?
1091 p
->maxrmargin
- titlen
: 0;
1092 p
->flags
|= TERMP_NOSPACE
;
1094 term_word(p
, meta
->date
);
1097 /* Bottom right corner: manual title and section. */
1099 p
->flags
&= ~TERMP_NOBREAK
;
1100 p
->flags
|= TERMP_NOSPACE
;
1102 p
->tcol
->offset
= p
->tcol
->rmargin
;
1103 p
->tcol
->rmargin
= p
->maxrmargin
;
1105 term_word(p
, title
);
1109 * Reset the terminal state for more output after the footer:
1110 * Some output modes, in particular PostScript and PDF, print
1111 * the header and the footer into a buffer such that it can be
1112 * reused for multiple output pages, then go on to format the
1116 p
->tcol
->offset
= 0;
1123 print_man_head(struct termp
*p
, const struct roff_meta
*meta
)
1127 size_t vollen
, titlen
;
1129 assert(meta
->title
);
1132 volume
= NULL
== meta
->vol
? "" : meta
->vol
;
1133 vollen
= term_strlen(p
, volume
);
1135 /* Top left corner: manual title and section. */
1137 mandoc_asprintf(&title
, "%s(%s)", meta
->title
, meta
->msec
);
1138 titlen
= term_strlen(p
, title
);
1140 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
1142 p
->tcol
->offset
= 0;
1143 p
->tcol
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
1144 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
1145 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
1147 term_word(p
, title
);
1150 /* At the top in the middle: manual volume. */
1152 p
->flags
|= TERMP_NOSPACE
;
1153 p
->tcol
->offset
= p
->tcol
->rmargin
;
1154 p
->tcol
->rmargin
= p
->tcol
->offset
+ vollen
+ titlen
<
1155 p
->maxrmargin
? p
->maxrmargin
- titlen
: p
->maxrmargin
;
1157 term_word(p
, volume
);
1160 /* Top right corner: title and section, again. */
1162 p
->flags
&= ~TERMP_NOBREAK
;
1164 if (p
->tcol
->rmargin
+ titlen
<= p
->maxrmargin
) {
1165 p
->flags
|= TERMP_NOSPACE
;
1166 p
->tcol
->offset
= p
->tcol
->rmargin
;
1167 p
->tcol
->rmargin
= p
->maxrmargin
;
1168 term_word(p
, title
);
1172 p
->flags
&= ~TERMP_NOSPACE
;
1173 p
->tcol
->offset
= 0;
1174 p
->tcol
->rmargin
= p
->maxrmargin
;
1177 * Groff prints three blank lines before the content.
1178 * Do the same, except in the temporary, undocumented
1179 * mode imitating mdoc(7) output.
1183 if ( ! p
->mdocstyle
) {