=================================================================== RCS file: /cvs/mandoc/term.c,v retrieving revision 1.47 retrieving revision 1.52 diff -u -p -r1.47 -r1.52 --- mandoc/term.c 2009/03/08 19:38:08 1.47 +++ mandoc/term.c 2009/03/10 11:16:43 1.52 @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.47 2009/03/08 19:38:08 kristaps Exp $ */ +/* $Id: term.c,v 1.52 2009/03/10 11:16:43 kristaps Exp $ */ /* * Copyright (c) 2009 Kristaps Dzonsons * @@ -16,6 +16,8 @@ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. */ +#include + #include #include #include @@ -51,7 +53,9 @@ #define TTYPE_SYMB 16 #define TTYPE_SYMBOL 17 #define TTYPE_DIAG 18 -#define TTYPE_NMAX 19 +#define TTYPE_LINK_ANCHOR 19 +#define TTYPE_LINK_TEXT 20 +#define TTYPE_NMAX 21 /* * These define "styles" for element types, like command arguments or @@ -80,7 +84,9 @@ const int ttypes[TTYPE_NMAX] = { TERMP_BOLD, /* TTYPE_INCLUDE */ TERMP_BOLD, /* TTYPE_SYMB */ TERMP_BOLD, /* TTYPE_SYMBOL */ - TERMP_BOLD /* TTYPE_DIAG */ + TERMP_BOLD, /* TTYPE_DIAG */ + TERMP_UNDERLINE, /* TTYPE_LINK_ANCHOR */ + TERMP_BOLD /* TTYPE_LINK_TEXT */ }; static int arg_hasattr(int, const struct mdoc_node *); @@ -130,6 +136,7 @@ DECL_PREPOST(termp_ss); DECL_PREPOST(termp_sq); DECL_PREPOST(termp_vt); +DECL_PRE(termp_ap); DECL_PRE(termp_ar); DECL_PRE(termp_at); DECL_PRE(termp_bf); @@ -143,7 +150,9 @@ DECL_PRE(termp_fa); DECL_PRE(termp_fl); DECL_PRE(termp_fx); DECL_PRE(termp_ic); +DECL_PRE(termp_lk); DECL_PRE(termp_ms); +DECL_PRE(termp_mt); DECL_PRE(termp_nd); DECL_PRE(termp_nm); DECL_PRE(termp_ns); @@ -274,6 +283,10 @@ const struct termact __termacts[MDOC_MAX] = { { NULL, NULL }, /* Fr */ { termp_ud_pre, NULL }, /* Ud */ { termp_lb_pre, termp_lb_post }, /* Lb */ + { termp_ap_pre, NULL }, /* Lb */ + { termp_pp_pre, NULL }, /* Pp */ + { termp_lk_pre, NULL }, /* Lk */ + { termp_mt_pre, NULL }, /* Mt */ }; const struct termact *termacts = __termacts; @@ -720,12 +733,8 @@ termp_st_pre(DECL_ARGS) { const char *cp; - if (node->child) { - if (MDOC_TEXT != node->child->type) - errx(1, "expected text line arguments"); - if ((cp = mdoc_a2st(node->child->string))) - word(p, cp); - } + if (node->child && (cp = mdoc_a2st(node->child->string))) + word(p, cp); return(0); } @@ -834,23 +843,15 @@ termp_xr_pre(DECL_ARGS) if (NULL == (n = node->child)) errx(1, "expected text line argument"); - if (MDOC_TEXT != n->type) - errx(1, "expected text line argument"); - word(p, n->string); - if (NULL == (n = n->next)) return(0); - if (MDOC_TEXT != n->type) - errx(1, "expected text line argument"); - p->flags |= TERMP_NOSPACE; word(p, "("); p->flags |= TERMP_NOSPACE; word(p, n->string); p->flags |= TERMP_NOSPACE; word(p, ")"); - return(0); } @@ -977,14 +978,10 @@ termp_lb_pre(DECL_ARGS) if (NULL == node->child) errx(1, "expected text line argument"); - if (MDOC_TEXT != node->child->type) - errx(1, "expected text line argument"); - if ((lb = mdoc_a2lib(node->child->string))) { word(p, lb); return(0); } - word(p, "library"); return(1); } @@ -1090,8 +1087,6 @@ termp_fn_pre(DECL_ARGS) if (NULL == node->child) errx(1, "expected text line arguments"); - if (MDOC_TEXT != node->child->type) - errx(1, "expected text line arguments"); /* FIXME: can be "type funcname" "type varname"... */ @@ -1103,8 +1098,6 @@ termp_fn_pre(DECL_ARGS) p->flags |= TERMP_NOSPACE; for (n = node->child->next; n; n = n->next) { - if (MDOC_TEXT != n->type) - errx(1, "expected text line arguments"); p->flags |= ttypes[TTYPE_FUNC_ARG]; word(p, n->string); p->flags &= ~ttypes[TTYPE_FUNC_ARG]; @@ -1154,13 +1147,9 @@ termp_fa_pre(DECL_ARGS) } for (n = node->child; n; n = n->next) { - if (MDOC_TEXT != n->type) - errx(1, "expected text line arguments"); - p->flags |= ttypes[TTYPE_FUNC_ARG]; word(p, n->string); p->flags &= ~ttypes[TTYPE_FUNC_ARG]; - if (n->next) word(p, ","); } @@ -1523,12 +1512,8 @@ termp_at_pre(DECL_ARGS) att = NULL; - if (node->child) { - if (MDOC_TEXT != node->child->type) - errx(1, "expected text line argument"); + if (node->child) att = mdoc_a2att(node->child->string); - } - if (NULL == att) att = "AT&T UNIX"; @@ -1700,6 +1685,18 @@ termp_sm_pre(DECL_ARGS) /* ARGSUSED */ static int +termp_ap_pre(DECL_ARGS) +{ + + p->flags |= TERMP_NOSPACE; + word(p, "\\(aq"); + p->flags |= TERMP_NOSPACE; + return(1); +} + + +/* ARGSUSED */ +static int termp__t_pre(DECL_ARGS) { @@ -1730,3 +1727,39 @@ termp____post(DECL_ARGS) p->flags |= TERMP_NOSPACE; word(p, node->next ? "," : "."); } + + +/* ARGSUSED */ +static int +termp_lk_pre(DECL_ARGS) +{ + const struct mdoc_node *n; + + if (NULL == (n = node->child)) + errx(1, "expected line argument"); + + p->flags |= ttypes[TTYPE_LINK_ANCHOR]; + word(p, n->string); + p->flags &= ~ttypes[TTYPE_LINK_ANCHOR]; + p->flags |= TERMP_NOSPACE; + word(p, ":"); + + p->flags |= ttypes[TTYPE_LINK_TEXT]; + for ( ; n; n = n->next) { + word(p, n->string); + } + p->flags &= ~ttypes[TTYPE_LINK_TEXT]; + + return(0); +} + + +/* ARGSUSED */ +static int +termp_mt_pre(DECL_ARGS) +{ + + TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_LINK_ANCHOR]); + return(1); +} +