=================================================================== RCS file: /cvs/mandoc/mdoc_man.c,v retrieving revision 1.9 retrieving revision 1.12 diff -u -p -r1.9 -r1.12 --- mandoc/mdoc_man.c 2011/10/24 21:47:59 1.9 +++ mandoc/mdoc_man.c 2012/07/07 13:53:14 1.12 @@ -1,6 +1,6 @@ -/* $Id: mdoc_man.c,v 1.9 2011/10/24 21:47:59 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.12 2012/07/07 13:53:14 schwarze Exp $ */ /* - * Copyright (c) 2011 Ingo Schwarze + * Copyright (c) 2011, 2012 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -18,10 +18,12 @@ #include "config.h" #endif +#include #include #include #include "mandoc.h" +#include "out.h" #include "man.h" #include "mdoc.h" #include "main.h" @@ -31,6 +33,7 @@ struct mman *mm struct mman { + int mode_space; /* spacing mode: 1 = on */ int need_space; /* next word needs prior ws */ int need_nl; /* next word needs prior nl */ }; @@ -63,11 +66,13 @@ static int pre_it(DECL_ARGS); static int pre_nm(DECL_ARGS); static int pre_ns(DECL_ARGS); 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 int pre_ux(DECL_ARGS); static int pre_xr(DECL_ARGS); static void print_word(struct mman *, const char *); +static void print_offs(struct mman *, const char *); static void print_node(DECL_ARGS); static const struct manact manacts[MDOC_MAX + 1] = { @@ -166,7 +171,7 @@ static const struct manact manacts[MDOC_MAX + 1] = { { NULL, NULL, NULL, NULL, NULL }, /* Sc */ { cond_body, pre_enc, post_enc, "`", "'" }, /* So */ { cond_body, pre_enc, post_enc, "`", "'" }, /* Sq */ - { NULL, NULL, NULL, NULL, NULL }, /* _Sm */ + { NULL, pre_sm, NULL, NULL, NULL }, /* Sm */ { NULL, pre_enc, post_enc, "\\fI", "\\fP" }, /* Sx */ { NULL, pre_enc, post_enc, "\\fB", "\\fP" }, /* Sy */ { NULL, pre_enc, post_enc, "\\fR", "\\fP" }, /* Tn */ @@ -227,8 +232,8 @@ print_word(struct mman *mm, const char *s) * Reassign needing space if we're not following opening * punctuation. */ - mm->need_space = - ('(' != s[0] && '[' != s[0]) || '\0' != s[1]; + mm->need_space = mm->mode_space && + (('(' != s[0] && '[' != s[0]) || '\0' != s[1]); for ( ; *s; s++) { switch (*s) { @@ -245,6 +250,29 @@ print_word(struct mman *mm, const char *s) } } +static void +print_offs(struct mman *mm, const char *v) +{ + char buf[24]; + struct roffsu su; + size_t sz; + + if (NULL == v || '\0' == *v || 0 == strcmp(v, "left")) + sz = 0; + else if (0 == strcmp(v, "indent")) + sz = 6; + else if (0 == strcmp(v, "indent-two")) + sz = 12; + else if (a2roffsu(v, &su, SCALE_MAX)) { + print_word(mm, v); + return; + } else + sz = strlen(v); + + snprintf(buf, sizeof(buf), "%ldn", sz); + print_word(mm, buf); +} + void man_man(void *arg, const struct man *man) { @@ -273,6 +301,7 @@ man_mdoc(void *arg, const struct mdoc *mdoc) memset(&mm, 0, sizeof(struct mman)); + mm.mode_space = 1; mm.need_nl = 1; print_node(m, n, &mm); putchar('\n'); @@ -290,7 +319,7 @@ print_node(DECL_ARGS) * This makes the page structure be more consistent. */ prev = n->prev ? n->prev : n->parent; - if (prev && prev->line < n->line) + if (prev && prev->line < n->line && MDOC_Ns != prev->tok) mm->need_nl = 1; act = NULL; @@ -379,6 +408,8 @@ post_enc(DECL_ARGS) return; mm->need_space = 0; print_word(mm, suffix); + if (MDOC_Fl == n->tok && 0 == n->nchild) + mm->need_space = 0; } /* @@ -443,12 +474,19 @@ static int pre_bd(DECL_ARGS) { + if (0 == n->norm->Bd.comp) { + mm->need_nl = 1; + print_word(mm, ".sp"); + } if (DISP_unfilled == n->norm->Bd.type || DISP_literal == n->norm->Bd.type) { mm->need_nl = 1; print_word(mm, ".nf"); } mm->need_nl = 1; + print_word(mm, ".RS"); + print_offs(mm, n->norm->Bd.offs); + mm->need_nl = 1; return(1); } @@ -456,6 +494,8 @@ static void post_bd(DECL_ARGS) { + mm->need_nl = 1; + print_word(mm, ".RE"); if (DISP_unfilled == n->norm->Bd.type || DISP_literal == n->norm->Bd.type) { mm->need_nl = 1; @@ -544,6 +584,11 @@ pre_nm(DECL_ARGS) if (MDOC_ELEM != n->type && MDOC_HEAD != n->type) return(1); + if (MDOC_SYNPRETTY & n->flags) { + mm->need_nl = 1; + print_word(mm, ".br"); + mm->need_nl = 1; + } print_word(mm, "\\fB"); mm->need_space = 0; if (NULL == n->child) @@ -586,7 +631,19 @@ pre_pp(DECL_ARGS) else print_word(mm, ".PP"); mm->need_nl = 1; - return(1); + return(MDOC_Rs == n->tok); +} + +static int +pre_sm(DECL_ARGS) +{ + + assert(n->child && MDOC_TEXT == n->child->type); + if (0 == strcmp("on", n->child->string)) + mm->mode_space = 1; + else + mm->mode_space = 0; + return(0); } static int