=================================================================== RCS file: /cvs/mandoc/term.c,v retrieving revision 1.28 retrieving revision 1.31 diff -u -p -r1.28 -r1.31 --- mandoc/term.c 2009/02/28 19:15:28 1.28 +++ mandoc/term.c 2009/03/01 13:06:49 1.31 @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.28 2009/02/28 19:15:28 kristaps Exp $ */ +/* $Id: term.c,v 1.31 2009/03/01 13:06:49 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -25,7 +25,7 @@ #include "term.h" -#define INDENT 8 +#define INDENT 6 /* * Performs actions on nodes of the abstract syntax tree. Both pre- and @@ -118,6 +118,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 +134,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 +142,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 +163,7 @@ DECL_PRE(termp_xr); DECL_POST(termp___); DECL_POST(termp_bl); +DECL_POST(termp_bx); const struct termact __termacts[MDOC_MAX] = { { NULL, NULL }, /* \" */ @@ -174,7 +174,7 @@ const struct termact __termacts[MDOC_MAX] = { { termp_ss_pre, termp_ss_post }, /* Ss */ { termp_pp_pre, NULL }, /* Pp */ { termp_d1_pre, termp_d1_post }, /* D1 */ - { NULL, NULL }, /* Dl */ + { termp_d1_pre, termp_d1_post }, /* Dl */ { termp_bd_pre, termp_bd_post }, /* Bd */ { NULL, NULL }, /* Ed */ { NULL, termp_bl_post }, /* Bl */ @@ -195,7 +195,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 */ @@ -208,16 +208,16 @@ const struct termact __termacts[MDOC_MAX] = { { termp_vt_pre, termp_vt_post }, /* Vt */ { termp_xr_pre, NULL }, /* Xr */ { NULL, termp____post }, /* %A */ - { NULL, NULL }, /* %B */ + { NULL, termp____post }, /* %B */ { NULL, termp____post }, /* %D */ - { NULL, NULL }, /* %I */ + { NULL, termp____post }, /* %I */ { NULL, termp____post }, /* %J */ - { NULL, NULL }, /* %N */ - { NULL, NULL }, /* %O */ - { NULL, NULL }, /* %P */ - { NULL, NULL }, /* %R */ + { NULL, termp____post }, /* %N */ + { NULL, termp____post }, /* %O */ + { NULL, termp____post }, /* %P */ + { NULL, termp____post }, /* %R */ { termp__t_pre, termp__t_post }, /* %T */ - { NULL, NULL }, /* %V */ + { NULL, termp____post }, /* %V */ { NULL, NULL }, /* Ac */ { termp_aq_pre, termp_aq_post }, /* Ao */ { termp_aq_pre, termp_aq_post }, /* Aq */ @@ -227,7 +227,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 */ @@ -395,10 +395,10 @@ termp_it_pre(DECL_ARGS) bl = &n->data.block; if (MDOC_BLOCK == node->type) { - if (arg_hasattr(MDOC_Compact, bl->argc, bl->argv)) - newln(p); - else - vspace(p); + newln(p); + if ( ! arg_hasattr(MDOC_Compact, bl->argc, bl->argv)) + if (node->prev || n->prev) + vspace(p); return(1); } @@ -550,10 +550,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; } @@ -563,9 +562,13 @@ static int termp_nm_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_PROG]); + if (SEC_SYNOPSIS == node->sec) + newln(p); + + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_PROG]); if (NULL == node->child) word(p, meta->name); + return(1); } @@ -575,7 +578,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); @@ -587,9 +590,11 @@ static int termp_ar_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_ARG]); - if (NULL == node->child) + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_ARG]); + if (NULL == node->child) { + word(p, "file"); word(p, "..."); + } return(1); } @@ -634,7 +639,7 @@ static int termp_rs_pre(DECL_ARGS) { - if (MDOC_BLOCK == node->type) + if (MDOC_BLOCK == node->type && node->prev) vspace(p); return(1); } @@ -756,7 +761,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); } @@ -780,7 +785,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); } @@ -790,7 +795,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); } @@ -803,7 +811,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; @@ -926,7 +934,7 @@ static int termp_ft_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_TYPE]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_TYPE]); return(1); } @@ -982,7 +990,7 @@ static void termp_fn_post(DECL_ARGS) { - if (node->sec == SEC_SYNOPSIS) + if (node->sec == SEC_SYNOPSIS && node->next) vspace(p); } @@ -993,7 +1001,7 @@ static int termp_sx_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_LINK]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_LINK]); return(1); } @@ -1005,7 +1013,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); } @@ -1032,7 +1040,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); } @@ -1046,7 +1054,8 @@ termp_bd_pre(DECL_ARGS) int i; if (MDOC_BLOCK == node->type) { - vspace(p); + if (node->prev) + vspace(p); return(1); } else if (MDOC_BODY != node->type) return(1); @@ -1131,12 +1140,12 @@ termp_bsx_pre(DECL_ARGS) /* ARGSUSED */ -static int -termp_bx_pre(DECL_ARGS) +static void +termp_bx_post(DECL_ARGS) { + p->flags |= TERMP_NOSPACE; word(p, "BSD"); - return(1); } @@ -1233,7 +1242,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: @@ -1265,7 +1274,7 @@ static int termp_pa_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FILE]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FILE]); return(1); } @@ -1275,7 +1284,7 @@ static int termp_em_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]); return(1); } @@ -1285,7 +1294,7 @@ static int termp_cd_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CONFIG]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CONFIG]); return(1); } @@ -1295,7 +1304,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); } @@ -1305,7 +1314,7 @@ static int termp_ic_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD]); return(1); } @@ -1315,12 +1324,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) { @@ -1344,7 +1372,7 @@ termp_bq_pre(DECL_ARGS) if (MDOC_BODY != node->type) return(1); - word(p, "\\["); + word(p, "["); p->flags |= TERMP_NOSPACE; return(1); } @@ -1442,9 +1470,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); } @@ -1452,9 +1480,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); } @@ -1465,7 +1493,7 @@ static int termp_sy_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMB]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]); return(1); } @@ -1475,7 +1503,7 @@ static int termp_ms_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMBOL]); + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMBOL]); return(1); }