mirror of
https://github.com/labwc/labwc.git
synced 2026-03-15 05:33:53 -04:00
menu: split parse_xml() in readiness for pipemenus
This commit is contained in:
parent
ecad76560e
commit
c827c4c9e5
1 changed files with 26 additions and 15 deletions
|
|
@ -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
|
static void
|
||||||
parse_xml(const char *filename, struct server *server)
|
parse(struct server *server, FILE *stream)
|
||||||
{
|
{
|
||||||
FILE *stream;
|
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
struct buf b;
|
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);
|
buf_init(&b);
|
||||||
while (getline(&line, &len, stream) != -1) {
|
while (getline(&line, &len, stream) != -1) {
|
||||||
char *p = strrchr(line, '\n');
|
char *p = strrchr(line, '\n');
|
||||||
|
|
@ -553,7 +545,6 @@ parse_xml(const char *filename, struct server *server)
|
||||||
buf_add(&b, line);
|
buf_add(&b, line);
|
||||||
}
|
}
|
||||||
free(line);
|
free(line);
|
||||||
fclose(stream);
|
|
||||||
xmlDoc *d = xmlParseMemory(b.buf, b.len);
|
xmlDoc *d = xmlParseMemory(b.buf, b.len);
|
||||||
if (!d) {
|
if (!d) {
|
||||||
wlr_log(WLR_ERROR, "xmlParseMemory()");
|
wlr_log(WLR_ERROR, "xmlParseMemory()");
|
||||||
|
|
@ -566,6 +557,26 @@ err:
|
||||||
free(b.buf);
|
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
|
static int
|
||||||
menu_get_full_width(struct menu *menu)
|
menu_get_full_width(struct menu *menu)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue