[BACK]Return to mdoc_term.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Annotation of mandoc/mdoc_term.c, Revision 1.288

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

CVSweb