]> git.cameronkatri.com Git - mandoc.git/blob - man_term.c
f55726fb3c7800024028923290b724cf9f4e410b
[mandoc.git] / man_term.c
1 /* $Id: man_term.c,v 1.60 2010/05/10 08:05:17 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 term_vspace(p);
714 break;
715 case (MAN_HEAD):
716 term_fontrepl(p, TERMFONT_BOLD);
717 p->offset = 0;
718 break;
719 case (MAN_BODY):
720 p->offset = mt->offset;
721 break;
722 default:
723 break;
724 }
725
726 return(1);
727 }
728
729
730 /* ARGSUSED */
731 static void
732 post_SH(DECL_ARGS)
733 {
734
735 switch (n->type) {
736 case (MAN_HEAD):
737 term_newln(p);
738 break;
739 case (MAN_BODY):
740 term_newln(p);
741 break;
742 default:
743 break;
744 }
745 }
746
747
748 /* ARGSUSED */
749 static int
750 pre_RS(DECL_ARGS)
751 {
752 const struct man_node *nn;
753 int ival;
754
755 switch (n->type) {
756 case (MAN_BLOCK):
757 term_newln(p);
758 return(1);
759 case (MAN_HEAD):
760 return(0);
761 default:
762 break;
763 }
764
765 if (NULL == (nn = n->parent->head->child)) {
766 mt->offset = mt->lmargin + INDENT;
767 p->offset = mt->offset;
768 return(1);
769 }
770
771 if ((ival = a2width(nn)) < 0)
772 return(1);
773
774 mt->offset = INDENT + (size_t)ival;
775 p->offset = mt->offset;
776
777 return(1);
778 }
779
780
781 /* ARGSUSED */
782 static void
783 post_RS(DECL_ARGS)
784 {
785
786 switch (n->type) {
787 case (MAN_BLOCK):
788 mt->offset = mt->lmargin = INDENT;
789 break;
790 case (MAN_HEAD):
791 break;
792 default:
793 term_newln(p);
794 p->offset = INDENT;
795 break;
796 }
797 }
798
799
800 static void
801 print_man_node(DECL_ARGS)
802 {
803 int c;
804
805 c = 1;
806
807 switch (n->type) {
808 case(MAN_TEXT):
809 if (0 == *n->string) {
810 term_vspace(p);
811 break;
812 }
813
814 term_word(p, n->string);
815
816 /* FIXME: this means that macro lines are munged! */
817
818 if (MANT_LITERAL & mt->fl) {
819 p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
820 p->flags |= TERMP_NOSPACE;
821 term_flushln(p);
822 p->rmargin = p->maxrmargin = 65;
823 }
824 break;
825 default:
826 if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
827 term_fontrepl(p, TERMFONT_NONE);
828 if (termacts[n->tok].pre)
829 c = (*termacts[n->tok].pre)(p, mt, n, m);
830 break;
831 }
832
833 if (c && n->child)
834 print_man_nodelist(p, mt, n->child, m);
835
836 if (MAN_TEXT != n->type) {
837 if (termacts[n->tok].post)
838 (*termacts[n->tok].post)(p, mt, n, m);
839 if ( ! (MAN_NOTEXT & termacts[n->tok].flags))
840 term_fontrepl(p, TERMFONT_NONE);
841 }
842 }
843
844
845 static void
846 print_man_nodelist(DECL_ARGS)
847 {
848
849 print_man_node(p, mt, n, m);
850 if ( ! n->next)
851 return;
852 print_man_nodelist(p, mt, n->next, m);
853 }
854
855
856 static void
857 print_man_foot(struct termp *p, const struct man_meta *meta)
858 {
859 char buf[DATESIZ];
860
861 term_fontrepl(p, TERMFONT_NONE);
862
863 time2a(meta->date, buf, DATESIZ);
864
865 term_vspace(p);
866
867 p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
868 p->rmargin = p->maxrmargin - strlen(buf);
869 p->offset = 0;
870
871 if (meta->source)
872 term_word(p, meta->source);
873 if (meta->source)
874 term_word(p, "");
875 term_flushln(p);
876
877 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
878 p->offset = p->rmargin;
879 p->rmargin = p->maxrmargin;
880 p->flags &= ~TERMP_NOBREAK;
881
882 term_word(p, buf);
883 term_flushln(p);
884 }
885
886
887 static void
888 print_man_head(struct termp *p, const struct man_meta *m)
889 {
890 char buf[BUFSIZ], title[BUFSIZ];
891 size_t buflen, titlen;
892
893 p->rmargin = p->maxrmargin;
894
895 p->offset = 0;
896 buf[0] = title[0] = '\0';
897
898 if (m->vol)
899 strlcpy(buf, m->vol, BUFSIZ);
900 buflen = strlen(buf);
901
902 snprintf(title, BUFSIZ, "%s(%d)", m->title, m->msec);
903 titlen = strlen(title);
904
905 p->offset = 0;
906 p->rmargin = 2 * (titlen+1) + buflen < p->maxrmargin ?
907 (p->maxrmargin - strlen(buf) + 1) / 2 :
908 p->maxrmargin - buflen;
909 p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
910
911 term_word(p, title);
912 term_flushln(p);
913
914 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
915 p->offset = p->rmargin;
916 p->rmargin = p->offset + buflen + titlen < p->maxrmargin ?
917 p->maxrmargin - titlen : p->maxrmargin;
918
919 term_word(p, buf);
920 term_flushln(p);
921
922 p->flags &= ~TERMP_NOBREAK;
923 if (p->rmargin + titlen <= p->maxrmargin) {
924 p->flags |= TERMP_NOLPAD | TERMP_NOSPACE;
925 p->offset = p->rmargin;
926 p->rmargin = p->maxrmargin;
927 term_word(p, title);
928 term_flushln(p);
929 }
930
931 p->rmargin = p->maxrmargin;
932 p->offset = 0;
933 p->flags &= ~TERMP_NOSPACE;
934 }