Skip to content

Commit bb7e525

Browse files
committed
xml: move code to xml_init() to keep main.c clean
1 parent 092b108 commit bb7e525

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

main.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,6 @@ activate(GtkApplication *app, gpointer user_data)
5454
gtk_widget_show_all(state->window);
5555
}
5656

57-
static const char rcxml_template[] =
58-
"<?xml version=\"1.0\"?>\n"
59-
"<labwc_config>\n"
60-
" <core>\n"
61-
" </core>\n"
62-
"</labwc_config>\n";
63-
64-
static void
65-
create_basic_rcxml(const char *filename)
66-
{
67-
FILE *file = fopen(filename, "w");
68-
if (!file) {
69-
fprintf(stderr, "warn: fopen(%s) failed\n", filename);
70-
return;
71-
}
72-
if (!fwrite(rcxml_template, sizeof(rcxml_template), 1, file)) {
73-
fprintf(stderr, "warn: error writing to %s", filename);
74-
}
75-
fclose(file);
76-
}
77-
7857
int
7958
main(int argc, char **argv)
8059
{
@@ -84,17 +63,8 @@ main(int argc, char **argv)
8463
char filename[4096];
8564
char *home = getenv("HOME");
8665
snprintf(filename, sizeof(filename), "%s/%s", home, ".config/labwc/rc.xml");
87-
if (access(filename, F_OK)) {
88-
create_basic_rcxml(filename);
89-
}
9066
xml_init(filename);
9167

92-
/* ensure all relevant nodes exist before we start getting/setting */
93-
xpath_add_node("/labwc_config/theme/cornerRadius");
94-
xpath_add_node("/labwc_config/theme/name");
95-
xpath_add_node("/labwc_config/libinput/device/naturalScroll");
96-
xml_save();
97-
9868
/* connect to gsettings */
9969
state.settings = g_settings_new("org.gnome.desktop.interface");
10070

xml.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <string.h>
1414
#include <strings.h>
1515
#include <unistd.h>
16+
#include "xml.h"
1617

1718
static struct ctx {
1819
char *filename;
@@ -120,11 +121,36 @@ xml_tree_walk(xmlNode *node)
120121
}
121122
}
122123

124+
static const char rcxml_template[] =
125+
"<?xml version=\"1.0\"?>\n"
126+
"<labwc_config>\n"
127+
" <core>\n"
128+
" </core>\n"
129+
"</labwc_config>\n";
130+
131+
static void
132+
create_basic_rcxml(const char *filename)
133+
{
134+
FILE *file = fopen(filename, "w");
135+
if (!file) {
136+
fprintf(stderr, "warn: fopen(%s) failed\n", filename);
137+
return;
138+
}
139+
if (!fwrite(rcxml_template, sizeof(rcxml_template), 1, file)) {
140+
fprintf(stderr, "warn: error writing to %s", filename);
141+
}
142+
fclose(file);
143+
}
144+
123145
void
124146
xml_init(const char *filename)
125147
{
126148
LIBXML_TEST_VERSION
127149

150+
if (access(filename, F_OK)) {
151+
create_basic_rcxml(filename);
152+
}
153+
128154
/* Use XML_PARSE_NOBLANKS for xmlSaveFormatFile() to indent properly */
129155
ctx.filename = strdup(filename);
130156
ctx.doc = xmlReadFile(filename, NULL, XML_PARSE_NOBLANKS);
@@ -136,6 +162,12 @@ xml_init(const char *filename)
136162
fprintf(stderr, "warn: xmlXPathNewContext()\n");
137163
xmlFreeDoc(ctx.doc);
138164
}
165+
166+
/* Ensure all relevant nodes exist before we start getting/setting */
167+
xpath_add_node("/labwc_config/theme/cornerRadius");
168+
xpath_add_node("/labwc_config/theme/name");
169+
xpath_add_node("/labwc_config/libinput/device/naturalScroll");
170+
xml_save();
139171
}
140172

141173
void

0 commit comments

Comments
 (0)