=================================================================== RCS file: /cvs/mandoc/term.c,v retrieving revision 1.24 retrieving revision 1.29 diff -u -p -r1.24 -r1.29 --- mandoc/term.c 2009/02/26 14:56:27 1.24 +++ mandoc/term.c 2009/02/28 20:13:06 1.29 @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.24 2009/02/26 14:56:27 kristaps Exp $ */ +/* $Id: term.c,v 1.29 2009/02/28 20:13:06 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -17,6 +17,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ #include +#include #include #include #include @@ -24,7 +25,7 @@ #include "term.h" -#define INDENT 4 +#define INDENT 6 /* * Performs actions on nodes of the abstract syntax tree. Both pre- and @@ -107,6 +108,7 @@ static void name##_post(DECL_ARGS) DECL_PRE(name); \ DECL_POST(name); +DECL_PREPOST(termp__t); DECL_PREPOST(termp_aq); DECL_PREPOST(termp_bd); DECL_PREPOST(termp_bq); @@ -149,6 +151,7 @@ DECL_PRE(termp_nx); DECL_PRE(termp_ox); DECL_PRE(termp_pa); DECL_PRE(termp_pp); +DECL_PRE(termp_rs); DECL_PRE(termp_rv); DECL_PRE(termp_sm); DECL_PRE(termp_st); @@ -159,6 +162,7 @@ DECL_PRE(termp_ux); DECL_PRE(termp_va); DECL_PRE(termp_xr); +DECL_POST(termp___); DECL_POST(termp_bl); const struct termact __termacts[MDOC_MAX] = { @@ -170,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 */ @@ -203,17 +207,17 @@ const struct termact __termacts[MDOC_MAX] = { { termp_va_pre, NULL }, /* Va */ { termp_vt_pre, termp_vt_post }, /* Vt */ { termp_xr_pre, NULL }, /* Xr */ - { NULL, NULL }, /* %A */ - { NULL, NULL }, /* %B */ - { NULL, NULL }, /* %D */ - { NULL, NULL }, /* %I */ - { NULL, NULL }, /* %J */ - { NULL, NULL }, /* %N */ - { NULL, NULL }, /* %O */ - { NULL, NULL }, /* %P */ - { NULL, NULL }, /* %R */ - { NULL, NULL }, /* %T */ - { NULL, NULL }, /* %V */ + { NULL, termp____post }, /* %A */ + { NULL, termp____post }, /* %B */ + { NULL, termp____post }, /* %D */ + { NULL, termp____post }, /* %I */ + { NULL, termp____post }, /* %J */ + { NULL, termp____post }, /* %N */ + { NULL, termp____post }, /* %O */ + { NULL, termp____post }, /* %P */ + { NULL, termp____post }, /* %R */ + { termp__t_pre, termp__t_post }, /* %T */ + { NULL, termp____post }, /* %V */ { NULL, NULL }, /* Ac */ { termp_aq_pre, termp_aq_post }, /* Ao */ { termp_aq_pre, termp_aq_post }, /* Aq */ @@ -247,7 +251,7 @@ const struct termact __termacts[MDOC_MAX] = { { termp_qq_pre, termp_qq_post }, /* Qo */ { termp_qq_pre, termp_qq_post }, /* Qq */ { NULL, NULL }, /* Re */ - { NULL, NULL }, /* Rs */ + { termp_rs_pre, NULL }, /* Rs */ { NULL, NULL }, /* Sc */ { termp_sq_pre, termp_sq_post }, /* So */ { termp_sq_pre, termp_sq_post }, /* Sq */ @@ -276,10 +280,30 @@ const struct termact *termacts = __termacts; static size_t arg_width(const struct mdoc_arg *arg) { + size_t v; + int i, len; - /* TODO */ assert(*arg->value); - return(strlen(*arg->value)); + if (0 == strcmp(*arg->value, "indent")) + return(INDENT); + if (0 == strcmp(*arg->value, "indent-two")) + return(INDENT * 2); + + len = (int)strlen(*arg->value); + assert(len > 0); + + for (i = 0; i < len - 1; i++) + if ( ! isdigit((int)(*arg->value)[i])) + break; + + if (i == len - 1) { + if ('n' == (*arg->value)[len - 1]) { + v = (size_t)atoi(*arg->value); + return(v); + } + + } + return(strlen(*arg->value) + 2); } @@ -293,7 +317,6 @@ arg_offset(const struct mdoc_arg *arg) return(INDENT); if (0 == strcmp(*arg->value, "indent-two")) return(INDENT * 2); - return(strlen(*arg->value)); } @@ -372,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); } @@ -540,6 +563,9 @@ static int termp_nm_pre(DECL_ARGS) { + if (SEC_SYNOPSIS == node->sec) + newln(p); + TERMPAIR_SETFLAG(pair, ttypes[TTYPE_PROG]); if (NULL == node->child) word(p, meta->name); @@ -564,9 +590,14 @@ static int termp_ar_pre(DECL_ARGS) { - TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_ARG]); - if (NULL == node->child) - word(p, "..."); + if (node->child) { + TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_ARG]); + return(1); + } + p->flags |= ttypes[TTYPE_CMD_ARG]; + word(p, "file"); + word(p, "..."); + p->flags &= ~ttypes[TTYPE_CMD_ARG]; return(1); } @@ -608,6 +639,17 @@ termp_st_pre(DECL_ARGS) /* ARGSUSED */ static int +termp_rs_pre(DECL_ARGS) +{ + + if (MDOC_BLOCK == node->type) + vspace(p); + return(1); +} + + +/* ARGSUSED */ +static int termp_rv_pre(DECL_ARGS) { int i; @@ -1153,7 +1195,7 @@ termp_sq_pre(DECL_ARGS) if (MDOC_BODY != node->type) return(1); - word(p, "\'"); + word(p, "`"); p->flags |= TERMP_NOSPACE; return(1); } @@ -1310,7 +1352,7 @@ termp_bq_pre(DECL_ARGS) if (MDOC_BODY != node->type) return(1); - word(p, "["); + word(p, "\\["); p->flags |= TERMP_NOSPACE; return(1); } @@ -1334,7 +1376,7 @@ termp_pq_pre(DECL_ARGS) if (MDOC_BODY != node->type) return(1); - word(p, "("); + word(p, "\\&("); p->flags |= TERMP_NOSPACE; return(1); } @@ -1464,4 +1506,36 @@ termp_sm_pre(DECL_ARGS) #endif return(0); +} + + +/* ARGSUSED */ +static int +termp__t_pre(DECL_ARGS) +{ + + word(p, "\""); + p->flags |= TERMP_NOSPACE; + return(1); +} + + +/* ARGSUSED */ +static void +termp__t_post(DECL_ARGS) +{ + + p->flags |= TERMP_NOSPACE; + word(p, "\""); + word(p, node->next ? "," : "."); +} + + +/* ARGSUSED */ +static void +termp____post(DECL_ARGS) +{ + + p->flags |= TERMP_NOSPACE; + word(p, node->next ? "," : "."); }