]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Improve log messages for reading config+theme
authorJohan Malm <jgm323@gmail.com>
Mon, 14 Sep 2020 17:17:36 +0000 (18:17 +0100)
committerJohan Malm <jgm323@gmail.com>
Mon, 14 Sep 2020 17:17:36 +0000 (18:17 +0100)
src/common/dir.c
src/common/log.c
src/config/rcxml.c
src/theme/theme.c

index 10b957638d8b09b94cbc0012cf74c90f8e77b4d6..75adb0722fa7b345c5156d60ee4156087a0d0ce8 100644 (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;
 }
 
index e3385b1f6c60d69dbf677f8915fd383638b6aadc..c67e8e1e079d8df234dda252a211af9628ecaa5f 100644 (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);
index 5ce5ed5617d0e47bc506cd797d85daf86ae35fed..835bea195c3a89750b7578caf0bc051a83c45c2d 100644 (file)
@@ -260,12 +260,11 @@ 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
-               snprintf(buf, len, "%s/rc.xml", config_dir());
+       if (!strlen(config_dir()))
+               return;
+       snprintf(buf, len, "%s/rc.xml", config_dir());
 }
 
 void rcxml_read(const char *filename)
@@ -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();
 }
 
index 4abb3621e6bdc71e472da607e3598ea0d0a7ad92..5942d0c618e81862e3882696357a24ac13042000 100644 (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);
-       stream = fopen(themerc, "r");
+       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)