version 1.3, 2019/03/26 21:52:09 |
version 1.4, 2019/03/26 22:39:33 |
|
|
const char *fname; /* Name of the input file. */ |
const char *fname; /* Name of the input file. */ |
struct ptree *tree; /* Complete parse result. */ |
struct ptree *tree; /* Complete parse result. */ |
struct pnode *cur; /* Current node in the tree. */ |
struct pnode *cur; /* Current node in the tree. */ |
|
int del; /* Levels of nested nodes being deleted. */ |
int warn; |
int warn; |
}; |
}; |
|
|
|
|
static const struct element elements[] = { |
static const struct element elements[] = { |
{ "acronym", NODE_IGNORE }, |
{ "acronym", NODE_IGNORE }, |
{ "affiliation", NODE_AFFILIATION }, |
{ "affiliation", NODE_AFFILIATION }, |
{ "anchor", NODE_IGNORE }, |
{ "anchor", NODE_DELETE }, |
{ "application", NODE_APPLICATION }, |
{ "application", NODE_APPLICATION }, |
{ "arg", NODE_ARG }, |
{ "arg", NODE_ARG }, |
{ "author", NODE_AUTHOR }, |
{ "author", NODE_AUTHOR }, |
Line 87 static const struct element elements[] = { |
|
Line 88 static const struct element elements[] = { |
|
{ "group", NODE_GROUP }, |
{ "group", NODE_GROUP }, |
{ "holder", NODE_HOLDER }, |
{ "holder", NODE_HOLDER }, |
{ "index", NODE_INDEX }, |
{ "index", NODE_INDEX }, |
{ "indexterm", NODE_INDEXTERM }, |
{ "indexterm", NODE_DELETE }, |
{ "info", NODE_INFO }, |
{ "info", NODE_INFO }, |
{ "informalequation", NODE_INFORMALEQUATION }, |
{ "informalequation", NODE_INFORMALEQUATION }, |
{ "informaltable", NODE_INFORMALTABLE }, |
{ "informaltable", NODE_INFORMALTABLE }, |
Line 123 static const struct element elements[] = { |
|
Line 124 static const struct element elements[] = { |
|
{ "personname", NODE_PERSONNAME }, |
{ "personname", NODE_PERSONNAME }, |
{ "phrase", NODE_IGNORE }, |
{ "phrase", NODE_IGNORE }, |
{ "preface", NODE_PREFACE }, |
{ "preface", NODE_PREFACE }, |
{ "primary", NODE_PRIMARY }, |
{ "primary", NODE_DELETE }, |
{ "programlisting", NODE_PROGRAMLISTING }, |
{ "programlisting", NODE_PROGRAMLISTING }, |
{ "prompt", NODE_PROMPT }, |
{ "prompt", NODE_PROMPT }, |
{ "quote", NODE_QUOTE }, |
{ "quote", NODE_QUOTE }, |
Line 148 static const struct element elements[] = { |
|
Line 149 static const struct element elements[] = { |
|
{ "row", NODE_ROW }, |
{ "row", NODE_ROW }, |
{ "sbr", NODE_SBR }, |
{ "sbr", NODE_SBR }, |
{ "screen", NODE_SCREEN }, |
{ "screen", NODE_SCREEN }, |
{ "secondary", NODE_SECONDARY }, |
{ "secondary", NODE_DELETE }, |
{ "sect1", NODE_SECTION }, |
{ "sect1", NODE_SECTION }, |
{ "sect2", NODE_SECTION }, |
{ "sect2", NODE_SECTION }, |
{ "section", NODE_SECTION }, |
{ "section", NODE_SECTION }, |
Line 176 static const struct element elements[] = { |
|
Line 177 static const struct element elements[] = { |
|
{ "varname", NODE_VARNAME }, |
{ "varname", NODE_VARNAME }, |
{ "warning", NODE_WARNING }, |
{ "warning", NODE_WARNING }, |
{ "wordasword", NODE_WORDASWORD }, |
{ "wordasword", NODE_WORDASWORD }, |
{ "xi:include", NODE_WARN }, |
{ "xi:include", NODE_DELETE_WARN }, |
{ "year", NODE_YEAR }, |
{ "year", NODE_YEAR }, |
{ NULL, NODE__MAX } |
{ NULL, NODE__MAX } |
}; |
}; |
Line 194 xml_char(void *arg, const XML_Char *p, int sz) |
|
Line 195 xml_char(void *arg, const XML_Char *p, int sz) |
|
int i; |
int i; |
|
|
ps = arg; |
ps = arg; |
if (ps->tree->flags && TREE_FAIL) |
if (ps->del > 0 || ps->tree->flags & TREE_FAIL) |
return; |
return; |
|
|
/* |
/* |
Line 260 xml_elem_start(void *arg, const XML_Char *name, const |
|
Line 261 xml_elem_start(void *arg, const XML_Char *name, const |
|
const XML_Char **att; |
const XML_Char **att; |
|
|
ps = arg; |
ps = arg; |
if (ps->tree->flags && TREE_FAIL) |
if (ps->tree->flags & TREE_FAIL) |
return; |
return; |
|
|
|
/* |
|
* An ancestor is excluded from the tree; |
|
* keep track of the number of levels excluded. |
|
*/ |
|
if (ps->del > 0) { |
|
ps->del++; |
|
return; |
|
} |
|
|
/* Close out the text node, if there is one. */ |
/* Close out the text node, if there is one. */ |
if (ps->cur != NULL && ps->cur->node == NODE_TEXT) { |
if (ps->cur != NULL && ps->cur->node == NODE_TEXT) { |
pnode_trim(ps->cur); |
pnode_trim(ps->cur); |
Line 282 xml_elem_start(void *arg, const XML_Char *name, const |
|
Line 292 xml_elem_start(void *arg, const XML_Char *name, const |
|
} |
} |
|
|
switch (elem->node) { |
switch (elem->node) { |
case NODE_WARN: |
case NODE_DELETE_WARN: |
if (ps->warn) |
if (ps->warn) |
fprintf(stderr, "%s:%zu:%zu: warning: " |
fprintf(stderr, "%s:%zu:%zu: warning: " |
"ignoring element <%s>\n", ps->fname, |
"skipping element <%s>\n", ps->fname, |
XML_GetCurrentLineNumber(ps->xml), |
XML_GetCurrentLineNumber(ps->xml), |
XML_GetCurrentColumnNumber(ps->xml), name); |
XML_GetCurrentColumnNumber(ps->xml), name); |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
|
case NODE_DELETE: |
|
ps->del = 1; |
|
/* FALLTHROUGH */ |
case NODE_IGNORE: |
case NODE_IGNORE: |
return; |
return; |
case NODE_INLINEEQUATION: |
case NODE_INLINEEQUATION: |
Line 347 xml_elem_end(void *arg, const XML_Char *name) |
|
Line 360 xml_elem_end(void *arg, const XML_Char *name) |
|
const struct element *elem; |
const struct element *elem; |
|
|
ps = arg; |
ps = arg; |
if (ps->tree->flags && TREE_FAIL) |
if (ps->tree->flags & TREE_FAIL) |
return; |
return; |
|
|
|
/* |
|
* An ancestor is excluded from the tree; |
|
* keep track of the number of levels excluded. |
|
*/ |
|
if (ps->del > 1) { |
|
ps->del--; |
|
return; |
|
} |
|
|
/* Close out the text node, if there is one. */ |
/* Close out the text node, if there is one. */ |
if (ps->cur->node == NODE_TEXT) { |
if (ps->del == 0 && ps->cur->node == NODE_TEXT) { |
pnode_trim(ps->cur); |
pnode_trim(ps->cur); |
ps->cur = ps->cur->parent; |
ps->cur = ps->cur->parent; |
} |
} |
Line 361 xml_elem_end(void *arg, const XML_Char *name) |
|
Line 383 xml_elem_end(void *arg, const XML_Char *name) |
|
break; |
break; |
|
|
switch (elem->node) { |
switch (elem->node) { |
|
case NODE_DELETE_WARN: |
|
case NODE_DELETE: |
|
ps->del--; |
|
break; |
case NODE_IGNORE: |
case NODE_IGNORE: |
case NODE_WARN: |
|
break; |
break; |
default: |
default: |
assert(elem->node == ps->cur->node); |
assert(elem->node == ps->cur->node); |
ps->cur = ps->cur->parent; |
ps->cur = ps->cur->parent; |
|
break; |
} |
} |
|
assert(ps->del == 0); |
} |
} |
|
|
struct parse * |
struct parse * |