rc.xml: move nodename() to nodename.c

This commit is contained in:
Johan Malm 2021-02-16 21:04:49 +00:00
parent a97428020e
commit 9eac349046
4 changed files with 58 additions and 34 deletions

37
src/common/nodename.c Normal file
View file

@ -0,0 +1,37 @@
#include <ctype.h>
#include <string.h>
#include "common/nodename.h"
char *
nodename(xmlNode *node, char *buf, int len)
{
if (!node || !node->name) {
return NULL;
}
/* Ignore superflous 'text.' in node name */
if (node->parent && !strcmp((char *)node->name, "text")) {
node = node->parent;
}
char *p = buf;
p[--len] = 0;
for (;;) {
const char *name = (char *)node->name;
char c;
while ((c = *name++) != 0) {
*p++ = tolower(c);
if (!--len)
return buf;
}
*p = 0;
node = node->parent;
if (!node || !node->name) {
return buf;
}
*p++ = '.';
if (!--len) {
return buf;
}
}
}