]> git.mdlowis.com Git - proto/labwc.git/commitdiff
menu: split parse_xml() in readiness for pipemenus
authorJohan Malm <jgm323@gmail.com>
Mon, 9 Oct 2023 19:43:43 +0000 (20:43 +0100)
committerJohan Malm <johanmalm@users.noreply.github.com>
Tue, 10 Oct 2023 05:13:55 +0000 (06:13 +0100)
src/menu/menu.c

index 5c7712f17dbddd18a68b33d915185be4471c7f7c..c51141c46d617b93278116edcdc9d9a4048ff07a 100644 (file)
@@ -524,26 +524,18 @@ xml_tree_walk(xmlNode *node, struct server *server)
        }
 }
 
+/*
+ * @stream can come from either of the following:
+ *   - fopen() in the case of reading a file such as menu.xml
+ *   - popen() when processing pipemenus
+ */
 static void
-parse_xml(const char *filename, struct server *server)
+parse(struct server *server, FILE *stream)
 {
-       FILE *stream;
        char *line = NULL;
        size_t len = 0;
        struct buf b;
-       static char menuxml[4096] = { 0 };
-
-       if (!rc.config_dir) {
-               return;
-       }
-       snprintf(menuxml, sizeof(menuxml), "%s/%s", rc.config_dir, filename);
 
-       stream = fopen(menuxml, "r");
-       if (!stream) {
-               wlr_log(WLR_ERROR, "cannot read %s", menuxml);
-               return;
-       }
-       wlr_log(WLR_INFO, "read menu file %s", menuxml);
        buf_init(&b);
        while (getline(&line, &len, stream) != -1) {
                char *p = strrchr(line, '\n');
@@ -553,7 +545,6 @@ parse_xml(const char *filename, struct server *server)
                buf_add(&b, line);
        }
        free(line);
-       fclose(stream);
        xmlDoc *d = xmlParseMemory(b.buf, b.len);
        if (!d) {
                wlr_log(WLR_ERROR, "xmlParseMemory()");
@@ -566,6 +557,26 @@ err:
        free(b.buf);
 }
 
+static void
+parse_xml(const char *filename, struct server *server)
+{
+       static char buf[4096] = { 0 };
+
+       if (!rc.config_dir) {
+               return;
+       }
+       snprintf(buf, sizeof(buf), "%s/%s", rc.config_dir, filename);
+
+       FILE *stream = fopen(buf, "r");
+       if (!stream) {
+               wlr_log(WLR_ERROR, "cannot read %s", buf);
+               return;
+       }
+       wlr_log(WLR_INFO, "read menu file %s", buf);
+       parse(server, stream);
+       fclose(stream);
+}
+
 static int
 menu_get_full_width(struct menu *menu)
 {