WIP: devel : travail du mois de mars/avril #28

Draft
neox wants to merge 24 commits from devel into devel_orig
1 changed files with 16 additions and 16 deletions
Showing only changes of commit 6da0e65073 - Show all commits

View File

@ -58,26 +58,26 @@ void model_populate_hashtable (xmlNode *node,
// Skip text nodes and others that are not element nodes // Skip text nodes and others that are not element nodes
if (node->type != XML_ELEMENT_NODE) { if (node->type != XML_ELEMENT_NODE) {
model_populate_hashtable(node->next, hashTable, currentPath); model_populate_hashtable (node->next, hashTable, currentPath);
return; return;
} }
// Calculate new path // Calculate new path
char newPath[1024]; // large enough char newPath[1024]; // large enough
if (currentPath && strlen(currentPath) > 0) { if (currentPath && strlen(currentPath) > 0) {
snprintf(newPath, sizeof(newPath), "%s/%s", currentPath, node->name); snprintf (newPath, sizeof(newPath), "%s/%s", currentPath, node->name);
} else { } else {
snprintf(newPath, sizeof(newPath), "%s", node->name); // Root element snprintf (newPath, sizeof(newPath), "%s", node->name); // Root element
} }
// Add current node to hash table with its path as the key // Add current node to hash table with its path as the key
xmlHashAddEntry(hashTable, (const xmlChar *)newPath, node); xmlHashAddEntry (hashTable, (const xmlChar *)newPath, node);
// Recurse into child nodes with the updated path // Recurse into child nodes with the updated path
model_populate_hashtable(node->children, hashTable, newPath); model_populate_hashtable (node->children, hashTable, newPath);
// Continue with the next sibling // Continue with the next sibling
model_populate_hashtable(node->next, hashTable, currentPath); model_populate_hashtable (node->next, hashTable, currentPath);
} }
/* /*
@ -110,9 +110,9 @@ int model_modify_node (const char *path,
xmlNodePtr node = model_find_node_by_path(hashTable, path); xmlNodePtr node = model_find_node_by_path(hashTable, path);
if (node) { if (node) {
// Free the current content of the node, if any // Free the current content of the node, if any
xmlNodeSetContent(node, (const xmlChar *)""); // Clear existing content xmlNodeSetContent (node, (const xmlChar *)""); // Clear existing content
// Set new content // Set new content
xmlNodeSetContent(node, (const xmlChar *)newContent); xmlNodeSetContent (node, (const xmlChar *)newContent);
return 1; // Success return 1; // Success
} }
return 0; // Node not found or unable to modify return 0; // Node not found or unable to modify
@ -131,9 +131,9 @@ char* model_get_attribute (const char* nodePath,
{ {
assert(hashTable != NULL); assert(hashTable != NULL);
xmlNodePtr node = (xmlNodePtr)xmlHashLookup(hashTable, (const xmlChar*)nodePath); xmlNodePtr node = (xmlNodePtr)xmlHashLookup (hashTable, (const xmlChar*)nodePath);
if (node) { if (node) {
return getAttributeValue(node, attributeName); return getAttributeValue (node, attributeName);
} else { } else {
return NULL; return NULL;
} }
@ -154,9 +154,9 @@ int model_set_attribute (const char* nodePath,
{ {
assert(hashTable != NULL); assert(hashTable != NULL);
xmlNodePtr node = (xmlNodePtr)xmlHashLookup(hashTable, (const xmlChar*)nodePath); xmlNodePtr node = (xmlNodePtr)xmlHashLookup (hashTable, (const xmlChar*)nodePath);
if (node) { if (node) {
return setAttributeValue(node, attributeName, attributeValue); return setAttributeValue (node, attributeName, attributeValue);
} else { } else {
return 0; return 0;
} }
@ -188,17 +188,17 @@ xmlNodePtr model_copy_node(struct model_t *self,
} }
// Modify the specified attribute in the copied node // Modify the specified attribute in the copied node
xmlSetProp(copiedNode, (const xmlChar*)attributeName, (const xmlChar*)newAttributeValue); xmlSetProp (copiedNode, (const xmlChar*)attributeName, (const xmlChar*)newAttributeValue);
// Insert the copied node as the next sibling of the original node // Insert the copied node as the next sibling of the original node
xmlAddNextSibling(node, copiedNode); xmlAddNextSibling (node, copiedNode);
// Calculate the new node's path. // Calculate the new node's path.
char newPath[1024]; char newPath[1024];
snprintf(newPath, sizeof(newPath), "%s_copy", originalNodePath); snprintf (newPath, sizeof(newPath), "%s_copy", originalNodePath);
// Update the hashtable with the new node's path // Update the hashtable with the new node's path
xmlHashAddEntry(hashTable, (const xmlChar*)newPath, copiedNode); xmlHashAddEntry (hashTable, (const xmlChar*)newPath, copiedNode);
return copiedNode; return copiedNode;
} }