=================================================================== RCS file: /cvs/docbook2mdoc/parse.c,v retrieving revision 1.42 retrieving revision 1.47 diff -u -p -r1.42 -r1.47 --- docbook2mdoc/parse.c 2019/04/14 14:00:16 1.42 +++ docbook2mdoc/parse.c 2019/04/20 04:15:06 1.47 @@ -1,4 +1,4 @@ -/* $Id: parse.c,v 1.42 2019/04/14 14:00:16 schwarze Exp $ */ +/* $Id: parse.c,v 1.47 2019/04/20 04:15:06 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2019 Ingo Schwarze @@ -56,6 +56,7 @@ struct parse { int nline; /* Line number of next token. */ int ncol; /* Column number of next token. */ int del; /* Levels of nested nodes being deleted. */ + int nofill; /* Levels of open no-fill displays. */ int flags; #define PFLAG_WARN (1 << 0) /* Print warning messages. */ #define PFLAG_SPC (1 << 1) /* Whitespace before the next element. */ @@ -70,25 +71,32 @@ struct alias { static const struct alias aliases[] = { { "acronym", NODE_IGNORE }, + { "affiliation", NODE_IGNORE }, { "anchor", NODE_DELETE }, { "application", NODE_COMMAND }, { "article", NODE_SECTION }, { "articleinfo", NODE_BOOKINFO }, { "book", NODE_SECTION }, { "chapter", NODE_SECTION }, + { "caption", NODE_IGNORE }, { "code", NODE_LITERAL }, { "computeroutput", NODE_LITERAL }, { "!doctype", NODE_DOCTYPE }, + { "figure", NODE_IGNORE }, { "firstname", NODE_PERSONNAME }, { "glossary", NODE_VARIABLELIST }, { "glossdef", NODE_IGNORE }, { "glossdiv", NODE_IGNORE }, { "glossentry", NODE_VARLISTENTRY }, { "glosslist", NODE_VARIABLELIST }, + { "holder", NODE_IGNORE }, + { "imageobject", NODE_IGNORE }, { "indexterm", NODE_DELETE }, { "informaltable", NODE_TABLE }, { "keycap", NODE_KEYSYM }, { "keycode", NODE_IGNORE }, + { "mediaobject", NODE_BLOCKQUOTE }, + { "orgname", NODE_IGNORE }, { "othercredit", NODE_AUTHOR }, { "othername", NODE_PERSONNAME }, { "part", NODE_SECTION }, @@ -99,10 +107,13 @@ static const struct alias aliases[] = { { "refsect2", NODE_SECTION }, { "refsect3", NODE_SECTION }, { "refsection", NODE_SECTION }, + { "releaseinfo", NODE_IGNORE }, { "returnvalue", NODE_IGNORE }, { "secondary", NODE_DELETE }, { "sect1", NODE_SECTION }, { "sect2", NODE_SECTION }, + { "sect3", NODE_SECTION }, + { "sect4", NODE_SECTION }, { "sgmltag", NODE_MARKUP }, { "simpara", NODE_PARA }, { "structfield", NODE_PARAMETER }, @@ -112,6 +123,7 @@ static const struct alias aliases[] = { { "trademark", NODE_IGNORE }, { "ulink", NODE_LINK }, { "userinput", NODE_LITERAL }, + { "year", NODE_IGNORE }, { NULL, NODE_IGNORE } }; @@ -275,6 +287,7 @@ xml_text(struct parse *p, const char *word, int sz) case CLASS_VOID: case CLASS_TEXT: case CLASS_BLOCK: + case CLASS_NOFILL: np = NULL; break; case CLASS_TRANS: @@ -516,6 +529,9 @@ xml_elem_start(struct parse *p, const char *name) case CLASS_ENCL: n->spc = (p->flags & PFLAG_SPC) != 0; break; + case CLASS_NOFILL: + p->nofill++; + /* FALLTHROUGH */ default: n->spc = 1; break; @@ -537,7 +553,7 @@ xml_attrkey(struct parse *p, const char *name) const char *value; enum attrkey key; - if (p->del > 0 || p->ncur == NODE_IGNORE || *name == '\0') + if (p->del > 0 || p->ncur >= NODE_UNKNOWN || *name == '\0') return; if ((p->ncur == NODE_DOCTYPE || p->ncur == NODE_ENTITY) && @@ -574,7 +590,7 @@ xml_attrval(struct parse *p, const char *name) { struct pattr *a; - if (p->del > 0 || p->ncur == NODE_IGNORE || + if (p->del > 0 || p->ncur >= NODE_UNKNOWN || (p->flags & PFLAG_ATTR) == 0) return; if ((a = TAILQ_LAST(&p->cur->attrq, pattrq)) == NULL) @@ -640,6 +656,8 @@ xml_elem_end(struct parse *p, const char *name) warn_msg(p, "element not open: ", name); break; } + if (pnode_class(node) == CLASS_NOFILL) + p->nofill--; /* * Refrain from actually closing the document element. @@ -747,11 +765,12 @@ parse_string(struct parse *p, char *b, size_t rlen, enum pstate *pstate, int refill) { char *cp; + size_t pws; /* Parse offset including whitespace. */ size_t poff; /* Parse offset in b[]. */ size_t pend; /* Offset of the end of the current word. */ int elem_end; - pend = 0; + pend = pws = 0; for (;;) { /* Proceed to the next token, skipping whitespace. */ @@ -764,6 +783,8 @@ parse_string(struct parse *p, char *b, size_t rlen, break; if (isspace((unsigned char)b[pend])) { p->flags |= PFLAG_SPC; + if (b[pend] == '\n') + pws = pend + 1; increment(p, b, &pend, refill); continue; } @@ -925,10 +946,13 @@ parse_string(struct parse *p, char *b, size_t rlen, advance(p, b, rlen, &pend, p->ncur == NODE_DOCTYPE ? "<&]\n" : "<&\n", refill); + if (p->nofill) + poff = pws; xml_text(p, b + poff, pend - poff); if (b[pend] == '\n') pnode_closetext(p, 0); } + pws = pend; } return poff; }