=================================================================== RCS file: /cvs/mandoc/mdoc_man.c,v retrieving revision 1.20 retrieving revision 1.23 diff -u -p -r1.20 -r1.23 --- mandoc/mdoc_man.c 2012/07/08 15:01:57 1.20 +++ mandoc/mdoc_man.c 2012/07/08 18:39:47 1.23 @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.20 2012/07/08 15:01:57 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.23 2012/07/08 18:39:47 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Ingo Schwarze * @@ -56,6 +56,7 @@ static void post_pf(DECL_ARGS); static void post_sect(DECL_ARGS); static void post_sp(DECL_ARGS); static void post_vt(DECL_ARGS); +static int pre_an(DECL_ARGS); static int pre_ap(DECL_ARGS); static int pre_bd(DECL_ARGS); static int pre_bk(DECL_ARGS); @@ -66,6 +67,7 @@ static int pre_enc(DECL_ARGS); static int pre_fa(DECL_ARGS); static int pre_fn(DECL_ARGS); static int pre_fo(DECL_ARGS); +static int pre_ft(DECL_ARGS); static int pre_in(DECL_ARGS); static int pre_it(DECL_ARGS); static int pre_nm(DECL_ARGS); @@ -74,6 +76,7 @@ static int pre_pp(DECL_ARGS); static int pre_sm(DECL_ARGS); static int pre_sp(DECL_ARGS); static int pre_sect(DECL_ARGS); +static void pre_syn(const struct mdoc_node *); static int pre_vt(DECL_ARGS); static int pre_ux(DECL_ARGS); static int pre_xr(DECL_ARGS); @@ -97,7 +100,7 @@ static const struct manact manacts[MDOC_MAX + 1] = { { NULL, NULL, NULL, NULL, NULL }, /* El */ { NULL, pre_it, NULL, NULL, NULL }, /* _It */ { NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Ad */ - { NULL, NULL, NULL, NULL, NULL }, /* _An */ + { NULL, pre_an, NULL, NULL, NULL }, /* An */ { NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Ar */ { NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Cd */ { NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Cm */ @@ -111,7 +114,7 @@ static const struct manact manacts[MDOC_MAX + 1] = { { NULL, NULL, NULL, NULL, NULL }, /* _Fd */ { NULL, pre_enc, post_enc, "\\fB-", "\\fP" }, /* Fl */ { NULL, pre_fn, post_fn, NULL, NULL }, /* Fn */ - { NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Ft */ + { NULL, pre_ft, post_enc, NULL, "\\fP" }, /* Ft */ { NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Ic */ { NULL, pre_in, post_in, NULL, NULL }, /* In */ { NULL, pre_enc, post_enc, "\\fR", "\\fP" }, /* Li */ @@ -216,19 +219,28 @@ static const struct manact manacts[MDOC_MAX + 1] = { static int outflags; #define MMAN_spc (1 << 0) #define MMAN_nl (1 << 1) -#define MMAN_Sm (1 << 2) -#define MMAN_Bk (1 << 3) +#define MMAN_br (1 << 2) +#define MMAN_sp (1 << 3) +#define MMAN_Sm (1 << 4) +#define MMAN_Bk (1 << 5) +#define MMAN_An_split (1 << 6) +#define MMAN_An_nosplit (1 << 7) static void print_word(const char *s) { - if (MMAN_nl & outflags) { + if ((MMAN_sp | MMAN_br | MMAN_nl) & outflags) { /* * If we need a newline, print it now and start afresh. */ - putchar('\n'); - outflags &= ~(MMAN_nl|MMAN_spc); + if (MMAN_sp & outflags) + printf("\n.sp\n"); + else if (MMAN_br & outflags) + printf("\n.br\n"); + else if (MMAN_nl & outflags) + putchar('\n'); + outflags &= ~(MMAN_sp|MMAN_br|MMAN_nl|MMAN_spc); } else if (MMAN_spc & outflags && '\0' != s[0]) /* * If we need a space, only print it before @@ -474,9 +486,74 @@ post_sect(DECL_ARGS) outflags &= ~MMAN_spc; print_word("\""); outflags |= MMAN_nl; + if (MDOC_Sh == n->tok && SEC_AUTHORS == n->sec) + outflags &= ~(MMAN_An_split | MMAN_An_nosplit); } +/* See mdoc_term.c, synopsis_pre() for comments. */ +static void +pre_syn(const struct mdoc_node *n) +{ + + if (NULL == n->prev || ! (MDOC_SYNPRETTY & n->flags)) + return; + + if (n->prev->tok == n->tok && + MDOC_Ft != n->tok && + MDOC_Fo != n->tok && + MDOC_Fn != n->tok) { + outflags |= MMAN_br; + return; + } + + switch (n->prev->tok) { + case (MDOC_Fd): + /* FALLTHROUGH */ + case (MDOC_Fn): + /* FALLTHROUGH */ + case (MDOC_Fo): + /* FALLTHROUGH */ + case (MDOC_In): + /* FALLTHROUGH */ + case (MDOC_Vt): + outflags |= MMAN_sp; + break; + case (MDOC_Ft): + if (MDOC_Fn != n->tok && MDOC_Fo != n->tok) { + outflags |= MMAN_sp; + break; + } + /* FALLTHROUGH */ + default: + outflags |= MMAN_br; + break; + } +} + static int +pre_an(DECL_ARGS) +{ + + switch (n->norm->An.auth) { + case (AUTH_split): + outflags &= ~MMAN_An_nosplit; + outflags |= MMAN_An_split; + return(0); + case (AUTH_nosplit): + outflags &= ~MMAN_An_split; + outflags |= MMAN_An_nosplit; + return(0); + default: + if (MMAN_An_split & outflags) + outflags |= MMAN_br; + else if (SEC_AUTHORS == n->sec && + ! (MMAN_An_nosplit & outflags)) + outflags |= MMAN_An_split; + return(1); + } +} + +static int pre_ap(DECL_ARGS) { @@ -490,10 +567,8 @@ static int pre_bd(DECL_ARGS) { - if (0 == n->norm->Bd.comp) { - outflags |= MMAN_nl; - print_word(".sp"); - } + if (0 == n->norm->Bd.comp) + outflags |= MMAN_sp; if (DISP_unfilled == n->norm->Bd.type || DISP_literal == n->norm->Bd.type) { outflags |= MMAN_nl; @@ -547,9 +622,7 @@ static int pre_br(DECL_ARGS) { - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; + outflags |= MMAN_br; return(0); } @@ -623,15 +696,12 @@ static int pre_fn(DECL_ARGS) { + pre_syn(n); + n = n->child; if (NULL == n) return(0); - if (MDOC_SYNPRETTY & n->flags) { - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; - } print_word("\\fB"); outflags &= ~MMAN_spc; print_node(m, n); @@ -648,9 +718,7 @@ post_fn(DECL_ARGS) print_word(")"); if (MDOC_SYNPRETTY & n->flags) { print_word(";"); - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; + outflags |= MMAN_br; } } @@ -659,12 +727,10 @@ pre_fo(DECL_ARGS) { switch (n->type) { + case (MDOC_BLOCK): + pre_syn(n); + break; case (MDOC_HEAD): - if (MDOC_SYNPRETTY & n->flags) { - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; - } print_word("\\fB"); outflags &= ~MMAN_spc; break; @@ -697,13 +763,21 @@ post_fo(DECL_ARGS) } static int +pre_ft(DECL_ARGS) +{ + + pre_syn(n); + print_word("\\fI"); + outflags &= ~MMAN_spc; + return(1); +} + +static int pre_in(DECL_ARGS) { if (MDOC_SYNPRETTY & n->flags) { - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; + pre_syn(n); print_word("\\fB#include <"); } else print_word("<\\fI"); @@ -718,9 +792,7 @@ post_in(DECL_ARGS) outflags &= ~MMAN_spc; if (MDOC_SYNPRETTY & n->flags) { print_word(">\\fP"); - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; + outflags |= MMAN_br; } else print_word("\\fP>"); } @@ -754,24 +826,20 @@ static void post_lb(DECL_ARGS) { - if (SEC_LIBRARY == n->sec) { - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; - } + if (SEC_LIBRARY == n->sec) + outflags |= MMAN_br; } static int pre_nm(DECL_ARGS) { + if (MDOC_BLOCK == n->type) + pre_syn(n); if (MDOC_ELEM != n->type && MDOC_HEAD != n->type) return(1); - if (MDOC_SYNPRETTY & n->flags) { - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; - } + if (NULL == n->child && NULL == m->name) + return(0); print_word("\\fB"); outflags &= ~MMAN_spc; if (NULL == n->child) @@ -852,15 +920,13 @@ pre_vt(DECL_ARGS) if (MDOC_SYNPRETTY & n->flags) { switch (n->type) { case (MDOC_BLOCK): + pre_syn(n); return(1); case (MDOC_BODY): break; default: return(0); } - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; } print_word("\\fI"); outflags &= ~MMAN_spc; @@ -876,11 +942,6 @@ post_vt(DECL_ARGS) outflags &= ~MMAN_spc; print_word("\\fP"); - if (MDOC_SYNPRETTY & n->flags) { - outflags |= MMAN_nl; - print_word(".br"); - outflags |= MMAN_nl; - } } static int