]> git.cameronkatri.com Git - mandoc.git/blob - man_term.c
Fixed bug in -Thtml -mdoc where `Lb' would line-break in LIBRARY section.
[mandoc.git] / man_term.c
1 /* $Id: man_term.c,v 1.63 2010/05/12 16:46:28 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/types.h>
22
23 #include <assert.h>
24 #include <ctype.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "out.h"
30 #include "man.h"
31 #include "term.h"
32 #include "chars.h"
33 #include "main.h"
34
35 #define INDENT 7
36 #define HALFINDENT 3
37
38 /* FIXME: have PD set the default vspace width. */
39
40 struct mtermp {
41 int fl;
42 #define MANT_LITERAL (1 << 0)
43 /*
44 * Default amount to indent the left margin after leading text
45 * has been printed (e.g., `HP' left-indent, `TP' and `IP' body
46 * indent). This needs to be saved because `HP' and so on, if
47 * not having a specified value, must default.
48 *
49 * Note that this is the indentation AFTER the left offset, so
50 * the total offset is usually offset + lmargin.
51 */
52 size_t lmargin;
53 /*
54 * The default offset, i.e., the amount between any text and the
55 * page boundary.
56 */
57 size_t offset;
58 };
59
60 #define DECL_ARGS struct termp *p, \
61 struct mtermp *mt, \
62 const struct man_node *n, \
63 const struct man_meta *m
64
65 struct termact {
66 int (*pre)(DECL_ARGS);
67 void (*post)(DECL_ARGS);
68 int flags;
69 #define MAN_NOTEXT (1 << 0) /* Never has text children. */
70 };
71
72 static int a2width(const struct man_node *);
73 static int a2height(const struct man_node *);
74
75 static void print_man_head(struct termp *,
76 const struct man_meta *);
77 static void print_man_nodelist(DECL_ARGS);
78 static void print_man_node(DECL_ARGS);
79 static void print_man_foot(struct termp *,
80 const struct man_meta *);
81 static void print_bvspace(struct termp *,
82 const struct man_node *);
83
84 static int pre_B(DECL_ARGS);
85 static int pre_BI(DECL_ARGS);
86 static int pre_HP(DECL_ARGS);
87 static int pre_I(DECL_ARGS);
88 static int pre_IP(DECL_ARGS);
89 static int pre_PP(DECL_ARGS);
90 static int pre_RB(DECL_ARGS);
91 static int pre_RI(DECL_ARGS);
92 static int pre_RS(DECL_ARGS);
93 static int pre_SH(DECL_ARGS);
94 static int pre_SS(DECL_ARGS);
95 static int pre_TP(DECL_ARGS);
96 static int pre_br(DECL_ARGS);
97 static int pre_fi(DECL_ARGS);
98 static int pre_ign(DECL_ARGS);
99 static int pre_nf(DECL_ARGS);
100 static int pre_sp(DECL_ARGS);
101
102 static void post_IP(DECL_ARGS);
103 static void post_HP(DECL_ARGS);
104 static void post_RS(DECL_ARGS);
105 static void post_SH(DECL_ARGS);
106 static void post_SS(DECL_ARGS);
107 static void post_TP(DECL_ARGS);
108
109 static const struct termact termacts[MAN_MAX] = {
110 { pre_br, NULL, MAN_NOTEXT }, /* br */
111 { NULL, NULL, 0 }, /* TH */
112 { pre_SH, post_SH, 0 }, /* SH */
113 { pre_SS, post_SS, 0 }, /* SS */
114 { pre_TP, post_TP, 0 }, /* TP */
115 { pre_PP, NULL, 0 }, /* LP */
116 { pre_PP, NULL, 0 }, /* PP */
117 { pre_PP, NULL, 0 }, /* P */
118 { pre_IP, post_IP, 0 }, /* IP */
119 { pre_HP, post_HP, 0 }, /* HP */
120 { NULL, NULL, 0 }, /* SM */
121 { pre_B, NULL, 0 }, /* SB */
122 { pre_BI, NULL, 0 }, /* BI */
123 { pre_BI, NULL, 0 }, /* IB */
124 { pre_RB, NULL, 0 }, /* BR */
125 { pre_RB, NULL, 0 }, /* RB */
126 { NULL, NULL, 0 }, /* R */
127 { pre_B, NULL, 0 }, /* B */
128 { pre_I, NULL, 0 }, /* I */
129 { pre_RI, NULL, 0 }, /* IR */
130 { pre_RI, NULL, 0 }, /* RI */
131 { NULL, NULL, MAN_NOTEXT }, /* na */
132 { pre_I, NULL, 0 }, /* i */
133 { pre_sp, NULL, MAN_NOTEXT }, /* sp */
134 { pre_nf, NULL, 0 }, /* nf */
135 { pre_fi, NULL, 0 }, /* fi */
136 { NULL, NULL, 0 }, /* r */
137 { NULL, NULL, 0 }, /* RE */
138 { pre_RS, post_RS, 0 }, /* RS */
139 { pre_ign, NULL, 0 }, /* DT */
140 { pre_ign, NULL, 0 }, /* UC */
141 { pre_ign, NULL, 0 }, /* PD */
142 { pre_sp, NULL, MAN_NOTEXT }, /* Sp */
143 { pre_nf, NULL, 0 }, /* Vb */
144 { pre_fi, NULL, 0 }, /* Ve */
145 { pre_ign, NULL, MAN_NOTEXT }, /* de */
146 { pre_ign, NULL, MAN_NOTEXT }, /* dei */
147 { pre_ign, NULL, MAN_NOTEXT }, /* am */
148 { pre_ign, NULL, MAN_NOTEXT }, /* ami */
149 { pre_ign, NULL, MAN_NOTEXT }, /* ig */
150 { NULL, NULL, 0 }, /* . */
151 };
152
153
154
155 void
156 terminal_man(void *arg, const struct man *man)
157 {
158 struct termp *p;
159 const struct man_node *n;
160 const struct man_meta *m;
161 struct mtermp mt;
162
163 p = (struct termp *)arg;
164
165 p->overstep = 0;
166 p->maxrmargin = 65;
167
168 if (NULL == p->symtab)
169 switch (p->enc) {
170 case (TERMENC_ASCII):
171 p->symtab = chars_init(CHARS_ASCII);
172 break;
173 default:
174 abort();
175 /* NOTREACHED */
176 }
177
178 n = man_node(man);
179 m = man_meta(man);
180
181 print_man_head(p, m);
182 p->flags |= TERMP_NOSPACE;
183
184 mt.fl = 0;
185 mt.lmargin = INDENT;
186 mt.offset = INDENT;
187
188 if (n->child)
189 print_man_nodelist(p, &mt, n->child, m);
190 print_man_foot(p, m);
191 }
192
193
194 static int
195 a2height(const struct man_node *n)
196 {
197 struct roffsu su;
198
199 assert(MAN_TEXT == n->type);
200 assert(n->string);
201 if ( ! a2roffsu(n->string, &su, SCALE_VS))
202 SCALE_VS_INIT(&su, strlen(n->string));
203
204 return((int)term_vspan(&su));
205 }
206
207
208 static int
209 a2width(const struct man_node *n)
210 {
211 struct roffsu su;
212
213 assert(MAN_TEXT == n->type);
214 assert(n->string);
215 if ( ! a2roffsu(n->string, &su, SCALE_BU))
216 return(-1);
217
218 return((int)term_hspan(&su));
219 }
220
221
222 static void
223 print_bvspace(struct termp *p, const struct man_node *n)
224 {
225 term_newln(p);
226
227 if (NULL == n->prev)
228 return;
229
230 if (MAN_SS == n->prev->tok)
231 return;
232 if (MAN_SH == n->prev->tok)
233 return;
234
235 term_vspace(p);
236 }
237
238
239 /* ARGSUSED */
240 static int
241 pre_ign(DECL_ARGS)
242 {
243
244 return(0);
245 }
246
247
248 /* ARGSUSED */
249 static int
250 pre_I(DECL_ARGS)
251 {
252
253 term_fontrepl(p, TERMFONT_UNDER);
254 return(1);
255 }
256
257
258 /* ARGSUSED */
259 static int
260 pre_fi(DECL_ARGS)
261 {
262
263 mt->fl &= ~MANT_LITERAL;
264 return(1);
265 }
266
267
268 /* ARGSUSED */
269 static int
270 pre_nf(DECL_ARGS)
271 {
272
273 mt->fl |= MANT_LITERAL;
274 return(MAN_Vb != n->tok);
275 }
276
277
278 /* ARGSUSED */
279 static int
280 pre_RB(DECL_ARGS)
281 {
282 const struct man_node *nn;
283 int i;
284
285 for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
286 if (i % 2 && MAN_RB == n->tok)
287 term_fontrepl(p, TERMFONT_BOLD);
288 else if ( ! (i % 2) && MAN_RB != n->tok)
289 term_fontrepl(p, TERMFONT_BOLD);
290 else
291 term_fontrepl(p, TERMFONT_NONE);
292
293 if (i > 0)
294 p->flags |= TERMP_NOSPACE;
295
296 print_man_node(p, mt, nn, m);
297 }
298 return(0);
299 }
300
301
302 /* ARGSUSED */
303 static int
304 pre_RI(DECL_ARGS)
305 {
306 const struct man_node *nn;
307 int i;
308
309 for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
310 if (i % 2 && MAN_RI == n->tok)
311 term_fontrepl(p, TERMFONT_UNDER);
312 else if ( ! (i % 2) && MAN_RI != n->tok)
313 term_fontrepl(p, TERMFONT_UNDER);
314 else
315 term_fontrepl(p, TERMFONT_NONE);
316
317 if (i > 0)
318 p->flags |= TERMP_NOSPACE;
319
320 print_man_node(p, mt, nn, m);
321 }
322 return(0);
323 }
324
325
326 /* ARGSUSED */
327 static int
328 pre_BI(DECL_ARGS)
329 {
330 const struct man_node *nn;
331 int i;
332
333 for (i = 0, nn = n->child; nn; nn = nn->next, i++) {
334 if (i % 2 && MAN_BI == n->tok)
335 term_fontrepl(p, TERMFONT_UNDER);
336 else if (i % 2)
337 term_fontrepl(p, TERMFONT_BOLD);
338 else if (MAN_BI == n->tok)
339 term_fontrepl(p, TERMFONT_BOLD);
340 else
341 term_fontrepl(p, TERMFONT_UNDER);
342
343 if (i)
344 p->flags |= TERMP_NOSPACE;
345
346 print_man_node(p, mt, nn, m);
347 }
348 return(0);
349 }
350
351
352 /* ARGSUSED */
353 static int
354 pre_B(DECL_ARGS)
355 {
356
357 term_fontrepl(p, TERMFONT_BOLD);
358 return(1);
359 }
360
361
362 /* ARGSUSED */
363 static int
364 pre_sp(DECL_ARGS)
365 {
366 int i, len;
367
368 len = n->child ? a2height(n->child) : 1;
369
370 if (0 == len)
371 term_newln(p);
372 for (i = 0; i <= len; i++)
373 term_vspace(p);
374
375 return(0);
376 }
377
378
379 /* ARGSUSED */
380 static int
381 pre_br(DECL_ARGS)
382 {
383
384 term_newln(p);
385 return(0);
386 }
387
388
389 /* ARGSUSED */
390 static int
391 pre_HP(DECL_ARGS)
392 {
393 size_t len;
394 int ival;
395 const struct man_node *nn;
396
397 switch (n->type) {
398 case (MAN_BLOCK):
399 print_bvspace(p, n);
400 return(1);
401 case (MAN_BODY):
402 p->flags |= TERMP_NOBREAK;
403 p->flags |= TERMP_TWOSPACE;
404 break;
405 default:
406 return(0);
407 }
408
409 len = mt->lmargin;
410 ival = -1;
411
412 /* Calculate offset. */
413
414 if (NULL != (nn = n->parent->head->child))
415 if ((ival = a2width(nn)) >= 0)
416 len = (size_t)ival;
417
418 if (0 == len)
419 len = 1;
420
421 p->offset = mt->offset;
422 p->rmargin = mt->offset + len;
423
424 if (ival >= 0)
425 mt->lmargin = (size_t)ival;
426
427 return(1);
428 }
429
430
431 /* ARGSUSED */
432 static void
433 post_HP(DECL_ARGS)
434 {
435
436 switch (n->type) {
437 case (MAN_BLOCK):
438 term_flushln(p);
439 break;
440 case (MAN_BODY):
441 term_flushln(p);
442 p->flags &= ~TERMP_NOBREAK;
443 p->flags &= ~TERMP_TWOSPACE;
444 p->offset = mt->offset;
445 p->rmargin = p->maxrmargin;
446 break;
447 default:
448 break;
449 }
450 }
451
452
453 /* ARGSUSED */
454 static int
455 pre_PP(DECL_ARGS)
456 {
457
458 switch (n->type) {
459 case (MAN_BLOCK):
460 mt->lmargin = INDENT;
461 print_bvspace(p, n);
462 break;
463 default:
464 p->offset = mt->offset;
465 break;
466 }
467
468 return(1);
469 }
470
471
472 /* ARGSUSED */
473 static int
474 pre_IP(DECL_ARGS)
475 {
476 const struct man_node *nn;
477 size_t len;
478 int ival;
479
480 switch (n->type) {
481 case (MAN_BODY):
482 p->flags |= TERMP_NOLPAD;
483 p->flags |= TERMP_NOSPACE;
484 break;
485 case (MAN_HEAD):
486 p->flags |= TERMP_NOBREAK;
487 p->flags |= TERMP_TWOSPACE;
488 break;
489 case (MAN_BLOCK):
490 print_bvspace(p, n);
491 /* FALLTHROUGH */
492 default:
493 return(1);
494 }
495
496 len = mt->lmargin;
497 ival = -1;
498
499 /* Calculate offset. */
500
501 if (NULL != (nn = n->parent->head->child))
502 if (NULL != (nn = nn->next)) {
503 for ( ; nn->next; nn = nn->next)
504 /* Do nothing. */ ;
505 if ((ival = a2width(nn)) >= 0)
506 len = (size_t)ival;
507 }
508
509 switch (n->type) {
510 case (MAN_HEAD):
511 /* Handle zero-width lengths. */
512 if (0 == len)
513 len = 1;
514
515 p->offset = mt->offset;
516 p->rmargin = mt->offset + len;
517 if (ival < 0)
518 break;
519
520 /* Set the saved left-margin. */
521 mt->lmargin = (size_t)ival;
522
523 /* Don't print the length value. */
524 for (nn = n->child; nn->next; nn = nn->next)
525 print_man_node(p, mt, nn, m);
526 return(0);
527 case (MAN_BODY):
528 p->offset = mt->offset + len;
529 p->rmargin = p->maxrmargin;
530 break;
531 default:
532 break;
533 }
534
535 return(1);
536 }
537
538
539 /* ARGSUSED */
540 static void
541 post_IP(DECL_ARGS)
542 {
543
544 switch (n->type) {
545 case (MAN_HEAD):
546 term_flushln(p);
547 p->flags &= ~TERMP_NOBREAK;
548 p->flags &= ~TERMP_TWOSPACE;
549 p->rmargin = p->maxrmargin;
550 break;
551 case (MAN_BODY):
552 term_flushln(p);
553 p->flags &= ~TERMP_NOLPAD;
554 break;
555 default:
556 break;
557 }
558 }
559
560
561 /* ARGSUSED */
562 static int
563 pre_TP(DECL_ARGS)
564 {
565 const struct man_node *nn;
566 size_t len;
567 int ival;
568
569 switch (n->type) {
570 case (MAN_HEAD):
571 p->flags |= TERMP_NOBREAK;
572 p->flags |= TERMP_TWOSPACE;
573 break;
574 case (MAN_BODY):
575 p->flags |= TERMP_NOLPAD;
576 p->flags |= TERMP_NOSPACE;
577 break;
578 case (MAN_BLOCK):
579 print_bvspace(p, n);
580 /* FALLTHROUGH */
581 default:
582 return(1);
583 }
584
585 len = (size_t)mt->lmargin;
586 ival = -1;
587
588 /* Calculate offset. */
589
590 if (NULL != (nn = n->parent->head->child)) {
591 while (nn && MAN_TEXT != nn->type)
592 nn = nn->next;
593 if (nn && nn->next)
594 if ((ival = a2width(nn)) >= 0)
595 len = (size_t)ival;
596 }
597
598 switch (n->type) {
599 case (MAN_HEAD):
600 /* Handle zero-length properly. */
601 if (0 == len)
602 len = 1;
603
604 p->offset = mt->offset;
605 p->rmargin = mt->offset + len;
606
607 /* Don't print same-line elements. */
608 for (nn = n->child; nn; nn = nn->next)
609 if (nn->line > n->line)
610 print_man_node(p, mt, nn, m);
611
612 if (ival >= 0)
613 mt->lmargin = (size_t)ival;
614
615 return(0);
616 case (MAN_BODY):
617 p->offset = mt->offset + len;
618 p->rmargin = p->maxrmargin;
619 break;
620 default:
621 break;
622 }
623
624 return(1);
625 }
626
627
628 /* ARGSUSED */
629 static void
630 post_TP(DECL_ARGS)
631 {
632
633 switch (n->type) {
634 case (MAN_HEAD):
635 term_flushln(p);
636 p->flags &= ~TERMP_NOBREAK;
637 p->flags &= ~TERMP_TWOSPACE;
638 p->rmargin = p->maxrmargin;
639 break;
640 case (MAN_BODY):
641 term_flushln(p);
642 p->flags &= ~TERMP_NOLPAD;
643 break;
644 default:
645 break;
646 }
647 }
648
649
650 /* ARGSUSED */
651 static int
652 pre_SS(DECL_ARGS)
653 {
654
655 switch (n->type) {
656 case (MAN_BLOCK):
657 mt->lmargin = INDENT;
658 mt->offset = INDENT;
659 /* If following a prior empty `SS', no vspace. */
660 if (n->prev && MAN_SS == n->prev->tok)
661 if (NULL == n->prev->body->child)
662 break;
663 if (NULL == n->prev)
664 break;
665 term_vspace(p);
666 break;
667 case (MAN_HEAD):
668 term_fontrepl(p, TERMFONT_BOLD);
669 p->offset = HALFINDENT;
670 break;
671 case (MAN_BODY):
672 p->offset = mt->offset;
673 break;
674 default:
675 break;
676 }
677
678 return(1);
679 }
680
681
682 /* ARGSUSED */
683 static void
684 post_SS(DECL_ARGS)
685 {
686
687 switch (n->type) {
688 case (MAN_HEAD):
689 term_newln(p);
690 break;
691 case (MAN_BODY):
692 term_newln(p);
693 break;
694 default:
695 break;
696 }
697 }
698
699
700 /* ARGSUSED */
701 static int
702 pre_SH(DECL_ARGS)
703 {
704
705 switch (n->type) {
706 case (MAN_BLOCK):
707 mt->lmargin = INDENT;
708 mt->offset = INDENT;
709 /* If following a prior empty `SH', no vspace. */
710 if (n->prev && MAN_SH == n->prev->tok)
711 if (NULL == n->prev->body->child)
712 break;
713 /* If the first macro, no vspae. */
714 if (NULL == n->prev)
715 break;
716 term_vspace(p);
717 break;
718 case (MAN_HEAD):
719 term_fontrepl(p, TERMFONT_BOLD);
720 p->offset = 0;
721 break;
722 case (MAN_BODY):
723 p->offset = mt->offset;
724 break;
725 default:
726 break;
727 }
728
729 return(1);
730 }
731
732
733 /* ARGSUSED */
734 static void
735 post_SH(DECL_ARGS)
736 {
737
738 switch (n->type) {
739 case (MAN_HEAD):
740 term_newln(p);
741 break;
742 case (MAN_BODY):
743 term_newln(p);
744 break;
745 default:
746 break;
747 }
748 }
749
750
751 /* ARGSUSED */
752 static int
753 pre_RS(DECL_ARGS)
754 {
755 const struct man_node *nn;
756 int ival;
757
758 switch (n->type) {
759 case (MAN_BLOCK):
760 term_newln(p);
761 return(1);
762 case (MAN_HEAD):
763 return(0);
764 default:
765 break;
766 }
767
768 if (NULL == (nn = n->parent->head->child)) {
769 mt->offset = mt->lmargin + INDENT;
770 p->offset = mt->offset;
771 return(1);
772 }
773
774 if ((ival = a2width(nn)) < 0)
775 return(1);
776
777 mt->offset = INDENT + (size_t)ival;
778 p->offset = mt->offset;
779
780 return(1);
781 }
782
783
784 /* ARGSUSED */
785 static void
786 post_RS(DECL_ARGS)
787 {
788
789 switch (n->type) {
790 case (MAN_BLOCK):
791 mt->offset = mt->lmargin = INDENT;
792 break;
793 case (MAN_HEAD):
794 break;
795 default:
796 term_newln(p);
797 p->offset = INDENT;
798 break;
799 }
800 }
801
802
803 static void
804 print_man_node(DECL_ARGS)
805 {
806 int c;
807
808 c = 1;
809
810 switch (n->type) {
811 case(MAN_TEXT):
812 if (0 == *n->string) {
813 term_vspace(p);
814 break;
815 }
816
817 term_word(p, n->string);
818
819 /* FIXME: this means that macro lines are munged! */
820
821 if (MANT_LITERAL & mt->fl) {
822 p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
823 p->flags |= TERMP_NOSPACE;
824 term_flushln(p);
825 p->rmargin = p->maxrmargin = 65;
826 }
827 break;
828 default:
829 if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
830 term_fontrepl(p, TERMFONT_NONE);
831 if (termacts[n->tok].pre)
832 c = (*termacts[n->tok].pre)(p, mt, n, m);
833 break;
834 }
835
836 if (c && n->child)
837 print_man_nodelist(p, mt, n->child, m);
838
839 if (MAN_TEXT != n->type) {
840 if (termacts[n->tok].post)
841 (*termacts[n->tok].post)(p, mt, n, m);
842 if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
843 term_fontrepl(p, TERMFONT_NONE);
844 }
845
846 if (MAN_EOS & n->flags)
847 p->flags |= TERMP_SENTENCE;
848 }
849
850
851 static void
852 print_man_nodelist(DECL_ARGS)
853 {
854
855 print_man_node(p, mt, n, m);
856 if ( ! n->next)
857 return;
858 print_man_nodelist(p, mt, n->next, m);
859 }
860
861
862 static void
863 print_man_foot(struct termp *p, const struct man_meta *meta)
864 {
865 char buf[DATESIZ];
866
867 term_fontrepl(p, TERMFONT_NONE);
868
869 time2a(meta->date, buf, DATESIZ);
870
871 term_vspace(p);
872
873 p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
874 p->rmargin = p->maxrmargin - strlen(buf);
875 p->offset = 0;
876
877 if (meta->source)
878 term_word(p, meta->source);
879 if (meta->source)
880 term_word(p, "");
881 term_flushln(p);
882
883 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
884 p->offset = p->rmargin;
885 p->rmargin = p->maxrmargin;
886 p->flags &= ~TERMP_NOBREAK;
887
888 term_word(p, buf);
889 term_flushln(p);
890 }
891
892
893 static void
894 print_man_head(struct termp *p, const struct man_meta *m)
895 {
896 char buf[BUFSIZ], title[BUFSIZ];
897 size_t buflen, titlen;
898
899 /*
900 * Note that old groff would spit out some spaces before the
901 * header. We discontinue this strange behaviour, but at one
902 * point we did so here.
903 */
904
905 p->rmargin = p->maxrmargin;
906
907 p->offset = 0;
908 buf[0] = title[0] = '\0';
909
910 if (m->vol)
911 strlcpy(buf, m->vol, BUFSIZ);
912 buflen = strlen(buf);
913
914 snprintf(title, BUFSIZ, "%s(%d)", m->title, m->msec);
915 titlen = strlen(title);
916
917 p->offset = 0;
918 p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?
919 (p->maxrmargin - strlen(buf) + 1) / 2 :
920 p->maxrmargin - buflen;
921 p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
922
923 term_word(p, title);
924 term_flushln(p);
925
926 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
927 p->offset = p->rmargin;
928 p->rmargin = p->offset + buflen + titlen < p->maxrmargin ?
929 p->maxrmargin - titlen : p->maxrmargin;
930
931 term_word(p, buf);
932 term_flushln(p);
933
934 p->flags &= ~TERMP_NOBREAK;
935 if (p->rmargin + titlen <= p->maxrmargin) {
936 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
937 p->offset = p->rmargin;
938 p->rmargin = p->maxrmargin;
939 term_word(p, title);
940 term_flushln(p);
941 }
942
943 p->rmargin = p->maxrmargin;
944 p->offset = 0;
945 p->flags &= ~TERMP_NOSPACE;
946
947 /*
948 * Groff likes to have some leading spaces before content. Well
949 * that's fine by me.
950 */
951
952 term_vspace(p);
953 term_vspace(p);
954 term_vspace(p);
955 }