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

Function xmlShellDu

ThirdParty/libxml2/vtklibxml2/debugXML.c:2670–2739  ·  view source on GitHub ↗

* xmlShellDu: * @ctxt: the shell context * @arg: unused * @tree: a node defining a subtree * @node2: unused * * Implements the XML shell function "du" * show the structure of the subtree under node @tree * If @tree is null, the command works on the current node. * * Returns 0 or -1 in case of error */

Source from the content-addressed store, hash-verified

2668 * Returns 0 or -1 in case of error
2669 */
2670int
2671xmlShellDu(xmlShellCtxtPtr ctxt,
2672 char *arg ATTRIBUTE_UNUSED, xmlNodePtr tree,
2673 xmlNodePtr node2 ATTRIBUTE_UNUSED)
2674{
2675 xmlNodePtr node;
2676 int indent = 0, i;
2677
2678 if (!ctxt)
2679 return (-1);
2680
2681 if (tree == NULL)
2682 return (-1);
2683 node = tree;
2684 while (node != NULL) {
2685 if ((node->type == XML_DOCUMENT_NODE) ||
2686 (node->type == XML_HTML_DOCUMENT_NODE)) {
2687 fprintf(ctxt->output, "/\n");
2688 } else if (node->type == XML_ELEMENT_NODE) {
2689 for (i = 0; i < indent; i++)
2690 fprintf(ctxt->output, " ");
2691 if ((node->ns) && (node->ns->prefix))
2692 fprintf(ctxt->output, "%s:", node->ns->prefix);
2693 fprintf(ctxt->output, "%s\n", node->name);
2694 } else {
2695 }
2696
2697 /*
2698 * Browse the full subtree, deep first
2699 */
2700
2701 if ((node->type == XML_DOCUMENT_NODE) ||
2702 (node->type == XML_HTML_DOCUMENT_NODE)) {
2703 node = ((xmlDocPtr) node)->children;
2704 } else if ((node->children != NULL)
2705 && (node->type != XML_ENTITY_REF_NODE)) {
2706 /* deep first */
2707 node = node->children;
2708 indent++;
2709 } else if ((node != tree) && (node->next != NULL)) {
2710 /* then siblings */
2711 node = node->next;
2712 } else if (node != tree) {
2713 /* go up to parents->next if needed */
2714 while (node != tree) {
2715 if (node->parent != NULL) {
2716 node = node->parent;
2717 indent--;
2718 }
2719 if ((node != tree) && (node->next != NULL)) {
2720 node = node->next;
2721 break;
2722 }
2723 if (node->parent == NULL) {
2724 node = NULL;
2725 break;
2726 }
2727 if (node == tree) {

Callers 1

xmlShellFunction · 0.85

Calls 1

fprintfFunction · 0.85

Tested by

no test coverage detected