]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/config/rcxml.c: optionally write nodenames to buffer
authorJohan Malm <jgm323@gmail.com>
Tue, 9 Jun 2020 21:01:19 +0000 (22:01 +0100)
committerJohan Malm <jgm323@gmail.com>
Tue, 9 Jun 2020 21:01:19 +0000 (22:01 +0100)
include/rcxml.h
src/config/rcxml.c
src/main.c
tools/rcxml/rcxml-print-nodenames.c

index 5370a7968a61e5f2e4d469c3267aa577a050b152..4e1d4b0ca98a54def4063c7caa77347d2f49d9e5 100644 (file)
@@ -15,6 +15,6 @@ extern struct rcxml rc;
 void rcxml_init(struct rcxml *rc);
 void rcxml_parse_xml(struct buf *b);
 void rcxml_read(const char *filename);
-void rcxml_set_verbose(void);
+void rcxml_get_nodenames(struct buf *b);
 
 #endif /* RCXML_H */
index 7caab18cddb3f68e901462fe2fe03aa6ac461f08..599b206937e05abd1bdc5a9ddd65f021c503ad10 100644 (file)
@@ -13,7 +13,8 @@
 
 static bool in_keybind = false;
 static bool is_attribute = false;
-static bool verbose = false;
+static bool write_to_nodename_buffer = false;
+static struct buf *nodename_buffer;
 
 static void rstrip(char *buf, const char *pattern)
 {
@@ -47,10 +48,13 @@ static void entry(xmlNode *node, char *nodename, char *content)
        if (!nodename)
                return;
        rstrip(nodename, ".openbox_config");
-       if (verbose) {
+       if (write_to_nodename_buffer) {
                if (is_attribute)
-                       printf("@");
-               printf("%s: %s\n", nodename, content);
+                       buf_add(nodename_buffer, "@");
+               buf_add(nodename_buffer, nodename);
+               buf_add(nodename_buffer, ": ");
+               buf_add(nodename_buffer, content);
+               buf_add(nodename_buffer, "\n");
        }
        if (!content)
                return;
@@ -188,7 +192,8 @@ void rcxml_read(const char *filename)
        free(b.buf);
 }
 
-void rcxml_set_verbose(void)
+void rcxml_get_nodenames(struct buf *b)
 {
-       verbose = true;
+       write_to_nodename_buffer = true;
+       nodename_buffer = b;
 }
index 616b0babcc54fde53ce0def6e80ddc234e08adb0..c2591bd8295b94d84cafd788e6755e69d9cba9e0 100644 (file)
@@ -26,7 +26,6 @@ int main(int argc, char *argv[])
        }
 
        rcxml_init(&rc);
-       rcxml_set_verbose();
        rcxml_read("data/rc.xml");
 
        /* Wayland requires XDG_RUNTIME_DIR to be set */
index c47e2c72778e2e5693be5586c5e56df35d0d83b1..b64d6158f2aba75f3c96530d067816a5c907c85f 100644 (file)
@@ -3,16 +3,22 @@
 #include <unistd.h>
 
 #include "rcxml.h"
+#include "buf.h"
 
 struct rcxml rc = { 0 };
 
 int main(int argc, char **argv)
 {
+       struct buf b;
+
        if (argc != 2) {
                fprintf(stderr, "usage: %s <rc.xml file>\n", argv[0]);
                exit(EXIT_FAILURE);
        }
+       buf_init(&b);
        rcxml_init(&rc);
-       rcxml_set_verbose();
+       rcxml_get_nodenames(&b);
        rcxml_read(argv[1]);
+       printf("%s", b.buf);
+       free(b.buf);
 }