📄 mxml-node.c
字号:
if (!name) return (NULL); /* * Create the node and set the element name... */ if ((node = mxml_new(parent, MXML_ELEMENT)) != NULL) node->value.element.name = strdup(name); return (node);}/* * 'mxmlNewInteger()' - Create a new integer node. * * The new integer node is added to the end of the specified parent's child * list. The constant MXML_NO_PARENT can be used to specify that the new * integer node has no parent. */mxml_node_t * /* O - New node */mxmlNewInteger(mxml_node_t *parent, /* I - Parent node or MXML_NO_PARENT */ int integer) /* I - Integer value */{ mxml_node_t *node; /* New node */#ifdef DEBUG fprintf(stderr, "mxmlNewInteger(parent=%p, integer=%d)\n", parent, integer);#endif /* DEBUG */ /* * Create the node and set the element name... */ if ((node = mxml_new(parent, MXML_INTEGER)) != NULL) node->value.integer = integer; return (node);}/* * 'mxmlNewOpaque()' - Create a new opaque string. * * The new opaque node is added to the end of the specified parent's child * list. The constant MXML_NO_PARENT can be used to specify that the new * opaque node has no parent. The opaque string must be nul-terminated and * is copied into the new node. */mxml_node_t * /* O - New node */mxmlNewOpaque(mxml_node_t *parent, /* I - Parent node or MXML_NO_PARENT */ const char *opaque) /* I - Opaque string */{ mxml_node_t *node; /* New node */#ifdef DEBUG fprintf(stderr, "mxmlNewOpaque(parent=%p, opaque=\"%s\")\n", parent, opaque ? opaque : "(null)");#endif /* DEBUG */ /* * Range check input... */ if (!opaque) return (NULL); /* * Create the node and set the element name... */ if ((node = mxml_new(parent, MXML_OPAQUE)) != NULL) node->value.opaque = strdup(opaque); return (node);}/* * 'mxmlNewReal()' - Create a new real number node. * * The new real number node is added to the end of the specified parent's * child list. The constant MXML_NO_PARENT can be used to specify that * the new real number node has no parent. */mxml_node_t * /* O - New node */mxmlNewReal(mxml_node_t *parent, /* I - Parent node or MXML_NO_PARENT */ double real) /* I - Real number value */{ mxml_node_t *node; /* New node */#ifdef DEBUG fprintf(stderr, "mxmlNewReal(parent=%p, real=%g)\n", parent, real);#endif /* DEBUG */ /* * Create the node and set the element name... */ if ((node = mxml_new(parent, MXML_REAL)) != NULL) node->value.real = real; return (node);}/* * 'mxmlNewText()' - Create a new text fragment node. * * The new text node is added to the end of the specified parent's child * list. The constant MXML_NO_PARENT can be used to specify that the new * text node has no parent. The whitespace parameter is used to specify * whether leading whitespace is present before the node. The text * string must be nul-terminated and is copied into the new node. */mxml_node_t * /* O - New node */mxmlNewText(mxml_node_t *parent, /* I - Parent node or MXML_NO_PARENT */ int whitespace, /* I - 1 = leading whitespace, 0 = no whitespace */ const char *string) /* I - String */{ mxml_node_t *node; /* New node */#ifdef DEBUG fprintf(stderr, "mxmlNewText(parent=%p, whitespace=%d, string=\"%s\")\n", parent, whitespace, string ? string : "(null)");#endif /* DEBUG */ /* * Range check input... */ if (!string) return (NULL); /* * Create the node and set the text value... */ if ((node = mxml_new(parent, MXML_TEXT)) != NULL) { node->value.text.whitespace = whitespace; node->value.text.string = strdup(string); } return (node);}/* * 'mxmlNewTextf()' - Create a new formatted text fragment node. * * The new text node is added to the end of the specified parent's child * list. The constant MXML_NO_PARENT can be used to specify that the new * text node has no parent. The whitespace parameter is used to specify * whether leading whitespace is present before the node. The format * string must be nul-terminated and is formatted into the new node. */mxml_node_t * /* O - New node */mxmlNewTextf(mxml_node_t *parent, /* I - Parent node or MXML_NO_PARENT */ int whitespace, /* I - 1 = leading whitespace, 0 = no whitespace */ const char *format, /* I - Printf-style frmat string */ ...) /* I - Additional args as needed */{ mxml_node_t *node; /* New node */ va_list ap; /* Pointer to arguments */#ifdef DEBUG fprintf(stderr, "mxmlNewTextf(parent=%p, whitespace=%d, format=\"%s\", ...)\n", parent, whitespace, format ? format : "(null)");#endif /* DEBUG */ /* * Range check input... */ if (!format) return (NULL); /* * Create the node and set the text value... */ if ((node = mxml_new(parent, MXML_TEXT)) != NULL) { va_start(ap, format); node->value.text.whitespace = whitespace; node->value.text.string = mxml_strdupf(format, ap); va_end(ap); } return (node);}/* * 'mxmlRemove()' - Remove a node from its parent. * * Does not free memory used by the node - use mxmlDelete() for that. * This function does nothing if the node has no parent. */voidmxmlRemove(mxml_node_t *node) /* I - Node to remove */{#ifdef DEBUG fprintf(stderr, "mxmlRemove(node=%p)\n", node);#endif /* DEBUG */ /* * Range check input... */ if (!node || !node->parent) return; /* * Remove from parent... */#if DEBUG > 1 fprintf(stderr, " BEFORE: node->parent=%p\n", node->parent); if (node->parent) { fprintf(stderr, " BEFORE: node->parent->child=%p\n", node->parent->child); fprintf(stderr, " BEFORE: node->parent->last_child=%p\n", node->parent->last_child); } fprintf(stderr, " BEFORE: node->child=%p\n", node->child); fprintf(stderr, " BEFORE: node->last_child=%p\n", node->last_child); fprintf(stderr, " BEFORE: node->prev=%p\n", node->prev); fprintf(stderr, " BEFORE: node->next=%p\n", node->next);#endif /* DEBUG > 1 */ if (node->prev) node->prev->next = node->next; else node->parent->child = node->next; if (node->next) node->next->prev = node->prev; else node->parent->last_child = node->prev; node->parent = NULL; node->prev = NULL; node->next = NULL;#if DEBUG > 1 fprintf(stderr, " AFTER: node->parent=%p\n", node->parent); if (node->parent) { fprintf(stderr, " AFTER: node->parent->child=%p\n", node->parent->child); fprintf(stderr, " AFTER: node->parent->last_child=%p\n", node->parent->last_child); } fprintf(stderr, " AFTER: node->child=%p\n", node->child); fprintf(stderr, " AFTER: node->last_child=%p\n", node->last_child); fprintf(stderr, " AFTER: node->prev=%p\n", node->prev); fprintf(stderr, " AFTER: node->next=%p\n", node->next);#endif /* DEBUG > 1 */}/* * 'mxml_new()' - Create a new node. */static mxml_node_t * /* O - New node */mxml_new(mxml_node_t *parent, /* I - Parent node */ mxml_type_t type) /* I - Node type */{ mxml_node_t *node; /* New node */#if DEBUG > 1 fprintf(stderr, "mxml_new(parent=%p, type=%d)\n", parent, type);#endif /* DEBUG > 1 */ /* * Allocate memory for the node... */ if ((node = calloc(1, sizeof(mxml_node_t))) == NULL) {#if DEBUG > 1 fputs(" returning NULL\n", stderr);#endif /* DEBUG > 1 */ return (NULL); }#if DEBUG > 1 fprintf(stderr, " returning %p\n", node);#endif /* DEBUG > 1 */ /* * Set the node type... */ node->type = type; /* * Add to the parent if present... */ if (parent) mxmlAdd(parent, MXML_ADD_AFTER, MXML_ADD_TO_PARENT, node); /* * Return the new node... */ return (node);}/* * End of "$Id: mxml-node.c 22267 2006-04-24 17:11:45Z kpfleming $". */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -