2021-11-13 21:56:53 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2021-02-16 21:04:49 +00:00
|
|
|
#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);
|
2022-01-09 05:48:27 +01:00
|
|
|
if (!--len) {
|
2021-02-16 21:04:49 +00:00
|
|
|
return buf;
|
2022-01-09 05:48:27 +01:00
|
|
|
}
|
2021-02-16 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
*p = 0;
|
|
|
|
|
node = node->parent;
|
|
|
|
|
if (!node || !node->name) {
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
*p++ = '.';
|
|
|
|
|
if (!--len) {
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|