MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCOLLADA / xmlShellGrep

Function xmlShellGrep

Externals/LibXML/debugXML.c:2190–2254  ·  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 informations about the node (namespace, attributes, content). * * Returns 0 */

Source from the content-addressed store, hash-verified

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

Callers 1

xmlShellFunction · 0.85

Calls 4

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

Tested by

no test coverage detected