=================================================================== RCS file: /cvs/mandoc/man.c,v retrieving revision 1.119 retrieving revision 1.127 diff -u -p -r1.119 -r1.127 --- mandoc/man.c 2012/11/17 00:26:33 1.119 +++ mandoc/man.c 2014/03/23 20:57:27 1.127 @@ -1,6 +1,8 @@ -/* $Id: man.c,v 1.119 2012/11/17 00:26:33 schwarze Exp $ */ +/* $Id: man.c,v 1.127 2014/03/23 20:57:27 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons + * Copyright (c) 2013, 2014 Ingo Schwarze + * Copyright (c) 2011 Joerg Sonnenberger * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -21,6 +23,7 @@ #include #include +#include #include #include #include @@ -28,6 +31,7 @@ #include "man.h" #include "mandoc.h" +#include "mandoc_aux.h" #include "libman.h" #include "libmandoc.h" @@ -40,7 +44,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; @@ -96,7 +101,7 @@ man_free(struct man *man) struct man * -man_alloc(struct roff *roff, struct mparse *parse) +man_alloc(struct roff *roff, struct mparse *parse, int quick) { struct man *p; @@ -104,6 +109,7 @@ man_alloc(struct roff *roff, struct mparse *parse) man_hash_init(); p->parse = parse; + p->quick = quick; p->roff = roff; man_alloc1(p); @@ -428,16 +434,22 @@ man_ptext(struct man *man, int line, char *buf, int of return(man_descope(man, line, offs)); } - /* Pump blank lines directly into the backend. */ - for (i = offs; ' ' == buf[i]; i++) /* Skip leading whitespace. */ ; + /* + * Blank lines are ignored right after headings + * but add a single vertical space elsewhere. + */ + if ('\0' == buf[i]) { /* Allocate a blank entry. */ - if ( ! man_elem_alloc(man, line, offs, MAN_sp)) - return(0); - man->next = MAN_NEXT_SIBLING; + if (MAN_SH != man->last->tok && + MAN_SS != man->last->tok) { + if ( ! man_elem_alloc(man, line, offs, MAN_sp)) + return(0); + man->next = MAN_NEXT_SIBLING; + } return(1); } @@ -472,7 +484,7 @@ man_ptext(struct man *man, int line, char *buf, int of */ assert(i); - if (mandoc_eos(buf, (size_t)i, 0)) + if (mandoc_eos(buf, (size_t)i)) man->last->flags |= MAN_EOS; return(man_descope(man, line, offs)); @@ -597,6 +609,12 @@ man_pmacro(struct man *man, int ln, char *buf, int off if ( ! (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf)) goto err; + /* In quick mode (for mandocdb), abort after the NAME section. */ + + if (man->quick && MAN_SH == tok && + strcmp(man->last->prev->child->string, "NAME")) + return(2); + /* * We weren't in a block-line scope when entering the * above-parsed macro, so return. @@ -688,4 +706,50 @@ man_mparse(const struct man *man) assert(man && man->parse); return(man->parse); +} + +void +man_deroff(char **dest, const struct man_node *n) +{ + char *cp; + size_t sz; + + if (MAN_TEXT != n->type) { + for (n = n->child; n; n = n->next) + man_deroff(dest, n); + return; + } + + /* Skip leading whitespace and escape sequences. */ + + cp = n->string; + while ('\0' != *cp) { + if ('\\' == *cp) { + cp++; + mandoc_escape((const char **)&cp, NULL, NULL); + } else if (isspace((unsigned char)*cp)) + cp++; + else + break; + } + + /* Skip trailing whitespace. */ + + for (sz = strlen(cp); sz; sz--) + if (0 == isspace((unsigned char)cp[sz-1])) + break; + + /* Skip empty strings. */ + + if (0 == sz) + return; + + if (NULL == *dest) { + *dest = mandoc_strndup(cp, sz); + return; + } + + mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp); + free(*dest); + *dest = cp; }