Files
ModManager/src/fomod/xmlUtil.c
T
Marc b8affcadbc New naming conventions to avoid conflicts.
i don't know if it was such a great idea but at least it is a starting point.
2022-10-09 15:46:58 +02:00

73 lines
1.4 KiB
C

#include "xmlUtil.h"
#include <string.h>
#include <sys/types.h>
char * xml_freeAndDup(xmlChar * line) {
char * free = strdup((const char *) line);
xmlFree(line);
return free;
}
fomod_Order_t fomod_getOrder(const char * order) {
if(order == NULL || strcmp(order, "Ascending") == 0) {
return ASC;
} else if(strcmp(order, "Explicit") == 0) {
return ORD;
} else if(strcmp(order, "Descending") == 0) {
return DESC;
}
return -1;
}
//replace \ in the path by /
void xml_fixPath(char * path) {
while(*path != '\0') {
if(*path == '\\')*path = '/';
path++;
}
}
int fomod_countUntilNull(void * pointers, size_t typeSize) {
int i = 0;
char * arithmetic = (char *)pointers;
while(arithmetic != NULL) {
arithmetic += typeSize;
i++;
}
return i;
}
//names cannot contain false
//need to be null terminated
bool xml_validateNode(xmlNodePtr * node, bool skipText, const char * names, ...) {
va_list namesPtr;
while(*node != NULL && xmlStrcmp((*node)->name, (const xmlChar *)"text") == 0) {
if(skipText) {
(*node) = (*node)->next;
} else {
//could not skip and the node was a text node.
return false;
}
}
if(*node == NULL) {
return true;
}
va_start(namesPtr, names);
const char * validName = names;
while(validName != NULL) {
if(xmlStrcmp((*node)->name, (const xmlChar *)validName) == 0) {
va_end(namesPtr);
return true;
}
validName = va_arg(namesPtr, char *);
}
va_end(namesPtr);
return false;
}