]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_term.c
no more _subdir; Jan Stary <hans at stare dot cz>
[mandoc.git] / mdoc_term.c
1 /* $Id: mdoc_term.c,v 1.325 2015/09/14 12:57:47 schwarze Exp $ */
2 /*
3 * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4 * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
5 * Copyright (c) 2013 Franco Fichtner <franco@lastsummer.de>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19 #include "config.h"
20
21 #include <sys/types.h>
22
23 #include <assert.h>
24 #include <ctype.h>
25 #include <limits.h>
26 #include <stdint.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30
31 #include "mandoc_aux.h"
32 #include "mandoc.h"
33 #include "roff.h"
34 #include "mdoc.h"
35 #include "out.h"
36 #include "term.h"
37 #include "tag.h"
38 #include "main.h"
39
40 struct termpair {
41 struct termpair *ppair;
42 int count;
43 };
44
45 #define DECL_ARGS struct termp *p, \
46 struct termpair *pair, \
47 const struct roff_meta *meta, \
48 struct roff_node *n
49
50 struct termact {
51 int (*pre)(DECL_ARGS);
52 void (*post)(DECL_ARGS);
53 };
54
55 static int a2width(const struct termp *, const char *);
56
57 static void print_bvspace(struct termp *,
58 const struct roff_node *,
59 const struct roff_node *);
60 static void print_mdoc_node(DECL_ARGS);
61 static void print_mdoc_nodelist(DECL_ARGS);
62 static void print_mdoc_head(struct termp *, const struct roff_meta *);
63 static void print_mdoc_foot(struct termp *, const struct roff_meta *);
64 static void synopsis_pre(struct termp *,
65 const struct roff_node *);
66
67 static void termp____post(DECL_ARGS);
68 static void termp__t_post(DECL_ARGS);
69 static void termp_bd_post(DECL_ARGS);
70 static void termp_bk_post(DECL_ARGS);
71 static void termp_bl_post(DECL_ARGS);
72 static void termp_eo_post(DECL_ARGS);
73 static void termp_fd_post(DECL_ARGS);
74 static void termp_fo_post(DECL_ARGS);
75 static void termp_in_post(DECL_ARGS);
76 static void termp_it_post(DECL_ARGS);
77 static void termp_lb_post(DECL_ARGS);
78 static void termp_nm_post(DECL_ARGS);
79 static void termp_pf_post(DECL_ARGS);
80 static void termp_quote_post(DECL_ARGS);
81 static void termp_sh_post(DECL_ARGS);
82 static void termp_ss_post(DECL_ARGS);
83
84 static int termp__a_pre(DECL_ARGS);
85 static int termp__t_pre(DECL_ARGS);
86 static int termp_an_pre(DECL_ARGS);
87 static int termp_ap_pre(DECL_ARGS);
88 static int termp_bd_pre(DECL_ARGS);
89 static int termp_bf_pre(DECL_ARGS);
90 static int termp_bk_pre(DECL_ARGS);
91 static int termp_bl_pre(DECL_ARGS);
92 static int termp_bold_pre(DECL_ARGS);
93 static int termp_bt_pre(DECL_ARGS);
94 static int termp_bx_pre(DECL_ARGS);
95 static int termp_cd_pre(DECL_ARGS);
96 static int termp_d1_pre(DECL_ARGS);
97 static int termp_eo_pre(DECL_ARGS);
98 static int termp_er_pre(DECL_ARGS);
99 static int termp_ex_pre(DECL_ARGS);
100 static int termp_fa_pre(DECL_ARGS);
101 static int termp_fd_pre(DECL_ARGS);
102 static int termp_fl_pre(DECL_ARGS);
103 static int termp_fn_pre(DECL_ARGS);
104 static int termp_fo_pre(DECL_ARGS);
105 static int termp_ft_pre(DECL_ARGS);
106 static int termp_in_pre(DECL_ARGS);
107 static int termp_it_pre(DECL_ARGS);
108 static int termp_li_pre(DECL_ARGS);
109 static int termp_ll_pre(DECL_ARGS);
110 static int termp_lk_pre(DECL_ARGS);
111 static int termp_nd_pre(DECL_ARGS);
112 static int termp_nm_pre(DECL_ARGS);
113 static int termp_ns_pre(DECL_ARGS);
114 static int termp_quote_pre(DECL_ARGS);
115 static int termp_rs_pre(DECL_ARGS);
116 static int termp_rv_pre(DECL_ARGS);
117 static int termp_sh_pre(DECL_ARGS);
118 static int termp_skip_pre(DECL_ARGS);
119 static int termp_sm_pre(DECL_ARGS);
120 static int termp_sp_pre(DECL_ARGS);
121 static int termp_ss_pre(DECL_ARGS);
122 static int termp_tag_pre(DECL_ARGS);
123 static int termp_under_pre(DECL_ARGS);
124 static int termp_ud_pre(DECL_ARGS);
125 static int termp_vt_pre(DECL_ARGS);
126 static int termp_xr_pre(DECL_ARGS);
127 static int termp_xx_pre(DECL_ARGS);
128
129 static const struct termact termacts[MDOC_MAX] = {
130 { termp_ap_pre, NULL }, /* Ap */
131 { NULL, NULL }, /* Dd */
132 { NULL, NULL }, /* Dt */
133 { NULL, NULL }, /* Os */
134 { termp_sh_pre, termp_sh_post }, /* Sh */
135 { termp_ss_pre, termp_ss_post }, /* Ss */
136 { termp_sp_pre, NULL }, /* Pp */
137 { termp_d1_pre, termp_bl_post }, /* D1 */
138 { termp_d1_pre, termp_bl_post }, /* Dl */
139 { termp_bd_pre, termp_bd_post }, /* Bd */
140 { NULL, NULL }, /* Ed */
141 { termp_bl_pre, termp_bl_post }, /* Bl */
142 { NULL, NULL }, /* El */
143 { termp_it_pre, termp_it_post }, /* It */
144 { termp_under_pre, NULL }, /* Ad */
145 { termp_an_pre, NULL }, /* An */
146 { termp_under_pre, NULL }, /* Ar */
147 { termp_cd_pre, NULL }, /* Cd */
148 { termp_bold_pre, NULL }, /* Cm */
149 { termp_li_pre, NULL }, /* Dv */
150 { termp_er_pre, NULL }, /* Er */
151 { termp_tag_pre, NULL }, /* Ev */
152 { termp_ex_pre, NULL }, /* Ex */
153 { termp_fa_pre, NULL }, /* Fa */
154 { termp_fd_pre, termp_fd_post }, /* Fd */
155 { termp_fl_pre, NULL }, /* Fl */
156 { termp_fn_pre, NULL }, /* Fn */
157 { termp_ft_pre, NULL }, /* Ft */
158 { termp_bold_pre, NULL }, /* Ic */
159 { termp_in_pre, termp_in_post }, /* In */
160 { termp_li_pre, NULL }, /* Li */
161 { termp_nd_pre, NULL }, /* Nd */
162 { termp_nm_pre, termp_nm_post }, /* Nm */
163 { termp_quote_pre, termp_quote_post }, /* Op */
164 { termp_ft_pre, NULL }, /* Ot */
165 { termp_under_pre, NULL }, /* Pa */
166 { termp_rv_pre, NULL }, /* Rv */
167 { NULL, NULL }, /* St */
168 { termp_under_pre, NULL }, /* Va */
169 { termp_vt_pre, NULL }, /* Vt */
170 { termp_xr_pre, NULL }, /* Xr */
171 { termp__a_pre, termp____post }, /* %A */
172 { termp_under_pre, termp____post }, /* %B */
173 { NULL, termp____post }, /* %D */
174 { termp_under_pre, termp____post }, /* %I */
175 { termp_under_pre, termp____post }, /* %J */
176 { NULL, termp____post }, /* %N */
177 { NULL, termp____post }, /* %O */
178 { NULL, termp____post }, /* %P */
179 { NULL, termp____post }, /* %R */
180 { termp__t_pre, termp__t_post }, /* %T */
181 { NULL, termp____post }, /* %V */
182 { NULL, NULL }, /* Ac */
183 { termp_quote_pre, termp_quote_post }, /* Ao */
184 { termp_quote_pre, termp_quote_post }, /* Aq */
185 { NULL, NULL }, /* At */
186 { NULL, NULL }, /* Bc */
187 { termp_bf_pre, NULL }, /* Bf */
188 { termp_quote_pre, termp_quote_post }, /* Bo */
189 { termp_quote_pre, termp_quote_post }, /* Bq */
190 { termp_xx_pre, NULL }, /* Bsx */
191 { termp_bx_pre, NULL }, /* Bx */
192 { termp_skip_pre, NULL }, /* Db */
193 { NULL, NULL }, /* Dc */
194 { termp_quote_pre, termp_quote_post }, /* Do */
195 { termp_quote_pre, termp_quote_post }, /* Dq */
196 { NULL, NULL }, /* Ec */ /* FIXME: no space */
197 { NULL, NULL }, /* Ef */
198 { termp_under_pre, NULL }, /* Em */
199 { termp_eo_pre, termp_eo_post }, /* Eo */
200 { termp_xx_pre, NULL }, /* Fx */
201 { termp_bold_pre, NULL }, /* Ms */
202 { termp_li_pre, NULL }, /* No */
203 { termp_ns_pre, NULL }, /* Ns */
204 { termp_xx_pre, NULL }, /* Nx */
205 { termp_xx_pre, NULL }, /* Ox */
206 { NULL, NULL }, /* Pc */
207 { NULL, termp_pf_post }, /* Pf */
208 { termp_quote_pre, termp_quote_post }, /* Po */
209 { termp_quote_pre, termp_quote_post }, /* Pq */
210 { NULL, NULL }, /* Qc */
211 { termp_quote_pre, termp_quote_post }, /* Ql */
212 { termp_quote_pre, termp_quote_post }, /* Qo */
213 { termp_quote_pre, termp_quote_post }, /* Qq */
214 { NULL, NULL }, /* Re */
215 { termp_rs_pre, NULL }, /* Rs */
216 { NULL, NULL }, /* Sc */
217 { termp_quote_pre, termp_quote_post }, /* So */
218 { termp_quote_pre, termp_quote_post }, /* Sq */
219 { termp_sm_pre, NULL }, /* Sm */
220 { termp_under_pre, NULL }, /* Sx */
221 { termp_bold_pre, NULL }, /* Sy */
222 { NULL, NULL }, /* Tn */
223 { termp_xx_pre, NULL }, /* Ux */
224 { NULL, NULL }, /* Xc */
225 { NULL, NULL }, /* Xo */
226 { termp_fo_pre, termp_fo_post }, /* Fo */
227 { NULL, NULL }, /* Fc */
228 { termp_quote_pre, termp_quote_post }, /* Oo */
229 { NULL, NULL }, /* Oc */
230 { termp_bk_pre, termp_bk_post }, /* Bk */
231 { NULL, NULL }, /* Ek */
232 { termp_bt_pre, NULL }, /* Bt */
233 { NULL, NULL }, /* Hf */
234 { termp_under_pre, NULL }, /* Fr */
235 { termp_ud_pre, NULL }, /* Ud */
236 { NULL, termp_lb_post }, /* Lb */
237 { termp_sp_pre, NULL }, /* Lp */
238 { termp_lk_pre, NULL }, /* Lk */
239 { termp_under_pre, NULL }, /* Mt */
240 { termp_quote_pre, termp_quote_post }, /* Brq */
241 { termp_quote_pre, termp_quote_post }, /* Bro */
242 { NULL, NULL }, /* Brc */
243 { NULL, termp____post }, /* %C */
244 { termp_skip_pre, NULL }, /* Es */
245 { termp_quote_pre, termp_quote_post }, /* En */
246 { termp_xx_pre, NULL }, /* Dx */
247 { NULL, termp____post }, /* %Q */
248 { termp_sp_pre, NULL }, /* br */
249 { termp_sp_pre, NULL }, /* sp */
250 { NULL, termp____post }, /* %U */
251 { NULL, NULL }, /* Ta */
252 { termp_ll_pre, NULL }, /* ll */
253 };
254
255 static int fn_prio;
256
257 void
258 terminal_mdoc(void *arg, const struct roff_man *mdoc)
259 {
260 struct roff_node *n;
261 struct termp *p;
262
263 p = (struct termp *)arg;
264 p->overstep = 0;
265 p->rmargin = p->maxrmargin = p->defrmargin;
266 p->tabwidth = term_len(p, 5);
267
268 n = mdoc->first->child;
269 if (p->synopsisonly) {
270 while (n != NULL) {
271 if (n->tok == MDOC_Sh && n->sec == SEC_SYNOPSIS) {
272 if (n->child->next->child != NULL)
273 print_mdoc_nodelist(p, NULL,
274 &mdoc->meta,
275 n->child->next->child);
276 term_newln(p);
277 break;
278 }
279 n = n->next;
280 }
281 } else {
282 if (p->defindent == 0)
283 p->defindent = 5;
284 term_begin(p, print_mdoc_head, print_mdoc_foot,
285 &mdoc->meta);
286 if (n != NULL) {
287 if (n->tok != MDOC_Sh)
288 term_vspace(p);
289 print_mdoc_nodelist(p, NULL, &mdoc->meta, n);
290 }
291 term_end(p);
292 }
293 }
294
295 static void
296 print_mdoc_nodelist(DECL_ARGS)
297 {
298
299 while (n != NULL) {
300 print_mdoc_node(p, pair, meta, n);
301 n = n->next;
302 }
303 }
304
305 static void
306 print_mdoc_node(DECL_ARGS)
307 {
308 int chld;
309 struct termpair npair;
310 size_t offset, rmargin;
311
312 chld = 1;
313 offset = p->offset;
314 rmargin = p->rmargin;
315 n->flags &= ~MDOC_ENDED;
316 n->prev_font = p->fonti;
317
318 memset(&npair, 0, sizeof(struct termpair));
319 npair.ppair = pair;
320
321 /*
322 * Keeps only work until the end of a line. If a keep was
323 * invoked in a prior line, revert it to PREKEEP.
324 */
325
326 if (p->flags & TERMP_KEEP && n->flags & MDOC_LINE) {
327 p->flags &= ~TERMP_KEEP;
328 p->flags |= TERMP_PREKEEP;
329 }
330
331 /*
332 * After the keep flags have been set up, we may now
333 * produce output. Note that some pre-handlers do so.
334 */
335
336 switch (n->type) {
337 case ROFFT_TEXT:
338 if (' ' == *n->string && MDOC_LINE & n->flags)
339 term_newln(p);
340 if (MDOC_DELIMC & n->flags)
341 p->flags |= TERMP_NOSPACE;
342 term_word(p, n->string);
343 if (MDOC_DELIMO & n->flags)
344 p->flags |= TERMP_NOSPACE;
345 break;
346 case ROFFT_EQN:
347 if ( ! (n->flags & MDOC_LINE))
348 p->flags |= TERMP_NOSPACE;
349 term_eqn(p, n->eqn);
350 if (n->next != NULL && ! (n->next->flags & MDOC_LINE))
351 p->flags |= TERMP_NOSPACE;
352 break;
353 case ROFFT_TBL:
354 if (p->tbl.cols == NULL)
355 term_newln(p);
356 term_tbl(p, n->span);
357 break;
358 default:
359 if (termacts[n->tok].pre &&
360 (n->end == ENDBODY_NOT || n->nchild))
361 chld = (*termacts[n->tok].pre)
362 (p, &npair, meta, n);
363 break;
364 }
365
366 if (chld && n->child)
367 print_mdoc_nodelist(p, &npair, meta, n->child);
368
369 term_fontpopq(p,
370 (ENDBODY_NOT == n->end ? n : n->body)->prev_font);
371
372 switch (n->type) {
373 case ROFFT_TEXT:
374 break;
375 case ROFFT_TBL:
376 break;
377 case ROFFT_EQN:
378 break;
379 default:
380 if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags)
381 break;
382 (void)(*termacts[n->tok].post)(p, &npair, meta, n);
383
384 /*
385 * Explicit end tokens not only call the post
386 * handler, but also tell the respective block
387 * that it must not call the post handler again.
388 */
389 if (ENDBODY_NOT != n->end)
390 n->body->flags |= MDOC_ENDED;
391
392 /*
393 * End of line terminating an implicit block
394 * while an explicit block is still open.
395 * Continue the explicit block without spacing.
396 */
397 if (ENDBODY_NOSPACE == n->end)
398 p->flags |= TERMP_NOSPACE;
399 break;
400 }
401
402 if (MDOC_EOS & n->flags)
403 p->flags |= TERMP_SENTENCE;
404
405 if (MDOC_ll != n->tok) {
406 p->offset = offset;
407 p->rmargin = rmargin;
408 }
409 }
410
411 static void
412 print_mdoc_foot(struct termp *p, const struct roff_meta *meta)
413 {
414 size_t sz;
415
416 term_fontrepl(p, TERMFONT_NONE);
417
418 /*
419 * Output the footer in new-groff style, that is, three columns
420 * with the middle being the manual date and flanking columns
421 * being the operating system:
422 *
423 * SYSTEM DATE SYSTEM
424 */
425
426 term_vspace(p);
427
428 p->offset = 0;
429 sz = term_strlen(p, meta->date);
430 p->rmargin = p->maxrmargin > sz ?
431 (p->maxrmargin + term_len(p, 1) - sz) / 2 : 0;
432 p->trailspace = 1;
433 p->flags |= TERMP_NOSPACE | TERMP_NOBREAK;
434
435 term_word(p, meta->os);
436 term_flushln(p);
437
438 p->offset = p->rmargin;
439 sz = term_strlen(p, meta->os);
440 p->rmargin = p->maxrmargin > sz ? p->maxrmargin - sz : 0;
441 p->flags |= TERMP_NOSPACE;
442
443 term_word(p, meta->date);
444 term_flushln(p);
445
446 p->offset = p->rmargin;
447 p->rmargin = p->maxrmargin;
448 p->trailspace = 0;
449 p->flags &= ~TERMP_NOBREAK;
450 p->flags |= TERMP_NOSPACE;
451
452 term_word(p, meta->os);
453 term_flushln(p);
454
455 p->offset = 0;
456 p->rmargin = p->maxrmargin;
457 p->flags = 0;
458 }
459
460 static void
461 print_mdoc_head(struct termp *p, const struct roff_meta *meta)
462 {
463 char *volume, *title;
464 size_t vollen, titlen;
465
466 /*
467 * The header is strange. It has three components, which are
468 * really two with the first duplicated. It goes like this:
469 *
470 * IDENTIFIER TITLE IDENTIFIER
471 *
472 * The IDENTIFIER is NAME(SECTION), which is the command-name
473 * (if given, or "unknown" if not) followed by the manual page
474 * section. These are given in `Dt'. The TITLE is a free-form
475 * string depending on the manual volume. If not specified, it
476 * switches on the manual section.
477 */
478
479 assert(meta->vol);
480 if (NULL == meta->arch)
481 volume = mandoc_strdup(meta->vol);
482 else
483 mandoc_asprintf(&volume, "%s (%s)",
484 meta->vol, meta->arch);
485 vollen = term_strlen(p, volume);
486
487 if (NULL == meta->msec)
488 title = mandoc_strdup(meta->title);
489 else
490 mandoc_asprintf(&title, "%s(%s)",
491 meta->title, meta->msec);
492 titlen = term_strlen(p, title);
493
494 p->flags |= TERMP_NOBREAK | TERMP_NOSPACE;
495 p->trailspace = 1;
496 p->offset = 0;
497 p->rmargin = 2 * (titlen+1) + vollen < p->maxrmargin ?
498 (p->maxrmargin - vollen + term_len(p, 1)) / 2 :
499 vollen < p->maxrmargin ? p->maxrmargin - vollen : 0;
500
501 term_word(p, title);
502 term_flushln(p);
503
504 p->flags |= TERMP_NOSPACE;
505 p->offset = p->rmargin;
506 p->rmargin = p->offset + vollen + titlen < p->maxrmargin ?
507 p->maxrmargin - titlen : p->maxrmargin;
508
509 term_word(p, volume);
510 term_flushln(p);
511
512 p->flags &= ~TERMP_NOBREAK;
513 p->trailspace = 0;
514 if (p->rmargin + titlen <= p->maxrmargin) {
515 p->flags |= TERMP_NOSPACE;
516 p->offset = p->rmargin;
517 p->rmargin = p->maxrmargin;
518 term_word(p, title);
519 term_flushln(p);
520 }
521
522 p->flags &= ~TERMP_NOSPACE;
523 p->offset = 0;
524 p->rmargin = p->maxrmargin;
525 free(title);
526 free(volume);
527 }
528
529 static int
530 a2width(const struct termp *p, const char *v)
531 {
532 struct roffsu su;
533
534 if (a2roffsu(v, &su, SCALE_MAX) < 2) {
535 SCALE_HS_INIT(&su, term_strlen(p, v));
536 su.scale /= term_strlen(p, "0");
537 }
538 return(term_hspan(p, &su) / 24);
539 }
540
541 /*
542 * Determine how much space to print out before block elements of `It'
543 * (and thus `Bl') and `Bd'. And then go ahead and print that space,
544 * too.
545 */
546 static void
547 print_bvspace(struct termp *p,
548 const struct roff_node *bl,
549 const struct roff_node *n)
550 {
551 const struct roff_node *nn;
552
553 assert(n);
554
555 term_newln(p);
556
557 if (MDOC_Bd == bl->tok && bl->norm->Bd.comp)
558 return;
559 if (MDOC_Bl == bl->tok && bl->norm->Bl.comp)
560 return;
561
562 /* Do not vspace directly after Ss/Sh. */
563
564 nn = n;
565 while (nn->prev == NULL) {
566 do {
567 nn = nn->parent;
568 if (nn->type == ROFFT_ROOT)
569 return;
570 } while (nn->type != ROFFT_BLOCK);
571 if (nn->tok == MDOC_Sh || nn->tok == MDOC_Ss)
572 return;
573 if (nn->tok == MDOC_It &&
574 nn->parent->parent->norm->Bl.type != LIST_item)
575 break;
576 }
577
578 /* A `-column' does not assert vspace within the list. */
579
580 if (MDOC_Bl == bl->tok && LIST_column == bl->norm->Bl.type)
581 if (n->prev && MDOC_It == n->prev->tok)
582 return;
583
584 /* A `-diag' without body does not vspace. */
585
586 if (MDOC_Bl == bl->tok && LIST_diag == bl->norm->Bl.type)
587 if (n->prev && MDOC_It == n->prev->tok) {
588 assert(n->prev->body);
589 if (NULL == n->prev->body->child)
590 return;
591 }
592
593 term_vspace(p);
594 }
595
596
597 static int
598 termp_ll_pre(DECL_ARGS)
599 {
600
601 term_setwidth(p, n->nchild ? n->child->string : NULL);
602 return(0);
603 }
604
605 static int
606 termp_it_pre(DECL_ARGS)
607 {
608 char buf[24];
609 const struct roff_node *bl, *nn;
610 size_t ncols, dcol;
611 int i, offset, width;
612 enum mdoc_list type;
613
614 if (n->type == ROFFT_BLOCK) {
615 print_bvspace(p, n->parent->parent, n);
616 return(1);
617 }
618
619 bl = n->parent->parent->parent;
620 type = bl->norm->Bl.type;
621
622 /*
623 * Defaults for specific list types.
624 */
625
626 switch (type) {
627 case LIST_bullet:
628 /* FALLTHROUGH */
629 case LIST_dash:
630 /* FALLTHROUGH */
631 case LIST_hyphen:
632 /* FALLTHROUGH */
633 case LIST_enum:
634 width = term_len(p, 2);
635 break;
636 case LIST_hang:
637 width = term_len(p, 8);
638 break;
639 case LIST_column:
640 /* FALLTHROUGH */
641 case LIST_tag:
642 width = term_len(p, 10);
643 break;
644 default:
645 width = 0;
646 break;
647 }
648 offset = 0;
649
650 /*
651 * First calculate width and offset. This is pretty easy unless
652 * we're a -column list, in which case all prior columns must
653 * be accounted for.
654 */
655
656 if (bl->norm->Bl.offs != NULL) {
657 offset = a2width(p, bl->norm->Bl.offs);
658 if (offset < 0 && (size_t)(-offset) > p->offset)
659 offset = -p->offset;
660 else if (offset > SHRT_MAX)
661 offset = 0;
662 }
663
664 switch (type) {
665 case LIST_column:
666 if (n->type == ROFFT_HEAD)
667 break;
668
669 /*
670 * Imitate groff's column handling:
671 * - For each earlier column, add its width.
672 * - For less than 5 columns, add four more blanks per
673 * column.
674 * - For exactly 5 columns, add three more blank per
675 * column.
676 * - For more than 5 columns, add only one column.
677 */
678 ncols = bl->norm->Bl.ncols;
679 dcol = ncols < 5 ? term_len(p, 4) :
680 ncols == 5 ? term_len(p, 3) : term_len(p, 1);
681
682 /*
683 * Calculate the offset by applying all prior ROFFT_BODY,
684 * so we stop at the ROFFT_HEAD (nn->prev == NULL).
685 */
686
687 for (i = 0, nn = n->prev;
688 nn->prev && i < (int)ncols;
689 nn = nn->prev, i++)
690 offset += dcol + a2width(p,
691 bl->norm->Bl.cols[i]);
692
693 /*
694 * When exceeding the declared number of columns, leave
695 * the remaining widths at 0. This will later be
696 * adjusted to the default width of 10, or, for the last
697 * column, stretched to the right margin.
698 */
699 if (i >= (int)ncols)
700 break;
701
702 /*
703 * Use the declared column widths, extended as explained
704 * in the preceding paragraph.
705 */
706 width = a2width(p, bl->norm->Bl.cols[i]) + dcol;
707 break;
708 default:
709 if (NULL == bl->norm->Bl.width)
710 break;
711
712 /*
713 * Note: buffer the width by 2, which is groff's magic
714 * number for buffering single arguments. See the above
715 * handling for column for how this changes.
716 */
717 width = a2width(p, bl->norm->Bl.width) + term_len(p, 2);
718 if (width < 0 && (size_t)(-width) > p->offset)
719 width = -p->offset;
720 else if (width > SHRT_MAX)
721 width = 0;
722 break;
723 }
724
725 /*
726 * Whitespace control. Inset bodies need an initial space,
727 * while diagonal bodies need two.
728 */
729
730 p->flags |= TERMP_NOSPACE;
731
732 switch (type) {
733 case LIST_diag:
734 if (n->type == ROFFT_BODY)
735 term_word(p, "\\ \\ ");
736 break;
737 case LIST_inset:
738 if (n->type == ROFFT_BODY && n->parent->head->nchild)
739 term_word(p, "\\ ");
740 break;
741 default:
742 break;
743 }
744
745 p->flags |= TERMP_NOSPACE;
746
747 switch (type) {
748 case LIST_diag:
749 if (n->type == ROFFT_HEAD)
750 term_fontpush(p, TERMFONT_BOLD);
751 break;
752 default:
753 break;
754 }
755
756 /*
757 * Pad and break control. This is the tricky part. These flags
758 * are documented in term_flushln() in term.c. Note that we're
759 * going to unset all of these flags in termp_it_post() when we
760 * exit.
761 */
762
763 switch (type) {
764 case LIST_enum:
765 /*
766 * Weird special case.
767 * Some very narrow lists actually hang.
768 */
769 /* FALLTHROUGH */
770 case LIST_bullet:
771 /* FALLTHROUGH */
772 case LIST_dash:
773 /* FALLTHROUGH */
774 case LIST_hyphen:
775 if (width <= (int)term_len(p, 2))
776 p->flags |= TERMP_HANG;
777 if (n->type != ROFFT_HEAD)
778 break;
779 p->flags |= TERMP_NOBREAK;
780 p->trailspace = 1;
781 break;
782 case LIST_hang:
783 if (n->type != ROFFT_HEAD)
784 break;
785
786 /*
787 * This is ugly. If `-hang' is specified and the body
788 * is a `Bl' or `Bd', then we want basically to nullify
789 * the "overstep" effect in term_flushln() and treat
790 * this as a `-ohang' list instead.
791 */
792 if (NULL != n->next &&
793 NULL != n->next->child &&
794 (MDOC_Bl == n->next->child->tok ||
795 MDOC_Bd == n->next->child->tok))
796 break;
797
798 p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
799 p->trailspace = 1;
800 break;
801 case LIST_tag:
802 if (n->type != ROFFT_HEAD)
803 break;
804
805 p->flags |= TERMP_NOBREAK | TERMP_BRIND;
806 p->trailspace = 2;
807
808 if (NULL == n->next || NULL == n->next->child)
809 p->flags |= TERMP_DANGLE;
810 break;
811 case LIST_column:
812 if (n->type == ROFFT_HEAD)
813 break;
814
815 if (NULL == n->next) {
816 p->flags &= ~TERMP_NOBREAK;
817 p->trailspace = 0;
818 } else {
819 p->flags |= TERMP_NOBREAK;
820 p->trailspace = 1;
821 }
822
823 break;
824 case LIST_diag:
825 if (n->type != ROFFT_HEAD)
826 break;
827 p->flags |= TERMP_NOBREAK | TERMP_BRIND;
828 p->trailspace = 1;
829 break;
830 default:
831 break;
832 }
833
834 /*
835 * Margin control. Set-head-width lists have their right
836 * margins shortened. The body for these lists has the offset
837 * necessarily lengthened. Everybody gets the offset.
838 */
839
840 p->offset += offset;
841
842 switch (type) {
843 case LIST_hang:
844 /*
845 * Same stipulation as above, regarding `-hang'. We
846 * don't want to recalculate rmargin and offsets when
847 * using `Bd' or `Bl' within `-hang' overstep lists.
848 */
849 if (n->type == ROFFT_HEAD &&
850 NULL != n->next &&
851 NULL != n->next->child &&
852 (MDOC_Bl == n->next->child->tok ||
853 MDOC_Bd == n->next->child->tok))
854 break;
855 /* FALLTHROUGH */
856 case LIST_bullet:
857 /* FALLTHROUGH */
858 case LIST_dash:
859 /* FALLTHROUGH */
860 case LIST_enum:
861 /* FALLTHROUGH */
862 case LIST_hyphen:
863 /* FALLTHROUGH */
864 case LIST_tag:
865 if (n->type == ROFFT_HEAD)
866 p->rmargin = p->offset + width;
867 else
868 p->offset += width;
869 break;
870 case LIST_column:
871 assert(width);
872 p->rmargin = p->offset + width;
873 /*
874 * XXX - this behaviour is not documented: the
875 * right-most column is filled to the right margin.
876 */
877 if (n->type == ROFFT_HEAD)
878 break;
879 if (NULL == n->next && p->rmargin < p->maxrmargin)
880 p->rmargin = p->maxrmargin;
881 break;
882 default:
883 break;
884 }
885
886 /*
887 * The dash, hyphen, bullet and enum lists all have a special
888 * HEAD character (temporarily bold, in some cases).
889 */
890
891 if (n->type == ROFFT_HEAD)
892 switch (type) {
893 case LIST_bullet:
894 term_fontpush(p, TERMFONT_BOLD);
895 term_word(p, "\\[bu]");
896 term_fontpop(p);
897 break;
898 case LIST_dash:
899 /* FALLTHROUGH */
900 case LIST_hyphen:
901 term_fontpush(p, TERMFONT_BOLD);
902 term_word(p, "\\(hy");
903 term_fontpop(p);
904 break;
905 case LIST_enum:
906 (pair->ppair->ppair->count)++;
907 (void)snprintf(buf, sizeof(buf), "%d.",
908 pair->ppair->ppair->count);
909 term_word(p, buf);
910 break;
911 default:
912 break;
913 }
914
915 /*
916 * If we're not going to process our children, indicate so here.
917 */
918
919 switch (type) {
920 case LIST_bullet:
921 /* FALLTHROUGH */
922 case LIST_item:
923 /* FALLTHROUGH */
924 case LIST_dash:
925 /* FALLTHROUGH */
926 case LIST_hyphen:
927 /* FALLTHROUGH */
928 case LIST_enum:
929 if (n->type == ROFFT_HEAD)
930 return(0);
931 break;
932 case LIST_column:
933 if (n->type == ROFFT_HEAD)
934 return(0);
935 break;
936 default:
937 break;
938 }
939
940 return(1);
941 }
942
943 static void
944 termp_it_post(DECL_ARGS)
945 {
946 enum mdoc_list type;
947
948 if (n->type == ROFFT_BLOCK)
949 return;
950
951 type = n->parent->parent->parent->norm->Bl.type;
952
953 switch (type) {
954 case LIST_item:
955 /* FALLTHROUGH */
956 case LIST_diag:
957 /* FALLTHROUGH */
958 case LIST_inset:
959 if (n->type == ROFFT_BODY)
960 term_newln(p);
961 break;
962 case LIST_column:
963 if (n->type == ROFFT_BODY)
964 term_flushln(p);
965 break;
966 default:
967 term_newln(p);
968 break;
969 }
970
971 /*
972 * Now that our output is flushed, we can reset our tags. Since
973 * only `It' sets these flags, we're free to assume that nobody
974 * has munged them in the meanwhile.
975 */
976
977 p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND |
978 TERMP_DANGLE | TERMP_HANG);
979 p->trailspace = 0;
980 }
981
982 static int
983 termp_nm_pre(DECL_ARGS)
984 {
985 const char *cp;
986
987 if (n->type == ROFFT_BLOCK) {
988 p->flags |= TERMP_PREKEEP;
989 return(1);
990 }
991
992 if (n->type == ROFFT_BODY) {
993 if (NULL == n->child)
994 return(0);
995 p->flags |= TERMP_NOSPACE;
996 cp = NULL;
997 if (n->prev->child != NULL)
998 cp = n->prev->child->string;
999 if (cp == NULL)
1000 cp = meta->name;
1001 if (cp == NULL)
1002 p->offset += term_len(p, 6);
1003 else
1004 p->offset += term_len(p, 1) + term_strlen(p, cp);
1005 return(1);
1006 }
1007
1008 if (NULL == n->child && NULL == meta->name)
1009 return(0);
1010
1011 if (n->type == ROFFT_HEAD)
1012 synopsis_pre(p, n->parent);
1013
1014 if (n->type == ROFFT_HEAD &&
1015 NULL != n->next && NULL != n->next->child) {
1016 p->flags |= TERMP_NOSPACE | TERMP_NOBREAK | TERMP_BRIND;
1017 p->trailspace = 1;
1018 p->rmargin = p->offset + term_len(p, 1);
1019 if (NULL == n->child) {
1020 p->rmargin += term_strlen(p, meta->name);
1021 } else if (n->child->type == ROFFT_TEXT) {
1022 p->rmargin += term_strlen(p, n->child->string);
1023 if (n->child->next)
1024 p->flags |= TERMP_HANG;
1025 } else {
1026 p->rmargin += term_len(p, 5);
1027 p->flags |= TERMP_HANG;
1028 }
1029 }
1030
1031 term_fontpush(p, TERMFONT_BOLD);
1032 if (NULL == n->child)
1033 term_word(p, meta->name);
1034 return(1);
1035 }
1036
1037 static void
1038 termp_nm_post(DECL_ARGS)
1039 {
1040
1041 if (n->type == ROFFT_BLOCK) {
1042 p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
1043 } else if (n->type == ROFFT_HEAD &&
1044 NULL != n->next && NULL != n->next->child) {
1045 term_flushln(p);
1046 p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
1047 p->trailspace = 0;
1048 } else if (n->type == ROFFT_BODY && n->child != NULL)
1049 term_flushln(p);
1050 }
1051
1052 static int
1053 termp_fl_pre(DECL_ARGS)
1054 {
1055
1056 termp_tag_pre(p, pair, meta, n);
1057 term_fontpush(p, TERMFONT_BOLD);
1058 term_word(p, "\\-");
1059
1060 if ( ! (n->nchild == 0 &&
1061 (n->next == NULL ||
1062 n->next->type == ROFFT_TEXT ||
1063 n->next->flags & MDOC_LINE)))
1064 p->flags |= TERMP_NOSPACE;
1065
1066 return(1);
1067 }
1068
1069 static int
1070 termp__a_pre(DECL_ARGS)
1071 {
1072
1073 if (n->prev && MDOC__A == n->prev->tok)
1074 if (NULL == n->next || MDOC__A != n->next->tok)
1075 term_word(p, "and");
1076
1077 return(1);
1078 }
1079
1080 static int
1081 termp_an_pre(DECL_ARGS)
1082 {
1083
1084 if (n->norm->An.auth == AUTH_split) {
1085 p->flags &= ~TERMP_NOSPLIT;
1086 p->flags |= TERMP_SPLIT;
1087 return(0);
1088 }
1089 if (n->norm->An.auth == AUTH_nosplit) {
1090 p->flags &= ~TERMP_SPLIT;
1091 p->flags |= TERMP_NOSPLIT;
1092 return(0);
1093 }
1094
1095 if (p->flags & TERMP_SPLIT)
1096 term_newln(p);
1097
1098 if (n->sec == SEC_AUTHORS && ! (p->flags & TERMP_NOSPLIT))
1099 p->flags |= TERMP_SPLIT;
1100
1101 return(1);
1102 }
1103
1104 static int
1105 termp_ns_pre(DECL_ARGS)
1106 {
1107
1108 if ( ! (MDOC_LINE & n->flags))
1109 p->flags |= TERMP_NOSPACE;
1110 return(1);
1111 }
1112
1113 static int
1114 termp_rs_pre(DECL_ARGS)
1115 {
1116
1117 if (SEC_SEE_ALSO != n->sec)
1118 return(1);
1119 if (n->type == ROFFT_BLOCK && n->prev != NULL)
1120 term_vspace(p);
1121 return(1);
1122 }
1123
1124 static int
1125 termp_rv_pre(DECL_ARGS)
1126 {
1127 int nchild;
1128
1129 term_newln(p);
1130
1131 nchild = n->nchild;
1132 if (nchild > 0) {
1133 term_word(p, "The");
1134
1135 for (n = n->child; n; n = n->next) {
1136 term_fontpush(p, TERMFONT_BOLD);
1137 term_word(p, n->string);
1138 term_fontpop(p);
1139
1140 p->flags |= TERMP_NOSPACE;
1141 term_word(p, "()");
1142
1143 if (n->next == NULL)
1144 continue;
1145
1146 if (nchild > 2) {
1147 p->flags |= TERMP_NOSPACE;
1148 term_word(p, ",");
1149 }
1150 if (n->next->next == NULL)
1151 term_word(p, "and");
1152 }
1153
1154 if (nchild > 1)
1155 term_word(p, "functions return");
1156 else
1157 term_word(p, "function returns");
1158
1159 term_word(p, "the value\\~0 if successful;");
1160 } else
1161 term_word(p, "Upon successful completion,"
1162 " the value\\~0 is returned;");
1163
1164 term_word(p, "otherwise the value\\~\\-1 is returned"
1165 " and the global variable");
1166
1167 term_fontpush(p, TERMFONT_UNDER);
1168 term_word(p, "errno");
1169 term_fontpop(p);
1170
1171 term_word(p, "is set to indicate the error.");
1172 p->flags |= TERMP_SENTENCE;
1173
1174 return(0);
1175 }
1176
1177 static int
1178 termp_ex_pre(DECL_ARGS)
1179 {
1180 int nchild;
1181
1182 term_newln(p);
1183 term_word(p, "The");
1184
1185 nchild = n->nchild;
1186 for (n = n->child; n; n = n->next) {
1187 term_fontpush(p, TERMFONT_BOLD);
1188 term_word(p, n->string);
1189 term_fontpop(p);
1190
1191 if (nchild > 2 && n->next) {
1192 p->flags |= TERMP_NOSPACE;
1193 term_word(p, ",");
1194 }
1195
1196 if (n->next && NULL == n->next->next)
1197 term_word(p, "and");
1198 }
1199
1200 if (nchild > 1)
1201 term_word(p, "utilities exit\\~0");
1202 else
1203 term_word(p, "utility exits\\~0");
1204
1205 term_word(p, "on success, and\\~>0 if an error occurs.");
1206
1207 p->flags |= TERMP_SENTENCE;
1208 return(0);
1209 }
1210
1211 static int
1212 termp_nd_pre(DECL_ARGS)
1213 {
1214
1215 if (n->type == ROFFT_BODY)
1216 term_word(p, "\\(en");
1217 return(1);
1218 }
1219
1220 static int
1221 termp_bl_pre(DECL_ARGS)
1222 {
1223
1224 return(n->type != ROFFT_HEAD);
1225 }
1226
1227 static void
1228 termp_bl_post(DECL_ARGS)
1229 {
1230
1231 if (n->type == ROFFT_BLOCK)
1232 term_newln(p);
1233 }
1234
1235 static int
1236 termp_xr_pre(DECL_ARGS)
1237 {
1238
1239 if (NULL == (n = n->child))
1240 return(0);
1241
1242 assert(n->type == ROFFT_TEXT);
1243 term_word(p, n->string);
1244
1245 if (NULL == (n = n->next))
1246 return(0);
1247
1248 p->flags |= TERMP_NOSPACE;
1249 term_word(p, "(");
1250 p->flags |= TERMP_NOSPACE;
1251
1252 assert(n->type == ROFFT_TEXT);
1253 term_word(p, n->string);
1254
1255 p->flags |= TERMP_NOSPACE;
1256 term_word(p, ")");
1257
1258 return(0);
1259 }
1260
1261 /*
1262 * This decides how to assert whitespace before any of the SYNOPSIS set
1263 * of macros (which, as in the case of Ft/Fo and Ft/Fn, may contain
1264 * macro combos).
1265 */
1266 static void
1267 synopsis_pre(struct termp *p, const struct roff_node *n)
1268 {
1269 /*
1270 * Obviously, if we're not in a SYNOPSIS or no prior macros
1271 * exist, do nothing.
1272 */
1273 if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags))
1274 return;
1275
1276 /*
1277 * If we're the second in a pair of like elements, emit our
1278 * newline and return. UNLESS we're `Fo', `Fn', `Fn', in which
1279 * case we soldier on.
1280 */
1281 if (n->prev->tok == n->tok &&
1282 MDOC_Ft != n->tok &&
1283 MDOC_Fo != n->tok &&
1284 MDOC_Fn != n->tok) {
1285 term_newln(p);
1286 return;
1287 }
1288
1289 /*
1290 * If we're one of the SYNOPSIS set and non-like pair-wise after
1291 * another (or Fn/Fo, which we've let slip through) then assert
1292 * vertical space, else only newline and move on.
1293 */
1294 switch (n->prev->tok) {
1295 case MDOC_Fd:
1296 /* FALLTHROUGH */
1297 case MDOC_Fn:
1298 /* FALLTHROUGH */
1299 case MDOC_Fo:
1300 /* FALLTHROUGH */
1301 case MDOC_In:
1302 /* FALLTHROUGH */
1303 case MDOC_Vt:
1304 term_vspace(p);
1305 break;
1306 case MDOC_Ft:
1307 if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) {
1308 term_vspace(p);
1309 break;
1310 }
1311 /* FALLTHROUGH */
1312 default:
1313 term_newln(p);
1314 break;
1315 }
1316 }
1317
1318 static int
1319 termp_vt_pre(DECL_ARGS)
1320 {
1321
1322 if (n->type == ROFFT_ELEM) {
1323 synopsis_pre(p, n);
1324 return(termp_under_pre(p, pair, meta, n));
1325 } else if (n->type == ROFFT_BLOCK) {
1326 synopsis_pre(p, n);
1327 return(1);
1328 } else if (n->type == ROFFT_HEAD)
1329 return(0);
1330
1331 return(termp_under_pre(p, pair, meta, n));
1332 }
1333
1334 static int
1335 termp_bold_pre(DECL_ARGS)
1336 {
1337
1338 termp_tag_pre(p, pair, meta, n);
1339 term_fontpush(p, TERMFONT_BOLD);
1340 return(1);
1341 }
1342
1343 static int
1344 termp_fd_pre(DECL_ARGS)
1345 {
1346
1347 synopsis_pre(p, n);
1348 return(termp_bold_pre(p, pair, meta, n));
1349 }
1350
1351 static void
1352 termp_fd_post(DECL_ARGS)
1353 {
1354
1355 term_newln(p);
1356 }
1357
1358 static int
1359 termp_sh_pre(DECL_ARGS)
1360 {
1361
1362 switch (n->type) {
1363 case ROFFT_BLOCK:
1364 /*
1365 * Vertical space before sections, except
1366 * when the previous section was empty.
1367 */
1368 if (n->prev == NULL ||
1369 n->prev->tok != MDOC_Sh ||
1370 (n->prev->body != NULL &&
1371 n->prev->body->child != NULL))
1372 term_vspace(p);
1373 break;
1374 case ROFFT_HEAD:
1375 term_fontpush(p, TERMFONT_BOLD);
1376 break;
1377 case ROFFT_BODY:
1378 p->offset = term_len(p, p->defindent);
1379 switch (n->sec) {
1380 case SEC_DESCRIPTION:
1381 fn_prio = 0;
1382 break;
1383 case SEC_AUTHORS:
1384 p->flags &= ~(TERMP_SPLIT|TERMP_NOSPLIT);
1385 break;
1386 default:
1387 break;
1388 }
1389 break;
1390 default:
1391 break;
1392 }
1393 return(1);
1394 }
1395
1396 static void
1397 termp_sh_post(DECL_ARGS)
1398 {
1399
1400 switch (n->type) {
1401 case ROFFT_HEAD:
1402 term_newln(p);
1403 break;
1404 case ROFFT_BODY:
1405 term_newln(p);
1406 p->offset = 0;
1407 break;
1408 default:
1409 break;
1410 }
1411 }
1412
1413 static int
1414 termp_bt_pre(DECL_ARGS)
1415 {
1416
1417 term_word(p, "is currently in beta test.");
1418 p->flags |= TERMP_SENTENCE;
1419 return(0);
1420 }
1421
1422 static void
1423 termp_lb_post(DECL_ARGS)
1424 {
1425
1426 if (SEC_LIBRARY == n->sec && MDOC_LINE & n->flags)
1427 term_newln(p);
1428 }
1429
1430 static int
1431 termp_ud_pre(DECL_ARGS)
1432 {
1433
1434 term_word(p, "currently under development.");
1435 p->flags |= TERMP_SENTENCE;
1436 return(0);
1437 }
1438
1439 static int
1440 termp_d1_pre(DECL_ARGS)
1441 {
1442
1443 if (n->type != ROFFT_BLOCK)
1444 return(1);
1445 term_newln(p);
1446 p->offset += term_len(p, p->defindent + 1);
1447 return(1);
1448 }
1449
1450 static int
1451 termp_ft_pre(DECL_ARGS)
1452 {
1453
1454 /* NB: MDOC_LINE does not effect this! */
1455 synopsis_pre(p, n);
1456 term_fontpush(p, TERMFONT_UNDER);
1457 return(1);
1458 }
1459
1460 static int
1461 termp_fn_pre(DECL_ARGS)
1462 {
1463 size_t rmargin = 0;
1464 int pretty;
1465
1466 pretty = MDOC_SYNPRETTY & n->flags;
1467
1468 synopsis_pre(p, n);
1469
1470 if (NULL == (n = n->child))
1471 return(0);
1472
1473 if (pretty) {
1474 rmargin = p->rmargin;
1475 p->rmargin = p->offset + term_len(p, 4);
1476 p->flags |= TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG;
1477 }
1478
1479 assert(n->type == ROFFT_TEXT);
1480 term_fontpush(p, TERMFONT_BOLD);
1481 term_word(p, n->string);
1482 term_fontpop(p);
1483
1484 if (n->sec == SEC_DESCRIPTION)
1485 tag_put(n->string, ++fn_prio, p->line);
1486
1487 if (pretty) {
1488 term_flushln(p);
1489 p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
1490 p->offset = p->rmargin;
1491 p->rmargin = rmargin;
1492 }
1493
1494 p->flags |= TERMP_NOSPACE;
1495 term_word(p, "(");
1496 p->flags |= TERMP_NOSPACE;
1497
1498 for (n = n->next; n; n = n->next) {
1499 assert(n->type == ROFFT_TEXT);
1500 term_fontpush(p, TERMFONT_UNDER);
1501 if (pretty)
1502 p->flags |= TERMP_NBRWORD;
1503 term_word(p, n->string);
1504 term_fontpop(p);
1505
1506 if (n->next) {
1507 p->flags |= TERMP_NOSPACE;
1508 term_word(p, ",");
1509 }
1510 }
1511
1512 p->flags |= TERMP_NOSPACE;
1513 term_word(p, ")");
1514
1515 if (pretty) {
1516 p->flags |= TERMP_NOSPACE;
1517 term_word(p, ";");
1518 term_flushln(p);
1519 }
1520
1521 return(0);
1522 }
1523
1524 static int
1525 termp_fa_pre(DECL_ARGS)
1526 {
1527 const struct roff_node *nn;
1528
1529 if (n->parent->tok != MDOC_Fo) {
1530 term_fontpush(p, TERMFONT_UNDER);
1531 return(1);
1532 }
1533
1534 for (nn = n->child; nn; nn = nn->next) {
1535 term_fontpush(p, TERMFONT_UNDER);
1536 p->flags |= TERMP_NBRWORD;
1537 term_word(p, nn->string);
1538 term_fontpop(p);
1539
1540 if (nn->next || (n->next && n->next->tok == MDOC_Fa)) {
1541 p->flags |= TERMP_NOSPACE;
1542 term_word(p, ",");
1543 }
1544 }
1545
1546 return(0);
1547 }
1548
1549 static int
1550 termp_bd_pre(DECL_ARGS)
1551 {
1552 size_t tabwidth, lm, len, rm, rmax;
1553 struct roff_node *nn;
1554 int offset;
1555
1556 if (n->type == ROFFT_BLOCK) {
1557 print_bvspace(p, n, n);
1558 return(1);
1559 } else if (n->type == ROFFT_HEAD)
1560 return(0);
1561
1562 /* Handle the -offset argument. */
1563
1564 if (n->norm->Bd.offs == NULL ||
1565 ! strcmp(n->norm->Bd.offs, "left"))
1566 /* nothing */;
1567 else if ( ! strcmp(n->norm->Bd.offs, "indent"))
1568 p->offset += term_len(p, p->defindent + 1);
1569 else if ( ! strcmp(n->norm->Bd.offs, "indent-two"))
1570 p->offset += term_len(p, (p->defindent + 1) * 2);
1571 else {
1572 offset = a2width(p, n->norm->Bd.offs);
1573 if (offset < 0 && (size_t)(-offset) > p->offset)
1574 p->offset = 0;
1575 else if (offset < SHRT_MAX)
1576 p->offset += offset;
1577 }
1578
1579 /*
1580 * If -ragged or -filled are specified, the block does nothing
1581 * but change the indentation. If -unfilled or -literal are
1582 * specified, text is printed exactly as entered in the display:
1583 * for macro lines, a newline is appended to the line. Blank
1584 * lines are allowed.
1585 */
1586
1587 if (DISP_literal != n->norm->Bd.type &&
1588 DISP_unfilled != n->norm->Bd.type &&
1589 DISP_centered != n->norm->Bd.type)
1590 return(1);
1591
1592 tabwidth = p->tabwidth;
1593 if (DISP_literal == n->norm->Bd.type)
1594 p->tabwidth = term_len(p, 8);
1595
1596 lm = p->offset;
1597 rm = p->rmargin;
1598 rmax = p->maxrmargin;
1599 p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1600
1601 for (nn = n->child; nn; nn = nn->next) {
1602 if (DISP_centered == n->norm->Bd.type) {
1603 if (nn->type == ROFFT_TEXT) {
1604 len = term_strlen(p, nn->string);
1605 p->offset = len >= rm ? 0 :
1606 lm + len >= rm ? rm - len :
1607 (lm + rm - len) / 2;
1608 } else
1609 p->offset = lm;
1610 }
1611 print_mdoc_node(p, pair, meta, nn);
1612 /*
1613 * If the printed node flushes its own line, then we
1614 * needn't do it here as well. This is hacky, but the
1615 * notion of selective eoln whitespace is pretty dumb
1616 * anyway, so don't sweat it.
1617 */
1618 switch (nn->tok) {
1619 case MDOC_Sm:
1620 /* FALLTHROUGH */
1621 case MDOC_br:
1622 /* FALLTHROUGH */
1623 case MDOC_sp:
1624 /* FALLTHROUGH */
1625 case MDOC_Bl:
1626 /* FALLTHROUGH */
1627 case MDOC_D1:
1628 /* FALLTHROUGH */
1629 case MDOC_Dl:
1630 /* FALLTHROUGH */
1631 case MDOC_Lp:
1632 /* FALLTHROUGH */
1633 case MDOC_Pp:
1634 continue;
1635 default:
1636 break;
1637 }
1638 if (p->flags & TERMP_NONEWLINE ||
1639 (nn->next && ! (nn->next->flags & MDOC_LINE)))
1640 continue;
1641 term_flushln(p);
1642 p->flags |= TERMP_NOSPACE;
1643 }
1644
1645 p->tabwidth = tabwidth;
1646 p->rmargin = rm;
1647 p->maxrmargin = rmax;
1648 return(0);
1649 }
1650
1651 static void
1652 termp_bd_post(DECL_ARGS)
1653 {
1654 size_t rm, rmax;
1655
1656 if (n->type != ROFFT_BODY)
1657 return;
1658
1659 rm = p->rmargin;
1660 rmax = p->maxrmargin;
1661
1662 if (DISP_literal == n->norm->Bd.type ||
1663 DISP_unfilled == n->norm->Bd.type)
1664 p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
1665
1666 p->flags |= TERMP_NOSPACE;
1667 term_newln(p);
1668
1669 p->rmargin = rm;
1670 p->maxrmargin = rmax;
1671 }
1672
1673 static int
1674 termp_bx_pre(DECL_ARGS)
1675 {
1676
1677 if (NULL != (n = n->child)) {
1678 term_word(p, n->string);
1679 p->flags |= TERMP_NOSPACE;
1680 term_word(p, "BSD");
1681 } else {
1682 term_word(p, "BSD");
1683 return(0);
1684 }
1685
1686 if (NULL != (n = n->next)) {
1687 p->flags |= TERMP_NOSPACE;
1688 term_word(p, "-");
1689 p->flags |= TERMP_NOSPACE;
1690 term_word(p, n->string);
1691 }
1692
1693 return(0);
1694 }
1695
1696 static int
1697 termp_xx_pre(DECL_ARGS)
1698 {
1699 const char *pp;
1700 int flags;
1701
1702 pp = NULL;
1703 switch (n->tok) {
1704 case MDOC_Bsx:
1705 pp = "BSD/OS";
1706 break;
1707 case MDOC_Dx:
1708 pp = "DragonFly";
1709 break;
1710 case MDOC_Fx:
1711 pp = "FreeBSD";
1712 break;
1713 case MDOC_Nx:
1714 pp = "NetBSD";
1715 break;
1716 case MDOC_Ox:
1717 pp = "OpenBSD";
1718 break;
1719 case MDOC_Ux:
1720 pp = "UNIX";
1721 break;
1722 default:
1723 abort();
1724 /* NOTREACHED */
1725 }
1726
1727 term_word(p, pp);
1728 if (n->child) {
1729 flags = p->flags;
1730 p->flags |= TERMP_KEEP;
1731 term_word(p, n->child->string);
1732 p->flags = flags;
1733 }
1734 return(0);
1735 }
1736
1737 static void
1738 termp_pf_post(DECL_ARGS)
1739 {
1740
1741 if ( ! (n->next == NULL || n->next->flags & MDOC_LINE))
1742 p->flags |= TERMP_NOSPACE;
1743 }
1744
1745 static int
1746 termp_ss_pre(DECL_ARGS)
1747 {
1748
1749 switch (n->type) {
1750 case ROFFT_BLOCK:
1751 term_newln(p);
1752 if (n->prev)
1753 term_vspace(p);
1754 break;
1755 case ROFFT_HEAD:
1756 term_fontpush(p, TERMFONT_BOLD);
1757 p->offset = term_len(p, (p->defindent+1)/2);
1758 break;
1759 case ROFFT_BODY:
1760 p->offset = term_len(p, p->defindent);
1761 break;
1762 default:
1763 break;
1764 }
1765
1766 return(1);
1767 }
1768
1769 static void
1770 termp_ss_post(DECL_ARGS)
1771 {
1772
1773 if (n->type == ROFFT_HEAD || n->type == ROFFT_BODY)
1774 term_newln(p);
1775 }
1776
1777 static int
1778 termp_cd_pre(DECL_ARGS)
1779 {
1780
1781 synopsis_pre(p, n);
1782 term_fontpush(p, TERMFONT_BOLD);
1783 return(1);
1784 }
1785
1786 static int
1787 termp_in_pre(DECL_ARGS)
1788 {
1789
1790 synopsis_pre(p, n);
1791
1792 if (MDOC_SYNPRETTY & n->flags && MDOC_LINE & n->flags) {
1793 term_fontpush(p, TERMFONT_BOLD);
1794 term_word(p, "#include");
1795 term_word(p, "<");
1796 } else {
1797 term_word(p, "<");
1798 term_fontpush(p, TERMFONT_UNDER);
1799 }
1800
1801 p->flags |= TERMP_NOSPACE;
1802 return(1);
1803 }
1804
1805 static void
1806 termp_in_post(DECL_ARGS)
1807 {
1808
1809 if (MDOC_SYNPRETTY & n->flags)
1810 term_fontpush(p, TERMFONT_BOLD);
1811
1812 p->flags |= TERMP_NOSPACE;
1813 term_word(p, ">");
1814
1815 if (MDOC_SYNPRETTY & n->flags)
1816 term_fontpop(p);
1817 }
1818
1819 static int
1820 termp_sp_pre(DECL_ARGS)
1821 {
1822 struct roffsu su;
1823 int i, len;
1824
1825 switch (n->tok) {
1826 case MDOC_sp:
1827 if (n->child) {
1828 if ( ! a2roffsu(n->child->string, &su, SCALE_VS))
1829 su.scale = 1.0;
1830 len = term_vspan(p, &su);
1831 } else
1832 len = 1;
1833 break;
1834 case MDOC_br:
1835 len = 0;
1836 break;
1837 default:
1838 len = 1;
1839 fn_prio = 0;
1840 break;
1841 }
1842
1843 if (0 == len)
1844 term_newln(p);
1845 else if (len < 0)
1846 p->skipvsp -= len;
1847 else
1848 for (i = 0; i < len; i++)
1849 term_vspace(p);
1850
1851 return(0);
1852 }
1853
1854 static int
1855 termp_skip_pre(DECL_ARGS)
1856 {
1857
1858 return(0);
1859 }
1860
1861 static int
1862 termp_quote_pre(DECL_ARGS)
1863 {
1864
1865 if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1866 return(1);
1867
1868 switch (n->tok) {
1869 case MDOC_Ao:
1870 /* FALLTHROUGH */
1871 case MDOC_Aq:
1872 term_word(p, n->nchild == 1 &&
1873 n->child->tok == MDOC_Mt ? "<" : "\\(la");
1874 break;
1875 case MDOC_Bro:
1876 /* FALLTHROUGH */
1877 case MDOC_Brq:
1878 term_word(p, "{");
1879 break;
1880 case MDOC_Oo:
1881 /* FALLTHROUGH */
1882 case MDOC_Op:
1883 /* FALLTHROUGH */
1884 case MDOC_Bo:
1885 /* FALLTHROUGH */
1886 case MDOC_Bq:
1887 term_word(p, "[");
1888 break;
1889 case MDOC_Do:
1890 /* FALLTHROUGH */
1891 case MDOC_Dq:
1892 term_word(p, "\\(Lq");
1893 break;
1894 case MDOC_En:
1895 if (NULL == n->norm->Es ||
1896 NULL == n->norm->Es->child)
1897 return(1);
1898 term_word(p, n->norm->Es->child->string);
1899 break;
1900 case MDOC_Po:
1901 /* FALLTHROUGH */
1902 case MDOC_Pq:
1903 term_word(p, "(");
1904 break;
1905 case MDOC__T:
1906 /* FALLTHROUGH */
1907 case MDOC_Qo:
1908 /* FALLTHROUGH */
1909 case MDOC_Qq:
1910 term_word(p, "\"");
1911 break;
1912 case MDOC_Ql:
1913 /* FALLTHROUGH */
1914 case MDOC_So:
1915 /* FALLTHROUGH */
1916 case MDOC_Sq:
1917 term_word(p, "\\(oq");
1918 break;
1919 default:
1920 abort();
1921 /* NOTREACHED */
1922 }
1923
1924 p->flags |= TERMP_NOSPACE;
1925 return(1);
1926 }
1927
1928 static void
1929 termp_quote_post(DECL_ARGS)
1930 {
1931
1932 if (n->type != ROFFT_BODY && n->type != ROFFT_ELEM)
1933 return;
1934
1935 p->flags |= TERMP_NOSPACE;
1936
1937 switch (n->tok) {
1938 case MDOC_Ao:
1939 /* FALLTHROUGH */
1940 case MDOC_Aq:
1941 term_word(p, n->nchild == 1 &&
1942 n->child->tok == MDOC_Mt ? ">" : "\\(ra");
1943 break;
1944 case MDOC_Bro:
1945 /* FALLTHROUGH */
1946 case MDOC_Brq:
1947 term_word(p, "}");
1948 break;
1949 case MDOC_Oo:
1950 /* FALLTHROUGH */
1951 case MDOC_Op:
1952 /* FALLTHROUGH */
1953 case MDOC_Bo:
1954 /* FALLTHROUGH */
1955 case MDOC_Bq:
1956 term_word(p, "]");
1957 break;
1958 case MDOC_Do:
1959 /* FALLTHROUGH */
1960 case MDOC_Dq:
1961 term_word(p, "\\(Rq");
1962 break;
1963 case MDOC_En:
1964 if (n->norm->Es == NULL ||
1965 n->norm->Es->child == NULL ||
1966 n->norm->Es->child->next == NULL)
1967 p->flags &= ~TERMP_NOSPACE;
1968 else
1969 term_word(p, n->norm->Es->child->next->string);
1970 break;
1971 case MDOC_Po:
1972 /* FALLTHROUGH */
1973 case MDOC_Pq:
1974 term_word(p, ")");
1975 break;
1976 case MDOC__T:
1977 /* FALLTHROUGH */
1978 case MDOC_Qo:
1979 /* FALLTHROUGH */
1980 case MDOC_Qq:
1981 term_word(p, "\"");
1982 break;
1983 case MDOC_Ql:
1984 /* FALLTHROUGH */
1985 case MDOC_So:
1986 /* FALLTHROUGH */
1987 case MDOC_Sq:
1988 term_word(p, "\\(cq");
1989 break;
1990 default:
1991 abort();
1992 /* NOTREACHED */
1993 }
1994 }
1995
1996 static int
1997 termp_eo_pre(DECL_ARGS)
1998 {
1999
2000 if (n->type != ROFFT_BODY)
2001 return(1);
2002
2003 if (n->end == ENDBODY_NOT &&
2004 n->parent->head->child == NULL &&
2005 n->child != NULL &&
2006 n->child->end != ENDBODY_NOT)
2007 term_word(p, "\\&");
2008 else if (n->end != ENDBODY_NOT ? n->child != NULL :
2009 n->parent->head->child != NULL && (n->child != NULL ||
2010 (n->parent->tail != NULL && n->parent->tail->child != NULL)))
2011 p->flags |= TERMP_NOSPACE;
2012
2013 return(1);
2014 }
2015
2016 static void
2017 termp_eo_post(DECL_ARGS)
2018 {
2019 int body, tail;
2020
2021 if (n->type != ROFFT_BODY)
2022 return;
2023
2024 if (n->end != ENDBODY_NOT) {
2025 p->flags &= ~TERMP_NOSPACE;
2026 return;
2027 }
2028
2029 body = n->child != NULL || n->parent->head->child != NULL;
2030 tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
2031
2032 if (body && tail)
2033 p->flags |= TERMP_NOSPACE;
2034 else if ( ! (body || tail))
2035 term_word(p, "\\&");
2036 else if ( ! tail)
2037 p->flags &= ~TERMP_NOSPACE;
2038 }
2039
2040 static int
2041 termp_fo_pre(DECL_ARGS)
2042 {
2043 size_t rmargin = 0;
2044 int pretty;
2045
2046 pretty = MDOC_SYNPRETTY & n->flags;
2047
2048 if (n->type == ROFFT_BLOCK) {
2049 synopsis_pre(p, n);
2050 return(1);
2051 } else if (n->type == ROFFT_BODY) {
2052 if (pretty) {
2053 rmargin = p->rmargin;
2054 p->rmargin = p->offset + term_len(p, 4);
2055 p->flags |= TERMP_NOBREAK | TERMP_BRIND |
2056 TERMP_HANG;
2057 }
2058 p->flags |= TERMP_NOSPACE;
2059 term_word(p, "(");
2060 p->flags |= TERMP_NOSPACE;
2061 if (pretty) {
2062 term_flushln(p);
2063 p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND |
2064 TERMP_HANG);
2065 p->offset = p->rmargin;
2066 p->rmargin = rmargin;
2067 }
2068 return(1);
2069 }
2070
2071 if (NULL == n->child)
2072 return(0);
2073
2074 /* XXX: we drop non-initial arguments as per groff. */
2075
2076 assert(n->child->string);
2077 term_fontpush(p, TERMFONT_BOLD);
2078 term_word(p, n->child->string);
2079 return(0);
2080 }
2081
2082 static void
2083 termp_fo_post(DECL_ARGS)
2084 {
2085
2086 if (n->type != ROFFT_BODY)
2087 return;
2088
2089 p->flags |= TERMP_NOSPACE;
2090 term_word(p, ")");
2091
2092 if (MDOC_SYNPRETTY & n->flags) {
2093 p->flags |= TERMP_NOSPACE;
2094 term_word(p, ";");
2095 term_flushln(p);
2096 }
2097 }
2098
2099 static int
2100 termp_bf_pre(DECL_ARGS)
2101 {
2102
2103 if (n->type == ROFFT_HEAD)
2104 return(0);
2105 else if (n->type != ROFFT_BODY)
2106 return(1);
2107
2108 if (FONT_Em == n->norm->Bf.font)
2109 term_fontpush(p, TERMFONT_UNDER);
2110 else if (FONT_Sy == n->norm->Bf.font)
2111 term_fontpush(p, TERMFONT_BOLD);
2112 else
2113 term_fontpush(p, TERMFONT_NONE);
2114
2115 return(1);
2116 }
2117
2118 static int
2119 termp_sm_pre(DECL_ARGS)
2120 {
2121
2122 if (NULL == n->child)
2123 p->flags ^= TERMP_NONOSPACE;
2124 else if (0 == strcmp("on", n->child->string))
2125 p->flags &= ~TERMP_NONOSPACE;
2126 else
2127 p->flags |= TERMP_NONOSPACE;
2128
2129 if (p->col && ! (TERMP_NONOSPACE & p->flags))
2130 p->flags &= ~TERMP_NOSPACE;
2131
2132 return(0);
2133 }
2134
2135 static int
2136 termp_ap_pre(DECL_ARGS)
2137 {
2138
2139 p->flags |= TERMP_NOSPACE;
2140 term_word(p, "'");
2141 p->flags |= TERMP_NOSPACE;
2142 return(1);
2143 }
2144
2145 static void
2146 termp____post(DECL_ARGS)
2147 {
2148
2149 /*
2150 * Handle lists of authors. In general, print each followed by
2151 * a comma. Don't print the comma if there are only two
2152 * authors.
2153 */
2154 if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok)
2155 if (NULL == n->next->next || MDOC__A != n->next->next->tok)
2156 if (NULL == n->prev || MDOC__A != n->prev->tok)
2157 return;
2158
2159 /* TODO: %U. */
2160
2161 if (NULL == n->parent || MDOC_Rs != n->parent->tok)
2162 return;
2163
2164 p->flags |= TERMP_NOSPACE;
2165 if (NULL == n->next) {
2166 term_word(p, ".");
2167 p->flags |= TERMP_SENTENCE;
2168 } else
2169 term_word(p, ",");
2170 }
2171
2172 static int
2173 termp_li_pre(DECL_ARGS)
2174 {
2175
2176 term_fontpush(p, TERMFONT_NONE);
2177 return(1);
2178 }
2179
2180 static int
2181 termp_lk_pre(DECL_ARGS)
2182 {
2183 const struct roff_node *link, *descr;
2184
2185 if (NULL == (link = n->child))
2186 return(0);
2187
2188 if (NULL != (descr = link->next)) {
2189 term_fontpush(p, TERMFONT_UNDER);
2190 while (NULL != descr) {
2191 term_word(p, descr->string);
2192 descr = descr->next;
2193 }
2194 p->flags |= TERMP_NOSPACE;
2195 term_word(p, ":");
2196 term_fontpop(p);
2197 }
2198
2199 term_fontpush(p, TERMFONT_BOLD);
2200 term_word(p, link->string);
2201 term_fontpop(p);
2202
2203 return(0);
2204 }
2205
2206 static int
2207 termp_bk_pre(DECL_ARGS)
2208 {
2209
2210 switch (n->type) {
2211 case ROFFT_BLOCK:
2212 break;
2213 case ROFFT_HEAD:
2214 return(0);
2215 case ROFFT_BODY:
2216 if (n->parent->args || 0 == n->prev->nchild)
2217 p->flags |= TERMP_PREKEEP;
2218 break;
2219 default:
2220 abort();
2221 /* NOTREACHED */
2222 }
2223
2224 return(1);
2225 }
2226
2227 static void
2228 termp_bk_post(DECL_ARGS)
2229 {
2230
2231 if (n->type == ROFFT_BODY)
2232 p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
2233 }
2234
2235 static void
2236 termp__t_post(DECL_ARGS)
2237 {
2238
2239 /*
2240 * If we're in an `Rs' and there's a journal present, then quote
2241 * us instead of underlining us (for disambiguation).
2242 */
2243 if (n->parent && MDOC_Rs == n->parent->tok &&
2244 n->parent->norm->Rs.quote_T)
2245 termp_quote_post(p, pair, meta, n);
2246
2247 termp____post(p, pair, meta, n);
2248 }
2249
2250 static int
2251 termp__t_pre(DECL_ARGS)
2252 {
2253
2254 /*
2255 * If we're in an `Rs' and there's a journal present, then quote
2256 * us instead of underlining us (for disambiguation).
2257 */
2258 if (n->parent && MDOC_Rs == n->parent->tok &&
2259 n->parent->norm->Rs.quote_T)
2260 return(termp_quote_pre(p, pair, meta, n));
2261
2262 term_fontpush(p, TERMFONT_UNDER);
2263 return(1);
2264 }
2265
2266 static int
2267 termp_under_pre(DECL_ARGS)
2268 {
2269
2270 term_fontpush(p, TERMFONT_UNDER);
2271 return(1);
2272 }
2273
2274 static int
2275 termp_er_pre(DECL_ARGS)
2276 {
2277
2278 if (n->sec == SEC_ERRORS &&
2279 (n->parent->tok == MDOC_It ||
2280 (n->parent->tok == MDOC_Bq &&
2281 n->parent->parent->parent->tok == MDOC_It)))
2282 tag_put(n->child->string, 1, p->line);
2283 return(1);
2284 }
2285
2286 static int
2287 termp_tag_pre(DECL_ARGS)
2288 {
2289
2290 if (n->child != NULL &&
2291 n->child->type == ROFFT_TEXT &&
2292 n->prev == NULL &&
2293 (n->parent->tok == MDOC_It ||
2294 (n->parent->tok == MDOC_Xo &&
2295 n->parent->parent->prev == NULL &&
2296 n->parent->parent->parent->tok == MDOC_It)))
2297 tag_put(n->child->string, 1, p->line);
2298 return(1);
2299 }