labwc/src/common/nodename.c
John Lindgren 31d42b50e2 src: include primary header first
This is a common practice in C projects, which simply enforces that
each header must compile cleanly without implicit dependencies on
other headers (see also the previous commit).
2025-07-29 21:51:56 +01:00

39 lines
670 B
C

// SPDX-License-Identifier: GPL-2.0-only
#include "common/nodename.h"
#include <ctype.h>
#include <string.h>
char *
nodename(xmlNode *node, char *buf, int len)
{
if (!node || !node->name) {
return NULL;
}
/* Ignore superfluous '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;
}
}
}