=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.204 retrieving revision 1.212 diff -u -p -r1.204 -r1.212 --- mandoc/mdoc.c 2013/10/05 22:08:12 1.204 +++ mandoc/mdoc.c 2014/03/30 19:47:48 1.212 @@ -1,7 +1,7 @@ -/* $Id: mdoc.c,v 1.204 2013/10/05 22:08:12 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.212 2014/03/30 19:47:48 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 @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include "mdoc.h" #include "mandoc.h" +#include "mandoc_aux.h" #include "libmdoc.h" #include "libmandoc.h" @@ -70,7 +72,7 @@ const char *const __mdoc_macronames[MDOC_MAX] = { /* LINTED */ "Dx", "%Q", "br", "sp", /* LINTED */ - "%U", "Ta" + "%U", "Ta", "ll", }; const char *const __mdoc_argnames[MDOC_ARG_MAX] = { @@ -197,7 +199,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 +208,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(); @@ -434,6 +438,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; @@ -582,7 +587,21 @@ 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); + mandoc_asprintf(&newstr, "%s %s", n->string, addstr); + free(addstr); + free(n->string); + n->string = newstr; + mdoc->next = MDOC_NEXT_SIBLING; +} + static void mdoc_node_free(struct mdoc_node *p) { @@ -828,7 +847,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); @@ -943,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); err: /* Error out. */ @@ -995,4 +1020,43 @@ mdoc_isdelim(const char *p) return(DELIM_MIDDLE); return(DELIM_NONE); +} + +void +mdoc_deroff(char **dest, const struct mdoc_node *n) +{ + char *cp; + size_t sz; + + if (MDOC_TEXT != n->type) { + for (n = n->child; n; n = n->next) + mdoc_deroff(dest, n); + return; + } + + /* Skip leading whitespace. */ + + for (cp = n->string; '\0' != *cp; cp++) + if (0 == isspace((unsigned char)*cp)) + 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; }