From: Johan Malm Date: Tue, 9 Jun 2020 21:01:19 +0000 (+0100) Subject: src/config/rcxml.c: optionally write nodenames to buffer X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=1f5d8c38120d68c8dc0abee9272723b3d1b1c422;p=proto%2Flabwc.git src/config/rcxml.c: optionally write nodenames to buffer --- diff --git a/include/rcxml.h b/include/rcxml.h index 5370a796..4e1d4b0c 100644 --- a/include/rcxml.h +++ b/include/rcxml.h @@ -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 */ diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 7caab18c..599b2069 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -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; } diff --git a/src/main.c b/src/main.c index 616b0bab..c2591bd8 100644 --- a/src/main.c +++ b/src/main.c @@ -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 */ diff --git a/tools/rcxml/rcxml-print-nodenames.c b/tools/rcxml/rcxml-print-nodenames.c index c47e2c72..b64d6158 100644 --- a/tools/rcxml/rcxml-print-nodenames.c +++ b/tools/rcxml/rcxml-print-nodenames.c @@ -3,16 +3,22 @@ #include #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 \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); }