From e34eebeaa729c7d5cc258b87d5a6edd409cfaea2 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sat, 4 Sep 2010 19:01:52 +0000 Subject: Properly handle -mdoc %A in all outputs. This has two-author entires separated by only "and" while two or more are with ", and" for the last author. Also remove relevant TODO and add regression tests. --- mdoc_term.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'mdoc_term.c') diff --git a/mdoc_term.c b/mdoc_term.c index ba16bbc2..ca865c4f 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.183 2010/08/21 14:04:13 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.184 2010/09/04 19:01:52 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze @@ -92,6 +92,7 @@ static void termp_sh_post(DECL_ARGS); static void termp_sq_post(DECL_ARGS); static void termp_ss_post(DECL_ARGS); +static int termp__a_pre(DECL_ARGS); static int termp_an_pre(DECL_ARGS); static int termp_ap_pre(DECL_ARGS); static int termp_aq_pre(DECL_ARGS); @@ -178,7 +179,7 @@ static const struct termact termacts[MDOC_MAX] = { { termp_under_pre, NULL }, /* Va */ { termp_vt_pre, NULL }, /* Vt */ { termp_xr_pre, NULL }, /* Xr */ - { NULL, termp____post }, /* %A */ + { termp__a_pre, termp____post }, /* %A */ { termp_under_pre, termp____post }, /* %B */ { NULL, termp____post }, /* %D */ { termp_under_pre, termp____post }, /* %I */ @@ -1077,6 +1078,19 @@ termp_fl_pre(DECL_ARGS) } +/* ARGSUSED */ +static int +termp__a_pre(DECL_ARGS) +{ + + if (n->prev && MDOC__A == n->prev->tok) + if (NULL == n->next || MDOC__A != n->next->tok) + term_word(p, "and"); + + return(1); +} + + /* ARGSUSED */ static int termp_an_pre(DECL_ARGS) @@ -2098,6 +2112,16 @@ static void termp____post(DECL_ARGS) { + /* + * Handle lists of authors. In general, print each followed by + * a comma. Don't print the comma if there are only two + * authors. + */ + if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok) + if (NULL == n->next->next || MDOC__A != n->next->next->tok) + if (NULL == n->prev || MDOC__A != n->prev->tok) + return; + /* TODO: %U. */ p->flags |= TERMP_NOSPACE; -- cgit v1.2.3-56-ge451