=================================================================== RCS file: /cvs/mandoc/term.c,v retrieving revision 1.29 retrieving revision 1.35 diff -u -p -r1.29 -r1.35 --- mandoc/term.c 2009/02/28 20:13:06 1.29 +++ mandoc/term.c 2009/03/02 17:14:46 1.35 @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.29 2009/02/28 20:13:06 kristaps Exp $ */ +/* $Id: term.c,v 1.35 2009/03/02 17:14:46 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -25,8 +25,6 @@ #include "term.h" -#define INDENT 6 - /* * Performs actions on nodes of the abstract syntax tree. Both pre- and * post-fix operations are defined here. @@ -118,6 +116,7 @@ DECL_PREPOST(termp_fd); DECL_PREPOST(termp_fn); DECL_PREPOST(termp_fo); DECL_PREPOST(termp_ft); +DECL_PREPOST(termp_in); DECL_PREPOST(termp_it); DECL_PREPOST(termp_op); DECL_PREPOST(termp_pf); @@ -133,7 +132,6 @@ DECL_PRE(termp_at); DECL_PRE(termp_bf); DECL_PRE(termp_bsx); DECL_PRE(termp_bt); -DECL_PRE(termp_bx); DECL_PRE(termp_cd); DECL_PRE(termp_cm); DECL_PRE(termp_em); @@ -142,7 +140,6 @@ DECL_PRE(termp_fa); DECL_PRE(termp_fl); DECL_PRE(termp_fx); DECL_PRE(termp_ic); -DECL_PRE(termp_in); DECL_PRE(termp_ms); DECL_PRE(termp_nd); DECL_PRE(termp_nm); @@ -164,6 +161,7 @@ DECL_PRE(termp_xr); DECL_POST(termp___); DECL_POST(termp_bl); +DECL_POST(termp_bx); const struct termact __termacts[MDOC_MAX] = { { NULL, NULL }, /* \" */ @@ -195,7 +193,7 @@ const struct termact __termacts[MDOC_MAX] = { { termp_fn_pre, termp_fn_post }, /* Fn */ { termp_ft_pre, termp_ft_post }, /* Ft */ { termp_ic_pre, NULL }, /* Ic */ - { termp_in_pre, NULL }, /* In */ + { termp_in_pre, termp_in_post }, /* In */ { NULL, NULL }, /* Li */ { termp_nd_pre, NULL }, /* Nd */ { termp_nm_pre, NULL }, /* Nm */ @@ -227,7 +225,7 @@ const struct termact __termacts[MDOC_MAX] = { { termp_bq_pre, termp_bq_post }, /* Bo */ { termp_bq_pre, termp_bq_post }, /* Bq */ { termp_bsx_pre, NULL }, /* Bsx */ - { termp_bx_pre, NULL }, /* Bx */ + { NULL, termp_bx_post }, /* Bx */ { NULL, NULL }, /* Db */ { NULL, NULL }, /* Dc */ { termp_dq_pre, termp_dq_post }, /* Do */ @@ -303,7 +301,7 @@ arg_width(const struct mdoc_arg *arg) } } - return(strlen(*arg->value) + 2); + return(strlen(*arg->value) + 1); } @@ -550,10 +548,9 @@ termp_it_post(DECL_ARGS) p->offset = pair->offset; p->rmargin = pair->rmargin; - if (MDOC_HEAD == node->type) { + if (MDOC_HEAD == node->type) p->flags &= ~TERMP_NOBREAK; - p->flags &= ~TERMP_NORPAD; - } else if (MDOC_BODY == node->type) + else if (MDOC_BODY == node->type) p->flags &= ~TERMP_NOLPAD; } @@ -566,9 +563,10 @@ termp_nm_pre(DECL_ARGS) if (SEC_SYNOPSIS == node->sec) newln(p); - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_PROG]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_PROG]); if (NULL == node->child) word(p, meta->name); + return(1); } @@ -578,7 +576,7 @@ static int termp_fl_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_FLAG]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_FLAG]); word(p, "\\-"); p->flags |= TERMP_NOSPACE; return(1); @@ -590,14 +588,11 @@ static int termp_ar_pre(DECL_ARGS) { - if (node->child) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_ARG]); - return(1); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_ARG]); + if (NULL == node->child) { + word(p, "file"); + word(p, "..."); } - p->flags |= ttypes[TTYPE_CMD_ARG]; - word(p, "file"); - word(p, "..."); - p->flags &= ~ttypes[TTYPE_CMD_ARG]; return(1); } @@ -642,7 +637,7 @@ static int termp_rs_pre(DECL_ARGS) { - if (MDOC_BLOCK == node->type) + if (MDOC_BLOCK == node->type && node->prev) vspace(p); return(1); } @@ -764,7 +759,7 @@ termp_vt_pre(DECL_ARGS) { /* FIXME: this can be "type name". */ - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_VAR_DECL]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]); return(1); } @@ -788,7 +783,7 @@ termp_fd_pre(DECL_ARGS) * FIXME: this naming is bad. This value is used, in general, * for the #include header or other preprocessor statement. */ - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_DECL]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_DECL]); return(1); } @@ -798,7 +793,10 @@ static void termp_fd_post(DECL_ARGS) { - if (node->sec == SEC_SYNOPSIS) + if (node->sec != SEC_SYNOPSIS) + return; + newln(p); + if (node->next && MDOC_Fd != node->next->tok) vspace(p); } @@ -811,7 +809,7 @@ termp_sh_pre(DECL_ARGS) switch (node->type) { case (MDOC_HEAD): vspace(p); - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SECTION]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SECTION]); break; case (MDOC_BODY): p->offset = INDENT; @@ -934,7 +932,10 @@ static int termp_ft_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_TYPE]); + if (SEC_SYNOPSIS == node->sec) + if (node->prev && MDOC_Fo == node->prev->tok) + vspace(p); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_TYPE]); return(1); } @@ -944,7 +945,7 @@ static void termp_ft_post(DECL_ARGS) { - if (node->sec == SEC_SYNOPSIS) + if (SEC_SYNOPSIS == node->sec) newln(p); } @@ -990,7 +991,7 @@ static void termp_fn_post(DECL_ARGS) { - if (node->sec == SEC_SYNOPSIS) + if (node->sec == SEC_SYNOPSIS && node->next) vspace(p); } @@ -1001,7 +1002,7 @@ static int termp_sx_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_LINK]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_LINK]); return(1); } @@ -1013,7 +1014,7 @@ termp_fa_pre(DECL_ARGS) struct mdoc_node *n; if (node->parent->tok != MDOC_Fo) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_ARG]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_ARG]); return(1); } @@ -1040,7 +1041,7 @@ static int termp_va_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_VAR_DECL]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]); return(1); } @@ -1050,43 +1051,65 @@ static int termp_bd_pre(DECL_ARGS) { const struct mdoc_block *bl; - const struct mdoc_node *n; - int i; + const struct mdoc_node *n; + int i, type; if (MDOC_BLOCK == node->type) { - vspace(p); + if (node->prev) + vspace(p); return(1); } else if (MDOC_BODY != node->type) return(1); - assert(MDOC_BLOCK == node->parent->type); pair->offset = p->offset; - bl = &node->parent->data.block; + for (type = -1, i = 0; i < (int)bl->argc; i++) { + switch (bl->argv[i].arg) { + case (MDOC_Ragged): + /* FALLTHROUGH */ + case (MDOC_Filled): + /* FALLTHROUGH */ + case (MDOC_Unfilled): + /* FALLTHROUGH */ + case (MDOC_Literal): + type = bl->argv[i].arg; + i = (int)bl->argc; + break; + default: + errx(1, "display type not supported"); + } + } + assert(-1 != type); + i = arg_getattr(MDOC_Offset, bl->argc, bl->argv); if (-1 != i) { assert(1 == bl->argv[i].sz); p->offset += arg_offset(&bl->argv[i]); } - if ( ! arg_hasattr(MDOC_Literal, bl->argc, bl->argv)) + + switch (type) { + case (MDOC_Literal): + /* FALLTHROUGH */ + case (MDOC_Unfilled): + break; + default: return(1); + } p->flags |= TERMP_LITERAL; for (n = node->child; n; n = n->next) { - assert(MDOC_TEXT == n->type); /* FIXME */ - if ((*n->data.text.string)) { - word(p, n->data.text.string); - flushln(p); - } else - vspace(p); - + if (MDOC_TEXT != n->type) { + warnx("non-text children not yet allowed"); + continue; + } + word(p, n->data.text.string); + flushln(p); } - p->flags &= ~TERMP_LITERAL; return(0); } @@ -1098,7 +1121,11 @@ termp_bd_post(DECL_ARGS) if (MDOC_BODY != node->type) return; - newln(p); + + if ( ! (p->flags & TERMP_LITERAL)) + flushln(p); + + p->flags &= ~TERMP_LITERAL; p->offset = pair->offset; } @@ -1139,12 +1166,13 @@ termp_bsx_pre(DECL_ARGS) /* ARGSUSED */ -static int -termp_bx_pre(DECL_ARGS) +static void +termp_bx_post(DECL_ARGS) { + if (node->child) + p->flags |= TERMP_NOSPACE; word(p, "BSD"); - return(1); } @@ -1241,7 +1269,7 @@ termp_ss_pre(DECL_ARGS) switch (node->type) { case (MDOC_HEAD): vspace(p); - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SSECTION]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SSECTION]); p->offset = INDENT / 2; break; default: @@ -1273,7 +1301,7 @@ static int termp_pa_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FILE]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FILE]); return(1); } @@ -1283,7 +1311,7 @@ static int termp_em_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); return(1); } @@ -1293,7 +1321,8 @@ static int termp_cd_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CONFIG]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CONFIG]); + newln(p); return(1); } @@ -1303,7 +1332,7 @@ static int termp_cm_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_FLAG]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_FLAG]); return(1); } @@ -1313,7 +1342,7 @@ static int termp_ic_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD]); return(1); } @@ -1323,12 +1352,31 @@ static int termp_in_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_INCLUDE]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_INCLUDE]); + word(p, "#include"); + word(p, "<"); + p->flags |= TERMP_NOSPACE; return(1); } /* ARGSUSED */ +static void +termp_in_post(DECL_ARGS) +{ + + p->flags |= TERMP_NOSPACE; + word(p, ">"); + + newln(p); + if (SEC_SYNOPSIS != node->sec) + return; + if (node->next && MDOC_In != node->next->tok) + vspace(p); +} + + +/* ARGSUSED */ static int termp_at_pre(DECL_ARGS) { @@ -1352,7 +1400,7 @@ termp_bq_pre(DECL_ARGS) if (MDOC_BODY != node->type) return(1); - word(p, "\\["); + word(p, "["); p->flags |= TERMP_NOSPACE; return(1); } @@ -1450,9 +1498,9 @@ termp_bf_pre(DECL_ARGS) if (NULL == (n = b->head->child)) { if (arg_hasattr(MDOC_Emphasis, b->argc, b->argv)) - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); else if (arg_hasattr(MDOC_Symbolic, b->argc, b->argv)) - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMB]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]); return(1); } @@ -1460,9 +1508,9 @@ termp_bf_pre(DECL_ARGS) assert(MDOC_TEXT == n->type); if (0 == strcmp("Em", n->data.text.string)) - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); else if (0 == strcmp("Sy", n->data.text.string)) - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); return(1); } @@ -1473,7 +1521,7 @@ static int termp_sy_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMB]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]); return(1); } @@ -1483,7 +1531,7 @@ static int termp_ms_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMBOL]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMBOL]); return(1); }