1 /* $Id: man_term.c,v 1.232 2019/07/23 17:53:35 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"
38 #define MAXMARGINS 64 /* maximum number of indented scopes */
41 int lmargin
[MAXMARGINS
]; /* margins (incl. vis. page) */
42 int lmargincur
; /* index of current margin */
43 int lmarginsz
; /* actual number of nested margins */
44 size_t offset
; /* default offset to visible page */
45 int pardist
; /* vert. space before par., unit: [v] */
48 #define DECL_ARGS struct termp *p, \
50 struct roff_node *n, \
51 const struct roff_meta *meta
54 int (*pre
)(DECL_ARGS
);
55 void (*post
)(DECL_ARGS
);
57 #define MAN_NOTEXT (1 << 0) /* Never has text children. */
60 static void print_man_nodelist(DECL_ARGS
);
61 static void print_man_node(DECL_ARGS
);
62 static void print_man_head(struct termp
*,
63 const struct roff_meta
*);
64 static void print_man_foot(struct termp
*,
65 const struct roff_meta
*);
66 static void print_bvspace(struct termp
*,
67 const struct roff_node
*, int);
69 static int pre_B(DECL_ARGS
);
70 static int pre_DT(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_SY(DECL_ARGS
);
81 static int pre_TP(DECL_ARGS
);
82 static int pre_UR(DECL_ARGS
);
83 static int pre_abort(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_SY(DECL_ARGS
);
94 static void post_TP(DECL_ARGS
);
95 static void post_UR(DECL_ARGS
);
97 static void tag_man(struct termp
*, struct roff_node
*);
99 static const struct man_term_act man_term_acts
[MAN_MAX
- MAN_TH
] = {
100 { NULL
, NULL
, 0 }, /* TH */
101 { pre_SH
, post_SH
, 0 }, /* SH */
102 { pre_SS
, post_SH
, 0 }, /* SS */
103 { pre_TP
, post_TP
, 0 }, /* TP */
104 { pre_TP
, post_TP
, 0 }, /* TQ */
105 { pre_abort
, NULL
, 0 }, /* LP */
106 { pre_PP
, NULL
, 0 }, /* PP */
107 { pre_abort
, NULL
, 0 }, /* P */
108 { pre_IP
, post_IP
, 0 }, /* IP */
109 { pre_HP
, post_HP
, 0 }, /* HP */
110 { NULL
, NULL
, 0 }, /* SM */
111 { pre_B
, NULL
, 0 }, /* SB */
112 { pre_alternate
, NULL
, 0 }, /* BI */
113 { pre_alternate
, NULL
, 0 }, /* IB */
114 { pre_alternate
, NULL
, 0 }, /* BR */
115 { pre_alternate
, NULL
, 0 }, /* RB */
116 { NULL
, NULL
, 0 }, /* R */
117 { pre_B
, NULL
, 0 }, /* B */
118 { pre_I
, NULL
, 0 }, /* I */
119 { pre_alternate
, NULL
, 0 }, /* IR */
120 { pre_alternate
, NULL
, 0 }, /* RI */
121 { NULL
, NULL
, 0 }, /* RE */
122 { pre_RS
, post_RS
, 0 }, /* RS */
123 { pre_DT
, NULL
, 0 }, /* DT */
124 { pre_ign
, NULL
, MAN_NOTEXT
}, /* UC */
125 { pre_PD
, NULL
, MAN_NOTEXT
}, /* PD */
126 { pre_ign
, NULL
, 0 }, /* AT */
127 { pre_in
, NULL
, MAN_NOTEXT
}, /* in */
128 { pre_SY
, post_SY
, 0 }, /* SY */
129 { NULL
, NULL
, 0 }, /* YS */
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_UR
, post_UR
, 0 }, /* MT */
136 { NULL
, NULL
, 0 }, /* ME */
138 static const struct man_term_act
*man_term_act(enum roff_tok
);
141 static const struct man_term_act
*
142 man_term_act(enum roff_tok tok
)
144 assert(tok
>= MAN_TH
&& tok
<= MAN_MAX
);
145 return man_term_acts
+ (tok
- MAN_TH
);
149 terminal_man(void *arg
, const struct roff_meta
*man
)
153 struct roff_node
*n
, *nc
, *nn
;
154 size_t save_defindent
;
156 p
= (struct termp
*)arg
;
157 save_defindent
= p
->defindent
;
158 if (p
->synopsisonly
== 0 && p
->defindent
== 0)
160 p
->tcol
->rmargin
= p
->maxrmargin
= p
->defrmargin
;
161 term_tab_set(p
, NULL
);
162 term_tab_set(p
, "T");
163 term_tab_set(p
, ".5i");
165 memset(&mt
, 0, sizeof(mt
));
166 mt
.lmargin
[mt
.lmargincur
] = term_len(p
, p
->defindent
);
167 mt
.offset
= term_len(p
, p
->defindent
);
170 n
= man
->first
->child
;
171 if (p
->synopsisonly
) {
172 for (nn
= NULL
; n
!= NULL
; n
= n
->next
) {
173 if (n
->tok
!= MAN_SH
)
175 nc
= n
->child
->child
;
176 if (nc
->type
!= ROFFT_TEXT
)
178 if (strcmp(nc
->string
, "SYNOPSIS") == 0)
180 if (nn
== NULL
&& strcmp(nc
->string
, "NAME") == 0)
185 p
->flags
|= TERMP_NOSPACE
;
186 if (n
!= NULL
&& (n
= n
->child
->next
->child
) != NULL
)
187 print_man_nodelist(p
, &mt
, n
, man
);
190 term_begin(p
, print_man_head
, print_man_foot
, man
);
191 p
->flags
|= TERMP_NOSPACE
;
193 print_man_nodelist(p
, &mt
, n
, man
);
196 p
->defindent
= save_defindent
;
200 * Printing leading vertical space before a block.
201 * This is used for the paragraph macros.
202 * The rules are pretty simple, since there's very little nesting going
203 * on here. Basically, if we're the first within another block (SS/SH),
204 * then don't emit vertical space. If we are (RS), then do. If not the
208 print_bvspace(struct termp
*p
, const struct roff_node
*n
, int pardist
)
214 if (n
->body
!= NULL
&& n
->body
->child
!= NULL
)
215 if (n
->body
->child
->type
== ROFFT_TBL
)
218 if (n
->parent
->type
== ROFFT_ROOT
|| n
->parent
->tok
!= MAN_RS
)
222 for (i
= 0; i
< pardist
; i
++)
242 term_fontrepl(p
, TERMFONT_UNDER
);
247 pre_literal(DECL_ARGS
)
252 * Unlike .IP and .TP, .HP does not have a HEAD.
253 * So in case a second call to term_flushln() is needed,
254 * indentation has to be set up explicitly.
256 if (n
->parent
->tok
== MAN_HP
&& p
->tcol
->rmargin
< p
->maxrmargin
) {
257 p
->tcol
->offset
= p
->tcol
->rmargin
;
258 p
->tcol
->rmargin
= p
->maxrmargin
;
260 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
261 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
;
317 for (i
= 0, nn
= n
->child
; nn
!= NULL
; nn
= nn
->next
, i
= 1 - i
) {
318 term_fontrepl(p
, font
[i
]);
319 assert(nn
->type
== ROFFT_TEXT
);
320 term_word(p
, nn
->string
);
321 if (nn
->flags
& NODE_EOS
)
322 p
->flags
|= TERMP_SENTENCE
;
323 if (nn
->next
!= NULL
)
324 p
->flags
|= TERMP_NOSPACE
;
332 term_fontrepl(p
, TERMFONT_BOLD
);
340 p
->flags
|= TERMP_KEEP
| TERMP_NOSPACE
;
342 if ((n
= n
->child
) != NULL
) {
343 term_fontrepl(p
, TERMFONT_BOLD
);
344 term_word(p
, n
->string
);
346 if (n
!= NULL
&& n
->next
!= NULL
) {
347 term_fontrepl(p
, TERMFONT_UNDER
);
348 term_word(p
, n
->next
->string
);
350 term_fontrepl(p
, TERMFONT_NONE
);
351 p
->flags
&= ~TERMP_KEEP
;
352 p
->flags
|= TERMP_NOSPACE
;
367 if (n
->child
== NULL
) {
368 p
->tcol
->offset
= mt
->offset
;
372 cp
= n
->child
->string
;
382 if (a2roffsu(++cp
, &su
, SCALE_EN
) == NULL
)
385 v
= term_hen(p
, &su
);
388 p
->tcol
->offset
-= p
->tcol
->offset
> v
? v
: p
->tcol
->offset
;
390 p
->tcol
->offset
+= v
;
393 if (p
->tcol
->offset
> SHRT_MAX
)
394 p
->tcol
->offset
= term_len(p
, p
->defindent
);
402 term_tab_set(p
, NULL
);
403 term_tab_set(p
, "T");
404 term_tab_set(p
, ".5i");
412 const struct roff_node
*nn
;
417 print_bvspace(p
, n
, mt
->pardist
);
427 if (n
->child
== NULL
)
430 if ((n
->child
->flags
& NODE_NOFILL
) == 0) {
431 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
435 /* Calculate offset. */
437 if ((nn
= n
->parent
->head
->child
) != NULL
&&
438 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
439 len
= term_hen(p
, &su
);
440 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
442 else if (len
> SHRT_MAX
)
443 len
= term_len(p
, p
->defindent
);
444 mt
->lmargin
[mt
->lmargincur
] = len
;
446 len
= mt
->lmargin
[mt
->lmargincur
];
448 p
->tcol
->offset
= mt
->offset
;
449 p
->tcol
->rmargin
= mt
->offset
+ len
;
464 * Compatibility with a groff bug.
465 * The .HP macro uses the undocumented .tag request
466 * which causes a line break and cancels no-space
467 * mode even if there isn't any output.
470 if (n
->child
== NULL
)
473 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
475 p
->tcol
->offset
= mt
->offset
;
476 p
->tcol
->rmargin
= p
->maxrmargin
;
488 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
489 print_bvspace(p
, n
, mt
->pardist
);
494 p
->tcol
->offset
= mt
->offset
;
506 const struct roff_node
*nn
;
511 print_bvspace(p
, n
, mt
->pardist
);
514 p
->flags
|= TERMP_NOBREAK
;
518 p
->flags
|= TERMP_NOSPACE
;
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
;
541 if (n
->child
!= NULL
) {
542 print_man_node(p
, mt
, n
->child
, meta
);
543 tag_man(p
, n
->child
);
547 p
->tcol
->offset
= mt
->offset
+ len
;
548 p
->tcol
->rmargin
= p
->maxrmargin
;
564 p
->flags
&= ~TERMP_NOBREAK
;
566 p
->tcol
->rmargin
= p
->maxrmargin
;
570 p
->tcol
->offset
= mt
->offset
;
581 struct roff_node
*nn
;
586 if (n
->tok
== MAN_TP
)
587 print_bvspace(p
, n
, mt
->pardist
);
590 p
->flags
|= TERMP_NOBREAK
| TERMP_BRTRSP
;
594 p
->flags
|= TERMP_NOSPACE
;
600 /* Calculate offset. */
602 if ((nn
= n
->parent
->head
->child
) != NULL
&&
603 nn
->string
!= NULL
&& ! (NODE_LINE
& nn
->flags
) &&
604 a2roffsu(nn
->string
, &su
, SCALE_EN
) != NULL
) {
605 len
= term_hen(p
, &su
);
606 if (len
< 0 && (size_t)(-len
) > mt
->offset
)
608 else if (len
> SHRT_MAX
)
609 len
= term_len(p
, p
->defindent
);
610 mt
->lmargin
[mt
->lmargincur
] = len
;
612 len
= mt
->lmargin
[mt
->lmargincur
];
616 p
->tcol
->offset
= mt
->offset
;
617 p
->tcol
->rmargin
= mt
->offset
+ len
;
619 /* Don't print same-line elements. */
621 while (nn
!= NULL
&& (nn
->flags
& NODE_LINE
) == 0)
627 if (nn
->type
== ROFFT_TEXT
)
629 else if (nn
->child
!= NULL
&&
630 nn
->child
->type
== ROFFT_TEXT
&&
631 (nn
->tok
== MAN_B
|| nn
->tok
== MAN_BI
||
632 nn
->tok
== MAN_BR
|| nn
->tok
== MAN_I
||
633 nn
->tok
== MAN_IB
|| nn
->tok
== MAN_IR
))
634 tag_man(p
, nn
->child
);
637 print_man_node(p
, mt
, nn
, meta
);
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
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
679 mt
->offset
= term_len(p
, p
->defindent
);
682 * No vertical space before the first subsection
683 * and after an empty subsection.
688 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
689 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
690 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
691 (n
->tok
== MAN_SS
&& n
->body
->child
== NULL
))
694 for (i
= 0; i
< mt
->pardist
; i
++)
698 term_fontrepl(p
, TERMFONT_BOLD
);
699 p
->tcol
->offset
= term_len(p
, 3);
700 p
->tcol
->rmargin
= mt
->offset
;
701 p
->trailspace
= mt
->offset
;
702 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
705 p
->tcol
->offset
= mt
->offset
;
706 p
->tcol
->rmargin
= p
->maxrmargin
;
708 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
723 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
724 mt
->offset
= term_len(p
, p
->defindent
);
727 * No vertical space before the first section
728 * and after an empty section.
733 } while (n
!= NULL
&& n
->tok
>= MAN_TH
&&
734 man_term_act(n
->tok
)->flags
& MAN_NOTEXT
);
735 if (n
== NULL
|| n
->type
== ROFFT_COMMENT
||
736 (n
->tok
== MAN_SH
&& n
->body
->child
== NULL
))
739 for (i
= 0; i
< mt
->pardist
; i
++)
743 term_fontrepl(p
, TERMFONT_BOLD
);
745 p
->tcol
->rmargin
= mt
->offset
;
746 p
->trailspace
= mt
->offset
;
747 p
->flags
|= TERMP_NOBREAK
| TERMP_BRIND
;
750 p
->tcol
->offset
= mt
->offset
;
751 p
->tcol
->rmargin
= p
->maxrmargin
;
753 p
->flags
&= ~(TERMP_NOBREAK
| TERMP_BRIND
);
794 n
->aux
= SHRT_MAX
+ 1;
795 if (n
->child
== NULL
)
796 n
->aux
= mt
->lmargin
[mt
->lmargincur
];
797 else if (a2roffsu(n
->child
->string
, &su
, SCALE_EN
) != NULL
)
798 n
->aux
= term_hen(p
, &su
);
799 if (n
->aux
< 0 && (size_t)(-n
->aux
) > mt
->offset
)
800 n
->aux
= -mt
->offset
;
801 else if (n
->aux
> SHRT_MAX
)
802 n
->aux
= term_len(p
, p
->defindent
);
804 mt
->offset
+= n
->aux
;
805 p
->tcol
->offset
= mt
->offset
;
806 p
->tcol
->rmargin
= p
->maxrmargin
;
808 if (++mt
->lmarginsz
< MAXMARGINS
)
809 mt
->lmargincur
= mt
->lmarginsz
;
811 mt
->lmargin
[mt
->lmargincur
] = term_len(p
, p
->defindent
);
828 mt
->offset
-= n
->parent
->head
->aux
;
829 p
->tcol
->offset
= mt
->offset
;
830 if (--mt
->lmarginsz
< MAXMARGINS
)
831 mt
->lmargincur
= mt
->lmarginsz
;
837 const struct roff_node
*nn
;
842 if (n
->prev
== NULL
|| n
->prev
->tok
!= MAN_SY
)
843 print_bvspace(p
, n
, mt
->pardist
);
852 nn
= n
->parent
->head
->child
;
853 len
= nn
== NULL
? 1 : term_strlen(p
, nn
->string
) + 1;
857 p
->tcol
->offset
= mt
->offset
;
858 p
->tcol
->rmargin
= mt
->offset
+ len
;
859 if (n
->next
->child
== NULL
||
860 (n
->next
->child
->flags
& NODE_NOFILL
) == 0)
861 p
->flags
|= TERMP_NOBREAK
;
862 term_fontrepl(p
, TERMFONT_BOLD
);
865 mt
->lmargin
[mt
->lmargincur
] = len
;
866 p
->tcol
->offset
= mt
->offset
+ len
;
867 p
->tcol
->rmargin
= p
->maxrmargin
;
868 p
->flags
|= TERMP_NOSPACE
;
884 p
->flags
&= ~TERMP_NOBREAK
;
888 p
->tcol
->offset
= mt
->offset
;
898 return n
->type
!= ROFFT_HEAD
;
904 if (n
->type
!= ROFFT_BLOCK
)
908 p
->flags
|= TERMP_NOSPACE
;
910 if (n
->child
->child
!= NULL
)
911 print_man_node(p
, mt
, n
->child
->child
, meta
);
913 p
->flags
|= TERMP_NOSPACE
;
918 print_man_node(DECL_ARGS
)
920 const struct man_term_act
*act
;
926 * If we have a blank line, output a vertical space.
927 * If we have a space as the first character, break
928 * before printing the line's data.
930 if (*n
->string
== '\0') {
931 if (p
->flags
& TERMP_NONEWLINE
)
936 } else if (*n
->string
== ' ' && n
->flags
& NODE_LINE
&&
937 (p
->flags
& TERMP_NONEWLINE
) == 0)
939 else if (n
->flags
& NODE_DELIMC
)
940 p
->flags
|= TERMP_NOSPACE
;
942 term_word(p
, n
->string
);
947 if ( ! (n
->flags
& NODE_LINE
))
948 p
->flags
|= TERMP_NOSPACE
;
950 if (n
->next
!= NULL
&& ! (n
->next
->flags
& NODE_LINE
))
951 p
->flags
|= TERMP_NOSPACE
;
954 if (p
->tbl
.cols
== NULL
)
956 term_tbl(p
, n
->span
);
962 if (n
->tok
< ROFF_MAX
) {
967 act
= man_term_act(n
->tok
);
968 if ((act
->flags
& MAN_NOTEXT
) == 0 && n
->tok
!= MAN_SM
)
969 term_fontrepl(p
, TERMFONT_NONE
);
972 if (act
->pre
!= NULL
)
973 c
= (*act
->pre
)(p
, mt
, n
, meta
);
975 if (c
&& n
->child
!= NULL
)
976 print_man_nodelist(p
, mt
, n
->child
, meta
);
978 if (act
->post
!= NULL
)
979 (*act
->post
)(p
, mt
, n
, meta
);
980 if ((act
->flags
& MAN_NOTEXT
) == 0 && n
->tok
!= MAN_SM
)
981 term_fontrepl(p
, TERMFONT_NONE
);
985 * If we're in a literal context, make sure that words
986 * together on the same line stay together. This is a
987 * POST-printing call, so we check the NEXT word. Since
988 * -man doesn't have nested macros, we don't need to be
989 * more specific than this.
991 if (n
->flags
& NODE_NOFILL
&&
992 ! (p
->flags
& (TERMP_NOBREAK
| TERMP_NONEWLINE
)) &&
993 (n
->next
== NULL
|| n
->next
->flags
& NODE_LINE
)) {
994 p
->flags
|= TERMP_BRNEVER
| TERMP_NOSPACE
;
995 if (n
->string
!= NULL
&& *n
->string
!= '\0')
999 p
->flags
&= ~TERMP_BRNEVER
;
1000 if (p
->tcol
->rmargin
< p
->maxrmargin
&&
1001 n
->parent
->tok
== MAN_HP
) {
1002 p
->tcol
->offset
= p
->tcol
->rmargin
;
1003 p
->tcol
->rmargin
= p
->maxrmargin
;
1006 if (n
->flags
& NODE_EOS
)
1007 p
->flags
|= TERMP_SENTENCE
;
1011 print_man_nodelist(DECL_ARGS
)
1014 print_man_node(p
, mt
, n
, meta
);
1020 print_man_foot(struct termp
*p
, const struct roff_meta
*meta
)
1023 size_t datelen
, titlen
;
1025 assert(meta
->title
);
1029 term_fontrepl(p
, TERMFONT_NONE
);
1035 * Temporary, undocumented option to imitate mdoc(7) output.
1036 * In the bottom right corner, use the operating system
1037 * instead of the title.
1040 if ( ! p
->mdocstyle
) {
1041 if (meta
->hasbody
) {
1045 mandoc_asprintf(&title
, "%s(%s)",
1046 meta
->title
, meta
->msec
);
1047 } else if (meta
->os
!= NULL
) {
1048 title
= mandoc_strdup(meta
->os
);
1050 title
= mandoc_strdup("");
1052 datelen
= term_strlen(p
, meta
->date
);
1054 /* Bottom left corner: operating system. */
1056 p
->flags
|= TERMP_NOSPACE
| TERMP_NOBREAK
;
1058 p
->tcol
->offset
= 0;
1059 p
->tcol
->rmargin
= p
->maxrmargin
> datelen
?
1060 (p
->maxrmargin
+ term_len(p
, 1) - datelen
) / 2 : 0;
1063 term_word(p
, meta
->os
);
1066 /* At the bottom in the middle: manual date. */
1068 p
->tcol
->offset
= p
->tcol
->rmargin
;
1069 titlen
= term_strlen(p
, title
);
1070 p
->tcol
->rmargin
= p
->maxrmargin
> titlen
?
1071 p
->maxrmargin
- titlen
: 0;
1072 p
->flags
|= TERMP_NOSPACE
;
1074 term_word(p
, meta
->date
);
1077 /* Bottom right corner: manual title and section. */
1079 p
->flags
&= ~TERMP_NOBREAK
;
1080 p
->flags
|= TERMP_NOSPACE
;
1082 p
->tcol
->offset
= p
->tcol
->rmargin
;
1083 p
->tcol
->rmargin
= p
->maxrmargin
;
1085 term_word(p
, title
);
1089 * Reset the terminal state for more output after the footer:
1090 * Some output modes, in particular PostScript and PDF, print
1091 * the header and the footer into a buffer such that it can be
1092 * reused for multiple output pages, then go on to format the
1096 p
->tcol
->offset
= 0;
1103 print_man_head(struct termp
*p
, const struct roff_meta
*meta
)
1107 size_t vollen
, titlen
;
1109 assert(meta
->title
);
1112 volume
= NULL
== meta
->vol
? "" : meta
->vol
;
1113 vollen
= term_strlen(p
, volume
);
1115 /* Top left corner: manual title and section. */
1117 mandoc_asprintf(&title
, "%s(%s)", meta
->title
, meta
->msec
);
1118 titlen
= term_strlen(p
, title
);
1120 p
->flags
|= TERMP_NOBREAK
| TERMP_NOSPACE
;
1122 p
->tcol
->offset
= 0;
1123 p
->tcol
->rmargin
= 2 * (titlen
+1) + vollen
< p
->maxrmargin
?
1124 (p
->maxrmargin
- vollen
+ term_len(p
, 1)) / 2 :
1125 vollen
< p
->maxrmargin
? p
->maxrmargin
- vollen
: 0;
1127 term_word(p
, title
);
1130 /* At the top in the middle: manual volume. */
1132 p
->flags
|= TERMP_NOSPACE
;
1133 p
->tcol
->offset
= p
->tcol
->rmargin
;
1134 p
->tcol
->rmargin
= p
->tcol
->offset
+ vollen
+ titlen
<
1135 p
->maxrmargin
? p
->maxrmargin
- titlen
: p
->maxrmargin
;
1137 term_word(p
, volume
);
1140 /* Top right corner: title and section, again. */
1142 p
->flags
&= ~TERMP_NOBREAK
;
1144 if (p
->tcol
->rmargin
+ titlen
<= p
->maxrmargin
) {
1145 p
->flags
|= TERMP_NOSPACE
;
1146 p
->tcol
->offset
= p
->tcol
->rmargin
;
1147 p
->tcol
->rmargin
= p
->maxrmargin
;
1148 term_word(p
, title
);
1152 p
->flags
&= ~TERMP_NOSPACE
;
1153 p
->tcol
->offset
= 0;
1154 p
->tcol
->rmargin
= p
->maxrmargin
;
1157 * Groff prints three blank lines before the content.
1158 * Do the same, except in the temporary, undocumented
1159 * mode imitating mdoc(7) output.
1163 if ( ! p
->mdocstyle
) {
1171 * Skip leading whitespace, dashes, backslashes, and font escapes,
1172 * then create a tag if the first following byte is a letter.
1173 * Priority is high unless whitespace is present.
1176 tag_man(struct termp
*p
, struct roff_node
*n
)
1178 const char *cp
, *arg
;
1181 assert(n
->type
== ROFFT_TEXT
);
1195 switch (mandoc_escape(&cp
, &arg
, &sz
)) {
1197 case ESCAPE_FONTROMAN
:
1198 case ESCAPE_FONTITALIC
:
1199 case ESCAPE_FONTBOLD
:
1200 case ESCAPE_FONTPREV
:
1203 case ESCAPE_SPECIAL
:
1220 if (isalpha((unsigned char)*cp
))
1221 tag_put(cp
, prio
, p
->line
);