Improve log messages for reading config+theme

This commit is contained in:
Johan Malm 2020-09-14 18:17:36 +01:00
parent 35015e57c6
commit 4a89fbfb22
4 changed files with 26 additions and 18 deletions

View file

@ -103,8 +103,7 @@ char *find_dir(struct ctx *ctx)
}
}
/* no directory was found */
ctx->buf[0] = '.';
ctx->buf[1] = '\0';
ctx->buf[0] = '\0';
return ctx->buf;
}

View file

@ -23,7 +23,7 @@ void warn(const char *err, ...)
{
va_list params;
fprintf(stderr, LABWC_COLOR_RED);
fprintf(stderr, "[labwc] warning: ");
fprintf(stderr, "[labwc] ");
va_start(params, err);
vfprintf(stderr, err, params);
va_end(params);

View file

@ -260,11 +260,10 @@ static void post_processing(void)
set_title_height();
}
static void rcxml_path(char *buf, size_t len, const char *filename)
static void rcxml_path(char *buf, size_t len)
{
if (filename)
snprintf(buf, len, "%s", filename);
else
if (!strlen(config_dir()))
return;
snprintf(buf, len, "%s/rc.xml", config_dir());
}
@ -274,7 +273,7 @@ void rcxml_read(const char *filename)
char *line = NULL;
size_t len = 0;
struct buf b;
char rcxml[4096];
char rcxml[4096] = { 0 };
rcxml_init();
wl_list_init(&rc.keybinds);
@ -283,13 +282,20 @@ void rcxml_read(const char *filename)
* Reading file into buffer before parsing makes it easier to write
* unit tests.
*/
rcxml_path(rcxml, sizeof(rcxml), filename);
info("reading config file (%s)", rcxml);
if (filename)
snprintf(rcxml, sizeof(rcxml), "%s", filename);
else
rcxml_path(rcxml, sizeof(rcxml));
if (rcxml[0] == '\0') {
warn("cannot find rc.xml config file");
goto no_config;
}
stream = fopen(rcxml, "r");
if (!stream) {
warn("cannot read (%s)", rcxml);
goto out;
goto no_config;
}
info("reading config file (%s)", rcxml);
buf_init(&b);
while (getline(&line, &len, stream) != -1) {
char *p = strrchr(line, '\n');
@ -301,7 +307,7 @@ void rcxml_read(const char *filename)
fclose(stream);
rcxml_parse_xml(&b);
free(b.buf);
out:
no_config:
post_processing();
}

View file

@ -118,19 +118,22 @@ void theme_builtin(void)
void theme_read(const char *theme_name)
{
FILE *stream;
FILE *stream = NULL;
char *line = NULL;
size_t len = 0;
char themerc[4096];
snprintf(themerc, sizeof(themerc), "%s/themerc", theme_dir(theme_name));
info("reading themerc (%s)", themerc);
if (strlen(theme_dir(theme_name))) {
snprintf(themerc, sizeof(themerc), "%s/themerc",
theme_dir(theme_name));
stream = fopen(themerc, "r");
}
if (!stream) {
warn("cannot read (%s) - load built-in theme", themerc);
warn("cannot find theme (%s), using built-in", theme_name);
theme_builtin();
return;
}
info("reading themerc (%s)", themerc);
while (getline(&line, &len, stream) != -1) {
char *p = strrchr(line, '\n');
if (p)