MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlShellGrep

Function xmlShellGrep

ThirdParty/libxml2/vtklibxml2/debugXML.c:2179–2243  ·  view source on GitHub ↗

* xmlShellGrep: * @ctxt: the shell context * @arg: the string or regular expression to find * @node: a node * @node2: unused * * Implements the XML shell function "grep" * dumps information about the node (namespace, attributes, content). * * Returns 0 */

Source from the content-addressed store, hash-verified

2177 * Returns 0
2178 */
2179static int
2180xmlShellGrep(xmlShellCtxtPtr ctxt ATTRIBUTE_UNUSED,
2181 char *arg, xmlNodePtr node, xmlNodePtr node2 ATTRIBUTE_UNUSED)
2182{
2183 if (!ctxt)
2184 return (0);
2185 if (node == NULL)
2186 return (0);
2187 if (arg == NULL)
2188 return (0);
2189#ifdef LIBXML_REGEXP_ENABLED
2190 if ((xmlStrchr((xmlChar *) arg, '?')) ||
2191 (xmlStrchr((xmlChar *) arg, '*')) ||
2192 (xmlStrchr((xmlChar *) arg, '.')) ||
2193 (xmlStrchr((xmlChar *) arg, '['))) {
2194 }
2195#endif
2196 while (node != NULL) {
2197 if (node->type == XML_COMMENT_NODE) {
2198 if (xmlStrstr(node->content, (xmlChar *) arg)) {
2199
2200 fprintf(ctxt->output, "%s : ", xmlGetNodePath(node));
2201 xmlShellList(ctxt, NULL, node, NULL);
2202 }
2203 } else if (node->type == XML_TEXT_NODE) {
2204 if (xmlStrstr(node->content, (xmlChar *) arg)) {
2205
2206 fprintf(ctxt->output, "%s : ", xmlGetNodePath(node->parent));
2207 xmlShellList(ctxt, NULL, node->parent, NULL);
2208 }
2209 }
2210
2211 /*
2212 * Browse the full subtree, deep first
2213 */
2214
2215 if ((node->type == XML_DOCUMENT_NODE) ||
2216 (node->type == XML_HTML_DOCUMENT_NODE)) {
2217 node = ((xmlDocPtr) node)->children;
2218 } else if ((node->children != NULL)
2219 && (node->type != XML_ENTITY_REF_NODE)) {
2220 /* deep first */
2221 node = node->children;
2222 } else if (node->next != NULL) {
2223 /* then siblings */
2224 node = node->next;
2225 } else {
2226 /* go up to parents->next if needed */
2227 while (node != NULL) {
2228 if (node->parent != NULL) {
2229 node = node->parent;
2230 }
2231 if (node->next != NULL) {
2232 node = node->next;
2233 break;
2234 }
2235 if (node->parent == NULL) {
2236 node = NULL;

Callers 1

xmlShellFunction · 0.85

Calls 5

xmlStrchrFunction · 0.85
xmlStrstrFunction · 0.85
fprintfFunction · 0.85
xmlGetNodePathFunction · 0.85
xmlShellListFunction · 0.85

Tested by

no test coverage detected