diff options
author | Ingo Schwarze <schwarze@openbsd.org> | 2013-10-17 20:54:58 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@openbsd.org> | 2013-10-17 20:54:58 +0000 |
commit | a24894c279cda3d965668a3548d070489a8aceed (patch) | |
tree | 802cd2c3ea9060f30b957ad4a052608a76fe9b4a | |
parent | 9680b7282e62aa4b1c49f8ee927df097cbe37246 (diff) | |
download | mandoc-a24894c279cda3d965668a3548d070489a8aceed.tar.gz |
Implement the .UR/.UE block (uniform resource identifier) introduced in the
man-ext macros by Eric S. Raymond, enabled by default in groff_man(7).
Usual disclaimer: You don't write new man(7) code, so you are not going
to use these, either.
Improves e.g. the bzr(1) and etherape(1) manuals.
Thanks to naddy@ for bringing these to my attention.
-rw-r--r-- | man.c | 3 | ||||
-rw-r--r-- | man.h | 2 | ||||
-rw-r--r-- | man_html.c | 28 | ||||
-rw-r--r-- | man_macro.c | 5 | ||||
-rw-r--r-- | man_term.c | 30 | ||||
-rw-r--r-- | man_validate.c | 17 |
6 files changed, 83 insertions, 2 deletions
@@ -40,7 +40,8 @@ const char *const __man_macronames[MAN_MAX] = { "RI", "na", "sp", "nf", "fi", "RE", "RS", "DT", "UC", "PD", "AT", "in", - "ft", "OP", "EX", "EE" + "ft", "OP", "EX", "EE", + "UR", "UE" }; const char * const *man_macronames = __man_macronames; @@ -54,6 +54,8 @@ enum mant { MAN_OP, MAN_EX, MAN_EE, + MAN_UR, + MAN_UE, MAN_MAX }; @@ -1,6 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> + * Copyright (c) 2013 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -70,6 +71,7 @@ static int man_RS_pre(MAN_ARGS); static int man_SH_pre(MAN_ARGS); static int man_SM_pre(MAN_ARGS); static int man_SS_pre(MAN_ARGS); +static int man_UR_pre(MAN_ARGS); static int man_alt_pre(MAN_ARGS); static int man_br_pre(MAN_ARGS); static int man_ign_pre(MAN_ARGS); @@ -115,6 +117,8 @@ static const struct htmlman mans[MAN_MAX] = { { man_OP_pre, NULL }, /* OP */ { man_literal_pre, NULL }, /* EX */ { man_literal_pre, NULL }, /* EE */ + { man_UR_pre, NULL }, /* UR */ + { NULL, NULL }, /* UE */ }; /* @@ -688,3 +692,27 @@ man_RS_pre(MAN_ARGS) print_otag(h, TAG_DIV, 1, &tag); return(1); } + +/* ARGSUSED */ +static int +man_UR_pre(MAN_ARGS) +{ + struct htmlpair tag[2]; + + n = n->child; + assert(MAN_HEAD == n->type); + if (n->nchild) { + assert(MAN_TEXT == n->child->type); + PAIR_CLASS_INIT(&tag[0], "link-ext"); + PAIR_HREF_INIT(&tag[1], n->child->string); + print_otag(h, TAG_A, 2, tag); + } + + assert(MAN_BODY == n->next->type); + if (n->next->nchild) + n = n->next; + + print_man_nodelist(man, n->child, mh, h); + + return(0); +} diff --git a/man_macro.c b/man_macro.c index ab252b83..18eedbcb 100644 --- a/man_macro.c +++ b/man_macro.c @@ -88,6 +88,8 @@ const struct man_macro __man_macros[MAN_MAX] = { { in_line_eoln, 0 }, /* OP */ { in_line_eoln, MAN_BSCOPE }, /* EX */ { in_line_eoln, MAN_BSCOPE }, /* EE */ + { blk_exp, MAN_BSCOPE | MAN_EXPLICIT }, /* UR */ + { blk_close, 0 }, /* UE */ }; const struct man_macro * const man_macros = __man_macros; @@ -284,6 +286,9 @@ blk_close(MACRO_PROT_ARGS) case (MAN_RE): ntok = MAN_RS; break; + case (MAN_UE): + ntok = MAN_UR; + break; default: abort(); /* NOTREACHED */ @@ -78,6 +78,7 @@ static int pre_RS(DECL_ARGS); static int pre_SH(DECL_ARGS); static int pre_SS(DECL_ARGS); static int pre_TP(DECL_ARGS); +static int pre_UR(DECL_ARGS); static int pre_alternate(DECL_ARGS); static int pre_ft(DECL_ARGS); static int pre_ign(DECL_ARGS); @@ -91,6 +92,7 @@ static void post_RS(DECL_ARGS); static void post_SH(DECL_ARGS); static void post_SS(DECL_ARGS); static void post_TP(DECL_ARGS); +static void post_UR(DECL_ARGS); static const struct termact termacts[MAN_MAX] = { { pre_sp, NULL, MAN_NOTEXT }, /* br */ @@ -129,6 +131,8 @@ static const struct termact termacts[MAN_MAX] = { { pre_OP, NULL, 0 }, /* OP */ { pre_literal, NULL, 0 }, /* EX */ { pre_literal, NULL, 0 }, /* EE */ + { pre_UR, post_UR, 0 }, /* UR */ + { NULL, NULL, 0 }, /* UE */ }; @@ -939,6 +943,32 @@ post_RS(DECL_ARGS) mt->lmargincur = mt->lmarginsz; } +/* ARGSUSED */ +static int +pre_UR(DECL_ARGS) +{ + + return (MAN_HEAD != n->type); +} + +/* ARGSUSED */ +static void +post_UR(DECL_ARGS) +{ + + if (MAN_BLOCK != n->type) + return; + + term_word(p, "<"); + p->flags |= TERMP_NOSPACE; + + if (NULL != n->child->child) + print_man_node(p, mt, n->child->child, meta); + + p->flags |= TERMP_NOSPACE; + term_word(p, ">"); +} + static void print_man_node(DECL_ARGS) { diff --git a/man_validate.c b/man_validate.c index 95e452bd..ad923caf 100644 --- a/man_validate.c +++ b/man_validate.c @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010, 2012 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -49,6 +49,7 @@ static int check_eq2(CHKARGS); static int check_le1(CHKARGS); static int check_ge2(CHKARGS); static int check_le5(CHKARGS); +static int check_head1(CHKARGS); static int check_par(CHKARGS); static int check_part(CHKARGS); static int check_root(CHKARGS); @@ -80,6 +81,7 @@ static v_check posts_sec[] = { post_sec, NULL }; static v_check posts_sp[] = { post_vs, check_le1, NULL }; static v_check posts_th[] = { check_ge2, check_le5, post_TH, NULL }; static v_check posts_uc[] = { post_UC, NULL }; +static v_check posts_ur[] = { check_head1, check_part, NULL }; static v_check pres_sec[] = { pre_sec, NULL }; static const struct man_valid man_valids[MAN_MAX] = { @@ -119,6 +121,8 @@ static const struct man_valid man_valids[MAN_MAX] = { { NULL, posts_eq2 }, /* OP */ { NULL, posts_nf }, /* EX */ { NULL, posts_fi }, /* EE */ + { NULL, posts_ur }, /* UR */ + { NULL, NULL }, /* UE */ }; @@ -246,6 +250,17 @@ INEQ_DEFINE(2, >=, ge2) INEQ_DEFINE(5, <=, le5) static int +check_head1(CHKARGS) +{ + + if (MAN_HEAD == n->type && 1 != n->nchild) + mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, + n->pos, "line arguments eq 1 (have %d)", n->nchild); + + return(1); +} + +static int post_ft(CHKARGS) { char *cp; |