=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.203 retrieving revision 1.208 diff -u -p -r1.203 -r1.208 --- mandoc/mdoc.c 2012/11/17 00:26:33 1.203 +++ mandoc/mdoc.c 2014/01/05 20:26:36 1.208 @@ -1,7 +1,7 @@ -/* $Id: mdoc.c,v 1.203 2012/11/17 00:26:33 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.208 2014/01/05 20:26:36 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2012 Ingo Schwarze + * Copyright (c) 2010, 2012, 2013, 2014 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 @@ -197,7 +197,8 @@ mdoc_free(struct mdoc *mdoc) * Allocate volatile and non-volatile parse resources. */ struct mdoc * -mdoc_alloc(struct roff *roff, struct mparse *parse, char *defos) +mdoc_alloc(struct roff *roff, struct mparse *parse, + char *defos, int quick) { struct mdoc *p; @@ -205,6 +206,7 @@ mdoc_alloc(struct roff *roff, struct mparse *parse, ch p->parse = parse; p->defos = defos; + p->quick = quick; p->roff = roff; mdoc_hash_init(); @@ -295,12 +297,10 @@ mdoc_parseln(struct mdoc *mdoc, int ln, char *buf, int * whether this mode is on or off. * Note that this mode is also switched by the Sh macro. */ - if (roff_regisset(mdoc->roff, REG_nS)) { - if (roff_regget(mdoc->roff, REG_nS)) - mdoc->flags |= MDOC_SYNOPSIS; - else - mdoc->flags &= ~MDOC_SYNOPSIS; - } + if (roff_getreg(mdoc->roff, "nS")) + mdoc->flags |= MDOC_SYNOPSIS; + else + mdoc->flags &= ~MDOC_SYNOPSIS; return(roff_getcontrol(mdoc->roff, buf, &offs) ? mdoc_pmacro(mdoc, ln, buf, offs) : @@ -436,6 +436,7 @@ node_alloc(struct mdoc *mdoc, int line, int pos, p->sec = mdoc->lastsec; p->line = line; p->pos = pos; + p->lastline = line; p->tok = tok; p->type = type; @@ -584,7 +585,24 @@ mdoc_word_alloc(struct mdoc *mdoc, int line, int pos, return(1); } +void +mdoc_word_append(struct mdoc *mdoc, const char *p) +{ + struct mdoc_node *n; + char *addstr, *newstr; + n = mdoc->last; + addstr = roff_strdup(mdoc->roff, p); + if (-1 == asprintf(&newstr, "%s %s", n->string, addstr)) { + perror(NULL); + exit((int)MANDOCLEVEL_SYSERR); + } + free(addstr); + free(n->string); + n->string = newstr; + mdoc->next = MDOC_NEXT_SIBLING; +} + static void mdoc_node_free(struct mdoc_node *p) { @@ -830,7 +848,7 @@ mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int assert(buf < end); - if (mandoc_eos(buf+offs, (size_t)(end-buf-offs), 0)) + if (mandoc_eos(buf+offs, (size_t)(end-buf-offs))) mdoc->last->flags |= MDOC_EOS; return(1); @@ -944,6 +962,12 @@ mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf)) goto err; + + /* In quick mode (for mandocdb), abort after the NAME section. */ + + if (mdoc->quick && MDOC_Sh == tok && + SEC_NAME != mdoc->last->sec) + return(2); return(1);