From 9eac349046050b21d6af8a4e9421f1422cc2a3b2 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Tue, 16 Feb 2021 21:04:49 +0000 Subject: [PATCH] rc.xml: move nodename() to nodename.c --- include/common/nodename.h | 19 +++++++++++++++++++ src/common/meson.build | 1 + src/common/nodename.c | 37 +++++++++++++++++++++++++++++++++++++ src/config/rcxml.c | 35 +---------------------------------- 4 files changed, 58 insertions(+), 34 deletions(-) create mode 100644 include/common/nodename.h create mode 100644 src/common/nodename.c diff --git a/include/common/nodename.h b/include/common/nodename.h new file mode 100644 index 00000000..a54694fa --- /dev/null +++ b/include/common/nodename.h @@ -0,0 +1,19 @@ +#ifndef __LABWC_NODENAME_H +#define __LABWC_NODENAME_H + +#include +#include +#include + +/** + * nodename - give xml node an ascii name + * @node: xml-node + * @buf: buffer to receive the name + * @len: size of buffer + * + * For example, the xml structure would return the + * name c.b.a + */ +char *nodename(xmlNode *node, char *buf, int len); + +#endif /* __LABWC_NODENAME_H */ diff --git a/src/common/meson.build b/src/common/meson.build index 962b2b94..3efd27b4 100644 --- a/src/common/meson.build +++ b/src/common/meson.build @@ -4,6 +4,7 @@ labwc_sources += files( 'font.c', 'grab-file.c', 'log.c', + 'nodename.c', 'spawn.c', 'string-helpers.c', ) diff --git a/src/common/nodename.c b/src/common/nodename.c new file mode 100644 index 00000000..315ae6e1 --- /dev/null +++ b/src/common/nodename.c @@ -0,0 +1,37 @@ +#include +#include +#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; + } + } +} diff --git a/src/config/rcxml.c b/src/config/rcxml.c index e390c8d0..835b24ae 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -14,6 +14,7 @@ #include "common/dir.h" #include "common/font.h" #include "common/log.h" +#include "common/nodename.h" #include "common/string-helpers.h" #include "config/keybind.h" #include "config/rcxml.h" @@ -146,40 +147,6 @@ entry(xmlNode *node, char *nodename, char *content) } } -static 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; - } - } -} - static void process_node(xmlNode *node) {