]> git.mdlowis.com Git - proto/labwc.git/commitdiff
rc.xml: move nodename() to nodename.c
authorJohan Malm <jgm323@gmail.com>
Tue, 16 Feb 2021 21:04:49 +0000 (21:04 +0000)
committerJohan Malm <jgm323@gmail.com>
Tue, 16 Feb 2021 21:04:49 +0000 (21:04 +0000)
include/common/nodename.h [new file with mode: 0644]
src/common/meson.build
src/common/nodename.c [new file with mode: 0644]
src/config/rcxml.c

diff --git a/include/common/nodename.h b/include/common/nodename.h
new file mode 100644 (file)
index 0000000..a54694f
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef __LABWC_NODENAME_H
+#define __LABWC_NODENAME_H
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <stdio.h>
+
+/**
+ * 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 <a><b><c></c></b></a> would return the
+ * name c.b.a
+ */
+char *nodename(xmlNode *node, char *buf, int len);
+
+#endif /* __LABWC_NODENAME_H */
index 962b2b94c9dc3624444c81a9b782926e3fb75a11..3efd27b41bf9ea4b63420704fa7f926bcbcf2c9d 100644 (file)
@@ -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 (file)
index 0000000..315ae6e
--- /dev/null
@@ -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;
+               }
+       }
+}
index e390c8d090eb9b6b0c0fd4ffc3143841797d88ae..835b24aecdb5e15497106746062fa2d1e3a62ecf 100644 (file)
@@ -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)
 {